clang  8.0.0svn
Linux.cpp
Go to the documentation of this file.
1 //===--- Linux.h - Linux ToolChain Implementations --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "Linux.h"
11 #include "Arch/ARM.h"
12 #include "Arch/Mips.h"
13 #include "Arch/PPC.h"
14 #include "Arch/RISCV.h"
15 #include "CommonArgs.h"
16 #include "clang/Config/config.h"
17 #include "clang/Driver/Distro.h"
18 #include "clang/Driver/Driver.h"
19 #include "clang/Driver/Options.h"
21 #include "llvm/Option/ArgList.h"
22 #include "llvm/ProfileData/InstrProf.h"
23 #include "llvm/Support/Path.h"
24 #include "llvm/Support/ScopedPrinter.h"
25 #include "llvm/Support/VirtualFileSystem.h"
26 #include <system_error>
27 
28 using namespace clang::driver;
29 using namespace clang::driver::toolchains;
30 using namespace clang;
31 using namespace llvm::opt;
32 
34 
35 /// Get our best guess at the multiarch triple for a target.
36 ///
37 /// Debian-based systems are starting to use a multiarch setup where they use
38 /// a target-triple directory in the library and header search paths.
39 /// Unfortunately, this triple does not align with the vanilla target triple,
40 /// so we provide a rough mapping here.
41 static std::string getMultiarchTriple(const Driver &D,
42  const llvm::Triple &TargetTriple,
43  StringRef SysRoot) {
44  llvm::Triple::EnvironmentType TargetEnvironment =
45  TargetTriple.getEnvironment();
46  bool IsAndroid = TargetTriple.isAndroid();
47  std::string Mips64Abi = "gnuabi64";
48  if (TargetEnvironment == llvm::Triple::GNUABIN32)
49  Mips64Abi = "gnuabin32";
50 
51  // For most architectures, just use whatever we have rather than trying to be
52  // clever.
53  switch (TargetTriple.getArch()) {
54  default:
55  break;
56 
57  // We use the existence of '/lib/<triple>' as a directory to detect some
58  // common linux triples that don't quite match the Clang triple for both
59  // 32-bit and 64-bit targets. Multiarch fixes its install triples to these
60  // regardless of what the actual target triple is.
61  case llvm::Triple::arm:
62  case llvm::Triple::thumb:
63  if (IsAndroid) {
64  return "arm-linux-androideabi";
65  } else if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
66  if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf"))
67  return "arm-linux-gnueabihf";
68  } else {
69  if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi"))
70  return "arm-linux-gnueabi";
71  }
72  break;
73  case llvm::Triple::armeb:
74  case llvm::Triple::thumbeb:
75  if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
76  if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf"))
77  return "armeb-linux-gnueabihf";
78  } else {
79  if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi"))
80  return "armeb-linux-gnueabi";
81  }
82  break;
83  case llvm::Triple::x86:
84  if (IsAndroid)
85  return "i686-linux-android";
86  if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu"))
87  return "i386-linux-gnu";
88  break;
89  case llvm::Triple::x86_64:
90  if (IsAndroid)
91  return "x86_64-linux-android";
92  // We don't want this for x32, otherwise it will match x86_64 libs
93  if (TargetEnvironment != llvm::Triple::GNUX32 &&
94  D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
95  return "x86_64-linux-gnu";
96  break;
97  case llvm::Triple::aarch64:
98  if (IsAndroid)
99  return "aarch64-linux-android";
100  if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu"))
101  return "aarch64-linux-gnu";
102  break;
103  case llvm::Triple::aarch64_be:
104  if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
105  return "aarch64_be-linux-gnu";
106  break;
107  case llvm::Triple::mips:
108  if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu"))
109  return "mips-linux-gnu";
110  break;
111  case llvm::Triple::mipsel:
112  if (IsAndroid)
113  return "mipsel-linux-android";
114  if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu"))
115  return "mipsel-linux-gnu";
116  break;
117  case llvm::Triple::mips64:
118  if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-" + Mips64Abi))
119  return "mips64-linux-" + Mips64Abi;
120  break;
121  case llvm::Triple::mips64el:
122  if (IsAndroid)
123  return "mips64el-linux-android";
124  if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-" + Mips64Abi))
125  return "mips64el-linux-" + Mips64Abi;
126  break;
127  case llvm::Triple::ppc:
128  if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe"))
129  return "powerpc-linux-gnuspe";
130  if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu"))
131  return "powerpc-linux-gnu";
132  break;
133  case llvm::Triple::ppc64:
134  if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu"))
135  return "powerpc64-linux-gnu";
136  break;
137  case llvm::Triple::ppc64le:
138  if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu"))
139  return "powerpc64le-linux-gnu";
140  break;
141  case llvm::Triple::sparc:
142  if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu"))
143  return "sparc-linux-gnu";
144  break;
145  case llvm::Triple::sparcv9:
146  if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu"))
147  return "sparc64-linux-gnu";
148  break;
149  case llvm::Triple::systemz:
150  if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu"))
151  return "s390x-linux-gnu";
152  break;
153  }
154  return TargetTriple.str();
155 }
156 
157 static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
158  if (Triple.isMIPS()) {
159  if (Triple.isAndroid()) {
160  StringRef CPUName;
161  StringRef ABIName;
162  tools::mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName);
163  if (CPUName == "mips32r6")
164  return "libr6";
165  if (CPUName == "mips32r2")
166  return "libr2";
167  }
168  // lib32 directory has a special meaning on MIPS targets.
169  // It contains N32 ABI binaries. Use this folder if produce
170  // code for N32 ABI only.
171  if (tools::mips::hasMipsAbiArg(Args, "n32"))
172  return "lib32";
173  return Triple.isArch32Bit() ? "lib" : "lib64";
174  }
175 
176  // It happens that only x86 and PPC use the 'lib32' variant of oslibdir, and
177  // using that variant while targeting other architectures causes problems
178  // because the libraries are laid out in shared system roots that can't cope
179  // with a 'lib32' library search path being considered. So we only enable
180  // them when we know we may need it.
181  //
182  // FIXME: This is a bit of a hack. We should really unify this code for
183  // reasoning about oslibdir spellings with the lib dir spellings in the
184  // GCCInstallationDetector, but that is a more significant refactoring.
185  if (Triple.getArch() == llvm::Triple::x86 ||
186  Triple.getArch() == llvm::Triple::ppc)
187  return "lib32";
188 
189  if (Triple.getArch() == llvm::Triple::x86_64 &&
190  Triple.getEnvironment() == llvm::Triple::GNUX32)
191  return "libx32";
192 
193  if (Triple.getArch() == llvm::Triple::riscv32)
194  return "lib32";
195 
196  return Triple.isArch32Bit() ? "lib" : "lib64";
197 }
198 
199 static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs,
200  const Multilib &Multilib,
201  StringRef InstallPath,
202  ToolChain::path_list &Paths) {
203  if (const auto &PathsCallback = Multilibs.filePathsCallback())
204  for (const auto &Path : PathsCallback(Multilib))
205  addPathIfExists(D, InstallPath + Path, Paths);
206 }
207 
208 Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
209  : Generic_ELF(D, Triple, Args) {
210  GCCInstallation.init(Triple, Args);
213  llvm::Triple::ArchType Arch = Triple.getArch();
214  std::string SysRoot = computeSysRoot();
215 
216  // Cross-compiling binutils and GCC installations (vanilla and openSUSE at
217  // least) put various tools in a triple-prefixed directory off of the parent
218  // of the GCC installation. We use the GCC triple here to ensure that we end
219  // up with tools that support the same amount of cross compiling as the
220  // detected GCC installation. For example, if we find a GCC installation
221  // targeting x86_64, but it is a bi-arch GCC installation, it can also be
222  // used to target i386.
223  // FIXME: This seems unlikely to be Linux-specific.
225  PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
226  GCCInstallation.getTriple().str() + "/bin")
227  .str());
228 
229  Distro Distro(D.getVFS());
230 
231  if (Distro.IsAlpineLinux() || Triple.isAndroid()) {
232  ExtraOpts.push_back("-z");
233  ExtraOpts.push_back("now");
234  }
235 
237  Triple.isAndroid()) {
238  ExtraOpts.push_back("-z");
239  ExtraOpts.push_back("relro");
240  }
241 
242  if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
243  StringRef::npos)
244  // With devtoolset on RHEL, we want to add a bin directory that is relative
245  // to the detected gcc install, because if we are using devtoolset gcc then
246  // we want to use other tools from devtoolset (e.g. ld) instead of the
247  // standard system tools.
248  PPaths.push_back(Twine(GCCInstallation.getParentLibPath() +
249  "/../bin").str());
250 
251  if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)
252  ExtraOpts.push_back("-X");
253 
254  const bool IsAndroid = Triple.isAndroid();
255  const bool IsMips = Triple.isMIPS();
256  const bool IsHexagon = Arch == llvm::Triple::hexagon;
257  const bool IsRISCV =
258  Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64;
259 
260  if (IsMips && !SysRoot.empty())
261  ExtraOpts.push_back("--sysroot=" + SysRoot);
262 
263  // Do not use 'gnu' hash style for Mips targets because .gnu.hash
264  // and the MIPS ABI require .dynsym to be sorted in different ways.
265  // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS
266  // ABI requires a mapping between the GOT and the symbol table.
267  // Android loader does not support .gnu.hash until API 23.
268  // Hexagon linker/loader does not support .gnu.hash
269  if (!IsMips && !IsHexagon) {
272  (IsAndroid && !Triple.isAndroidVersionLT(23)))
273  ExtraOpts.push_back("--hash-style=gnu");
274 
275  if (Distro.IsDebian() || Distro.IsOpenSUSE() ||
278  (IsAndroid && Triple.isAndroidVersionLT(23)))
279  ExtraOpts.push_back("--hash-style=both");
280  }
281 
283  ExtraOpts.push_back("--no-add-needed");
284 
285 #ifdef ENABLE_LINKER_BUILD_ID
286  ExtraOpts.push_back("--build-id");
287 #endif
288 
289  if (IsAndroid || Distro.IsOpenSUSE())
290  ExtraOpts.push_back("--enable-new-dtags");
291 
292  // The selection of paths to try here is designed to match the patterns which
293  // the GCC driver itself uses, as this is part of the GCC-compatible driver.
294  // This was determined by running GCC in a fake filesystem, creating all
295  // possible permutations of these directories, and seeing which ones it added
296  // to the link paths.
297  path_list &Paths = getFilePaths();
298 
299  const std::string OSLibDir = getOSLibDir(Triple, Args);
300  const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
301 
302  // Add the multilib suffixed paths where they are available.
303  if (GCCInstallation.isValid()) {
304  const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
305  const std::string &LibPath = GCCInstallation.getParentLibPath();
306 
307  // Add toolchain / multilib specific file paths.
310 
311  // Sourcery CodeBench MIPS toolchain holds some libraries under
312  // a biarch-like suffix of the GCC installation.
314  Paths);
315 
316  // GCC cross compiling toolchains will install target libraries which ship
317  // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as
318  // any part of the GCC installation in
319  // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat
320  // debatable, but is the reality today. We need to search this tree even
321  // when we have a sysroot somewhere else. It is the responsibility of
322  // whomever is doing the cross build targeting a sysroot using a GCC
323  // installation that is *not* within the system root to ensure two things:
324  //
325  // 1) Any DSOs that are linked in from this tree or from the install path
326  // above must be present on the system root and found via an
327  // appropriate rpath.
328  // 2) There must not be libraries installed into
329  // <prefix>/<triple>/<libdir> unless they should be preferred over
330  // those within the system root.
331  //
332  // Note that this matches the GCC behavior. See the below comment for where
333  // Clang diverges from GCC's behavior.
334  addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" +
335  OSLibDir + SelectedMultilib.osSuffix(),
336  Paths);
337 
338  // If the GCC installation we found is inside of the sysroot, we want to
339  // prefer libraries installed in the parent prefix of the GCC installation.
340  // It is important to *not* use these paths when the GCC installation is
341  // outside of the system root as that can pick up unintended libraries.
342  // This usually happens when there is an external cross compiler on the
343  // host system, and a more minimal sysroot available that is the target of
344  // the cross. Note that GCC does include some of these directories in some
345  // configurations but this seems somewhere between questionable and simply
346  // a bug.
347  if (StringRef(LibPath).startswith(SysRoot)) {
348  addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths);
349  addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths);
350  }
351  }
352 
353  // Similar to the logic for GCC above, if we currently running Clang inside
354  // of the requested system root, add its parent library paths to
355  // those searched.
356  // FIXME: It's not clear whether we should use the driver's installed
357  // directory ('Dir' below) or the ResourceDir.
358  if (StringRef(D.Dir).startswith(SysRoot)) {
359  addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths);
360  addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
361  }
362 
363  addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
364  addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);
365 
366  if (IsAndroid) {
367  // Android sysroots contain a library directory for each supported OS
368  // version as well as some unversioned libraries in the usual multiarch
369  // directory.
370  unsigned Major;
371  unsigned Minor;
372  unsigned Micro;
373  Triple.getEnvironmentVersion(Major, Minor, Micro);
374  addPathIfExists(D,
375  SysRoot + "/usr/lib/" + MultiarchTriple + "/" +
376  llvm::to_string(Major),
377  Paths);
378  }
379 
380  addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
381  // 64-bit OpenEmbedded sysroots may not have a /usr/lib dir. So they cannot
382  // find /usr/lib64 as it is referenced as /usr/lib/../lib64. So we handle
383  // this here.
384  if (Triple.getVendor() == llvm::Triple::OpenEmbedded &&
385  Triple.isArch64Bit())
386  addPathIfExists(D, SysRoot + "/usr/" + OSLibDir, Paths);
387  else
388  addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths);
389  if (IsRISCV) {
390  StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
391  addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths);
392  addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths);
393  }
394 
395  // Try walking via the GCC triple path in case of biarch or multiarch GCC
396  // installations with strange symlinks.
397  if (GCCInstallation.isValid()) {
398  addPathIfExists(D,
399  SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
400  "/../../" + OSLibDir,
401  Paths);
402 
403  // Add the 'other' biarch variant path
404  Multilib BiarchSibling;
405  if (GCCInstallation.getBiarchSibling(BiarchSibling)) {
407  BiarchSibling.gccSuffix(),
408  Paths);
409  }
410 
411  // See comments above on the multilib variant for details of why this is
412  // included even from outside the sysroot.
413  const std::string &LibPath = GCCInstallation.getParentLibPath();
414  const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
416  addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" +
417  Multilib.osSuffix(),
418  Paths);
419 
420  // See comments above on the multilib variant for details of why this is
421  // only included from within the sysroot.
422  if (StringRef(LibPath).startswith(SysRoot))
423  addPathIfExists(D, LibPath, Paths);
424  }
425 
426  // Similar to the logic for GCC above, if we are currently running Clang
427  // inside of the requested system root, add its parent library path to those
428  // searched.
429  // FIXME: It's not clear whether we should use the driver's installed
430  // directory ('Dir' below) or the ResourceDir.
431  if (StringRef(D.Dir).startswith(SysRoot))
432  addPathIfExists(D, D.Dir + "/../lib", Paths);
433 
434  addPathIfExists(D, SysRoot + "/lib", Paths);
435  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
436 }
437 
438 bool Linux::HasNativeLLVMSupport() const { return true; }
439 
440 Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); }
441 
443  return new tools::gnutools::Assembler(*this);
444 }
445 
446 std::string Linux::computeSysRoot() const {
447  if (!getDriver().SysRoot.empty())
448  return getDriver().SysRoot;
449 
450  if (getTriple().isAndroid()) {
451  // Android toolchains typically include a sysroot at ../sysroot relative to
452  // the clang binary.
453  const StringRef ClangDir = getDriver().getInstalledDir();
454  std::string AndroidSysRootPath = (ClangDir + "/../sysroot").str();
455  if (getVFS().exists(AndroidSysRootPath))
456  return AndroidSysRootPath;
457  }
458 
459  if (!GCCInstallation.isValid() || !getTriple().isMIPS())
460  return std::string();
461 
462  // Standalone MIPS toolchains use different names for sysroot folder
463  // and put it into different places. Here we try to check some known
464  // variants.
465 
466  const StringRef InstallDir = GCCInstallation.getInstallPath();
467  const StringRef TripleStr = GCCInstallation.getTriple().str();
469 
470  std::string Path =
471  (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix())
472  .str();
473 
474  if (getVFS().exists(Path))
475  return Path;
476 
477  Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str();
478 
479  if (getVFS().exists(Path))
480  return Path;
481 
482  return std::string();
483 }
484 
485 std::string Linux::getDynamicLinker(const ArgList &Args) const {
486  const llvm::Triple::ArchType Arch = getArch();
487  const llvm::Triple &Triple = getTriple();
488 
489  const Distro Distro(getDriver().getVFS());
490 
491  if (Triple.isAndroid())
492  return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker";
493 
494  if (Triple.isMusl()) {
495  std::string ArchName;
496  bool IsArm = false;
497 
498  switch (Arch) {
499  case llvm::Triple::arm:
500  case llvm::Triple::thumb:
501  ArchName = "arm";
502  IsArm = true;
503  break;
504  case llvm::Triple::armeb:
505  case llvm::Triple::thumbeb:
506  ArchName = "armeb";
507  IsArm = true;
508  break;
509  default:
510  ArchName = Triple.getArchName().str();
511  }
512  if (IsArm &&
513  (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
515  ArchName += "hf";
516 
517  return "/lib/ld-musl-" + ArchName + ".so.1";
518  }
519 
520  std::string LibDir;
521  std::string Loader;
522 
523  switch (Arch) {
524  default:
525  llvm_unreachable("unsupported architecture");
526 
527  case llvm::Triple::aarch64:
528  LibDir = "lib";
529  Loader = "ld-linux-aarch64.so.1";
530  break;
531  case llvm::Triple::aarch64_be:
532  LibDir = "lib";
533  Loader = "ld-linux-aarch64_be.so.1";
534  break;
535  case llvm::Triple::arm:
536  case llvm::Triple::thumb:
537  case llvm::Triple::armeb:
538  case llvm::Triple::thumbeb: {
539  const bool HF =
540  Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
542 
543  LibDir = "lib";
544  Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3";
545  break;
546  }
547  case llvm::Triple::mips:
548  case llvm::Triple::mipsel:
549  case llvm::Triple::mips64:
550  case llvm::Triple::mips64el: {
551  bool IsNaN2008 = tools::mips::isNaN2008(Args, Triple);
552 
553  LibDir = "lib" + tools::mips::getMipsABILibSuffix(Args, Triple);
554 
555  if (tools::mips::isUCLibc(Args))
556  Loader = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0";
557  else if (!Triple.hasEnvironment() &&
558  Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies)
559  Loader =
560  Triple.isLittleEndian() ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1";
561  else
562  Loader = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1";
563 
564  break;
565  }
566  case llvm::Triple::ppc:
567  LibDir = "lib";
568  Loader = "ld.so.1";
569  break;
570  case llvm::Triple::ppc64:
571  LibDir = "lib64";
572  Loader =
573  (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2" : "ld64.so.1";
574  break;
575  case llvm::Triple::ppc64le:
576  LibDir = "lib64";
577  Loader =
578  (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2";
579  break;
580  case llvm::Triple::riscv32: {
581  StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
582  LibDir = "lib";
583  Loader = ("ld-linux-riscv32-" + ABIName + ".so.1").str();
584  break;
585  }
586  case llvm::Triple::riscv64: {
587  StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
588  LibDir = "lib";
589  Loader = ("ld-linux-riscv64-" + ABIName + ".so.1").str();
590  break;
591  }
592  case llvm::Triple::sparc:
593  case llvm::Triple::sparcel:
594  LibDir = "lib";
595  Loader = "ld-linux.so.2";
596  break;
597  case llvm::Triple::sparcv9:
598  LibDir = "lib64";
599  Loader = "ld-linux.so.2";
600  break;
601  case llvm::Triple::systemz:
602  LibDir = "lib";
603  Loader = "ld64.so.1";
604  break;
605  case llvm::Triple::x86:
606  LibDir = "lib";
607  Loader = "ld-linux.so.2";
608  break;
609  case llvm::Triple::x86_64: {
610  bool X32 = Triple.getEnvironment() == llvm::Triple::GNUX32;
611 
612  LibDir = X32 ? "libx32" : "lib64";
613  Loader = X32 ? "ld-linux-x32.so.2" : "ld-linux-x86-64.so.2";
614  break;
615  }
616  }
617 
618  if (Distro == Distro::Exherbo && (Triple.getVendor() == llvm::Triple::UnknownVendor ||
619  Triple.getVendor() == llvm::Triple::PC))
620  return "/usr/" + Triple.str() + "/lib/" + Loader;
621  return "/" + LibDir + "/" + Loader;
622 }
623 
624 void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
625  ArgStringList &CC1Args) const {
626  const Driver &D = getDriver();
627  std::string SysRoot = computeSysRoot();
628 
629  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
630  return;
631 
632  if (!DriverArgs.hasArg(options::OPT_nostdlibinc))
633  addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
634 
635  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
637  llvm::sys::path::append(P, "include");
638  addSystemInclude(DriverArgs, CC1Args, P);
639  }
640 
641  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
642  return;
643 
644  // Check for configure-time C include directories.
645  StringRef CIncludeDirs(C_INCLUDE_DIRS);
646  if (CIncludeDirs != "") {
648  CIncludeDirs.split(dirs, ":");
649  for (StringRef dir : dirs) {
650  StringRef Prefix =
651  llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : "";
652  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
653  }
654  return;
655  }
656 
657  // Lacking those, try to detect the correct set of system includes for the
658  // target triple.
659 
660  // Add include directories specific to the selected multilib set and multilib.
661  if (GCCInstallation.isValid()) {
662  const auto &Callback = Multilibs.includeDirsCallback();
663  if (Callback) {
664  for (const auto &Path : Callback(GCCInstallation.getMultilib()))
666  DriverArgs, CC1Args, GCCInstallation.getInstallPath() + Path);
667  }
668  }
669 
670  // Implement generic Debian multiarch support.
671  const StringRef X86_64MultiarchIncludeDirs[] = {
672  "/usr/include/x86_64-linux-gnu",
673 
674  // FIXME: These are older forms of multiarch. It's not clear that they're
675  // in use in any released version of Debian, so we should consider
676  // removing them.
677  "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"};
678  const StringRef X86MultiarchIncludeDirs[] = {
679  "/usr/include/i386-linux-gnu",
680 
681  // FIXME: These are older forms of multiarch. It's not clear that they're
682  // in use in any released version of Debian, so we should consider
683  // removing them.
684  "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu",
685  "/usr/include/i486-linux-gnu"};
686  const StringRef AArch64MultiarchIncludeDirs[] = {
687  "/usr/include/aarch64-linux-gnu"};
688  const StringRef ARMMultiarchIncludeDirs[] = {
689  "/usr/include/arm-linux-gnueabi"};
690  const StringRef ARMHFMultiarchIncludeDirs[] = {
691  "/usr/include/arm-linux-gnueabihf"};
692  const StringRef ARMEBMultiarchIncludeDirs[] = {
693  "/usr/include/armeb-linux-gnueabi"};
694  const StringRef ARMEBHFMultiarchIncludeDirs[] = {
695  "/usr/include/armeb-linux-gnueabihf"};
696  const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"};
697  const StringRef MIPSELMultiarchIncludeDirs[] = {
698  "/usr/include/mipsel-linux-gnu"};
699  const StringRef MIPS64MultiarchIncludeDirs[] = {
700  "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"};
701  const StringRef MIPS64ELMultiarchIncludeDirs[] = {
702  "/usr/include/mips64el-linux-gnu",
703  "/usr/include/mips64el-linux-gnuabi64"};
704  const StringRef MIPSN32MultiarchIncludeDirs[] = {
705  "/usr/include/mips64-linux-gnuabin32"};
706  const StringRef MIPSN32ELMultiarchIncludeDirs[] = {
707  "/usr/include/mips64el-linux-gnuabin32"};
708  const StringRef PPCMultiarchIncludeDirs[] = {
709  "/usr/include/powerpc-linux-gnu",
710  "/usr/include/powerpc-linux-gnuspe"};
711  const StringRef PPC64MultiarchIncludeDirs[] = {
712  "/usr/include/powerpc64-linux-gnu"};
713  const StringRef PPC64LEMultiarchIncludeDirs[] = {
714  "/usr/include/powerpc64le-linux-gnu"};
715  const StringRef SparcMultiarchIncludeDirs[] = {
716  "/usr/include/sparc-linux-gnu"};
717  const StringRef Sparc64MultiarchIncludeDirs[] = {
718  "/usr/include/sparc64-linux-gnu"};
719  const StringRef SYSTEMZMultiarchIncludeDirs[] = {
720  "/usr/include/s390x-linux-gnu"};
721  ArrayRef<StringRef> MultiarchIncludeDirs;
722  switch (getTriple().getArch()) {
723  case llvm::Triple::x86_64:
724  MultiarchIncludeDirs = X86_64MultiarchIncludeDirs;
725  break;
726  case llvm::Triple::x86:
727  MultiarchIncludeDirs = X86MultiarchIncludeDirs;
728  break;
729  case llvm::Triple::aarch64:
730  case llvm::Triple::aarch64_be:
731  MultiarchIncludeDirs = AArch64MultiarchIncludeDirs;
732  break;
733  case llvm::Triple::arm:
734  case llvm::Triple::thumb:
735  if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
736  MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs;
737  else
738  MultiarchIncludeDirs = ARMMultiarchIncludeDirs;
739  break;
740  case llvm::Triple::armeb:
741  case llvm::Triple::thumbeb:
742  if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
743  MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs;
744  else
745  MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs;
746  break;
747  case llvm::Triple::mips:
748  MultiarchIncludeDirs = MIPSMultiarchIncludeDirs;
749  break;
750  case llvm::Triple::mipsel:
751  MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs;
752  break;
753  case llvm::Triple::mips64:
754  if (getTriple().getEnvironment() == llvm::Triple::GNUABIN32)
755  MultiarchIncludeDirs = MIPSN32MultiarchIncludeDirs;
756  else
757  MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs;
758  break;
759  case llvm::Triple::mips64el:
760  if (getTriple().getEnvironment() == llvm::Triple::GNUABIN32)
761  MultiarchIncludeDirs = MIPSN32ELMultiarchIncludeDirs;
762  else
763  MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs;
764  break;
765  case llvm::Triple::ppc:
766  MultiarchIncludeDirs = PPCMultiarchIncludeDirs;
767  break;
768  case llvm::Triple::ppc64:
769  MultiarchIncludeDirs = PPC64MultiarchIncludeDirs;
770  break;
771  case llvm::Triple::ppc64le:
772  MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs;
773  break;
774  case llvm::Triple::sparc:
775  MultiarchIncludeDirs = SparcMultiarchIncludeDirs;
776  break;
777  case llvm::Triple::sparcv9:
778  MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs;
779  break;
780  case llvm::Triple::systemz:
781  MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs;
782  break;
783  default:
784  break;
785  }
786 
787  const std::string AndroidMultiarchIncludeDir =
788  std::string("/usr/include/") +
789  getMultiarchTriple(D, getTriple(), SysRoot);
790  const StringRef AndroidMultiarchIncludeDirs[] = {AndroidMultiarchIncludeDir};
791  if (getTriple().isAndroid())
792  MultiarchIncludeDirs = AndroidMultiarchIncludeDirs;
793 
794  for (StringRef Dir : MultiarchIncludeDirs) {
795  if (D.getVFS().exists(SysRoot + Dir)) {
796  addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir);
797  break;
798  }
799  }
800 
801  if (getTriple().getOS() == llvm::Triple::RTEMS)
802  return;
803 
804  // Add an include of '/include' directly. This isn't provided by default by
805  // system GCCs, but is often used with cross-compiling GCCs, and harmless to
806  // add even when Clang is acting as-if it were a system compiler.
807  addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
808 
809  addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
810 }
811 
812 static std::string DetectLibcxxIncludePath(StringRef base) {
813  std::error_code EC;
814  int MaxVersion = 0;
815  std::string MaxVersionString = "";
816  for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE;
817  LI = LI.increment(EC)) {
818  StringRef VersionText = llvm::sys::path::filename(LI->path());
819  int Version;
820  if (VersionText[0] == 'v' &&
821  !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
822  if (Version > MaxVersion) {
823  MaxVersion = Version;
824  MaxVersionString = VersionText;
825  }
826  }
827  }
828  return MaxVersion ? (base + "/" + MaxVersionString).str() : "";
829 }
830 
831 void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
832  llvm::opt::ArgStringList &CC1Args) const {
833  const std::string& SysRoot = computeSysRoot();
834  const std::string LibCXXIncludePathCandidates[] = {
835  DetectLibcxxIncludePath(getDriver().ResourceDir + "/include/c++"),
836  DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"),
837  // If this is a development, non-installed, clang, libcxx will
838  // not be found at ../include/c++ but it likely to be found at
839  // one of the following two locations:
840  DetectLibcxxIncludePath(SysRoot + "/usr/local/include/c++"),
841  DetectLibcxxIncludePath(SysRoot + "/usr/include/c++") };
842  for (const auto &IncludePath : LibCXXIncludePathCandidates) {
843  if (IncludePath.empty() || !getVFS().exists(IncludePath))
844  continue;
845  // Use the first candidate that exists.
846  addSystemInclude(DriverArgs, CC1Args, IncludePath);
847  return;
848  }
849 }
850 
851 void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
852  llvm::opt::ArgStringList &CC1Args) const {
853  // We need a detected GCC installation on Linux to provide libstdc++'s
854  // headers.
855  if (!GCCInstallation.isValid())
856  return;
857 
858  // By default, look for the C++ headers in an include directory adjacent to
859  // the lib directory of the GCC installation. Note that this is expect to be
860  // equivalent to '/usr/include/c++/X.Y' in almost all cases.
861  StringRef LibDir = GCCInstallation.getParentLibPath();
862  StringRef InstallDir = GCCInstallation.getInstallPath();
863  StringRef TripleStr = GCCInstallation.getTriple().str();
865  const std::string GCCMultiarchTriple = getMultiarchTriple(
867  const std::string TargetMultiarchTriple =
869  const GCCVersion &Version = GCCInstallation.getVersion();
870 
871  // The primary search for libstdc++ supports multiarch variants.
872  if (addLibStdCXXIncludePaths(LibDir.str() + "/../include",
873  "/c++/" + Version.Text, TripleStr,
874  GCCMultiarchTriple, TargetMultiarchTriple,
875  Multilib.includeSuffix(), DriverArgs, CC1Args))
876  return;
877 
878  // Otherwise, fall back on a bunch of options which don't use multiarch
879  // layouts for simplicity.
880  const std::string LibStdCXXIncludePathCandidates[] = {
881  // Gentoo is weird and places its headers inside the GCC install,
882  // so if the first attempt to find the headers fails, try these patterns.
883  InstallDir.str() + "/include/g++-v" + Version.Text,
884  InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." +
885  Version.MinorStr,
886  InstallDir.str() + "/include/g++-v" + Version.MajorStr,
887  // Android standalone toolchain has C++ headers in yet another place.
888  LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,
889  // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++,
890  // without a subdirectory corresponding to the gcc version.
891  LibDir.str() + "/../include/c++",
892  };
893 
894  for (const auto &IncludePath : LibStdCXXIncludePathCandidates) {
895  if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr,
896  /*GCCMultiarchTriple*/ "",
897  /*TargetMultiarchTriple*/ "",
898  Multilib.includeSuffix(), DriverArgs, CC1Args))
899  break;
900  }
901 }
902 
903 void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
904  ArgStringList &CC1Args) const {
905  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
906 }
907 
908 void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
909  ArgStringList &CC1Args) const {
910  if (GCCInstallation.isValid()) {
911  CC1Args.push_back("-isystem");
912  CC1Args.push_back(DriverArgs.MakeArgString(
913  GCCInstallation.getParentLibPath() + "/../" +
914  GCCInstallation.getTriple().str() + "/include"));
915  }
916 }
917 
918 bool Linux::isPIEDefault() const {
919  return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
920  getTriple().isMusl() || getSanitizerArgs().requiresPIE();
921 }
922 
924  if (getTriple().isAndroid())
925  return false;
927 }
928 
930  const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
931  const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
932  const bool IsMIPS = getTriple().isMIPS32();
933  const bool IsMIPS64 = getTriple().isMIPS64();
934  const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 ||
935  getTriple().getArch() == llvm::Triple::ppc64le;
936  const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 ||
937  getTriple().getArch() == llvm::Triple::aarch64_be;
938  const bool IsArmArch = getTriple().getArch() == llvm::Triple::arm ||
939  getTriple().getArch() == llvm::Triple::thumb ||
940  getTriple().getArch() == llvm::Triple::armeb ||
941  getTriple().getArch() == llvm::Triple::thumbeb;
943  Res |= SanitizerKind::Address;
944  Res |= SanitizerKind::Fuzzer;
945  Res |= SanitizerKind::FuzzerNoLink;
946  Res |= SanitizerKind::KernelAddress;
947  Res |= SanitizerKind::Memory;
948  Res |= SanitizerKind::Vptr;
949  Res |= SanitizerKind::SafeStack;
950  if (IsX86_64 || IsMIPS64 || IsAArch64)
951  Res |= SanitizerKind::DataFlow;
952  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64)
953  Res |= SanitizerKind::Leak;
954  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
955  Res |= SanitizerKind::Thread;
956  if (IsX86_64)
957  Res |= SanitizerKind::KernelMemory;
958  if (IsX86_64 || IsMIPS64)
959  Res |= SanitizerKind::Efficiency;
960  if (IsX86 || IsX86_64)
961  Res |= SanitizerKind::Function;
962  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsMIPS || IsArmArch ||
963  IsPowerPC64)
964  Res |= SanitizerKind::Scudo;
965  if (IsX86_64 || IsAArch64) {
966  Res |= SanitizerKind::HWAddress;
967  Res |= SanitizerKind::KernelHWAddress;
968  }
969  return Res;
970 }
971 
972 void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args,
973  llvm::opt::ArgStringList &CmdArgs) const {
974  if (!needsProfileRT(Args)) return;
975 
976  // Add linker option -u__llvm_runtime_variable to cause runtime
977  // initialization module to be linked in.
978  if (!Args.hasArg(options::OPT_coverage))
979  CmdArgs.push_back(Args.MakeArgString(
980  Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
981  ToolChain::addProfileRTLibs(Args, CmdArgs);
982 }
static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory with extern "C" semantics to CC1 arguments...
Definition: ToolChain.cpp:713
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: Linux.cpp:918
virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const
Definition: Linux.cpp:485
static void addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Definition: ToolChain.cpp:720
bool getBiarchSibling(Multilib &M) const
Get the biarch sibling multilib (if it exists).
Definition: Gnu.cpp:1747
const IncludeDirsFunc & includeDirsCallback() const
Definition: Multilib.h:175
const llvm::Triple & getTriple() const
Get the GCC triple for the detected install.
Definition: Gnu.h:220
StringRef P
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: Linux.cpp:929
StringRef getOS() const
Definition: ToolChain.h:203
bool IsOpenSUSE() const
Definition: Distro.h:109
const IncludeDirsFunc & filePathsCallback() const
Definition: Multilib.h:182
void addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Definition: Linux.cpp:851
Struct to store and manipulate GCC versions.
Definition: Gnu.h:157
virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass a suitable profile runtime ...
Definition: ToolChain.cpp:653
FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args)
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific CUDA includes.
Definition: Linux.cpp:903
GCCInstallationDetector GCCInstallation
Definition: Gnu.h:280
path_list & getProgramPaths()
Definition: ToolChain.h:225
Distro - Helper class for detecting and classifying Linux distributions.
Definition: Distro.h:23
const std::string & includeSuffix() const
Get the include directory suffix.
Definition: Multilib.h:67
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition: Linux.cpp:438
std::string Dir
The path the driver executable was in, as invoked from the command line.
Definition: Driver.h:120
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant.
Definition: Multilib.h:45
static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args)
Definition: Linux.cpp:157
bool isNaN2008(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static bool needsProfileRT(const llvm::opt::ArgList &Args)
needsProfileRT - returns true if instrumentation profile is on.
Definition: ToolChain.cpp:405
const std::string & osSuffix() const
Get the detected os path suffix for the multi-arch target variant.
Definition: Multilib.h:56
static std::string DetectLibcxxIncludePath(StringRef base)
Definition: Linux.cpp:812
path_list & getFilePaths()
Definition: ToolChain.h:222
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:58
bool hasMipsAbiArg(const llvm::opt::ArgList &Args, const char *Value)
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:300
const GCCVersion & getVersion() const
Get the detected GCC version string.
Definition: Gnu.h:239
return Out str()
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: Linux.cpp:624
StringRef getRISCVABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
CudaInstallationDetector CudaInstallation
Definition: Gnu.h:281
void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass a suitable profile runtime ...
Definition: Linux.cpp:972
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag...
Definition: Multilib.h:29
virtual bool IsMathErrnoDefault() const
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: ToolChain.h:328
bool IsDebian() const
Definition: Distro.h:113
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:200
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Cuda.cpp:231
static std::string getMultiarchTriple(const Driver &D, const llvm::Triple &TargetTriple, StringRef SysRoot)
Get our best guess at the multiarch triple for a target.
Definition: Linux.cpp:41
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use MCU GCC toolchain includes.
Definition: Linux.cpp:908
const Driver & getDriver() const
Definition: ToolChain.h:184
bool hasPPCAbiArg(const llvm::opt::ArgList &Args, const char *Value)
bool isUCLibc(const llvm::opt::ArgList &Args)
virtual std::string computeSysRoot() const
Definition: Linux.cpp:446
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:698
StringRef getParentLibPath() const
Get the detected GCC parent lib path.
Definition: Gnu.h:226
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: Linux.cpp:923
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:102
bool IsAlpineLinux() const
Definition: Distro.h:121
static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, const Multilib &Multilib, StringRef InstallPath, ToolChain::path_list &Paths)
Definition: Linux.cpp:199
Dataflow Directional Tag Classes.
std::string SysRoot
sysroot, if present
Definition: Driver.h:148
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
const SanitizerArgs & getSanitizerArgs() const
Definition: ToolChain.cpp:116
const char * getInstalledDir() const
Get the path to where the clang executable was installed.
Definition: Driver.h:319
uint64_t SanitizerMask
Definition: Sanitizers.h:26
std::string MajorStr
The text of the parsed major, and major+minor versions.
Definition: Gnu.h:165
std::string Text
The unparsed text of the version.
Definition: Gnu.h:159
Tool * buildLinker() const override
Definition: Linux.cpp:440
const llvm::Triple & getTriple() const
Definition: ToolChain.h:186
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:814
bool IsRedhat() const
Definition: Distro.h:105
bool IsUbuntu() const
Definition: Distro.h:117
void addPathIfExists(const Driver &D, const Twine &Path, ToolChain::path_list &Paths)
Definition: CommonArgs.cpp:62
Tool * buildAssembler() const override
Definition: Linux.cpp:442
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:2473
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:1639
const MultilibSet & getMultilibs() const
Get the whole MultilibSet.
Definition: Gnu.h:232
void getMipsCPUAndABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, StringRef &CPUName, StringRef &ABIName)
void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Definition: Linux.cpp:831
std::vector< std::string > ExtraOpts
Definition: Linux.h:49
std::string getMipsABILibSuffix(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
StringRef getInstallPath() const
Get the detected GCC installation path.
Definition: Gnu.h:223
const Multilib & getMultilib() const
Get the detected Multilib.
Definition: Gnu.h:229
Linux(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: Linux.cpp:208
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:132
bool isValid() const
Check whether we detected a valid GCC install.
Definition: Gnu.h:217