[llvm] e77a473 - [ORC][MachO] Simplify use of LC_BUILD_VERSION in JITDylib headers.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 5 14:46:27 PST 2024
Author: Lang Hames
Date: 2024-03-05T14:46:22-08:00
New Revision: e77a473601314cc7e7aa912579982a38326d334c
URL: https://github.com/llvm/llvm-project/commit/e77a473601314cc7e7aa912579982a38326d334c
DIFF: https://github.com/llvm/llvm-project/commit/e77a473601314cc7e7aa912579982a38326d334c.diff
LOG: [ORC][MachO] Simplify use of LC_BUILD_VERSION in JITDylib headers.
API clients can now set a MachO::HeaderOptions::BuildVersionOpts field to have
MachOPlatform add an LC_BUILD_VERSION load command to the Mach header for each
JITDylib.
No testcase yet. In the future we'll try to add a MachO parser to the ORC
runtime and extra test options to llvm-jitlink for this.
This commit also incidentally fixes a bug in the MachOBuilder class that lead to
a delegation cycle.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h
llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h
index 9a011a427db3b7..6ffd286c365ac2 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h
@@ -78,7 +78,7 @@ struct MachOBuilderLoadCommand
template <typename... ArgTs>
MachOBuilderLoadCommand(ArgTs &&...Args)
- : MachOBuilderLoadCommand(std::forward<ArgTs>(Args)...) {}
+ : MachOBuilderLoadCommandImplBase<LCType>(std::forward<ArgTs>(Args)...) {}
};
template <>
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
index ff1c420d047e5f..e928faf4788559 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
@@ -58,9 +58,24 @@ class MachOPlatform : public Platform {
uint32_t CompatibilityVersion;
};
+ struct BuildVersionOpts {
+
+ // Derive platform from triple.
+ static BuildVersionOpts fromTriple(const Triple &TT, uint32_t MinOS,
+ uint32_t SDK);
+
+ uint32_t Platform; // Platform.
+ uint32_t MinOS; // X.Y.Z is encoded in nibbles xxxx.yy.zz
+ uint32_t SDK; // X.Y.Z is encoded in nibbles xxxx.yy.zz
+ };
+
/// Override for LC_IC_DYLIB. If this is nullopt, {JD.getName(), 0, 0, 0}
/// will be used.
std::optional<Dylib> IDDylib;
+
+ /// Override for LC_BUILD_VERSION. If this is nullopt then
+ std::optional<BuildVersionOpts> BuildVersion;
+
/// List of LC_LOAD_DYLIBs.
std::vector<Dylib> LoadDylibs;
/// List of LC_RPATHs.
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 377a31e63ec11c..994acf5843642a 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -255,6 +255,36 @@ struct ObjCImageInfoFlags {
namespace llvm {
namespace orc {
+MachOPlatform::HeaderOptions::BuildVersionOpts
+MachOPlatform::HeaderOptions::BuildVersionOpts::fromTriple(const Triple &TT,
+ uint32_t MinOS,
+ uint32_t SDK) {
+
+ uint32_t Platform;
+ switch (TT.getOS()) {
+ case Triple::IOS:
+ Platform = TT.isSimulatorEnvironment() ? MachO::PLATFORM_IOS
+ : MachO::PLATFORM_IOSSIMULATOR;
+ break;
+ case Triple::MacOSX:
+ Platform = MachO::PLATFORM_MACOS;
+ break;
+ case Triple::TvOS:
+ Platform = TT.isSimulatorEnvironment() ? MachO::PLATFORM_TVOS
+ : MachO::PLATFORM_TVOSSIMULATOR;
+ break;
+ case Triple::WatchOS:
+ Platform = TT.isSimulatorEnvironment() ? MachO::PLATFORM_WATCHOS
+ : MachO::PLATFORM_WATCHOSSIMULATOR;
+ break;
+ default:
+ Platform = MachO::PLATFORM_UNKNOWN;
+ break;
+ }
+
+ return {Platform, MinOS, SDK};
+}
+
Expected<std::unique_ptr<MachOPlatform>> MachOPlatform::Create(
ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
JITDylib &PlatformJD, std::unique_ptr<DefinitionGenerator> OrcRuntime,
@@ -1695,6 +1725,11 @@ jitlink::Block &createHeaderBlock(MachOPlatform &MOP,
else
B.template addLoadCommand<MachO::LC_ID_DYLIB>(JD.getName(), 0, 0, 0);
+ if (Opts.BuildVersion)
+ B.template addLoadCommand<MachO::LC_BUILD_VERSION>(
+ Opts.BuildVersion->Platform, Opts.BuildVersion->MinOS,
+ Opts.BuildVersion->SDK, static_cast<uint32_t>(0));
+
for (auto &D : Opts.LoadDylibs)
B.template addLoadCommand<MachO::LC_LOAD_DYLIB>(
D.Name, D.Timestamp, D.CurrentVersion, D.CompatibilityVersion);
More information about the llvm-commits
mailing list