23 #include "clang/Config/config.h" 34 #include "llvm/ADT/STLExtras.h" 35 #include "llvm/ADT/SmallString.h" 36 #include "llvm/ADT/StringExtras.h" 37 #include "llvm/ADT/StringSwitch.h" 38 #include "llvm/ADT/Twine.h" 39 #include "llvm/Option/Arg.h" 40 #include "llvm/Option/ArgList.h" 41 #include "llvm/Option/Option.h" 42 #include "llvm/Support/CodeGen.h" 43 #include "llvm/Support/Compression.h" 44 #include "llvm/Support/Debug.h" 45 #include "llvm/Support/ErrorHandling.h" 46 #include "llvm/Support/FileSystem.h" 47 #include "llvm/Support/Host.h" 48 #include "llvm/Support/Path.h" 49 #include "llvm/Support/Process.h" 50 #include "llvm/Support/Program.h" 51 #include "llvm/Support/ScopedPrinter.h" 52 #include "llvm/Support/TargetParser.h" 53 #include "llvm/Support/VirtualFileSystem.h" 54 #include "llvm/Support/YAMLParser.h" 58 using namespace clang;
63 if (D.
getVFS().exists(Path))
64 Paths.push_back(Path.str());
68 std::vector<StringRef> &Features,
70 for (
const Arg *A : Args.filtered(Group)) {
71 StringRef Name = A->getOption().getName();
75 assert(Name.startswith(
"m") &&
"Invalid feature name.");
76 Name = Name.substr(1);
78 bool IsNegative = Name.startswith(
"no-");
80 Name = Name.substr(3);
81 Features.push_back(Args.MakeArgString((IsNegative ?
"-" :
"+") + Name));
86 const char *ArgName,
const char *EnvVar) {
87 const char *DirList = ::getenv(EnvVar);
88 bool CombinedArg =
false;
93 StringRef Name(ArgName);
94 if (Name.equals(
"-I") || Name.equals(
"-L"))
97 StringRef Dirs(DirList);
101 StringRef::size_type Delim;
102 while ((Delim = Dirs.find(llvm::sys::EnvPathSeparator)) != StringRef::npos) {
105 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
107 CmdArgs.push_back(ArgName);
108 CmdArgs.push_back(
".");
113 Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim)));
115 CmdArgs.push_back(ArgName);
116 CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim)));
119 Dirs = Dirs.substr(Delim + 1);
124 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
126 CmdArgs.push_back(ArgName);
127 CmdArgs.push_back(
".");
131 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs));
133 CmdArgs.push_back(ArgName);
134 CmdArgs.push_back(Args.MakeArgString(Dirs));
140 const ArgList &Args, ArgStringList &CmdArgs,
146 Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
148 for (
const auto &II : Inputs) {
152 if (
auto *IA = II.getAction())
164 if (II.isFilename()) {
165 CmdArgs.push_back(II.getFilename());
170 const Arg &A = II.getInputArg();
173 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
175 else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
177 else if (A.getOption().matches(options::OPT_z)) {
180 A.render(Args, CmdArgs);
182 A.renderAsInput(Args, CmdArgs);
194 std::vector<StringRef> &Features,
195 OptSpecifier OnOpt, OptSpecifier OffOpt,
196 StringRef FeatureName) {
197 if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) {
198 if (A->getOption().matches(OnOpt))
199 Features.push_back(Args.MakeArgString(
"+" + FeatureName));
201 Features.push_back(Args.MakeArgString(
"-" + FeatureName));
207 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
208 const char *GPUName = A->getValue();
209 return llvm::StringSwitch<const char *>(GPUName)
210 .Cases(
"rv630",
"rv635",
"r600")
211 .Cases(
"rv610",
"rv620",
"rs780",
"rs880")
212 .Case(
"rv740",
"rv770")
213 .Case(
"palm",
"cedar")
214 .Cases(
"sumo",
"sumo2",
"sumo")
215 .Case(
"hemlock",
"cypress")
216 .Case(
"aruba",
"cayman")
223 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
224 return A->getValue();
232 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
233 StringRef CPU = A->getValue();
239 return llvm::sys::getHostCPUName();
252 switch (T.getArch()) {
256 case llvm::Triple::aarch64:
257 case llvm::Triple::aarch64_be:
260 case llvm::Triple::arm:
261 case llvm::Triple::armeb:
262 case llvm::Triple::thumb:
263 case llvm::Triple::thumbeb: {
264 StringRef MArch, MCPU;
269 case llvm::Triple::avr:
270 if (
const Arg *A = Args.getLastArg(options::OPT_mmcu_EQ))
271 return A->getValue();
274 case llvm::Triple::mips:
275 case llvm::Triple::mipsel:
276 case llvm::Triple::mips64:
277 case llvm::Triple::mips64el: {
284 case llvm::Triple::nvptx:
285 case llvm::Triple::nvptx64:
286 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
287 return A->getValue();
290 case llvm::Triple::ppc:
291 case llvm::Triple::ppc64:
292 case llvm::Triple::ppc64le: {
297 if (TargetCPUName.empty() && !T.isOSDarwin()) {
298 if (T.getArch() == llvm::Triple::ppc64)
299 TargetCPUName =
"ppc64";
300 else if (T.getArch() == llvm::Triple::ppc64le)
301 TargetCPUName =
"ppc64le";
303 TargetCPUName =
"ppc";
305 return TargetCPUName;
308 case llvm::Triple::bpfel:
309 case llvm::Triple::bpfeb:
310 case llvm::Triple::sparc:
311 case llvm::Triple::sparcel:
312 case llvm::Triple::sparcv9:
313 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
314 return A->getValue();
317 case llvm::Triple::x86:
318 case llvm::Triple::x86_64:
321 case llvm::Triple::hexagon:
325 case llvm::Triple::lanai:
328 case llvm::Triple::systemz:
331 case llvm::Triple::r600:
332 case llvm::Triple::amdgcn:
335 case llvm::Triple::wasm32:
336 case llvm::Triple::wasm64:
342 unsigned Parallelism = 0;
343 Arg *LtoJobsArg = Args.getLastArg(options::OPT_flto_jobs_EQ);
345 StringRef(LtoJobsArg->getValue()).getAsInteger(10, Parallelism))
346 D.
Diag(diag::err_drv_invalid_int_value) << LtoJobsArg->getAsString(Args)
347 << LtoJobsArg->getValue();
353 return Triple.getOS() == llvm::Triple::CloudABI;
357 ArgStringList &CmdArgs,
const InputInfo &Output,
358 const InputInfo &Input,
bool IsThinLTO) {
362 CmdArgs.push_back(
"-plugin");
365 const char *Suffix =
".dll";
366 #elif defined(__APPLE__) 367 const char *Suffix =
".dylib";
369 const char *Suffix =
".so";
373 llvm::sys::path::native(Twine(ToolChain.
getDriver().
Dir) +
374 "/../lib" CLANG_LIBDIR_SUFFIX
"/LLVMgold" +
377 CmdArgs.push_back(Args.MakeArgString(Plugin));
385 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=mcpu=") + CPU));
387 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
389 if (A->getOption().matches(options::OPT_O4) ||
390 A->getOption().matches(options::OPT_Ofast))
392 else if (A->getOption().matches(options::OPT_O))
393 OOpt = A->getValue();
394 else if (A->getOption().matches(options::OPT_O0))
397 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=O") + OOpt));
400 if (Args.hasArg(options::OPT_gsplit_dwarf)) {
402 Args.MakeArgString(Twine(
"-plugin-opt=dwo_dir=") +
407 CmdArgs.push_back(
"-plugin-opt=thinlto");
411 Args.MakeArgString(
"-plugin-opt=jobs=" + Twine(Parallelism)));
414 if (Arg *A = Args.getLastArg(options::OPT_gTune_Group,
415 options::OPT_ggdbN_Group)) {
416 if (A->getOption().matches(options::OPT_glldb))
417 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=lldb");
418 else if (A->getOption().matches(options::OPT_gsce))
419 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=sce");
421 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=gdb");
424 bool UseSeparateSections =
427 if (Args.hasFlag(options::OPT_ffunction_sections,
428 options::OPT_fno_function_sections, UseSeparateSections)) {
429 CmdArgs.push_back(
"-plugin-opt=-function-sections");
432 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
433 UseSeparateSections)) {
434 CmdArgs.push_back(
"-plugin-opt=-data-sections");
438 StringRef FName = A->getValue();
439 if (!llvm::sys::fs::exists(FName))
440 ToolChain.
getDriver().
Diag(diag::err_drv_no_such_file) << FName;
443 Args.MakeArgString(Twine(
"-plugin-opt=sample-profile=") + FName));
446 auto *CSPGOGenerateArg = Args.getLastArg(options::OPT_fcs_profile_generate,
447 options::OPT_fcs_profile_generate_EQ,
448 options::OPT_fno_profile_generate);
449 if (CSPGOGenerateArg &&
450 CSPGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
451 CSPGOGenerateArg =
nullptr;
455 if (CSPGOGenerateArg) {
456 CmdArgs.push_back(Args.MakeArgString(
"-plugin-opt=cs-profile-generate"));
457 if (CSPGOGenerateArg->getOption().matches(
458 options::OPT_fcs_profile_generate_EQ)) {
460 llvm::sys::path::append(Path,
"default_%m.profraw");
462 Args.MakeArgString(Twine(
"-plugin-opt=cs-profile-path=") + Path));
465 Args.MakeArgString(
"-plugin-opt=cs-profile-path=default_%m.profraw"));
466 }
else if (ProfileUseArg) {
468 ProfileUseArg->getNumValues() == 0 ?
"" : ProfileUseArg->getValue());
469 if (Path.empty() || llvm::sys::fs::is_directory(Path))
470 llvm::sys::path::append(Path,
"default.profdata");
471 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=cs-profile-path=") +
476 if (Args.hasFlag(options::OPT_fexperimental_new_pass_manager,
477 options::OPT_fno_experimental_new_pass_manager,
478 ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER)) {
479 CmdArgs.push_back(
"-plugin-opt=new-pass-manager");
485 if (!StatsFile.empty())
487 Args.MakeArgString(Twine(
"-plugin-opt=stats-file=") + StatsFile));
491 ArgStringList &CmdArgs) {
492 if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
493 options::OPT_fno_rtlib_add_rpath,
false))
497 if (TC.
getVFS().exists(CandidateRPath)) {
498 CmdArgs.push_back(
"-rpath");
499 CmdArgs.push_back(Args.MakeArgString(CandidateRPath.c_str()));
504 const ArgList &Args,
bool IsOffloadingHost,
506 if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
507 options::OPT_fno_openmp,
false))
512 CmdArgs.push_back(
"-lomp");
515 CmdArgs.push_back(
"-lgomp");
518 CmdArgs.push_back(
"-lrt");
521 CmdArgs.push_back(
"-liomp5");
528 if (IsOffloadingHost)
529 CmdArgs.push_back(
"-lomptarget");
537 ArgStringList &CmdArgs, StringRef Sanitizer,
538 bool IsShared,
bool IsWhole) {
541 if (IsWhole) CmdArgs.push_back(
"--whole-archive");
544 if (IsWhole) CmdArgs.push_back(
"--no-whole-archive");
554 ArgStringList &CmdArgs,
555 StringRef Sanitizer) {
558 if (TC.
getTriple().getOS() == llvm::Triple::Solaris)
563 if (TC.
getTriple().getVendor() == llvm::Triple::Myriad)
566 if (llvm::sys::fs::exists(SanRT +
".syms")) {
567 CmdArgs.push_back(Args.MakeArgString(
"--dynamic-list=" + SanRT +
".syms"));
574 ArgStringList &CmdArgs) {
577 CmdArgs.push_back(
"--no-as-needed");
579 if (TC.
getTriple().getOS() != llvm::Triple::RTEMS &&
581 CmdArgs.push_back(
"-lpthread");
583 CmdArgs.push_back(
"-lrt");
585 CmdArgs.push_back(
"-lm");
590 TC.
getTriple().getOS() != llvm::Triple::RTEMS)
591 CmdArgs.push_back(
"-ldl");
595 CmdArgs.push_back(
"-lexecinfo");
609 SharedRuntimes.push_back(
"asan");
610 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
611 HelperStaticRuntimes.push_back(
"asan-preinit");
615 SharedRuntimes.push_back(
"ubsan_minimal");
617 SharedRuntimes.push_back(
"ubsan_standalone");
621 SharedRuntimes.push_back(
"scudo_minimal");
623 SharedRuntimes.push_back(
"scudo");
626 SharedRuntimes.push_back(
"hwasan");
631 StaticRuntimes.push_back(
"stats_client");
634 if (Args.hasArg(options::OPT_shared) || SanArgs.
needsSharedRt()) {
639 StaticRuntimes.push_back(
"asan");
641 StaticRuntimes.push_back(
"asan_cxx");
645 StaticRuntimes.push_back(
"hwasan");
647 StaticRuntimes.push_back(
"hwasan_cxx");
650 StaticRuntimes.push_back(
"dfsan");
652 StaticRuntimes.push_back(
"lsan");
654 StaticRuntimes.push_back(
"msan");
656 StaticRuntimes.push_back(
"msan_cxx");
659 StaticRuntimes.push_back(
"tsan");
661 StaticRuntimes.push_back(
"tsan_cxx");
665 StaticRuntimes.push_back(
"ubsan_minimal");
667 StaticRuntimes.push_back(
"ubsan_standalone");
669 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
673 NonWholeStaticRuntimes.push_back(
"safestack");
674 RequiredSymbols.push_back(
"__safestack_init");
677 StaticRuntimes.push_back(
"cfi");
679 StaticRuntimes.push_back(
"cfi_diag");
681 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
684 NonWholeStaticRuntimes.push_back(
"stats");
685 RequiredSymbols.push_back(
"__sanitizer_stats_register");
689 StaticRuntimes.push_back(
"scudo_minimal");
691 StaticRuntimes.push_back(
"scudo_cxx_minimal");
693 StaticRuntimes.push_back(
"scudo");
695 StaticRuntimes.push_back(
"scudo_cxx");
703 ArgStringList &CmdArgs) {
705 NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
707 NonWholeStaticRuntimes, HelperStaticRuntimes,
712 && !Args.hasArg(options::OPT_shared)) {
715 if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx))
719 for (
auto RT : SharedRuntimes)
721 for (
auto RT : HelperStaticRuntimes)
723 bool AddExportDynamic =
false;
724 for (
auto RT : StaticRuntimes) {
728 for (
auto RT : NonWholeStaticRuntimes) {
732 for (
auto S : RequiredSymbols) {
733 CmdArgs.push_back(
"-u");
734 CmdArgs.push_back(Args.MakeArgString(S));
738 if (AddExportDynamic)
739 CmdArgs.push_back(
"--export-dynamic");
743 CmdArgs.push_back(
"-export-dynamic-symbol=__cfi_check");
745 return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
749 if (Args.hasArg(options::OPT_shared))
753 CmdArgs.push_back(
"-whole-archive");
757 CmdArgs.push_back(
"-no-whole-archive");
765 CmdArgs.push_back(
"--no-as-needed");
766 CmdArgs.push_back(
"-lpthread");
768 CmdArgs.push_back(
"-lrt");
769 CmdArgs.push_back(
"-lm");
774 CmdArgs.push_back(
"-ldl");
779 if (Arg *A = Args.getLastArg(options::OPT_O_Group))
780 return !A->getOption().matches(options::OPT_O0);
787 if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
788 if (StringRef(A->getValue()) ==
"single")
791 Arg *FinalOutput = Args.getLastArg(options::OPT_o);
792 if (FinalOutput && Args.hasArg(options::OPT_c)) {
794 llvm::sys::path::replace_extension(T,
"dwo");
795 return Args.MakeArgString(T);
799 Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
801 llvm::sys::path::replace_extension(F,
"dwo");
803 return Args.MakeArgString(F);
808 const JobAction &JA,
const ArgList &Args,
809 const InputInfo &Output,
const char *OutFile) {
810 ArgStringList ExtractArgs;
811 ExtractArgs.push_back(
"--extract-dwo");
813 ArgStringList StripArgs;
814 StripArgs.push_back(
"--strip-dwo");
819 ExtractArgs.push_back(OutFile);
826 C.
addCommand(llvm::make_unique<Command>(JA, T, Exec, ExtractArgs, II));
829 C.
addCommand(llvm::make_unique<Command>(JA, T, Exec, StripArgs, II));
838 Args.ClaimAllArgs(options::OPT_flto_EQ);
839 Args.ClaimAllArgs(options::OPT_flto);
840 Args.ClaimAllArgs(options::OPT_fno_lto);
844 auto *ProfileUseArg = Args.getLastArg(
845 options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
846 options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
847 options::OPT_fno_profile_instr_use);
850 ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
851 ProfileUseArg =
nullptr;
853 return ProfileUseArg;
857 auto *ProfileSampleUseArg = Args.getLastArg(
858 options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ,
859 options::OPT_fauto_profile, options::OPT_fauto_profile_EQ,
860 options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile);
862 if (ProfileSampleUseArg &&
863 (ProfileSampleUseArg->getOption().matches(
864 options::OPT_fno_profile_sample_use) ||
865 ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile)))
868 return Args.getLastArg(options::OPT_fprofile_sample_use_EQ,
869 options::OPT_fauto_profile_EQ);
876 std::tuple<llvm::Reloc::Model, unsigned, bool>
879 const llvm::Triple &Triple = ToolChain.
getTriple();
884 if (Triple.isOSBinFormatMachO() && Args.hasArg(options::OPT_static))
886 bool IsPICLevelTwo = PIC;
889 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
892 if (Triple.isAndroid()) {
893 switch (Triple.getArch()) {
894 case llvm::Triple::arm:
895 case llvm::Triple::armeb:
896 case llvm::Triple::thumb:
897 case llvm::Triple::thumbeb:
898 case llvm::Triple::aarch64:
899 case llvm::Triple::mips:
900 case llvm::Triple::mipsel:
901 case llvm::Triple::mips64:
902 case llvm::Triple::mips64el:
906 case llvm::Triple::x86:
907 case llvm::Triple::x86_64:
909 IsPICLevelTwo =
true;
918 if (Triple.isOSOpenBSD()) {
920 case llvm::Triple::arm:
921 case llvm::Triple::aarch64:
922 case llvm::Triple::mips64:
923 case llvm::Triple::mips64el:
924 case llvm::Triple::x86:
925 case llvm::Triple::x86_64:
926 IsPICLevelTwo =
false;
929 case llvm::Triple::ppc:
930 case llvm::Triple::sparc:
931 case llvm::Triple::sparcel:
932 case llvm::Triple::sparcv9:
933 IsPICLevelTwo =
true;
942 if (Triple.getArch() == llvm::Triple::amdgcn)
949 Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
950 options::OPT_fpic, options::OPT_fno_pic,
951 options::OPT_fPIE, options::OPT_fno_PIE,
952 options::OPT_fpie, options::OPT_fno_pie);
953 if (Triple.isOSWindows() && LastPICArg &&
955 Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
956 options::OPT_fPIE, options::OPT_fpie)) {
957 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
958 << LastPICArg->getSpelling() << Triple.str();
959 if (Triple.getArch() == llvm::Triple::x86_64)
960 return std::make_tuple(llvm::Reloc::PIC_, 2U,
false);
961 return std::make_tuple(llvm::Reloc::Static, 0U,
false);
968 Option O = LastPICArg->getOption();
969 if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) ||
970 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) {
971 PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie);
973 PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic);
975 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fPIC);
978 if (EffectiveTriple.isPS4CPU()) {
979 Arg *ModelArg = Args.getLastArg(options::OPT_mcmodel_EQ);
980 StringRef Model = ModelArg ? ModelArg->getValue() :
"";
981 if (Model !=
"kernel") {
984 << LastPICArg->getSpelling();
994 if (PIC && (Triple.isOSDarwin() || EffectiveTriple.isPS4CPU()))
1000 ((!EffectiveTriple.isiOS() || EffectiveTriple.isOSVersionLT(6)) &&
1001 !EffectiveTriple.isWatchOS()))
1004 if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
1007 if (!Triple.isOSDarwin())
1008 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1009 << A->getSpelling() << Triple.str();
1018 return std::make_tuple(llvm::Reloc::DynamicNoPIC, PIC ? 2U : 0U,
false);
1021 bool EmbeddedPISupported;
1022 switch (Triple.getArch()) {
1023 case llvm::Triple::arm:
1024 case llvm::Triple::armeb:
1025 case llvm::Triple::thumb:
1026 case llvm::Triple::thumbeb:
1027 EmbeddedPISupported =
true;
1030 EmbeddedPISupported =
false;
1034 bool ROPI =
false, RWPI =
false;
1035 Arg* LastROPIArg = Args.getLastArg(options::OPT_fropi, options::OPT_fno_ropi);
1036 if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
1037 if (!EmbeddedPISupported)
1038 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1039 << LastROPIArg->getSpelling() << Triple.str();
1042 Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
1043 if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
1044 if (!EmbeddedPISupported)
1045 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1046 << LastRWPIArg->getSpelling() << Triple.str();
1051 if ((ROPI || RWPI) && (PIC || PIE))
1052 ToolChain.
getDriver().
Diag(diag::err_drv_ropi_rwpi_incompatible_with_pic);
1054 if (Triple.isMIPS()) {
1061 if (ABIName ==
"n64")
1064 if(Args.hasArg(options::OPT_mno_abicalls))
1065 return std::make_tuple(llvm::Reloc::Static, 0U,
false);
1068 IsPICLevelTwo =
false;
1072 return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE);
1074 llvm::Reloc::Model RelocM = llvm::Reloc::Static;
1076 RelocM = llvm::Reloc::ROPI_RWPI;
1078 RelocM = llvm::Reloc::ROPI;
1080 RelocM = llvm::Reloc::RWPI;
1082 return std::make_tuple(RelocM, 0U,
false);
1102 const ArgList &Args) {
1103 const Arg *A = Args.getLastArg(options::OPT_falign_functions,
1104 options::OPT_falign_functions_EQ,
1105 options::OPT_fno_align_functions);
1106 if (!A || A->getOption().matches(options::OPT_fno_align_functions))
1109 if (A->getOption().matches(options::OPT_falign_functions))
1113 if (StringRef(A->getValue()).getAsInteger(10, Value) || Value > 65536)
1115 << A->getAsString(Args) << A->getValue();
1116 return Value ? llvm::Log2_32_Ceil(
std::min(Value, 65536u)) :
Value;
1120 ArgStringList &CmdArgs) {
1121 llvm::Reloc::Model RelocationModel;
1124 std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(ToolChain, Args);
1126 if (RelocationModel != llvm::Reloc::Static)
1127 CmdArgs.push_back(
"-KPIC");
1133 return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc,
false);
1139 if (Args.hasArg(options::OPT_static_libgcc) ||
1140 Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_pie))
1142 if (Args.hasArg(options::OPT_shared_libgcc) || D.
CCCIsCXX())
1161 ArgStringList &CmdArgs,
const ArgList &Args) {
1173 CmdArgs.push_back(
"--as-needed");
1181 CmdArgs.push_back(
"-lgcc_eh");
1183 CmdArgs.push_back(
"-lgcc_s");
1187 CmdArgs.push_back(
"-lunwind");
1192 CmdArgs.push_back(
"--no-as-needed");
1196 ArgStringList &CmdArgs,
const ArgList &Args) {
1199 CmdArgs.push_back(
"-lgcc");
1202 CmdArgs.push_back(
"-lgcc");
1210 CmdArgs.push_back(
"-ldl");
1214 ArgStringList &CmdArgs,
const ArgList &Args) {
1225 if (TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
1228 if (Args.hasArg(options::OPT_rtlib_EQ)) {
1229 TC.
getDriver().
Diag(diag::err_drv_unsupported_rtlib_for_platform)
1230 << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() <<
"MSVC";
1247 const ArgList &Args, ArgStringList &CmdArgs,
1256 SmallString<256> Name = llvm::sys::path::filename(Output.
getFilename());
1258 llvm::sys::path::replace_extension(Name,
"lk");
1259 LKS = C.
getArgs().MakeArgString(Name.c_str());
1261 llvm::sys::path::replace_extension(Name,
"");
1267 CmdArgs.push_back(
"-T");
1268 CmdArgs.push_back(LKS);
1271 std::string LksBuffer;
1272 llvm::raw_string_ostream LksStream(LksBuffer);
1277 assert(OpenMPToolChains.first != OpenMPToolChains.second &&
1278 "No OpenMP toolchains??");
1288 LksStream <<
"/*\n";
1289 LksStream <<
" OpenMP Offload Linker Script\n";
1290 LksStream <<
" *** Automatically generated by Clang ***\n";
1291 LksStream <<
"*/\n";
1292 LksStream <<
"TARGET(binary)\n";
1293 auto DTC = OpenMPToolChains.first;
1294 for (
auto &II : Inputs) {
1295 const Action *A = II.getAction();
1297 if (A && isa<LinkJobAction>(A) &&
1299 assert(DTC != OpenMPToolChains.second &&
1300 "More device inputs than device toolchains??");
1301 InputBinaryInfo.push_back(std::make_pair(
1302 DTC->second->getTriple().normalize(), II.getFilename()));
1304 LksStream <<
"INPUT(" << II.getFilename() <<
")\n";
1308 assert(DTC == OpenMPToolChains.second &&
1309 "Less device inputs than device toolchains??");
1311 LksStream <<
"SECTIONS\n";
1315 for (
const auto &BI : InputBinaryInfo) {
1316 LksStream <<
" .omp_offloading." << BI.first <<
" :\n";
1317 LksStream <<
" ALIGN(0x10)\n";
1318 LksStream <<
" {\n";
1319 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.img_start." << BI.first
1321 LksStream <<
" " << BI.second <<
"\n";
1322 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.img_end." << BI.first
1324 LksStream <<
" }\n";
1330 LksStream <<
" .omp_offloading.entries :\n";
1331 LksStream <<
" ALIGN(0x10)\n";
1332 LksStream <<
" SUBALIGN(0x01)\n";
1333 LksStream <<
" {\n";
1334 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.entries_begin = .);\n";
1335 LksStream <<
" *(.omp_offloading.entries)\n";
1336 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.entries_end = .);\n";
1337 LksStream <<
" }\n";
1339 LksStream <<
"INSERT BEFORE .data\n";
1344 if (C.
getArgs().hasArg(options::OPT_fopenmp_dump_offload_linker_script))
1345 llvm::errs() << LksBuffer;
1348 if (C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH))
1353 llvm::raw_fd_ostream Lksf(LKS, EC, llvm::sys::fs::F_None);
1356 C.
getDriver().
Diag(clang::diag::err_unable_to_make_temp) << EC.message();
1371 ArgStringList &CmdArgs,
const JobAction &JA,
1379 for (
const auto &II : Inputs) {
1380 const Action *A = II.getAction();
1383 DeviceInputs.push_back(II);
1387 if (DeviceInputs.empty())
1392 SmallString<256> Name = llvm::sys::path::filename(Output.
getFilename());
1394 llvm::sys::path::replace_extension(Name,
"lk");
1395 LKS = C.
getArgs().MakeArgString(Name.c_str());
1397 llvm::sys::path::replace_extension(Name,
"");
1403 CmdArgs.push_back(
"-T");
1404 CmdArgs.push_back(LKS);
1407 std::string LksBuffer;
1408 llvm::raw_string_ostream LksStream(LksBuffer);
1413 assert(HIPTC->getTriple().getArch() == llvm::Triple::amdgcn &&
1420 const char *BundleFile =
1428 LksStream <<
"/*\n";
1429 LksStream <<
" HIP Offload Linker Script\n";
1430 LksStream <<
" *** Automatically generated by Clang ***\n";
1431 LksStream <<
"*/\n";
1432 LksStream <<
"TARGET(binary)\n";
1433 LksStream <<
"INPUT(" << BundleFileName <<
")\n";
1434 LksStream <<
"SECTIONS\n";
1436 LksStream <<
" .hip_fatbin :\n";
1437 LksStream <<
" ALIGN(0x10)\n";
1438 LksStream <<
" {\n";
1439 LksStream <<
" PROVIDE_HIDDEN(__hip_fatbin = .);\n";
1440 LksStream <<
" " << BundleFileName <<
"\n";
1441 LksStream <<
" }\n";
1442 LksStream <<
" /DISCARD/ :\n";
1443 LksStream <<
" {\n";
1444 LksStream <<
" * ( __CLANG_OFFLOAD_BUNDLE__* )\n";
1445 LksStream <<
" }\n";
1447 LksStream <<
"INSERT BEFORE .data\n";
1452 if (C.
getArgs().hasArg(options::OPT_fhip_dump_offload_linker_script))
1453 llvm::errs() << LksBuffer;
1456 if (C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH))
1461 llvm::raw_fd_ostream Lksf(LKS, EC, llvm::sys::fs::F_None);
1464 C.
getDriver().
Diag(clang::diag::err_unable_to_make_temp) << EC.message();
1475 const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ);
1479 StringRef SaveStats = A->getValue();
1481 if (SaveStats ==
"obj" && Output.
isFilename()) {
1483 llvm::sys::path::remove_filename(StatsFile);
1484 }
else if (SaveStats !=
"cwd") {
1485 D.
Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats;
1489 StringRef BaseName = llvm::sys::path::filename(Input.
getBaseInput());
1490 llvm::sys::path::append(StatsFile, BaseName);
1491 llvm::sys::path::replace_extension(StatsFile,
"stats");
1497 Flags.push_back(std::string(Enabled ?
"+" :
"-") + Flag);
bool needsStatsRt() const
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const
GetTemporaryPath - Return the pathname of a temporary file to use as part of compilation; the file wi...
bool needsHwasanRt() const
Defines types useful for describing an Objective-C runtime.
bool isHostOffloading(OffloadKind OKind) const
Check if this action have any offload kinds.
DiagnosticBuilder Diag(unsigned DiagID) const
static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer, bool IsShared, bool IsWhole)
bool needsUbsanRt() const
std::string Dir
The path the driver executable was in, as invoked from the command line.
static bool addSanitizerDynamicList(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer)
Action - Represent an abstract compilation step to perform.
bool isDeviceOffloading(OffloadKind OKind) const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
An unknown OpenMP runtime.
static LibGccType getLibGccType(const Driver &D, const ArgList &Args)
static void AddLibgcc(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
llvm::vfs::FileSystem & getVFS() const
bool hasCrossDsoCfi() const
bool needsCfiDiagRt() const
llvm::ArrayRef< std::string > modeList() const
bool requiresMinimalRuntime() const
Defines the clang::LangOptions interface.
static StringRef getWebAssemblyTargetCPU(const ArgList &Args)
Get the (LLVM) name of the WebAssembly cpu we are targeting.
static void AddUnwindLibrary(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
Defines version macros and version-related utility functions for Clang.
std::vector< std::string > flags_list
void addCommand(std::unique_ptr< Command > C)
bool needsSafeStackRt() const
const_offload_toolchains_range getOffloadToolChains() const
bool needsDfsanRt() const
bool needsScudoRt() const
const llvm::opt::DerivedArgList & getArgs() const
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
bool isSaveTempsEnabled() const
Dataflow Directional Tag Classes.
static std::string getLanaiTargetCPU(const ArgList &Args)
Compilation - A set of tasks to perform for a single driver invocation.
const Driver & getDriver() const
static std::string getR600TargetGPU(const ArgList &Args)
Get the (LLVM) name of the R600 gpu we are targeting.
__DEVICE__ int min(int __a, int __b)
const char * addTempFile(const char *Name)
addTempFile - Add a file to remove on exit, and returns its argument.
bool needsSharedRt() const
const ToolChain * getSingleOffloadToolChain() const
Return an offload toolchain of the provided kind.
bool isLLVMIR(ID Id)
Is this LLVM IR.
static void collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, SmallVectorImpl< StringRef > &SharedRuntimes, SmallVectorImpl< StringRef > &StaticRuntimes, SmallVectorImpl< StringRef > &NonWholeStaticRuntimes, SmallVectorImpl< StringRef > &HelperStaticRuntimes, SmallVectorImpl< StringRef > &RequiredSymbols)
bool linkCXXRuntimes() const