nasm问题:重定位R_X86_64_PC32共享库

3

我正在使用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中的函数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

我可以在使用gcc编译.S文件时使用-fPIC选项,但我使用的是nasm,我找不到相当于该选项的选项。

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

提前致谢。


你是“编译器”(手动生成汇编代码)。避免使用32位绝对地址取决于你自己(如现代PIE可执行文件中不再允许使用32位绝对地址:x86-64 Linux中不再允许使用32位绝对地址?)。如果你想要尊重符号插入的内容,你也需要手动完成这个过程,即使是对于你自己的静态存储,也需要通过PLT或GOT进行处理,除非你希望将其视为ELF可见性=隐藏。 - undefined
1个回答

3

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接