You're right, I conflated the two options.Octocontrabass wrote:Hold on, there's a difference between "-fpie" and "-pie".davmac314 wrote:Note that If compiling with GCC and linking with GNU ld (to `pei-XXX` format eg pei-x86-64) you can use `--emit-reloc-section` at link time (possibly requires `-mi386pep` linker emulation setting) rather than `-fpie` at compile time, if you want to preserve relocations (rather than eliminate the need for them, which is what `-fpie` achieves).
"-fpie" causes GCC to emit position-independent code, which is not strictly the same thing as relocatable code (i.e. code with relocations). With "-fpie", loads are emitted as PC-relative, which means load-time relocations are generally not necessary (in the ELF world, it turns out that references to variables in shared libraries will use a special COPY relocation record, which literally copies the variable into the executable's own chosen location; a PLT is still used for calls to functions from shared libraries).Octocontrabass wrote:Mingw-w64 GCC ignores options like "-fpie"; it unconditionally generates relocatable code.
Regular GCC also unconditionally generates relocatable code - it's the link stage which strips the relocations. They can be kept, via "--emit-relocs"; most ELF loaders will probably just load a non-PIE ELF image at its nominal address, however, even if relocations are present.