Ich versuche Funktionen in Assembler-Sprache zu machen und sie in einer dynamischen Bibliothek setzen, damit ich mit .S mit diesem Befehl erstellen .o:
nasm -f elf64 hello.S -o hello.o
aber wenn ich möchte, dass die erstellen lib mit gcc:
gcc -fPIC -shared hello.o -o libasm.so
und es zeigt mir diesen Fehler:
/usr/bin/ld: hello.o: relocation R_X86_64_PC32 against undefined symbol [email protected]@GLIBC_2.2.5 can not be used when making a shared object; recompile with -fPIC
Compile Fehler: Verlagerung R_X86_64_PC32 gegen undefiniertes Symbol
6
A
Antwort
4
Von http://www.nasm.us/xdoc/2.10rc8/html/nasmdoc9.html#section-9.2.5:
To call an external routine, you must use another special PIC relocation type, WRT ..plt. This is much easier than the GOT-based ones: you simply replace calls such as CALL printf with the PLT-relative version CALL printf WRT ..plt.
so statt
; ...
call printf
Verwendung
; ...
call printf WRT ..plt
und kompilieren und verknüpfen wie normal.
Siehe http://www.nasm.us/xdoc/2.10rc8/html/nasmdoc9.html#section-9.2.5 (_Calling-Prozeduren außerhalb der Bibliothek_) – Michael