elfcopy: Add --redefine-syms <file> arguments #508
Merged
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.
I know that elfcopy is supposed to be a reader/writer example for ELF files, but I found it was the only tool that would let me redefine symbols in shared libraries. I think there is some serious value in having a tool that does this, especially since the way other objcopy implementations work makes it basically impossible to implement something like this easily.
If you'd like elfcopy to remain a basic copy example without command line arguments I'll understand. I originally made this a standalone repo, but I'd like to contribute it back as I personally found it pretty lifesaving. Thanks and love the toolkit!
This commit makes elfcopy the only tool I'm aware of that will let you rename symbols in dynamic libraries. Other tools like objcopy will only perform renaming on the symbol table, but will not rename dynamic strings or recalculate the hashes/offsets that change as a result.
This works by creating a redefinition table, and handing symbol (dynamic and otherwise) to the table's get_redefined_name function before adding that string to the out_* variables. The elf binary is then regenerated from the output data (containing the renamed strings) and a valid DSO is generated.