nasm问题重定位R_X86_64_PC32共享库 [英] nasm issue relocation R_X86_64_PC32 shared library

查看:382
本文介绍了nasm问题重定位R_X86_64_PC32共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nasm 64将.S编译为.o,然后使用gcc创建一个共享库,如下所示:

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调用位于source/strlen.S中的函数strlen 编译行将引发错误:

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

在编译.S时,我可以在gcc中使用-fPIC选项,但是我使用的是nasm,但找不到等效的选项.

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 ?

提前谢谢.

推荐答案

您需要确保要编写位置无关的代码.您可能会找到默认REL REL 关键字本身很有帮助.

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

这篇关于nasm问题重定位R_X86_64_PC32共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆