[llvm] 382bafc - [ORC][MachO] Prepare MachOPlatform for compact-unwind support.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 21:51:49 PST 2025
Author: Lang Hames
Date: 2025-01-22T16:51:40+11:00
New Revision: 382bafc9579f40bd834b78df671ac45308310462
URL: https://github.com/llvm/llvm-project/commit/382bafc9579f40bd834b78df671ac45308310462
DIFF: https://github.com/llvm/llvm-project/commit/382bafc9579f40bd834b78df671ac45308310462.diff
LOG: [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).
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
index c9f7178ebcadbd..6e99f6c03a7c67 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
@@ -259,6 +259,7 @@ class MachOPlatform : public Platform {
std::optional<UnwindSections> findUnwindSectionInfo(jitlink::LinkGraph &G);
Error registerObjectPlatformSections(jitlink::LinkGraph &G, JITDylib &JD,
+ ExecutorAddr HeaderAddr,
bool InBootstrapPhase);
Error createObjCRuntimeObject(jitlink::LinkGraph &G);
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index f8f65ec3b4cf3c..48d54190fafb6a 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -794,14 +794,29 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
bool InBootstrapPhase = false;
- if (LLVM_UNLIKELY(&MR.getTargetJITDylib() == &MP.PlatformJD)) {
+ ExecutorAddr HeaderAddr;
+ {
std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
- if (MP.Bootstrap) {
- InBootstrapPhase = true;
- ++MP.Bootstrap->ActiveGraphs;
+ if (LLVM_UNLIKELY(&MR.getTargetJITDylib() == &MP.PlatformJD)) {
+ if (MP.Bootstrap) {
+ InBootstrapPhase = true;
+ ++MP.Bootstrap->ActiveGraphs;
+ }
}
+
+ // Get the dso-base address if available.
+ auto I = MP.JITDylibToHeaderAddr.find(&MR.getTargetJITDylib());
+ if (I != MP.JITDylibToHeaderAddr.end())
+ HeaderAddr = I->second;
}
+ // Point the libunwind dso-base absolute symbol at the header for the
+ // JITDylib. This will prevent us from synthesizing a new header for
+ // every object.
+ if (HeaderAddr)
+ LG.addAbsoluteSymbol("__jitlink$libunwind_dso_base", HeaderAddr, 0,
+ Linkage::Strong, Scope::Local, true);
+
// If we're in the bootstrap phase then increment the active graphs.
if (LLVM_UNLIKELY(InBootstrapPhase))
Config.PostAllocationPasses.push_back([this](LinkGraph &G) {
@@ -857,10 +872,11 @@ void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
// Add a pass to register the final addresses of any special sections in the
// object with the runtime.
- Config.PostAllocationPasses.push_back(
- [this, &JD = MR.getTargetJITDylib(), InBootstrapPhase](LinkGraph &G) {
- return registerObjectPlatformSections(G, JD, InBootstrapPhase);
- });
+ Config.PostAllocationPasses.push_back([this, &JD = MR.getTargetJITDylib(),
+ HeaderAddr,
+ InBootstrapPhase](LinkGraph &G) {
+ return registerObjectPlatformSections(G, JD, HeaderAddr, InBootstrapPhase);
+ });
// If we're in the bootstrap phase then steal allocation actions and then
// decrement the active graphs.
@@ -1249,7 +1265,7 @@ MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
SecRange.Start = std::min(SecRange.Start, R.Start);
SecRange.End = std::max(SecRange.End, R.End);
for (auto &E : B->edges()) {
- if (!E.getTarget().isDefined())
+ if (E.getKind() != Edge::KeepAlive || !E.getTarget().isDefined())
continue;
auto &TargetBlock = E.getTarget().getBlock();
auto &TargetSection = TargetBlock.getSection();
@@ -1307,7 +1323,8 @@ MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
}
Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
- jitlink::LinkGraph &G, JITDylib &JD, bool InBootstrapPhase) {
+ jitlink::LinkGraph &G, JITDylib &JD, ExecutorAddr HeaderAddr,
+ bool InBootstrapPhase) {
// Get a pointer to the thread data section if there is one. It will be used
// below.
@@ -1378,22 +1395,13 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
dbgs() << " " << KV.first << ": " << KV.second << "\n";
});
+ assert(HeaderAddr && "Null header registered for JD");
using SPSRegisterObjectPlatformSectionsArgs = SPSArgList<
SPSExecutorAddr,
SPSOptional<SPSTuple<SPSSequence<SPSExecutorAddrRange>,
SPSExecutorAddrRange, SPSExecutorAddrRange>>,
SPSSequence<SPSTuple<SPSString, SPSExecutorAddrRange>>>;
- ExecutorAddr HeaderAddr;
- {
- std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
- auto I = MP.JITDylibToHeaderAddr.find(&JD);
- assert(I != MP.JITDylibToHeaderAddr.end() &&
- "No header registered for JD");
- assert(I->second && "Null header registered for JD");
- HeaderAddr = I->second;
- }
-
AllocActionCallPair AllocActions = {
cantFail(
WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
More information about the llvm-commits
mailing list