Question about MIPS GOT / value computed into $gp.
David Daney
ddaney@avtrex.com
Tue Jan 30 21:49:00 GMT 2007
More information about the Binutils mailing list
Tue Jan 30 21:49:00 GMT 2007
- Previous message (by thread): Question about MIPS GOT / value computed into $gp.
- Next message (by thread): PATCH: PR binutils/3945: Can't enable both x86_64-mingw32 and i386-mingw32 at the same time
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
John wrote:
> Hi Folks,
>
> I have a question about the value held in $gp pointing to the GOT in
> MIPS generated code after static linking.
> I'm not sure whether this is/was an issue with binutils (i'm stuck
> with ld version 2.13.90.0.20 for a couple of reasons), or whether I've
> just missed something from the MIPS/SysV abi. Apologies if this is the
> wrong place to solicit an answer to my question.
>
It is unfortunate that you are stuck. The current CVS HEAD fixes many
bugs in mips support.
> My question is why the gp computed in the statically linked code is
> 0x10 off what i expected it to be.
Look in the linker scripts. _gp and (thus _gp_disp) are 0x7ff0 from the
start of the .got output section. I think the ABI documents address
this point. The locations just prior to the got point to the dynamic
linker entry point used to resolve PLT entries via the linker stubs.
Your missing 0x10 is needed as part of the linker stub protocol as
access to these locations is always done relative to $gp.
> For example, given the following source (in functions.c)
>
> int sum(int a, int b)
> {
> return a + b;
> }
> [snip]
>
> I get the following code after doing a gcc -c functions.c followed by an
> objdump
>
> 00000000 <sum>:
> 0: 3c1c0000 lui gp,0x0
> 0: R_MIPS_HI16 _gp_disp
> 4: 279c0000 addiu gp,gp,0
> 4: R_MIPS_LO16 _gp_disp
> 8: 0399e021 addu gp,gp,t9
> [snip]
>
> after static linking against uClibc (and an objdump -D), this becomes:
>
> 00400300 <sum>:
> 400300: 3c1c0005 lui gp,0x5
> 400304: 279c8660 addiu gp,gp,-31136
> # distance between start of sum and the middle of the got now in gp
> 400308: 0399e021 addu gp,gp,t9
> # virtual address of sum is in $t9, so gp now points to middle of got
> [...]
> 00440970 <_GLOBAL_OFFSET_TABLE_>:
> 440970: 00000000 nop
> 440974: 80000000 lb zero,0(zero)
>
> It evaluates $gp to 0x448960 in 'sum' rather than the middle of the
> GOT, which would be 0x440970 + 2^15 (which is 0x448970)?
> Have I missed something obvious?
>
I don't know. Are you having some problem? Or are you just trying to
understand how it works?
David Daney
- Previous message (by thread): Question about MIPS GOT / value computed into $gp.
- Next message (by thread): PATCH: PR binutils/3945: Can't enable both x86_64-mingw32 and i386-mingw32 at the same time
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list