forked from OSchip/llvm-project
[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
This commit is contained in:
parent
e1afae0311
commit
f69328049e
|
@ -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)
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -717,6 +717,10 @@ public:
|
|||
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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -489,6 +489,12 @@ public:
|
|||
: 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
|
||||
|
|
|
@ -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: }
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue