OSDN Git Service

[ORC] Guard access to the MemMgrs vector in RTDyldObjectLinkingLayer.
authorLang Hames <lhames@gmail.com>
Mon, 22 Oct 2018 21:17:56 +0000 (21:17 +0000)
committerLang Hames <lhames@gmail.com>
Mon, 22 Oct 2018 21:17:56 +0000 (21:17 +0000)
Otherwise we can end up with a data-race when linking concurrently.

This should fix an intermittent failure in the multiple-compile-threads-basic.ll
testcase.

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

lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp

index 8511e41..616251c 100644 (file)
@@ -121,8 +121,15 @@ void RTDyldObjectLinkingLayer::emit(MaterializationResponsibility R,
   }
 
   auto K = R.getVModuleKey();
-  MemMgrs.push_back(GetMemoryManager());
-  auto &MemMgr = *MemMgrs.back();
+  RuntimeDyld::MemoryManager *MemMgr = nullptr;
+
+  // Create a record a memory manager for this object.
+  {
+    auto Tmp = GetMemoryManager();
+    std::lock_guard<std::mutex> Lock(RTDyldLayerMutex);
+    MemMgrs.push_back(std::move(Tmp));
+    MemMgr = MemMgrs.back().get();
+  }
 
   JITDylibSearchOrderResolver Resolver(*SharedR);
 
@@ -134,7 +141,7 @@ void RTDyldObjectLinkingLayer::emit(MaterializationResponsibility R,
    * duplicate defs.
    */
   jitLinkForORC(
-      **Obj, std::move(O), MemMgr, Resolver, ProcessAllSections,
+      **Obj, std::move(O), *MemMgr, Resolver, ProcessAllSections,
       [this, K, SharedR, &Obj, InternalSymbols](
           std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo,
           std::map<StringRef, JITEvaluatedSymbol> ResolvedSymbols) {