-
Notifications
You must be signed in to change notification settings - Fork 962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prototypes for dynamically-linked functions without headers #1092
Conversation
…ut headers When the program involves dynamically-linked functions like _Znwj (operator new) that return a pointer, it is necessary to have prototypes for them, since otherwise they will be implicitly deduced to return "int" which cannnot be dereferenced. Previously RetDec was emitting comments telling which functions were dynamically linked. This change moves them up before the functions are emitted and instead emits prototypes for the functions. However, RetDec also inserts includes of headers for functions for with know headers. We do not emit prototypes for functions with headers as that would be redundant. As a result, some dynamically-linked functions that used to show in the comments no longer appear as the included header will declare them. The section header comment for dynamically-linked functions is only produced if some prototypes are written for dynamically-linked functions. A related PR will have added tests as well as changes needed for existing tests.
@PeterMatula, could you please review this change? This continues my effort to get dynamically-linked functions to decompile correctly. |
Thanks @richardlford for another improvement. In general I like it, however did you notice a small regression in this test? Looks like before, we applied type info to functions in |
@PeterMatula, I have investigated this further. Here are some findings:
In summary, I think it would require a bit more work to make the function prototypes look like the lti declarations. On the other hand, it would be relatively easy to include the lti declaration as a comment just above each prototype, if you think that would be helpful. What do you think? Do you have suggestions for how to proceed? |
@PeterMatula, ping? |
Sorry about the delay @richardlford, I know about it, I just didn't get around to looking into it more so I can answer. I have a look tomorrow and let you know. |
Sorry for taking so long @richardlford, and thanks for the improvement. I looked into it again and realized I misunderstood what exactly was going on the first time. I thought there is a regression on an LLVM IR level, and that we are possibly losing correct data type information on function parameters. But that is not the case, all the info is there, we just generate it slightly differently. The output could be further improved with the info we have by either omitting all the linked functions we know via LTI, or by using the argument names from the same source. But this is not the goal of your PR, so let's not complicate it. You are right about this:
Or even better, it would be best to use external knowledge like LTI information only once somewhere in the beginning and embed it all into LLVM IR either directly or via some well-documented metadata, so that we have a fully self-contained LLVM IR and further passes do not have to access specialized resources. But like I said, this is just an idea for further improvements, it does not block your work. |
When the program involves dynamically-linked functions like _Znwj
(operator new) that return a pointer, it is necessary to have
prototypes for them, since otherwise they will be implicitly deduced
to return "int" which cannnot be dereferenced.
Previously RetDec was emitting comments telling which functions were
dynamically linked. This change moves them up before the functions are
emitted and instead emits prototypes for the functions. However,
RetDec also inserts includes of headers for functions with known
headers. So this change does not emit prototypes for functions with headers as that
would be redundant. As a result, some dynamically-linked functions
that used to show in the comments no longer appear as the included
header will declare them.
The section header comment for dynamically-linked functions is only
produced if some prototypes are written for dynamically-linked
functions.
A related PR (avast/retdec-regression-tests#121)
adds tests as well as changes needed for existing tests.