When a symbol in a comdat/linkonce section has different visibility in different files, linker doesn't merge symbol visibility: bash-3.1$ cat foo.c int foo __attribute__ ((section (".gnu.linkonce.d.1"))) = 1; int __attribute__ ((section (".gnu.linkonce.t.1"))) bar () { return 1; } bash-3.1$ cat bar.c int foo __attribute__ ((section (".gnu.linkonce.d.1"), visibility ("hidden"))) = 1; int __attribute__ ((section (".gnu.linkonce.t.1"), visibility ("hidden"))) bar () { return 1; } int get_foo () { return foo; } int get_bar () { return bar (); } bash-3.1$ make gcc -fPIC -O -c -o bar.o bar.c gcc -fPIC -O -c -o foo.o foo.c ld -shared -o lib1.so bar.o foo.o ld -shared -o lib2.so foo.o bar.o ld: bar.o: relocation R_X86_64_PC32 against `foo' can not be used when making a shared object; recompile with -fPIC ld: final link failed: Bad value make: *** [lib2.so] Error 1 bash-3.1$ Should we handle this case?
A patch is posted at http://sourceware.org/ml/binutils/2006-12/msg00059.html
Fixed.