diff options
author | Lang Hames <lhames@gmail.com> | 2016-08-06 00:54:43 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-08-06 00:54:43 +0000 |
commit | 38365dac943ec8261aa404b270b724ae1ccb86b2 (patch) | |
tree | 114f24f1d3f23606061e3f2d797cade9ec3e21c5 /tools/lli | |
parent | faa5bfd28832572d7148ba4092f1b34360b9262b (diff) |
[ORC] Add (partial) weak symbol support to the CompileOnDemand layer.
This adds partial support for weak functions to the CompileOnDemandLayer by
modifying the addLogicalModule method to check for existing stub definitions
before building a new stub for a weak function. This scheme is sufficient to
support ODR definitions, but fails for general weak definitions if strong
definition is encountered after the first weak definition. (A more extensive
refactor will be required to fully support weak symbols).
This patch does *not* add weak symbol support to RuntimeDyld: I hope to add
that in the near future.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277896 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli')
-rw-r--r-- | tools/lli/OrcLazyJIT.cpp | 3 | ||||
-rw-r--r-- | tools/lli/OrcLazyJIT.h | 37 |
2 files changed, 18 insertions, 22 deletions
diff --git a/tools/lli/OrcLazyJIT.cpp b/tools/lli/OrcLazyJIT.cpp index a36d5731599..d9cec0ce363 100644 --- a/tools/lli/OrcLazyJIT.cpp +++ b/tools/lli/OrcLazyJIT.cpp @@ -144,8 +144,7 @@ int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms, int ArgC, OrcInlineStubs); // Add the module, look up main and run it. - for (auto &M : Ms) - J.addModule(std::move(M)); + J.addModuleSet(std::move(Ms)); auto MainSym = J.findSymbol("main"); if (!MainSym) { diff --git a/tools/lli/OrcLazyJIT.h b/tools/lli/OrcLazyJIT.h index 26be63de53e..71e0d839d27 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 ModuleHandleT; + typedef CODLayerT::ModuleSetHandleT ModuleSetHandleT; OrcLazyJIT(std::unique_ptr<TargetMachine> TM, std::unique_ptr<CompileCallbackMgr> CCMgr, @@ -62,18 +62,21 @@ public: DtorRunner.runViaLayer(CODLayer); } - ModuleHandleT addModule(std::unique_ptr<Module> M) { - // Attach a data-layout if one isn't already present. - if (M->getDataLayout().isDefault()) - M->setDataLayout(DL); + 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); // 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 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 &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())); + } // Symbol resolution order: // 1) Search the JIT symbols. @@ -84,24 +87,18 @@ public: [this](const std::string &Name) -> JITSymbol { if (auto Sym = CODLayer.findSymbol(Name, true)) return Sym; - if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name)) - return Sym; - + return CXXRuntimeOverrides.searchOverrides(Name); + }, + [](const std::string &Name) { 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. - std::vector<std::unique_ptr<Module>> S; - S.push_back(std::move(M)); - auto H = CODLayer.addModuleSet(std::move(S), + auto H = CODLayer.addModuleSet(std::move(Ms), llvm::make_unique<SectionMemoryManager>(), std::move(Resolver)); @@ -119,7 +116,7 @@ public: return CODLayer.findSymbol(mangle(Name), true); } - JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) { + JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name) { return CODLayer.findSymbolIn(H, mangle(Name), true); } |