diff --git a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp index 27a4ad68f596..f7ff40cf802c 100644 --- a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp @@ -322,11 +322,15 @@ std::unique_ptr CompileOnDemandLayer2::extractFunctions( ValueToValueMapTy VMap; auto Materializer = createLambdaValueMaterializer([&](Value *V) -> Value * { + GlobalValue *NewGV = nullptr; if (auto *F = dyn_cast(V)) - return cloneFunctionDecl(*ExtractedFunctionsModule, *F); + NewGV = cloneFunctionDecl(*ExtractedFunctionsModule, *F); else if (auto *GV = dyn_cast(V)) - return cloneGlobalVariableDecl(*ExtractedFunctionsModule, *GV); - return nullptr; + NewGV = cloneGlobalVariableDecl(*ExtractedFunctionsModule, *GV); + + if (NewGV) + NewGV->setLinkage(GlobalValue::ExternalLinkage); + return NewGV; }); std::vector> OrigToNew; diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index b7c821bb5856..74ab2f3cd5ac 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -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::vector> Ms, 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 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::vector> Ms, 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());