Skip to content

Instantly share code, notes, and snippets.

@depressed-pho
Created April 4, 2013 05:18
Show Gist options
  • Save depressed-pho/5308015 to your computer and use it in GitHub Desktop.
Save depressed-pho/5308015 to your computer and use it in GitHub Desktop.
Old binutils fails to link a shared library if there is a reference to a hidden symbol that isn't locally defined.
void callee() {
/* Look I'm not declared as a hidden symbol! */
}
__attribute__((__visibility__("hidden"))) void callee();
void caller() {
callee();
}
% gmake
ld -v
GNU ld version 2.17.50.0.6-20.el5_8.3 20061020
gcc -fPIC -o caller.o -c caller.c
gcc -fPIC -o callee.o -c callee.c
gcc -shared -o libfoo.so caller.o callee.o
/usr/bin/ld: caller.o: relocation R_X86_64_PC32 against `callee' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
gmake: *** [all] Error 1
%
% gmake
ld -v
GNU ld (NetBSD Binutils nb1) 2.21.1
gcc -fPIC -o caller.o -c caller.c
gcc -fPIC -o callee.o -c callee.c
gcc -shared -o libfoo.so caller.o callee.o
%
all:
ld -v
gcc -fPIC -o caller.o -c caller.c
gcc -fPIC -o callee.o -c callee.c
gcc -shared -o libfoo.so caller.o callee.o
clean:
rm -f *.o *.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment