about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-12-09 18:24:37 -0800
committerH.J. Lu <hjl.tools@gmail.com>2022-01-03 05:16:03 -0800
commit9288c92d0037745b940a90d59cbe102d4c218c26 (patch)
tree4edc09f879a504a05bdef6a473982023b8c06e25 /elf
parentbd1616c6bee625a2726d0f8b477881b4b25697d8 (diff)
downloadglibc-9288c92d0037745b940a90d59cbe102d4c218c26.tar.gz
glibc-9288c92d0037745b940a90d59cbe102d4c218c26.tar.xz
glibc-9288c92d0037745b940a90d59cbe102d4c218c26.zip
elf: Add <dl-debug.h>
Add <dl-debug.h> to setup debugging entry in PT_DYNAMIC segment to support
DT_DEBUG, DT_MIPS_RLD_MAP_REL and DT_MIPS_RLD_MAP.

Tested on x86-64, x32 and i686 as well as with build-many-glibcs.py.
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-reloc-static-pie.c11
-rw-r--r--elf/rtld.c13
2 files changed, 6 insertions, 18 deletions
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index 261bdd6352..bf895e5dd0 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -24,6 +24,7 @@
 #include <ldsodefs.h>
 
 #include <dl-machine.h>
+#include <dl-debug.h>
 
 #define RESOLVE_MAP(map, scope, sym, version, flags) map
 #include "dynamic-link.h"
@@ -68,14 +69,6 @@ _dl_relocate_static_pie (void)
 
   /* Set up debugging before the debugger is notified for the first
      time.  */
-# ifdef ELF_MACHINE_DEBUG_SETUP
-  /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */
-  ELF_MACHINE_DEBUG_SETUP (main_map, r);
-# else
-  if (main_map->l_info[DT_DEBUG] != NULL)
-    /* There is a DT_DEBUG entry in the dynamic section.  Fill it in
-       with the run-time address of the r_debug structure  */
-    main_map->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
-# endif
+  elf_setup_debug_entry (main_map, r);
 }
 #endif
diff --git a/elf/rtld.c b/elf/rtld.c
index 24e48bf3fa..39cab66e6b 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -63,6 +63,9 @@
 #define RESOLVE_MAP(map, scope, sym, version, flags) map
 #include "dynamic-link.h"
 
+/* Must include after <dl-machine.h> for DT_MIPS definition.  */
+#include <dl-debug.h>
+
 /* Only enables rtld profiling for architectures which provides non generic
    hp-timing support.  The generic support requires either syscall
    (clock_gettime), which will incur in extra overhead on loading time.
@@ -1776,15 +1779,7 @@ dl_main (const ElfW(Phdr) *phdr,
   size_t count_modids = _dl_count_modids ();
 
   /* Set up debugging before the debugger is notified for the first time.  */
-#ifdef ELF_MACHINE_DEBUG_SETUP
-  /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */
-  ELF_MACHINE_DEBUG_SETUP (main_map, r);
-#else
-  if (main_map->l_info[DT_DEBUG] != NULL)
-    /* There is a DT_DEBUG entry in the dynamic section.  Fill it in
-       with the run-time address of the r_debug structure  */
-    main_map->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
-#endif
+  elf_setup_debug_entry (main_map, r);
 
   /* We start adding objects.  */
   r->r_state = RT_ADD;