From 0e39210161e7c547ab53afb86997303e24a42c0c Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Tue, 28 Feb 2017 00:14:08 +0000 Subject: MIPS/BFD: Also handle `jalr $0, $25' with R_MIPS_JALR Interpret the `jalr $0, $25' instruction encoding with an R_MIPS_JALR relocation attached as an alias to `jr $25' and convert the jump to an equivalent branch where possible, consequently covering the MIPSr6 architecture for the purpose of this optimization too. bfd/ * elfxx-mips.c (mips_elf_perform_relocation): Also handle the `jalr $0, $25' instruction encoding. gas/ * testsuite/gas/mips/jalr4.s: Add `jalr $0, $25' instructions. * testsuite/gas/mips/jalr4.d: Adjust accordingly. Remove MIPSr6 encoding patterns. * testsuite/gas/mips/jalr4-n64.d: Likewise. * testsuite/gas/mips/mipsr6@jalr4.d: New test. * testsuite/gas/mips/mipsr6@jalr4-n32.d: New test. * testsuite/gas/mips/mipsr6@jalr4-n64.d: New test. ld/ * testsuite/ld-mips-elf/jalr4.dd: Adjust for `jalr $0, $25' instructions. * testsuite/ld-mips-elf/jalr4-r6.dd: New test. * testsuite/ld-mips-elf/mips-elf.exp: Run the new test. --- bfd/elfxx-mips.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bfd/elfxx-mips.c') diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 9693442..7a1d5f8 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -6465,13 +6465,13 @@ mips_elf_perform_relocation (struct bfd_link_info *info, && !cross_mode_jump_p && ((JAL_TO_BAL_P (input_bfd) && r_type == R_MIPS_26 - && (x >> 26) == 0x3) /* jal addr */ + && (x >> 26) == 0x3) /* jal addr */ || (JALR_TO_BAL_P (input_bfd) && r_type == R_MIPS_JALR - && x == 0x0320f809) /* jalr t9 */ + && x == 0x0320f809) /* jalr t9 */ || (JR_TO_B_P (input_bfd) && r_type == R_MIPS_JALR - && x == 0x03200008))) /* jr t9 */ + && (x & ~1) == 0x03200008))) /* jr t9 / jalr zero, t9 */ { bfd_vma addr; bfd_vma dest; @@ -6488,7 +6488,7 @@ mips_elf_perform_relocation (struct bfd_link_info *info, off = dest - addr; if (off <= 0x1ffff && off >= -0x20000) { - if (x == 0x03200008) /* jr t9 */ + if ((x & ~1) == 0x03200008) /* jr t9 / jalr zero, t9 */ x = 0x10000000 | (((bfd_vma) off >> 2) & 0xffff); /* b addr */ else x = 0x04110000 | (((bfd_vma) off >> 2) & 0xffff); /* bal addr */ -- cgit v1.1