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

    <tr>
        <th>Summary</th>
        <td>
            __cxa_atexit@plt is used when -fno-plt is supplied
        </td>
    </tr>

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

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

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

<pre>
    (forwarded from GCC's bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115170 as GCC is doing the right thing, only clang is not).
Take:
```
struct s
{
        ~s();
};
s f;
void g();
void h()
{
 g();
}
```
With `-fno-plt -fPIE`, clang will call __cxa_atexit@plt rather than doing an indirect call to __cxa_atexit via a load from the GOT.
```

        .cfi_def_cfa_register %rbp
        movq _ZN1sD1Ev@GOTPCREL(%rip), %rdi
        leaq    f(%rip), %rsi
 leaq    __dso_handle(%rip), %rdx
        callq   __cxa_atexit@PLT
 popq    %rbp
```

vs what is done for the call to g:
```
 .cfi_def_cfa_register %rbp
        callq   *_Z1gv@GOTPCREL(%rip)
 popq    %rbp
        .cfi_def_cfa %rsp, 8
 retq
```

GCC will do an indirect call to the `__cxa_atexit@GOTPCREL`:
```

        movq    %rax, %rdi
 call    *__cxa_atexit@GOTPCREL(%rip)
        nop
        popq %rbp
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlN2OozYUx5_G3BwFGfOR5IKLmWQYVVp1R9VIlfYGGWyMu47N2CaZ7UWfvTIhaZMllYoiYez_-fr55FDnpNCclyh_Rvk-oqPvjS0Hqd13SaPGsB8lIpvO2BO1jDPorDnA626HyNpBM4o_pVIUpU_Qez84lD4hUiFSibaNhR5jYwUi1VVHKtebU92MIm6FRGklGUr3SZInawzUBccgHTAjtQDfc7BS9B58L7VAZAdGqx_QKqpFkGnjEdnGCO8Rfnqn33kIP32gAs-_6dN5O7Ye3Hy4fj4vYH7-cohsENmi9Pmi2F_XDrrr-mgkA3Ennjb7efMuwL02OF5K8Hfpe0AFXnXarAblYdW9_fISjslurvcklYKWKgV13X7Smnr-KT3KcJBb6ntuwfdUz_CoBqmZtLz1ZytvbgzhKClQUIbOdxpov359jxfzu-UVt52sGe_qtqO15UI6zy0gkttmuFUezPED6m-_Jm6fvBxRhl-_vr_tfnv5MnHJrRwCHbKbjJm8NVacfoR3tyR2F_FFVdfMmbqnmim-6P3z1nuA8jHZ3dB8-_I-6wYzTI7_XdcilqODU0_9uXE1h87YieYFu3jUlv8D5CVbRJ7qb4l4iPJx6kuXdyY5BESbWWW5__iPWsMfdOpEZhZbLNSNCnwH9ZpqgR-xWOibuQD6-VODTNFmGg8i_QxlfrS5AzLBWrzkiJUp26ZbGvEyWScFKfIsxVFfbpp2i7vNuuhykic8JwlbpzTHjG-6dcuaSJYEkwznJMEZSXMcsww3OCmapilomuRblGF-oFLFSh0PYUpG0rmRl1uyydNI0YYrd5nJtgyiVTMKhzKspPPuHzMvveLlwkiQDkbHGZx6ruE6V6QDNw6DkpxFo1Xl3dSWvh-buDUHRKoQYn6tBmv-4K1HpJrSdIhUU6Z_BwAA__-068cJ">