20#include "clang/Config/config.h"
28#include "llvm/ADT/StringSet.h"
29#include "llvm/ADT/Twine.h"
30#include "llvm/Option/ArgList.h"
31#include "llvm/Support/CodeGen.h"
32#include "llvm/Support/Path.h"
33#include "llvm/Support/VirtualFileSystem.h"
34#include "llvm/TargetParser/RISCVISAInfo.h"
35#include "llvm/TargetParser/TargetParser.h"
36#include <system_error>
57 ArgStringList &CmdArgs) {
58 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
59 StringRef CPUArg(A->getValue());
60 if (CPUArg.equals_insensitive(
"krait"))
61 CmdArgs.push_back(
"-mcpu=cortex-a15");
62 else if (CPUArg.equals_insensitive(
"kryo"))
63 CmdArgs.push_back(
"-mcpu=cortex-a57");
65 Args.AddLastArg(CmdArgs, options::OPT_mcpu_EQ);
73 const char *LinkingOutput)
const {
75 ArgStringList CmdArgs;
77 for (
const auto &A : Args) {
85 A->render(Args, CmdArgs);
93 CmdArgs.push_back(
"-arch");
95 Args.MakeArgString(
getToolChain().getDefaultUniversalArchName()));
106 case llvm::Triple::x86:
107 case llvm::Triple::ppc:
108 case llvm::Triple::ppcle:
109 CmdArgs.push_back(
"-m32");
111 case llvm::Triple::x86_64:
112 case llvm::Triple::ppc64:
113 case llvm::Triple::ppc64le:
114 CmdArgs.push_back(
"-m64");
116 case llvm::Triple::sparcel:
117 CmdArgs.push_back(
"-EL");
123 CmdArgs.push_back(
"-o");
126 CmdArgs.push_back(
"-fsyntax-only");
129 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
139 for (
const auto &II : Inputs) {
142 D.Diag(clang::diag::err_drv_no_linker_llvm_support)
144 else if (II.getType() == types::TY_AST)
146 else if (II.getType() == types::TY_ModuleFile)
147 D.Diag(diag::err_drv_no_module_support)
151 CmdArgs.push_back(
"-x");
156 CmdArgs.push_back(II.getFilename());
158 const Arg &A = II.getInputArg();
161 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
162 CmdArgs.push_back(
"-lstdc++");
167 A.render(Args, CmdArgs);
171 const std::string &customGCCName =
D.getCCCGenericGCCName();
173 if (!customGCCName.empty())
174 GCCName = customGCCName.c_str();
175 else if (
D.CCCIsCXX()) {
180 const char *Exec = Args.MakeArgString(
getToolChain().GetProgramPath(GCCName));
181 C.addCommand(std::make_unique<Command>(JA, *
this,
183 Exec, CmdArgs, Inputs, Output));
187 const JobAction &JA, ArgStringList &CmdArgs)
const {
188 CmdArgs.push_back(
"-E");
192 ArgStringList &CmdArgs)
const {
193 const Driver &
D = getToolChain().getDriver();
197 case types::TY_LLVM_IR:
198 case types::TY_LTO_IR:
199 case types::TY_LLVM_BC:
200 case types::TY_LTO_BC:
201 CmdArgs.push_back(
"-c");
205 case types::TY_Object:
206 CmdArgs.push_back(
"-c");
208 case types::TY_PP_Asm:
209 CmdArgs.push_back(
"-S");
211 case types::TY_Nothing:
212 CmdArgs.push_back(
"-fsyntax-only");
215 D.Diag(diag::err_drv_invalid_gcc_output_type) << getTypeName(JA.
getType());
220 ArgStringList &CmdArgs)
const {
224static const char *
getLDMOption(
const llvm::Triple &
T,
const ArgList &Args) {
225 switch (
T.getArch()) {
226 case llvm::Triple::x86:
230 case llvm::Triple::aarch64:
231 return "aarch64linux";
232 case llvm::Triple::aarch64_be:
233 return "aarch64linuxb";
234 case llvm::Triple::arm:
235 case llvm::Triple::thumb:
236 case llvm::Triple::armeb:
237 case llvm::Triple::thumbeb:
239 :
"armelf_linux_eabi";
240 case llvm::Triple::m68k:
242 case llvm::Triple::ppc:
244 return "elf32ppclinux";
246 case llvm::Triple::ppcle:
248 return "elf32lppclinux";
250 case llvm::Triple::ppc64:
252 case llvm::Triple::ppc64le:
254 case llvm::Triple::riscv32:
255 return "elf32lriscv";
256 case llvm::Triple::riscv64:
257 return "elf64lriscv";
258 case llvm::Triple::sparc:
259 case llvm::Triple::sparcel:
260 return "elf32_sparc";
261 case llvm::Triple::sparcv9:
262 return "elf64_sparc";
263 case llvm::Triple::loongarch32:
264 return "elf32loongarch";
265 case llvm::Triple::loongarch64:
266 return "elf64loongarch";
267 case llvm::Triple::mips:
268 return "elf32btsmip";
269 case llvm::Triple::mipsel:
270 return "elf32ltsmip";
271 case llvm::Triple::mips64:
273 T.getEnvironment() == llvm::Triple::GNUABIN32)
274 return "elf32btsmipn32";
275 return "elf64btsmip";
276 case llvm::Triple::mips64el:
278 T.getEnvironment() == llvm::Triple::GNUABIN32)
279 return "elf32ltsmipn32";
280 return "elf64ltsmip";
281 case llvm::Triple::systemz:
283 case llvm::Triple::x86_64:
285 return "elf32_x86_64";
287 case llvm::Triple::ve:
289 case llvm::Triple::csky:
290 return "cskyelf_linux";
297 bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
298 if (HasStaticPIE && Args.hasArg(options::OPT_no_pie)) {
300 const llvm::opt::OptTable &Opts =
D.getOpts();
301 StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
302 StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
303 D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
309 return Args.hasArg(options::OPT_static) &&
310 !Args.hasArg(options::OPT_static_pie);
316 const char *LinkingOutput)
const {
317 const Driver &
D = getToolChain().getDriver();
320 Args.ClaimAllArgs(options::OPT_g_Group);
322 Args.ClaimAllArgs(options::OPT_emit_llvm);
325 Args.ClaimAllArgs(options::OPT_w);
327 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
330 ArgStringList CmdArgs;
332 CmdArgs.push_back(
"rcsD");
335 for (
const auto &II : Inputs) {
336 if (II.isFilename()) {
337 CmdArgs.push_back(II.getFilename());
344 if (Output.
isFilename() && llvm::sys::fs::exists(OutputFileName)) {
345 if (std::error_code EC = llvm::sys::fs::remove(OutputFileName)) {
346 D.Diag(diag::err_drv_unable_to_remove_file) << EC.message();
351 const char *Exec = Args.MakeArgString(getToolChain().GetStaticLibToolPath());
352 C.addCommand(std::make_unique<Command>(JA, *
this,
354 Exec, CmdArgs, Inputs, Output));
361 const char *LinkingOutput)
const {
369 const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
378 const bool HasCRTBeginEndFiles =
382 ArgStringList CmdArgs;
385 Args.ClaimAllArgs(options::OPT_g_Group);
387 Args.ClaimAllArgs(options::OPT_emit_llvm);
390 Args.ClaimAllArgs(options::OPT_w);
392 if (!
D.SysRoot.empty())
393 CmdArgs.push_back(Args.MakeArgString(
"--sysroot=" +
D.SysRoot));
395 if (Args.hasArg(options::OPT_s))
396 CmdArgs.push_back(
"-s");
398 if (Triple.isARM() || Triple.isThumb()) {
402 CmdArgs.push_back(IsBigEndian ?
"-EB" :
"-EL");
403 }
else if (Triple.isAArch64()) {
404 CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ?
"-EB" :
"-EL");
409 if (Arch == llvm::Triple::aarch64 && (isAndroid || isOHOSFamily)) {
411 if (CPU.empty() || CPU ==
"generic" || CPU ==
"cortex-a53")
412 CmdArgs.push_back(
"--fix-cortex-a53-843419");
417 CmdArgs.push_back(
"--eh-frame-hdr");
420 CmdArgs.push_back(
"-m");
421 CmdArgs.push_back(LDMOption);
423 D.Diag(diag::err_target_unknown_triple) << Triple.str();
427 if (Triple.isRISCV()) {
428 CmdArgs.push_back(
"-X");
429 if (Args.hasArg(options::OPT_mno_relax))
430 CmdArgs.push_back(
"--no-relax");
433 const bool IsShared = Args.hasArg(options::OPT_shared);
435 CmdArgs.push_back(
"-shared");
438 CmdArgs.push_back(
"-static");
439 CmdArgs.push_back(
"-pie");
440 CmdArgs.push_back(
"--no-dynamic-linker");
441 CmdArgs.push_back(
"-z");
442 CmdArgs.push_back(
"text");
444 CmdArgs.push_back(
"-static");
445 }
else if (!Args.hasArg(options::OPT_r)) {
446 if (Args.hasArg(options::OPT_rdynamic))
447 CmdArgs.push_back(
"-export-dynamic");
449 IsPIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
452 CmdArgs.push_back(
"-pie");
453 CmdArgs.push_back(
"-dynamic-linker");
454 CmdArgs.push_back(Args.MakeArgString(Twine(
D.DyldPrefix) +
459 CmdArgs.push_back(
"-o");
462 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
464 if (!isAndroid && !IsIAMCU) {
465 const char *crt1 =
nullptr;
466 if (!Args.hasArg(options::OPT_shared)) {
467 if (Args.hasArg(options::OPT_pg))
471 else if (IsStaticPIE)
483 CmdArgs.push_back(
"-z");
484 CmdArgs.push_back(
"max-page-size=0x4000000");
489 else if (HasCRTBeginEndFiles) {
499 const char *crtbegin;
500 if (Args.hasArg(options::OPT_shared))
501 crtbegin = isAndroid ?
"crtbegin_so.o" :
"crtbeginS.o";
503 crtbegin = isAndroid ?
"crtbegin_static.o" :
"crtbeginT.o";
504 else if (IsPIE || IsStaticPIE)
505 crtbegin = isAndroid ?
"crtbegin_dynamic.o" :
"crtbeginS.o";
507 crtbegin = isAndroid ?
"crtbegin_dynamic.o" :
"crtbegin.o";
510 CmdArgs.push_back(Args.MakeArgString(
P));
516 if (isAndroid && Args.hasFlag(options::OPT_fandroid_pad_segment,
517 options::OPT_fno_android_pad_segment,
false))
522 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
526 if (
D.isUsingLTO()) {
527 assert(!Inputs.empty() &&
"Must have at least one input.");
529 auto Input = llvm::find_if(
531 if (Input == Inputs.end())
534 Input = Inputs.begin();
540 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
541 CmdArgs.push_back(
"--no-demangle");
551 getToolChain().addProfileRTLibs(Args, CmdArgs);
554 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
557 bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
558 !Args.hasArg(options::OPT_static);
559 if (OnlyLibstdcxxStatic)
560 CmdArgs.push_back(
"-Bstatic");
562 if (OnlyLibstdcxxStatic)
563 CmdArgs.push_back(
"-Bdynamic");
565 CmdArgs.push_back(
"-lm");
569 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
575 if (
D.IsFlangMode()) {
578 CmdArgs.push_back(
"-lm");
581 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_r)) {
582 if (!Args.hasArg(options::OPT_nodefaultlibs)) {
584 CmdArgs.push_back(
"--start-group");
586 if (NeedsSanitizerDeps)
592 bool WantPthread = Args.hasArg(options::OPT_pthread) ||
593 Args.hasArg(options::OPT_pthreads);
596 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
597 !Args.hasArg(options::OPT_static);
613 if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
614 CmdArgs.push_back(
"--push-state");
615 CmdArgs.push_back(
"--as-needed");
616 CmdArgs.push_back(
"-latomic");
617 CmdArgs.push_back(
"--pop-state");
622 if (WantPthread && !isAndroid && !isOHOSFamily)
623 CmdArgs.push_back(
"-lpthread");
625 if (Args.hasArg(options::OPT_fsplit_stack))
626 CmdArgs.push_back(
"--wrap=pthread_create");
628 if (!Args.hasArg(options::OPT_nolibc))
629 CmdArgs.push_back(
"-lc");
633 CmdArgs.push_back(
"-lgloss");
636 CmdArgs.push_back(
"--end-group");
642 CmdArgs.push_back(
"--as-needed");
643 CmdArgs.push_back(
"-lsoftfp");
644 CmdArgs.push_back(
"--no-as-needed");
648 if (!Args.hasArg(options::OPT_nostartfiles) && !IsIAMCU) {
649 if (HasCRTBeginEndFiles) {
660 if (Args.hasArg(options::OPT_shared))
661 crtend = isAndroid ?
"crtend_so.o" :
"crtendS.o";
662 else if (IsPIE || IsStaticPIE)
663 crtend = isAndroid ?
"crtend_android.o" :
"crtendS.o";
665 crtend = isAndroid ?
"crtend_android.o" :
"crtend.o";
668 CmdArgs.push_back(Args.MakeArgString(
P));
675 Args.AddAllArgs(CmdArgs, options::OPT_T);
678 C.addCommand(std::make_unique<Command>(JA, *
this,
680 Exec, CmdArgs, Inputs, Output));
688 const char *LinkingOutput)
const {
689 const auto &
D = getToolChain().getDriver();
693 ArgStringList CmdArgs;
695 llvm::Reloc::Model RelocationModel;
698 const char *DefaultAssembler =
"as";
701 if (getToolChain().getTriple().isOSSolaris())
702 DefaultAssembler =
"gas";
703 std::tie(RelocationModel, PICLevel, IsPIE) =
706 if (
const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ)) {
707 if (A->getOption().getID() == options::OPT_gz) {
708 CmdArgs.push_back(
"--compress-debug-sections");
710 StringRef
Value = A->getValue();
713 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
715 D.Diag(diag::err_drv_unsupported_option_argument)
716 << A->getSpelling() <<
Value;
721 switch (getToolChain().getArch()) {
726 case llvm::Triple::x86:
727 CmdArgs.push_back(
"--32");
729 case llvm::Triple::x86_64:
730 if (getToolChain().getTriple().isX32())
731 CmdArgs.push_back(
"--x32");
733 CmdArgs.push_back(
"--64");
735 case llvm::Triple::ppc: {
736 CmdArgs.push_back(
"-a32");
737 CmdArgs.push_back(
"-mppc");
738 CmdArgs.push_back(
"-mbig-endian");
743 case llvm::Triple::ppcle: {
744 CmdArgs.push_back(
"-a32");
745 CmdArgs.push_back(
"-mppc");
746 CmdArgs.push_back(
"-mlittle-endian");
751 case llvm::Triple::ppc64: {
752 CmdArgs.push_back(
"-a64");
753 CmdArgs.push_back(
"-mppc64");
754 CmdArgs.push_back(
"-mbig-endian");
759 case llvm::Triple::ppc64le: {
760 CmdArgs.push_back(
"-a64");
761 CmdArgs.push_back(
"-mppc64");
762 CmdArgs.push_back(
"-mlittle-endian");
767 case llvm::Triple::riscv32:
768 case llvm::Triple::riscv64: {
770 CmdArgs.push_back(
"-mabi");
771 CmdArgs.push_back(ABIName.data());
772 std::string MArchName =
774 CmdArgs.push_back(
"-march");
775 CmdArgs.push_back(Args.MakeArgString(MArchName));
776 if (!Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax,
true))
777 Args.addOptOutFlag(CmdArgs, options::OPT_mrelax, options::OPT_mno_relax);
780 case llvm::Triple::sparc:
781 case llvm::Triple::sparcel: {
782 CmdArgs.push_back(
"-32");
783 std::string CPU =
getCPUName(
D, Args, getToolChain().getTriple());
789 case llvm::Triple::sparcv9: {
790 CmdArgs.push_back(
"-64");
791 std::string CPU =
getCPUName(
D, Args, getToolChain().getTriple());
797 case llvm::Triple::arm:
798 case llvm::Triple::armeb:
799 case llvm::Triple::thumb:
800 case llvm::Triple::thumbeb: {
801 const llvm::Triple &Triple2 = getToolChain().getTriple();
803 switch (Triple2.getSubArch()) {
804 case llvm::Triple::ARMSubArch_v7:
805 CmdArgs.push_back(
"-mfpu=neon");
807 case llvm::Triple::ARMSubArch_v8:
808 CmdArgs.push_back(
"-mfpu=crypto-neon-fp-armv8");
817 CmdArgs.push_back(Args.MakeArgString(
"-mfloat-abi=soft"));
820 CmdArgs.push_back(Args.MakeArgString(
"-mfloat-abi=softfp"));
823 CmdArgs.push_back(Args.MakeArgString(
"-mfloat-abi=hard"));
827 Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
830 Args.AddLastArg(CmdArgs, options::OPT_mfpu_EQ);
834 if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
835 A->ignoreTargetSpecific();
838 case llvm::Triple::aarch64:
839 case llvm::Triple::aarch64_be: {
841 getToolChain().getArch() == llvm::Triple::aarch64_be ?
"-EB" :
"-EL");
842 Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
848 case llvm::Triple::loongarch64: {
851 CmdArgs.push_back(Args.MakeArgString(
"-mabi=" + ABIName));
854 case llvm::Triple::mips:
855 case llvm::Triple::mipsel:
856 case llvm::Triple::mips64:
857 case llvm::Triple::mips64el: {
863 CmdArgs.push_back(
"-march");
864 CmdArgs.push_back(CPUName.data());
866 CmdArgs.push_back(
"-mabi");
867 CmdArgs.push_back(ABIName.data());
871 if (RelocationModel == llvm::Reloc::Static)
872 CmdArgs.push_back(
"-mno-shared");
876 if (ABIName !=
"64" && !Args.hasArg(options::OPT_mno_abicalls))
877 CmdArgs.push_back(
"-call_nonpic");
879 if (getToolChain().getTriple().isLittleEndian())
880 CmdArgs.push_back(
"-EL");
882 CmdArgs.push_back(
"-EB");
884 if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
885 if (StringRef(A->getValue()) ==
"2008")
886 CmdArgs.push_back(Args.MakeArgString(
"-mnan=2008"));
890 if (Arg *A = Args.getLastArg(options::OPT_mfp32, options::OPT_mfpxx,
891 options::OPT_mfp64)) {
893 A->render(Args, CmdArgs);
895 Args, getToolChain().getTriple(), CPUName, ABIName,
897 getToolChain().getTriple())))
898 CmdArgs.push_back(
"-mfpxx");
903 Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16)) {
904 if (A->getOption().matches(options::OPT_mips16)) {
906 A->render(Args, CmdArgs);
909 CmdArgs.push_back(
"-no-mips16");
913 Args.AddLastArg(CmdArgs, options::OPT_mmicromips,
914 options::OPT_mno_micromips);
915 Args.AddLastArg(CmdArgs, options::OPT_mdsp, options::OPT_mno_dsp);
916 Args.AddLastArg(CmdArgs, options::OPT_mdspr2, options::OPT_mno_dspr2);
918 if (Arg *A = Args.getLastArg(options::OPT_mmsa, options::OPT_mno_msa)) {
921 if (A->getOption().matches(options::OPT_mmsa))
922 CmdArgs.push_back(Args.MakeArgString(
"-mmsa"));
925 Args.AddLastArg(CmdArgs, options::OPT_mhard_float,
926 options::OPT_msoft_float);
928 Args.AddLastArg(CmdArgs, options::OPT_mdouble_float,
929 options::OPT_msingle_float);
931 Args.AddLastArg(CmdArgs, options::OPT_modd_spreg,
932 options::OPT_mno_odd_spreg);
937 case llvm::Triple::systemz: {
941 CmdArgs.push_back(Args.MakeArgString(
"-march=" + CPUName));
944 case llvm::Triple::ve:
945 DefaultAssembler =
"nas";
948 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
949 options::OPT_fdebug_prefix_map_EQ)) {
950 StringRef Map = A->getValue();
951 if (!Map.contains(
'='))
952 D.Diag(diag::err_drv_invalid_argument_to_option)
953 << Map << A->getOption().getName();
955 CmdArgs.push_back(Args.MakeArgString(
"--debug-prefix-map"));
956 CmdArgs.push_back(Args.MakeArgString(Map));
961 Args.AddAllArgs(CmdArgs, options::OPT_I);
962 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
964 CmdArgs.push_back(
"-o");
967 for (
const auto &II : Inputs)
968 CmdArgs.push_back(II.getFilename());
970 if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group,
971 options::OPT_gdwarf_2, options::OPT_gdwarf_3,
972 options::OPT_gdwarf_4, options::OPT_gdwarf_5,
973 options::OPT_gdwarf))
974 if (!A->getOption().matches(options::OPT_g0)) {
975 Args.AddLastArg(CmdArgs, options::OPT_g_Flag);
978 CmdArgs.push_back(Args.MakeArgString(
"-gdwarf-" + Twine(DwarfVersion)));
982 Args.MakeArgString(getToolChain().GetProgramPath(DefaultAssembler));
983 C.addCommand(std::make_unique<Command>(JA, *
this,
985 Exec, CmdArgs, Inputs, Output));
990 if (Args.hasArg(options::OPT_gsplit_dwarf) &&
991 getToolChain().getTriple().isOSLinux())
998class FilterNonExistent {
1000 llvm::vfs::FileSystem &VFS;
1003 FilterNonExistent(StringRef
Base, StringRef
File, llvm::vfs::FileSystem &VFS)
1005 bool operator()(
const Multilib &M) {
1012 Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
1013 options::OPT_mfloat_abi_EQ);
1017 return A->getOption().matches(options::OPT_msoft_float) ||
1018 (A->getOption().matches(options::OPT_mfloat_abi_EQ) &&
1019 A->getValue() == StringRef(
"soft"));
1023 return Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb;
1027 return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el;
1031 Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16);
1032 return A && A->getOption().matches(options::OPT_mips16);
1036 Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips);
1037 return A && A->getOption().matches(options::OPT_mmicromips);
1041 return Arch == llvm::Triple::msp430;
1045 FilterNonExistent &NonExistent,
1052 auto MArchMicroMips =
1056 .
flag(
"-mips16",
true)
1057 .
flag(
"-mmicromips",
true);
1066 .
flag(
"-msoft-float",
true)
1067 .
flag(
"-mnan=2008",
true);
1078 .includeSuffix(
"/64")
1080 .flag(
"-mabi=n32",
true)
1081 .flag(
"-m32",
true);
1085 .
Either(MArchMips16, MArchMicroMips, MArchDefault)
1087 .
Either(SoftFloat, Nan2008, DefaultFloat)
1090 .
Either(BigEndian, LittleEndian)
1097 std::vector<std::string> Dirs({
"/include"});
1100 "/../../../../mips-linux-gnu/libc/uclibc/usr/include");
1102 Dirs.push_back(
"/../../../../mips-linux-gnu/libc/usr/include");
1115 .includeSuffix(
"/64")
1118 .flag(
"-mabi=n32",
true);
1124 .flag(
"-mabi=n32",
true);
1127 .
Either(M32, M64, MAbiN32)
1134 MultilibSet *Candidates[] = {&CSMipsMultilibs, &DebianMipsMultilibs};
1135 if (CSMipsMultilibs.
size() < DebianMipsMultilibs.
size())
1136 std::iter_swap(Candidates, Candidates + 1);
1138 if (Candidate->select(Flags,
Result.SelectedMultilibs)) {
1139 if (Candidate == &DebianMipsMultilibs)
1141 Result.Multilibs = *Candidate;
1150 FilterNonExistent &NonExistent,
1164 .flag(
"-march=mips32r2"),
1166 .flag(
"-march=mips32r6"))
1174 .flag(
"-march=mips32"),
1176 .flag(
"-march=mips32r2"),
1178 .flag(
"-march=mips32r6"))
1183 if (VFS.exists(
Path +
"/mips-r6"))
1184 MS = &AndroidMipselMultilibs;
1185 else if (VFS.exists(
Path +
"/32"))
1186 MS = &AndroidMips64elMultilibs;
1195 FilterNonExistent &NonExistent,
1204 .flag(
"-march=mips32r2");
1209 .
flag(
"-march=mips32r2");
1212 .
Either(MArchMipsR2, MArchMipselR2)
1217 return std::vector<std::string>(
1218 {
"/../sysroot" + M.
osSuffix() +
"/usr/include"});
1221 if (MuslMipsMultilibs.
select(Flags,
Result.SelectedMultilibs)) {
1222 Result.Multilibs = MuslMipsMultilibs;
1229 FilterNonExistent &NonExistent,
1237 .
flag(
"-mmicromips",
true)
1238 .
flag(
"-march=mips32");
1243 .
flag(
"-mmicromips");
1248 .
flag(
"-march=mips64r2");
1253 .
flag(
"-march=mips64r2",
true);
1258 .
flag(
"-mmicromips",
true)
1259 .
flag(
"-march=mips32r2");
1267 .
flag(
"-mabi=n32",
true)
1268 .
flag(
"-m32",
true);
1280 MtiMipsMultilibsV1 =
1282 .
Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64,
1294 .
Either(BigEndian, LittleEndian)
1301 std::vector<std::string> Dirs({
"/include"});
1303 Dirs.push_back(
"/../../../../sysroot/uclibc/usr/include");
1305 Dirs.push_back(
"/../../../../sysroot/usr/include");
1315 .
flag(
"-msoft-float",
true)
1316 .
flag(
"-mnan=2008",
true)
1317 .
flag(
"-muclibc",
true);
1320 .
flag(
"-msoft-float")
1321 .
flag(
"-mnan=2008",
true);
1324 .
flag(
"-msoft-float",
true)
1325 .
flag(
"-mnan=2008",
true)
1326 .
flag(
"-muclibc",
true);
1329 .
flag(
"-msoft-float")
1330 .
flag(
"-mnan=2008",
true)
1331 .
flag(
"-mmicromips",
true);
1334 .
flag(
"-msoft-float",
true)
1336 .
flag(
"-muclibc",
true);
1339 .
flag(
"-msoft-float",
true)
1341 .
flag(
"-muclibc",
true)
1342 .
flag(
"-mmicromips",
true);
1343 auto BeHardNanUclibc =
MultilibBuilder(
"/mips-r2-hard-nan2008-uclibc")
1345 .
flag(
"-msoft-float",
true)
1348 auto ElHardNanUclibc =
MultilibBuilder(
"/mipsel-r2-hard-nan2008-uclibc")
1350 .
flag(
"-msoft-float",
true)
1355 .
flag(
"-msoft-float",
true)
1356 .
flag(
"-mnan=2008",
true)
1360 .
flag(
"-msoft-float",
true)
1361 .
flag(
"-mnan=2008",
true)
1365 .
flag(
"-msoft-float",
true)
1367 .
flag(
"-mmicromips");
1370 .
flag(
"-msoft-float")
1371 .
flag(
"-mnan=2008",
true)
1372 .
flag(
"-mmicromips");
1376 .flag(
"-mabi=n32",
true)
1377 .flag(
"-mabi=n64",
true);
1381 .flag(
"-mabi=n64",
true);
1384 .flag(
"-mabi=n32",
true)
1387 MtiMipsMultilibsV2 =
1389 .
Either({BeHard, BeSoft, ElHard, ElSoft, BeHardNan, ElHardNan,
1390 BeHardNanUclibc, ElHardNanUclibc, BeHardUclibc,
1391 ElHardUclibc, ElMicroHardNan, ElMicroSoft})
1392 .Either(O32, N32, N64)
1396 return std::vector<std::string>({
"/../../../../sysroot" +
1398 "/../usr/include"});
1400 .setFilePathsCallback([](
const Multilib &M) {
1401 return std::vector<std::string>(
1402 {
"/../../../../mips-mti-linux-gnu/lib" + M.
gccSuffix()});
1405 for (
auto *Candidate : {&MtiMipsMultilibsV1, &MtiMipsMultilibsV2}) {
1406 if (Candidate->select(Flags,
Result.SelectedMultilibs)) {
1407 Result.Multilibs = *Candidate;
1415 FilterNonExistent &NonExistent,
1422 .
flag(
"-m32",
true);
1429 .
flag(
"-mabi=n32",
true)
1430 .
flag(
"-m32",
true);
1436 .
Maybe(LittleEndian)
1440 return std::vector<std::string>(
1441 {
"/include",
"/../../../../sysroot/usr/include"});
1450 .
flag(
"-msoft-float",
true)
1451 .
flag(
"-mmicromips",
true);
1454 .
flag(
"-msoft-float")
1455 .
flag(
"-mmicromips",
true);
1458 .
flag(
"-msoft-float",
true)
1459 .
flag(
"-mmicromips",
true);
1462 .
flag(
"-msoft-float")
1463 .
flag(
"-mmicromips",
true);
1466 .
flag(
"-msoft-float",
true)
1467 .
flag(
"-mmicromips");
1470 .
flag(
"-msoft-float")
1471 .
flag(
"-mmicromips");
1474 .
flag(
"-msoft-float",
true)
1475 .
flag(
"-mmicromips");
1478 .
flag(
"-msoft-float")
1479 .
flag(
"-mmicromips");
1483 .flag(
"-mabi=n32",
true)
1484 .flag(
"-mabi=n64",
true);
1488 .flag(
"-mabi=n64",
true);
1491 .flag(
"-mabi=n32",
true)
1496 .
Either({BeHard, BeSoft, ElHard, ElSoft, BeMicroHard, BeMicroSoft,
1497 ElMicroHard, ElMicroSoft})
1498 .Either(O32, N32, N64)
1502 return std::vector<std::string>({
"/../../../../sysroot" +
1504 "/../usr/include"});
1506 .setFilePathsCallback([](
const Multilib &M) {
1507 return std::vector<std::string>(
1508 {
"/../../../../mips-img-linux-gnu/lib" + M.
gccSuffix()});
1511 for (
auto *Candidate : {&ImgMultilibsV1, &ImgMultilibsV2}) {
1512 if (Candidate->select(Flags,
Result.SelectedMultilibs)) {
1513 Result.Multilibs = *Candidate;
1521 const llvm::Triple &TargetTriple,
1522 StringRef
Path,
const ArgList &Args,
1524 FilterNonExistent NonExistent(
Path,
"/crtbegin.o",
D.getVFS());
1530 llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
1538 CPUName ==
"mips32r5" || CPUName ==
"p5600",
1539 "-march=mips32r2", Flags);
1543 CPUName ==
"mips64r5" || CPUName ==
"octeon" ||
1544 CPUName ==
"octeon+",
1545 "-march=mips64r2", Flags);
1558 if (TargetTriple.isAndroid())
1562 if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies &&
1563 TargetTriple.getOS() == llvm::Triple::Linux &&
1564 TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment)
1567 if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies &&
1568 TargetTriple.getOS() == llvm::Triple::Linux &&
1569 TargetTriple.isGNUEnvironment())
1572 if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies &&
1573 TargetTriple.getOS() == llvm::Triple::Linux &&
1574 TargetTriple.isGNUEnvironment())
1583 Result.Multilibs.FilterOut(NonExistent);
1585 if (
Result.Multilibs.select(Flags,
Result.SelectedMultilibs)) {
1594 const llvm::Triple &TargetTriple,
1595 StringRef
Path,
const ArgList &Args,
1598 FilterNonExistent NonExistent(
Path,
"/crtbegin.o",
D.getVFS());
1600 .
flag(
"-march=armv7-a")
1601 .
flag(
"-mthumb",
true);
1603 .
flag(
"-march=armv7-a",
true)
1609 .
flag(
"-march=armv7-a",
true)
1610 .
flag(
"-mthumb",
true);
1613 .
Either(ThumbMultilib, ArmV7Multilib, ArmV7ThumbMultilib,
1619 llvm::StringRef Arch = Args.getLastArgValue(options::OPT_march_EQ);
1620 bool IsArmArch = TargetTriple.getArch() == llvm::Triple::arm;
1621 bool IsThumbArch = TargetTriple.getArch() == llvm::Triple::thumb;
1622 bool IsV7SubArch = TargetTriple.getSubArch() == llvm::Triple::ARMSubArch_v7;
1623 bool IsThumbMode = IsThumbArch ||
1624 Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb,
false) ||
1625 (IsArmArch && llvm::ARM::parseArchISA(Arch) == llvm::ARM::ISAKind::THUMB);
1626 bool IsArmV7Mode = (IsArmArch || IsThumbArch) &&
1627 (llvm::ARM::parseArchVersion(Arch) == 7 ||
1628 (IsArmArch && Arch ==
"" && IsV7SubArch));
1629 addMultilibFlag(IsArmV7Mode,
"-march=armv7-a", Flags);
1630 addMultilibFlag(IsThumbMode,
"-mthumb", Flags);
1632 if (AndroidArmMultilibs.
select(Flags,
Result.SelectedMultilibs))
1633 Result.Multilibs = AndroidArmMultilibs;
1637 const llvm::Triple &TargetTriple,
1638 StringRef
Path,
const ArgList &Args,
1640 FilterNonExistent NonExistent(
Path,
"/crtbegin.o",
D.getVFS());
1652 Result.Multilibs.FilterOut(NonExistent);
1655 addMultilibFlag(Args.hasFlag(options::OPT_fexceptions,
1656 options::OPT_fno_exceptions,
false),
1657 "-exceptions", Flags);
1658 if (
Result.Multilibs.select(Flags,
Result.SelectedMultilibs))
1665 StringRef
Path,
const ArgList &Args,
1667 FilterNonExistent NonExistent(
Path,
"/crtbegin.o",
D.getVFS());
1670 std::optional<llvm::StringRef> Res =
1675 auto ARCHName = *Res;
1683 addMultilibFlag(ARCHName ==
"ck801",
"-march=ck801", Flags);
1684 addMultilibFlag(ARCHName ==
"ck802",
"-march=ck802", Flags);
1685 addMultilibFlag(ARCHName ==
"ck803",
"-march=ck803", Flags);
1686 addMultilibFlag(ARCHName ==
"ck804",
"-march=ck804", Flags);
1687 addMultilibFlag(ARCHName ==
"ck805",
"-march=ck805", Flags);
1688 addMultilibFlag(ARCHName ==
"ck807",
"-march=ck807", Flags);
1689 addMultilibFlag(ARCHName ==
"ck810",
"-march=ck810", Flags);
1690 addMultilibFlag(ARCHName ==
"ck810v",
"-march=ck810v", Flags);
1691 addMultilibFlag(ARCHName ==
"ck860",
"-march=ck860", Flags);
1692 addMultilibFlag(ARCHName ==
"ck860v",
"-march=ck860v", Flags);
1694 bool isBigEndian =
false;
1695 if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
1696 options::OPT_mbig_endian))
1697 isBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
1698 addMultilibFlag(isBigEndian,
"-EB", Flags);
1719 .
Either({Arch801, Arch802, Arch803, Arch804, Arch805, Arch807,
1720 Arch810, Arch810v, Arch860, Arch860v})
1721 .Either(HardFloat, SoftFpFloat, SoftFloat)
1725 if (CSKYMultilibs.
select(Flags,
Result.SelectedMultilibs))
1726 Result.Multilibs = CSKYMultilibs;
1744 if (RISCVMultilibSet.
select(Flags, SelectedMultilibs))
1748 std::vector<MultilibBuilder> NewMultilibs;
1751 llvm::RISCVISAInfo::parseArchString(
1755 if (llvm::errorToBool(ParseResult.takeError()))
1758 auto &ISAInfo = *ParseResult;
1760 addMultilibFlag(ISAInfo->getXLen() == 32,
"-m32", NewFlags);
1761 addMultilibFlag(ISAInfo->getXLen() == 64,
"-m64", NewFlags);
1764 for (StringRef Flag : Flags) {
1765 if (Flag.starts_with(
"!march=") || Flag.starts_with(
"-march="))
1768 NewFlags.push_back(Flag.str());
1771 llvm::StringSet<> AllArchExts;
1774 for (
const auto &M : RISCVMultilibSet) {
1779 for (StringRef Flag : M.flags()) {
1781 if (!Flag.consume_front(
"-march=")) {
1782 NewMultilib.
flag(Flag);
1788 llvm::RISCVISAInfo::parseArchString(
1792 if (llvm::errorToBool(MLConfigParseResult.takeError())) {
1798 auto &MLConfigISAInfo = *MLConfigParseResult;
1800 for (
auto &MLConfigArchExt : MLConfigISAInfo->getExtensions()) {
1801 auto ExtName = MLConfigArchExt.first;
1802 NewMultilib.
flag(Twine(
"-", ExtName).str());
1804 if (AllArchExts.insert(ExtName).second) {
1805 addMultilibFlag(ISAInfo->hasExtension(ExtName),
1806 Twine(
"-", ExtName).str(), NewFlags);
1811 if (MLConfigISAInfo->getXLen() == 32) {
1812 NewMultilib.
flag(
"-m32");
1813 NewMultilib.
flag(
"-m64",
true);
1815 NewMultilib.
flag(
"-m32",
true);
1816 NewMultilib.
flag(
"-m64");
1821 if (!MLConfigISAInfo->hasExtension(
"a"))
1822 NewMultilib.
flag(
"-a",
true);
1828 NewMultilibs.emplace_back(NewMultilib);
1836 if (NewRISCVMultilibs.
select(NewFlags, SelectedMultilibs))
1837 for (
const Multilib &NewSelectedM : SelectedMultilibs)
1838 for (
const auto &M : RISCVMultilibSet)
1840 if (M.gccSuffix() == NewSelectedM.gccSuffix())
1847 const llvm::Triple &TargetTriple,
1848 StringRef
Path,
const ArgList &Args,
1850 FilterNonExistent NonExistent(
Path,
"/crtbegin.o",
D.getVFS());
1851 struct RiscvMultilib {
1857 constexpr RiscvMultilib RISCVMultilibSet[] = {
1858 {
"rv32i",
"ilp32"}, {
"rv32im",
"ilp32"}, {
"rv32iac",
"ilp32"},
1859 {
"rv32imac",
"ilp32"}, {
"rv32imafc",
"ilp32f"}, {
"rv64imac",
"lp64"},
1860 {
"rv64imafdc",
"lp64d"}};
1862 std::vector<MultilibBuilder> Ms;
1863 for (
auto Element : RISCVMultilibSet) {
1867 (Twine(Element.march) +
"/" + Twine(Element.mabi)).str())
1868 .
flag(Twine(
"-march=", Element.march).str())
1869 .
flag(Twine(
"-mabi=", Element.mabi).str()));
1877 return std::vector<std::string>(
1879 "/../../../../riscv64-unknown-elf/lib" + M.
gccSuffix(),
1880 "/../../../../riscv32-unknown-elf/lib" + M.
gccSuffix()});
1884 llvm::StringSet<> Added_ABIs;
1887 for (
auto Element : RISCVMultilibSet) {
1888 addMultilibFlag(MArch == Element.march,
1889 Twine(
"-march=", Element.march).str().c_str(), Flags);
1890 if (!Added_ABIs.count(Element.mabi)) {
1891 Added_ABIs.insert(Element.mabi);
1892 addMultilibFlag(ABIName == Element.mabi,
1893 Twine(
"-mabi=", Element.mabi).str().c_str(), Flags);
1898 Result.SelectedMultilibs))
1899 Result.Multilibs = RISCVMultilibs;
1903 const llvm::Triple &TargetTriple, StringRef
Path,
1905 if (TargetTriple.getOS() == llvm::Triple::UnknownOS)
1908 FilterNonExistent NonExistent(
Path,
"/crtbegin.o",
D.getVFS());
1923 .
Either({Ilp32, Ilp32f, Ilp32d, Lp64, Lp64f, Lp64d})
1928 bool IsRV64 = TargetTriple.getArch() == llvm::Triple::riscv64;
1931 addMultilibFlag(!IsRV64,
"-m32", Flags);
1932 addMultilibFlag(IsRV64,
"-m64", Flags);
1933 addMultilibFlag(ABIName ==
"ilp32",
"-mabi=ilp32", Flags);
1934 addMultilibFlag(ABIName ==
"ilp32f",
"-mabi=ilp32f", Flags);
1935 addMultilibFlag(ABIName ==
"ilp32d",
"-mabi=ilp32d", Flags);
1936 addMultilibFlag(ABIName ==
"lp64",
"-mabi=lp64", Flags);
1937 addMultilibFlag(ABIName ==
"lp64f",
"-mabi=lp64f", Flags);
1938 addMultilibFlag(ABIName ==
"lp64d",
"-mabi=lp64d", Flags);
1940 if (RISCVMultilibs.
select(Flags,
Result.SelectedMultilibs))
1941 Result.Multilibs = RISCVMultilibs;
1945 const llvm::Triple &TargetTriple,
1946 StringRef
Path,
const ArgList &Args,
1947 bool NeedsBiarchSuffix,
1958 StringRef Suff64 =
"/64";
1960 if (TargetTriple.isOSSolaris()) {
1961 switch (TargetTriple.getArch()) {
1962 case llvm::Triple::x86:
1963 case llvm::Triple::x86_64:
1966 case llvm::Triple::sparc:
1967 case llvm::Triple::sparcv9:
1968 Suff64 =
"/sparcv9";
1977 .includeSuffix(Suff64)
1980 .flag(
"-mx32",
true)
1984 .includeSuffix(
"/32")
1987 .flag(
"-mx32",
true)
1991 .includeSuffix(
"/x32")
1998 .includeSuffix(
"/sparcv8plus")
2004 FilterNonExistent NonExistent(
2005 Path, TargetTriple.isOSIAMCU() ?
"/libgcc.a" :
"/crtbegin.o",
D.getVFS());
2010 const bool IsX32 = TargetTriple.isX32();
2011 if (TargetTriple.isArch32Bit() && !NonExistent(Alt32))
2013 if (TargetTriple.isArch32Bit() && !NonExistent(Alt32sparc))
2015 else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32))
2017 else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64))
2019 else if (TargetTriple.isArch64Bit() && !NonExistent(Alt32sparc))
2022 if (TargetTriple.isArch32Bit())
2023 Want = NeedsBiarchSuffix ? WANT64 : WANT32;
2025 Want = NeedsBiarchSuffix ? WANT64 : WANTX32;
2027 Want = NeedsBiarchSuffix ? WANT32 : WANT64;
2031 DefaultBuilder.
flag(
"-m32")
2033 .
flag(
"-mx32",
true);
2034 else if (Want == WANT64)
2035 DefaultBuilder.
flag(
"-m32",
true)
2037 .
flag(
"-mx32",
true);
2038 else if (Want == WANTX32)
2039 DefaultBuilder.
flag(
"-m32",
true)
2048 Result.Multilibs.push_back(Alt64);
2049 Result.Multilibs.push_back(Alt32);
2050 Result.Multilibs.push_back(Altx32);
2051 Result.Multilibs.push_back(Alt32sparc);
2053 Result.Multilibs.FilterOut(NonExistent);
2056 addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32,
"-m64", Flags);
2057 addMultilibFlag(TargetTriple.isArch32Bit(),
"-m32", Flags);
2058 addMultilibFlag(TargetTriple.isArch64Bit() && IsX32,
"-mx32", Flags);
2060 if (!
Result.Multilibs.select(Flags,
Result.SelectedMultilibs))
2063 if (
Result.SelectedMultilibs.back() == Alt64 ||
2064 Result.SelectedMultilibs.back() == Alt32 ||
2065 Result.SelectedMultilibs.back() == Altx32 ||
2066 Result.SelectedMultilibs.back() == Alt32sparc)
2079 StringRef RHSPatchSuffix)
const {
2080 if (Major != RHSMajor)
2081 return Major < RHSMajor;
2082 if (Minor != RHSMinor) {
2089 return Minor < RHSMinor;
2091 if (Patch != RHSPatch) {
2100 return Patch < RHSPatch;
2102 if (PatchSuffix != RHSPatchSuffix) {
2104 if (RHSPatchSuffix.empty())
2106 if (PatchSuffix.empty())
2110 return PatchSuffix < RHSPatchSuffix;
2122 const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1,
"",
"",
""};
2123 std::pair<StringRef, StringRef>
First = VersionText.split(
'.');
2124 std::pair<StringRef, StringRef> Second =
First.second.split(
'.');
2126 StringRef MajorStr =
First.first;
2127 StringRef MinorStr = Second.first;
2128 StringRef PatchStr = Second.second;
2130 GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1,
"",
"",
""};
2146 auto TryParseLastNumber = [&](StringRef Segment,
int &Number,
2147 std::string &OutStr) ->
bool {
2151 if (
size_t EndNumber = Segment.find_first_not_of(
"0123456789")) {
2152 StringRef NumberStr = Segment.slice(0, EndNumber);
2153 if (NumberStr.getAsInteger(10, Number) || Number < 0)
2156 GoodVersion.
PatchSuffix = Segment.substr(EndNumber);
2161 auto TryParseNumber = [](StringRef Segment,
int &Number) ->
bool {
2162 if (Segment.getAsInteger(10, Number) || Number < 0)
2167 if (MinorStr.empty()) {
2169 if (!TryParseLastNumber(MajorStr, GoodVersion.
Major, GoodVersion.
MajorStr))
2174 if (!TryParseNumber(MajorStr, GoodVersion.
Major))
2178 if (PatchStr.empty()) {
2180 if (!TryParseLastNumber(MinorStr, GoodVersion.
Minor, GoodVersion.
MinorStr))
2185 if (!TryParseNumber(MinorStr, GoodVersion.
Minor))
2190 std::string DummyStr;
2191 TryParseLastNumber(PatchStr, GoodVersion.
Patch, DummyStr);
2196 llvm::StringRef SysRoot) {
2197 const Arg *A = Args.getLastArg(clang::driver::options::OPT_gcc_toolchain);
2199 return A->getValue();
2204 if (!SysRoot.empty())
2207 return GCC_INSTALL_PREFIX;
2220 const llvm::Triple &TargetTriple,
const ArgList &Args) {
2221 llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit()
2222 ? TargetTriple.get64BitArchVariant()
2223 : TargetTriple.get32BitArchVariant();
2230 CandidateTripleAliases.push_back(TargetTriple.str());
2231 std::string TripleNoVendor, BiarchTripleNoVendor;
2232 if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor) {
2233 StringRef OSEnv = TargetTriple.getOSAndEnvironmentName();
2234 if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32)
2235 OSEnv =
"linux-gnu";
2236 TripleNoVendor = (TargetTriple.getArchName().str() +
'-' + OSEnv).str();
2237 CandidateTripleAliases.push_back(TripleNoVendor);
2238 if (BiarchVariantTriple.getArch() != llvm::Triple::UnknownArch) {
2239 BiarchTripleNoVendor =
2240 (BiarchVariantTriple.getArchName().str() +
'-' + OSEnv).str();
2241 CandidateBiarchTripleAliases.push_back(BiarchTripleNoVendor);
2245 CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
2246 CandidateTripleAliases, CandidateBiarchLibDirs,
2247 CandidateBiarchTripleAliases);
2251 Args.getLastArg(clang::driver::options::OPT_gcc_install_dir_EQ);
2252 A && A->getValue()[0]) {
2253 StringRef InstallDir = A->getValue();
2254 if (!ScanGCCForMultilibs(TargetTriple, Args, InstallDir,
false)) {
2255 D.Diag(diag::err_drv_invalid_gcc_install_dir) << InstallDir;
2257 (void)InstallDir.consume_back(
"/");
2258 StringRef VersionText = llvm::sys::path::filename(InstallDir);
2259 StringRef TripleText =
2260 llvm::sys::path::filename(llvm::sys::path::parent_path(InstallDir));
2262 Version = GCCVersion::Parse(VersionText);
2263 GCCTriple.setTriple(TripleText);
2264 GCCInstallPath = std::string(InstallDir);
2265 GCCParentLibPath = GCCInstallPath +
"/../../..";
2274 Args.getLastArg(clang::driver::options::OPT_gcc_triple_EQ)) {
2275 StringRef GCCTriple = A->getValue();
2276 CandidateTripleAliases.clear();
2277 CandidateTripleAliases.push_back(GCCTriple);
2283 if (GCCToolchainDir !=
"") {
2284 if (GCCToolchainDir.back() ==
'/')
2285 GCCToolchainDir = GCCToolchainDir.drop_back();
2287 Prefixes.push_back(std::string(GCCToolchainDir));
2290 if (!
D.SysRoot.empty()) {
2291 Prefixes.push_back(
D.SysRoot);
2292 AddDefaultGCCPrefixes(TargetTriple, Prefixes,
D.SysRoot);
2296 Prefixes.push_back(
D.Dir +
"/..");
2300 if (
D.SysRoot.empty()) {
2302 AddDefaultGCCPrefixes(TargetTriple, Prefixes,
D.SysRoot);
2314 GentooTestTriples.push_back(TargetTriple.str());
2315 GentooTestTriples.append(CandidateTripleAliases.begin(),
2316 CandidateTripleAliases.end());
2317 if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
2318 CandidateBiarchTripleAliases))
2324 const GCCVersion VersionZero = GCCVersion::Parse(
"0.0.0");
2325 Version = VersionZero;
2326 for (
const std::string &Prefix : Prefixes) {
2327 auto &VFS =
D.getVFS();
2328 if (!VFS.exists(Prefix))
2330 for (StringRef Suffix : CandidateLibDirs) {
2331 const std::string LibDir = concat(Prefix, Suffix);
2332 if (!VFS.exists(LibDir))
2335 bool GCCDirExists = VFS.exists(LibDir +
"/gcc");
2336 bool GCCCrossDirExists = VFS.exists(LibDir +
"/gcc-cross");
2337 for (StringRef Candidate : CandidateTripleAliases)
2338 ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate,
false,
2339 GCCDirExists, GCCCrossDirExists);
2341 for (StringRef Suffix : CandidateBiarchLibDirs) {
2342 const std::string LibDir = Prefix + Suffix.str();
2343 if (!VFS.exists(LibDir))
2345 bool GCCDirExists = VFS.exists(LibDir +
"/gcc");
2346 bool GCCCrossDirExists = VFS.exists(LibDir +
"/gcc-cross");
2347 for (StringRef Candidate : CandidateBiarchTripleAliases)
2348 ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate,
true,
2349 GCCDirExists, GCCCrossDirExists);
2353 if (Version > VersionZero)
2359 for (
const auto &InstallPath : CandidateGCCInstallPaths)
2360 OS <<
"Found candidate GCC installation: " << InstallPath <<
"\n";
2362 if (!GCCInstallPath.empty())
2363 OS <<
"Selected GCC installation: " << GCCInstallPath <<
"\n";
2365 for (
const auto &
Multilib : Multilibs)
2366 OS <<
"Candidate multilib: " <<
Multilib <<
"\n";
2368 if (Multilibs.size() != 0 || !SelectedMultilib.
isDefault())
2369 OS <<
"Selected multilib: " << SelectedMultilib <<
"\n";
2373 if (BiarchSibling) {
2380void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
2382 StringRef SysRoot) {
2384 if (TargetTriple.isOSHaiku()) {
2385 Prefixes.push_back(concat(SysRoot,
"/boot/system/develop/tools"));
2389 if (TargetTriple.isOSSolaris()) {
2397 std::string PrefixDir = concat(SysRoot,
"/usr/gcc");
2399 for (llvm::vfs::directory_iterator LI =
D.getVFS().dir_begin(PrefixDir, EC),
2401 !EC && LI != LE; LI = LI.increment(EC)) {
2402 StringRef VersionText = llvm::sys::path::filename(LI->path());
2403 GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
2406 if (CandidateVersion.Major == -1 || CandidateVersion.isOlderThan(4, 1, 1))
2409 std::string CandidatePrefix = PrefixDir +
"/" + VersionText.str();
2410 std::string CandidateLibPath = CandidatePrefix +
"/lib/gcc";
2411 if (!
D.getVFS().exists(CandidateLibPath))
2414 SolarisPrefixes.emplace_back(
2415 std::make_pair(CandidateVersion, CandidatePrefix));
2418 std::sort(SolarisPrefixes.rbegin(), SolarisPrefixes.rend());
2419 for (
auto p : SolarisPrefixes)
2420 Prefixes.emplace_back(p.second);
2426 if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux &&
2427 D.getVFS().exists(
"/opt/rh")) {
2430 Prefixes.push_back(
"/opt/rh/gcc-toolset-12/root/usr");
2431 Prefixes.push_back(
"/opt/rh/gcc-toolset-11/root/usr");
2432 Prefixes.push_back(
"/opt/rh/gcc-toolset-10/root/usr");
2433 Prefixes.push_back(
"/opt/rh/devtoolset-12/root/usr");
2434 Prefixes.push_back(
"/opt/rh/devtoolset-11/root/usr");
2435 Prefixes.push_back(
"/opt/rh/devtoolset-10/root/usr");
2436 Prefixes.push_back(
"/opt/rh/devtoolset-9/root/usr");
2437 Prefixes.push_back(
"/opt/rh/devtoolset-8/root/usr");
2438 Prefixes.push_back(
"/opt/rh/devtoolset-7/root/usr");
2439 Prefixes.push_back(
"/opt/rh/devtoolset-6/root/usr");
2440 Prefixes.push_back(
"/opt/rh/devtoolset-4/root/usr");
2441 Prefixes.push_back(
"/opt/rh/devtoolset-3/root/usr");
2442 Prefixes.push_back(
"/opt/rh/devtoolset-2/root/usr");
2446 Prefixes.push_back(concat(SysRoot,
"/usr"));
2449 void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples(
2450 const llvm::Triple &TargetTriple,
const llvm::Triple &BiarchTriple,
2464 static const char *
const AArch64LibDirs[] = {
"/lib64",
"/lib"};
2465 static const char *
const AArch64Triples[] = {
2466 "aarch64-none-linux-gnu",
"aarch64-redhat-linux",
"aarch64-suse-linux"};
2467 static const char *
const AArch64beLibDirs[] = {
"/lib"};
2468 static const char *
const AArch64beTriples[] = {
"aarch64_be-none-linux-gnu"};
2470 static const char *
const ARMLibDirs[] = {
"/lib"};
2471 static const char *
const ARMTriples[] = {
"arm-linux-gnueabi"};
2472 static const char *
const ARMHFTriples[] = {
"arm-linux-gnueabihf",
2473 "armv7hl-redhat-linux-gnueabi",
2474 "armv6hl-suse-linux-gnueabi",
2475 "armv7hl-suse-linux-gnueabi"};
2476 static const char *
const ARMebLibDirs[] = {
"/lib"};
2477 static const char *
const ARMebTriples[] = {
"armeb-linux-gnueabi"};
2478 static const char *
const ARMebHFTriples[] = {
2479 "armeb-linux-gnueabihf",
"armebv7hl-redhat-linux-gnueabi"};
2481 static const char *
const AVRLibDirs[] = {
"/lib"};
2482 static const char *
const AVRTriples[] = {
"avr"};
2484 static const char *
const CSKYLibDirs[] = {
"/lib"};
2485 static const char *
const CSKYTriples[] = {
2486 "csky-linux-gnuabiv2",
"csky-linux-uclibcabiv2",
"csky-elf-noneabiv2"};
2488 static const char *
const X86_64LibDirs[] = {
"/lib64",
"/lib"};
2489 static const char *
const X86_64Triples[] = {
2490 "x86_64-linux-gnu",
"x86_64-unknown-linux-gnu",
2491 "x86_64-pc-linux-gnu",
"x86_64-redhat-linux6E",
2492 "x86_64-redhat-linux",
"x86_64-suse-linux",
2493 "x86_64-manbo-linux-gnu",
"x86_64-slackware-linux",
2494 "x86_64-unknown-linux",
"x86_64-amazon-linux"};
2495 static const char *
const X32Triples[] = {
"x86_64-linux-gnux32",
2496 "x86_64-pc-linux-gnux32"};
2497 static const char *
const X32LibDirs[] = {
"/libx32",
"/lib"};
2498 static const char *
const X86LibDirs[] = {
"/lib32",
"/lib"};
2499 static const char *
const X86Triples[] = {
2500 "i586-linux-gnu",
"i686-linux-gnu",
"i686-pc-linux-gnu",
2501 "i386-redhat-linux6E",
"i686-redhat-linux",
"i386-redhat-linux",
2502 "i586-suse-linux",
"i686-montavista-linux",
2505 static const char *
const LoongArch64LibDirs[] = {
"/lib64",
"/lib"};
2506 static const char *
const LoongArch64Triples[] = {
2507 "loongarch64-linux-gnu",
"loongarch64-unknown-linux-gnu"};
2509 static const char *
const M68kLibDirs[] = {
"/lib"};
2510 static const char *
const M68kTriples[] = {
"m68k-unknown-linux-gnu",
2513 static const char *
const MIPSLibDirs[] = {
"/libo32",
"/lib"};
2514 static const char *
const MIPSTriples[] = {
2515 "mips-linux-gnu",
"mips-mti-linux",
"mips-mti-linux-gnu",
2516 "mips-img-linux-gnu",
"mipsisa32r6-linux-gnu"};
2517 static const char *
const MIPSELLibDirs[] = {
"/libo32",
"/lib"};
2518 static const char *
const MIPSELTriples[] = {
"mipsel-linux-gnu",
2519 "mips-img-linux-gnu"};
2521 static const char *
const MIPS64LibDirs[] = {
"/lib64",
"/lib"};
2522 static const char *
const MIPS64Triples[] = {
2523 "mips-mti-linux-gnu",
"mips-img-linux-gnu",
"mips64-linux-gnuabi64",
2524 "mipsisa64r6-linux-gnu",
"mipsisa64r6-linux-gnuabi64"};
2525 static const char *
const MIPS64ELLibDirs[] = {
"/lib64",
"/lib"};
2526 static const char *
const MIPS64ELTriples[] = {
2527 "mips-mti-linux-gnu",
"mips-img-linux-gnu",
"mips64el-linux-gnuabi64",
2528 "mipsisa64r6el-linux-gnu",
"mipsisa64r6el-linux-gnuabi64"};
2530 static const char *
const MIPSN32LibDirs[] = {
"/lib32"};
2531 static const char *
const MIPSN32Triples[] = {
"mips64-linux-gnuabin32",
2532 "mipsisa64r6-linux-gnuabin32"};
2533 static const char *
const MIPSN32ELLibDirs[] = {
"/lib32"};
2534 static const char *
const MIPSN32ELTriples[] = {
2535 "mips64el-linux-gnuabin32",
"mipsisa64r6el-linux-gnuabin32"};
2537 static const char *
const MSP430LibDirs[] = {
"/lib"};
2538 static const char *
const MSP430Triples[] = {
"msp430-elf"};
2540 static const char *
const PPCLibDirs[] = {
"/lib32",
"/lib"};
2541 static const char *
const PPCTriples[] = {
2542 "powerpc-unknown-linux-gnu",
2545 "powerpc64-suse-linux",
"powerpc-montavista-linuxspe"};
2546 static const char *
const PPCLELibDirs[] = {
"/lib32",
"/lib"};
2547 static const char *
const PPCLETriples[] = {
"powerpcle-unknown-linux-gnu",
2548 "powerpcle-linux-musl"};
2550 static const char *
const PPC64LibDirs[] = {
"/lib64",
"/lib"};
2551 static const char *
const PPC64Triples[] = {
"powerpc64-unknown-linux-gnu",
2552 "powerpc64-suse-linux",
2553 "ppc64-redhat-linux"};
2554 static const char *
const PPC64LELibDirs[] = {
"/lib64",
"/lib"};
2555 static const char *
const PPC64LETriples[] = {
2556 "powerpc64le-unknown-linux-gnu",
"powerpc64le-none-linux-gnu",
2557 "powerpc64le-suse-linux",
"ppc64le-redhat-linux"};
2559 static const char *
const RISCV32LibDirs[] = {
"/lib32",
"/lib"};
2560 static const char *
const RISCV32Triples[] = {
"riscv32-unknown-linux-gnu",
2561 "riscv32-unknown-elf"};
2562 static const char *
const RISCV64LibDirs[] = {
"/lib64",
"/lib"};
2563 static const char *
const RISCV64Triples[] = {
"riscv64-unknown-linux-gnu",
2564 "riscv64-unknown-elf"};
2566 static const char *
const SPARCv8LibDirs[] = {
"/lib32",
"/lib"};
2567 static const char *
const SPARCv8Triples[] = {
"sparc-linux-gnu",
2568 "sparcv8-linux-gnu"};
2569 static const char *
const SPARCv9LibDirs[] = {
"/lib64",
"/lib"};
2570 static const char *
const SPARCv9Triples[] = {
"sparc64-linux-gnu",
2571 "sparcv9-linux-gnu"};
2573 static const char *
const SystemZLibDirs[] = {
"/lib64",
"/lib"};
2574 static const char *
const SystemZTriples[] = {
2575 "s390x-unknown-linux-gnu",
"s390x-ibm-linux-gnu",
"s390x-suse-linux",
2576 "s390x-redhat-linux"};
2581 if (TargetTriple.isOSSolaris()) {
2582 static const char *
const SolarisLibDirs[] = {
"/lib"};
2583 static const char *
const SolarisSparcV8Triples[] = {
2584 "sparc-sun-solaris2.11"};
2585 static const char *
const SolarisSparcV9Triples[] = {
2586 "sparcv9-sun-solaris2.11"};
2587 static const char *
const SolarisX86Triples[] = {
"i386-pc-solaris2.11"};
2588 static const char *
const SolarisX86_64Triples[] = {
"x86_64-pc-solaris2.11"};
2589 LibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
2590 BiarchLibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
2591 switch (TargetTriple.getArch()) {
2592 case llvm::Triple::x86:
2593 TripleAliases.append(begin(SolarisX86Triples), end(SolarisX86Triples));
2594 BiarchTripleAliases.append(begin(SolarisX86_64Triples),
2595 end(SolarisX86_64Triples));
2597 case llvm::Triple::x86_64:
2598 TripleAliases.append(begin(SolarisX86_64Triples),
2599 end(SolarisX86_64Triples));
2600 BiarchTripleAliases.append(begin(SolarisX86Triples),
2601 end(SolarisX86Triples));
2603 case llvm::Triple::sparc:
2604 TripleAliases.append(begin(SolarisSparcV8Triples),
2605 end(SolarisSparcV8Triples));
2606 BiarchTripleAliases.append(begin(SolarisSparcV9Triples),
2607 end(SolarisSparcV9Triples));
2609 case llvm::Triple::sparcv9:
2610 TripleAliases.append(begin(SolarisSparcV9Triples),
2611 end(SolarisSparcV9Triples));
2612 BiarchTripleAliases.append(begin(SolarisSparcV8Triples),
2613 end(SolarisSparcV8Triples));
2622 if (TargetTriple.isAndroid()) {
2623 static const char *
const AArch64AndroidTriples[] = {
2624 "aarch64-linux-android"};
2625 static const char *
const ARMAndroidTriples[] = {
"arm-linux-androideabi"};
2626 static const char *
const X86AndroidTriples[] = {
"i686-linux-android"};
2627 static const char *
const X86_64AndroidTriples[] = {
"x86_64-linux-android"};
2629 switch (TargetTriple.getArch()) {
2630 case llvm::Triple::aarch64:
2631 LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2632 TripleAliases.append(begin(AArch64AndroidTriples),
2633 end(AArch64AndroidTriples));
2635 case llvm::Triple::arm:
2636 case llvm::Triple::thumb:
2637 LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
2638 TripleAliases.append(begin(ARMAndroidTriples), end(ARMAndroidTriples));
2640 case llvm::Triple::x86_64:
2641 LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2642 TripleAliases.append(begin(X86_64AndroidTriples),
2643 end(X86_64AndroidTriples));
2644 BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2645 BiarchTripleAliases.append(begin(X86AndroidTriples),
2646 end(X86AndroidTriples));
2648 case llvm::Triple::x86:
2649 LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2650 TripleAliases.append(begin(X86AndroidTriples), end(X86AndroidTriples));
2651 BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2652 BiarchTripleAliases.append(begin(X86_64AndroidTriples),
2653 end(X86_64AndroidTriples));
2662 if (TargetTriple.isOSHurd()) {
2663 switch (TargetTriple.getArch()) {
2664 case llvm::Triple::x86_64:
2665 LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2666 TripleAliases.push_back(
"x86_64-gnu");
2668 case llvm::Triple::x86:
2669 LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2670 TripleAliases.push_back(
"i686-gnu");
2679 switch (TargetTriple.getArch()) {
2680 case llvm::Triple::aarch64:
2681 LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2682 TripleAliases.append(begin(AArch64Triples), end(AArch64Triples));
2683 BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2684 BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples));
2686 case llvm::Triple::aarch64_be:
2687 LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs));
2688 TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples));
2689 BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs));
2690 BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples));
2692 case llvm::Triple::arm:
2693 case llvm::Triple::thumb:
2694 LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
2695 if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF ||
2696 TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF ||
2697 TargetTriple.getEnvironment() == llvm::Triple::EABIHF) {
2698 TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples));
2700 TripleAliases.append(begin(ARMTriples), end(ARMTriples));
2703 case llvm::Triple::armeb:
2704 case llvm::Triple::thumbeb:
2705 LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs));
2706 if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF ||
2707 TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF ||
2708 TargetTriple.getEnvironment() == llvm::Triple::EABIHF) {
2709 TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples));
2711 TripleAliases.append(begin(ARMebTriples), end(ARMebTriples));
2714 case llvm::Triple::avr:
2715 LibDirs.append(begin(AVRLibDirs), end(AVRLibDirs));
2716 TripleAliases.append(begin(AVRTriples), end(AVRTriples));
2718 case llvm::Triple::csky:
2719 LibDirs.append(begin(CSKYLibDirs), end(CSKYLibDirs));
2720 TripleAliases.append(begin(CSKYTriples), end(CSKYTriples));
2722 case llvm::Triple::x86_64:
2723 if (TargetTriple.isX32()) {
2724 LibDirs.append(begin(X32LibDirs), end(X32LibDirs));
2725 TripleAliases.append(begin(X32Triples), end(X32Triples));
2726 BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2727 BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2729 LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2730 TripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2731 BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs));
2732 BiarchTripleAliases.append(begin(X32Triples), end(X32Triples));
2734 BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2735 BiarchTripleAliases.append(begin(X86Triples), end(X86Triples));
2737 case llvm::Triple::x86:
2738 LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2741 if (!TargetTriple.isOSIAMCU()) {
2742 TripleAliases.append(begin(X86Triples), end(X86Triples));
2743 BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2744 BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2745 BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs));
2746 BiarchTripleAliases.append(begin(X32Triples), end(X32Triples));
2750 case llvm::Triple::loongarch64:
2751 LibDirs.append(begin(LoongArch64LibDirs), end(LoongArch64LibDirs));
2752 TripleAliases.append(begin(LoongArch64Triples), end(LoongArch64Triples));
2754 case llvm::Triple::m68k:
2755 LibDirs.append(begin(M68kLibDirs), end(M68kLibDirs));
2756 TripleAliases.append(begin(M68kTriples), end(M68kTriples));
2758 case llvm::Triple::mips:
2759 LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
2760 TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2761 BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs));
2762 BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples));
2763 BiarchLibDirs.append(begin(MIPSN32LibDirs), end(MIPSN32LibDirs));
2764 BiarchTripleAliases.append(begin(MIPSN32Triples), end(MIPSN32Triples));
2766 case llvm::Triple::mipsel:
2767 LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2768 TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples));
2769 TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2770 BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2771 BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples));
2772 BiarchLibDirs.append(begin(MIPSN32ELLibDirs), end(MIPSN32ELLibDirs));
2773 BiarchTripleAliases.append(begin(MIPSN32ELTriples), end(MIPSN32ELTriples));
2775 case llvm::Triple::mips64:
2776 LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs));
2777 TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples));
2778 BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
2779 BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2780 BiarchLibDirs.append(begin(MIPSN32LibDirs), end(MIPSN32LibDirs));
2781 BiarchTripleAliases.append(begin(MIPSN32Triples), end(MIPSN32Triples));
2783 case llvm::Triple::mips64el:
2784 LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2785 TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples));
2786 BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2787 BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples));
2788 BiarchLibDirs.append(begin(MIPSN32ELLibDirs), end(MIPSN32ELLibDirs));
2789 BiarchTripleAliases.append(begin(MIPSN32ELTriples), end(MIPSN32ELTriples));
2790 BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2792 case llvm::Triple::msp430:
2793 LibDirs.append(begin(MSP430LibDirs), end(MSP430LibDirs));
2794 TripleAliases.append(begin(MSP430Triples), end(MSP430Triples));
2796 case llvm::Triple::ppc:
2797 LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
2798 TripleAliases.append(begin(PPCTriples), end(PPCTriples));
2799 BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
2800 BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples));
2802 case llvm::Triple::ppcle:
2803 LibDirs.append(begin(PPCLELibDirs), end(PPCLELibDirs));
2804 TripleAliases.append(begin(PPCLETriples), end(PPCLETriples));
2805 BiarchLibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs));
2806 BiarchTripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples));
2808 case llvm::Triple::ppc64:
2809 LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
2810 TripleAliases.append(begin(PPC64Triples), end(PPC64Triples));
2811 BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
2812 BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples));
2814 case llvm::Triple::ppc64le:
2815 LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs));
2816 TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples));
2817 BiarchLibDirs.append(begin(PPCLELibDirs), end(PPCLELibDirs));
2818 BiarchTripleAliases.append(begin(PPCLETriples), end(PPCLETriples));
2820 case llvm::Triple::riscv32:
2821 LibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
2822 TripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
2823 BiarchLibDirs.append(begin(RISCV64LibDirs), end(RISCV64LibDirs));
2824 BiarchTripleAliases.append(begin(RISCV64Triples), end(RISCV64Triples));
2826 case llvm::Triple::riscv64:
2827 LibDirs.append(begin(RISCV64LibDirs), end(RISCV64LibDirs));
2828 TripleAliases.append(begin(RISCV64Triples), end(RISCV64Triples));
2829 BiarchLibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
2830 BiarchTripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
2832 case llvm::Triple::sparc:
2833 case llvm::Triple::sparcel:
2834 LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
2835 TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples));
2836 BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs));
2837 BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples));
2839 case llvm::Triple::sparcv9:
2840 LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs));
2841 TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples));
2842 BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
2843 BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples));
2845 case llvm::Triple::systemz:
2846 LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs));
2847 TripleAliases.append(begin(SystemZTriples), end(SystemZTriples));
2856 if (TargetTriple.str() != BiarchTriple.str())
2857 BiarchTripleAliases.push_back(BiarchTriple.str());
2860bool Generic_GCC::GCCInstallationDetector::ScanGCCForMultilibs(
2861 const llvm::Triple &TargetTriple,
const ArgList &Args,
2862 StringRef
Path,
bool NeedsBiarchSuffix) {
2863 llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
2872 }
else if (TargetTriple.isCSKY()) {
2874 }
else if (TargetTriple.isMIPS()) {
2877 }
else if (TargetTriple.isRISCV()) {
2881 }
else if (TargetArch == llvm::Triple::avr) {
2884 NeedsBiarchSuffix, Detected)) {
2891 : Detected.SelectedMultilibs.back();
2897void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
2898 const llvm::Triple &TargetTriple,
const ArgList &Args,
2899 const std::string &LibDir, StringRef CandidateTriple,
2900 bool NeedsBiarchSuffix,
bool GCCDirExists,
bool GCCCrossDirExists) {
2903 struct GCCLibSuffix {
2905 std::string LibSuffix;
2908 StringRef ReversePath;
2913 {
"gcc/" + CandidateTriple.str(),
"../..", GCCDirExists},
2916 {
"gcc-cross/" + CandidateTriple.str(),
"../..", GCCCrossDirExists},
2922 {CandidateTriple.str(),
"..",
2923 TargetTriple.getVendor() == llvm::Triple::Freescale ||
2924 TargetTriple.getVendor() == llvm::Triple::OpenEmbedded}};
2930 StringRef LibSuffix = Suffix.LibSuffix;
2932 for (llvm::vfs::directory_iterator
2933 LI =
D.getVFS().dir_begin(LibDir +
"/" + LibSuffix, EC),
2935 !EC && LI != LE; LI = LI.increment(EC)) {
2936 StringRef VersionText = llvm::sys::path::filename(LI->path());
2937 GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
2938 if (CandidateVersion.Major != -1)
2939 if (!CandidateGCCInstallPaths.insert(std::string(LI->path())).second)
2941 if (CandidateVersion.isOlderThan(4, 1, 1))
2943 if (CandidateVersion <= Version)
2946 if (!ScanGCCForMultilibs(TargetTriple, Args, LI->path(),
2950 Version = CandidateVersion;
2951 GCCTriple.setTriple(CandidateTriple);
2955 GCCInstallPath = (LibDir +
"/" + LibSuffix +
"/" + VersionText).str();
2956 GCCParentLibPath = (GCCInstallPath +
"/../" + Suffix.ReversePath).str();
2962bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
2963 const llvm::Triple &TargetTriple,
const ArgList &Args,
2966 if (!
D.getVFS().exists(concat(
D.SysRoot, GentooConfigDir)))
2969 for (StringRef CandidateTriple : CandidateTriples) {
2970 if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
2974 for (StringRef CandidateTriple : CandidateBiarchTriples) {
2975 if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple,
true))
2981bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
2982 const llvm::Triple &TargetTriple,
const ArgList &Args,
2983 StringRef CandidateTriple,
bool NeedsBiarchSuffix) {
2984 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
2985 D.getVFS().getBufferForFile(concat(
D.SysRoot, GentooConfigDir,
2986 "/config-" + CandidateTriple.str()));
2989 File.get()->getBuffer().split(Lines,
"\n");
2990 for (StringRef
Line : Lines) {
2993 if (!
Line.consume_front(
"CURRENT="))
2996 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ConfigFile =
2997 D.getVFS().getBufferForFile(
2998 concat(
D.SysRoot, GentooConfigDir,
"/" +
Line));
2999 std::pair<StringRef, StringRef> ActiveVersion =
Line.rsplit(
'-');
3012 ConfigFile.get()->getBuffer().split(ConfigLines,
"\n");
3013 for (StringRef ConfLine : ConfigLines) {
3014 ConfLine = ConfLine.trim();
3015 if (ConfLine.consume_front(
"LDPATH=")) {
3017 ConfLine.consume_back(
"\"");
3018 ConfLine.consume_front(
"\"");
3020 ConfLine.split(GentooScanPaths,
':', -1,
false);
3025 std::string basePath =
"/usr/lib/gcc/" + ActiveVersion.first.str() +
"/"
3026 + ActiveVersion.second.str();
3027 GentooScanPaths.push_back(StringRef(basePath));
3030 for (
const auto &GentooScanPath : GentooScanPaths) {
3031 std::string GentooPath = concat(
D.SysRoot, GentooScanPath);
3032 if (
D.getVFS().exists(GentooPath +
"/crtbegin.o")) {
3033 if (!ScanGCCForMultilibs(TargetTriple, Args, GentooPath,
3037 Version = GCCVersion::Parse(ActiveVersion.second);
3038 GCCInstallPath = GentooPath;
3039 GCCParentLibPath = GentooPath + std::string(
"/../../..");
3040 GCCTriple.setTriple(ActiveVersion.first);
3052 const ArgList &Args)
3054 CudaInstallation(
D, Triple, Args), RocmInstallation(
D, Triple, Args) {
3065 return Preprocess.get();
3069 return Compile.get();
3091 case llvm::Triple::aarch64:
3092 case llvm::Triple::aarch64_be:
3093 case llvm::Triple::ppc:
3094 case llvm::Triple::ppcle:
3095 case llvm::Triple::ppc64:
3096 case llvm::Triple::ppc64le:
3097 case llvm::Triple::riscv32:
3098 case llvm::Triple::riscv64:
3099 case llvm::Triple::x86:
3100 case llvm::Triple::x86_64:
3109 case llvm::Triple::x86_64:
3111 case llvm::Triple::mips64:
3112 case llvm::Triple::mips64el:
3129 case llvm::Triple::nvptx:
3130 case llvm::Triple::nvptx64:
3131 case llvm::Triple::xcore:
3154 const std::string &SysRoot,
3155 const std::string &OSLibDir,
3156 const std::string &MultiarchTriple,
3162 const std::string &LibPath =
3201 LibPath +
"/../" + GCCTriple.str() +
"/lib/../" + OSLibDir +
3214 if (StringRef(LibPath).starts_with(SysRoot))
3215 addPathIfExists(
D, LibPath +
"/../" + OSLibDir, Paths);
3220 const std::string &SysRoot,
3221 const std::string &OSLibDir,
3224 const std::string &LibPath =
3235 ArgStringList &CC1Args)
const {
3243 Twine(LibPath) +
"/../" + GCCTriple.str() +
"/include");
3254 ArgStringList &CC1Args)
const {
3255 if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdincxx,
3256 options::OPT_nostdlibinc))
3272 llvm::opt::ArgStringList &CC1Args)
const {
3275 if (SysRoot.empty())
3276 SysRoot = llvm::sys::path::get_separator();
3278 auto AddIncludePath = [&](StringRef
Path,
bool TargetDirRequired =
false) {
3280 if (Version.empty())
3284 bool TargetDirExists =
false;
3286 if (TargetIncludeDir) {
3288 llvm::sys::path::append(TargetDir,
"c++", Version);
3289 if (
D.getVFS().exists(TargetDir)) {
3291 TargetDirExists =
true;
3294 if (TargetDirRequired && !TargetDirExists)
3299 llvm::sys::path::append(GenericDir,
"c++", Version);
3308 llvm::sys::path::append(DriverIncludeDir,
"..",
"include");
3309 if (AddIncludePath(DriverIncludeDir,
3316 llvm::sys::path::append(UsrLocalIncludeDir,
"usr",
"local",
"include");
3317 if (AddIncludePath(UsrLocalIncludeDir))
3320 llvm::sys::path::append(UsrIncludeDir,
"usr",
"include");
3321 if (AddIncludePath(UsrIncludeDir))
3326 Twine IncludeSuffix,
3327 const llvm::opt::ArgList &DriverArgs,
3328 llvm::opt::ArgStringList &CC1Args,
3329 bool DetectDebian)
const {
3330 if (!
getVFS().exists(IncludeDir))
3336 std::string Dir = IncludeDir.str();
3338 llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
3340 (Include +
"/" + Triple + Dir.substr(Include.size()) + IncludeSuffix)
3351 else if (!Triple.empty())
3353 IncludeDir +
"/" + Triple + IncludeSuffix);
3360 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
3361 StringRef DebianMultiarch)
const {
3375 LibDir.str() +
"/../" + TripleStr +
"/include/c++/" + Version.
Text,
3383 Version.
Text +
"/include/c++/",
3391 DriverArgs, CC1Args,
true))
3402 const std::string LibStdCXXIncludePathCandidates[] = {
3405 InstallDir.str() +
"/include/g++-v" + Version.
Text,
3406 InstallDir.str() +
"/include/g++-v" + Version.
MajorStr +
"." +
3408 InstallDir.str() +
"/include/g++-v" + Version.
MajorStr,
3411 for (
const auto &IncludePath : LibStdCXXIncludePathCandidates) {
3421 llvm::opt::ArgStringList &CC1Args)
const {
3428llvm::opt::DerivedArgList *
3437 DerivedArgList *DAL =
new DerivedArgList(Args.getBaseArgs());
3442 DAL->AddFlagArg(
nullptr, Opts.getOption(options::OPT_shared));
3443 DAL->AddFlagArg(
nullptr, Opts.getOption(options::OPT_fPIC));
3447 for (
auto *A : Args) {
3452 case options::OPT_shared:
3453 case options::OPT_dynamic:
3454 case options::OPT_static:
3455 case options::OPT_fPIC:
3456 case options::OPT_fno_PIC:
3457 case options::OPT_fpic:
3458 case options::OPT_fno_pic:
3459 case options::OPT_fPIE:
3460 case options::OPT_fno_PIE:
3461 case options::OPT_fpie:
3462 case options::OPT_fno_pie:
3471void Generic_ELF::anchor() {}
3474 ArgStringList &CC1Args,
3476 if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
3477 options::OPT_fno_use_init_array,
true))
3478 CC1Args.push_back(
"-fno-use-init-array");
static constexpr CPUSuffix Suffixes[]
static void findCSKYMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
static void findAndroidArmMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
static bool isArmOrThumbArch(llvm::Triple::ArchType Arch)
static void normalizeCPUNamesForAssembler(const ArgList &Args, ArgStringList &CmdArgs)
static bool findBiarchMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, bool NeedsBiarchSuffix, DetectedMultilibs &Result)
static bool isMips16(const ArgList &Args)
static llvm::StringRef getGCCToolchainDir(const ArgList &Args, llvm::StringRef SysRoot)
static bool findMSP430Multilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
static bool getStatic(const ArgList &Args)
static bool selectRISCVMultilib(const MultilibSet &RISCVMultilibSet, StringRef Arch, const Multilib::flags_list &Flags, llvm::SmallVectorImpl< Multilib > &SelectedMultilibs)
Extend the multi-lib re-use selection mechanism for RISC-V.
static bool findMipsCsMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
static bool findMipsMtiMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
static bool isMipsEL(llvm::Triple::ArchType Arch)
static const char * getLDMOption(const llvm::Triple &T, const ArgList &Args)
static bool findMipsMuslMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
static void findRISCVBareMetalMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
static bool findMipsAndroidMultilibs(llvm::vfs::FileSystem &VFS, StringRef Path, const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
static bool isMSP430(llvm::Triple::ArchType Arch)
static bool isSoftFloatABI(const ArgList &Args)
static bool findMipsImgMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
static bool getStaticPIE(const ArgList &Args, const ToolChain &TC)
static bool forwardToGCC(const Option &O)
static bool isMicroMips(const ArgList &Args)
types::ID getType() 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...
const llvm::opt::OptTable & getOpts() const
This corresponds to a single GCC multilib, or a segment of one controlled by a command line flag.
MultilibBuilder & flag(StringRef Flag, bool Disallow=false)
Add a flag to the flags list Flag must be a flag accepted by the driver.
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant.
const std::string & osSuffix() const
Get the detected os path suffix for the multi-arch target variant.
Multilib makeMultilib() const
This class can be used to create a MultilibSet, and contains helper functions to add combinations of ...
MultilibSetBuilder & Maybe(const MultilibBuilder &M)
Add an optional Multilib segment.
MultilibSetBuilder & FilterOut(const char *Regex)
Filter out those Multilibs whose gccSuffix matches the given expression.
MultilibSetBuilder & Either(const MultilibBuilder &M1, const MultilibBuilder &M2)
Add a set of mutually incompatible Multilib segments.
MultilibSet makeMultilibSet() const
See also MultilibSetBuilder for combining multilibs into a set.
MultilibSet & setFilePathsCallback(IncludeDirsFunc F)
MultilibSet & FilterOut(FilterCallback F)
Filter out some subset of the Multilibs using a user defined callback.
const IncludeDirsFunc & filePathsCallback() const
bool select(const Multilib::flags_list &Flags, llvm::SmallVectorImpl< Multilib > &) const
Select compatible variants,.
const IncludeDirsFunc & includeDirsCallback() const
MultilibSet & setIncludeDirsCallback(IncludeDirsFunc F)
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag.
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant.
const std::string & osSuffix() const
Get the detected os path suffix for the multi-arch target variant.
std::vector< std::string > flags_list
const std::string & includeSuffix() const
Get the include directory suffix.
bool isDefault() const
Check whether the default is selected.
bool isLLVMIR(ID Id)
Is this LLVM IR.
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
bool canTypeBeUserSpecified(ID Id)
canTypeBeUserSpecified - Can this type be specified on the command line (by the type name); this is u...
bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const llvm::opt::ArgList &Args, DetectedMultilibs &Result)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
MultilibSet Multilibs
The set of multilibs that the detected installation supports.
std::optional< Multilib > BiarchSibling
On Biarch systems, this corresponds to the default multilib when targeting the non-default multilib.
llvm::SmallVector< Multilib > SelectedMultilibs
The multilibs appropriate for the given flags.
static constexpr ResponseFileSupport AtFileCurCP()