Upstream commit: fffc2df8a3e2c8cda2991063d23086360268b777 - i386: Provide GLIBC_ABI_GNU_TLS symbol version [BZ #33221] - i386: Update ___tls_get_addr to preserve vector registers - Extend struct r_debug to support multiple namespaces (RHEL-101985) - Fix a potential crash in the dynamic loader when processing specific symbol versions (RHEL-109683) - Signal la_objopen for ld.so with dlmopen (RHEL-109693) - Switch to main malloc after final ld.so self-relocation (RHEL-109703) - Prevent ld.so from asserting and crashing during audited library loads (RHEL-109702) - x86-64: Provide GLIBC_ABI_DT_X86_64_PLT symbol version (RHEL-109621) - x86-64, i386: Provide GLIBC_ABI_GNU2_TLS symbol version (RHEL-109625) - Ensure fallback initialization of ctype TLS data pointers to fix segfaults in programs using dlmopen or auditors (RHEL-72018) - Handle load segment gaps in _dl_find_object (RHEL-104854) - AArch64: Improve codegen in SVE log1p - AArch64: Optimize inverse trig functions - AArch64: Avoid memset ifunc in cpu-features.c [BZ #33112] Resolves: RHEL-109536 Resolves: RHEL-72018 Resolves: RHEL-101985 Resolves: RHEL-104854 Resolves: RHEL-109621 Resolves: RHEL-109625 Resolves: RHEL-109683 Resolves: RHEL-109693 Resolves: RHEL-109702 Resolves: RHEL-109703
90 lines
3.2 KiB
Diff
90 lines
3.2 KiB
Diff
commit 64488b4b31d63b59b06b42ad93a092053364801b
|
|
Author: Florian Weimer <fweimer@redhat.com>
|
|
Date: Fri Aug 1 10:20:23 2025 +0200
|
|
|
|
elf: Extract rtld_setup_phdr function from dl_main
|
|
|
|
Remove historic binutils reference from comment and update
|
|
how this data is used by applications.
|
|
|
|
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
(cherry picked from commit 2cac9559e06044ba520e785c151fbbd25011865f)
|
|
|
|
diff --git a/elf/rtld.c b/elf/rtld.c
|
|
index 3ca9a11009a74626..3bf9707e0007bc83 100644
|
|
--- a/elf/rtld.c
|
|
+++ b/elf/rtld.c
|
|
@@ -1284,6 +1284,37 @@ rtld_setup_main_map (struct link_map *main_map)
|
|
return has_interp;
|
|
}
|
|
|
|
+/* Set up the program header information for the dynamic linker
|
|
+ itself. It can be accessed via _r_debug and dl_iterate_phdr
|
|
+ callbacks. */
|
|
+static void
|
|
+rtld_setup_phdr (void)
|
|
+{
|
|
+ /* 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. */
|
|
+
|
|
+ const ElfW(Ehdr) *rtld_ehdr = &__ehdr_start;
|
|
+ assert (rtld_ehdr->e_ehsize == sizeof *rtld_ehdr);
|
|
+ assert (rtld_ehdr->e_phentsize == sizeof (ElfW(Phdr)));
|
|
+
|
|
+ const ElfW(Phdr) *rtld_phdr = (const void *) rtld_ehdr + rtld_ehdr->e_phoff;
|
|
+
|
|
+ GL(dl_rtld_map).l_phdr = rtld_phdr;
|
|
+ GL(dl_rtld_map).l_phnum = rtld_ehdr->e_phnum;
|
|
+
|
|
+
|
|
+ /* PT_GNU_RELRO is usually the last phdr. */
|
|
+ size_t cnt = rtld_ehdr->e_phnum;
|
|
+ while (cnt-- > 0)
|
|
+ if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)
|
|
+ {
|
|
+ GL(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;
|
|
+ GL(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz;
|
|
+ break;
|
|
+ }
|
|
+}
|
|
+
|
|
/* Adjusts the contents of the stack and related globals for the user
|
|
entry point. The ld.so processed skip_args arguments and bumped
|
|
_dl_argv and _dl_argc accordingly. Those arguments are removed from
|
|
@@ -1749,33 +1780,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
|
++GL(dl_ns)[LM_ID_BASE]._ns_nloaded;
|
|
++GL(dl_load_adds);
|
|
|
|
- /* 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. 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. */
|
|
-
|
|
- /* Set up the program header information for the dynamic linker
|
|
- itself. It is needed in the dl_iterate_phdr callbacks. */
|
|
- const ElfW(Ehdr) *rtld_ehdr = &__ehdr_start;
|
|
- assert (rtld_ehdr->e_ehsize == sizeof *rtld_ehdr);
|
|
- assert (rtld_ehdr->e_phentsize == sizeof (ElfW(Phdr)));
|
|
-
|
|
- const ElfW(Phdr) *rtld_phdr = (const void *) rtld_ehdr + rtld_ehdr->e_phoff;
|
|
-
|
|
- GL(dl_rtld_map).l_phdr = rtld_phdr;
|
|
- GL(dl_rtld_map).l_phnum = rtld_ehdr->e_phnum;
|
|
-
|
|
-
|
|
- /* PT_GNU_RELRO is usually the last phdr. */
|
|
- size_t cnt = rtld_ehdr->e_phnum;
|
|
- while (cnt-- > 0)
|
|
- if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)
|
|
- {
|
|
- GL(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;
|
|
- GL(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz;
|
|
- break;
|
|
- }
|
|
+ rtld_setup_phdr ();
|
|
|
|
/* Add the dynamic linker to the TLS list if it also uses TLS. */
|
|
if (GL(dl_rtld_map).l_tls_blocksize != 0)
|