public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: Florian Weimer <fweimer@redhat.com>, libc-alpha@sourceware.org
Cc: nd@arm.com
Subject: Re: [PATCH] Reduce the statically linked startup code [BZ #23323]
Date: Wed, 08 Aug 2018 15:56:00 -0000	[thread overview]
Message-ID: <4bf6f18d-790d-e56a-9604-39b354e34487@arm.com> (raw)
In-Reply-To: <edc80e57-356a-dc28-6195-f4508410c8ab@redhat.com>

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]
> To:libc-alpha@sourceware.org
> 
> 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 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.

  parent reply	other threads:[~2018-08-08 15:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-23 21:45 Florian Weimer
2018-07-01  9:30 ` Florian Weimer
2018-07-03 10:01 ` Florian Weimer
2018-08-08 14:48 ` Florian Weimer
2018-08-08 15:10   ` H.J. Lu
2018-08-08 15:17     ` Florian Weimer
2018-08-08 15:56   ` Szabolcs Nagy [this message]
2018-08-08 16:11     ` Florian Weimer
2021-02-18 13:12 Florian Weimer
2021-02-25 11:00 ` Siddhesh Poyarekar
2021-02-25 18:43 ` Mike Frysinger
2021-02-25 18:52   ` Florian Weimer
2021-02-28  6:02     ` Mike Frysinger
2021-03-01  9:43       ` Florian Weimer
2021-03-07 16:39         ` Mike Frysinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4bf6f18d-790d-e56a-9604-39b354e34487@arm.com \
    --to=szabolcs.nagy@arm.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nd@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).