[clang] [Clang] Ensure that .fini_array is available with -fno-use-cxa-atexit (PR #211963)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 26 00:16:31 PDT 2026
pyxherb wrote:
> Running C++ destructors using .fini_array is nowhere near compliant with standard requirements; the standard requires destructors to run in a specific order. And that order exists for good reasons: destruction in the wrong order is likely to lead to use-after-free, or destroying objects which were never constructed.
>
> Are you sure you can't use `-fno-c++-static-destructors`? That suppresses atexit calls in a way that's much less likely to explode.
`-fno-c++-static-destructors` completely prevents the destructor from running (at least in our practical test, it actually does so), this leads to some resource leaks in our scenario (kernel modules), unless we manually destruct all of the global variables, which will make the codes much more complicated.
If there are codes that sort the destructors and put them into the `atexit()` calls in correct order, there may be some ways to implement an equivalent mechanism for .fini_array and let the global variables destruct correctly. But anyway current codes of this PR have to be modified.
https://github.com/llvm/llvm-project/pull/211963
More information about the cfe-commits
mailing list