Blame SOURCES/binutils-gas-loc-view.patch

a8cd6b
diff -rup binutils.orig/gas/symbols.c binutils-2.38/gas/symbols.c
a8cd6b
--- binutils.orig/gas/symbols.c	2022-03-09 11:43:34.706610216 +0000
a8cd6b
+++ binutils-2.38/gas/symbols.c	2022-03-09 11:45:57.540686508 +0000
a8cd6b
@@ -61,8 +61,10 @@ struct symbol_flags
a8cd6b
   /* Whether the symbol can be re-defined.  */
a8cd6b
   unsigned int volatil : 1;
a8cd6b
 
a8cd6b
-  /* Whether the symbol is a forward reference.  */
a8cd6b
+  /* Whether the symbol is a forward reference, and whether such has
a8cd6b
+     been determined.  */
a8cd6b
   unsigned int forward_ref : 1;
a8cd6b
+  unsigned int forward_resolved : 1;
a8cd6b
 
a8cd6b
   /* This is set if the symbol is defined in an MRI common section.
a8cd6b
      We handle such sections as single common symbols, so symbols
a8cd6b
@@ -202,7 +204,7 @@ static void *
a8cd6b
 symbol_entry_find (htab_t table, const char *name)
a8cd6b
 {
a8cd6b
   hashval_t hash = htab_hash_string (name);
a8cd6b
-  symbol_entry_t needle = { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
a8cd6b
+  symbol_entry_t needle = { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
a8cd6b
 			      hash, name, 0, 0, 0 } };
a8cd6b
   return htab_find_with_hash (table, &needle, hash);
a8cd6b
 }
a8cd6b
@@ -784,7 +786,9 @@ symbol_clone (symbolS *orgsymP, int repl
a8cd6b
 symbolS *
a8cd6b
 symbol_clone_if_forward_ref (symbolS *symbolP, int is_forward)
a8cd6b
 {
a8cd6b
-  if (symbolP && !symbolP->flags.local_symbol)
a8cd6b
+  if (symbolP
a8cd6b
+      && !symbolP->flags.local_symbol
a8cd6b
+      && !symbolP->flags.forward_resolved)
a8cd6b
     {
a8cd6b
       symbolS *orig_add_symbol = symbolP->x->value.X_add_symbol;
a8cd6b
       symbolS *orig_op_symbol = symbolP->x->value.X_op_symbol;
a8cd6b
@@ -837,6 +841,7 @@ symbol_clone_if_forward_ref (symbolS *sy
a8cd6b
 
a8cd6b
       symbolP->x->value.X_add_symbol = add_symbol;
a8cd6b
       symbolP->x->value.X_op_symbol = op_symbol;
a8cd6b
+      symbolP->flags.forward_resolved = 1;
a8cd6b
     }
a8cd6b
 
a8cd6b
   return symbolP;
a8cd6b
diff -rup binutils.orig/gas/testsuite/gas/elf/dwarf2-18.d binutils-2.38/gas/testsuite/gas/elf/dwarf2-18.d
a8cd6b
--- binutils.orig/gas/testsuite/gas/elf/dwarf2-18.d	2022-03-09 11:43:34.487611632 +0000
a8cd6b
+++ binutils-2.38/gas/testsuite/gas/elf/dwarf2-18.d	2022-03-09 11:48:03.298873228 +0000
a8cd6b
@@ -2,9 +2,8 @@
a8cd6b
 #readelf: -x.rodata -wL
a8cd6b
 #name: DWARF2 18
a8cd6b
 # The am33 cr16 crx ft32 mn10 msp430 nds32 and rl78 targets do not evaluate the subtraction of symbols at assembly time.
a8cd6b
-# The mep targets turns some view computations into complex relocations.
a8cd6b
 # The riscv targets do not support the subtraction of symbols.
a8cd6b
-#xfail: am3*-* cr16-* crx-* ft32*-* mep-* mn10*-* msp430-* nds32*-* riscv*-* rl78-*
a8cd6b
+#xfail: am3*-* cr16-* crx-* ft32*-* mn10*-* msp430-* nds32*-* riscv*-* rl78-*
a8cd6b
 
a8cd6b
 Hex dump of section '\.rodata':
a8cd6b
   0x00000000 0100 *.*
a8cd6b
--- binutils.orig/gas/dwarf2dbg.c	2022-03-10 09:13:18.516639363 +0000
a8cd6b
+++ binutils-2.38/gas/dwarf2dbg.c	2022-03-10 12:45:25.191933733 +0000
a8cd6b
@@ -402,18 +402,27 @@ set_or_check_view (struct line_entry *e,
a8cd6b
   if (viewx.X_op != O_constant || viewx.X_add_number)
a8cd6b
     {
a8cd6b
       expressionS incv;
a8cd6b
+      expressionS *p_view;
a8cd6b
 
a8cd6b
       if (!p->loc.u.view)
a8cd6b
-	{
a8cd6b
-	  p->loc.u.view = symbol_temp_make ();
a8cd6b
-	  gas_assert (!S_IS_DEFINED (p->loc.u.view));
a8cd6b
-	}
a8cd6b
+	p->loc.u.view = symbol_temp_make ();
a8cd6b
 
a8cd6b
       memset (&incv, 0, sizeof (incv));
a8cd6b
       incv.X_unsigned = 1;
a8cd6b
       incv.X_op = O_symbol;
a8cd6b
       incv.X_add_symbol = p->loc.u.view;
a8cd6b
       incv.X_add_number = 1;
a8cd6b
+      p_view = symbol_get_value_expression (p->loc.u.view);
a8cd6b
+      if (p_view->X_op == O_constant || p_view->X_op == O_symbol)
a8cd6b
+	{
a8cd6b
+	  /* If we can, constant fold increments so that a chain of
a8cd6b
+	     expressions v + 1 + 1 ... + 1 is not created.
a8cd6b
+	     resolve_expression isn't ideal for this purpose.  The
a8cd6b
+	     base v might not be resolvable until later.  */
a8cd6b
+	  incv.X_op = p_view->X_op;
a8cd6b
+	  incv.X_add_symbol = p_view->X_add_symbol;
a8cd6b
+	  incv.X_add_number = p_view->X_add_number + 1;
a8cd6b
+	}
a8cd6b
 
a8cd6b
       if (viewx.X_op == O_constant)
a8cd6b
 	{