[LLVMdev] [llvm] r205200 - [mips] Implement missing relocations in the integrated assembler.
Rafael Espíndola
rafael.espindola at gmail.com
Mon Mar 31 11:58:40 PDT 2014
On 31 March 2014 14:55, Simon Atanasyan <simon at atanasyan.com> wrote:
> CC to the group.
thanks
>> Note 1: R_MIPS_LO16 can be alone and does not have a paired R_MIPS_HI16
>> Note 2: Several R_MIPS_HI16s can be attached to the same R_MIPS_LO16
>>
>> R_MIPS_HI16 (1)
>> R_MIPS_HI16 (2)
>> R_MIPS_LO16 (3)
>> R_MIPS_LO16 (4)
>>
>> If all relocations above are against the same symbol then:
>> bfd linker:
>> a) process 1 and find 3
>> b) process 2 and find 3 again
>> c) 4 is alone
>>
>> gold linker:
>> a) save 1
>> b) save 2
>> c) process 3 and handle 1 and 2
>> d) 4 is alone
>>
>>> Just as a curiosity (from the MC perspective), why is the linker
>>> required to match these relocations?
>>
>> To handle R_MIPS_HI16 and R_MIPS_LO16 relocations we need a "combined"
>> addend "AHL". This addend is calculated using addends from both
>> R_MIPS_HI16 ("AHI") and R_MIPS_LO16 ("ALO"). That is why we need to
>> pair these relocations.
>>
>> AHL = (AHI << 16) + (short)ALO
>>
>> R_MIPS_LO16: AHL + symbol
>> R_MIPS_HI16: ((AHL + symbol) – (short)(AHL + symbol)) >> 16
Ah, having a LO16 map to multiple relocations explains the problem. If
they were 1:1, they could be applied independently, right? The linker
would just need to be careful to not overwrite the other 16 bits.
Cheers,
Rafael
More information about the llvm-dev
mailing list