Skip to content

Commit 30b73ed

Browse files
committed
[ORC][MachO] Avoid another race condition in MachOPlatform bootstrap.
Similar to a9e75b1: During MachOPlatform bootstrap we need to defer actions until essential platform functionality has been loaded, but the platform itself may be loaded under a concurrent dispatcher so we have to guard against the deferred actions vector being accessed concurrently. This fixes a probablistic failure in the ORC runtime regression tests on Darwin/x86-64 that was spotted after edca1d9 (which turned on concurrent linking by default in llvm-jitlink).
1 parent febe1a9 commit 30b73ed

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,12 @@ Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineEnd(
937937
jitlink::LinkGraph &G) {
938938
std::lock_guard<std::mutex> Lock(MP.Bootstrap.load()->Mutex);
939939
assert(MP.Bootstrap && "DeferredAAs reset before bootstrap completed");
940+
941+
// Transfer any allocation actions to DeferredAAs.
942+
std::move(G.allocActions().begin(), G.allocActions().end(),
943+
std::back_inserter(MP.Bootstrap.load()->DeferredAAs));
944+
G.allocActions().clear();
945+
940946
--MP.Bootstrap.load()->ActiveGraphs;
941947
// Notify Bootstrap->CV while holding the mutex because the mutex is
942948
// also keeping Bootstrap->CV alive.
@@ -1397,10 +1403,6 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
13971403
SPSExecutorAddrRange, SPSExecutorAddrRange>>,
13981404
SPSSequence<SPSTuple<SPSString, SPSExecutorAddrRange>>>;
13991405

1400-
shared::AllocActions &allocActions = LLVM_LIKELY(!InBootstrapPhase)
1401-
? G.allocActions()
1402-
: MP.Bootstrap.load()->DeferredAAs;
1403-
14041406
ExecutorAddr HeaderAddr;
14051407
{
14061408
std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
@@ -1410,7 +1412,7 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
14101412
assert(I->second && "Null header registered for JD");
14111413
HeaderAddr = I->second;
14121414
}
1413-
allocActions.push_back(
1415+
G.allocActions().push_back(
14141416
{cantFail(
14151417
WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
14161418
MP.RegisterObjectPlatformSections.Addr, HeaderAddr, UnwindInfo,

0 commit comments

Comments
 (0)