创建共享库时,不能使用针对".data"的重定位R_X86_64_32S;用gcc用-fPIC重新编译 [英] relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC with gcc
问题描述
当我使用gcc编译print.s时,出现以下错误:
When I compile print.s using gcc I get the following error:
/usr/bin/ld: /tmp/cc45uyZj.o: relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
-
我在另一个linux发行版中尝试了同样的方法,并且效果很好.
I tried the same in another linux distribution and it worked perfectly.
添加-fPIC没有帮助. apt-get更新也不会.
Adding -fPIC doesn't help. Nor does apt-get update.
如果您想查看代码: https://github.com/NEGU93/练习>第1部分中的Compilation.git .当然是文件print.s(顺便说一句,当我执行gcc时,所有.s文件都有类似的错误).
if you want to see the code: https://github.com/NEGU93/Compilation.git inside the Practice > Part1. Of course is the file print.s (btw. all the .s files have similar errors when I do gcc).
我猜Kali发行版中缺少某些内容,但我不知道该怎么办.
I guess something is missing in the Kali distro but I don't know what can it be.
推荐答案
似乎您的发行版默认启用了-pie
(检查gcc -v
输出),但是您的程序集与位置无关.尝试在-fPIC
下编译一个示例.c文件,并查看其如何生成调用.您的情况应该是
It seems that your distro enables -pie
by default (check gcc -v
output) but your assembly is not position-independent. Try compiling a sample .c file under -fPIC
and see how it generates calls. In your case it should be
call printf@PLT
,或者您可以尝试使用gcc -no-pie
进行编译.
or you can try compiling with gcc -no-pie
.
这篇关于创建共享库时,不能使用针对".data"的重定位R_X86_64_32S;用gcc用-fPIC重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!