This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
How ld decides offset for relocation type MIPS GPREL16?
- From: jigsaw <jigsaw at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 5 Jul 2012 22:47:32 +0300
- Subject: How ld decides offset for relocation type MIPS GPREL16?
Hi,
I'm writing a runtime linker for MIPS32 arch, and have problems with
GPREL16 relocation type.
For instance, the 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.
Given that _gp is 0x12b12220, and .sbss section starts at 0x12b11868.
( The values are read from target ELF object.)
After relocated by ld, 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 address 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?
thanks &
regards,
-Qinglai