相关疑难解决方法(0)

与位置无关的代码的差异:x86 vs x86-64

我最近正在构建一个针对x86-64架构的特定共享库(ELF),如下所示:

g++ -o binary.so -shared --no-undefined ... -lfoo -lbar
Run Code Online (Sandbox Code Playgroud)

这失败,出现以下错误:

在制作共享对象时,不能使用对"本地符号"的重定位R_X86_64_32; 用-fPIC重新编译

当然,这意味着我需要将其重建为与位置无关的代码,因此它适合链接到共享库.

But this works perfectly well on x86 with exactly the same build arguments. So the question is, how is relocation on x86 different from x86-64 and why don't I need to compile with -fPIC on the former?

c linux x86 x86-64 elf

24
推荐指数
2
解决办法
5719
查看次数

标签 统计

c ×1

elf ×1

linux ×1

x86 ×1

x86-64 ×1