x86/Intel: avoid infinite recursion in i386_intel_simplify_symbol() (again)

Message ID 6c7ea50b-2bd6-45b8-9112-e452b5a2c376@suse.com
State New
Headers
Series x86/Intel: avoid infinite recursion in i386_intel_simplify_symbol() (again) |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Beulich May 8, 2026, 8:10 a.m. UTC
  PR gas/30308

The same problem has appeared again due to insufficient use of the
"resolving" property (respective helpers originally introduced for this
PR) in 22f8905d9f38 ("x86/Intel: don't modify equates' expressions").

Also put in place a testcase, so this (hopefully) won't regress again.
  

Comments

Jan Beulich May 8, 2026, 9:03 a.m. UTC | #1
On 08.05.2026 10:10, Jan Beulich wrote:
> --- /dev/null
> +++ b/gas/testsuite/gas/i386/intel-equ-loop.l
> @@ -0,0 +1,4 @@
> +.*: Assembler messages:
> +.*:4: Error: .*
> +.*:8: Error: .*
> +#pass

This fails for (at least) COFF/PE targets when as is passed --32. There looks
to be a separate issue there, but ...

> --- /dev/null
> +++ b/gas/testsuite/gas/i386/intel-equ-loop.s
> @@ -0,0 +1,8 @@
> +	.intel_syntax

... "noprefix" was missing here anyway (for Intel syntax this really should
be the default), hence ...

> +
> +	a = a
> +	mov eax, [a]
> +
> +	b = c
> +	c = b
> +	mov eax, [c]

... the two MOVs fail to assemble for other reasons. This works better
(and covers another sub-aspect):

--- /dev/null
+++ b/gas/testsuite/gas/i386/intel-equ-loop.l
@@ -0,0 +1,6 @@
+.*: Assembler messages:
+.*: Error: symbol definition loop .*
+.*: Error: can't resolve .*
+.*: Error: symbol definition loop .*
+.*: Error: can't resolve .*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/i386/intel-equ-loop.s
@@ -0,0 +1,9 @@
+	.intel_syntax noprefix
+
+	a = a
+	mov eax, [a]
+
+	b = c
+	c = b
+	mov eax, [b]
+	mov eax, [c]

Jan
  

Patch

--- a/gas/config/tc-i386-intel.c
+++ b/gas/config/tc-i386-intel.c
@@ -383,6 +383,8 @@  i386_intel_simplify_register (expression
 static symbolS *
 i386_intel_simplify_symbol (symbolS *sym, bool in_equate)
 {
+  symbolS *orig = NULL;
+
   if (symbol_resolving_p (sym))
     return sym;
 
@@ -396,7 +398,9 @@  i386_intel_simplify_symbol (symbolS *sym
       if (symbol_on_chain(sym, symbol_rootP, symbol_lastP))
 	{
 	  in_equate = true;
+	  orig = sym;
 	  sym = symbol_clone (sym, 0);
+	  symbol_mark_resolving (orig);
 	}
       else if (in_equate)
 	{
@@ -405,6 +409,8 @@  i386_intel_simplify_symbol (symbolS *sym
 	  if (e->X_op == O_symbol && !e->X_add_number)
 	    {
 	      sym = e->X_add_symbol;
+	      if (symbol_resolving_p (sym))
+		return sym;
 	      continue;
 	    }
 	  sym = make_expr_symbol (e);
@@ -419,6 +425,9 @@  i386_intel_simplify_symbol (symbolS *sym
     S_SET_SEGMENT (sym, absolute_section);
   symbol_clear_resolving (sym);
 
+  if (orig)
+    symbol_clear_resolving (orig);
+
   return ret ? sym : NULL;
 }
 
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -63,6 +63,7 @@  if [gas_32_check] then {
     run_dump_test "opcode-suffix"
     run_dump_test "intel"
     run_dump_test "intel-intel"
+    run_list_test "intel-equ-loop"
     run_dump_test "intel16"
     run_list_test "intelbad" ""
     run_dump_test "intelok"
--- /dev/null
+++ b/gas/testsuite/gas/i386/intel-equ-loop.l
@@ -0,0 +1,4 @@ 
+.*: Assembler messages:
+.*:4: Error: .*
+.*:8: Error: .*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/i386/intel-equ-loop.s
@@ -0,0 +1,8 @@ 
+	.intel_syntax
+
+	a = a
+	mov eax, [a]
+
+	b = c
+	c = b
+	mov eax, [c]