This is the mail archive of the
mailing list for the binutils project.
How ld decides offset for relocation type MIPS GPREL16?
- From: Qinglai Xiao <jigsaw at gmail dot com>
- To: binutils at sourceware dot org
- Date: Sat, 7 Jul 2012 11:02:35 +0300
- Subject: How ld decides offset for relocation type MIPS GPREL16?
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.
And I believe the related code is in routine
_bfd_mips_elf_gprel16_reloc of binutils/src/bfd/elf32-mips.c.
But I'm not able to figure out how this is calculated.
Could someone give a hand?