From patchwork Mon Feb 24 11:09:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 38284 Received: (qmail 117694 invoked by alias); 24 Feb 2020 11:10:01 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 117685 invoked by uid 89); 24 Feb 2020 11:10:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=dsos, DSOs X-HELO: us-smtp-delivery-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582542598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J8k8cX43BcHt1vvPqUmEoK+8yVbGQ/6iGWCUChUdJEM=; b=Kc673izBVFCnmhBdqYDeRVbz5NS9NIZDv4pBxiF3yf8FI7DFCu6NOTJWZEhjEy9Y12O/hV FejUNv/tiBaFW3s/1hJTYqVMORITNP3lr/faCRrq2uKCNsGfCE6P6rg+jFeRS61pFw7fdt 5DyYD3COG1VVZ8ESm7+JmQGHXKDrDhc= From: Florian Weimer To: libc-alpha@sourceware.org Cc: DJ Delorie , Jim Wilson , Andreas Schwab Subject: [PATCH] csu: Use ELF constructor instead of _init in libc.so Date: Mon, 24 Feb 2020 12:09:47 +0100 Message-ID: <87v9nwqm10.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Tested on aarch64-linux-gnu, i386-linux-gnu, powerpc64le-linux-gnu, x86_64-linux-gnu. Also built on i686-gnu, riscv64-linux-gnu-rv64imac-lp64, and s390x-linux-gnu. Would someone with access to RISC-V hardware please test this patch? Thanks. Florian 8<------------------------------------------------------------------8< On !ELF_INITFINI architectures, _init is no longer called by the dynamic linker. We can use an ELF constructor instead because the constructor order does not matter. (The other constructors are used to set up libio vtable bypasses and do not depend on this initialization routine.) ----- csu/init-first.c | 12 ++++++------ elf/soinit.c | 2 +- include/libc-internal.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/csu/init-first.c b/csu/init-first.c index 1cd8a75098..264e6f348d 100644 --- a/csu/init-first.c +++ b/csu/init-first.c @@ -43,12 +43,11 @@ void __libc_init_first (int argc, char **argv, char **envp) { #ifdef SHARED - /* For DSOs we do not need __libc_init_first but instead _init. */ + /* For DSOs we do not need __libc_init_first but an ELF constructor. */ } -void -attribute_hidden -_init (int argc, char **argv, char **envp) +static void __attribute__ ((constructor)) +_init_first (int argc, char **argv, char **envp) { #endif @@ -86,8 +85,9 @@ _init (int argc, char **argv, char **envp) /* This function is defined here so that if this file ever gets into ld.so we will get a link error. Having this file silently included - in ld.so causes disaster, because the _init definition above will - cause ld.so to gain an init function, which is not a cool thing. */ + in ld.so causes disaster, because the _init_first definition above + will cause ld.so to gain an ELF constructor, which is not a cool + thing. */ extern void _dl_start (void) __attribute__ ((noreturn)); diff --git a/elf/soinit.c b/elf/soinit.c index fe9935732b..538eb68186 100644 --- a/elf/soinit.c +++ b/elf/soinit.c @@ -20,7 +20,7 @@ run_hooks (void (*const list[]) (void)) (**list) (); } -/* This function will be called from _init in init-first.c. */ +/* This function will be called from _init_first in init-first.c. */ void __libc_global_ctors (void) { diff --git a/include/libc-internal.h b/include/libc-internal.h index fcd21468c0..4c74f6ba60 100644 --- a/include/libc-internal.h +++ b/include/libc-internal.h @@ -24,7 +24,7 @@ /* Initialize the `__libc_enable_secure' flag. */ extern void __libc_init_secure (void); -/* This function will be called from _init in init-first.c. */ +/* This function will be called from _init_first in init-first.c. */ extern void __libc_global_ctors (void); /* Discover the tick frequency of the machine if something goes wrong,