This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Move DT_DEBUG initialization earlier in dl_main


Hi!

gdb can't debug PIE binaries without this, because it will see DT_DEBUG
being NULL the first time it is notified.

2005-06-13  Jakub Jelinek  <jakub@redhat.com>

	* elf/rtld.c (dl_main): Move DT_DEBUG setup before first
	_dl_debug_state call.

--- libc/elf/rtld.c.jj	2005-05-26 14:21:09.000000000 +0200
+++ libc/elf/rtld.c	2005-06-13 18:59:11.000000000 +0200
@@ -1540,6 +1540,30 @@ ERROR: ld.so: object '%s' cannot be load
 	}
     }
 
+  {
+    struct link_map *l = main_map;
+
+#ifdef ELF_MACHINE_DEBUG_SETUP
+
+    /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */
+
+    ELF_MACHINE_DEBUG_SETUP (l, r);
+    ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r);
+
+#else
+
+    if (l->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  */
+      l->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
+
+    /* Fill in the pointer in the dynamic linker's own dynamic section, in
+       case you run gdb on the dynamic linker directly.  */
+    if (GL(dl_rtld_map).l_info[DT_DEBUG] != NULL)
+      GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
+#endif
+  }
+
   /* We start adding objects.  */
   r->r_state = RT_ADD;
   _dl_debug_state ();
@@ -2058,30 +2082,6 @@ ERROR: ld.so: object '%s' cannot be load
     }
 
 
-  {
-    struct link_map *l = main_map;
-
-#ifdef ELF_MACHINE_DEBUG_SETUP
-
-    /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */
-
-    ELF_MACHINE_DEBUG_SETUP (l, r);
-    ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r);
-
-#else
-
-    if (l->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  */
-      l->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
-
-    /* Fill in the pointer in the dynamic linker's own dynamic section, in
-       case you run gdb on the dynamic linker directly.  */
-    if (GL(dl_rtld_map).l_info[DT_DEBUG] != NULL)
-      GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
-#endif
-  }
-
   /* Now set up the variable which helps the assembler startup code.  */
   GL(dl_ns)[LM_ID_BASE]._ns_main_searchlist = &main_map->l_searchlist;
   GL(dl_ns)[LM_ID_BASE]._ns_global_scope[0] = &main_map->l_searchlist;

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]