[1/2] elf: Record original entry point in GLRO(dl_entry)

Message ID e2a4b3cee18e071b158772bf21aa442a138e8b46.1782766548.git.fweimer@redhat.com (mailing list archive)
State New
Headers
Series Work around GDB bug overwriting __libc_malloc |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 fail Test failed

Commit Message

Florian Weimer June 29, 2026, 9:07 p.m. UTC
  This could be useful information for debugging purposes.  On Linux,
the kernel-provided value in the auxilary vector is overwritten
by ld.so.

This is also the address that GDB uses on some architectures to
set the breakpoint on the return from an inferior function call.
---
 elf/rtld.c                 | 1 +
 sysdeps/generic/ldsodefs.h | 4 ++++
 2 files changed, 5 insertions(+)
  

Patch

diff --git a/elf/rtld.c b/elf/rtld.c
index e5ba71fef1..cc813201dc 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1366,6 +1366,7 @@  dl_main (const ElfW(Phdr) *phdr,
 #endif
 
   const char *ld_so_name = _dl_argv[0];
+  GLRO(dl_entry) = *user_entry;
   if (*user_entry == (ElfW(Addr)) ENTRY_POINT)
     {
       /* Ho ho.  We are not the program interpreter!  We are the program
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index f94247ad9f..9bbc9f2c54 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -682,6 +682,10 @@  struct rtld_global_ro
   /* Dynamic linker operations used after static dlopen.  */
   const struct dlfcn_hook *_dl_dlfcn_hook;
 
+  /* Original kernel-provided entry point.  Could be the main program
+     or ld.so itself.  */
+  ElfW(Addr) _dl_entry;
+
   /* List of auditing interfaces.  */
   struct audit_ifaces *_dl_audit;
   unsigned int _dl_naudit;