nasm issue relocation R_X86_64_PC32 shared library

拟墨画扇 提交于 2019-12-12 02:24:19

问题


I am using nasm 64 to compile .S to .o and then create a shared library with gcc like this:

nasm -f elf64 source/strlen.S
nasm -f elf64 source/strchr.S
nasm -f elf64 source/memset.S
nasm -f elf64 source/strcspn.S
nasm -f elf64 source/rindex.S
nasm -f elf64 source/strpbrk.S
nasm -f elf64 source/strcmp.S
nasm -f elf64 source/strncmp.S
nasm -f elf64 source/strcasecmp.S
/usr/bin/gcc -shared ./source/strlen.o ./source/strchr.o ./source/memset.o ./source/strcspn.o ./source/rindex.o ./source/strpbrk.o ./source/strcmp.o ./source/strncmp.o ./source/strcasecmp.o -o libasm.so

source/rindex.S calls the fonction strlen which is in source/strlen.S The compilation line throw an error:

/usr/bin/ld: ./source/rindex.o: relocation R_X86_64_PC32 against symbol `strlen' can not be used when making a shared object; recompile with -fPIC

I could use -fPIC option with gcc when compiling the .S but I am using nasm and I don't find the equivalent option.

Does someone know how I can avoid this issue ?

Thanks in advance.


回答1:


You need to make sure you are writing position independent code. You might find the DEFAULT REL and the REL keyword itself helpful.



来源:https://stackoverflow.com/questions/22691370/nasm-issue-relocation-r-x86-64-pc32-shared-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!