llvm-objcopy --localize-hidden should ignore common section objects
| Bugzilla Link | 39461 |
| Resolution | FIXED |
| Resolved on | Nov 02, 2018 11:28 |
| Version | trunk |
| OS | Linux |
| CC | @alexshap,@jh7370,@pcc,@rupprecht |
| Fixed by commit(s) | rL345856 |
Extended Description
echo 'int a; int b = 0; int c() { return 5; }' | bin/clang -xc - -c -o /tmp/common.o -fvisibility=hidden
objcopy --localize-hidden /tmp/common.o; bin/llvm-readobj -symbols /tmp/common.o => a is not localized, though b/c are
bin/llvm-objcopy --localize-hidden /tmp/common.o; bin/llvm-readobj -symbols /tmp/common.o => a, b, c are all localized
Still not sure if this behavior is intentional or not, but SHN_COMMON explicitly prevents BSF_GLOBAL from being included in the flags here: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elfcode.h;h=f224c8b79d2fb0516a90c1a8ad818d11a1a971a5;hb=HEAD#l1298
No, I'm not sure it's not just a bug in objcopy.
I threw this in a debugger and poked at some values here: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/objcopy.c;h=1d29059b8df90eebab2dc9ec99ff1796f7ff2a3b;hb=HEAD#l1637 For a common symbol, "flags" is 65536 (BSF_OBJECT). Since only global/weak symbols are allowed by that check, --localize flags are ignored there.
I created https://reviews.llvm.org/D53782 to match objcopy behavior, but I can revert it if it's wrong.
btw, this was found when building dynamorio here, which explains why it uses --localize-hidden: https://chromium.googlesource.com/external/dynamorio/+/master/core/CMakeLists.txt#541
Are you sure this isn't a bug in objcopy? I'm not sure why common symbols should be treated differently to, for example, weak or comdat symbols, which are also "merged" by the linker.
assigned to @rupprecht