<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 - [PowerPC64] lld incorrectly optimizes ifunc TOC relocations"
   href="https://bugs.llvm.org/show_bug.cgi?id=42759">42759</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[PowerPC64] lld incorrectly optimizes ifunc TOC relocations
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>luporl@FreeBSD.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following C fragment:

void (*funcptr)(void) = my_ifunc;
(*funcptr)();


Where my_ifunc is an ifunc. When built with clang and linked with lld, the
program will call the ifunc resolver, instead of the function returned by it.

Inspecting the .o file, it can be seen that clang emits code to load the
pointer to my_ifunc from the TOC, which is patched by the dynamic linker or C
startup code (for static binaries).

The problem is that lld is optimizing this load from TOC, replacing it by an
addis/addi pair to get the function address. This is valid for regular
functions, but not for ifuncs.

The issue doesn't happen if --no-toc-optimize is passed to lld, or if the
program is linked with bfd. It also doesn't happen if the ifunc is defined in a
separate .so file.

I have a reproduce tar file, but it has 2.5 MB when compressed with xz, which
is over the 1000 KB attachment limit.</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>