MIPS/GAS: Keep the original microMIPS symbol reference in branch relocs
authorMaciej W. Rozycki <macro@imgtec.com>
Thu, 23 Jun 2016 10:33:52 +0000 (11:33 +0100)
committerMaciej W. Rozycki <macro@imgtec.com>
Thu, 23 Jun 2016 11:23:32 +0000 (12:23 +0100)
Keep original microMIPS symbols in references from branch relocations so
that the ISA bit is retained and can be verified for validity in static
link.  No need to update WRT MIPS16 symbols because we keep them all
anyway for other reasons.

gas/
* config/tc-mips.c (b_reloc_p): New function.
(mips_fix_adjustable): Also keep the original microMIPS symbol
referred from branch relocations.
* testsuite/gas/mips/branch-local-1.d: New test.
* testsuite/gas/mips/branch-local-n32-1.d: New test.
* testsuite/gas/mips/branch-local-n64-1.d: New test.
* testsuite/gas/mips/micromips@branch-misc-4-64.d: Update
relocations.
* testsuite/gas/mips/branch-local-1.s: New test source.
* testsuite/gas/mips/mips.exp: Run the new cases.

gas/ChangeLog
gas/config/tc-mips.c
gas/testsuite/gas/mips/branch-local-1.d [new file with mode: 0644]
gas/testsuite/gas/mips/branch-local-1.s [new file with mode: 0644]
gas/testsuite/gas/mips/branch-local-n32-1.d [new file with mode: 0644]
gas/testsuite/gas/mips/branch-local-n64-1.d [new file with mode: 0644]
gas/testsuite/gas/mips/micromips@branch-misc-4-64.d
gas/testsuite/gas/mips/mips.exp

index 66c36073410bb35e7dfb2c140a80c6dfcbf73285..782dc8e3a6095512de4c92337efb2c9ff04e7fa6 100644 (file)
@@ -1,3 +1,16 @@
+2016-06-23  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * config/tc-mips.c (b_reloc_p): New function.
+       (mips_fix_adjustable): Also keep the original microMIPS symbol
+       referred from branch relocations.
+       * testsuite/gas/mips/branch-local-1.d: New test.
+       * testsuite/gas/mips/branch-local-n32-1.d: New test.
+       * testsuite/gas/mips/branch-local-n64-1.d: New test.
+       * testsuite/gas/mips/micromips@branch-misc-4-64.d: Update
+       relocations.
+       * testsuite/gas/mips/branch-local-1.s: New test source.
+       * testsuite/gas/mips/mips.exp: Run the new cases.
+
 2016-06-23  Graham Markall  <graham.markall@embecosm.com>
 
        * config/tc-arc.c (options, md_longopts, md_parse_option): Move
index 6891508e132a38cd6b38a0d740ac2b052e8924f5..bbb604ae179d1a325b9779261f2f16089bbaf475 100644 (file)
@@ -4108,6 +4108,17 @@ jmp_reloc_p (bfd_reloc_code_real_type reloc)
   return reloc == BFD_RELOC_MIPS_JMP || reloc == BFD_RELOC_MICROMIPS_JMP;
 }
 
+static inline bfd_boolean
+b_reloc_p (bfd_reloc_code_real_type reloc)
+{
+  return (reloc == BFD_RELOC_MIPS_26_PCREL_S2
+         || reloc == BFD_RELOC_MIPS_21_PCREL_S2
+         || reloc == BFD_RELOC_16_PCREL_S2
+         || reloc == BFD_RELOC_MICROMIPS_16_PCREL_S1
+         || reloc == BFD_RELOC_MICROMIPS_10_PCREL_S1
+         || reloc == BFD_RELOC_MICROMIPS_7_PCREL_S1);
+}
+
 static inline bfd_boolean
 got16_reloc_p (bfd_reloc_code_real_type reloc)
 {
@@ -17218,13 +17229,16 @@ mips_fix_adjustable (fixS *fixp)
      There is a further restriction:
 
        5. We cannot reduce jump relocations (R_MIPS_26, R_MIPS16_26 or
-         R_MICROMIPS_26_S1) against MIPS16 or microMIPS symbols because
-         we need to keep the MIPS16 or microMIPS symbol for the purpose
-         of converting JAL to JALX instructions in the linker.
+         R_MICROMIPS_26_S1) or branch relocations (R_MIPS_PC26_S2,
+         R_MIPS_PC21_S2, R_MIPS_PC16, R_MICROMIPS_PC16_S1,
+         R_MICROMIPS_PC10_S1 or R_MICROMIPS_PC7_S1) against MIPS16 or
+         microMIPS symbols because we need to keep the MIPS16 or
+         microMIPS symbol for the purpose of mode mismatch detection
+         and JAL to JALX instruction conversion in the linker.
 
      For simplicity, we deal with (3)-(4) by not reducing _any_ relocation
      against a MIPS16 symbol.  We deal with (5) by additionally leaving
-     alone any jump relocations against a microMIPS symbol.
+     alone any jump and branch relocations against a microMIPS symbol.
 
      We deal with (1)-(2) by saying that, if there's a R_MIPS16_26
      relocation against some symbol R, no relocation against R may be
@@ -17236,7 +17250,8 @@ mips_fix_adjustable (fixS *fixp)
   if (fixp->fx_subsy == NULL
       && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
          || (ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy))
-             && jmp_reloc_p (fixp->fx_r_type))
+             && (jmp_reloc_p (fixp->fx_r_type)
+                 || b_reloc_p (fixp->fx_r_type)))
          || *symbol_get_tc (fixp->fx_addsy)))
     return 0;
 
diff --git a/gas/testsuite/gas/mips/branch-local-1.d b/gas/testsuite/gas/mips/branch-local-1.d
new file mode 100644 (file)
index 0000000..f85bb8d
--- /dev/null
@@ -0,0 +1,26 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch local symbol relocation 1
+#as: -32
+#source: branch-local-1.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+       \.\.\.
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c    jr      ra
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 0000 0000    nop
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 40e2 fffe    beqzc   v0,00001014 <bar\+0x4>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC16_S1        foo
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> cfff         b       0000101c <bar\+0xc>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC10_S1        foo
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 8d7f         beqz    v0,00001022 <bar\+0x12>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC7_S1 foo
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c    jr      ra
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+       \.\.\.
diff --git a/gas/testsuite/gas/mips/branch-local-1.s b/gas/testsuite/gas/mips/branch-local-1.s
new file mode 100644 (file)
index 0000000..4000c8f
--- /dev/null
@@ -0,0 +1,31 @@
+       .text
+       .set    noreorder
+       .space  0x1000
+
+       .align  4
+       .set    micromips
+       .ent    foo
+foo:
+       nor     $0, $0
+       jalr    $0, $ra
+        nor    $0, $0
+       .end    foo
+
+       .align  4
+       .set    micromips
+       .ent    bar
+bar:
+       nor     $0, $0
+       beqzc   $2, foo
+       nor     $0, $0
+       b       foo
+        nor    $0, $0
+       beqz    $2, foo
+        nor    $0, $0
+       jalr    $0, $ra
+        nor    $0, $0
+       .end    bar
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+       .align  4, 0
+       .space  16
diff --git a/gas/testsuite/gas/mips/branch-local-n32-1.d b/gas/testsuite/gas/mips/branch-local-n32-1.d
new file mode 100644 (file)
index 0000000..5dbf9e6
--- /dev/null
@@ -0,0 +1,26 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch local symbol relocation 1 (n32)
+#as: -n32 -march=from-abi
+#source: branch-local-1.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+       \.\.\.
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c    jr      ra
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 0000 0000    nop
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 40e2 0000    beqzc   v0,00001018 <bar\+0x8>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC16_S1        foo-0x4
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> cc00         b       0000101e <bar\+0xe>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC10_S1        foo-0x2
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 8d00         beqz    v0,00001024 <bar\+0x14>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC7_S1 foo-0x2
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c    jr      ra
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+       \.\.\.
diff --git a/gas/testsuite/gas/mips/branch-local-n64-1.d b/gas/testsuite/gas/mips/branch-local-n64-1.d
new file mode 100644 (file)
index 0000000..f20819e
--- /dev/null
@@ -0,0 +1,32 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch local symbol relocation 1 (n64)
+#as: -64 -march=from-abi
+#source: branch-local-1.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+       \.\.\.
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c    jr      ra
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 0000 0000    nop
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 40e2 0000    beqzc   v0,0000000000001018 <bar\+0x8>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC16_S1        foo-0x4
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x4
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x4
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> cc00         b       000000000000101e <bar\+0xe>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC10_S1        foo-0x2
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x2
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x2
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 8d00         beqz    v0,0000000000001024 <bar\+0x14>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC7_S1 foo-0x2
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x2
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x2
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+[0-9a-f]+ <[^>]*> 001f 0f3c    jr      ra
+[0-9a-f]+ <[^>]*> 0000 02d0    not     zero,zero
+       \.\.\.
index 008dac004ede4bcf10df2f37c7764c14fdc44647..4665d97a60f6ea4448ce096ab8757b42096b5954 100644 (file)
@@ -14,10 +14,10 @@ Disassembly of section \.text:
 [      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\-0x4
 [      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\-0x4
 [0-9a-f]+ <[^>]*> 0c00         nop
-[0-9a-f]+ <[^>]*> 9400 0000    b       [0-9a-f]+ <foo\+0x[0-9a-f]+>
-[      ]*[0-9a-f]+: R_MICROMIPS_PC16_S1        \.init\+0x2
-[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0x2
-[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0x2
+[0-9a-f]+ <[^>]*> 9400 0000    b       [0-9a-f]+ <\.Lfoo\+0x[0-9a-f]+>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC16_S1        \.Lbar-0x4
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x4
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x4
 [0-9a-f]+ <[^>]*> 0c00         nop
        \.\.\.
 
@@ -27,9 +27,9 @@ Disassembly of section \.init:
 [      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\-0x4
 [      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\-0x4
 [0-9a-f]+ <[^>]*> 0c00         nop
-[0-9a-f]+ <[^>]*> 9400 0000    b       [0-9a-f]+ <bar\+0x[0-9a-f]+>
-[      ]*[0-9a-f]+: R_MICROMIPS_PC16_S1        \.text\+0x40002
-[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0x40002
-[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*\+0x40002
+[0-9a-f]+ <[^>]*> 9400 0000    b       [0-9a-f]+ <\.Lbar\+0x[0-9a-f]+>
+[      ]*[0-9a-f]+: R_MICROMIPS_PC16_S1        \.Lfoo-0x4
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x4
+[      ]*[0-9a-f]+: R_MIPS_NONE        \*ABS\*-0x4
 [0-9a-f]+ <[^>]*> 0c00         nop
        \.\.\.
index 4236397dcf2b335a22dd54fa2c571230349adfa3..30143b86746ed8b86248590f2b87e517d67a0659 100644 (file)
@@ -588,6 +588,11 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "branch-weak-3"
     run_dump_test "branch-weak-4"
     run_dump_test "branch-weak-5"
+    run_dump_test "branch-local-1"
+    if $has_newabi {
+       run_dump_test "branch-local-n32-1"
+       run_dump_test "branch-local-n64-1"
+    }
 
     run_dump_test "compact-eh-eb-1"
     run_dump_test "compact-eh-eb-2"
This page took 0.042698 seconds and 4 git commands to generate.