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

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