nasm问题重定位R_X86_64_PC32共享库

时间:2014-03-27 14:56:20

标签: gcc assembly 64-bit nasm fpic

我使用nasm 64将.S编译为.o然后使用gcc创建一个共享库:

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调用source / strlen.S中的fonction strlen 编译行会抛出错误:

/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

我可以在编译.S时使用-cPIC选项和gcc但是我使用的是nasm而我找不到相同的选项。

有人知道如何避免这个问题吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

您需要确保编写与位置无关的代码。您可能会发现DEFAULT RELREL关键字本身很有用。

相关问题