This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[committed 1/5] MIPS16/GAS: Improve disallowed relocation operand error diagnostics
- From: "Maciej W. Rozycki" <macro at imgtec dot com>
- To: <binutils at sourceware dot org>
- Date: Mon, 15 May 2017 14:29:48 +0100
- Subject: [committed 1/5] MIPS16/GAS: Improve disallowed relocation operand error diagnostics
- Authentication-results: sourceware.org; auth=none
- References: <alpine.DEB.2.00.1705102025580.2590@tp.orcam.me.uk>
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.
---
binutils-mips16-gas-not-const-err.diff
Index: binutils/gas/config/tc-mips.c
===================================================================
--- binutils.orig/gas/config/tc-mips.c 2017-05-12 08:47:14.978493693 +0100
+++ binutils/gas/config/tc-mips.c 2017-05-12 13:21:55.457157986 +0100
@@ -8259,7 +8259,10 @@ match_mips16_insn (struct mips_cl_insn *
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;
Index: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp 2017-05-12 08:45:42.614003991 +0100
+++ binutils/gas/testsuite/gas/mips/mips.exp 2017-05-12 13:21:55.470317153 +0100
@@ -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"
Index: binutils/gas/testsuite/gas/mips/mips16-reloc-error.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-reloc-error.d 2017-05-12 10:44:47.552787860 +0100
@@ -0,0 +1,3 @@
+#name: MIPS16 relocation errors
+#as: -32 -mips64r2
+#error-output: mips16-reloc-error.l
Index: binutils/gas/testsuite/gas/mips/mips16-reloc-error.l
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-reloc-error.l 2017-05-12 08:50:06.106927914 +0100
@@ -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'
Index: binutils/gas/testsuite/gas/mips/mips16-reloc-error.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-reloc-error.s 2017-05-12 08:50:06.127143451 +0100
@@ -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