This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] microMIPS/GAS: Avoid relocation overflow with forced 16-bit branches
- From: "Maciej W. Rozycki" <macro at codesourcery dot com>
- To: <binutils at sourceware dot org>
- Cc: Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Wed, 24 Oct 2012 23:44:50 +0100
- Subject: [PATCH] microMIPS/GAS: Avoid relocation overflow with forced 16-bit branches
Hi,
The change below fixes a relocation overflow triggered by forced 16-bit
branches:
$ cat b16.s
.text
test1:
.space 65536
test2:
b16 1f
1:
$ mips-linux-gnu-as -mmicromips -o b16.o b16.s
b16.s: Assembler messages:
b16.s:5: Error: value of fffffffffffefffe too large for field of 2 bytes at 0000000000010000
$
Overall it looks to me the whole idea of using fixp->fx_size to check for
relocatable field overflows is missing the point, at least for the MIPS
target and relocations in text, where the size of the fixup reflects the
width of the instruction a relocation is applied to and has little to do
with the range supported.
Anyway, to fix this immediate problem I have gladly accepted Chao-ying's
proposal.
No regressions in testing across the usual MIPS targets. OK to apply?
2012-10-24 Chao-ying Fu <fu@mips.com>
gas/
* config/tc-mips.c (append_insn): Set fx_no_overflow for 16-bit
microMIPS branch relocations.
gas/testsuite/
* gas/mips/micromips-b16.d: New test.
* gas/mips/micromips-b16.s: New test source.
* gas/mips/mips.exp: Run the new test.
Maciej
binutils-mips-gas-b16-overflow.diff
Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c 2012-10-23 16:01:36.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c 2012-10-23 16:50:29.421771475 +0100
@@ -4464,6 +4464,11 @@ append_insn (struct mips_cl_insn *ip, ex
|| lo16_reloc_p (reloc_type[0])))
ip->fixp[0]->fx_no_overflow = 1;
+ /* These relocations can have an addend that won't fit in 2 octets. */
+ if (reloc_type[0] == BFD_RELOC_MICROMIPS_7_PCREL_S1
+ || reloc_type[0] == BFD_RELOC_MICROMIPS_10_PCREL_S1)
+ ip->fixp[0]->fx_no_overflow = 1;
+
if (mips_relax.sequence)
{
if (mips_relax.first_fixup == 0)
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips-b16.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips-b16.d 2012-10-23 16:06:13.491781218 +0100
@@ -0,0 +1,45 @@
+#objdump: -dr --show-raw-insn
+#name: microMIPS b16, bnez16, beqz16
+#as: -32 -mmicromips
+#source: micromips-b16.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <test1>:
+ \.\.\.
+
+[0-9a-f]+ <test2>:
+[ 0-9a-f]+: cfff b [0-9a-f]+ <.*>
+[ ]*[0-9a-f]+: R_MICROMIPS_PC10_S1 .*
+[ 0-9a-f]+: 0c00 nop
+
+[0-9a-f]+ <.*>:
+[ 0-9a-f]+: ad7f bnez v0,[0-9a-f]+ <.*>
+[ ]*[0-9a-f]+: R_MICROMIPS_PC7_S1 .*
+[ 0-9a-f]+: 0c00 nop
+
+[0-9a-f]+ <.*>:
+[ 0-9a-f]+: 8d7f beqz v0,[0-9a-f]+ <.*>
+[ ]*[0-9a-f]+: R_MICROMIPS_PC7_S1 .*
+[ 0-9a-f]+: 0c00 nop
+
+[0-9a-f]+ <.*>:
+[ 0-9a-f]+: cfff b [0-9a-f]+ <.*>
+[ ]*[0-9a-f]+: R_MICROMIPS_PC10_S1 .*
+[ 0-9a-f]+: 0c00 nop
+
+[0-9a-f]+ <.*>:
+[ 0-9a-f]+: ad7f bnez v0,[0-9a-f]+ <.*>
+[ ]*[0-9a-f]+: R_MICROMIPS_PC7_S1 .*
+[ 0-9a-f]+: 0c00 nop
+
+[0-9a-f]+ <.*>:
+[ 0-9a-f]+: 8d7f beqz v0,[0-9a-f]+ <.*>
+[ ]*[0-9a-f]+: R_MICROMIPS_PC7_S1 .*
+[ 0-9a-f]+: 0c00 nop
+
+[0-9a-f]+ <.*>:
+[ 0-9a-f]+: 0c00 nop
+#pass
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips-b16.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/micromips-b16.s 2012-10-23 16:06:13.491781218 +0100
@@ -0,0 +1,17 @@
+ .text
+test1:
+ .space 65536
+test2:
+ b16 1f
+1:
+ bnez16 $2,1f
+1:
+ beqz16 $2,1f
+1:
+ b 1f
+1:
+ bnez $2,1f
+1:
+ beqz $2,1f
+1:
+ nop
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/mips.exp 2012-10-23 16:05:48.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp 2012-10-23 16:06:13.491781218 +0100
@@ -1115,6 +1115,7 @@ if { [istarget mips*-*-vxworks*] } {
run_dump_test "micromips-branch-delay"
run_dump_test "micromips-warn-branch-delay"
run_dump_test "micromips-warn-branch-delay-1"
+ run_dump_test "micromips-b16"
}
run_dump_test_arches "mcu" [mips_arch_list_matching mips32r2 \