Use RELR relative relocations to reduce file sizes (-z pack-relative-relocs)
#134
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In binutils 2.38 and the recently released glibc 2.36, support has been added for the
DT_RELRrelative relocation format. This format can significantly reduce the size of shared libraries and position-independent executables. Measurements show a 5% decrease in size for libraries, and 8% for executables in total.One particular measurement, taken from MaskRay's Arch feature request (https://bugs.archlinux.org/task/72433):
This great blog post explains the technical details: https://maskray.me/blog/2021-10-31-relative-relocations-and-relr. It highlights that RELR been used (with patched binutils+libc) in ChromeOS/Android for a long time without any issues. User applications don't need to adapt to the new format.
To enable RELR, the
-z pack-relative-relocsflag must be passed to GNU ld. With LLD/mold, the--pack-dyn-relocs=relrspelling should be used instead.Sounds interesting. As far as I understand, ALHP would need to detect the compiler/linker used, so that the correct flags are added? If so, this is probably blocked by #124.
LLD will get support for the GNU argument name in 15.0.0, whose is planned to be released on September 6th. If I remember correctly,
molddoes not support that spelling as of now; we could open a feature request. The only package that lists mold as its build dependency iscardinal. The only remaining linker is GNU gold, but I hope there aren't any projects depending on it in 2022...Sidenote: it's a bit infuriating that the binutils maintainers decided to go with a custom spelling instead of the one established by the original implementation in LLD.
Do you have any examples of packages that override the default linker?
Gold is most likely not worth talking about, no. So, best case scenario would be to wait until that new LLD release, then add
-z pack-relative-relocs, since this should be supported by LLD and ld by then.I quickly grep'd the PKGBUILD tree, and besides already mentioned
cardinal, there appear to be none.cardinal, using mold, will most likely fail after adding that above mentioned flag, but adding one more package to the ignore list would not be that detrimental. Maybe we can, as you said, convince the mold devs to also accept the GNU flag.@BertalanD How is the status here? Are we still waiting for upstream? I see some of the versions you mentioned are already released now.
It looks like we should be good to go.
-z pack-relative-relocsas of 1.7.0Very nice. If I understood correctly
-z,pack-relative-relocshas to be added toLDFLAGS?It also needs the
-Wl,prefix if the flag is separated by a space from the other linker flags.I'll try to add it without space, but I think I need to adjust the flag parsing logic for
LDFLAGS, because of the different separation.I made the necessary changes. Should be active from now on 👍