]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Reduce size of rtld by 22% by pulling in less code from libc
authorarichardson <arichardson@FreeBSD.org>
Sun, 30 Jun 2019 11:49:58 +0000 (11:49 +0000)
committerarichardson <arichardson@FreeBSD.org>
Sun, 30 Jun 2019 11:49:58 +0000 (11:49 +0000)
commit8ea98b7069aa4bb0636456be451301149706eeea
treec88a1ee4e11ddbe5fd350a40026c3ad0e0f61935
parenta33a56c7b548f3c176d0f213dd8dd69ee64233f0
Reduce size of rtld by 22% by pulling in less code from libc

Currently RTLD is linked against libc_nossp_pic which means that any libc
symbol used in rtld can pull in a lot of depedencies. This was causing
symbol such as __libc_interposing and all the pthread stubs to be included
in RTLD even though they are not required. It turns out most of these
dependencies can easily be avoided by providing overrides inside of rtld.

This change is motivated by CHERI, where we have an experimental ABI that
requires additional relocation processing to allow the use of function
pointers inside of rtld. Instead of adding this self-relocation code to
RTLD I attempted to remove most function pointers from RTLD and discovered
that most of them came from the libc dependencies instead of being actually
used inside rtld.

A nice side-effect of this change is that rtld is now 22% smaller on amd64.

   text    data     bss     dec     hex filename
0x21eb6   0xce0   0xe60  145910   239f6 /home/alr48/ld-elf-x86.before.so.1
0x1a6ed   0x728   0xdd8  113645   1bbed /home/alr48/ld-elf-x86.after.so.1

The number of R_X86_64_RELATIVE relocations that need to be processed on
startup has also gone down from 368 to 187 (almost 50% less).

Reviewed By: kib
Differential Revision: https://reviews.freebsd.org/D20663
13 files changed:
lib/libc/gen/gen-private.h
libexec/rtld-elf/Makefile
libexec/rtld-elf/libmap.c
libexec/rtld-elf/rtld-libc/Makefile.inc [new file with mode: 0644]
libexec/rtld-elf/rtld-libc/libc_private.h [new file with mode: 0644]
libexec/rtld-elf/rtld-libc/namespace.h [new file with mode: 0644]
libexec/rtld-elf/rtld-libc/rtld_libc.c [new file with mode: 0644]
libexec/rtld-elf/rtld-libc/rtld_libc.h [new file with mode: 0644]
libexec/rtld-elf/rtld-libc/un-namespace.h [new file with mode: 0644]
libexec/rtld-elf/rtld.c
libexec/rtld-elf/rtld_lock.c
libexec/rtld-elf/rtld_printf.c
libexec/rtld-elf/xmalloc.c