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/VirtualFileSystem.h" 55 #include "llvm/Support/YAMLParser.h" 59 using namespace clang;
64 if (D.
getVFS().exists(Path))
65 Paths.push_back(Path.str());
69 std::vector<StringRef> &Features,
71 for (
const Arg *A : Args.filtered(Group)) {
72 StringRef Name = A->getOption().getName();
76 assert(Name.startswith(
"m") &&
"Invalid feature name.");
77 Name = Name.substr(1);
79 bool IsNegative = Name.startswith(
"no-");
81 Name = Name.substr(3);
82 Features.push_back(Args.MakeArgString((IsNegative ?
"-" :
"+") + Name));
87 const char *ArgName,
const char *EnvVar) {
88 const char *DirList = ::getenv(EnvVar);
89 bool CombinedArg =
false;
94 StringRef Name(ArgName);
95 if (Name.equals(
"-I") || Name.equals(
"-L"))
98 StringRef Dirs(DirList);
102 StringRef::size_type Delim;
103 while ((Delim = Dirs.find(llvm::sys::EnvPathSeparator)) != StringRef::npos) {
106 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
108 CmdArgs.push_back(ArgName);
109 CmdArgs.push_back(
".");
114 Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim)));
116 CmdArgs.push_back(ArgName);
117 CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim)));
120 Dirs = Dirs.substr(Delim + 1);
125 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
127 CmdArgs.push_back(ArgName);
128 CmdArgs.push_back(
".");
132 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs));
134 CmdArgs.push_back(ArgName);
135 CmdArgs.push_back(Args.MakeArgString(Dirs));
141 const ArgList &Args, ArgStringList &CmdArgs,
147 Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
149 for (
const auto &II : Inputs) {
153 if (
auto *IA = II.getAction())
165 if (II.isFilename()) {
166 CmdArgs.push_back(II.getFilename());
171 const Arg &A = II.getInputArg();
174 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
176 else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
178 else if (A.getOption().matches(options::OPT_z)) {
181 A.render(Args, CmdArgs);
183 A.renderAsInput(Args, CmdArgs);
195 std::vector<StringRef> &Features,
196 OptSpecifier OnOpt, OptSpecifier OffOpt,
197 StringRef FeatureName) {
198 if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) {
199 if (A->getOption().matches(OnOpt))
200 Features.push_back(Args.MakeArgString(
"+" + FeatureName));
202 Features.push_back(Args.MakeArgString(
"-" + FeatureName));
208 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
209 const char *GPUName = A->getValue();
210 return llvm::StringSwitch<const char *>(GPUName)
211 .Cases(
"rv630",
"rv635",
"r600")
212 .Cases(
"rv610",
"rv620",
"rs780",
"rs880")
213 .Case(
"rv740",
"rv770")
214 .Case(
"palm",
"cedar")
215 .Cases(
"sumo",
"sumo2",
"sumo")
216 .Case(
"hemlock",
"cypress")
217 .Case(
"aruba",
"cayman")
224 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
225 return A->getValue();
233 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
234 StringRef CPU = A->getValue();
240 return llvm::sys::getHostCPUName();
253 switch (T.getArch()) {
257 case llvm::Triple::aarch64:
258 case llvm::Triple::aarch64_be:
261 case llvm::Triple::arm:
262 case llvm::Triple::armeb:
263 case llvm::Triple::thumb:
264 case llvm::Triple::thumbeb: {
265 StringRef MArch, MCPU;
270 case llvm::Triple::avr:
271 if (
const Arg *A = Args.getLastArg(options::OPT_mmcu_EQ))
272 return A->getValue();
275 case llvm::Triple::mips:
276 case llvm::Triple::mipsel:
277 case llvm::Triple::mips64:
278 case llvm::Triple::mips64el: {
285 case llvm::Triple::nvptx:
286 case llvm::Triple::nvptx64:
287 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
288 return A->getValue();
291 case llvm::Triple::ppc:
292 case llvm::Triple::ppc64:
293 case llvm::Triple::ppc64le: {
298 if (TargetCPUName.empty() && !T.isOSDarwin()) {
299 if (T.getArch() == llvm::Triple::ppc64)
300 TargetCPUName =
"ppc64";
301 else if (T.getArch() == llvm::Triple::ppc64le)
302 TargetCPUName =
"ppc64le";
304 TargetCPUName =
"ppc";
306 return TargetCPUName;
309 case llvm::Triple::bpfel:
310 case llvm::Triple::bpfeb:
311 case llvm::Triple::sparc:
312 case llvm::Triple::sparcel:
313 case llvm::Triple::sparcv9:
314 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
315 return A->getValue();
318 case llvm::Triple::x86:
319 case llvm::Triple::x86_64:
322 case llvm::Triple::hexagon:
326 case llvm::Triple::lanai:
329 case llvm::Triple::systemz:
332 case llvm::Triple::r600:
333 case llvm::Triple::amdgcn:
336 case llvm::Triple::wasm32:
337 case llvm::Triple::wasm64:
343 unsigned Parallelism = 0;
344 Arg *LtoJobsArg = Args.getLastArg(options::OPT_flto_jobs_EQ);
346 StringRef(LtoJobsArg->getValue()).getAsInteger(10, Parallelism))
347 D.
Diag(diag::err_drv_invalid_int_value) << LtoJobsArg->getAsString(Args)
348 << LtoJobsArg->getValue();
354 return Triple.getOS() == llvm::Triple::CloudABI;
358 ArgStringList &CmdArgs,
const InputInfo &Output,
359 const InputInfo &Input,
bool IsThinLTO) {
363 CmdArgs.push_back(
"-plugin");
366 const char *Suffix =
".dll";
367 #elif defined(__APPLE__) 368 const char *Suffix =
".dylib";
370 const char *Suffix =
".so";
374 llvm::sys::path::native(Twine(ToolChain.
getDriver().
Dir) +
375 "/../lib" CLANG_LIBDIR_SUFFIX
"/LLVMgold" +
378 CmdArgs.push_back(Args.MakeArgString(Plugin));
386 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=mcpu=") + CPU));
388 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
390 if (A->getOption().matches(options::OPT_O4) ||
391 A->getOption().matches(options::OPT_Ofast))
393 else if (A->getOption().matches(options::OPT_O))
394 OOpt = A->getValue();
395 else if (A->getOption().matches(options::OPT_O0))
398 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=O") + OOpt));
401 if (Args.hasArg(options::OPT_gsplit_dwarf)) {
403 Args.MakeArgString(Twine(
"-plugin-opt=dwo_dir=") +
408 CmdArgs.push_back(
"-plugin-opt=thinlto");
412 Args.MakeArgString(
"-plugin-opt=jobs=" + Twine(Parallelism)));
415 if (Arg *A = Args.getLastArg(options::OPT_gTune_Group,
416 options::OPT_ggdbN_Group)) {
417 if (A->getOption().matches(options::OPT_glldb))
418 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=lldb");
419 else if (A->getOption().matches(options::OPT_gsce))
420 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=sce");
422 CmdArgs.push_back(
"-plugin-opt=-debugger-tune=gdb");
425 bool UseSeparateSections =
428 if (Args.hasFlag(options::OPT_ffunction_sections,
429 options::OPT_fno_function_sections, UseSeparateSections)) {
430 CmdArgs.push_back(
"-plugin-opt=-function-sections");
433 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
434 UseSeparateSections)) {
435 CmdArgs.push_back(
"-plugin-opt=-data-sections");
439 StringRef FName = A->getValue();
440 if (!llvm::sys::fs::exists(FName))
441 ToolChain.
getDriver().
Diag(diag::err_drv_no_such_file) << FName;
444 Args.MakeArgString(Twine(
"-plugin-opt=sample-profile=") + FName));
448 if (Args.hasFlag(options::OPT_fexperimental_new_pass_manager,
449 options::OPT_fno_experimental_new_pass_manager,
450 ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER)) {
451 CmdArgs.push_back(
"-plugin-opt=new-pass-manager");
457 if (!StatsFile.empty())
459 Args.MakeArgString(Twine(
"-plugin-opt=stats-file=") + StatsFile));
463 ArgStringList &CmdArgs) {
464 if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
465 options::OPT_fno_rtlib_add_rpath,
false))
469 if (TC.
getVFS().exists(CandidateRPath)) {
470 CmdArgs.push_back(
"-rpath");
471 CmdArgs.push_back(Args.MakeArgString(CandidateRPath.c_str()));
476 const ArgList &Args,
bool IsOffloadingHost,
478 if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
479 options::OPT_fno_openmp,
false))
484 CmdArgs.push_back(
"-lomp");
487 CmdArgs.push_back(
"-lgomp");
490 CmdArgs.push_back(
"-lrt");
493 CmdArgs.push_back(
"-liomp5");
500 if (IsOffloadingHost)
501 CmdArgs.push_back(
"-lomptarget");
509 ArgStringList &CmdArgs, StringRef Sanitizer,
510 bool IsShared,
bool IsWhole) {
513 if (IsWhole) CmdArgs.push_back(
"--whole-archive");
515 if (IsWhole) CmdArgs.push_back(
"--no-whole-archive");
525 ArgStringList &CmdArgs,
526 StringRef Sanitizer) {
529 if (TC.
getTriple().getOS() == llvm::Triple::Solaris)
534 if (TC.
getTriple().getVendor() == llvm::Triple::Myriad)
537 if (llvm::sys::fs::exists(SanRT +
".syms")) {
538 CmdArgs.push_back(Args.MakeArgString(
"--dynamic-list=" + SanRT +
".syms"));
545 ArgStringList &CmdArgs, StringRef Name) {
547 if (!LibPath.empty()) {
549 llvm::sys::path::append(P, Name);
550 if (TC.
getVFS().exists(P))
551 CmdArgs.push_back(Args.MakeArgString(StringRef(
"-L") + P));
557 ArgStringList &CmdArgs) {
579 ArgStringList &CmdArgs) {
582 CmdArgs.push_back(
"--no-as-needed");
584 if (TC.
getTriple().getOS() != llvm::Triple::RTEMS &&
586 CmdArgs.push_back(
"-lpthread");
588 CmdArgs.push_back(
"-lrt");
590 CmdArgs.push_back(
"-lm");
595 TC.
getTriple().getOS() != llvm::Triple::RTEMS)
596 CmdArgs.push_back(
"-ldl");
600 CmdArgs.push_back(
"-lexecinfo");
614 SharedRuntimes.push_back(
"asan");
615 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
616 HelperStaticRuntimes.push_back(
"asan-preinit");
620 SharedRuntimes.push_back(
"ubsan_minimal");
622 SharedRuntimes.push_back(
"ubsan_standalone");
626 SharedRuntimes.push_back(
"scudo_minimal");
628 SharedRuntimes.push_back(
"scudo");
631 SharedRuntimes.push_back(
"hwasan");
636 StaticRuntimes.push_back(
"stats_client");
639 if (Args.hasArg(options::OPT_shared) || SanArgs.
needsSharedRt()) {
644 StaticRuntimes.push_back(
"asan");
646 StaticRuntimes.push_back(
"asan_cxx");
650 StaticRuntimes.push_back(
"hwasan");
652 StaticRuntimes.push_back(
"hwasan_cxx");
655 StaticRuntimes.push_back(
"dfsan");
657 StaticRuntimes.push_back(
"lsan");
659 StaticRuntimes.push_back(
"msan");
661 StaticRuntimes.push_back(
"msan_cxx");
664 StaticRuntimes.push_back(
"tsan");
666 StaticRuntimes.push_back(
"tsan_cxx");
670 StaticRuntimes.push_back(
"ubsan_minimal");
672 StaticRuntimes.push_back(
"ubsan_standalone");
674 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
678 NonWholeStaticRuntimes.push_back(
"safestack");
679 RequiredSymbols.push_back(
"__safestack_init");
682 StaticRuntimes.push_back(
"cfi");
684 StaticRuntimes.push_back(
"cfi_diag");
686 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
689 NonWholeStaticRuntimes.push_back(
"stats");
690 RequiredSymbols.push_back(
"__sanitizer_stats_register");
693 StaticRuntimes.push_back(
"esan");
696 StaticRuntimes.push_back(
"scudo_minimal");
698 StaticRuntimes.push_back(
"scudo_cxx_minimal");
700 StaticRuntimes.push_back(
"scudo");
702 StaticRuntimes.push_back(
"scudo_cxx");
710 ArgStringList &CmdArgs) {
712 NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
714 NonWholeStaticRuntimes, HelperStaticRuntimes,
719 && !Args.hasArg(options::OPT_shared)) {
722 if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx))
726 for (
auto RT : SharedRuntimes)
728 for (
auto RT : HelperStaticRuntimes)
730 bool AddExportDynamic =
false;
731 for (
auto RT : StaticRuntimes) {
735 for (
auto RT : NonWholeStaticRuntimes) {
739 for (
auto S : RequiredSymbols) {
740 CmdArgs.push_back(
"-u");
741 CmdArgs.push_back(Args.MakeArgString(S));
745 if (AddExportDynamic)
746 CmdArgs.push_back(
"--export-dynamic");
750 CmdArgs.push_back(
"-export-dynamic-symbol=__cfi_check");
752 return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
756 if (Args.hasArg(options::OPT_shared))
760 CmdArgs.push_back(
"-whole-archive");
764 CmdArgs.push_back(
"-no-whole-archive");
772 CmdArgs.push_back(
"--no-as-needed");
773 CmdArgs.push_back(
"-lpthread");
775 CmdArgs.push_back(
"-lrt");
776 CmdArgs.push_back(
"-lm");
781 CmdArgs.push_back(
"-ldl");
786 if (Arg *A = Args.getLastArg(options::OPT_O_Group))
787 return !A->getOption().matches(options::OPT_O0);
798 if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
799 if (StringRef(A->getValue()) ==
"single")
800 return Args.MakeArgString(F);
802 llvm::sys::path::replace_extension(F,
"dwo");
803 return Args.MakeArgString(F);
807 const JobAction &JA,
const ArgList &Args,
808 const InputInfo &Output,
const char *OutFile) {
809 ArgStringList ExtractArgs;
810 ExtractArgs.push_back(
"--extract-dwo");
812 ArgStringList StripArgs;
813 StripArgs.push_back(
"--strip-dwo");
818 ExtractArgs.push_back(OutFile);
825 C.
addCommand(llvm::make_unique<Command>(JA, T, Exec, ExtractArgs, II));
828 C.
addCommand(llvm::make_unique<Command>(JA, T, Exec, StripArgs, II));
837 Args.ClaimAllArgs(options::OPT_flto_EQ);
838 Args.ClaimAllArgs(options::OPT_flto);
839 Args.ClaimAllArgs(options::OPT_fno_lto);
843 auto *ProfileUseArg = Args.getLastArg(
844 options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
845 options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
846 options::OPT_fno_profile_instr_use);
849 ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
850 ProfileUseArg =
nullptr;
852 return ProfileUseArg;
856 auto *ProfileSampleUseArg = Args.getLastArg(
857 options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ,
858 options::OPT_fauto_profile, options::OPT_fauto_profile_EQ,
859 options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile);
861 if (ProfileSampleUseArg &&
862 (ProfileSampleUseArg->getOption().matches(
863 options::OPT_fno_profile_sample_use) ||
864 ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile)))
867 return Args.getLastArg(options::OPT_fprofile_sample_use_EQ,
868 options::OPT_fauto_profile_EQ);
875 std::tuple<llvm::Reloc::Model, unsigned, bool>
878 const llvm::Triple &Triple = ToolChain.
getTriple();
883 if (Triple.isOSBinFormatMachO() && Args.hasArg(options::OPT_static))
885 bool IsPICLevelTwo = PIC;
888 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
891 if (Triple.isAndroid()) {
892 switch (Triple.getArch()) {
893 case llvm::Triple::arm:
894 case llvm::Triple::armeb:
895 case llvm::Triple::thumb:
896 case llvm::Triple::thumbeb:
897 case llvm::Triple::aarch64:
898 case llvm::Triple::mips:
899 case llvm::Triple::mipsel:
900 case llvm::Triple::mips64:
901 case llvm::Triple::mips64el:
905 case llvm::Triple::x86:
906 case llvm::Triple::x86_64:
908 IsPICLevelTwo =
true;
917 if (Triple.isOSOpenBSD()) {
919 case llvm::Triple::arm:
920 case llvm::Triple::aarch64:
921 case llvm::Triple::mips64:
922 case llvm::Triple::mips64el:
923 case llvm::Triple::x86:
924 case llvm::Triple::x86_64:
925 IsPICLevelTwo =
false;
928 case llvm::Triple::ppc:
929 case llvm::Triple::sparc:
930 case llvm::Triple::sparcel:
931 case llvm::Triple::sparcv9:
932 IsPICLevelTwo =
true;
941 if (Triple.getArch() == llvm::Triple::amdgcn)
948 Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
949 options::OPT_fpic, options::OPT_fno_pic,
950 options::OPT_fPIE, options::OPT_fno_PIE,
951 options::OPT_fpie, options::OPT_fno_pie);
952 if (Triple.isOSWindows() && LastPICArg &&
954 Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
955 options::OPT_fPIE, options::OPT_fpie)) {
956 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
957 << LastPICArg->getSpelling() << Triple.str();
958 if (Triple.getArch() == llvm::Triple::x86_64)
959 return std::make_tuple(llvm::Reloc::PIC_, 2U,
false);
960 return std::make_tuple(llvm::Reloc::Static, 0U,
false);
967 Option O = LastPICArg->getOption();
968 if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) ||
969 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) {
970 PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie);
972 PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic);
974 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fPIC);
977 if (EffectiveTriple.isPS4CPU()) {
978 Arg *ModelArg = Args.getLastArg(options::OPT_mcmodel_EQ);
979 StringRef Model = ModelArg ? ModelArg->getValue() :
"";
980 if (Model !=
"kernel") {
983 << LastPICArg->getSpelling();
993 if (PIC && (Triple.isOSDarwin() || EffectiveTriple.isPS4CPU()))
999 ((!EffectiveTriple.isiOS() || EffectiveTriple.isOSVersionLT(6)) &&
1000 !EffectiveTriple.isWatchOS()))
1003 if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
1006 if (!Triple.isOSDarwin())
1007 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1008 << A->getSpelling() << Triple.str();
1017 return std::make_tuple(llvm::Reloc::DynamicNoPIC, PIC ? 2U : 0U,
false);
1020 bool EmbeddedPISupported;
1021 switch (Triple.getArch()) {
1022 case llvm::Triple::arm:
1023 case llvm::Triple::armeb:
1024 case llvm::Triple::thumb:
1025 case llvm::Triple::thumbeb:
1026 EmbeddedPISupported =
true;
1029 EmbeddedPISupported =
false;
1033 bool ROPI =
false, RWPI =
false;
1034 Arg* LastROPIArg = Args.getLastArg(options::OPT_fropi, options::OPT_fno_ropi);
1035 if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
1036 if (!EmbeddedPISupported)
1037 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1038 << LastROPIArg->getSpelling() << Triple.str();
1041 Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
1042 if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
1043 if (!EmbeddedPISupported)
1044 ToolChain.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1045 << LastRWPIArg->getSpelling() << Triple.str();
1050 if ((ROPI || RWPI) && (PIC || PIE))
1051 ToolChain.
getDriver().
Diag(diag::err_drv_ropi_rwpi_incompatible_with_pic);
1053 if (Triple.isMIPS()) {
1060 if (ABIName ==
"n64")
1063 if(Args.hasArg(options::OPT_mno_abicalls))
1064 return std::make_tuple(llvm::Reloc::Static, 0U,
false);
1067 IsPICLevelTwo =
false;
1071 return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE);
1073 llvm::Reloc::Model RelocM = llvm::Reloc::Static;
1075 RelocM = llvm::Reloc::ROPI_RWPI;
1077 RelocM = llvm::Reloc::ROPI;
1079 RelocM = llvm::Reloc::RWPI;
1081 return std::make_tuple(RelocM, 0U,
false);
1101 const ArgList &Args) {
1102 const Arg *A = Args.getLastArg(options::OPT_falign_functions,
1103 options::OPT_falign_functions_EQ,
1104 options::OPT_fno_align_functions);
1105 if (!A || A->getOption().matches(options::OPT_fno_align_functions))
1108 if (A->getOption().matches(options::OPT_falign_functions))
1112 if (StringRef(A->getValue()).getAsInteger(10, Value) || Value > 65536)
1114 << A->getAsString(Args) << A->getValue();
1115 return Value ? llvm::Log2_32_Ceil(
std::min(Value, 65536u)) :
Value;
1119 ArgStringList &CmdArgs) {
1120 llvm::Reloc::Model RelocationModel;
1123 std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(ToolChain, Args);
1125 if (RelocationModel != llvm::Reloc::Static)
1126 CmdArgs.push_back(
"-KPIC");
1132 return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc,
false);
1136 ArgStringList &CmdArgs,
const ArgList &Args) {
1137 bool isAndroid = Triple.isAndroid();
1138 bool isCygMing = Triple.isOSCygMing();
1139 bool IsIAMCU = Triple.isOSIAMCU();
1140 bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) ||
1141 Args.hasArg(options::OPT_static);
1143 bool SharedLibgcc = Args.hasArg(options::OPT_shared_libgcc);
1144 bool UnspecifiedLibgcc = !StaticLibgcc && !SharedLibgcc;
1157 bool LibGccFirst = (D.
CCCIsCC() && UnspecifiedLibgcc) || StaticLibgcc;
1159 CmdArgs.push_back(
"-lgcc");
1161 bool AsNeeded = D.
CCCIsCC() && UnspecifiedLibgcc && !isAndroid && !isCygMing;
1163 CmdArgs.push_back(
"--as-needed");
1165 if ((UnspecifiedLibgcc || SharedLibgcc) && !isAndroid)
1166 CmdArgs.push_back(
"-lgcc_s");
1168 else if (StaticLibgcc && !isAndroid && !IsIAMCU)
1169 CmdArgs.push_back(
"-lgcc_eh");
1172 CmdArgs.push_back(
"--no-as-needed");
1175 CmdArgs.push_back(
"-lgcc");
1182 if (isAndroid && !StaticLibgcc)
1183 CmdArgs.push_back(
"-ldl");
1187 ArgStringList &CmdArgs,
const ArgList &Args) {
1197 if (TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
1200 if (Args.hasArg(options::OPT_rtlib_EQ)) {
1201 TC.
getDriver().
Diag(diag::err_drv_unsupported_rtlib_for_platform)
1202 << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() <<
"MSVC";
1219 const ArgList &Args, ArgStringList &CmdArgs,
1230 llvm::sys::path::replace_extension(Name,
"lk");
1231 LKS = C.
getArgs().MakeArgString(Name.c_str());
1233 llvm::sys::path::replace_extension(Name,
"");
1239 CmdArgs.push_back(
"-T");
1240 CmdArgs.push_back(LKS);
1243 std::string LksBuffer;
1244 llvm::raw_string_ostream LksStream(LksBuffer);
1249 assert(OpenMPToolChains.first != OpenMPToolChains.second &&
1250 "No OpenMP toolchains??");
1260 LksStream <<
"/*\n";
1261 LksStream <<
" OpenMP Offload Linker Script\n";
1262 LksStream <<
" *** Automatically generated by Clang ***\n";
1263 LksStream <<
"*/\n";
1264 LksStream <<
"TARGET(binary)\n";
1265 auto DTC = OpenMPToolChains.first;
1266 for (
auto &II : Inputs) {
1267 const Action *A = II.getAction();
1269 if (A && isa<LinkJobAction>(A) &&
1271 assert(DTC != OpenMPToolChains.second &&
1272 "More device inputs than device toolchains??");
1273 InputBinaryInfo.push_back(std::make_pair(
1274 DTC->second->getTriple().normalize(), II.getFilename()));
1276 LksStream <<
"INPUT(" << II.getFilename() <<
")\n";
1280 assert(DTC == OpenMPToolChains.second &&
1281 "Less device inputs than device toolchains??");
1283 LksStream <<
"SECTIONS\n";
1287 for (
const auto &BI : InputBinaryInfo) {
1288 LksStream <<
" .omp_offloading." << BI.first <<
" :\n";
1289 LksStream <<
" ALIGN(0x10)\n";
1290 LksStream <<
" {\n";
1291 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.img_start." << BI.first
1293 LksStream <<
" " << BI.second <<
"\n";
1294 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.img_end." << BI.first
1296 LksStream <<
" }\n";
1302 LksStream <<
" .omp_offloading.entries :\n";
1303 LksStream <<
" ALIGN(0x10)\n";
1304 LksStream <<
" SUBALIGN(0x01)\n";
1305 LksStream <<
" {\n";
1306 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.entries_begin = .);\n";
1307 LksStream <<
" *(.omp_offloading.entries)\n";
1308 LksStream <<
" PROVIDE_HIDDEN(.omp_offloading.entries_end = .);\n";
1309 LksStream <<
" }\n";
1311 LksStream <<
"INSERT BEFORE .data\n";
1316 if (C.
getArgs().hasArg(options::OPT_fopenmp_dump_offload_linker_script))
1317 llvm::errs() << LksBuffer;
1320 if (C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH))
1325 llvm::raw_fd_ostream Lksf(LKS, EC, llvm::sys::fs::F_None);
1328 C.
getDriver().
Diag(clang::diag::err_unable_to_make_temp) << EC.message();
1343 ArgStringList &CmdArgs,
const JobAction &JA,
1351 for (
const auto &II : Inputs) {
1352 const Action *A = II.getAction();
1355 DeviceInputs.push_back(II);
1359 if (DeviceInputs.empty())
1366 llvm::sys::path::replace_extension(Name,
"lk");
1367 LKS = C.
getArgs().MakeArgString(Name.c_str());
1369 llvm::sys::path::replace_extension(Name,
"");
1375 CmdArgs.push_back(
"-T");
1376 CmdArgs.push_back(LKS);
1379 std::string LksBuffer;
1380 llvm::raw_string_ostream LksStream(LksBuffer);
1385 assert(HIPTC->getTriple().getArch() == llvm::Triple::amdgcn &&
1392 const char *BundleFile =
1400 LksStream <<
"/*\n";
1401 LksStream <<
" HIP Offload Linker Script\n";
1402 LksStream <<
" *** Automatically generated by Clang ***\n";
1403 LksStream <<
"*/\n";
1404 LksStream <<
"TARGET(binary)\n";
1405 LksStream <<
"INPUT(" << BundleFileName <<
")\n";
1406 LksStream <<
"SECTIONS\n";
1408 LksStream <<
" .hip_fatbin :\n";
1409 LksStream <<
" ALIGN(0x10)\n";
1410 LksStream <<
" {\n";
1411 LksStream <<
" PROVIDE_HIDDEN(__hip_fatbin = .);\n";
1412 LksStream <<
" " << BundleFileName <<
"\n";
1413 LksStream <<
" }\n";
1414 LksStream <<
" /DISCARD/ :\n";
1415 LksStream <<
" {\n";
1416 LksStream <<
" * ( __CLANG_OFFLOAD_BUNDLE__* )\n";
1417 LksStream <<
" }\n";
1419 LksStream <<
"INSERT BEFORE .data\n";
1424 if (C.
getArgs().hasArg(options::OPT_fhip_dump_offload_linker_script))
1425 llvm::errs() << LksBuffer;
1428 if (C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH))
1433 llvm::raw_fd_ostream Lksf(LKS, EC, llvm::sys::fs::F_None);
1436 C.
getDriver().
Diag(clang::diag::err_unable_to_make_temp) << EC.message();
1447 const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ);
1451 StringRef SaveStats = A->getValue();
1453 if (SaveStats ==
"obj" && Output.
isFilename()) {
1455 llvm::sys::path::remove_filename(StatsFile);
1456 }
else if (SaveStats !=
"cwd") {
1457 D.
Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats;
1461 StringRef BaseName = llvm::sys::path::filename(Input.
getBaseInput());
1462 llvm::sys::path::append(StatsFile, BaseName);
1463 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.
bool isDeviceOffloading(OffloadKind OKind) const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
An unknown OpenMP runtime.
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.
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
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
bool isSaveTempsEnabled() const
static void addSanitizerLibPath(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Name)
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.
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 CCCIsCC() const
Whether the driver should follow gcc like behavior.
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