24 #include "clang/Config/config.h" 35 #include "llvm/ADT/STLExtras.h" 36 #include "llvm/ADT/SmallString.h" 37 #include "llvm/ADT/StringExtras.h" 38 #include "llvm/ADT/StringSwitch.h" 39 #include "llvm/ADT/Twine.h" 40 #include "llvm/Option/Arg.h" 41 #include "llvm/Option/ArgList.h" 42 #include "llvm/Option/Option.h" 43 #include "llvm/Support/CodeGen.h" 44 #include "llvm/Support/Compression.h" 45 #include "llvm/Support/Debug.h" 46 #include "llvm/Support/ErrorHandling.h" 47 #include "llvm/Support/FileSystem.h" 48 #include "llvm/Support/Host.h" 49 #include "llvm/Support/Path.h" 50 #include "llvm/Support/Process.h" 51 #include "llvm/Support/Program.h" 52 #include "llvm/Support/ScopedPrinter.h" 53 #include "llvm/Support/TargetParser.h" 54 #include "llvm/Support/YAMLParser.h" 58 using namespace clang;
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 Arg *A = Args.getLastArg(options::OPT_mcpu_EQ);
225 A = Args.getLastArg(options::OPT_march_EQ);
230 const char *name = A->getValue();
231 return llvm::StringSwitch<const char *>(name)
232 .Case(
"r1",
"nios2r1")
233 .Case(
"r2",
"nios2r2")
238 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
239 return A->getValue();
247 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
248 StringRef CPU = A->getValue();
254 return llvm::sys::getHostCPUName();
267 switch (T.getArch()) {
271 case llvm::Triple::aarch64:
272 case llvm::Triple::aarch64_be:
275 case llvm::Triple::arm:
276 case llvm::Triple::armeb:
277 case llvm::Triple::thumb:
278 case llvm::Triple::thumbeb: {
279 StringRef MArch, MCPU;
284 case llvm::Triple::avr:
285 if (
const Arg *A = Args.getLastArg(options::OPT_mmcu_EQ))
286 return A->getValue();
289 case llvm::Triple::nios2: {
293 case llvm::Triple::mips:
294 case llvm::Triple::mipsel:
295 case llvm::Triple::mips64:
296 case llvm::Triple::mips64el: {
303 case llvm::Triple::nvptx:
304 case llvm::Triple::nvptx64:
305 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
306 return A->getValue();
309 case llvm::Triple::ppc:
310 case llvm::Triple::ppc64:
311 case llvm::Triple::ppc64le: {
316 if (TargetCPUName.empty() && !T.isOSDarwin()) {
317 if (T.getArch() == llvm::Triple::ppc64)
318 TargetCPUName =
"ppc64";
319 else if (T.getArch() == llvm::Triple::ppc64le)
320 TargetCPUName =
"ppc64le";
322 TargetCPUName =
"ppc";
324 return TargetCPUName;
327 case llvm::Triple::bpfel:
328 case llvm::Triple::bpfeb:
329 case llvm::Triple::sparc:
330 case llvm::Triple::sparcel:
331 case llvm::Triple::sparcv9:
332 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
333 return A->getValue();
336 case llvm::Triple::x86:
337 case llvm::Triple::x86_64:
340 case llvm::Triple::hexagon:
344 case llvm::Triple::lanai:
347 case llvm::Triple::systemz:
350 case llvm::Triple::r600:
351 case llvm::Triple::amdgcn:
354 case llvm::Triple::wasm32:
355 case llvm::Triple::wasm64:
361 unsigned Parallelism = 0;
362 Arg *LtoJobsArg = Args.getLastArg(options::OPT_flto_jobs_EQ);
364 StringRef(LtoJobsArg->getValue()).getAsInteger(10, Parallelism))
365 D.
Diag(diag::err_drv_invalid_int_value) << LtoJobsArg->getAsString(Args)
366 << LtoJobsArg->getValue();
372 return Triple.getOS() == llvm::Triple::CloudABI;
376 ArgStringList &CmdArgs,
const InputInfo &Output,
377 const InputInfo &Input,
bool IsThinLTO) {
381 CmdArgs.push_back(
"-plugin");
384 const char *Suffix =
".dll";
385 #elif defined(__APPLE__) 386 const char *Suffix =
".dylib";
388 const char *Suffix =
".so";
392 llvm::sys::path::native(Twine(ToolChain.
getDriver().
Dir) +
393 "/../lib" CLANG_LIBDIR_SUFFIX
"/LLVMgold" +
396 CmdArgs.push_back(Args.MakeArgString(Plugin));
404 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=mcpu=") + CPU));
406 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
408 if (A->getOption().matches(options::OPT_O4) ||
409 A->getOption().matches(options::OPT_Ofast))
411 else if (A->getOption().matches(options::OPT_O))
412 OOpt = A->getValue();
413 else if (A->getOption().matches(options::OPT_O0))
416 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=O") + OOpt));
419 if (Args.hasArg(options::OPT_gsplit_dwarf)) {
421 Args.MakeArgString(Twine(
"-plugin-opt=dwo_dir=") +
426 CmdArgs.push_back(
"-plugin-opt=thinlto");
430 Args.MakeArgString(
"-plugin-opt=jobs=" + Twine(Parallelism)));
433 if (Arg *A = Args.getLastArg(options::OPT_gTune_Group,
434 options::OPT_ggdbN_Group)) {
435 if (A->getOption().matches(options::OPT_glldb))
436 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=lldb");
437 else if (A->getOption().matches(options::OPT_gsce))
438 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=sce");
440 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=gdb");
443 bool UseSeparateSections =
446 if (Args.hasFlag(options::OPT_ffunction_sections,
447 options::OPT_fno_function_sections, UseSeparateSections)) {
448 CmdArgs.push_back(
"-plugin-opt=-function-sections");
451 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
452 UseSeparateSections)) {
453 CmdArgs.push_back(
"-plugin-opt=-data-sections");
457 StringRef FName = A->getValue();
458 if (!llvm::sys::fs::exists(FName))
459 ToolChain.
getDriver().
Diag(diag::err_drv_no_such_file) << FName;
462 Args.MakeArgString(Twine(
"-plugin-opt=sample-profile=") + FName));
466 if (Args.hasFlag(options::OPT_fexperimental_new_pass_manager,
467 options::OPT_fno_experimental_new_pass_manager,
468 ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER)) {
469 CmdArgs.push_back(
"-plugin-opt=new-pass-manager");
475 if (!StatsFile.empty())
477 Args.MakeArgString(Twine(
"-plugin-opt=stats-file=") + StatsFile));
481 ArgStringList &CmdArgs) {
482 if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
483 options::OPT_fno_rtlib_add_rpath,
false))
488 CmdArgs.push_back(
"-rpath");
489 CmdArgs.push_back(Args.MakeArgString(CandidateRPath.c_str()));
494 const ArgList &Args,
bool IsOffloadingHost,
496 if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
497 options::OPT_fno_openmp,
false))
502 CmdArgs.push_back(
"-lomp");
505 CmdArgs.push_back(
"-lgomp");
508 CmdArgs.push_back(
"-lrt");
511 CmdArgs.push_back(
"-liomp5");
518 if (IsOffloadingHost)
519 CmdArgs.push_back(
"-lomptarget");
527 ArgStringList &CmdArgs, StringRef Sanitizer,
528 bool IsShared,
bool IsWhole) {
531 if (IsWhole) CmdArgs.push_back(
"--whole-archive");
533 if (IsWhole) CmdArgs.push_back(
"--no-whole-archive");
543 ArgStringList &CmdArgs,
544 StringRef Sanitizer) {
547 if (TC.
getTriple().getOS() == llvm::Triple::Solaris)
552 if (TC.
getTriple().getVendor() == llvm::Triple::Myriad)
555 if (llvm::sys::fs::exists(SanRT +
".syms")) {
556 CmdArgs.push_back(Args.MakeArgString(
"--dynamic-list=" + SanRT +
".syms"));
563 ArgStringList &CmdArgs) {
566 CmdArgs.push_back(
"--no-as-needed");
568 if (TC.
getTriple().getOS() != llvm::Triple::RTEMS &&
570 CmdArgs.push_back(
"-lpthread");
571 if (TC.
getTriple().getOS() != llvm::Triple::OpenBSD)
572 CmdArgs.push_back(
"-lrt");
574 CmdArgs.push_back(
"-lm");
576 if (TC.
getTriple().getOS() != llvm::Triple::FreeBSD &&
577 TC.
getTriple().getOS() != llvm::Triple::NetBSD &&
578 TC.
getTriple().getOS() != llvm::Triple::OpenBSD &&
579 TC.
getTriple().getOS() != llvm::Triple::RTEMS)
580 CmdArgs.push_back(
"-ldl");
582 if (TC.
getTriple().getOS() == llvm::Triple::NetBSD ||
583 TC.
getTriple().getOS() == llvm::Triple::FreeBSD)
584 CmdArgs.push_back(
"-lexecinfo");
598 SharedRuntimes.push_back(
"asan");
599 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
600 HelperStaticRuntimes.push_back(
"asan-preinit");
604 SharedRuntimes.push_back(
"ubsan_minimal");
606 SharedRuntimes.push_back(
"ubsan_standalone");
610 SharedRuntimes.push_back(
"scudo_minimal");
612 SharedRuntimes.push_back(
"scudo");
615 SharedRuntimes.push_back(
"hwasan");
620 StaticRuntimes.push_back(
"stats_client");
623 if (Args.hasArg(options::OPT_shared) || SanArgs.
needsSharedRt()) {
628 StaticRuntimes.push_back(
"asan");
630 StaticRuntimes.push_back(
"asan_cxx");
634 StaticRuntimes.push_back(
"hwasan");
636 StaticRuntimes.push_back(
"hwasan_cxx");
639 StaticRuntimes.push_back(
"dfsan");
641 StaticRuntimes.push_back(
"lsan");
643 StaticRuntimes.push_back(
"msan");
645 StaticRuntimes.push_back(
"msan_cxx");
648 StaticRuntimes.push_back(
"tsan");
650 StaticRuntimes.push_back(
"tsan_cxx");
654 StaticRuntimes.push_back(
"ubsan_minimal");
656 StaticRuntimes.push_back(
"ubsan_standalone");
658 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
662 NonWholeStaticRuntimes.push_back(
"safestack");
663 RequiredSymbols.push_back(
"__safestack_init");
666 StaticRuntimes.push_back(
"cfi");
668 StaticRuntimes.push_back(
"cfi_diag");
670 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
673 NonWholeStaticRuntimes.push_back(
"stats");
674 RequiredSymbols.push_back(
"__sanitizer_stats_register");
677 StaticRuntimes.push_back(
"esan");
680 StaticRuntimes.push_back(
"scudo_minimal");
682 StaticRuntimes.push_back(
"scudo_cxx_minimal");
684 StaticRuntimes.push_back(
"scudo");
686 StaticRuntimes.push_back(
"scudo_cxx");
694 ArgStringList &CmdArgs) {
696 NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
698 NonWholeStaticRuntimes, HelperStaticRuntimes,
703 && !Args.hasArg(options::OPT_shared)) {
706 if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx))
710 for (
auto RT : SharedRuntimes)
712 for (
auto RT : HelperStaticRuntimes)
714 bool AddExportDynamic =
false;
715 for (
auto RT : StaticRuntimes) {
719 for (
auto RT : NonWholeStaticRuntimes) {
723 for (
auto S : RequiredSymbols) {
724 CmdArgs.push_back(
"-u");
725 CmdArgs.push_back(Args.MakeArgString(S));
729 if (AddExportDynamic)
730 CmdArgs.push_back(
"--export-dynamic");
734 CmdArgs.push_back(
"-export-dynamic-symbol=__cfi_check");
736 return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
740 if (Args.hasArg(options::OPT_shared))
744 CmdArgs.push_back(
"-whole-archive");
748 CmdArgs.push_back(
"-no-whole-archive");
756 CmdArgs.push_back(
"--no-as-needed");
757 CmdArgs.push_back(
"-lpthread");
758 if (TC.
getTriple().getOS() != llvm::Triple::OpenBSD)
759 CmdArgs.push_back(
"-lrt");
760 CmdArgs.push_back(
"-lm");
762 if (TC.
getTriple().getOS() != llvm::Triple::FreeBSD &&
763 TC.
getTriple().getOS() != llvm::Triple::NetBSD &&
764 TC.
getTriple().getOS() != llvm::Triple::OpenBSD)
765 CmdArgs.push_back(
"-ldl");
770 if (Arg *A = Args.getLastArg(options::OPT_O_Group))
771 return !A->getOption().matches(options::OPT_O0);
777 Arg *FinalOutput = Args.getLastArg(options::OPT_o);
778 if (FinalOutput && Args.hasArg(options::OPT_c)) {
780 llvm::sys::path::replace_extension(T,
"dwo");
781 return Args.MakeArgString(T);
785 Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
787 llvm::sys::path::replace_extension(F,
"dwo");
789 return Args.MakeArgString(F);
794 const JobAction &JA,
const ArgList &Args,
795 const InputInfo &Output,
const char *OutFile) {
796 ArgStringList ExtractArgs;
797 ExtractArgs.push_back(
"--extract-dwo");
799 ArgStringList StripArgs;
800 StripArgs.push_back(
"--strip-dwo");
805 ExtractArgs.push_back(OutFile);
812 C.
addCommand(llvm::make_unique<Command>(JA, T, Exec, ExtractArgs, II));
815 C.
addCommand(llvm::make_unique<Command>(JA, T, Exec, StripArgs, II));
824 Args.ClaimAllArgs(options::OPT_flto_EQ);
825 Args.ClaimAllArgs(options::OPT_flto);
826 Args.ClaimAllArgs(options::OPT_fno_lto);
830 auto *ProfileUseArg = Args.getLastArg(
831 options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
832 options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
833 options::OPT_fno_profile_instr_use);
836 ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
837 ProfileUseArg =
nullptr;
839 return ProfileUseArg;
843 auto *ProfileSampleUseArg = Args.getLastArg(
844 options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ,
845 options::OPT_fauto_profile, options::OPT_fauto_profile_EQ,
846 options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile);
848 if (ProfileSampleUseArg &&
849 (ProfileSampleUseArg->getOption().matches(
850 options::OPT_fno_profile_sample_use) ||
851 ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile)))
854 return Args.getLastArg(options::OPT_fprofile_sample_use_EQ,
855 options::OPT_fauto_profile_EQ);
862 std::tuple<llvm::Reloc::Model, unsigned, bool>
865 const llvm::Triple &Triple = ToolChain.
getTriple();
870 if (Triple.isOSBinFormatMachO() && Args.hasArg(options::OPT_static))
872 bool IsPICLevelTwo = PIC;
875 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
878 if (Triple.isAndroid()) {
879 switch (Triple.getArch()) {
880 case llvm::Triple::arm:
881 case llvm::Triple::armeb:
882 case llvm::Triple::thumb:
883 case llvm::Triple::thumbeb:
884 case llvm::Triple::aarch64:
885 case llvm::Triple::mips:
886 case llvm::Triple::mipsel:
887 case llvm::Triple::mips64:
888 case llvm::Triple::mips64el:
892 case llvm::Triple::x86:
893 case llvm::Triple::x86_64:
895 IsPICLevelTwo =
true;
904 if (Triple.getOS() == llvm::Triple::OpenBSD) {
906 case llvm::Triple::arm:
907 case llvm::Triple::aarch64:
908 case llvm::Triple::mips64:
909 case llvm::Triple::mips64el:
910 case llvm::Triple::x86:
911 case llvm::Triple::x86_64:
912 IsPICLevelTwo =
false;
915 case llvm::Triple::ppc:
916 case llvm::Triple::sparc:
917 case llvm::Triple::sparcel:
918 case llvm::Triple::sparcv9:
919 IsPICLevelTwo =
true;
928 if (Triple.getArch() == llvm::Triple::amdgcn)
935 Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
936 options::OPT_fpic, options::OPT_fno_pic,
937 options::OPT_fPIE, options::OPT_fno_PIE,
938 options::OPT_fpie, options::OPT_fno_pie);
939 if (Triple.isOSWindows() && LastPICArg &&
941 Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
942 options::OPT_fPIE, options::OPT_fpie)) {
943 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
944 << LastPICArg->getSpelling() << Triple.str();
945 if (Triple.getArch() == llvm::Triple::x86_64)
946 return std::make_tuple(llvm::Reloc::PIC_, 2U,
false);
947 return std::make_tuple(llvm::Reloc::Static, 0U,
false);
954 Option O = LastPICArg->getOption();
955 if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) ||
956 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) {
957 PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie);
959 PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic);
961 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fPIC);
964 if (EffectiveTriple.isPS4CPU()) {
965 Arg *ModelArg = Args.getLastArg(options::OPT_mcmodel_EQ);
966 StringRef Model = ModelArg ? ModelArg->getValue() :
"";
967 if (Model !=
"kernel") {
970 << LastPICArg->getSpelling();
980 if (PIC && (Triple.isOSDarwin() || EffectiveTriple.isPS4CPU()))
986 ((!EffectiveTriple.isiOS() || EffectiveTriple.isOSVersionLT(6)) &&
987 !EffectiveTriple.isWatchOS()))
990 if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
993 if (!Triple.isOSDarwin())
994 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
995 << A->getSpelling() << Triple.str();
1004 return std::make_tuple(llvm::Reloc::DynamicNoPIC, PIC ? 2U : 0U,
false);
1007 bool EmbeddedPISupported;
1008 switch (Triple.getArch()) {
1009 case llvm::Triple::arm:
1010 case llvm::Triple::armeb:
1011 case llvm::Triple::thumb:
1012 case llvm::Triple::thumbeb:
1013 EmbeddedPISupported =
true;
1016 EmbeddedPISupported =
false;
1020 bool ROPI =
false, RWPI =
false;
1021 Arg* LastROPIArg = Args.getLastArg(options::OPT_fropi, options::OPT_fno_ropi);
1022 if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
1023 if (!EmbeddedPISupported)
1024 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1025 << LastROPIArg->getSpelling() << Triple.str();
1028 Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
1029 if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
1030 if (!EmbeddedPISupported)
1031 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1032 << LastRWPIArg->getSpelling() << Triple.str();
1037 if ((ROPI || RWPI) && (PIC || PIE))
1038 ToolChain.
getDriver().
Diag(diag::err_drv_ropi_rwpi_incompatible_with_pic);
1040 if (Triple.isMIPS()) {
1047 if (ABIName ==
"n64")
1050 if(Args.hasArg(options::OPT_mno_abicalls))
1051 return std::make_tuple(llvm::Reloc::Static, 0U,
false);
1054 IsPICLevelTwo =
false;
1058 return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE);
1060 llvm::Reloc::Model RelocM = llvm::Reloc::Static;
1062 RelocM = llvm::Reloc::ROPI_RWPI;
1064 RelocM = llvm::Reloc::ROPI;
1066 RelocM = llvm::Reloc::RWPI;
1068 return std::make_tuple(RelocM, 0U,
false);
1088 const ArgList &Args) {
1089 const Arg *A = Args.getLastArg(options::OPT_falign_functions,
1090 options::OPT_falign_functions_EQ,
1091 options::OPT_fno_align_functions);
1092 if (!A || A->getOption().matches(options::OPT_fno_align_functions))
1095 if (A->getOption().matches(options::OPT_falign_functions))
1099 if (StringRef(A->getValue()).getAsInteger(10, Value) || Value > 65536)
1101 << A->getAsString(Args) << A->getValue();
1102 return Value ? llvm::Log2_32_Ceil(
std::min(Value, 65536u)) :
Value;
1106 ArgStringList &CmdArgs) {
1107 llvm::Reloc::Model RelocationModel;
1110 std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(ToolChain, Args);
1112 if (RelocationModel != llvm::Reloc::Static)
1113 CmdArgs.push_back(
"-KPIC");
1119 return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc,
false);
1123 ArgStringList &CmdArgs,
const ArgList &Args) {
1124 bool isAndroid = Triple.isAndroid();
1125 bool isCygMing = Triple.isOSCygMing();
1126 bool IsIAMCU = Triple.isOSIAMCU();
1127 bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) ||
1128 Args.hasArg(options::OPT_static);
1130 CmdArgs.push_back(
"-lgcc");
1132 if (StaticLibgcc || isAndroid) {
1134 CmdArgs.push_back(
"-lgcc");
1137 CmdArgs.push_back(
"--as-needed");
1138 CmdArgs.push_back(
"-lgcc_s");
1140 CmdArgs.push_back(
"--no-as-needed");
1143 if (StaticLibgcc && !isAndroid && !IsIAMCU)
1144 CmdArgs.push_back(
"-lgcc_eh");
1145 else if (!Args.hasArg(options::OPT_shared) && D.
CCCIsCXX())
1146 CmdArgs.push_back(
"-lgcc");
1153 if (isAndroid && !StaticLibgcc)
1154 CmdArgs.push_back(
"-ldl");
1158 ArgStringList &CmdArgs,
const ArgList &Args) {
1168 if (TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
1171 if (Args.hasArg(options::OPT_rtlib_EQ)) {
1172 TC.
getDriver().
Diag(diag::err_drv_unsupported_rtlib_for_platform)
1173 << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() <<
"MSVC";
1190 const ArgList &Args, ArgStringList &CmdArgs,
1201 llvm::sys::path::replace_extension(Name,
"lk");
1202 LKS = C.
getArgs().MakeArgString(Name.c_str());
1204 llvm::sys::path::replace_extension(Name,
"");
1210 CmdArgs.push_back(
"-T");
1211 CmdArgs.push_back(LKS);
1214 std::string LksBuffer;
1215 llvm::raw_string_ostream LksStream(LksBuffer);
1220 assert(OpenMPToolChains.first != OpenMPToolChains.second &&
1221 "No OpenMP toolchains??");
1231 LksStream <<
"/*\n";
1232 LksStream <<
" OpenMP Offload Linker Script\n";
1233 LksStream <<
" *** Automatically generated by Clang ***\n";
1234 LksStream <<
"*/\n";
1235 LksStream <<
"TARGET(binary)\n";
1236 auto DTC = OpenMPToolChains.first;
1237 for (
auto &II : Inputs) {
1238 const Action *A = II.getAction();
1240 if (A && isa<LinkJobAction>(A) &&
1242 assert(DTC != OpenMPToolChains.second &&
1243 "More device inputs than device toolchains??");
1244 InputBinaryInfo.push_back(std::make_pair(
1245 DTC->second->getTriple().normalize(), II.getFilename()));
1247 LksStream <<
"INPUT(" << II.getFilename() <<
")\n";
1251 assert(DTC == OpenMPToolChains.second &&
1252 "Less device inputs than device toolchains??");
1254 LksStream <<
"SECTIONS\n";
1258 for (
const auto &BI : InputBinaryInfo) {
1259 LksStream <<
" .omp_offloading." << BI.first <<
" :\n";
1260 LksStream <<
" ALIGN(0x10)\n";
1261 LksStream <<
" {\n";
1262 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.img_start." << BI.first
1264 LksStream <<
" " << BI.second <<
"\n";
1265 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.img_end." << BI.first
1267 LksStream <<
" }\n";
1273 LksStream <<
" .omp_offloading.entries :\n";
1274 LksStream <<
" ALIGN(0x10)\n";
1275 LksStream <<
" SUBALIGN(0x01)\n";
1276 LksStream <<
" {\n";
1277 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.entries_begin = .);\n";
1278 LksStream <<
" *(.omp_offloading.entries)\n";
1279 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.entries_end = .);\n";
1280 LksStream <<
" }\n";
1282 LksStream <<
"INSERT BEFORE .data\n";
1287 if (C.
getArgs().hasArg(options::OPT_fopenmp_dump_offload_linker_script))
1288 llvm::errs() << LksBuffer;
1291 if (C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH))
1296 llvm::raw_fd_ostream Lksf(LKS, EC, llvm::sys::fs::F_None);
1299 C.
getDriver().
Diag(clang::diag::err_unable_to_make_temp) << EC.message();
1314 ArgStringList &CmdArgs,
const JobAction &JA,
1325 llvm::sys::path::replace_extension(Name,
"lk");
1326 LKS = C.
getArgs().MakeArgString(Name.c_str());
1328 llvm::sys::path::replace_extension(Name,
"");
1334 CmdArgs.push_back(
"-T");
1335 CmdArgs.push_back(LKS);
1338 std::string LksBuffer;
1339 llvm::raw_string_ostream LksStream(LksBuffer);
1344 assert(HIPTC->getTriple().getArch() == llvm::Triple::amdgcn &&
1350 ArgStringList BundlerArgs;
1351 BundlerArgs.push_back(Args.MakeArgString(
"-type=o"));
1355 std::string BundlerTargetArg =
"-targets=host-x86_64-unknown-linux";
1356 std::string BundlerInputArg =
"-inputs=/dev/null";
1358 for (
const auto &II : Inputs) {
1359 const Action *A = II.getAction();
1362 BundlerTargetArg = BundlerTargetArg +
",hip-amdgcn-amd-amdhsa-" +
1364 BundlerInputArg = BundlerInputArg +
"," + II.getFilename();
1367 BundlerArgs.push_back(Args.MakeArgString(BundlerTargetArg));
1368 BundlerArgs.push_back(Args.MakeArgString(BundlerInputArg));
1371 const char *BundleFile =
1373 auto BundlerOutputArg =
1374 Args.MakeArgString(std::string(
"-outputs=").append(BundleFile));
1375 BundlerArgs.push_back(BundlerOutputArg);
1378 llvm::sys::path::append(BundlerPath,
"clang-offload-bundler");
1379 const char *Bundler = Args.MakeArgString(BundlerPath);
1380 C.
addCommand(llvm::make_unique<Command>(JA, T, Bundler, BundlerArgs, Inputs));
1386 LksStream <<
"/*\n";
1387 LksStream <<
" HIP Offload Linker Script\n";
1388 LksStream <<
" *** Automatically generated by Clang ***\n";
1389 LksStream <<
"*/\n";
1390 LksStream <<
"TARGET(binary)\n";
1391 LksStream <<
"INPUT(" << BundleFileName <<
")\n";
1392 LksStream <<
"SECTIONS\n";
1394 LksStream <<
" .hip_fatbin :\n";
1395 LksStream <<
" ALIGN(0x10)\n";
1396 LksStream <<
" {\n";
1397 LksStream <<
" PROVIDE_HIDDEN(__hip_fatbin = .);\n";
1398 LksStream <<
" " << BundleFileName <<
"\n";
1399 LksStream <<
" }\n";
1401 LksStream <<
"INSERT BEFORE .data\n";
1406 if (C.
getArgs().hasArg(options::OPT_fhip_dump_offload_linker_script))
1407 llvm::errs() << LksBuffer;
1410 if (C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH))
1415 llvm::raw_fd_ostream Lksf(LKS, EC, llvm::sys::fs::F_None);
1418 C.
getDriver().
Diag(clang::diag::err_unable_to_make_temp) << EC.message();
1429 const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ);
1433 StringRef SaveStats = A->getValue();
1435 if (SaveStats ==
"obj" && Output.
isFilename()) {
1437 llvm::sys::path::remove_filename(StatsFile);
1438 }
else if (SaveStats !=
"cwd") {
1439 D.
Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats;
1443 StringRef BaseName = llvm::sys::path::filename(Input.
getBaseInput());
1444 llvm::sys::path::append(StatsFile, BaseName);
1445 llvm::sys::path::replace_extension(StatsFile,
"stats");
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)
static void AddLibgcc(const llvm::Triple &Triple, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
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.
static std::string getNios2TargetCPU(const ArgList &Args)
bool isDeviceOffloading(OffloadKind OKind) const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
An unknown OpenMP runtime.
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.
Defines version macros and version-related utility functions for Clang.
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
vfs::FileSystem & getVFS() 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.
Defines the virtual file system interface vfs::FileSystem.
static std::string getLanaiTargetCPU(const ArgList &Args)
bool exists(const Twine &Path)
Check whether a file exists. Provided for convenience.
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.
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.
__DEVICE__ int min(int __a, int __b)
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)
const char * getOffloadingArch() const
bool linkCXXRuntimes() const