[RFA] Fall back on dynamic symtab in solib.c:bdf_lookup_symbol

Mark Kettenis kettenis@wins.uva.nl
Sun May 21 05:38:00 GMT 2000


It turns out that the dynamic linker on FreeBSD is stripped by
default.  Since bfd_lookup_symbol() only checks the normal symbol
table, which isn't present in a stripped shared object, this means
that on FreeBSD the initial solib_event breakpoint cannot be set.
This patch makes bfd_lookup_symbol() fall back on the dynamic symtab,
which works since r_debug_state() is exported on FreeBSD.

OK to check this in?

Mark

P.S. By the way, it somwhat surprised me to see that the sybol table in
the dynamic linker on Solaris isn't stripped.  They probably need the
symbols for their librtld_db debugging interface.

P.P.S. It also surprises me that apparently, none of the Linux
distributions is stripping their dynamic linker.


2000-05-21  Mark Kettenis  <kettenis@gnu.org>

	* solib.c (bfd_lookup_symbol): Fall back on the dynamic symbol
	table if the symbol couldn't be found in the normal symbol table
	(i.e. if the shared object in question was stripped).


Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.14
diff -u -p -r1.14 solib.c
--- solib.c	2000/05/16 04:07:39	1.14
+++ solib.c	2000/05/21 12:26:33
@@ -545,7 +545,35 @@ bfd_lookup_symbol (abfd, symname)
 	}
       do_cleanups (back_to);
     }
-  return (symaddr);
+
+  if (symaddr)
+    return symaddr;
+
+  /* On FreeBSD, the dynamic linker is stripped by default.  So we'll
+     have to check the dynamic string table too.  */
+
+  storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
+
+  if (storage_needed > 0)
+    {
+      symbol_table = (asymbol **) xmalloc (storage_needed);
+      back_to = make_cleanup (free, (PTR) symbol_table);
+      number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
+
+      for (i = 0; i < number_of_symbols; i++)
+	{
+	  sym = *symbol_table++;
+	  if (STREQ (sym->name, symname))
+	    {
+	      /* Bfd symbols are section relative. */
+	      symaddr = sym->value + sym->section->vma;
+	      break;
+	    }
+	}
+      do_cleanups (back_to);
+    }
+
+  return symaddr;
 }
 
 #ifdef HANDLE_SVR4_EXEC_EMULATORS



More information about the Gdb-patches mailing list