[binutils-gdb] Re: PR 30308 more unbounded recursion
Alan Modra via Binutils-cvs <[email protected]> Thu, 30 Jul 2026 07:35:09 +0000 (GMT)
| Newsgroups | gmane.comp.gnu.binutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0d22d419a4b6= 0672acf5555f5479fcf6956018a1 commit 0d22d419a4b60672acf5555f5479fcf6956018a1 Author: Alan Modra <[email protected]> Date: Thu Jul 30 15:02:21 2026 +0930 Re: PR 30308 more unbounded recursion =20 Commit 85fb82cc8c had some errors. The extra places marking and clearing syms as resolving didn't take into account that the sym might already be so marked and thus should not be cleared. Fixing that cured the first testcase addition, but not the second. Even worse is that fact that marking X_add_symbol when trying to simplify X_op_symbol would make it impossible to simplify x=3D=3Dx or other such expressions where the symbols are the same (or the same via equates, making a test for X_add_symbol !=3D X_op_symbol harder). So commit 85fb82cc8c needs reverting. =20 When I analysed what was going on with the second testcase addition, and reanalysed the testcase added in commit 85fb82cc8c, I decided a better fix was to immediately fail on hitting a symbol loop; It was the simplification done in i386_intel_simplify_symbol after hitting a symbol loop that made the "resolving" mark set on syms insufficient. =20 * config/tc-i386-intel.c (i386_intel_simplify_symbol): Return NULL on finding symbol loops. (i386_intel_simplify): Revert commit 85fb82cc8c marking and clearing "resolved" for X_add_symbol. For O_add, don't simplify after i386_intel_simplify_symbol returns NULL. * testsuite/gas/i386/intel-equ-loop.l, * testsuite/gas/i386/intel-equ-loop.s: Extend testcase. Diff: --- gas/config/tc-i386-intel.c | 59 ++++++++++++++---------------= ---- gas/testsuite/gas/i386/intel-equ-loop.l | 7 ++++ gas/testsuite/gas/i386/intel-equ-loop.s | 6 ++++ 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/gas/config/tc-i386-intel.c b/gas/config/tc-i386-intel.c index aafaaba0c9a..aee19446c8c 100644 --- a/gas/config/tc-i386-intel.c +++ b/gas/config/tc-i386-intel.c @@ -384,12 +384,14 @@ static symbolS * i386_intel_simplify_symbol (symbolS *sym) { if (symbol_resolving_p (sym)) - return sym; + return NULL; =20 symbolS *orig =3D sym; offsetT off; sym =3D symbol_equated_to (sym, &off); - if (sym =3D=3D NULL || off !=3D 0) + if (sym =3D=3D NULL) + return NULL; + if (off !=3D 0) return orig; =20 segT seg =3D S_GET_SEGMENT (sym); @@ -443,13 +445,10 @@ i386_intel_simplify (expressionS *e) intel_state.index)) return 0; e->X_add_symbol =3D newsym; - symbol_mark_resolving (e->X_add_symbol); } if (!intel_state.in_offset) ++intel_state.in_bracket; newsym =3D i386_intel_simplify_symbol (e->X_op_symbol); - if (e->X_add_symbol) - symbol_clear_resolving (e->X_add_symbol); if (!intel_state.in_offset) --intel_state.in_bracket; if (!newsym) @@ -549,35 +548,31 @@ i386_intel_simplify (expressionS *e) segT leftseg =3D NULL, rightseg =3D NULL; =20 newsym =3D i386_intel_simplify_symbol (e->X_add_symbol); - if (newsym) - { - e->X_add_symbol =3D newsym; + if (!newsym) + return 0; + e->X_add_symbol =3D newsym; =20 - if (base !=3D intel_state.base || state_index !=3D intel_state.inde= x) - { - base =3D intel_state.base; - state_index =3D intel_state.index; - left =3D symbol_get_value_expression (newsym); - resolve_expression (left); - leftseg =3D S_GET_SEGMENT (newsym); - } + if (base !=3D intel_state.base || state_index !=3D intel_state.index) + { + base =3D intel_state.base; + state_index =3D intel_state.index; + left =3D symbol_get_value_expression (newsym); + resolve_expression (left); + leftseg =3D S_GET_SEGMENT (newsym); } =20 - symbol_mark_resolving (e->X_add_symbol); newsym =3D i386_intel_simplify_symbol (e->X_op_symbol); - symbol_clear_resolving (e->X_add_symbol); - if (newsym) - { - e->X_op_symbol =3D newsym; + if (!newsym) + return 0; + e->X_op_symbol =3D newsym; =20 - if (base !=3D intel_state.base || state_index !=3D intel_state.inde= x) - { - base =3D intel_state.base; - state_index =3D intel_state.index; - right =3D symbol_get_value_expression (newsym); - resolve_expression (right); - rightseg =3D S_GET_SEGMENT (newsym); - } + if (base !=3D intel_state.base || state_index !=3D intel_state.index) + { + base =3D intel_state.base; + state_index =3D intel_state.index; + right =3D symbol_get_value_expression (newsym); + resolve_expression (right); + rightseg =3D S_GET_SEGMENT (newsym); } =20 if (left && right @@ -622,9 +617,7 @@ i386_intel_simplify (expressionS *e) other =3D symbol_get_value_expression (e->X_add_symbol); } =20 - symbol_mark_resolving (e->X_add_symbol); newsym =3D i386_intel_simplify_symbol (e->X_op_symbol); - symbol_clear_resolving (e->X_add_symbol); } =20 if (newsym) @@ -726,11 +719,7 @@ i386_intel_simplify (expressionS *e) return 0; if (e->X_op_symbol) { - if (e->X_add_symbol) - symbol_mark_resolving (e->X_add_symbol); newsym =3D i386_intel_simplify_symbol (e->X_op_symbol); - if (e->X_add_symbol) - symbol_clear_resolving (e->X_add_symbol); if (!newsym) return 0; e->X_op_symbol =3D newsym; diff --git a/gas/testsuite/gas/i386/intel-equ-loop.l b/gas/testsuite/gas/i3= 86/intel-equ-loop.l index 03f21082c3f..18a1bc93abc 100644 --- a/gas/testsuite/gas/i386/intel-equ-loop.l +++ b/gas/testsuite/gas/i386/intel-equ-loop.l @@ -9,4 +9,11 @@ .*: Error: can't resolve .* .*: Error: symbol definition loop .* .*: 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/i3= 86/intel-equ-loop.s index f7d1d63395b..f68cb596c8c 100644 --- a/gas/testsuite/gas/i386/intel-equ-loop.s +++ b/gas/testsuite/gas/i386/intel-equ-loop.s @@ -23,3 +23,9 @@ j=3Dh i=3Dj+h .int i + + k=3Dk+esi + mov [k],al + + l=3Dl+edx + mov [2*l+edx],al