public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb, solib-svr4: remove locate_base()
@ 2022-10-18 13:24 Markus Metzger
  0 siblings, 0 replies; only message in thread
From: Markus Metzger @ 2022-10-18 13:24 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=60d09f0a0d8000359b8f1dd14b51e7f013ea9e5c

commit 60d09f0a0d8000359b8f1dd14b51e7f013ea9e5c
Author: Markus Metzger <markus.t.metzger@intel.com>
Date:   Fri Mar 11 06:46:15 2022 +0100

    gdb, solib-svr4: remove locate_base()
    
    Whenever we call locate_base(), we clear info->debug_base directly before
    the call.  Thus, we never cache the base location as locate_base() had
    intended.
    
    Move the svr4_have_link_map_offsets() check into elf_locate_base(), inline
    locate_base() at all call sites, and remove it.

Diff:
---
 gdb/solib-svr4.c | 62 ++++++++++----------------------------------------------
 1 file changed, 11 insertions(+), 51 deletions(-)

diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 7e83819a03d..222b9df3c47 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -661,6 +661,9 @@ elf_locate_base (void)
   struct bound_minimal_symbol msymbol;
   CORE_ADDR dyn_ptr, dyn_ptr_addr;
 
+  if (!svr4_have_link_map_offsets ())
+    return 0;
+
   /* Look for DT_MIPS_RLD_MAP first.  MIPS executables use this
      instead of DT_DEBUG, although they sometimes contain an unused
      DT_DEBUG.  */
@@ -718,45 +721,6 @@ elf_locate_base (void)
   return 0;
 }
 
-/* Locate the base address of dynamic linker structs.
-
-   For both the SunOS and SVR4 shared library implementations, if the
-   inferior executable has been linked dynamically, there is a single
-   address somewhere in the inferior's data space which is the key to
-   locating all of the dynamic linker's runtime structures.  This
-   address is the value of the debug base symbol.  The job of this
-   function is to find and return that address, or to return 0 if there
-   is no such address (the executable is statically linked for example).
-
-   For SunOS, the job is almost trivial, since the dynamic linker and
-   all of it's structures are statically linked to the executable at
-   link time.  Thus the symbol for the address we are looking for has
-   already been added to the minimal symbol table for the executable's
-   objfile at the time the symbol file's symbols were read, and all we
-   have to do is look it up there.  Note that we explicitly do NOT want
-   to find the copies in the shared library.
-
-   The SVR4 version is a bit more complicated because the address
-   is contained somewhere in the dynamic info section.  We have to go
-   to a lot more work to discover the address of the debug base symbol.
-   Because of this complexity, we cache the value we find and return that
-   value on subsequent invocations.  Note there is no copy in the
-   executable symbol tables.  */
-
-static CORE_ADDR
-locate_base (struct svr4_info *info)
-{
-  /* Check to see if we have a currently valid address, and if so, avoid
-     doing all this work again and just return the cached address.  If
-     we have no cached address, try to locate it in the dynamic info
-     section for ELF executables.  There's no point in doing any of this
-     though if we don't have some link map offsets to work with.  */
-
-  if (info->debug_base == 0 && svr4_have_link_map_offsets ())
-    info->debug_base = elf_locate_base ();
-  return info->debug_base;
-}
-
 /* Find the first element in the inferior's dynamic link map, and
    return its address in the inferior.  Return zero if the address
    could not be determined.
@@ -844,9 +808,8 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
 
   info = get_svr4_info (current_program_space);
 
-  info->debug_base = 0;
-  locate_base (info);
-  if (!info->debug_base)
+  info->debug_base = elf_locate_base ();
+  if (info->debug_base == 0)
     return 0;
 
   ldsomap = solib_svr4_r_ldsomap (info);
@@ -880,8 +843,8 @@ open_symbol_file_object (int from_tty)
       return 0;
 
   /* Always locate the debug struct, in case it has moved.  */
-  info->debug_base = 0;
-  if (locate_base (info) == 0)
+  info->debug_base = elf_locate_base ();
+  if (info->debug_base == 0)
     return 0;	/* failed somehow...  */
 
   /* First link map member should be the executable.  */
@@ -1297,13 +1260,10 @@ svr4_current_sos_direct (struct svr4_info *info)
       return library_list.head ? library_list.head : svr4_default_sos (info);
     }
 
-  /* Always locate the debug struct, in case it has moved.  */
-  info->debug_base = 0;
-  locate_base (info);
-
   /* If we can't find the dynamic linker's base structure, this
      must not be a dynamically linked executable.  Hmm.  */
-  if (! info->debug_base)
+  info->debug_base = elf_locate_base ();
+  if (info->debug_base == 0)
     return svr4_default_sos (info);
 
   /* Assume that everything is a library if the dynamic loader was loaded
@@ -1839,8 +1799,8 @@ svr4_handle_solib_event (void)
       return;
 
     /* Always locate the debug struct, in case it moved.  */
-    info->debug_base = 0;
-    if (locate_base (info) == 0)
+    info->debug_base = elf_locate_base ();
+    if (info->debug_base == 0)
       {
 	/* It's possible for the reloc_complete probe to be triggered before
 	   the linker has set the DT_DEBUG pointer (for example, when the

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-18 13:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 13:24 [binutils-gdb] gdb, solib-svr4: remove locate_base() Markus Metzger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).