Blame SOURCES/binutils-bfd-DWARF-improvements.patch

f8cceb
--- binutils.orig/bfd/dwarf2.c	2022-05-16 16:40:15.590519654 +0100
f8cceb
+++ binutils-2.38/bfd/dwarf2.c	2022-05-16 16:45:31.824590450 +0100
f8cceb
@@ -3291,6 +3291,36 @@ lookup_var_by_offset (bfd_uint64_t offse
f8cceb
 }
f8cceb
 
f8cceb
 
f8cceb
+static struct funcinfo *
f8cceb
+reverse_funcinfo_list (struct funcinfo *head)
f8cceb
+{
f8cceb
+  struct funcinfo *rhead;
f8cceb
+  struct funcinfo *temp;
f8cceb
+
f8cceb
+  for (rhead = NULL; head; head = temp)
f8cceb
+    {
f8cceb
+      temp = head->prev_func;
f8cceb
+      head->prev_func = rhead;
f8cceb
+      rhead = head;
f8cceb
+    }
f8cceb
+  return rhead;
f8cceb
+}
f8cceb
+
f8cceb
+static struct varinfo *
f8cceb
+reverse_varinfo_list (struct varinfo *head)
f8cceb
+{
f8cceb
+  struct varinfo *rhead;
f8cceb
+  struct varinfo *temp;
f8cceb
+
f8cceb
+  for (rhead = NULL; head; head = temp)
f8cceb
+    {
f8cceb
+      temp = head->prev_var;
f8cceb
+      head->prev_var = rhead;
f8cceb
+      rhead = head;
f8cceb
+    }
f8cceb
+  return rhead;
f8cceb
+}
f8cceb
+
f8cceb
 /* DWARF2 Compilation unit functions.  */
f8cceb
 
f8cceb
 /* Scan over each die in a comp. unit looking for functions to add
f8cceb
@@ -3308,6 +3338,8 @@ scan_unit_for_symbols (struct comp_unit
f8cceb
     struct funcinfo *func;
f8cceb
   } *nested_funcs;
f8cceb
   int nested_funcs_size;
f8cceb
+  struct funcinfo *last_func;
f8cceb
+  struct varinfo *last_var;
f8cceb
 
f8cceb
   /* Maintain a stack of in-scope functions and inlined functions, which we
f8cceb
      can use to set the caller_func field.  */
f8cceb
@@ -3442,10 +3474,16 @@ scan_unit_for_symbols (struct comp_unit
f8cceb
 	}
f8cceb
     }
f8cceb
 
f8cceb
+  unit->function_table = reverse_funcinfo_list (unit->function_table);
f8cceb
+  unit->variable_table = reverse_varinfo_list (unit->variable_table);
f8cceb
+
f8cceb
   /* This is the second pass over the abbrevs.  */      
f8cceb
   info_ptr = unit->first_child_die_ptr;
f8cceb
   nesting_level = 0;
f8cceb
   
f8cceb
+  last_func = NULL;
f8cceb
+  last_var = NULL;
f8cceb
+
f8cceb
   while (nesting_level >= 0)
f8cceb
     {
f8cceb
       unsigned int abbrev_number, i;
f8cceb
@@ -3481,16 +3519,32 @@ scan_unit_for_symbols (struct comp_unit
f8cceb
 	  || abbrev->tag == DW_TAG_entry_point
f8cceb
 	  || abbrev->tag == DW_TAG_inlined_subroutine)
f8cceb
 	{
f8cceb
-	  func = lookup_func_by_offset (current_offset, unit->function_table);
f8cceb
+	  if (last_func
f8cceb
+	      && last_func->prev_func
f8cceb
+	      && last_func->prev_func->unit_offset == current_offset)
f8cceb
+	    func = last_func->prev_func;
f8cceb
+	  else
f8cceb
+	    func = lookup_func_by_offset (current_offset, unit->function_table);
f8cceb
+
f8cceb
 	  if (func == NULL)
f8cceb
 	    goto fail;
f8cceb
+
f8cceb
+	  last_func = func;
f8cceb
 	}
f8cceb
       else if (abbrev->tag == DW_TAG_variable
f8cceb
 	       || abbrev->tag == DW_TAG_member)
f8cceb
 	{
f8cceb
-	  var = lookup_var_by_offset (current_offset, unit->variable_table);
f8cceb
+	  if (last_var
f8cceb
+	      && last_var->prev_var
f8cceb
+	      && last_var->prev_var->unit_offset == current_offset)
f8cceb
+	    var = last_var->prev_var;
f8cceb
+	  else
f8cceb
+	    var = lookup_var_by_offset (current_offset, unit->variable_table);
f8cceb
+
f8cceb
 	  if (var == NULL)
f8cceb
 	    goto fail;
f8cceb
+
f8cceb
+	  last_var = var;
f8cceb
 	}
f8cceb
 
f8cceb
       for (i = 0; i < abbrev->num_attrs; ++i)
f8cceb
@@ -3684,6 +3738,9 @@ scan_unit_for_symbols (struct comp_unit
f8cceb
 	}
f8cceb
     }
f8cceb
 
f8cceb
+  unit->function_table = reverse_funcinfo_list (unit->function_table);
f8cceb
+  unit->variable_table = reverse_varinfo_list (unit->variable_table);
f8cceb
+
f8cceb
   free (nested_funcs);
f8cceb
   return true;
f8cceb
 
f8cceb
@@ -4047,36 +4104,6 @@ comp_unit_find_line (struct comp_unit *u
f8cceb
 					  linenumber_ptr);
f8cceb
 }
f8cceb
 
f8cceb
-static struct funcinfo *
f8cceb
-reverse_funcinfo_list (struct funcinfo *head)
f8cceb
-{
f8cceb
-  struct funcinfo *rhead;
f8cceb
-  struct funcinfo *temp;
f8cceb
-
f8cceb
-  for (rhead = NULL; head; head = temp)
f8cceb
-    {
f8cceb
-      temp = head->prev_func;
f8cceb
-      head->prev_func = rhead;
f8cceb
-      rhead = head;
f8cceb
-    }
f8cceb
-  return rhead;
f8cceb
-}
f8cceb
-
f8cceb
-static struct varinfo *
f8cceb
-reverse_varinfo_list (struct varinfo *head)
f8cceb
-{
f8cceb
-  struct varinfo *rhead;
f8cceb
-  struct varinfo *temp;
f8cceb
-
f8cceb
-  for (rhead = NULL; head; head = temp)
f8cceb
-    {
f8cceb
-      temp = head->prev_var;
f8cceb
-      head->prev_var = rhead;
f8cceb
-      rhead = head;
f8cceb
-    }
f8cceb
-  return rhead;
f8cceb
-}
f8cceb
-
f8cceb
 /* Extract all interesting funcinfos and varinfos of a compilation
f8cceb
    unit into hash tables for faster lookup.  Returns TRUE if no
f8cceb
    errors were enountered; FALSE otherwise.  */