@@ -794,14 +794,29 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
794794
795795 bool InBootstrapPhase = false ;
796796
797- if (LLVM_UNLIKELY (&MR.getTargetJITDylib () == &MP.PlatformJD )) {
797+ ExecutorAddr HeaderAddr;
798+ {
798799 std::lock_guard<std::mutex> Lock (MP.PlatformMutex );
799- if (MP.Bootstrap ) {
800- InBootstrapPhase = true ;
801- ++MP.Bootstrap ->ActiveGraphs ;
800+ if (LLVM_UNLIKELY (&MR.getTargetJITDylib () == &MP.PlatformJD )) {
801+ if (MP.Bootstrap ) {
802+ InBootstrapPhase = true ;
803+ ++MP.Bootstrap ->ActiveGraphs ;
804+ }
802805 }
806+
807+ // Get the dso-base address if available.
808+ auto I = MP.JITDylibToHeaderAddr .find (&MR.getTargetJITDylib ());
809+ if (I != MP.JITDylibToHeaderAddr .end ())
810+ HeaderAddr = I->second ;
803811 }
804812
813+ // Point the libunwind dso-base absolute symbol at the header for the
814+ // JITDylib. This will prevent us from synthesizing a new header for
815+ // every object.
816+ if (HeaderAddr)
817+ LG.addAbsoluteSymbol (" __jitlink$libunwind_dso_base" , HeaderAddr, 0 ,
818+ Linkage::Strong, Scope::Local, true );
819+
805820 // If we're in the bootstrap phase then increment the active graphs.
806821 if (LLVM_UNLIKELY (InBootstrapPhase))
807822 Config.PostAllocationPasses .push_back ([this ](LinkGraph &G) {
@@ -857,10 +872,11 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
857872
858873 // Add a pass to register the final addresses of any special sections in the
859874 // object with the runtime.
860- Config.PostAllocationPasses .push_back (
861- [this , &JD = MR.getTargetJITDylib (), InBootstrapPhase](LinkGraph &G) {
862- return registerObjectPlatformSections (G, JD, InBootstrapPhase);
863- });
875+ Config.PostAllocationPasses .push_back ([this , &JD = MR.getTargetJITDylib (),
876+ HeaderAddr,
877+ InBootstrapPhase](LinkGraph &G) {
878+ return registerObjectPlatformSections (G, JD, HeaderAddr, InBootstrapPhase);
879+ });
864880
865881 // If we're in the bootstrap phase then steal allocation actions and then
866882 // decrement the active graphs.
@@ -1249,7 +1265,7 @@ MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
12491265 SecRange.Start = std::min (SecRange.Start , R.Start );
12501266 SecRange.End = std::max (SecRange.End , R.End );
12511267 for (auto &E : B->edges ()) {
1252- if (!E.getTarget ().isDefined ())
1268+ if (E. getKind () != Edge::KeepAlive || !E.getTarget ().isDefined ())
12531269 continue ;
12541270 auto &TargetBlock = E.getTarget ().getBlock ();
12551271 auto &TargetSection = TargetBlock.getSection ();
@@ -1307,7 +1323,8 @@ MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
13071323}
13081324
13091325Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections (
1310- jitlink::LinkGraph &G, JITDylib &JD, bool InBootstrapPhase) {
1326+ jitlink::LinkGraph &G, JITDylib &JD, ExecutorAddr HeaderAddr,
1327+ bool InBootstrapPhase) {
13111328
13121329 // Get a pointer to the thread data section if there is one. It will be used
13131330 // below.
@@ -1378,22 +1395,13 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
13781395 dbgs () << " " << KV.first << " : " << KV.second << " \n " ;
13791396 });
13801397
1398+ assert (HeaderAddr && " Null header registered for JD" );
13811399 using SPSRegisterObjectPlatformSectionsArgs = SPSArgList<
13821400 SPSExecutorAddr,
13831401 SPSOptional<SPSTuple<SPSSequence<SPSExecutorAddrRange>,
13841402 SPSExecutorAddrRange, SPSExecutorAddrRange>>,
13851403 SPSSequence<SPSTuple<SPSString, SPSExecutorAddrRange>>>;
13861404
1387- ExecutorAddr HeaderAddr;
1388- {
1389- std::lock_guard<std::mutex> Lock (MP.PlatformMutex );
1390- auto I = MP.JITDylibToHeaderAddr .find (&JD);
1391- assert (I != MP.JITDylibToHeaderAddr .end () &&
1392- " No header registered for JD" );
1393- assert (I->second && " Null header registered for JD" );
1394- HeaderAddr = I->second ;
1395- }
1396-
13971405 AllocActionCallPair AllocActions = {
13981406 cantFail (
13991407 WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
0 commit comments