为什么不能将 R_X86_64_PC32 与共享库一起使用

why cannot use R_X86_64_PC32 with shared libs

似乎无法从具有 R_X86_64_PC32 引用的可重定位对象构建共享库,我不明白为什么。

这些引用是相对于 IP 的,因此与位置无关。那么,为什么 ld 告诉我情况并非如此,我必须使用 -fPIC 来生成 GOT 引用?

relocation R_X86_64_PC32 against symbol `infolib' can not be used when making a shared object; recompile with -fPIC

正如这里所说:Difference in position-independent code: x86 vs x86-64

IP-relative offset does not work for shared libraries, because global symbols can be overridden, so x86-64 breaks down when not built with PIC.

我们必须使用 -fPIC 来通过 GOT,它在运行时更新以进行符号覆盖。