]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Driver/ToolChains.h
Merge ^/head r284737 through r285152.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Driver / ToolChains.h
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"
14 #include "clang/Basic/VersionTuple.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 protected:
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.
78   class GCCInstallationDetector {
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:
102     GCCInstallationDetector() : IsValid(false) {}
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,
138                              SmallVectorImpl<StringRef> &LibDirs,
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   GCCInstallationDetector GCCInstallation;
151
152 public:
153   Generic_GCC(const Driver &D, const llvm::Triple &Triple,
154               const llvm::opt::ArgList &Args);
155   ~Generic_GCC() override;
156
157   void printVerboseInfo(raw_ostream &OS) const override;
158
159   bool IsUnwindTablesDefault() const override;
160   bool isPICDefault() const override;
161   bool isPIEDefault() const override;
162   bool isPICDefaultForced() const override;
163   bool IsIntegratedAssemblerDefault() const override;
164
165 protected:
166   Tool *getTool(Action::ActionClass AC) const override;
167   Tool *buildAssembler() const override;
168   Tool *buildLinker() const override;
169
170   /// \name ToolChain Implementation Helper Functions
171   /// @{
172
173   /// \brief Check whether the target triple's architecture is 64-bits.
174   bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
175
176   /// \brief Check whether the target triple's architecture is 32-bits.
177   bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
178
179   /// @}
180
181 private:
182   mutable std::unique_ptr<tools::gcc::Preprocess> Preprocess;
183   mutable std::unique_ptr<tools::gcc::Compile> Compile;
184 };
185
186 class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
187 protected:
188   Tool *buildAssembler() const override;
189   Tool *buildLinker() const override;
190   Tool *getTool(Action::ActionClass AC) const override;
191 private:
192   mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
193   mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
194   mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug;
195
196 public:
197   MachO(const Driver &D, const llvm::Triple &Triple,
198              const llvm::opt::ArgList &Args);
199   ~MachO() override;
200
201   /// @name MachO specific toolchain API
202   /// {
203
204   /// Get the "MachO" arch name for a particular compiler invocation. For
205   /// example, Apple treats different ARM variations as distinct architectures.
206   StringRef getMachOArchName(const llvm::opt::ArgList &Args) const;
207
208
209   /// Add the linker arguments to link the ARC runtime library.
210   virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
211                               llvm::opt::ArgStringList &CmdArgs) const {}
212
213   /// Add the linker arguments to link the compiler runtime library.
214   virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
215                                      llvm::opt::ArgStringList &CmdArgs) const;
216
217   virtual void
218   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
219                          llvm::opt::ArgStringList &CmdArgs) const {}
220
221   virtual void addMinVersionArgs(const llvm::opt::ArgList &Args,
222                                  llvm::opt::ArgStringList &CmdArgs) const {}
223
224   /// On some iOS platforms, kernel and kernel modules were built statically. Is
225   /// this such a target?
226   virtual bool isKernelStatic() const {
227     return false;
228   }
229
230   /// Is the target either iOS or an iOS simulator?
231   bool isTargetIOSBased() const {
232     return false;
233   }
234
235   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
236                          llvm::opt::ArgStringList &CmdArgs,
237                          StringRef DarwinLibName,
238                          bool AlwaysLink = false,
239                          bool IsEmbedded = false,
240                          bool AddRPath = false) const;
241
242   /// Add any profiling runtime libraries that are needed. This is essentially a
243   /// MachO specific version of addProfileRT in Tools.cpp.
244   virtual void addProfileRTLibs(const llvm::opt::ArgList &Args,
245                                 llvm::opt::ArgStringList &CmdArgs) const {
246     // There aren't any profiling libs for embedded targets currently.
247   }
248
249   /// }
250   /// @name ToolChain Implementation
251   /// {
252
253   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
254                                           types::ID InputType) const override;
255
256   types::ID LookupTypeForExtension(const char *Ext) const override;
257
258   bool HasNativeLLVMSupport() const override;
259
260   llvm::opt::DerivedArgList *
261   TranslateArgs(const llvm::opt::DerivedArgList &Args,
262                 const char *BoundArch) const override;
263
264   bool IsBlocksDefault() const override {
265     // Always allow blocks on Apple; users interested in versioning are
266     // expected to use /usr/include/Block.h.
267     return true;
268   }
269   bool IsIntegratedAssemblerDefault() const override {
270     // Default integrated assembler to on for Apple's MachO targets.
271     return true;
272   }
273
274   bool IsMathErrnoDefault() const override {
275     return false;
276   }
277
278   bool IsEncodeExtendedBlockSignatureDefault() const override {
279     return true;
280   }
281
282   bool IsObjCNonFragileABIDefault() const override {
283     // Non-fragile ABI is default for everything but i386.
284     return getTriple().getArch() != llvm::Triple::x86;
285   }
286
287   bool UseObjCMixedDispatch() const override {
288     return true;
289   }
290
291   bool IsUnwindTablesDefault() const override;
292
293   RuntimeLibType GetDefaultRuntimeLibType() const override {
294     return ToolChain::RLT_CompilerRT;
295   }
296
297   bool isPICDefault() const override;
298   bool isPIEDefault() const override;
299   bool isPICDefaultForced() const override;
300
301   bool SupportsProfiling() const override;
302
303   bool SupportsObjCGC() const override {
304     return false;
305   }
306
307   bool UseDwarfDebugFlags() const override;
308
309   bool UseSjLjExceptions() const override {
310     return false;
311   }
312
313   /// }
314 };
315
316   /// Darwin - The base Darwin tool chain.
317 class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
318 public:
319   /// Whether the information on the target has been initialized.
320   //
321   // FIXME: This should be eliminated. What we want to do is make this part of
322   // the "default target for arguments" selection process, once we get out of
323   // the argument translation business.
324   mutable bool TargetInitialized;
325
326   enum DarwinPlatformKind {
327     MacOS,
328     IPhoneOS,
329     IPhoneOSSimulator
330   };
331
332   mutable DarwinPlatformKind TargetPlatform;
333
334   /// The OS version we are targeting.
335   mutable VersionTuple TargetVersion;
336
337 private:
338   void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
339
340 public:
341   Darwin(const Driver &D, const llvm::Triple &Triple,
342          const llvm::opt::ArgList &Args);
343   ~Darwin() override;
344
345   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
346                                           types::ID InputType) const override;
347
348   /// @name Apple Specific Toolchain Implementation
349   /// {
350
351   void
352   addMinVersionArgs(const llvm::opt::ArgList &Args,
353                     llvm::opt::ArgStringList &CmdArgs) const override;
354
355   void
356   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
357                          llvm::opt::ArgStringList &CmdArgs) const override;
358
359   bool isKernelStatic() const override {
360     return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0);
361   }
362
363   void addProfileRTLibs(const llvm::opt::ArgList &Args,
364                         llvm::opt::ArgStringList &CmdArgs) const override;
365
366 protected:
367   /// }
368   /// @name Darwin specific Toolchain functions
369   /// {
370
371   // FIXME: Eliminate these ...Target functions and derive separate tool chains
372   // for these targets and put version in constructor.
373   void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
374                  unsigned Micro) const {
375     // FIXME: For now, allow reinitialization as long as values don't
376     // change. This will go away when we move away from argument translation.
377     if (TargetInitialized && TargetPlatform == Platform &&
378         TargetVersion == VersionTuple(Major, Minor, Micro))
379       return;
380
381     assert(!TargetInitialized && "Target already initialized!");
382     TargetInitialized = true;
383     TargetPlatform = Platform;
384     TargetVersion = VersionTuple(Major, Minor, Micro);
385   }
386
387   bool isTargetIPhoneOS() const {
388     assert(TargetInitialized && "Target not initialized!");
389     return TargetPlatform == IPhoneOS;
390   }
391
392   bool isTargetIOSSimulator() const {
393     assert(TargetInitialized && "Target not initialized!");
394     return TargetPlatform == IPhoneOSSimulator;
395   }
396
397   bool isTargetIOSBased() const {
398     assert(TargetInitialized && "Target not initialized!");
399     return isTargetIPhoneOS() || isTargetIOSSimulator();
400   }
401
402   bool isTargetMacOS() const {
403     assert(TargetInitialized && "Target not initialized!");
404     return TargetPlatform == MacOS;
405   }
406
407   bool isTargetInitialized() const { return TargetInitialized; }
408
409   VersionTuple getTargetVersion() const {
410     assert(TargetInitialized && "Target not initialized!");
411     return TargetVersion;
412   }
413
414   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
415     assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
416     return TargetVersion < VersionTuple(V0, V1, V2);
417   }
418
419   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
420     assert(isTargetMacOS() && "Unexpected call for non OS X target!");
421     return TargetVersion < VersionTuple(V0, V1, V2);
422   }
423
424 public:
425   /// }
426   /// @name ToolChain Implementation
427   /// {
428
429   // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
430   // most development is done against SDKs, so compiling for a different
431   // architecture should not get any special treatment.
432   bool isCrossCompiling() const override { return false; }
433
434   llvm::opt::DerivedArgList *
435   TranslateArgs(const llvm::opt::DerivedArgList &Args,
436                 const char *BoundArch) const override;
437
438   ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
439   bool hasBlocksRuntime() const override;
440
441   bool UseObjCMixedDispatch() const override {
442     // This is only used with the non-fragile ABI and non-legacy dispatch.
443
444     // Mixed dispatch is used everywhere except OS X before 10.6.
445     return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
446   }
447
448   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
449     // Stack protectors default to on for user code on 10.5,
450     // and for everything in 10.6 and beyond
451     if (isTargetIOSBased())
452       return 1;
453     else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
454       return 1;
455     else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
456       return 1;
457
458     return 0;
459   }
460
461   bool SupportsObjCGC() const override;
462
463   void CheckObjCARC() const override;
464
465   bool UseSjLjExceptions() const override;
466
467   SanitizerMask getSupportedSanitizers() const override;
468 };
469
470 /// DarwinClang - The Darwin toolchain used by Clang.
471 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
472 public:
473   DarwinClang(const Driver &D, const llvm::Triple &Triple,
474               const llvm::opt::ArgList &Args);
475
476   /// @name Apple ToolChain Implementation
477   /// {
478
479   void
480   AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
481                         llvm::opt::ArgStringList &CmdArgs) const override;
482
483   void
484   AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
485                       llvm::opt::ArgStringList &CmdArgs) const override;
486
487   void
488   AddCCKextLibArgs(const llvm::opt::ArgList &Args,
489                    llvm::opt::ArgStringList &CmdArgs) const override;
490
491   void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
492
493   void
494   AddLinkARCArgs(const llvm::opt::ArgList &Args,
495                  llvm::opt::ArgStringList &CmdArgs) const override;
496   /// }
497
498 private:
499   void AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
500                                llvm::opt::ArgStringList &CmdArgs,
501                                StringRef Sanitizer) const;
502 };
503
504 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
505   virtual void anchor();
506 public:
507   Generic_ELF(const Driver &D, const llvm::Triple &Triple,
508               const llvm::opt::ArgList &Args)
509       : Generic_GCC(D, Triple, Args) {}
510
511   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
512                              llvm::opt::ArgStringList &CC1Args) const override;
513 };
514
515 class LLVM_LIBRARY_VISIBILITY CloudABI : public Generic_ELF {
516 public:
517   CloudABI(const Driver &D, const llvm::Triple &Triple,
518            const llvm::opt::ArgList &Args);
519   bool HasNativeLLVMSupport() const override { return true; }
520
521   bool IsMathErrnoDefault() const override { return false; }
522   bool IsObjCNonFragileABIDefault() const override { return true; }
523
524   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args)
525       const override {
526     return ToolChain::CST_Libcxx;
527   }
528   void AddClangCXXStdlibIncludeArgs(
529       const llvm::opt::ArgList &DriverArgs,
530       llvm::opt::ArgStringList &CC1Args) const override;
531   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
532                            llvm::opt::ArgStringList &CmdArgs) const override;
533
534   bool isPIEDefault() const override { return false; }
535
536 protected:
537   Tool *buildLinker() const override;
538 };
539
540 class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
541 public:
542   Solaris(const Driver &D, const llvm::Triple &Triple,
543           const llvm::opt::ArgList &Args);
544
545   bool IsIntegratedAssemblerDefault() const override { return true; }
546 protected:
547   Tool *buildAssembler() const override;
548   Tool *buildLinker() const override;
549
550 };
551
552
553 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
554 public:
555   OpenBSD(const Driver &D, const llvm::Triple &Triple,
556           const llvm::opt::ArgList &Args);
557
558   bool IsMathErrnoDefault() const override { return false; }
559   bool IsObjCNonFragileABIDefault() const override { return true; }
560   bool isPIEDefault() const override { return true; }
561
562   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
563     return 2;
564   }
565
566 protected:
567   Tool *buildAssembler() const override;
568   Tool *buildLinker() const override;
569 };
570
571 class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
572 public:
573   Bitrig(const Driver &D, const llvm::Triple &Triple,
574          const llvm::opt::ArgList &Args);
575
576   bool IsMathErrnoDefault() const override { return false; }
577   bool IsObjCNonFragileABIDefault() const override { return true; }
578
579   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
580   void
581   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
582                               llvm::opt::ArgStringList &CC1Args) const override;
583   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
584                            llvm::opt::ArgStringList &CmdArgs) const override;
585   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
586      return 1;
587   }
588
589 protected:
590   Tool *buildAssembler() const override;
591   Tool *buildLinker() const override;
592 };
593
594 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
595 public:
596   FreeBSD(const Driver &D, const llvm::Triple &Triple,
597           const llvm::opt::ArgList &Args);
598   bool HasNativeLLVMSupport() const override;
599
600   bool IsMathErrnoDefault() const override { return false; }
601   bool IsObjCNonFragileABIDefault() const override { return true; }
602
603   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
604   void
605   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
606                                llvm::opt::ArgStringList &CC1Args) const override;
607
608   bool UseSjLjExceptions() const override;
609   bool isPIEDefault() const override;
610   SanitizerMask getSupportedSanitizers() const override;
611 protected:
612   Tool *buildAssembler() const override;
613   Tool *buildLinker() const override;
614 };
615
616 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
617 public:
618   NetBSD(const Driver &D, const llvm::Triple &Triple,
619          const llvm::opt::ArgList &Args);
620
621   bool IsMathErrnoDefault() const override { return false; }
622   bool IsObjCNonFragileABIDefault() const override { return true; }
623
624   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
625
626   void
627   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
628                               llvm::opt::ArgStringList &CC1Args) const override;
629   bool IsUnwindTablesDefault() const override {
630     return true;
631   }
632
633 protected:
634   Tool *buildAssembler() const override;
635   Tool *buildLinker() const override;
636 };
637
638 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
639 public:
640   Minix(const Driver &D, const llvm::Triple &Triple,
641         const llvm::opt::ArgList &Args);
642
643 protected:
644   Tool *buildAssembler() const override;
645   Tool *buildLinker() const override;
646 };
647
648 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
649 public:
650   DragonFly(const Driver &D, const llvm::Triple &Triple,
651             const llvm::opt::ArgList &Args);
652
653   bool IsMathErrnoDefault() const override { return false; }
654
655 protected:
656   Tool *buildAssembler() const override;
657   Tool *buildLinker() const override;
658 };
659
660 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
661 public:
662   Linux(const Driver &D, const llvm::Triple &Triple,
663         const llvm::opt::ArgList &Args);
664
665   bool HasNativeLLVMSupport() const override;
666
667   void
668   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
669                             llvm::opt::ArgStringList &CC1Args) const override;
670   void
671   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
672                                llvm::opt::ArgStringList &CC1Args) const override;
673   bool isPIEDefault() const override;
674   SanitizerMask getSupportedSanitizers() const override;
675
676   std::string Linker;
677   std::vector<std::string> ExtraOpts;
678
679 protected:
680   Tool *buildAssembler() const override;
681   Tool *buildLinker() const override;
682
683 private:
684   static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
685                                        StringRef GCCTriple,
686                                        StringRef GCCMultiarchTriple,
687                                        StringRef TargetMultiarchTriple,
688                                        Twine IncludeSuffix,
689                                        const llvm::opt::ArgList &DriverArgs,
690                                        llvm::opt::ArgStringList &CC1Args);
691
692   std::string computeSysRoot() const;
693 };
694
695 class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
696 protected:
697   GCCVersion GCCLibAndIncVersion;
698   Tool *buildAssembler() const override;
699   Tool *buildLinker() const override;
700
701 public:
702   Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
703              const llvm::opt::ArgList &Args);
704   ~Hexagon_TC() override;
705
706   void
707   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
708                             llvm::opt::ArgStringList &CC1Args) const override;
709   void
710   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
711                               llvm::opt::ArgStringList &CC1Args) const override;
712   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
713
714   StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
715
716   static std::string GetGnuDir(const std::string &InstalledDir,
717                                const llvm::opt::ArgList &Args);
718
719   static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
720
721   static const char *GetSmallDataThreshold(const llvm::opt::ArgList &Args);
722
723   static bool UsesG0(const char* smallDataThreshold);
724 };
725
726 class LLVM_LIBRARY_VISIBILITY NaCl_TC : public Generic_ELF {
727 public:
728   NaCl_TC(const Driver &D, const llvm::Triple &Triple,
729           const llvm::opt::ArgList &Args);
730
731   void
732   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
733                             llvm::opt::ArgStringList &CC1Args) const override;
734   void
735   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
736                                llvm::opt::ArgStringList &CC1Args) const override;
737
738   CXXStdlibType
739   GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
740
741   void
742   AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
743                       llvm::opt::ArgStringList &CmdArgs) const override;
744
745   bool
746   IsIntegratedAssemblerDefault() const override { return false; }
747
748   // Get the path to the file containing NaCl's ARM macros. It lives in NaCl_TC
749   // because the AssembleARM tool needs a const char * that it can pass around
750   // and the toolchain outlives all the jobs.
751   const char *GetNaClArmMacrosPath() const { return NaClArmMacrosPath.c_str(); }
752
753   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
754                                           types::ID InputType) const override;
755   std::string Linker;
756
757 protected:
758   Tool *buildLinker() const override;
759   Tool *buildAssembler() const override;
760
761 private:
762   std::string NaClArmMacrosPath;
763 };
764
765 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
766 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
767 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
768 public:
769   TCEToolChain(const Driver &D, const llvm::Triple &Triple,
770                const llvm::opt::ArgList &Args);
771   ~TCEToolChain() override;
772
773   bool IsMathErrnoDefault() const override;
774   bool isPICDefault() const override;
775   bool isPIEDefault() const override;
776   bool isPICDefaultForced() const override;
777 };
778
779 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
780 public:
781   MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
782                 const llvm::opt::ArgList &Args);
783
784   bool IsIntegratedAssemblerDefault() const override;
785   bool IsUnwindTablesDefault() const override;
786   bool isPICDefault() const override;
787   bool isPIEDefault() const override;
788   bool isPICDefaultForced() const override;
789
790   void
791   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
792                             llvm::opt::ArgStringList &CC1Args) const override;
793   void
794   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
795                                llvm::opt::ArgStringList &CC1Args) const override;
796
797   bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
798   bool getWindowsSDKLibraryPath(std::string &path) const;
799   bool getVisualStudioInstallDir(std::string &path) const;
800   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
801                                      std::string &path) const;
802
803   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
804                                           types::ID InputType) const override;
805   SanitizerMask getSupportedSanitizers() const override;
806
807 protected:
808   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
809                                      llvm::opt::ArgStringList &CC1Args,
810                                      const std::string &folder,
811                                      const char *subfolder) const;
812
813   Tool *buildLinker() const override;
814   Tool *buildAssembler() const override;
815 };
816
817 class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
818 public:
819   CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
820                         const llvm::opt::ArgList &Args);
821
822   bool IsIntegratedAssemblerDefault() const override { return true; }
823   bool IsUnwindTablesDefault() const override;
824   bool isPICDefault() const override;
825   bool isPIEDefault() const override;
826   bool isPICDefaultForced() const override;
827
828   unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
829     return 0;
830   }
831
832   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
833                                  llvm::opt::ArgStringList &CC1Args)
834       const override;
835   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
836                                     llvm::opt::ArgStringList &CC1Args)
837       const override;
838   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
839                            llvm::opt::ArgStringList &CmdArgs) const override;
840
841 protected:
842   Tool *buildLinker() const override;
843   Tool *buildAssembler() const override;
844 };
845
846 class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
847 public:
848   XCore(const Driver &D, const llvm::Triple &Triple,
849           const llvm::opt::ArgList &Args);
850 protected:
851   Tool *buildAssembler() const override;
852   Tool *buildLinker() const override;
853 public:
854   bool isPICDefault() const override;
855   bool isPIEDefault() const override;
856   bool isPICDefaultForced() const override;
857   bool SupportsProfiling() const override;
858   bool hasBlocksRuntime() const override;
859   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
860                     llvm::opt::ArgStringList &CC1Args) const override;
861   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
862                              llvm::opt::ArgStringList &CC1Args) const override;
863   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
864                        llvm::opt::ArgStringList &CC1Args) const override;
865   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
866                            llvm::opt::ArgStringList &CmdArgs) const override;
867 };
868
869 /// SHAVEToolChain - A tool chain using the compiler installed by the the
870 // Movidius SDK into MV_TOOLS_DIR (which we assume will be copied to llvm's
871 // installation dir) to perform all subcommands.
872 class LLVM_LIBRARY_VISIBILITY SHAVEToolChain : public Generic_GCC {
873 public:
874   SHAVEToolChain(const Driver &D, const llvm::Triple &Triple,
875             const llvm::opt::ArgList &Args);
876   ~SHAVEToolChain() override;
877
878   virtual Tool *SelectTool(const JobAction &JA) const override;
879
880 protected:
881   Tool *getTool(Action::ActionClass AC) const override;
882   Tool *buildAssembler() const override;
883   Tool *buildLinker() const override;
884
885 private:
886   mutable std::unique_ptr<Tool> Compiler;
887   mutable std::unique_ptr<Tool> Assembler;
888 };
889
890 } // end namespace toolchains
891 } // end namespace driver
892 } // end namespace clang
893
894 #endif