Fix gdb.ada/import.exp when using mold

Message ID 20250115171318.1008473-1-tromey@adacore.com
State New
Headers
Series Fix gdb.ada/import.exp when using mold |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom Tromey Jan. 15, 2025, 5:13 p.m. UTC
  We found that the gdb.ada/import.exp test fails when 'mold' is used as
the linker.  This happens because mold decides to mark most of the
symbols in the executable as being file-local.  I tend to think this
choice, while non-traditional, is probably fine.  So, this patch fixes
the problem by changing the relevant Ada code to look for file-local
symbols as well.

Furthermore, there are two overloads of lookup_minimal_symbol_linkage
that both have a final 'bool' parameter -- but with radically
different meanings.  This patch somewhat clears up this confusion as
well.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31378
---
 gdb/dwarf2/ada-imported.c | 3 ++-
 gdb/minsyms.c             | 7 +++----
 gdb/minsyms.h             | 4 ++--
 gdb/symtab.c              | 5 +++--
 4 files changed, 10 insertions(+), 9 deletions(-)
  

Comments

Tom Tromey Jan. 28, 2025, 5:49 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> We found that the gdb.ada/import.exp test fails when 'mold' is used as
Tom> the linker.  This happens because mold decides to mark most of the
Tom> symbols in the executable as being file-local.  I tend to think this
Tom> choice, while non-traditional, is probably fine.  So, this patch fixes
Tom> the problem by changing the relevant Ada code to look for file-local
Tom> symbols as well.

Tom> Furthermore, there are two overloads of lookup_minimal_symbol_linkage
Tom> that both have a final 'bool' parameter -- but with radically
Tom> different meanings.  This patch somewhat clears up this confusion as
Tom> well.

Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31378

I'm checking this in.

Tom
  

Patch

diff --git a/gdb/dwarf2/ada-imported.c b/gdb/dwarf2/ada-imported.c
index eabbab181c9..1654d5852a2 100644
--- a/gdb/dwarf2/ada-imported.c
+++ b/gdb/dwarf2/ada-imported.c
@@ -36,7 +36,8 @@  ada_imported_read_variable (struct symbol *symbol, const frame_info_ptr &frame)
 {
   const char *name = get_imported_name (symbol);
   bound_minimal_symbol minsym
-    = lookup_minimal_symbol_linkage (symbol->objfile ()->pspace (), name, false);
+    = lookup_minimal_symbol_linkage (symbol->objfile ()->pspace (), name,
+				     true, false);
   if (minsym.minsym == nullptr)
     error (_("could not find imported name %s"), name);
   return value_at (symbol->type (), minsym.value_address ());
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 4e1868c9f87..7b03e38de06 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -589,7 +589,7 @@  lookup_minimal_symbol_linkage (const char *name, struct objfile *objf,
 
 bound_minimal_symbol
 lookup_minimal_symbol_linkage (program_space *pspace, const char *name,
-			       bool only_main)
+			       bool match_static_type, bool only_main)
 {
   for (objfile *objfile : pspace->objfiles ())
     {
@@ -599,9 +599,8 @@  lookup_minimal_symbol_linkage (program_space *pspace, const char *name,
       if (only_main && (objfile->flags & OBJF_MAINLINE) == 0)
 	continue;
 
-      bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (name,
-								   objfile,
-								   false);
+      bound_minimal_symbol minsym
+	= lookup_minimal_symbol_linkage (name, objfile, match_static_type);
       if (minsym.minsym != nullptr)
 	return minsym;
     }
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index 3eea55847bd..2327a1bd77c 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -240,8 +240,8 @@  extern bound_minimal_symbol lookup_minimal_symbol_linkage
    OBJF_MAINLINE will be considered.  */
 
 extern bound_minimal_symbol lookup_minimal_symbol_linkage
-  (program_space *pspace, const char *name, bool only_main)
-  ATTRIBUTE_NONNULL (1);
+  (program_space *pspace, const char *name, bool match_static_type,
+   bool only_main) ATTRIBUTE_NONNULL (1);
 
 /* Look through all the current minimal symbol tables and find the
    first minimal symbol that matches NAME and PC.  If OBJF is non-NULL,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index ab29b59fe9c..c8bcab7f8ff 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -6817,7 +6817,7 @@  symbol::get_maybe_copied_address () const
   const char *linkage_name = this->linkage_name ();
   bound_minimal_symbol minsym
     = lookup_minimal_symbol_linkage (this->objfile ()->pspace (), linkage_name,
-				     false);
+				     false, false);
   if (minsym.minsym != nullptr)
     return minsym.value_address ();
 
@@ -6834,7 +6834,8 @@  minimal_symbol::get_maybe_copied_address (objfile *objf) const
 
   const char *linkage_name = this->linkage_name ();
   bound_minimal_symbol found
-    = lookup_minimal_symbol_linkage (objf->pspace (), linkage_name, true);
+    = lookup_minimal_symbol_linkage (objf->pspace (), linkage_name,
+				     false, true);
   if (found.minsym != nullptr)
     return found.value_address ();