aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2024-02-15 11:12:01 +1030
committerAlan Modra <amodra@gmail.com>2024-02-15 11:24:13 +1030
commit2fbbadc2c336cad228be998a118e3bab3be30757 (patch)
treeff430b7baafaabf784d228c71918b0be9f9cf6d2
parentcf95b909e2c29476525da29bfb4f0d2c8211e8b6 (diff)
downloadgdb-2fbbadc2c336cad228be998a118e3bab3be30757.zip
gdb-2fbbadc2c336cad228be998a118e3bab3be30757.tar.gz
gdb-2fbbadc2c336cad228be998a118e3bab3be30757.tar.bz2
PR30308, infinite recursion in i386_intel_simplify
This patch exposes the symbol "resolving" flag for use in i386_intel_simplify, not only preventing infinite recursion on the testcase in the PR but also more complicated cases like: .intel_syntax b = a a = b mov eax, [a] PR 30308 * symbols.c (symbol_mark_resolving, symbol_clear_resolving), (symbol_resolving_p): New functions. * symbols.h: Declare them. * config/tc-i386-intel.c (i386_intel_simplify): Delete forward declaration. Formatting. (i386_intel_simplify_symbol): Use resolving flag to prevent infinite recursion.
-rw-r--r--gas/config/tc-i386-intel.c22
-rw-r--r--gas/symbols.c24
-rw-r--r--gas/symbols.h3
3 files changed, 39 insertions, 10 deletions
diff --git a/gas/config/tc-i386-intel.c b/gas/config/tc-i386-intel.c
index c95af41..3011606 100644
--- a/gas/config/tc-i386-intel.c
+++ b/gas/config/tc-i386-intel.c
@@ -369,21 +369,25 @@ i386_intel_simplify_register (expressionS *e)
return 2;
}
-static int i386_intel_simplify (expressionS *);
-
-static INLINE int i386_intel_simplify_symbol(symbolS *sym)
+static int
+i386_intel_simplify_symbol (symbolS *sym)
{
- int ret = i386_intel_simplify (symbol_get_value_expression (sym));
+ if (symbol_resolving_p (sym))
+ return 1;
+ symbol_mark_resolving (sym);
+ int ret = i386_intel_simplify (symbol_get_value_expression (sym));
if (ret == 2)
- {
- S_SET_SEGMENT(sym, absolute_section);
- ret = 1;
- }
+ {
+ S_SET_SEGMENT (sym, absolute_section);
+ ret = 1;
+ }
+ symbol_clear_resolving (sym);
return ret;
}
-static int i386_intel_simplify (expressionS *e)
+static int
+i386_intel_simplify (expressionS *e)
{
const reg_entry *the_reg = (this_operand >= 0
? i.op[this_operand].regs : NULL);
diff --git a/gas/symbols.c b/gas/symbols.c
index 41f273c..4df83ba 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -2936,7 +2936,7 @@ symbol_removed_p (symbolS *s)
return s->flags.removed;
}
-/* Mark a symbol has having been resolved. */
+/* Mark a symbol as having been resolved. */
void
symbol_mark_resolved (symbolS *s)
@@ -2952,6 +2952,28 @@ symbol_resolved_p (symbolS *s)
return s->flags.resolved;
}
+/* Mark a symbol as being resolved. */
+
+void
+symbol_mark_resolving (symbolS *s)
+{
+ s->flags.resolving = 1;
+}
+
+void
+symbol_clear_resolving (symbolS *s)
+{
+ s->flags.resolving = 0;
+}
+
+/* Return whether a symbol is being resolved. */
+
+int
+symbol_resolving_p (symbolS *s)
+{
+ return s->flags.resolving;
+}
+
/* Return whether a symbol is a section symbol. */
int
diff --git a/gas/symbols.h b/gas/symbols.h
index 3232f1b..c61fabc 100644
--- a/gas/symbols.h
+++ b/gas/symbols.h
@@ -206,6 +206,9 @@ extern void symbol_mark_removed (symbolS *);
extern int symbol_removed_p (symbolS *);
extern void symbol_mark_resolved (symbolS *);
extern int symbol_resolved_p (symbolS *);
+extern void symbol_mark_resolving (symbolS *);
+extern void symbol_clear_resolving (symbolS *);
+extern int symbol_resolving_p (symbolS *);
extern int symbol_section_p (symbolS *);
extern int symbol_equated_p (symbolS *);
extern int symbol_equated_reloc_p (symbolS *);