gas/
authorMaciej W. Rozycki <macro@linux-mips.org>
Mon, 28 Feb 2011 15:44:53 +0000 (15:44 +0000)
committerMaciej W. Rozycki <macro@linux-mips.org>
Mon, 28 Feb 2011 15:44:53 +0000 (15:44 +0000)
* config/tc-mips.c (mips_fix_adjustable): On REL targets also
reject PC-relative relocations.

gas/testsuite/
* gas/mips/branch-misc-2.d: Adjust for relocation change.
* gas/mips/branch-misc-2pic.d: Likewise.
* gas/mips/branch-misc-4.d: New test for PC-relative relocation
overflow.
* gas/mips/branch-misc-4-64.d: Likewise.
* gas/mips/branch-misc-4.s: Source for the new tests.
* testsuite/gas/mips/mips.exp: Run the new tests.

gas/ChangeLog
gas/config/tc-mips.c
gas/testsuite/ChangeLog
gas/testsuite/gas/mips/branch-misc-2.d
gas/testsuite/gas/mips/branch-misc-2pic.d
gas/testsuite/gas/mips/branch-misc-4-64.d [new file with mode: 0644]
gas/testsuite/gas/mips/branch-misc-4.d [new file with mode: 0644]
gas/testsuite/gas/mips/branch-misc-4.s [new file with mode: 0644]
gas/testsuite/gas/mips/mips.exp

index e5dd2bdcfc960971dc453cba52fe6ca5caa2bdd8..316abb73c7bc689d7a644c4ec7f9322b1ad00e5a 100644 (file)
@@ -1,3 +1,8 @@
+2011-02-28  Maciej W. Rozycki  <macro@codesourcery.com>
+
+       * config/tc-mips.c (mips_fix_adjustable): On REL targets also
+       reject PC-relative relocations.
+
 2011-02-28  Maciej W. Rozycki  <macro@codesourcery.com>
 
        * config/tc-mips.c (md_convert_frag): Correct message
index 4b7dcdcdd84e1255d45d27d210cdd6c3b2dda989..897ed0f83616835f84b97fb96de6be6b122b64f2 100644 (file)
@@ -14248,8 +14248,12 @@ mips_fix_adjustable (fixS *fixp)
       && (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE) != 0)
     return 0;
 
-  /* There is no place to store an in-place offset for JALR relocations.  */
-  if (fixp->fx_r_type == BFD_RELOC_MIPS_JALR && HAVE_IN_PLACE_ADDENDS)
+  /* There is no place to store an in-place offset for JALR relocations.
+     Likewise an in-range offset of PC-relative relocations may overflow
+     the in-place relocatable field if recalculated against the start
+     address of the symbol's containing section.  */
+  if (HAVE_IN_PLACE_ADDENDS
+      && (fixp->fx_pcrel || fixp->fx_r_type == BFD_RELOC_MIPS_JALR))
     return 0;
 
 #ifdef OBJ_ELF
index 8eca541b67d43b51b3890ac78dd2e32d2dab68f0..1b0dfde83275b2ce1215ecd895c8acbd2b7bacd9 100644 (file)
@@ -1,3 +1,13 @@
+2011-02-28  Maciej W. Rozycki  <macro@codesourcery.com>
+
+       * gas/mips/branch-misc-2.d: Adjust for relocation change.
+       * gas/mips/branch-misc-2pic.d: Likewise.
+       * gas/mips/branch-misc-4.d: New test for PC-relative relocation
+       overflow.
+       * gas/mips/branch-misc-4-64.d: Likewise.
+       * gas/mips/branch-misc-4.s: Source for the new tests.
+       * testsuite/gas/mips/mips.exp: Run the new tests.
+
 2011-02-28  Maciej W. Rozycki  <macro@codesourcery.com>
 
        * gas/mips/relax-swap1.l: Adjust for message capitalization
index ffd823c7b62e20a51764a8840e00678be366a015..205d68542f8bd33bf948538da449a79dbd9549d6 100644 (file)
@@ -39,6 +39,6 @@ Disassembly of section .text:
 [      ]*b0: R_MIPS_PC16       x2
 0+00b4 <[^>]*> 00000000        nop
 0+00b8 <[^>]*> 1000ffff        b       000000b8 <g6\+0x10>
-[      ]*b8: R_MIPS_PC16       \.data
+[      ]*b8: R_MIPS_PC16       \.Ldata
 0+00bc <[^>]*> 00000000        nop
        \.\.\.
index 5b42b29603ee54206e7eae9458f1f86a13defdf6..bc604311a995b1edc9fb3a3e570eafc48f5265dd 100644 (file)
@@ -40,6 +40,6 @@ Disassembly of section .text:
 [      ]*b0: R_MIPS_PC16       x2
 0+00b4 <[^>]*> 00000000        nop
 0+00b8 <[^>]*> 1000ffff        b       000000b8 <g6\+0x10>
-[      ]*b8: R_MIPS_PC16       \.data
+[      ]*b8: R_MIPS_PC16       \.Ldata
 0+00bc <[^>]*> 00000000        nop
        \.\.\.
diff --git a/gas/testsuite/gas/mips/branch-misc-4-64.d b/gas/testsuite/gas/mips/branch-misc-4-64.d
new file mode 100644 (file)
index 0000000..13c77d7
--- /dev/null
@@ -0,0 +1,35 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch-misc-4-64
+#as: -64
+#source: branch-misc-4.s
+
+# Verify PC-relative relocations do not overflow.
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+       \.\.\.
+[0-9a-f]+ <[^>]*> 10000000     b       [0-9a-f]+ <foo\+0x[0-9a-f]+>
+[      ]*[0-9a-f]+: R_MIPS_PC16        bar\+0xf+fffc
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0xf+fffc
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0xf+fffc
+[0-9a-f]+ <[^>]*> 00000000     nop
+[0-9a-f]+ <[^>]*> 10000000     b       [0-9a-f]+ <foo\+0x[0-9a-f]+>
+[      ]*[0-9a-f]+: R_MIPS_PC16        \.init\+0x4
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0x4
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0x4
+[0-9a-f]+ <[^>]*> 00000000     nop
+       \.\.\.
+
+Disassembly of section \.init:
+[0-9a-f]+ <[^>]*> 10000000     b       [0-9a-f]+ <bar\+0x[0-9a-f]+>
+[      ]*[0-9a-f]+: R_MIPS_PC16        foo\+0xf+fffc
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0xf+fffc
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0xf+fffc
+[0-9a-f]+ <[^>]*> 00000000     nop
+[0-9a-f]+ <[^>]*> 10000000     b       [0-9a-f]+ <bar\+0x[0-9a-f]+>
+[      ]*[0-9a-f]+: R_MIPS_PC16        \.text\+0x40004
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0x40004
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0x40004
+[0-9a-f]+ <[^>]*> 00000000     nop
+       \.\.\.
diff --git a/gas/testsuite/gas/mips/branch-misc-4.d b/gas/testsuite/gas/mips/branch-misc-4.d
new file mode 100644 (file)
index 0000000..6c4e99c
--- /dev/null
@@ -0,0 +1,26 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch-misc-4
+#as: -32
+
+# Verify PC-relative relocations do not overflow.
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+       \.\.\.
+([0-9a-f]+) <[^>]*> 1000ffff   b       \1 <foo>
+[      ]*[0-9a-f]+: R_MIPS_PC16        bar
+[0-9a-f]+ <[^>]*> 00000000     nop
+([0-9a-f]+) <[^>]*> 1000ffff   b       \1 <\.Lfoo>
+[      ]*[0-9a-f]+: R_MIPS_PC16        \.Lbar
+[0-9a-f]+ <[^>]*> 00000000     nop
+       \.\.\.
+
+Disassembly of section \.init:
+([0-9a-f]+) <[^>]*> 1000ffff   b       \1 <bar>
+[      ]*[0-9a-f]+: R_MIPS_PC16        foo
+[0-9a-f]+ <[^>]*> 00000000     nop
+([0-9a-f]+) <[^>]*> 1000ffff   b       \1 <\.Lbar>
+[      ]*[0-9a-f]+: R_MIPS_PC16        \.Lfoo
+[0-9a-f]+ <[^>]*> 00000000     nop
+       \.\.\.
diff --git a/gas/testsuite/gas/mips/branch-misc-4.s b/gas/testsuite/gas/mips/branch-misc-4.s
new file mode 100644 (file)
index 0000000..0b7a817
--- /dev/null
@@ -0,0 +1,28 @@
+# Source file to verify PC-relative relocations do not overflow.
+
+       .text
+       .space  0x40000
+       .globl  foo
+       .ent    foo
+foo:
+       b       bar
+.Lfoo:
+       b       .Lbar
+       .end    foo
+
+# Force at least 8 (non-delay-slot) zero bytes, to make 'objdump' print ...
+       .align  2
+       .space  8
+
+       .section .init, "ax", @progbits
+       .globl  bar
+       .ent    bar
+bar:
+       b       foo
+.Lbar:
+       b       .Lfoo
+       .end    bar
+
+# Force at least 8 (non-delay-slot) zero bytes, to make 'objdump' print ...
+       .align  2
+       .space  8
index 056dd75c0904611dea71d293f46960fe6c2b91b1..ad11f0225ec6cb60a74961db618eafcd9f002c92 100644 (file)
@@ -830,6 +830,11 @@ if { [istarget mips*-*-vxworks*] } {
        run_dump_test "jalr2"
 
        run_dump_test_arches "aent"     [mips_arch_list_matching mips1]
+
+       run_dump_test_arches "branch-misc-4" \
+                                       [mips_arch_list_matching mips1]
+       run_dump_test_arches "branch-misc-4-64" \
+                                       [mips_arch_list_matching mips3]
     }
 
     if $has_newabi {