From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 63181 invoked by alias); 8 Aug 2018 15:56:56 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 63164 invoked by uid 89); 8 Aug 2018 15:56:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=BAYES_00,GARBLED_BODY,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VQ2Zb7A1OgDtqipXxByjabP0REfwELatdZLYaN7UvuA=; b=YXxWLLo6brBc55YWBYzKttk5l8kEp8jvl7s5J9a3agb4WI9EaCkBCj6rJvnNZm3NEIc6NOP3c17qauDc2+RvqPZD6w0pCV3wKvGItLHGaZ6IFEiG1IvO5yup/8N9CHpkVQ9GJ6JHlQweNIMrzxvsmjr5KcMa3ad/F+4afXIN6qc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; Cc: nd@arm.com Subject: Re: [PATCH] Reduce the statically linked startup code [BZ #23323] To: Florian Weimer , libc-alpha@sourceware.org References: <20180623214525.CB496402DFEF9@oldenburg.str.redhat.com> From: Szabolcs Nagy Message-ID: <4bf6f18d-790d-e56a-9604-39b354e34487@arm.com> Date: Wed, 08 Aug 2018 15:56:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Return-Path: szabolcs.nagy@arm.com Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-SW-Source: 2018-08/txt/msg00165.txt.bz2 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 > > [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 . > (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.