]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Optimize lookup_minimal_symbol_text
authorTom Tromey <tom@tromey.com>
Sat, 21 Oct 2023 22:38:23 +0000 (16:38 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 9 Jan 2024 01:40:22 +0000 (18:40 -0700)
lookup_minimal_symbol_text always loops over all objfiles, even when
an objfile is passed in as an argument.  This patch changes the
function to loop over the minimal number of objfiles in the latter
situation.

gdb/minsyms.c

index 71e22ce1a90cdee94ec1d3b1b5ab089ff635303d..0e24da918d989e94b18229bfd2930cd3dbe9f6da 100644 (file)
@@ -623,38 +623,51 @@ lookup_minimal_symbol_text (const char *name, struct objfile *objf)
 
   unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE;
 
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      if (found_symbol.minsym != NULL)
-       break;
+  auto search = [&] (struct objfile *objfile)
+  {
+    for (msymbol = objfile->per_bfd->msymbol_hash[hash];
+        msymbol != NULL && found_symbol.minsym == NULL;
+        msymbol = msymbol->hash_next)
+      {
+       if (strcmp (msymbol->linkage_name (), name) == 0 &&
+           (msymbol->type () == mst_text
+            || msymbol->type () == mst_text_gnu_ifunc
+            || msymbol->type () == mst_file_text))
+         {
+           switch (msymbol->type ())
+             {
+             case mst_file_text:
+               found_file_symbol.minsym = msymbol;
+               found_file_symbol.objfile = objfile;
+               break;
+             default:
+               found_symbol.minsym = msymbol;
+               found_symbol.objfile = objfile;
+               break;
+             }
+         }
+      }
+  };
 
-      if (objf == NULL || objf == objfile
-         || objf == objfile->separate_debug_objfile_backlink)
+  if (objf == nullptr)
+    {
+      for (objfile *objfile : current_program_space->objfiles ())
        {
-         for (msymbol = objfile->per_bfd->msymbol_hash[hash];
-              msymbol != NULL && found_symbol.minsym == NULL;
-              msymbol = msymbol->hash_next)
-           {
-             if (strcmp (msymbol->linkage_name (), name) == 0 &&
-                 (msymbol->type () == mst_text
-                  || msymbol->type () == mst_text_gnu_ifunc
-                  || msymbol->type () == mst_file_text))
-               {
-                 switch (msymbol->type ())
-                   {
-                   case mst_file_text:
-                     found_file_symbol.minsym = msymbol;
-                     found_file_symbol.objfile = objfile;
-                     break;
-                   default:
-                     found_symbol.minsym = msymbol;
-                     found_symbol.objfile = objfile;
-                     break;
-                   }
-               }
-           }
+         if (found_symbol.minsym != NULL)
+           break;
+         search (objfile);
        }
     }
+  else
+    {
+      for (objfile *objfile : objf->separate_debug_objfiles ())
+       {
+         if (found_symbol.minsym != NULL)
+           break;
+         search (objfile);
+       }
+    }
+
   /* External symbols are best.  */
   if (found_symbol.minsym)
     return found_symbol;