Skip to content

Commit

Permalink
Revert r277896.
Browse files Browse the repository at this point in the history
It breaks ExecutionEngine/OrcLazy/weak-function.ll on most bots.

Script:
--
...
--
Exit Code: 1

Command Output (stderr):
--
Could not find main function.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277907 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
nico committed Aug 6, 2016
1 parent d9a9f7d commit 84f6a48
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 74 deletions.
4 changes: 0 additions & 4 deletions include/llvm/ExecutionEngine/JITSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ class JITSymbolFlags {
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;
Expand Down
14 changes: 4 additions & 10 deletions include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,12 @@ class CompileOnDemandLayer {
// 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);
Expand All @@ -303,14 +295,15 @@ class CompileOnDemandLayer {
// 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]() {
return this->extractAndCompile(LD, LMH, F);
});
}

LMResources.StubsMgr = CreateIndirectStubsManager();
auto EC = LMResources.StubsMgr->createStubs(StubInits);
(void)EC;
// FIXME: This should be propagated back to the user. Stub creation may
Expand Down Expand Up @@ -390,7 +383,8 @@ class CompileOnDemandLayer {
// 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);
Expand Down
2 changes: 1 addition & 1 deletion lib/ExecutionEngine/JITSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 0 additions & 13 deletions test/ExecutionEngine/OrcLazy/Inputs/weak-function-2.ll

This file was deleted.

28 changes: 0 additions & 28 deletions test/ExecutionEngine/OrcLazy/weak-function.ll

This file was deleted.

3 changes: 2 additions & 1 deletion tools/lli/OrcLazyJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
37 changes: 20 additions & 17 deletions tools/lli/OrcLazyJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OrcLazyJIT {
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,
Expand All @@ -62,21 +62,18 @@ class OrcLazyJIT {
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.
Expand All @@ -87,18 +84,24 @@ class OrcLazyJIT {
[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));

Expand All @@ -116,7 +119,7 @@ class OrcLazyJIT {
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);
}

Expand Down

0 comments on commit 84f6a48

Please sign in to comment.