This is the mail archive of the binutils@sourceware.org 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: How ld decides offset for relocation type MIPS GPREL16?


Qinglai Xiao <jigsaw@gmail.com> writes:
> I'm writing a runtime linker for MIPS32 arch, and have problems with
> GPREL16 relocation type.
> For instance, the GNU compiler/assembler outputs a relocatable object with
> an instruction as below :
>
>     ff838018        sd      v1,-32744(gp)
>
> The symbol involved here belongs to .sbss section, and is set to
> runtime address 0x12b119e8.
>
> After relocated by ld,
> _gp = .0x12b12220
> .sdata = 0x12b0a228
> .sbss =  0x12b11868
> Size of .sdata is 0x7640 and size of .sbss is 0x770.
> ( The values are read from target ELF object.)
>
> And the instruction becomes:
>
>     ff83f7c8        sd      v1,-2104(gp)
>
> My question is: How ld calculates the offset 0xf7c8?
> My guess is that 0xf7c8 is calculated by _gp, .sbss/.sdata addresses and
> original offset 0x8018.

Yeah.  For local symbols (including .sbss and .sdata section symbols
like you say) it's:

   (symbol value)
   + (original offset)
   + (ELF GP value in original object's .reginfo)
   - (_gp value in final link)

> And I believe the related code is in routine
> _bfd_mips_elf_gprel16_reloc of binutils/src/bfd/elf32-mips.c.

That's the code that writes the offset, but it's the R_MIPS_GPREL16
case in mips_elf_calculate_relocation that does the calculation above.

Richard


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