[clang] f693280 - [cc1as] Add support for emitting the build version load command for -darwin-target-variant
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 22 05:38:18 PDT 2022
Author: Byoungchan Lee
Date: 2022-04-22T08:38:07-04:00
New Revision: f69328049e9e7fde7a314de785c76c1b93e069b2
URL: https://github.com/llvm/llvm-project/commit/f69328049e9e7fde7a314de785c76c1b93e069b2
DIFF: https://github.com/llvm/llvm-project/commit/f69328049e9e7fde7a314de785c76c1b93e069b2.diff
LOG: [cc1as] Add support for emitting the build version load command for -darwin-target-variant
This patch extends cc1as to export the build version load command with
LC_VERSION_MIN_MACOSX.
This is especially important for Mac Catalyst as Mac Catalyst uses
the MacOS's compiler rt built-ins.
Differential Revision: https://reviews.llvm.org/D121868
Added:
clang/test/Misc/cc1as-darwin-target-variant-triple.s
Modified:
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Darwin.h
clang/tools/driver/cc1as_main.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index bb870dd8bb26c..8c013e3fe5b19 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4854,16 +4854,21 @@ def target_abi : Separate<["-"], "target-abi">,
MarshallingInfoString<TargetOpts<"ABI">>;
def target_sdk_version_EQ : Joined<["-"], "target-sdk-version=">,
HelpText<"The version of target SDK used for compilation">;
-def darwin_target_variant_triple : Separate<["-"], "darwin-target-variant-triple">,
- HelpText<"Specify the darwin target variant triple">,
- MarshallingInfoString<TargetOpts<"DarwinTargetVariantTriple">>,
- Normalizer<"normalizeTriple">;
def darwin_target_variant_sdk_version_EQ : Joined<["-"],
"darwin-target-variant-sdk-version=">,
HelpText<"The version of darwin target variant SDK used for compilation">;
} // let Flags = [CC1Option, CC1AsOption, NoDriverOption]
+let Flags = [CC1Option, CC1AsOption] in {
+
+def darwin_target_variant_triple : Separate<["-"], "darwin-target-variant-triple">,
+ HelpText<"Specify the darwin target variant triple">,
+ MarshallingInfoString<TargetOpts<"DarwinTargetVariantTriple">>,
+ Normalizer<"normalizeTriple">;
+
+} // let Flags = [CC1Option, CC1AsOption]
+
//===----------------------------------------------------------------------===//
// Target Options (cc1 + cc1as + fc1)
//===----------------------------------------------------------------------===//
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index adf1753e8d3a6..a3da1db2f15ef 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -717,6 +717,10 @@ class ToolChain {
return llvm::DenormalMode::getIEEE();
}
+ virtual Optional<llvm::Triple> getTargetVariantTriple() const {
+ return llvm::None;
+ }
+
// We want to expand the shortened versions of the triples passed in to
// the values used for the bitcode libraries.
static llvm::Triple getOpenMPTriple(StringRef TripleStr) {
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 28910d4bd4321..ddc9559f0d950 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7721,6 +7721,8 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
const std::string &TripleStr = Triple.getTriple();
+ const Optional<llvm::Triple> TargetVariantTriple =
+ getToolChain().getTargetVariantTriple();
const auto &D = getToolChain().getDriver();
// Don't warn about "clang -w -c foo.s"
@@ -7738,6 +7740,10 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
// Add the "effective" target triple.
CmdArgs.push_back("-triple");
CmdArgs.push_back(Args.MakeArgString(TripleStr));
+ if (TargetVariantTriple) {
+ CmdArgs.push_back("-darwin-target-variant-triple");
+ CmdArgs.push_back(Args.MakeArgString(TargetVariantTriple->getTriple()));
+ }
// Set the output mode, we currently only expect to be used as a real
// assembler.
diff --git a/clang/lib/Driver/ToolChains/Darwin.h b/clang/lib/Driver/ToolChains/Darwin.h
index a5f8e45640b5a..a622024b79930 100644
--- a/clang/lib/Driver/ToolChains/Darwin.h
+++ b/clang/lib/Driver/ToolChains/Darwin.h
@@ -489,6 +489,12 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
: TargetVersion) < VersionTuple(V0, V1, V2);
}
+ /// Returns the darwin target variant triple, the variant of the deployment
+ /// target for which the code is being compiled.
+ Optional<llvm::Triple> getTargetVariantTriple() const override {
+ return TargetVariantTriple;
+ }
+
protected:
/// Return true if c++17 aligned allocation/deallocation functions are not
/// implemented in the c++ standard library of the deployment target we are
diff --git a/clang/test/Misc/cc1as-darwin-target-variant-triple.s b/clang/test/Misc/cc1as-darwin-target-variant-triple.s
new file mode 100644
index 0000000000000..b30e5e52c1ef2
--- /dev/null
+++ b/clang/test/Misc/cc1as-darwin-target-variant-triple.s
@@ -0,0 +1,34 @@
+// Run cc1as using darwin-target-variant-triple
+// REQUIRES: x86-registered-target
+// RUN: %clang -cc1as -triple x86_64-apple-macos10.9 -darwin-target-variant-triple x86_64-apple-ios13.1-macabi -filetype obj %s -o - \
+// RUN: | llvm-readobj --file-headers --macho-version-min - \
+// RUN: | FileCheck --check-prefix=CHECK %s
+
+// CHECK: File: <stdin>
+// CHECK-NEXT: Format: Mach-O 64-bit x86-64
+// CHECK-NEXT: Arch: x86_64
+// CHECK-NEXT: AddressSize: 64bit
+// CHECK-NEXT: MachHeader {
+// CHECK-NEXT: Magic: Magic64 (0xFEEDFACF)
+// CHECK-NEXT: CpuType: X86-64 (0x1000007)
+// CHECK-NEXT: CpuSubType: CPU_SUBTYPE_X86_64_ALL (0x3)
+// CHECK-NEXT: FileType: Relocatable (0x1)
+// CHECK-NEXT: NumOfLoadCommands: 3
+// CHECK-NEXT: SizeOfLoadCommands: 192
+// CHECK-NEXT: Flags [ (0x0)
+// CHECK-NEXT: ]
+// CHECK-NEXT: Reserved: 0x0
+// CHECK-NEXT: }
+// CHECK-NEXT: MinVersion {
+// CHECK-NEXT: Cmd: LC_VERSION_MIN_MACOSX
+// CHECK-NEXT: Size: 16
+// CHECK-NEXT: Version: 10.9
+// CHECK-NEXT: SDK: n/a
+// CHECK-NEXT: }
+// CHECK-NEXT: MinVersion {
+// CHECK-NEXT: Cmd: LC_BUILD_VERSION
+// CHECK-NEXT: Size: 24
+// CHECK-NEXT: Platform: macCatalyst
+// CHECK-NEXT: Version: 13.1
+// CHECK-NEXT: SDK: n/a
+// CHECK-NEXT: }
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index 26b4eb27a290a..f1531669709aa 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -144,6 +144,9 @@ struct AssemblerInvocation {
/// otherwise.
std::string TargetABI;
+ /// Darwin target variant triple, the variant of the deployment target
+ /// for which the code is being compiled.
+ llvm::Optional<llvm::Triple> DarwinTargetVariantTriple;
/// @}
public:
@@ -209,6 +212,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
// Target Options
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
+ if (Arg *A = Args.getLastArg(options::OPT_darwin_target_variant_triple))
+ Opts.DarwinTargetVariantTriple = llvm::Triple(A->getValue());
+
Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu));
Opts.Features = Args.getAllArgValues(OPT_target_feature);
@@ -407,6 +413,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
std::unique_ptr<MCObjectFileInfo> MOFI(
TheTarget->createMCObjectFileInfo(Ctx, PIC));
+ if (Opts.DarwinTargetVariantTriple)
+ MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
Ctx.setObjectFileInfo(MOFI.get());
if (Opts.SaveTemporaryLabels)
More information about the cfe-commits
mailing list