Adding a new option to CMake to disable C++ atexit on llvm-shlib.
authorChris Bieneman <beanz@apple.com>
Tue, 9 Dec 2014 18:49:55 +0000 (18:49 +0000)
committerChris Bieneman <beanz@apple.com>
Tue, 9 Dec 2014 18:49:55 +0000 (18:49 +0000)
Summary:
This is desirable for WebKit and other clients of the llvm-shlib because C++ exit time destructors have a tendency to crash when invoked from multi-threaded applications.

Ideally this option will be temporary, because the ideal fix is to just not have exit time destructors.

Reviewers: chapuni, ributzka

Reviewed By: ributzka

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6572

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223805 91177308-0d34-0410-b5e6-96231b3b80d8

CMakeLists.txt
include/llvm/Config/config.h.cmake
tools/llvm-shlib/libllvm.cpp

index ef07bfa615c1357b9133bd71a473a9b29a2a4553..563a249dc534c1ae37717f403546bebdcc378181 100644 (file)
@@ -324,6 +324,10 @@ option (LLVM_BUILD_EXTERNAL_COMPILER_RT
   "Build compiler-rt as an external project." OFF)
 
 option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" OFF)
+option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ON)
+if(LLVM_DISABLE_LLVM_DYLIB_ATEXIT)
+  set(DISABLE_LLVM_DYLIB_ATEXIT 1)
+endif()
 
 # All options referred to from HandleLLVMOptions have to be specified
 # BEFORE this include, otherwise options will not be correctly set on
index 0017d737772219402814288cd955028c3306f705..d154135e25b2ce345ec55f1eee28e241a86b5034 100644 (file)
@@ -18,6 +18,9 @@
 /* Define to enable crash overrides */
 #cmakedefine ENABLE_CRASH_OVERRIDES
 
+/* Define to disable C++ atexit */
+#cmakedefine DISABLE_LLVM_DYLIB_ATEXIT
+
 /* Define if position independent code is enabled */
 #cmakedefine ENABLE_PIC
 
index 40b4f66b0733135a9d0ca726acb390b3f0eb2533..8424d660c9d0e0e17714378d1b9e8bfa84fd0677 100644 (file)
 // you can't define a target with no sources.
 //
 //===----------------------------------------------------------------------===//
+
+#include "llvm/Config/config.h"
+
+#if defined(DISABLE_LLVM_DYLIB_ATEXIT)
+extern "C" int __cxa_atexit();
+extern "C" int __cxa_atexit() { return 0; }
+#endif