15#include "clang/Config/config.h"
21#include "llvm/ADT/StringSwitch.h"
22#include "llvm/Option/ArgList.h"
23#include "llvm/ProfileData/InstrProf.h"
24#include "llvm/Support/Path.h"
25#include "llvm/Support/ScopedPrinter.h"
26#include "llvm/Support/Threading.h"
27#include "llvm/Support/VirtualFileSystem.h"
28#include "llvm/TargetParser/TargetParser.h"
29#include "llvm/TargetParser/Triple.h"
39 return VersionTuple(13, 1);
55 return llvm::StringSwitch<llvm::Triple::ArchType>(Str)
56 .Cases(
"i386",
"i486",
"i486SX",
"i586",
"i686", llvm::Triple::x86)
57 .Cases(
"pentium",
"pentpro",
"pentIIm3",
"pentIIm5",
"pentium4",
59 .Cases(
"x86_64",
"x86_64h", llvm::Triple::x86_64)
61 .Cases(
"arm",
"armv4t",
"armv5",
"armv6",
"armv6m", llvm::Triple::arm)
62 .Cases(
"armv7",
"armv7em",
"armv7k",
"armv7m", llvm::Triple::arm)
63 .Cases(
"armv7s",
"xscale", llvm::Triple::arm)
64 .Cases(
"arm64",
"arm64e", llvm::Triple::aarch64)
65 .Case(
"arm64_32", llvm::Triple::aarch64_32)
66 .Case(
"r600", llvm::Triple::r600)
67 .Case(
"amdgcn", llvm::Triple::amdgcn)
68 .Case(
"nvptx", llvm::Triple::nvptx)
69 .Case(
"nvptx64", llvm::Triple::nvptx64)
70 .Case(
"amdil", llvm::Triple::amdil)
71 .Case(
"spir", llvm::Triple::spir)
72 .Default(llvm::Triple::UnknownArch);
76 const ArgList &Args) {
77 const llvm::Triple::ArchType Arch = getArchTypeForMachOArchName(Str);
78 llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(Str);
80 if (Arch != llvm::Triple::UnknownArch)
83 if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
84 ArchKind == llvm::ARM::ArchKind::ARMV7M ||
85 ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
87 if (
T.getOS() == llvm::Triple::IOS)
88 for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
89 A->ignoreTargetSpecific();
90 if (
T.getOS() == llvm::Triple::WatchOS)
91 for (Arg *A : Args.filtered(options::OPT_mwatchos_version_min_EQ))
92 A->ignoreTargetSpecific();
93 if (
T.getOS() == llvm::Triple::TvOS)
94 for (Arg *A : Args.filtered(options::OPT_mtvos_version_min_EQ))
95 A->ignoreTargetSpecific();
97 T.setOS(llvm::Triple::UnknownOS);
98 T.setObjectFormat(llvm::Triple::MachO);
106 const char *LinkingOutput)
const {
109 ArgStringList CmdArgs;
111 assert(Inputs.size() == 1 &&
"Unexpected number of inputs.");
115 const Action *SourceAction = &JA;
117 assert(!SourceAction->
getInputs().empty() &&
"unexpected root action!");
118 SourceAction = SourceAction->
getInputs()[0];
126 if (Args.hasArg(options::OPT_fno_integrated_as)) {
127 if (!(
T.isMacOSX() &&
T.isMacOSXVersionLT(10, 7)))
128 CmdArgs.push_back(
"-Q");
132 if (SourceAction->
getType() == types::TY_Asm ||
133 SourceAction->
getType() == types::TY_PP_Asm) {
134 if (Args.hasArg(options::OPT_gstabs))
135 CmdArgs.push_back(
"--gstabs");
136 else if (Args.hasArg(options::OPT_g_Group))
137 CmdArgs.push_back(
"-g");
144 if (
T.isX86() || Args.hasArg(options::OPT_force__cpusubtype__ALL))
145 CmdArgs.push_back(
"-force_cpusubtype_ALL");
148 (((Args.hasArg(options::OPT_mkernel) ||
149 Args.hasArg(options::OPT_fapple_kext)) &&
151 Args.hasArg(options::OPT_static)))
152 CmdArgs.push_back(
"-static");
154 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
156 assert(Output.
isFilename() &&
"Unexpected lipo output.");
157 CmdArgs.push_back(
"-o");
160 assert(Input.
isFilename() &&
"Invalid input.");
165 const char *Exec = Args.MakeArgString(
getToolChain().GetProgramPath(
"as"));
167 Exec, CmdArgs, Inputs, Output));
170void darwin::MachOTool::anchor() {}
173 ArgStringList &CmdArgs)
const {
174 StringRef ArchName = getMachOToolChain().getMachOArchName(Args);
177 CmdArgs.push_back(
"-arch");
178 CmdArgs.push_back(Args.MakeArgString(ArchName));
181 if (ArchName ==
"arm")
182 CmdArgs.push_back(
"-force_cpusubtype_ALL");
185bool darwin::Linker::NeedsTempPath(
const InputInfoList &Inputs)
const {
189 for (
const auto &Input : Inputs)
190 if (Input.getType() != types::TY_Object)
204 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
205 if (A->getOption().matches(options::OPT_O0))
207 if (A->getOption().matches(options::OPT_O))
208 return llvm::StringSwitch<bool>(A->getValue())
214 if (!IsLinkerOnlyAction)
219void darwin::Linker::AddLinkArgs(
Compilation &
C,
const ArgList &Args,
220 ArgStringList &CmdArgs,
222 VersionTuple Version,
bool LinkerIsLLD,
223 bool UsePlatformVersion)
const {
224 const Driver &
D = getToolChain().getDriver();
229 if ((Version >= VersionTuple(100) || LinkerIsLLD) &&
230 !Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
231 CmdArgs.push_back(
"-demangle");
233 if (Args.hasArg(options::OPT_rdynamic) &&
234 (Version >= VersionTuple(137) || LinkerIsLLD))
235 CmdArgs.push_back(
"-export_dynamic");
239 if (Args.hasFlag(options::OPT_fapplication_extension,
240 options::OPT_fno_application_extension,
false))
241 CmdArgs.push_back(
"-application_extension");
243 if (
D.isUsingLTO() && (Version >= VersionTuple(116) || LinkerIsLLD) &&
244 NeedsTempPath(Inputs)) {
245 std::string TmpPathName;
254 TmpPathName =
D.GetTemporaryDirectory(
"thinlto");
256 if (!TmpPathName.empty()) {
257 auto *TmpPath =
C.getArgs().MakeArgString(TmpPathName);
258 C.addTempFile(TmpPath);
259 CmdArgs.push_back(
"-object_path_lto");
260 CmdArgs.push_back(TmpPath);
273 if (Version >= VersionTuple(133) && !LinkerIsLLD) {
275 StringRef
P = llvm::sys::path::parent_path(
D.Dir);
277 llvm::sys::path::append(LibLTOPath,
"lib");
278 llvm::sys::path::append(LibLTOPath,
"libLTO.dylib");
279 CmdArgs.push_back(
"-lto_library");
280 CmdArgs.push_back(
C.getArgs().MakeArgString(LibLTOPath));
286 if (Version >= VersionTuple(262) &&
288 CmdArgs.push_back(
"-no_deduplicate");
291 Args.AddAllArgs(CmdArgs, options::OPT_static);
292 if (!Args.hasArg(options::OPT_static))
293 CmdArgs.push_back(
"-dynamic");
294 if (Args.hasArg(options::OPT_fgnu_runtime)) {
299 if (!Args.hasArg(options::OPT_dynamiclib)) {
300 AddMachOArch(Args, CmdArgs);
302 Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL);
304 Args.AddLastArg(CmdArgs, options::OPT_bundle);
305 Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader);
306 Args.AddAllArgs(CmdArgs, options::OPT_client__name);
309 if ((A = Args.getLastArg(options::OPT_compatibility__version)) ||
310 (A = Args.getLastArg(options::OPT_current__version)) ||
311 (A = Args.getLastArg(options::OPT_install__name)))
312 D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args)
315 Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace);
316 Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs);
317 Args.AddLastArg(CmdArgs, options::OPT_private__bundle);
319 CmdArgs.push_back(
"-dylib");
322 if ((A = Args.getLastArg(options::OPT_bundle)) ||
323 (A = Args.getLastArg(options::OPT_bundle__loader)) ||
324 (A = Args.getLastArg(options::OPT_client__name)) ||
325 (A = Args.getLastArg(options::OPT_force__flat__namespace)) ||
326 (A = Args.getLastArg(options::OPT_keep__private__externs)) ||
327 (A = Args.getLastArg(options::OPT_private__bundle)))
328 D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args)
331 Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version,
332 "-dylib_compatibility_version");
333 Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version,
334 "-dylib_current_version");
336 AddMachOArch(Args, CmdArgs);
338 Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name,
339 "-dylib_install_name");
342 Args.AddLastArg(CmdArgs, options::OPT_all__load);
343 Args.AddAllArgs(CmdArgs, options::OPT_allowable__client);
344 Args.AddLastArg(CmdArgs, options::OPT_bind__at__load);
346 Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal);
347 Args.AddLastArg(CmdArgs, options::OPT_dead__strip);
348 Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms);
349 Args.AddAllArgs(CmdArgs, options::OPT_dylib__file);
350 Args.AddLastArg(CmdArgs, options::OPT_dynamic);
351 Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list);
352 Args.AddLastArg(CmdArgs, options::OPT_flat__namespace);
353 Args.AddAllArgs(CmdArgs, options::OPT_force__load);
354 Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names);
355 Args.AddAllArgs(CmdArgs, options::OPT_image__base);
356 Args.AddAllArgs(CmdArgs, options::OPT_init);
359 if (Version >= VersionTuple(520) || LinkerIsLLD || UsePlatformVersion)
364 Args.AddLastArg(CmdArgs, options::OPT_nomultidefs);
365 Args.AddLastArg(CmdArgs, options::OPT_multi__module);
366 Args.AddLastArg(CmdArgs, options::OPT_single__module);
367 Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined);
368 Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused);
371 Args.getLastArg(options::OPT_fpie, options::OPT_fPIE,
372 options::OPT_fno_pie, options::OPT_fno_PIE)) {
373 if (A->getOption().matches(options::OPT_fpie) ||
374 A->getOption().matches(options::OPT_fPIE))
375 CmdArgs.push_back(
"-pie");
377 CmdArgs.push_back(
"-no_pie");
381 if (
C.getDriver().embedBitcodeEnabled()) {
384 CmdArgs.push_back(
"-bitcode_bundle");
386 if (
C.getDriver().embedBitcodeMarkerOnly() &&
387 Version >= VersionTuple(278)) {
388 CmdArgs.push_back(
"-bitcode_process_mode");
389 CmdArgs.push_back(
"marker");
392 D.Diag(diag::err_drv_bitcode_unsupported_on_toolchain);
396 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
397 options::OPT_fno_global_isel)) {
398 if (A->getOption().matches(options::OPT_fglobal_isel)) {
399 CmdArgs.push_back(
"-mllvm");
400 CmdArgs.push_back(
"-global-isel");
402 CmdArgs.push_back(
"-mllvm");
403 CmdArgs.push_back(
"-global-isel-abort=0");
407 if (Args.hasArg(options::OPT_mkernel) ||
408 Args.hasArg(options::OPT_fapple_kext) ||
409 Args.hasArg(options::OPT_ffreestanding)) {
410 CmdArgs.push_back(
"-mllvm");
411 CmdArgs.push_back(
"-disable-atexit-based-global-dtor-lowering");
414 Args.AddLastArg(CmdArgs, options::OPT_prebind);
415 Args.AddLastArg(CmdArgs, options::OPT_noprebind);
416 Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding);
417 Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules);
418 Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs);
419 Args.AddAllArgs(CmdArgs, options::OPT_sectcreate);
420 Args.AddAllArgs(CmdArgs, options::OPT_sectorder);
421 Args.AddAllArgs(CmdArgs, options::OPT_seg1addr);
422 Args.AddAllArgs(CmdArgs, options::OPT_segprot);
423 Args.AddAllArgs(CmdArgs, options::OPT_segaddr);
424 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr);
425 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr);
426 Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table);
427 Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename);
428 Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
429 Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
433 StringRef sysroot =
C.getSysRoot();
435 CmdArgs.push_back(
"-syslibroot");
436 CmdArgs.push_back(
C.getArgs().MakeArgString(sysroot));
437 }
else if (
const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
438 CmdArgs.push_back(
"-syslibroot");
439 CmdArgs.push_back(A->getValue());
442 Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);
443 Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints);
444 Args.AddAllArgs(CmdArgs, options::OPT_umbrella);
445 Args.AddAllArgs(CmdArgs, options::OPT_undefined);
446 Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list);
447 Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches);
448 Args.AddLastArg(CmdArgs, options::OPT_X_Flag);
449 Args.AddAllArgs(CmdArgs, options::OPT_y);
450 Args.AddLastArg(CmdArgs, options::OPT_w);
451 Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size);
452 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__);
453 Args.AddLastArg(CmdArgs, options::OPT_seglinkedit);
454 Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit);
455 Args.AddAllArgs(CmdArgs, options::OPT_sectalign);
456 Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols);
457 Args.AddAllArgs(CmdArgs, options::OPT_segcreate);
458 Args.AddLastArg(CmdArgs, options::OPT_why_load);
459 Args.AddLastArg(CmdArgs, options::OPT_whatsloaded);
460 Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name);
461 Args.AddLastArg(CmdArgs, options::OPT_dylinker);
462 Args.AddLastArg(CmdArgs, options::OPT_Mach);
468 : CSPGOGenerateArg->getValue());
469 llvm::sys::path::append(
Path,
"default_%m.profraw");
470 CmdArgs.push_back(
"--cs-profile-generate");
471 CmdArgs.push_back(Args.MakeArgString(Twine(
"--cs-profile-path=") +
Path));
474 ProfileUseArg->getNumValues() == 0 ?
"" : ProfileUseArg->getValue());
475 if (
Path.empty() || llvm::sys::fs::is_directory(
Path))
476 llvm::sys::path::append(
Path,
"default.profdata");
477 CmdArgs.push_back(Args.MakeArgString(Twine(
"--cs-profile-path=") +
Path));
485 Args.ClaimAllArgs(options::OPT_fobjc_link_runtime);
488 return Args.hasArg(options::OPT_fobjc_link_runtime);
492 const llvm::Triple &Triple) {
497 Args.getAllArgValues(options::OPT_arch).size() > 1;
498 bool hasExplicitOutputFile =
499 Args.getLastArg(options::OPT_foptimization_record_file_EQ);
501 D.Diag(diag::err_drv_invalid_output_with_multiple_archs)
502 <<
"-foptimization-record-file";
509 const llvm::Triple &Triple,
511 StringRef Format =
"yaml";
512 if (
const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
513 Format = A->getValue();
515 CmdArgs.push_back(
"-mllvm");
516 CmdArgs.push_back(
"-lto-pass-remarks-output");
517 CmdArgs.push_back(
"-mllvm");
519 const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
521 CmdArgs.push_back(A->getValue());
523 assert(Output.
isFilename() &&
"Unexpected ld output.");
529 CmdArgs.push_back(Args.MakeArgString(F));
533 Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
534 CmdArgs.push_back(
"-mllvm");
536 std::string(
"-lto-pass-remarks-filter=") + A->getValue();
537 CmdArgs.push_back(Args.MakeArgString(Passes));
540 if (!Format.empty()) {
541 CmdArgs.push_back(
"-mllvm");
542 Twine FormatArg = Twine(
"-lto-pass-remarks-format=") + Format;
543 CmdArgs.push_back(Args.MakeArgString(FormatArg));
547 CmdArgs.push_back(
"-mllvm");
548 CmdArgs.push_back(
"-lto-pass-remarks-with-hotness");
551 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) {
552 CmdArgs.push_back(
"-mllvm");
554 std::string(
"-lto-pass-remarks-hotness-threshold=") + A->getValue();
555 CmdArgs.push_back(Args.MakeArgString(Opt));
566 const char *LinkingOutput)
const {
567 assert(Output.
getType() == types::TY_Image &&
"Invalid linker output type.");
573 llvm::opt::ArgStringList InputFileList;
578 ArgStringList CmdArgs;
581 if (Args.hasArg(options::OPT_ccc_arcmt_check,
582 options::OPT_ccc_arcmt_migrate)) {
583 for (
const auto &Arg : Args)
586 Args.MakeArgString(getToolChain().GetProgramPath(
"touch"));
588 C.addCommand(std::make_unique<Command>(JA, *
this,
590 CmdArgs, std::nullopt, Output));
594 VersionTuple Version = getMachOToolChain().getLinkerVersion(Args);
598 Args.MakeArgString(getToolChain().GetLinkerPath(&LinkerIsLLD));
601 bool UsePlatformVersion = getToolChain().getTriple().isXROS();
605 AddLinkArgs(
C, Args, CmdArgs, Inputs, Version, LinkerIsLLD,
610 getToolChain().getTriple()))
615 Args.getLastArg(options::OPT_moutline, options::OPT_mno_outline)) {
616 if (A->getOption().matches(options::OPT_moutline)) {
617 if (getMachOToolChain().getMachOArchName(Args) ==
"arm64") {
618 CmdArgs.push_back(
"-mllvm");
619 CmdArgs.push_back(
"-enable-machine-outliner");
625 CmdArgs.push_back(
"-mllvm");
626 CmdArgs.push_back(
"-enable-machine-outliner=never");
633 CmdArgs.push_back(
"-mllvm");
634 CmdArgs.push_back(
"-enable-linkonceodr-outlining");
639 if (!StatsFile.empty()) {
640 CmdArgs.push_back(
"-mllvm");
641 CmdArgs.push_back(Args.MakeArgString(
"-lto-stats-file=" + StatsFile.str()));
646 Args.addAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
647 options::OPT_Z_Flag, options::OPT_u_Group});
652 if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX))
653 CmdArgs.push_back(
"-ObjC");
655 CmdArgs.push_back(
"-o");
658 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
659 getMachOToolChain().addStartObjectFileArgs(Args, CmdArgs);
661 Args.AddAllArgs(CmdArgs, options::OPT_L);
666 for (
const auto &II : Inputs) {
667 if (!II.isFilename()) {
672 if (InputFileList.size() > 0)
678 InputFileList.push_back(II.getFilename());
683 if (getToolChain().getDriver().IsFlangMode()) {
688 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
692 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
694 getMachOToolChain().AddLinkARCArgs(Args, CmdArgs);
696 CmdArgs.push_back(
"-framework");
697 CmdArgs.push_back(
"Foundation");
699 CmdArgs.push_back(
"-lobjc");
703 CmdArgs.push_back(
"-arch_multiple");
704 CmdArgs.push_back(
"-final_output");
705 CmdArgs.push_back(LinkingOutput);
708 if (Args.hasArg(options::OPT_fnested_functions))
709 CmdArgs.push_back(
"-allow_stack_execute");
711 getMachOToolChain().addProfileRTLibs(Args, CmdArgs);
714 if (!Parallelism.empty()) {
715 CmdArgs.push_back(
"-mllvm");
716 unsigned NumThreads =
717 llvm::get_threadpool_strategy(Parallelism)->compute_thread_count();
718 CmdArgs.push_back(Args.MakeArgString(
"-threads=" + Twine(NumThreads)));
721 if (getToolChain().ShouldLinkCXXStdlib(Args))
722 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
724 bool NoStdOrDefaultLibs =
725 Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs);
726 bool ForceLinkBuiltins = Args.hasArg(options::OPT_fapple_link_rtlib);
727 if (!NoStdOrDefaultLibs || ForceLinkBuiltins) {
732 if (NoStdOrDefaultLibs && ForceLinkBuiltins) {
733 getMachOToolChain().AddLinkRuntimeLib(Args, CmdArgs,
"builtins");
736 getMachOToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs,
740 Args.ClaimAllArgs(options::OPT_pthread);
741 Args.ClaimAllArgs(options::OPT_pthreads);
745 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
749 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
750 Args.AddAllArgs(CmdArgs, options::OPT_F);
753 for (
const Arg *A : Args.filtered(options::OPT_iframework))
754 CmdArgs.push_back(Args.MakeArgString(std::string(
"-F") + A->getValue()));
756 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
757 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
758 if (A->getValue() == StringRef(
"Accelerate")) {
759 CmdArgs.push_back(
"-framework");
760 CmdArgs.push_back(
"Accelerate");
769 bool NonStandardSearchPath =
false;
770 const auto &Triple = getToolChain().getTriple();
771 if (Triple.isDriverKit()) {
773 NonStandardSearchPath =
774 Version.getMajor() < 605 ||
775 (Version.getMajor() == 605 && Version.getMinor().value_or(0) < 1);
778 if (NonStandardSearchPath) {
779 if (
auto *Sysroot = Args.getLastArg(options::OPT_isysroot)) {
780 auto AddSearchPath = [&](StringRef Flag, StringRef SearchPath) {
783 llvm::sys::path::append(
P, SearchPath);
784 if (getToolChain().getVFS().exists(
P)) {
785 CmdArgs.push_back(Args.MakeArgString(Flag +
P));
788 AddSearchPath(
"-L",
"/usr/lib");
789 AddSearchPath(
"-F",
"/System/Library/Frameworks");
795 if (Version >= VersionTuple(705) || LinkerIsLLD) {
803 std::unique_ptr<Command>
Cmd = std::make_unique<Command>(
804 JA, *
this, ResponseSupport, Exec, CmdArgs, Inputs, Output);
805 Cmd->setInputFileList(std::move(InputFileList));
806 C.addCommand(std::move(
Cmd));
813 const char *LinkingOutput)
const {
814 const Driver &
D = getToolChain().getDriver();
817 Args.ClaimAllArgs(options::OPT_g_Group);
819 Args.ClaimAllArgs(options::OPT_emit_llvm);
822 Args.ClaimAllArgs(options::OPT_w);
824 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
827 ArgStringList CmdArgs;
829 CmdArgs.push_back(
"-static");
830 CmdArgs.push_back(
"-D");
831 CmdArgs.push_back(
"-no_warning_for_no_symbols");
832 CmdArgs.push_back(
"-o");
835 for (
const auto &II : Inputs) {
836 if (II.isFilename()) {
837 CmdArgs.push_back(II.getFilename());
844 if (Output.
isFilename() && llvm::sys::fs::exists(OutputFileName)) {
845 if (std::error_code EC = llvm::sys::fs::remove(OutputFileName)) {
846 D.Diag(diag::err_drv_unable_to_remove_file) << EC.message();
851 const char *Exec = Args.MakeArgString(getToolChain().GetStaticLibToolPath());
852 C.addCommand(std::make_unique<Command>(JA, *
this,
854 Exec, CmdArgs, Inputs, Output));
861 const char *LinkingOutput)
const {
862 ArgStringList CmdArgs;
864 CmdArgs.push_back(
"-create");
865 assert(Output.
isFilename() &&
"Unexpected lipo output.");
867 CmdArgs.push_back(
"-output");
870 for (
const auto &II : Inputs) {
871 assert(II.isFilename() &&
"Unexpected lipo input.");
872 CmdArgs.push_back(II.getFilename());
875 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(
"lipo"));
877 Exec, CmdArgs, Inputs, Output));
884 const char *LinkingOutput)
const {
885 ArgStringList CmdArgs;
887 CmdArgs.push_back(
"-o");
890 assert(Inputs.size() == 1 &&
"Unable to handle multiple inputs.");
892 assert(Input.
isFilename() &&
"Unexpected dsymutil input.");
896 Args.MakeArgString(getToolChain().GetProgramPath(
"dsymutil"));
898 Exec, CmdArgs, Inputs, Output));
905 const char *LinkingOutput)
const {
906 ArgStringList CmdArgs;
907 CmdArgs.push_back(
"--verify");
908 CmdArgs.push_back(
"--debug-info");
909 CmdArgs.push_back(
"--eh-frame");
910 CmdArgs.push_back(
"--quiet");
912 assert(Inputs.size() == 1 &&
"Unable to handle multiple inputs.");
914 assert(Input.
isFilename() &&
"Unexpected verify input");
920 Args.MakeArgString(getToolChain().GetProgramPath(
"dwarfdump"));
922 Exec, CmdArgs, Inputs, Output));
933 :
MachO(
D, Triple, Args), TargetInitialized(
false),
934 CudaInstallation(
D, Triple, Args), RocmInstallation(
D, Triple, Args) {}
940 if (Ty == types::TY_PP_Asm)
941 return types::TY_Asm;
961 auto T = llvm::Triple(Twine(
"arm64-apple-") +
962 llvm::Triple::getOSTypeName(llvm::Triple::XROS) +
984 ArgStringList &CC1Args)
const {
989 ArgStringList &CC1Args)
const {
998 return llvm::StringSwitch<const char *>(Arch)
999 .Case(
"armv6k",
"armv6")
1000 .Case(
"armv6m",
"armv6m")
1001 .Case(
"armv5tej",
"armv5")
1002 .Case(
"xscale",
"xscale")
1003 .Case(
"armv4t",
"armv4t")
1004 .Case(
"armv7",
"armv7")
1005 .Cases(
"armv7a",
"armv7-a",
"armv7")
1006 .Cases(
"armv7r",
"armv7-r",
"armv7")
1007 .Cases(
"armv7em",
"armv7e-m",
"armv7em")
1008 .Cases(
"armv7k",
"armv7-k",
"armv7k")
1009 .Cases(
"armv7m",
"armv7-m",
"armv7m")
1010 .Cases(
"armv7s",
"armv7-s",
"armv7s")
1015 llvm::ARM::ArchKind ArchKind = llvm::ARM::parseCPUArch(CPU);
1016 if (ArchKind == llvm::ARM::ArchKind::INVALID)
1018 StringRef Arch = llvm::ARM::getArchName(ArchKind);
1022 if (Arch.starts_with(
"armv5"))
1023 Arch = Arch.substr(0, 5);
1025 else if (Arch.starts_with(
"armv6") && !Arch.ends_with(
"6m"))
1026 Arch = Arch.substr(0, 5);
1028 else if (Arch.ends_with(
"v7a"))
1029 Arch = Arch.substr(0, 5);
1038 case llvm::Triple::aarch64_32:
1041 case llvm::Triple::aarch64: {
1047 case llvm::Triple::thumb:
1048 case llvm::Triple::arm:
1049 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ))
1053 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
1062 if (LinkerVersion) {
1064 VersionTuple NewLinkerVersion;
1065 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ))
1066 (void)NewLinkerVersion.tryParse(A->getValue());
1067 assert(NewLinkerVersion == LinkerVersion);
1069 return *LinkerVersion;
1072 VersionTuple NewLinkerVersion;
1073 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ))
1074 if (NewLinkerVersion.tryParse(A->getValue()))
1076 << A->getAsString(Args);
1078 LinkerVersion = NewLinkerVersion;
1079 return *LinkerVersion;
1093 return Triple.getTriple();
1105 Str += llvm::Triple::getOSTypeName(llvm::Triple::XROS);
1109 Triple.setOSName(Str);
1111 return Triple.getTriple();
1123 return Dsymutil.get();
1127 return VerifyDebug.get();
1144 const ArgList &Args)
1149 CC1Args.push_back(
"-Wundef-prefix=TARGET_OS_");
1150 CC1Args.push_back(
"-Werror=undef-prefix");
1156 CC1Args.push_back(
"-Wdeprecated-objc-isa-usage");
1157 CC1Args.push_back(
"-Werror=deprecated-objc-isa-usage");
1162 CC1Args.push_back(
"-Werror=implicit-function-declaration");
1170 static constexpr llvm::StringLiteral XcodeAppSuffix(
1171 ".app/Contents/Developer");
1172 size_t Index = PathIntoXcode.find(XcodeAppSuffix);
1173 if (Index == StringRef::npos)
1175 return PathIntoXcode.take_front(Index + XcodeAppSuffix.size());
1179 ArgStringList &CmdArgs)
const {
1198 llvm::sys::path::remove_filename(
P);
1199 llvm::sys::path::remove_filename(
P);
1200 llvm::sys::path::append(
P,
"lib",
"arc");
1207 auto updatePath = [&](
const Arg *A) {
1211 if (XcodePathForSDK.empty())
1214 P = XcodePathForSDK;
1215 llvm::sys::path::append(
P,
"Toolchains/XcodeDefault.xctoolchain/usr",
1220 bool updated =
false;
1221 if (
const Arg *A = Args.getLastArg(options::OPT_isysroot))
1222 updated = updatePath(A);
1225 if (
const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
1230 CmdArgs.push_back(
"-force_load");
1231 llvm::sys::path::append(
P,
"libarclite_");
1234 P +=
"watchsimulator";
1238 P +=
"appletvsimulator";
1242 P +=
"iphonesimulator";
1250 getDriver().
Diag(clang::diag::err_drv_darwin_sdk_missing_arclite) <<
P;
1252 CmdArgs.push_back(Args.MakeArgString(
P));
1274 bool IsShared)
const {
1282 const char *LibArg = Args.MakeArgString(
P);
1283 CmdArgs.push_back(LibArg);
1291 assert(StringRef(
P).ends_with(
".dylib") &&
"must be a dynamic library");
1295 CmdArgs.push_back(
"-rpath");
1296 CmdArgs.push_back(
"@executable_path");
1300 CmdArgs.push_back(
"-rpath");
1301 CmdArgs.push_back(Args.MakeArgString(llvm::sys::path::parent_path(
P)));
1308 "it doesn't make sense to ask for the compiler-rt library name as an "
1312 if (Component !=
"builtins") {
1313 MachOLibName +=
'.';
1314 MachOLibName += Component;
1319 llvm::sys::path::append(FullPath,
"lib",
"darwin",
"macho_embedded",
1321 return std::string(FullPath);
1327 "it doesn't make sense to ask for the compiler-rt library name as an "
1331 if (Component !=
"builtins") {
1332 DarwinLibName += Component;
1333 DarwinLibName +=
'_';
1339 llvm::sys::path::append(FullPath,
"lib",
"darwin", DarwinLibName);
1340 return std::string(FullPath);
1360 llvm_unreachable(
"Unsupported platform");
1365 auto BeginSDK = llvm::sys::path::rbegin(isysroot);
1366 auto EndSDK = llvm::sys::path::rend(isysroot);
1367 for (
auto IT = BeginSDK; IT != EndSDK; ++IT) {
1368 StringRef SDK = *IT;
1369 if (SDK.ends_with(
".sdk"))
1370 return SDK.slice(0, SDK.size() - 4);
1396 llvm_unreachable(
"Unsupported platform");
1401 for (Arg *A : Args) {
1402 if (A->getOption().matches(options::OPT_exported__symbols__list))
1404 if (!A->getOption().matches(options::OPT_Wl_COMMA) &&
1405 !A->getOption().matches(options::OPT_Xlinker))
1407 if (A->containsValue(
"-exported_symbols_list") ||
1408 A->containsValue(
"-exported_symbol"))
1416 CmdArgs.push_back(
"-exported_symbol");
1417 CmdArgs.push_back(Symbol);
1427 StringRef Segment, StringRef Section) {
1428 for (
const char *A : {
"-sectalign", Args.MakeArgString(Segment),
1429 Args.MakeArgString(Section),
"0x4000"})
1430 CmdArgs.push_back(A);
1434 ArgStringList &CmdArgs)
const {
1463 for (
auto IPSK : {llvm::IPSK_cnts, llvm::IPSK_bitmap, llvm::IPSK_data}) {
1465 Args, CmdArgs,
"__DATA",
1466 llvm::getInstrProfSectionName(IPSK, llvm::Triple::MachO,
1472void DarwinClang::AddLinkSanitizerLibArgs(
const ArgList &Args,
1473 ArgStringList &CmdArgs,
1474 StringRef Sanitizer,
1475 bool Shared)
const {
1481 const ArgList &Args)
const {
1482 if (Arg* A = Args.getLastArg(options::OPT_rtlib_EQ)) {
1483 StringRef
Value = A->getValue();
1484 if (
Value !=
"compiler-rt" &&
Value !=
"platform")
1485 getDriver().
Diag(clang::diag::err_drv_unsupported_rtlib_for_platform)
1486 <<
Value <<
"darwin";
1493 ArgStringList &CmdArgs,
1494 bool ForceLinkBuiltinRT)
const {
1500 if (Args.hasArg(options::OPT_static) ||
1501 Args.hasArg(options::OPT_fapple_kext) ||
1502 Args.hasArg(options::OPT_mkernel)) {
1503 if (ForceLinkBuiltinRT)
1511 if (
const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
1512 getDriver().
Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args);
1519 const char *sanitizer =
nullptr;
1521 sanitizer =
"UndefinedBehaviorSanitizer";
1523 sanitizer =
"AddressSanitizer";
1525 sanitizer =
"ThreadSanitizer";
1528 getDriver().
Diag(diag::err_drv_unsupported_static_sanitizer_darwin)
1537 AddLinkSanitizerLibArgs(Args, CmdArgs,
"asan_abi",
false);
1540 "Static sanitizer runtimes not supported");
1541 AddLinkSanitizerLibArgs(Args, CmdArgs,
"asan");
1545 AddLinkSanitizerLibArgs(Args, CmdArgs,
"lsan");
1548 "Static sanitizer runtimes not supported");
1549 AddLinkSanitizerLibArgs(
1555 "Static sanitizer runtimes not supported");
1556 AddLinkSanitizerLibArgs(Args, CmdArgs,
"tsan");
1558 if (Sanitize.
needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
1559 AddLinkSanitizerLibArgs(Args, CmdArgs,
"fuzzer",
false);
1566 AddLinkSanitizerLibArgs(Args, CmdArgs,
"stats");
1578 CmdArgs.push_back(
"-framework");
1579 CmdArgs.push_back(
"DriverKit");
1585 CmdArgs.push_back(
"-lSystem");
1594 CmdArgs.push_back(
"-lgcc_s.1");
1604 llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
1605 if (!SystemTriple.isMacOSX())
1606 return std::string(MacOSSDKVersion);
1607 VersionTuple SystemVersion;
1608 SystemTriple.getMacOSXVersion(SystemVersion);
1610 unsigned Major, Minor, Micro;
1614 return std::string(MacOSSDKVersion);
1615 VersionTuple SDKVersion(Major, Minor, Micro);
1617 if (SDKVersion > SystemVersion)
1618 return SystemVersion.getAsString();
1619 return std::string(MacOSSDKVersion);
1625struct DarwinPlatform {
1634 DeploymentTargetEnv,
1644 DarwinPlatformKind getPlatform()
const {
return Platform; }
1646 DarwinEnvironmentKind getEnvironment()
const {
return Environment; }
1648 void setEnvironment(DarwinEnvironmentKind
Kind) {
1650 InferSimulatorFromArch =
false;
1653 StringRef getOSVersion()
const {
1654 if (
Kind == OSVersionArg)
1655 return Argument->getValue();
1659 void setOSVersion(StringRef S) {
1660 assert(
Kind == TargetArg &&
"Unexpected kind!");
1661 OSVersion = std::string(S);
1664 bool hasOSVersion()
const {
return HasOSVersion; }
1666 VersionTuple getNativeTargetVersion()
const {
1667 assert(Environment == DarwinEnvironmentKind::MacCatalyst &&
1668 "native target version is specified only for Mac Catalyst");
1669 return NativeTargetVersion;
1673 bool isExplicitlySpecified()
const {
return Kind <= DeploymentTargetEnv; }
1676 bool canInferSimulatorFromArch()
const {
return InferSimulatorFromArch; }
1678 const std::optional<llvm::Triple> &getTargetVariantTriple()
const {
1679 return TargetVariantTriple;
1683 void addOSVersionMinArgument(DerivedArgList &Args,
const OptTable &Opts) {
1686 assert(
Kind != TargetArg &&
Kind != MTargetOSArg &&
Kind != OSVersionArg &&
1690 case DarwinPlatformKind::MacOS:
1691 Opt = options::OPT_mmacos_version_min_EQ;
1693 case DarwinPlatformKind::IPhoneOS:
1694 Opt = options::OPT_mios_version_min_EQ;
1696 case DarwinPlatformKind::TvOS:
1697 Opt = options::OPT_mtvos_version_min_EQ;
1699 case DarwinPlatformKind::WatchOS:
1700 Opt = options::OPT_mwatchos_version_min_EQ;
1702 case DarwinPlatformKind::XROS:
1705 case DarwinPlatformKind::DriverKit:
1709 Argument = Args.MakeJoinedArg(
nullptr, Opts.getOption(Opt), OSVersion);
1710 Args.append(Argument);
1715 std::string
getAsString(DerivedArgList &Args,
const OptTable &Opts) {
1720 case InferredFromSDK:
1721 case InferredFromArch:
1722 assert(Argument &&
"OS version argument not yet inferred");
1723 return Argument->getAsString(Args);
1724 case DeploymentTargetEnv:
1725 return (llvm::Twine(EnvVarName) +
"=" + OSVersion).str();
1727 llvm_unreachable(
"Unsupported Darwin Source Kind");
1730 void setEnvironment(llvm::Triple::EnvironmentType EnvType,
1731 const VersionTuple &OSVersion,
1732 const std::optional<DarwinSDKInfo> &SDKInfo) {
1734 case llvm::Triple::Simulator:
1735 Environment = DarwinEnvironmentKind::Simulator;
1737 case llvm::Triple::MacABI: {
1738 Environment = DarwinEnvironmentKind::MacCatalyst;
1740 NativeTargetVersion = VersionTuple(10, 15);
1741 if (HasOSVersion && SDKInfo) {
1742 if (
const auto *MacCatalystToMacOSMapping = SDKInfo->getVersionMapping(
1744 if (
auto MacOSVersion = MacCatalystToMacOSMapping->map(
1745 OSVersion, NativeTargetVersion, std::nullopt)) {
1746 NativeTargetVersion = *MacOSVersion;
1753 if (TargetVariantTriple) {
1754 auto TargetVariantVersion = TargetVariantTriple->getOSVersion();
1755 if (TargetVariantVersion.getMajor()) {
1756 if (TargetVariantVersion < NativeTargetVersion)
1757 NativeTargetVersion = TargetVariantVersion;
1767 static DarwinPlatform
1768 createFromTarget(
const llvm::Triple &TT, StringRef OSVersion, Arg *A,
1769 std::optional<llvm::Triple> TargetVariantTriple,
1770 const std::optional<DarwinSDKInfo> &SDKInfo) {
1771 DarwinPlatform Result(TargetArg, getPlatformFromOS(TT.getOS()), OSVersion,
1773 VersionTuple OsVersion = TT.getOSVersion();
1774 if (OsVersion.getMajor() == 0)
1775 Result.HasOSVersion =
false;
1776 Result.TargetVariantTriple = TargetVariantTriple;
1777 Result.setEnvironment(TT.getEnvironment(), OsVersion, SDKInfo);
1780 static DarwinPlatform
1781 createFromMTargetOS(llvm::Triple::OSType OS, VersionTuple OSVersion,
1782 llvm::Triple::EnvironmentType Environment, Arg *A,
1783 const std::optional<DarwinSDKInfo> &SDKInfo) {
1784 DarwinPlatform Result(MTargetOSArg, getPlatformFromOS(OS),
1785 OSVersion.getAsString(), A);
1786 Result.InferSimulatorFromArch =
false;
1787 Result.setEnvironment(Environment, OSVersion, SDKInfo);
1790 static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform, Arg *A,
1792 DarwinPlatform Result{OSVersionArg, Platform, A};
1794 Result.Environment = DarwinEnvironmentKind::Simulator;
1797 static DarwinPlatform createDeploymentTargetEnv(DarwinPlatformKind Platform,
1798 StringRef EnvVarName,
1800 DarwinPlatform Result(DeploymentTargetEnv, Platform,
Value);
1801 Result.EnvVarName = EnvVarName;
1804 static DarwinPlatform createFromSDK(DarwinPlatformKind Platform,
1806 bool IsSimulator =
false) {
1807 DarwinPlatform Result(InferredFromSDK, Platform,
Value);
1809 Result.Environment = DarwinEnvironmentKind::Simulator;
1810 Result.InferSimulatorFromArch =
false;
1813 static DarwinPlatform createFromArch(llvm::Triple::OSType OS,
1815 return DarwinPlatform(InferredFromArch, getPlatformFromOS(OS),
Value);
1822 assert(
Kind == InferredFromSDK &&
"can infer SDK info only");
1823 llvm::VersionTuple Version;
1824 bool IsValid = !Version.tryParse(OSVersion);
1826 assert(IsValid &&
"invalid SDK version");
1829 VersionTuple(Version.getMajor(), 0, 99));
1833 DarwinPlatform(SourceKind
Kind, DarwinPlatformKind Platform, Arg *Argument)
1834 :
Kind(
Kind), Platform(Platform), Argument(Argument) {}
1835 DarwinPlatform(SourceKind
Kind, DarwinPlatformKind Platform, StringRef
Value,
1836 Arg *Argument =
nullptr)
1837 :
Kind(
Kind), Platform(Platform), OSVersion(
Value), Argument(Argument) {}
1839 static DarwinPlatformKind getPlatformFromOS(llvm::Triple::OSType OS) {
1841 case llvm::Triple::Darwin:
1842 case llvm::Triple::MacOSX:
1843 return DarwinPlatformKind::MacOS;
1844 case llvm::Triple::IOS:
1845 return DarwinPlatformKind::IPhoneOS;
1846 case llvm::Triple::TvOS:
1847 return DarwinPlatformKind::TvOS;
1848 case llvm::Triple::WatchOS:
1849 return DarwinPlatformKind::WatchOS;
1850 case llvm::Triple::XROS:
1851 return DarwinPlatformKind::XROS;
1852 case llvm::Triple::DriverKit:
1853 return DarwinPlatformKind::DriverKit;
1855 llvm_unreachable(
"Unable to infer Darwin variant");
1860 DarwinPlatformKind Platform;
1861 DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
1862 VersionTuple NativeTargetVersion;
1863 std::string OSVersion;
1864 bool HasOSVersion =
true, InferSimulatorFromArch =
true;
1866 StringRef EnvVarName;
1867 std::optional<llvm::Triple> TargetVariantTriple;
1872std::optional<DarwinPlatform>
1873getDeploymentTargetFromOSVersionArg(DerivedArgList &Args,
1874 const Driver &TheDriver) {
1875 Arg *macOSVersion = Args.getLastArg(options::OPT_mmacos_version_min_EQ);
1876 Arg *iOSVersion = Args.getLastArg(options::OPT_mios_version_min_EQ,
1877 options::OPT_mios_simulator_version_min_EQ);
1879 Args.getLastArg(options::OPT_mtvos_version_min_EQ,
1880 options::OPT_mtvos_simulator_version_min_EQ);
1881 Arg *WatchOSVersion =
1882 Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
1883 options::OPT_mwatchos_simulator_version_min_EQ);
1885 if (iOSVersion || TvOSVersion || WatchOSVersion) {
1886 TheDriver.
Diag(diag::err_drv_argument_not_allowed_with)
1887 << macOSVersion->getAsString(Args)
1888 << (iOSVersion ? iOSVersion
1889 : TvOSVersion ? TvOSVersion : WatchOSVersion)
1892 return DarwinPlatform::createOSVersionArg(
Darwin::MacOS, macOSVersion,
1894 }
else if (iOSVersion) {
1895 if (TvOSVersion || WatchOSVersion) {
1896 TheDriver.
Diag(diag::err_drv_argument_not_allowed_with)
1897 << iOSVersion->getAsString(Args)
1898 << (TvOSVersion ? TvOSVersion : WatchOSVersion)->
getAsString(Args);
1900 return DarwinPlatform::createOSVersionArg(
1902 iOSVersion->getOption().getID() ==
1903 options::OPT_mios_simulator_version_min_EQ);
1904 }
else if (TvOSVersion) {
1905 if (WatchOSVersion) {
1906 TheDriver.
Diag(diag::err_drv_argument_not_allowed_with)
1907 << TvOSVersion->getAsString(Args)
1908 << WatchOSVersion->getAsString(Args);
1910 return DarwinPlatform::createOSVersionArg(
1912 TvOSVersion->getOption().getID() ==
1913 options::OPT_mtvos_simulator_version_min_EQ);
1914 }
else if (WatchOSVersion)
1915 return DarwinPlatform::createOSVersionArg(
1917 WatchOSVersion->getOption().getID() ==
1918 options::OPT_mwatchos_simulator_version_min_EQ);
1919 return std::nullopt;
1924std::optional<DarwinPlatform>
1925getDeploymentTargetFromEnvironmentVariables(
const Driver &TheDriver,
1926 const llvm::Triple &Triple) {
1928 const char *EnvVars[] = {
1929 "MACOSX_DEPLOYMENT_TARGET",
1930 "IPHONEOS_DEPLOYMENT_TARGET",
1931 "TVOS_DEPLOYMENT_TARGET",
1932 "WATCHOS_DEPLOYMENT_TARGET",
1933 "DRIVERKIT_DEPLOYMENT_TARGET",
1934 "XROS_DEPLOYMENT_TARGET"
1937 "Missing platform");
1939 if (
char *
Env = ::getenv(I.value()))
1940 Targets[I.index()] =
Env;
1949 if (Triple.getArch() == llvm::Triple::arm ||
1950 Triple.getArch() == llvm::Triple::aarch64 ||
1951 Triple.getArch() == llvm::Triple::thumb)
1958 unsigned FirstTarget = std::size(Targets);
1959 for (
unsigned I = 0; I != std::size(Targets); ++I) {
1960 if (Targets[I].empty())
1962 if (FirstTarget == std::size(Targets))
1965 TheDriver.
Diag(diag::err_drv_conflicting_deployment_targets)
1966 << Targets[FirstTarget] << Targets[I];
1971 if (!
Target.value().empty())
1972 return DarwinPlatform::createDeploymentTargetEnv(
1976 return std::nullopt;
1981static StringRef dropSDKNamePrefix(StringRef SDKName) {
1982 size_t PrefixPos = SDKName.find(
'.');
1983 if (PrefixPos == StringRef::npos)
1985 return SDKName.substr(PrefixPos + 1);
1991std::optional<DarwinPlatform>
1992inferDeploymentTargetFromSDK(DerivedArgList &Args,
1993 const std::optional<DarwinSDKInfo> &SDKInfo) {
1994 const Arg *A = Args.getLastArg(options::OPT_isysroot);
1996 return std::nullopt;
1997 StringRef isysroot = A->getValue();
2000 return std::nullopt;
2002 std::string Version;
2005 Version = SDKInfo->getVersion().getAsString();
2009 size_t StartVer = SDK.find_first_of(
"0123456789");
2010 size_t EndVer = SDK.find_last_of(
"0123456789");
2011 if (StartVer != StringRef::npos && EndVer > StartVer)
2012 Version = std::string(SDK.slice(StartVer, EndVer + 1));
2014 if (Version.empty())
2015 return std::nullopt;
2017 auto CreatePlatformFromSDKName =
2018 [&](StringRef SDK) -> std::optional<DarwinPlatform> {
2019 if (SDK.starts_with(
"iPhoneOS") || SDK.starts_with(
"iPhoneSimulator"))
2020 return DarwinPlatform::createFromSDK(
2022 SDK.starts_with(
"iPhoneSimulator"));
2023 else if (SDK.starts_with(
"MacOSX"))
2026 else if (SDK.starts_with(
"WatchOS") || SDK.starts_with(
"WatchSimulator"))
2027 return DarwinPlatform::createFromSDK(
2029 SDK.starts_with(
"WatchSimulator"));
2030 else if (SDK.starts_with(
"AppleTVOS") ||
2031 SDK.starts_with(
"AppleTVSimulator"))
2032 return DarwinPlatform::createFromSDK(
2034 SDK.starts_with(
"AppleTVSimulator"));
2035 else if (SDK.starts_with(
"XR"))
2036 return DarwinPlatform::createFromSDK(
2038 SDK.contains(
"Simulator"));
2039 else if (SDK.starts_with(
"DriverKit"))
2041 return std::nullopt;
2043 if (
auto Result = CreatePlatformFromSDKName(SDK))
2046 return CreatePlatformFromSDKName(dropSDKNamePrefix(SDK));
2049std::string getOSVersion(llvm::Triple::OSType OS,
const llvm::Triple &Triple,
2050 const Driver &TheDriver) {
2051 VersionTuple OsVersion;
2052 llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
2054 case llvm::Triple::Darwin:
2055 case llvm::Triple::MacOSX:
2058 if (Triple.isMacOSX() && SystemTriple.isMacOSX() &&
2059 !Triple.getOSMajorVersion())
2060 SystemTriple.getMacOSXVersion(OsVersion);
2061 else if (!Triple.getMacOSXVersion(OsVersion))
2062 TheDriver.
Diag(diag::err_drv_invalid_darwin_version)
2063 << Triple.getOSName();
2065 case llvm::Triple::IOS:
2066 if (Triple.isMacCatalystEnvironment() && !Triple.getOSMajorVersion()) {
2067 OsVersion = VersionTuple(13, 1);
2069 OsVersion = Triple.getiOSVersion();
2071 case llvm::Triple::TvOS:
2072 OsVersion = Triple.getOSVersion();
2074 case llvm::Triple::WatchOS:
2075 OsVersion = Triple.getWatchOSVersion();
2077 case llvm::Triple::XROS:
2078 OsVersion = Triple.getOSVersion();
2079 if (!OsVersion.getMajor())
2080 OsVersion = OsVersion.withMajorReplaced(1);
2082 case llvm::Triple::DriverKit:
2083 OsVersion = Triple.getDriverKitVersion();
2086 llvm_unreachable(
"Unexpected OS type");
2090 std::string OSVersion;
2091 llvm::raw_string_ostream(OSVersion)
2092 << OsVersion.getMajor() <<
'.' << OsVersion.getMinor().value_or(0) <<
'.'
2093 << OsVersion.getSubminor().value_or(0);
2098std::optional<DarwinPlatform>
2099inferDeploymentTargetFromArch(DerivedArgList &Args,
const Darwin &Toolchain,
2100 const llvm::Triple &Triple,
2101 const Driver &TheDriver) {
2102 llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS;
2105 if (MachOArchName ==
"arm64" || MachOArchName ==
"arm64e")
2106 OSTy = llvm::Triple::MacOSX;
2107 else if (MachOArchName ==
"armv7" || MachOArchName ==
"armv7s")
2108 OSTy = llvm::Triple::IOS;
2109 else if (MachOArchName ==
"armv7k" || MachOArchName ==
"arm64_32")
2110 OSTy = llvm::Triple::WatchOS;
2111 else if (MachOArchName !=
"armv6m" && MachOArchName !=
"armv7m" &&
2112 MachOArchName !=
"armv7em")
2113 OSTy = llvm::Triple::MacOSX;
2114 if (OSTy == llvm::Triple::UnknownOS)
2115 return std::nullopt;
2116 return DarwinPlatform::createFromArch(OSTy,
2117 getOSVersion(OSTy, Triple, TheDriver));
2121std::optional<DarwinPlatform> getDeploymentTargetFromTargetArg(
2122 DerivedArgList &Args,
const llvm::Triple &Triple,
const Driver &TheDriver,
2123 const std::optional<DarwinSDKInfo> &SDKInfo) {
2124 if (!Args.hasArg(options::OPT_target))
2125 return std::nullopt;
2126 if (Triple.getOS() == llvm::Triple::Darwin ||
2127 Triple.getOS() == llvm::Triple::UnknownOS)
2128 return std::nullopt;
2129 std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
2130 std::optional<llvm::Triple> TargetVariantTriple;
2131 for (
const Arg *A : Args.filtered(options::OPT_darwin_target_variant)) {
2132 llvm::Triple TVT(A->getValue());
2134 if ((Triple.getArch() == llvm::Triple::aarch64 ||
2135 TVT.getArchName() == Triple.getArchName()) &&
2136 TVT.getArch() == Triple.getArch() &&
2137 TVT.getSubArch() == Triple.getSubArch() &&
2138 TVT.getVendor() == Triple.getVendor()) {
2139 if (TargetVariantTriple)
2144 if ((Triple.isMacOSX() && TVT.getOS() == llvm::Triple::IOS &&
2145 TVT.isMacCatalystEnvironment()) ||
2146 (TVT.isMacOSX() && Triple.getOS() == llvm::Triple::IOS &&
2147 Triple.isMacCatalystEnvironment())) {
2148 TargetVariantTriple = TVT;
2151 TheDriver.
Diag(diag::err_drv_target_variant_invalid)
2152 << A->getSpelling() << A->getValue();
2155 return DarwinPlatform::createFromTarget(Triple, OSVersion,
2156 Args.getLastArg(options::OPT_target),
2157 TargetVariantTriple, SDKInfo);
2161std::optional<DarwinPlatform> getDeploymentTargetFromMTargetOSArg(
2162 DerivedArgList &Args,
const Driver &TheDriver,
2163 const std::optional<DarwinSDKInfo> &SDKInfo) {
2164 auto *A = Args.getLastArg(options::OPT_mtargetos_EQ);
2166 return std::nullopt;
2167 llvm::Triple TT(llvm::Twine(
"unknown-apple-") + A->getValue());
2168 switch (TT.getOS()) {
2169 case llvm::Triple::MacOSX:
2170 case llvm::Triple::IOS:
2171 case llvm::Triple::TvOS:
2172 case llvm::Triple::WatchOS:
2173 case llvm::Triple::XROS:
2176 TheDriver.
Diag(diag::err_drv_invalid_os_in_arg)
2177 << TT.getOSName() << A->getAsString(Args);
2178 return std::nullopt;
2181 VersionTuple Version = TT.getOSVersion();
2182 if (!Version.getMajor()) {
2183 TheDriver.
Diag(diag::err_drv_invalid_version_number)
2184 << A->getAsString(Args);
2185 return std::nullopt;
2187 return DarwinPlatform::createFromMTargetOS(TT.getOS(), Version,
2188 TT.getEnvironment(), A, SDKInfo);
2191std::optional<DarwinSDKInfo> parseSDKSettings(llvm::vfs::FileSystem &VFS,
2192 const ArgList &Args,
2193 const Driver &TheDriver) {
2194 const Arg *A = Args.getLastArg(options::OPT_isysroot);
2196 return std::nullopt;
2197 StringRef isysroot = A->getValue();
2199 if (!SDKInfoOrErr) {
2200 llvm::consumeError(SDKInfoOrErr.takeError());
2201 TheDriver.
Diag(diag::warn_drv_darwin_sdk_invalid_settings);
2202 return std::nullopt;
2204 return *SDKInfoOrErr;
2209void Darwin::AddDeploymentTarget(DerivedArgList &Args)
const {
2215 if (
const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
2217 if (!
getVFS().exists(A->getValue()))
2218 getDriver().
Diag(clang::diag::warn_missing_sysroot) << A->getValue();
2220 if (
char *env = ::getenv(
"SDKROOT")) {
2223 if (llvm::sys::path::is_absolute(env) &&
getVFS().exists(env) &&
2224 StringRef(env) !=
"/") {
2225 Args.append(Args.MakeSeparateArg(
2226 nullptr, Opts.getOption(options::OPT_isysroot), env));
2236 std::optional<DarwinPlatform> OSTarget =
2240 if (
const auto *MTargetOSArg = Args.getLastArg(options::OPT_mtargetos_EQ)) {
2241 std::string TargetArgStr = OSTarget->getAsString(Args, Opts);
2242 std::string MTargetOSArgStr = MTargetOSArg->getAsString(Args);
2244 << TargetArgStr << MTargetOSArgStr;
2246 std::optional<DarwinPlatform> OSVersionArgTarget =
2247 getDeploymentTargetFromOSVersionArg(Args,
getDriver());
2248 if (OSVersionArgTarget) {
2249 unsigned TargetMajor, TargetMinor, TargetMicro;
2251 unsigned ArgMajor, ArgMinor, ArgMicro;
2253 if (OSTarget->getPlatform() != OSVersionArgTarget->getPlatform() ||
2255 TargetMinor, TargetMicro, TargetExtra) &&
2257 ArgMajor, ArgMinor, ArgMicro, ArgExtra) &&
2258 (VersionTuple(TargetMajor, TargetMinor, TargetMicro) !=
2259 VersionTuple(ArgMajor, ArgMinor, ArgMicro) ||
2260 TargetExtra != ArgExtra))) {
2263 if (OSTarget->getPlatform() == OSVersionArgTarget->getPlatform() &&
2264 !OSTarget->hasOSVersion()) {
2265 OSTarget->setOSVersion(OSVersionArgTarget->getOSVersion());
2269 std::string OSVersionArg =
2270 OSVersionArgTarget->getAsString(Args, Opts);
2271 std::string TargetArg = OSTarget->getAsString(Args, Opts);
2273 << OSVersionArg << TargetArg;
2277 }
else if ((OSTarget = getDeploymentTargetFromMTargetOSArg(Args,
getDriver(),
2281 std::optional<DarwinPlatform> OSVersionArgTarget =
2282 getDeploymentTargetFromOSVersionArg(Args,
getDriver());
2283 if (OSVersionArgTarget) {
2284 std::string MTargetOSArgStr = OSTarget->getAsString(Args, Opts);
2285 std::string OSVersionArgStr = OSVersionArgTarget->getAsString(Args, Opts);
2287 << MTargetOSArgStr << OSVersionArgStr;
2291 OSTarget = getDeploymentTargetFromOSVersionArg(Args,
getDriver());
2299 std::optional<DarwinPlatform> SDKTarget =
2300 inferDeploymentTargetFromSDK(Args,
SDKInfo);
2302 OSTarget->setEnvironment(SDKTarget->getEnvironment());
2309 OSTarget = inferDeploymentTargetFromSDK(Args,
SDKInfo);
2313 SDKInfo = OSTarget->inferSDKInfo();
2322 assert(OSTarget &&
"Unable to infer Darwin variant");
2323 OSTarget->addOSVersionMinArgument(Args, Opts);
2326 unsigned Major, Minor, Micro;
2329 const unsigned MajorVersionLimit = 1000;
2331 if (Platform ==
MacOS) {
2334 HadExtra || Major < 10 || Major >= MajorVersionLimit || Minor >= 100 ||
2337 << OSTarget->getAsString(Args, Opts);
2341 HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
2343 << OSTarget->getAsString(Args, Opts);
2346 (Major < 13 || (Major == 13 && Minor < 1))) {
2348 << OSTarget->getAsString(Args, Opts);
2355 if (
getTriple().isArch32Bit() && Major >= 11) {
2357 if (OSTarget->isExplicitlySpecified()) {
2359 getDriver().
Diag(diag::err_invalid_macos_32bit_deployment_target);
2362 << OSTarget->getAsString(Args, Opts);
2370 }
else if (Platform ==
TvOS) {
2373 HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
2375 << OSTarget->getAsString(Args, Opts);
2376 }
else if (Platform ==
WatchOS) {
2379 HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
2381 << OSTarget->getAsString(Args, Opts);
2385 HadExtra || Major < 19 || Major >= MajorVersionLimit || Minor >= 100 ||
2388 << OSTarget->getAsString(Args, Opts);
2389 }
else if (Platform ==
XROS) {
2392 HadExtra || Major < 1 || Major >= MajorVersionLimit || Minor >= 100 ||
2395 << OSTarget->getAsString(Args, Opts);
2397 llvm_unreachable(
"unknown kind of Darwin platform");
2402 Platform !=
DriverKit && OSTarget->canInferSimulatorFromArch() &&
2406 VersionTuple NativeTargetVersion;
2408 NativeTargetVersion = OSTarget->getNativeTargetVersion();
2409 setTarget(Platform, Environment, Major, Minor, Micro, NativeTargetVersion);
2412 if (
const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
2414 if (SDK.size() > 0) {
2415 size_t StartVer = SDK.find_first_of(
"0123456789");
2416 StringRef SDKName = SDK.slice(0, StartVer);
2429 const llvm::Triple &
T) {
2430 if (
T.isDriverKit()) {
2431 llvm::sys::path::append(
Path,
"System",
"DriverKit");
2438DarwinClang::GetEffectiveSysroot(
const llvm::opt::ArgList &DriverArgs)
const {
2440 if (DriverArgs.hasArg(options::OPT_isysroot))
2441 Path = DriverArgs.getLastArgValue(options::OPT_isysroot);
2452 llvm::opt::ArgStringList &CC1Args)
const {
2457 bool NoStdInc = DriverArgs.hasArg(options::OPT_nostdinc);
2458 bool NoStdlibInc = DriverArgs.hasArg(options::OPT_nostdlibinc);
2459 bool NoBuiltinInc = DriverArgs.hasFlag(
2460 options::OPT_nobuiltininc, options::OPT_ibuiltininc,
false);
2461 bool ForceBuiltinInc = DriverArgs.hasFlag(
2462 options::OPT_ibuiltininc, options::OPT_nobuiltininc,
false);
2465 if (!NoStdInc && !NoStdlibInc) {
2467 llvm::sys::path::append(
P,
"usr",
"local",
"include");
2472 if (!(NoStdInc && !ForceBuiltinInc) && !NoBuiltinInc) {
2474 llvm::sys::path::append(
P,
"include");
2478 if (NoStdInc || NoStdlibInc)
2482 llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS);
2483 if (!CIncludeDirs.empty()) {
2485 CIncludeDirs.split(dirs,
":");
2486 for (llvm::StringRef dir : dirs) {
2487 llvm::StringRef Prefix =
2488 llvm::sys::path::is_absolute(dir) ?
"" : llvm::StringRef(Sysroot);
2494 llvm::sys::path::append(
P,
"usr",
"include");
2499bool DarwinClang::AddGnuCPlusPlusIncludePaths(
const llvm::opt::ArgList &DriverArgs,
2500 llvm::opt::ArgStringList &CC1Args,
2502 llvm::StringRef Version,
2503 llvm::StringRef ArchDir,
2504 llvm::StringRef BitDir)
const {
2505 llvm::sys::path::append(
Base, Version);
2513 if (!ArchDir.empty())
2514 llvm::sys::path::append(
P, ArchDir);
2515 if (!BitDir.empty())
2516 llvm::sys::path::append(
P, BitDir);
2523 llvm::sys::path::append(
P,
"backward");
2531 const llvm::opt::ArgList &DriverArgs,
2532 llvm::opt::ArgStringList &CC1Args)
const {
2540 if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
2541 options::OPT_nostdincxx))
2562 llvm::sys::path::append(InstallBin,
"..",
"include",
"c++",
"v1");
2563 if (
getVFS().exists(InstallBin)) {
2566 }
else if (DriverArgs.hasArg(options::OPT_v)) {
2567 llvm::errs() <<
"ignoring nonexistent directory \"" << InstallBin
2573 llvm::sys::path::append(SysrootUsr,
"usr",
"include",
"c++",
"v1");
2574 if (
getVFS().exists(SysrootUsr)) {
2577 }
else if (DriverArgs.hasArg(options::OPT_v)) {
2578 llvm::errs() <<
"ignoring nonexistent directory \"" << SysrootUsr
2588 llvm::sys::path::append(UsrIncludeCxx,
"usr",
"include",
"c++");
2591 bool IsBaseFound =
true;
2595 case llvm::Triple::x86:
2596 case llvm::Triple::x86_64:
2597 IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2599 "i686-apple-darwin10",
2600 arch == llvm::Triple::x86_64 ?
"x86_64" :
"");
2601 IsBaseFound |= AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2602 "4.0.0",
"i686-apple-darwin8",
2606 case llvm::Triple::arm:
2607 case llvm::Triple::thumb:
2608 IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2610 "arm-apple-darwin10",
2612 IsBaseFound |= AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2614 "arm-apple-darwin10",
2618 case llvm::Triple::aarch64:
2619 IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2621 "arm64-apple-darwin10",
2635 ArgStringList &CmdArgs)
const {
2640 CmdArgs.push_back(
"-lc++");
2641 if (Args.hasArg(options::OPT_fexperimental_library))
2642 CmdArgs.push_back(
"-lc++experimental");
2652 if (
const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
2654 llvm::sys::path::append(
P,
"usr",
"lib",
"libstdc++.dylib");
2657 llvm::sys::path::remove_filename(
P);
2658 llvm::sys::path::append(
P,
"libstdc++.6.dylib");
2660 CmdArgs.push_back(Args.MakeArgString(
P));
2669 if (!
getVFS().exists(
"/usr/lib/libstdc++.dylib") &&
2670 getVFS().exists(
"/usr/lib/libstdc++.6.dylib")) {
2671 CmdArgs.push_back(
"/usr/lib/libstdc++.6.dylib");
2676 CmdArgs.push_back(
"-lstdc++");
2682 ArgStringList &CmdArgs)
const {
2688 llvm::sys::path::append(
P,
"lib",
"darwin");
2692 llvm::sys::path::append(
P,
"libclang_rt.cc_kext_watchos.a");
2694 llvm::sys::path::append(
P,
"libclang_rt.cc_kext_tvos.a");
2696 llvm::sys::path::append(
P,
"libclang_rt.cc_kext_ios.a");
2700 llvm::sys::path::append(
2701 P, llvm::Twine(
"libclang_rt.cc_kext_") +
2702 llvm::Triple::getOSTypeName(llvm::Triple::XROS) +
".a");
2704 llvm::sys::path::append(
P,
"libclang_rt.cc_kext.a");
2710 CmdArgs.push_back(Args.MakeArgString(
P));
2714 StringRef BoundArch,
2716 DerivedArgList *DAL =
new DerivedArgList(Args.getBaseArgs());
2726 for (Arg *A : Args) {
2727 if (A->getOption().matches(options::OPT_Xarch__)) {
2730 StringRef XarchArch = A->getValue(0);
2732 (!BoundArch.empty() && XarchArch == BoundArch)))
2735 Arg *OriginalArg = A;
2743 for (
const char *
Value : A->getValues()) {
2744 DAL->AddSeparateArg(
2745 OriginalArg, Opts.getOption(options::OPT_Zlinker_input),
Value);
2759 case options::OPT_mkernel:
2760 case options::OPT_fapple_kext:
2762 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
2765 case options::OPT_dependency_file:
2766 DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue());
2769 case options::OPT_gfull:
2770 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
2772 A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols));
2775 case options::OPT_gused:
2776 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
2778 A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols));
2781 case options::OPT_shared:
2782 DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib));
2785 case options::OPT_fconstant_cfstrings:
2786 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings));
2789 case options::OPT_fno_constant_cfstrings:
2790 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings));
2793 case options::OPT_Wnonportable_cfstrings:
2795 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings));
2798 case options::OPT_Wno_nonportable_cfstrings:
2800 A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings));
2807 if (!BoundArch.empty()) {
2808 StringRef Name = BoundArch;
2809 const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ);
2810 const Option MArch = Opts.getOption(clang::driver::options::OPT_march_EQ);
2816 else if (Name ==
"ppc601")
2817 DAL->AddJoinedArg(
nullptr, MCpu,
"601");
2818 else if (Name ==
"ppc603")
2819 DAL->AddJoinedArg(
nullptr, MCpu,
"603");
2820 else if (Name ==
"ppc604")
2821 DAL->AddJoinedArg(
nullptr, MCpu,
"604");
2822 else if (Name ==
"ppc604e")
2823 DAL->AddJoinedArg(
nullptr, MCpu,
"604e");
2824 else if (Name ==
"ppc750")
2825 DAL->AddJoinedArg(
nullptr, MCpu,
"750");
2826 else if (Name ==
"ppc7400")
2827 DAL->AddJoinedArg(
nullptr, MCpu,
"7400");
2828 else if (Name ==
"ppc7450")
2829 DAL->AddJoinedArg(
nullptr, MCpu,
"7450");
2830 else if (Name ==
"ppc970")
2831 DAL->AddJoinedArg(
nullptr, MCpu,
"970");
2833 else if (Name ==
"ppc64" || Name ==
"ppc64le")
2834 DAL->AddFlagArg(
nullptr, Opts.getOption(options::OPT_m64));
2836 else if (Name ==
"i386")
2838 else if (Name ==
"i486")
2839 DAL->AddJoinedArg(
nullptr, MArch,
"i486");
2840 else if (Name ==
"i586")
2841 DAL->AddJoinedArg(
nullptr, MArch,
"i586");
2842 else if (Name ==
"i686")
2843 DAL->AddJoinedArg(
nullptr, MArch,
"i686");
2844 else if (Name ==
"pentium")
2845 DAL->AddJoinedArg(
nullptr, MArch,
"pentium");
2846 else if (Name ==
"pentium2")
2847 DAL->AddJoinedArg(
nullptr, MArch,
"pentium2");
2848 else if (Name ==
"pentpro")
2849 DAL->AddJoinedArg(
nullptr, MArch,
"pentiumpro");
2850 else if (Name ==
"pentIIm3")
2851 DAL->AddJoinedArg(
nullptr, MArch,
"pentium2");
2853 else if (Name ==
"x86_64" || Name ==
"x86_64h")
2854 DAL->AddFlagArg(
nullptr, Opts.getOption(options::OPT_m64));
2856 else if (Name ==
"arm")
2857 DAL->AddJoinedArg(
nullptr, MArch,
"armv4t");
2858 else if (Name ==
"armv4t")
2859 DAL->AddJoinedArg(
nullptr, MArch,
"armv4t");
2860 else if (Name ==
"armv5")
2861 DAL->AddJoinedArg(
nullptr, MArch,
"armv5tej");
2862 else if (Name ==
"xscale")
2863 DAL->AddJoinedArg(
nullptr, MArch,
"xscale");
2864 else if (Name ==
"armv6")
2865 DAL->AddJoinedArg(
nullptr, MArch,
"armv6k");
2866 else if (Name ==
"armv6m")
2867 DAL->AddJoinedArg(
nullptr, MArch,
"armv6m");
2868 else if (Name ==
"armv7")
2869 DAL->AddJoinedArg(
nullptr, MArch,
"armv7a");
2870 else if (Name ==
"armv7em")
2871 DAL->AddJoinedArg(
nullptr, MArch,
"armv7em");
2872 else if (Name ==
"armv7k")
2873 DAL->AddJoinedArg(
nullptr, MArch,
"armv7k");
2874 else if (Name ==
"armv7m")
2875 DAL->AddJoinedArg(
nullptr, MArch,
"armv7m");
2876 else if (Name ==
"armv7s")
2877 DAL->AddJoinedArg(
nullptr, MArch,
"armv7s");
2884 ArgStringList &CmdArgs,
2885 bool ForceLinkBuiltinRT)
const {
2894 CompilerRT += Args.hasArg(options::OPT_fPIC) ?
"_pic" :
"_static";
2900 llvm::Triple::OSType OS;
2906 OS = llvm::Triple::MacOSX;
2909 OS = llvm::Triple::IOS;
2912 OS = llvm::Triple::TvOS;
2915 OS = llvm::Triple::WatchOS;
2929 const std::optional<DarwinSDKInfo> &SDKInfo) {
2949 VersionTuple SDKVersion = SDKInfo->getVersion();
2950 switch (TargetPlatform) {
2954 return SDKVersion >= VersionTuple(15U);
2956 switch (TargetEnvironment) {
2961 return SDKVersion >= VersionTuple(15U);
2963 return SDKVersion >= VersionTuple(18U);
2966 return SDKVersion >= VersionTuple(18U);
2968 return SDKVersion >= VersionTuple(11U);
2970 return SDKVersion >= VersionTuple(2U);
2978static inline llvm::VersionTuple
2983 case llvm::Triple::Darwin:
2984 case llvm::Triple::MacOSX:
2985 return llvm::VersionTuple(10U, 12U);
2986 case llvm::Triple::IOS:
2987 case llvm::Triple::TvOS:
2988 return llvm::VersionTuple(10U);
2989 case llvm::Triple::WatchOS:
2990 return llvm::VersionTuple(3U);
2993 llvm_unreachable(
"Unexpected OS");
2997 llvm::Triple::OSType OS;
3003 OS = llvm::Triple::MacOSX;
3006 OS = llvm::Triple::IOS;
3009 OS = llvm::Triple::TvOS;
3012 OS = llvm::Triple::WatchOS;
3024 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
3028 if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
3029 options::OPT_fno_aligned_allocation) &&
3031 CC1Args.push_back(
"-faligned-alloc-unavailable");
3035 if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
3036 options::OPT_fno_sized_deallocation) &&
3038 CC1Args.push_back(
"-fno-sized-deallocation");
3044 CC1Args.push_back(
"-fcompatibility-qualified-id-block-type-checking");
3048 if (!DriverArgs.getLastArgNoClaim(
3049 options::OPT_fvisibility_inlines_hidden_static_local_var,
3050 options::OPT_fno_visibility_inlines_hidden_static_local_var))
3051 CC1Args.push_back(
"-fvisibility-inlines-hidden-static-local-var");
3065 CC1Args.push_back(
"-fbuiltin-headers-in-system-modules");
3067 if (!DriverArgs.hasArgNoClaim(options::OPT_fdefine_target_os_macros,
3068 options::OPT_fno_define_target_os_macros))
3069 CC1Args.push_back(
"-fdefine-target-os-macros");
3073 !DriverArgs.hasFlag(options::OPT_fmodulemap_allow_subdirectory_search,
3074 options::OPT_fno_modulemap_allow_subdirectory_search,
3076 bool RequiresSubdirectorySearch;
3077 VersionTuple SDKVersion =
SDKInfo->getVersion();
3080 RequiresSubdirectorySearch =
true;
3083 RequiresSubdirectorySearch = SDKVersion < VersionTuple(15, 0);
3087 RequiresSubdirectorySearch = SDKVersion < VersionTuple(18, 0);
3090 RequiresSubdirectorySearch = SDKVersion < VersionTuple(11, 0);
3093 RequiresSubdirectorySearch = SDKVersion < VersionTuple(2, 0);
3096 if (!RequiresSubdirectorySearch)
3097 CC1Args.push_back(
"-fno-modulemap-allow-subdirectory-search");
3102 const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1ASArgs)
const {
3104 CC1ASArgs.push_back(
"-darwin-target-variant-triple");
3111 auto EmitTargetSDKVersionArg = [&](
const VersionTuple &
V) {
3113 llvm::raw_string_ostream OS(Arg);
3114 OS <<
"-target-sdk-version=" <<
V;
3115 CC1ASArgs.push_back(Args.MakeArgString(Arg));
3119 if (
const auto *MacOStoMacCatalystMapping =
SDKInfo->getVersionMapping(
3121 std::optional<VersionTuple> SDKVersion = MacOStoMacCatalystMapping->map(
3124 EmitTargetSDKVersionArg(
3128 EmitTargetSDKVersionArg(
SDKInfo->getVersion());
3136 llvm::raw_string_ostream OS(Arg);
3137 OS <<
"-darwin-target-variant-sdk-version=" <<
SDKInfo->getVersion();
3138 CC1ASArgs.push_back(Args.MakeArgString(Arg));
3139 }
else if (
const auto *MacOStoMacCatalystMapping =
3142 if (std::optional<VersionTuple> SDKVersion =
3143 MacOStoMacCatalystMapping->map(
3147 llvm::raw_string_ostream OS(Arg);
3148 OS <<
"-darwin-target-variant-sdk-version=" << *SDKVersion;
3149 CC1ASArgs.push_back(Args.MakeArgString(Arg));
3160 DerivedArgList *DAL =
3164 if (BoundArch.empty())
3170 AddDeploymentTarget(*DAL);
3178 for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) {
3181 if (A->getOption().getID() != options::OPT_mkernel &&
3182 A->getOption().getID() != options::OPT_fapple_kext)
3184 assert(it != ie &&
"unexpected argument translation");
3186 assert(A->getOption().getID() == options::OPT_static &&
3187 "missing expected -static argument");
3194 if ((Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)) {
3195 if (Args.hasFlag(options::OPT_fomit_frame_pointer,
3196 options::OPT_fno_omit_frame_pointer,
false))
3197 getDriver().
Diag(clang::diag::warn_drv_unsupported_opt_for_target)
3198 <<
"-fomit-frame-pointer" << BoundArch;
3207 if (
getArch() == llvm::Triple::x86_64 ||
3209 Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
3211 return (
getArch() == llvm::Triple::aarch64 ||
3212 getArch() == llvm::Triple::aarch64_32)
3220 if (
const char *S = ::getenv(
"RC_DEBUG_OPTIONS"))
3221 return S[0] !=
'\0';
3226 if (
const char *S = ::getenv(
"RC_DEBUG_PREFIX_MAP"))
3235 return llvm::ExceptionHandling::None;
3239 if (Triple.isWatchABI())
3240 return llvm::ExceptionHandling::DwarfCFI;
3242 return llvm::ExceptionHandling::SjLj;
3257 return (
getArch() == llvm::Triple::x86_64 ||
3258 getArch() == llvm::Triple::aarch64);
3267 ArgStringList &CmdArgs)
const {
3270 assert(!
isTargetXROS() &&
"xrOS always uses -platform-version");
3273 CmdArgs.push_back(
"-watchos_version_min");
3275 CmdArgs.push_back(
"-watchos_simulator_version_min");
3277 CmdArgs.push_back(
"-tvos_version_min");
3279 CmdArgs.push_back(
"-tvos_simulator_version_min");
3281 CmdArgs.push_back(
"-driverkit_version_min");
3283 CmdArgs.push_back(
"-ios_simulator_version_min");
3285 CmdArgs.push_back(
"-iphoneos_version_min");
3287 CmdArgs.push_back(
"-maccatalyst_version_min");
3290 CmdArgs.push_back(
"-macosx_version_min");
3296 CmdArgs.push_back(Args.MakeArgString(
TargetVersion.getAsString()));
3299 VersionTuple VariantTargetVersion;
3301 CmdArgs.push_back(
"-macosx_version_min");
3306 "unexpected target variant triple");
3307 CmdArgs.push_back(
"-maccatalyst_version_min");
3310 VersionTuple MinTgtVers =
3312 if (MinTgtVers.getMajor() && MinTgtVers > VariantTargetVersion)
3313 VariantTargetVersion = MinTgtVers;
3314 CmdArgs.push_back(Args.MakeArgString(VariantTargetVersion.getAsString()));
3325 return "mac catalyst";
3336 llvm_unreachable(
"invalid platform");
3340 llvm::opt::ArgStringList &CmdArgs)
const {
3341 auto EmitPlatformVersionArg =
3344 const llvm::Triple &TT) {
3347 CmdArgs.push_back(
"-platform_version");
3348 std::string PlatformName =
3351 PlatformName +=
"-simulator";
3352 CmdArgs.push_back(Args.MakeArgString(PlatformName));
3361 VersionTuple MinTgtVers = TT.getMinimumSupportedOSVersion();
3364 CmdArgs.push_back(Args.MakeArgString(
TargetVersion.getAsString()));
3369 std::optional<VersionTuple> iOSSDKVersion;
3371 if (
const auto *MacOStoMacCatalystMapping =
3374 iOSSDKVersion = MacOStoMacCatalystMapping->map(
3375 SDKInfo->getVersion().withoutBuild(),
3379 CmdArgs.push_back(Args.MakeArgString(
3380 (iOSSDKVersion ? *iOSSDKVersion
3387 VersionTuple SDKVersion =
SDKInfo->getVersion().withoutBuild();
3388 if (!SDKVersion.getMinor())
3389 SDKVersion = VersionTuple(SDKVersion.getMajor(), 0);
3390 CmdArgs.push_back(Args.MakeArgString(SDKVersion.getAsString()));
3401 CmdArgs.push_back(Args.MakeArgString(
TargetVersion.getAsString()));
3410 VersionTuple TargetVariantVersion;
3418 "unexpected target variant triple");
3423 EmitPlatformVersionArg(TargetVariantVersion, Platform, Environment,
3429 ArgStringList &CmdArgs) {
3431 if (
D.isTargetIPhoneOS()) {
3432 if (
D.isIPhoneOSVersionLT(3, 1))
3433 CmdArgs.push_back(
"-ldylib1.o");
3437 if (!
D.isTargetMacOS())
3439 if (
D.isMacosxVersionLT(10, 5))
3440 CmdArgs.push_back(
"-ldylib1.o");
3441 else if (
D.isMacosxVersionLT(10, 6))
3442 CmdArgs.push_back(
"-ldylib1.10.5.o");
3447 ArgStringList &CmdArgs) {
3448 if (Args.hasArg(options::OPT_static))
3451 if ((
D.isTargetIPhoneOS() &&
D.isIPhoneOSVersionLT(3, 1)) ||
3452 (
D.isTargetMacOS() &&
D.isMacosxVersionLT(10, 6)))
3453 CmdArgs.push_back(
"-lbundle1.o");
3458 ArgStringList &CmdArgs) {
3459 if (
D.isTargetMacOS() &&
D.isMacosxVersionLT(10, 9)) {
3460 if (Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_object) ||
3461 Args.hasArg(options::OPT_preload)) {
3462 CmdArgs.push_back(
"-lgcrt0.o");
3464 CmdArgs.push_back(
"-lgcrt1.o");
3473 if (!
D.isMacosxVersionLT(10, 8))
3474 CmdArgs.push_back(
"-no_new_main");
3476 D.getDriver().Diag(diag::err_drv_clang_unsupported_opt_pg_darwin)
3477 <<
D.isTargetMacOSBased();
3482 ArgStringList &CmdArgs) {
3484 if (
D.isTargetIPhoneOS()) {
3485 if (
D.getArch() == llvm::Triple::aarch64)
3487 else if (
D.isIPhoneOSVersionLT(3, 1))
3488 CmdArgs.push_back(
"-lcrt1.o");
3489 else if (
D.isIPhoneOSVersionLT(6, 0))
3490 CmdArgs.push_back(
"-lcrt1.3.1.o");
3494 if (!
D.isTargetMacOS())
3496 if (
D.isMacosxVersionLT(10, 5))
3497 CmdArgs.push_back(
"-lcrt1.o");
3498 else if (
D.isMacosxVersionLT(10, 6))
3499 CmdArgs.push_back(
"-lcrt1.10.5.o");
3500 else if (
D.isMacosxVersionLT(10, 8))
3501 CmdArgs.push_back(
"-lcrt1.10.6.o");
3506 ArgStringList &CmdArgs)
const {
3508 if (Args.hasArg(options::OPT_dynamiclib))
3510 else if (Args.hasArg(options::OPT_bundle))
3514 else if (Args.hasArg(options::OPT_static) ||
3515 Args.hasArg(options::OPT_object) ||
3516 Args.hasArg(options::OPT_preload))
3517 CmdArgs.push_back(
"-lcrt0.o");
3521 if (
isTargetMacOS() && Args.hasArg(options::OPT_shared_libgcc) &&
3523 const char *Str = Args.MakeArgString(
GetFilePath(
"crt3.o"));
3524 CmdArgs.push_back(Str);
3536 const bool IsX86_64 =
getTriple().getArch() == llvm::Triple::x86_64;
3537 const bool IsAArch64 =
getTriple().getArch() == llvm::Triple::aarch64;
3539 Res |= SanitizerKind::Address;
3540 Res |= SanitizerKind::PointerCompare;
3541 Res |= SanitizerKind::PointerSubtract;
3542 Res |= SanitizerKind::Leak;
3543 Res |= SanitizerKind::Fuzzer;
3544 Res |= SanitizerKind::FuzzerNoLink;
3545 Res |= SanitizerKind::ObjCCast;
3552 Res |= SanitizerKind::Vptr;
3554 if ((IsX86_64 || IsAArch64) &&
3557 Res |= SanitizerKind::Thread;
3561 Res |= SanitizerKind::NumericalStability;
Defines a function that returns the minimum OS versions supporting C++17's aligned allocation functio...
enum clang::sema::@1653::IndirectLocalPathEntry::EntryKind Kind
static bool hasMultipleInvocations(const llvm::Triple &Triple, const ArgList &Args)
static bool checkRemarksOptions(const Driver &D, const ArgList &Args, const llvm::Triple &Triple)
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const JobAction &JA)
static void addPgProfilingLinkArgs(const Darwin &D, const ArgList &Args, ArgStringList &CmdArgs)
static const char * ArmMachOArchName(StringRef Arch)
static bool shouldLinkerNotDedup(bool IsLinkerOnlyAction, const ArgList &Args)
Pass -no_deduplicate to ld64 under certain conditions:
static bool hasExportSymbolDirective(const ArgList &Args)
Check if the link command contains a symbol export directive.
static void addDefaultCRTLinkArgs(const Darwin &D, const ArgList &Args, ArgStringList &CmdArgs)
static void addBundleLinkArgs(const Darwin &D, const ArgList &Args, ArgStringList &CmdArgs)
static llvm::VersionTuple sizedDeallocMinVersion(llvm::Triple::OSType OS)
static VersionTuple minimumMacCatalystDeploymentTarget()
static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion)
Returns the most appropriate macOS target version for the current process.
static bool sdkSupportsBuiltinModules(const Darwin::DarwinPlatformKind &TargetPlatform, const Darwin::DarwinEnvironmentKind &TargetEnvironment, const std::optional< DarwinSDKInfo > &SDKInfo)
static void addDynamicLibLinkArgs(const Darwin &D, const ArgList &Args, ArgStringList &CmdArgs)
static void AppendPlatformPrefix(SmallString< 128 > &Path, const llvm::Triple &T)
static bool isObjCRuntimeLinked(const ArgList &Args)
Determine whether we are linking the ObjC runtime.
static const char * getPlatformName(Darwin::DarwinPlatformKind Platform, Darwin::DarwinEnvironmentKind Environment)
static const char * ArmMachOArchNameCPU(StringRef CPU)
static void addExportedSymbol(ArgStringList &CmdArgs, const char *Symbol)
Add an export directive for Symbol to the link command.
static StringRef getXcodeDeveloperPath(StringRef PathIntoXcode)
Take a path that speculatively points into Xcode and return the XCODE/Contents/Developer path if it i...
static void addSectalignToPage(const ArgList &Args, ArgStringList &CmdArgs, StringRef Segment, StringRef Section)
Add a sectalign directive for Segment and Section to the maximum expected page size for Darwin.
llvm::MachO::Target Target
Defines types useful for describing an Objective-C runtime.
The information about the darwin SDK that was used during this compilation.
The basic abstraction for the target Objective-C runtime.
bool hasNativeARC() const
Does this runtime natively provide the ARC entrypoints?
bool hasSubscripting() const
Does this runtime directly support the subscripting methods?
@ MacOSX
'macosx' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the non-fragile AB...
@ FragileMacOSX
'macosx-fragile' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the fragil...
@ iOS
'ios' is the Apple-provided NeXT-derived runtime on iOS or the iOS simulator; it is always non-fragil...
@ WatchOS
'watchos' is a variant of iOS for Apple's watchOS.
The base class of the type hierarchy.
Action - Represent an abstract compilation step to perform.
types::ID getType() const
ActionClass getKind() const
@ VerifyDebugInfoJobClass
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string SysRoot
sysroot, if present
DiagnosticBuilder Diag(unsigned DiagID) const
static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor, unsigned &Micro, bool &HadExtra)
GetReleaseVersion - Parse (([0-9]+)(.
const llvm::opt::OptTable & getOpts() const
bool needsStatsRt() const
bool linkRuntimes() const
bool needsUbsanRt() const
bool requiresMinimalRuntime() const
bool needsSharedRt() const
bool needsStableAbi() const
const char * getTypeTempSuffix(ID Id, bool CLStyle=false)
getTypeTempSuffix - Return the suffix to use when creating a temp file of this type,...
bool willEmitRemarks(const llvm::opt::ArgList &Args)
The JSON file list parser is used to communicate input to InstallAPI.
Expected< std::optional< DarwinSDKInfo > > parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath)
Parse the SDK information from the SDKSettings.json file.
@ Result
The result type of a method or function.
llvm::VersionTuple alignedAllocMinVersion(llvm::Triple::OSType OS)
const FunctionProtoType * T
llvm::StringRef getAsString(SyncScope S)
static constexpr OSEnvPair macCatalystToMacOSPair()
Returns the os-environment mapping pair that's used to represent the Mac Catalyst -> macOS version ma...
static constexpr OSEnvPair macOStoMacCatalystPair()
Returns the os-environment mapping pair that's used to represent the macOS -> Mac Catalyst version ma...
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.
static constexpr ResponseFileSupport AtFileUTF8()