bash-3.2$ cat x.c extern void foo() __attribute__((weak,visibility("hidden"))); extern int puts( char const* ); int main() { foo ? foo() : puts( "foo == null, skipped." ); return 0; } bash-3.2$ /usr/gcc-4.4/bin/gcc -B./ -fPIC -g -c -o x.o x.c bash-3.2$ ./ld -shared -o libx.so x.o ./ld: x.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 bash-3.2$ /usr/gcc-4.4/bin/gcc -B./ -fPIC -g -c -o x.o x.c -m32 bash-3.2$ ld -m elf_i386 -shared -o libx.so x.o bash-3.2$ Linker should issue clear error message for both cases.
Gcc bug is http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32219 A patch is posted at http://sourceware.org/ml/binutils/2008-02/msg00239.html
Fixed by http://sourceware.org/ml/binutils/2008-03/msg00111.html