diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4832,16 +4832,21 @@ MarshallingInfoString>; 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>, - 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>, + 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 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -717,6 +717,10 @@ return llvm::DenormalMode::getIEEE(); } + virtual Optional getTargetVariantTriple() const { + return llvm::Optional(); + } + // 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 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7754,6 +7754,8 @@ const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); const std::string &TripleStr = Triple.getTriple(); + const Optional TargetVariantTriple = + getToolChain().getTargetVariantTriple(); const auto &D = getToolChain().getDriver(); // Don't warn about "clang -w -c foo.s" @@ -7771,6 +7773,10 @@ // 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 --- a/clang/lib/Driver/ToolChains/Darwin.h +++ b/clang/lib/Driver/ToolChains/Darwin.h @@ -489,6 +489,12 @@ : 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 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/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -144,6 +144,9 @@ /// otherwise. std::string TargetABI; + /// Darwin target variant triple, the variant of the deployment target + /// for which the code is being compiled. + llvm::Optional DarwinTargetVariantTriple; /// @} public: @@ -209,6 +212,11 @@ // Target Options Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); + if (Arg *A = Args.getLastArg(options::OPT_darwin_target_variant_triple)) { + llvm::Triple TVT(A->getValue()); + Opts.DarwinTargetVariantTriple = TVT; + } + Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu)); Opts.Features = Args.getAllArgValues(OPT_target_feature); @@ -407,6 +415,9 @@ // MCObjectFileInfo needs a MCContext reference in order to initialize itself. std::unique_ptr MOFI( TheTarget->createMCObjectFileInfo(Ctx, PIC)); + if (Opts.DarwinTargetVariantTriple) { + MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple); + } Ctx.setObjectFileInfo(MOFI.get()); if (Opts.SaveTemporaryLabels)