32#include "clang/Config/config.h"
44#include "llvm/ADT/STLExtras.h"
45#include "llvm/ADT/SmallSet.h"
46#include "llvm/ADT/SmallString.h"
47#include "llvm/ADT/StringExtras.h"
48#include "llvm/ADT/StringSwitch.h"
49#include "llvm/ADT/Twine.h"
50#include "llvm/BinaryFormat/Magic.h"
51#include "llvm/Config/llvm-config.h"
52#include "llvm/Option/Arg.h"
53#include "llvm/Option/ArgList.h"
54#include "llvm/Option/Option.h"
55#include "llvm/Support/CodeGen.h"
56#include "llvm/Support/Compression.h"
57#include "llvm/Support/Debug.h"
58#include "llvm/Support/ErrorHandling.h"
59#include "llvm/Support/FileSystem.h"
60#include "llvm/Support/Path.h"
61#include "llvm/Support/Process.h"
62#include "llvm/Support/Program.h"
63#include "llvm/Support/ScopedPrinter.h"
64#include "llvm/Support/Threading.h"
65#include "llvm/Support/VirtualFileSystem.h"
66#include "llvm/Support/YAMLParser.h"
67#include "llvm/TargetParser/Host.h"
68#include "llvm/TargetParser/PPCTargetParser.h"
69#include "llvm/TargetParser/TargetParser.h"
78 const llvm::Triple &Triple) {
79 if (Args.hasArg(clang::driver::options::OPT_pg) &&
80 !Args.hasArg(clang::driver::options::OPT_mfentry))
83 if (Triple.isAndroid())
86 switch (Triple.getArch()) {
87 case llvm::Triple::xcore:
88 case llvm::Triple::wasm32:
89 case llvm::Triple::wasm64:
90 case llvm::Triple::msp430:
94 case llvm::Triple::ppc:
95 case llvm::Triple::ppcle:
96 case llvm::Triple::ppc64:
97 case llvm::Triple::ppc64le:
98 case llvm::Triple::riscv32:
99 case llvm::Triple::riscv64:
100 case llvm::Triple::sparc:
101 case llvm::Triple::sparcel:
102 case llvm::Triple::sparcv9:
103 case llvm::Triple::amdgcn:
104 case llvm::Triple::r600:
105 case llvm::Triple::csky:
106 case llvm::Triple::loongarch32:
107 case llvm::Triple::loongarch64:
108 case llvm::Triple::m68k:
114 if (Triple.isOSFuchsia() || Triple.isOSNetBSD()) {
118 if (Triple.isOSLinux() || Triple.isOSHurd()) {
119 switch (Triple.getArch()) {
121 case llvm::Triple::arm:
122 case llvm::Triple::armeb:
123 case llvm::Triple::thumb:
124 case llvm::Triple::thumbeb:
125 case llvm::Triple::mips64:
126 case llvm::Triple::mips64el:
127 case llvm::Triple::mips:
128 case llvm::Triple::mipsel:
129 case llvm::Triple::systemz:
130 case llvm::Triple::x86:
131 case llvm::Triple::x86_64:
138 if (Triple.isOSWindows()) {
139 switch (Triple.getArch()) {
140 case llvm::Triple::x86:
142 case llvm::Triple::x86_64:
143 return Triple.isOSBinFormatMachO();
144 case llvm::Triple::arm:
145 case llvm::Triple::thumb:
162 if (Triple.isAArch64() || Triple.isPS() || Triple.isVE() ||
163 (Triple.isAndroid() && !Triple.isARM()))
170 switch (Triple.getArch()) {
173 case llvm::Triple::arm:
174 case llvm::Triple::thumb:
177 return Triple.isOSDarwin();
184 const llvm::Triple &Triple) {
185 if (Triple.isARM() || Triple.isThumb()) {
189 if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
190 StringRef
V = A->getValue();
201 const llvm::Triple &Triple) {
202 if (Triple.isARM() || Triple.isThumb()) {
206 if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
207 StringRef
V = A->getValue();
208 return V ==
"aapcs+leaf";
217 const llvm::Triple &Triple) {
247 Args.hasFlag(clang::driver::options::OPT_fno_omit_frame_pointer,
248 clang::driver::options::OPT_fomit_frame_pointer, DefaultFP);
253 bool EnableLeafFP = Args.hasFlag(
254 clang::driver::options::OPT_mno_omit_leaf_frame_pointer,
255 clang::driver::options::OPT_momit_leaf_frame_pointer, DefaultLeafFP);
270 const StringRef PluginOptPrefix) {
271 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
272 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
273 "-pass-remarks=" + A->getValue()));
275 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
276 CmdArgs.push_back(Args.MakeArgString(
277 Twine(PluginOptPrefix) +
"-pass-remarks-missed=" + A->getValue()));
279 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
280 CmdArgs.push_back(Args.MakeArgString(
281 Twine(PluginOptPrefix) +
"-pass-remarks-analysis=" + A->getValue()));
285 const llvm::Triple &Triple,
288 const StringRef PluginOptPrefix) {
289 StringRef Format =
"yaml";
290 if (
const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
291 Format = A->getValue();
294 const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
300 assert(!F.empty() &&
"Cannot determine remarks output name.");
302 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
303 "opt-remarks-filename=" + F +
304 ".opt.ld." + Format));
307 Args.getLastArg(options::OPT_foptimization_record_passes_EQ))
308 CmdArgs.push_back(Args.MakeArgString(
309 Twine(PluginOptPrefix) +
"opt-remarks-passes=" + A->getValue()));
311 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
312 "opt-remarks-format=" + Format.data()));
316 ArgStringList &CmdArgs,
317 const StringRef PluginOptPrefix) {
318 if (Args.hasFlag(options::OPT_fdiagnostics_show_hotness,
319 options::OPT_fno_diagnostics_show_hotness,
false))
320 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
321 "opt-remarks-with-hotness"));
324 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ))
326 Args.MakeArgString(Twine(PluginOptPrefix) +
327 "opt-remarks-hotness-threshold=" + A->getValue()));
332 StringRef Processor) {
336 auto GPUKind =
T.isAMDGCN() ? llvm::AMDGPU::parseArchAMDGCN(Processor)
337 : llvm::AMDGPU::parseArchR600(Processor);
338 auto GPUFeatures =
T.isAMDGCN() ? llvm::AMDGPU::getArchAttrAMDGCN(GPUKind)
339 : llvm::AMDGPU::getArchAttrR600(GPUKind);
340 if (GPUFeatures & llvm::AMDGPU::FEATURE_WGP)
342 return TargetFeatureArg.getOption().matches(options::OPT_mno_cumode);
347 if (
D.getVFS().exists(
Path))
348 Paths.push_back(
Path.str());
352 const llvm::Triple &Triple,
354 std::vector<StringRef> &Features,
355 OptSpecifier Group) {
356 std::set<StringRef> Warned;
357 for (
const Arg *A : Args.filtered(Group)) {
358 StringRef Name = A->getOption().getName();
362 assert(Name.starts_with(
"m") &&
"Invalid feature name.");
363 Name = Name.substr(1);
367 if (Warned.count(Name) == 0) {
369 clang::diag::warn_drv_unsupported_option_for_processor)
370 << A->getAsString(Args) << Proc;
376 bool IsNegative = Name.consume_front(
"no-");
378 Features.push_back(Args.MakeArgString((IsNegative ?
"-" :
"+") + Name));
386 llvm::DenseSet<StringRef> UsedFeatures;
387 for (StringRef Feature : llvm::reverse(Features)) {
388 if (UsedFeatures.insert(Feature.drop_front()).second)
389 UnifiedFeatures.insert(UnifiedFeatures.begin(), Feature);
392 return UnifiedFeatures;
396 const char *ArgName,
const char *EnvVar) {
397 const char *DirList = ::getenv(EnvVar);
398 bool CombinedArg =
false;
403 StringRef Name(ArgName);
404 if (Name ==
"-I" || Name ==
"-L" || Name.empty())
407 StringRef Dirs(DirList);
411 StringRef::size_type Delim;
412 while ((Delim = Dirs.find(llvm::sys::EnvPathSeparator)) != StringRef::npos) {
415 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
417 CmdArgs.push_back(ArgName);
418 CmdArgs.push_back(
".");
423 Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim)));
425 CmdArgs.push_back(ArgName);
426 CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim)));
429 Dirs = Dirs.substr(Delim + 1);
434 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
436 CmdArgs.push_back(ArgName);
437 CmdArgs.push_back(
".");
441 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs));
443 CmdArgs.push_back(ArgName);
444 CmdArgs.push_back(Args.MakeArgString(Dirs));
450 const ArgList &Args, ArgStringList &CmdArgs,
456 Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
463 for (
const auto &II : Inputs) {
467 if (
auto *IA = II.getAction())
477 if (II.isFilename()) {
478 CmdArgs.push_back(II.getFilename());
487 const Arg &A = II.getInputArg();
490 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
492 else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
495 A.renderAsInput(Args, CmdArgs);
497 if (
const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
498 const llvm::Triple &Triple = TC.
getTriple();
499 StringRef
V = A->getValue();
500 if (
V ==
"ArmPL" && (Triple.isOSLinux() || Triple.isOSDarwin())) {
518 if (Triple.isOSLinux()) {
519 CmdArgs.push_back(Args.MakeArgString(
"--push-state"));
520 CmdArgs.push_back(Args.MakeArgString(
"--as-needed"));
522 CmdArgs.push_back(Args.MakeArgString(
"-lm"));
523 CmdArgs.push_back(Args.MakeArgString(
"-lamath"));
524 CmdArgs.push_back(Args.MakeArgString(
"-lm"));
525 if (Triple.isOSLinux())
526 CmdArgs.push_back(Args.MakeArgString(
"--pop-state"));
533 const ToolChain &TC,
const llvm::opt::ArgList &Args,
534 llvm::opt::ArgStringList &CmdArgs) {
540 if (
const Arg *A = Args.getLastArg(options::OPT_gz_EQ)) {
541 StringRef
V = A->getValue();
542 if (
V ==
"none" ||
V ==
"zlib" ||
V ==
"zstd")
543 CmdArgs.push_back(Args.MakeArgString(
"--compress-debug-sections=" +
V));
545 TC.
getDriver().
Diag(diag::err_drv_unsupported_option_argument)
546 << A->getSpelling() <<
V;
551 std::vector<StringRef> &Features,
552 OptSpecifier OnOpt, OptSpecifier OffOpt,
553 StringRef FeatureName) {
554 if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) {
555 if (A->getOption().matches(OnOpt))
556 Features.push_back(Args.MakeArgString(
"+" + FeatureName));
558 Features.push_back(Args.MakeArgString(
"-" + FeatureName));
564 const ArgList &Args) {
565 Arg *MArch = Args.getLastArg(options::OPT_march_EQ);
566 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
568 return llvm::StringSwitch<std::string>(GPUName)
569 .Cases(
"rv630",
"rv635",
"r600")
570 .Cases(
"rv610",
"rv620",
"rs780",
"rs880")
571 .Case(
"rv740",
"rv770")
572 .Case(
"palm",
"cedar")
573 .Cases(
"sumo",
"sumo2",
"sumo")
574 .Case(
"hemlock",
"cypress")
575 .Case(
"aruba",
"cayman")
576 .Default(GPUName.str());
584 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
585 return A->getValue();
593 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
594 StringRef CPU = A->getValue();
600 return llvm::sys::getHostCPUName();
610 const llvm::Triple &
T,
bool FromAs) {
613 switch (
T.getArch()) {
617 case llvm::Triple::aarch64:
618 case llvm::Triple::aarch64_32:
619 case llvm::Triple::aarch64_be:
622 case llvm::Triple::arm:
623 case llvm::Triple::armeb:
624 case llvm::Triple::thumb:
625 case llvm::Triple::thumbeb: {
626 StringRef MArch, MCPU;
631 case llvm::Triple::avr:
632 if (
const Arg *A = Args.getLastArg(options::OPT_mmcu_EQ))
633 return A->getValue();
636 case llvm::Triple::m68k:
639 case llvm::Triple::mips:
640 case llvm::Triple::mipsel:
641 case llvm::Triple::mips64:
642 case llvm::Triple::mips64el: {
646 return std::string(CPUName);
649 case llvm::Triple::nvptx:
650 case llvm::Triple::nvptx64:
651 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
652 return A->getValue();
655 case llvm::Triple::ppc:
656 case llvm::Triple::ppcle:
657 case llvm::Triple::ppc64:
658 case llvm::Triple::ppc64le:
659 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ))
661 llvm::PPC::getNormalizedPPCTargetCPU(
T, A->getValue()));
662 return std::string(llvm::PPC::getNormalizedPPCTargetCPU(
T));
664 case llvm::Triple::csky:
665 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
666 return A->getValue();
667 else if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
668 return A->getValue();
671 case llvm::Triple::riscv32:
672 case llvm::Triple::riscv64:
675 case llvm::Triple::bpfel:
676 case llvm::Triple::bpfeb:
677 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
678 return A->getValue();
681 case llvm::Triple::sparc:
682 case llvm::Triple::sparcel:
683 case llvm::Triple::sparcv9:
686 case llvm::Triple::x86:
687 case llvm::Triple::x86_64:
690 case llvm::Triple::hexagon:
694 case llvm::Triple::lanai:
697 case llvm::Triple::systemz:
700 case llvm::Triple::r600:
701 case llvm::Triple::amdgcn:
704 case llvm::Triple::wasm32:
705 case llvm::Triple::wasm64:
708 case llvm::Triple::loongarch32:
709 case llvm::Triple::loongarch64:
712 case llvm::Triple::xtensa:
713 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
714 return A->getValue();
720 const llvm::Triple &Triple,
722 std::vector<StringRef> &Features) {
724 options::OPT_m_wasm_Features_Group);
728 const ArgList &Args, ArgStringList &CmdArgs,
729 bool ForAS,
bool IsAux) {
730 std::vector<StringRef> Features;
731 switch (Triple.getArch()) {
734 case llvm::Triple::mips:
735 case llvm::Triple::mipsel:
736 case llvm::Triple::mips64:
737 case llvm::Triple::mips64el:
740 case llvm::Triple::arm:
741 case llvm::Triple::armeb:
742 case llvm::Triple::thumb:
743 case llvm::Triple::thumbeb:
746 case llvm::Triple::ppc:
747 case llvm::Triple::ppcle:
748 case llvm::Triple::ppc64:
749 case llvm::Triple::ppc64le:
752 case llvm::Triple::riscv32:
753 case llvm::Triple::riscv64:
756 case llvm::Triple::systemz:
759 case llvm::Triple::aarch64:
760 case llvm::Triple::aarch64_32:
761 case llvm::Triple::aarch64_be:
764 case llvm::Triple::x86:
765 case llvm::Triple::x86_64:
768 case llvm::Triple::hexagon:
771 case llvm::Triple::wasm32:
772 case llvm::Triple::wasm64:
775 case llvm::Triple::sparc:
776 case llvm::Triple::sparcel:
777 case llvm::Triple::sparcv9:
780 case llvm::Triple::r600:
781 case llvm::Triple::amdgcn:
784 case llvm::Triple::nvptx:
785 case llvm::Triple::nvptx64:
788 case llvm::Triple::m68k:
791 case llvm::Triple::msp430:
794 case llvm::Triple::ve:
797 case llvm::Triple::csky:
800 case llvm::Triple::loongarch32:
801 case llvm::Triple::loongarch64:
807 CmdArgs.push_back(IsAux ?
"-aux-target-feature" :
"-target-feature");
808 CmdArgs.push_back(Feature.data());
813 Arg *LtoJobsArg = Args.getLastArg(options::OPT_flto_jobs_EQ);
816 if (!llvm::get_threadpool_strategy(LtoJobsArg->getValue()))
817 D.Diag(diag::err_drv_invalid_int_value)
818 << LtoJobsArg->getAsString(Args) << LtoJobsArg->getValue();
819 return LtoJobsArg->getValue();
824 return Triple.isPS();
828 const llvm::opt::ArgList &Args) {
830 Arg *A = Args.getLastArg(options::OPT_mtls_dialect_EQ);
832 return Triple.hasDefaultTLSDESC();
833 StringRef
V = A->getValue();
834 bool SupportedArgument =
false, EnableTLSDESC =
false;
835 bool Unsupported = !Triple.isOSBinFormatELF();
836 if (Triple.isLoongArch() || Triple.isRISCV()) {
837 SupportedArgument =
V ==
"desc" ||
V ==
"trad";
838 EnableTLSDESC =
V ==
"desc";
839 }
else if (Triple.isX86()) {
840 SupportedArgument =
V ==
"gnu" ||
V ==
"gnu2";
841 EnableTLSDESC =
V ==
"gnu2";
846 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
847 << A->getSpelling() << Triple.getTriple();
848 }
else if (!SupportedArgument) {
849 TC.
getDriver().
Diag(diag::err_drv_unsupported_option_argument_for_target)
850 << A->getSpelling() <<
V << Triple.getTriple();
852 return EnableTLSDESC;
856 ArgStringList &CmdArgs,
const InputInfo &Output,
857 const InputInfo &Input,
bool IsThinLTO) {
859 const bool IsOSAIX = Triple.isOSAIX();
860 const bool IsAMDGCN = Triple.isAMDGCN();
863 const bool IsFatLTO = Args.hasArg(options::OPT_ffat_lto_objects);
864 const bool IsUnifiedLTO = Args.hasArg(options::OPT_funified_lto);
865 if (llvm::sys::path::filename(Linker) !=
"ld.lld" &&
866 llvm::sys::path::stem(Linker) !=
"ld.lld" && !Triple.isOSOpenBSD()) {
870 const char *PluginPrefix = IsOSAIX ?
"-bplugin:" :
"";
871 const char *PluginName = IsOSAIX ?
"/libLTO" :
"/LLVMgold";
874 CmdArgs.push_back(
"-plugin");
877 const char *Suffix =
".dll";
878#elif defined(__APPLE__)
879 const char *Suffix =
".dylib";
881 const char *Suffix =
".so";
885 llvm::sys::path::native(Twine(
D.Dir) +
886 "/../" CLANG_INSTALL_LIBDIR_BASENAME +
889 CmdArgs.push_back(Args.MakeArgString(Twine(PluginPrefix) + Plugin));
894 CmdArgs.push_back(
"--fat-lto-objects");
897 const char *PluginOptPrefix = IsOSAIX ?
"-bplugin_opt:" :
"-plugin-opt=";
898 const char *ExtraDash = IsOSAIX ?
"-" :
"";
899 const char *ParallelismOpt = IsOSAIX ?
"-threads=" :
"jobs=";
904 if (Args.hasArg(options::OPT_gdwarf_aranges)) {
905 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
906 "-generate-arange-section"));
910 Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
911 if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
914 std::optional<StringRef> OptVal =
915 llvm::StringSwitch<std::optional<StringRef>>(ArgVecLib->getValue())
916 .Case(
"Accelerate",
"Accelerate")
917 .Case(
"LIBMVEC",
"LIBMVEC-X86")
918 .Case(
"MASSV",
"MASSV")
919 .Case(
"SVML",
"SVML")
920 .Case(
"SLEEF",
"sleefgnuabi")
921 .Case(
"Darwin_libsystem_m",
"Darwin_libsystem_m")
922 .Case(
"ArmPL",
"ArmPL")
923 .Case(
"none",
"none")
924 .Default(std::nullopt);
927 CmdArgs.push_back(Args.MakeArgString(
928 Twine(PluginOptPrefix) +
"-vector-library=" + OptVal.value()));
938 Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
"mcpu=" + CPU));
940 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
944 if (A->getOption().matches(options::OPT_O4) ||
945 A->getOption().matches(options::OPT_Ofast))
947 else if (A->getOption().matches(options::OPT_O)) {
948 OOpt = A->getValue();
951 else if (OOpt ==
"s" || OOpt ==
"z")
953 }
else if (A->getOption().matches(options::OPT_O0))
957 Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
"O" + OOpt));
959 CmdArgs.push_back(Args.MakeArgString(Twine(
"--lto-CGO") + OOpt));
963 if (Args.hasArg(options::OPT_gsplit_dwarf))
964 CmdArgs.push_back(Args.MakeArgString(
965 Twine(PluginOptPrefix) +
"dwo_dir=" + Output.
getFilename() +
"_dwo"));
967 if (IsThinLTO && !IsOSAIX)
968 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
"thinlto"));
969 else if (IsThinLTO && IsOSAIX)
970 CmdArgs.push_back(Args.MakeArgString(Twine(
"-bdbg:thinlto")));
975 if ((IsThinLTO || IsFatLTO || IsUnifiedLTO) &&
976 Args.hasArg(options::OPT_fenable_matrix))
978 Args.MakeArgString(Twine(PluginOptPrefix) +
"-enable-matrix"));
981 if (!Parallelism.empty())
982 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
983 ParallelismOpt + Parallelism));
986 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
987 options::OPT_fno_global_isel)) {
990 CmdArgs.push_back(Args.MakeArgString(
991 Twine(PluginOptPrefix) +
"-global-isel=" +
992 (A->getOption().matches(options::OPT_fglobal_isel) ?
"1" :
"0")));
997 Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
998 if (A->getOption().matches(options::OPT_glldb))
1000 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=lldb"));
1001 else if (A->getOption().matches(options::OPT_gsce))
1003 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=sce"));
1004 else if (A->getOption().matches(options::OPT_gdbx))
1006 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=dbx"));
1009 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=gdb"));
1015 Args.MakeArgString(Twine(PluginOptPrefix) +
"-no-integrated-as=1"));
1019 Arg *A = Args.getLastArg(options::OPT_g_Group);
1020 bool EnableDebugInfo = A && !A->getOption().matches(options::OPT_g0) &&
1021 !A->getOption().matches(options::OPT_ggdb0);
1022 if (EnableDebugInfo && Args.hasFlag(options::OPT_gstrict_dwarf,
1023 options::OPT_gno_strict_dwarf,
true))
1025 Args.MakeArgString(Twine(PluginOptPrefix) +
"-strict-dwarf=true"));
1027 for (
const Arg *A : Args.filtered_reverse(options::OPT_mabi_EQ)) {
1028 StringRef
V = A->getValue();
1029 if (
V ==
"vec-default")
1031 if (
V ==
"vec-extabi") {
1033 Args.MakeArgString(Twine(PluginOptPrefix) +
"-vec-extabi"));
1039 bool UseSeparateSections =
1042 if (Args.hasFlag(options::OPT_ffunction_sections,
1043 options::OPT_fno_function_sections, UseSeparateSections))
1045 Args.MakeArgString(Twine(PluginOptPrefix) +
"-function-sections=1"));
1046 else if (Args.hasArg(options::OPT_fno_function_sections))
1048 Args.MakeArgString(Twine(PluginOptPrefix) +
"-function-sections=0"));
1050 bool DataSectionsTurnedOff =
false;
1051 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
1052 UseSeparateSections)) {
1054 Args.MakeArgString(Twine(PluginOptPrefix) +
"-data-sections=1"));
1055 }
else if (Args.hasArg(options::OPT_fno_data_sections)) {
1056 DataSectionsTurnedOff =
true;
1058 Args.MakeArgString(Twine(PluginOptPrefix) +
"-data-sections=0"));
1061 if (Args.hasArg(options::OPT_mxcoff_roptr) ||
1062 Args.hasArg(options::OPT_mno_xcoff_roptr)) {
1063 bool HasRoptr = Args.hasFlag(options::OPT_mxcoff_roptr,
1064 options::OPT_mno_xcoff_roptr,
false);
1065 StringRef OptStr = HasRoptr ?
"-mxcoff-roptr" :
"-mno-xcoff-roptr";
1067 D.Diag(diag::err_drv_unsupported_opt_for_target)
1068 << OptStr << Triple.str();
1074 if (DataSectionsTurnedOff)
1075 D.Diag(diag::err_roptr_requires_data_sections);
1078 Args.MakeArgString(Twine(PluginOptPrefix) +
"-mxcoff-roptr"));
1083 if (
auto *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
1084 options::OPT_fno_split_machine_functions)) {
1085 if (A->getOption().matches(options::OPT_fsplit_machine_functions))
1086 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1087 "-split-machine-functions"));
1091 StringRef FName = A->getValue();
1092 if (!llvm::sys::fs::exists(FName))
1093 D.Diag(diag::err_drv_no_such_file) << FName;
1095 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1096 "sample-profile=" + FName));
1100 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1101 "cs-profile-generate"));
1102 if (CSPGOGenerateArg->getOption().matches(
1103 options::OPT_fcs_profile_generate_EQ)) {
1105 llvm::sys::path::append(
Path,
"default_%m.profraw");
1106 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1107 "cs-profile-path=" +
Path));
1110 Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1111 "cs-profile-path=default_%m.profraw"));
1114 ProfileUseArg->getNumValues() == 0 ?
"" : ProfileUseArg->getValue());
1115 if (
Path.empty() || llvm::sys::fs::is_directory(
Path))
1116 llvm::sys::path::append(
Path,
"default.profdata");
1117 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1118 "cs-profile-path=" +
Path));
1122 if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false)) {
1124 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1125 "-enable-jmc-instrument"));
1127 D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
1130 if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
1131 Triple.hasDefaultEmulatedTLS())) {
1133 Args.MakeArgString(Twine(PluginOptPrefix) +
"-emulated-tls"));
1137 Args.MakeArgString(Twine(PluginOptPrefix) +
"-enable-tlsdesc"));
1139 if (Args.hasFlag(options::OPT_fstack_size_section,
1140 options::OPT_fno_stack_size_section,
false))
1142 Args.MakeArgString(Twine(PluginOptPrefix) +
"-stack-size-section"));
1146 if (!StatsFile.empty())
1148 Args.MakeArgString(Twine(PluginOptPrefix) +
"stats-file=" + StatsFile));
1151 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
1152 CmdArgs.push_back(Args.MakeArgString(
1153 Twine(PluginOptPrefix) +
"-crash-diagnostics-dir=" + A->getValue()));
1164 Output, PluginOptPrefix);
1170 true, PluginOptPrefix);
1172 bool IsELF = Triple.isOSBinFormatELF();
1174 bool ImplicitMapSyms =
false;
1175 for (
const Arg *A : Args.filtered(options::OPT_Wa_COMMA)) {
1176 for (StringRef
V : A->getValues()) {
1177 auto Equal =
V.split(
'=');
1178 auto checkArg = [&](
bool ValidTarget,
1179 std::initializer_list<const char *>
Set) {
1181 D.Diag(diag::err_drv_unsupported_opt_for_target)
1182 << (Twine(
"-Wa,") +
Equal.first +
"=").str()
1183 << Triple.getTriple();
1184 }
else if (!llvm::is_contained(
Set,
Equal.second)) {
1185 D.Diag(diag::err_drv_unsupported_option_argument)
1186 << (Twine(
"-Wa,") +
Equal.first +
"=").str() <<
Equal.second;
1189 if (
Equal.first ==
"-mmapsyms") {
1190 ImplicitMapSyms =
Equal.second ==
"implicit";
1191 checkArg(IsELF && Triple.isAArch64(), {
"default",
"implicit"});
1192 }
else if (
V ==
"--crel")
1194 else if (
V ==
"--no-crel")
1202 if (IsELF && !Triple.isMIPS()) {
1203 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
"-crel"));
1205 D.Diag(diag::err_drv_unsupported_opt_for_target)
1206 <<
"-Wa,--crel" <<
D.getTargetTriple();
1209 if (ImplicitMapSyms)
1211 Args.MakeArgString(Twine(PluginOptPrefix) +
"-implicit-mapsyms"));
1215 const ArgList &Args,
1216 ArgStringList &CmdArgs) {
1221 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
1222 CmdArgs.push_back(Args.MakeArgString(
"-L" + DefaultLibPath));
1226 ArgStringList &CmdArgs) {
1227 if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
1228 options::OPT_fno_rtlib_add_rpath,
false))
1233 CandidateRPaths.emplace_back(*CandidateRPath);
1235 for (
const auto &CandidateRPath : CandidateRPaths) {
1236 if (TC.
getVFS().exists(CandidateRPath)) {
1237 CmdArgs.push_back(
"-rpath");
1238 CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
1244 const ToolChain &TC,
const ArgList &Args,
1245 bool ForceStaticHostRuntime,
bool IsOffloadingHost,
1247 if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
1248 options::OPT_fno_openmp,
false)) {
1250 if (Args.hasFlag(options::OPT_foffload_via_llvm,
1251 options::OPT_fno_offload_via_llvm,
false))
1252 CmdArgs.push_back(
"-lomptarget");
1262 if (ForceStaticHostRuntime)
1263 CmdArgs.push_back(
"-Bstatic");
1267 CmdArgs.push_back(
"-lomp");
1270 CmdArgs.push_back(
"-lgomp");
1273 CmdArgs.push_back(
"-liomp5");
1279 if (ForceStaticHostRuntime)
1280 CmdArgs.push_back(
"-Bdynamic");
1283 CmdArgs.push_back(
"-lrt");
1285 if (IsOffloadingHost)
1286 CmdArgs.push_back(
"-lomptarget");
1288 if (IsOffloadingHost && !Args.hasArg(options::OPT_nogpulib))
1289 CmdArgs.push_back(
"-lomptarget.devicertl");
1300 const llvm::opt::ArgList &Args,
1301 llvm::opt::ArgStringList &CmdArgs) {
1307 constexpr llvm::StringLiteral Targets(
"-fopenmp-targets=");
1311 std::transform(TCRange.first, TCRange.second, std::back_inserter(Triples),
1312 [](
auto TC) { return TC.second->getTripleString(); });
1314 Args.MakeArgString(Twine(Targets) + llvm::join(Triples,
",")));
1319 llvm::opt::ArgStringList &CmdArgs) {
1324 if (!TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
1326 F128LibName.consume_front_insensitive(
"lib");
1327 if (!F128LibName.empty()) {
1328 bool AsNeeded = !TC.
getTriple().isOSAIX();
1329 CmdArgs.push_back(
"-lFortranFloat128Math");
1332 CmdArgs.push_back(Args.MakeArgString(
"-l" + F128LibName));
1336 CmdArgs.push_back(
"-lFortranRuntime");
1337 CmdArgs.push_back(
"-lFortranDecimal");
1342 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
1343 options::OPT_fno_openmp,
false)) {
1348 CmdArgs.push_back(
"-latomic");
1353 const llvm::opt::ArgList &Args,
1354 ArgStringList &CmdArgs) {
1361 llvm::sys::path::append(DefaultLibPath,
"lib");
1362 if (TC.
getTriple().isKnownWindowsMSVCEnvironment())
1363 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + DefaultLibPath));
1365 CmdArgs.push_back(Args.MakeArgString(
"-L" + DefaultLibPath));
1369 ArgStringList &CmdArgs, StringRef Sanitizer,
1370 bool IsShared,
bool IsWhole) {
1373 if (IsWhole) CmdArgs.push_back(
"--whole-archive");
1376 if (IsWhole) CmdArgs.push_back(
"--no-whole-archive");
1386 ArgStringList &CmdArgs,
1387 StringRef Sanitizer) {
1392 if (TC.
getTriple().isOSSolaris() && !LinkerIsGnuLd)
1395 if (llvm::sys::fs::exists(SanRT +
".syms")) {
1396 CmdArgs.push_back(Args.MakeArgString(
"--dynamic-list=" + SanRT +
".syms"));
1403 const llvm::opt::ArgList &Args,
1404 llvm::opt::ArgStringList &CmdArgs,
1407 "AIX linker does not support any form of --as-needed option yet.");
1415 if (TC.
getTriple().isOSSolaris() && !LinkerIsGnuLd) {
1416 CmdArgs.push_back(
"-z");
1417 CmdArgs.push_back(as_needed ?
"ignore" :
"record");
1419 CmdArgs.push_back(as_needed ?
"--as-needed" :
"--no-as-needed");
1424 const llvm::opt::ArgList &Args,
1425 ArgStringList &CmdArgs) {
1430 if (TC.
getTriple().getOS() != llvm::Triple::RTEMS &&
1432 CmdArgs.push_back(
"-lpthread");
1434 CmdArgs.push_back(
"-lrt");
1436 CmdArgs.push_back(
"-lm");
1440 TC.
getTriple().getOS() != llvm::Triple::RTEMS)
1441 CmdArgs.push_back(
"-ldl");
1446 CmdArgs.push_back(
"-lexecinfo");
1452 CmdArgs.push_back(
"-lresolv");
1462 assert(!TC.
getTriple().isOSDarwin() &&
"it's not used by Darwin");
1467 SharedRuntimes.push_back(
"asan");
1468 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
1469 HelperStaticRuntimes.push_back(
"asan-preinit");
1472 SharedRuntimes.push_back(
"memprof");
1473 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
1474 HelperStaticRuntimes.push_back(
"memprof-preinit");
1477 SharedRuntimes.push_back(
"nsan");
1480 SharedRuntimes.push_back(
"ubsan_minimal");
1482 SharedRuntimes.push_back(
"ubsan_standalone");
1485 SharedRuntimes.push_back(
"scudo_standalone");
1488 SharedRuntimes.push_back(
"tsan");
1490 SharedRuntimes.push_back(
"tysan");
1493 SharedRuntimes.push_back(
"hwasan_aliases");
1495 SharedRuntimes.push_back(
"hwasan");
1496 if (!Args.hasArg(options::OPT_shared))
1497 HelperStaticRuntimes.push_back(
"hwasan-preinit");
1500 SharedRuntimes.push_back(
"rtsan");
1505 StaticRuntimes.push_back(
"stats_client");
1509 HelperStaticRuntimes.push_back(
"asan_static");
1512 if (Args.hasArg(options::OPT_shared)) {
1521 StaticRuntimes.push_back(
"asan");
1523 StaticRuntimes.push_back(
"asan_cxx");
1528 StaticRuntimes.push_back(
"rtsan");
1531 StaticRuntimes.push_back(
"memprof");
1533 StaticRuntimes.push_back(
"memprof_cxx");
1538 StaticRuntimes.push_back(
"hwasan_aliases");
1540 StaticRuntimes.push_back(
"hwasan_aliases_cxx");
1542 StaticRuntimes.push_back(
"hwasan");
1544 StaticRuntimes.push_back(
"hwasan_cxx");
1548 StaticRuntimes.push_back(
"dfsan");
1550 StaticRuntimes.push_back(
"lsan");
1552 StaticRuntimes.push_back(
"msan");
1554 StaticRuntimes.push_back(
"msan_cxx");
1557 StaticRuntimes.push_back(
"nsan");
1559 StaticRuntimes.push_back(
"tsan");
1561 StaticRuntimes.push_back(
"tsan_cxx");
1564 StaticRuntimes.push_back(
"tysan");
1567 StaticRuntimes.push_back(
"ubsan_minimal");
1569 StaticRuntimes.push_back(
"ubsan_standalone");
1573 NonWholeStaticRuntimes.push_back(
"safestack");
1574 RequiredSymbols.push_back(
"__safestack_init");
1578 StaticRuntimes.push_back(
"cfi");
1580 StaticRuntimes.push_back(
"cfi_diag");
1585 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
1588 NonWholeStaticRuntimes.push_back(
"stats");
1589 RequiredSymbols.push_back(
"__sanitizer_stats_register");
1592 StaticRuntimes.push_back(
"scudo_standalone");
1594 StaticRuntimes.push_back(
"scudo_standalone_cxx");
1601 ArgStringList &CmdArgs) {
1604 NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
1607 NonWholeStaticRuntimes, HelperStaticRuntimes,
1612 for (
auto S : RequiredSymbols) {
1613 CmdArgs.push_back(
"-u");
1614 CmdArgs.push_back(Args.MakeArgString(S));
1619 !Args.hasArg(options::OPT_shared)) {
1625 if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx)) {
1626 bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
1627 !Args.hasArg(options::OPT_static);
1628 if (OnlyLibstdcxxStatic)
1629 CmdArgs.push_back(
"-Bstatic");
1631 if (OnlyLibstdcxxStatic)
1632 CmdArgs.push_back(
"-Bdynamic");
1636 for (
auto RT : SharedRuntimes)
1638 for (
auto RT : HelperStaticRuntimes)
1640 bool AddExportDynamic =
false;
1641 for (
auto RT : StaticRuntimes) {
1645 for (
auto RT : NonWholeStaticRuntimes) {
1651 if (AddExportDynamic)
1652 CmdArgs.push_back(
"--export-dynamic");
1655 CmdArgs.push_back(
"--export-dynamic-symbol=__cfi_check");
1659 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1660 <<
"-fsanitize=memtag*" << TC.
getTriple().str();
1663 Args.MakeArgString(
"--android-memtag-mode=" + SanArgs.
getMemtagMode()));
1665 CmdArgs.push_back(
"--android-memtag-heap");
1667 CmdArgs.push_back(
"--android-memtag-stack");
1670 return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
1674 if (Args.hasArg(options::OPT_shared)) {
1676 CmdArgs.push_back(
"--whole-archive");
1678 CmdArgs.push_back(
"--no-whole-archive");
1682 CmdArgs.push_back(
"--whole-archive");
1686 CmdArgs.push_back(
"--no-whole-archive");
1694 const llvm::opt::ArgList &Args,
1695 ArgStringList &CmdArgs) {
1697 CmdArgs.push_back(
"-lpthread");
1699 CmdArgs.push_back(
"-lrt");
1700 CmdArgs.push_back(
"-lm");
1705 CmdArgs.push_back(
"-ldl");
1710 if (Arg *A = Args.getLastArg(options::OPT_O_Group))
1711 return !A->getOption().matches(options::OPT_O0);
1719 auto AddPostfix = [JA](
auto &F) {
1724 if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
1725 if (StringRef(A->getValue()) ==
"single" && Output.
isFilename())
1729 if (
const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
1732 Arg *FinalOutput = Args.getLastArg(options::OPT_o, options::OPT__SLASH_o);
1733 if (FinalOutput && Args.hasArg(options::OPT_c)) {
1734 T = FinalOutput->getValue();
1735 llvm::sys::path::remove_filename(
T);
1736 llvm::sys::path::append(
T,
1737 llvm::sys::path::stem(FinalOutput->getValue()));
1739 return Args.MakeArgString(
T);
1745 return Args.MakeArgString(
T);
1749 const JobAction &JA,
const ArgList &Args,
1750 const InputInfo &Output,
const char *OutFile) {
1751 ArgStringList ExtractArgs;
1752 ExtractArgs.push_back(
"--extract-dwo");
1754 ArgStringList StripArgs;
1755 StripArgs.push_back(
"--strip-dwo");
1760 ExtractArgs.push_back(OutFile);
1767 C.addCommand(std::make_unique<Command>(JA,
T,
1769 Exec, ExtractArgs, II, Output));
1772 C.addCommand(std::make_unique<Command>(
1782 Args.ClaimAllArgs(options::OPT_flto_EQ);
1783 Args.ClaimAllArgs(options::OPT_flto);
1784 Args.ClaimAllArgs(options::OPT_fno_lto);
1788 auto *CSPGOGenerateArg = Args.getLastArg(options::OPT_fcs_profile_generate,
1789 options::OPT_fcs_profile_generate_EQ,
1790 options::OPT_fno_profile_generate);
1791 if (CSPGOGenerateArg &&
1792 CSPGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
1793 CSPGOGenerateArg =
nullptr;
1795 return CSPGOGenerateArg;
1799 auto *ProfileUseArg = Args.getLastArg(
1800 options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
1801 options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
1802 options::OPT_fno_profile_instr_use);
1804 if (ProfileUseArg &&
1805 ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
1806 ProfileUseArg =
nullptr;
1808 return ProfileUseArg;
1812 auto *ProfileSampleUseArg = Args.getLastArg(
1813 options::OPT_fprofile_sample_use_EQ, options::OPT_fno_profile_sample_use);
1815 if (ProfileSampleUseArg && (ProfileSampleUseArg->getOption().matches(
1816 options::OPT_fno_profile_sample_use)))
1819 return Args.getLastArg(options::OPT_fprofile_sample_use_EQ);
1824 case llvm::Reloc::Static:
1826 case llvm::Reloc::PIC_:
1828 case llvm::Reloc::DynamicNoPIC:
1829 return "dynamic-no-pic";
1830 case llvm::Reloc::ROPI:
1832 case llvm::Reloc::RWPI:
1834 case llvm::Reloc::ROPI_RWPI:
1837 llvm_unreachable(
"Unknown Reloc::Model kind");
1844std::tuple<llvm::Reloc::Model, unsigned, bool>
1852 if (Triple.isOSBinFormatMachO() && Args.hasArg(options::OPT_static))
1854 bool IsPICLevelTwo = PIC;
1857 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
1860 if (Triple.isAndroid()) {
1861 switch (Triple.getArch()) {
1862 case llvm::Triple::arm:
1863 case llvm::Triple::armeb:
1864 case llvm::Triple::thumb:
1865 case llvm::Triple::thumbeb:
1866 case llvm::Triple::aarch64:
1867 case llvm::Triple::mips:
1868 case llvm::Triple::mipsel:
1869 case llvm::Triple::mips64:
1870 case llvm::Triple::mips64el:
1874 case llvm::Triple::x86:
1875 case llvm::Triple::x86_64:
1877 IsPICLevelTwo =
true;
1886 if (Triple.isOHOSFamily() && Triple.getArch() == llvm::Triple::aarch64)
1890 if (Triple.isOSOpenBSD()) {
1892 case llvm::Triple::arm:
1893 case llvm::Triple::aarch64:
1894 case llvm::Triple::mips64:
1895 case llvm::Triple::mips64el:
1896 case llvm::Triple::x86:
1897 case llvm::Triple::x86_64:
1898 IsPICLevelTwo =
false;
1901 case llvm::Triple::ppc:
1902 case llvm::Triple::sparcv9:
1903 IsPICLevelTwo =
true;
1915 Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
1916 options::OPT_fpic, options::OPT_fno_pic,
1917 options::OPT_fPIE, options::OPT_fno_PIE,
1918 options::OPT_fpie, options::OPT_fno_pie);
1919 if (Triple.isOSWindows() && !Triple.isOSCygMing() && LastPICArg &&
1920 LastPICArg == Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
1921 options::OPT_fPIE, options::OPT_fpie)) {
1923 << LastPICArg->getSpelling() << Triple.str();
1924 if (Triple.getArch() == llvm::Triple::x86_64)
1925 return std::make_tuple(llvm::Reloc::PIC_, 2U,
false);
1926 return std::make_tuple(llvm::Reloc::Static, 0
U,
false);
1933 Option O = LastPICArg->getOption();
1934 if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) ||
1935 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) {
1936 PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie);
1938 PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic);
1940 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fPIC);
1943 if (EffectiveTriple.isPS()) {
1944 Arg *ModelArg = Args.getLastArg(options::OPT_mcmodel_EQ);
1945 StringRef Model = ModelArg ? ModelArg->getValue() :
"";
1946 if (Model !=
"kernel") {
1949 << LastPICArg->getSpelling()
1950 << (EffectiveTriple.isPS4() ?
"PS4" :
"PS5");
1960 if (PIC && (Triple.isOSDarwin() || EffectiveTriple.isPS()))
1966 ((!EffectiveTriple.isiOS() || EffectiveTriple.isOSVersionLT(6)) &&
1967 !EffectiveTriple.isWatchOS() && !EffectiveTriple.isDriverKit()))
1970 if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
1973 if (!Triple.isOSDarwin())
1975 << A->getSpelling() << Triple.str();
1984 return std::make_tuple(llvm::Reloc::DynamicNoPIC, PIC ? 2U : 0
U,
false);
1987 bool EmbeddedPISupported;
1988 switch (Triple.getArch()) {
1989 case llvm::Triple::arm:
1990 case llvm::Triple::armeb:
1991 case llvm::Triple::thumb:
1992 case llvm::Triple::thumbeb:
1993 EmbeddedPISupported =
true;
1996 EmbeddedPISupported =
false;
2000 bool ROPI =
false, RWPI =
false;
2001 Arg* LastROPIArg = Args.getLastArg(options::OPT_fropi, options::OPT_fno_ropi);
2002 if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
2003 if (!EmbeddedPISupported)
2005 << LastROPIArg->getSpelling() << Triple.str();
2008 Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
2009 if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
2010 if (!EmbeddedPISupported)
2012 << LastRWPIArg->getSpelling() << Triple.str();
2017 if ((ROPI || RWPI) && (PIC || PIE))
2020 if (Triple.isMIPS()) {
2027 if (ABIName ==
"n64")
2030 if(Args.hasArg(options::OPT_mno_abicalls))
2031 return std::make_tuple(llvm::Reloc::Static, 0
U,
false);
2034 IsPICLevelTwo =
false;
2038 return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE);
2040 llvm::Reloc::Model RelocM = llvm::Reloc::Static;
2042 RelocM = llvm::Reloc::ROPI_RWPI;
2044 RelocM = llvm::Reloc::ROPI;
2046 RelocM = llvm::Reloc::RWPI;
2048 return std::make_tuple(RelocM, 0
U,
false);
2068 const ArgList &Args) {
2069 const Arg *A = Args.getLastArg(options::OPT_falign_functions,
2070 options::OPT_falign_functions_EQ,
2071 options::OPT_fno_align_functions);
2072 if (!A || A->getOption().matches(options::OPT_fno_align_functions))
2075 if (A->getOption().matches(options::OPT_falign_functions))
2079 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
2081 << A->getAsString(Args) << A->getValue();
2086 ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind) {
2087 switch (DebugInfoKind) {
2088 case llvm::codegenoptions::DebugDirectivesOnly:
2089 CmdArgs.push_back(
"-debug-info-kind=line-directives-only");
2091 case llvm::codegenoptions::DebugLineTablesOnly:
2092 CmdArgs.push_back(
"-debug-info-kind=line-tables-only");
2094 case llvm::codegenoptions::DebugInfoConstructor:
2095 CmdArgs.push_back(
"-debug-info-kind=constructor");
2097 case llvm::codegenoptions::LimitedDebugInfo:
2098 CmdArgs.push_back(
"-debug-info-kind=limited");
2100 case llvm::codegenoptions::FullDebugInfo:
2101 CmdArgs.push_back(
"-debug-info-kind=standalone");
2103 case llvm::codegenoptions::UnusedTypeInfo:
2104 CmdArgs.push_back(
"-debug-info-kind=unused-types");
2114 assert(A.getOption().matches(options::OPT_gN_Group) &&
2115 "Not a -g option that specifies a debug-info level");
2116 if (A.getOption().matches(options::OPT_g0) ||
2117 A.getOption().matches(options::OPT_ggdb0))
2118 return llvm::codegenoptions::NoDebugInfo;
2119 if (A.getOption().matches(options::OPT_gline_tables_only) ||
2120 A.getOption().matches(options::OPT_ggdb1))
2121 return llvm::codegenoptions::DebugLineTablesOnly;
2122 if (A.getOption().matches(options::OPT_gline_directives_only))
2123 return llvm::codegenoptions::DebugDirectivesOnly;
2124 return llvm::codegenoptions::DebugInfoConstructor;
2128 const ArgList &Args) {
2129 const Arg *A = Args.getLastArg(options::OPT_fdebug_default_version);
2135 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 5 ||
2138 << A->getAsString(Args) << A->getValue();
2143 return llvm::StringSwitch<unsigned>(ArgValue)
2144 .Case(
"-gdwarf-2", 2)
2145 .Case(
"-gdwarf-3", 3)
2146 .Case(
"-gdwarf-4", 4)
2147 .Case(
"-gdwarf-5", 5)
2152 return Args.getLastArg(options::OPT_gdwarf_2, options::OPT_gdwarf_3,
2153 options::OPT_gdwarf_4, options::OPT_gdwarf_5,
2154 options::OPT_gdwarf);
2158 const llvm::opt::ArgList &Args) {
2163 if (DwarfVersion == 5 && TC.
getTriple().isOSAIX())
2164 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
2165 << GDwarfN->getSpelling() << TC.
getTriple().str();
2167 if (DwarfVersion == 0) {
2169 assert(DwarfVersion &&
"toolchain default DWARF version must be nonzero");
2171 return DwarfVersion;
2175 ArgStringList &CmdArgs) {
2176 llvm::Reloc::Model RelocationModel;
2181 if (RelocationModel != llvm::Reloc::Static)
2182 CmdArgs.push_back(
"-KPIC");
2188 return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc,
false);
2194 const ArgList &Args) {
2195 if (Args.hasArg(options::OPT_static_libgcc) ||
2196 Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_pie) ||
2200 if (Args.hasArg(options::OPT_shared_libgcc))
2219 ArgStringList &CmdArgs,
const ArgList &Args) {
2223 CmdArgs.push_back(
"-l:libunwind.a");
2246 CmdArgs.push_back(
"-lgcc_eh");
2248 CmdArgs.push_back(
"-lgcc_s");
2256 CmdArgs.push_back(
"-lunwind");
2258 CmdArgs.push_back(
"-l:libunwind.a");
2261 CmdArgs.push_back(
"-l:libunwind.dll.a");
2263 CmdArgs.push_back(
"-l:libunwind.so");
2267 CmdArgs.push_back(
"-lunwind");
2277 ArgStringList &CmdArgs,
const ArgList &Args) {
2281 CmdArgs.push_back(
"-lgcc");
2285 CmdArgs.push_back(
"-lgcc");
2289 ArgStringList &CmdArgs,
const ArgList &Args) {
2300 if (TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
2303 Arg *A = Args.getLastArg(options::OPT_rtlib_EQ);
2304 if (A && A->getValue() != StringRef(
"platform")) {
2305 TC.
getDriver().
Diag(diag::err_drv_unsupported_rtlib_for_platform)
2306 << A->getValue() <<
"MSVC";
2316 if (TC.
getTriple().isAndroid() && !Args.hasArg(options::OPT_static) &&
2317 !Args.hasArg(options::OPT_static_pie))
2318 CmdArgs.push_back(
"-ldl");
2325 const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ);
2326 if (!A && !
D.CCPrintInternalStats)
2331 StringRef SaveStats = A->getValue();
2332 if (SaveStats ==
"obj" && Output.
isFilename()) {
2334 llvm::sys::path::remove_filename(StatsFile);
2335 }
else if (SaveStats !=
"cwd") {
2336 D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats;
2340 StringRef BaseName = llvm::sys::path::filename(Input.
getBaseInput());
2341 llvm::sys::path::append(StatsFile, BaseName);
2342 llvm::sys::path::replace_extension(StatsFile,
"stats");
2344 assert(
D.CCPrintInternalStats);
2345 StatsFile.assign(
D.CCPrintInternalStatReportFilename.empty()
2347 :
D.CCPrintInternalStatReportFilename);
2354 assert(Flag.front() ==
'-');
2356 Flags.push_back(Flag.str());
2358 Flags.push_back((
"!" + Flag.substr(1)).str());
2363 ArgStringList &CmdArgs,
bool IsLTO,
2364 const StringRef PluginOptPrefix) {
2365 auto addArg = [&, IsLTO](
const Twine &Arg) {
2367 assert(!PluginOptPrefix.empty() &&
"Cannot have empty PluginOptPrefix!");
2368 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + Arg));
2370 CmdArgs.push_back(
"-mllvm");
2371 CmdArgs.push_back(Args.MakeArgString(Arg));
2375 if (Args.hasArg(options::OPT_mbranches_within_32B_boundaries)) {
2376 addArg(Twine(
"-x86-branches-within-32B-boundaries"));
2378 if (
const Arg *A = Args.getLastArg(options::OPT_malign_branch_boundary_EQ)) {
2379 StringRef
Value = A->getValue();
2381 if (
Value.getAsInteger(10, Boundary) || Boundary < 16 ||
2382 !llvm::isPowerOf2_64(Boundary)) {
2383 D.Diag(diag::err_drv_invalid_argument_to_option)
2384 <<
Value << A->getOption().getName();
2386 addArg(
"-x86-align-branch-boundary=" + Twine(Boundary));
2389 if (
const Arg *A = Args.getLastArg(options::OPT_malign_branch_EQ)) {
2390 std::string AlignBranch;
2391 for (StringRef
T : A->getValues()) {
2392 if (
T !=
"fused" &&
T !=
"jcc" &&
T !=
"jmp" &&
T !=
"call" &&
2393 T !=
"ret" &&
T !=
"indirect")
2394 D.Diag(diag::err_drv_invalid_malign_branch_EQ)
2395 <<
T <<
"fused, jcc, jmp, call, ret, indirect";
2396 if (!AlignBranch.empty())
2400 addArg(
"-x86-align-branch=" + Twine(AlignBranch));
2402 if (
const Arg *A = Args.getLastArg(options::OPT_mpad_max_prefix_size_EQ)) {
2403 StringRef
Value = A->getValue();
2404 unsigned PrefixSize;
2405 if (
Value.getAsInteger(10, PrefixSize)) {
2406 D.Diag(diag::err_drv_invalid_argument_to_option)
2407 <<
Value << A->getOption().getName();
2409 addArg(
"-x86-pad-max-prefix-size=" + Twine(PrefixSize));
2435 llvm::opt::ArgStringList &CC1Args,
2437 StringRef Lib, StringRef Arch, StringRef
Target,
2438 bool isBitCodeSDL) {
2441 std::string LibDeviceLoc =
"/libdevice";
2442 std::string LibBcPrefix =
"/libbc-";
2443 std::string LibPrefix =
"/lib";
2460 for (StringRef
Base : {LibBcPrefix, LibPrefix}) {
2461 const auto *Ext =
Base.contains(LibBcPrefix) ?
".a" :
".bc";
2463 for (
auto Suffix : {Twine(Lib +
"-" + Arch +
"-" +
Target).str(),
2464 Twine(Lib +
"-" + Arch).str(), Twine(Lib).str()}) {
2465 SDLs.push_back(Twine(LibDeviceLoc +
Base + Suffix + Ext).str());
2466 SDLs.push_back(Twine(
Base + Suffix + Ext).str());
2476 const auto *Ext =
".a";
2478 for (
auto Suffix : {Twine(Lib +
"-" + Arch +
"-" +
Target).str(),
2479 Twine(Lib +
"-" + Arch).str()}) {
2480 SDLs.push_back(Twine(LibDeviceLoc + LibPrefix + Suffix + Ext).str());
2481 SDLs.push_back(Twine(LibPrefix + Suffix + Ext).str());
2492 bool FoundSDL =
false;
2493 for (
auto LPath : LibraryPaths) {
2494 for (
auto SDL : SDLs) {
2495 auto FullName = Twine(LPath + SDL).str();
2496 if (llvm::sys::fs::exists(
FullName)) {
2497 CC1Args.push_back(DriverArgs.MakeArgString(
FullName));
2514 const InputInfoList &Inputs,
const llvm::opt::ArgList &DriverArgs,
2515 llvm::opt::ArgStringList &CC1Args,
2517 StringRef Arch, StringRef
Target,
bool isBitCodeSDL) {
2520 if (isBitCodeSDL && Arch.contains(
"nvptx"))
2523 bool FoundAOB =
false;
2524 std::string ArchiveOfBundles;
2526 llvm::Triple Triple(
D.getTargetTriple());
2527 bool IsMSVC = Triple.isWindowsMSVCEnvironment();
2528 auto Ext = IsMSVC ?
".lib" :
".a";
2529 if (!Lib.starts_with(
":") && !Lib.starts_with(
"-l")) {
2530 if (llvm::sys::fs::exists(Lib)) {
2531 ArchiveOfBundles = Lib;
2535 Lib.consume_front(
"-l");
2536 for (
auto LPath : LibraryPaths) {
2537 ArchiveOfBundles.clear();
2538 auto LibFile = (Lib.starts_with(
":") ? Lib.drop_front()
2539 : IsMSVC ? Lib + Ext
2540 :
"lib" + Lib + Ext)
2542 for (
auto Prefix : {
"/libdevice/",
"/"}) {
2543 auto AOB = Twine(LPath + Prefix + LibFile).str();
2544 if (llvm::sys::fs::exists(AOB)) {
2545 ArchiveOfBundles = AOB;
2558 llvm::file_magic Magic;
2559 auto EC = llvm::identify_magic(ArchiveOfBundles, Magic);
2560 if (EC || Magic != llvm::file_magic::archive)
2563 StringRef Prefix = isBitCodeSDL ?
"libbc-" :
"lib";
2564 std::string OutputLib =
2565 D.GetTemporaryPath(Twine(Prefix + llvm::sys::path::filename(Lib) +
"-" +
2570 C.addTempFile(
C.getArgs().MakeArgString(OutputLib));
2572 ArgStringList CmdArgs;
2575 DeviceTriple +=
'-';
2576 std::string NormalizedTriple =
T.getToolChain().getTriple().normalize();
2577 DeviceTriple += NormalizedTriple;
2579 DeviceTriple +=
'-';
2583 std::string UnbundleArg(
"-unbundle");
2584 std::string TypeArg(
"-type=a");
2585 std::string InputArg(
"-input=" + ArchiveOfBundles);
2586 std::string OffloadArg(
"-targets=" + std::string(DeviceTriple));
2587 std::string OutputArg(
"-output=" + OutputLib);
2589 const char *UBProgram = DriverArgs.MakeArgString(
2590 T.getToolChain().GetProgramPath(
"clang-offload-bundler"));
2592 ArgStringList UBArgs;
2593 UBArgs.push_back(
C.getArgs().MakeArgString(UnbundleArg));
2594 UBArgs.push_back(
C.getArgs().MakeArgString(TypeArg));
2595 UBArgs.push_back(
C.getArgs().MakeArgString(InputArg));
2596 UBArgs.push_back(
C.getArgs().MakeArgString(OffloadArg));
2597 UBArgs.push_back(
C.getArgs().MakeArgString(OutputArg));
2601 std::string AdditionalArgs(
"-allow-missing-bundles");
2602 UBArgs.push_back(
C.getArgs().MakeArgString(AdditionalArgs));
2607 std::string HipCompatibleArgs(
"-hip-openmp-compatible");
2608 UBArgs.push_back(
C.getArgs().MakeArgString(HipCompatibleArgs));
2610 C.addCommand(std::make_unique<Command>(
2612 InputInfo(&JA,
C.getArgs().MakeArgString(OutputLib))));
2614 CC1Args.push_back(DriverArgs.MakeArgString(OutputLib));
2623 const llvm::opt::ArgList &DriverArgs,
2624 llvm::opt::ArgStringList &CC1Args,
2625 StringRef Arch, StringRef
Target,
2626 bool isBitCodeSDL) {
2628 Arch,
Target, isBitCodeSDL);
2657 const llvm::opt::ArgList &DriverArgs,
2658 llvm::opt::ArgStringList &CC1Args,
2659 StringRef Arch, StringRef
Target,
2660 bool isBitCodeSDL) {
2664 std::optional<std::string> LibPath =
2665 llvm::sys::Process::GetEnv(
"LIBRARY_PATH");
2668 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator,
'\0'};
2669 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
2670 for (StringRef
Path : Frags)
2671 LibraryPaths.emplace_back(
Path.trim());
2675 for (std::string Search_Dir : DriverArgs.getAllArgValues(options::OPT_L))
2676 LibraryPaths.emplace_back(Search_Dir);
2680 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
2681 LibraryPaths.emplace_back(DefaultLibPath.c_str());
2684 llvm::SmallSet<std::string, 16> SDLNames;
2685 static const StringRef HostOnlyArchives[] = {
2686 "omp",
"cudart",
"m",
"gcc",
"gcc_s",
"pthread",
"hip_hcc"};
2687 for (
auto SDLName : DriverArgs.getAllArgValues(options::OPT_l)) {
2688 if (!llvm::is_contained(HostOnlyArchives, SDLName)) {
2689 SDLNames.insert(std::string(
"-l") + SDLName);
2693 for (
auto Input : DriverArgs.getAllArgValues(options::OPT_INPUT)) {
2700 const StringRef LibFileExt =
".lib";
2701 if (!llvm::sys::path::has_extension(
FileName) ||
2703 llvm::sys::path::extension(
FileName).drop_front()) ==
2705 llvm::sys::path::extension(
FileName) == LibFileExt)
2706 SDLNames.insert(Input);
2713 for (
auto SDLName : SDLNames) {
2715 if (!
SDLSearch(
D, DriverArgs, CC1Args, LibraryPaths, SDLName, Arch,
Target,
2718 LibraryPaths, SDLName, Arch,
Target,
2724static llvm::opt::Arg *
2726 return Args.getLastArg(options::OPT_mcode_object_version_EQ);
2730 const llvm::opt::ArgList &Args) {
2731 const unsigned MinCodeObjVer = 4;
2732 const unsigned MaxCodeObjVer = 6;
2735 if (CodeObjArg->getOption().getID() ==
2736 options::OPT_mcode_object_version_EQ) {
2737 unsigned CodeObjVer = MaxCodeObjVer;
2739 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
2740 if (Remnant || CodeObjVer < MinCodeObjVer || CodeObjVer > MaxCodeObjVer)
2741 D.Diag(diag::err_drv_invalid_int_value)
2742 << CodeObjArg->getAsString(Args) << CodeObjArg->getValue();
2747 if (CodeObjVer == 6)
2748 D.Diag(diag::warn_drv_amdgpu_cov6);
2754 const llvm::opt::ArgList &Args) {
2755 unsigned CodeObjVer = 5;
2757 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
2762 const Driver &
D,
const llvm::opt::ArgList &Args) {
2767 const llvm::opt::ArgList &Args,
2768 llvm::opt::ArgStringList &CmdArgs,
2769 const llvm::Triple &Triple,
bool IsLTO,
2770 const StringRef PluginOptPrefix) {
2771 auto addArg = [&, IsLTO](
const Twine &Arg) {
2773 assert(!PluginOptPrefix.empty() &&
"Cannot have empty PluginOptPrefix!");
2774 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + Arg));
2776 CmdArgs.push_back(
"-mllvm");
2777 CmdArgs.push_back(Args.MakeArgString(Arg));
2781 if (Arg *A = Args.getLastArg(options::OPT_moutline,
2782 options::OPT_mno_outline)) {
2783 if (A->getOption().matches(options::OPT_moutline)) {
2787 if (!(Triple.isARM() || Triple.isThumb() || Triple.isAArch64())) {
2788 D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
2790 addArg(Twine(
"-enable-machine-outliner"));
2794 addArg(Twine(
"-enable-machine-outliner=never"));
2798 auto *CodeGenDataGenArg =
2799 Args.getLastArg(options::OPT_fcodegen_data_generate_EQ);
2800 auto *CodeGenDataUseArg = Args.getLastArg(options::OPT_fcodegen_data_use_EQ);
2803 if (CodeGenDataGenArg && CodeGenDataUseArg)
2804 D.Diag(diag::err_drv_argument_not_allowed_with)
2805 << CodeGenDataGenArg->getAsString(Args)
2806 << CodeGenDataUseArg->getAsString(Args);
2810 if (CodeGenDataGenArg)
2811 addArg(Twine(
"-codegen-data-generate"));
2814 if (CodeGenDataUseArg)
2815 addArg(Twine(
"-codegen-data-use-path=") + CodeGenDataUseArg->getValue());
2819 const llvm::opt::ArgList &DriverArgs,
2820 llvm::opt::ArgStringList &CC1Args,
2821 StringRef BitcodeSuffix,
2822 const llvm::Triple &Triple,
2827 std::optional<std::string> LibPath =
2828 llvm::sys::Process::GetEnv(
"LIBRARY_PATH");
2831 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator,
'\0'};
2832 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
2833 for (StringRef
Path : Frags)
2834 LibraryPaths.emplace_back(
Path.trim());
2839 LibraryPaths.emplace_back(LibPath);
2841 OptSpecifier LibomptargetBCPathOpt =
2842 Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
2843 : options::OPT_libomptarget_nvptx_bc_path_EQ;
2845 StringRef ArchPrefix = Triple.isAMDGCN() ?
"amdgpu" :
"nvptx";
2846 std::string LibOmpTargetName = (
"libomptarget-" + ArchPrefix +
".bc").str();
2849 if (
const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
2851 if (llvm::sys::fs::exists(LibOmpTargetFile) &&
2852 llvm::sys::fs::is_directory(LibOmpTargetFile)) {
2853 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
2856 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
2857 CC1Args.push_back(
"-mlink-builtin-bitcode");
2858 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
2860 D.Diag(diag::err_drv_omp_offload_target_bcruntime_not_found)
2861 << LibOmpTargetFile;
2864 bool FoundBCLibrary =
false;
2866 for (StringRef LibraryPath : LibraryPaths) {
2868 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
2869 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
2870 CC1Args.push_back(
"-mlink-builtin-bitcode");
2871 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
2872 FoundBCLibrary =
true;
2877 if (!FoundBCLibrary)
2878 D.Diag(diag::err_drv_omp_offload_target_missingbcruntime)
2879 << LibOmpTargetName << ArchPrefix;
2883 const llvm::opt::ArgList &Args,
2884 llvm::opt::ArgStringList &CmdArgs) {
2886 !Args.hasArg(options::OPT_nostdlib) &&
2887 !Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
2891 for (
auto *Arg : Args.filtered(options::OPT_no_hip_rt)) {
2898 const llvm::opt::ArgList &Args,
2899 llvm::opt::ArgStringList &CmdArgs,
2900 const llvm::Triple &Triple) {
2901 if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
2902 options::OPT_mno_outline_atomics)) {
2904 if (!Triple.isAArch64()) {
2905 D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
2906 << Triple.getArchName() << A->getOption().getName();
2908 if (A->getOption().matches(options::OPT_moutline_atomics)) {
2909 CmdArgs.push_back(
"-target-feature");
2910 CmdArgs.push_back(
"+outline-atomics");
2912 CmdArgs.push_back(
"-target-feature");
2913 CmdArgs.push_back(
"-outline-atomics");
2917 CmdArgs.push_back(
"-target-feature");
2918 CmdArgs.push_back(
"+outline-atomics");
2923 llvm::opt::ArgStringList &CmdArgs) {
2924 if (TCArgs.hasFlag(options::OPT_offload_compress,
2925 options::OPT_no_offload_compress,
false))
2926 CmdArgs.push_back(
"-compress");
2927 if (TCArgs.hasArg(options::OPT_v))
2928 CmdArgs.push_back(
"-verbose");
2929 if (
auto *Arg = TCArgs.getLastArg(options::OPT_offload_compression_level_EQ))
2931 TCArgs.MakeArgString(Twine(
"-compression-level=") + Arg->getValue()));
2935 const llvm::Triple &Triple,
2936 const llvm::Reloc::Model &RelocationModel,
2937 llvm::opt::ArgStringList &CmdArgs) {
2938 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
2939 StringRef CM = A->getValue();
2941 if (Triple.isOSAIX() && CM ==
"medium")
2943 if (Triple.isAArch64(64)) {
2944 Ok = CM ==
"tiny" || CM ==
"small" || CM ==
"large";
2945 if (CM ==
"large" && !Triple.isOSBinFormatMachO() &&
2946 RelocationModel != llvm::Reloc::Static)
2947 D.Diag(diag::err_drv_argument_only_allowed_with)
2948 << A->getAsString(Args) <<
"-fno-pic";
2949 }
else if (Triple.isLoongArch()) {
2950 if (CM ==
"extreme" &&
2951 Args.hasFlagNoClaim(options::OPT_fplt, options::OPT_fno_plt,
false))
2952 D.Diag(diag::err_drv_argument_not_allowed_with)
2953 << A->getAsString(Args) <<
"-fplt";
2954 Ok = CM ==
"normal" || CM ==
"medium" || CM ==
"extreme";
2957 CM = llvm::StringSwitch<StringRef>(CM)
2958 .Case(
"normal",
"small")
2959 .Case(
"extreme",
"large")
2961 }
else if (Triple.isPPC64() || Triple.isOSAIX()) {
2962 Ok = CM ==
"small" || CM ==
"medium" || CM ==
"large";
2963 }
else if (Triple.isRISCV()) {
2965 if (CM ==
"large" && RelocationModel != llvm::Reloc::Static)
2966 D.Diag(diag::err_drv_argument_not_allowed_with)
2967 << A->getAsString(Args) <<
"-fpic";
2970 else if (CM ==
"medany")
2972 Ok = CM ==
"small" || CM ==
"medium" ||
2973 (CM ==
"large" && Triple.isRISCV64());
2974 }
else if (Triple.getArch() == llvm::Triple::x86_64) {
2975 Ok = llvm::is_contained({
"small",
"kernel",
"medium",
"large",
"tiny"},
2977 }
else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
2981 }
else if (Triple.isSPARC64()) {
2984 else if (CM ==
"medmid")
2986 else if (CM ==
"medany")
2988 Ok = CM ==
"small" || CM ==
"medium" || CM ==
"large";
2991 CmdArgs.push_back(Args.MakeArgString(
"-mcmodel=" + CM));
2993 D.Diag(diag::err_drv_unsupported_option_argument_for_target)
2994 << A->getSpelling() << CM << Triple.getTriple();
2998 if (Triple.getArch() == llvm::Triple::x86_64) {
2999 bool IsMediumCM =
false;
3000 bool IsLargeCM =
false;
3001 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
3002 IsMediumCM = StringRef(A->getValue()) ==
"medium";
3003 IsLargeCM = StringRef(A->getValue()) ==
"large";
3005 if (Arg *A = Args.getLastArg(options::OPT_mlarge_data_threshold_EQ)) {
3006 if (!IsMediumCM && !IsLargeCM) {
3007 D.Diag(diag::warn_drv_large_data_threshold_invalid_code_model)
3008 << A->getOption().getRenderName();
3010 A->render(Args, CmdArgs);
3012 }
else if (IsMediumCM) {
3013 CmdArgs.push_back(
"-mlarge-data-threshold=65536");
3014 }
else if (IsLargeCM) {
3015 CmdArgs.push_back(
"-mlarge-data-threshold=0");
3021 ArgStringList &CmdArgs) {
3026 Args.getLastArg(options::OPT_fcolor_diagnostics,
3027 options::OPT_fno_color_diagnostics);
3028 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
3029 StringRef
Value(A->getValue());
3031 D.Diag(diag::err_drv_invalid_argument_to_option)
3032 <<
Value << A->getOption().getName();
3035 if (
D.getDiags().getDiagnosticOptions().ShowColors)
3036 CmdArgs.push_back(
"-fcolor-diagnostics");
3041 for (; *Arg; ++Arg) {
3047 Res.push_back(
'\\');
3050 Res.push_back(*Arg);
3055 const llvm::opt::ArgList &Args) {
3057 const char *Exec =
D.getClangProgramPath();
3059 llvm::opt::ArgStringList OriginalArgs;
3060 for (
const auto &Arg : Args)
3061 Arg->render(Args, OriginalArgs);
3065 for (
const char *OriginalArg : OriginalArgs) {
3069 Flags += EscapedArg;
3072 return Args.MakeArgString(Flags);
3076 const llvm::opt::ArgList &Args,
3077 bool &FRecordCommandLine,
3078 bool &GRecordCommandLine) {
3081 const std::string &TripleStr = Triple.getTriple();
3083 FRecordCommandLine =
3084 Args.hasFlag(options::OPT_frecord_command_line,
3085 options::OPT_fno_record_command_line,
false);
3086 GRecordCommandLine =
3087 Args.hasFlag(options::OPT_grecord_command_line,
3088 options::OPT_gno_record_command_line,
false);
3089 if (FRecordCommandLine && !Triple.isOSBinFormatELF() &&
3090 !Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
3091 D.Diag(diag::err_drv_unsupported_opt_for_target)
3092 << Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
3099 ArgStringList &CmdArgs) {
3102 if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
3103 if (A->getOption().matches(options::OPT_fwrapv))
3104 CmdArgs.push_back(
"-fwrapv");
3105 }
else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
3106 options::OPT_fno_strict_overflow)) {
3107 if (A->getOption().matches(options::OPT_fno_strict_overflow))
3108 CmdArgs.push_back(
"-fwrapv");
static bool useLeafFramePointerForTargetByDefault(const llvm::Triple &Triple)
static unsigned ParseDebugDefaultVersion(const ToolChain &TC, const ArgList &Args)
static void getWebAssemblyTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector< StringRef > &Features)
static bool addSanitizerDynamicList(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer)
static bool mustMaintainValidFrameChain(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static llvm::opt::Arg * getAMDGPUCodeObjectArgument(const Driver &D, const llvm::opt::ArgList &Args)
static void collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, SmallVectorImpl< StringRef > &SharedRuntimes, SmallVectorImpl< StringRef > &StaticRuntimes, SmallVectorImpl< StringRef > &NonWholeStaticRuntimes, SmallVectorImpl< StringRef > &HelperStaticRuntimes, SmallVectorImpl< StringRef > &RequiredSymbols)
static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer, bool IsShared, bool IsWhole)
static void AddUnwindLibrary(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
static bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const SmallVectorImpl< std::string > &LibraryPaths, StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL)
SDLSearch: Search for Static Device Library The search for SDL bitcode files is consistent with how s...
static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs, const StringRef PluginOptPrefix)
static StringRef getWebAssemblyTargetCPU(const ArgList &Args)
Get the (LLVM) name of the WebAssembly cpu we are targeting.
static bool framePointerImpliesLeafFramePointer(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static void renderRemarksHotnessOptions(const ArgList &Args, ArgStringList &CmdArgs, const StringRef PluginOptPrefix)
static void GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T, const JobAction &JA, const InputInfoList &Inputs, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const SmallVectorImpl< std::string > &LibraryPaths, StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL)
Search if a user provided archive file lib<libname>.a exists in any of the library paths.
static std::string getLanaiTargetCPU(const ArgList &Args)
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const StringRef PluginOptPrefix)
static bool useFramePointerForTargetByDefault(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static void AddLibgcc(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
static LibGccType getLibGccType(const ToolChain &TC, const Driver &D, const ArgList &Args)
clang::CodeGenOptions::FramePointerKind getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static std::string getAMDGPUTargetGPU(const llvm::Triple &T, const ArgList &Args)
Get the (LLVM) name of the AMDGPU gpu we are targeting.
static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple)
static bool shouldIgnoreUnsupportedTargetFeature(const Arg &TargetFeatureArg, llvm::Triple T, StringRef Processor)
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Defines types useful for describing an Objective-C runtime.
Defines version macros and version-related utility functions for Clang.
const char * getOffloadingArch() const
static StringRef GetOffloadKindName(OffloadKind Kind)
Return a string containing a offload kind name.
OffloadKind getOffloadingDeviceKind() const
bool isHostOffloading(unsigned int OKind) const
Check if this action have any offload kinds.
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...
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
DiagnosticBuilder Diag(unsigned DiagID) const
StringRef getFlangF128MathLibrary() const
std::string Dir
The path the driver executable was in, as invoked from the command line.
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
@ OMPRT_OMP
The LLVM OpenMP runtime.
@ OMPRT_Unknown
An unknown OpenMP runtime.
@ OMPRT_GOMP
The GNU OpenMP runtime.
std::vector< std::string > flags_list
bool needsFuzzerInterceptors() const
bool needsHwasanAliasesRt() const
bool needsStatsRt() const
bool needsMemProfRt() const
bool needsCfiDiagRt() const
bool linkRuntimes() const
bool needsUbsanRt() const
bool needsHwasanRt() const
bool hasCrossDsoCfi() const
bool hasMemtagHeap() const
bool needsSafeStackRt() const
bool needsRtsanRt() const
bool requiresMinimalRuntime() const
bool hasMemtagStack() const
bool needsDfsanRt() const
bool needsScudoRt() const
bool needsUbsanCXXRt() const
const std::string & getMemtagMode() const
bool needsSharedRt() const
bool needsTysanRt() const
bool linkCXXRuntimes() const
bool needsXRayDSORt() const
llvm::ArrayRef< std::string > modeList() const
bool isLLVMIR(ID Id)
Is this LLVM IR.
ID lookupTypeForExtension(llvm::StringRef Ext)
lookupTypeForExtension - Lookup the type to use for the file extension Ext.
bool willEmitRemarks(const llvm::opt::ArgList &Args)
The JSON file list parser is used to communicate input to InstallAPI.
llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch)
Get processor name from target ID.
const FunctionProtoType * T
static constexpr ResponseFileSupport AtFileCurCP()