[binutils-gdb] PR 30308 yet again

Alan Modra via Binutils-cvs <[email protected]> Thu, 11 Jun 2026 23:48:28 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0f6b256ca84c113a8b06d878f19ed98c40a62b3d

commit 0f6b256ca84c113a8b06d878f19ed98c40a62b3d
Author: Alan Modra <[email protected]>
Date:   Fri Jun 12 08:32:18 2026 +0930

    PR 30308 yet again
    
    Commit cc28c46227cd removed the symbol_resolving recursion guards in
    i386_intel_simplify_symbol.  The testcases we'd considered then just
    involved simple equates, handled by symbol_equated_to.  However, more
    complex expressions can also cause unbounded recursion.  This patch
    restores the recursion guards.
    
            * config/tc-i386-intel.c (i386_intel_simplify_symbol): Add
            recursion guards.
            * testsuite/gas/i386/intel-equ-loop.s,
            * testsuite/gas/i386/intel-equ-loop.l: Extend testcase.

Diff:
---
 gas/config/tc-i386-intel.c              | 5 +++++
 gas/testsuite/gas/i386/intel-equ-loop.l | 2 ++
 gas/testsuite/gas/i386/intel-equ-loop.s | 4 ++++
 3 files changed, 11 insertions(+)

diff --git a/gas/config/tc-i386-intel.c b/gas/config/tc-i386-intel.c
index 77b61d426bc..21d3a333182 100644
--- a/gas/config/tc-i386-intel.c
+++ b/gas/config/tc-i386-intel.c
@@ -383,6 +383,9 @@ i386_intel_simplify_register (expressionS *e)
 static symbolS *
 i386_intel_simplify_symbol (symbolS *sym)
 {
+  if (symbol_resolving_p (sym))
+    return sym;
+
   symbolS *orig = sym;
   offsetT off;
   sym = symbol_equated_to (sym, &off);
@@ -405,7 +408,9 @@ i386_intel_simplify_symbol (symbolS *sym)
   expressionS *e = symbol_get_value_expression (sym);
   expressionS exp;
   memcpy (&exp, e, sizeof exp);
+  symbol_mark_resolving (sym);
   int ret = i386_intel_simplify (&exp);
+  symbol_clear_resolving (sym);
   if (ret == 0)
     return NULL;
 
diff --git a/gas/testsuite/gas/i386/intel-equ-loop.l b/gas/testsuite/gas/i386/intel-equ-loop.l
index 76ca03a43df..90dfa9623db 100644
--- a/gas/testsuite/gas/i386/intel-equ-loop.l
+++ b/gas/testsuite/gas/i386/intel-equ-loop.l
@@ -5,4 +5,6 @@
 .*: Error: can't resolve .*
 .*: Error: symbol definition loop .*
 .*: Error: can't resolve .*
+.*: Error: symbol definition loop .*
+.*: Error: can't resolve .*
 #pass
diff --git a/gas/testsuite/gas/i386/intel-equ-loop.s b/gas/testsuite/gas/i386/intel-equ-loop.s
index bb0cce8f413..02b2d3f44ff 100644
--- a/gas/testsuite/gas/i386/intel-equ-loop.s
+++ b/gas/testsuite/gas/i386/intel-equ-loop.s
@@ -14,3 +14,7 @@
 	d = 1
 	e = 2
 	mov eax, [x]
+
+	f = g + 1
+	g = f - 1
+	mov eax, [f]