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

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