diff options
author | Alex Lorenz <arphaman@gmail.com> | 2022-02-02 00:19:49 -0800 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2022-02-02 08:30:39 -0800 |
commit | 116c1bea65ac268bc46a2373220c81d02fc0a256 (patch) | |
tree | 294819c7088249fa8de575c7cfd3aa1fe51b8b94 /llvm/lib/IR/Module.cpp | |
parent | 6440197ba5bfc05c1fda74e11f6dbe93c1b5dea6 (diff) | |
download | llvm-116c1bea65ac268bc46a2373220c81d02fc0a256.zip llvm-116c1bea65ac268bc46a2373220c81d02fc0a256.tar.gz llvm-116c1bea65ac268bc46a2373220c81d02fc0a256.tar.bz2 |
[clang][macho] add clang frontend support for emitting macho files with two build version load commands
This patch extends clang frontend to add metadata that can be used to emit macho files with two build version load commands.
It utilizes "darwin.target_variant.triple" and "darwin.target_variant.SDK Version" metadata names for that.
MachO uses two build version load commands to represent an object file / binary that is targeting both the macOS target,
and the Mac Catalyst target. At runtime, a dynamic library that supports both targets can be loaded from either a native
macOS or a Mac Catalyst app on a macOS system. We want to add support to this to upstream to LLVM to be able to build
compiler-rt for both targets, to finish the complete support for the Mac Catalyst platform, which is right now targetable
by upstream clang, but the compiler-rt bits aren't supported because of the lack of this multiple build version support.
Differential Revision: https://reviews.llvm.org/D115415
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 4974b37..6156edd 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -734,7 +734,7 @@ void Module::setOverrideStackAlignment(unsigned Align) { addModuleFlag(ModFlagBehavior::Error, "override-stack-alignment", Align); } -void Module::setSDKVersion(const VersionTuple &V) { +static void addSDKVersionMD(const VersionTuple &V, Module &M, StringRef Name) { SmallVector<unsigned, 3> Entries; Entries.push_back(V.getMajor()); if (auto Minor = V.getMinor()) { @@ -744,8 +744,12 @@ void Module::setSDKVersion(const VersionTuple &V) { // Ignore the 'build' component as it can't be represented in the object // file. } - addModuleFlag(ModFlagBehavior::Warning, "SDK Version", - ConstantDataArray::get(Context, Entries)); + M.addModuleFlag(Module::ModFlagBehavior::Warning, Name, + ConstantDataArray::get(M.getContext(), Entries)); +} + +void Module::setSDKVersion(const VersionTuple &V) { + addSDKVersionMD(V, *this, "SDK Version"); } static VersionTuple getSDKVersionMD(Metadata *MD) { @@ -818,6 +822,15 @@ StringRef Module::getDarwinTargetVariantTriple() const { return ""; } +void Module::setDarwinTargetVariantTriple(StringRef T) { + addModuleFlag(ModFlagBehavior::Override, "darwin.target_variant.triple", + MDString::get(getContext(), T)); +} + VersionTuple Module::getDarwinTargetVariantSDKVersion() const { return getSDKVersionMD(getModuleFlag("darwin.target_variant.SDK Version")); } + +void Module::setDarwinTargetVariantSDKVersion(VersionTuple Version) { + addSDKVersionMD(Version, *this, "darwin.target_variant.SDK Version"); +} |