This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] MIPS16/GAS: Improve disallowed relocation operand error diagnostics
- From: Maciej W.Rozycki <macro at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 15 May 2017 13:25:17 -0000
- Subject: [binutils-gdb] MIPS16/GAS: Improve disallowed relocation operand error diagnostics
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e295202f606accec7623c961997a295a8e680247
commit e295202f606accec7623c961997a295a8e680247
Author: Maciej W. Rozycki <macro@imgtec.com>
Date: Mon May 15 13:09:37 2017 +0100
MIPS16/GAS: Improve disallowed relocation operand error diagnostics
Improve disallowed relocation operand error diagnostics for MIPS16 code
and make it match corresponding regular MIPS and microMIPS handling,
e.g:
$ cat sltu.s
sltu $2, %lo(foo)
$ as -o sltu.o sltu.s
sltu.s: Assembler messages:
sltu.s:1: Error: operand 2 must be constant `sltu $2,%lo(foo)'
$ as -mips16 -o sltu.o sltu.s
sltu.s: Assembler messages:
sltu.s:1: Error: invalid operands `sltu $2,%lo(foo)'
$
To do so call `match_not_constant' from `match_mips16_insn' whenever a
disallowed relocation operation has been noticed, like `match_const_int'
does, making reporting consistent:
$ as -mips16 -o sltu.o sltu.s
sltu.s: Assembler messages:
sltu.s:1: Error: operand 2 must be constant `sltu $2,%lo(foo)'
$
gas/
* config/tc-mips.c (match_mips16_insn): Call
`match_not_constant' for a disallowed relocation operation.
* testsuite/gas/mips/mips16-reloc-error.d: New test.
* testsuite/gas/mips/mips16-reloc-error.l: New stderr output.
* testsuite/gas/mips/mips16-reloc-error.s: New test source.
* testsuite/gas/mips/mips.exp: Run the new test.
Diff:
---
gas/ChangeLog | 9 +++++
gas/config/tc-mips.c | 5 ++-
gas/testsuite/gas/mips/mips.exp | 2 ++
gas/testsuite/gas/mips/mips16-reloc-error.d | 3 ++
gas/testsuite/gas/mips/mips16-reloc-error.l | 28 ++++++++++++++++
gas/testsuite/gas/mips/mips16-reloc-error.s | 52 +++++++++++++++++++++++++++++
6 files changed, 98 insertions(+), 1 deletion(-)
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 4aca584..65a4577 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,5 +1,14 @@
2017-05-15 Maciej W. Rozycki <macro@imgtec.com>
+ * config/tc-mips.c (match_mips16_insn): Call
+ `match_not_constant' for a disallowed relocation operation.
+ * testsuite/gas/mips/mips16-reloc-error.d: New test.
+ * testsuite/gas/mips/mips16-reloc-error.l: New stderr output.
+ * testsuite/gas/mips/mips16-reloc-error.s: New test source.
+ * testsuite/gas/mips/mips.exp: Run the new test.
+
+2017-05-15 Maciej W. Rozycki <macro@imgtec.com>
+
* testsuite/gas/mips/lui-1.d: New test.
* testsuite/gas/mips/lui-2.d: New test.
* gas/testsuite/gas/mips/mips.exp: Fold corresponding list tests
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 27ce043..0932cea 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -8259,7 +8259,10 @@ match_mips16_insn (struct mips_cl_insn *insn, const struct mips_opcode *opcode,
been allowed to take relocation operators. */
if (offset_reloc[0] != BFD_RELOC_UNUSED
&& (ext_operand->size != 16 || c == '8'))
- return FALSE;
+ {
+ match_not_constant (&arg);
+ return FALSE;
+ }
relax_char = c;
continue;
diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp
index cdc39df..c0bdd77 100644
--- a/gas/testsuite/gas/mips/mips.exp
+++ b/gas/testsuite/gas/mips/mips.exp
@@ -967,6 +967,8 @@ if { [istarget mips*-*-vxworks*] } {
run_dump_test "mips16-hilo-n32"
}
run_dump_test "mips16-hilo-match"
+ run_dump_test "mips16-reloc-error"
+
run_dump_test "delay"
run_dump_test "nodelay"
run_dump_test "mips4010"
diff --git a/gas/testsuite/gas/mips/mips16-reloc-error.d b/gas/testsuite/gas/mips/mips16-reloc-error.d
new file mode 100644
index 0000000..1129a65
--- /dev/null
+++ b/gas/testsuite/gas/mips/mips16-reloc-error.d
@@ -0,0 +1,3 @@
+#name: MIPS16 relocation errors
+#as: -32 -mips64r2
+#error-output: mips16-reloc-error.l
diff --git a/gas/testsuite/gas/mips/mips16-reloc-error.l b/gas/testsuite/gas/mips/mips16-reloc-error.l
new file mode 100644
index 0000000..a107604
--- /dev/null
+++ b/gas/testsuite/gas/mips/mips16-reloc-error.l
@@ -0,0 +1,28 @@
+.*: Assembler messages:
+.*:11: Error: operand 3 must be constant `addiu \$3,\$2,%lo\(bar\)'
+.*:12: Error: operand 3 must be constant `daddiu \$3,\$2,%lo\(bar\)'
+.*:14: Error: operand 2 must be constant `slti \$3,%lo\(bar\)'
+.*:15: Error: operand 2 must be constant `sltiu \$3,%lo\(bar\)'
+.*:17: Error: operand 3 must be constant `sll \$3,\$2,%lo\(bar\)'
+.*:18: Error: operand 3 must be constant `sra \$3,\$2,%lo\(bar\)'
+.*:19: Error: operand 3 must be constant `srl \$3,\$2,%lo\(bar\)'
+.*:20: Error: operand 3 must be constant `dsll \$3,\$2,%lo\(bar\)'
+.*:21: Error: operand 2 must be constant `dsra \$3,%lo\(bar\)'
+.*:22: Error: operand 2 must be constant `dsrl \$3,%lo\(bar\)'
+.*:24: Error: operand 1 must be constant `break %lo\(bar\)'
+.*:25: Error: operand 1 must be constant `sdbbp %lo\(bar\)'
+.*:27: Error: invalid operands `b %lo\(bar\)'
+.*:28: Error: invalid operands `beqz \$3,%lo\(bar\)'
+.*:29: Error: invalid operands `bnez \$3,%lo\(bar\)'
+.*:30: Error: invalid operands `bteqz %lo\(bar\)'
+.*:31: Error: invalid operands `btnez %lo\(bar\)'
+.*:33: Error: invalid operands `jal %lo\(bar\)'
+.*:34: Error: invalid operands `jalx %lo\(bar\)'
+.*:36: Error: operand 3 must be constant `save \$31,\$16,%lo\(bar\)'
+.*:37: Error: operand 3 must be constant `restore \$31,\$16,%lo\(bar\)'
+.*:39: Error: operand 6 must be constant `asmacro 0,0,0,0,0,%lo\(bar\)'
+.*:40: Error: operand 5 must be constant `asmacro 0,0,0,0,%lo\(bar\),0'
+.*:41: Error: operand 4 must be constant `asmacro 0,0,0,%lo\(bar\),0,0'
+.*:42: Error: operand 3 must be constant `asmacro 0,0,%lo\(bar\),0,0,0'
+.*:43: Error: operand 2 must be constant `asmacro 0,%lo\(bar\),0,0,0,0'
+.*:44: Error: operand 1 must be constant `asmacro %lo\(bar\),0,0,0,0,0'
diff --git a/gas/testsuite/gas/mips/mips16-reloc-error.s b/gas/testsuite/gas/mips/mips16-reloc-error.s
new file mode 100644
index 0000000..f826682
--- /dev/null
+++ b/gas/testsuite/gas/mips/mips16-reloc-error.s
@@ -0,0 +1,52 @@
+ .text
+
+ .set bar, 8
+
+ .ent foo
+ .set mips16
+foo:
+ li $2, %hi(bar)
+ sll $2, $2, 16
+
+ addiu $3, $2, %lo(bar)
+ daddiu $3, $2, %lo(bar)
+
+ slti $3, %lo(bar)
+ sltiu $3, %lo(bar)
+
+ sll $3, $2, %lo(bar)
+ sra $3, $2, %lo(bar)
+ srl $3, $2, %lo(bar)
+ dsll $3, $2, %lo(bar)
+ dsra $3, %lo(bar)
+ dsrl $3, %lo(bar)
+
+ break %lo(bar)
+ sdbbp %lo(bar)
+
+ b %lo(bar)
+ beqz $3, %lo(bar)
+ bnez $3, %lo(bar)
+ bteqz %lo(bar)
+ btnez %lo(bar)
+
+ jal %lo(bar)
+ jalx %lo(bar)
+
+ save $31, $16, %lo(bar)
+ restore $31, $16, %lo(bar)
+
+ asmacro 0, 0, 0, 0, 0, %lo(bar)
+ asmacro 0, 0, 0, 0, %lo(bar), 0
+ asmacro 0, 0, 0, %lo(bar), 0, 0
+ asmacro 0, 0, %lo(bar), 0, 0, 0
+ asmacro 0, %lo(bar), 0, 0, 0, 0
+ asmacro %lo(bar), 0, 0, 0, 0, 0
+
+ nop
+ .set nomips16
+ .end foo
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+ .align 4, 0
+ .space 16