mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[ORC] Rename SearchOrder operations on JITDylib to LinkOrder.
Refering to the link order of a dylib better matches the terminology used in static compilation. As upcoming patches will increase the number of places where link order matters (for example when closing JITDylibs) it's better to get this name change out of the way early.
This commit is contained in:
parent
2ab7a0d825
commit
7864e622b1
@ -825,47 +825,46 @@ public:
|
||||
/// have been added and not yet removed).
|
||||
void removeGenerator(DefinitionGenerator &G);
|
||||
|
||||
/// Set the search order to be used when fixing up definitions in JITDylib.
|
||||
/// This will replace the previous search order, and apply to any symbol
|
||||
/// Set the link order to be used when fixing up definitions in JITDylib.
|
||||
/// This will replace the previous link order, and apply to any symbol
|
||||
/// resolutions made for definitions in this JITDylib after the call to
|
||||
/// setSearchOrder (even if the definition itself was added before the
|
||||
/// setLinkOrder (even if the definition itself was added before the
|
||||
/// call).
|
||||
///
|
||||
/// If SearchThisJITDylibFirst is set, which by default it is, then this
|
||||
/// JITDylib will add itself to the beginning of the SearchOrder (Clients
|
||||
/// should *not* put this JITDylib in the list in this case, to avoid
|
||||
/// redundant lookups).
|
||||
/// If LinkAgainstThisJITDylibFirst is true (the default) then this JITDylib
|
||||
/// will add itself to the beginning of the LinkOrder (Clients should not
|
||||
/// put this JITDylib in the list in this case, to avoid redundant lookups).
|
||||
///
|
||||
/// If SearchThisJITDylibFirst is false then the search order will be used as
|
||||
/// given. The main motivation for this feature is to support deliberate
|
||||
/// If LinkAgainstThisJITDylibFirst is false then the link order will be used
|
||||
/// as-is. The primary motivation for this feature is to support deliberate
|
||||
/// shadowing of symbols in this JITDylib by a facade JITDylib. For example,
|
||||
/// the facade may resolve function names to stubs, and the stubs may compile
|
||||
/// lazily by looking up symbols in this dylib. Adding the facade dylib
|
||||
/// as the first in the search order (instead of this dylib) ensures that
|
||||
/// as the first in the link order (instead of this dylib) ensures that
|
||||
/// definitions within this dylib resolve to the lazy-compiling stubs,
|
||||
/// rather than immediately materializing the definitions in this dylib.
|
||||
void setSearchOrder(JITDylibSearchOrder NewSearchOrder,
|
||||
bool SearchThisJITDylibFirst = true);
|
||||
void setLinkOrder(JITDylibSearchOrder NewSearchOrder,
|
||||
bool LinkAgainstThisJITDylibFirst = true);
|
||||
|
||||
/// Add the given JITDylib to the search order for definitions in this
|
||||
/// Add the given JITDylib to the link order for definitions in this
|
||||
/// JITDylib.
|
||||
void addToSearchOrder(JITDylib &JD,
|
||||
JITDylibLookupFlags JDLookupFlags =
|
||||
JITDylibLookupFlags::MatchExportedSymbolsOnly);
|
||||
void addToLinkOrder(JITDylib &JD,
|
||||
JITDylibLookupFlags JDLookupFlags =
|
||||
JITDylibLookupFlags::MatchExportedSymbolsOnly);
|
||||
|
||||
/// Replace OldJD with NewJD in the search order if OldJD is present.
|
||||
/// Replace OldJD with NewJD in the link order if OldJD is present.
|
||||
/// Otherwise this operation is a no-op.
|
||||
void replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD,
|
||||
JITDylibLookupFlags JDLookupFlags =
|
||||
JITDylibLookupFlags::MatchExportedSymbolsOnly);
|
||||
void replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD,
|
||||
JITDylibLookupFlags JDLookupFlags =
|
||||
JITDylibLookupFlags::MatchExportedSymbolsOnly);
|
||||
|
||||
/// Remove the given JITDylib from the search order for this JITDylib if it is
|
||||
/// Remove the given JITDylib from the link order for this JITDylib if it is
|
||||
/// present. Otherwise this operation is a no-op.
|
||||
void removeFromSearchOrder(JITDylib &JD);
|
||||
void removeFromLinkOrder(JITDylib &JD);
|
||||
|
||||
/// Do something with the search order (run under the session lock).
|
||||
/// Do something with the link order (run under the session lock).
|
||||
template <typename Func>
|
||||
auto withSearchOrderDo(Func &&F)
|
||||
auto withLinkOrderDo(Func &&F)
|
||||
-> decltype(F(std::declval<const JITDylibSearchOrder &>()));
|
||||
|
||||
/// Define all symbols provided by the materialization unit to be part of this
|
||||
@ -1049,7 +1048,7 @@ private:
|
||||
UnmaterializedInfosMap UnmaterializedInfos;
|
||||
MaterializingInfosMap MaterializingInfos;
|
||||
std::vector<std::unique_ptr<DefinitionGenerator>> DefGenerators;
|
||||
JITDylibSearchOrder SearchOrder;
|
||||
JITDylibSearchOrder LinkOrder;
|
||||
};
|
||||
|
||||
/// Platforms set up standard symbols and mediate interactions between dynamic
|
||||
@ -1297,9 +1296,9 @@ GeneratorT &JITDylib::addGenerator(std::unique_ptr<GeneratorT> DefGenerator) {
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
auto JITDylib::withSearchOrderDo(Func &&F)
|
||||
auto JITDylib::withLinkOrderDo(Func &&F)
|
||||
-> decltype(F(std::declval<const JITDylibSearchOrder &>())) {
|
||||
return ES.runSessionLocked([&]() { return F(SearchOrder); });
|
||||
return ES.runSessionLocked([&]() { return F(LinkOrder); });
|
||||
}
|
||||
|
||||
template <typename MaterializationUnitType>
|
||||
|
@ -179,21 +179,20 @@ CompileOnDemandLayer::getPerDylibResources(JITDylib &TargetD) {
|
||||
if (I == DylibResources.end()) {
|
||||
auto &ImplD =
|
||||
getExecutionSession().createBareJITDylib(TargetD.getName() + ".impl");
|
||||
JITDylibSearchOrder NewSearchOrder;
|
||||
TargetD.withSearchOrderDo(
|
||||
[&](const JITDylibSearchOrder &TargetSearchOrder) {
|
||||
NewSearchOrder = TargetSearchOrder;
|
||||
});
|
||||
JITDylibSearchOrder NewLinkOrder;
|
||||
TargetD.withLinkOrderDo([&](const JITDylibSearchOrder &TargetLinkOrder) {
|
||||
NewLinkOrder = TargetLinkOrder;
|
||||
});
|
||||
|
||||
assert(
|
||||
!NewSearchOrder.empty() && NewSearchOrder.front().first == &TargetD &&
|
||||
NewSearchOrder.front().second == JITDylibLookupFlags::MatchAllSymbols &&
|
||||
"TargetD must be at the front of its own search order and match "
|
||||
"non-exported symbol");
|
||||
NewSearchOrder.insert(std::next(NewSearchOrder.begin()),
|
||||
{&ImplD, JITDylibLookupFlags::MatchAllSymbols});
|
||||
ImplD.setSearchOrder(NewSearchOrder, false);
|
||||
TargetD.setSearchOrder(std::move(NewSearchOrder), false);
|
||||
assert(!NewLinkOrder.empty() && NewLinkOrder.front().first == &TargetD &&
|
||||
NewLinkOrder.front().second ==
|
||||
JITDylibLookupFlags::MatchAllSymbols &&
|
||||
"TargetD must be at the front of its own search order and match "
|
||||
"non-exported symbol");
|
||||
NewLinkOrder.insert(std::next(NewLinkOrder.begin()),
|
||||
{&ImplD, JITDylibLookupFlags::MatchAllSymbols});
|
||||
ImplD.setLinkOrder(NewLinkOrder, false);
|
||||
TargetD.setLinkOrder(std::move(NewLinkOrder), false);
|
||||
|
||||
PerDylibResources PDR(ImplD, BuildIndirectStubsManager());
|
||||
I = DylibResources.insert(std::make_pair(&TargetD, std::move(PDR))).first;
|
||||
|
@ -1157,30 +1157,29 @@ void JITDylib::notifyFailed(FailedSymbolsWorklist Worklist) {
|
||||
Q->handleFailed(make_error<FailedToMaterialize>(FailedSymbolsMap));
|
||||
}
|
||||
|
||||
void JITDylib::setSearchOrder(JITDylibSearchOrder NewSearchOrder,
|
||||
bool SearchThisJITDylibFirst) {
|
||||
void JITDylib::setLinkOrder(JITDylibSearchOrder NewLinkOrder,
|
||||
bool LinkAgainstThisJITDylibFirst) {
|
||||
ES.runSessionLocked([&]() {
|
||||
if (SearchThisJITDylibFirst) {
|
||||
SearchOrder.clear();
|
||||
if (NewSearchOrder.empty() || NewSearchOrder.front().first != this)
|
||||
SearchOrder.push_back(
|
||||
if (LinkAgainstThisJITDylibFirst) {
|
||||
LinkOrder.clear();
|
||||
if (NewLinkOrder.empty() || NewLinkOrder.front().first != this)
|
||||
LinkOrder.push_back(
|
||||
std::make_pair(this, JITDylibLookupFlags::MatchAllSymbols));
|
||||
SearchOrder.insert(SearchOrder.end(), NewSearchOrder.begin(),
|
||||
NewSearchOrder.end());
|
||||
LinkOrder.insert(LinkOrder.end(), NewLinkOrder.begin(),
|
||||
NewLinkOrder.end());
|
||||
} else
|
||||
SearchOrder = std::move(NewSearchOrder);
|
||||
LinkOrder = std::move(NewLinkOrder);
|
||||
});
|
||||
}
|
||||
|
||||
void JITDylib::addToSearchOrder(JITDylib &JD,
|
||||
JITDylibLookupFlags JDLookupFlags) {
|
||||
ES.runSessionLocked([&]() { SearchOrder.push_back({&JD, JDLookupFlags}); });
|
||||
void JITDylib::addToLinkOrder(JITDylib &JD, JITDylibLookupFlags JDLookupFlags) {
|
||||
ES.runSessionLocked([&]() { LinkOrder.push_back({&JD, JDLookupFlags}); });
|
||||
}
|
||||
|
||||
void JITDylib::replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD,
|
||||
JITDylibLookupFlags JDLookupFlags) {
|
||||
void JITDylib::replaceInLinkOrder(JITDylib &OldJD, JITDylib &NewJD,
|
||||
JITDylibLookupFlags JDLookupFlags) {
|
||||
ES.runSessionLocked([&]() {
|
||||
for (auto &KV : SearchOrder)
|
||||
for (auto &KV : LinkOrder)
|
||||
if (KV.first == &OldJD) {
|
||||
KV = {&NewJD, JDLookupFlags};
|
||||
break;
|
||||
@ -1188,14 +1187,14 @@ void JITDylib::replaceInSearchOrder(JITDylib &OldJD, JITDylib &NewJD,
|
||||
});
|
||||
}
|
||||
|
||||
void JITDylib::removeFromSearchOrder(JITDylib &JD) {
|
||||
void JITDylib::removeFromLinkOrder(JITDylib &JD) {
|
||||
ES.runSessionLocked([&]() {
|
||||
auto I = std::find_if(SearchOrder.begin(), SearchOrder.end(),
|
||||
auto I = std::find_if(LinkOrder.begin(), LinkOrder.end(),
|
||||
[&](const JITDylibSearchOrder::value_type &KV) {
|
||||
return KV.first == &JD;
|
||||
});
|
||||
if (I != SearchOrder.end())
|
||||
SearchOrder.erase(I);
|
||||
if (I != LinkOrder.end())
|
||||
LinkOrder.erase(I);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1529,7 +1528,7 @@ void JITDylib::dump(raw_ostream &OS) {
|
||||
ES.runSessionLocked([&, this]() {
|
||||
OS << "JITDylib \"" << JITDylibName << "\" (ES: "
|
||||
<< format("0x%016" PRIx64, reinterpret_cast<uintptr_t>(&ES)) << "):\n"
|
||||
<< "Search order: " << SearchOrder << "\n"
|
||||
<< "Link order: " << LinkOrder << "\n"
|
||||
<< "Symbol table:\n";
|
||||
|
||||
for (auto &KV : Symbols) {
|
||||
@ -1610,7 +1609,7 @@ JITDylib::MaterializingInfo::takeQueriesMeeting(SymbolState RequiredState) {
|
||||
|
||||
JITDylib::JITDylib(ExecutionSession &ES, std::string Name)
|
||||
: ES(ES), JITDylibName(std::move(Name)) {
|
||||
SearchOrder.push_back({this, JITDylibLookupFlags::MatchAllSymbols});
|
||||
LinkOrder.push_back({this, JITDylibLookupFlags::MatchAllSymbols});
|
||||
}
|
||||
|
||||
Error JITDylib::defineImpl(MaterializationUnit &MU) {
|
||||
|
@ -374,8 +374,8 @@ private:
|
||||
continue;
|
||||
Visited.insert(&NextJD);
|
||||
DFSLinkOrder.push_back(&NextJD);
|
||||
NextJD.withSearchOrderDo([&](const JITDylibSearchOrder &SearchOrder) {
|
||||
for (auto &KV : SearchOrder)
|
||||
NextJD.withLinkOrderDo([&](const JITDylibSearchOrder &LinkOrder) {
|
||||
for (auto &KV : LinkOrder)
|
||||
WorkStack.push_back(KV.first);
|
||||
});
|
||||
}
|
||||
|
@ -271,8 +271,8 @@ std::vector<JITDylib *> MachOPlatform::getDFSLinkOrder(JITDylib &JD) {
|
||||
continue;
|
||||
Visited.insert(NextJD);
|
||||
Result.push_back(NextJD);
|
||||
NextJD->withSearchOrderDo([&](const JITDylibSearchOrder &SO) {
|
||||
for (auto &KV : SO)
|
||||
NextJD->withLinkOrderDo([&](const JITDylibSearchOrder &LO) {
|
||||
for (auto &KV : LO)
|
||||
WorkStack.push_back(KV.first);
|
||||
});
|
||||
}
|
||||
|
@ -50,9 +50,9 @@ public:
|
||||
void lookup(const LookupMap &Symbols,
|
||||
std::unique_ptr<JITLinkAsyncLookupContinuation> LC) override {
|
||||
|
||||
JITDylibSearchOrder SearchOrder;
|
||||
MR.getTargetJITDylib().withSearchOrderDo(
|
||||
[&](const JITDylibSearchOrder &O) { SearchOrder = O; });
|
||||
JITDylibSearchOrder LinkOrder;
|
||||
MR.getTargetJITDylib().withLinkOrderDo(
|
||||
[&](const JITDylibSearchOrder &LO) { LinkOrder = LO; });
|
||||
|
||||
auto &ES = Layer.getExecutionSession();
|
||||
|
||||
@ -90,7 +90,7 @@ public:
|
||||
MR.addDependencies(KV.first, InternalDeps);
|
||||
}
|
||||
|
||||
ES.lookup(LookupKind::Static, SearchOrder, std::move(LookupSet),
|
||||
ES.lookup(LookupKind::Static, LinkOrder, std::move(LookupSet),
|
||||
SymbolState::Resolved, std::move(OnResolve),
|
||||
[this](const SymbolDependenceMap &Deps) {
|
||||
registerDependencies(Deps);
|
||||
|
@ -47,10 +47,10 @@ public:
|
||||
MR.addDependenciesForAll(Deps);
|
||||
};
|
||||
|
||||
JITDylibSearchOrder SearchOrder;
|
||||
MR.getTargetJITDylib().withSearchOrderDo(
|
||||
[&](const JITDylibSearchOrder &JDs) { SearchOrder = JDs; });
|
||||
ES.lookup(LookupKind::Static, SearchOrder, InternedSymbols,
|
||||
JITDylibSearchOrder LinkOrder;
|
||||
MR.getTargetJITDylib().withLinkOrderDo(
|
||||
[&](const JITDylibSearchOrder &LO) { LinkOrder = LO; });
|
||||
ES.lookup(LookupKind::Static, LinkOrder, InternedSymbols,
|
||||
SymbolState::Resolved, std::move(OnResolvedWithUnwrap),
|
||||
RegisterDependencies);
|
||||
}
|
||||
|
@ -942,8 +942,8 @@ int runOrcLazyJIT(const char *ProgName) {
|
||||
orc::JITDylib *JD = J->getJITDylibByName(*JDItr);
|
||||
if (!JD) {
|
||||
JD = &ExitOnErr(J->createJITDylib(*JDItr));
|
||||
J->getMainJITDylib().addToSearchOrder(*JD);
|
||||
JD->addToSearchOrder(J->getMainJITDylib());
|
||||
J->getMainJITDylib().addToLinkOrder(*JD);
|
||||
JD->addToLinkOrder(J->getMainJITDylib());
|
||||
}
|
||||
IdxToDylib[JITDylibs.getPosition(JDItr - JITDylibs.begin())] = JD;
|
||||
}
|
||||
|
@ -657,13 +657,13 @@ Error loadObjects(Session &S) {
|
||||
// Set every dylib to link against every other, in command line order.
|
||||
for (auto *JD : S.JDSearchOrder) {
|
||||
auto LookupFlags = JITDylibLookupFlags::MatchExportedSymbolsOnly;
|
||||
JITDylibSearchOrder O;
|
||||
JITDylibSearchOrder LinkOrder;
|
||||
for (auto *JD2 : S.JDSearchOrder) {
|
||||
if (JD2 == JD)
|
||||
continue;
|
||||
O.push_back(std::make_pair(JD2, LookupFlags));
|
||||
LinkOrder.push_back(std::make_pair(JD2, LookupFlags));
|
||||
}
|
||||
JD->setSearchOrder(std::move(O));
|
||||
JD->setLinkOrder(std::move(LinkOrder));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user