This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about MIPS GOT / value computed into $gp.

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 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;

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

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
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]