[llvm] r336150 - [ORC] Verify modules when running LLLazyJIT in LLI, and deal with fallout.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 2 15:30:18 PDT 2018


Author: lhames
Date: Mon Jul  2 15:30:18 2018
New Revision: 336150

URL: http://llvm.org/viewvc/llvm-project?rev=336150&view=rev
Log:
[ORC] Verify modules when running LLLazyJIT in LLI, and deal with fallout.

The verifier identified several modules that were broken due to incorrect
linkage on declarations. To fix this, CompileOnDemandLayer2::extractFunction
has been updated to change decls to external linkage.

Modified:
    llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
    llvm/trunk/tools/lli/lli.cpp

Modified: llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp?rev=336150&r1=336149&r2=336150&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp Mon Jul  2 15:30:18 2018
@@ -322,11 +322,15 @@ std::unique_ptr<Module> CompileOnDemandL
   ValueToValueMapTy VMap;
 
   auto Materializer = createLambdaValueMaterializer([&](Value *V) -> Value * {
+    GlobalValue *NewGV = nullptr;
     if (auto *F = dyn_cast<Function>(V))
-      return cloneFunctionDecl(*ExtractedFunctionsModule, *F);
+      NewGV = cloneFunctionDecl(*ExtractedFunctionsModule, *F);
     else if (auto *GV = dyn_cast<GlobalVariable>(V))
-      return cloneGlobalVariableDecl(*ExtractedFunctionsModule, *GV);
-    return nullptr;
+      NewGV = cloneGlobalVariableDecl(*ExtractedFunctionsModule, *GV);
+
+    if (NewGV)
+      NewGV->setLinkage(GlobalValue::ExternalLinkage);
+    return NewGV;
   });
 
   std::vector<std::pair<Function *, Function *>> OrigToNew;

Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=336150&r1=336149&r2=336150&view=diff
==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Mon Jul  2 15:30:18 2018
@@ -35,6 +35,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/TypeBuilder.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/ObjectFile.h"
@@ -767,7 +768,16 @@ int runOrcLazyJIT(LLVMContext &Ctx, std:
   auto J =
       ExitOnErr(orc::LLLazyJIT::Create(std::move(ES), std::move(TM), DL, Ctx));
 
-  J->setLazyCompileTransform(createDebugDumper());
+  auto Dump = createDebugDumper();
+
+  J->setLazyCompileTransform(
+    [&](std::unique_ptr<Module> M) {
+      if (verifyModule(*M, &dbgs())) {
+        dbgs() << "Bad module: " << *M << "\n";
+        exit(1);
+      }
+      return Dump(std::move(M));
+    });
   J->getMainVSO().setFallbackDefinitionGenerator(
       orc::DynamicLibraryFallbackGenerator(
           std::move(LibLLI), DL, [](orc::SymbolStringPtr) { return true; }));
@@ -776,8 +786,10 @@ int runOrcLazyJIT(LLVMContext &Ctx, std:
   orc::LocalCXXRuntimeOverrides2 CXXRuntimeOverrides;
   ExitOnErr(CXXRuntimeOverrides.enable(J->getMainVSO(), Mangle));
 
-  for (auto &M : Ms)
+  for (auto &M : Ms) {
+    orc::makeAllSymbolsExternallyAccessible(*M);
     ExitOnErr(J->addLazyIRModule(std::move(M)));
+  }
 
   ExitOnErr(J->runConstructors());
 




More information about the llvm-commits mailing list