I’m looking into some research regarding relocations and I was wondering if anyone had insights if I could make clang force-emit text relocations for symbols in PIE/PIC code rather than either a PLT/GOT or GOT (-fno-plt). I’m happy to restrict myself to a single target if it exists there and emulate via qemu.
On my x86 system, for PIC code, we have to use the GOT since our memory model is such that code lives in 64-bit address space but our static data lives in 32-bit address space. You either need the GOT to reach that far (or use the extreme large-model on x86).
I’m also looking into R_X86_64_64 relocations which I think are produced for non-PIE.
They seem analogous to as if we had done the text relocations rather than GOT/PLT?
Whether text relocations are needed is decided by both compiler code generation (-fPIC/-fno-pic, -fdirect-access-external-data are relevant) and linker behavior (-no-pie/-pie/-shared are relevant).
However, linkers largely only emit text relocations for very few scenarios on ELF platforms.
Copy relocations and canonical PLT entries are used for many scenarios.
Grepping -z notext in lld/text/ELF may yield some results.
I don’t think we would introduce new mode to upstream linkers to allow more text relocations.
From Linker notes on PE/COFF | MaskRay
MinGW implements runtime pseudo relocations to patch the text section so that absolute pointers and relative offsets to the symbol will be rewritten to bind to the actual definition.
movq var(%rip), %rax # the runtime will rewrite this to point to the definition in b.dll