make sure to unlock keymgr if the JIT is created and destroyed, all
[oota-llvm.git] / lib / ExecutionEngine / JIT / JIT.cpp
index 386c3beedd6ca4572f7081c20dfa6b67c65e2837..986ec91ede0564d24c30424f1bd073dc6c6f0b5e 100644 (file)
@@ -86,7 +86,13 @@ namespace llvm {
 
 extern "C" void __register_frame(void*);
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
+# define USE_KEYMGR 1
+#else
+# define USE_KEYMGR 0
+#endif
+
+#if USE_KEYMGR
 
 namespace {
 
@@ -224,18 +230,16 @@ JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji,
   
   // Register routine for informing unwinding runtime about new EH frames
 #if defined(__GNUC__) && !defined(__ARM_EABI__)
-#if defined(__APPLE__)
+#if USE_KEYMGR
   struct LibgccObjectInfo* LOI = (struct LibgccObjectInfo*)
     _keymgr_get_and_lock_processwide_ptr(KEYMGR_GCC3_DW2_OBJ_LIST);
   
   // The key is created on demand, and libgcc creates it the first time an
   // exception occurs. Since we need the key to register frames, we create
   // it now.
-  if (!LOI) {
-    LOI = (LibgccObjectInfo*)malloc(sizeof(struct LibgccObjectInfo)); 
-    _keymgr_set_and_unlock_processwide_ptr(KEYMGR_GCC3_DW2_OBJ_LIST,
-                                           LOI);
-  }
+  if (!LOI)
+    LOI = (LibgccObjectInfo*)calloc(sizeof(struct LibgccObjectInfo), 1); 
+  _keymgr_set_and_unlock_processwide_ptr(KEYMGR_GCC3_DW2_OBJ_LIST, LOI);
   InstallExceptionTableRegister(DarwinRegisterFrame);
 #else
   InstallExceptionTableRegister(__register_frame);
@@ -580,8 +584,8 @@ void *JIT::getPointerToFunction(Function *F) {
   }
 
   if (F->isDeclaration()) {
-    bool AbortOnFailure = !areDlsymStubsEnabled() &&
-                          F->getLinkage() != GlobalValue::ExternalWeakLinkage;
+    bool AbortOnFailure =
+      !areDlsymStubsEnabled() && !F->hasExternalWeakLinkage();
     void *Addr = getPointerToNamedFunction(F->getName(), AbortOnFailure);
     addGlobalMapping(F, Addr);
     return Addr;