From patchwork Wed Dec 7 12:16:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Yago_Guti=C3=A9rrez?= X-Patchwork-Id: 61658 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6129A38B81C0 for ; Wed, 7 Dec 2022 12:17:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6129A38B81C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670415420; bh=W4J83CBaCzSSczad5mzXL7DODhm2YsSNfSr01vCMKSc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=SHS956mqx5vmMvNoFZbzfaIXlIBbssT3wWuyzVXPUDFWij4KOk0cNFJg/SesCgr92 KSDm9JxEigKM35uDGixJtSDYF/T8SL14E+DO2ATsi9muDGy1uFJTyv+rK2iBB3bwlU rVqd2oCHK+wpzOAt1+yeK4dbJ+FRxOZBtqOCNKFs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-4325.protonmail.ch (mail-4325.protonmail.ch [185.70.43.25]) by sourceware.org (Postfix) with ESMTPS id 8612838369CB for ; Wed, 7 Dec 2022 12:16:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8612838369CB Date: Wed, 07 Dec 2022 12:16:33 +0000 To: "libc-alpha@sourceware.org" Subject: [PATCH 0/1] __libc_start_main() now uses auxv to obtain phdr's address [BZ #29864] Message-ID: <73l3eC0YTCoWnmm2zGV-SIY9-W5DQ-peyx7secTao121qocwqub-R4Zhrpkai8_LRxy4xsn7ARdHRbI7NnzSysk6ACmQWfiavdpz-tA70xc=@protonmail.com> Feedback-ID: 34810787:user:proton MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Yago_Guti=C3=A9rrez_via_Libc-alpha?= From: =?utf-8?q?Yago_Guti=C3=A9rrez?= Reply-To: =?utf-8?q?Yago_Guti=C3=A9rrez?= Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Yago GutiƩrrez (1): __libc_start_main() now uses auxv to obtain phdr's address [BZ #29864] csu/libc-start.c | 34 +++++++++++++------------ sysdeps/generic/ldsodefs.h | 3 +++ sysdeps/unix/sysv/linux/dl-parse_auxv.h | 1 + 3 files changed, 22 insertions(+), 16 deletions(-) From bf2371ce732194f652719aff4af0f9021f9cbd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20Guti=C3=A9rrez?= Date: Wed, 7 Dec 2022 12:49:22 +0100 Subject: [PATCH 1/1] __libc_start_main() now uses auxv to obtain phdr's address [BZ #29864] To: libc-alpha@sourceware.org --- csu/libc-start.c | 34 +++++++++++++------------ sysdeps/generic/ldsodefs.h | 3 +++ sysdeps/unix/sysv/linux/dl-parse_auxv.h | 1 + 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/csu/libc-start.c b/csu/libc-start.c index 543560f36c..f6e0fbf60a 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -262,28 +262,30 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), } # endif _dl_aux_init (auxvec); - if (GL(dl_phdr) == NULL) # endif - { - /* Starting from binutils-2.23, the linker will define the - magic symbol __ehdr_start to point to our own ELF header - if it is visible in a segment that also includes the phdrs. - So we can set up _dl_phdr and _dl_phnum even without any - information from auxv. */ - extern const ElfW(Ehdr) __ehdr_start + /* Starting from binutils-2.23, the linker will define the + magic symbol __ehdr_start to point to our own ELF header + if it is visible in a segment that also includes the phdrs. + So we can set up _dl_phdr and _dl_phnum even without any + information from auxv. */ + extern const ElfW(Ehdr) __ehdr_start # if BUILD_PIE_DEFAULT - __attribute__ ((visibility ("hidden"))); + __attribute__ ((visibility ("hidden"))); # else - __attribute__ ((weak, visibility ("hidden"))); - if (&__ehdr_start != NULL) + __attribute__ ((weak, visibility ("hidden"))); + if (&__ehdr_start != NULL) +# endif + { +# ifdef HAVE_AUX_VECTOR + if (GL(dl_phdr) == NULL) # endif - { - assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr)); - GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff; - GL(dl_phnum) = __ehdr_start.e_phnum; - } + { + assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr)); + GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff; } + GL(dl_phnum) = __ehdr_start.e_phnum; + } __tunables_init (__environ); diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 9dae72b1ed..ccdb42837f 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -395,6 +395,9 @@ struct rtld_global /* Structure describing the dynamic linker itself. */ EXTERN struct link_map _dl_rtld_map; + + EXTERN const ElfW(Phdr)* _dl_phdr; + #ifdef SHARED /* Used to store the audit information for the link map of the dynamic loader. */ diff --git a/sysdeps/unix/sysv/linux/dl-parse_auxv.h b/sysdeps/unix/sysv/linux/dl-parse_auxv.h index bf9374371e..2cc666cbd6 100644 --- a/sysdeps/unix/sysv/linux/dl-parse_auxv.h +++ b/sysdeps/unix/sysv/linux/dl-parse_auxv.h @@ -52,6 +52,7 @@ void _dl_parse_auxv (ElfW(auxv_t) *av, dl_parse_auxv_t auxv_values) _dl_random = (void *) auxv_values[AT_RANDOM]; GLRO(dl_minsigstacksize) = auxv_values[AT_MINSIGSTKSZ]; GLRO(dl_sysinfo_dso) = (void *) auxv_values[AT_SYSINFO_EHDR]; + GL(dl_phdr) = (void*) auxv_values[AT_PHDR]; #ifdef NEED_DL_SYSINFO if (GLRO(dl_sysinfo_dso) != NULL) GLRO(dl_sysinfo) = auxv_values[AT_SYSINFO]; -- 2.38.1