aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/ChangeLog10
-rw-r--r--bfd/elf32-mips.c1
-rw-r--r--bfd/elfxx-mips.c27
3 files changed, 30 insertions, 8 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index a18c0db..95e033c 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,13 @@
+2009-08-05 Chao-ying Fu <fu@mips.com>
+
+ * elf32-mips.c (mips_reloc_map): Add BFD_RELOC_MIPS_JALR.
+ * elfxx-mips.c (JAL_TO_BAL_P): New define to transform JAL to BAL
+ for CPUs. It is true for RM9000.
+ (JALR_TO_BAL_P): New define to transform JALR to BAL. It is true
+ for all CPUs.
+ (mips_elf_perform_relocation): Use JAL_TO_BAL_P and JALR_TO_BAL_P
+ to guard the transformation.
+
2009-08-05 Trevor Smigiel <Trevor_Smigiel@playstation.sony.com>
* elf32-spu.h (spu_elf_params): Add member emit_fixups.
diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c
index c928586..ba3ee91 100644
--- a/bfd/elf32-mips.c
+++ b/bfd/elf32-mips.c
@@ -1261,6 +1261,7 @@ static const struct elf_reloc_map mips_reloc_map[] =
{ BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
{ BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
{ BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
+ { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
{ BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
{ BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
{ BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 814ba90..ec712fa 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -668,6 +668,17 @@ static bfd *reldyn_sorting_bfd;
( ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) != E_MIPS_ARCH_1) \
|| ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_3900))
+/* True if ABFD is for CPUs that are faster if JAL is converted to BAL.
+ This should be safe for all architectures. We enable this predicate
+ for RM9000 for now. */
+#define JAL_TO_BAL_P(abfd) \
+ ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_9000)
+
+/* True if ABFD is for CPUs that are faster if JALR is converted to BAL.
+ This should be safe for all architectures. We enable this predicate for
+ all CPUs. */
+#define JALR_TO_BAL_P(abfd) 1
+
/* True if ABFD is a PIC object. */
#define PIC_OBJECT_P(abfd) \
((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) != 0)
@@ -5586,15 +5597,15 @@ mips_elf_perform_relocation (struct bfd_link_info *info,
x = (x & ~(0x3f << 26)) | (jalx_opcode << 26);
}
- /* On the RM9000, bal is faster than jal, because bal uses branch
- prediction hardware. If we are linking for the RM9000, and we
- see jal, and bal fits, use it instead. Note that this
- transformation should be safe for all architectures. */
- if (bfd_get_mach (input_bfd) == bfd_mach_mips9000
- && !info->relocatable
+ /* Try converting JAL and JALR to BAL, if the target is in range. */
+ if (!info->relocatable
&& !require_jalx
- && ((r_type == R_MIPS_26 && (x >> 26) == 0x3) /* jal addr */
- || (r_type == R_MIPS_JALR && x == 0x0320f809))) /* jalr t9 */
+ && ((JAL_TO_BAL_P (input_bfd)
+ && r_type == R_MIPS_26
+ && (x >> 26) == 0x3) /* jal addr */
+ || (JALR_TO_BAL_P (input_bfd)
+ && r_type == R_MIPS_JALR
+ && x == 0x0320f809))) /* jalr t9 */
{
bfd_vma addr;
bfd_vma dest;