Simon Atanasyan
2014-Mar-31 18:55 UTC
[LLVMdev] [llvm] r205200 - [mips] Implement missing relocations in the integrated assembler.
CC to the group. On Mon, Mar 31, 2014 at 9:53 PM, Simon Atanasyan <simon at atanasyan.com> wrote:> On Mon, Mar 31, 2014 at 9:27 PM, Rafael Espíndola > <rafael.espindola at gmail.com> wrote: >>> AFAIK the patch for the gold linker is under review now. Here is the >>> git repository: >>> https://dmz-portal.mips.com/git/?p=gold.git;a=blob_plain;f=src/gold/mips.cc;hb=HEAD >>> >>> Function rello16(). >>> >>> The gold linker uses slightly different approach. It postpones >>> handling of "HI" relocations and save them into containers. When it >>> handles "LO" relocation, it iterates over postponed "HI" relocations, >>> find "paired" ones and process them. >> >> >> It looks like they produce different results for >> >> R_MIPS_HI16 (1) >> R_MIPS_HI16 (2) >> R_MIPS_LO16 (3) >> R_MIPS_LO16 (4) >> >> The gas implementation will match (1,3) and (2,3) while the gold >> implementation will match (1,3) and (2,4), no? > > 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-- Simon Atanasyan
Rafael Espíndola
2014-Mar-31 18:58 UTC
[LLVMdev] [llvm] r205200 - [mips] Implement missing relocations in the integrated assembler.
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)) >> 16Ah, 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