[llvm] [ORC] Add MachOPlatform::HeaderOptions customization callback. (PR #191819)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 07:15:15 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/191819
This change aims to make it easier for MachOPlatform clients to customize JITDylib MachO headers.
At MachOPlatform construction time clients can now supply a MachOPlatform::HeaderOptionsBuilder. The supplied callback will be called by setupJITDylib to create the HeaderOptions for the JITDylib being set up.
No testcase: Constructing a MachOPlatform instance requires the ORC runtime, which we can't require for LLVM unit or regression suite tests. We should look at testing this functionality in the new ORC runtime once it's ready.
>From 7e4ea0fdcdd086aadf998737e8e4dc4df8f8332b Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Mon, 13 Apr 2026 23:46:15 +1000
Subject: [PATCH] [ORC] Add MachOPlatform::HeaderOptions customization
callback.
This change aims to make it easier for MachOPlatform clients to customize
JITDylib MachO headers.
At MachOPlatform construction time clients can now supply a
MachOPlatform::HeaderOptionsBuilder. The supplied callback will be called by
setupJITDylib to create the HeaderOptions for the JITDylib being set up.
No testcase: Constructing a MachOPlatform instance requires the ORC runtime,
which we can't require for LLVM unit or regression suite tests. We should look
at testing this functionality in the new ORC runtime once it's ready.
---
.../llvm/ExecutionEngine/Orc/MachOPlatform.h | 12 ++++++-
.../lib/ExecutionEngine/Orc/MachOPlatform.cpp | 33 +++++++++++--------
2 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
index b23093df80084..753c322a9121f 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
@@ -92,6 +92,9 @@ class LLVM_ABI MachOPlatform : public Platform {
HeaderOptions(Dylib D) : IDDylib(std::move(D)) {}
};
+ /// Callback for generating HeaderOptions structs for new JITDylibs.
+ using HeaderOptionsBuilder = unique_function<HeaderOptions(JITDylib &JD)>;
+
/// Used by setupJITDylib to create MachO header MaterializationUnits for
/// JITDylibs.
using MachOHeaderMUBuilder =
@@ -143,6 +146,7 @@ class LLVM_ABI MachOPlatform : public Platform {
static Expected<std::unique_ptr<MachOPlatform>>
Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
std::unique_ptr<DefinitionGenerator> OrcRuntime,
+ HeaderOptionsBuilder BuildHeaderOpts = defaultHeaderOpts,
HeaderOptions PlatformJDOpts = {},
MachOHeaderMUBuilder BuildMachOHeaderMU = buildSimpleMachOHeaderMU,
std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
@@ -150,7 +154,9 @@ class LLVM_ABI MachOPlatform : public Platform {
/// Construct using a path to the ORC runtime.
static Expected<std::unique_ptr<MachOPlatform>>
Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
- const char *OrcRuntimePath, HeaderOptions PlatformJDOpts = {},
+ const char *OrcRuntimePath,
+ HeaderOptionsBuilder BuildHeaderOpts = defaultHeaderOpts,
+ HeaderOptions PlatformJDOpts = {},
MachOHeaderMUBuilder BuildMachOHeaderMU = buildSimpleMachOHeaderMU,
std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
@@ -189,6 +195,8 @@ class LLVM_ABI MachOPlatform : public Platform {
static ArrayRef<std::pair<const char *, const char *>>
standardLazyCompilationAliases();
+ static HeaderOptions defaultHeaderOpts(JITDylib &JD);
+
private:
using SymbolTableVector = SmallVector<
std::tuple<ExecutorAddr, ExecutorAddr, MachOExecutorSymbolFlags>>;
@@ -305,6 +313,7 @@ class LLVM_ABI MachOPlatform : public Platform {
MachOPlatform(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
+ HeaderOptionsBuilder BuildHeaderOpts,
HeaderOptions PlatformJDOpts,
MachOHeaderMUBuilder BuildMachOHeaderMU, Error &Err);
@@ -334,6 +343,7 @@ class LLVM_ABI MachOPlatform : public Platform {
ExecutionSession &ES;
JITDylib &PlatformJD;
ObjectLinkingLayer &ObjLinkingLayer;
+ HeaderOptionsBuilder BuildHeaderOpts;
MachOHeaderMUBuilder BuildMachOHeaderMU;
SymbolStringPtr MachOHeaderStartSymbol = ES.intern("___dso_handle");
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 6a5fb51cd6d5e..f8bdb6e541df1 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -279,6 +279,7 @@ MachOPlatform::HeaderOptions::BuildVersionOpts::fromTriple(const Triple &TT,
Expected<std::unique_ptr<MachOPlatform>>
MachOPlatform::Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
std::unique_ptr<DefinitionGenerator> OrcRuntime,
+ HeaderOptionsBuilder BuildHeaderOpts,
HeaderOptions PlatformJDOpts,
MachOHeaderMUBuilder BuildMachOHeaderMU,
std::optional<SymbolAliasMap> RuntimeAliases) {
@@ -313,19 +314,20 @@ MachOPlatform::Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
// Create the instance.
Error Err = Error::success();
- auto P = std::unique_ptr<MachOPlatform>(new MachOPlatform(
- ObjLinkingLayer, PlatformJD, std::move(OrcRuntime),
- std::move(PlatformJDOpts), std::move(BuildMachOHeaderMU), Err));
+ auto P = std::unique_ptr<MachOPlatform>(
+ new MachOPlatform(ObjLinkingLayer, PlatformJD, std::move(OrcRuntime),
+ std::move(BuildHeaderOpts), std::move(PlatformJDOpts),
+ std::move(BuildMachOHeaderMU), Err));
if (Err)
return std::move(Err);
return std::move(P);
}
-Expected<std::unique_ptr<MachOPlatform>>
-MachOPlatform::Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
- const char *OrcRuntimePath, HeaderOptions PlatformJDOpts,
- MachOHeaderMUBuilder BuildMachOHeaderMU,
- std::optional<SymbolAliasMap> RuntimeAliases) {
+Expected<std::unique_ptr<MachOPlatform>> MachOPlatform::Create(
+ ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
+ const char *OrcRuntimePath, HeaderOptionsBuilder BuildHeaderOpts,
+ HeaderOptions PlatformJDOpts, MachOHeaderMUBuilder BuildMachOHeaderMU,
+ std::optional<SymbolAliasMap> RuntimeAliases) {
// Create a generator for the ORC runtime archive.
auto OrcRuntimeArchiveGenerator =
@@ -335,12 +337,12 @@ MachOPlatform::Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
return Create(ObjLinkingLayer, PlatformJD,
std::move(*OrcRuntimeArchiveGenerator),
- std::move(PlatformJDOpts), std::move(BuildMachOHeaderMU),
- std::move(RuntimeAliases));
+ std::move(BuildHeaderOpts), std::move(PlatformJDOpts),
+ std::move(BuildMachOHeaderMU), std::move(RuntimeAliases));
}
Error MachOPlatform::setupJITDylib(JITDylib &JD) {
- return setupJITDylib(JD, /*Opts=*/{});
+ return setupJITDylib(JD, BuildHeaderOpts(JD));
}
Error MachOPlatform::setupJITDylib(JITDylib &JD, HeaderOptions Opts) {
@@ -436,6 +438,10 @@ MachOPlatform::standardLazyCompilationAliases() {
StandardLazyCompilationAliases);
}
+MachOPlatform::HeaderOptions MachOPlatform::defaultHeaderOpts(JITDylib &JD) {
+ return {};
+}
+
bool MachOPlatform::supportedTarget(const Triple &TT) {
switch (TT.getArch()) {
case Triple::aarch64:
@@ -472,10 +478,11 @@ MachOPlatform::flagsForSymbol(jitlink::Symbol &Sym) {
MachOPlatform::MachOPlatform(
ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
- HeaderOptions PlatformJDOpts, MachOHeaderMUBuilder BuildMachOHeaderMU,
- Error &Err)
+ HeaderOptionsBuilder BuildHeaderOpts, HeaderOptions PlatformJDOpts,
+ MachOHeaderMUBuilder BuildMachOHeaderMU, Error &Err)
: ES(ObjLinkingLayer.getExecutionSession()), PlatformJD(PlatformJD),
ObjLinkingLayer(ObjLinkingLayer),
+ BuildHeaderOpts(std::move(BuildHeaderOpts)),
BuildMachOHeaderMU(std::move(BuildMachOHeaderMU)) {
ErrorAsOutParameter _(Err);
ObjLinkingLayer.addPlugin(std::make_unique<MachOPlatformPlugin>(*this));
More information about the llvm-commits
mailing list