1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00
serenity/Userland/Libraries/LibELF
Daniel Bertalan 3974cac148 LibELF: Implement support for DT_RELR relative relocations
The DT_RELR relocation is a relatively new relocation encoding designed
to achieve space-efficient relative relocations in PIE programs.

The description of the format is available here:
https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/Pi9aSwwABgAJ

It works by using a bitmap to store the offsets which need to be
relocated. Even entries are *address* entries: they contain an address
(relative to the base of the executable) which needs to be relocated.
Subsequent even entries are *bitmap* entries: "1" bits encode offsets
(in word size increments) relative to the last address entry which need
to be relocated.

This is in contrast to the REL/RELA format, where each entry takes up
2/3 machine words. Certain kinds of relocations store useful data in
that space (like the name of the referenced symbol), so not everything
can be encoded in this format. But as position-independent executables
and shared libraries tend to have a lot of relative relocations, a
specialized encoding for them absolutely makes sense.

The authors of the format suggest an overall 5-20% reduction in the file
size of various programs. Due to our extensive use of dynamic linking
and us not stripping debug info, relative relocations don't make up such
a large portion of the binary's size, so the measurements will tend to
skew to the lower side of the spectrum.

The following measurements were made with the x86-64 Clang toolchain:

- The kernel contains 290989 relocations. Enabling RELR decreased its
  size from 30 MiB to 23 MiB.
- LibUnicodeData contains 190262 relocations, almost all of them
  relative. Its file size changed from 17 MiB to 13 MiB.
- /bin/WebContent contains 1300 relocations, 66% of which are relative
  relocations. With RELR, its size changed from 832 KiB to 812 KiB.

This change was inspired by the following blog post:
https://maskray.me/blog/2021-10-31-relative-relocations-and-relr
2022-02-11 18:07:53 +01:00
..
Arch LibELF: Store SSE registers in x86_64 PLT Trampoline 2021-10-31 00:21:31 +02:00
AuxiliaryVector.h LibC+LibELF: Move getauxval and AT_* flags to sys/auxv.h 2021-10-28 11:24:36 +02:00
CMakeLists.txt LibELF+LibTest: Fix serenity_install_sources() paths 2021-03-15 09:06:10 +01:00
Core.h Kernel: Use Process::require_promise() instead of REQUIRE_PROMISE() 2021-12-29 18:08:15 +01:00
DynamicLinker.cpp Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr 2022-01-24 22:36:09 +01:00
DynamicLinker.h Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
DynamicLoader.cpp LibELF: Implement support for DT_RELR relative relocations 2022-02-11 18:07:53 +01:00
DynamicLoader.h LibELF: Implement support for DT_RELR relative relocations 2022-02-11 18:07:53 +01:00
DynamicObject.cpp LibELF: Implement support for DT_RELR relative relocations 2022-02-11 18:07:53 +01:00
DynamicObject.h LibELF: Implement support for DT_RELR relative relocations 2022-02-11 18:07:53 +01:00
Hashes.h Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Image.cpp LibELF: Accept Span instead of Pointer+Size in validate_program_headers 2022-01-13 22:40:25 +01:00
Image.h Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Relocation.cpp LibELF: Implement support for DT_RELR relative relocations 2022-02-11 18:07:53 +01:00
Relocation.h Userland: Remove a bunch of unnecessary Vector imports 2022-01-28 23:40:25 +01:00
Validation.cpp LibELF: Accept Span instead of Pointer+Size in validate_program_headers 2022-01-13 22:40:25 +01:00
Validation.h LibELF: Accept Span instead of Pointer+Size in validate_program_headers 2022-01-13 22:40:25 +01:00