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)
(In reply to Sam James from comment #6) > 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) Depending on how long the 23.0 stuff takes us some other arches might catch up. :o)
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=57250bdaec26224add7447e8d439d75960645737 commit 57250bdaec26224add7447e8d439d75960645737 Author: Andreas K. Hüttel <dilfridge@gentoo.org> AuthorDate: 2023-11-25 23:12:22 +0000 Commit: Andreas K. Hüttel <dilfridge@gentoo.org> CommitDate: 2023-11-25 23:13:25 +0000 profiles, 23.0: drop global DT_RELR and enable it only on x86 and Power Bug: https://bugs.gentoo.org/show_bug.cgi?id=818376 Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org> profiles/default/linux/amd64/23.0/make.defaults | 4 ++++ profiles/default/linux/ppc/23.0/make.defaults | 4 ++++ profiles/default/linux/ppc64/23.0/make.defaults | 4 ++++ profiles/default/linux/x86/23.0/make.defaults | 4 ++++ profiles/releases/23.0/make.defaults | 4 ++-- 5 files changed, 18 insertions(+), 2 deletions(-)
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fac51cc9370713f6b2764e8e03ee2ff8d652c3af commit fac51cc9370713f6b2764e8e03ee2ff8d652c3af Author: Sam James <sam@gentoo.org> AuthorDate: 2024-03-25 18:46:04 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2024-03-25 18:48:58 +0000 profiles/default/linux/ppc/23.0: drop DT_RELR bfd doesn't support DT_RELR on ppc32. Bug: https://bugs.gentoo.org/818376 Signed-off-by: Sam James <sam@gentoo.org> profiles/default/linux/ppc/23.0/make.defaults | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
This is fixed in the 23.0 profiles (available and stable now). Closing. (Well, at least for amd64 where the relocation exists. More arches will follow.)
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=73a0dd3bbee2dd5280d0c7aaa82fe71176b1b0e0 commit 73a0dd3bbee2dd5280d0c7aaa82fe71176b1b0e0 Author: Sam James <sam@gentoo.org> AuthorDate: 2025-05-02 05:47:13 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2025-05-07 08:59:01 +0000 profiles/default/linux/loong/23.0: enable DT_RELR binutils supports this since d89ecf33ab6dd86290b43dc3751d66f263614e68 which is in >=2.43. The intention was always to enable this for all supported arches, we just had to drop it temporarily in some places (see 57250bdaec26224add7447e8d439d75960645737 and fac51cc9370713f6b2764e8e03ee2ff8d652c3af). Bug: https://bugs.gentoo.org/818376 Acked-by: WANG Xuerui <xen0n@gentoo.org> Signed-off-by: Sam James <sam@gentoo.org> Part-of: https://github.com/gentoo/gentoo/pull/41893 Closes: https://github.com/gentoo/gentoo/pull/41893 Signed-off-by: Sam James <sam@gentoo.org> profiles/default/linux/loong/23.0/make.defaults | 1 + 1 file changed, 1 insertion(+) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6bf6168b21255e068510f4982b228a28ca2df7a8 commit 6bf6168b21255e068510f4982b228a28ca2df7a8 Author: Sam James <sam@gentoo.org> AuthorDate: 2025-05-02 05:46:00 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2025-05-07 08:59:01 +0000 profiles/default/linux/arm64/23.0: enable DT_RELR binutils supports this since a71d87680110d854f966d8cda0f1c7887001fcdd which is in >=2.43. The intention was always to enable this for all supported arches, we just had to drop it temporarily in some places (see 57250bdaec26224add7447e8d439d75960645737 and fac51cc9370713f6b2764e8e03ee2ff8d652c3af). Bug: https://bugs.gentoo.org/818376 Signed-off-by: Sam James <sam@gentoo.org> Part-of: https://github.com/gentoo/gentoo/pull/41893 Signed-off-by: Sam James <sam@gentoo.org> profiles/default/linux/arm64/23.0/make.defaults | 1 + 1 file changed, 1 insertion(+)