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

    <tr>
        <th>Summary</th>
        <td>
            [lld/ELF] LLD does not set ELFOSABI_GNU when using IFUNC
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld
      </td>
    </tr>

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

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

<pre>
    When creating a binary using IFUNC symbols with LLD, (GNU) readelf does not show the type correctly.  We see
```
692: 0000000000122de0    28 <OS specific>: 10 GLOBAL DEFAULT   18 strstr@@GLIBC_2.2
```
instead of
```
692: 0000000000122de0    28 IFUNC   GLOBAL DEFAULT   18 strstr@@GLIBC_2.2
```

It turns out that this is because GNU readelf thinks symbol type 10 means IFUNC only on GNU / Linux and FreeBSD targets (and indeed 10 is in the "OS specific" range of symbol types according to the ELF definition):
```
          if (type == STT_GNU_IFUNC
 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD))
 return "IFUNC";
```

The GNU linker has code that will set the OSABI field to ELFOSABI_GNU if the output binary contains any IFUNC symbols.  LLD does not currently appear to do so.  Should it?

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE2P4jgT_jXOpdQoqYSPHHIAkiCkqFt6aTRH5MQV4neMjWxnWf79yoHu6ZZGe9ixkImtctXzPPXBnZNnTVSw-YbNy4iPfjC2GG8kz1yLqDXiXvwYSENniXupz8ChlZrbO4wuHPf18XUL7n5pjXJwk36ApikZboHhavd6ZJiDJS5I9SAMOdDGgxvMDfxA4O9Xgs5YS51X9xnADwJHxOKSxWu2iJ-_6bjIkaVriD9XgigoBgDAFbB0-3YAd6VO9rJjaRVskxh2zdtm3UBZ1etj8w4AyQqct85blsUsi3fNfrM94Qx_G1Nq54kLMP1_gPSQBv4QwmPfe_Cj1Q7M6MEPPGzSgXTQUsdHR7B7PX4K7Qepf7pnVh4iJzFciGv3RGW0uoPR0yuGNTRSj38D1wJqS7Q5lOC5PZN3IY3hWmpBJIKbEFZP2WOIXzVHBMv1mcD0X0M74F1nrAjV4s30sGpqENRLLb00mmHO0vVvycPnkn1AMlFhacnSEg7v76fd6_E0EXqaM1wwXATLXioS3PMXllbh-zQEbeyMTlKQ9my-qfant8N6s2fz8sNl1dTTVfD74XG5Zcst_Jm7-n9VtTmUgSjmT8eWQkKDhg8CiCzd_EsFvA-PHCupf5KFgTvojKBHMdykUuDIT-pOMaGXpEQQ_CupIGMwMaO_jv6jkzujPZfaAdf37w09g9DNvxq3G60l7dUd-PVK3Ab_woAzM4DDYEYlQHqW1g_IkShSkac5j6hIlvEyxyRZYDQUedstUkLqse-WfEGiX3R8vhLtkni_4hjJAmPMYkyyJEsxwxkuRYwrweN5hlmb5CyL6cKlmin112Vm7DmSzo1UrJJlFkeKt6TcNNQQlRJB3HkZ2SJYv7Tj2bEsVtJ59-u9l15Nc3Cyr6umDpn8xj4I_E3NW5iMX-ZgNFpVDN5fXShorBnWZ-mHsZ115sKwDsGefy9Xa_5PnWdYT8gdw3oC_08AAAD__5mxqPc">