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