Skip to content
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

Unify the relocations loading #16705

Merged
merged 6 commits into from Apr 24, 2020
Merged

Unify the relocations loading #16705

merged 6 commits into from Apr 24, 2020

Conversation

ghost
Copy link

@ghost ghost commented Apr 23, 2020

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the documentation and the radare2 book with the relevant information (if needed)

Detailed description
The relocations are loaded 3 times... I try to fix that.

Test plan
...

Closing issues
#12732
...

@ghost
Copy link
Author

ghost commented Apr 23, 2020

@ret2libc Again i move stuff up... sorry
I was thinking about using Ht_(foreach) on rel_cache when used inside bin_elf.inc?

  2 libr/bin/p/bin_elf.inc
  3 691:            if (!(relocs = Elf_(r_bin_elf_get_relocs) (bin))) {
  4 907:    if (!(relcs = Elf_(r_bin_elf_get_relocs) (bin))) {

Is this function well optimized?

@ret2libc
Copy link
Contributor

Is this function well optimized?

I guess that depends on what you mean by "well optimized" :) It is a foreach, it iterates over each element of the hash table and run a callback function. You can use that to convert the hashtable to an array. It will be O(n) and that is what matters for now I think. If we need even more optimization, we can take care of that later if/when needed.

@ghost
Copy link
Author

ghost commented Apr 23, 2020

An other alternative could be

bin->relocs (array relocs)
bin->rel_cache (Hash Table)

@ghost
Copy link
Author

ghost commented Apr 23, 2020

In the idea bin->relocs would hold all the data and rel_cache reference the array

@ghost
Copy link
Author

ghost commented Apr 23, 2020

@ret2libc For me this refactorization is done

@ghost ghost marked this pull request as ready for review April 23, 2020 21:16
@github-actions github-actions bot added the RBin label Apr 23, 2020
@XVilka XVilka requested a review from ret2libc April 24, 2020 05:03
@XVilka XVilka added this to the 4.5.0 - Organized Chaos milestone Apr 24, 2020
Copy link
Contributor

@ret2libc ret2libc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it's better to keep using Elf_(r_bin_elf_get_relocs) to access relocations. Inside that function, you can fill bin->relocs and bin->rel_cache the first time and then return bin->relocs once it was set.

libr/bin/p/bin_elf.inc Outdated Show resolved Hide resolved
libr/bin/p/bin_elf.inc Show resolved Hide resolved
@ghost
Copy link
Author

ghost commented Apr 24, 2020

I removed a check for bin->g_section because all the subfunctions do already the check.

Copy link
Contributor

@ret2libc ret2libc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM

@XVilka XVilka merged commit 78de31f into radareorg:master Apr 24, 2020
@ghost ghost deleted the refacto_loading_relocation branch April 24, 2020 13:54
Emi1305 pushed a commit to Emi1305/radare2 that referenced this pull request Jul 12, 2020
* Mov init rel_cache inside the bin init
* Introduce array cache
* Use bin->relocs after loading all relocs
* Handle bin->relocs == NULL
* Remove last free
* Use cache to get relocations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants