From 44d3da2338157ad7acfd6facbcfb38ed6ec94fa1 Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Tue, 24 May 2016 13:54:31 +0100 Subject: [PATCH] MIPS/GAS: Treat local jump relocs the same no matter if REL or RELA Do not convert jump relocs against local MIPS16 or microMIPS symbols to refer to a section symbol instead even on RELA targets, as it makes it impossible for the linker to make a JAL to JALX conversion based on ISA symbol annotation, breaking regular and compressed MIPS interlinking. gas/ * config/tc-mips.c (mips_fix_adjustable): Also return 0 for jump relocations against MIPS16 or microMIPS symbols on RELA targets. * testsuite/gas/mips/jalx-local.d: New test. * testsuite/gas/mips/jalx-local-n32.d: New test. * testsuite/gas/mips/jalx-local-n64.d: New test. * testsuite/gas/mips/jalx-local.s: New test source. * testsuite/gas/mips/mips.exp: Run the new tests. ld/ * testsuite/ld-mips-elf/jalx-local.d: New test. * testsuite/ld-mips-elf/jalx-local-n32.d: New test. * testsuite/ld-mips-elf/jalx-local-n64.d: New test. * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests. --- gas/ChangeLog | 11 +++++++ gas/config/tc-mips.c | 13 ++++---- gas/testsuite/gas/mips/jalx-local-n32.d | 29 ++++++++++++++++++ gas/testsuite/gas/mips/jalx-local-n64.d | 37 +++++++++++++++++++++++ gas/testsuite/gas/mips/jalx-local.d | 28 +++++++++++++++++ gas/testsuite/gas/mips/jalx-local.s | 33 ++++++++++++++++++++ gas/testsuite/gas/mips/mips.exp | 3 ++ ld/ChangeLog | 7 +++++ ld/testsuite/ld-mips-elf/jalx-local-n32.d | 6 ++++ ld/testsuite/ld-mips-elf/jalx-local-n64.d | 6 ++++ ld/testsuite/ld-mips-elf/jalx-local.d | 26 ++++++++++++++++ ld/testsuite/ld-mips-elf/mips-elf.exp | 3 ++ 12 files changed, 195 insertions(+), 7 deletions(-) create mode 100644 gas/testsuite/gas/mips/jalx-local-n32.d create mode 100644 gas/testsuite/gas/mips/jalx-local-n64.d create mode 100644 gas/testsuite/gas/mips/jalx-local.d create mode 100644 gas/testsuite/gas/mips/jalx-local.s create mode 100644 ld/testsuite/ld-mips-elf/jalx-local-n32.d create mode 100644 ld/testsuite/ld-mips-elf/jalx-local-n64.d create mode 100644 ld/testsuite/ld-mips-elf/jalx-local.d diff --git a/gas/ChangeLog b/gas/ChangeLog index 8cf0a50c2c..03f331955c 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,14 @@ +2016-05-24 Maciej W. Rozycki + + * config/tc-mips.c (mips_fix_adjustable): Also return 0 for + jump relocations against MIPS16 or microMIPS symbols on RELA + targets. + * testsuite/gas/mips/jalx-local.d: New test. + * testsuite/gas/mips/jalx-local-n32.d: New test. + * testsuite/gas/mips/jalx-local-n64.d: New test. + * testsuite/gas/mips/jalx-local.s: New test source. + * testsuite/gas/mips/mips.exp: Run the new tests. + 2016-05-24 Maciej W. Rozycki * config/tc-mips.c (md_apply_fix) diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index 82bd8307e4..2e8be588c3 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -17165,9 +17165,9 @@ 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 on - targets with in-place addends; the relocation field cannot - encode the low bit. + 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. For simplicity, we deal with (3)-(4) by not reducing _any_ relocation against a MIPS16 symbol. We deal with (5) by by not reducing any @@ -17182,10 +17182,9 @@ mips_fix_adjustable (fixS *fixp) that we have for MIPS16 symbols. */ if (fixp->fx_subsy == NULL && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy)) - || *symbol_get_tc (fixp->fx_addsy) - || (HAVE_IN_PLACE_ADDENDS - && ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy)) - && jmp_reloc_p (fixp->fx_r_type)))) + || (ELF_ST_IS_MICROMIPS (S_GET_OTHER (fixp->fx_addsy)) + && jmp_reloc_p (fixp->fx_r_type)) + || *symbol_get_tc (fixp->fx_addsy))) return 0; return 1; diff --git a/gas/testsuite/gas/mips/jalx-local-n32.d b/gas/testsuite/gas/mips/jalx-local-n32.d new file mode 100644 index 0000000000..5db4ddbd0b --- /dev/null +++ b/gas/testsuite/gas/mips/jalx-local-n32.d @@ -0,0 +1,29 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS JALX local symbol relocation (n32) +#as: -n32 -march=from-abi +#source: jalx-local.s + +.*: +file format .*mips.* + +Disassembly of section \.text: + \.\.\. +[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero +[0-9a-f]+ <[^>]*> f400 0000 jal 00000000 +[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 \.text\+0x1020 +[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero +[0-9a-f]+ <[^>]*> f000 0000 jalx 00000000 +[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 \.text\+0x1020 +[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]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 0c000000 jal 00000000 +[ ]*[0-9a-f]+: R_MIPS_26 foo +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 74000000 jalx 00000000 +[ ]*[0-9a-f]+: R_MIPS_26 foo +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero + \.\.\. diff --git a/gas/testsuite/gas/mips/jalx-local-n64.d b/gas/testsuite/gas/mips/jalx-local-n64.d new file mode 100644 index 0000000000..6e592f87bf --- /dev/null +++ b/gas/testsuite/gas/mips/jalx-local-n64.d @@ -0,0 +1,37 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS JALX local symbol relocation (n64) +#as: -64 -march=from-abi +#source: jalx-local.s + +.*: +file format .*mips.* + +Disassembly of section \.text: + \.\.\. +[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero +[0-9a-f]+ <[^>]*> f400 0000 jal 0000000000000000 +[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 \.text\+0x1020 +[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*\+0x1020 +[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*\+0x1020 +[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero +[0-9a-f]+ <[^>]*> f000 0000 jalx 0000000000000000 +[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 \.text\+0x1020 +[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*\+0x1020 +[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\*\+0x1020 +[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]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 0c000000 jal 0000000000000000 +[ ]*[0-9a-f]+: R_MIPS_26 foo +[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\* +[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\* +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 74000000 jalx 0000000000000000 +[ ]*[0-9a-f]+: R_MIPS_26 foo +[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\* +[ ]*[0-9a-f]+: R_MIPS_NONE \*ABS\* +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero + \.\.\. diff --git a/gas/testsuite/gas/mips/jalx-local.d b/gas/testsuite/gas/mips/jalx-local.d new file mode 100644 index 0000000000..e380160ff3 --- /dev/null +++ b/gas/testsuite/gas/mips/jalx-local.d @@ -0,0 +1,28 @@ +#objdump: -dr --prefix-addresses --show-raw-insn +#name: MIPS JALX local symbol relocation +#as: -32 + +.*: +file format .*mips.* + +Disassembly of section \.text: + \.\.\. +[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero +[0-9a-f]+ <[^>]*> f400 0810 jal 00001020 +[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 \.text +[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero +[0-9a-f]+ <[^>]*> f000 0408 jalx 00001020 +[ ]*[0-9a-f]+: R_MICROMIPS_26_S1 \.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]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 0c000000 jal 00000000 +[ ]*[0-9a-f]+: R_MIPS_26 foo +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 74000000 jalx 00000000 +[ ]*[0-9a-f]+: R_MIPS_26 foo +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero + \.\.\. diff --git a/gas/testsuite/gas/mips/jalx-local.s b/gas/testsuite/gas/mips/jalx-local.s new file mode 100644 index 0000000000..fc345f6315 --- /dev/null +++ b/gas/testsuite/gas/mips/jalx-local.s @@ -0,0 +1,33 @@ + .text + .set noreorder + .space 0x1000 + + .align 4 + .set micromips + .ent foo +foo: + nor $0, $0 + jal bar + nor $0, $0 + jalx bar + nor $0, $0 + jalr $0, $ra + nor $0, $0 + .end foo + + .align 4 + .set nomicromips + .ent bar +bar: + nor $0, $0 + jal foo + nor $0, $0 + jalx 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/mips.exp b/gas/testsuite/gas/mips/mips.exp index 1b1ac02db5..f5ed6747ee 100644 --- a/gas/testsuite/gas/mips/mips.exp +++ b/gas/testsuite/gas/mips/mips.exp @@ -796,11 +796,14 @@ if { [istarget mips*-*-vxworks*] } { run_dump_test "mips-jalx-2" run_dump_test "jalx-imm" run_dump_test "jalx-addend" + run_dump_test "jalx-local" if $has_newabi { run_dump_test "jalx-imm-n32" run_dump_test "jalx-addend-n32" + run_dump_test "jalx-local-n32" run_dump_test "jalx-imm-n64" run_dump_test "jalx-addend-n64" + run_dump_test "jalx-local-n64" } # Check MIPS16 HI16/LO16 relocations run_dump_test "mips16-hilo" diff --git a/ld/ChangeLog b/ld/ChangeLog index 6509f33930..aaab50d55e 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2016-05-24 Maciej W. Rozycki + + * testsuite/ld-mips-elf/jalx-local.d: New test. + * testsuite/ld-mips-elf/jalx-local-n32.d: New test. + * testsuite/ld-mips-elf/jalx-local-n64.d: New test. + * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests. + 2016-05-23 Kuba Sejdak * Makefile.am: Add earmelf_phoenix.c. diff --git a/ld/testsuite/ld-mips-elf/jalx-local-n32.d b/ld/testsuite/ld-mips-elf/jalx-local-n32.d new file mode 100644 index 0000000000..b5615b92c2 --- /dev/null +++ b/ld/testsuite/ld-mips-elf/jalx-local-n32.d @@ -0,0 +1,6 @@ +#name: MIPS JALX to local symbol (n32) +#source: ../../../gas/testsuite/gas/mips/jalx-local.s +#as: -EB -n32 -march=from-abi +#ld: -EB -Ttext 0x1c000000 -e 0x1c000000 +#objdump: -dr --prefix-addresses --show-raw-insn +#dump: jalx-local.d diff --git a/ld/testsuite/ld-mips-elf/jalx-local-n64.d b/ld/testsuite/ld-mips-elf/jalx-local-n64.d new file mode 100644 index 0000000000..3a18363940 --- /dev/null +++ b/ld/testsuite/ld-mips-elf/jalx-local-n64.d @@ -0,0 +1,6 @@ +#name: MIPS JALX to local symbol (n64) +#source: ../../../gas/testsuite/gas/mips/jalx-local.s +#as: -EB -64 -march=from-abi +#ld: -EB -Ttext 0x1c000000 -e 0x1c000000 +#objdump: -dr --prefix-addresses --show-raw-insn +#dump: jalx-local.d diff --git a/ld/testsuite/ld-mips-elf/jalx-local.d b/ld/testsuite/ld-mips-elf/jalx-local.d new file mode 100644 index 0000000000..04538588ca --- /dev/null +++ b/ld/testsuite/ld-mips-elf/jalx-local.d @@ -0,0 +1,26 @@ +#name: MIPS JALX to local symbol +#source: ../../../gas/testsuite/gas/mips/jalx-local.s +#as: -EB -32 +#ld: -EB -Ttext 0x1c000000 -e 0x1c000000 +#objdump: -dr --prefix-addresses --show-raw-insn + +.*: +file format .*mips.* + +Disassembly of section \.text: + \.\.\. +[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero +[0-9a-f]+ <[^>]*> f300 0408 jalx 0*1c001020 <.*> +[0-9a-f]+ <[^>]*> 0000 02d0 not zero,zero +[0-9a-f]+ <[^>]*> f300 0408 jalx 0*1c001020 <.*> +[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]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 77000400 jalx 0*1c001000 <.*> +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 77000400 jalx 0*1c001000 <.*> +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero +[0-9a-f]+ <[^>]*> 03e00009 jalr zero,ra +[0-9a-f]+ <[^>]*> 00000027 nor zero,zero,zero + \.\.\. diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp index 741f2e28be..615f173e74 100644 --- a/ld/testsuite/ld-mips-elf/mips-elf.exp +++ b/ld/testsuite/ld-mips-elf/mips-elf.exp @@ -169,9 +169,12 @@ if { $linux_gnu } { } run_dump_test "jalx-addend" [list [list ld $abi_ldflags(o32)]] +run_dump_test "jalx-local" [list [list ld $abi_ldflags(o32)]] if $has_newabi { run_dump_test "jalx-addend-n32" [list [list ld $abi_ldflags(n32)]] + run_dump_test "jalx-local-n32" [list [list ld $abi_ldflags(n32)]] run_dump_test "jalx-addend-n64" [list [list ld $abi_ldflags(n64)]] + run_dump_test "jalx-local-n64" [list [list ld $abi_ldflags(n64)]] } # Test multi-got link. We only do this on GNU/Linux because it requires