@@ -794,14 +794,29 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
794
794
795
795
bool InBootstrapPhase = false ;
796
796
797
- if (LLVM_UNLIKELY (&MR.getTargetJITDylib () == &MP.PlatformJD )) {
797
+ ExecutorAddr HeaderAddr;
798
+ {
798
799
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
+ }
802
805
}
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 ;
803
811
}
804
812
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
+
805
820
// If we're in the bootstrap phase then increment the active graphs.
806
821
if (LLVM_UNLIKELY (InBootstrapPhase))
807
822
Config.PostAllocationPasses .push_back ([this ](LinkGraph &G) {
@@ -857,10 +872,11 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
857
872
858
873
// Add a pass to register the final addresses of any special sections in the
859
874
// 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
+ });
864
880
865
881
// If we're in the bootstrap phase then steal allocation actions and then
866
882
// decrement the active graphs.
@@ -1249,7 +1265,7 @@ MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
1249
1265
SecRange.Start = std::min (SecRange.Start , R.Start );
1250
1266
SecRange.End = std::max (SecRange.End , R.End );
1251
1267
for (auto &E : B->edges ()) {
1252
- if (!E.getTarget ().isDefined ())
1268
+ if (E. getKind () != Edge::KeepAlive || !E.getTarget ().isDefined ())
1253
1269
continue ;
1254
1270
auto &TargetBlock = E.getTarget ().getBlock ();
1255
1271
auto &TargetSection = TargetBlock.getSection ();
@@ -1307,7 +1323,8 @@ MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
1307
1323
}
1308
1324
1309
1325
Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections (
1310
- jitlink::LinkGraph &G, JITDylib &JD, bool InBootstrapPhase) {
1326
+ jitlink::LinkGraph &G, JITDylib &JD, ExecutorAddr HeaderAddr,
1327
+ bool InBootstrapPhase) {
1311
1328
1312
1329
// Get a pointer to the thread data section if there is one. It will be used
1313
1330
// below.
@@ -1378,22 +1395,13 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
1378
1395
dbgs () << " " << KV.first << " : " << KV.second << " \n " ;
1379
1396
});
1380
1397
1398
+ assert (HeaderAddr && " Null header registered for JD" );
1381
1399
using SPSRegisterObjectPlatformSectionsArgs = SPSArgList<
1382
1400
SPSExecutorAddr,
1383
1401
SPSOptional<SPSTuple<SPSSequence<SPSExecutorAddrRange>,
1384
1402
SPSExecutorAddrRange, SPSExecutorAddrRange>>,
1385
1403
SPSSequence<SPSTuple<SPSString, SPSExecutorAddrRange>>>;
1386
1404
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
-
1397
1405
AllocActionCallPair AllocActions = {
1398
1406
cantFail (
1399
1407
WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
0 commit comments