From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id CFB7F385735C for ; Thu, 15 Sep 2022 06:04:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CFB7F385735C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=aurel32.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Content-Type:From:Reply-To:Subject:Content-ID: Content-Description:In-Reply-To:References:X-Debbugs-Cc; bh=uf6Vba1y4HhMXxjdfrHAK41meNdfz5jOZlSiejgFqUw=; b=pJlyV75ILRdQZ3Zn7heq25nOlv V8NVPVntgOyzIAy9eQvgKIwPo+CGZXZXvE0WtgfAhik6BlsS+pTJgyoV5/kJoCJ3tyBRAtd56gFhG e/4On4Kw2im2FrQ2XC67GY86MmJ3vNv9UyuGy8kMDsINHK2Y37ED7QUgtMy7VpbfvRnYcs7BNL+++ ZHSwc3Td76txHgCO8OmUmtZiGcgPAA/r7YGyJ+7Uf5K9fbEacSAogh3PwCfCn4MMhgeh1v4wVA7k3 eLZfrqZdnnsYeF3zNKpSzcUo2aOTo3QLUThIf8KjHpv288p7+xM0dFpx5tzXidyN0H7pQeD9knyu7 4PR5182A==; Received: from [2a01:e34:ec5d:a741:8a4c:7c4e:dc4c:1787] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oYhzB-002lfd-T1; Thu, 15 Sep 2022 08:04:29 +0200 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.96) (envelope-from ) id 1oYhzB-009iSK-1S; Thu, 15 Sep 2022 08:04:29 +0200 From: Aurelien Jarno To: libc-stable@sourceware.org Cc: Alan Modra , Florian Weimer Subject: [COMMITTED 2.35] Use __ehdr_start rather than _begin in _dl_start_final Date: Thu, 15 Sep 2022 08:04:21 +0200 Message-Id: <20220915060421.2315808-1-aurelien@aurel32.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_NONE,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 List-Id: From: Alan Modra __ehdr_start is already used in rltld.c:dl_main, and can serve the same purpose as _begin. Besides tidying the code, using linker defined section relative symbols rather than "-defsym _begin=0" better reflects the intent of _dl_start_final use of _begin, which is to refer to the load address of ld.so rather than absolute address zero. Reviewed-by: Florian Weimer (cherry picked from commit 6f043e0ee7e477f50a44024ed0cb579d5e3f511d) --- elf/Makefile | 3 +-- elf/rtld.c | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/elf/Makefile b/elf/Makefile index 811859654a..bf2550472b 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1296,8 +1296,7 @@ $(objpfx)ld.so: $(objpfx)librtld.os $(ld-map) $(LINK.o) -nostdlib -nostartfiles -shared -o $@.new \ $(LDFLAGS-rtld) -Wl,-z,defs $(z-now-$(bind-now)) \ $(filter-out $(map-file),$^) $(load-map-file) \ - -Wl,-soname=$(rtld-installed-name) \ - -Wl,-defsym=_begin=0 + -Wl,-soname=$(rtld-installed-name) $(call after-link,$@.new) $(READELF) -s $@.new \ | $(AWK) '($$7 ~ /^UND(|EF)$$/ && $$1 != "0:" && $$4 != "REGISTER") { print; p=1 } END { exit p != 0 }' diff --git a/elf/rtld.c b/elf/rtld.c index 9cc9e5fd4c..86354fb0c2 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -441,8 +441,8 @@ static ElfW(Addr) _dl_start_final (void *arg, struct dl_start_final_info *info); #endif -/* These defined magically in the linker script. */ -extern char _begin[] attribute_hidden; +/* These are defined magically by the linker. */ +extern const ElfW(Ehdr) __ehdr_start attribute_hidden; extern char _etext[] attribute_hidden; extern char _end[] attribute_hidden; @@ -487,7 +487,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) #endif _dl_setup_hash (&GL(dl_rtld_map)); GL(dl_rtld_map).l_real = &GL(dl_rtld_map); - GL(dl_rtld_map).l_map_start = (ElfW(Addr)) _begin; + GL(dl_rtld_map).l_map_start = (ElfW(Addr)) &__ehdr_start; GL(dl_rtld_map).l_map_end = (ElfW(Addr)) _end; GL(dl_rtld_map).l_text_end = (ElfW(Addr)) _etext; /* Copy the TLS related data if necessary. */ @@ -1801,7 +1801,6 @@ dl_main (const ElfW(Phdr) *phdr, segment that also includes the phdrs. If that's not available, we use the old method that assumes the beginning of the file is part of the lowest-addressed PT_LOAD segment. */ - extern const ElfW(Ehdr) __ehdr_start __attribute__ ((visibility ("hidden"))); /* Set up the program header information for the dynamic linker itself. It is needed in the dl_iterate_phdr callbacks. */ -- 2.35.1