MIPS JAL/JALR to BAL transformation for Linux (o32 ABI)

Richard Sandiford rdsandiford@googlemail.com
Sat Aug 1 08:08:00 GMT 2009


"Fu, Chao-Ying" <fu@mips.com> writes:
> Ex 2: (Calls not in a shared library)
> # cat call.c
> int t2() { return 1984 + t3(); }
> int t3() { return 0; }
>
> # cc1 -quiet call.c -O2 -mabicalls -mno-shared -G0 -o call.s -fno-inline-small-functions
> # as-new call.s -o call.o -mips32r2
> # objdump -dr call.o
> call.o:     file format elf32-tradbigmips
>
>
> Disassembly of section .text:
>
> 00000000 <t3>:
>    0:   03e00008        jr      ra
>    4:   00001021        move    v0,zero
>
> 00000008 <t2>:
>    8:   27bdffe0        addiu   sp,sp,-32
>    c:   afbf001c        sw      ra,28(sp)
>   10:   0c000000        jal     0 <t3>	<-----------------
>                         10: R_MIPS_26   t3
>   14:   00000000        nop
>   18:   8fbf001c        lw      ra,28(sp)
>   1c:   244207c0        addiu   v0,v0,1984
>   20:   03e00008        jr      ra
>   24:   27bd0020        addiu   sp,sp,32
>
> # ld-new call.o -o call
> # objdump -dr call
> call:     file format elf32-tradbigmips
>
>
> Disassembly of section .text:
>
> 0040006c <t3>:
>   40006c:       03e00008        jr      ra
>   400070:       00001021        move    v0,zero
>
> 00400074 <t2>:
>   400074:       27bdffe0        addiu   sp,sp,-32
>   400078:       afbf001c        sw      ra,28(sp)
>   40007c:       0411fffb        bal     40006c <t3> 	<-----------------
>   400080:       00000000        nop
>   400084:       8fbf001c        lw      ra,28(sp)
>   400088:       244207c0        addiu   v0,v0,1984
>   40008c:       03e00008        jr      ra
>   400090:       27bd0020        addiu   sp,sp,32

You probably know this already, but since it wasn't explicitly
mentioned: -mno-shared -mexplicit-relocs will achieve the same effect
in cases like these, and should be more efficient.  The optimisation is
still useful for cross-TU calls though.  Hopefully LTO will eventually
make that case work with -mno-shared -mexplicit-relocs too.

Richard



More information about the Binutils mailing list