aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2024-09-22 18:17:14 +1000
committerLang Hames <lhames@gmail.com>2024-09-22 18:51:17 +1000
commit0074cea432e268ed126b12c6e7fd4df2e1707a77 (patch)
tree435e7b3f76b8503c6722c10869d62394e3215868 /llvm/lib/ExecutionEngine/Orc
parente4e3ff5adc8b374be0620223ea2b654adde038ea (diff)
downloadllvm-0074cea432e268ed126b12c6e7fd4df2e1707a77.zip
llvm-0074cea432e268ed126b12c6e7fd4df2e1707a77.tar.gz
llvm-0074cea432e268ed126b12c6e7fd4df2e1707a77.tar.bz2
[ORC] Get rid of ObjectLinkingLayer::Plugin::getSyntheticSymbolDependencies.
Instead, when a MaterializationResponsibility contains an initializer symbol, the Platform classes (MachO, COFF, ELFNix) will now add a defined symbol with the same name to an arbitary block within the initializer sections, and then add keep-alive edges from that symbol to all other init section blocks. ObjectLinkingLayer is updated to automatically discard symbols where the corresponding MaterializationResponsibility entry has the MaterializationSideEffecstsOnly flag. This change simplifies both the ObjectLinkingLayer::Plugin interface and the dependence tracking algorithm, which no longer needs a special case for "synthetic" (MaterializationSideEffectsOnly) symbols.
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc')
-rw-r--r--llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp55
-rw-r--r--llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp64
-rw-r--r--llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp70
-rw-r--r--llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp19
4 files changed, 92 insertions, 116 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
index c8f5a99..eab0dfa 100644
--- a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
@@ -786,20 +786,6 @@ void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
});
}
-ObjectLinkingLayer::Plugin::SyntheticSymbolDependenciesMap
-COFFPlatform::COFFPlatformPlugin::getSyntheticSymbolDependencies(
- MaterializationResponsibility &MR) {
- std::lock_guard<std::mutex> Lock(PluginMutex);
- auto I = InitSymbolDeps.find(&MR);
- if (I != InitSymbolDeps.end()) {
- SyntheticSymbolDependenciesMap Result;
- Result[MR.getInitializerSymbol()] = std::move(I->second);
- InitSymbolDeps.erase(&MR);
- return Result;
- }
- return SyntheticSymbolDependenciesMap();
-}
-
Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
jitlink::LinkGraph &G, MaterializationResponsibility &MR,
bool IsBootstraping) {
@@ -859,16 +845,37 @@ Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
jitlink::LinkGraph &G, MaterializationResponsibility &MR) {
- JITLinkSymbolSet InitSectionSymbols;
- for (auto &Sec : G.sections())
- if (isCOFFInitializerSection(Sec.getName()))
- for (auto *B : Sec.blocks())
- if (!B->edges_empty())
- InitSectionSymbols.insert(
- &G.addAnonymousSymbol(*B, 0, 0, false, true));
-
- std::lock_guard<std::mutex> Lock(PluginMutex);
- InitSymbolDeps[&MR] = InitSectionSymbols;
+
+ if (const auto &InitSymName = MR.getInitializerSymbol()) {
+
+ jitlink::Symbol *InitSym = nullptr;
+
+ for (auto &InitSection : G.sections()) {
+ // Skip non-init sections.
+ if (!isCOFFInitializerSection(InitSection.getName()) ||
+ InitSection.empty())
+ continue;
+
+ // Create the init symbol if it has not been created already and attach it
+ // to the first block.
+ if (!InitSym) {
+ auto &B = **InitSection.blocks().begin();
+ InitSym = &G.addDefinedSymbol(B, 0, *InitSymName, B.getSize(),
+ jitlink::Linkage::Strong,
+ jitlink::Scope::Default, false, true);
+ }
+
+ // Add keep-alive edges to anonymous symbols in all other init blocks.
+ for (auto *B : InitSection.blocks()) {
+ if (B == &InitSym->getBlock())
+ continue;
+
+ auto &S = G.addAnonymousSymbol(*B, 0, B->getSize(), false, true);
+ InitSym->getBlock().addEdge(jitlink::Edge::KeepAlive, 0, S, 0);
+ }
+ }
+ }
+
return Error::success();
}
diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
index 2b6c4b9..67c920a 100644
--- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
@@ -616,20 +616,6 @@ void ELFNixPlatform::ELFNixPlatformPlugin::modifyPassConfig(
addEHAndTLVSupportPasses(MR, Config);
}
-ObjectLinkingLayer::Plugin::SyntheticSymbolDependenciesMap
-ELFNixPlatform::ELFNixPlatformPlugin::getSyntheticSymbolDependencies(
- MaterializationResponsibility &MR) {
- std::lock_guard<std::mutex> Lock(PluginMutex);
- auto I = InitSymbolDeps.find(&MR);
- if (I != InitSymbolDeps.end()) {
- SyntheticSymbolDependenciesMap Result;
- Result[MR.getInitializerSymbol()] = std::move(I->second);
- InitSymbolDeps.erase(&MR);
- return Result;
- }
- return SyntheticSymbolDependenciesMap();
-}
-
void ELFNixPlatform::ELFNixPlatformPlugin::addInitializerSupportPasses(
MaterializationResponsibility &MR, jitlink::PassConfiguration &Config) {
@@ -737,34 +723,34 @@ void ELFNixPlatform::ELFNixPlatformPlugin::addEHAndTLVSupportPasses(
Error ELFNixPlatform::ELFNixPlatformPlugin::preserveInitSections(
jitlink::LinkGraph &G, MaterializationResponsibility &MR) {
- JITLinkSymbolSet InitSectionSymbols;
- for (auto &InitSection : G.sections()) {
- // Skip non-init sections.
- if (!isELFInitializerSection(InitSection.getName()))
- continue;
-
- // Make a pass over live symbols in the section: those blocks are already
- // preserved.
- DenseSet<jitlink::Block *> AlreadyLiveBlocks;
- for (auto &Sym : InitSection.symbols()) {
- auto &B = Sym->getBlock();
- if (Sym->isLive() && Sym->getOffset() == 0 &&
- Sym->getSize() == B.getSize() && !AlreadyLiveBlocks.count(&B)) {
- InitSectionSymbols.insert(Sym);
- AlreadyLiveBlocks.insert(&B);
+ if (const auto &InitSymName = MR.getInitializerSymbol()) {
+
+ jitlink::Symbol *InitSym = nullptr;
+
+ for (auto &InitSection : G.sections()) {
+ // Skip non-init sections.
+ if (!isELFInitializerSection(InitSection.getName()) ||
+ InitSection.empty())
+ continue;
+
+ // Create the init symbol if it has not been created already and attach it
+ // to the first block.
+ if (!InitSym) {
+ auto &B = **InitSection.blocks().begin();
+ InitSym = &G.addDefinedSymbol(B, 0, *InitSymName, B.getSize(),
+ jitlink::Linkage::Strong,
+ jitlink::Scope::Default, false, true);
}
- }
- // Add anonymous symbols to preserve any not-already-preserved blocks.
- for (auto *B : InitSection.blocks())
- if (!AlreadyLiveBlocks.count(B))
- InitSectionSymbols.insert(
- &G.addAnonymousSymbol(*B, 0, B->getSize(), false, true));
- }
+ // Add keep-alive edges to anonymous symbols in all other init blocks.
+ for (auto *B : InitSection.blocks()) {
+ if (B == &InitSym->getBlock())
+ continue;
- if (!InitSectionSymbols.empty()) {
- std::lock_guard<std::mutex> Lock(PluginMutex);
- InitSymbolDeps[&MR] = std::move(InitSectionSymbols);
+ auto &S = G.addAnonymousSymbol(*B, 0, B->getSize(), false, true);
+ InitSym->getBlock().addEdge(jitlink::Edge::KeepAlive, 0, S, 0);
+ }
+ }
}
return Error::success();
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index e56d6b4..0248043 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -861,20 +861,6 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
[this](LinkGraph &G) { return bootstrapPipelineEnd(G); });
}
-ObjectLinkingLayer::Plugin::SyntheticSymbolDependenciesMap
-MachOPlatform::MachOPlatformPlugin::getSyntheticSymbolDependencies(
- MaterializationResponsibility &MR) {
- std::lock_guard<std::mutex> Lock(PluginMutex);
- auto I = InitSymbolDeps.find(&MR);
- if (I != InitSymbolDeps.end()) {
- SyntheticSymbolDependenciesMap Result;
- Result[MR.getInitializerSymbol()] = std::move(I->second);
- InitSymbolDeps.erase(&MR);
- return Result;
- }
- return SyntheticSymbolDependenciesMap();
-}
-
Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineStart(
jitlink::LinkGraph &G) {
// Increment the active graphs count in BootstrapInfo.
@@ -998,40 +984,38 @@ Error MachOPlatform::MachOPlatformPlugin::preserveImportantSections(
// Init sections are important: We need to preserve them and so that their
// addresses can be captured and reported to the ORC runtime in
// registerObjectPlatformSections.
- JITLinkSymbolSet InitSectionSymbols;
- for (auto &InitSectionName : MachOInitSectionNames) {
- // Skip ObjCImageInfo -- this shouldn't have any dependencies, and we may
- // remove it later.
- if (InitSectionName == MachOObjCImageInfoSectionName)
- continue;
+ if (const auto &InitSymName = MR.getInitializerSymbol()) {
- // Skip non-init sections.
- auto *InitSection = G.findSectionByName(InitSectionName);
- if (!InitSection)
- continue;
+ jitlink::Symbol *InitSym = nullptr;
+ for (auto &InitSectionName : MachOInitSectionNames) {
+ // Skip ObjCImageInfo -- this shouldn't have any dependencies, and we may
+ // remove it later.
+ if (InitSectionName == MachOObjCImageInfoSectionName)
+ continue;
- // Make a pass over live symbols in the section: those blocks are already
- // preserved.
- DenseSet<jitlink::Block *> AlreadyLiveBlocks;
- for (auto &Sym : InitSection->symbols()) {
- auto &B = Sym->getBlock();
- if (Sym->isLive() && Sym->getOffset() == 0 &&
- Sym->getSize() == B.getSize() && !AlreadyLiveBlocks.count(&B)) {
- InitSectionSymbols.insert(Sym);
- AlreadyLiveBlocks.insert(&B);
+ // Skip non-init sections.
+ auto *InitSection = G.findSectionByName(InitSectionName);
+ if (!InitSection || InitSection->empty())
+ continue;
+
+ // Create the init symbol if it has not been created already and attach it
+ // to the first block.
+ if (!InitSym) {
+ auto &B = **InitSection->blocks().begin();
+ InitSym = &G.addDefinedSymbol(B, 0, *InitSymName, B.getSize(),
+ jitlink::Linkage::Strong,
+ jitlink::Scope::Default, false, true);
}
- }
- // Add anonymous symbols to preserve any not-already-preserved blocks.
- for (auto *B : InitSection->blocks())
- if (!AlreadyLiveBlocks.count(B))
- InitSectionSymbols.insert(
- &G.addAnonymousSymbol(*B, 0, B->getSize(), false, true));
- }
+ // Add keep-alive edges to anonymous symbols in all other init blocks.
+ for (auto *B : InitSection->blocks()) {
+ if (B == &InitSym->getBlock())
+ continue;
- if (!InitSectionSymbols.empty()) {
- std::lock_guard<std::mutex> Lock(PluginMutex);
- InitSymbolDeps[&MR] = std::move(InitSectionSymbols);
+ auto &S = G.addAnonymousSymbol(*B, 0, B->getSize(), false, true);
+ InitSym->getBlock().addEdge(jitlink::Edge::KeepAlive, 0, S, 0);
+ }
+ }
}
return Error::success();
diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
index 19d8307..25ab154 100644
--- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
@@ -275,24 +275,22 @@ public:
// First check that there aren't any missing symbols.
size_t NumMaterializationSideEffectsOnlySymbols = 0;
- SymbolNameVector ExtraSymbols;
SymbolNameVector MissingSymbols;
- for (auto &KV : MR->getSymbols()) {
+ for (auto &[Sym, Flags] : MR->getSymbols()) {
- auto I = InternedResult.find(KV.first);
+ auto I = InternedResult.find(Sym);
// If this is a materialization-side-effects only symbol then bump
- // the counter and make sure it's *not* defined, otherwise make
- // sure that it is defined.
- if (KV.second.hasMaterializationSideEffectsOnly()) {
+ // the counter and remove in from the result, otherwise make sure that
+ // it's defined.
+ if (Flags.hasMaterializationSideEffectsOnly()) {
++NumMaterializationSideEffectsOnlySymbols;
- if (I != InternedResult.end())
- ExtraSymbols.push_back(KV.first);
+ InternedResult.erase(Sym);
continue;
} else if (I == InternedResult.end())
- MissingSymbols.push_back(KV.first);
+ MissingSymbols.push_back(Sym);
else if (Layer.OverrideObjectFlags)
- I->second.setFlags(KV.second);
+ I->second.setFlags(Flags);
}
// If there were missing symbols then report the error.
@@ -303,6 +301,7 @@ public:
// If there are more definitions than expected, add them to the
// ExtraSymbols vector.
+ SymbolNameVector ExtraSymbols;
if (InternedResult.size() >
MR->getSymbols().size() - NumMaterializationSideEffectsOnlySymbols) {
for (auto &KV : InternedResult)