Use llvm_shutdown_obj to fix "static initialization order fiasco."
Yesterday we added a static guard, which is removed from this commit.
Using llvm_shutdown_obj will avoid the ordering problem.
Change-Id: Iaa2e4293373c849f6b07082fb70b49ff0e805033
diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc
index 6646b19..67b3f4d 100644
--- a/src/compiler_llvm/compiler_llvm.cc
+++ b/src/compiler_llvm/compiler_llvm.cc
@@ -41,10 +41,11 @@
// ARMISelLowering.cpp, however, it is not in the llvm namespace.
-namespace art {
-namespace compiler_llvm {
+namespace {
-CompilerLLVM::LLVMInitializer::LLVMInitializer() {
+pthread_once_t llvm_initialized = PTHREAD_ONCE_INIT;
+
+void InitializeLLVM() {
// NOTE: Uncomment following line to show the time consumption of LLVM passes
//llvm::TimePassesIsEnabled = true;
@@ -75,13 +76,15 @@
llvm::llvm_start_multithreaded();
}
-CompilerLLVM::LLVMInitializer::~LLVMInitializer() {
- llvm::llvm_shutdown();
-}
-
// Singleton. Otherwise, multiple CompilerLLVM instances may cause crashes if
// one shuts down prematurely.
-CompilerLLVM::LLVMInitializer CompilerLLVM::llvm_initialize_guard;
+llvm::llvm_shutdown_obj llvm_guard;
+
+} // anonymous namespace
+
+
+namespace art {
+namespace compiler_llvm {
llvm::Module* makeLLVMModuleContents(llvm::Module* module);
@@ -90,6 +93,10 @@
CompilerLLVM::CompilerLLVM(Compiler* compiler, InstructionSet insn_set)
: compiler_(compiler), compiler_lock_("llvm_compiler_lock"),
insn_set_(insn_set), curr_cunit_(NULL) {
+
+
+ // Initialize LLVM libraries
+ pthread_once(&llvm_initialized, InitializeLLVM);
}