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

elfcopy: Add --redefine-syms <file> arguments #508

Merged
merged 1 commit into from
Feb 14, 2023

Conversation

amshafer
Copy link
Contributor

@amshafer amshafer commented Feb 8, 2023

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.

crates/examples/src/bin/elfcopy.rs Outdated Show resolved Hide resolved
crates/examples/src/bin/elfcopy.rs Outdated Show resolved Hide resolved
crates/examples/src/bin/elfcopy.rs Outdated Show resolved Hide resolved
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.
Copy link
Contributor

@philipc philipc left a comment

Choose a reason for hiding this comment

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

Thanks! We'll want to do something better with the command line argument parsing if we add more arguments, but this is ok for now.

@philipc philipc merged commit a3706b5 into gimli-rs:master Feb 14, 2023
mcbegamerxx954 pushed a commit to mcbegamerxx954/object that referenced this pull request Jun 15, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants