[cfe-dev] [RFC] Suppress C++ static destructor registration
James Knight via cfe-dev
cfe-dev at lists.llvm.org
Mon Jul 18 17:37:19 PDT 2016
That sounds like a nice idea. The standards-required behavior of tearing down globals is insane, and it'd sure be nice to be able to easily opt out of the insanity. It'd be nicest if it was supported in both GCC and Clang with the same flag, of course. :)
std::quick_exit is just about worthless, because there's just about no practical way that you can ever get all the code linked into your binary to stop calling exit().
IMO, the standard should just entirely remove the utterly broken global destructors "feature".
In the "interim", a compiler flag is nice because you can set it in your build system, and all your existing code just starts working better (where better = fewer random unreproducible crashes on shutdown when someone accidentally used a global with a destructor). And you don't ever have to worry about this problem again...
> On Jul 18, 2016, at 4:39 PM, Bruno Cardoso Lopes via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>
> Hi,
>
> 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
> in question.
>
> 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):
> https://reviews.llvm.org/D22474
>
> 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.
>
> Cheers,
>
> --
> Bruno Cardoso Lopes
> http://www.brunocardoso.cc
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list