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