@@ -799,17 +799,21 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
799
799
800
800
using namespace jitlink ;
801
801
802
- bool InBootstrapPhase =
803
- &MR.getTargetJITDylib () == &MP.PlatformJD && MP.Bootstrap ;
802
+ bool InBootstrapPhase = false ;
803
+
804
+ if (LLVM_UNLIKELY (&MR.getTargetJITDylib () == &MP.PlatformJD )) {
805
+ std::lock_guard<std::mutex> Lock (MP.PlatformMutex );
806
+ if (MP.Bootstrap ) {
807
+ InBootstrapPhase = true ;
808
+ ++MP.Bootstrap ->ActiveGraphs ;
809
+ }
810
+ }
804
811
805
812
// If we're in the bootstrap phase then increment the active graphs.
806
- if (InBootstrapPhase) {
807
- Config.PrePrunePasses .push_back (
808
- [this ](LinkGraph &G) { return bootstrapPipelineStart (G); });
813
+ if (LLVM_UNLIKELY (InBootstrapPhase))
809
814
Config.PostAllocationPasses .push_back ([this ](LinkGraph &G) {
810
815
return bootstrapPipelineRecordRuntimeFunctions (G);
811
816
});
812
- }
813
817
814
818
// --- Handle Initializers ---
815
819
if (auto InitSymbol = MR.getInitializerSymbol ()) {
@@ -872,19 +876,11 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
872
876
[this ](LinkGraph &G) { return bootstrapPipelineEnd (G); });
873
877
}
874
878
875
- Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineStart (
876
- jitlink::LinkGraph &G) {
877
- // Increment the active graphs count in BootstrapInfo.
878
- std::lock_guard<std::mutex> Lock (MP.Bootstrap .load ()->Mutex );
879
- ++MP.Bootstrap .load ()->ActiveGraphs ;
880
- return Error::success ();
881
- }
882
-
883
879
Error MachOPlatform::MachOPlatformPlugin::
884
880
bootstrapPipelineRecordRuntimeFunctions (jitlink::LinkGraph &G) {
885
881
// Record bootstrap function names.
886
882
std::pair<StringRef, ExecutorAddr *> RuntimeSymbols[] = {
887
- {*MP.MachOHeaderStartSymbol , &MP.Bootstrap . load () ->MachOHeaderAddr },
883
+ {*MP.MachOHeaderStartSymbol , &MP.Bootstrap ->MachOHeaderAddr },
888
884
{*MP.PlatformBootstrap .Name , &MP.PlatformBootstrap .Addr },
889
885
{*MP.PlatformShutdown .Name , &MP.PlatformShutdown .Addr },
890
886
{*MP.RegisterJITDylib .Name , &MP.RegisterJITDylib .Addr },
@@ -924,30 +920,22 @@ Error MachOPlatform::MachOPlatformPlugin::
924
920
// If this graph defines the macho header symbol then create the internal
925
921
// mapping between it and PlatformJD.
926
922
std::lock_guard<std::mutex> Lock (MP.PlatformMutex );
927
- MP.JITDylibToHeaderAddr [&MP.PlatformJD ] =
928
- MP.Bootstrap .load ()->MachOHeaderAddr ;
929
- MP.HeaderAddrToJITDylib [MP.Bootstrap .load ()->MachOHeaderAddr ] =
930
- &MP.PlatformJD ;
923
+ MP.JITDylibToHeaderAddr [&MP.PlatformJD ] = MP.Bootstrap ->MachOHeaderAddr ;
924
+ MP.HeaderAddrToJITDylib [MP.Bootstrap ->MachOHeaderAddr ] = &MP.PlatformJD ;
931
925
}
932
926
933
927
return Error::success ();
934
928
}
935
929
936
930
Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineEnd (
937
931
jitlink::LinkGraph &G) {
938
- std::lock_guard<std::mutex> Lock (MP.Bootstrap .load ()->Mutex );
939
- 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 ();
932
+ std::lock_guard<std::mutex> Lock (MP.Bootstrap ->Mutex );
945
933
946
- --MP.Bootstrap . load () ->ActiveGraphs ;
934
+ --MP.Bootstrap ->ActiveGraphs ;
947
935
// Notify Bootstrap->CV while holding the mutex because the mutex is
948
936
// also keeping Bootstrap->CV alive.
949
- if (MP.Bootstrap . load () ->ActiveGraphs == 0 )
950
- MP.Bootstrap . load () ->CV .notify_all ();
937
+ if (MP.Bootstrap ->ActiveGraphs == 0 )
938
+ MP.Bootstrap ->CV .notify_all ();
951
939
return Error::success ();
952
940
}
953
941
@@ -1412,15 +1400,23 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
1412
1400
assert (I->second && " Null header registered for JD" );
1413
1401
HeaderAddr = I->second ;
1414
1402
}
1415
- G.allocActions ().push_back (
1416
- {cantFail (
1417
- WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
1418
- MP.RegisterObjectPlatformSections .Addr , HeaderAddr, UnwindInfo,
1419
- MachOPlatformSecs)),
1420
- cantFail (
1421
- WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
1422
- MP.DeregisterObjectPlatformSections .Addr , HeaderAddr,
1423
- UnwindInfo, MachOPlatformSecs))});
1403
+
1404
+ AllocActionCallPair AllocActions = {
1405
+ cantFail (
1406
+ WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
1407
+ MP.RegisterObjectPlatformSections .Addr , HeaderAddr, UnwindInfo,
1408
+ MachOPlatformSecs)),
1409
+ cantFail (
1410
+ WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
1411
+ MP.DeregisterObjectPlatformSections .Addr , HeaderAddr,
1412
+ UnwindInfo, MachOPlatformSecs))};
1413
+
1414
+ if (LLVM_LIKELY (!InBootstrapPhase))
1415
+ G.allocActions ().push_back (std::move (AllocActions));
1416
+ else {
1417
+ std::lock_guard<std::mutex> Lock (MP.Bootstrap ->Mutex );
1418
+ MP.Bootstrap ->DeferredAAs .push_back (std::move (AllocActions));
1419
+ }
1424
1420
}
1425
1421
1426
1422
return Error::success ();
@@ -1701,8 +1697,8 @@ Error MachOPlatform::MachOPlatformPlugin::addSymbolTableRegistration(
1701
1697
// If we're in the bootstrap phase then just record these symbols in the
1702
1698
// bootstrap object and then bail out -- registration will be attached to
1703
1699
// the bootstrap graph.
1704
- std::lock_guard<std::mutex> Lock (MP.Bootstrap . load () ->Mutex );
1705
- auto &SymTab = MP.Bootstrap . load () ->SymTab ;
1700
+ std::lock_guard<std::mutex> Lock (MP.Bootstrap ->Mutex );
1701
+ auto &SymTab = MP.Bootstrap ->SymTab ;
1706
1702
for (auto &[OriginalSymbol, NameSym] : JITSymTabInfo)
1707
1703
SymTab.push_back ({NameSym->getAddress (), OriginalSymbol->getAddress (),
1708
1704
flagsForSymbol (*OriginalSymbol)});
0 commit comments