Skip to content

Commit 382bafc

Browse files
committed
[ORC][MachO] Prepare MachOPlatform for compact-unwind support.
The MachOPlatform::MachOPlatformPlugin class will now inject a "__jitlink$libunwind_dso_base" symbol into each LinkGraph pointing to the Mach header for the containing JITDylib. The compact-unwind support plugin will use this symbol as the dso-base for the __unwind_info sections. (Failure to inject this symbol would result in the compact-unwind support plugin creating a new header for every graph).
1 parent 7256c91 commit 382bafc

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class MachOPlatform : public Platform {
259259

260260
std::optional<UnwindSections> findUnwindSectionInfo(jitlink::LinkGraph &G);
261261
Error registerObjectPlatformSections(jitlink::LinkGraph &G, JITDylib &JD,
262+
ExecutorAddr HeaderAddr,
262263
bool InBootstrapPhase);
263264

264265
Error createObjCRuntimeObject(jitlink::LinkGraph &G);

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

13091325
Error 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

Comments
 (0)