clang  10.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(std::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  // Use the static OpenMP runtime with -static-openmp
559  bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
560  !Args.hasArg(options::OPT_static);
561 
562  // FIXME: Only pass GompNeedsRT = true for platforms with libgomp that
563  // require librt. Most modern Linux platforms do, but some may not.
564  if (addOpenMPRuntime(CmdArgs, ToolChain, Args, StaticOpenMP,
566  /* GompNeedsRT= */ true))
567  // OpenMP runtimes implies pthreads when using the GNU toolchain.
568  // FIXME: Does this really make sense for all GNU toolchains?
569  WantPthread = true;
570 
571  AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
572 
573  if (WantPthread && !isAndroid)
574  CmdArgs.push_back("-lpthread");
575 
576  if (Args.hasArg(options::OPT_fsplit_stack))
577  CmdArgs.push_back("--wrap=pthread_create");
578 
579  if (!Args.hasArg(options::OPT_nolibc))
580  CmdArgs.push_back("-lc");
581 
582  // Add IAMCU specific libs, if needed.
583  if (IsIAMCU)
584  CmdArgs.push_back("-lgloss");
585 
586  if (IsStatic || IsStaticPIE)
587  CmdArgs.push_back("--end-group");
588  else
589  AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
590 
591  // Add IAMCU specific libs (outside the group), if needed.
592  if (IsIAMCU) {
593  CmdArgs.push_back("--as-needed");
594  CmdArgs.push_back("-lsoftfp");
595  CmdArgs.push_back("--no-as-needed");
596  }
597  }
598 
599  if (!Args.hasArg(options::OPT_nostartfiles) && !IsIAMCU) {
600  if (HasCRTBeginEndFiles) {
601  std::string P;
602  if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT &&
603  !isAndroid) {
604  std::string crtend = ToolChain.getCompilerRT(Args, "crtend",
606  if (ToolChain.getVFS().exists(crtend))
607  P = crtend;
608  }
609  if (P.empty()) {
610  const char *crtend;
611  if (Args.hasArg(options::OPT_shared))
612  crtend = isAndroid ? "crtend_so.o" : "crtendS.o";
613  else if (IsPIE || IsStaticPIE)
614  crtend = isAndroid ? "crtend_android.o" : "crtendS.o";
615  else
616  crtend = isAndroid ? "crtend_android.o" : "crtend.o";
617  P = ToolChain.GetFilePath(crtend);
618  }
619  CmdArgs.push_back(Args.MakeArgString(P));
620  }
621  if (!isAndroid)
622  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
623  }
624  }
625 
626  // Add OpenMP offloading linker script args if required.
627  AddOpenMPLinkerScript(getToolChain(), C, Output, Inputs, Args, CmdArgs, JA);
628 
629  // Add HIP offloading linker script args if required.
630  AddHIPLinkerScript(getToolChain(), C, Output, Inputs, Args, CmdArgs, JA,
631  *this);
632 
633  const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
634  C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
635 }
636 
638  const JobAction &JA,
639  const InputInfo &Output,
640  const InputInfoList &Inputs,
641  const ArgList &Args,
642  const char *LinkingOutput) const {
643  const auto &D = getToolChain().getDriver();
644 
645  claimNoWarnArgs(Args);
646 
647  ArgStringList CmdArgs;
648 
649  llvm::Reloc::Model RelocationModel;
650  unsigned PICLevel;
651  bool IsPIE;
652  std::tie(RelocationModel, PICLevel, IsPIE) =
653  ParsePICArgs(getToolChain(), Args);
654 
655  if (const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ)) {
656  if (A->getOption().getID() == options::OPT_gz) {
657  CmdArgs.push_back("--compress-debug-sections");
658  } else {
659  StringRef Value = A->getValue();
660  if (Value == "none" || Value == "zlib" || Value == "zlib-gnu") {
661  CmdArgs.push_back(
662  Args.MakeArgString("--compress-debug-sections=" + Twine(Value)));
663  } else {
664  D.Diag(diag::err_drv_unsupported_option_argument)
665  << A->getOption().getName() << Value;
666  }
667  }
668  }
669 
670  if (getToolChain().isNoExecStackDefault()) {
671  CmdArgs.push_back("--noexecstack");
672  }
673 
674  switch (getToolChain().getArch()) {
675  default:
676  break;
677  // Add --32/--64 to make sure we get the format we want.
678  // This is incomplete
679  case llvm::Triple::x86:
680  CmdArgs.push_back("--32");
681  break;
682  case llvm::Triple::x86_64:
683  if (getToolChain().getTriple().getEnvironment() == llvm::Triple::GNUX32)
684  CmdArgs.push_back("--x32");
685  else
686  CmdArgs.push_back("--64");
687  break;
688  case llvm::Triple::ppc: {
689  CmdArgs.push_back("-a32");
690  CmdArgs.push_back("-mppc");
691  CmdArgs.push_back(
692  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
693  break;
694  }
695  case llvm::Triple::ppc64: {
696  CmdArgs.push_back("-a64");
697  CmdArgs.push_back("-mppc64");
698  CmdArgs.push_back(
699  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
700  break;
701  }
702  case llvm::Triple::ppc64le: {
703  CmdArgs.push_back("-a64");
704  CmdArgs.push_back("-mppc64");
705  CmdArgs.push_back("-mlittle-endian");
706  CmdArgs.push_back(
707  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
708  break;
709  }
710  case llvm::Triple::riscv32:
711  case llvm::Triple::riscv64: {
712  StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
713  CmdArgs.push_back("-mabi");
714  CmdArgs.push_back(ABIName.data());
715  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
716  StringRef MArch = A->getValue();
717  CmdArgs.push_back("-march");
718  CmdArgs.push_back(MArch.data());
719  }
720  break;
721  }
722  case llvm::Triple::sparc:
723  case llvm::Triple::sparcel: {
724  CmdArgs.push_back("-32");
725  std::string CPU = getCPUName(Args, getToolChain().getTriple());
726  CmdArgs.push_back(
727  sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
728  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
729  break;
730  }
731  case llvm::Triple::sparcv9: {
732  CmdArgs.push_back("-64");
733  std::string CPU = getCPUName(Args, getToolChain().getTriple());
734  CmdArgs.push_back(
735  sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
736  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
737  break;
738  }
739  case llvm::Triple::arm:
740  case llvm::Triple::armeb:
741  case llvm::Triple::thumb:
742  case llvm::Triple::thumbeb: {
743  const llvm::Triple &Triple2 = getToolChain().getTriple();
744  CmdArgs.push_back(isArmBigEndian(Triple2, Args) ? "-EB" : "-EL");
745  switch (Triple2.getSubArch()) {
746  case llvm::Triple::ARMSubArch_v7:
747  CmdArgs.push_back("-mfpu=neon");
748  break;
749  case llvm::Triple::ARMSubArch_v8:
750  CmdArgs.push_back("-mfpu=crypto-neon-fp-armv8");
751  break;
752  default:
753  break;
754  }
755 
756  switch (arm::getARMFloatABI(getToolChain(), Args)) {
757  case arm::FloatABI::Invalid: llvm_unreachable("must have an ABI!");
758  case arm::FloatABI::Soft:
759  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=soft"));
760  break;
761  case arm::FloatABI::SoftFP:
762  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=softfp"));
763  break;
764  case arm::FloatABI::Hard:
765  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=hard"));
766  break;
767  }
768 
769  Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
770  normalizeCPUNamesForAssembler(Args, CmdArgs);
771 
772  Args.AddLastArg(CmdArgs, options::OPT_mfpu_EQ);
773  break;
774  }
775  case llvm::Triple::aarch64:
776  case llvm::Triple::aarch64_be: {
777  CmdArgs.push_back(
778  getToolChain().getArch() == llvm::Triple::aarch64_be ? "-EB" : "-EL");
779  Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
780  normalizeCPUNamesForAssembler(Args, CmdArgs);
781 
782  break;
783  }
784  case llvm::Triple::mips:
785  case llvm::Triple::mipsel:
786  case llvm::Triple::mips64:
787  case llvm::Triple::mips64el: {
788  StringRef CPUName;
789  StringRef ABIName;
790  mips::getMipsCPUAndABI(Args, getToolChain().getTriple(), CPUName, ABIName);
791  ABIName = mips::getGnuCompatibleMipsABIName(ABIName);
792 
793  CmdArgs.push_back("-march");
794  CmdArgs.push_back(CPUName.data());
795 
796  CmdArgs.push_back("-mabi");
797  CmdArgs.push_back(ABIName.data());
798 
799  // -mno-shared should be emitted unless -fpic, -fpie, -fPIC, -fPIE,
800  // or -mshared (not implemented) is in effect.
801  if (RelocationModel == llvm::Reloc::Static)
802  CmdArgs.push_back("-mno-shared");
803 
804  // LLVM doesn't support -mplt yet and acts as if it is always given.
805  // However, -mplt has no effect with the N64 ABI.
806  if (ABIName != "64" && !Args.hasArg(options::OPT_mno_abicalls))
807  CmdArgs.push_back("-call_nonpic");
808 
809  if (getToolChain().getTriple().isLittleEndian())
810  CmdArgs.push_back("-EL");
811  else
812  CmdArgs.push_back("-EB");
813 
814  if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
815  if (StringRef(A->getValue()) == "2008")
816  CmdArgs.push_back(Args.MakeArgString("-mnan=2008"));
817  }
818 
819  // Add the last -mfp32/-mfpxx/-mfp64 or -mfpxx if it is enabled by default.
820  if (Arg *A = Args.getLastArg(options::OPT_mfp32, options::OPT_mfpxx,
821  options::OPT_mfp64)) {
822  A->claim();
823  A->render(Args, CmdArgs);
824  } else if (mips::shouldUseFPXX(
825  Args, getToolChain().getTriple(), CPUName, ABIName,
826  mips::getMipsFloatABI(getToolChain().getDriver(), Args)))
827  CmdArgs.push_back("-mfpxx");
828 
829  // Pass on -mmips16 or -mno-mips16. However, the assembler equivalent of
830  // -mno-mips16 is actually -no-mips16.
831  if (Arg *A =
832  Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16)) {
833  if (A->getOption().matches(options::OPT_mips16)) {
834  A->claim();
835  A->render(Args, CmdArgs);
836  } else {
837  A->claim();
838  CmdArgs.push_back("-no-mips16");
839  }
840  }
841 
842  Args.AddLastArg(CmdArgs, options::OPT_mmicromips,
843  options::OPT_mno_micromips);
844  Args.AddLastArg(CmdArgs, options::OPT_mdsp, options::OPT_mno_dsp);
845  Args.AddLastArg(CmdArgs, options::OPT_mdspr2, options::OPT_mno_dspr2);
846 
847  if (Arg *A = Args.getLastArg(options::OPT_mmsa, options::OPT_mno_msa)) {
848  // Do not use AddLastArg because not all versions of MIPS assembler
849  // support -mmsa / -mno-msa options.
850  if (A->getOption().matches(options::OPT_mmsa))
851  CmdArgs.push_back(Args.MakeArgString("-mmsa"));
852  }
853 
854  Args.AddLastArg(CmdArgs, options::OPT_mhard_float,
855  options::OPT_msoft_float);
856 
857  Args.AddLastArg(CmdArgs, options::OPT_mdouble_float,
858  options::OPT_msingle_float);
859 
860  Args.AddLastArg(CmdArgs, options::OPT_modd_spreg,
861  options::OPT_mno_odd_spreg);
862 
863  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
864  break;
865  }
866  case llvm::Triple::systemz: {
867  // Always pass an -march option, since our default of z10 is later
868  // than the GNU assembler's default.
869  StringRef CPUName = systemz::getSystemZTargetCPU(Args);
870  CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName));
871  break;
872  }
873  }
874 
875  Args.AddAllArgs(CmdArgs, options::OPT_I);
876  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
877 
878  CmdArgs.push_back("-o");
879  CmdArgs.push_back(Output.getFilename());
880 
881  for (const auto &II : Inputs)
882  CmdArgs.push_back(II.getFilename());
883 
884  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
885  C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
886 
887  // Handle the debug info splitting at object creation time if we're
888  // creating an object.
889  // TODO: Currently only works on linux with newer objcopy.
890  if (Args.hasArg(options::OPT_gsplit_dwarf) &&
891  getToolChain().getTriple().isOSLinux())
892  SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
893  SplitDebugName(Args, Inputs[0], Output));
894 }
895 
896 namespace {
897 // Filter to remove Multilibs that don't exist as a suffix to Path
898 class FilterNonExistent {
899  StringRef Base, File;
900  llvm::vfs::FileSystem &VFS;
901 
902 public:
903  FilterNonExistent(StringRef Base, StringRef File, llvm::vfs::FileSystem &VFS)
904  : Base(Base), File(File), VFS(VFS) {}
905  bool operator()(const Multilib &M) {
906  return !VFS.exists(Base + M.gccSuffix() + File);
907  }
908 };
909 } // end anonymous namespace
910 
911 static bool isSoftFloatABI(const ArgList &Args) {
912  Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
913  options::OPT_mfloat_abi_EQ);
914  if (!A)
915  return false;
916 
917  return A->getOption().matches(options::OPT_msoft_float) ||
918  (A->getOption().matches(options::OPT_mfloat_abi_EQ) &&
919  A->getValue() == StringRef("soft"));
920 }
921 
922 static bool isArmOrThumbArch(llvm::Triple::ArchType Arch) {
923  return Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb;
924 }
925 
926 static bool isMipsEL(llvm::Triple::ArchType Arch) {
927  return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el;
928 }
929 
930 static bool isMips16(const ArgList &Args) {
931  Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16);
932  return A && A->getOption().matches(options::OPT_mips16);
933 }
934 
935 static bool isMicroMips(const ArgList &Args) {
936  Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips);
937  return A && A->getOption().matches(options::OPT_mmicromips);
938 }
939 
940 static bool isMSP430(llvm::Triple::ArchType Arch) {
941  return Arch == llvm::Triple::msp430;
942 }
943 
944 static Multilib makeMultilib(StringRef commonSuffix) {
945  return Multilib(commonSuffix, commonSuffix, commonSuffix);
946 }
947 
948 static bool findMipsCsMultilibs(const Multilib::flags_list &Flags,
949  FilterNonExistent &NonExistent,
950  DetectedMultilibs &Result) {
951  // Check for Code Sourcery toolchain multilibs
952  MultilibSet CSMipsMultilibs;
953  {
954  auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16");
955 
956  auto MArchMicroMips =
957  makeMultilib("/micromips").flag("+m32").flag("+mmicromips");
958 
959  auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips");
960 
961  auto UCLibc = makeMultilib("/uclibc").flag("+muclibc");
962 
963  auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float");
964 
965  auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008");
966 
967  auto DefaultFloat =
968  makeMultilib("").flag("-msoft-float").flag("-mnan=2008");
969 
970  auto BigEndian = makeMultilib("").flag("+EB").flag("-EL");
971 
972  auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB");
973 
974  // Note that this one's osSuffix is ""
975  auto MAbi64 = makeMultilib("")
976  .gccSuffix("/64")
977  .includeSuffix("/64")
978  .flag("+mabi=n64")
979  .flag("-mabi=n32")
980  .flag("-m32");
981 
982  CSMipsMultilibs =
983  MultilibSet()
984  .Either(MArchMips16, MArchMicroMips, MArchDefault)
985  .Maybe(UCLibc)
986  .Either(SoftFloat, Nan2008, DefaultFloat)
987  .FilterOut("/micromips/nan2008")
988  .FilterOut("/mips16/nan2008")
989  .Either(BigEndian, LittleEndian)
990  .Maybe(MAbi64)
991  .FilterOut("/mips16.*/64")
992  .FilterOut("/micromips.*/64")
993  .FilterOut(NonExistent)
994  .setIncludeDirsCallback([](const Multilib &M) {
995  std::vector<std::string> Dirs({"/include"});
996  if (StringRef(M.includeSuffix()).startswith("/uclibc"))
997  Dirs.push_back(
998  "/../../../../mips-linux-gnu/libc/uclibc/usr/include");
999  else
1000  Dirs.push_back("/../../../../mips-linux-gnu/libc/usr/include");
1001  return Dirs;
1002  });
1003  }
1004 
1005  MultilibSet DebianMipsMultilibs;
1006  {
1007  Multilib MAbiN32 =
1008  Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32");
1009 
1010  Multilib M64 = Multilib()
1011  .gccSuffix("/64")
1012  .includeSuffix("/64")
1013  .flag("+m64")
1014  .flag("-m32")
1015  .flag("-mabi=n32");
1016 
1017  Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32");
1018 
1019  DebianMipsMultilibs =
1020  MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent);
1021  }
1022 
1023  // Sort candidates. Toolchain that best meets the directories tree goes first.
1024  // Then select the first toolchains matches command line flags.
1025  MultilibSet *Candidates[] = {&CSMipsMultilibs, &DebianMipsMultilibs};
1026  if (CSMipsMultilibs.size() < DebianMipsMultilibs.size())
1027  std::iter_swap(Candidates, Candidates + 1);
1028  for (const MultilibSet *Candidate : Candidates) {
1029  if (Candidate->select(Flags, Result.SelectedMultilib)) {
1030  if (Candidate == &DebianMipsMultilibs)
1031  Result.BiarchSibling = Multilib();
1032  Result.Multilibs = *Candidate;
1033  return true;
1034  }
1035  }
1036  return false;
1037 }
1038 
1039 static bool findMipsAndroidMultilibs(llvm::vfs::FileSystem &VFS, StringRef Path,
1040  const Multilib::flags_list &Flags,
1041  FilterNonExistent &NonExistent,
1042  DetectedMultilibs &Result) {
1043 
1044  MultilibSet AndroidMipsMultilibs =
1045  MultilibSet()
1046  .Maybe(Multilib("/mips-r2").flag("+march=mips32r2"))
1047  .Maybe(Multilib("/mips-r6").flag("+march=mips32r6"))
1048  .FilterOut(NonExistent);
1049 
1050  MultilibSet AndroidMipselMultilibs =
1051  MultilibSet()
1052  .Either(Multilib().flag("+march=mips32"),
1053  Multilib("/mips-r2", "", "/mips-r2").flag("+march=mips32r2"),
1054  Multilib("/mips-r6", "", "/mips-r6").flag("+march=mips32r6"))
1055  .FilterOut(NonExistent);
1056 
1057  MultilibSet AndroidMips64elMultilibs =
1058  MultilibSet()
1059  .Either(
1060  Multilib().flag("+march=mips64r6"),
1061  Multilib("/32/mips-r1", "", "/mips-r1").flag("+march=mips32"),
1062  Multilib("/32/mips-r2", "", "/mips-r2").flag("+march=mips32r2"),
1063  Multilib("/32/mips-r6", "", "/mips-r6").flag("+march=mips32r6"))
1064  .FilterOut(NonExistent);
1065 
1066  MultilibSet *MS = &AndroidMipsMultilibs;
1067  if (VFS.exists(Path + "/mips-r6"))
1068  MS = &AndroidMipselMultilibs;
1069  else if (VFS.exists(Path + "/32"))
1070  MS = &AndroidMips64elMultilibs;
1071  if (MS->select(Flags, Result.SelectedMultilib)) {
1072  Result.Multilibs = *MS;
1073  return true;
1074  }
1075  return false;
1076 }
1077 
1079  FilterNonExistent &NonExistent,
1080  DetectedMultilibs &Result) {
1081  // Musl toolchain multilibs
1082  MultilibSet MuslMipsMultilibs;
1083  {
1084  auto MArchMipsR2 = makeMultilib("")
1085  .osSuffix("/mips-r2-hard-musl")
1086  .flag("+EB")
1087  .flag("-EL")
1088  .flag("+march=mips32r2");
1089 
1090  auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl")
1091  .flag("-EB")
1092  .flag("+EL")
1093  .flag("+march=mips32r2");
1094 
1095  MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2);
1096 
1097  // Specify the callback that computes the include directories.
1098  MuslMipsMultilibs.setIncludeDirsCallback([](const Multilib &M) {
1099  return std::vector<std::string>(
1100  {"/../sysroot" + M.osSuffix() + "/usr/include"});
1101  });
1102  }
1103  if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) {
1104  Result.Multilibs = MuslMipsMultilibs;
1105  return true;
1106  }
1107  return false;
1108 }
1109 
1111  FilterNonExistent &NonExistent,
1112  DetectedMultilibs &Result) {
1113  // CodeScape MTI toolchain v1.2 and early.
1114  MultilibSet MtiMipsMultilibsV1;
1115  {
1116  auto MArchMips32 = makeMultilib("/mips32")
1117  .flag("+m32")
1118  .flag("-m64")
1119  .flag("-mmicromips")
1120  .flag("+march=mips32");
1121 
1122  auto MArchMicroMips = makeMultilib("/micromips")
1123  .flag("+m32")
1124  .flag("-m64")
1125  .flag("+mmicromips");
1126 
1127  auto MArchMips64r2 = makeMultilib("/mips64r2")
1128  .flag("-m32")
1129  .flag("+m64")
1130  .flag("+march=mips64r2");
1131 
1132  auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag(
1133  "-march=mips64r2");
1134 
1135  auto MArchDefault = makeMultilib("")
1136  .flag("+m32")
1137  .flag("-m64")
1138  .flag("-mmicromips")
1139  .flag("+march=mips32r2");
1140 
1141  auto Mips16 = makeMultilib("/mips16").flag("+mips16");
1142 
1143  auto UCLibc = makeMultilib("/uclibc").flag("+muclibc");
1144 
1145  auto MAbi64 =
1146  makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32");
1147 
1148  auto BigEndian = makeMultilib("").flag("+EB").flag("-EL");
1149 
1150  auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB");
1151 
1152  auto SoftFloat = makeMultilib("/sof").flag("+msoft-float");
1153 
1154  auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008");
1155 
1156  MtiMipsMultilibsV1 =
1157  MultilibSet()
1158  .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64,
1159  MArchDefault)
1160  .Maybe(UCLibc)
1161  .Maybe(Mips16)
1162  .FilterOut("/mips64/mips16")
1163  .FilterOut("/mips64r2/mips16")
1164  .FilterOut("/micromips/mips16")
1165  .Maybe(MAbi64)
1166  .FilterOut("/micromips/64")
1167  .FilterOut("/mips32/64")
1168  .FilterOut("^/64")
1169  .FilterOut("/mips16/64")
1170  .Either(BigEndian, LittleEndian)
1171  .Maybe(SoftFloat)
1172  .Maybe(Nan2008)
1173  .FilterOut(".*sof/nan2008")
1174  .FilterOut(NonExistent)
1175  .setIncludeDirsCallback([](const Multilib &M) {
1176  std::vector<std::string> Dirs({"/include"});
1177  if (StringRef(M.includeSuffix()).startswith("/uclibc"))
1178  Dirs.push_back("/../../../../sysroot/uclibc/usr/include");
1179  else
1180  Dirs.push_back("/../../../../sysroot/usr/include");
1181  return Dirs;
1182  });
1183  }
1184 
1185  // CodeScape IMG toolchain starting from v1.3.
1186  MultilibSet MtiMipsMultilibsV2;
1187  {
1188  auto BeHard = makeMultilib("/mips-r2-hard")
1189  .flag("+EB")
1190  .flag("-msoft-float")
1191  .flag("-mnan=2008")
1192  .flag("-muclibc");
1193  auto BeSoft = makeMultilib("/mips-r2-soft")
1194  .flag("+EB")
1195  .flag("+msoft-float")
1196  .flag("-mnan=2008");
1197  auto ElHard = makeMultilib("/mipsel-r2-hard")
1198  .flag("+EL")
1199  .flag("-msoft-float")
1200  .flag("-mnan=2008")
1201  .flag("-muclibc");
1202  auto ElSoft = makeMultilib("/mipsel-r2-soft")
1203  .flag("+EL")
1204  .flag("+msoft-float")
1205  .flag("-mnan=2008")
1206  .flag("-mmicromips");
1207  auto BeHardNan = makeMultilib("/mips-r2-hard-nan2008")
1208  .flag("+EB")
1209  .flag("-msoft-float")
1210  .flag("+mnan=2008")
1211  .flag("-muclibc");
1212  auto ElHardNan = makeMultilib("/mipsel-r2-hard-nan2008")
1213  .flag("+EL")
1214  .flag("-msoft-float")
1215  .flag("+mnan=2008")
1216  .flag("-muclibc")
1217  .flag("-mmicromips");
1218  auto BeHardNanUclibc = makeMultilib("/mips-r2-hard-nan2008-uclibc")
1219  .flag("+EB")
1220  .flag("-msoft-float")
1221  .flag("+mnan=2008")
1222  .flag("+muclibc");
1223  auto ElHardNanUclibc = makeMultilib("/mipsel-r2-hard-nan2008-uclibc")
1224  .flag("+EL")
1225  .flag("-msoft-float")
1226  .flag("+mnan=2008")
1227  .flag("+muclibc");
1228  auto BeHardUclibc = makeMultilib("/mips-r2-hard-uclibc")
1229  .flag("+EB")
1230  .flag("-msoft-float")
1231  .flag("-mnan=2008")
1232  .flag("+muclibc");
1233  auto ElHardUclibc = makeMultilib("/mipsel-r2-hard-uclibc")
1234  .flag("+EL")
1235  .flag("-msoft-float")
1236  .flag("-mnan=2008")
1237  .flag("+muclibc");
1238  auto ElMicroHardNan = makeMultilib("/micromipsel-r2-hard-nan2008")
1239  .flag("+EL")
1240  .flag("-msoft-float")
1241  .flag("+mnan=2008")
1242  .flag("+mmicromips");
1243  auto ElMicroSoft = makeMultilib("/micromipsel-r2-soft")
1244  .flag("+EL")
1245  .flag("+msoft-float")
1246  .flag("-mnan=2008")
1247  .flag("+mmicromips");
1248 
1249  auto O32 =
1250  makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64");
1251  auto N32 =
1252  makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64");
1253  auto N64 =
1254  makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64");
1255 
1256  MtiMipsMultilibsV2 =
1257  MultilibSet()
1258  .Either({BeHard, BeSoft, ElHard, ElSoft, BeHardNan, ElHardNan,
1259  BeHardNanUclibc, ElHardNanUclibc, BeHardUclibc,
1260  ElHardUclibc, ElMicroHardNan, ElMicroSoft})
1261  .Either(O32, N32, N64)
1262  .FilterOut(NonExistent)
1263  .setIncludeDirsCallback([](const Multilib &M) {
1264  return std::vector<std::string>({"/../../../../sysroot" +
1265  M.includeSuffix() +
1266  "/../usr/include"});
1267  })
1268  .setFilePathsCallback([](const Multilib &M) {
1269  return std::vector<std::string>(
1270  {"/../../../../mips-mti-linux-gnu/lib" + M.gccSuffix()});
1271  });
1272  }
1273  for (auto Candidate : {&MtiMipsMultilibsV1, &MtiMipsMultilibsV2}) {
1274  if (Candidate->select(Flags, Result.SelectedMultilib)) {
1275  Result.Multilibs = *Candidate;
1276  return true;
1277  }
1278  }
1279  return false;
1280 }
1281 
1283  FilterNonExistent &NonExistent,
1284  DetectedMultilibs &Result) {
1285  // CodeScape IMG toolchain v1.2 and early.
1286  MultilibSet ImgMultilibsV1;
1287  {
1288  auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32");
1289 
1290  auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB");
1291 
1292  auto MAbi64 =
1293  makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32");
1294 
1295  ImgMultilibsV1 =
1296  MultilibSet()
1297  .Maybe(Mips64r6)
1298  .Maybe(MAbi64)
1299  .Maybe(LittleEndian)
1300  .FilterOut(NonExistent)
1301  .setIncludeDirsCallback([](const Multilib &M) {
1302  return std::vector<std::string>(
1303  {"/include", "/../../../../sysroot/usr/include"});
1304  });
1305  }
1306 
1307  // CodeScape IMG toolchain starting from v1.3.
1308  MultilibSet ImgMultilibsV2;
1309  {
1310  auto BeHard = makeMultilib("/mips-r6-hard")
1311  .flag("+EB")
1312  .flag("-msoft-float")
1313  .flag("-mmicromips");
1314  auto BeSoft = makeMultilib("/mips-r6-soft")
1315  .flag("+EB")
1316  .flag("+msoft-float")
1317  .flag("-mmicromips");
1318  auto ElHard = makeMultilib("/mipsel-r6-hard")
1319  .flag("+EL")
1320  .flag("-msoft-float")
1321  .flag("-mmicromips");
1322  auto ElSoft = makeMultilib("/mipsel-r6-soft")
1323  .flag("+EL")
1324  .flag("+msoft-float")
1325  .flag("-mmicromips");
1326  auto BeMicroHard = makeMultilib("/micromips-r6-hard")
1327  .flag("+EB")
1328  .flag("-msoft-float")
1329  .flag("+mmicromips");
1330  auto BeMicroSoft = makeMultilib("/micromips-r6-soft")
1331  .flag("+EB")
1332  .flag("+msoft-float")
1333  .flag("+mmicromips");
1334  auto ElMicroHard = makeMultilib("/micromipsel-r6-hard")
1335  .flag("+EL")
1336  .flag("-msoft-float")
1337  .flag("+mmicromips");
1338  auto ElMicroSoft = makeMultilib("/micromipsel-r6-soft")
1339  .flag("+EL")
1340  .flag("+msoft-float")
1341  .flag("+mmicromips");
1342 
1343  auto O32 =
1344  makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64");
1345  auto N32 =
1346  makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64");
1347  auto N64 =
1348  makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64");
1349 
1350  ImgMultilibsV2 =
1351  MultilibSet()
1352  .Either({BeHard, BeSoft, ElHard, ElSoft, BeMicroHard, BeMicroSoft,
1353  ElMicroHard, ElMicroSoft})
1354  .Either(O32, N32, N64)
1355  .FilterOut(NonExistent)
1356  .setIncludeDirsCallback([](const Multilib &M) {
1357  return std::vector<std::string>({"/../../../../sysroot" +
1358  M.includeSuffix() +
1359  "/../usr/include"});
1360  })
1361  .setFilePathsCallback([](const Multilib &M) {
1362  return std::vector<std::string>(
1363  {"/../../../../mips-img-linux-gnu/lib" + M.gccSuffix()});
1364  });
1365  }
1366  for (auto Candidate : {&ImgMultilibsV1, &ImgMultilibsV2}) {
1367  if (Candidate->select(Flags, Result.SelectedMultilib)) {
1368  Result.Multilibs = *Candidate;
1369  return true;
1370  }
1371  }
1372  return false;
1373 }
1374 
1376  const llvm::Triple &TargetTriple,
1377  StringRef Path, const ArgList &Args,
1378  DetectedMultilibs &Result) {
1379  FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
1380 
1381  StringRef CPUName;
1382  StringRef ABIName;
1383  tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName);
1384 
1385  llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
1386 
1387  Multilib::flags_list Flags;
1388  addMultilibFlag(TargetTriple.isMIPS32(), "m32", Flags);
1389  addMultilibFlag(TargetTriple.isMIPS64(), "m64", Flags);
1390  addMultilibFlag(isMips16(Args), "mips16", Flags);
1391  addMultilibFlag(CPUName == "mips32", "march=mips32", Flags);
1392  addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" ||
1393  CPUName == "mips32r5" || CPUName == "p5600",
1394  "march=mips32r2", Flags);
1395  addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags);
1396  addMultilibFlag(CPUName == "mips64", "march=mips64", Flags);
1397  addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" ||
1398  CPUName == "mips64r5" || CPUName == "octeon",
1399  "march=mips64r2", Flags);
1400  addMultilibFlag(CPUName == "mips64r6", "march=mips64r6", Flags);
1401  addMultilibFlag(isMicroMips(Args), "mmicromips", Flags);
1402  addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags);
1403  addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008",
1404  Flags);
1405  addMultilibFlag(ABIName == "n32", "mabi=n32", Flags);
1406  addMultilibFlag(ABIName == "n64", "mabi=n64", Flags);
1407  addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags);
1408  addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags);
1409  addMultilibFlag(isMipsEL(TargetArch), "EL", Flags);
1410  addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags);
1411 
1412  if (TargetTriple.isAndroid())
1413  return findMipsAndroidMultilibs(D.getVFS(), Path, Flags, NonExistent,
1414  Result);
1415 
1416  if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies &&
1417  TargetTriple.getOS() == llvm::Triple::Linux &&
1418  TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment)
1419  return findMipsMuslMultilibs(Flags, NonExistent, Result);
1420 
1421  if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies &&
1422  TargetTriple.getOS() == llvm::Triple::Linux &&
1423  TargetTriple.isGNUEnvironment())
1424  return findMipsMtiMultilibs(Flags, NonExistent, Result);
1425 
1426  if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies &&
1427  TargetTriple.getOS() == llvm::Triple::Linux &&
1428  TargetTriple.isGNUEnvironment())
1429  return findMipsImgMultilibs(Flags, NonExistent, Result);
1430 
1431  if (findMipsCsMultilibs(Flags, NonExistent, Result))
1432  return true;
1433 
1434  // Fallback to the regular toolchain-tree structure.
1435  Multilib Default;
1436  Result.Multilibs.push_back(Default);
1437  Result.Multilibs.FilterOut(NonExistent);
1438 
1439  if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) {
1440  Result.BiarchSibling = Multilib();
1441  return true;
1442  }
1443 
1444  return false;
1445 }
1446 
1447 static void findAndroidArmMultilibs(const Driver &D,
1448  const llvm::Triple &TargetTriple,
1449  StringRef Path, const ArgList &Args,
1450  DetectedMultilibs &Result) {
1451  // Find multilibs with subdirectories like armv7-a, thumb, armv7-a/thumb.
1452  FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
1453  Multilib ArmV7Multilib = makeMultilib("/armv7-a")
1454  .flag("+march=armv7-a")
1455  .flag("-mthumb");
1456  Multilib ThumbMultilib = makeMultilib("/thumb")
1457  .flag("-march=armv7-a")
1458  .flag("+mthumb");
1459  Multilib ArmV7ThumbMultilib = makeMultilib("/armv7-a/thumb")
1460  .flag("+march=armv7-a")
1461  .flag("+mthumb");
1462  Multilib DefaultMultilib = makeMultilib("")
1463  .flag("-march=armv7-a")
1464  .flag("-mthumb");
1465  MultilibSet AndroidArmMultilibs =
1466  MultilibSet()
1467  .Either(ThumbMultilib, ArmV7Multilib,
1468  ArmV7ThumbMultilib, DefaultMultilib)
1469  .FilterOut(NonExistent);
1470 
1471  Multilib::flags_list Flags;
1472  llvm::StringRef Arch = Args.getLastArgValue(options::OPT_march_EQ);
1473  bool IsArmArch = TargetTriple.getArch() == llvm::Triple::arm;
1474  bool IsThumbArch = TargetTriple.getArch() == llvm::Triple::thumb;
1475  bool IsV7SubArch = TargetTriple.getSubArch() == llvm::Triple::ARMSubArch_v7;
1476  bool IsThumbMode = IsThumbArch ||
1477  Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, false) ||
1478  (IsArmArch && llvm::ARM::parseArchISA(Arch) == llvm::ARM::ISAKind::THUMB);
1479  bool IsArmV7Mode = (IsArmArch || IsThumbArch) &&
1480  (llvm::ARM::parseArchVersion(Arch) == 7 ||
1481  (IsArmArch && Arch == "" && IsV7SubArch));
1482  addMultilibFlag(IsArmV7Mode, "march=armv7-a", Flags);
1483  addMultilibFlag(IsThumbMode, "mthumb", Flags);
1484 
1485  if (AndroidArmMultilibs.select(Flags, Result.SelectedMultilib))
1486  Result.Multilibs = AndroidArmMultilibs;
1487 }
1488 
1489 static bool findMSP430Multilibs(const Driver &D,
1490  const llvm::Triple &TargetTriple,
1491  StringRef Path, const ArgList &Args,
1492  DetectedMultilibs &Result) {
1493  FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
1494  Multilib MSP430Multilib = makeMultilib("/430");
1495  // FIXME: when clang starts to support msp430x ISA additional logic
1496  // to select between multilib must be implemented
1497  // Multilib MSP430xMultilib = makeMultilib("/large");
1498 
1499  Result.Multilibs.push_back(MSP430Multilib);
1500  Result.Multilibs.FilterOut(NonExistent);
1501 
1502  Multilib::flags_list Flags;
1503  if (Result.Multilibs.select(Flags, Result.SelectedMultilib))
1504  return true;
1505 
1506  return false;
1507 }
1508 
1509 static void findRISCVMultilibs(const Driver &D,
1510  const llvm::Triple &TargetTriple, StringRef Path,
1511  const ArgList &Args, DetectedMultilibs &Result) {
1512 
1513  FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
1514  Multilib Ilp32 = makeMultilib("lib32/ilp32").flag("+m32").flag("+mabi=ilp32");
1515  Multilib Ilp32f =
1516  makeMultilib("lib32/ilp32f").flag("+m32").flag("+mabi=ilp32f");
1517  Multilib Ilp32d =
1518  makeMultilib("lib32/ilp32d").flag("+m32").flag("+mabi=ilp32d");
1519  Multilib Lp64 = makeMultilib("lib64/lp64").flag("+m64").flag("+mabi=lp64");
1520  Multilib Lp64f = makeMultilib("lib64/lp64f").flag("+m64").flag("+mabi=lp64f");
1521  Multilib Lp64d = makeMultilib("lib64/lp64d").flag("+m64").flag("+mabi=lp64d");
1522  MultilibSet RISCVMultilibs =
1523  MultilibSet()
1524  .Either({Ilp32, Ilp32f, Ilp32d, Lp64, Lp64f, Lp64d})
1525  .FilterOut(NonExistent);
1526 
1527  Multilib::flags_list Flags;
1528  bool IsRV64 = TargetTriple.getArch() == llvm::Triple::riscv64;
1529  StringRef ABIName = tools::riscv::getRISCVABI(Args, TargetTriple);
1530 
1531  addMultilibFlag(!IsRV64, "m32", Flags);
1532  addMultilibFlag(IsRV64, "m64", Flags);
1533  addMultilibFlag(ABIName == "ilp32", "mabi=ilp32", Flags);
1534  addMultilibFlag(ABIName == "ilp32f", "mabi=ilp32f", Flags);
1535  addMultilibFlag(ABIName == "ilp32d", "mabi=ilp32d", Flags);
1536  addMultilibFlag(ABIName == "lp64", "mabi=lp64", Flags);
1537  addMultilibFlag(ABIName == "lp64f", "mabi=lp64f", Flags);
1538  addMultilibFlag(ABIName == "lp64d", "mabi=lp64d", Flags);
1539 
1540  if (RISCVMultilibs.select(Flags, Result.SelectedMultilib))
1541  Result.Multilibs = RISCVMultilibs;
1542 }
1543 
1544 static bool findBiarchMultilibs(const Driver &D,
1545  const llvm::Triple &TargetTriple,
1546  StringRef Path, const ArgList &Args,
1547  bool NeedsBiarchSuffix,
1548  DetectedMultilibs &Result) {
1549  Multilib Default;
1550 
1551  // Some versions of SUSE and Fedora on ppc64 put 32-bit libs
1552  // in what would normally be GCCInstallPath and put the 64-bit
1553  // libs in a subdirectory named 64. The simple logic we follow is that
1554  // *if* there is a subdirectory of the right name with crtbegin.o in it,
1555  // we use that. If not, and if not a biarch triple alias, we look for
1556  // crtbegin.o without the subdirectory.
1557 
1558  StringRef Suff64 = "/64";
1559  // Solaris uses platform-specific suffixes instead of /64.
1560  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
1561  switch (TargetTriple.getArch()) {
1562  case llvm::Triple::x86:
1563  case llvm::Triple::x86_64:
1564  Suff64 = "/amd64";
1565  break;
1566  case llvm::Triple::sparc:
1567  case llvm::Triple::sparcv9:
1568  Suff64 = "/sparcv9";
1569  break;
1570  default:
1571  break;
1572  }
1573  }
1574 
1575  Multilib Alt64 = Multilib()
1576  .gccSuffix(Suff64)
1577  .includeSuffix(Suff64)
1578  .flag("-m32")
1579  .flag("+m64")
1580  .flag("-mx32");
1581  Multilib Alt32 = Multilib()
1582  .gccSuffix("/32")
1583  .includeSuffix("/32")
1584  .flag("+m32")
1585  .flag("-m64")
1586  .flag("-mx32");
1587  Multilib Altx32 = Multilib()
1588  .gccSuffix("/x32")
1589  .includeSuffix("/x32")
1590  .flag("-m32")
1591  .flag("-m64")
1592  .flag("+mx32");
1593 
1594  // GCC toolchain for IAMCU doesn't have crtbegin.o, so look for libgcc.a.
1595  FilterNonExistent NonExistent(
1596  Path, TargetTriple.isOSIAMCU() ? "/libgcc.a" : "/crtbegin.o", D.getVFS());
1597 
1598  // Determine default multilib from: 32, 64, x32
1599  // Also handle cases such as 64 on 32, 32 on 64, etc.
1600  enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN;
1601  const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32;
1602  if (TargetTriple.isArch32Bit() && !NonExistent(Alt32))
1603  Want = WANT64;
1604  else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32))
1605  Want = WANT64;
1606  else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64))
1607  Want = WANT32;
1608  else {
1609  if (TargetTriple.isArch32Bit())
1610  Want = NeedsBiarchSuffix ? WANT64 : WANT32;
1611  else if (IsX32)
1612  Want = NeedsBiarchSuffix ? WANT64 : WANTX32;
1613  else
1614  Want = NeedsBiarchSuffix ? WANT32 : WANT64;
1615  }
1616 
1617  if (Want == WANT32)
1618  Default.flag("+m32").flag("-m64").flag("-mx32");
1619  else if (Want == WANT64)
1620  Default.flag("-m32").flag("+m64").flag("-mx32");
1621  else if (Want == WANTX32)
1622  Default.flag("-m32").flag("-m64").flag("+mx32");
1623  else
1624  return false;
1625 
1626  Result.Multilibs.push_back(Default);
1627  Result.Multilibs.push_back(Alt64);
1628  Result.Multilibs.push_back(Alt32);
1629  Result.Multilibs.push_back(Altx32);
1630 
1631  Result.Multilibs.FilterOut(NonExistent);
1632 
1633  Multilib::flags_list Flags;
1634  addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags);
1635  addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags);
1636  addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags);
1637 
1638  if (!Result.Multilibs.select(Flags, Result.SelectedMultilib))
1639  return false;
1640 
1641  if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 ||
1642  Result.SelectedMultilib == Altx32)
1643  Result.BiarchSibling = Default;
1644 
1645  return true;
1646 }
1647 
1648 /// Generic_GCC - A tool chain using the 'gcc' command to perform
1649 /// all subcommands; this relies on gcc translating the majority of
1650 /// command line options.
1651 
1652 /// Less-than for GCCVersion, implementing a Strict Weak Ordering.
1653 bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor,
1654  int RHSPatch,
1655  StringRef RHSPatchSuffix) const {
1656  if (Major != RHSMajor)
1657  return Major < RHSMajor;
1658  if (Minor != RHSMinor)
1659  return Minor < RHSMinor;
1660  if (Patch != RHSPatch) {
1661  // Note that versions without a specified patch sort higher than those with
1662  // a patch.
1663  if (RHSPatch == -1)
1664  return true;
1665  if (Patch == -1)
1666  return false;
1667 
1668  // Otherwise just sort on the patch itself.
1669  return Patch < RHSPatch;
1670  }
1671  if (PatchSuffix != RHSPatchSuffix) {
1672  // Sort empty suffixes higher.
1673  if (RHSPatchSuffix.empty())
1674  return true;
1675  if (PatchSuffix.empty())
1676  return false;
1677 
1678  // Provide a lexicographic sort to make this a total ordering.
1679  return PatchSuffix < RHSPatchSuffix;
1680  }
1681 
1682  // The versions are equal.
1683  return false;
1684 }
1685 
1686 /// Parse a GCCVersion object out of a string of text.
1687 ///
1688 /// This is the primary means of forming GCCVersion objects.
1689 /*static*/
1691  const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""};
1692  std::pair<StringRef, StringRef> First = VersionText.split('.');
1693  std::pair<StringRef, StringRef> Second = First.second.split('.');
1694 
1695  GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""};
1696  if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0)
1697  return BadVersion;
1698  GoodVersion.MajorStr = First.first.str();
1699  if (First.second.empty())
1700  return GoodVersion;
1701  StringRef MinorStr = Second.first;
1702  if (Second.second.empty()) {
1703  if (size_t EndNumber = MinorStr.find_first_not_of("0123456789")) {
1704  GoodVersion.PatchSuffix = MinorStr.substr(EndNumber);
1705  MinorStr = MinorStr.slice(0, EndNumber);
1706  }
1707  }
1708  if (MinorStr.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0)
1709  return BadVersion;
1710  GoodVersion.MinorStr = MinorStr.str();
1711 
1712  // First look for a number prefix and parse that if present. Otherwise just
1713  // stash the entire patch string in the suffix, and leave the number
1714  // unspecified. This covers versions strings such as:
1715  // 5 (handled above)
1716  // 4.4
1717  // 4.4-patched
1718  // 4.4.0
1719  // 4.4.x
1720  // 4.4.2-rc4
1721  // 4.4.x-patched
1722  // And retains any patch number it finds.
1723  StringRef PatchText = Second.second;
1724  if (!PatchText.empty()) {
1725  if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) {
1726  // Try to parse the number and any suffix.
1727  if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) ||
1728  GoodVersion.Patch < 0)
1729  return BadVersion;
1730  GoodVersion.PatchSuffix = PatchText.substr(EndNumber);
1731  }
1732  }
1733 
1734  return GoodVersion;
1735 }
1736 
1737 static llvm::StringRef getGCCToolchainDir(const ArgList &Args,
1738  llvm::StringRef SysRoot) {
1739  const Arg *A = Args.getLastArg(clang::driver::options::OPT_gcc_toolchain);
1740  if (A)
1741  return A->getValue();
1742 
1743  // If we have a SysRoot, ignore GCC_INSTALL_PREFIX.
1744  // GCC_INSTALL_PREFIX specifies the gcc installation for the default
1745  // sysroot and is likely not valid with a different sysroot.
1746  if (!SysRoot.empty())
1747  return "";
1748 
1749  return GCC_INSTALL_PREFIX;
1750 }
1751 
1752 /// Initialize a GCCInstallationDetector from the driver.
1753 ///
1754 /// This performs all of the autodetection and sets up the various paths.
1755 /// Once constructed, a GCCInstallationDetector is essentially immutable.
1756 ///
1757 /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and
1758 /// should instead pull the target out of the driver. This is currently
1759 /// necessary because the driver doesn't store the final version of the target
1760 /// triple.
1762  const llvm::Triple &TargetTriple, const ArgList &Args,
1763  ArrayRef<std::string> ExtraTripleAliases) {
1764  llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit()
1765  ? TargetTriple.get64BitArchVariant()
1766  : TargetTriple.get32BitArchVariant();
1767  // The library directories which may contain GCC installations.
1768  SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs;
1769  // The compatible GCC triples for this particular architecture.
1770  SmallVector<StringRef, 16> CandidateTripleAliases;
1771  SmallVector<StringRef, 16> CandidateBiarchTripleAliases;
1772  CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
1773  CandidateTripleAliases, CandidateBiarchLibDirs,
1774  CandidateBiarchTripleAliases);
1775 
1776  // Compute the set of prefixes for our search.
1777  SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(),
1778  D.PrefixDirs.end());
1779 
1780  StringRef GCCToolchainDir = getGCCToolchainDir(Args, D.SysRoot);
1781  if (GCCToolchainDir != "") {
1782  if (GCCToolchainDir.back() == '/')
1783  GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the /
1784 
1785  Prefixes.push_back(GCCToolchainDir);
1786  } else {
1787  // If we have a SysRoot, try that first.
1788  if (!D.SysRoot.empty()) {
1789  Prefixes.push_back(D.SysRoot);
1790  AddDefaultGCCPrefixes(TargetTriple, Prefixes, D.SysRoot);
1791  }
1792 
1793  // Then look for gcc installed alongside clang.
1794  Prefixes.push_back(D.InstalledDir + "/..");
1795 
1796  // Next, look for prefix(es) that correspond to distribution-supplied gcc
1797  // installations.
1798  if (D.SysRoot.empty()) {
1799  // Typically /usr.
1800  AddDefaultGCCPrefixes(TargetTriple, Prefixes, D.SysRoot);
1801  }
1802  }
1803 
1804  // Try to respect gcc-config on Gentoo. However, do that only
1805  // if --gcc-toolchain is not provided or equal to the Gentoo install
1806  // in /usr. This avoids accidentally enforcing the system GCC version
1807  // when using a custom toolchain.
1808  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
1809  SmallVector<StringRef, 16> GentooTestTriples;
1810  // Try to match an exact triple as target triple first.
1811  // e.g. crossdev -S x86_64-gentoo-linux-gnu will install gcc libs for
1812  // x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
1813  // may pick the libraries for x86_64-pc-linux-gnu even when exact matching
1814  // triple x86_64-gentoo-linux-gnu is present.
1815  GentooTestTriples.push_back(TargetTriple.str());
1816  // Check rest of triples.
1817  GentooTestTriples.append(ExtraTripleAliases.begin(),
1818  ExtraTripleAliases.end());
1819  GentooTestTriples.append(CandidateTripleAliases.begin(),
1820  CandidateTripleAliases.end());
1821  if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
1822  CandidateBiarchTripleAliases))
1823  return;
1824  }
1825 
1826  // Loop over the various components which exist and select the best GCC
1827  // installation available. GCC installs are ranked by version number.
1828  Version = GCCVersion::Parse("0.0.0");
1829  for (const std::string &Prefix : Prefixes) {
1830  if (!D.getVFS().exists(Prefix))
1831  continue;
1832  for (StringRef Suffix : CandidateLibDirs) {
1833  const std::string LibDir = Prefix + Suffix.str();
1834  if (!D.getVFS().exists(LibDir))
1835  continue;
1836  // Try to match the exact target triple first.
1837  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str());
1838  // Try rest of possible triples.
1839  for (StringRef Candidate : ExtraTripleAliases) // Try these first.
1840  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
1841  for (StringRef Candidate : CandidateTripleAliases)
1842  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
1843  }
1844  for (StringRef Suffix : CandidateBiarchLibDirs) {
1845  const std::string LibDir = Prefix + Suffix.str();
1846  if (!D.getVFS().exists(LibDir))
1847  continue;
1848  for (StringRef Candidate : CandidateBiarchTripleAliases)
1849  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate,
1850  /*NeedsBiarchSuffix=*/ true);
1851  }
1852  }
1853 }
1854 
1855 void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const {
1856  for (const auto &InstallPath : CandidateGCCInstallPaths)
1857  OS << "Found candidate GCC installation: " << InstallPath << "\n";
1858 
1859  if (!GCCInstallPath.empty())
1860  OS << "Selected GCC installation: " << GCCInstallPath << "\n";
1861 
1862  for (const auto &Multilib : Multilibs)
1863  OS << "Candidate multilib: " << Multilib << "\n";
1864 
1865  if (Multilibs.size() != 0 || !SelectedMultilib.isDefault())
1866  OS << "Selected multilib: " << SelectedMultilib << "\n";
1867 }
1868 
1870  if (BiarchSibling.hasValue()) {
1871  M = BiarchSibling.getValue();
1872  return true;
1873  }
1874  return false;
1875 }
1876 
1877 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
1878  const llvm::Triple &TargetTriple, SmallVectorImpl<std::string> &Prefixes,
1879  StringRef SysRoot) {
1880  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
1881  // Solaris is a special case.
1882  // The GCC installation is under
1883  // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/
1884  // so we need to find those /usr/gcc/*/lib/gcc libdirs and go with
1885  // /usr/gcc/<version> as a prefix.
1886 
1887  std::string PrefixDir = SysRoot.str() + "/usr/gcc";
1888  std::error_code EC;
1889  for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin(PrefixDir, EC),
1890  LE;
1891  !EC && LI != LE; LI = LI.increment(EC)) {
1892  StringRef VersionText = llvm::sys::path::filename(LI->path());
1893  GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
1894 
1895  // Filter out obviously bad entries.
1896  if (CandidateVersion.Major == -1 || CandidateVersion.isOlderThan(4, 1, 1))
1897  continue;
1898 
1899  std::string CandidatePrefix = PrefixDir + "/" + VersionText.str();
1900  std::string CandidateLibPath = CandidatePrefix + "/lib/gcc";
1901  if (!D.getVFS().exists(CandidateLibPath))
1902  continue;
1903 
1904  Prefixes.push_back(CandidatePrefix);
1905  }
1906  return;
1907  }
1908 
1909  // Non-Solaris is much simpler - most systems just go with "/usr".
1910  if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux) {
1911  // Yet, still look for RHEL devtoolsets.
1912  Prefixes.push_back("/opt/rh/devtoolset-8/root/usr");
1913  Prefixes.push_back("/opt/rh/devtoolset-7/root/usr");
1914  Prefixes.push_back("/opt/rh/devtoolset-6/root/usr");
1915  Prefixes.push_back("/opt/rh/devtoolset-4/root/usr");
1916  Prefixes.push_back("/opt/rh/devtoolset-3/root/usr");
1917  Prefixes.push_back("/opt/rh/devtoolset-2/root/usr");
1918  }
1919  Prefixes.push_back(SysRoot.str() + "/usr");
1920 }
1921 
1922 /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples(
1923  const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple,
1924  SmallVectorImpl<StringRef> &LibDirs,
1925  SmallVectorImpl<StringRef> &TripleAliases,
1926  SmallVectorImpl<StringRef> &BiarchLibDirs,
1927  SmallVectorImpl<StringRef> &BiarchTripleAliases) {
1928  // Declare a bunch of static data sets that we'll select between below. These
1929  // are specifically designed to always refer to string literals to avoid any
1930  // lifetime or initialization issues.
1931  static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
1932  static const char *const AArch64Triples[] = {
1933  "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
1934  "aarch64-suse-linux", "aarch64-linux-android"};
1935  static const char *const AArch64beLibDirs[] = {"/lib"};
1936  static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
1937  "aarch64_be-linux-gnu"};
1938 
1939  static const char *const ARMLibDirs[] = {"/lib"};
1940  static const char *const ARMTriples[] = {"arm-linux-gnueabi",
1941  "arm-linux-androideabi"};
1942  static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf",
1943  "armv7hl-redhat-linux-gnueabi",
1944  "armv6hl-suse-linux-gnueabi",
1945  "armv7hl-suse-linux-gnueabi"};
1946  static const char *const ARMebLibDirs[] = {"/lib"};
1947  static const char *const ARMebTriples[] = {"armeb-linux-gnueabi",
1948  "armeb-linux-androideabi"};
1949  static const char *const ARMebHFTriples[] = {
1950  "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"};
1951 
1952  static const char *const AVRLibDirs[] = {"/lib"};
1953  static const char *const AVRTriples[] = {"avr"};
1954 
1955  static const char *const X86_64LibDirs[] = {"/lib64", "/lib"};
1956  static const char *const X86_64Triples[] = {
1957  "x86_64-linux-gnu", "x86_64-unknown-linux-gnu",
1958  "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E",
1959  "x86_64-redhat-linux", "x86_64-suse-linux",
1960  "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
1961  "x86_64-slackware-linux", "x86_64-unknown-linux",
1962  "x86_64-amazon-linux", "x86_64-linux-android"};
1963  static const char *const X32LibDirs[] = {"/libx32"};
1964  static const char *const X86LibDirs[] = {"/lib32", "/lib"};
1965  static const char *const X86Triples[] = {
1966  "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu",
1967  "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux",
1968  "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux",
1969  "i486-slackware-linux", "i686-montavista-linux", "i586-linux-gnu",
1970  "i686-linux-android", "i386-gnu", "i486-gnu",
1971  "i586-gnu", "i686-gnu"};
1972 
1973  static const char *const MIPSLibDirs[] = {"/lib"};
1974  static const char *const MIPSTriples[] = {
1975  "mips-linux-gnu", "mips-mti-linux", "mips-mti-linux-gnu",
1976  "mips-img-linux-gnu", "mipsisa32r6-linux-gnu"};
1977  static const char *const MIPSELLibDirs[] = {"/lib"};
1978  static const char *const MIPSELTriples[] = {
1979  "mipsel-linux-gnu", "mips-img-linux-gnu", "mipsisa32r6el-linux-gnu",
1980  "mipsel-linux-android"};
1981 
1982  static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"};
1983  static const char *const MIPS64Triples[] = {
1984  "mips64-linux-gnu", "mips-mti-linux-gnu",
1985  "mips-img-linux-gnu", "mips64-linux-gnuabi64",
1986  "mipsisa64r6-linux-gnu", "mipsisa64r6-linux-gnuabi64"};
1987  static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"};
1988  static const char *const MIPS64ELTriples[] = {
1989  "mips64el-linux-gnu", "mips-mti-linux-gnu",
1990  "mips-img-linux-gnu", "mips64el-linux-gnuabi64",
1991  "mipsisa64r6el-linux-gnu", "mipsisa64r6el-linux-gnuabi64",
1992  "mips64el-linux-android"};
1993 
1994  static const char *const MIPSN32LibDirs[] = {"/lib32"};
1995  static const char *const MIPSN32Triples[] = {"mips64-linux-gnuabin32",
1996  "mipsisa64r6-linux-gnuabin32"};
1997  static const char *const MIPSN32ELLibDirs[] = {"/lib32"};
1998  static const char *const MIPSN32ELTriples[] = {
1999  "mips64el-linux-gnuabin32", "mipsisa64r6el-linux-gnuabin32"};
2000 
2001  static const char *const MSP430LibDirs[] = {"/lib"};
2002  static const char *const MSP430Triples[] = {"msp430-elf"};
2003 
2004  static const char *const PPCLibDirs[] = {"/lib32", "/lib"};
2005  static const char *const PPCTriples[] = {
2006  "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe",
2007  "powerpc-suse-linux", "powerpc-montavista-linuxspe"};
2008  static const char *const PPC64LibDirs[] = {"/lib64", "/lib"};
2009  static const char *const PPC64Triples[] = {
2010  "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu",
2011  "powerpc64-suse-linux", "ppc64-redhat-linux"};
2012  static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"};
2013  static const char *const PPC64LETriples[] = {
2014  "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu",
2015  "powerpc64le-suse-linux", "ppc64le-redhat-linux"};
2016 
2017  static const char *const RISCV32LibDirs[] = {"/lib32", "/lib"};
2018  static const char *const RISCV32Triples[] = {"riscv32-unknown-linux-gnu",
2019  "riscv32-linux-gnu",
2020  "riscv32-unknown-elf"};
2021  static const char *const RISCV64LibDirs[] = {"/lib64", "/lib"};
2022  static const char *const RISCV64Triples[] = {"riscv64-unknown-linux-gnu",
2023  "riscv64-linux-gnu",
2024  "riscv64-unknown-elf",
2025  "riscv64-suse-linux"};
2026 
2027  static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
2028  static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",
2029  "sparcv8-linux-gnu"};
2030  static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"};
2031  static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu",
2032  "sparcv9-linux-gnu"};
2033 
2034  static const char *const SystemZLibDirs[] = {"/lib64", "/lib"};
2035  static const char *const SystemZTriples[] = {
2036  "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu",
2037  "s390x-suse-linux", "s390x-redhat-linux"};
2038 
2039 
2040  using std::begin;
2041  using std::end;
2042 
2043  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
2044  static const char *const SolarisLibDirs[] = {"/lib"};
2045  static const char *const SolarisSparcV8Triples[] = {
2046  "sparc-sun-solaris2.11", "sparc-sun-solaris2.12"};
2047  static const char *const SolarisSparcV9Triples[] = {
2048  "sparcv9-sun-solaris2.11", "sparcv9-sun-solaris2.12"};
2049  static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11",
2050  "i386-pc-solaris2.12"};
2051  static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11",
2052  "x86_64-pc-solaris2.12"};
2053  LibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
2054  BiarchLibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
2055  switch (TargetTriple.getArch()) {
2056  case llvm::Triple::x86:
2057  TripleAliases.append(begin(SolarisX86Triples), end(SolarisX86Triples));
2058  BiarchTripleAliases.append(begin(SolarisX86_64Triples),
2059  end(SolarisX86_64Triples));
2060  break;
2061  case llvm::Triple::x86_64:
2062  TripleAliases.append(begin(SolarisX86_64Triples),
2063  end(SolarisX86_64Triples));
2064  BiarchTripleAliases.append(begin(SolarisX86Triples),
2065  end(SolarisX86Triples));
2066  break;
2067  case llvm::Triple::sparc:
2068  TripleAliases.append(begin(SolarisSparcV8Triples),
2069  end(SolarisSparcV8Triples));
2070  BiarchTripleAliases.append(begin(SolarisSparcV9Triples),
2071  end(SolarisSparcV9Triples));
2072  break;
2073  case llvm::Triple::sparcv9:
2074  TripleAliases.append(begin(SolarisSparcV9Triples),
2075  end(SolarisSparcV9Triples));
2076  BiarchTripleAliases.append(begin(SolarisSparcV8Triples),
2077  end(SolarisSparcV8Triples));
2078  break;
2079  default:
2080  break;
2081  }
2082  return;
2083  }
2084 
2085  // Android targets should not use GNU/Linux tools or libraries.
2086  if (TargetTriple.isAndroid()) {
2087  static const char *const AArch64AndroidTriples[] = {
2088  "aarch64-linux-android"};
2089  static const char *const ARMAndroidTriples[] = {"arm-linux-androideabi"};
2090  static const char *const MIPSELAndroidTriples[] = {"mipsel-linux-android"};
2091  static const char *const MIPS64ELAndroidTriples[] = {
2092  "mips64el-linux-android"};
2093  static const char *const X86AndroidTriples[] = {"i686-linux-android"};
2094  static const char *const X86_64AndroidTriples[] = {"x86_64-linux-android"};
2095 
2096  switch (TargetTriple.getArch()) {
2097  case llvm::Triple::aarch64:
2098  LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2099  TripleAliases.append(begin(AArch64AndroidTriples),
2100  end(AArch64AndroidTriples));
2101  break;
2102  case llvm::Triple::arm:
2103  case llvm::Triple::thumb:
2104  LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
2105  TripleAliases.append(begin(ARMAndroidTriples), end(ARMAndroidTriples));
2106  break;
2107  case llvm::Triple::mipsel:
2108  LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2109  TripleAliases.append(begin(MIPSELAndroidTriples),
2110  end(MIPSELAndroidTriples));
2111  BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2112  BiarchTripleAliases.append(begin(MIPS64ELAndroidTriples),
2113  end(MIPS64ELAndroidTriples));
2114  break;
2115  case llvm::Triple::mips64el:
2116  LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2117  TripleAliases.append(begin(MIPS64ELAndroidTriples),
2118  end(MIPS64ELAndroidTriples));
2119  BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2120  BiarchTripleAliases.append(begin(MIPSELAndroidTriples),
2121  end(MIPSELAndroidTriples));
2122  break;
2123  case llvm::Triple::x86_64:
2124  LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2125  TripleAliases.append(begin(X86_64AndroidTriples),
2126  end(X86_64AndroidTriples));
2127  BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2128  BiarchTripleAliases.append(begin(X86AndroidTriples),
2129  end(X86AndroidTriples));
2130  break;
2131  case llvm::Triple::x86:
2132  LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2133  TripleAliases.append(begin(X86AndroidTriples), end(X86AndroidTriples));
2134  BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2135  BiarchTripleAliases.append(begin(X86_64AndroidTriples),
2136  end(X86_64AndroidTriples));
2137  break;
2138  default:
2139  break;
2140  }
2141 
2142  return;
2143  }
2144 
2145  switch (TargetTriple.getArch()) {
2146  case llvm::Triple::aarch64:
2147  LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2148  TripleAliases.append(begin(AArch64Triples), end(AArch64Triples));
2149  BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2150  BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples));
2151  break;
2152  case llvm::Triple::aarch64_be:
2153  LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs));
2154  TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples));
2155  BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs));
2156  BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples));
2157  break;
2158  case llvm::Triple::arm:
2159  case llvm::Triple::thumb:
2160  LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
2161  if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
2162  TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples));
2163  } else {
2164  TripleAliases.append(begin(ARMTriples), end(ARMTriples));
2165  }
2166  break;
2167  case llvm::Triple::armeb:
2168  case llvm::Triple::thumbeb:
2169  LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs));
2170  if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
2171  TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples));
2172  } else {
2173  TripleAliases.append(begin(ARMebTriples), end(ARMebTriples));
2174  }
2175  break;
2176  case llvm::Triple::avr:
2177  LibDirs.append(begin(AVRLibDirs), end(AVRLibDirs));
2178  TripleAliases.append(begin(AVRTriples), end(AVRTriples));
2179  break;
2180  case llvm::Triple::x86_64:
2181  LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2182  TripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2183  // x32 is always available when x86_64 is available, so adding it as
2184  // secondary arch with x86_64 triples
2185  if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) {
2186  BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs));
2187  BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2188  } else {
2189  BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2190  BiarchTripleAliases.append(begin(X86Triples), end(X86Triples));
2191  }
2192  break;
2193  case llvm::Triple::x86:
2194  LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2195  // MCU toolchain is 32 bit only and its triple alias is TargetTriple
2196  // itself, which will be appended below.
2197  if (!TargetTriple.isOSIAMCU()) {
2198  TripleAliases.append(begin(X86Triples), end(X86Triples));
2199  BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2200  BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2201  }
2202  break;
2203  case llvm::Triple::mips:
2204  LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
2205  TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2206  BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs));
2207  BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples));
2208  BiarchLibDirs.append(begin(MIPSN32LibDirs), end(MIPSN32LibDirs));
2209  BiarchTripleAliases.append(begin(MIPSN32Triples), end(MIPSN32Triples));
2210  break;
2211  case llvm::Triple::mipsel:
2212  LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2213  TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples));
2214  TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2215  BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2216  BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples));
2217  BiarchLibDirs.append(begin(MIPSN32ELLibDirs), end(MIPSN32ELLibDirs));
2218  BiarchTripleAliases.append(begin(MIPSN32ELTriples), end(MIPSN32ELTriples));
2219  break;
2220  case llvm::Triple::mips64:
2221  LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs));
2222  TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples));
2223  BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
2224  BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2225  BiarchLibDirs.append(begin(MIPSN32LibDirs), end(MIPSN32LibDirs));
2226  BiarchTripleAliases.append(begin(MIPSN32Triples), end(MIPSN32Triples));
2227  break;
2228  case llvm::Triple::mips64el:
2229  LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2230  TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples));
2231  BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2232  BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples));
2233  BiarchLibDirs.append(begin(MIPSN32ELLibDirs), end(MIPSN32ELLibDirs));
2234  BiarchTripleAliases.append(begin(MIPSN32ELTriples), end(MIPSN32ELTriples));
2235  BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2236  break;
2237  case llvm::Triple::msp430:
2238  LibDirs.append(begin(MSP430LibDirs), end(MSP430LibDirs));
2239  TripleAliases.append(begin(MSP430Triples), end(MSP430Triples));
2240  break;
2241  case llvm::Triple::ppc:
2242  LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
2243  TripleAliases.append(begin(PPCTriples), end(PPCTriples));
2244  BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
2245  BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples));
2246  break;
2247  case llvm::Triple::ppc64:
2248  LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
2249  TripleAliases.append(begin(PPC64Triples), end(PPC64Triples));
2250  BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
2251  BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples));
2252  break;
2253  case llvm::Triple::ppc64le:
2254  LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs));
2255  TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples));
2256  break;
2257  case llvm::Triple::riscv32:
2258  LibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
2259  TripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
2260  BiarchLibDirs.append(begin(RISCV64LibDirs), end(RISCV64LibDirs));
2261  BiarchTripleAliases.append(begin(RISCV64Triples), end(RISCV64Triples));
2262  break;
2263  case llvm::Triple::riscv64:
2264  LibDirs.append(begin(RISCV64LibDirs), end(RISCV64LibDirs));
2265  TripleAliases.append(begin(RISCV64Triples), end(RISCV64Triples));
2266  BiarchLibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
2267  BiarchTripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
2268  break;
2269  case llvm::Triple::sparc:
2270  case llvm::Triple::sparcel:
2271  LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
2272  TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples));
2273  BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs));
2274  BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples));
2275  break;
2276  case llvm::Triple::sparcv9:
2277  LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs));
2278  TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples));
2279  BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
2280  BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples));
2281  break;
2282  case llvm::Triple::systemz:
2283  LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs));
2284  TripleAliases.append(begin(SystemZTriples), end(SystemZTriples));
2285  break;
2286  default:
2287  // By default, just rely on the standard lib directories and the original
2288  // triple.
2289  break;
2290  }
2291 
2292  // Always append the drivers target triple to the end, in case it doesn't
2293  // match any of our aliases.
2294  TripleAliases.push_back(TargetTriple.str());
2295 
2296  // Also include the multiarch variant if it's different.
2297  if (TargetTriple.str() != BiarchTriple.str())
2298  BiarchTripleAliases.push_back(BiarchTriple.str());
2299 }
2300 
2301 bool Generic_GCC::GCCInstallationDetector::ScanGCCForMultilibs(
2302  const llvm::Triple &TargetTriple, const ArgList &Args,
2303  StringRef Path, bool NeedsBiarchSuffix) {
2304  llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
2305  DetectedMultilibs Detected;
2306 
2307  // Android standalone toolchain could have multilibs for ARM and Thumb.
2308  // Debian mips multilibs behave more like the rest of the biarch ones,
2309  // so handle them there
2310  if (isArmOrThumbArch(TargetArch) && TargetTriple.isAndroid()) {
2311  // It should also work without multilibs in a simplified toolchain.
2312  findAndroidArmMultilibs(D, TargetTriple, Path, Args, Detected);
2313  } else if (TargetTriple.isMIPS()) {
2314  if (!findMIPSMultilibs(D, TargetTriple, Path, Args, Detected))
2315  return false;
2316  } else if (TargetTriple.isRISCV()) {
2317  findRISCVMultilibs(D, TargetTriple, Path, Args, Detected);
2318  } else if (isMSP430(TargetArch)) {
2319  findMSP430Multilibs(D, TargetTriple, Path, Args, Detected);
2320  } else if (TargetArch == llvm::Triple::avr) {
2321  // AVR has no multilibs.
2322  } else if (!findBiarchMultilibs(D, TargetTriple, Path, Args,
2323  NeedsBiarchSuffix, Detected)) {
2324  return false;
2325  }
2326 
2327  Multilibs = Detected.Multilibs;
2328  SelectedMultilib = Detected.SelectedMultilib;
2329  BiarchSibling = Detected.BiarchSibling;
2330 
2331  return true;
2332 }
2333 
2334 void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
2335  const llvm::Triple &TargetTriple, const ArgList &Args,
2336  const std::string &LibDir, StringRef CandidateTriple,
2337  bool NeedsBiarchSuffix) {
2338  llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
2339  // Locations relative to the system lib directory where GCC's triple-specific
2340  // directories might reside.
2341  struct GCCLibSuffix {
2342  // Path from system lib directory to GCC triple-specific directory.
2343  std::string LibSuffix;
2344  // Path from GCC triple-specific directory back to system lib directory.
2345  // This is one '..' component per component in LibSuffix.
2346  StringRef ReversePath;
2347  // Whether this library suffix is relevant for the triple.
2348  bool Active;
2349  } Suffixes[] = {
2350  // This is the normal place.
2351  {"gcc/" + CandidateTriple.str(), "../..", true},
2352 
2353  // Debian puts cross-compilers in gcc-cross.
2354  {"gcc-cross/" + CandidateTriple.str(), "../..",
2355  TargetTriple.getOS() != llvm::Triple::Solaris},
2356 
2357  // The Freescale PPC SDK has the gcc libraries in
2358  // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. Only do
2359  // this on Freescale triples, though, since some systems put a *lot* of
2360  // files in that location, not just GCC installation data.
2361  {CandidateTriple.str(), "..",
2362  TargetTriple.getVendor() == llvm::Triple::Freescale ||
2363  TargetTriple.getVendor() == llvm::Triple::OpenEmbedded},
2364 
2365  // Natively multiarch systems sometimes put the GCC triple-specific
2366  // directory within their multiarch lib directory, resulting in the
2367  // triple appearing twice.
2368  {CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), "../../..",
2369  TargetTriple.getOS() != llvm::Triple::Solaris},
2370 
2371  // Deal with cases (on Ubuntu) where the system architecture could be i386
2372  // but the GCC target architecture could be (say) i686.
2373  // FIXME: It may be worthwhile to generalize this and look for a second
2374  // triple.
2375  {"i386-linux-gnu/gcc/" + CandidateTriple.str(), "../../..",
2376  (TargetArch == llvm::Triple::x86 &&
2377  TargetTriple.getOS() != llvm::Triple::Solaris)},
2378  {"i386-gnu/gcc/" + CandidateTriple.str(), "../../..",
2379  (TargetArch == llvm::Triple::x86 &&
2380  TargetTriple.getOS() != llvm::Triple::Solaris)}};
2381 
2382  for (auto &Suffix : Suffixes) {
2383  if (!Suffix.Active)
2384  continue;
2385 
2386  StringRef LibSuffix = Suffix.LibSuffix;
2387  std::error_code EC;
2388  for (llvm::vfs::directory_iterator
2389  LI = D.getVFS().dir_begin(LibDir + "/" + LibSuffix, EC),
2390  LE;
2391  !EC && LI != LE; LI = LI.increment(EC)) {
2392  StringRef VersionText = llvm::sys::path::filename(LI->path());
2393  GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
2394  if (CandidateVersion.Major != -1) // Filter obviously bad entries.
2395  if (!CandidateGCCInstallPaths.insert(LI->path()).second)
2396  continue; // Saw this path before; no need to look at it again.
2397  if (CandidateVersion.isOlderThan(4, 1, 1))
2398  continue;
2399  if (CandidateVersion <= Version)
2400  continue;
2401 
2402  if (!ScanGCCForMultilibs(TargetTriple, Args, LI->path(),
2403  NeedsBiarchSuffix))
2404  continue;
2405 
2406  Version = CandidateVersion;
2407  GCCTriple.setTriple(CandidateTriple);
2408  // FIXME: We hack together the directory name here instead of
2409  // using LI to ensure stable path separators across Windows and
2410  // Linux.
2411  GCCInstallPath = (LibDir + "/" + LibSuffix + "/" + VersionText).str();
2412  GCCParentLibPath = (GCCInstallPath + "/../" + Suffix.ReversePath).str();
2413  IsValid = true;
2414  }
2415  }
2416 }
2417 
2418 bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
2419  const llvm::Triple &TargetTriple, const ArgList &Args,
2420  const SmallVectorImpl<StringRef> &CandidateTriples,
2421  const SmallVectorImpl<StringRef> &CandidateBiarchTriples) {
2422  for (StringRef CandidateTriple : CandidateTriples) {
2423  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
2424  return true;
2425  }
2426 
2427  for (StringRef CandidateTriple : CandidateBiarchTriples) {
2428  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
2429  return true;
2430  }
2431  return false;
2432 }
2433 
2434 bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
2435  const llvm::Triple &TargetTriple, const ArgList &Args,
2436  StringRef CandidateTriple, bool NeedsBiarchSuffix) {
2437  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
2438  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
2439  CandidateTriple.str());
2440  if (File) {
2442  File.get()->getBuffer().split(Lines, "\n");
2443  for (StringRef Line : Lines) {
2444  Line = Line.trim();
2445  // CURRENT=triple-version
2446  if (!Line.consume_front("CURRENT="))
2447  continue;
2448  // Process the config file pointed to by CURRENT.
2449  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ConfigFile =
2450  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/" +
2451  Line.str());
2452  std::pair<StringRef, StringRef> ActiveVersion = Line.rsplit('-');
2453  // List of paths to scan for libraries.
2454  SmallVector<StringRef, 4> GentooScanPaths;
2455  // Scan the Config file to find installed GCC libraries path.
2456  // Typical content of the GCC config file:
2457  // LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x:/usr/lib/gcc/
2458  // (continued from previous line) x86_64-pc-linux-gnu/4.9.x/32"
2459  // MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.x/man"
2460  // INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.x/info"
2461  // STDCXX_INCDIR="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4"
2462  // We are looking for the paths listed in LDPATH=... .
2463  if (ConfigFile) {
2464  SmallVector<StringRef, 2> ConfigLines;
2465  ConfigFile.get()->getBuffer().split(ConfigLines, "\n");
2466  for (StringRef ConfLine : ConfigLines) {
2467  ConfLine = ConfLine.trim();
2468  if (ConfLine.consume_front("LDPATH=")) {
2469  // Drop '"' from front and back if present.
2470  ConfLine.consume_back("\"");
2471  ConfLine.consume_front("\"");
2472  // Get all paths sperated by ':'
2473  ConfLine.split(GentooScanPaths, ':', -1, /*AllowEmpty*/ false);
2474  }
2475  }
2476  }
2477  // Test the path based on the version in /etc/env.d/gcc/config-{tuple}.
2478  std::string basePath = "/usr/lib/gcc/" + ActiveVersion.first.str() + "/"
2479  + ActiveVersion.second.str();
2480  GentooScanPaths.push_back(StringRef(basePath));
2481 
2482  // Scan all paths for GCC libraries.
2483  for (const auto &GentooScanPath : GentooScanPaths) {
2484  std::string GentooPath = D.SysRoot + std::string(GentooScanPath);
2485  if (D.getVFS().exists(GentooPath + "/crtbegin.o")) {
2486  if (!ScanGCCForMultilibs(TargetTriple, Args, GentooPath,
2487  NeedsBiarchSuffix))
2488  continue;
2489 
2490  Version = GCCVersion::Parse(ActiveVersion.second);
2491  GCCInstallPath = GentooPath;
2492  GCCParentLibPath = GentooPath + std::string("/../../..");
2493  GCCTriple.setTriple(ActiveVersion.first);
2494  IsValid = true;
2495  return true;
2496  }
2497  }
2498  }
2499  }
2500 
2501  return false;
2502 }
2503 
2504 Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
2505  const ArgList &Args)
2506  : ToolChain(D, Triple, Args), GCCInstallation(D),
2507  CudaInstallation(D, Triple, Args) {
2508  getProgramPaths().push_back(getDriver().getInstalledDir());
2509  if (getDriver().getInstalledDir() != getDriver().Dir)
2510  getProgramPaths().push_back(getDriver().Dir);
2511 }
2512 
2514 
2516  switch (AC) {
2518  if (!Preprocess)
2519  Preprocess.reset(new clang::driver::tools::gcc::Preprocessor(*this));
2520  return Preprocess.get();
2522  if (!Compile)
2523  Compile.reset(new tools::gcc::Compiler(*this));
2524  return Compile.get();
2525  default:
2526  return ToolChain::getTool(AC);
2527  }
2528 }
2529 
2531  return new tools::gnutools::Assembler(*this);
2532 }
2533 
2534 Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); }
2535 
2536 void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
2537  // Print the information about how we detected the GCC installation.
2538  GCCInstallation.print(OS);
2539  CudaInstallation.print(OS);
2540 }
2541 
2542 bool Generic_GCC::IsUnwindTablesDefault(const ArgList &Args) const {
2543  return getArch() == llvm::Triple::x86_64;
2544 }
2545 
2547  switch (getArch()) {
2548  case llvm::Triple::x86_64:
2549  return getTriple().isOSWindows();
2550  case llvm::Triple::ppc64:
2551  // Big endian PPC is PIC by default
2552  return !getTriple().isOSBinFormatMachO() && !getTriple().isMacOSX();
2553  case llvm::Triple::mips64:
2554  case llvm::Triple::mips64el:
2555  return true;
2556  default:
2557  return false;
2558  }
2559 }
2560 
2561 bool Generic_GCC::isPIEDefault() const { return false; }
2562 
2564  return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows();
2565 }
2566 
2568  switch (getTriple().getArch()) {
2569  case llvm::Triple::x86:
2570  case llvm::Triple::x86_64:
2571  case llvm::Triple::aarch64:
2572  case llvm::Triple::aarch64_be:
2573  case llvm::Triple::arm:
2574  case llvm::Triple::armeb:
2575  case llvm::Triple::avr:
2576  case llvm::Triple::bpfel:
2577  case llvm::Triple::bpfeb:
2578  case llvm::Triple::thumb:
2579  case llvm::Triple::thumbeb:
2580  case llvm::Triple::ppc:
2581  case llvm::Triple::ppc64:
2582  case llvm::Triple::ppc64le:
2583  case llvm::Triple::riscv32:
2584  case llvm::Triple::riscv64:
2585  case llvm::Triple::systemz:
2586  case llvm::Triple::mips:
2587  case llvm::Triple::mipsel:
2588  case llvm::Triple::mips64:
2589  case llvm::Triple::mips64el:
2590  case llvm::Triple::msp430:
2591  return true;
2592  case llvm::Triple::sparc:
2593  case llvm::Triple::sparcel:
2594  case llvm::Triple::sparcv9:
2595  if (getTriple().isOSFreeBSD() || getTriple().isOSOpenBSD() ||
2596  getTriple().isOSSolaris())
2597  return true;
2598  return false;
2599  default:
2600  return false;
2601  }
2602 }
2603 
2604 void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
2605  ArgStringList &CC1Args) const {
2606  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
2607  DriverArgs.hasArg(options::OPT_nostdincxx))
2608  return;
2609 
2610  switch (GetCXXStdlibType(DriverArgs)) {
2611  case ToolChain::CST_Libcxx:
2612  addLibCxxIncludePaths(DriverArgs, CC1Args);
2613  break;
2614 
2616  addLibStdCxxIncludePaths(DriverArgs, CC1Args);
2617  break;
2618  }
2619 }
2620 
2621 void
2622 Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
2623  llvm::opt::ArgStringList &CC1Args) const {
2624  // FIXME: The Linux behavior would probaby be a better approach here.
2625  addSystemInclude(DriverArgs, CC1Args,
2626  getDriver().SysRoot + "/usr/include/c++/v1");
2627 }
2628 
2629 void
2630 Generic_GCC::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
2631  llvm::opt::ArgStringList &CC1Args) const {
2632  // By default, we don't assume we know where libstdc++ might be installed.
2633  // FIXME: If we have a valid GCCInstallation, use it.
2634 }
2635 
2636 /// Helper to add the variant paths of a libstdc++ installation.
2638  Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple,
2639  StringRef TargetMultiarchTriple, Twine IncludeSuffix,
2640  const ArgList &DriverArgs, ArgStringList &CC1Args) const {
2641  if (!getVFS().exists(Base + Suffix))
2642  return false;
2643 
2644  addSystemInclude(DriverArgs, CC1Args, Base + Suffix);
2645 
2646  // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If
2647  // that path exists or we have neither a GCC nor target multiarch triple, use
2648  // this vanilla search path.
2649  if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) ||
2650  getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) {
2651  addSystemInclude(DriverArgs, CC1Args,
2652  Base + Suffix + "/" + GCCTriple + IncludeSuffix);
2653  } else {
2654  // Otherwise try to use multiarch naming schemes which have normalized the
2655  // triples and put the triple before the suffix.
2656  //
2657  // GCC surprisingly uses *both* the GCC triple with a multilib suffix and
2658  // the target triple, so we support that here.
2659  addSystemInclude(DriverArgs, CC1Args,
2660  Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix);
2661  addSystemInclude(DriverArgs, CC1Args,
2662  Base + "/" + TargetMultiarchTriple + Suffix);
2663  }
2664 
2665  addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward");
2666  return true;
2667 }
2668 
2669 llvm::opt::DerivedArgList *
2670 Generic_GCC::TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef,
2671  Action::OffloadKind DeviceOffloadKind) const {
2672 
2673  // If this tool chain is used for an OpenMP offloading device we have to make
2674  // sure we always generate a shared library regardless of the commands the
2675  // user passed to the host. This is required because the runtime library
2676  // is required to load the device image dynamically at run time.
2677  if (DeviceOffloadKind == Action::OFK_OpenMP) {
2678  DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
2679  const OptTable &Opts = getDriver().getOpts();
2680 
2681  // Request the shared library. Given that these options are decided
2682  // implicitly, they do not refer to any base argument.
2683  DAL->AddFlagArg(/*BaseArg=*/nullptr, Opts.getOption(options::OPT_shared));
2684  DAL->AddFlagArg(/*BaseArg=*/nullptr, Opts.getOption(options::OPT_fPIC));
2685 
2686  // Filter all the arguments we don't care passing to the offloading
2687  // toolchain as they can mess up with the creation of a shared library.
2688  for (auto *A : Args) {
2689  switch ((options::ID)A->getOption().getID()) {
2690  default:
2691  DAL->append(A);
2692  break;
2693  case options::OPT_shared:
2694  case options::OPT_dynamic:
2695  case options::OPT_static:
2696  case options::OPT_fPIC:
2697  case options::OPT_fno_PIC:
2698  case options::OPT_fpic:
2699  case options::OPT_fno_pic:
2700  case options::OPT_fPIE:
2701  case options::OPT_fno_PIE:
2702  case options::OPT_fpie:
2703  case options::OPT_fno_pie:
2704  break;
2705  }
2706  }
2707  return DAL;
2708  }
2709  return nullptr;
2710 }
2711 
2712 void Generic_ELF::anchor() {}
2713 
2714 void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs,
2715  ArgStringList &CC1Args,
2716  Action::OffloadKind) const {
2718  bool UseInitArrayDefault =
2719  getTriple().getArch() == llvm::Triple::aarch64 ||
2720  getTriple().getArch() == llvm::Triple::aarch64_be ||
2721  (getTriple().isOSFreeBSD() &&
2722  getTriple().getOSMajorVersion() >= 12) ||
2723  (getTriple().getOS() == llvm::Triple::Linux &&
2724  ((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
2725  getTriple().isAndroid())) ||
2726  getTriple().getOS() == llvm::Triple::NaCl ||
2727  (getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
2728  !getTriple().hasEnvironment()) ||
2729  getTriple().getOS() == llvm::Triple::Solaris ||
2730  getTriple().getArch() == llvm::Triple::riscv32 ||
2731  getTriple().getArch() == llvm::Triple::riscv64;
2732 
2733  if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
2734  options::OPT_fno_use_init_array, UseInitArrayDefault))
2735  CC1Args.push_back("-fuse-init-array");
2736 }
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:1760
bool isNoExecStackDefault() const override
Test whether this toolchaind defaults to non-executable stacks.
Definition: Linux.cpp:982
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: Linux.cpp:977
virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const
Definition: Linux.cpp:510
Tool * buildLinker() const override
Definition: Gnu.cpp:2534
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:2515
bool getBiarchSibling(Multilib &M) const
Get the biarch sibling multilib (if it exists).
Definition: Gnu.cpp:1869
static bool findMipsAndroidMultilibs(llvm::vfs::FileSystem &VFS, StringRef Path, const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:1039
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:538
static GCCVersion Parse(StringRef VersionText)
Parse a GCCVersion object out of a string of text.
Definition: Gnu.cpp:1690
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:95
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:541
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:2561
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
bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC, const llvm::opt::ArgList &Args, bool ForceStaticHostRuntime=false, bool IsOffloadingHost=false, bool GompNeedsRT=false)
Returns true, if an OpenMP runtime has been added.
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:1855
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:944
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:926
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:880
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
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
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:307
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:930
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:911
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:2604
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
Definition: Types.cpp:43
const AnnotatedLine * Line
static bool findMipsMuslMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:1078
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:2546
#define V(N, I)
Definition: ASTContext.h:2913
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:1110
Tool * buildAssembler() const override
Definition: Gnu.cpp:2530
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:2542
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:2536
static bool findMipsImgMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:1282
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:868
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:1737
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:2622
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:1489
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:922
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:637
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:1653
static bool findBiarchMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, bool NeedsBiarchSuffix, DetectedMultilibs &Result)
Definition: Gnu.cpp:1544
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: Gnu.cpp:2563
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
Definition: ToolChain.cpp:845
Dataflow Directional Tag Classes.
Generic_GCC(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: Gnu.cpp:2504
static bool isMSP430(llvm::Triple::ArchType Arch)
Definition: Gnu.cpp:940
const std::string & getCCCGenericGCCName() const
Name to use when invoking gcc/g++.
Definition: Driver.h:299
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:2714
static bool findMipsCsMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp:948
bool IsIntegratedAssemblerDefault() const override
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: Gnu.cpp:2567
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:2670
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:2630
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 LE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:240
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:303
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:2637
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:1761
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:935
bool isLLVMIR(ID Id)
Is this LLVM IR.
Definition: Types.cpp:178
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:1447
static void findRISCVMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
Definition: Gnu.cpp:1509
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:851
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