diff options
author | Lang Hames <lhames@Langs-MacBook-Pro.local> | 2024-03-05 14:27:31 -0800 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2024-03-05 14:46:22 -0800 |
commit | e77a473601314cc7e7aa912579982a38326d334c (patch) | |
tree | 0e75f1bd1fbce2acacfd9d2584fe95c1f8af9dbf | |
parent | 58d8805ff9f0a9947ac122b463c00d6c0656eae6 (diff) | |
download | llvm-e77a473601314cc7e7aa912579982a38326d334c.zip llvm-e77a473601314cc7e7aa912579982a38326d334c.tar.gz llvm-e77a473601314cc7e7aa912579982a38326d334c.tar.bz2 |
[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.
-rw-r--r-- | llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h | 15 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp | 35 |
3 files changed, 51 insertions, 1 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h index 9a011a4..6ffd286 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h @@ -78,7 +78,7 @@ public: 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 ff1c420..e928faf 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h @@ -58,9 +58,24 @@ public: 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 377a31e..994acf5 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); |