I am trying to create shared libraries that have some functions in the assembly that call other functions. When I build liba.so
with code
void aFunc1()
{
}
asm(
".globl aFunc2\n\t"
".type aFunc2, @function\n\t"
"aFunc2:\n\t"
".cfi_startproc\n\t"
"call aFunc1\n\t" /* note here*/
"ret\n\t"
".cfi_endproc\n\t"
);
and team
gcc -o liba.so a.c -shared -fPIC
I got an error
/usr/bin/ld: /tmp/ccdGBiQv.o: relocation R_X86_64_PC32 against symbol `aFunc1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
He tells me to use the option -fPIC
, but I already use this option! However, I find out that with the option -Wl,-Bsymbolic
it compiles fine.
gcc -o liba.so a.c -shared -fPIC -Wl,-Bsymbolic
Unfortunately, the problem arises when I try to create a second library libb.so
also with build functions that try to call calling functions from the first library. Code compilation
#include <a.h>
asm(
".globl bFunc2\n\t"
".type bFunc2, @function\n\t"
"bFunc2:\n\t"
".cfi_startproc\n\t"
"call aFunc1\n\t" /* note here*/
"ret\n\t"
".cfi_endproc\n\t"
);
with the team
gcc -o libb.so b.c liba.so -shared -fPIC -Wl,-Bsymbolic
gives an error
/usr/bin/ld: /tmp/ccaGvn5d.o: relocation R_X86_64_PC32 against symbol `aFunc1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
and, as you see, the option -Wl,Bsymbolic
does not help.
, -Wl,Bsymbolic
. , , - . , ?