<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 2, 2016 at 2:13 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 2 February 2016 at 16:43, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> I guess that I still don't fully understand this piece of code. When we<br>
> reach here for what? Can you describe it a little bit more in detail for me?<br>
<br>
</span>Sure. The code is trying to decide if a given relocation can be fully<br>
resolved by the static linker or if needs to ask the dynamic linker<br>
for help (i.e., create a dynamic relocation).<br>
<br>
The static linker cannot know the final answer when:<br>
<br>
* The symbol can be preempted. That is, the symbol the static linker<br>
is seeing might not be the one used at runtime.<br>
* The symbol is the final one, but the value the relocation wants<br>
depends on where the code is placed in memory.<br>
<br>
 I actually find it a bit harder to follow now that part of the code<br>
is duplicated in the "need got" if. We have:<br>
<br>
-------------------------------<br>
    bool CBP = canBePreempted(Body, /*NeedsGot=*/true);<br>
<span class="">      bool Dynrel = Config->Shared && !Target->isRelRelative(Type) &&<br>
</span>                    !Target->isSizeRel(Type);<br>
      if (CBP)<br>
        Body->setUsedInDynamicReloc();<br>
      if (CBP || Dynrel)<br>
<span class="">        Out<ELFT>::RelaDyn->addReloc({&C, &RI});<br>
</span>......<br>
<span class=""><br>
<br>
  if (canBePreempted(Body, /*NeedsGot=*/false)) {<br>
      Body->setUsedInDynamicReloc();<br>
</span><span class="">      Out<ELFT>::RelaDyn->addReloc({&C, &RI});<br>
</span>      continue;<br>
<span class="">    }<br>
<br>
    // If we get here, the code we are handling is not PIC. We need to copy<br>
</span><span class="">    // relocations from object files to the output file, so that the<br>
</span><span class="">    // dynamic linker can fix up addresses. But there are a few exceptions.<br>
</span><span class="">    // If the relocation will not change at runtime, we don't need to copy<br>
</span><span class="">    // them. For example, we don't copy PC-relative relocations because<br>
</span><span class="">    // the distance between two symbols won't change whereever they are<br>
</span><span class="">    // loaded. Likewise, if we are linking an executable, it will be loaded<br>
</span><span class="">    // at a fixed address, so we don't copy relocations.<br>
</span><span class="">    if (Config->Shared && !Target->isRelRelative(Type) &&<br>
</span><span class="">        !Target->isSizeRel(Type))<br>
       Out<ELFT>::RelaDyn->addReloc({&C, &RI});<br>
</span>----------------------------<br>
<br>
The two calls to setUsedInDynamicReloc and RelaDyn->addReloc should be merged.<br></blockquote><div><br></div><div>The point of my patches is to make code a series of the decisions like</div><div><br></div><div> - here we are handling <i>something</i> (e.g. relocation against IFUNC), and in this case we need to create something and something (e.g. GOT and PLT) and nothing more</div><div><br></div><div>Previously, there were bunch of cascading if's that affect each other, so it was not clear how many cases we need to handle and what we want for each case.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The overall structure of how we collect information for dynamic<br>
relocations should be fixed too, I will try to do that next.<br>
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div></div>