clang  3.7.0
ToolChains.h
Go to the documentation of this file.
1 //===--- ToolChains.h - 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 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
11 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
12 
13 #include "Tools.h"
15 #include "clang/Driver/Action.h"
16 #include "clang/Driver/Multilib.h"
17 #include "clang/Driver/ToolChain.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/Support/Compiler.h"
21 #include <set>
22 #include <vector>
23 
24 namespace clang {
25 namespace driver {
26 namespace toolchains {
27 
28 /// Generic_GCC - A tool chain using the 'gcc' command to perform
29 /// all subcommands; this relies on gcc translating the majority of
30 /// command line options.
31 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
32 public:
33  /// \brief Struct to store and manipulate GCC versions.
34  ///
35  /// We rely on assumptions about the form and structure of GCC version
36  /// numbers: they consist of at most three '.'-separated components, and each
37  /// component is a non-negative integer except for the last component. For
38  /// the last component we are very flexible in order to tolerate release
39  /// candidates or 'x' wildcards.
40  ///
41  /// Note that the ordering established among GCCVersions is based on the
42  /// preferred version string to use. For example we prefer versions without
43  /// a hard-coded patch number to those with a hard coded patch number.
44  ///
45  /// Currently this doesn't provide any logic for textual suffixes to patches
46  /// in the way that (for example) Debian's version format does. If that ever
47  /// becomes necessary, it can be added.
48  struct GCCVersion {
49  /// \brief The unparsed text of the version.
50  std::string Text;
51 
52  /// \brief The parsed major, minor, and patch numbers.
53  int Major, Minor, Patch;
54 
55  /// \brief The text of the parsed major, and major+minor versions.
56  std::string MajorStr, MinorStr;
57 
58  /// \brief Any textual suffix on the patch number.
59  std::string PatchSuffix;
60 
61  static GCCVersion Parse(StringRef VersionText);
62  bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch,
63  StringRef RHSPatchSuffix = StringRef()) const;
64  bool operator<(const GCCVersion &RHS) const {
65  return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix);
66  }
67  bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
68  bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
69  bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
70  };
71 
72  /// \brief This is a class to find a viable GCC installation for Clang to
73  /// use.
74  ///
75  /// This class tries to find a GCC installation on the system, and report
76  /// information about it. It starts from the host information provided to the
77  /// Driver, and has logic for fuzzing that where appropriate.
79  bool IsValid;
80  llvm::Triple GCCTriple;
81 
82  // FIXME: These might be better as path objects.
83  std::string GCCInstallPath;
84  std::string GCCParentLibPath;
85 
86  /// The primary multilib appropriate for the given flags.
87  Multilib SelectedMultilib;
88  /// On Biarch systems, this corresponds to the default multilib when
89  /// targeting the non-default multilib. Otherwise, it is empty.
90  llvm::Optional<Multilib> BiarchSibling;
91 
92  GCCVersion Version;
93 
94  // We retain the list of install paths that were considered and rejected in
95  // order to print out detailed information in verbose mode.
96  std::set<std::string> CandidateGCCInstallPaths;
97 
98  /// The set of multilibs that the detected installation supports.
99  MultilibSet Multilibs;
100 
101  public:
103  void init(const Driver &D, const llvm::Triple &TargetTriple,
104  const llvm::opt::ArgList &Args);
105 
106  /// \brief Check whether we detected a valid GCC install.
107  bool isValid() const { return IsValid; }
108 
109  /// \brief Get the GCC triple for the detected install.
110  const llvm::Triple &getTriple() const { return GCCTriple; }
111 
112  /// \brief Get the detected GCC installation path.
113  StringRef getInstallPath() const { return GCCInstallPath; }
114 
115  /// \brief Get the detected GCC parent lib path.
116  StringRef getParentLibPath() const { return GCCParentLibPath; }
117 
118  /// \brief Get the detected Multilib
119  const Multilib &getMultilib() const { return SelectedMultilib; }
120 
121  /// \brief Get the whole MultilibSet
122  const MultilibSet &getMultilibs() const { return Multilibs; }
123 
124  /// Get the biarch sibling multilib (if it exists).
125  /// \return true iff such a sibling exists
126  bool getBiarchSibling(Multilib &M) const;
127 
128  /// \brief Get the detected GCC version string.
129  const GCCVersion &getVersion() const { return Version; }
130 
131  /// \brief Print information about the detected GCC installation.
132  void print(raw_ostream &OS) const;
133 
134  private:
135  static void
136  CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
137  const llvm::Triple &BiarchTriple,
139  SmallVectorImpl<StringRef> &TripleAliases,
140  SmallVectorImpl<StringRef> &BiarchLibDirs,
141  SmallVectorImpl<StringRef> &BiarchTripleAliases);
142 
143  void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch,
144  const llvm::opt::ArgList &Args,
145  const std::string &LibDir,
146  StringRef CandidateTriple,
147  bool NeedsBiarchSuffix = false);
148  };
149 
150 protected:
152 
153 public:
154  Generic_GCC(const Driver &D, const llvm::Triple &Triple,
155  const llvm::opt::ArgList &Args);
156  ~Generic_GCC() override;
157 
158  void printVerboseInfo(raw_ostream &OS) const override;
159 
160  bool IsUnwindTablesDefault() const override;
161  bool isPICDefault() const override;
162  bool isPIEDefault() const override;
163  bool isPICDefaultForced() const override;
164  bool IsIntegratedAssemblerDefault() const override;
165 
166 protected:
167  Tool *getTool(Action::ActionClass AC) const override;
168  Tool *buildAssembler() const override;
169  Tool *buildLinker() const override;
170 
171  /// \name ToolChain Implementation Helper Functions
172  /// @{
173 
174  /// \brief Check whether the target triple's architecture is 64-bits.
175  bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
176 
177  /// \brief Check whether the target triple's architecture is 32-bits.
178  bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
179 
180  /// @}
181 
182 private:
183  mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocess;
184  mutable std::unique_ptr<tools::gcc::Compiler> Compile;
185 };
186 
187 class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
188 protected:
189  Tool *buildAssembler() const override;
190  Tool *buildLinker() const override;
191  Tool *getTool(Action::ActionClass AC) const override;
192 
193 private:
194  mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
195  mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
196  mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug;
197 
198 public:
199  MachO(const Driver &D, const llvm::Triple &Triple,
200  const llvm::opt::ArgList &Args);
201  ~MachO() override;
202 
203  /// @name MachO specific toolchain API
204  /// {
205 
206  /// Get the "MachO" arch name for a particular compiler invocation. For
207  /// example, Apple treats different ARM variations as distinct architectures.
208  StringRef getMachOArchName(const llvm::opt::ArgList &Args) const;
209 
210  /// Add the linker arguments to link the ARC runtime library.
211  virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
212  llvm::opt::ArgStringList &CmdArgs) const {}
213 
214  /// Add the linker arguments to link the compiler runtime library.
215  virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
216  llvm::opt::ArgStringList &CmdArgs) const;
217 
218  virtual void addStartObjectFileArgs(const llvm::opt::ArgList &Args,
219  llvm::opt::ArgStringList &CmdArgs) const {
220  }
221 
222  virtual void addMinVersionArgs(const llvm::opt::ArgList &Args,
223  llvm::opt::ArgStringList &CmdArgs) const {}
224 
225  /// On some iOS platforms, kernel and kernel modules were built statically. Is
226  /// this such a target?
227  virtual bool isKernelStatic() const { return false; }
228 
229  /// Is the target either iOS or an iOS simulator?
230  bool isTargetIOSBased() const { return false; }
231 
232  void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
233  llvm::opt::ArgStringList &CmdArgs,
234  StringRef DarwinLibName, bool AlwaysLink = false,
235  bool IsEmbedded = false, bool AddRPath = false) const;
236 
237  /// Add any profiling runtime libraries that are needed. This is essentially a
238  /// MachO specific version of addProfileRT in Tools.cpp.
239  virtual void addProfileRTLibs(const llvm::opt::ArgList &Args,
240  llvm::opt::ArgStringList &CmdArgs) const {
241  // There aren't any profiling libs for embedded targets currently.
242  }
243 
244  /// }
245  /// @name ToolChain Implementation
246  /// {
247 
248  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
249  types::ID InputType) const override;
250 
251  types::ID LookupTypeForExtension(const char *Ext) const override;
252 
253  bool HasNativeLLVMSupport() const override;
254 
255  llvm::opt::DerivedArgList *
256  TranslateArgs(const llvm::opt::DerivedArgList &Args,
257  const char *BoundArch) const override;
258 
259  bool IsBlocksDefault() const override {
260  // Always allow blocks on Apple; users interested in versioning are
261  // expected to use /usr/include/Block.h.
262  return true;
263  }
264  bool IsIntegratedAssemblerDefault() const override {
265  // Default integrated assembler to on for Apple's MachO targets.
266  return true;
267  }
268 
269  bool IsMathErrnoDefault() const override { return false; }
270 
271  bool IsEncodeExtendedBlockSignatureDefault() const override { return true; }
272 
273  bool IsObjCNonFragileABIDefault() const override {
274  // Non-fragile ABI is default for everything but i386.
275  return getTriple().getArch() != llvm::Triple::x86;
276  }
277 
278  bool UseObjCMixedDispatch() const override { return true; }
279 
280  bool IsUnwindTablesDefault() const override;
281 
284  }
285 
286  bool isPICDefault() const override;
287  bool isPIEDefault() const override;
288  bool isPICDefaultForced() const override;
289 
290  bool SupportsProfiling() const override;
291 
292  bool SupportsObjCGC() const override { return false; }
293 
294  bool UseDwarfDebugFlags() const override;
295 
296  bool UseSjLjExceptions() const override { return false; }
297 
298  /// }
299 };
300 
301 /// Darwin - The base Darwin tool chain.
302 class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
303 public:
304  /// Whether the information on the target has been initialized.
305  //
306  // FIXME: This should be eliminated. What we want to do is make this part of
307  // the "default target for arguments" selection process, once we get out of
308  // the argument translation business.
309  mutable bool TargetInitialized;
310 
311  enum DarwinPlatformKind { MacOS, IPhoneOS, IPhoneOSSimulator };
312 
314 
315  /// The OS version we are targeting.
317 
318 private:
319  void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
320 
321 public:
322  Darwin(const Driver &D, const llvm::Triple &Triple,
323  const llvm::opt::ArgList &Args);
324  ~Darwin() override;
325 
326  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
327  types::ID InputType) const override;
328 
329  /// @name Apple Specific Toolchain Implementation
330  /// {
331 
332  void addMinVersionArgs(const llvm::opt::ArgList &Args,
333  llvm::opt::ArgStringList &CmdArgs) const override;
334 
335  void addStartObjectFileArgs(const llvm::opt::ArgList &Args,
336  llvm::opt::ArgStringList &CmdArgs) const override;
337 
338  bool isKernelStatic() const override {
339  return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0);
340  }
341 
342  void addProfileRTLibs(const llvm::opt::ArgList &Args,
343  llvm::opt::ArgStringList &CmdArgs) const override;
344 
345 protected:
346  /// }
347  /// @name Darwin specific Toolchain functions
348  /// {
349 
350  // FIXME: Eliminate these ...Target functions and derive separate tool chains
351  // for these targets and put version in constructor.
352  void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
353  unsigned Micro) const {
354  // FIXME: For now, allow reinitialization as long as values don't
355  // change. This will go away when we move away from argument translation.
356  if (TargetInitialized && TargetPlatform == Platform &&
357  TargetVersion == VersionTuple(Major, Minor, Micro))
358  return;
359 
360  assert(!TargetInitialized && "Target already initialized!");
361  TargetInitialized = true;
362  TargetPlatform = Platform;
363  TargetVersion = VersionTuple(Major, Minor, Micro);
364  }
365 
366  bool isTargetIPhoneOS() const {
367  assert(TargetInitialized && "Target not initialized!");
368  return TargetPlatform == IPhoneOS;
369  }
370 
371  bool isTargetIOSSimulator() const {
372  assert(TargetInitialized && "Target not initialized!");
373  return TargetPlatform == IPhoneOSSimulator;
374  }
375 
376  bool isTargetIOSBased() const {
377  assert(TargetInitialized && "Target not initialized!");
378  return isTargetIPhoneOS() || isTargetIOSSimulator();
379  }
380 
381  bool isTargetMacOS() const {
382  assert(TargetInitialized && "Target not initialized!");
383  return TargetPlatform == MacOS;
384  }
385 
386  bool isTargetInitialized() const { return TargetInitialized; }
387 
389  assert(TargetInitialized && "Target not initialized!");
390  return TargetVersion;
391  }
392 
393  bool isIPhoneOSVersionLT(unsigned V0, unsigned V1 = 0,
394  unsigned V2 = 0) const {
395  assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
396  return TargetVersion < VersionTuple(V0, V1, V2);
397  }
398 
399  bool isMacosxVersionLT(unsigned V0, unsigned V1 = 0, unsigned V2 = 0) const {
400  assert(isTargetMacOS() && "Unexpected call for non OS X target!");
401  return TargetVersion < VersionTuple(V0, V1, V2);
402  }
403 
404 public:
405  /// }
406  /// @name ToolChain Implementation
407  /// {
408 
409  // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
410  // most development is done against SDKs, so compiling for a different
411  // architecture should not get any special treatment.
412  bool isCrossCompiling() const override { return false; }
413 
414  llvm::opt::DerivedArgList *
415  TranslateArgs(const llvm::opt::DerivedArgList &Args,
416  const char *BoundArch) const override;
417 
418  ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
419  bool hasBlocksRuntime() const override;
420 
421  bool UseObjCMixedDispatch() const override {
422  // This is only used with the non-fragile ABI and non-legacy dispatch.
423 
424  // Mixed dispatch is used everywhere except OS X before 10.6.
425  return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
426  }
427 
428  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
429  // Stack protectors default to on for user code on 10.5,
430  // and for everything in 10.6 and beyond
431  if (isTargetIOSBased())
432  return 1;
433  else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
434  return 1;
435  else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
436  return 1;
437 
438  return 0;
439  }
440 
441  bool SupportsObjCGC() const override;
442 
443  void CheckObjCARC() const override;
444 
445  bool UseSjLjExceptions() const override;
446 
447  SanitizerMask getSupportedSanitizers() const override;
448 };
449 
450 /// DarwinClang - The Darwin toolchain used by Clang.
451 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
452 public:
453  DarwinClang(const Driver &D, const llvm::Triple &Triple,
454  const llvm::opt::ArgList &Args);
455 
456  /// @name Apple ToolChain Implementation
457  /// {
458 
459  void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
460  llvm::opt::ArgStringList &CmdArgs) const override;
461 
462  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
463  llvm::opt::ArgStringList &CmdArgs) const override;
464 
465  void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
466  llvm::opt::ArgStringList &CmdArgs) const override;
467 
468  void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
469 
470  void AddLinkARCArgs(const llvm::opt::ArgList &Args,
471  llvm::opt::ArgStringList &CmdArgs) const override;
472  /// }
473 
474 private:
475  void AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
476  llvm::opt::ArgStringList &CmdArgs,
477  StringRef Sanitizer) const;
478 };
479 
480 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
481  virtual void anchor();
482 
483 public:
484  Generic_ELF(const Driver &D, const llvm::Triple &Triple,
485  const llvm::opt::ArgList &Args)
486  : Generic_GCC(D, Triple, Args) {}
487 
488  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
489  llvm::opt::ArgStringList &CC1Args) const override;
490 };
491 
492 class LLVM_LIBRARY_VISIBILITY CloudABI : public Generic_ELF {
493 public:
494  CloudABI(const Driver &D, const llvm::Triple &Triple,
495  const llvm::opt::ArgList &Args);
496  bool HasNativeLLVMSupport() const override { return true; }
497 
498  bool IsMathErrnoDefault() const override { return false; }
499  bool IsObjCNonFragileABIDefault() const override { return true; }
500 
501  CXXStdlibType
502  GetCXXStdlibType(const llvm::opt::ArgList &Args) const override {
503  return ToolChain::CST_Libcxx;
504  }
505  void AddClangCXXStdlibIncludeArgs(
506  const llvm::opt::ArgList &DriverArgs,
507  llvm::opt::ArgStringList &CC1Args) const override;
508  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
509  llvm::opt::ArgStringList &CmdArgs) const override;
510 
511  bool isPIEDefault() const override { return false; }
512 
513 protected:
514  Tool *buildLinker() const override;
515 };
516 
517 class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
518 public:
519  Solaris(const Driver &D, const llvm::Triple &Triple,
520  const llvm::opt::ArgList &Args);
521 
522  bool IsIntegratedAssemblerDefault() const override { return true; }
523 
524 protected:
525  Tool *buildAssembler() const override;
526  Tool *buildLinker() const override;
527 };
528 
529 class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {
530 public:
531  MinGW(const Driver &D, const llvm::Triple &Triple,
532  const llvm::opt::ArgList &Args);
533 
534  bool IsIntegratedAssemblerDefault() const override;
535  bool IsUnwindTablesDefault() const override;
536  bool isPICDefault() const override;
537  bool isPIEDefault() const override;
538  bool isPICDefaultForced() const override;
539  bool UseSEHExceptions() const;
540 
541  void
542  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
543  llvm::opt::ArgStringList &CC1Args) const override;
544  void AddClangCXXStdlibIncludeArgs(
545  const llvm::opt::ArgList &DriverArgs,
546  llvm::opt::ArgStringList &CC1Args) const override;
547 
548 protected:
549  Tool *getTool(Action::ActionClass AC) const override;
550  Tool *buildLinker() const override;
551  Tool *buildAssembler() const override;
552 
553 private:
554  std::string Base;
555  std::string GccLibDir;
556  std::string Ver;
557  std::string Arch;
558  mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocessor;
559  mutable std::unique_ptr<tools::gcc::Compiler> Compiler;
560  void findGccLibDir();
561 };
562 
563 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
564 public:
565  OpenBSD(const Driver &D, const llvm::Triple &Triple,
566  const llvm::opt::ArgList &Args);
567 
568  bool IsMathErrnoDefault() const override { return false; }
569  bool IsObjCNonFragileABIDefault() const override { return true; }
570  bool isPIEDefault() const override { return true; }
571 
572  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
573  return 2;
574  }
575 
576 protected:
577  Tool *buildAssembler() const override;
578  Tool *buildLinker() const override;
579 };
580 
581 class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
582 public:
583  Bitrig(const Driver &D, const llvm::Triple &Triple,
584  const llvm::opt::ArgList &Args);
585 
586  bool IsMathErrnoDefault() const override { return false; }
587  bool IsObjCNonFragileABIDefault() const override { return true; }
588 
589  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
590  void AddClangCXXStdlibIncludeArgs(
591  const llvm::opt::ArgList &DriverArgs,
592  llvm::opt::ArgStringList &CC1Args) const override;
593  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
594  llvm::opt::ArgStringList &CmdArgs) const override;
595  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
596  return 1;
597  }
598 
599 protected:
600  Tool *buildAssembler() const override;
601  Tool *buildLinker() const override;
602 };
603 
604 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
605 public:
606  FreeBSD(const Driver &D, const llvm::Triple &Triple,
607  const llvm::opt::ArgList &Args);
608  bool HasNativeLLVMSupport() const override;
609 
610  bool IsMathErrnoDefault() const override { return false; }
611  bool IsObjCNonFragileABIDefault() const override { return true; }
612 
613  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
614  void AddClangCXXStdlibIncludeArgs(
615  const llvm::opt::ArgList &DriverArgs,
616  llvm::opt::ArgStringList &CC1Args) const override;
617 
618  bool UseSjLjExceptions() const override;
619  bool isPIEDefault() const override;
620  SanitizerMask getSupportedSanitizers() const override;
621 
622 protected:
623  Tool *buildAssembler() const override;
624  Tool *buildLinker() const override;
625 };
626 
627 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
628 public:
629  NetBSD(const Driver &D, const llvm::Triple &Triple,
630  const llvm::opt::ArgList &Args);
631 
632  bool IsMathErrnoDefault() const override { return false; }
633  bool IsObjCNonFragileABIDefault() const override { return true; }
634 
635  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
636 
637  void AddClangCXXStdlibIncludeArgs(
638  const llvm::opt::ArgList &DriverArgs,
639  llvm::opt::ArgStringList &CC1Args) const override;
640  bool IsUnwindTablesDefault() const override { return true; }
641 
642 protected:
643  Tool *buildAssembler() const override;
644  Tool *buildLinker() const override;
645 };
646 
647 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
648 public:
649  Minix(const Driver &D, const llvm::Triple &Triple,
650  const llvm::opt::ArgList &Args);
651 
652 protected:
653  Tool *buildAssembler() const override;
654  Tool *buildLinker() const override;
655 };
656 
657 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
658 public:
659  DragonFly(const Driver &D, const llvm::Triple &Triple,
660  const llvm::opt::ArgList &Args);
661 
662  bool IsMathErrnoDefault() const override { return false; }
663 
664 protected:
665  Tool *buildAssembler() const override;
666  Tool *buildLinker() const override;
667 };
668 
669 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
670 public:
671  Linux(const Driver &D, const llvm::Triple &Triple,
672  const llvm::opt::ArgList &Args);
673 
674  bool HasNativeLLVMSupport() const override;
675 
676  void
677  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
678  llvm::opt::ArgStringList &CC1Args) const override;
679  void AddClangCXXStdlibIncludeArgs(
680  const llvm::opt::ArgList &DriverArgs,
681  llvm::opt::ArgStringList &CC1Args) const override;
682  bool isPIEDefault() const override;
683  SanitizerMask getSupportedSanitizers() const override;
684 
685  std::string Linker;
686  std::vector<std::string> ExtraOpts;
687 
688 protected:
689  Tool *buildAssembler() const override;
690  Tool *buildLinker() const override;
691 
692 private:
693  static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
694  StringRef GCCTriple,
695  StringRef GCCMultiarchTriple,
696  StringRef TargetMultiarchTriple,
697  Twine IncludeSuffix,
698  const llvm::opt::ArgList &DriverArgs,
699  llvm::opt::ArgStringList &CC1Args);
700 
701  std::string computeSysRoot() const;
702 };
703 
704 class LLVM_LIBRARY_VISIBILITY CudaToolChain : public Linux {
705 public:
706  CudaToolChain(const Driver &D, const llvm::Triple &Triple,
707  const llvm::opt::ArgList &Args);
708 
709  llvm::opt::DerivedArgList *
710  TranslateArgs(const llvm::opt::DerivedArgList &Args,
711  const char *BoundArch) const override;
712  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
713  llvm::opt::ArgStringList &CC1Args) const override;
714 };
715 
716 class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
717 protected:
719  Tool *buildAssembler() const override;
720  Tool *buildLinker() const override;
721 
722 public:
723  Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
724  const llvm::opt::ArgList &Args);
725  ~Hexagon_TC() override;
726 
727  void
728  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
729  llvm::opt::ArgStringList &CC1Args) const override;
730  void AddClangCXXStdlibIncludeArgs(
731  const llvm::opt::ArgList &DriverArgs,
732  llvm::opt::ArgStringList &CC1Args) const override;
733  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
734 
735  StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
736 
737  static std::string GetGnuDir(const std::string &InstalledDir,
738  const llvm::opt::ArgList &Args);
739 
740  static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
741 
742  static const char *GetSmallDataThreshold(const llvm::opt::ArgList &Args);
743 
744  static bool UsesG0(const char *smallDataThreshold);
745 };
746 
747 class LLVM_LIBRARY_VISIBILITY NaCl_TC : public Generic_ELF {
748 public:
749  NaCl_TC(const Driver &D, const llvm::Triple &Triple,
750  const llvm::opt::ArgList &Args);
751 
752  void
753  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
754  llvm::opt::ArgStringList &CC1Args) const override;
755  void AddClangCXXStdlibIncludeArgs(
756  const llvm::opt::ArgList &DriverArgs,
757  llvm::opt::ArgStringList &CC1Args) const override;
758 
759  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
760 
761  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
762  llvm::opt::ArgStringList &CmdArgs) const override;
763 
764  bool IsIntegratedAssemblerDefault() const override {
765  return getTriple().getArch() == llvm::Triple::mipsel;
766  }
767 
768  // Get the path to the file containing NaCl's ARM macros. It lives in NaCl_TC
769  // because the AssembleARM tool needs a const char * that it can pass around
770  // and the toolchain outlives all the jobs.
771  const char *GetNaClArmMacrosPath() const { return NaClArmMacrosPath.c_str(); }
772 
773  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
774  types::ID InputType) const override;
775  std::string Linker;
776 
777 protected:
778  Tool *buildLinker() const override;
779  Tool *buildAssembler() const override;
780 
781 private:
782  std::string NaClArmMacrosPath;
783 };
784 
785 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
786 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
787 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
788 public:
789  TCEToolChain(const Driver &D, const llvm::Triple &Triple,
790  const llvm::opt::ArgList &Args);
791  ~TCEToolChain() override;
792 
793  bool IsMathErrnoDefault() const override;
794  bool isPICDefault() const override;
795  bool isPIEDefault() const override;
796  bool isPICDefaultForced() const override;
797 };
798 
799 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
800 public:
801  MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
802  const llvm::opt::ArgList &Args);
803 
804  bool IsIntegratedAssemblerDefault() const override;
805  bool IsUnwindTablesDefault() const override;
806  bool isPICDefault() const override;
807  bool isPIEDefault() const override;
808  bool isPICDefaultForced() const override;
809 
810  void
811  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
812  llvm::opt::ArgStringList &CC1Args) const override;
813  void AddClangCXXStdlibIncludeArgs(
814  const llvm::opt::ArgList &DriverArgs,
815  llvm::opt::ArgStringList &CC1Args) const override;
816 
817  bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
818  bool getWindowsSDKLibraryPath(std::string &path) const;
819  bool getVisualStudioInstallDir(std::string &path) const;
820  bool getVisualStudioBinariesFolder(const char *clangProgramPath,
821  std::string &path) const;
822 
823  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
824  types::ID InputType) const override;
825  SanitizerMask getSupportedSanitizers() const override;
826 
827 protected:
828  void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
829  llvm::opt::ArgStringList &CC1Args,
830  const std::string &folder,
831  const char *subfolder) const;
832 
833  Tool *buildLinker() const override;
834  Tool *buildAssembler() const override;
835 };
836 
837 class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
838 public:
839  CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
840  const llvm::opt::ArgList &Args);
841 
842  bool IsIntegratedAssemblerDefault() const override { return true; }
843  bool IsUnwindTablesDefault() const override;
844  bool isPICDefault() const override;
845  bool isPIEDefault() const override;
846  bool isPICDefaultForced() const override;
847 
848  unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
849  return 0;
850  }
851 
852  void
853  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
854  llvm::opt::ArgStringList &CC1Args) const override;
855  void AddClangCXXStdlibIncludeArgs(
856  const llvm::opt::ArgList &DriverArgs,
857  llvm::opt::ArgStringList &CC1Args) const override;
858  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
859  llvm::opt::ArgStringList &CmdArgs) const override;
860 
861 protected:
862  Tool *buildLinker() const override;
863  Tool *buildAssembler() const override;
864 };
865 
866 class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
867 public:
868  XCore(const Driver &D, const llvm::Triple &Triple,
869  const llvm::opt::ArgList &Args);
870 
871 protected:
872  Tool *buildAssembler() const override;
873  Tool *buildLinker() const override;
874 
875 public:
876  bool isPICDefault() const override;
877  bool isPIEDefault() const override;
878  bool isPICDefaultForced() const override;
879  bool SupportsProfiling() const override;
880  bool hasBlocksRuntime() const override;
881  void
882  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
883  llvm::opt::ArgStringList &CC1Args) const override;
884  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
885  llvm::opt::ArgStringList &CC1Args) const override;
886  void AddClangCXXStdlibIncludeArgs(
887  const llvm::opt::ArgList &DriverArgs,
888  llvm::opt::ArgStringList &CC1Args) const override;
889  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
890  llvm::opt::ArgStringList &CmdArgs) const override;
891 };
892 
893 /// SHAVEToolChain - A tool chain using the compiler installed by the the
894 // Movidius SDK into MV_TOOLS_DIR (which we assume will be copied to llvm's
895 // installation dir) to perform all subcommands.
896 class LLVM_LIBRARY_VISIBILITY SHAVEToolChain : public Generic_GCC {
897 public:
898  SHAVEToolChain(const Driver &D, const llvm::Triple &Triple,
899  const llvm::opt::ArgList &Args);
900  ~SHAVEToolChain() override;
901 
902  virtual Tool *SelectTool(const JobAction &JA) const override;
903 
904 protected:
905  Tool *getTool(Action::ActionClass AC) const override;
906  Tool *buildAssembler() const override;
907  Tool *buildLinker() const override;
908 
909 private:
910  mutable std::unique_ptr<Tool> Compiler;
911  mutable std::unique_ptr<Tool> Assembler;
912 };
913 
914 } // end namespace toolchains
915 } // end namespace driver
916 } // end namespace clang
917 
918 #endif
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: ToolChains.h:498
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: ToolChains.h:511
bool IsEncodeExtendedBlockSignatureDefault() const override
Definition: ToolChains.h:271
DarwinClang - The Darwin toolchain used by Clang.
Definition: ToolChains.h:451
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override
Definition: ToolChains.h:428
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: ToolChains.h:662
SHAVEToolChain - A tool chain using the compiler installed by the the.
Definition: ToolChains.h:896
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: ToolChains.h:586
bool IsIntegratedAssemblerDefault() const override
Definition: ToolChains.h:764
RuntimeLibType GetDefaultRuntimeLibType() const override
GetDefaultRuntimeLibType - Get the default runtime library variant to use.
Definition: ToolChains.h:282
unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override
Definition: ToolChains.h:848
bool isCrossCompiling() const override
Returns true if the toolchain is targeting a non-native architecture.
Definition: ToolChains.h:412
Struct to store and manipulate GCC versions.
Definition: ToolChains.h:48
StringRef getInstallPath() const
Get the detected GCC installation path.
Definition: ToolChains.h:113
bool operator<=(const GCCVersion &RHS) const
Definition: ToolChains.h:68
StringRef GetGCCLibAndIncVersion() const
Definition: ToolChains.h:735
virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Definition: ToolChains.h:239
bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const
Definition: ToolChains.h:393
bool IsBlocksDefault() const override
IsBlocksDefault - Does this tool chain enable -fblocks by default.
Definition: ToolChains.h:259
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: ToolChains.h:568
std::string PatchSuffix
Any textual suffix on the patch number.
Definition: ToolChains.h:59
bool TargetInitialized
Whether the information on the target has been initialized.
Definition: ToolChains.h:309
const llvm::Triple & getTriple() const
Get the GCC triple for the detected install.
Definition: ToolChains.h:110
bool IsObjCNonFragileABIDefault() const override
Definition: ToolChains.h:499
GCCInstallationDetector GCCInstallation
Definition: ToolChains.h:151
bool IsObjCNonFragileABIDefault() const override
Definition: ToolChains.h:569
bool UseSjLjExceptions() const override
UseSjLjExceptions - Does this tool chain use SjLj exceptions.
Definition: ToolChains.h:296
virtual void addStartObjectFileArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Definition: ToolChains.h:218
Darwin - The base Darwin tool chain.
Definition: ToolChains.h:302
bool IsIntegratedAssemblerDefault() const override
Definition: ToolChains.h:522
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: ToolChains.h:269
const Multilib & getMultilib() const
Get the detected Multilib.
Definition: ToolChains.h:119
unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override
Definition: ToolChains.h:572
bool IsObjCNonFragileABIDefault() const override
Definition: ToolChains.h:587
const MultilibSet & getMultilibs() const
Get the whole MultilibSet.
Definition: ToolChains.h:122
bool SupportsObjCGC() const override
Does this tool chain support Objective-C garbage collection.
Definition: ToolChains.h:292
bool isValid() const
Check whether we detected a valid GCC install.
Definition: ToolChains.h:107
VersionTuple getTargetVersion() const
Definition: ToolChains.h:388
VersionTuple TargetVersion
The OS version we are targeting.
Definition: ToolChains.h:316
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition: ToolChains.h:502
bool IsUnwindTablesDefault() const override
Definition: ToolChains.h:640
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: ToolChains.h:610
virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Add the linker arguments to link the ARC runtime library.
Definition: ToolChains.h:211
bool UseObjCMixedDispatch() const override
Definition: ToolChains.h:421
void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor, unsigned Micro) const
Definition: ToolChains.h:352
#define false
Definition: stdbool.h:33
bool isKernelStatic() const override
Definition: ToolChains.h:338
bool isTargetIOSBased() const
Is the target either iOS or an iOS simulator?
Definition: ToolChains.h:230
bool HasNativeLLVMSupport() const override
Definition: ToolChains.h:496
This is a class to find a viable GCC installation for Clang to use.
Definition: ToolChains.h:78
bool operator>=(const GCCVersion &RHS) const
Definition: ToolChains.h:69
bool isTarget32Bit() const
Check whether the target triple's architecture is 32-bits.
Definition: ToolChains.h:178
unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override
Definition: ToolChains.h:595
virtual bool isKernelStatic() const
Definition: ToolChains.h:227
DarwinPlatformKind TargetPlatform
Definition: ToolChains.h:313
uint64_t SanitizerMask
Definition: Sanitizers.h:24
const char * GetNaClArmMacrosPath() const
Definition: ToolChains.h:771
bool IsObjCNonFragileABIDefault() const override
Definition: ToolChains.h:273
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:25
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
virtual void addMinVersionArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Definition: ToolChains.h:222
bool operator>(const GCCVersion &RHS) const
Definition: ToolChains.h:67
bool IsIntegratedAssemblerDefault() const override
Definition: ToolChains.h:264
std::string Text
The unparsed text of the version.
Definition: ToolChains.h:50
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: ToolChains.h:632
bool isTarget64Bit() const
Check whether the target triple's architecture is 64-bits.
Definition: ToolChains.h:175
const GCCVersion & getVersion() const
Get the detected GCC version string.
Definition: ToolChains.h:129
Generic_ELF(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: ToolChains.h:484
bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const
Definition: ToolChains.h:399
bool operator<(const GCCVersion &RHS) const
Definition: ToolChains.h:64
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: ToolChains.h:570
Defines the clang::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
bool IsObjCNonFragileABIDefault() const override
Definition: ToolChains.h:633
bool UseObjCMixedDispatch() const override
Definition: ToolChains.h:278
std::vector< std::string > ExtraOpts
Definition: ToolChains.h:686
int Major
The parsed major, minor, and patch numbers.
Definition: ToolChains.h:53
StringRef getParentLibPath() const
Get the detected GCC parent lib path.
Definition: ToolChains.h:116
bool IsObjCNonFragileABIDefault() const override
Definition: ToolChains.h:611
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:96
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:43