[U-Boot-Users] _gp in current u-boot.lds for MIPS ports

Andrew Dyer amdyer at gmail.com
Tue Oct 16 22:15:31 CEST 2007


On 10/16/07, Wolfgang Denk <wd at denx.de> wrote:
> Dear Shinya Kuribayashi,
>
> on IRC you asked:
> >
> > In Current u-boot.lds for MIPS ports, _gp is basically equals to __got_start.
> > Is this intentional, or not?
> > If this is intentional for simplification, I'll take into account such original intention.
> > If not, I'll take Vlad suggests because what he changes is basically right as PIC code.
>
> I'm afraid I don't remember this any more. The code is as old as  the
> very  first  MIPS  port for the Infineon INCA-IP board, back in March
> 2003. It is easily possible that we didn't know any better  by  then,
> and everybody just copied the code without thinking since.
>
> Speaking for myself, I'm not much of a MIPS expert and will  rely  on
> your judgment. All I can do is helping to test changes on the INCA-IP
> board.

Typically _gp is set in the linker script to 0x7ff0 above the start of
the 'small' sections (all ELF sections with SHF_MIPS_GPREL flag), so
that all small items can be accessed by a 16 bit signed offset off of
the register allocated for _gp.  The 16-bit signed offset corresponds
to the native MIPS addressing mode.  The .got section usually comes
first in the link map and so .got + 0x7ff0 = _gp.

Somewhere in the linking process the linker calculates the signed
offset necessary for each instruction accessing data in these sections
based on the _gp symbol from the link scripts and puts that into the
appropriate offset field in the instruction.

For us, I don't believe it matters where _gp is, as long as the
relative offsets to all small items can be held in the 16 bit field
and that _gp is aligned properly.  Obviously we need to fixup the _gp
register correctly during relocation.  Since _gp is only a pointer,
IMHO it makes sense to adhere to the standard map with a 0x7ff0
offset.

(BTW, ${CROSS_COMPILE}ld --verbose will dump the normal link script
that gets used in an ELDK setup)

-- 
Hardware, n.:
        The parts of a computer system that can be kicked.




More information about the U-Boot mailing list