This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Suppress C++ static destructor registration
AbandonedPublic

Authored by bruno on Jul 18 2016, 1:39 PM.

Details

Summary

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 the compiler flag -fno-cxx-static-destructors, which allows clang to suppress static destructor registration (suppress emitting __cxa_atexit, atexit, etc).

Diff Detail

Event Timeline

bruno updated this revision to Diff 64217.Jul 18 2016, 1:39 PM
bruno retitled this revision from to [CodeGen] Suppress C++ static destructor registration.
bruno updated this object.
bruno added reviewers: rsmith, doug.gregor.
bruno added subscribers: cfe-commits, dexonsmith.
davide added a subscriber: davide.Jul 18 2016, 1:51 PM
rsmith edited edge metadata.Jul 18 2016, 2:28 PM

Interested reviewers, see also discussion here of whether we want this feature: http://lists.llvm.org/pipermail/cfe-dev/2016-July/050040.html

bruno abandoned this revision.Nov 5 2020, 7:04 PM