This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Reduce the statically linked startup code [BZ #23323]

On 08/08/18 15:48, Florian Weimer wrote:
This is the patch rebased for glibc 2.29.

Should we make more far-reaching changes and remove the arguments which are now zero?

there might be code that calls __libc_start_main directly
(e.g. the cgo runtime ?), if removing args breaks something
then i'd keep them (i don't know if it does).

the aarch64 changes look good.

Subject: [PATCH] Reduce the statically linked startup code [BZ #23323]

It turns out the startup code in csu/elf-unit.c has a perfect pair of

i think you mean csu/elf-init.c

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  This patch
depends on the earlier patch which introduces ELF_INITFINI.

2018-06-23  Florian Weimer<>

	[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
	[!SHARED] (call_init, call_fini): New functions, based on
	(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).
	* elf/dl-init.c (init_t): Move to <ldsodefs.h>.
	(call_init, _dl_init) Adjust.
	* sysdeps/generic/ldsodefs.h (dl_init_t): Moved from
	(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):
	(_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
	* sysdeps/riscv/start.S (ENTRY_POINT): Pass zero for init and fini.
	* sysdeps/s390/s390-32/start.S (_start): Pass zero for init and
	(.L1, .L2): Remove.
	* sysdeps/s390/s390-64/start.S (_start): Pass zero for init and
	* sysdeps/s390/s390-64/start.S (_start): Pass zero for init and
	* sysdeps/sh/start.S (_start): Likewise.
	(L_init, L_fini): Remove.
	* sysdeps/sparc/sparc32/start.S (_start): Pass zero for init and
	* sysdeps/sparc/sparc64/start.S (_start): Likewise.
	* sysdeps/x86_64/start.S (start): Likewise.
	* sysdeps/mach/hurd/i386/libc.abilist: Add
	* 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:
	* 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:
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist:
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist:
	* 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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]