[U-Boot] [u-boot-mips] gp init and -pie option

Daniel Schwierzeck daniel.schwierzeck at gmail.com
Tue Feb 26 10:52:50 CET 2013


2013/2/25 Juhyun (Justin) Oh <Juhyun_Oh at sigmadesigns.com>:
> Hi,
>
> I got a problem while I was trying out v2013.01.01 on the u-boot-mips fork repo. It looks like my u-boot binary built with "-pie" linker option doesn't work due to wrong "gp" initialization.
>
> In the "start.S" file, the gp is supposed to be initialized with "_gp" because ra will hold the address of ".word _gp" line. The below is part of "start.S".
>
> ----------------------------
> ...
>     /* Initialize $gp */
>     bal 1f
>      nop
>     .word   _gp
> 1:
>     lw  gp, 0(ra)
> ...
> ----------------------------
>
> Without the -pie option, linker puts the start address of the .got section. However, with -pie option, the ".word _gp" is translated to "nop". The below is disassembled code.
>
> ----------------------------------------------------------------------------
> 84001490 <reset>:
> ...
> 840014b8:   40804800    mtc0    zero,c0_count
> 840014bc:   40805800    mtc0    zero,c0_compare
> 840014c0:   04110002    bal 840014cc <reset+0x3c>
> 840014c4:   00000000    nop
> 840014c8:   00000000    nop <---------------
> 840014cc:   8ffc0000    lw  gp,0(ra)
> 840014d0:   3c1d8440    lui sp,0x8440
> 840014d4:   8f9982c0    lw  t9,-32064(gp)
> 840014d8:   03200008    jr  t9
> 840014dc:   00000000    nop
> ----------------------------------------------------------------------------
>
> Could anyone tell me what is going on here? Am I missing anything?
>
> Thanks,
> Justin

which board and toolchain do you use?

PIE support has been tested with various toolchains from ELDK,
CodeSourcery and OpenWRT.

-- 
Best regards,
Daniel


More information about the U-Boot mailing list