问题
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