[cfe-dev] [RFC] Suppress C++ static destructor registration
Bruno Cardoso Lopes via cfe-dev
cfe-dev at lists.llvm.org
Mon Jul 18 13:39:49 PDT 2016
C++ static destructors can be problematic in multi-threaded
environment. Some of the issues users often complain about include:
1. Teardown ordering: crashes when one thread is exiting the process
and calling destructors while another thread is still running and
accessing the destructing variables
2. Shared code that is compiled both as an application and as a
library. When library mode is chosen, goto (1).
3. Some projects currently override __cxa_atexit to avoid the behavior
To get around that, I propose we add a compiler option (e.g.
-fno-cxx-static-destructors) to allow clang to suppress destructor
registration (currently done via __cxa_atexit, atexit):
I'm opening this discussion here on cfe-dev to get some feedback on the matter
One can argue that dealing with C++ static destructors in
multi-threaded environment is solely the responsibility of the
developer, however since (AFAIK) we don't have any standard guaranteed
semantic for "global destruction vs. threads", it seems fair to me
that we could give developers some option.
Bruno Cardoso Lopes
More information about the cfe-dev