From fc34adb0c40e336c4d0582698fd6d4bf3b3de5e1 Mon Sep 17 00:00:00 2001 From: Shih-wei Liao Date: Wed, 7 Mar 2012 08:51:44 -0800 Subject: 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 --- src/compiler_llvm/compiler_llvm.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/compiler_llvm/compiler_llvm.cc') diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc index 6646b196ca..67b3f4d50c 100644 --- a/src/compiler_llvm/compiler_llvm.cc +++ b/src/compiler_llvm/compiler_llvm.cc @@ -41,10 +41,11 @@ extern llvm::cl::opt EnableARMLongCalls; // ARMISelLowering.cpp, however, it is not in the llvm namespace. -namespace art { -namespace compiler_llvm { +namespace { + +pthread_once_t llvm_initialized = PTHREAD_ONCE_INIT; -CompilerLLVM::LLVMInitializer::LLVMInitializer() { +void InitializeLLVM() { // NOTE: Uncomment following line to show the time consumption of LLVM passes //llvm::TimePassesIsEnabled = true; @@ -75,13 +76,15 @@ CompilerLLVM::LLVMInitializer::LLVMInitializer() { 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 @@ llvm::Module* makeLLVMModuleContents(llvm::Module* module); 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); } -- cgit v1.2.3-59-g8ed1b