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

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