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