2016-03-15 7 views
6

Staram się funkcji w asemblerze i umieścić je w dynamicznej biblioteki więc tworzę .o z .S poleceniem:
nasm -f elf64 hello.S -o hello.o
ale gdy chcę utworzyć lib z gcc:
gcc -fPIC -shared hello.o -o libasm.so
i wyświetla mi ten błąd:
/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 -fPICBłąd kompilacji: relokacja R_X86_64_PC32 przed nieokreślonym symbolem

+2

Zobacz http://www.nasm.us/xdoc/2.10rc8/html/nasmdoc9.html#section-9.2.5 (_ Procedury wywoływania poza biblioteką_) – Michael

Odpowiedz

4

Od 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.

więc zamiast

; ... 
call  printf 

użycie

; ... 
call  printf WRT ..plt 

i skompilować i link jako normalne.