ROP gadgets (see Marco-Gisbert and Ripoll-Ripoll, “return-to-csu: A
New Method to Bypass 64-bit Linux ASLRâ€). These functions are not
needed in dynamically-linked binaries because DT_INIT/DT_INIT_ARRAY
are already processed by the dynamic linker. However, the dynamic
linker skipped the main program for some reason. For maximum
backwards compatibility, this is not changed, and instead, the main
map is consulted from __libc_start_main if the init function argument
is a NULL pointer.
For statically linked binaries, the old approach based on linker
symbols is still used because there is nothing else available.
A new symbol version __libc_start_main@@GLIBC_2.29 is introduced because
new binaries running on an old libc would not run their ELF
constructors, leading to difficult-to-debug issues. This approach
(multiple symbol versions for the same function symbol) requires a
recent binutils version (later than 2.25 on some architectures) because
earlier versions cannot use a symbol alias to define multiple symbol
versions for the same symbol.
Tested on aarch64, armhfp, i686, mips64, ppc, ppc64, ppc64el, s390,
s390x, x86_64, and built with build-many-glibcs.py. This patch
depends on the earlier patch which introduces ELF_INITFINI.
2018-06-23 Florian Weimer<fweimer@redhat.com>
[BZ #23323]
Reduce statically-linked startup code.
* csu/Makefile (routines): Remove elf-init.
* csu/elf-init.c: Remove file.
* csu/Versions (GLIBC_2.29): Export __libc_start_main from libc.
* csu/libc-start.c: Add note that this is not part of the startup
code for dynamically linked applications.
[SHARED] (call_init): New function, based on call_init from
elf/dl-init.c.
[!SHARED] (call_init, call_fini): New functions, based on
csu/elf-init.c
(LIBC_START_MAIN): Update function comment. Register call_fini
directly for statically linked applications. Call call_init
instead of init (in statically linked applications, and if it is
not NULL).
(DO_DEFINE_LIBC_START_MAIN_VERSION)
(DEFINE_LIBC_START_MAIN_VERSION_1)
(DEFINE_LIBC_START_MAIN_VERSION): Define.
* elf/dl-init.c (init_t): Move to <ldsodefs.h>.
(call_init, _dl_init) Adjust.
* sysdeps/generic/ldsodefs.h (dl_init_t): Moved from
elf/dl-init.c.
(DL_CALL_DT_INIT): Adjust.
* sysdeps/hppa/dl-lookupcfg.h (DL_CALL_DT_INIT): Likewise.
* sysdeps/ia64/dl-lookupcfg.h (DL_CALL_DT_INIT): Likewise.
* sysdeps/aarch64/start.S (_start): Pass zero for init and fini.
* sysdeps/alpha/start.S (_start): Likewise.
* sysdeps/arm/start.S (_start): Likewise. Adjust offset of
pointer to main.
(.L_GOT): Adjust.
* sysdeps/hppa/start.S (.Lp__libc_csu_fini, .Lp__libc_csu_init):
Remove.
(_start): Pass zero for init and fini.
* sysdeps/ia64/start.S (_start): Pass zero for init and fini.
* sysdeps/i386/start.S (_start): Likewise.
* sysdeps/m68k/start.S (_start): Likewise.
* sysdeps/microblaze/start.S (_start): Likewise.
* sysdeps/mips/start.S (ENTRY_POINT): Likewise.
* sysdeps/nios2/start.S (_start): Likewise.
* sydeps/powerpc/powerpc32/start.S (start_addresses): Use zero for
init and fini.
* sysdeps/powerpc/powerpc64/start.S (start_addresses): Likewise.
* sysdeps/unix/sysv/linux/powerpc/libc-start: Use
DEFINE_LIBC_START_MAIN_VERSION.
* sysdeps/riscv/start.S (ENTRY_POINT): Pass zero for init and fini.
* sysdeps/s390/s390-32/start.S (_start): Pass zero for init and
fini.
(.L1, .L2): Remove.
* sysdeps/s390/s390-64/start.S (_start): Pass zero for init and
fini.
* sysdeps/s390/s390-64/start.S (_start): Pass zero for init and
fini.
* sysdeps/sh/start.S (_start): Likewise.
(L_init, L_fini): Remove.
* sysdeps/sparc/sparc32/start.S (_start): Pass zero for init and
fini.
* sysdeps/sparc/sparc64/start.S (_start): Likewise.
* sysdeps/x86_64/start.S (start): Likewise.
* sysdeps/mach/hurd/i386/libc.abilist: Add
__libc_start_main@GLIBC_2.29.
* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist:
Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
Likewise.
* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.