]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Constant fold view increment expressions
authorAlan Modra <amodra@gmail.com>
Tue, 8 Mar 2022 12:18:51 +0000 (22:48 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 9 Mar 2022 05:20:34 +0000 (15:50 +1030)
The idea here is to replace expressions like v + 1 + 1 + 1 with v + 3.

* dwarf2dbg.c (set_or_check_view): Remove useless assertion.
Resolve multiple view increments.
* testsuite/gas/elf/dwarf2-18.d: Don't xfail mep.

gas/dwarf2dbg.c
gas/testsuite/gas/elf/dwarf2-18.d

index 7269c4cdf87677abb6361468f95a6dc567c05283..ba97b5f0126695f23f929d2e6512f31322925781 100644 (file)
@@ -402,18 +402,27 @@ set_or_check_view (struct line_entry *e, struct line_entry *p,
   if (viewx.X_op != O_constant || viewx.X_add_number)
     {
       expressionS incv;
+      expressionS *p_view;
 
       if (!p->loc.u.view)
-       {
-         p->loc.u.view = symbol_temp_make ();
-         gas_assert (!S_IS_DEFINED (p->loc.u.view));
-       }
+       p->loc.u.view = symbol_temp_make ();
 
       memset (&incv, 0, sizeof (incv));
       incv.X_unsigned = 1;
       incv.X_op = O_symbol;
       incv.X_add_symbol = p->loc.u.view;
       incv.X_add_number = 1;
+      p_view = symbol_get_value_expression (p->loc.u.view);
+      if (p_view->X_op == O_constant || p_view->X_op == O_symbol)
+       {
+         /* If we can, constant fold increments so that a chain of
+            expressions v + 1 + 1 ... + 1 is not created.
+            resolve_expression isn't ideal for this purpose.  The
+            base v might not be resolvable until later.  */
+         incv.X_op = p_view->X_op;
+         incv.X_add_symbol = p_view->X_add_symbol;
+         incv.X_add_number = p_view->X_add_number + 1;
+       }
 
       if (viewx.X_op == O_constant)
        {
index db7a4f9f20b5d83df5bc94ae62d991e32f164ee3..fbaebaa901916858988b0b0859c8c36ab7008000 100644 (file)
@@ -2,9 +2,8 @@
 #readelf: -x.rodata -wL
 #name: DWARF2 18
 # The am33 cr16 crx ft32 mn10 msp430 nds32 and rl78 targets do not evaluate the subtraction of symbols at assembly time.
-# The mep targets turns some view computations into complex relocations.
 # The riscv targets do not support the subtraction of symbols.
-#xfail: am3*-* cr16-* crx-* ft32*-* mep-* mn10*-* msp430-* nds32*-* riscv*-* rl78-*
+#xfail: am3*-* cr16-* crx-* ft32*-* mn10*-* msp430-* nds32*-* riscv*-* rl78-*
 
 Hex dump of section '\.rodata':
   0x00000000 0100 *.*