FS#72433 - [toolchain] Adopt SHT_RELR/DT_RELR to decrease PIE and shared object size

Attached to Project: Arch Linux
Opened by Ray Song (MaskRay) - Friday, 15 October 2021, 22:04 GMT
Last edited by Toolybird (Toolybird) - Monday, 04 September 2023, 08:51 GMT
Task Type Feature Request
Category Packages: Core
Status Closed
Assigned To Giancarlo Razzolini (grazzolini)
freswa (frederik)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

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.

E.g. clang's virtual memory size is 8.2% smaller. The size varies across projects, but I anticipate at least 5% decrease for most projects.

% ~/projects/bloaty/Release/bloaty clang.pie.relr -- clang.pie
FILE SIZE VM SIZE
-------------- --------------
[NEW] +163Ki [NEW] +163Ki .relr.dyn
+4.9% +32 +5.4% +32 .dynamic
+2.5% +8 [ = ] 0 .shstrtab
-99.5% -13.8Mi -99.5% -13.8Mi .rela.dyn
-8.3% -13.6Mi -8.2% -13.6Mi TOTAL

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).

See also Gentoo: https://bugs.gentoo.org/818376 Fedora: https://bugzilla.redhat.com/show_bug.cgi?id=2014699
This task depends upon

Closed by  Toolybird (Toolybird)
Monday, 04 September 2023, 08:51 GMT
Reason for closing:  None
Additional comments about closing:  Closing in favor of RFC:

https://gitlab.archlinux.org/archlinux/r fcs/-/merge_requests/23
Comment by Toolybird (Toolybird) - Saturday, 02 September 2023, 01:22 GMT

Loading...