Skip to content

Commit

Permalink
Re-apply "[ORC][JITLink] Treat common symbols as weak definitions." w…
Browse files Browse the repository at this point in the history
…ith fixes.

This reapplies 785d376, which was reverted in c49837f due to bot
failures. The fix was to relax some asserts to allow common symbols to be
resolved with either common or weak flags, rather than requiring one or the
other.
  • Loading branch information
lhames committed Jul 24, 2024
1 parent dbe308c commit e7698a1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ Expected<Symbol *> COFFLinkGraphBuilder::createDefinedSymbol(
return &G->addDefinedSymbol(
G->createZeroFillBlock(getCommonSection(), Symbol.getValue(),
orc::ExecutorAddr(), Symbol.getValue(), 0),
0, SymbolName, Symbol.getValue(), Linkage::Strong, Scope::Default,
0, SymbolName, Symbol.getValue(), Linkage::Weak, Scope::Default,
false, false);
}
if (Symbol.isAbsolute())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
Symbol &GSym = G->addDefinedSymbol(
G->createZeroFillBlock(getCommonSection(), Sym.st_size,
orc::ExecutorAddr(), Sym.getValue(), 0),
0, *Name, Sym.st_size, Linkage::Strong, Scope::Default, false, false);
0, *Name, Sym.st_size, Linkage::Weak, Scope::Default, false, false);
setGraphSymbol(SymIndex, GSym);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ Error MachOLinkGraphBuilder::graphifyRegularSymbols() {
orc::ExecutorAddrDiff(NSym.Value),
orc::ExecutorAddr(),
1ull << MachO::GET_COMM_ALIGN(NSym.Desc), 0),
0, *NSym.Name, orc::ExecutorAddrDiff(NSym.Value), Linkage::Strong,
0, *NSym.Name, orc::ExecutorAddrDiff(NSym.Value), Linkage::Weak,
NSym.S, false, NSym.Desc & MachO::N_NO_DEAD_STRIP);
} else {
if (!NSym.Name)
Expand Down
32 changes: 23 additions & 9 deletions llvm/lib/ExecutionEngine/Orc/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,20 @@ Error JITDylib::resolve(MaterializationResponsibility &MR,
if (SymI->second.getFlags().hasError())
SymbolsInErrorState.insert(KV.first);
else {
auto Flags = KV.second.getFlags();
Flags &= ~JITSymbolFlags::Common;
assert(Flags ==
(SymI->second.getFlags() & ~JITSymbolFlags::Common) &&
"Resolved flags should match the declared flags");
if (SymI->second.getFlags() & JITSymbolFlags::Common) {
auto WeakOrCommon = JITSymbolFlags::Weak | JITSymbolFlags::Common;
assert((KV.second.getFlags() & WeakOrCommon) &&
"Common symbols must be resolved as common or weak");
assert((KV.second.getFlags() & ~WeakOrCommon) ==
(SymI->second.getFlags() & ~JITSymbolFlags::Common) &&
"Resolving symbol with incorrect flags");

Worklist.push_back({SymI, {KV.second.getAddress(), Flags}});
} else
assert(KV.second.getFlags() == SymI->second.getFlags() &&
"Resolved flags should match the declared flags");

Worklist.push_back(
{SymI, {KV.second.getAddress(), SymI->second.getFlags()}});
}
}

Expand Down Expand Up @@ -2899,9 +2906,16 @@ Error ExecutionSession::OL_notifyResolved(MaterializationResponsibility &MR,
"Resolving symbol outside this responsibility set");
assert(!I->second.hasMaterializationSideEffectsOnly() &&
"Can't resolve materialization-side-effects-only symbol");
assert((KV.second.getFlags() & ~JITSymbolFlags::Common) ==
(I->second & ~JITSymbolFlags::Common) &&
"Resolving symbol with incorrect flags");
if (I->second & JITSymbolFlags::Common) {
auto WeakOrCommon = JITSymbolFlags::Weak | JITSymbolFlags::Common;
assert((KV.second.getFlags() & WeakOrCommon) &&
"Common symbols must be resolved as common or weak");
assert((KV.second.getFlags() & ~WeakOrCommon) ==
(I->second & ~JITSymbolFlags::Common) &&
"Resolving symbol with incorrect flags");
} else
assert(KV.second.getFlags() == I->second &&
"Resolving symbol with incorrect flags");
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# CHECK: Creating graph symbols...
# CHECK: 7: Creating defined graph symbol for COFF symbol "var" in (common) (index: 0)
# CHECK-NEXT: 0x0 (block + 0x00000000): size: 0x00000004, linkage: strong, scope: default, dead - var
# CHECK-NEXT: 0x0 (block + 0x00000000): size: 0x00000004, linkage: weak, scope: default, dead - var

.text

Expand Down

0 comments on commit e7698a1

Please sign in to comment.