From: Maciej W. Rozycki Date: Fri, 23 Dec 2016 18:06:55 +0000 (+0000) Subject: MIPS16/GAS: Clean up invalid unextended operand handling X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1da43accb4f8e2a19dc033b617982e3c2dc83a08;p=binutils-gdb.git MIPS16/GAS: Clean up invalid unextended operand handling Bail out right away when an unextended instruction encoding is required either with the use of a `.t' suffix or by means of `.set noautoextend', however an operand supplied requires the extended instruction form to be used. This is to avoid messing up with the internal state of the assembler, even though no actual failures are known to happen as a result. Add test cases for the situation concerned. gas/ * config/tc-mips.c (match_mips16_insn): Don't update `forced_insn_length' or the instruction opcode if an operand requires an extended instruction form, but an unextended one has been requested. * testsuite/gas/mips/mips16-relax-unextended-1.d: New test. * testsuite/gas/mips/mips16-relax-unextended-2.d: New test. * testsuite/gas/mips/mips16-relax-unextended-1.l: New stderr output. * testsuite/gas/mips/mips16-relax-unextended-2.l: New stderr output. * testsuite/gas/mips/mips16-relax-unextended-1.s: New test source. * testsuite/gas/mips/mips16-relax-unextended-2.s: New test source. * testsuite/gas/mips/mips.exp: Run the new tests. --- diff --git a/gas/ChangeLog b/gas/ChangeLog index b181f0ccc0b..2d0f4b104de 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,21 @@ +2016-12-23 Maciej W. Rozycki + + * config/tc-mips.c (match_mips16_insn): Don't update + `forced_insn_length' or the instruction opcode if an operand + requires an extended instruction form, but an unextended one + has been requested. + * testsuite/gas/mips/mips16-relax-unextended-1.d: New test. + * testsuite/gas/mips/mips16-relax-unextended-2.d: New test. + * testsuite/gas/mips/mips16-relax-unextended-1.l: New stderr + output. + * testsuite/gas/mips/mips16-relax-unextended-2.l: New stderr + output. + * testsuite/gas/mips/mips16-relax-unextended-1.s: New test + source. + * testsuite/gas/mips/mips16-relax-unextended-2.s: New test + source. + * testsuite/gas/mips/mips.exp: Run the new tests. + 2016-12-23 Maciej W. Rozycki * config/tc-mips.c (mips16_macro_build): Replace `0' and `4' diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index e6b8c1bbc83..20e8020bda4 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -8136,8 +8136,11 @@ match_mips16_insn (struct mips_cl_insn *insn, const struct mips_opcode *opcode, { if (required_insn_length == 2) set_insn_error (0, _("invalid unextended operand value")); - forced_insn_length = 4; - insn->insn_opcode |= MIPS16_EXTEND; + else + { + forced_insn_length = 4; + insn->insn_opcode |= MIPS16_EXTEND; + } } else if (relax_char) *offset_reloc = (int) BFD_RELOC_UNUSED + relax_char; diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp index 60d956ddfea..678e8d9eb7d 100644 --- a/gas/testsuite/gas/mips/mips.exp +++ b/gas/testsuite/gas/mips/mips.exp @@ -1352,6 +1352,8 @@ if { [istarget mips*-*-vxworks*] } { run_dump_test "mips16-branch-unextended-1" run_dump_test "mips16-branch-unextended-2" + run_dump_test "mips16-relax-unextended-1" + run_dump_test "mips16-relax-unextended-2" run_dump_test "mips16-jal-t" run_dump_test "mips16-jal-e" diff --git a/gas/testsuite/gas/mips/mips16-relax-unextended-1.d b/gas/testsuite/gas/mips/mips16-relax-unextended-1.d new file mode 100644 index 00000000000..dc7a85ef08c --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-relax-unextended-1.d @@ -0,0 +1,3 @@ +#name: MIPS16 relaxation with unextended instructions forced 1 +#as: -32 +#error-output: mips16-relax-unextended-1.l diff --git a/gas/testsuite/gas/mips/mips16-relax-unextended-1.l b/gas/testsuite/gas/mips/mips16-relax-unextended-1.l new file mode 100644 index 00000000000..a22b79e8ffe --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-relax-unextended-1.l @@ -0,0 +1,49 @@ +.*: Assembler messages: +.*:6: Error: invalid unextended operand value +.*:8: Error: invalid unextended operand value +.*:10: Error: invalid unextended operand value +.*:13: Error: invalid unextended operand value +.*:15: Error: invalid unextended operand value `lb\.t \$4,%hi\(baz\)\(\$5\)' +.*:16: Error: invalid unextended operand value +.*:23: Error: invalid unextended operand value +.*:25: Error: invalid unextended operand value `sd\.t \$31,%lo\(baz\)\(\$29\)' +.*:26: Error: invalid unextended operand value +.*:28: Error: invalid unextended operand value `sd\.t \$4,%lo\(baz\)\(\$29\)' +.*:31: Error: invalid unextended operand value +.*:33: Error: invalid unextended operand value +.*:35: Error: invalid unextended operand value `lh\.t \$6,%lo\(baz\)\(\$7\)' +.*:36: Error: invalid unextended operand value +.*:38: Error: invalid unextended operand value `addiu\.t \$29,%lo\(baz\)' +.*:39: Error: invalid unextended operand value +.*:41: Error: invalid unextended operand value `cmpi\.t \$2,%hi\(baz\)' +.*:42: Error: invalid unextended operand value +.*:44: Error: invalid unextended operand value `addiu\.t \$3,\$pc,%lo\(baz\)' +.*:45: Error: invalid unextended operand value +.*:47: Error: invalid unextended operand value `daddiu\.t \$4,\$pc,%lo\(baz\)' +.*:49: Error: invalid unextended operand value +.*:51: Error: invalid unextended operand value `daddiu\.t \$5,%lo\(baz\)' +.*:52: Error: invalid unextended operand value +.*:54: Error: invalid unextended operand value `addiu\.t \$2,%lo\(baz\)' +.*:7: Error: invalid unextended operand value +.*:9: Error: invalid unextended operand value +.*:11: Error: invalid unextended operand value +.*:14: Error: invalid unextended operand value +.*:17: Error: invalid unextended operand value +.*:19: Error: invalid unextended operand value +.*:20: Error: invalid unextended operand value +.*:21: Error: invalid unextended operand value +.*:22: Error: invalid unextended operand value +.*:24: Error: invalid unextended operand value +.*:27: Error: invalid unextended operand value +.*:29: Error: invalid unextended operand value +.*:30: Error: invalid unextended operand value +.*:32: Error: invalid unextended operand value +.*:34: Error: invalid unextended operand value +.*:37: Error: invalid unextended operand value +.*:40: Error: invalid unextended operand value +.*:43: Error: invalid unextended operand value +.*:46: Error: invalid unextended operand value +.*:50: Error: invalid unextended operand value +.*:53: Error: invalid unextended operand value +.*:55: Error: invalid unextended operand value +.*:56: Error: invalid unextended operand value diff --git a/gas/testsuite/gas/mips/mips16-relax-unextended-1.s b/gas/testsuite/gas/mips/mips16-relax-unextended-1.s new file mode 100644 index 00000000000..ff4ffdd4a82 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-relax-unextended-1.s @@ -0,0 +1,58 @@ + .module mips3 + .set mips16 + .set autoextend +foo: + # Operand code: + sll.t $2, $3, 17 # < + sll.t $2, $3, bar + dsll.t $4, $5, 17 # [ + dsll.t $4, $5, bar + dsrl.t $6, 17 # ] + dsrl.t $6, bar + + lb.t $4, 0x1234($5) # 5 + lb.t $4, bar($5) + lb.t $4, %hi(baz)($5) + slti.t $6, 0x5678 # 8 + slti.t $6, bar + + la.t $2, . + 0x1234 # A + la.t $2, . + bar + ld.t $3, . + 0x5678 # B + ld.t $3, . + bar + sd.t $31, 0x5678($29) # C + sd.t $31, bar($29) + sd.t $31, %lo(baz)($29) + sd.t $4, 0x5678($29) # D + sd.t $4, bar($29) + sd.t $4, %lo(baz)($29) + dla.t $5, . + 0x5678 # E + dla.t $5, . + bar + daddiu.t $2, $3, 0x5678 # F + daddiu.t $2, $3, bar + lh.t $6, 0x1234($7) # H + lh.t $6, bar($7) + lh.t $6, %lo(baz)($7) + addiu.t $29, 0x5678 # K + addiu.t $29, bar + addiu.t $29, %lo(baz) + cmpi.t $2, 0x1234 # U + cmpi.t $2, bar + cmpi.t $2, %hi(baz) + addiu.t $3, $pc, 0x5678 # V + addiu.t $3, $pc, bar + addiu.t $3, $pc, %lo(baz) + daddiu.t $4, $pc, 0x5678 # W + daddiu.t $4, $pc, bar + daddiu.t $4, $pc, %lo(baz) + + daddiu.t $5, 0x5678 # j + daddiu.t $5, bar + daddiu.t $5, %lo(baz) + addiu.t $6, 0x1234 # k + addiu.t $6, bar + addiu.t $2, %lo(baz) + beqz.t $7, . + 0x5678 # p + b.t . + 0x1234 # q + + .set bar, 0x5678 diff --git a/gas/testsuite/gas/mips/mips16-relax-unextended-2.d b/gas/testsuite/gas/mips/mips16-relax-unextended-2.d new file mode 100644 index 00000000000..5e1682032ac --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-relax-unextended-2.d @@ -0,0 +1,3 @@ +#name: MIPS16 relaxation with unextended instructions forced 2 +#as: -32 +#error-output: mips16-relax-unextended-2.l diff --git a/gas/testsuite/gas/mips/mips16-relax-unextended-2.l b/gas/testsuite/gas/mips/mips16-relax-unextended-2.l new file mode 100644 index 00000000000..6b130f99755 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-relax-unextended-2.l @@ -0,0 +1,49 @@ +.*: Assembler messages: +.*:6: Error: invalid unextended operand value +.*:8: Error: invalid unextended operand value +.*:10: Error: invalid unextended operand value +.*:13: Error: invalid unextended operand value +.*:15: Error: invalid unextended operand value `lb \$4,%hi\(baz\)\(\$5\)' +.*:16: Error: invalid unextended operand value +.*:23: Error: invalid unextended operand value +.*:25: Error: invalid unextended operand value `sd \$31,%lo\(baz\)\(\$29\)' +.*:26: Error: invalid unextended operand value +.*:28: Error: invalid unextended operand value `sd \$4,%lo\(baz\)\(\$29\)' +.*:31: Error: invalid unextended operand value +.*:33: Error: invalid unextended operand value +.*:35: Error: invalid unextended operand value `lh \$6,%lo\(baz\)\(\$7\)' +.*:36: Error: invalid unextended operand value +.*:38: Error: invalid unextended operand value `addiu \$29,%lo\(baz\)' +.*:39: Error: invalid unextended operand value +.*:41: Error: invalid unextended operand value `cmpi \$2,%hi\(baz\)' +.*:42: Error: invalid unextended operand value +.*:44: Error: invalid unextended operand value `addiu \$3,\$pc,%lo\(baz\)' +.*:45: Error: invalid unextended operand value +.*:47: Error: invalid unextended operand value `daddiu \$4,\$pc,%lo\(baz\)' +.*:49: Error: invalid unextended operand value +.*:51: Error: invalid unextended operand value `daddiu \$5,%lo\(baz\)' +.*:52: Error: invalid unextended operand value +.*:54: Error: invalid unextended operand value `addiu \$2,%lo\(baz\)' +.*:7: Error: invalid unextended operand value +.*:9: Error: invalid unextended operand value +.*:11: Error: invalid unextended operand value +.*:14: Error: invalid unextended operand value +.*:17: Error: invalid unextended operand value +.*:19: Error: invalid unextended operand value +.*:20: Error: invalid unextended operand value +.*:21: Error: invalid unextended operand value +.*:22: Error: invalid unextended operand value +.*:24: Error: invalid unextended operand value +.*:27: Error: invalid unextended operand value +.*:29: Error: invalid unextended operand value +.*:30: Error: invalid unextended operand value +.*:32: Error: invalid unextended operand value +.*:34: Error: invalid unextended operand value +.*:37: Error: invalid unextended operand value +.*:40: Error: invalid unextended operand value +.*:43: Error: invalid unextended operand value +.*:46: Error: invalid unextended operand value +.*:50: Error: invalid unextended operand value +.*:53: Error: invalid unextended operand value +.*:55: Error: invalid unextended operand value +.*:56: Error: invalid unextended operand value diff --git a/gas/testsuite/gas/mips/mips16-relax-unextended-2.s b/gas/testsuite/gas/mips/mips16-relax-unextended-2.s new file mode 100644 index 00000000000..505ca56121e --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-relax-unextended-2.s @@ -0,0 +1,58 @@ + .module mips3 + .set mips16 + .set noautoextend +foo: + # Operand code: + sll $2, $3, 17 # < + sll $2, $3, bar + dsll $4, $5, 17 # [ + dsll $4, $5, bar + dsrl $6, 17 # ] + dsrl $6, bar + + lb $4, 0x1234($5) # 5 + lb $4, bar($5) + lb $4, %hi(baz)($5) + slti $6, 0x5678 # 8 + slti $6, bar + + la $2, . + 0x1234 # A + la $2, . + bar + ld $3, . + 0x5678 # B + ld $3, . + bar + sd $31, 0x5678($29) # C + sd $31, bar($29) + sd $31, %lo(baz)($29) + sd $4, 0x5678($29) # D + sd $4, bar($29) + sd $4, %lo(baz)($29) + dla $5, . + 0x5678 # E + dla $5, . + bar + daddiu $2, $3, 0x5678 # F + daddiu $2, $3, bar + lh $6, 0x1234($7) # H + lh $6, bar($7) + lh $6, %lo(baz)($7) + addiu $29, 0x5678 # K + addiu $29, bar + addiu $29, %lo(baz) + cmpi $2, 0x1234 # U + cmpi $2, bar + cmpi $2, %hi(baz) + addiu $3, $pc, 0x5678 # V + addiu $3, $pc, bar + addiu $3, $pc, %lo(baz) + daddiu $4, $pc, 0x5678 # W + daddiu $4, $pc, bar + daddiu $4, $pc, %lo(baz) + + daddiu $5, 0x5678 # j + daddiu $5, bar + daddiu $5, %lo(baz) + addiu $6, 0x1234 # k + addiu $6, bar + addiu $2, %lo(baz) + beqz $7, . + 0x5678 # p + b . + 0x1234 # q + + .set bar, 0x5678