<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 20, 2015 at 10:13 PM, Simon Atanasyan <span dir="ltr"><<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I am working on support R_MIPS_HI16 / R_MIPS_LO16 in the new LLD and<br>
have a couple of questions.<br>
<br>
== Q1<br>
In case of MIPS O32 ABI we have to find a matching R_MIPS_LO16<br>
relocation to calculate R_MIPS_HI16 one because R_MIPS_HI16 uses<br>
combined addend (AHI << 16) + (short)ALO where AHI is original<br>
R_MIPS_HI16 addend and ALO is addend of the matching R_MIPS_LO16<br>
relocation [1]. There are two methods to do matching and R_MIPS_HI16<br>
calculation.<br>
<br>
Method A:<br>
1. Postpone R_MIPS_HI16 relocation calculation and record its arguments.<br>
2. When R_MIPS_LO16 is found, iterate over recorded R_MIPS_HI16<br>
relocations, calculate combined addend and apply relocations.<br>
3. At the end check orphaned (without R_MIPS_LO16 pair) R_MIPS_HI16<br>
relocations, show warnings and apply them with zero addend.<br>
<br>
Method B:<br>
1. Each time we have found R_MIPS_HI16 relocation, iterate remaining<br>
relocations list to find matching R_MIPS_LO16.<br>
2. Calculate combined adddend and apply relocation or show warning if<br>
the R_MIPS_LO16 is not found.<br>
<br>
Method A requires some sort of container to keep postponed HI16<br>
relocations. If we add the container to the `MipsTargetInfo` class we<br>
will be able to hide all this unusual scheme inside MIPS specific code<br>
and will not need to perform LO16 lookups. But the `MipsTargetInfo`<br>
becomes stateful.<br>
<br>
Method B keeps the `MipsTargetInfo` stateless but requires forward<br>
LO16 lookup for each HI16 relocation and requires to provide an<br>
interface for such lookup to the `MipsTargetInfo`.<br>
<br>
Sure we can implement each of these methods somewhere in the<br>
`InputSectionBase` class under `if (MIPS)` statements.<br>
<br>
Any opinions about the best method / approach?<br></blockquote><div><br></div><div>If I understand that spec correctly, an R_MIPS_HI16 should immediately be followed by an R_MIPS_LO16. Can't you use that property? It doesn't seem to me that you really have to search and pair up HI16 and LO16 relocations.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
== Q2<br>
<br>
R_MIPS_HI16 and R_MIPS_LO16 relocations perform a special calculation<br>
if a target symbol's name is `_gp_disp` [2]. AFAIK now in the target<br>
`relocateOne` method there is no chance to get the traget symbol name.<br>
Is it okay to pass the target symbol index and provide<br>
`MipsTargetInfo` access to the symbol table of the processing input<br>
file?<br></blockquote><div><br></div><div>One way is to add a SymbolBody* field to Out<ELFT> struct, and let it have a pointer to _gp_disp symbol. And do pointer comparison to check if a relocation target is _gp_disp or not.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[1] <a href="ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf" rel="noreferrer" target="_blank">ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf</a> page 4-18<br>
[2] <a href="ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf" rel="noreferrer" target="_blank">ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf</a> page 4-19<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Simon Atanasyan<br>
</font></span></blockquote></div><br></div></div>