public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PR30308, infinite recursion in i386_intel_simplify
Date: Thu, 15 Feb 2024 11:58:16 +1030	[thread overview]
Message-ID: <Zc1osM8Uw97ZVfni@squeak.grove.modra.org> (raw)

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.

diff --git a/gas/config/tc-i386-intel.c b/gas/config/tc-i386-intel.c
index c95af419cf7..3011606d574 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 41f273c85ff..4df83bab0e9 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 3232f1b2a33..c61fabcbe0a 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 *);

-- 
Alan Modra
Australia Development Lab, IBM

             reply	other threads:[~2024-02-15  1:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-15  1:28 Alan Modra [this message]
2024-02-15  9:23 ` Jan Beulich
2024-02-15 10:50   ` Alan Modra
2024-02-15 11:31     ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zc1osM8Uw97ZVfni@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).