<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57722>57722</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [LLD] powerpc64/powerpc64le incorrect linkage of IFUNC symbols on FreeBSD kernel
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          adalava
      </td>
    </tr>
</table>

<pre>
    On FreeBSD powerpc64 and powerpc64le kernels panic when copyin/copyout symbols are called by external loadable kernel modules (like pfsync) after change https://reviews.freebsd.org/rG47a57144af25a7bd768b29272d50a36fdf2874ba where the IFUNC copyin/copyout functions are in a struct of function pointers.

While debugging LLD I found that the symbols get HAS_DIRECT_RELOC set and the type is changed from STT_GNU_IFUNC to STT_FUNC. A workaround is wrap the calls in a local function (see workaround code in https://reviews.freebsd.org/D36234). 
The following tentative also makes a good binary, but it's incorrect and may cause other problems: https://reviews.llvm.org/D133745

You can download LLD reproduce tar from: https://people.freebsd.org/~alfredo/tmp/llvm-freebsd-ppc64-kernel-copyout-ifunc.tar.xz
With "readelf -a kernel.full | grep -w copyout" on a good binary you should see two entries of type IFUNC while FUNC on the bad binaries.

Thanks!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVF1vnDoQ_TXwMloEhl12H3hId5PeSFErNRtV9ykasAHfNTayTej213eATTa5VaVKCPlz5pwzx1Mafi6-arizQnx6PEBvRmH7apMBan6dKQEnYbVQDnrUsoKxFRoq05-lDtjdNDCDB3fuSkNn0AqoUCnBoTyD-OHpLipQBjmWb7GgM3xQwkHAtkqeBPS1O-sqYDvAmq5A1aJuBLTe9y5IbygRfVa8SDG6qCbEpeORsc20-jnLcZ0nWYY1W2Ne8nyzLdmO5YyvY0w3Na_ZNs9KnKATPN8KuL97-rL_nUU96MpLoxceUgOC83aoPJj6bZO0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