Romain
Romain

Reputation: 107

why cannot use R_X86_64_PC32 with shared libs

It seems to not be possible to build a shared lib from relocable objects with R_X86_64_PC32 references and I don't understand why.

These references are IP relative and so are position independent. So why ld tell me this is not the case and I have to use -fPIC which generate a GOT reference ?

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

Upvotes: 1

Views: 279

Answers (1)

Romain
Romain

Reputation: 107

As it is said here : 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.

We have to use -fPIC to go through GOT which is updated at runtime for symbol overriding.

Upvotes: 1

Related Questions