MIPS16/GAS: Fix delay slot filling across frags
authorMatthew Fortune <Matthew.Fortune@imgtec.com>
Thu, 30 Jun 2016 14:02:20 +0000 (15:02 +0100)
committerMaciej W. Rozycki <macro@imgtec.com>
Thu, 30 Jun 2016 14:11:23 +0000 (15:11 +0100)
commit99e7978bd25ab7b39ce2596b19a437eed7d7fd69
tree211763625c2d1baf8afad09c3fcbe9898b65bbf9
parent5e35670ba76690524dc69cc7a2bc8d7df8eb4249
MIPS16/GAS: Fix delay slot filling across frags

Fix an assertion failure like:

test.s: Assembler messages:
test.s:3: Internal error!
Assertion failure in append_insn at .../gas/config/tc-mips.c:7523.
Please report this bug.

triggered by assembling MIPS16 code like:

hello:
addiu $4, $4, 4
jr $31

with the generation of a listing file enabled, e.g.:

$ as -mips16 -O2 -aln=test.lst

The cause of the problem is the lack of support for moving instructions
across frags in MIPS16 jump swapping, which triggers more easily with
listing enabled as in that case every instruction gets placed in its own
frag.  It would trigger even with listing disabled though if the
instruction to swap a MIPS16 jump with was unfortunately enough placed
as last in a frag that became full.

This scenario is already handled correctly with branch swapping in
regular MIPS and microMIPS code, so reuse it for MIPS16 code as well,
and now that all MIPS16 handling has become the same as the regular MIPS
and microMIPS cases remove MIPS16 special casing altogether.

This effectively complements:

commit 464ab0e55ade01d2bb0b4fa45c429af7a2f85a26
Author: Maciej W. Rozycki <macro@linux-mips.org>
Date:   Mon Aug 6 20:33:00 2012 +0000

<https://sourceware.org/ml/binutils/2012-08/msg00043.html>, ("MIPS/GAS:
Correct microMIPS branch swapping assertion") for the MIPS16 case.

The assertion itself was introduced with:

commit 1e91584932efd70020c8c98037d0cb93a0552a20
Author: Richard Sandiford <rdsandiford@googlemail.com>
Date:   Wed Mar 9 09:17:02 2005 +0000

<https://sourceware.org/ml/binutils/2005-03/msg00217.html>, ("Rework
MIPS nop-insertion code, add -mfix-vr4130 [5/11]"), but its introduction
merely noted our existing lack of support for MIPS16 jump swapping
across frags.

gas/
* config/tc-mips.c (append_insn) <APPEND_SWAP>: Do not special
case MIPS16 handling.
* testsuite/gas/mips/branch-swap-3.d: New test.
* testsuite/gas/mips/branch-swap-4.d: New test.
* testsuite/gas/mips/mips16@branch-swap-3.d: New test.
* testsuite/gas/mips/mips16@branch-swap-4.d: New test.
* testsuite/gas/mips/micromips@branch-swap-3.d: New test.
* testsuite/gas/mips/micromips@branch-swap-4.d: New test.
* testsuite/gas/mips/branch-swap-3.s: New test source.
* testsuite/gas/mips/mips.exp: Run the new tests.
gas/ChangeLog
gas/config/tc-mips.c
gas/testsuite/gas/mips/branch-swap-3.d [new file with mode: 0644]
gas/testsuite/gas/mips/branch-swap-3.s [new file with mode: 0644]
gas/testsuite/gas/mips/branch-swap-4.d [new file with mode: 0644]
gas/testsuite/gas/mips/micromips@branch-swap-3.d [new file with mode: 0644]
gas/testsuite/gas/mips/micromips@branch-swap-4.d [new file with mode: 0644]
gas/testsuite/gas/mips/mips.exp
gas/testsuite/gas/mips/mips16@branch-swap-3.d [new file with mode: 0644]
gas/testsuite/gas/mips/mips16@branch-swap-4.d [new file with mode: 0644]