当我使用 gcc 编译 print.s 时,出现以下错误:
/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
Run Code Online (Sandbox Code Playgroud)
我在另一个 linux 发行版中尝试了同样的方法,它运行得很好。
添加-fPIC没有帮助。apt-get 更新也不行。
如果你想看代码:https : //github.com/NEGU93/Compilation.git里面的练习 > Part1。当然是文件print.s(顺便说一句。当我做gcc时,所有的.s文件都有类似的错误)。
我想 Kali 发行版中缺少某些东西,但我不知道它可能是什么。
yug*_*ugr 11
似乎您的发行版-pie默认启用(检查gcc -v输出),但您的程序集不是位置无关的。尝试在下面编译示例 .c 文件-fPIC并查看它如何生成调用。在你的情况下应该是
call printf@PLT
Run Code Online (Sandbox Code Playgroud)
或者您可以尝试使用gcc -no-pie.