Skip to content

Commit aba6bb0

Browse files
committed
[ORC][JITLink] Add jitlink::Scope::SideEffectsOnly, use it in ORC Platforms.
SideEffectsOnly is a new jitlink::Scope value that corresponds to the JITSymbolFlags::MaterializationSideEffectsOnly flag: Symbols with this scope can be looked up (and form part of the initial interface of a LinkGraph) but never actually resolve to an address (so can only be looked up with a WeaklyReferencedSymbol lookup). Previously ObjectLinkingLayer implicitly treated JITLink symbols as having this scope, regardless of a Symbol's actual scope, if the MaterializationSideEffectsOnly flag was set on the corresponding symbol in the MaterializationResponsibility object. Using an explicit scope in JITLink for this (1) allows JITLink plugins to identify and correctly handle side-effects-only symbols, and (2) allows raw LinkGraphs to define side-effects-only symbols without clients having to manually modify their `MaterializationUnit::Interface`.
1 parent 6ef4990 commit aba6bb0

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,13 @@ const char *getLinkageName(Linkage L);
393393
/// Defines the scope in which this symbol should be visible:
394394
/// Default -- Visible in the public interface of the linkage unit.
395395
/// Hidden -- Visible within the linkage unit, but not exported from it.
396+
/// SideEffectsOnly -- Like hidden, but symbol can only be looked up once
397+
/// to trigger materialization of the containing graph.
396398
/// Local -- Visible only within the LinkGraph.
397399
enum class Scope : uint8_t {
398400
Default,
399401
Hidden,
402+
SideEffectsOnly,
400403
Local
401404
};
402405

llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class COFFHeaderMaterializationUnit : public MaterializationUnit {
7676
// Init symbol is __ImageBase symbol.
7777
auto &ImageBaseSymbol = G->addDefinedSymbol(
7878
HeaderBlock, 0, *R->getInitializerSymbol(), HeaderBlock.getSize(),
79-
jitlink::Linkage::Strong, jitlink::Scope::Default, false, true);
79+
jitlink::Linkage::Strong, jitlink::Scope::SideEffectsOnly, false, true);
8080

8181
addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
8282

llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class DSOHandleMaterializationUnit : public MaterializationUnit {
197197
8, 0);
198198
auto &DSOHandleSymbol = G->addDefinedSymbol(
199199
DSOHandleBlock, 0, *R->getInitializerSymbol(), DSOHandleBlock.getSize(),
200-
jitlink::Linkage::Strong, jitlink::Scope::Default, false, true);
200+
jitlink::Linkage::Strong, jitlink::Scope::SideEffectsOnly, false, true);
201201
DSOHandleBlock.addEdge(EdgeKind, 0, DSOHandleSymbol, 0);
202202

203203
ENP.getObjectLinkingLayer().emit(std::move(R), std::move(G));

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,9 +1001,9 @@ Error MachOPlatform::MachOPlatformPlugin::preserveImportantSections(
10011001
// to the first block.
10021002
if (!InitSym) {
10031003
auto &B = **InitSection->blocks().begin();
1004-
InitSym = &G.addDefinedSymbol(B, 0, *InitSymName, B.getSize(),
1005-
jitlink::Linkage::Strong,
1006-
jitlink::Scope::Default, false, true);
1004+
InitSym = &G.addDefinedSymbol(
1005+
B, 0, *InitSymName, B.getSize(), jitlink::Linkage::Strong,
1006+
jitlink::Scope::SideEffectsOnly, false, true);
10071007
}
10081008

10091009
// Add keep-alive edges to anonymous symbols in all other init blocks.

llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ JITSymbolFlags getJITSymbolFlagsForSymbol(Symbol &Sym) {
6565

6666
if (Sym.getScope() == Scope::Default)
6767
Flags |= JITSymbolFlags::Exported;
68+
else if (Sym.getScope() == Scope::SideEffectsOnly)
69+
Flags |= JITSymbolFlags::MaterializationSideEffectsOnly;
6870

6971
if (Sym.isCallable())
7072
Flags |= JITSymbolFlags::Callable;
@@ -236,7 +238,7 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
236238

237239
SymbolMap InternedResult;
238240
for (auto *Sym : G.defined_symbols())
239-
if (Sym->getScope() != Scope::Local) {
241+
if (Sym->getScope() < Scope::SideEffectsOnly) {
240242
auto InternedName = ES.intern(Sym->getName());
241243
auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple());
242244
auto Flags = getJITSymbolFlagsForSymbol(*Sym);
@@ -249,7 +251,7 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
249251
}
250252

251253
for (auto *Sym : G.absolute_symbols())
252-
if (Sym->getScope() != Scope::Local) {
254+
if (Sym->getScope() < Scope::SideEffectsOnly) {
253255
auto InternedName = ES.intern(Sym->getName());
254256
auto Ptr = getJITSymbolPtrForSymbol(*Sym, G.getTargetTriple());
255257
auto Flags = getJITSymbolFlagsForSymbol(*Sym);
@@ -281,11 +283,9 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
281283
// If this is a materialization-side-effects only symbol then bump
282284
// the counter and remove in from the result, otherwise make sure that
283285
// it's defined.
284-
if (Flags.hasMaterializationSideEffectsOnly()) {
286+
if (Flags.hasMaterializationSideEffectsOnly())
285287
++NumMaterializationSideEffectsOnlySymbols;
286-
InternedResult.erase(Sym);
287-
continue;
288-
} else if (I == InternedResult.end())
288+
else if (I == InternedResult.end())
289289
MissingSymbols.push_back(Sym);
290290
else if (Layer.OverrideObjectFlags)
291291
I->second.setFlags(Flags);

0 commit comments

Comments
 (0)