I've played with binutils objcopy --strip-all --keep-symbol foo,
so if the symbol table contains the symbol "foo"
it's not getting remove.
Test plan: make check-all
Differential D47052
[llvm-objcopy] Fix the behavior of --strip-* and --keep-symbol alexander-shaposhnikov on May 17 2018, 9:32 PM. Authored by
Details I've played with binutils objcopy --strip-all --keep-symbol foo, Test plan: make check-all
Diff Detail
Event Timeline
Comment Actions Hi ! First, for example, if we take localize-hidden.test test, and we apply -R .rel.text -N undefLocal, this way we would trigger an error. I know that objcopy is behaving the same as this patch behaves, but I was wondering if we could/want to do better ? Then, for the example you gave, it seems that the behavior is not matching what you're saying. For instance, still with localize-hidden.test with --strip-all -K defaultGlobal, every other global/weak symbols are kept, which is not the case with objcopy. I think this change is not sufficient to handle this problem (and more generally option conflicts), and it is creating other problems we might at least be aware of.
Comment Actions I might have missed something, but why do we need to keep _all_ of the local symbols, if one is kept? Surely that's completely unnecessary? And why local symbols and not global or weak symbols? It seems pretty straightforward that --strip-all --K <some symbol> should produce a symbol table with exactly one symbol in it (plus the null symbol). Comment Actions @jhenderson, [alexshap@devvm1372.frc2 ~/local] cat a.c Binding: Local (0x0) Binding: Local (0x0) Binding: Local (0x0) Binding: Local (0x0) Binding: Local (0x0) Binding: Local (0x0) Binding: Local (0x0) [alexshap@devvm1372.frc2 ~/local] ~/llvm-readobj.sh -symbols b.o | grep yy Name: yy (1) [alexshap@devvm1372.frc2 ~/local] ~/llvm-readobj.sh -symbols b.o | grep xx so basically we can implement this option without trying to repeat binutils behavior, Comment Actions I'm of the opinion that if the GNU behaviour doesn't make sense, we shouldn't follow it blindly, so I'd be happy in a divergence here, but I'm not a regular GNU tools user, so it might be wise to get @jakehehrlich's thoughts on this before proceeding. Comment Actions I agree. This dosn't make sense to me. We should only keep the explicitly kept symbol and anything it relays on. Comment Actions LGTM, with a few nits.
|
If possible I'd prefer this come after and I'd prefer not using the functions in removeSymbols to keep state. I think it's sufficient to just check that SymbolsToKeep is non-empty for the single explicit section keep.