2016-03-15 12 views
6

Tôi cố gắng làm cho các chức năng trong ngôn ngữ lắp ráp và đặt chúng trong một thư viện động vì vậy tôi tạo .o với .S với lệnh này:
nasm -f elf64 hello.S -o hello.o
nhưng khi tôi muốn tạo lib với gcc:
gcc -fPIC -shared hello.o -o libasm.so
và nó sẽ hiển thị cho tôi lỗi này:
/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 -fPICCompile error: di dời R_X86_64_PC32 đối với ký hiệu không xác định

+2

Xem http://www.nasm.us/xdoc/2.10rc8/html/nasmdoc9.html#section-9.2.5 (_Hủy thủ tục bên ngoài thư viện_) – Michael

Trả lời

4

Từ 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.

nên thay vì

; ... 
call  printf 

sử dụng

; ... 
call  printf WRT ..plt 

và biên dịch và liên kết như bình thường.

Các vấn đề liên quan