Compilation error: moving R_X86_64_PC32 against undefined character

I am trying to execute functions in assembly language and put them in a dynamic library, so I create .o with .S using this command:
nasm -f elf64 hello.S -o hello.o
but when I want to create lib with gcc:
gcc -fPIC -shared hello.o -o libasm.so
and it displays me this error:
/usr/bin/ld: hello.o: relocation R_X86_64_PC32 against undefined symbol printf@ @GLIBC_2.2.5 can not be used when making a shared object; recompile with -fPIC

+6
source share
1 answer

From http://www.nasm.us/xdoc/2.10rc8/html/nasmdoc9.html#section-9.2.5 :

To call an external routine, you must use another special type of PIC movement, WRT..plt. This is much simpler than on a GOT basis: you simply replace calls like CALL printf with the PLT-relative version of CALL printf WRT..plt.

therefore instead

 ; ... call printf 

use

 ; ... call printf WRT ..plt 

and compile and link as usual.

+4
source

All Articles