* How ld decides offset for relocation type MIPS GPREL16?
@ 2012-07-07 8:02 Qinglai Xiao
2012-07-09 18:14 ` Richard Sandiford
0 siblings, 1 reply; 3+ messages in thread
From: Qinglai Xiao @ 2012-07-07 8:02 UTC (permalink / raw)
To: binutils
Hi,
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?
thanks &
regards,
-Qinglai
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How ld decides offset for relocation type MIPS GPREL16?
2012-07-07 8:02 How ld decides offset for relocation type MIPS GPREL16? Qinglai Xiao
@ 2012-07-09 18:14 ` Richard Sandiford
2012-07-10 8:19 ` Qinglai Xiao
0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2012-07-09 18:14 UTC (permalink / raw)
To: Qinglai Xiao; +Cc: binutils
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How ld decides offset for relocation type MIPS GPREL16?
2012-07-09 18:14 ` Richard Sandiford
@ 2012-07-10 8:19 ` Qinglai Xiao
0 siblings, 0 replies; 3+ messages in thread
From: Qinglai Xiao @ 2012-07-10 8:19 UTC (permalink / raw)
To: Qinglai Xiao, binutils, rdsandiford
>> (ELF GP value in original object's .reginfo)
This is what I'm looking for. Thanks a bunch!
regards,
-Qinglai
On Mon, Jul 9, 2012 at 9:14 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-07-10 8:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-07 8:02 How ld decides offset for relocation type MIPS GPREL16? Qinglai Xiao
2012-07-09 18:14 ` Richard Sandiford
2012-07-10 8:19 ` Qinglai Xiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).