-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Refactor of elf.c and remove reference to section name in get_import_addr #16530
Conversation
Instead of using a full matrix, just add the builds we care about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove all the style-only changes from this PR, then I'll review. Anyway, the results about symbols with no sections header information 3:
look better in your PR than in master, so that's already an improvement :)
Ah, @08a please rebase on top of current master as well. |
What do you think of |
Should i rewrite |
Yes, you should fix the test. Your results seem good.
I see these changes:
I think your changes are still good even in this case. The old values may interpreted as real addresses, but they are not. They are just useless values, so I think it's better to have 0s. IDA creates a fake section for those entries, but I think 0 for now is good. Does that sound good? |
perfect i will fix that |
Okay, thanks for your feedback. For the position, i choose to not include this information inside the struct, because i didn't find any documentation which explain that the position inside the relocation table is the same that the position inside the got. So we need to recompute every time the position (the cost is not really expensive). I understand that the majority of the code can be confusing so i will try to explain my choices. get_import_addr_armIn arm elf, the plt_addr is stored inside the got_entry, so i can read a random entry and get the based addr of the plt section. get_import_addr_mipsIn mips the got addr is stored inside a special dynamic entry anmed DT_MIPS_PLTGOT (when there is some relocation) get_import_addr_riscvRiscv is like arm (get_got_entry). get_import_sparcWe only support R_SPARC_JMP_SLOT. If the relocation is supported the entry inside the got return almost the exact position in the plt of the import_addr we only need some small adjustment (-size of the instruction to jump). It is cleaner than use some position. get_import_ppcAlmost the same, pos is from the base addr of the plt (since the rva has a ref inside the plt). get_import_x86less modified, the code is self-explanatory. ConclusionAs you can see i tried to be more logic. I understand that your are scared that the new code is broken. I will try to reduce again the diff size. |
There is to much dependencies between to many function, it is why the size a the diff is so big. |
I believe i revert all the esthetic change, now all we have is algorithm modification. imho algorihm that should have been changed long time ago. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the position, i choose to not include this information inside the struct, because i didn't find any documentation which explain that the position inside the relocation table is the same that the position inside the got. So we need to recompute every time the position (the cost is not really expensive).
Ok.
I understand that the majority of the code can be confusing so i will try to explain my choices.
Thanks a lot! I really appreciate the explanation!
I understand that your are scared that the new code is broken. The main problem is not that we have a new code but that you don't trust the test suite. Maybe it is a small sign that the test suite is not exhaustive
Of course I don't trust the test suite :) It's hard to cover everything. I think, for example, we don't have any MIPS bin with relocations.
I personally don't have all the competence to add tests but if you know someone that is willing to do, let me know.
Yeah, me neither. That's why I try to touch things I need and never "too much".
Anyway, overall the PR looks good to me, I just added some small comments here and there. Please try to address them, then we are almost ready to merge I think. Thanks again for your hard work!
I found one bin with relocation.
|
Nice catch! I did not find it because I was using |
This pull request introduces 2 alerts when merging 06cd49b into 1b56d63 - view on LGTM.com new alerts:
|
I don't see why lgtm isn't happy? Each comparison are valid. |
Oh, tricky one :D ut64 base = r_buf_read_ble32_at (bin->b, p_plt_addr, bin->endian);
if (base == UT64_MAX) {
ut64 addr = BREADWORD (bin->b, p_sym_got_addr);
return (!addr || addr == UT64_MAX) ? UT64_MAX : addr; When R_BIN_ELF64 is not defined, BREADWORD will use the r_buf_read_ble32_at, which, again, returns UT32_MAX in case of error and not UT64_MAX. |
@ret2libc It is fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I will review this later and merge if ok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks a lot for the great work, impressive!
Your checklist for this pull request
Detailed description
2 tests fail.symbols with no sections header information 3
: i believe the test is wrong, before the refacto the return addr of get_import_addr was always -1 because there was no section name.ELF: imports partial
: i believe the return value (get_import_addr_x86_manual
) when to .plt.got entry can't be found should be -1 not a garbage value.PS: if the return value of
get_import_addr_x86_manual
is the variableplt_sym_addr
another test fail.Test plan
Run tests
Closing issues
#12732