Octocontrabass wrote:
I'm pretty sure PIE can still require relocations, just not in the .text section. (But PE doesn't have PIC or PIE, those are part of ELF.)
True, it can require relocations in the .data section for instance if you initialise something with the address of something else. But it will not require a GOT. Remember the original context was:
zaval wrote:
I am not sure what effect the gcc's -pie flag would have on PE targets, if any. in the ELF context, it's a total opposite to the PE approach, and it hardly would work for the latter, because PE loader does apply base relocations, that is fixes up addresses in the code and data itself, while -pie would require fixing up the contents of a special indirection table (GOT)
Regarding:
Octocontrabass wrote:
Actually, on further investigation, this might be target-dependent. Mingw-w64 GCC always uses RIP-relative addressing for x64, but Linux GCC only uses RIP-relative addressing for position-independent code (PIC or PIE).
Linux GCC will at least sometimes use RIP-relative addressing for non-PIC & non-PIE code:
https://godbolt.org/z/3jWTorbTqAgain it will depend on the memory model, at least. Adding "-mcmodel=large" to the command line will cause the above example to no longer use RIP-relative addressing.
Octocontrabass wrote:
Mingw-w64 never uses EIP-relative addressing for i686, but the reasoning is much easier to understand: PE doesn't have PIC or PIE, and EIP-relative addressing is significantly bigger and slower than ordinary position-dependent addressing.
That makes sense. The same is true on Linux unless you use -fpie (or your GCC is configured to generate PIE code by default).