[binutils-gdb] MIPS16/GAS: Reject instructions that end with a dot

Maciej W. Rozycki macro@sourceware.org
Mon Feb 10 22:14:50 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=04e94ec07306efebec091e8f2c9a0dfd7ea5613c

commit 04e94ec07306efebec091e8f2c9a0dfd7ea5613c
Author: Maciej W. Rozycki <macro@orcam.me.uk>
Date:   Mon Feb 10 22:11:25 2025 +0000

    MIPS16/GAS: Reject instructions that end with a dot
    
    Fix a regression from commit 3fb49709438e ("MIPS16/GAS: Fix forced size
    suffixes with argumentless instructions") and reject MIPS16 instructions
    that end with a dot and no forced size suffix following, e.g.:
    
    $ cat test.s
            .set    mips16
    foo:
            break.
            entry.
            addiu.  $2, 0x7fff
            addiu.  $3, $2, 0
            .align  8, 0
    $ as -32 -o test.o test.s
    $ objdump -d test.o
    
    test.o:     file format elf32-tradbigmips
    
    Disassembly of section .text:
    
    00000000 <foo>:
       0:   e805            break
       2:   e809            entry
       4:   f7ef 4a1f       addiu   v0,32767
       8:   4260            addiu   v1,v0,0
            ...
    $
    
    Add a test accordingly, also verifying invalid forced size suffixes.

Diff:
---
 gas/config/tc-mips.c                            | 11 +++++++----
 gas/testsuite/gas/mips/mips.exp                 |  2 ++
 gas/testsuite/gas/mips/mips16-insn-length-bad.d |  3 +++
 gas/testsuite/gas/mips/mips16-insn-length-bad.l | 11 +++++++++++
 gas/testsuite/gas/mips/mips16-insn-length-bad.s | 16 ++++++++++++++++
 5 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 91be392cb4b..c5d36c24558 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -14416,10 +14416,13 @@ mips16_ip (char *str, struct mips_cl_insn *insn)
 	  l = 4;
 	  s++;
 	}
-      if (*s == '\0')
-	break;
-      else if (is_whitespace (*s++))
-	break;
+      if (l != 0)
+	{
+	  if (*s == '\0')
+	    break;
+	  else if (is_whitespace (*s++))
+	    break;
+	}
       set_insn_error (0, _("unrecognized opcode"));
       return;
     }
diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp
index d3877a023a2..4e7a587bfe5 100644
--- a/gas/testsuite/gas/mips/mips.exp
+++ b/gas/testsuite/gas/mips/mips.exp
@@ -1523,6 +1523,8 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "mips16-sprel-swap"
     run_dump_test "mips16-sdrasp"
     run_dump_test "mips16-insn-length-noargs"
+    run_dump_test_arches "mips16-insn-length-bad" \
+					[mips_arch_list_matching mips16-32]
 
     run_dump_test "mips16-branch-unextended-1"
     run_dump_test "mips16-branch-unextended-2"
diff --git a/gas/testsuite/gas/mips/mips16-insn-length-bad.d b/gas/testsuite/gas/mips/mips16-insn-length-bad.d
new file mode 100644
index 00000000000..9e2d3bc1e5d
--- /dev/null
+++ b/gas/testsuite/gas/mips/mips16-insn-length-bad.d
@@ -0,0 +1,3 @@
+#as: -32
+#name: MIPS16 bad instruction size override
+#error_output: mips16-insn-length-bad.l
diff --git a/gas/testsuite/gas/mips/mips16-insn-length-bad.l b/gas/testsuite/gas/mips/mips16-insn-length-bad.l
new file mode 100644
index 00000000000..b955ea71c5e
--- /dev/null
+++ b/gas/testsuite/gas/mips/mips16-insn-length-bad.l
@@ -0,0 +1,11 @@
+.*: Assembler messages:
+.*:3: Error: unrecognized opcode `break\.'
+.*:4: Error: unrecognized opcode `entry\.'
+.*:5: Error: unrecognized opcode `addiu\. \$2,0x7fff'
+.*:6: Error: unrecognized opcode `addiu\. \$3,\$2,0'
+.*:7: Error: unrecognized opcode `exit\.ex'
+.*:8: Error: unrecognized opcode `exit\.tx'
+.*:9: Error: unrecognized opcode `nop\.ey'
+.*:10: Error: unrecognized opcode `nop\.ty'
+.*:11: Error: unrecognized opcode `li\.ez \$2,0'
+.*:12: Error: unrecognized opcode `li\.tz \$2,0'
diff --git a/gas/testsuite/gas/mips/mips16-insn-length-bad.s b/gas/testsuite/gas/mips/mips16-insn-length-bad.s
new file mode 100644
index 00000000000..edff61a2b3f
--- /dev/null
+++ b/gas/testsuite/gas/mips/mips16-insn-length-bad.s
@@ -0,0 +1,16 @@
+	.set	mips16
+foo:
+	break.
+	entry.
+	addiu.	$2, 0x7fff
+	addiu.	$3, $2, 0
+	exit.ex
+	exit.tx
+	nop.ey
+	nop.ty
+	li.ez	$2, 0
+	li.tz	$2, 0
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16


More information about the Binutils-cvs mailing list