-
Notifications
You must be signed in to change notification settings - Fork 24
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
scanelf: allow user to choose whether to scan .symtab or .dynsym #9
base: master
Are you sure you want to change the base?
Conversation
I don't know enough about ELF yet to give a good review by myself. cc @SoapGentoo @xen0n |
oh, and ofc @vapier |
9958d87
to
cf6d096
Compare
Fixed wrong version name being extracted from |
Signed-off-by: Kacper Słomiński <kacper.slominski72@gmail.com>
This commit adds a new command line switch (-H/--how) that allows the user to select whether scanelf should look for symbols in .symtab or .dynsym. This is done because the the sections contain different sets of symbols (which somewhat intersect), and the names for the symbols differ (.symtab includes the version suffix within the symbol itself), which would cause scanelf to behave differently before and after stripping the executable. Additionally, it adds two modes of looking for symbols in .dynsym: - unversioned - look at the .dynsym entries as they are, - versioned - also look at .gnu.version to figure out the symbol version, and suffix the symbol name with it before matching, emulating the behavior of .symtab. Note that this does not handle the case where the dynamic section needs to be scanned to find the version information, as that case appears to not be fully functional anyway (no DT_GNU_HASH support, and most ELFs these days don't have DT_HASH). Consider it a TODO if need be :^). Bug: https://bugs.gentoo.org/847493 Co-authored-by: Arsen Arsenović <arsen@aarsen.me> Signed-off-by: Kacper Słomiński <kacper.slominski72@gmail.com>
cf6d096
to
6977085
Compare
Also added a sign off to both commits. |
in theory, the debug symbols (.symtab/.strtab) should be a superset of the runtime symbols (.dynsym/.dynstr). it used to be that way before commit efb0dff, then i changed it to try and guess based on who had more symbols. i don't recall what ELFs i was looking at at the time, but i'd believe there's still weirdness out there. i wonder if we should always scan both if they're found, and complain if there's a mismatch (i.e. one claims symbol foo lives at address X, but the other claims symbol foo lives at address Y, but we always defer to the runtime set). the poor symbol version matching has been a known problem for a long time -- it's in the TODO. i think we can/should handle it, but i'd like to disconnect it from the debug-vs-runtime symbol issue, and not involve off the top of my head, the states are:
so if someone is using that leaves the question of expected output behavior. if we scanned for
i'm kind of inclined to keep that. if people want to include the symbol version info in the output when passing an unversioned symbol, maybe we extend the output format. let's add
if they scanned for is there another scenario we need to cover ? |
That is reasonable, yes, and should be doable (with some caveats: see below).
Thing is, .symtab/.strtab contents (even the matching parts) don't exactly align with .dynsym/.dynstr precisely due to symbol versioning:
(didn't search for the same symbols, but the pattern is visible nevertheless) ... which means that the default behaviour before depended on whether .symtab/.strtab is present:
I guess we could decode dynsym/dynstr as name@[@] before matching against symtab/strtab? Hmm, that might be even more compatible.
Yeah, this idea sounds okay.
One more thing, maybe it'd be a good idea to detect whether |
This pull request adds a new command line switch (
-H
/--how
) thatallows the user to select whether
scanelf
should look for symbols in.symtab
or.dynsym
.This is done because the the sections contain different sets
of symbols (which somewhat intersect), and the names for the symbols
differ (
.symtab
includes the version suffix within the symbol itself),which would cause
scanelf
to behave differently before and afterstripping the executable.
Additionally, it adds two modes of looking for symbols in
.dynsym
:.dynsym
entries as they are,.gnu.version
to figure out the symbolversion, and suffix the symbol name with it before matching,
emulating the behavior of
.symtab
.Note that this does not handle the case where the dynamic section needs
to be scanned to find the version information, as that case appears to
not be fully functional anyway (no
DT_GNU_HASH
support, and most ELFsthese days don't have
DT_HASH
). Consider it a TODO if need be :^).Fixes bug 847493.
Thanks to @ArsenArsen for the idea for the fix.