Skip to content

Commit a9e75b1

Browse files
committed
[ORC][MachO] Fix race condition during MachOPlatform bootstrap.
In 93509b4 MachOPlatform was updated to store object symbols in a shared vector during bootstrap (this table is later attached to the bootstrap-completion graph once the ORC runtime's symbol table registration code is ready). The shared vector was not guarded with a mutex, so use of a concurrent dispatcher could lead to races during bootstrap. This commit fixes the issue by guarding access to the table with the BootstrapInfo mutex. No testcase since this only manifests rarely when both a concurrent dispatcher and the ORC runtime are used. Once we add a concurrent dispatcher option to llvm-jitlink we may be able to test this with a regression test in the ORC runtime and TSan enabled. rdar://133520308
1 parent a50b963 commit a9e75b1

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,22 +1697,24 @@ Error MachOPlatform::MachOPlatformPlugin::addSymbolTableRegistration(
16971697
HeaderAddr = I->second;
16981698
}
16991699

1700-
SymbolTableVector LocalSymTab;
1701-
auto &SymTab = LLVM_LIKELY(!InBootstrapPhase) ? LocalSymTab
1702-
: MP.Bootstrap.load()->SymTab;
1700+
if (LLVM_UNLIKELY(InBootstrapPhase)) {
1701+
// If we're in the bootstrap phase then just record these symbols in the
1702+
// bootstrap object and then bail out -- registration will be attached to
1703+
// the bootstrap graph.
1704+
std::lock_guard<std::mutex> Lock(MP.Bootstrap.load()->Mutex);
1705+
auto &SymTab = MP.Bootstrap.load()->SymTab;
1706+
for (auto &[OriginalSymbol, NameSym] : JITSymTabInfo)
1707+
SymTab.push_back({NameSym->getAddress(), OriginalSymbol->getAddress(),
1708+
flagsForSymbol(*OriginalSymbol)});
1709+
return Error::success();
1710+
}
1711+
1712+
SymbolTableVector SymTab;
17031713
for (auto &[OriginalSymbol, NameSym] : JITSymTabInfo)
17041714
SymTab.push_back({NameSym->getAddress(), OriginalSymbol->getAddress(),
17051715
flagsForSymbol(*OriginalSymbol)});
17061716

1707-
// Bail out if we're in the bootstrap phase -- registration of thees symbols
1708-
// will be attached to the bootstrap graph.
1709-
if (LLVM_UNLIKELY(InBootstrapPhase))
1710-
return Error::success();
1711-
1712-
shared::AllocActions &allocActions = LLVM_LIKELY(!InBootstrapPhase)
1713-
? G.allocActions()
1714-
: MP.Bootstrap.load()->DeferredAAs;
1715-
allocActions.push_back(
1717+
G.allocActions().push_back(
17161718
{cantFail(WrapperFunctionCall::Create<SPSRegisterSymbolsArgs>(
17171719
MP.RegisterObjectSymbolTable.Addr, HeaderAddr, SymTab)),
17181720
cantFail(WrapperFunctionCall::Create<SPSRegisterSymbolsArgs>(

0 commit comments

Comments
 (0)