[PATCH] D53782: [llvm-objcopy] Don't apply --localize flags to common symbols

Jordan Rupprecht via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 30 15:30:34 PDT 2018


rupprecht added a comment.

In https://reviews.llvm.org/D53782#1280158, @jhenderson wrote:

> On STT_COMMON, it looks like it only matters in fully linked files, since STT_COMMON symbols must always be in SHN_COMMON in relocatable objects. However, STT_COMMON can affect dynamic link-time semantics too, so I guess we may have to check for both. You should check GNU objcopy's behaviour in this case too (i.e. does an STT_COMMON symbol in a fully-linked ELF get affected or not by this option - I assume it is affected), and test accordingly.


GNU objcopy seems to only ignore --localize options for symbols where the index is SHN_COMMON, but not when it is STT_COMMON in some other section.
Based on an earlier comment, I changed this to respect index == SHN_COMMON and type == STT_COMMON equally, i.e. --localize-* will not be applied in either of those cases. So this would be breaking compatibility. I don't have a preference one way or the other; I'm happy to change it back if someone feels strongly.

> At the moment, the tests only test for the relocatable output case (i.e. where STT_COMMON is in SHN_COMMON), and we need cases for STT_COMMON not in SHN_COMMON.

I wasn't able to come up with a real-life repro for this, but I changed the test case to EM_EXEC and changed the section.
readobj still prints "Common" for the section name, but you can see from the flag that it is not in the special SHN_COMMON section -- i.e. SHN_COMMON is 0xFFF2, but the STT_COMMON symbol here is in 0x2. But I'm not sure if that specific section number is reliable (based on buildbot configuration etc.), so I just checked that the output section is not 0xF* for that.

If you're able to come up with a real-life way to get STT_COMMON in a fully linked executable, I can adapt this test case to look like it. I tried variants of things like: `echo 'int foo; int main() { return 0; }' | gcc -xc - -o /tmp/common-linked -Wa,--elf-stt-common=yes -Wl,-z -Wl,common && bin/llvm-readobj -symbols /tmp/common-linked | grep -B1 -A7 foo`, which still converts it to STT_OBJECT when putting it in .bss.


Repository:
  rL LLVM

https://reviews.llvm.org/D53782





More information about the llvm-commits mailing list