[PATCH] xtensa: fix MAX_ISTACK for loopgtz L32R widening

Alexey Lapshin <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
Commit 403b0b61f6d4 ("gas: use literals/const16 for xtensa loop
relaxation") replaced loop widening with an L32R-based sequence.
The loopgtz variant of that sequence needs 13 istack entries, but
MAX_ISTACK remained 12, so relaxation of an out-of-range loopgtz
overflowed the instruction stack. Increase MAX_ISTACK and report
overflow with as_fatal that names MAX_ISTACK. Add a test.

gas/
	* config/xtensa-istack.h (MAX_ISTACK): Increase to 16. Document
	requirement.
	* config/tc-xtensa.c (istack_push, istack_push_space): Report
	stack overflow with as_fatal.
	* testsuite/gas/xtensa/loopgtz-relax.d: New test.
	* testsuite/gas/xtensa/loopgtz-relax.s: New test source.
---
 gas/config/tc-xtensa.c                   |  8 ++++++--
 gas/config/xtensa-istack.h               |  5 ++++-
 gas/testsuite/gas/xtensa/loopgtz-relax.d | 16 ++++++++++++++++
 gas/testsuite/gas/xtensa/loopgtz-relax.s | 10 ++++++++++
 4 files changed, 36 insertions(+), 3 deletions(-)
 create mode 100644 gas/testsuite/gas/xtensa/loopgtz-relax.d
 create mode 100644 gas/testsuite/gas/xtensa/loopgtz-relax.s

diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c
index deecbb143d0..0a360223c68 100644
--- a/gas/config/tc-xtensa.c
+++ b/gas/config/tc-xtensa.c
@@ -12517,7 +12517,9 @@ void
 istack_push (IStack *stack, TInsn *insn)
 {
   int rec = stack->ninsn;
-  gas_assert (!istack_full (stack));
+  if (istack_full (stack))
+    as_fatal (_("internal error: instruction stack overflow; "
+		"increase MAX_ISTACK"));
   stack->insn[rec] = *insn;
   stack->ninsn++;
 }
@@ -12531,7 +12533,9 @@ istack_push_space (IStack *stack)
 {
   int rec = stack->ninsn;
   TInsn *insn;
-  gas_assert (!istack_full (stack));
+  if (istack_full (stack))
+    as_fatal (_("internal error: instruction stack overflow; "
+		"increase MAX_ISTACK"));
   insn = &stack->insn[rec];
   tinsn_init (insn);
   stack->ninsn++;
diff --git a/gas/config/xtensa-istack.h b/gas/config/xtensa-istack.h
index 524f7fa774f..cdea1700842 100644
--- a/gas/config/xtensa-istack.h
+++ b/gas/config/xtensa-istack.h
@@ -23,7 +23,10 @@
 
 #include "xtensa-isa.h"
 
-#define MAX_ISTACK 12
+/* Must hold the largest multi-instruction widening expansion from
+   widen_spec_list in xtensa-relax.c.  Currently that is the loopgtz
+   + L32R sequence (13 entries including LITERAL and LABEL).  */
+#define MAX_ISTACK 16
 #define MAX_INSN_ARGS 64
 
 enum itype_enum
diff --git a/gas/testsuite/gas/xtensa/loopgtz-relax.d b/gas/testsuite/gas/xtensa/loopgtz-relax.d
new file mode 100644
index 00000000000..1374186c6d6
--- /dev/null
+++ b/gas/testsuite/gas/xtensa/loopgtz-relax.d
@@ -0,0 +1,16 @@
+#as:
+#objdump: -d
+
+#...
+.*beqz.*a9,.*
+.*bltz.*a9,.*
+.*loopgtz.*a9,.*
+.*rsr.lend.*a9
+.*wsr.lbeg.*a9
+.*l32r.*a9,.*
+.*nop
+.*wsr.lend.*a9
+.*isync
+.*rsr.lcount.*a9
+.*addi.*a9, a9, 1
+#...
diff --git a/gas/testsuite/gas/xtensa/loopgtz-relax.s b/gas/testsuite/gas/xtensa/loopgtz-relax.s
new file mode 100644
index 00000000000..a03528f306c
--- /dev/null
+++ b/gas/testsuite/gas/xtensa/loopgtz-relax.s
@@ -0,0 +1,10 @@
+	.text
+	.globl main
+	.align 4
+main:
+	loopgtz a9, .Lloop_end
+	.rep 200
+	nop
+	.endr
+.Lloop_end:
+	nop
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.