Handling weakundef symbol
| Bugzilla Link | 30609 |
| Version | trunk |
| OS | Linux |
Extended Description
LLVM gold plugin set the visibility of weakundef symbol to be default while GCC lto plugin sets it to hidden.
With LLVM gold plugin and bfd linker, the weak attribute of 'hello' will be dropped in the final shared object:
clang -fuse-ld=bfd -flto=thin -O2 -shared -fPIC -o libt.so test.c
If the program is compiled with -DHIDDEN, linker reports the following error (for both bfd and Gold linker): (happens with both llvm lto and thinlto)
/usr/bin/ld: /tmp/lto-llvm-e9a305.o: relocation R_X86_64_PC32 against undefined hidden symbol `hello_world' can not be used when making a shared object
/usr/bin/ld.gold: error: /tmp/lto-llvm-9dad7e.o: requires dynamic R_X86_64_PC32 reloc against 'hello_world' which may overflow at runtime; recompile with -fPIC
GCC LTO is fine (with both linkers)
#ifdef HIDDEN attribute((weak,visibility("hidden"))) int hello_world(); #else attribute((weak)) int hello_world(); #endif
int test() { if (hello_world) return hello_world(); return 0; }