diff options
-rw-r--r-- | include/llvm/ExecutionEngine/JITSymbol.h | 4 | ||||
-rw-r--r-- | include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h | 14 | ||||
-rw-r--r-- | lib/ExecutionEngine/JITSymbol.cpp | 2 | ||||
-rw-r--r-- | test/ExecutionEngine/OrcLazy/Inputs/weak-function-2.ll | 13 | ||||
-rw-r--r-- | test/ExecutionEngine/OrcLazy/weak-function.ll | 28 | ||||
-rw-r--r-- | tools/lli/OrcLazyJIT.cpp | 3 | ||||
-rw-r--r-- | tools/lli/OrcLazyJIT.h | 37 |
7 files changed, 27 insertions, 74 deletions
diff --git a/include/llvm/ExecutionEngine/JITSymbol.h b/include/llvm/ExecutionEngine/JITSymbol.h index 9b096896e75..138fe6e7411 100644 --- a/include/llvm/ExecutionEngine/JITSymbol.h +++ b/include/llvm/ExecutionEngine/JITSymbol.h @@ -59,10 +59,6 @@ public: return (Flags & Common) == Common; } - bool isStrongDefinition() const { - return !isWeak() && !isCommon(); - } - /// @brief Returns true is the Weak flag is set. bool isExported() const { return (Flags & Exported) == Exported; diff --git a/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h b/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h index f3d95e022b4..2f76b842ed3 100644 --- a/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h +++ b/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h @@ -281,20 +281,12 @@ private: // Create stub functions. const DataLayout &DL = SrcM.getDataLayout(); { - LMResources.StubsMgr = CreateIndirectStubsManager(); - typename IndirectStubsMgrT::StubInitsMap StubInits; for (auto &F : SrcM) { // Skip declarations. if (F.isDeclaration()) continue; - // Skip weak functions for which we already have definitions. - auto MangledName = mangle(F.getName(), DL); - if (F.hasWeakLinkage() || F.hasLinkOnceLinkage()) - if (auto Sym = LD.findSymbol(MangledName, false)) - continue; - // Record all functions defined by this module. if (CloneStubsIntoPartitions) LMResources.StubsToClone.insert(&F); @@ -303,7 +295,7 @@ private: // and set the compile action to compile the partition containing the // function. auto CCInfo = CompileCallbackMgr.getCompileCallback(); - StubInits[MangledName] = + StubInits[mangle(F.getName(), DL)] = std::make_pair(CCInfo.getAddress(), JITSymbolFlags::fromGlobalValue(F)); CCInfo.setCompileAction([this, &LD, LMH, &F]() { @@ -311,6 +303,7 @@ private: }); } + LMResources.StubsMgr = CreateIndirectStubsManager(); auto EC = LMResources.StubsMgr->createStubs(StubInits); (void)EC; // FIXME: This should be propagated back to the user. Stub creation may @@ -390,7 +383,8 @@ private: // Build a resolver for the globals module and add it to the base layer. auto GVsResolver = createLambdaResolver( [&LD, LMH](const std::string &Name) { - if (auto Sym = LD.findSymbol(Name, false)) + auto &LMResources = LD.getLogicalModuleResources(LMH); + if (auto Sym = LMResources.StubsMgr->findStub(Name, false)) return Sym; auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver; return LDResolver->findSymbolInLogicalDylib(Name); diff --git a/lib/ExecutionEngine/JITSymbol.cpp b/lib/ExecutionEngine/JITSymbol.cpp index 8769dcf7374..91d198ba786 100644 --- a/lib/ExecutionEngine/JITSymbol.cpp +++ b/lib/ExecutionEngine/JITSymbol.cpp @@ -19,7 +19,7 @@ using namespace llvm; JITSymbolFlags llvm::JITSymbolFlags::fromGlobalValue(const GlobalValue &GV) { JITSymbolFlags Flags = JITSymbolFlags::None; - if (GV.hasWeakLinkage() || GV.hasLinkOnceLinkage()) + if (GV.hasWeakLinkage()) Flags |= JITSymbolFlags::Weak; if (GV.hasCommonLinkage()) Flags |= JITSymbolFlags::Common; diff --git a/test/ExecutionEngine/OrcLazy/Inputs/weak-function-2.ll b/test/ExecutionEngine/OrcLazy/Inputs/weak-function-2.ll deleted file mode 100644 index dca4f707029..00000000000 --- a/test/ExecutionEngine/OrcLazy/Inputs/weak-function-2.ll +++ /dev/null @@ -1,13 +0,0 @@ -target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-apple-macosx10.12.0" - -; Function Attrs: nounwind ssp uwtable -define linkonce_odr i32 @baz() #0 { -entry: - ret i32 0 -} - -define i8* @bar() { -entry: - ret i8* bitcast (i32 ()* @baz to i8*) -} diff --git a/test/ExecutionEngine/OrcLazy/weak-function.ll b/test/ExecutionEngine/OrcLazy/weak-function.ll deleted file mode 100644 index 86c962e677e..00000000000 --- a/test/ExecutionEngine/OrcLazy/weak-function.ll +++ /dev/null @@ -1,28 +0,0 @@ -; RUN: lli -jit-kind=orc-lazy -extra-module %p/Inputs/weak-function-2.ll %s -; -; Check that functions in two different modules agree on the address of weak -; function 'baz' -target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-apple-macosx10.12.0" - -define linkonce_odr i32 @baz() { -entry: - ret i32 0 -} - -define i8* @foo() { -entry: - ret i8* bitcast (i32 ()* @baz to i8*) -} - -declare i8* @bar() - -define i32 @main(i32 %argc, i8** %argv) { -entry: - %call = tail call i8* @foo() - %call1 = tail call i8* @bar() - %cmp = icmp ne i8* %call, %call1 - %conv = zext i1 %cmp to i32 - ret i32 %conv -} - diff --git a/tools/lli/OrcLazyJIT.cpp b/tools/lli/OrcLazyJIT.cpp index d9cec0ce363..a36d5731599 100644 --- a/tools/lli/OrcLazyJIT.cpp +++ b/tools/lli/OrcLazyJIT.cpp @@ -144,7 +144,8 @@ int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms, int ArgC, OrcInlineStubs); // Add the module, look up main and run it. - J.addModuleSet(std::move(Ms)); + for (auto &M : Ms) + J.addModule(std::move(M)); auto MainSym = J.findSymbol("main"); if (!MainSym) { diff --git a/tools/lli/OrcLazyJIT.h b/tools/lli/OrcLazyJIT.h index 71e0d839d27..26be63de53e 100644 --- a/tools/lli/OrcLazyJIT.h +++ b/tools/lli/OrcLazyJIT.h @@ -38,7 +38,7 @@ public: typedef orc::CompileOnDemandLayer<IRDumpLayerT, CompileCallbackMgr> CODLayerT; typedef CODLayerT::IndirectStubsManagerBuilderT IndirectStubsManagerBuilder; - typedef CODLayerT::ModuleSetHandleT ModuleSetHandleT; + typedef CODLayerT::ModuleSetHandleT ModuleHandleT; OrcLazyJIT(std::unique_ptr<TargetMachine> TM, std::unique_ptr<CompileCallbackMgr> CCMgr, @@ -62,21 +62,18 @@ public: DtorRunner.runViaLayer(CODLayer); } - ModuleSetHandleT addModuleSet(std::vector<std::unique_ptr<Module>> Ms) { - // Attach a data-layouts if they aren't already present. - for (auto &M : Ms) - if (M->getDataLayout().isDefault()) - M->setDataLayout(DL); + ModuleHandleT addModule(std::unique_ptr<Module> M) { + // Attach a data-layout if one isn't already present. + if (M->getDataLayout().isDefault()) + M->setDataLayout(DL); // Record the static constructors and destructors. We have to do this before // we hand over ownership of the module to the JIT. std::vector<std::string> CtorNames, DtorNames; - for (auto &M : Ms) { - for (auto Ctor : orc::getConstructors(*M)) - CtorNames.push_back(mangle(Ctor.Func->getName())); - for (auto Dtor : orc::getDestructors(*M)) - DtorNames.push_back(mangle(Dtor.Func->getName())); - } + for (auto Ctor : orc::getConstructors(*M)) + CtorNames.push_back(mangle(Ctor.Func->getName())); + for (auto Dtor : orc::getDestructors(*M)) + DtorNames.push_back(mangle(Dtor.Func->getName())); // Symbol resolution order: // 1) Search the JIT symbols. @@ -87,18 +84,24 @@ public: [this](const std::string &Name) -> JITSymbol { if (auto Sym = CODLayer.findSymbol(Name, true)) return Sym; - return CXXRuntimeOverrides.searchOverrides(Name); - }, - [](const std::string &Name) { + if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name)) + return Sym; + if (auto Addr = RTDyldMemoryManager::getSymbolAddressInProcess(Name)) return JITSymbol(Addr, JITSymbolFlags::Exported); + + return JITSymbol(nullptr); + }, + [](const std::string &Name) { return JITSymbol(nullptr); } ); // Add the module to the JIT. - auto H = CODLayer.addModuleSet(std::move(Ms), + std::vector<std::unique_ptr<Module>> S; + S.push_back(std::move(M)); + auto H = CODLayer.addModuleSet(std::move(S), llvm::make_unique<SectionMemoryManager>(), std::move(Resolver)); @@ -116,7 +119,7 @@ public: return CODLayer.findSymbol(mangle(Name), true); } - JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name) { + JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) { return CODLayer.findSymbolIn(H, mangle(Name), true); } |