clang  9.0.0svn
Gnu.cpp
Go to the documentation of this file.
1 //===--- Gnu.cpp - Gnu Tool and ToolChain Implementations -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Gnu.h"
10 #include "Arch/ARM.h"
11 #include "Arch/Mips.h"
12 #include "Arch/PPC.h"
13 #include "Arch/RISCV.h"
14 #include "Arch/Sparc.h"
15 #include "Arch/SystemZ.h"
16 #include "CommonArgs.h"
17 #include "Linux.h"
18 #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX
20 #include "clang/Driver/Driver.h"
22 #include "clang/Driver/Options.h"
23 #include "clang/Driver/Tool.h"
24 #include "clang/Driver/ToolChain.h"
25 #include "llvm/Option/ArgList.h"
26 #include "llvm/Support/CodeGen.h"
27 #include "llvm/Support/Path.h"
28 #include "llvm/Support/TargetParser.h"
29 #include "llvm/Support/VirtualFileSystem.h"
30 #include <system_error>
31 
32 using namespace clang::driver;
33 using namespace clang::driver::toolchains;
34 using namespace clang;
35 using namespace llvm::opt;
36 
38 
39 void tools::GnuTool::anchor() {}
40 
41 static bool forwardToGCC(const Option &O) {
42  // Don't forward inputs from the original command line. They are added from
43  // InputInfoList.
44  return O.getKind() != Option::InputClass &&
45  !O.hasFlag(options::DriverOption) && !O.hasFlag(options::LinkerInput);
46 }
47 
48 // Switch CPU names not recognized by GNU assembler to a close CPU that it does
49 // recognize, instead of a lower march from being picked in the absence of a cpu
50 // flag.
51 static void normalizeCPUNamesForAssembler(const ArgList &Args,
52  ArgStringList &CmdArgs) {
53  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
54  StringRef CPUArg(A->getValue());
55  if (CPUArg.equals_lower("krait"))
56  CmdArgs.push_back("-mcpu=cortex-a15");
57  else if(CPUArg.equals_lower("kryo"))
58  CmdArgs.push_back("-mcpu=cortex-a57");
59  else
60  Args.AddLastArg(CmdArgs, options::OPT_mcpu_EQ);
61  }
62 }
63 
65  const InputInfo &Output,
66  const InputInfoList &Inputs,
67  const ArgList &Args,
68  const char *LinkingOutput) const {
69  const Driver &D = getToolChain().getDriver();
70  ArgStringList CmdArgs;
71 
72  for (const auto &A : Args) {
73  if (forwardToGCC(A->getOption())) {
74  // It is unfortunate that we have to claim here, as this means
75  // we will basically never report anything interesting for
76  // platforms using a generic gcc, even if we are just using gcc
77  // to get to the assembler.
78  A->claim();
79 
80  // Don't forward any -g arguments to assembly steps.
81  if (isa<AssembleJobAction>(JA) &&
82  A->getOption().matches(options::OPT_g_Group))
83  continue;
84 
85  // Don't forward any -W arguments to assembly and link steps.
86  if ((isa<AssembleJobAction>(JA) || isa<LinkJobAction>(JA)) &&
87  A->getOption().matches(options::OPT_W_Group))
88  continue;
89 
90  // Don't forward -mno-unaligned-access since GCC doesn't understand
91  // it and because it doesn't affect the assembly or link steps.
92  if ((isa<AssembleJobAction>(JA) || isa<LinkJobAction>(JA)) &&
93  (A->getOption().matches(options::OPT_munaligned_access) ||
94  A->getOption().matches(options::OPT_mno_unaligned_access)))
95  continue;
96 
97  A->render(Args, CmdArgs);
98  }
99  }
100 
101  RenderExtraToolArgs(JA, CmdArgs);
102 
103  // If using a driver driver, force the arch.
104  if (getToolChain().getTriple().isOSDarwin()) {
105  CmdArgs.push_back("-arch");
106  CmdArgs.push_back(
107  Args.MakeArgString(getToolChain().getDefaultUniversalArchName()));
108  }
109 
110  // Try to force gcc to match the tool chain we want, if we recognize
111  // the arch.
112  //
113  // FIXME: The triple class should directly provide the information we want
114  // here.
115  switch (getToolChain().getArch()) {
116  default:
117  break;
118  case llvm::Triple::x86:
119  case llvm::Triple::ppc:
120  CmdArgs.push_back("-m32");
121  break;
122  case llvm::Triple::x86_64:
123  case llvm::Triple::ppc64:
124  case llvm::Triple::ppc64le:
125  CmdArgs.push_back("-m64");
126  break;
127  case llvm::Triple::sparcel:
128  CmdArgs.push_back("-EL");
129  break;
130  }
131 
132  if (Output.isFilename()) {
133  CmdArgs.push_back("-o");
134  CmdArgs.push_back(Output.getFilename());
135  } else {
136  assert(Output.isNothing() && "Unexpected output");
137  CmdArgs.push_back("-fsyntax-only");
138  }
139 
140  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
141 
142  // Only pass -x if gcc will understand it; otherwise hope gcc
143  // understands the suffix correctly. The main use case this would go
144  // wrong in is for linker inputs if they happened to have an odd
145  // suffix; really the only way to get this to happen is a command
146  // like '-x foobar a.c' which will treat a.c like a linker input.
147  //
148  // FIXME: For the linker case specifically, can we safely convert
149  // inputs into '-Wl,' options?
150  for (const auto &II : Inputs) {
151  // Don't try to pass LLVM or AST inputs to a generic gcc.
152  if (types::isLLVMIR(II.getType()))
153  D.Diag(clang::diag::err_drv_no_linker_llvm_support)
154  << getToolChain().getTripleString();
155  else if (II.getType() == types::TY_AST)
156  D.Diag(diag::err_drv_no_ast_support) << getToolChain().getTripleString();
157  else if (II.getType() == types::TY_ModuleFile)
158  D.Diag(diag::err_drv_no_module_support)
159  << getToolChain().getTripleString();
160 
161  if (types::canTypeBeUserSpecified(II.getType())) {
162  CmdArgs.push_back("-x");
163  CmdArgs.push_back(types::getTypeName(II.getType()));
164  }
165 
166  if (II.isFilename())
167  CmdArgs.push_back(II.getFilename());
168  else {
169  const Arg &A = II.getInputArg();
170 
171  // Reverse translate some rewritten options.
172  if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
173  CmdArgs.push_back("-lstdc++");
174  continue;
175  }
176 
177  // Don't render as input, we need gcc to do the translations.
178  A.render(Args, CmdArgs);
179  }
180  }
181 
182  const std::string &customGCCName = D.getCCCGenericGCCName();
183  const char *GCCName;
184  if (!customGCCName.empty())
185  GCCName = customGCCName.c_str();
186  else if (D.CCCIsCXX()) {
187  GCCName = "g++";
188  } else
189  GCCName = "gcc";
190 
191  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(GCCName));
192  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
193 }
194 
196  const JobAction &JA, ArgStringList &CmdArgs) const {
197  CmdArgs.push_back("-E");
198 }
199 
201  ArgStringList &CmdArgs) const {
202  const Driver &D = getToolChain().getDriver();
203 
204  switch (JA.getType()) {
205  // If -flto, etc. are present then make sure not to force assembly output.
206  case types::TY_LLVM_IR:
207  case types::TY_LTO_IR:
208  case types::TY_LLVM_BC:
209  case types::TY_LTO_BC:
210  CmdArgs.push_back("-c");
211  break;
212  // We assume we've got an "integrated" assembler in that gcc will produce an
213  // object file itself.
214  case types::TY_Object:
215  CmdArgs.push_back("-c");
216  break;
217  case types::TY_PP_Asm:
218  CmdArgs.push_back("-S");
219  break;
220  case types::TY_Nothing:
221  CmdArgs.push_back("-fsyntax-only");
222  break;
223  default:
224  D.Diag(diag::err_drv_invalid_gcc_output_type) << getTypeName(JA.getType());
225  }
226 }
227 
229  ArgStringList &CmdArgs) const {
230  // The types are (hopefully) good enough.
231 }
232 
233 // On Arm the endianness of the output file is determined by the target and
234 // can be overridden by the pseudo-target flags '-mlittle-endian'/'-EL' and
235 // '-mbig-endian'/'-EB'. Unlike other targets the flag does not result in a
236 // normalized triple so we must handle the flag here.
237 static bool isArmBigEndian(const llvm::Triple &Triple,
238  const ArgList &Args) {
239  bool IsBigEndian = false;
240  switch (Triple.getArch()) {
241  case llvm::Triple::armeb:
242  case llvm::Triple::thumbeb:
243  IsBigEndian = true;
244  LLVM_FALLTHROUGH;
245  case llvm::Triple::arm:
246  case llvm::Triple::thumb:
247  if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
248  options::OPT_mbig_endian))
249  IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
250  break;
251  default:
252  break;
253  }
254  return IsBigEndian;
255 }
256 
257 static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) {
258  switch (T.getArch()) {
259  case llvm::Triple::x86:
260  if (T.isOSIAMCU())
261  return "elf_iamcu";
262  return "elf_i386";
263  case llvm::Triple::aarch64:
264  return "aarch64linux";
265  case llvm::Triple::aarch64_be:
266  return "aarch64linuxb";
267  case llvm::Triple::arm:
268  case llvm::Triple::thumb:
269  case llvm::Triple::armeb:
270  case llvm::Triple::thumbeb:
271  return isArmBigEndian(T, Args) ? "armelfb_linux_eabi" : "armelf_linux_eabi";
272  case llvm::Triple::ppc:
273  return "elf32ppclinux";
274  case llvm::Triple::ppc64:
275  return "elf64ppc";
276  case llvm::Triple::ppc64le:
277  return "elf64lppc";
278  case llvm::Triple::riscv32:
279  return "elf32lriscv";
280  case llvm::Triple::riscv64:
281  return "elf64lriscv";
282  case llvm::Triple::sparc:
283  case llvm::Triple::sparcel:
284  return "elf32_sparc";
285  case llvm::Triple::sparcv9:
286  return "elf64_sparc";
287  case llvm::Triple::mips:
288  return "elf32btsmip";
289  case llvm::Triple::mipsel:
290  return "elf32ltsmip";
291  case llvm::Triple::mips64:
292  if (tools::mips::hasMipsAbiArg(Args, "n32") ||
293  T.getEnvironment() == llvm::Triple::GNUABIN32)
294  return "elf32btsmipn32";
295  return "elf64btsmip";
296  case llvm::Triple::mips64el:
297  if (tools::mips::hasMipsAbiArg(Args, "n32") ||
298  T.getEnvironment() == llvm::Triple::GNUABIN32)
299  return "elf32ltsmipn32";
300  return "elf64ltsmip";
301  case llvm::Triple::systemz:
302  return "elf64_s390";
303  case llvm::Triple::x86_64:
304  if (T.getEnvironment() == llvm::Triple::GNUX32)
305  return "elf32_x86_64";
306  return "elf_x86_64";
307  default:
308  return nullptr;
309  }
310 }
311 
312 static bool getPIE(const ArgList &Args, const toolchains::Linux &ToolChain) {
313  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
314  Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
315  return false;
316 
317  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
318  options::OPT_nopie);
319  if (!A)
320  return ToolChain.isPIEDefault();
321  return A->getOption().matches(options::OPT_pie);
322 }
323 
324 static bool getStaticPIE(const ArgList &Args,
325  const toolchains::Linux &ToolChain) {
326  bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
327  // -no-pie is an alias for -nopie. So, handling -nopie takes care of
328  // -no-pie as well.
329  if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
330  const Driver &D = ToolChain.getDriver();
331  const llvm::opt::OptTable &Opts = D.getOpts();
332  const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
333  const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
334  D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
335  }
336  return HasStaticPIE;
337 }
338 
339 static bool getStatic(const ArgList &Args) {
340  return Args.hasArg(options::OPT_static) &&
341  !Args.hasArg(options::OPT_static_pie);
342 }
343 
345  const InputInfo &Output,
346  const InputInfoList &Inputs,
347  const ArgList &Args,
348  const char *LinkingOutput) const {
350  static_cast<const toolchains::Linux &>(getToolChain());
351  const Driver &D = ToolChain.getDriver();
352 
353  const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
354 
355  const llvm::Triple::ArchType Arch = ToolChain.getArch();
356  const bool isAndroid = ToolChain.getTriple().isAndroid();
357  const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
358  const bool IsPIE = getPIE(Args, ToolChain);
359  const bool IsStaticPIE = getStaticPIE(Args, ToolChain);
360  const bool IsStatic = getStatic(Args);
361  const bool HasCRTBeginEndFiles =
362  ToolChain.getTriple().hasEnvironment() ||
363  (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
364 
365  ArgStringList CmdArgs;
366 
367  // Silence warning for "clang -g foo.o -o foo"
368  Args.ClaimAllArgs(options::OPT_g_Group);
369  // and "clang -emit-llvm foo.o -o foo"
370  Args.ClaimAllArgs(options::OPT_emit_llvm);
371  // and for "clang -w foo.o -o foo". Other warning options are already
372  // handled somewhere else.
373  Args.ClaimAllArgs(options::OPT_w);
374 
375  if (!D.SysRoot.empty())
376  CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
377 
378  if (IsPIE)
379  CmdArgs.push_back("-pie");
380 
381  if (IsStaticPIE) {
382  CmdArgs.push_back("-static");
383  CmdArgs.push_back("-pie");
384  CmdArgs.push_back("--no-dynamic-linker");
385  CmdArgs.push_back("-z");
386  CmdArgs.push_back("text");
387  }
388 
389  if (ToolChain.isNoExecStackDefault()) {
390  CmdArgs.push_back("-z");
391  CmdArgs.push_back("noexecstack");
392  }
393 
394  if (Args.hasArg(options::OPT_rdynamic))
395  CmdArgs.push_back("-export-dynamic");
396 
397  if (Args.hasArg(options::OPT_s))
398  CmdArgs.push_back("-s");
399 
400  if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) {
401  bool IsBigEndian = isArmBigEndian(Triple, Args);
402  if (IsBigEndian)
403  arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
404  IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be;
405  CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
406  }
407 
408  // Most Android ARM64 targets should enable the linker fix for erratum
409  // 843419. Only non-Cortex-A53 devices are allowed to skip this flag.
410  if (Arch == llvm::Triple::aarch64 && isAndroid) {
411  std::string CPU = getCPUName(Args, Triple);
412  if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53")
413  CmdArgs.push_back("--fix-cortex-a53-843419");
414  }
415 
416  // Android does not allow shared text relocations. Emit a warning if the
417  // user's code contains any.
418  if (isAndroid)
419  CmdArgs.push_back("--warn-shared-textrel");
420 
421  for (const auto &Opt : ToolChain.ExtraOpts)
422  CmdArgs.push_back(Opt.c_str());
423 
424  CmdArgs.push_back("--eh-frame-hdr");
425 
426  if (const char *LDMOption = getLDMOption(ToolChain.getTriple(), Args)) {
427  CmdArgs.push_back("-m");
428  CmdArgs.push_back(LDMOption);
429  } else {
430  D.Diag(diag::err_target_unknown_triple) << Triple.str();
431  return;
432  }
433 
434  if (IsStatic) {
435  if (Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb ||
436  Arch == llvm::Triple::thumb || Arch == llvm::Triple::thumbeb)
437  CmdArgs.push_back("-Bstatic");
438  else
439  CmdArgs.push_back("-static");
440  } else if (Args.hasArg(options::OPT_shared)) {
441  CmdArgs.push_back("-shared");
442  }
443 
444  if (!IsStatic) {
445  if (Args.hasArg(options::OPT_rdynamic))
446  CmdArgs.push_back("-export-dynamic");
447 
448  if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) {
449  const std::string Loader =
450  D.DyldPrefix + ToolChain.getDynamicLinker(Args);
451  CmdArgs.push_back("-dynamic-linker");
452  CmdArgs.push_back(Args.MakeArgString(Loader));
453  }
454  }
455 
456  CmdArgs.push_back("-o");
457  CmdArgs.push_back(Output.getFilename());
458 
459  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
460  if (!isAndroid && !IsIAMCU) {
461  const char *crt1 = nullptr;
462  if (!Args.hasArg(options::OPT_shared)) {
463  if (Args.hasArg(options::OPT_pg))
464  crt1 = "gcrt1.o";
465  else if (IsPIE)
466  crt1 = "Scrt1.o";
467  else if (IsStaticPIE)
468  crt1 = "rcrt1.o";
469  else
470  crt1 = "crt1.o";
471  }
472  if (crt1)
473  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
474 
475  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
476  }
477 
478  if (IsIAMCU)
479  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
480  else if (HasCRTBeginEndFiles) {
481  std::string P;
482  if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT &&
483  !isAndroid) {
484  std::string crtbegin = ToolChain.getCompilerRT(Args, "crtbegin",
486  if (ToolChain.getVFS().exists(crtbegin))
487  P = crtbegin;
488  }
489  if (P.empty()) {
490  const char *crtbegin;
491  if (IsStatic)
492  crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o";
493  else if (Args.hasArg(options::OPT_shared))
494  crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o";
495  else if (IsPIE || IsStaticPIE)
496  crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o";
497  else
498  crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o";
499  P = ToolChain.GetFilePath(crtbegin);
500  }
501  CmdArgs.push_back(Args.MakeArgString(P));
502  }
503 
504  // Add crtfastmath.o if available and fast math is enabled.
505  ToolChain.AddFastMathRuntimeIfAvailable(Args, CmdArgs);
506  }
507 
508  Args.AddAllArgs(CmdArgs, options::OPT_L);
509  Args.AddAllArgs(CmdArgs, options::OPT_u);
510 
511  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
512 
513  if (D.isUsingLTO()) {
514  assert(!Inputs.empty() && "Must have at least one input.");
515  AddGoldPlugin(ToolChain, Args, CmdArgs, Output, Inputs[0],
516  D.getLTOMode() == LTOK_Thin);
517  }
518 
519  if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
520  CmdArgs.push_back("--no-demangle");
521 
522  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
523  bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
524  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
525  // The profile runtime also needs access to system libraries.
526  getToolChain().addProfileRTLibs(Args, CmdArgs);
527 
528  if (D.CCCIsCXX() &&
529  !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
530  if (ToolChain.ShouldLinkCXXStdlib(Args)) {
531  bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
532  !Args.hasArg(options::OPT_static);
533  if (OnlyLibstdcxxStatic)
534  CmdArgs.push_back("-Bstatic");
535  ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
536  if (OnlyLibstdcxxStatic)
537  CmdArgs.push_back("-Bdynamic");
538  }
539  CmdArgs.push_back("-lm");
540  }
541  // Silence warnings when linking C code with a C++ '-stdlib' argument.
542  Args.ClaimAllArgs(options::OPT_stdlib_EQ);
543 
544  if (!Args.hasArg(options::OPT_nostdlib)) {
545  if (!Args.hasArg(options::OPT_nodefaultlibs)) {
546  if (IsStatic || IsStaticPIE)
547  CmdArgs.push_back("--start-group");
548 
549  if (NeedsSanitizerDeps)
550  linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
551 
552  if (NeedsXRayDeps)
553  linkXRayRuntimeDeps(ToolChain, CmdArgs);
554 
555  bool WantPthread = Args.hasArg(options::OPT_pthread) ||
556  Args.hasArg(options::OPT_pthreads);
557 
558  // FIXME: Only pass GompNeedsRT = true for platforms with libgomp that
559  // require librt. Most modern Linux platforms do, but some may not.
560  if (addOpenMPRuntime(CmdArgs, ToolChain, Args,
562  /* GompNeedsRT= */ true))
563  // OpenMP runtimes implies pthreads when using the GNU toolchain.
564  // FIXME: Does this really make sense for all GNU toolchains?
565  WantPthread = true;
566 
567  AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
568 
569  if (WantPthread && !isAndroid)
570  CmdArgs.push_back("-lpthread");
571 
572  if (Args.hasArg(options::OPT_fsplit_stack))
573  CmdArgs.push_back("--wrap=pthread_create");
574 
575  if (!Args.hasArg(options::OPT_nolibc))
576  CmdArgs.push_back("-lc");
577 
578  // Add IAMCU specific libs, if needed.
579  if (IsIAMCU)
580  CmdArgs.push_back("-lgloss");
581 
582  if (IsStatic || IsStaticPIE)
583  CmdArgs.push_back("--end-group");
584  else
585  AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
586 
587  // Add IAMCU specific libs (outside the group), if needed.
588  if (IsIAMCU) {
589  CmdArgs.push_back("--as-needed");
590  CmdArgs.push_back("-lsoftfp");
591  CmdArgs.push_back("--no-as-needed");
592  }
593  }
594 
595  if (!Args.hasArg(options::OPT_nostartfiles) && !IsIAMCU) {
596  if (HasCRTBeginEndFiles) {
597  std::string P;
598  if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT &&
599  !isAndroid) {
600  std::string crtend = ToolChain.getCompilerRT(Args, "crtend",
602  if (ToolChain.getVFS().exists(crtend))
603  P = crtend;
604  }
605  if (P.empty()) {
606  const char *crtend;
607  if (Args.hasArg(options::OPT_shared))
608  crtend = isAndroid ? "crtend_so.o" : "crtendS.o";
609  else if (IsPIE || IsStaticPIE)
610  crtend = isAndroid ? "crtend_android.o" : "crtendS.o";
611  else
612  crtend = isAndroid ? "crtend_android.o" : "crtend.o";
613  P = ToolChain.GetFilePath(crtend);
614  }
615  CmdArgs.push_back(Args.MakeArgString(P));
616  }
617  if (!isAndroid)
618  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
619  }
620  }
621 
622  // Add OpenMP offloading linker script args if required.
623  AddOpenMPLinkerScript(getToolChain(), C, Output, Inputs, Args, CmdArgs, JA);
624 
625  // Add HIP offloading linker script args if required.
626  AddHIPLinkerScript(getToolChain(), C, Output, Inputs, Args, CmdArgs, JA,
627  *this);
628 
629  const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
630  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
631 }
632 
634  const JobAction &JA,
635  const InputInfo &Output,
636  const InputInfoList &Inputs,
637  const ArgList &Args,
638  const char *LinkingOutput) const {
639  const auto &D = getToolChain().getDriver();
640 
641  claimNoWarnArgs(Args);
642 
643  ArgStringList CmdArgs;
644 
645  llvm::Reloc::Model RelocationModel;
646  unsigned PICLevel;
647  bool IsPIE;
648  std::tie(RelocationModel, PICLevel, IsPIE) =
649  ParsePICArgs(getToolChain(), Args);
650 
651  if (const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ)) {
652  if (A->getOption().getID() == options::OPT_gz) {
653  CmdArgs.push_back("--compress-debug-sections");
654  } else {
655  StringRef Value = A->getValue();
656  if (Value == "none" || Value == "zlib" || Value == "zlib-gnu") {
657  CmdArgs.push_back(
658  Args.MakeArgString("--compress-debug-sections=" + Twine(Value)));
659  } else {
660  D.Diag(diag::err_drv_unsupported_option_argument)
661  << A->getOption().getName() << Value;
662  }
663  }
664  }
665 
666  if (getToolChain().isNoExecStackDefault()) {
667  CmdArgs.push_back("--noexecstack");
668  }
669 
670  switch (getToolChain().getArch()) {
671  default:
672  break;
673  // Add --32/--64 to make sure we get the format we want.
674  // This is incomplete
675  case llvm::Triple::x86:
676  CmdArgs.push_back("--32");
677  break;
678  case llvm::Triple::x86_64:
679  if (getToolChain().getTriple().getEnvironment() == llvm::Triple::GNUX32)
680  CmdArgs.push_back("--x32");
681  else
682  CmdArgs.push_back("--64");
683  break;
684  case llvm::Triple::ppc: {
685  CmdArgs.push_back("-a32");
686  CmdArgs.push_back("-mppc");
687  CmdArgs.push_back(
688  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
689  break;
690  }
691  case llvm::Triple::ppc64: {
692  CmdArgs.push_back("-a64");
693  CmdArgs.push_back("-mppc64");
694  CmdArgs.push_back(
695  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
696  break;
697  }
698  case llvm::Triple::ppc64le: {
699  CmdArgs.push_back("-a64");
700  CmdArgs.push_back("-mppc64");
701  CmdArgs.push_back("-mlittle-endian");
702  CmdArgs.push_back(
703  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
704  break;
705  }
706  case llvm::Triple::riscv32:
707  case llvm::Triple::riscv64: {
708  StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
709  CmdArgs.push_back("-mabi");
710  CmdArgs.push_back(ABIName.data());
711  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
712  StringRef MArch = A->getValue();
713  CmdArgs.push_back("-march");
714  CmdArgs.push_back(MArch.data());
715  }
716  break;
717  }
718  case llvm::Triple::sparc:
719  case llvm::Triple::sparcel: {
720  CmdArgs.push_back("-32");
721  std::string CPU = getCPUName(Args, getToolChain().getTriple());
722  CmdArgs.push_back(
723  sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
724  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
725  break;
726  }
727  case llvm::Triple::sparcv9: {
728  CmdArgs.push_back("-64");
729  std::string CPU = getCPUName(Args, getToolChain().getTriple());
730  CmdArgs.push_back(
731  sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
732  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
733  break;
734  }
735  case llvm::Triple::arm:
736  case llvm::Triple::armeb:
737  case llvm::Triple::thumb:
738  case llvm::Triple::thumbeb: {
739  const llvm::Triple &Triple2 = getToolChain().getTriple();
740  CmdArgs.push_back(isArmBigEndian(Triple2, Args) ? "-EB" : "-EL");
741  switch (Triple2.getSubArch()) {
742  case llvm::Triple::ARMSubArch_v7:
743  CmdArgs.push_back("-mfpu=neon");
744  break;
745  case llvm::Triple::ARMSubArch_v8:
746  CmdArgs.push_back("-mfpu=crypto-neon-fp-armv8");
747  break;
748  default:
749  break;
750  }
751 
752  switch (arm::getARMFloatABI(getToolChain(), Args)) {
753  case arm::FloatABI::Invalid: llvm_unreachable("must have an ABI!");
754  case arm::FloatABI::Soft:
755  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=soft"));
756  break;
757  case arm::FloatABI::SoftFP:
758  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=softfp"));
759  break;
760  case arm::FloatABI::Hard:
761  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=hard"));
762  break;
763  }
764 
765  Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
766  normalizeCPUNamesForAssembler(Args, CmdArgs);
767 
768  Args.AddLastArg(CmdArgs, options::OPT_mfpu_EQ);
769  break;
770  }
771  case llvm::Triple::aarch64:
772  case llvm::Triple::aarch64_be: {
773  CmdArgs.push_back(
774  getToolChain().getArch() == llvm::Triple::aarch64_be ? "-EB" : "-EL");
775  Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
776  normalizeCPUNamesForAssembler(Args, CmdArgs);
777 
778  break;
779  }
780  case llvm::Triple::mips:
781  case llvm::Triple::mipsel:
782  case llvm::Triple::mips64:
783  case llvm::Triple::mips64el: {
784  StringRef CPUName;
785  StringRef ABIName;
786  mips::getMipsCPUAndABI(Args, getToolChain().getTriple(), CPUName, ABIName);
787  ABIName = mips::getGnuCompatibleMipsABIName(ABIName);
788 
789  CmdArgs.push_back("-march");
790  CmdArgs.push_back(CPUName.data());
791 
792  CmdArgs.push_back("-mabi");
793  CmdArgs.push_back(ABIName.data());
794 
795  // -mno-shared should be emitted unless -fpic, -fpie, -fPIC, -fPIE,
796  // or -mshared (not implemented) is in effect.
797  if (RelocationModel == llvm::Reloc::Static)
798  CmdArgs.push_back("-mno-shared");
799 
800  // LLVM doesn't support -mplt yet and acts as if it is always given.
801  // However, -mplt has no effect with the N64 ABI.
802  if (ABIName != "64" && !Args.hasArg(options::OPT_mno_abicalls))
803  CmdArgs.push_back("-call_nonpic");
804 
805  if (getToolChain().getTriple().isLittleEndian())
806  CmdArgs.push_back("-EL");
807  else
808  CmdArgs.push_back("-EB");
809 
810  if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
811  if (StringRef(A->getValue()) == "2008")
812  CmdArgs.push_back(Args.MakeArgString("-mnan=2008"));
813  }
814 
815  // Add the last -mfp32/-mfpxx/-mfp64 or -mfpxx if it is enabled by default.
816  if (Arg *A = Args.getLastArg(options::OPT_mfp32, options::OPT_mfpxx,
817  options::OPT_mfp64)) {
818  A->claim();
819  A->render(Args, CmdArgs);
820  } else if (mips::shouldUseFPXX(
821  Args, getToolChain().getTriple(), CPUName, ABIName,
822  mips::getMipsFloatABI(getToolChain().getDriver(), Args)))
823  CmdArgs.push_back("-mfpxx");
824 
825  // Pass on -mmips16 or -mno-mips16. However, the assembler equivalent of
826  // -mno-mips16 is actually -no-mips16.
827  if (Arg *A =
828  Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16)) {
829  if (A->getOption().matches(options::OPT_mips16)) {
830  A->claim();
831  A->render(Args, CmdArgs);
832  } else {
833  A->claim();
834  CmdArgs.push_back("-no-mips16");
835  }
836  }
837 
838  Args.AddLastArg(CmdArgs, options::OPT_mmicromips,
839  options::OPT_mno_micromips);
840  Args.AddLastArg(CmdArgs, options::OPT_mdsp, options::OPT_mno_dsp);
841  Args.AddLastArg(CmdArgs, options::OPT_mdspr2, options::OPT_mno_dspr2);
842 
843  if (Arg *A = Args.getLastArg(options::OPT_mmsa, options::OPT_mno_msa)) {
844  // Do not use AddLastArg because not all versions of MIPS assembler
845  // support -mmsa / -mno-msa options.
846  if (A->getOption().matches(options::OPT_mmsa))
847  CmdArgs.push_back(Args.MakeArgString("-mmsa"));
848  }
849 
850  Args.AddLastArg(CmdArgs, options::OPT_mhard_float,
851  options::OPT_msoft_float);
852 
853  Args.AddLastArg(CmdArgs, options::OPT_mdouble_float,
854  options::OPT_msingle_float);
855 
856  Args.AddLastArg(CmdArgs, options::OPT_modd_spreg,
857  options::OPT_mno_odd_spreg);
858 
859  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
860  break;
861  }
862  case llvm::Triple::systemz: {
863  // Always pass an -march option, since our default of z10 is later
864  // than the GNU assembler's default.
865  StringRef CPUName = systemz::getSystemZTargetCPU(Args);
866  CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName));
867  break;
868  }
869  }
870 
871  Args.AddAllArgs(CmdArgs, options::OPT_I);
872  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
873 
874  CmdArgs.push_back("-o");
875  CmdArgs.push_back(Output.getFilename());
876 
877  for (const auto &II : Inputs)
878  CmdArgs.push_back(II.getFilename());
879 
880  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
881  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
882 
883  // Handle the debug info splitting at object creation time if we're
884  // creating an object.
885  // TODO: Currently only works on linux with newer objcopy.
886  if (Args.hasArg(options::OPT_gsplit_dwarf) &&
887  getToolChain().getTriple().isOSLinux())
888  SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
889  SplitDebugName(Args, Inputs[0], Output));
890 }
891 
892 namespace {
893 // Filter to remove Multilibs that don't exist as a suffix to Path
894 class FilterNonExistent {
895  StringRef Base, File;
896  llvm::vfs::FileSystem &VFS;
897 
898 public:
899  FilterNonExistent(StringRef Base, StringRef File, llvm::vfs::FileSystem &VFS)
900  : Base(Base), File(File), VFS(VFS) {}
901  bool operator()(const Multilib &M) {
902  return !VFS.exists(Base + M.gccSuffix() + File);
903  }
904 };
905 } // end anonymous namespace
906 
907 static bool isSoftFloatABI(const ArgList &Args) {
908  Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
909  options::OPT_mfloat_abi_EQ);
910  if (!A)
911  return false;
912 
913  return A->getOption().matches(options::OPT_msoft_float) ||
914  (A->getOption().matches(options::OPT_mfloat_abi_EQ) &&
915  A->getValue() == StringRef("soft"));
916 }
917 
918 static bool isArmOrThumbArch(llvm::Triple::ArchType Arch) {
919  return Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb;
920 }
921 
922 static bool isMipsEL(llvm::Triple::ArchType Arch) {
923  return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el;
924 }
925 
926 static bool isMips16(const ArgList &Args) {
927  Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16);
928  return A && A->getOption().matches(options::OPT_mips16);
929 }
930 
931 static bool isMicroMips(const ArgList &Args) {
932  Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips);
933  return A && A->getOption().matches(options::OPT_mmicromips);
934 }
935 
936 static bool isMSP430(llvm::Triple::ArchType Arch) {
937  return Arch == llvm::Triple::msp430;
938 }
939 
940 static Multilib makeMultilib(StringRef commonSuffix) {
941  return Multilib(commonSuffix, commonSuffix, commonSuffix);
942 }
943 
944 static bool findMipsCsMultilibs(const Multilib::flags_list &Flags,
945  FilterNonExistent &NonExistent,
946  DetectedMultilibs &Result) {
947  // Check for Code Sourcery toolchain multilibs
948  MultilibSet CSMipsMultilibs;
949  {
950  auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16");
951 
952  auto MArchMicroMips =
953  makeMultilib("/micromips").flag("+m32").flag("+mmicromips");
954 
955  auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips");
956 
957  auto UCLibc = makeMultilib("/uclibc").flag("+muclibc");
958 
959  auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float");
960 
961  auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008");
962 
963  auto DefaultFloat =
964  makeMultilib("").flag("-msoft-float").flag("-mnan=2008");
965 
966  auto BigEndian = makeMultilib("").flag("+EB").flag("-EL");
967 
968  auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB");
969 
970  // Note that this one's osSuffix is ""
971  auto MAbi64 = makeMultilib("")
972  .gccSuffix("/64")
973  .includeSuffix("/64")
974  .flag("+mabi=n64")
975  .flag("-mabi=n32")
976  .flag("-m32");
977 
978  CSMipsMultilibs =
979  MultilibSet()
980  .Either(MArchMips16, MArchMicroMips, MArchDefault)
981  .Maybe(UCLibc)
982  .Either(SoftFloat, Nan2008, DefaultFloat)
983  .FilterOut("/micromips/nan2008")
984  .FilterOut("/mips16/nan2008")
985  .Either(BigEndian, LittleEndian)
986  .Maybe(MAbi64)
987  .FilterOut("/mips16.*/64")
988  .FilterOut("/micromips.*/64")
989  .FilterOut(NonExistent)
990  .setIncludeDirsCallback([](const Multilib &M) {
991  std::vector<std::string> Dirs({"/include"});
992  if (StringRef(M.includeSuffix()).startswith("/uclibc"))
993  Dirs.push_back(
994  "/../../../../mips-linux-gnu/libc/uclibc/usr/include");
995  else
996  Dirs.push_back("/../../../../mips-linux-gnu/libc/usr/include");
997  return Dirs;
998  });
999  }
1000 
1001  MultilibSet DebianMipsMultilibs;
1002  {
1003  Multilib MAbiN32 =
1004  Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32");
1005 
1006  Multilib M64 = Multilib()
1007  .gccSuffix("/64")
1008  .includeSuffix("/64")
1009  .flag("+m64")
1010  .flag("-m32")
1011  .flag("-mabi=n32");
1012 
1013  Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32");
1014 
1015  DebianMipsMultilibs =
1016  MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent);
1017  }
1018 
1019  // Sort candidates. Toolchain that best meets the directories tree goes first.
1020  // Then select the first toolchains matches command line flags.
1021  MultilibSet *Candidates[] = {&CSMipsMultilibs, &DebianMipsMultilibs};
1022  if (CSMipsMultilibs.size() < DebianMipsMultilibs.size())
1023  std::iter_swap(Candidates, Candidates + 1);
1024  for (const MultilibSet *Candidate : Candidates) {
1025  if (Candidate->select(Flags, Result.SelectedMultilib)) {
1026  if (Candidate == &DebianMipsMultilibs)
1027  Result.BiarchSibling = Multilib();
1028  Result.Multilibs = *Candidate;
1029  return true;
1030  }
1031  }
1032  return false;
1033 }
1034 
1035 static bool findMipsAndroidMultilibs(llvm::vfs::FileSystem &VFS, StringRef Path,
1036  const Multilib::flags_list &Flags,
1037  FilterNonExistent &NonExistent,
1038  DetectedMultilibs &Result) {
1039 
1040  MultilibSet AndroidMipsMultilibs =
1041  MultilibSet()
1042  .Maybe(Multilib("/mips-r2").flag("+march=mips32r2"))
1043  .Maybe(Multilib("/mips-r6").flag("+march=mips32r6"))
1044  .FilterOut(NonExistent);
1045 
1046  MultilibSet AndroidMipselMultilibs =
1047  MultilibSet()
1048  .Either(Multilib().flag("+march=mips32"),
1049  Multilib("/mips-r2", "", "/mips-r2").flag("+march=mips32r2"),
1050  Multilib("/mips-r6", "", "/mips-r6").flag("+march=mips32r6"))
1051  .FilterOut(NonExistent);
1052 
1053  MultilibSet AndroidMips64elMultilibs =
1054  MultilibSet()
1055  .Either(
1056  Multilib().flag("+march=mips64r6"),
1057  Multilib("/32/mips-r1", "", "/mips-r1").flag("+march=mips32"),
1058  Multilib("/32/mips-r2", "", "/mips-r2").flag("+march=mips32r2"),
1059  Multilib("/32/mips-r6", "", "/mips-r6").flag("+march=mips32r6"))
1060  .FilterOut(NonExistent);
1061 
1062  MultilibSet *MS = &AndroidMipsMultilibs;
1063  if (VFS.exists(Path + "/mips-r6"))
1064  MS = &AndroidMipselMultilibs;
1065  else if (VFS.exists(Path + "/32"))
1066  MS = &AndroidMips64elMultilibs;
1067  if (MS->select(Flags, Result.SelectedMultilib)) {
1068  Result.Multilibs = *MS;
1069  return true;
1070  }
1071  return false;
1072 }
1073 
1075  FilterNonExistent &NonExistent,
1076  DetectedMultilibs &Result) {
1077  // Musl toolchain multilibs
1078  MultilibSet MuslMipsMultilibs;
1079  {
1080  auto MArchMipsR2 = makeMultilib("")
1081  .osSuffix("/mips-r2-hard-musl")
1082  .flag("+EB")
1083  .flag("-EL")
1084  .flag("+march=mips32r2");
1085 
1086  auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl")
1087  .flag("-EB")
1088  .flag("+EL")
1089  .flag("+march=mips32r2");
1090 
1091  MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2);
1092 
1093  // Specify the callback that computes the include directories.
1094  MuslMipsMultilibs.setIncludeDirsCallback([](const Multilib &M) {
1095  return std::vector<std::string>(
1096  {"/../sysroot" + M.osSuffix() + "/usr/include"});
1097  });
1098  }
1099  if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) {
1100  Result.Multilibs = MuslMipsMultilibs;
1101  return true;
1102  }
1103  return false;
1104 }
1105 
1107  FilterNonExistent &NonExistent,
1108  DetectedMultilibs &Result) {
1109  // CodeScape MTI toolchain v1.2 and early.
1110  MultilibSet MtiMipsMultilibsV1;
1111  {
1112  auto MArchMips32 = makeMultilib("/mips32")
1113  .flag("+m32")
1114  .flag("-m64")
1115  .flag("-mmicromips")
1116  .flag("+march=mips32");
1117 
1118  auto MArchMicroMips = makeMultilib("/micromips")
1119  .flag("+m32")
1120  .flag("-m64")
1121  .flag("+mmicromips");
1122 
1123  auto MArchMips64r2 = makeMultilib("/mips64r2")
1124  .flag("-m32")
1125  .flag("+m64")
1126  .flag("+march=mips64r2");
1127 
1128  auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag(
1129  "-march=mips64r2");
1130 
1131  auto MArchDefault = makeMultilib("")
1132  .flag("+m32")
1133  .flag("-m64")
1134  .flag("-mmicromips")
1135  .flag("+march=mips32r2");
1136 
1137  auto Mips16 = makeMultilib("/mips16").flag("+mips16");
1138 
1139  auto UCLibc = makeMultilib("/uclibc").flag("+muclibc");
1140 
1141  auto MAbi64 =
1142  makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32");
1143 
1144  auto BigEndian = makeMultilib("").flag("+EB").flag("-EL");
1145 
1146  auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB");
1147 
1148  auto SoftFloat = makeMultilib("/sof").flag("+msoft-float");
1149 
1150  auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008");
1151 
1152  MtiMipsMultilibsV1 =
1153  MultilibSet()
1154  .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64,
1155  MArchDefault)
1156  .Maybe(UCLibc)
1157  .Maybe(Mips16)
1158  .FilterOut("/mips64/mips16")
1159  .FilterOut("/mips64r2/mips16")
1160  .FilterOut("/micromips/mips16")
1161  .Maybe(MAbi64)
1162  .FilterOut("/micromips/64")
1163  .FilterOut("/mips32/64")
1164  .FilterOut("^/64")
1165  .FilterOut("/mips16/64")
1166  .Either(BigEndian, LittleEndian)
1167  .Maybe(SoftFloat)
1168  .Maybe(Nan2008)
1169  .FilterOut(".*sof/nan2008")
1170  .FilterOut(NonExistent)
1171  .setIncludeDirsCallback([](const Multilib &M) {
1172  std::vector<std::string> Dirs({"/include"});
1173  if (StringRef(M.includeSuffix()).startswith("/uclibc"))
1174  Dirs.push_back("/../../../../sysroot/uclibc/usr/include");
1175  else
1176  Dirs.push_back("/../../../../sysroot/usr/include");
1177  return Dirs;
1178  });
1179  }
1180 
1181  // CodeScape IMG toolchain starting from v1.3.
1182  MultilibSet MtiMipsMultilibsV2;
1183  {
1184  auto BeHard = makeMultilib("/mips-r2-hard")
1185  .flag("+EB")
1186  .flag("-msoft-float")
1187  .flag("-mnan=2008")
1188  .flag("-muclibc");
1189  auto BeSoft = makeMultilib("/mips-r2-soft")
1190  .flag("+EB")
1191  .flag("+msoft-float")
1192  .flag("-mnan=2008");
1193  auto ElHard = makeMultilib("/mipsel-r2-hard")
1194  .flag("+EL")
1195  .flag("-msoft-float")
1196  .flag("-mnan=2008")
1197  .flag("-muclibc");
1198  auto ElSoft = makeMultilib("/mipsel-r2-soft")
1199  .flag("+EL")
1200  .flag("+msoft-float")
1201  .flag("-mnan=2008")
1202  .flag("-mmicromips");
1203  auto BeHardNan = makeMultilib("/mips-r2-hard-nan2008")
1204  .flag("+EB")
1205  .flag("-msoft-float")
1206  .flag("+mnan=2008")
1207  .flag("-muclibc");
1208  auto ElHardNan = makeMultilib("/mipsel-r2-hard-nan2008")
1209  .flag("+EL")
1210  .flag("-msoft-float")
1211  .flag("+mnan=2008")
1212  .flag("-muclibc")
1213  .flag("-mmicromips");
1214  auto BeHardNanUclibc = makeMultilib("/mips-r2-hard-nan2008-uclibc")
1215  .flag("+EB")
1216  .flag("-msoft-float")
1217  .flag("+mnan=2008")
1218  .flag("+muclibc");
1219  auto ElHardNanUclibc = makeMultilib("/mipsel-r2-hard-nan2008-uclibc")
1220  .flag("+EL")
1221  .flag("-msoft-float")
1222  .flag("+mnan=2008")
1223  .flag("+muclibc");
1224  auto BeHardUclibc = makeMultilib("/mips-r2-hard-uclibc")
1225  .flag("+EB")
1226  .flag("-msoft-float")
1227  .flag("-mnan=2008")
1228  .flag("+muclibc");
1229  auto ElHardUclibc = makeMultilib("/mipsel-r2-hard-uclibc")
1230  .flag("+EL")
1231  .flag("-msoft-float")
1232  .flag("-mnan=2008")
1233  .flag("+muclibc");
1234  auto ElMicroHardNan = makeMultilib("/micromipsel-r2-hard-nan2008")
1235  .flag("+EL")
1236  .flag("-msoft-float")
1237  .flag("+mnan=2008")
1238  .flag("+mmicromips");
1239  auto ElMicroSoft = makeMultilib("/micromipsel-r2-soft")
1240  .flag("+EL")
1241  .flag("+msoft-float")
1242  .flag("-mnan=2008")
1243  .flag("+mmicromips");
1244 
1245  auto O32 =
1246  makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64");
1247  auto N32 =
1248  makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64");
1249  auto N64 =
1250  makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64");
1251 
1252  MtiMipsMultilibsV2 =
1253  MultilibSet()
1254  .Either({BeHard, BeSoft, ElHard, ElSoft, BeHardNan, ElHardNan,
1255  BeHardNanUclibc, ElHardNanUclibc, BeHardUclibc,
1256  ElHardUclibc, ElMicroHardNan, ElMicroSoft})
1257  .Either(O32, N32, N64)
1258  .FilterOut(NonExistent)
1259  .setIncludeDirsCallback([](const Multilib &M) {
1260  return std::vector<std::string>({"/../../../../sysroot" +
1261  M.includeSuffix() +
1262  "/../usr/include"});
1263  })
1264  .setFilePathsCallback([](const Multilib &M) {
1265  return std::vector<std::string>(
1266  {"/../../../../mips-mti-linux-gnu/lib" + M.gccSuffix()});
1267  });
1268  }
1269  for (auto Candidate : {&MtiMipsMultilibsV1, &MtiMipsMultilibsV2}) {
1270  if (Candidate->select(Flags, Result.SelectedMultilib)) {
1271  Result.Multilibs = *Candidate;
1272  return true;
1273  }
1274  }
1275  return false;
1276 }
1277 
1279  FilterNonExistent &NonExistent,
1280  DetectedMultilibs &Result) {
1281  // CodeScape IMG toolchain v1.2 and early.
1282  MultilibSet ImgMultilibsV1;
1283  {
1284  auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32");
1285 
1286  auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB");
1287 
1288  auto MAbi64 =
1289  makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32");
1290 
1291  ImgMultilibsV1 =
1292  MultilibSet()
1293  .Maybe(Mips64r6)
1294  .Maybe(MAbi64)
1295  .Maybe(LittleEndian)
1296  .FilterOut(NonExistent)
1297  .setIncludeDirsCallback([](const Multilib &M) {
1298  return std::vector<std::string>(
1299  {"/include", "/../../../../sysroot/usr/include"});
1300  });
1301  }
1302 
1303  // CodeScape IMG toolchain starting from v1.3.
1304  MultilibSet ImgMultilibsV2;
1305  {
1306  auto BeHard = makeMultilib("/mips-r6-hard")
1307  .flag("+EB")
1308  .flag("-msoft-float")
1309  .flag("-mmicromips");
1310  auto BeSoft = makeMultilib("/mips-r6-soft")
1311  .flag("+EB")
1312  .flag("+msoft-float")
1313  .flag("-mmicromips");
1314  auto ElHard = makeMultilib("/mipsel-r6-hard")
1315  .flag("+EL")
1316  .flag("-msoft-float")
1317  .flag("-mmicromips");
1318  auto ElSoft = makeMultilib("/mipsel-r6-soft")
1319  .flag("+EL")
1320  .flag("+msoft-float")
1321  .flag("-mmicromips");
1322  auto BeMicroHard = makeMultilib("/micromips-r6-hard")
1323  .flag("+EB")
1324  .flag("-msoft-float")
1325  .flag("+mmicromips");
1326  auto BeMicroSoft = makeMultilib("/micromips-r6-soft")
1327  .flag("+EB")
1328  .flag("+msoft-float")
1329  .flag("+mmicromips");
1330  auto ElMicroHard = makeMultilib("/micromipsel-r6-hard")
1331  .flag("+EL")
1332  .flag("-msoft-float")
1333  .flag("+mmicromips");
1334  auto ElMicroSoft = makeMultilib("/micromipsel-r6-soft")
1335  .flag("+EL")
1336  .flag("+msoft-float")
1337  .flag("+mmicromips");
1338 
1339  auto O32 =
1340  makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64");
1341  auto N32 =
1342  makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64");
1343  auto N64 =
1344  makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64");
1345 
1346  ImgMultilibsV2 =
1347  MultilibSet()
1348  .Either({BeHard, BeSoft, ElHard, ElSoft, BeMicroHard, BeMicroSoft,
1349  ElMicroHard, ElMicroSoft})
1350  .Either(O32, N32, N64)
1351  .FilterOut(NonExistent)
1352  .setIncludeDirsCallback([](const Multilib &M) {
1353  return std::vector<std::string>({"/../../../../sysroot" +
1354  M.includeSuffix() +
1355  "/../usr/include"});
1356  })
1357  .setFilePathsCallback([](const Multilib &M) {
1358  return std::vector<std::string>(
1359  {"/../../../../mips-img-linux-gnu/lib" + M.gccSuffix()});
1360  });
1361  }
1362  for (auto Candidate : {&ImgMultilibsV1, &ImgMultilibsV2}) {
1363  if (Candidate->select(Flags, Result.SelectedMultilib)) {
1364  Result.Multilibs = *Candidate;
1365  return true;
1366  }
1367  }
1368  return false;
1369 }
1370 
1372  const llvm::Triple &TargetTriple,
1373  StringRef Path, const ArgList &Args,
1374  DetectedMultilibs &Result) {
1375  FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
1376 
1377  StringRef CPUName;
1378  StringRef ABIName;
1379  tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName);
1380 
1381  llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
1382 
1383  Multilib::flags_list Flags;
1384  addMultilibFlag(TargetTriple.isMIPS32(), "m32", Flags);
1385  addMultilibFlag(TargetTriple.isMIPS64(), "m64", Flags);
1386  addMultilibFlag(isMips16(Args), "mips16", Flags);
1387  addMultilibFlag(CPUName == "mips32", "march=mips32", Flags);
1388  addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" ||
1389  CPUName == "mips32r5" || CPUName == "p5600",
1390  "march=mips32r2", Flags);
1391  addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags);
1392  addMultilibFlag(CPUName == "mips64", "march=mips64", Flags);
1393  addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" ||
1394  CPUName == "mips64r5" || CPUName == "octeon",
1395  "march=mips64r2", Flags);
1396  addMultilibFlag(CPUName == "mips64r6", "march=mips64r6", Flags);
1397  addMultilibFlag(isMicroMips(Args), "mmicromips", Flags);
1398  addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags);
1399  addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008",
1400  Flags);
1401  addMultilibFlag(ABIName == "n32", "mabi=n32", Flags);
1402  addMultilibFlag(ABIName == "n64", "mabi=n64", Flags);
1403  addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags);
1404  addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags);
1405  addMultilibFlag(isMipsEL(TargetArch), "EL", Flags);
1406  addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags);
1407 
1408  if (TargetTriple.isAndroid())
1409  return findMipsAndroidMultilibs(D.getVFS(), Path, Flags, NonExistent,
1410  Result);
1411 
1412  if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies &&
1413  TargetTriple.getOS() == llvm::Triple::Linux &&
1414  TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment)
1415  return findMipsMuslMultilibs(Flags, NonExistent, Result);
1416 
1417  if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies &&
1418  TargetTriple.getOS() == llvm::Triple::Linux &&
1419  TargetTriple.isGNUEnvironment())
1420  return findMipsMtiMultilibs(Flags, NonExistent, Result);
1421 
1422  if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies &&
1423  TargetTriple.getOS() == llvm::Triple::Linux &&
1424  TargetTriple.isGNUEnvironment())
1425  return findMipsImgMultilibs(Flags, NonExistent, Result);
1426 
1427  if (findMipsCsMultilibs(Flags, NonExistent, Result))
1428  return true;
1429 
1430  // Fallback to the regular toolchain-tree structure.
1431  Multilib Default;
1432  Result.Multilibs.push_back(Default);
1433  Result.Multilibs.FilterOut(NonExistent);
1434 
1435  if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) {
1436  Result.BiarchSibling = Multilib();
1437  return true;
1438  }
1439 
1440  return false;
1441 }
1442 
1443 static void findAndroidArmMultilibs(const Driver &D,
1444  const llvm::Triple &TargetTriple,
1445  StringRef Path, const ArgList &Args,
1446  DetectedMultilibs &Result) {
1447  // Find multilibs with subdirectories like armv7-a, thumb, armv7-a/thumb.
1448  FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
1449  Multilib ArmV7Multilib = makeMultilib("/armv7-a")
1450  .flag("+march=armv7-a")
1451  .flag("-mthumb");
1452  Multilib ThumbMultilib = makeMultilib("/thumb")
1453  .flag("-march=armv7-a")
1454  .flag("+mthumb");
1455  Multilib ArmV7ThumbMultilib = makeMultilib("/armv7-a/thumb")
1456  .flag("+march=armv7-a")
1457  .flag("+mthumb");
1458  Multilib DefaultMultilib = makeMultilib("")
1459  .flag("-march=armv7-a")
1460  .flag("-mthumb");
1461  MultilibSet AndroidArmMultilibs =
1462  MultilibSet()
1463  .Either(ThumbMultilib, ArmV7Multilib,
1464  ArmV7ThumbMultilib, DefaultMultilib)
1465  .FilterOut(NonExistent);
1466 
1467  Multilib::flags_list Flags;
1468  llvm::StringRef Arch = Args.getLastArgValue(options::OPT_march_EQ);
1469  bool IsArmArch = TargetTriple.getArch() == llvm::Triple::arm;
1470  bool IsThumbArch = TargetTriple.getArch() == llvm::Triple::thumb;
1471  bool IsV7SubArch = TargetTriple.getSubArch() == llvm::Triple::ARMSubArch_v7;
1472  bool IsThumbMode = IsThumbArch ||
1473  Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, false) ||
1474  (IsArmArch && llvm::ARM::parseArchISA(Arch) == llvm::ARM::ISAKind::THUMB);
1475  bool IsArmV7Mode = (IsArmArch || IsThumbArch) &&
1476  (llvm::ARM::parseArchVersion(Arch) == 7 ||
1477  (IsArmArch && Arch == "" && IsV7SubArch));
1478  addMultilibFlag(IsArmV7Mode, "march=armv7-a", Flags);
1479  addMultilibFlag(IsThumbMode, "mthumb", Flags);
1480 
1481  if (AndroidArmMultilibs.select(Flags, Result.SelectedMultilib))
1482  Result.Multilibs = AndroidArmMultilibs;
1483 }
1484 
1485 static bool findMSP430Multilibs(const Driver &D,
1486  const llvm::Triple &TargetTriple,
1487  StringRef Path, const ArgList &Args,
1488  DetectedMultilibs &Result) {
1489  FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
1490  Multilib MSP430Multilib = makeMultilib("/430");
1491  // FIXME: when clang starts to support msp430x ISA additional logic
1492  // to select between multilib must be implemented
1493  // Multilib MSP430xMultilib = makeMultilib("/large");
1494 
1495  Result.Multilibs.push_back(MSP430Multilib);
1496  Result.Multilibs.FilterOut(NonExistent);
1497 
1498  Multilib::flags_list Flags;
1499  if (Result.Multilibs.select(Flags, Result.SelectedMultilib))
1500  return true;
1501 
1502  return false;
1503 }
1504 
1505 static void findRISCVMultilibs(const Driver &D,
1506  const llvm::Triple &TargetTriple, StringRef Path,
1507  const ArgList &Args, DetectedMultilibs &Result) {
1508 
1509  FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
1510  Multilib Ilp32 = makeMultilib("lib32/ilp32").flag("+m32").flag("+mabi=ilp32");
1511  Multilib Ilp32f =
1512  makeMultilib("lib32/ilp32f").flag("+m32").flag("+mabi=ilp32f");
1513  Multilib Ilp32d =
1514  makeMultilib("lib32/ilp32d").flag("+m32").flag("+mabi=ilp32d");
1515  Multilib Lp64 = makeMultilib("lib64/lp64").flag("+m64").flag("+mabi=lp64");
1516  Multilib Lp64f = makeMultilib("lib64/lp64f").flag("+m64").flag("+mabi=lp64f");
1517  Multilib Lp64d = makeMultilib("lib64/lp64d").flag("+m64").flag("+mabi=lp64d");
1518  MultilibSet RISCVMultilibs =
1519  MultilibSet()
1520  .Either({Ilp32, Ilp32f, Ilp32d, Lp64, Lp64f, Lp64d})
1521  .FilterOut(NonExistent);
1522 
1523  Multilib::flags_list Flags;
1524  bool IsRV64 = TargetTriple.getArch() == llvm::Triple::riscv64;
1525  StringRef ABIName = tools::riscv::getRISCVABI(Args, TargetTriple);
1526 
1527  addMultilibFlag(!IsRV64, "m32", Flags);
1528  addMultilibFlag(IsRV64, "m64", Flags);
1529  addMultilibFlag(ABIName == "ilp32", "mabi=ilp32", Flags);
1530  addMultilibFlag(ABIName == "ilp32f", "mabi=ilp32f", Flags);
1531  addMultilibFlag(ABIName == "ilp32d", "mabi=ilp32d", Flags);
1532  addMultilibFlag(ABIName == "lp64", "mabi=lp64", Flags);
1533  addMultilibFlag(ABIName == "lp64f", "mabi=lp64f", Flags);
1534  addMultilibFlag(ABIName == "lp64d", "mabi=lp64d", Flags);
1535 
1536  if (RISCVMultilibs.select(Flags, Result.SelectedMultilib))
1537  Result.Multilibs = RISCVMultilibs;
1538 }
1539 
1540 static bool findBiarchMultilibs(const Driver &D,
1541  const llvm::Triple &TargetTriple,
1542  StringRef Path, const ArgList &Args,
1543  bool NeedsBiarchSuffix,
1544  DetectedMultilibs &Result) {
1545  Multilib Default;
1546 
1547  // Some versions of SUSE and Fedora on ppc64 put 32-bit libs
1548  // in what would normally be GCCInstallPath and put the 64-bit
1549  // libs in a subdirectory named 64. The simple logic we follow is that
1550  // *if* there is a subdirectory of the right name with crtbegin.o in it,
1551  // we use that. If not, and if not a biarch triple alias, we look for
1552  // crtbegin.o without the subdirectory.
1553 
1554  StringRef Suff64 = "/64";
1555  // Solaris uses platform-specific suffixes instead of /64.
1556  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
1557  switch (TargetTriple.getArch()) {
1558  case llvm::Triple::x86:
1559  case llvm::Triple::x86_64:
1560  Suff64 = "/amd64";
1561  break;
1562  case llvm::Triple::sparc:
1563  case llvm::Triple::sparcv9:
1564  Suff64 = "/sparcv9";
1565  break;
1566  default:
1567  break;
1568  }
1569  }
1570 
1571  Multilib Alt64 = Multilib()
1572  .gccSuffix(Suff64)
1573  .includeSuffix(Suff64)
1574  .flag("-m32")
1575  .flag("+m64")
1576  .flag("-mx32");
1577  Multilib Alt32 = Multilib()
1578  .gccSuffix("/32")
1579  .includeSuffix("/32")
1580  .flag("+m32")
1581  .flag("-m64")
1582  .flag("-mx32");
1583  Multilib Altx32 = Multilib()
1584  .gccSuffix("/x32")
1585  .includeSuffix("/x32")
1586  .flag("-m32")
1587  .flag("-m64")
1588  .flag("+mx32");
1589 
1590  // GCC toolchain for IAMCU doesn't have crtbegin.o, so look for libgcc.a.
1591  FilterNonExistent NonExistent(
1592  Path, TargetTriple.isOSIAMCU() ? "/libgcc.a" : "/crtbegin.o", D.getVFS());
1593 
1594  // Determine default multilib from: 32, 64, x32
1595  // Also handle cases such as 64 on 32, 32 on 64, etc.
1596  enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN;
1597  const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32;
1598  if (TargetTriple.isArch32Bit() && !NonExistent(Alt32))
1599  Want = WANT64;
1600  else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32))
1601  Want = WANT64;
1602  else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64))
1603  Want = WANT32;
1604  else {
1605  if (TargetTriple.isArch32Bit())
1606  Want = NeedsBiarchSuffix ? WANT64 : WANT32;
1607  else if (IsX32)
1608  Want = NeedsBiarchSuffix ? WANT64 : WANTX32;
1609  else
1610  Want = NeedsBiarchSuffix ? WANT32 : WANT64;
1611  }
1612 
1613  if (Want == WANT32)
1614  Default.flag("+m32").flag("-m64").flag("-mx32");
1615  else if (Want == WANT64)
1616  Default.flag("-m32").flag("+m64").flag("-mx32");
1617  else if (Want == WANTX32)
1618  Default.flag("-m32").flag("-m64").flag("+mx32");
1619  else
1620  return false;
1621 
1622  Result.Multilibs.push_back(Default);
1623  Result.Multilibs.push_back(Alt64);
1624  Result.Multilibs.push_back(Alt32);
1625  Result.Multilibs.push_back(Altx32);
1626 
1627  Result.Multilibs.FilterOut(NonExistent);
1628 
1629  Multilib::flags_list Flags;
1630  addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags);
1631  addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags);
1632  addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags);
1633 
1634  if (!Result.Multilibs.select(Flags, Result.SelectedMultilib))
1635  return false;
1636 
1637  if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 ||
1638  Result.SelectedMultilib == Altx32)
1639  Result.BiarchSibling = Default;
1640 
1641  return true;
1642 }
1643 
1644 /// Generic_GCC - A tool chain using the 'gcc' command to perform
1645 /// all subcommands; this relies on gcc translating the majority of
1646 /// command line options.
1647 
1648 /// Less-than for GCCVersion, implementing a Strict Weak Ordering.
1649 bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor,
1650  int RHSPatch,
1651  StringRef RHSPatchSuffix) const {
1652  if (Major != RHSMajor)
1653  return Major < RHSMajor;
1654  if (Minor != RHSMinor)
1655  return Minor < RHSMinor;
1656  if (Patch != RHSPatch) {
1657  // Note that versions without a specified patch sort higher than those with
1658  // a patch.
1659  if (RHSPatch == -1)
1660  return true;
1661  if (Patch == -1)
1662  return false;
1663 
1664  // Otherwise just sort on the patch itself.
1665  return Patch < RHSPatch;
1666  }
1667  if (PatchSuffix != RHSPatchSuffix) {
1668  // Sort empty suffixes higher.
1669  if (RHSPatchSuffix.empty())
1670  return true;
1671  if (PatchSuffix.empty())
1672  return false;
1673 
1674  // Provide a lexicographic sort to make this a total ordering.
1675  return PatchSuffix < RHSPatchSuffix;
1676  }
1677 
1678  // The versions are equal.
1679  return false;
1680 }
1681 
1682 /// Parse a GCCVersion object out of a string of text.
1683 ///
1684 /// This is the primary means of forming GCCVersion objects.
1685 /*static*/
1687  const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""};
1688  std::pair<StringRef, StringRef> First = VersionText.split('.');
1689  std::pair<StringRef, StringRef> Second = First.second.split('.');
1690 
1691  GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""};
1692  if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0)
1693  return BadVersion;
1694  GoodVersion.MajorStr = First.first.str();
1695  if (First.second.empty())
1696  return GoodVersion;
1697  StringRef MinorStr = Second.first;
1698  if (Second.second.empty()) {
1699  if (size_t EndNumber = MinorStr.find_first_not_of("0123456789")) {
1700  GoodVersion.PatchSuffix = MinorStr.substr(EndNumber);
1701  MinorStr = MinorStr.slice(0, EndNumber);
1702  }
1703  }
1704  if (MinorStr.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0)
1705  return BadVersion;
1706  GoodVersion.MinorStr = MinorStr.str();
1707 
1708  // First look for a number prefix and parse that if present. Otherwise just
1709  // stash the entire patch string in the suffix, and leave the number
1710  // unspecified. This covers versions strings such as:
1711  // 5 (handled above)
1712  // 4.4
1713  // 4.4-patched
1714  // 4.4.0
1715  // 4.4.x
1716  // 4.4.2-rc4
1717  // 4.4.x-patched
1718  // And retains any patch number it finds.
1719  StringRef PatchText = Second.second;
1720  if (!PatchText.empty()) {
1721  if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) {
1722  // Try to parse the number and any suffix.
1723  if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) ||
1724  GoodVersion.Patch < 0)
1725  return BadVersion;
1726  GoodVersion.PatchSuffix = PatchText.substr(EndNumber);
1727  }
1728  }
1729 
1730  return GoodVersion;
1731 }
1732 
1733 static llvm::StringRef getGCCToolchainDir(const ArgList &Args,
1734  llvm::StringRef SysRoot) {
1735  const Arg *A = Args.getLastArg(clang::driver::options::OPT_gcc_toolchain);
1736  if (A)
1737  return A->getValue();
1738 
1739  // If we have a SysRoot, ignore GCC_INSTALL_PREFIX.
1740  // GCC_INSTALL_PREFIX specifies the gcc installation for the default
1741  // sysroot and is likely not valid with a different sysroot.
1742  if (!SysRoot.empty())
1743  return "";
1744 
1745  return GCC_INSTALL_PREFIX;
1746 }
1747 
1748 /// Initialize a GCCInstallationDetector from the driver.
1749 ///
1750 /// This performs all of the autodetection and sets up the various paths.
1751 /// Once constructed, a GCCInstallationDetector is essentially immutable.
1752 ///
1753 /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and
1754 /// should instead pull the target out of the driver. This is currently
1755 /// necessary because the driver doesn't store the final version of the target
1756 /// triple.
1758  const llvm::Triple &TargetTriple, const ArgList &Args,
1759  ArrayRef<std::string> ExtraTripleAliases) {
1760  llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit()
1761  ? TargetTriple.get64BitArchVariant()
1762  : TargetTriple.get32BitArchVariant();
1763  // The library directories which may contain GCC installations.
1764  SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs;
1765  // The compatible GCC triples for this particular architecture.
1766  SmallVector<StringRef, 16> CandidateTripleAliases;
1767  SmallVector<StringRef, 16> CandidateBiarchTripleAliases;
1768  CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
1769  CandidateTripleAliases, CandidateBiarchLibDirs,
1770  CandidateBiarchTripleAliases);
1771 
1772  // Compute the set of prefixes for our search.
1773  SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(),
1774  D.PrefixDirs.end());
1775 
1776  StringRef GCCToolchainDir = getGCCToolchainDir(Args, D.SysRoot);
1777  if (GCCToolchainDir != "") {
1778  if (GCCToolchainDir.back() == '/')
1779  GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the /
1780 
1781  Prefixes.push_back(GCCToolchainDir);
1782  } else {
1783  // If we have a SysRoot, try that first.
1784  if (!D.SysRoot.empty()) {
1785  Prefixes.push_back(D.SysRoot);
1786  AddDefaultGCCPrefixes(TargetTriple, Prefixes, D.SysRoot);
1787  }
1788 
1789  // Then look for gcc installed alongside clang.
1790  Prefixes.push_back(D.InstalledDir + "/..");
1791 
1792  // Next, look for prefix(es) that correspond to distribution-supplied gcc
1793  // installations.
1794  if (D.SysRoot.empty()) {
1795  // Typically /usr.
1796  AddDefaultGCCPrefixes(TargetTriple, Prefixes, D.SysRoot);
1797  }
1798  }
1799 
1800  // Try to respect gcc-config on Gentoo. However, do that only
1801  // if --gcc-toolchain is not provided or equal to the Gentoo install
1802  // in /usr. This avoids accidentally enforcing the system GCC version
1803  // when using a custom toolchain.
1804  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
1805  SmallVector<StringRef, 16> GentooTestTriples;
1806  // Try to match an exact triple as target triple first.
1807  // e.g. crossdev -S x86_64-gentoo-linux-gnu will install gcc libs for
1808  // x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
1809  // may pick the libraries for x86_64-pc-linux-gnu even when exact matching
1810  // triple x86_64-gentoo-linux-gnu is present.
1811  GentooTestTriples.push_back(TargetTriple.str());
1812  // Check rest of triples.
1813  GentooTestTriples.append(ExtraTripleAliases.begin(),
1814  ExtraTripleAliases.end());
1815  GentooTestTriples.append(CandidateTripleAliases.begin(),
1816  CandidateTripleAliases.end());
1817  if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
1818  CandidateBiarchTripleAliases))
1819  return;
1820  }
1821 
1822  // Loop over the various components which exist and select the best GCC
1823  // installation available. GCC installs are ranked by version number.
1824  Version = GCCVersion::Parse("0.0.0");
1825  for (const std::string &Prefix : Prefixes) {
1826  if (!D.getVFS().exists(Prefix))
1827  continue;
1828  for (StringRef Suffix : CandidateLibDirs) {
1829  const std::string LibDir = Prefix + Suffix.str();
1830  if (!D.getVFS().exists(LibDir))
1831  continue;
1832  // Try to match the exact target triple first.
1833  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str());
1834  // Try rest of possible triples.
1835  for (StringRef Candidate : ExtraTripleAliases) // Try these first.
1836  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
1837  for (StringRef Candidate : CandidateTripleAliases)
1838  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
1839  }
1840  for (StringRef Suffix : CandidateBiarchLibDirs) {
1841  const std::string LibDir = Prefix + Suffix.str();
1842  if (!D.getVFS().exists(LibDir))
1843  continue;
1844  for (StringRef Candidate : CandidateBiarchTripleAliases)
1845  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate,
1846  /*NeedsBiarchSuffix=*/ true);
1847  }
1848  }
1849 }
1850 
1851 void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const {
1852  for (const auto &InstallPath : CandidateGCCInstallPaths)
1853  OS << "Found candidate GCC installation: " << InstallPath << "\n";
1854 
1855  if (!GCCInstallPath.empty())
1856  OS << "Selected GCC installation: " << GCCInstallPath << "\n";
1857 
1858  for (const auto &Multilib : Multilibs)
1859  OS << "Candidate multilib: " << Multilib << "\n";
1860 
1861  if (Multilibs.size() != 0 || !SelectedMultilib.isDefault())
1862  OS << "Selected multilib: " << SelectedMultilib << "\n";
1863 }
1864 
1866  if (BiarchSibling.hasValue()) {
1867  M = BiarchSibling.getValue();
1868  return true;
1869  }
1870  return false;
1871 }
1872 
1873 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
1874  const llvm::Triple &TargetTriple, SmallVectorImpl<std::string> &Prefixes,
1875  StringRef SysRoot) {
1876  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
1877  // Solaris is a special case.
1878  // The GCC installation is under
1879  // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/
1880  // so we need to find those /usr/gcc/*/lib/gcc libdirs and go with
1881  // /usr/gcc/<version> as a prefix.
1882 
1883  std::string PrefixDir = SysRoot.str() + "/usr/gcc";
1884  std::error_code EC;
1885  for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin(PrefixDir, EC),
1886  LE;
1887  !EC && LI != LE; LI = LI.increment(EC)) {
1888  StringRef VersionText = llvm::sys::path::filename(LI->path());
1889  GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
1890 
1891  // Filter out obviously bad entries.
1892  if (CandidateVersion.Major == -1 || CandidateVersion.isOlderThan(4, 1, 1))
1893  continue;
1894 
1895  std::string CandidatePrefix = PrefixDir + "/" + VersionText.str();
1896  std::string CandidateLibPath = CandidatePrefix + "/lib/gcc";
1897  if (!D.getVFS().exists(CandidateLibPath))
1898  continue;
1899 
1900  Prefixes.push_back(CandidatePrefix);
1901  }
1902  return;
1903  }
1904 
1905  // Non-Solaris is much simpler - most systems just go with "/usr".
1906  if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux) {
1907  // Yet, still look for RHEL devtoolsets.
1908  Prefixes.push_back("/opt/rh/devtoolset-8/root/usr");
1909  Prefixes.push_back("/opt/rh/devtoolset-7/root/usr");
1910  Prefixes.push_back("/opt/rh/devtoolset-6/root/usr");
1911  Prefixes.push_back("/opt/rh/devtoolset-4/root/usr");
1912  Prefixes.push_back("/opt/rh/devtoolset-3/root/usr");
1913  Prefixes.push_back("/opt/rh/devtoolset-2/root/usr");
1914  }
1915  Prefixes.push_back(SysRoot.str() + "/usr");
1916 }
1917 
1918 /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples(
1919  const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple,
1920  SmallVectorImpl<StringRef> &LibDirs,
1921  SmallVectorImpl<StringRef> &TripleAliases,
1922  SmallVectorImpl<StringRef> &BiarchLibDirs,
1923  SmallVectorImpl<StringRef> &BiarchTripleAliases) {
1924  // Declare a bunch of static data sets that we'll select between below. These
1925  // are specifically designed to always refer to string literals to avoid any
1926  // lifetime or initialization issues.
1927  static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
1928  static const char *const AArch64Triples[] = {
1929  "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
1930  "aarch64-suse-linux", "aarch64-linux-android"};
1931  static const char *const AArch64beLibDirs[] = {"/lib"};
1932  static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
1933  "aarch64_be-linux-gnu"};
1934 
1935  static const char *const ARMLibDirs[] = {"/lib"};
1936  static const char *const ARMTriples[] = {"arm-linux-gnueabi",
1937  "arm-linux-androideabi"};
1938  static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf",
1939  "armv7hl-redhat-linux-gnueabi",
1940  "armv6hl-suse-linux-gnueabi",
1941  "armv7hl-suse-linux-gnueabi"};
1942  static const char *const ARMebLibDirs[] = {"/lib"};
1943  static const char *const ARMebTriples[] = {"armeb-linux-gnueabi",
1944  "armeb-linux-androideabi"};
1945  static const char *const ARMebHFTriples[] = {
1946  "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"};
1947 
1948  static const char *const AVRLibDirs[] = {"/lib"};
1949  static const char *const AVRTriples[] = {"avr"};
1950 
1951  static const char *const X86_64LibDirs[] = {"/lib64", "/lib"};
1952  static const char *const X86_64Triples[] = {
1953  "x86_64-linux-gnu", "x86_64-unknown-linux-gnu",
1954  "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E",
1955  "x86_64-redhat-linux", "x86_64-suse-linux",
1956  "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
1957  "x86_64-slackware-linux", "x86_64-unknown-linux",
1958  "x86_64-amazon-linux", "x86_64-linux-android"};
1959  static const char *const X32LibDirs[] = {"/libx32"};
1960  static const char *const X86LibDirs[] = {"/lib32", "/lib"};
1961  static const char *const X86Triples[] = {
1962  "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu",
1963  "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux",
1964  "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux",
1965  "i486-slackware-linux", "i686-montavista-linux", "i586-linux-gnu",
1966  "i686-linux-android", "i386-gnu", "i486-gnu",
1967  "i586-gnu", "i686-gnu"};
1968 
1969  static const char *const MIPSLibDirs[] = {"/lib"};
1970  static const char *const MIPSTriples[] = {
1971  "mips-linux-gnu", "mips-mti-linux", "mips-mti-linux-gnu",
1972  "mips-img-linux-gnu", "mipsisa32r6-linux-gnu"};
1973  static const char *const MIPSELLibDirs[] = {"/lib"};
1974  static const char *const MIPSELTriples[] = {
1975  "mipsel-linux-gnu", "mips-img-linux-gnu", "mipsisa32r6el-linux-gnu",
1976  "mipsel-linux-android"};
1977 
1978  static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"};
1979  static const char *const MIPS64Triples[] = {
1980  "mips64-linux-gnu", "mips-mti-linux-gnu",
1981  "mips-img-linux-gnu", "mips64-linux-gnuabi64",
1982  "mipsisa64r6-linux-gnu", "mipsisa64r6-linux-gnuabi64"};
1983  static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"};
1984  static const char *const MIPS64ELTriples[] = {
1985  "mips64el-linux-gnu", "mips-mti-linux-gnu",
1986  "mips-img-linux-gnu", "mips64el-linux-gnuabi64",
1987  "mipsisa64r6el-linux-gnu", "mipsisa64r6el-linux-gnuabi64",
1988  "mips64el-linux-android"};
1989 
1990  static const char *const MIPSN32LibDirs[] = {"/lib32"};
1991  static const char *const MIPSN32Triples[] = {"mips64-linux-gnuabin32",
1992  "mipsisa64r6-linux-gnuabin32"};
1993  static const char *const MIPSN32ELLibDirs[] = {"/lib32"};
1994  static const char *const MIPSN32ELTriples[] = {
1995  "mips64el-linux-gnuabin32", "mipsisa64r6el-linux-gnuabin32"};
1996 
1997  static const char *const MSP430LibDirs[] = {"/lib"};
1998  static const char *const MSP430Triples[] = {"msp430-elf"};
1999 
2000  static const char *const PPCLibDirs[] = {"/lib32", "/lib"};
2001  static const char *const PPCTriples[] = {
2002  "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe",
2003  "powerpc-suse-linux", "powerpc-montavista-linuxspe"};
2004  static const char *const PPC64LibDirs[] = {"/lib64", "/lib"};
2005  static const char *const PPC64Triples[] = {
2006  "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu",
2007  "powerpc64-suse-linux", "ppc64-redhat-linux"};
2008  static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"};
2009  static const char *const PPC64LETriples[] = {
2010  "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu",
2011  "powerpc64le-suse-linux", "ppc64le-redhat-linux"};
2012 
2013  static const char *const RISCV32LibDirs[] = {"/lib32", "/lib"};
2014  static const char *const RISCV32Triples[] = {"riscv32-unknown-linux-gnu",
2015  "riscv32-linux-gnu",
2016  "riscv32-unknown-elf"};
2017  static const char *const RISCV64LibDirs[] = {"/lib64", "/lib"};
2018  static const char *const RISCV64Triples[] = {"riscv64-unknown-linux-gnu",
2019  "riscv64-linux-gnu",
2020  "riscv64-unknown-elf"};
2021 
2022  static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
2023  static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",
2024  "sparcv8-linux-gnu"};
2025  static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"};
2026  static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu",
2027  "sparcv9-linux-gnu"};
2028 
2029  static const char *const SystemZLibDirs[] = {"/lib64", "/lib"};
2030  static const char *const SystemZTriples[] = {
2031  "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu",
2032  "s390x-suse-linux", "s390x-redhat-linux"};
2033 
2034 
2035  using std::begin;
2036  using std::end;
2037 
2038  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
2039  static const char *const SolarisLibDirs[] = {"/lib"};
2040  static const char *const SolarisSparcV8Triples[] = {
2041  "sparc-sun-solaris2.11", "sparc-sun-solaris2.12"};
2042  static const char *const SolarisSparcV9Triples[] = {
2043  "sparcv9-sun-solaris2.11", "sparcv9-sun-solaris2.12"};
2044  static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11",
2045  "i386-pc-solaris2.12"};
2046  static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11",
2047  "x86_64-pc-solaris2.12"};
2048  LibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
2049  BiarchLibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
2050  switch (TargetTriple.getArch()) {
2051  case llvm::Triple::x86:
2052  TripleAliases.append(begin(SolarisX86Triples), end(SolarisX86Triples));
2053  BiarchTripleAliases.append(begin(SolarisX86_64Triples),
2054  end(SolarisX86_64Triples));
2055  break;
2056  case llvm::Triple::x86_64:
2057  TripleAliases.append(begin(SolarisX86_64Triples),
2058  end(SolarisX86_64Triples));
2059  BiarchTripleAliases.append(begin(SolarisX86Triples),
2060  end(SolarisX86Triples));
2061  break;
2062  case llvm::Triple::sparc:
2063  TripleAliases.append(begin(SolarisSparcV8Triples),
2064  end(SolarisSparcV8Triples));
2065  BiarchTripleAliases.append(begin(SolarisSparcV9Triples),
2066  end(SolarisSparcV9Triples));
2067  break;
2068  case llvm::Triple::sparcv9:
2069  TripleAliases.append(begin(SolarisSparcV9Triples),
2070  end(SolarisSparcV9Triples));
2071  BiarchTripleAliases.append(begin(SolarisSparcV8Triples),
2072  end(SolarisSparcV8Triples));
2073  break;
2074  default:
2075  break;
2076  }
2077  return;
2078  }
2079 
2080  // Android targets should not use GNU/Linux tools or libraries.
2081  if (TargetTriple.isAndroid()) {
2082  static const char *const AArch64AndroidTriples[] = {
2083  "aarch64-linux-android"};
2084  static const char *const ARMAndroidTriples[] = {"arm-linux-androideabi"};
2085  static const char *const MIPSELAndroidTriples[] = {"mipsel-linux-android"};
2086  static const char *const MIPS64ELAndroidTriples[] = {
2087  "mips64el-linux-android"};
2088  static const char *const X86AndroidTriples[] = {"i686-linux-android"};
2089  static const char *const X86_64AndroidTriples[] = {"x86_64-linux-android"};
2090 
2091  switch (TargetTriple.getArch()) {
2092  case llvm::Triple::aarch64:
2093  LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2094  TripleAliases.append(begin(AArch64AndroidTriples),
2095  end(AArch64AndroidTriples));
2096  break;
2097  case llvm::Triple::arm:
2098  case llvm::Triple::thumb:
2099  LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
2100  TripleAliases.append(begin(ARMAndroidTriples), end(ARMAndroidTriples));
2101  break;
2102  case llvm::Triple::mipsel:
2103  LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2104  TripleAliases.append(begin(MIPSELAndroidTriples),
2105  end(MIPSELAndroidTriples));
2106  BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2107  BiarchTripleAliases.append(begin(MIPS64ELAndroidTriples),
2108  end(MIPS64ELAndroidTriples));
2109  break;
2110  case llvm::Triple::mips64el:
2111  LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2112  TripleAliases.append(begin(MIPS64ELAndroidTriples),
2113  end(MIPS64ELAndroidTriples));
2114  BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2115  BiarchTripleAliases.append(begin(MIPSELAndroidTriples),
2116  end(MIPSELAndroidTriples));
2117  break;
2118  case llvm::Triple::x86_64:
2119  LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2120  TripleAliases.append(begin(X86_64AndroidTriples),
2121  end(X86_64AndroidTriples));
2122  BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2123  BiarchTripleAliases.append(begin(X86AndroidTriples),
2124  end(X86AndroidTriples));
2125  break;
2126  case llvm::Triple::x86:
2127  LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2128  TripleAliases.append(begin(X86AndroidTriples), end(X86AndroidTriples));
2129  BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2130  BiarchTripleAliases.append(begin(X86_64AndroidTriples),
2131  end(X86_64AndroidTriples));
2132  break;
2133  default:
2134  break;
2135  }
2136 
2137  return;
2138  }
2139 
2140  switch (TargetTriple.getArch()) {
2141  case llvm::Triple::aarch64:
2142  LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2143  TripleAliases.append(begin(AArch64Triples), end(AArch64Triples));
2144  BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2145  BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples));
2146  break;
2147  case llvm::Triple::aarch64_be:
2148  LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs));
2149  TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples));
2150  BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs));
2151  BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples));
2152  break;
2153  case llvm::Triple::arm:
2154  case llvm::Triple::thumb:
2155  LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
2156  if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
2157  TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples));
2158  } else {
2159  TripleAliases.append(begin(ARMTriples), end(ARMTriples));
2160  }
2161  break;
2162  case llvm::Triple::armeb:
2163  case llvm::Triple::thumbeb:
2164  LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs));
2165  if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
2166  TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples));
2167  } else {
2168  TripleAliases.append(begin(ARMebTriples), end(ARMebTriples));
2169  }
2170  break;
2171  case llvm::Triple::avr:
2172  LibDirs.append(begin(AVRLibDirs), end(AVRLibDirs));
2173  TripleAliases.append(begin(AVRTriples), end(AVRTriples));
2174  break;
2175  case llvm::Triple::x86_64:
2176  LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2177  TripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2178  // x32 is always available when x86_64 is available, so adding it as
2179  // secondary arch with x86_64 triples
2180  if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) {
2181  BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs));
2182  BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2183  } else {
2184  BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2185  BiarchTripleAliases.append(begin(X86Triples), end(X86Triples));
2186  }
2187  break;
2188  case llvm::Triple::x86:
2189  LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2190  // MCU toolchain is 32 bit only and its triple alias is TargetTriple
2191  // itself, which will be appended below.
2192  if (!TargetTriple.isOSIAMCU()) {
2193  TripleAliases.append(begin(X86Triples), end(X86Triples));
2194  BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2195  BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2196  }
2197  break;
2198  case llvm::Triple::mips:
2199  LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
2200  TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2201  BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs));
2202  BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples));
2203  BiarchLibDirs.append(begin(MIPSN32LibDirs), end(MIPSN32LibDirs));
2204  BiarchTripleAliases.append(begin(MIPSN32Triples), end(MIPSN32Triples));
2205  break;
2206  case llvm::Triple::mipsel:
2207  LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2208  TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples));
2209  TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2210  BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2211  BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples));
2212  BiarchLibDirs.append(begin(MIPSN32ELLibDirs), end(MIPSN32ELLibDirs));
2213  BiarchTripleAliases.append(begin(MIPSN32ELTriples), end(MIPSN32ELTriples));
2214  break;
2215  case llvm::Triple::mips64:
2216  LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs));
2217  TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples));
2218  BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
2219  BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2220  BiarchLibDirs.append(begin(MIPSN32LibDirs), end(MIPSN32LibDirs));
2221  BiarchTripleAliases.append(begin(MIPSN32Triples), end(MIPSN32Triples));
2222  break;
2223  case llvm::Triple::mips64el:
2224  LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2225  TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples));
2226  BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2227  BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples));
2228  BiarchLibDirs.append(begin(MIPSN32ELLibDirs), end(MIPSN32ELLibDirs));
2229  BiarchTripleAliases.append(begin(MIPSN32ELTriples), end(MIPSN32ELTriples));
2230  BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2231  break;
2232  case llvm::Triple::msp430:
2233  LibDirs.append(begin(MSP430LibDirs), end(MSP430LibDirs));
2234  TripleAliases.append(begin(MSP430Triples), end(MSP430Triples));
2235  break;
2236  case llvm::Triple::ppc:
2237  LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
2238  TripleAliases.append(begin(PPCTriples), end(PPCTriples));
2239  BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
2240  BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples));
2241  break;
2242  case llvm::Triple::ppc64:
2243  LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
2244  TripleAliases.append(begin(PPC64Triples), end(PPC64Triples));
2245  BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
2246  BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples));
2247  break;
2248  case llvm::Triple::ppc64le:
2249  LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs));
2250  TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples));
2251  break;
2252  case llvm::Triple::riscv32:
2253  LibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
2254  TripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
2255  BiarchLibDirs.append(begin(RISCV64LibDirs), end(RISCV64LibDirs));
2256  BiarchTripleAliases.append(begin(RISCV64Triples), end(RISCV64Triples));
2257  break;
2258  case llvm::Triple::riscv64:
2259  LibDirs.append(begin(RISCV64LibDirs), end(RISCV64LibDirs));
2260  TripleAliases.append(begin(RISCV64Triples), end(RISCV64Triples));
2261  BiarchLibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
2262  BiarchTripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
2263  break;
2264  case llvm::Triple::sparc:
2265  case llvm::Triple::sparcel:
2266  LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
2267  TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples));
2268  BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs));
2269  BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples));
2270  break;
2271  case llvm::Triple::sparcv9:
2272  LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs));
2273  TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples));
2274  BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
2275  BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples));
2276  break;
2277  case llvm::Triple::systemz:
2278  LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs));
2279  TripleAliases.append(begin(SystemZTriples), end(SystemZTriples));
2280  break;
2281  default:
2282  // By default, just rely on the standard lib directories and the original
2283  // triple.
2284  break;
2285  }
2286 
2287  // Always append the drivers target triple to the end, in case it doesn't
2288  // match any of our aliases.
2289  TripleAliases.push_back(TargetTriple.str());
2290 
2291  // Also include the multiarch variant if it's different.
2292  if (TargetTriple.str() != BiarchTriple.str())
2293  BiarchTripleAliases.push_back(BiarchTriple.str());
2294 }
2295 
2296 bool Generic_GCC::GCCInstallationDetector::ScanGCCForMultilibs(
2297  const llvm::Triple &TargetTriple, const ArgList &Args,
2298  StringRef Path, bool NeedsBiarchSuffix) {
2299  llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
2300  DetectedMultilibs Detected;
2301 
2302  // Android standalone toolchain could have multilibs for ARM and Thumb.
2303  // Debian mips multilibs behave more like the rest of the biarch ones,
2304  // so handle them there
2305  if (isArmOrThumbArch(TargetArch) && TargetTriple.isAndroid()) {
2306  // It should also work without multilibs in a simplified toolchain.
2307  findAndroidArmMultilibs(D, TargetTriple, Path, Args, Detected);
2308  } else if (TargetTriple.isMIPS()) {
2309  if (!findMIPSMultilibs(D, TargetTriple, Path, Args, Detected))
2310  return false;
2311  } else if (TargetTriple.isRISCV()) {
2312  findRISCVMultilibs(D, TargetTriple, Path, Args, Detected);
2313  } else if (isMSP430(TargetArch)) {
2314  findMSP430Multilibs(D, TargetTriple, Path, Args, Detected);
2315  } else if (TargetArch == llvm::Triple::avr) {
2316  // AVR has no multilibs.
2317  } else if (!findBiarchMultilibs(D, TargetTriple, Path, Args,
2318  NeedsBiarchSuffix, Detected)) {
2319  return false;
2320  }
2321 
2322  Multilibs = Detected.Multilibs;
2323  SelectedMultilib = Detected.SelectedMultilib;
2324  BiarchSibling = Detected.BiarchSibling;
2325 
2326  return true;
2327 }
2328 
2329 void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
2330  const llvm::Triple &TargetTriple, const ArgList &Args,
2331  const std::string &LibDir, StringRef CandidateTriple,
2332  bool NeedsBiarchSuffix) {
2333  llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
2334  // Locations relative to the system lib directory where GCC's triple-specific
2335  // directories might reside.
2336  struct GCCLibSuffix {
2337  // Path from system lib directory to GCC triple-specific directory.
2338  std::string LibSuffix;
2339  // Path from GCC triple-specific directory back to system lib directory.
2340  // This is one '..' component per component in LibSuffix.
2341  StringRef ReversePath;
2342  // Whether this library suffix is relevant for the triple.
2343  bool Active;
2344  } Suffixes[] = {
2345  // This is the normal place.
2346  {"gcc/" + CandidateTriple.str(), "../..", true},
2347 
2348  // Debian puts cross-compilers in gcc-cross.
2349  {"gcc-cross/" + CandidateTriple.str(), "../..",
2350  TargetTriple.getOS() != llvm::Triple::Solaris},
2351 
2352  // The Freescale PPC SDK has the gcc libraries in
2353  // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. Only do
2354  // this on Freescale triples, though, since some systems put a *lot* of
2355  // files in that location, not just GCC installation data.
2356  {CandidateTriple.str(), "..",
2357  TargetTriple.getVendor() == llvm::Triple::Freescale ||
2358  TargetTriple.getVendor() == llvm::Triple::OpenEmbedded},
2359 
2360  // Natively multiarch systems sometimes put the GCC triple-specific
2361  // directory within their multiarch lib directory, resulting in the
2362  // triple appearing twice.
2363  {CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), "../../..",
2364  TargetTriple.getOS() != llvm::Triple::Solaris},
2365 
2366  // Deal with cases (on Ubuntu) where the system architecture could be i386
2367  // but the GCC target architecture could be (say) i686.
2368  // FIXME: It may be worthwhile to generalize this and look for a second
2369  // triple.
2370  {"i386-linux-gnu/gcc/" + CandidateTriple.str(), "../../..",
2371  (TargetArch == llvm::Triple::x86 &&
2372  TargetTriple.getOS() != llvm::Triple::Solaris)},
2373  {"i386-gnu/gcc/" + CandidateTriple.str(), "../../..",
2374  (TargetArch == llvm::Triple::x86 &&
2375  TargetTriple.getOS() != llvm::Triple::Solaris)}};
2376 
2377  for (auto &Suffix : Suffixes) {
2378  if (!Suffix.Active)
2379  continue;
2380 
2381  StringRef LibSuffix = Suffix.LibSuffix;
2382  std::error_code EC;
2383  for (llvm::vfs::directory_iterator
2384  LI = D.getVFS().dir_begin(LibDir + "/" + LibSuffix, EC),
2385  LE;
2386  !EC && LI != LE; LI = LI.increment(EC)) {
2387  StringRef VersionText = llvm::sys::path::filename(LI->path());
2388  GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
2389  if (CandidateVersion.Major != -1) // Filter obviously bad entries.
2390  if (!CandidateGCCInstallPaths.insert(LI->path()).second)
2391  continue; // Saw this path before; no need to look at it again.
2392  if (CandidateVersion.isOlderThan(4, 1, 1))
2393  continue;
2394  if (CandidateVersion <= Version)
2395  continue;
2396 
2397  if (!ScanGCCForMultilibs(TargetTriple, Args, LI->path(),
2398  NeedsBiarchSuffix))
2399  continue;
2400 
2401  Version = CandidateVersion;
2402  GCCTriple.setTriple(CandidateTriple);
2403  // FIXME: We hack together the directory name here instead of
2404  // using LI to ensure stable path separators across Windows and
2405  // Linux.
2406  GCCInstallPath = (LibDir + "/" + LibSuffix + "/" + VersionText).str();
2407  GCCParentLibPath = (GCCInstallPath + "/../" + Suffix.ReversePath).str();
2408  IsValid = true;
2409  }
2410  }
2411 }
2412 
2413 bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
2414  const llvm::Triple &TargetTriple, const ArgList &Args,
2415  const SmallVectorImpl<StringRef> &CandidateTriples,
2416  const SmallVectorImpl<StringRef> &CandidateBiarchTriples) {
2417  for (StringRef CandidateTriple : CandidateTriples) {
2418  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
2419  return true;
2420  }
2421 
2422  for (StringRef CandidateTriple : CandidateBiarchTriples) {
2423  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
2424  return true;
2425  }
2426  return false;
2427 }
2428 
2429 bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
2430  const llvm::Triple &TargetTriple, const ArgList &Args,
2431  StringRef CandidateTriple, bool NeedsBiarchSuffix) {
2432  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
2433  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
2434  CandidateTriple.str());
2435  if (File) {
2437  File.get()->getBuffer().split(Lines, "\n");
2438  for (StringRef Line : Lines) {
2439  Line = Line.trim();
2440  // CURRENT=triple-version
2441  if (!Line.consume_front("CURRENT="))
2442  continue;
2443  // Process the config file pointed to by CURRENT.
2444  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ConfigFile =
2445  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/" +
2446  Line.str());
2447  std::pair<StringRef, StringRef> ActiveVersion = Line.rsplit('-');
2448  // List of paths to scan for libraries.
2449  SmallVector<StringRef, 4> GentooScanPaths;
2450  // Scan the Config file to find installed GCC libraries path.
2451  // Typical content of the GCC config file:
2452  // LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x:/usr/lib/gcc/
2453  // (continued from previous line) x86_64-pc-linux-gnu/4.9.x/32"
2454  // MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.x/man"
2455  // INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.x/info"
2456  // STDCXX_INCDIR="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4"
2457  // We are looking for the paths listed in LDPATH=... .
2458  if (ConfigFile) {
2459  SmallVector<StringRef, 2> ConfigLines;
2460  ConfigFile.get()->getBuffer().split(ConfigLines, "\n");
2461  for (StringRef ConfLine : ConfigLines) {
2462  ConfLine = ConfLine.trim();
2463  if (ConfLine.consume_front("LDPATH=")) {
2464  // Drop '"' from front and back if present.
2465  ConfLine.consume_back("\"");
2466  ConfLine.consume_front("\"");
2467  // Get all paths sperated by ':'
2468  ConfLine.split(GentooScanPaths, ':', -1, /*AllowEmpty*/ false);
2469  }
2470  }
2471  }
2472  // Test the path based on the version in /etc/env.d/gcc/config-{tuple}.
2473  std::string basePath = "/usr/lib/gcc/" + ActiveVersion.first.str() + "/"
2474  + ActiveVersion.second.str();
2475  GentooScanPaths.push_back(StringRef(basePath));
2476 
2477  // Scan all paths for GCC libraries.
2478  for (const auto &GentooScanPath : GentooScanPaths) {
2479  std::string GentooPath = D.SysRoot + std::string(GentooScanPath);
2480  if (D.getVFS().exists(GentooPath + "/crtbegin.o")) {
2481  if (!ScanGCCForMultilibs(TargetTriple, Args, GentooPath,
2482  NeedsBiarchSuffix))
2483  continue;
2484 
2485  Version = GCCVersion::Parse(ActiveVersion.second);
2486  GCCInstallPath = GentooPath;
2487  GCCParentLibPath = GentooPath + std::string("/../../..");
2488  GCCTriple.setTriple(ActiveVersion.first);
2489  IsValid = true;
2490  return true;
2491  }
2492  }
2493  }
2494  }
2495 
2496  return false;
2497 }
2498 
2499 Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
2500  const ArgList &Args)
2501  : ToolChain(D, Triple, Args), GCCInstallation(D),
2502  CudaInstallation(D, Triple, Args) {
2503  getProgramPaths().push_back(getDriver().getInstalledDir());
2504  if (getDriver().getInstalledDir() != getDriver().Dir)
2505  getProgramPaths().push_back(getDriver().Dir);
2506 }
2507 
2509 
2511  switch (AC) {
2513  if (!Preprocess)
2514  Preprocess.reset(new clang::driver::tools::gcc::Preprocessor(*this));
2515  return Preprocess.get();
2517  if (!Compile)
2518  Compile.reset(new tools::gcc::Compiler(*this));
2519  return Compile.get();
2520  default:
2521  return ToolChain::getTool(AC);
2522  }
2523 }
2524 
2526  return new tools::gnutools::Assembler(*this);
2527 }
2528 
2529 Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); }
2530 
2531 void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
2532  // Print the information about how we detected the GCC installation.
2533  GCCInstallation.print(OS);
2534  CudaInstallation.print(OS);
2535 }
2536 
2537 bool Generic_GCC::IsUnwindTablesDefault(const ArgList &Args) const {
2538  return getArch() == llvm::Triple::x86_64;
2539 }
2540 
2542  switch (getArch()) {
2543  case llvm::Triple::x86_64:
2544  return getTriple().isOSWindows();
2545  case llvm::Triple::ppc64:
2546  // Big endian PPC is PIC by default
2547  return !getTriple().isOSBinFormatMachO() && !getTriple().isMacOSX();
2548  case llvm::Triple::mips64:
2549  case llvm::Triple::mips64el:
2550  return true;
2551  default:
2552  return false;
2553  }
2554 }
2555 
2556 bool Generic_GCC::isPIEDefault() const { return false; }
2557 
2559  return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows();
2560 }
2561 
2563  switch (getTriple().getArch()) {
2564  case llvm::Triple::x86:
2565  case llvm::Triple::x86_64:
2566  case llvm::Triple::aarch64:
2567  case llvm::Triple::aarch64_be:
2568  case llvm::Triple::arm:
2569  case llvm::Triple::armeb:
2570  case llvm::Triple::avr:
2571  case llvm::Triple::bpfel:
2572  case llvm::Triple::bpfeb:
2573  case llvm::Triple::thumb:
2574  case llvm::Triple::thumbeb:
2575  case llvm::Triple::ppc:
2576  case llvm::Triple::ppc64:
2577  case llvm::Triple::ppc64le:
2578  case llvm::Triple::riscv32:
2579  case llvm::Triple::riscv64:
2580  case llvm::Triple::systemz:
2581  case llvm::Triple::mips:
2582  case llvm::Triple::mipsel:
2583  case llvm::Triple::mips64:
2584  case llvm::Triple::mips64el:
2585  case llvm::Triple::msp430:
2586  return true;
2587  case llvm::Triple::sparc:
2588  case llvm::Triple::sparcel:
2589  case llvm::Triple::sparcv9:
2590  if (getTriple().isOSFreeBSD() || getTriple().isOSOpenBSD() ||
2591  getTriple().isOSSolaris())
2592  return true;
2593  return false;
2594  default:
2595  return false;
2596  }
2597 }
2598 
2599 void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
2600  ArgStringList &CC1Args) const {
2601  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
2602  DriverArgs.hasArg(options::OPT_nostdincxx))
2603  return;
2604 
2605  switch (GetCXXStdlibType(DriverArgs)) {
2606  case ToolChain::CST_Libcxx:
2607  addLibCxxIncludePaths(DriverArgs, CC1Args);
2608  break;
2609 
2611  addLibStdCxxIncludePaths(DriverArgs, CC1Args);
2612  break;
2613  }
2614 }
2615 
2616 void
2617 Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
2618  llvm::opt::ArgStringList &CC1Args) const {
2619  // FIXME: The Linux behavior would probaby be a better approach here.
2620  addSystemInclude(DriverArgs, CC1Args,
2621  getDriver().SysRoot + "/usr/include/c++/v1");
2622 }
2623 
2624 void
2625 Generic_GCC::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
2626  llvm::opt::ArgStringList &CC1Args) const {
2627  // By default, we don't assume we know where libstdc++ might be installed.
2628  // FIXME: If we have a valid GCCInstallation, use it.
2629 }
2630 
2631 /// Helper to add the variant paths of a libstdc++ installation.
2633  Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple,
2634  StringRef TargetMultiarchTriple, Twine IncludeSuffix,
2635  const ArgList &DriverArgs, ArgStringList &CC1Args) const {
2636  if (!getVFS().exists(Base + Suffix))
2637  return false;
2638 
2639  addSystemInclude(DriverArgs, CC1Args, Base + Suffix);
2640 
2641  // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If
2642  // that path exists or we have neither a GCC nor target multiarch triple, use
2643  // this vanilla search path.
2644  if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) ||
2645  getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) {
2646  addSystemInclude(DriverArgs, CC1Args,
2647  Base + Suffix + "/" + GCCTriple + IncludeSuffix);
2648  } else {
2649  // Otherwise try to use multiarch naming schemes which have normalized the
2650  // triples and put the triple before the suffix.
2651  //
2652  // GCC surprisingly uses *both* the GCC triple with a multilib suffix and
2653  // the target triple, so we support that here.
2654  addSystemInclude(DriverArgs, CC1Args,
2655  Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix);
2656  addSystemInclude(DriverArgs, CC1Args,
2657  Base + "/" + TargetMultiarchTriple + Suffix);
2658  }
2659 
2660  addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward");
2661  return true;
2662 }
2663 
2664 llvm::opt::DerivedArgList *
2665 Generic_GCC::TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef,
2666  Action::OffloadKind DeviceOffloadKind) const {
2667 
2668  // If this tool chain is used for an OpenMP offloading device we have to make
2669  // sure we always generate a shared library regardless of the commands the
2670  // user passed to the host. This is required because the runtime library
2671  // is required to load the device image dynamically at run time.
2672  if (DeviceOffloadKind == Action::OFK_OpenMP) {
2673  DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
2674  const OptTable &Opts = getDriver().getOpts();
2675 
2676  // Request the shared library. Given that these options are decided
2677  // implicitly, they do not refer to any base argument.
2678  DAL->AddFlagArg(/*BaseArg=*/nullptr, Opts.getOption(options::OPT_shared));
2679  DAL->AddFlagArg(/*BaseArg=*/nullptr, Opts.getOption(options::OPT_fPIC));
2680 
2681  // Filter all the arguments we don't care passing to the offloading
2682  // toolchain as they can mess up with the creation of a shared library.
2683  for (auto *A : Args) {
2684  switch ((options::ID)A->getOption().getID()) {
2685  default:
2686  DAL->append(A);
2687  break;
2688  case options::OPT_shared:
2689  case options::OPT_dynamic:
2690  case options::OPT_static:
2691  case options::OPT_fPIC:
2692  case options::OPT_fno_PIC:
2693  case options::OPT_fpic:
2694  case options::OPT_fno_pic:
2695  case options::OPT_fPIE:
2696  case options::OPT_fno_PIE:
2697  case options::OPT_fpie:
2698  case options::OPT_fno_pie:
2699  break;
2700  }
2701  }
2702  return DAL;
2703  }
2704  return nullptr;
2705 }
2706 
2707 void Generic_ELF::anchor() {}
2708 
2709 void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs,
2710  ArgStringList &CC1Args,
2711  Action::OffloadKind) const {
2713  bool UseInitArrayDefault =
2714  getTriple().getArch() == llvm::Triple::aarch64 ||
2715  getTriple().getArch() == llvm::Triple::aarch64_be ||
2716  (getTriple().isOSFreeBSD() &&
2717  getTriple().getOSMajorVersion() >= 12) ||
2718  (getTriple().getOS() == llvm::Triple::Linux &&
2719  ((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
2720  getTriple().isAndroid())) ||
2721  getTriple().getOS() == llvm::Triple::NaCl ||
2722  (getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
2723  !getTriple().hasEnvironment()) ||
2724  getTriple().getOS() == llvm::Triple::Solaris ||
2725  getTriple().getArch() == llvm::Triple::riscv32 ||
2726  getTriple().getArch() == llvm::Triple::riscv64;
2727 
2728  if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
2729  options::OPT_fno_use_init_array, UseInitArrayDefault))
2730  CC1Args.push_back("-fuse-init-array");
2731 }
const char * getPPCAsmModeForCPU(StringRef Name)
Definition: PPC.cpp:88
MultilibSet & Either(const Multilib &M1, const Multilib &M2)
Add a set of mutually incompatible Multilib segments.
Definition: Multilib.cpp:152
MultilibSet & Maybe(const Multilib &M)
Add an optional Multilib segment.
Definition: Multilib.cpp:142
bool IsStatic
Definition: Format.cpp:1722
bool isNoExecStackDefault() const override
Test whether this toolchaind defaults to non-executable stacks.
Definition: Linux.cpp:979
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: Linux.cpp:974
virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const
Definition: Linux.cpp:510
Tool * buildLinker() const override
Definition: Gnu.cpp:2529
bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
const char * getSystemZTargetCPU(const llvm::opt::ArgList &Args)
prefix_list PrefixDirs
Definition: Driver.h:144
const char * getSparcAsmModeForCPU(llvm::StringRef Name, const llvm::Triple &Triple)
static bool getPIE(const ArgList &Args, const toolchains::Linux &ToolChain)
Definition: Gnu.cpp:312
bool shouldUseFPXX(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, StringRef CPUName, StringRef ABIName, mips::FloatABI FloatABI)
bool isDefault() const
Check whether the default is selected.
Definition: Multilib.h:106
Tool * getTool(Action::ActionClass AC) const override
Definition: Gnu.cpp:2510
bool getBiarchSibling(Multilib &M) const
Get the biarch sibling multilib (if it exists).
Definition: Gnu.cpp:1865
static bool findMipsAndroidMultilibs(llvm::vfs::FileSystem &VFS, StringRef Path, const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:1035
llvm::Optional< Multilib > BiarchSibling
On Biarch systems, this corresponds to the default multilib when targeting the non-default multilib...
Definition: Gnu.h:29
StringRef P
bool isUsingLTO() const
Returns true if we are performing any kind of LTO.
Definition: Driver.h:530
static GCCVersion Parse(StringRef VersionText)
Parse a GCCVersion object out of a string of text.
Definition: Gnu.cpp:1686
std::string DyldPrefix
Dynamic loader prefix, if present.
Definition: Driver.h:150
bool canTypeBeUserSpecified(ID Id)
canTypeBeUserSpecified - Can this type be specified on the command line (by the type name); this is u...
Definition: Types.cpp:79
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
void AddHIPLinkerScript(const ToolChain &TC, Compilation &C, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA, const Tool &T)
bool isHostOffloading(OffloadKind OKind) const
Check if this action have any offload kinds.
Definition: Action.h:201
LTOKind getLTOMode() const
Get the specific kind of LTO being performed.
Definition: Driver.h:533
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:108
Struct to store and manipulate GCC versions.
Definition: Gnu.h:156
void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const override
RenderExtraToolArgs - Render any arguments necessary to force the particular tool mode...
Definition: Gnu.cpp:228
std::string GetLinkerPath() const
Returns the linker path, respecting the -fuse-ld= argument to determine the linker suffix or name...
Definition: ToolChain.cpp:492
FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args)
std::string PatchSuffix
Any textual suffix on the patch number.
Definition: Gnu.h:167
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: Gnu.cpp:2556
bool select(const Multilib::flags_list &Flags, Multilib &M) const
Pick the best multilib in the set,.
Definition: Multilib.cpp:244
void print(raw_ostream &OS) const
Print information about the detected CUDA installation.
Definition: Cuda.cpp:275
Multilib & flag(StringRef F)
Add a flag to the flags list Flag must be a flag accepted by the driver with its leading &#39;-&#39; removed...
Definition: Multilib.h:92
std::string getCPUName(const llvm::opt::ArgList &Args, const llvm::Triple &T, bool FromAs=false)
void print(raw_ostream &OS) const
Print information about the detected GCC installation.
Definition: Gnu.cpp:1851
const char * getFilename() const
Definition: InputInfo.h:83
void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const override
RenderExtraToolArgs - Render any arguments necessary to force the particular tool mode...
Definition: Gnu.cpp:195
GCCInstallationDetector GCCInstallation
Definition: Gnu.h:279
path_list & getProgramPaths()
Definition: ToolChain.h:234
static Multilib makeMultilib(StringRef commonSuffix)
Definition: Gnu.cpp:940
void linkSanitizerRuntimeDeps(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
const std::string & includeSuffix() const
Get the include directory suffix.
Definition: Multilib.h:67
void AddGoldPlugin(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output, const InputInfo &Input, bool IsThinLTO)
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant.
Definition: Multilib.h:45
bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
bool isNaN2008(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
void addMultilibFlag(bool Enabled, const char *const Flag, Multilib::flags_list &Flags)
Flag must be a flag accepted by the driver with its leading &#39;-&#39; removed,
const std::string & osSuffix() const
Get the detected os path suffix for the multi-arch target variant.
Definition: Multilib.h:56
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
static bool isMipsEL(llvm::Triple::ArchType Arch)
Definition: Gnu.cpp:922
MultilibSet & setIncludeDirsCallback(IncludeDirsFunc F)
Definition: Multilib.h:174
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:484
types::ID getType() const
Definition: Action.h:140
virtual bool AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFastMathRuntimeIfAvailable - If a runtime library exists that sets global flags for unsafe floatin...
Definition: ToolChain.cpp:870
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:57
bool hasMipsAbiArg(const llvm::opt::ArgList &Args, const char *Value)
const char * SplitDebugName(const llvm::opt::ArgList &Args, const InputInfo &Input, const InputInfo &Output)
void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const override
RenderExtraToolArgs - Render any arguments necessary to force the particular tool mode...
Definition: Gnu.cpp:200
bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC, const llvm::opt::ArgList &Args, bool IsOffloadingHost=false, bool GompNeedsRT=false)
Returns true, if an OpenMP runtime has been added.
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Gnu.cpp:344
void AddOpenMPLinkerScript(const ToolChain &TC, Compilation &C, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:299
const GCCVersion & getVersion() const
Get the detected GCC version string.
Definition: Gnu.h:238
void linkXRayRuntimeDeps(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
static bool isMips16(const ArgList &Args)
Definition: Gnu.cpp:926
StringRef getRISCVABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
CudaInstallationDetector CudaInstallation
Definition: Gnu.h:280
static bool isSoftFloatABI(const ArgList &Args)
Definition: Gnu.cpp:907
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: Gnu.cpp:2599
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
Definition: Types.cpp:38
const AnnotatedLine * Line
static bool findMipsMuslMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:1074
static void normalizeCPUNamesForAssembler(const ArgList &Args, ArgStringList &CmdArgs)
Definition: Gnu.cpp:51
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: Gnu.cpp:2541
#define V(N, I)
Definition: ASTContext.h:2907
std::vector< std::string > flags_list
Definition: Multilib.h:30
void push_back(const Multilib &M)
Add a completed Multilib to the set.
Definition: Multilib.cpp:232
unsigned size() const
Definition: Multilib.h:169
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:205
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag...
Definition: Multilib.h:28
static bool findMipsMtiMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:1106
Tool * buildAssembler() const override
Definition: Gnu.cpp:2525
std::tuple< llvm::Reloc::Model, unsigned, bool > ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args)
static bool forwardToGCC(const Option &O)
Definition: Gnu.cpp:41
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override
IsUnwindTablesDefault - Does this tool chain use -funwind-tables by default.
Definition: Gnu.cpp:2537
static const char * getLDMOption(const llvm::Triple &T, const ArgList &Args)
Definition: Gnu.cpp:257
void AddAssemblerKPIC(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:209
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:364
void printVerboseInfo(raw_ostream &OS) const override
Dispatch to the specific toolchain for verbose printing.
Definition: Gnu.cpp:2531
static bool findMipsImgMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:1278
void AddFilePathLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
Definition: ToolChain.cpp:858
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Gnu.cpp:64
static llvm::StringRef getGCCToolchainDir(const ArgList &Args, llvm::StringRef SysRoot)
Definition: Gnu.cpp:1733
mips::FloatABI getMipsFloatABI(const Driver &D, const llvm::opt::ArgList &Args)
const Driver & getDriver() const
Definition: ToolChain.h:193
virtual void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Gnu.cpp:2617
std::string InstalledDir
The path to the installed clang directory, if any.
Definition: Driver.h:128
bool isUCLibc(const llvm::opt::ArgList &Args)
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:172
static bool findMSP430Multilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
Definition: Gnu.cpp:1485
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:782
void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T, const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Output, const char *OutFile)
static bool isArmOrThumbArch(llvm::Triple::ArchType Arch)
Definition: Gnu.cpp:918
virtual RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:717
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:97
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Gnu.cpp:633
bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch, StringRef RHSPatchSuffix=StringRef()) const
Generic_GCC - A tool chain using the &#39;gcc&#39; command to perform all subcommands; this relies on gcc tra...
Definition: Gnu.cpp:1649
static bool findBiarchMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, bool NeedsBiarchSuffix, DetectedMultilibs &Result)
Definition: Gnu.cpp:1540
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: Gnu.cpp:2558
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
Definition: ToolChain.cpp:835
Dataflow Directional Tag Classes.
Generic_GCC(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: Gnu.cpp:2499
static bool isMSP430(llvm::Triple::ArchType Arch)
Definition: Gnu.cpp:936
const std::string & getCCCGenericGCCName() const
Name to use when invoking gcc/g++.
Definition: Driver.h:291
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
std::string SysRoot
sysroot, if present
Definition: Driver.h:147
Tool - Information on a specific compilation tool.
Definition: Tool.h:33
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: Gnu.cpp:2709
static bool findMipsCsMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:944
bool IsIntegratedAssemblerDefault() const override
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: Gnu.cpp:2562
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
std::string MajorStr
The text of the parsed major, and major+minor versions.
Definition: Gnu.h:164
static bool isArmBigEndian(const llvm::Triple &Triple, const ArgList &Args)
Definition: Gnu.cpp:237
llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: Gnu.cpp:2665
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
const llvm::Triple & getTriple() const
Definition: ToolChain.h:195
virtual void addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Gnu.cpp:2625
virtual Tool * getTool(Action::ActionClass AC) const
Definition: ToolChain.cpp:288
bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const llvm::opt::ArgList &Args, DetectedMultilibs &Result)
void appendBE8LinkFlag(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple)
StringRef getGnuCompatibleMipsABIName(StringRef ABI)
Definition: Mips.cpp:143
bool isNothing() const
Definition: InputInfo.h:74
MultilibSet & FilterOut(FilterCallback F)
Filter out some subset of the Multilibs using a user defined callback.
Definition: Multilib.cpp:212
bool isFilename() const
Definition: InputInfo.h:75
static bool getStatic(const ArgList &Args)
Definition: Gnu.cpp:339
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:295
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:763
static constexpr CPUSuffix Suffixes[]
Definition: Hexagon.cpp:147
bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, StringRef TargetMultiarchTriple, Twine IncludeSuffix, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Helper to add the variant paths of a libstdc++ installation.
Definition: Gnu.cpp:2632
void init(const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args, ArrayRef< std::string > ExtraTripleAliases=None)
Initialize a GCCInstallationDetector from the driver.
Definition: Gnu.cpp:1757
void getMipsCPUAndABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, StringRef &CPUName, StringRef &ABIName)
MultilibSet Multilibs
The set of multilibs that the detected installation supports.
Definition: Gnu.h:22
std::vector< std::string > ExtraOpts
Definition: Linux.h:50
static bool isMicroMips(const ArgList &Args)
Definition: Gnu.cpp:931
bool isLLVMIR(ID Id)
Is this LLVM IR.
Definition: Types.cpp:153
int Major
The parsed major, minor, and patch numbers.
Definition: Gnu.h:161
static void findAndroidArmMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
Definition: Gnu.cpp:1443
static void findRISCVMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
Definition: Gnu.cpp:1505
virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
Definition: ToolChain.cpp:841
Multilib SelectedMultilib
The primary multilib appropriate for the given flags.
Definition: Gnu.h:25
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88
static bool getStaticPIE(const ArgList &Args, const toolchains::Linux &ToolChain)
Definition: Gnu.cpp:324
bool isValid() const
Check whether we detected a valid GCC install.
Definition: Gnu.h:216