llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

llvm-objcopy --localize-hidden should ignore common section objects

Open rupprecht opened this issue 8 years ago • 4 comments

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

rupprecht avatar Oct 26 '18 22:10 rupprecht

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

rupprecht avatar Oct 26 '18 23:10 rupprecht

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

rupprecht avatar Oct 26 '18 22:10 rupprecht

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.

pcc avatar Oct 26 '18 22:10 pcc

assigned to @rupprecht

rupprecht avatar Oct 26 '18 22:10 rupprecht