1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00
serenity/Userland/Libraries/LibC
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 LibC: Implement _setjmp and _longjmp 2021-12-24 05:26:21 -08:00
arpa LibC: Make <netinet/in.h> more POSIX compliant 2021-08-22 10:29:06 +02:00
bits LibC: Implement fflush(nullptr) 2022-01-16 14:59:21 -08:00
net LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
netinet LibC: Add IN6_IS_ADDR_LINKLOCAL to in.h 2022-02-03 14:57:16 +01:00
sys Kernel: Add ioctl to get the EDID from a framebuffer 2022-01-23 22:45:21 +00:00
alloca.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
assert.cpp LibC: Move _abort next to abort 2021-12-18 21:01:10 -08:00
assert.h LibC: Allow multiple includes of <assert.h> 2021-12-23 17:53:46 -08:00
byteswap.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
CMakeLists.txt DynamicLoader+LibC+LibTimeZone: Include LibTimeZone sources in LibC 2022-01-23 12:48:26 +00:00
crt0.cpp LibCore+LibC: Enforce the global event loop ban in code 2022-01-23 15:21:10 +01:00
crt0_shared.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ctype.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ctype.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
cxxabi.cpp LibC: Avoid unnecessary mprotect during program finalization 2021-11-11 09:20:35 +01:00
dirent.cpp LibC: Fix scandir not checking for allocation failure 2022-01-16 11:18:04 +01:00
dirent.h LibC: Add alphasort() implementation 2021-12-28 11:00:51 +01:00
dlfcn.cpp LibC+LibELF: Implement dladdr() 2021-06-06 22:16:11 +02:00
elf.h LibELF: Implement support for DT_RELR relative relocations 2022-02-11 18:07:53 +01:00
endian.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
errno.h Kernel+LibC: Move errno definitions to Kernel/API/POSIX 2021-12-16 22:21:35 +03:30
errno_codes.h Kernel: Remove EWHYTHO error code :^) 2022-01-08 20:10:58 +01:00
fcntl.cpp Kernel+LibC: Pack SC_inode_watcher_add_watch_params struct better 2021-09-16 17:17:13 +02:00
fcntl.h Kernel+LibC: Share definitions in fcntl.h and sys/types.h 2021-08-14 19:58:11 +02:00
fd_set.h LibC: Modify fd_set to be compatible with X/OPEN 2021-08-22 10:29:06 +02:00
fenv.cpp Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
fenv.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
float.h LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
fnmatch.cpp Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
fnmatch.h Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
getopt.cpp Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
getopt.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
grp.cpp Kernel+LibC: Move errno definitions to Kernel/API/POSIX 2021-12-16 22:21:35 +03:30
grp.h LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
iconv.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ifaddrs.cpp Kernel+LibC: Stub out getifaddrs() and freeifaddrs() 2021-12-22 00:02:36 -08:00
ifaddrs.h Kernel+LibC: Stub out getifaddrs() and freeifaddrs() 2021-12-22 00:02:36 -08:00
inttypes.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
inttypes.h LibC: Add definition for PRIxMAX 2022-01-13 18:46:22 +01:00
ioctl.cpp LibC: Don't truncate arguments for ioctl() on x86_64 2021-07-22 04:18:39 +04:30
langinfo.cpp Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
langinfo.h Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
libcinit.cpp LibCore+LibC: Enforce the global event loop ban in code 2022-01-23 15:21:10 +01:00
libgen.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
libgen.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
limits.h LibC: Define the POSIX TZNAME_MAX limit 2022-01-25 18:39:36 +00:00
link.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
link.h Userland: Prefer using ARCH() over __LP64__ 2021-07-13 23:19:33 +02:00
locale.cpp LibC: Let setlocale() pretend that setting the locale succeeded 2021-06-05 10:56:37 +02:00
locale.h LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
malloc.cpp LibC: Make *alloc return NULL in case of failure (POSIX) 2022-01-16 11:18:04 +01:00
mallocdefs.h AK+LibC+LibPthread: Introduce NoAllocationGuard 2022-01-11 00:08:58 +01:00
memory.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
mntent.cpp LibC: Remove TODO() macros to not break mc port 2022-01-13 18:46:22 +01:00
mntent.h LibC: Add mntent stub functions 2022-01-07 18:38:32 +01:00
net.cpp LibC: Add in6addr_loopback and IN6ADDR_LOOPBACK_INIT constant 2021-12-28 11:00:51 +01:00
netdb.cpp LibC: Remove debug spam in getaddrinfo() 2022-02-09 19:36:15 +01:00
netdb.h LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
nl_types.h Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
paths.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
poll.cpp LibC: Add POSIX spec comments for poll 2021-12-21 18:16:48 -08:00
poll.h Kernel+LibC: Share definitions for poll.h 2021-08-14 19:58:11 +02:00
priority.cpp LibC: Add getpriority() and setpriority() stubs 2021-09-23 18:51:21 +02:00
pthread_forward.cpp LibC+AK: Remove our custom macros from <assert.h> 2021-06-08 17:29:57 +02:00
pthread_integration.cpp LibC: Only set owner on recursive mutexes 2021-07-06 17:25:34 +02:00
pthread_tls.cpp Toolchain+Userland: Enable TLS for x86_64 2021-07-04 01:07:28 +02:00
pty.cpp LibC: Remove debug spam from openpty() 2021-10-26 08:47:06 +02:00
pty.h LibC: Remove 'int* aslave' parameter from forkpty() 2021-05-06 13:52:46 +01:00
pwd.cpp LibC: Do not include errno.h inside unistd.h 2021-05-14 22:24:02 +02:00
pwd.h LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
qsort.cpp LibC: Add POSIX spec comments for qsort 2021-12-21 18:16:48 -08:00
regex.cpp LibC: Add stub forwarders to LibRegex C API 2021-08-12 18:56:30 +02:00
regex.h LibRegex+LibJS: Avoid searching for more than one match in JS RegExps 2022-02-05 00:09:32 +01:00
resolv.cpp Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
resolv.h Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
scanf.cpp AK: Standardize the behaviour of GenericLexer::consume_until overloads 2022-01-25 13:41:09 +03:30
sched.cpp LibC: Add POSIX spec comments for sched APIs 2021-12-21 18:16:48 -08:00
sched.h LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
search.cpp LibC: Remove TODO() macros to not break mc port 2022-01-13 18:46:22 +01:00
search.h LibC: Add missing header in search.h 2021-10-20 09:20:18 +01:00
serenity.cpp LibC: Implement serenity_open 2021-12-16 22:21:35 +03:30
serenity.h LibC: Use NULL instead of nullptr in serenity.h 2022-01-04 19:08:07 +02:00
setjmp.h LibC: Implement _setjmp and _longjmp 2021-12-24 05:26:21 -08:00
shadow.cpp LibC: Allow empty spwd members when writing shadow entries via putspent 2021-05-30 17:42:03 +01:00
shadow.h LibC: Remove #ifdef AK_OS_MACOS checks from shadow.h 2022-01-08 19:22:00 +01:00
signal.cpp LibC: Add POSIX spec comments for signal APIs 2021-12-21 18:16:48 -08:00
signal.h LibC: Implement sigwait() 2021-12-12 08:34:19 +02:00
signal_numbers.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
spawn.cpp Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
spawn.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ssp.cpp Everywhere: Make some symbols __attribute__((used)) for LTO 2021-10-17 17:09:58 +01:00
stat.cpp Kernel+LibC+LibCore+UE: Implement fchmodat(2) 2022-01-12 14:54:12 +01:00
stdarg.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
stddef.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
stdint.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
stdio.cpp LibC+Kernel: Remove global variable use from snprintf and fprintf 2022-02-09 06:22:33 +00:00
stdio.h LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
stdio_ext.h Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
stdlib.cpp LibC: Flush all file streams on exit 2022-01-16 14:59:21 -08:00
stdlib.h LibC: Make the address argument of malloc_size a pointer to const 2022-01-12 14:54:12 +01:00
string.cpp LibC: Implement strsep() 2022-01-10 23:47:30 +01:00
string.h LibC: Implement strsep() 2022-01-10 23:47:30 +01:00
strings.cpp LibC: Add POSIX spec comments for string APIs 2021-12-21 18:16:48 -08:00
strings.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
stubs.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
sysexits.h LibC: Use EX_IOERR instead of EX_IOER 2021-06-10 20:21:08 +01:00
syslog.cpp LibC: Convert StringBuilder::appendf() => AK::Format 2021-05-07 21:12:09 +02:00
syslog.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
termcap.cpp LibC: Mark termcap symbols as weak 2021-10-15 14:47:41 -07:00
termcap.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
termios.cpp LibC: Stub out tcsendbreak(..) and tcdrain(..) 2021-12-29 03:17:41 -08:00
termios.h LibC: Stub out tcsendbreak(..) and tcdrain(..) 2021-12-29 03:17:41 -08:00
time.cpp LibTimeZone+Userland: Rename current_time_zone to system_time_zone 2022-01-25 18:39:36 +00:00
time.h LibC+LibDl: Declare functions taking no arguments as taking void 2022-01-08 19:22:00 +01:00
times.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
ulimit.cpp LibC: Add stubs for getrlimit()/setrlimit() 2021-05-08 19:14:21 +02:00
ulimit.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
unistd.cpp LibC: Add POSIX spec link for unistd mknod() API 2022-01-24 14:01:58 +03:30
unistd.h LibC: Add daemon(3) implementation to match behavior of Linux and BSDs 2022-01-11 11:47:48 +01:00
utime.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
utime.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
utmp.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
utsname.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
wchar.cpp LibC: Add POSIX spec links to all applicable wide character functions 2021-12-21 21:24:36 +03:30
wchar.h LibC: Make WEOF a signed value on clang 2021-12-21 21:24:36 +03:30
wctype.cpp Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
wctype.h Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
wstdio.cpp LibC: Add POSIX spec links to all applicable wide character functions 2021-12-21 21:24:36 +03:30