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

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