The SHT_RELR/DT_RELR format encodes relative relocations in a very efficient way (quite usually takes just 3% or smaller space). The size optimization can greatly decrease the virtual memory size of PIE and shared objects with many R_*_RELATIVE relocations. The SHT_RELR/DT_RELR relocation format requires linker and loader support. * On the linkder side, ld.lld has supported .relr.dyn/SHT_RELR/DT_RELR (`--pack-dyn-relocs=relr`) for a long time and the support has been stable since 2019-09 (after I fixed an address oscillating bug). * On the loader (glibc ld.so) side, a patch exists https://sourceware.org/pipermail/libc-alpha/2021-October/131768.html but lack of GNU ld support may impede its adoption among Linux distributions. User support is also important to push the patch forward. (ia64 according to folks isn't an issue. glibc doesn't implement ELFCLASS32 for ia64 AFAICT.) (Worth noting that the Linux kernel's arm64 port supports this format since 2019.) So I file this ticket seeking for support (comment on https://sourceware.org/bugzilla/show_bug.cgi?id=27924). I hope that with sufficient attention from users, someone (e.g. a GNU ld maintainer) will eventually stand up and implement `--pack-dyn-relocs=relr` for GNU ld (https://sourceware.org/bugzilla/show_bug.cgi?id=27923). Reproducible: Always
What can be done on Gentoo side? Personally it would be nice to have it supported by ld.bfd in the future to be usable on Android 12 (https://github.com/termux/termux-packages/issues/7382).
(In reply to Tee KOBAYASHI from comment #1) > What can be done on Gentoo side? > > Personally it would be nice to have it supported by ld.bfd in the future to > be usable on Android 12 > (https://github.com/termux/termux-packages/issues/7382). Android and Chrome OS have been using ld.lld --pack-dyn-relocs=relr for quite some time. The feature I want to push forward is glibc's DT_RELR support. Distributions' support will be great... I'll also add a note that RELR is more efficient than Firefox's ELF hack and may render it unneeded (https://glandium.org/blog/?p=1177)
Status update: - Binutils 2.38 supports it - glibc 2.36 (not yet released) will support it. It's _possibly_ a candidate for 22.0 profiles as default.
(In reply to Sam James from comment #3) > Status update: > - Binutils 2.38 supports it > - glibc 2.36 (not yet released) will support it. > > It's _possibly_ a candidate for 22.0 profiles as default. This needs discussion since the feature is quite new. Then again, people will have some time to switch to the new profiles.
I guess for ld.bfd this would be -z pack-relative-relocs However, from the manpage: pack-relative-relocs nopack-relative-relocs Generate compact relative relocation in position-independent executable and shared library. It adds "DT_RELR", "DT_RELRSZ" and "DT_RELRENT" entries to the dynamic section. It is ignored when building position-dependent executable and relocatable output. nopack-relative-relocs is the default, which disables compact relative relocation. When linked against the GNU C Library, a GLIBC_ABI_DT_RELR symbol version dependency on the shared C Library is added to the output. Supported for i386 and x86-64.
This is in the 23.0 profiles in preparation but we need to drop it for non amd64 as it doesn't exist there yet. (IIRC one other arch supports it but I haven't tested it much on non-amd64)