[v2] gas: fix MAX_ISTACK for loopgtz L32R widening
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
Commit Message
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
Comments
On Tue, Aug 25, 2026 at 12:46 AM Alexey Lapshin
<alexey.lapshin@espressif.com> wrote:
>
> 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
Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.
@@ -12520,7 +12520,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++;
}
@@ -12534,7 +12536,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++;
@@ -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
new file mode 100644
@@ -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
+#...
new file mode 100644
@@ -0,0 +1,10 @@
+ .text
+ .globl main
+ .align 4
+main:
+ loopgtz a9, .Lloop_end
+ .rep 200
+ nop
+ .endr
+.Lloop_end:
+ nop