clang  9.0.0svn
Gnu.cpp
Go to the documentation of this file.
1 //===--- Gnu.cpp - Gnu Tool and ToolChain Implementations -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Gnu.h"
10 #include "Arch/ARM.h"
11 #include "Arch/Mips.h"
12 #include "Arch/PPC.h"
13 #include "Arch/RISCV.h"
14 #include "Arch/Sparc.h"
15 #include "Arch/SystemZ.h"
16 #include "CommonArgs.h"
17 #include "Linux.h"
18 #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX
20 #include "clang/Driver/Driver.h"
22 #include "clang/Driver/Options.h"
23 #include "clang/Driver/Tool.h"
24 #include "clang/Driver/ToolChain.h"
25 #include "llvm/Option/ArgList.h"
26 #include "llvm/Support/CodeGen.h"
27 #include "llvm/Support/Path.h"
28 #include "llvm/Support/TargetParser.h"
29 #include "llvm/Support/VirtualFileSystem.h"
30 #include <system_error>
31 
32 using namespace clang::driver;
33 using namespace clang::driver::toolchains;
34 using namespace clang;
35 using namespace llvm::opt;
36 
38 
39 void tools::GnuTool::anchor() {}
40 
41 static bool forwardToGCC(const Option &O) {
42  // Don't forward inputs from the original command line. They are added from
43  // InputInfoList.
44  return O.getKind() != Option::InputClass &&
45  !O.hasFlag(options::DriverOption) && !O.hasFlag(options::LinkerInput);
46 }
47 
48 // Switch CPU names not recognized by GNU assembler to a close CPU that it does
49 // recognize, instead of a lower march from being picked in the absence of a cpu
50 // flag.
51 static void normalizeCPUNamesForAssembler(const ArgList &Args,
52  ArgStringList &CmdArgs) {
53  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
54  StringRef CPUArg(A->getValue());
55  if (CPUArg.equals_lower("krait"))
56  CmdArgs.push_back("-mcpu=cortex-a15");
57  else if(CPUArg.equals_lower("kryo"))
58  CmdArgs.push_back("-mcpu=cortex-a57");
59  else
60  Args.AddLastArg(CmdArgs, options::OPT_mcpu_EQ);
61  }
62 }
63 
65  const InputInfo &Output,
66  const InputInfoList &Inputs,
67  const ArgList &Args,
68  const char *LinkingOutput) const {
69  const Driver &D = getToolChain().getDriver();
70  ArgStringList CmdArgs;
71 
72  for (const auto &A : Args) {
73  if (forwardToGCC(A->getOption())) {
74  // It is unfortunate that we have to claim here, as this means
75  // we will basically never report anything interesting for
76  // platforms using a generic gcc, even if we are just using gcc
77  // to get to the assembler.
78  A->claim();
79 
80  // Don't forward any -g arguments to assembly steps.
81  if (isa<AssembleJobAction>(JA) &&
82  A->getOption().matches(options::OPT_g_Group))
83  continue;
84 
85  // Don't forward any -W arguments to assembly and link steps.
86  if ((isa<AssembleJobAction>(JA) || isa<LinkJobAction>(JA)) &&
87  A->getOption().matches(options::OPT_W_Group))
88  continue;
89 
90  // Don't forward -mno-unaligned-access since GCC doesn't understand
91  // it and because it doesn't affect the assembly or link steps.
92  if ((isa<AssembleJobAction>(JA) || isa<LinkJobAction>(JA)) &&
93  (A->getOption().matches(options::OPT_munaligned_access) ||
94  A->getOption().matches(options::OPT_mno_unaligned_access)))
95  continue;
96 
97  A->render(Args, CmdArgs);
98  }
99  }
100 
101  RenderExtraToolArgs(JA, CmdArgs);
102 
103  // If using a driver driver, force the arch.
104  if (getToolChain().getTriple().isOSDarwin()) {
105  CmdArgs.push_back("-arch");
106  CmdArgs.push_back(
107  Args.MakeArgString(getToolChain().getDefaultUniversalArchName()));
108  }
109 
110  // Try to force gcc to match the tool chain we want, if we recognize
111  // the arch.
112  //
113  // FIXME: The triple class should directly provide the information we want
114  // here.
115  switch (getToolChain().getArch()) {
116  default:
117  break;
118  case llvm::Triple::x86:
119  case llvm::Triple::ppc:
120  CmdArgs.push_back("-m32");
121  break;
122  case llvm::Triple::x86_64:
123  case llvm::Triple::ppc64:
124  case llvm::Triple::ppc64le:
125  CmdArgs.push_back("-m64");
126  break;
127  case llvm::Triple::sparcel:
128  CmdArgs.push_back("-EL");
129  break;
130  }
131 
132  if (Output.isFilename()) {
133  CmdArgs.push_back("-o");
134  CmdArgs.push_back(Output.getFilename());
135  } else {
136  assert(Output.isNothing() && "Unexpected output");
137  CmdArgs.push_back("-fsyntax-only");
138  }
139 
140  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
141 
142  // Only pass -x if gcc will understand it; otherwise hope gcc
143  // understands the suffix correctly. The main use case this would go
144  // wrong in is for linker inputs if they happened to have an odd
145  // suffix; really the only way to get this to happen is a command
146  // like '-x foobar a.c' which will treat a.c like a linker input.
147  //
148  // FIXME: For the linker case specifically, can we safely convert
149  // inputs into '-Wl,' options?
150  for (const auto &II : Inputs) {
151  // Don't try to pass LLVM or AST inputs to a generic gcc.
152  if (types::isLLVMIR(II.getType()))
153  D.Diag(clang::diag::err_drv_no_linker_llvm_support)
154  << getToolChain().getTripleString();
155  else if (II.getType() == types::TY_AST)
156  D.Diag(diag::err_drv_no_ast_support) << getToolChain().getTripleString();
157  else if (II.getType() == types::TY_ModuleFile)
158  D.Diag(diag::err_drv_no_module_support)
159  << getToolChain().getTripleString();
160 
161  if (types::canTypeBeUserSpecified(II.getType())) {
162  CmdArgs.push_back("-x");
163  CmdArgs.push_back(types::getTypeName(II.getType()));
164  }
165 
166  if (II.isFilename())
167  CmdArgs.push_back(II.getFilename());
168  else {
169  const Arg &A = II.getInputArg();
170 
171  // Reverse translate some rewritten options.
172  if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
173  CmdArgs.push_back("-lstdc++");
174  continue;
175  }
176 
177  // Don't render as input, we need gcc to do the translations.
178  A.render(Args, CmdArgs);
179  }
180  }
181 
182  const std::string &customGCCName = D.getCCCGenericGCCName();
183  const char *GCCName;
184  if (!customGCCName.empty())
185  GCCName = customGCCName.c_str();
186  else if (D.CCCIsCXX()) {
187  GCCName = "g++";
188  } else
189  GCCName = "gcc";
190 
191  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(GCCName));
192  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
193 }
194 
196  const JobAction &JA, ArgStringList &CmdArgs) const {
197  CmdArgs.push_back("-E");
198 }
199 
201  ArgStringList &CmdArgs) const {
202  const Driver &D = getToolChain().getDriver();
203 
204  switch (JA.getType()) {
205  // If -flto, etc. are present then make sure not to force assembly output.
206  case types::TY_LLVM_IR:
207  case types::TY_LTO_IR:
208  case types::TY_LLVM_BC:
209  case types::TY_LTO_BC:
210  CmdArgs.push_back("-c");
211  break;
212  // We assume we've got an "integrated" assembler in that gcc will produce an
213  // object file itself.
214  case types::TY_Object:
215  CmdArgs.push_back("-c");
216  break;
217  case types::TY_PP_Asm:
218  CmdArgs.push_back("-S");
219  break;
220  case types::TY_Nothing:
221  CmdArgs.push_back("-fsyntax-only");
222  break;
223  default:
224  D.Diag(diag::err_drv_invalid_gcc_output_type) << getTypeName(JA.getType());
225  }
226 }
227 
229  ArgStringList &CmdArgs) const {
230  // The types are (hopefully) good enough.
231 }
232 
233 // On Arm the endianness of the output file is determined by the target and
234 // can be overridden by the pseudo-target flags '-mlittle-endian'/'-EL' and
235 // '-mbig-endian'/'-EB'. Unlike other targets the flag does not result in a
236 // normalized triple so we must handle the flag here.
237 static bool isArmBigEndian(const llvm::Triple &Triple,
238  const ArgList &Args) {
239  bool IsBigEndian = false;
240  switch (Triple.getArch()) {
241  case llvm::Triple::armeb:
242  case llvm::Triple::thumbeb:
243  IsBigEndian = true;
244  LLVM_FALLTHROUGH;
245  case llvm::Triple::arm:
246  case llvm::Triple::thumb:
247  if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
248  options::OPT_mbig_endian))
249  IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
250  break;
251  default:
252  break;
253  }
254  return IsBigEndian;
255 }
256 
257 static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) {
258  switch (T.getArch()) {
259  case llvm::Triple::x86:
260  if (T.isOSIAMCU())
261  return "elf_iamcu";
262  return "elf_i386";
263  case llvm::Triple::aarch64:
264  return "aarch64linux";
265  case llvm::Triple::aarch64_be:
266  return "aarch64linuxb";
267  case llvm::Triple::arm:
268  case llvm::Triple::thumb:
269  case llvm::Triple::armeb:
270  case llvm::Triple::thumbeb:
271  return isArmBigEndian(T, Args) ? "armelfb_linux_eabi" : "armelf_linux_eabi";
272  case llvm::Triple::ppc:
273  return "elf32ppclinux";
274  case llvm::Triple::ppc64:
275  return "elf64ppc";
276  case llvm::Triple::ppc64le:
277  return "elf64lppc";
278  case llvm::Triple::riscv32:
279  return "elf32lriscv";
280  case llvm::Triple::riscv64:
281  return "elf64lriscv";
282  case llvm::Triple::sparc:
283  case llvm::Triple::sparcel:
284  return "elf32_sparc";
285  case llvm::Triple::sparcv9:
286  return "elf64_sparc";
287  case llvm::Triple::mips:
288  return "elf32btsmip";
289  case llvm::Triple::mipsel:
290  return "elf32ltsmip";
291  case llvm::Triple::mips64:
292  if (tools::mips::hasMipsAbiArg(Args, "n32") ||
293  T.getEnvironment() == llvm::Triple::GNUABIN32)
294  return "elf32btsmipn32";
295  return "elf64btsmip";
296  case llvm::Triple::mips64el:
297  if (tools::mips::hasMipsAbiArg(Args, "n32") ||
298  T.getEnvironment() == llvm::Triple::GNUABIN32)
299  return "elf32ltsmipn32";
300  return "elf64ltsmip";
301  case llvm::Triple::systemz:
302  return "elf64_s390";
303  case llvm::Triple::x86_64:
304  if (T.getEnvironment() == llvm::Triple::GNUX32)
305  return "elf32_x86_64";
306  return "elf_x86_64";
307  default:
308  return nullptr;
309  }
310 }
311 
312 static bool getPIE(const ArgList &Args, const toolchains::Linux &ToolChain) {
313  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
314  Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
315  return false;
316 
317  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
318  options::OPT_nopie);
319  if (!A)
320  return ToolChain.isPIEDefault();
321  return A->getOption().matches(options::OPT_pie);
322 }
323 
324 static bool getStaticPIE(const ArgList &Args,
325  const toolchains::Linux &ToolChain) {
326  bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
327  // -no-pie is an alias for -nopie. So, handling -nopie takes care of
328  // -no-pie as well.
329  if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
330  const Driver &D = ToolChain.getDriver();
331  const llvm::opt::OptTable &Opts = D.getOpts();
332  const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
333  const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
334  D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
335  }
336  return HasStaticPIE;
337 }
338 
339 static bool getStatic(const ArgList &Args) {
340  return Args.hasArg(options::OPT_static) &&
341  !Args.hasArg(options::OPT_static_pie);
342 }
343 
345  const InputInfo &Output,
346  const InputInfoList &Inputs,
347  const ArgList &Args,
348  const char *LinkingOutput) const {
350  static_cast<const toolchains::Linux &>(getToolChain());
351  const Driver &D = ToolChain.getDriver();
352 
353  const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
354 
355  const llvm::Triple::ArchType Arch = ToolChain.getArch();
356  const bool isAndroid = ToolChain.getTriple().isAndroid();
357  const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
358  const bool IsPIE = getPIE(Args, ToolChain);
359  const bool IsStaticPIE = getStaticPIE(Args, ToolChain);
360  const bool IsStatic = getStatic(Args);
361  const bool HasCRTBeginEndFiles =
362  ToolChain.getTriple().hasEnvironment() ||
363  (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
364 
365  ArgStringList CmdArgs;
366 
367  // Silence warning for "clang -g foo.o -o foo"
368  Args.ClaimAllArgs(options::OPT_g_Group);
369  // and "clang -emit-llvm foo.o -o foo"
370  Args.ClaimAllArgs(options::OPT_emit_llvm);
371  // and for "clang -w foo.o -o foo". Other warning options are already
372  // handled somewhere else.
373  Args.ClaimAllArgs(options::OPT_w);
374 
375  if (!D.SysRoot.empty())
376  CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
377 
378  if (IsPIE)
379  CmdArgs.push_back("-pie");
380 
381  if (IsStaticPIE) {
382  CmdArgs.push_back("-static");
383  CmdArgs.push_back("-pie");
384  CmdArgs.push_back("--no-dynamic-linker");
385  }
386 
387  if (ToolChain.isNoExecStackDefault()) {
388  CmdArgs.push_back("-z");
389  CmdArgs.push_back("noexecstack");
390  }
391 
392  if (Args.hasArg(options::OPT_rdynamic))
393  CmdArgs.push_back("-export-dynamic");
394 
395  if (Args.hasArg(options::OPT_s))
396  CmdArgs.push_back("-s");
397 
398  if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) {
399  bool IsBigEndian = isArmBigEndian(Triple, Args);
400  if (IsBigEndian)
401  arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
402  IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be;
403  CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
404  }
405 
406  // Most Android ARM64 targets should enable the linker fix for erratum
407  // 843419. Only non-Cortex-A53 devices are allowed to skip this flag.
408  if (Arch == llvm::Triple::aarch64 && isAndroid) {
409  std::string CPU = getCPUName(Args, Triple);
410  if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53")
411  CmdArgs.push_back("--fix-cortex-a53-843419");
412  }
413 
414  // Android does not allow shared text relocations. Emit a warning if the
415  // user's code contains any.
416  if (isAndroid)
417  CmdArgs.push_back("--warn-shared-textrel");
418 
419  for (const auto &Opt : ToolChain.ExtraOpts)
420  CmdArgs.push_back(Opt.c_str());
421 
422  CmdArgs.push_back("--eh-frame-hdr");
423 
424  if (const char *LDMOption = getLDMOption(ToolChain.getTriple(), Args)) {
425  CmdArgs.push_back("-m");
426  CmdArgs.push_back(LDMOption);
427  } else {
428  D.Diag(diag::err_target_unknown_triple) << Triple.str();
429  return;
430  }
431 
432  if (IsStatic) {
433  if (Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb ||
434  Arch == llvm::Triple::thumb || Arch == llvm::Triple::thumbeb)
435  CmdArgs.push_back("-Bstatic");
436  else
437  CmdArgs.push_back("-static");
438  } else if (Args.hasArg(options::OPT_shared)) {
439  CmdArgs.push_back("-shared");
440  }
441 
442  if (!IsStatic) {
443  if (Args.hasArg(options::OPT_rdynamic))
444  CmdArgs.push_back("-export-dynamic");
445 
446  if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) {
447  const std::string Loader =
448  D.DyldPrefix + ToolChain.getDynamicLinker(Args);
449  CmdArgs.push_back("-dynamic-linker");
450  CmdArgs.push_back(Args.MakeArgString(Loader));
451  }
452  }
453 
454  CmdArgs.push_back("-o");
455  CmdArgs.push_back(Output.getFilename());
456 
457  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
458  if (!isAndroid && !IsIAMCU) {
459  const char *crt1 = nullptr;
460  if (!Args.hasArg(options::OPT_shared)) {
461  if (Args.hasArg(options::OPT_pg))
462  crt1 = "gcrt1.o";
463  else if (IsPIE)
464  crt1 = "Scrt1.o";
465  else if (IsStaticPIE)
466  crt1 = "rcrt1.o";
467  else
468  crt1 = "crt1.o";
469  }
470  if (crt1)
471  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
472 
473  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
474  }
475 
476  if (IsIAMCU)
477  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
478  else if (HasCRTBeginEndFiles) {
479  std::string P;
480  if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT &&
481  !isAndroid) {
482  std::string crtbegin = ToolChain.getCompilerRT(Args, "crtbegin",
484  if (ToolChain.getVFS().exists(crtbegin))
485  P = crtbegin;
486  }
487  if (P.empty()) {
488  const char *crtbegin;
489  if (IsStatic)
490  crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o";
491  else if (Args.hasArg(options::OPT_shared))
492  crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o";
493  else if (IsPIE || IsStaticPIE)
494  crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o";
495  else
496  crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o";
497  P = ToolChain.GetFilePath(crtbegin);
498  }
499  CmdArgs.push_back(Args.MakeArgString(P));
500  }
501 
502  // Add crtfastmath.o if available and fast math is enabled.
503  ToolChain.AddFastMathRuntimeIfAvailable(Args, CmdArgs);
504  }
505 
506  Args.AddAllArgs(CmdArgs, options::OPT_L);
507  Args.AddAllArgs(CmdArgs, options::OPT_u);
508 
509  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
510 
511  if (D.isUsingLTO()) {
512  assert(!Inputs.empty() && "Must have at least one input.");
513  AddGoldPlugin(ToolChain, Args, CmdArgs, Output, Inputs[0],
514  D.getLTOMode() == LTOK_Thin);
515  }
516 
517  if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
518  CmdArgs.push_back("--no-demangle");
519 
520  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
521  bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
522  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
523  // The profile runtime also needs access to system libraries.
524  getToolChain().addProfileRTLibs(Args, CmdArgs);
525 
526  if (D.CCCIsCXX() &&
527  !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
528  if (ToolChain.ShouldLinkCXXStdlib(Args)) {
529  bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
530  !Args.hasArg(options::OPT_static);
531  if (OnlyLibstdcxxStatic)
532  CmdArgs.push_back("-Bstatic");
533  ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
534  if (OnlyLibstdcxxStatic)
535  CmdArgs.push_back("-Bdynamic");
536  }
537  CmdArgs.push_back("-lm");
538  }
539  // Silence warnings when linking C code with a C++ '-stdlib' argument.
540  Args.ClaimAllArgs(options::OPT_stdlib_EQ);
541 
542  if (!Args.hasArg(options::OPT_nostdlib)) {
543  if (!Args.hasArg(options::OPT_nodefaultlibs)) {
544  if (IsStatic || IsStaticPIE)
545  CmdArgs.push_back("--start-group");
546 
547  if (NeedsSanitizerDeps)
548  linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
549 
550  if (NeedsXRayDeps)
551  linkXRayRuntimeDeps(ToolChain, CmdArgs);
552 
553  bool WantPthread = Args.hasArg(options::OPT_pthread) ||
554  Args.hasArg(options::OPT_pthreads);
555 
556  // FIXME: Only pass GompNeedsRT = true for platforms with libgomp that
557  // require librt. Most modern Linux platforms do, but some may not.
558  if (addOpenMPRuntime(CmdArgs, ToolChain, Args,
560  /* GompNeedsRT= */ true))
561  // OpenMP runtimes implies pthreads when using the GNU toolchain.
562  // FIXME: Does this really make sense for all GNU toolchains?
563  WantPthread = true;
564 
565  AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
566 
567  if (WantPthread && !isAndroid)
568  CmdArgs.push_back("-lpthread");
569 
570  if (Args.hasArg(options::OPT_fsplit_stack))
571  CmdArgs.push_back("--wrap=pthread_create");
572 
573  if (!Args.hasArg(options::OPT_nolibc))
574  CmdArgs.push_back("-lc");
575 
576  // Add IAMCU specific libs, if needed.
577  if (IsIAMCU)
578  CmdArgs.push_back("-lgloss");
579 
580  if (IsStatic || IsStaticPIE)
581  CmdArgs.push_back("--end-group");
582  else
583  AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
584 
585  // Add IAMCU specific libs (outside the group), if needed.
586  if (IsIAMCU) {
587  CmdArgs.push_back("--as-needed");
588  CmdArgs.push_back("-lsoftfp");
589  CmdArgs.push_back("--no-as-needed");
590  }
591  }
592 
593  if (!Args.hasArg(options::OPT_nostartfiles) && !IsIAMCU) {
594  if (HasCRTBeginEndFiles) {
595  std::string P;
596  if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT &&
597  !isAndroid) {
598  std::string crtend = ToolChain.getCompilerRT(Args, "crtend",
600  if (ToolChain.getVFS().exists(crtend))
601  P = crtend;
602  }
603  if (P.empty()) {
604  const char *crtend;
605  if (Args.hasArg(options::OPT_shared))
606  crtend = isAndroid ? "crtend_so.o" : "crtendS.o";
607  else if (IsPIE || IsStaticPIE)
608  crtend = isAndroid ? "crtend_android.o" : "crtendS.o";
609  else
610  crtend = isAndroid ? "crtend_android.o" : "crtend.o";
611  P = ToolChain.GetFilePath(crtend);
612  }
613  CmdArgs.push_back(Args.MakeArgString(P));
614  }
615  if (!isAndroid)
616  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
617  }
618  }
619 
620  // Add OpenMP offloading linker script args if required.
621  AddOpenMPLinkerScript(getToolChain(), C, Output, Inputs, Args, CmdArgs, JA);
622 
623  // Add HIP offloading linker script args if required.
624  AddHIPLinkerScript(getToolChain(), C, Output, Inputs, Args, CmdArgs, JA,
625  *this);
626 
627  const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
628  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
629 }
630 
632  const JobAction &JA,
633  const InputInfo &Output,
634  const InputInfoList &Inputs,
635  const ArgList &Args,
636  const char *LinkingOutput) const {
637  const auto &D = getToolChain().getDriver();
638 
639  claimNoWarnArgs(Args);
640 
641  ArgStringList CmdArgs;
642 
643  llvm::Reloc::Model RelocationModel;
644  unsigned PICLevel;
645  bool IsPIE;
646  std::tie(RelocationModel, PICLevel, IsPIE) =
647  ParsePICArgs(getToolChain(), Args);
648 
649  if (const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ)) {
650  if (A->getOption().getID() == options::OPT_gz) {
651  CmdArgs.push_back("--compress-debug-sections");
652  } else {
653  StringRef Value = A->getValue();
654  if (Value == "none" || Value == "zlib" || Value == "zlib-gnu") {
655  CmdArgs.push_back(
656  Args.MakeArgString("--compress-debug-sections=" + Twine(Value)));
657  } else {
658  D.Diag(diag::err_drv_unsupported_option_argument)
659  << A->getOption().getName() << Value;
660  }
661  }
662  }
663 
664  if (getToolChain().isNoExecStackDefault()) {
665  CmdArgs.push_back("--noexecstack");
666  }
667 
668  switch (getToolChain().getArch()) {
669  default:
670  break;
671  // Add --32/--64 to make sure we get the format we want.
672  // This is incomplete
673  case llvm::Triple::x86:
674  CmdArgs.push_back("--32");
675  break;
676  case llvm::Triple::x86_64:
677  if (getToolChain().getTriple().getEnvironment() == llvm::Triple::GNUX32)
678  CmdArgs.push_back("--x32");
679  else
680  CmdArgs.push_back("--64");
681  break;
682  case llvm::Triple::ppc: {
683  CmdArgs.push_back("-a32");
684  CmdArgs.push_back("-mppc");
685  CmdArgs.push_back(
686  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
687  break;
688  }
689  case llvm::Triple::ppc64: {
690  CmdArgs.push_back("-a64");
691  CmdArgs.push_back("-mppc64");
692  CmdArgs.push_back(
693  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
694  break;
695  }
696  case llvm::Triple::ppc64le: {
697  CmdArgs.push_back("-a64");
698  CmdArgs.push_back("-mppc64");
699  CmdArgs.push_back("-mlittle-endian");
700  CmdArgs.push_back(
701  ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple())));
702  break;
703  }
704  case llvm::Triple::riscv32:
705  case llvm::Triple::riscv64: {
706  StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
707  CmdArgs.push_back("-mabi");
708  CmdArgs.push_back(ABIName.data());
709  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
710  StringRef MArch = A->getValue();
711  CmdArgs.push_back("-march");
712  CmdArgs.push_back(MArch.data());
713  }
714  break;
715  }
716  case llvm::Triple::sparc:
717  case llvm::Triple::sparcel: {
718  CmdArgs.push_back("-32");
719  std::string CPU = getCPUName(Args, getToolChain().getTriple());
720  CmdArgs.push_back(
721  sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
722  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
723  break;
724  }
725  case llvm::Triple::sparcv9: {
726  CmdArgs.push_back("-64");
727  std::string CPU = getCPUName(Args, getToolChain().getTriple());
728  CmdArgs.push_back(
729  sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
730  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
731  break;
732  }
733  case llvm::Triple::arm:
734  case llvm::Triple::armeb:
735  case llvm::Triple::thumb:
736  case llvm::Triple::thumbeb: {
737  const llvm::Triple &Triple2 = getToolChain().getTriple();
738  CmdArgs.push_back(isArmBigEndian(Triple2, Args) ? "-EB" : "-EL");
739  switch (Triple2.getSubArch()) {
740  case llvm::Triple::ARMSubArch_v7:
741  CmdArgs.push_back("-mfpu=neon");
742  break;
743  case llvm::Triple::ARMSubArch_v8:
744  CmdArgs.push_back("-mfpu=crypto-neon-fp-armv8");
745  break;
746  default:
747  break;
748  }
749 
750  switch (arm::getARMFloatABI(getToolChain(), Args)) {
751  case arm::FloatABI::Invalid: llvm_unreachable("must have an ABI!");
752  case arm::FloatABI::Soft:
753  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=soft"));
754  break;
755  case arm::FloatABI::SoftFP:
756  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=softfp"));
757  break;
758  case arm::FloatABI::Hard:
759  CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=hard"));
760  break;
761  }
762 
763  Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
764  normalizeCPUNamesForAssembler(Args, CmdArgs);
765 
766  Args.AddLastArg(CmdArgs, options::OPT_mfpu_EQ);
767  break;
768  }
769  case llvm::Triple::aarch64:
770  case llvm::Triple::aarch64_be: {
771  CmdArgs.push_back(
772  getToolChain().getArch() == llvm::Triple::aarch64_be ? "-EB" : "-EL");
773  Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
774  normalizeCPUNamesForAssembler(Args, CmdArgs);
775 
776  break;
777  }
778  case llvm::Triple::mips:
779  case llvm::Triple::mipsel:
780  case llvm::Triple::mips64:
781  case llvm::Triple::mips64el: {
782  StringRef CPUName;
783  StringRef ABIName;
784  mips::getMipsCPUAndABI(Args, getToolChain().getTriple(), CPUName, ABIName);
785  ABIName = mips::getGnuCompatibleMipsABIName(ABIName);
786 
787  CmdArgs.push_back("-march");
788  CmdArgs.push_back(CPUName.data());
789 
790  CmdArgs.push_back("-mabi");
791  CmdArgs.push_back(ABIName.data());
792 
793  // -mno-shared should be emitted unless -fpic, -fpie, -fPIC, -fPIE,
794  // or -mshared (not implemented) is in effect.
795  if (RelocationModel == llvm::Reloc::Static)
796  CmdArgs.push_back("-mno-shared");
797 
798  // LLVM doesn't support -mplt yet and acts as if it is always given.
799  // However, -mplt has no effect with the N64 ABI.
800  if (ABIName != "64" && !Args.hasArg(options::OPT_mno_abicalls))
801  CmdArgs.push_back("-call_nonpic");
802 
803  if (getToolChain().getTriple().isLittleEndian())
804  CmdArgs.push_back("-EL");
805  else
806  CmdArgs.push_back("-EB");
807 
808  if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
809  if (StringRef(A->getValue()) == "2008")
810  CmdArgs.push_back(Args.MakeArgString("-mnan=2008"));
811  }
812 
813  // Add the last -mfp32/-mfpxx/-mfp64 or -mfpxx if it is enabled by default.
814  if (Arg *A = Args.getLastArg(options::OPT_mfp32, options::OPT_mfpxx,
815  options::OPT_mfp64)) {
816  A->claim();
817  A->render(Args, CmdArgs);
818  } else if (mips::shouldUseFPXX(
819  Args, getToolChain().getTriple(), CPUName, ABIName,
820  mips::getMipsFloatABI(getToolChain().getDriver(), Args)))
821  CmdArgs.push_back("-mfpxx");
822 
823  // Pass on -mmips16 or -mno-mips16. However, the assembler equivalent of
824  // -mno-mips16 is actually -no-mips16.
825  if (Arg *A =
826  Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16)) {
827  if (A->getOption().matches(options::OPT_mips16)) {
828  A->claim();
829  A->render(Args, CmdArgs);
830  } else {
831  A->claim();
832  CmdArgs.push_back("-no-mips16");
833  }
834  }
835 
836  Args.AddLastArg(CmdArgs, options::OPT_mmicromips,
837  options::OPT_mno_micromips);
838  Args.AddLastArg(CmdArgs, options::OPT_mdsp, options::OPT_mno_dsp);
839  Args.AddLastArg(CmdArgs, options::OPT_mdspr2, options::OPT_mno_dspr2);
840 
841  if (Arg *A = Args.getLastArg(options::OPT_mmsa, options::OPT_mno_msa)) {
842  // Do not use AddLastArg because not all versions of MIPS assembler
843  // support -mmsa / -mno-msa options.
844  if (A->getOption().matches(options::OPT_mmsa))
845  CmdArgs.push_back(Args.MakeArgString("-mmsa"));
846  }
847 
848  Args.AddLastArg(CmdArgs, options::OPT_mhard_float,
849  options::OPT_msoft_float);
850 
851  Args.AddLastArg(CmdArgs, options::OPT_mdouble_float,
852  options::OPT_msingle_float);
853 
854  Args.AddLastArg(CmdArgs, options::OPT_modd_spreg,
855  options::OPT_mno_odd_spreg);
856 
857  AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
858  break;
859  }
860  case llvm::Triple::systemz: {
861  // Always pass an -march option, since our default of z10 is later
862  // than the GNU assembler's default.
863  StringRef CPUName = systemz::getSystemZTargetCPU(Args);
864  CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName));
865  break;
866  }
867  }
868 
869  Args.AddAllArgs(CmdArgs, options::OPT_I);
870  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
871 
872  CmdArgs.push_back("-o");
873  CmdArgs.push_back(Output.getFilename());
874 
875  for (const auto &II : Inputs)
876  CmdArgs.push_back(II.getFilename());
877 
878  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
879  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
880 
881  // Handle the debug info splitting at object creation time if we're
882  // creating an object.
883  // TODO: Currently only works on linux with newer objcopy.
884  if (Args.hasArg(options::OPT_gsplit_dwarf) &&
885  getToolChain().getTriple().isOSLinux())
886  SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
887  SplitDebugName(Args, Inputs[0], Output));
888 }
889 
890 namespace {
891 // Filter to remove Multilibs that don't exist as a suffix to Path
892 class FilterNonExistent {
893  StringRef Base, File;
894  llvm::vfs::FileSystem &VFS;
895 
896 public:
897  FilterNonExistent(StringRef Base, StringRef File, llvm::vfs::FileSystem &VFS)
898  : Base(Base), File(File), VFS(VFS) {}
899  bool operator()(const Multilib &M) {
900  return !VFS.exists(Base + M.gccSuffix() + File);
901  }
902 };
903 } // end anonymous namespace
904 
905 static bool isSoftFloatABI(const ArgList &Args) {
906  Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
907  options::OPT_mfloat_abi_EQ);
908  if (!A)
909  return false;
910 
911  return A->getOption().matches(options::OPT_msoft_float) ||
912  (A->getOption().matches(options::OPT_mfloat_abi_EQ) &&
913  A->getValue() == StringRef("soft"));
914 }
915 
916 static bool isArmOrThumbArch(llvm::Triple::ArchType Arch) {
917  return Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb;
918 }
919 
920 static bool isMipsEL(llvm::Triple::ArchType Arch) {
921  return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el;
922 }
923 
924 static bool isMips16(const ArgList &Args) {
925  Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16);
926  return A && A->getOption().matches(options::OPT_mips16);
927 }
928 
929 static bool isMicroMips(const ArgList &Args) {
930  Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips);
931  return A && A->getOption().matches(options::OPT_mmicromips);
932 }
933 
934 static bool isRISCV(llvm::Triple::ArchType Arch) {
935  return Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64;
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 
2024  static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
2025  static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",
2026  "sparcv8-linux-gnu"};
2027  static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"};
2028  static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu",
2029  "sparcv9-linux-gnu"};
2030 
2031  static const char *const SystemZLibDirs[] = {"/lib64", "/lib"};
2032  static const char *const SystemZTriples[] = {
2033  "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu",
2034  "s390x-suse-linux", "s390x-redhat-linux"};
2035 
2036 
2037  using std::begin;
2038  using std::end;
2039 
2040  if (TargetTriple.getOS() == llvm::Triple::Solaris) {
2041  static const char *const SolarisLibDirs[] = {"/lib"};
2042  static const char *const SolarisSparcV8Triples[] = {
2043  "sparc-sun-solaris2.11", "sparc-sun-solaris2.12"};
2044  static const char *const SolarisSparcV9Triples[] = {
2045  "sparcv9-sun-solaris2.11", "sparcv9-sun-solaris2.12"};
2046  static const char *const SolarisX86Triples[] = {"i386-pc-solaris2.11",
2047  "i386-pc-solaris2.12"};
2048  static const char *const SolarisX86_64Triples[] = {"x86_64-pc-solaris2.11",
2049  "x86_64-pc-solaris2.12"};
2050  LibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
2051  BiarchLibDirs.append(begin(SolarisLibDirs), end(SolarisLibDirs));
2052  switch (TargetTriple.getArch()) {
2053  case llvm::Triple::x86:
2054  TripleAliases.append(begin(SolarisX86Triples), end(SolarisX86Triples));
2055  BiarchTripleAliases.append(begin(SolarisX86_64Triples),
2056  end(SolarisX86_64Triples));
2057  break;
2058  case llvm::Triple::x86_64:
2059  TripleAliases.append(begin(SolarisX86_64Triples),
2060  end(SolarisX86_64Triples));
2061  BiarchTripleAliases.append(begin(SolarisX86Triples),
2062  end(SolarisX86Triples));
2063  break;
2064  case llvm::Triple::sparc:
2065  TripleAliases.append(begin(SolarisSparcV8Triples),
2066  end(SolarisSparcV8Triples));
2067  BiarchTripleAliases.append(begin(SolarisSparcV9Triples),
2068  end(SolarisSparcV9Triples));
2069  break;
2070  case llvm::Triple::sparcv9:
2071  TripleAliases.append(begin(SolarisSparcV9Triples),
2072  end(SolarisSparcV9Triples));
2073  BiarchTripleAliases.append(begin(SolarisSparcV8Triples),
2074  end(SolarisSparcV8Triples));
2075  break;
2076  default:
2077  break;
2078  }
2079  return;
2080  }
2081 
2082  // Android targets should not use GNU/Linux tools or libraries.
2083  if (TargetTriple.isAndroid()) {
2084  static const char *const AArch64AndroidTriples[] = {
2085  "aarch64-linux-android"};
2086  static const char *const ARMAndroidTriples[] = {"arm-linux-androideabi"};
2087  static const char *const MIPSELAndroidTriples[] = {"mipsel-linux-android"};
2088  static const char *const MIPS64ELAndroidTriples[] = {
2089  "mips64el-linux-android"};
2090  static const char *const X86AndroidTriples[] = {"i686-linux-android"};
2091  static const char *const X86_64AndroidTriples[] = {"x86_64-linux-android"};
2092 
2093  switch (TargetTriple.getArch()) {
2094  case llvm::Triple::aarch64:
2095  LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2096  TripleAliases.append(begin(AArch64AndroidTriples),
2097  end(AArch64AndroidTriples));
2098  break;
2099  case llvm::Triple::arm:
2100  case llvm::Triple::thumb:
2101  LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
2102  TripleAliases.append(begin(ARMAndroidTriples), end(ARMAndroidTriples));
2103  break;
2104  case llvm::Triple::mipsel:
2105  LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2106  TripleAliases.append(begin(MIPSELAndroidTriples),
2107  end(MIPSELAndroidTriples));
2108  BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2109  BiarchTripleAliases.append(begin(MIPS64ELAndroidTriples),
2110  end(MIPS64ELAndroidTriples));
2111  break;
2112  case llvm::Triple::mips64el:
2113  LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2114  TripleAliases.append(begin(MIPS64ELAndroidTriples),
2115  end(MIPS64ELAndroidTriples));
2116  BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2117  BiarchTripleAliases.append(begin(MIPSELAndroidTriples),
2118  end(MIPSELAndroidTriples));
2119  break;
2120  case llvm::Triple::x86_64:
2121  LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2122  TripleAliases.append(begin(X86_64AndroidTriples),
2123  end(X86_64AndroidTriples));
2124  BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2125  BiarchTripleAliases.append(begin(X86AndroidTriples),
2126  end(X86AndroidTriples));
2127  break;
2128  case llvm::Triple::x86:
2129  LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2130  TripleAliases.append(begin(X86AndroidTriples), end(X86AndroidTriples));
2131  BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2132  BiarchTripleAliases.append(begin(X86_64AndroidTriples),
2133  end(X86_64AndroidTriples));
2134  break;
2135  default:
2136  break;
2137  }
2138 
2139  return;
2140  }
2141 
2142  switch (TargetTriple.getArch()) {
2143  case llvm::Triple::aarch64:
2144  LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2145  TripleAliases.append(begin(AArch64Triples), end(AArch64Triples));
2146  BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
2147  BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples));
2148  break;
2149  case llvm::Triple::aarch64_be:
2150  LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs));
2151  TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples));
2152  BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs));
2153  BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples));
2154  break;
2155  case llvm::Triple::arm:
2156  case llvm::Triple::thumb:
2157  LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
2158  if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
2159  TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples));
2160  } else {
2161  TripleAliases.append(begin(ARMTriples), end(ARMTriples));
2162  }
2163  break;
2164  case llvm::Triple::armeb:
2165  case llvm::Triple::thumbeb:
2166  LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs));
2167  if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
2168  TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples));
2169  } else {
2170  TripleAliases.append(begin(ARMebTriples), end(ARMebTriples));
2171  }
2172  break;
2173  case llvm::Triple::avr:
2174  LibDirs.append(begin(AVRLibDirs), end(AVRLibDirs));
2175  TripleAliases.append(begin(AVRTriples), end(AVRTriples));
2176  break;
2177  case llvm::Triple::x86_64:
2178  LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2179  TripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2180  // x32 is always available when x86_64 is available, so adding it as
2181  // secondary arch with x86_64 triples
2182  if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) {
2183  BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs));
2184  BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2185  } else {
2186  BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2187  BiarchTripleAliases.append(begin(X86Triples), end(X86Triples));
2188  }
2189  break;
2190  case llvm::Triple::x86:
2191  LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
2192  // MCU toolchain is 32 bit only and its triple alias is TargetTriple
2193  // itself, which will be appended below.
2194  if (!TargetTriple.isOSIAMCU()) {
2195  TripleAliases.append(begin(X86Triples), end(X86Triples));
2196  BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
2197  BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
2198  }
2199  break;
2200  case llvm::Triple::mips:
2201  LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
2202  TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2203  BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs));
2204  BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples));
2205  BiarchLibDirs.append(begin(MIPSN32LibDirs), end(MIPSN32LibDirs));
2206  BiarchTripleAliases.append(begin(MIPSN32Triples), end(MIPSN32Triples));
2207  break;
2208  case llvm::Triple::mipsel:
2209  LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2210  TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples));
2211  TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2212  BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2213  BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples));
2214  BiarchLibDirs.append(begin(MIPSN32ELLibDirs), end(MIPSN32ELLibDirs));
2215  BiarchTripleAliases.append(begin(MIPSN32ELTriples), end(MIPSN32ELTriples));
2216  break;
2217  case llvm::Triple::mips64:
2218  LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs));
2219  TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples));
2220  BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
2221  BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2222  BiarchLibDirs.append(begin(MIPSN32LibDirs), end(MIPSN32LibDirs));
2223  BiarchTripleAliases.append(begin(MIPSN32Triples), end(MIPSN32Triples));
2224  break;
2225  case llvm::Triple::mips64el:
2226  LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs));
2227  TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples));
2228  BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs));
2229  BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples));
2230  BiarchLibDirs.append(begin(MIPSN32ELLibDirs), end(MIPSN32ELLibDirs));
2231  BiarchTripleAliases.append(begin(MIPSN32ELTriples), end(MIPSN32ELTriples));
2232  BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
2233  break;
2234  case llvm::Triple::msp430:
2235  LibDirs.append(begin(MSP430LibDirs), end(MSP430LibDirs));
2236  TripleAliases.append(begin(MSP430Triples), end(MSP430Triples));
2237  break;
2238  case llvm::Triple::ppc:
2239  LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
2240  TripleAliases.append(begin(PPCTriples), end(PPCTriples));
2241  BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
2242  BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples));
2243  break;
2244  case llvm::Triple::ppc64:
2245  LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
2246  TripleAliases.append(begin(PPC64Triples), end(PPC64Triples));
2247  BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
2248  BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples));
2249  break;
2250  case llvm::Triple::ppc64le:
2251  LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs));
2252  TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples));
2253  break;
2254  case llvm::Triple::riscv32:
2255  LibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
2256  TripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
2257  BiarchLibDirs.append(begin(RISCV64LibDirs), end(RISCV64LibDirs));
2258  BiarchTripleAliases.append(begin(RISCV64Triples), end(RISCV64Triples));
2259  break;
2260  case llvm::Triple::riscv64:
2261  LibDirs.append(begin(RISCV64LibDirs), end(RISCV64LibDirs));
2262  TripleAliases.append(begin(RISCV64Triples), end(RISCV64Triples));
2263  BiarchLibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
2264  BiarchTripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
2265  break;
2266  case llvm::Triple::sparc:
2267  case llvm::Triple::sparcel:
2268  LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
2269  TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples));
2270  BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs));
2271  BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples));
2272  break;
2273  case llvm::Triple::sparcv9:
2274  LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs));
2275  TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples));
2276  BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
2277  BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples));
2278  break;
2279  case llvm::Triple::systemz:
2280  LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs));
2281  TripleAliases.append(begin(SystemZTriples), end(SystemZTriples));
2282  break;
2283  default:
2284  // By default, just rely on the standard lib directories and the original
2285  // triple.
2286  break;
2287  }
2288 
2289  // Always append the drivers target triple to the end, in case it doesn't
2290  // match any of our aliases.
2291  TripleAliases.push_back(TargetTriple.str());
2292 
2293  // Also include the multiarch variant if it's different.
2294  if (TargetTriple.str() != BiarchTriple.str())
2295  BiarchTripleAliases.push_back(BiarchTriple.str());
2296 }
2297 
2298 bool Generic_GCC::GCCInstallationDetector::ScanGCCForMultilibs(
2299  const llvm::Triple &TargetTriple, const ArgList &Args,
2300  StringRef Path, bool NeedsBiarchSuffix) {
2301  llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
2302  DetectedMultilibs Detected;
2303 
2304  // Android standalone toolchain could have multilibs for ARM and Thumb.
2305  // Debian mips multilibs behave more like the rest of the biarch ones,
2306  // so handle them there
2307  if (isArmOrThumbArch(TargetArch) && TargetTriple.isAndroid()) {
2308  // It should also work without multilibs in a simplified toolchain.
2309  findAndroidArmMultilibs(D, TargetTriple, Path, Args, Detected);
2310  } else if (TargetTriple.isMIPS()) {
2311  if (!findMIPSMultilibs(D, TargetTriple, Path, Args, Detected))
2312  return false;
2313  } else if (isRISCV(TargetArch)) {
2314  findRISCVMultilibs(D, TargetTriple, Path, Args, Detected);
2315  } else if (isMSP430(TargetArch)) {
2316  findMSP430Multilibs(D, TargetTriple, Path, Args, Detected);
2317  } else if (TargetArch == llvm::Triple::avr) {
2318  // AVR has no multilibs.
2319  } else if (!findBiarchMultilibs(D, TargetTriple, Path, Args,
2320  NeedsBiarchSuffix, Detected)) {
2321  return false;
2322  }
2323 
2324  Multilibs = Detected.Multilibs;
2325  SelectedMultilib = Detected.SelectedMultilib;
2326  BiarchSibling = Detected.BiarchSibling;
2327 
2328  return true;
2329 }
2330 
2331 void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
2332  const llvm::Triple &TargetTriple, const ArgList &Args,
2333  const std::string &LibDir, StringRef CandidateTriple,
2334  bool NeedsBiarchSuffix) {
2335  llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
2336  // Locations relative to the system lib directory where GCC's triple-specific
2337  // directories might reside.
2338  struct GCCLibSuffix {
2339  // Path from system lib directory to GCC triple-specific directory.
2340  std::string LibSuffix;
2341  // Path from GCC triple-specific directory back to system lib directory.
2342  // This is one '..' component per component in LibSuffix.
2343  StringRef ReversePath;
2344  // Whether this library suffix is relevant for the triple.
2345  bool Active;
2346  } Suffixes[] = {
2347  // This is the normal place.
2348  {"gcc/" + CandidateTriple.str(), "../..", true},
2349 
2350  // Debian puts cross-compilers in gcc-cross.
2351  {"gcc-cross/" + CandidateTriple.str(), "../..",
2352  TargetTriple.getOS() != llvm::Triple::Solaris},
2353 
2354  // The Freescale PPC SDK has the gcc libraries in
2355  // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. Only do
2356  // this on Freescale triples, though, since some systems put a *lot* of
2357  // files in that location, not just GCC installation data.
2358  {CandidateTriple.str(), "..",
2359  TargetTriple.getVendor() == llvm::Triple::Freescale ||
2360  TargetTriple.getVendor() == llvm::Triple::OpenEmbedded},
2361 
2362  // Natively multiarch systems sometimes put the GCC triple-specific
2363  // directory within their multiarch lib directory, resulting in the
2364  // triple appearing twice.
2365  {CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), "../../..",
2366  TargetTriple.getOS() != llvm::Triple::Solaris},
2367 
2368  // Deal with cases (on Ubuntu) where the system architecture could be i386
2369  // but the GCC target architecture could be (say) i686.
2370  // FIXME: It may be worthwhile to generalize this and look for a second
2371  // triple.
2372  {"i386-linux-gnu/gcc/" + CandidateTriple.str(), "../../..",
2373  (TargetArch == llvm::Triple::x86 &&
2374  TargetTriple.getOS() != llvm::Triple::Solaris)},
2375  {"i386-gnu/gcc/" + CandidateTriple.str(), "../../..",
2376  (TargetArch == llvm::Triple::x86 &&
2377  TargetTriple.getOS() != llvm::Triple::Solaris)}};
2378 
2379  for (auto &Suffix : Suffixes) {
2380  if (!Suffix.Active)
2381  continue;
2382 
2383  StringRef LibSuffix = Suffix.LibSuffix;
2384  std::error_code EC;
2385  for (llvm::vfs::directory_iterator
2386  LI = D.getVFS().dir_begin(LibDir + "/" + LibSuffix, EC),
2387  LE;
2388  !EC && LI != LE; LI = LI.increment(EC)) {
2389  StringRef VersionText = llvm::sys::path::filename(LI->path());
2390  GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
2391  if (CandidateVersion.Major != -1) // Filter obviously bad entries.
2392  if (!CandidateGCCInstallPaths.insert(LI->path()).second)
2393  continue; // Saw this path before; no need to look at it again.
2394  if (CandidateVersion.isOlderThan(4, 1, 1))
2395  continue;
2396  if (CandidateVersion <= Version)
2397  continue;
2398 
2399  if (!ScanGCCForMultilibs(TargetTriple, Args, LI->path(),
2400  NeedsBiarchSuffix))
2401  continue;
2402 
2403  Version = CandidateVersion;
2404  GCCTriple.setTriple(CandidateTriple);
2405  // FIXME: We hack together the directory name here instead of
2406  // using LI to ensure stable path separators across Windows and
2407  // Linux.
2408  GCCInstallPath = (LibDir + "/" + LibSuffix + "/" + VersionText).str();
2409  GCCParentLibPath = (GCCInstallPath + "/../" + Suffix.ReversePath).str();
2410  IsValid = true;
2411  }
2412  }
2413 }
2414 
2415 bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
2416  const llvm::Triple &TargetTriple, const ArgList &Args,
2417  const SmallVectorImpl<StringRef> &CandidateTriples,
2418  const SmallVectorImpl<StringRef> &CandidateBiarchTriples) {
2419  for (StringRef CandidateTriple : CandidateTriples) {
2420  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
2421  return true;
2422  }
2423 
2424  for (StringRef CandidateTriple : CandidateBiarchTriples) {
2425  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
2426  return true;
2427  }
2428  return false;
2429 }
2430 
2431 bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
2432  const llvm::Triple &TargetTriple, const ArgList &Args,
2433  StringRef CandidateTriple, bool NeedsBiarchSuffix) {
2434  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
2435  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
2436  CandidateTriple.str());
2437  if (File) {
2439  File.get()->getBuffer().split(Lines, "\n");
2440  for (StringRef Line : Lines) {
2441  Line = Line.trim();
2442  // CURRENT=triple-version
2443  if (!Line.consume_front("CURRENT="))
2444  continue;
2445  // Process the config file pointed to by CURRENT.
2446  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ConfigFile =
2447  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/" +
2448  Line.str());
2449  std::pair<StringRef, StringRef> ActiveVersion = Line.rsplit('-');
2450  // List of paths to scan for libraries.
2451  SmallVector<StringRef, 4> GentooScanPaths;
2452  // Scan the Config file to find installed GCC libraries path.
2453  // Typical content of the GCC config file:
2454  // LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x:/usr/lib/gcc/
2455  // (continued from previous line) x86_64-pc-linux-gnu/4.9.x/32"
2456  // MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.x/man"
2457  // INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.x/info"
2458  // STDCXX_INCDIR="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4"
2459  // We are looking for the paths listed in LDPATH=... .
2460  if (ConfigFile) {
2461  SmallVector<StringRef, 2> ConfigLines;
2462  ConfigFile.get()->getBuffer().split(ConfigLines, "\n");
2463  for (StringRef ConfLine : ConfigLines) {
2464  ConfLine = ConfLine.trim();
2465  if (ConfLine.consume_front("LDPATH=")) {
2466  // Drop '"' from front and back if present.
2467  ConfLine.consume_back("\"");
2468  ConfLine.consume_front("\"");
2469  // Get all paths sperated by ':'
2470  ConfLine.split(GentooScanPaths, ':', -1, /*AllowEmpty*/ false);
2471  }
2472  }
2473  }
2474  // Test the path based on the version in /etc/env.d/gcc/config-{tuple}.
2475  std::string basePath = "/usr/lib/gcc/" + ActiveVersion.first.str() + "/"
2476  + ActiveVersion.second.str();
2477  GentooScanPaths.push_back(StringRef(basePath));
2478 
2479  // Scan all paths for GCC libraries.
2480  for (const auto &GentooScanPath : GentooScanPaths) {
2481  std::string GentooPath = D.SysRoot + std::string(GentooScanPath);
2482  if (D.getVFS().exists(GentooPath + "/crtbegin.o")) {
2483  if (!ScanGCCForMultilibs(TargetTriple, Args, GentooPath,
2484  NeedsBiarchSuffix))
2485  continue;
2486 
2487  Version = GCCVersion::Parse(ActiveVersion.second);
2488  GCCInstallPath = GentooPath;
2489  GCCParentLibPath = GentooPath + std::string("/../../..");
2490  GCCTriple.setTriple(ActiveVersion.first);
2491  IsValid = true;
2492  return true;
2493  }
2494  }
2495  }
2496  }
2497 
2498  return false;
2499 }
2500 
2501 Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
2502  const ArgList &Args)
2503  : ToolChain(D, Triple, Args), GCCInstallation(D),
2504  CudaInstallation(D, Triple, Args) {
2505  getProgramPaths().push_back(getDriver().getInstalledDir());
2506  if (getDriver().getInstalledDir() != getDriver().Dir)
2507  getProgramPaths().push_back(getDriver().Dir);
2508 }
2509 
2511 
2513  switch (AC) {
2515  if (!Preprocess)
2516  Preprocess.reset(new clang::driver::tools::gcc::Preprocessor(*this));
2517  return Preprocess.get();
2519  if (!Compile)
2520  Compile.reset(new tools::gcc::Compiler(*this));
2521  return Compile.get();
2522  default:
2523  return ToolChain::getTool(AC);
2524  }
2525 }
2526 
2528  return new tools::gnutools::Assembler(*this);
2529 }
2530 
2531 Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); }
2532 
2533 void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
2534  // Print the information about how we detected the GCC installation.
2535  GCCInstallation.print(OS);
2536  CudaInstallation.print(OS);
2537 }
2538 
2539 bool Generic_GCC::IsUnwindTablesDefault(const ArgList &Args) const {
2540  return getArch() == llvm::Triple::x86_64;
2541 }
2542 
2544  switch (getArch()) {
2545  case llvm::Triple::x86_64:
2546  return getTriple().isOSWindows();
2547  case llvm::Triple::ppc64:
2548  // Big endian PPC is PIC by default
2549  return !getTriple().isOSBinFormatMachO() && !getTriple().isMacOSX();
2550  case llvm::Triple::mips64:
2551  case llvm::Triple::mips64el:
2552  return true;
2553  default:
2554  return false;
2555  }
2556 }
2557 
2558 bool Generic_GCC::isPIEDefault() const { return false; }
2559 
2561  return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows();
2562 }
2563 
2565  switch (getTriple().getArch()) {
2566  case llvm::Triple::x86:
2567  case llvm::Triple::x86_64:
2568  case llvm::Triple::aarch64:
2569  case llvm::Triple::aarch64_be:
2570  case llvm::Triple::arm:
2571  case llvm::Triple::armeb:
2572  case llvm::Triple::avr:
2573  case llvm::Triple::bpfel:
2574  case llvm::Triple::bpfeb:
2575  case llvm::Triple::thumb:
2576  case llvm::Triple::thumbeb:
2577  case llvm::Triple::ppc:
2578  case llvm::Triple::ppc64:
2579  case llvm::Triple::ppc64le:
2580  case llvm::Triple::riscv32:
2581  case llvm::Triple::riscv64:
2582  case llvm::Triple::systemz:
2583  case llvm::Triple::mips:
2584  case llvm::Triple::mipsel:
2585  case llvm::Triple::mips64:
2586  case llvm::Triple::mips64el:
2587  case llvm::Triple::msp430:
2588  return true;
2589  case llvm::Triple::sparc:
2590  case llvm::Triple::sparcel:
2591  case llvm::Triple::sparcv9:
2592  if (getTriple().isOSFreeBSD() || getTriple().isOSOpenBSD() ||
2593  getTriple().isOSSolaris())
2594  return true;
2595  return false;
2596  default:
2597  return false;
2598  }
2599 }
2600 
2601 void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
2602  ArgStringList &CC1Args) const {
2603  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
2604  DriverArgs.hasArg(options::OPT_nostdincxx))
2605  return;
2606 
2607  switch (GetCXXStdlibType(DriverArgs)) {
2608  case ToolChain::CST_Libcxx:
2609  addLibCxxIncludePaths(DriverArgs, CC1Args);
2610  break;
2611 
2613  addLibStdCxxIncludePaths(DriverArgs, CC1Args);
2614  break;
2615  }
2616 }
2617 
2618 void
2619 Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
2620  llvm::opt::ArgStringList &CC1Args) const {
2621  // FIXME: The Linux behavior would probaby be a better approach here.
2622  addSystemInclude(DriverArgs, CC1Args,
2623  getDriver().SysRoot + "/usr/include/c++/v1");
2624 }
2625 
2626 void
2627 Generic_GCC::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
2628  llvm::opt::ArgStringList &CC1Args) const {
2629  // By default, we don't assume we know where libstdc++ might be installed.
2630  // FIXME: If we have a valid GCCInstallation, use it.
2631 }
2632 
2633 /// Helper to add the variant paths of a libstdc++ installation.
2635  Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple,
2636  StringRef TargetMultiarchTriple, Twine IncludeSuffix,
2637  const ArgList &DriverArgs, ArgStringList &CC1Args) const {
2638  if (!getVFS().exists(Base + Suffix))
2639  return false;
2640 
2641  addSystemInclude(DriverArgs, CC1Args, Base + Suffix);
2642 
2643  // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If
2644  // that path exists or we have neither a GCC nor target multiarch triple, use
2645  // this vanilla search path.
2646  if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) ||
2647  getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) {
2648  addSystemInclude(DriverArgs, CC1Args,
2649  Base + Suffix + "/" + GCCTriple + IncludeSuffix);
2650  } else {
2651  // Otherwise try to use multiarch naming schemes which have normalized the
2652  // triples and put the triple before the suffix.
2653  //
2654  // GCC surprisingly uses *both* the GCC triple with a multilib suffix and
2655  // the target triple, so we support that here.
2656  addSystemInclude(DriverArgs, CC1Args,
2657  Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix);
2658  addSystemInclude(DriverArgs, CC1Args,
2659  Base + "/" + TargetMultiarchTriple + Suffix);
2660  }
2661 
2662  addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward");
2663  return true;
2664 }
2665 
2666 llvm::opt::DerivedArgList *
2667 Generic_GCC::TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef,
2668  Action::OffloadKind DeviceOffloadKind) const {
2669 
2670  // If this tool chain is used for an OpenMP offloading device we have to make
2671  // sure we always generate a shared library regardless of the commands the
2672  // user passed to the host. This is required because the runtime library
2673  // is required to load the device image dynamically at run time.
2674  if (DeviceOffloadKind == Action::OFK_OpenMP) {
2675  DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
2676  const OptTable &Opts = getDriver().getOpts();
2677 
2678  // Request the shared library. Given that these options are decided
2679  // implicitly, they do not refer to any base argument.
2680  DAL->AddFlagArg(/*BaseArg=*/nullptr, Opts.getOption(options::OPT_shared));
2681  DAL->AddFlagArg(/*BaseArg=*/nullptr, Opts.getOption(options::OPT_fPIC));
2682 
2683  // Filter all the arguments we don't care passing to the offloading
2684  // toolchain as they can mess up with the creation of a shared library.
2685  for (auto *A : Args) {
2686  switch ((options::ID)A->getOption().getID()) {
2687  default:
2688  DAL->append(A);
2689  break;
2690  case options::OPT_shared:
2691  case options::OPT_dynamic:
2692  case options::OPT_static:
2693  case options::OPT_fPIC:
2694  case options::OPT_fno_PIC:
2695  case options::OPT_fpic:
2696  case options::OPT_fno_pic:
2697  case options::OPT_fPIE:
2698  case options::OPT_fno_PIE:
2699  case options::OPT_fpie:
2700  case options::OPT_fno_pie:
2701  break;
2702  }
2703  }
2704  return DAL;
2705  }
2706  return nullptr;
2707 }
2708 
2709 void Generic_ELF::anchor() {}
2710 
2711 void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs,
2712  ArgStringList &CC1Args,
2713  Action::OffloadKind) const {
2715  bool UseInitArrayDefault =
2716  getTriple().getArch() == llvm::Triple::aarch64 ||
2717  getTriple().getArch() == llvm::Triple::aarch64_be ||
2718  (getTriple().isOSFreeBSD() &&
2719  getTriple().getOSMajorVersion() >= 12) ||
2720  (getTriple().getOS() == llvm::Triple::Linux &&
2721  ((!GCCInstallation.isValid() || !V.isOlderThan(4, 7, 0)) ||
2722  getTriple().isAndroid())) ||
2723  getTriple().getOS() == llvm::Triple::NaCl ||
2724  (getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
2725  !getTriple().hasEnvironment()) ||
2726  getTriple().getOS() == llvm::Triple::Solaris ||
2727  getTriple().getArch() == llvm::Triple::riscv32 ||
2728  getTriple().getArch() == llvm::Triple::riscv64;
2729 
2730  if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
2731  options::OPT_fno_use_init_array, UseInitArrayDefault))
2732  CC1Args.push_back("-fuse-init-array");
2733 }
const char * getPPCAsmModeForCPU(StringRef Name)
Definition: PPC.cpp:88
MultilibSet & Either(const Multilib &M1, const Multilib &M2)
Add a set of mutually incompatible Multilib segments.
Definition: Multilib.cpp:152
MultilibSet & Maybe(const Multilib &M)
Add an optional Multilib segment.
Definition: Multilib.cpp:142
bool IsStatic
Definition: Format.cpp:1718
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:514
Tool * buildLinker() const override
Definition: Gnu.cpp:2531
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:2512
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:525
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:79
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
void AddHIPLinkerScript(const ToolChain &TC, Compilation &C, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA, const Tool &T)
bool isHostOffloading(OffloadKind OKind) const
Check if this action have any offload kinds.
Definition: Action.h:201
LTOKind getLTOMode() const
Get the specific kind of LTO being performed.
Definition: Driver.h:528
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:463
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:2558
bool select(const Multilib::flags_list &Flags, Multilib &M) const
Pick the best multilib in the set,.
Definition: Multilib.cpp:244
void print(raw_ostream &OS) const
Print information about the detected CUDA installation.
Definition: Cuda.cpp:275
Multilib & flag(StringRef F)
Add a flag to the flags list Flag must be a flag accepted by the driver with its leading &#39;-&#39; removed...
Definition: Multilib.h:92
std::string getCPUName(const llvm::opt::ArgList &Args, const llvm::Triple &T, bool FromAs=false)
void print(raw_ostream &OS) const
Print information about the detected GCC installation.
Definition: Gnu.cpp: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:234
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:920
MultilibSet & setIncludeDirsCallback(IncludeDirsFunc F)
Definition: Multilib.h:174
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:455
types::ID getType() const
Definition: Action.h:140
virtual bool AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFastMathRuntimeIfAvailable - If a runtime library exists that sets global flags for unsafe floatin...
Definition: ToolChain.cpp:845
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:57
bool hasMipsAbiArg(const llvm::opt::ArgList &Args, const char *Value)
const char * SplitDebugName(const llvm::opt::ArgList &Args, const InputInfo &Input, const InputInfo &Output)
void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const override
RenderExtraToolArgs - Render any arguments necessary to force the particular tool mode...
Definition: Gnu.cpp:200
bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC, const llvm::opt::ArgList &Args, bool IsOffloadingHost=false, bool GompNeedsRT=false)
Returns true, if an OpenMP runtime has been added.
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Gnu.cpp:344
void AddOpenMPLinkerScript(const ToolChain &TC, Compilation &C, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:302
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:924
return Out str()
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:905
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:2601
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
Definition: Types.cpp:38
const AnnotatedLine * Line
static bool findMipsMuslMultilibs(const Multilib::flags_list &Flags, FilterNonExistent &NonExistent, DetectedMultilibs &Result)
Definition: Gnu.cpp: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:2543
#define V(N, I)
Definition: ASTContext.h:2905
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:2527
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:2539
static const char * getLDMOption(const llvm::Triple &T, const ArgList &Args)
Definition: Gnu.cpp:257
void AddAssemblerKPIC(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:209
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:375
void printVerboseInfo(raw_ostream &OS) const override
Dispatch to the specific toolchain for verbose printing.
Definition: Gnu.cpp:2533
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:829
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
mips::FloatABI getMipsFloatABI(const Driver &D, const llvm::opt::ArgList &Args)
const Driver & getDriver() const
Definition: ToolChain.h:193
virtual void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Gnu.cpp:2619
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:753
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:916
virtual RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:688
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:108
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:631
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:2560
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
Definition: ToolChain.cpp:806
Dataflow Directional Tag Classes.
Generic_GCC(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: Gnu.cpp:2501
static bool isRISCV(llvm::Triple::ArchType Arch)
Definition: Gnu.cpp:934
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:294
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:2711
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:2564
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:2667
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
const llvm::Triple & getTriple() const
Definition: ToolChain.h:195
virtual void addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Gnu.cpp:2627
virtual Tool * getTool(Action::ActionClass AC) const
Definition: ToolChain.cpp:299
bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const llvm::opt::ArgList &Args, DetectedMultilibs &Result)
void appendBE8LinkFlag(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple)
StringRef getGnuCompatibleMipsABIName(StringRef ABI)
Definition: Mips.cpp:143
bool isNothing() const
Definition: InputInfo.h:74
MultilibSet & FilterOut(FilterCallback F)
Filter out some subset of the Multilibs using a user defined callback.
Definition: Multilib.cpp:212
bool isFilename() const
Definition: InputInfo.h:75
static bool getStatic(const ArgList &Args)
Definition: Gnu.cpp:339
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:298
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:734
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:2634
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:929
bool isLLVMIR(ID Id)
Is this LLVM IR.
Definition: Types.cpp:153
int Major
The parsed major, minor, and patch numbers.
Definition: Gnu.h:161
static void findAndroidArmMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
Definition: Gnu.cpp: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:812
Multilib SelectedMultilib
The primary multilib appropriate for the given flags.
Definition: Gnu.h:25
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88
static bool getStaticPIE(const ArgList &Args, const toolchains::Linux &ToolChain)
Definition: Gnu.cpp:324
bool isValid() const
Check whether we detected a valid GCC install.
Definition: Gnu.h:216