From 70e65ca8e5d1fc984d58f6137c290e807fe772a5 Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Wed, 30 Aug 2017 16:03:31 +0100 Subject: MIPS/BFD: Correct microMIPS cross-mode BAL to JALX relaxation Fix a bug in commit a6ebf6169a1b ("MIPS: Convert cross-mode BAL to JALX") and in BFD linker relaxation correct the microMIPS interpretation of the branch offset, which is supposed to be shifted by 1 bit, rather than 2 as in the regular MIPS case. bfd/ * elfxx-mips.c (mips_elf_perform_relocation): Correct microMIPS branch offset interpretation. gas/ * testsuite/gas/mips/branch-addend-micromips.d: New test. * testsuite/gas/mips/branch-addend-micromips-n32.d: New test. * testsuite/gas/mips/branch-addend-micromips-n64.d: New test. * testsuite/gas/mips/branch-addend-micromips.s: New test source. * testsuite/gas/mips/mips.exp: Run the new tests. ld/ * testsuite/ld-mips-elf/bal-jalx-addend-micromips.d: New test. * testsuite/ld-mips-elf/bal-jalx-addend-micromips-n32.d: New test. * testsuite/ld-mips-elf/bal-jalx-addend-micromips-n64.d: New test. * testsuite/ld-mips-elf/bal-jalx-local-micromips.d: New test. * testsuite/ld-mips-elf/bal-jalx-local-micromips-n32.d: New test. * testsuite/ld-mips-elf/bal-jalx-local-micromips-n64.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-micromips.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-micromips-n32.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-micromips-n64.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips-n32.d: New test. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips-n64.d: New test. * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests. --- bfd/ChangeLog | 5 +++++ bfd/elfxx-mips.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 4882260..f52e75d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2017-08-30 Maciej W. Rozycki + + * elfxx-mips.c (mips_elf_perform_relocation): Correct microMIPS + branch offset interpretation. + 2017-08-30 H.J. Lu PR binutils/22032 diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index fddf68c..6a4d3e1 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -6414,6 +6414,7 @@ mips_elf_perform_relocation (struct bfd_link_info *info, bfd_boolean ok = FALSE; bfd_vma opcode = x >> 16; bfd_vma jalx_opcode = 0; + bfd_vma sign_bit = 0; bfd_vma addr; bfd_vma dest; @@ -6421,12 +6422,14 @@ mips_elf_perform_relocation (struct bfd_link_info *info, { ok = opcode == 0x4060; jalx_opcode = 0x3c; + sign_bit = 0x10000; value <<= 1; } else if (r_type == R_MIPS_PC16 || r_type == R_MIPS_GNU_REL16_S2) { ok = opcode == 0x411; jalx_opcode = 0x1d; + sign_bit = 0x20000; value <<= 2; } @@ -6436,7 +6439,8 @@ mips_elf_perform_relocation (struct bfd_link_info *info, + input_section->output_offset + relocation->r_offset + 4); - dest = addr + (((value & 0x3ffff) ^ 0x20000) - 0x20000); + dest = (addr + + (((value & ((sign_bit << 1) - 1)) ^ sign_bit) - sign_bit)); if ((addr >> 28) << 28 != (dest >> 28) << 28) { -- cgit v1.1