loader fix for global symbols lookup #11
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a weird bug that occurs when an ELF binary is loaded dynamically. Basically, when we load an ELF, some global symbols are added in the global symbol table, and everything seems correct here. However, if we want to retrieve the symbol value afterwards, the lookup fails because the symbol name in the table contains weird spacing characters at the end, making
symbol_matches
returnfalse
.It is difficult to reproduce this bug because we need to dynamically load an ELF, but I took a screenshot that shows the anomaly:

In this debug logs, I printed the name of the symbol and its length with the format
<name>:<length>
.The second line (
Adding symbol...
) is printed when the ELF is loaded dynamically: here the name of the symbol is correct. The following lines are printed when we want to retrieve the value of this symbol: the name printed out is the one stored in the symbol table. You can see that now this symbol for some strange reason has an additional character at the end (a newline).I inspected the code quite carefully but I couldn't find the reason for this bug. However, I came up with a (temporary) fix to circumvent the bug, by ignoring spacing characters at the end of the symbol name in the comparison performed in
symbol_matches