[llvm] cd34c05 - [ORC] Bail out early if a replacement MaterializationUnit is empty.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 19 11:03:56 PDT 2020


Author: Lang Hames
Date: 2020-03-19T11:02:56-07:00
New Revision: cd34c0570b5e667cc856f14367a97f0279c4d64a

URL: https://github.com/llvm/llvm-project/commit/cd34c0570b5e667cc856f14367a97f0279c4d64a
DIFF: https://github.com/llvm/llvm-project/commit/cd34c0570b5e667cc856f14367a97f0279c4d64a.diff

LOG: [ORC] Bail out early if a replacement MaterializationUnit is empty.

The MU may define no symbols, but still contain a non-trivial destructor (e.g.
an LLVM IR module that has been stripped of all externally visible
definitions, but which still needs to lock its context to be destroyed).
Bailing out early ensures that we destroy the unit outside the session lock,
rather than under it which may cause deadlocks.

Also adds some extra sanity-checking assertions.

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/Orc/Core.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp
index c651fe68cb15..640f040b700a 100644
--- a/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -516,8 +516,15 @@ void MaterializationResponsibility::failMaterialization() {
 void MaterializationResponsibility::replace(
     std::unique_ptr<MaterializationUnit> MU) {
 
-  for (auto &KV : MU->getSymbols())
+  // If the replacement MU is empty then return.
+  if (MU->getSymbols().empty())
+    return;
+
+  for (auto &KV : MU->getSymbols()) {
+    assert(SymbolFlags.count(KV.first) &&
+           "Replacing definition outside this responsibility set");
     SymbolFlags.erase(KV.first);
+  }
 
   if (MU->getInitializerSymbol() == InitSymbol)
     InitSymbol = nullptr;
@@ -934,7 +941,11 @@ void JITDylib::replace(std::unique_ptr<MaterializationUnit> MU) {
                  "Unexpected materializer entry in map");
           SymI->second.setAddress(SymI->second.getAddress());
           SymI->second.setMaterializerAttached(true);
-          UnmaterializedInfos[KV.first] = UMI;
+
+          auto &UMIEntry = UnmaterializedInfos[KV.first];
+          assert((!UMIEntry || !UMIEntry->MU) &&
+                 "Replacing symbol with materializer still attached");
+          UMIEntry = UMI;
         }
 
         return nullptr;


        


More information about the llvm-commits mailing list