From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1778) id A2B2F3858404; Thu, 15 Sep 2022 06:04:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2B2F3858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663221866; bh=xQRoyWE9BfseUGlrquEVcWijijKejKcP08YiTj7GsfA=; h=From:To:Subject:Date:From; b=HIf0zok3G9hKFvQiSaKsGhqdpctWc0opUDQ9gZz54zoiab/QQ6mhsTDWQOqghe34w vU4JZy2dQddLOcUAPjURJIyZrGK8Ipx8o1oWsWdxG9hglukPAcbtEvQB2/7X0r4d+P oy4oOc5h0JYLm1iY1AOG2+E9eio4SR03px8dFwHs= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Aurelien Jarno To: glibc-cvs@sourceware.org Subject: [glibc/release/2.35/master] Use __ehdr_start rather than _begin in _dl_start_final X-Act-Checkin: glibc X-Git-Author: Alan Modra X-Git-Refname: refs/heads/release/2.35/master X-Git-Oldrev: 61e15f6815b6d4fb30b998716d5dd6d5aae7f445 X-Git-Newrev: 55a636430bd382fb9537e6d33cc6bc57bc2660c1 Message-Id: <20220915060426.A2B2F3858404@sourceware.org> Date: Thu, 15 Sep 2022 06:04:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=55a636430bd382fb9537e6d33cc6bc57bc2660c1 commit 55a636430bd382fb9537e6d33cc6bc57bc2660c1 Author: Alan Modra Date: Wed Apr 27 14:39:10 2022 +0930 Use __ehdr_start rather than _begin in _dl_start_final __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) Diff: --- 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. */