<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Stop indirecting non-preemptable ifuncs via the PLT if it can be avoided"
   href="https://bugs.llvm.org/show_bug.cgi?id=40474">40474</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Stop indirecting non-preemptable ifuncs via the PLT if it can be avoided
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>peter@pcc.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is a follow up to my <a href="show_bug.cgi?id=40474#c3">comment 3</a> in pr40250.

I've been giving this some more thought and it seems like there is only one
case where we need to create a PLT for an ifunc and redirect all references to
the ifunc (including GOT) to point to it, and that is the case where the
executable is non-PIC, there is a direct (non-GOT, non-PLT) relocation
referring to the ifunc, and the --ignore-function-address-equality argument
isn't passed. In this case, the address taken by the direct relocation and the
address in the GOT need to be equal. And since there isn't necessarily a
dynamic loader to fix up the direct relocation references for us (we can only
rely on a statically linked libc being able to apply the IRELATIVE relocs to
the GOT in __rela?_iplt_{start,end}), the symbol needs to have a constant
value, i.e. the address of the PLT entry. This is similar to the case of
pseudo-PLTs in dynamically relocated non-PIC binaries that we support already.

In PIC binaries, I think we can just use either the IRELATIVE (for the GOT) or
dynamic relocations (everything else). If --ignore-function-address-equality is
passed we can create the PLT and just make the direct and PLT relocations point
to it, leaving the GOT relocations pointing at the IRELATIVE.

Notably, this provides a way for sanitizers (and other users of
ifunc-resolves-to-data) to continue to work in a static executable: they simply
need to ensure that *all* references to their ifunc go via the GOT. Since the
sanitizers control the code that they generate, this seems doable to me. For
example in IR the sanitizers should be able to set dso_preemptable on the
GlobalVariable referring to the ifunc to ensure that the references go via the
GOT even without -fPIE.

Peter, does that match your understanding? I can also try to take a look at
this if you're not planning to take a look soon.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>