我最近正在构建一个针对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?