Open tf2spi opened 1 year ago
RELR support was added in https://github.com/ziglang/zig/pull/20893. Still need to add a frontend flag to actually emit these relocations.
I am not personally convinced that APS2 is worth the effort. It just seems like a worse RELR?
Linkers like LLVM's lld and GNU's ld support emitting packed relocations at link-time
For ld, it supports emitting RELR relocations, and for lld, it supports emitting both RELR relocations and Android's APS2 relocations by using the following flags.
Zig currently does not support either of these relocations for when compiling static PIE binaries.
Google Chromium's docs on Native Relocations and the MaskRay Blog Post give basic statistics on the space savings gained using these relocations. It's hard to find much more in-depth statistics on them.
RELR Example
It's easiest to see Zig segfaulting on unimplemented RELRs when mixing C code and Zig code.
Compile with these commands on amd64
Proposal
If any new relocation types are added to std.os.linux.start_pie.relocate, it'd be best to add RELR relocations before adding the android-specific relocations like APS2. Not only is the former not operating-system specific, it's shown to be more effective at compressing relative relocations on average while being simpler to implement.
If RELR is added, adding the appropriate linker flags to emit RELR relocation would make integrating this into current zig projects much easier as well.