MIPS JAL/JALR to BAL transformation for Linux (o32 ABI)
Richard Sandiford
rdsandiford@googlemail.com
Wed Aug 5 19:34:00 GMT 2009
"Fu, Chao-Ying" <fu@mips.com> writes:
> @@ -5590,11 +5601,12 @@ mips_elf_perform_relocation (struct bfd_
> 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. */
You need to update this comment too. With the new macros, it can
be a lot simpler, such as:
/* Try converting JAL and JALR to BAL, if the target is in range. */
> - if (bfd_get_mach (input_bfd) == bfd_mach_mips9000
> - && !info->relocatable
> + 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 */
Odd formatting. I think it should be:
if (!info->relocatable
&& !require_jalx
&& ((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 */
More importantly, I think we should be checking the output_bfd
rather than the input bfd. E.g. if you were linking legacy MIPS 3
n32 objects with MIPS64 objects, you'd want the MIPS64-related
optimisations to be applied to both.
Looks good to me with those changes.
Richard
More information about the Binutils
mailing list