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 <fweimer@redhat.com>
This commit is contained in:
Alan Modra 2022-04-27 14:39:10 +09:30
parent 911c63a51c
commit 6f043e0ee7
2 changed files with 4 additions and 6 deletions

View File

@ -1336,8 +1336,7 @@ $(objpfx)ld.so: $(objpfx)librtld.os $(ld-map)
$(LINK.o) -nostdlib -nostartfiles -shared -o $@.new \ $(LINK.o) -nostdlib -nostartfiles -shared -o $@.new \
$(LDFLAGS-rtld) -Wl,-z,defs $(z-now-$(bind-now)) \ $(LDFLAGS-rtld) -Wl,-z,defs $(z-now-$(bind-now)) \
$(filter-out $(map-file),$^) $(load-map-file) \ $(filter-out $(map-file),$^) $(load-map-file) \
-Wl,-soname=$(rtld-installed-name) \ -Wl,-soname=$(rtld-installed-name)
-Wl,-defsym=_begin=0
$(call after-link,$@.new) $(call after-link,$@.new)
$(READELF) -s $@.new \ $(READELF) -s $@.new \
| $(AWK) '($$7 ~ /^UND(|EF)$$/ && $$1 != "0:" && $$4 != "REGISTER") { print; p=1 } END { exit p != 0 }' | $(AWK) '($$7 ~ /^UND(|EF)$$/ && $$1 != "0:" && $$4 != "REGISTER") { print; p=1 } END { exit p != 0 }'

View File

@ -440,8 +440,8 @@ static ElfW(Addr) _dl_start_final (void *arg,
struct dl_start_final_info *info); struct dl_start_final_info *info);
#endif #endif
/* These defined magically in the linker script. */ /* These are defined magically by the linker. */
extern char _begin[] attribute_hidden; extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
extern char _etext[] attribute_hidden; extern char _etext[] attribute_hidden;
extern char _end[] attribute_hidden; extern char _end[] attribute_hidden;
@ -490,7 +490,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
#endif #endif
_dl_setup_hash (&GL(dl_rtld_map)); _dl_setup_hash (&GL(dl_rtld_map));
GL(dl_rtld_map).l_real = &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_map_end = (ElfW(Addr)) _end;
GL(dl_rtld_map).l_text_end = (ElfW(Addr)) _etext; GL(dl_rtld_map).l_text_end = (ElfW(Addr)) _etext;
/* Copy the TLS related data if necessary. */ /* Copy the TLS related data if necessary. */
@ -1741,7 +1741,6 @@ dl_main (const ElfW(Phdr) *phdr,
segment that also includes the phdrs. If that's not available, we use 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 the old method that assumes the beginning of the file is part of the
lowest-addressed PT_LOAD segment. */ lowest-addressed PT_LOAD segment. */
extern const ElfW(Ehdr) __ehdr_start __attribute__ ((visibility ("hidden")));
/* Set up the program header information for the dynamic linker /* Set up the program header information for the dynamic linker
itself. It is needed in the dl_iterate_phdr callbacks. */ itself. It is needed in the dl_iterate_phdr callbacks. */