From eefc3365838ed15c02bd7da39fbc31c00d07b398 Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Wed, 14 Dec 2016 21:20:01 +0000 Subject: [PATCH] MIPS16/GAS: Fix assertion failures with relocations on 16-bit instructions Complement commit c9775dde3277 ("MIPS16: Add R_MIPS16_PC16_S1 branch relocation support)" and report an assembly error when a relocation is required for an instruction, currently a branch only, that has been forced to use its unextended encoding, either with the use of an explicit `.t' mnemonic suffix, or by means of `.set noautoextend' being active, fixing an assertion failure currently caused instead. gas/ * config/tc-mips.c (md_convert_frag): Report an error instead of asserting on `ext'. * testsuite/gas/mips/mips16-branch-unextended-1.d: New test. * testsuite/gas/mips/mips16-branch-unextended-2.d: New test. * testsuite/gas/mips/mips16-branch-unextended-1.s: New test source. * testsuite/gas/mips/mips16-branch-unextended-2.s: New test. * testsuite/gas/mips/mips16-branch-unextended.l: New stderr output. * testsuite/gas/mips/mips.exp: Run the new tests. --- gas/ChangeLog | 13 +++++++++++++ gas/config/tc-mips.c | 9 ++++++--- gas/testsuite/gas/mips/mips.exp | 3 +++ gas/testsuite/gas/mips/mips16-branch-unextended-1.d | 3 +++ gas/testsuite/gas/mips/mips16-branch-unextended-1.s | 8 ++++++++ gas/testsuite/gas/mips/mips16-branch-unextended-2.d | 3 +++ gas/testsuite/gas/mips/mips16-branch-unextended-2.s | 8 ++++++++ gas/testsuite/gas/mips/mips16-branch-unextended.l | 6 ++++++ 8 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 gas/testsuite/gas/mips/mips16-branch-unextended-1.d create mode 100644 gas/testsuite/gas/mips/mips16-branch-unextended-1.s create mode 100644 gas/testsuite/gas/mips/mips16-branch-unextended-2.d create mode 100644 gas/testsuite/gas/mips/mips16-branch-unextended-2.s create mode 100644 gas/testsuite/gas/mips/mips16-branch-unextended.l diff --git a/gas/ChangeLog b/gas/ChangeLog index 742da3ecfd1..8a41fc7f65a 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,16 @@ +2016-12-14 Maciej W. Rozycki + + * config/tc-mips.c (md_convert_frag): Report an error instead of + asserting on `ext'. + * testsuite/gas/mips/mips16-branch-unextended-1.d: New test. + * testsuite/gas/mips/mips16-branch-unextended-2.d: New test. + * testsuite/gas/mips/mips16-branch-unextended-1.s: New test + source. + * testsuite/gas/mips/mips16-branch-unextended-2.s: New test. + * testsuite/gas/mips/mips16-branch-unextended.l: New stderr + output. + * testsuite/gas/mips/mips.exp: Run the new tests. + 2016-12-14 Maciej W. Rozycki * testsuite/gas/mips/mips16-sprel-swap.d: New test. diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index 4288d96271f..1241b9c1e5d 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -18369,10 +18369,10 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp) _("unsupported relocation")); break; } - if (reloc != BFD_RELOC_NONE) + if (reloc == BFD_RELOC_NONE) + ; + else if (ext) { - gas_assert (ext); - exp.X_op = O_symbol; exp.X_add_symbol = fragp->fr_symbol; exp.X_add_number = fragp->fr_offset; @@ -18387,6 +18387,9 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp) in 2 octets. */ fixp->fx_no_overflow = 1; } + else + as_bad_where (fragp->fr_file, fragp->fr_line, + _("invalid unextended operand value")); } else mips16_immed (fragp->fr_file, fragp->fr_line, type, diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp index da8d5693db4..d3809e7b327 100644 --- a/gas/testsuite/gas/mips/mips.exp +++ b/gas/testsuite/gas/mips/mips.exp @@ -1298,6 +1298,9 @@ if { [istarget mips*-*-vxworks*] } { run_dump_test "mips16-extend" run_dump_test "mips16-sprel-swap" + run_dump_test "mips16-branch-unextended-1" + run_dump_test "mips16-branch-unextended-2" + run_dump_test "vxworks1" run_dump_test "vxworks1-xgot" run_dump_test "vxworks1-el" diff --git a/gas/testsuite/gas/mips/mips16-branch-unextended-1.d b/gas/testsuite/gas/mips/mips16-branch-unextended-1.d new file mode 100644 index 00000000000..9bccd027d5f --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-unextended-1.d @@ -0,0 +1,3 @@ +#name: MIPS16 unextended branch instructions with relocation 1 +#as: -32 +#error-output: mips16-branch-unextended.l diff --git a/gas/testsuite/gas/mips/mips16-branch-unextended-1.s b/gas/testsuite/gas/mips/mips16-branch-unextended-1.s new file mode 100644 index 00000000000..3e59588f9aa --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-unextended-1.s @@ -0,0 +1,8 @@ + .set mips16 + .set noautoextend +foo: + beqz $2, baz + bnez $3, baz + bteqz baz + btnez baz + b baz diff --git a/gas/testsuite/gas/mips/mips16-branch-unextended-2.d b/gas/testsuite/gas/mips/mips16-branch-unextended-2.d new file mode 100644 index 00000000000..b64ee5a2825 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-unextended-2.d @@ -0,0 +1,3 @@ +#name: MIPS16 unextended branch instructions with relocation 2 +#as: -32 +#error-output: mips16-branch-unextended.l diff --git a/gas/testsuite/gas/mips/mips16-branch-unextended-2.s b/gas/testsuite/gas/mips/mips16-branch-unextended-2.s new file mode 100644 index 00000000000..1bc42825c5a --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-unextended-2.s @@ -0,0 +1,8 @@ + .set mips16 + .set autoextend +foo: + beqz.t $2, baz + bnez.t $3, baz + bteqz.t baz + btnez.t baz + b.t baz diff --git a/gas/testsuite/gas/mips/mips16-branch-unextended.l b/gas/testsuite/gas/mips/mips16-branch-unextended.l new file mode 100644 index 00000000000..611901cfa13 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-unextended.l @@ -0,0 +1,6 @@ +.*: Assembler messages: +.*:4: Error: invalid unextended operand value +.*:5: Error: invalid unextended operand value +.*:6: Error: invalid unextended operand value +.*:7: Error: invalid unextended operand value +.*:8: Error: invalid unextended operand value -- 2.30.2