From adc1273cb27286452ed8b32c5ca3ea263b4854f0 Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Tue, 25 Apr 2017 10:20:14 +0100 Subject: [PATCH] MIPS/GAS: Correct BFD_RELOC_MIPS16_16_PCREL_S1 fixup size Correct the size of a BFD_RELOC_MIPS16_16_PCREL_S1 fixup made in `md_convert_frag', fixing a bug introduced with commit c9775dde3277 ("MIPS16: Add R_MIPS16_PC16_S1 branch relocation support)". Add test cases to verify that the overflow of this fixup's in-place addend is still correctly detected. gas/ * config/tc-mips.c (md_convert_frag): Correct BFD_RELOC_MIPS16_16_PCREL_S1 fixup size. * testsuite/gas/mips/mips16-branch-addend-4.d: New test. * testsuite/gas/mips/mips16-branch-addend-5.d: New test. * testsuite/gas/mips/mips16-branch-addend-5.l: New stderr output. * testsuite/gas/mips/mips16-branch-addend-4.s: New test source. * testsuite/gas/mips/mips16-branch-addend-5.s: New test source. * testsuite/gas/mips/mips.exp: Run the new tests. --- gas/ChangeLog | 12 ++++++++ gas/config/tc-mips.c | 6 +--- gas/testsuite/gas/mips/mips.exp | 2 ++ .../gas/mips/mips16-branch-addend-4.d | 30 +++++++++++++++++++ .../gas/mips/mips16-branch-addend-4.s | 24 +++++++++++++++ .../gas/mips/mips16-branch-addend-5.d | 4 +++ .../gas/mips/mips16-branch-addend-5.l | 11 +++++++ .../gas/mips/mips16-branch-addend-5.s | 24 +++++++++++++++ 8 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 gas/testsuite/gas/mips/mips16-branch-addend-4.d create mode 100644 gas/testsuite/gas/mips/mips16-branch-addend-4.s create mode 100644 gas/testsuite/gas/mips/mips16-branch-addend-5.d create mode 100644 gas/testsuite/gas/mips/mips16-branch-addend-5.l create mode 100644 gas/testsuite/gas/mips/mips16-branch-addend-5.s diff --git a/gas/ChangeLog b/gas/ChangeLog index f85422353f2..a60731b9b13 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,15 @@ +2017-04-25 Maciej W. Rozycki + + * config/tc-mips.c (md_convert_frag): Correct + BFD_RELOC_MIPS16_16_PCREL_S1 fixup size. + * testsuite/gas/mips/mips16-branch-addend-4.d: New test. + * testsuite/gas/mips/mips16-branch-addend-5.d: New test. + * testsuite/gas/mips/mips16-branch-addend-5.l: New stderr + output. + * testsuite/gas/mips/mips16-branch-addend-4.s: New test source. + * testsuite/gas/mips/mips16-branch-addend-5.s: New test source. + * testsuite/gas/mips/mips.exp: Run the new tests. + 2017-04-25 Jose E. Marchesi PR gas/21407 diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index 6a981227279..da8e9ab2718 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -18445,15 +18445,11 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT asec, fragS *fragp) exp.X_add_symbol = fragp->fr_symbol; exp.X_add_number = fragp->fr_offset; - fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 2, &exp, + fixp = fix_new_exp (fragp, buf - fragp->fr_literal, 4, &exp, TRUE, reloc); fixp->fx_file = fragp->fr_file; fixp->fx_line = fragp->fr_line; - - /* These relocations can have an addend that won't fit - in 2 octets. */ - fixp->fx_no_overflow = 1; } else as_bad_where (fragp->fr_file, fragp->fr_line, diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp index f0c6c34dcd2..31a4075fade 100644 --- a/gas/testsuite/gas/mips/mips.exp +++ b/gas/testsuite/gas/mips/mips.exp @@ -1552,6 +1552,8 @@ if { [istarget mips*-*-vxworks*] } { run_dump_test "mips16-branch-addend-1" run_dump_test "mips16-branch-addend-2" run_dump_test "mips16-branch-addend-3" + run_dump_test "mips16-branch-addend-4" + run_dump_test "mips16-branch-addend-5" run_dump_test "mips16-branch-absolute" run_dump_test "mips16-branch-absolute-addend" if $has_newabi { diff --git a/gas/testsuite/gas/mips/mips16-branch-addend-4.d b/gas/testsuite/gas/mips/mips16-branch-addend-4.d new file mode 100644 index 00000000000..273a6e1f543 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-addend-4.d @@ -0,0 +1,30 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS16 branch relocation with addend 4 +#as: -32 + +.*: +file format .*mips.* + +Disassembly of section \.text: + \.\.\. +[0-9a-f]+ <[^>]*> f7ef 101f b 00011002 +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f7ef 601f bteqz 00011006 +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f7ef 611f btnez 0001100a +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f7ef 221f beqz v0,0001100e +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f7ef 2a1f bnez v0,00011012 +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f010 1000 b ffff1018 +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f010 6000 bteqz ffff101c +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f010 6100 btnez ffff1020 +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f010 2200 beqz v0,ffff1024 +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> f010 2a00 bnez v0,ffff1028 +[ ]*[0-9a-f]+: R_MIPS16_PC16_S1 bar +[0-9a-f]+ <[^>]*> 6500 nop + \.\.\. diff --git a/gas/testsuite/gas/mips/mips16-branch-addend-4.s b/gas/testsuite/gas/mips/mips16-branch-addend-4.s new file mode 100644 index 00000000000..5c5a7b70960 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-addend-4.s @@ -0,0 +1,24 @@ + .text + + .space 0x1000 + + .ent foo + .set mips16 +foo: + b bar + 4 + (0x7fff << 1) + bteqz bar + 4 + (0x7fff << 1) + btnez bar + 4 + (0x7fff << 1) + beqz $2, bar + 4 + (0x7fff << 1) + bnez $2, bar + 4 + (0x7fff << 1) + b bar + 4 - (0x8000 << 1) + bteqz bar + 4 - (0x8000 << 1) + btnez bar + 4 - (0x8000 << 1) + beqz $2, bar + 4 - (0x8000 << 1) + bnez $2, bar + 4 - (0x8000 << 1) + nop + .set nomips16 + .end foo + +# Force some (non-delay-slot) zero bytes, to make 'objdump' print ... + .align 4, 0 + .space 16 diff --git a/gas/testsuite/gas/mips/mips16-branch-addend-5.d b/gas/testsuite/gas/mips/mips16-branch-addend-5.d new file mode 100644 index 00000000000..47c1134c107 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-addend-5.d @@ -0,0 +1,4 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS16 branch relocation with addend 5 +#as: -32 +#error-output: mips16-branch-addend-5.l diff --git a/gas/testsuite/gas/mips/mips16-branch-addend-5.l b/gas/testsuite/gas/mips/mips16-branch-addend-5.l new file mode 100644 index 00000000000..99f844eba0a --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-addend-5.l @@ -0,0 +1,11 @@ +.*: Assembler messages: +.*:8: Error: relocation overflow +.*:9: Error: relocation overflow +.*:10: Error: relocation overflow +.*:11: Error: relocation overflow +.*:12: Error: relocation overflow +.*:13: Error: relocation overflow +.*:14: Error: relocation overflow +.*:15: Error: relocation overflow +.*:16: Error: relocation overflow +.*:17: Error: relocation overflow diff --git a/gas/testsuite/gas/mips/mips16-branch-addend-5.s b/gas/testsuite/gas/mips/mips16-branch-addend-5.s new file mode 100644 index 00000000000..aadfa19f41c --- /dev/null +++ b/gas/testsuite/gas/mips/mips16-branch-addend-5.s @@ -0,0 +1,24 @@ + .text + + .space 0x1000 + + .ent foo + .set mips16 +foo: + b bar + 4 + (0x8000 << 1) + bteqz bar + 4 + (0x8000 << 1) + btnez bar + 4 + (0x8000 << 1) + beqz $2, bar + 4 + (0x8000 << 1) + bnez $2, bar + 4 + (0x8000 << 1) + b bar + 4 - (0x8001 << 1) + bteqz bar + 4 - (0x8001 << 1) + btnez bar + 4 - (0x8001 << 1) + beqz $2, bar + 4 - (0x8001 << 1) + bnez $2, bar + 4 - (0x8001 << 1) + nop + .set nomips16 + .end foo + +# Force some (non-delay-slot) zero bytes, to make 'objdump' print ... + .align 4, 0 + .space 16 -- 2.30.2