xref: /minix3/external/bsd/llvm/dist/clang/lib/Driver/ToolChains.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
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:
GCCInstallationDetector()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.
isValid()107     bool isValid() const { return IsValid; }
108 
109     /// \brief Get the GCC triple for the detected install.
getTriple()110     const llvm::Triple &getTriple() const { return GCCTriple; }
111 
112     /// \brief Get the detected GCC installation path.
getInstallPath()113     StringRef getInstallPath() const { return GCCInstallPath; }
114 
115     /// \brief Get the detected GCC parent lib path.
getParentLibPath()116     StringRef getParentLibPath() const { return GCCParentLibPath; }
117 
118     /// \brief Get the detected Multilib
getMultilib()119     const Multilib &getMultilib() const { return SelectedMultilib; }
120 
121     /// \brief Get the whole MultilibSet
getMultilibs()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.
getVersion()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();
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.
isTarget64Bit()174   bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
175 
176   /// \brief Check whether the target triple's architecture is 32-bits.
isTarget32Bit()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();
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.
AddLinkARCArgs(const llvm::opt::ArgList & Args,llvm::opt::ArgStringList & CmdArgs)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,llvm::opt::ArgStringList & CmdArgs)218   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
219                          llvm::opt::ArgStringList &CmdArgs) const {}
220 
addMinVersionArgs(const llvm::opt::ArgList & Args,llvm::opt::ArgStringList & CmdArgs)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?
isKernelStatic()226   virtual bool isKernelStatic() const {
227     return false;
228   }
229 
230   /// Is the target either iOS or an iOS simulator?
isTargetIOSBased()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   /// }
243   /// @name ToolChain Implementation
244   /// {
245 
246   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
247                                           types::ID InputType) const override;
248 
249   types::ID LookupTypeForExtension(const char *Ext) const override;
250 
251   bool HasNativeLLVMSupport() const override;
252 
253   llvm::opt::DerivedArgList *
254   TranslateArgs(const llvm::opt::DerivedArgList &Args,
255                 const char *BoundArch) const override;
256 
IsBlocksDefault()257   bool IsBlocksDefault() const override {
258     // Always allow blocks on Apple; users interested in versioning are
259     // expected to use /usr/include/Block.h.
260     return true;
261   }
IsIntegratedAssemblerDefault()262   bool IsIntegratedAssemblerDefault() const override {
263     // Default integrated assembler to on for Apple's MachO targets.
264     return true;
265   }
266 
IsMathErrnoDefault()267   bool IsMathErrnoDefault() const override {
268     return false;
269   }
270 
IsEncodeExtendedBlockSignatureDefault()271   bool IsEncodeExtendedBlockSignatureDefault() const override {
272     return true;
273   }
274 
IsObjCNonFragileABIDefault()275   bool IsObjCNonFragileABIDefault() const override {
276     // Non-fragile ABI is default for everything but i386.
277     return getTriple().getArch() != llvm::Triple::x86;
278   }
279 
UseObjCMixedDispatch()280   bool UseObjCMixedDispatch() const override {
281     return true;
282   }
283 
284   bool IsUnwindTablesDefault() const override;
285 
GetDefaultRuntimeLibType()286   RuntimeLibType GetDefaultRuntimeLibType() const override {
287     return ToolChain::RLT_CompilerRT;
288   }
289 
290   bool isPICDefault() const override;
291   bool isPIEDefault() const override;
292   bool isPICDefaultForced() const override;
293 
294   bool SupportsProfiling() const override;
295 
SupportsObjCGC()296   bool SupportsObjCGC() const override {
297     return false;
298   }
299 
300   bool UseDwarfDebugFlags() const override;
301 
UseSjLjExceptions()302   bool UseSjLjExceptions() const override {
303     return false;
304   }
305 
306   /// }
307 };
308 
309   /// Darwin - The base Darwin tool chain.
310 class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
311 public:
312   /// The host version.
313   unsigned DarwinVersion[3];
314 
315   /// Whether the information on the target has been initialized.
316   //
317   // FIXME: This should be eliminated. What we want to do is make this part of
318   // the "default target for arguments" selection process, once we get out of
319   // the argument translation business.
320   mutable bool TargetInitialized;
321 
322   enum DarwinPlatformKind {
323     MacOS,
324     IPhoneOS,
325     IPhoneOSSimulator
326   };
327 
328   mutable DarwinPlatformKind TargetPlatform;
329 
330   /// The OS version we are targeting.
331   mutable VersionTuple TargetVersion;
332 
333 private:
334   /// The default macosx-version-min of this tool chain; empty until
335   /// initialized.
336   std::string MacosxVersionMin;
337 
338   /// The default ios-version-min of this tool chain; empty until
339   /// initialized.
340   std::string iOSVersionMin;
341 
342 private:
343   void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
344 
345 public:
346   Darwin(const Driver &D, const llvm::Triple &Triple,
347          const llvm::opt::ArgList &Args);
348   ~Darwin();
349 
350   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
351                                           types::ID InputType) const override;
352 
353   /// @name Apple Specific Toolchain Implementation
354   /// {
355 
356   void
357   addMinVersionArgs(const llvm::opt::ArgList &Args,
358                     llvm::opt::ArgStringList &CmdArgs) const override;
359 
360   void
361   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
362                          llvm::opt::ArgStringList &CmdArgs) const override;
363 
isKernelStatic()364   bool isKernelStatic() const override {
365     return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0) ||
366            getTriple().getArch() == llvm::Triple::aarch64;
367   }
368 
369 protected:
370   /// }
371   /// @name Darwin specific Toolchain functions
372   /// {
373 
374   // FIXME: Eliminate these ...Target functions and derive separate tool chains
375   // for these targets and put version in constructor.
setTarget(DarwinPlatformKind Platform,unsigned Major,unsigned Minor,unsigned Micro)376   void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
377                  unsigned Micro) const {
378     // FIXME: For now, allow reinitialization as long as values don't
379     // change. This will go away when we move away from argument translation.
380     if (TargetInitialized && TargetPlatform == Platform &&
381         TargetVersion == VersionTuple(Major, Minor, Micro))
382       return;
383 
384     assert(!TargetInitialized && "Target already initialized!");
385     TargetInitialized = true;
386     TargetPlatform = Platform;
387     TargetVersion = VersionTuple(Major, Minor, Micro);
388   }
389 
isTargetIPhoneOS()390   bool isTargetIPhoneOS() const {
391     assert(TargetInitialized && "Target not initialized!");
392     return TargetPlatform == IPhoneOS;
393   }
394 
isTargetIOSSimulator()395   bool isTargetIOSSimulator() const {
396     assert(TargetInitialized && "Target not initialized!");
397     return TargetPlatform == IPhoneOSSimulator;
398   }
399 
isTargetIOSBased()400   bool isTargetIOSBased() const {
401     assert(TargetInitialized && "Target not initialized!");
402     return isTargetIPhoneOS() || isTargetIOSSimulator();
403   }
404 
isTargetMacOS()405   bool isTargetMacOS() const {
406     return TargetPlatform == MacOS;
407   }
408 
isTargetInitialized()409   bool isTargetInitialized() const { return TargetInitialized; }
410 
getTargetVersion()411   VersionTuple getTargetVersion() const {
412     assert(TargetInitialized && "Target not initialized!");
413     return TargetVersion;
414   }
415 
416   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
417     assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
418     return TargetVersion < VersionTuple(V0, V1, V2);
419   }
420 
421   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
422     assert(isTargetMacOS() && "Unexpected call for non OS X target!");
423     return TargetVersion < VersionTuple(V0, V1, V2);
424   }
425 
426 public:
427   /// }
428   /// @name ToolChain Implementation
429   /// {
430 
431   // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
432   // most development is done against SDKs, so compiling for a different
433   // architecture should not get any special treatment.
isCrossCompiling()434   bool isCrossCompiling() const override { return false; }
435 
436   llvm::opt::DerivedArgList *
437   TranslateArgs(const llvm::opt::DerivedArgList &Args,
438                 const char *BoundArch) const override;
439 
440   ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
441   bool hasBlocksRuntime() const override;
442 
UseObjCMixedDispatch()443   bool UseObjCMixedDispatch() const override {
444     // This is only used with the non-fragile ABI and non-legacy dispatch.
445 
446     // Mixed dispatch is used everywhere except OS X before 10.6.
447     return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
448   }
449 
GetDefaultStackProtectorLevel(bool KernelOrKext)450   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
451     // Stack protectors default to on for user code on 10.5,
452     // and for everything in 10.6 and beyond
453     if (isTargetIOSBased())
454       return 1;
455     else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
456       return 1;
457     else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
458       return 1;
459 
460     return 0;
461   }
462 
463   bool SupportsObjCGC() const override;
464 
465   void CheckObjCARC() const override;
466 
467   bool UseSjLjExceptions() 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   virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args)
492                                                       const override;
493 
494   void
495   AddLinkARCArgs(const llvm::opt::ArgList &Args,
496                  llvm::opt::ArgStringList &CmdArgs) const override;
497   /// }
498 };
499 
500 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
501   virtual void anchor();
502 public:
Generic_ELF(const Driver & D,const llvm::Triple & Triple,const llvm::opt::ArgList & Args)503   Generic_ELF(const Driver &D, const llvm::Triple &Triple,
504               const llvm::opt::ArgList &Args)
505       : Generic_GCC(D, Triple, Args) {}
506 
507   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
508                              llvm::opt::ArgStringList &CC1Args) const override;
509 };
510 
511 class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
512 public:
513   Solaris(const Driver &D, const llvm::Triple &Triple,
514           const llvm::opt::ArgList &Args);
515 
IsIntegratedAssemblerDefault()516   bool IsIntegratedAssemblerDefault() const override { return true; }
517 protected:
518   Tool *buildAssembler() const override;
519   Tool *buildLinker() const override;
520 
521 };
522 
523 
524 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
525 public:
526   OpenBSD(const Driver &D, const llvm::Triple &Triple,
527           const llvm::opt::ArgList &Args);
528 
IsMathErrnoDefault()529   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()530   bool IsObjCNonFragileABIDefault() const override { return true; }
isPIEDefault()531   bool isPIEDefault() const override { return true; }
532 
GetDefaultStackProtectorLevel(bool KernelOrKext)533   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
534     return 2;
535   }
536 
537 protected:
538   Tool *buildAssembler() const override;
539   Tool *buildLinker() const override;
540 };
541 
542 class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
543 public:
544   Bitrig(const Driver &D, const llvm::Triple &Triple,
545          const llvm::opt::ArgList &Args);
546 
IsMathErrnoDefault()547   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()548   bool IsObjCNonFragileABIDefault() const override { return true; }
549 
550   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
551   void
552   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
553                               llvm::opt::ArgStringList &CC1Args) const override;
554   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
555                            llvm::opt::ArgStringList &CmdArgs) const override;
GetDefaultStackProtectorLevel(bool KernelOrKext)556   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
557      return 1;
558   }
559 
560 protected:
561   Tool *buildAssembler() const override;
562   Tool *buildLinker() const override;
563 };
564 
565 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
566 public:
567   FreeBSD(const Driver &D, const llvm::Triple &Triple,
568           const llvm::opt::ArgList &Args);
569   bool HasNativeLLVMSupport() const override;
570 
IsMathErrnoDefault()571   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()572   bool IsObjCNonFragileABIDefault() const override { return true; }
573 
574   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
575   void
576   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
577                                llvm::opt::ArgStringList &CC1Args) const override;
578 
579   bool UseSjLjExceptions() const override;
580   bool isPIEDefault() const override;
581 protected:
582   Tool *buildAssembler() const override;
583   Tool *buildLinker() const override;
584 };
585 
586 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
587 public:
588   NetBSD(const Driver &D, const llvm::Triple &Triple,
589          const llvm::opt::ArgList &Args);
590 
IsMathErrnoDefault()591   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()592   bool IsObjCNonFragileABIDefault() const override { return true; }
593 
594   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
595 
596   void
597   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
598                               llvm::opt::ArgStringList &CC1Args) const override;
IsUnwindTablesDefault()599   bool IsUnwindTablesDefault() const override {
600     return true;
601   }
602 
603 protected:
604   Tool *buildAssembler() const override;
605   Tool *buildLinker() const override;
606 };
607 
608 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
609 public:
610   Minix(const Driver &D, const llvm::Triple &Triple,
611          const llvm::opt::ArgList &Args);
612 
IsMathErrnoDefault()613   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()614   bool IsObjCNonFragileABIDefault() const override { return true; }
615 
616   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
617 
618   void
619   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
620                               llvm::opt::ArgStringList &CC1Args) const override;
IsUnwindTablesDefault()621   bool IsUnwindTablesDefault() const override {
622     return true;
623   }
624 
625 protected:
626   Tool *buildAssembler() const override;
627   Tool *buildLinker() const override;
628 };
629 
630 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
631 public:
632   DragonFly(const Driver &D, const llvm::Triple &Triple,
633             const llvm::opt::ArgList &Args);
634 
IsMathErrnoDefault()635   bool IsMathErrnoDefault() const override { return false; }
636 
637 protected:
638   Tool *buildAssembler() const override;
639   Tool *buildLinker() const override;
640 };
641 
642 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
643 public:
644   Linux(const Driver &D, const llvm::Triple &Triple,
645         const llvm::opt::ArgList &Args);
646 
647   bool HasNativeLLVMSupport() const override;
648 
649   void
650   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
651                             llvm::opt::ArgStringList &CC1Args) const override;
652   void
653   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
654                                llvm::opt::ArgStringList &CC1Args) const override;
655   bool isPIEDefault() const override;
656 
657   std::string Linker;
658   std::vector<std::string> ExtraOpts;
659 
660 protected:
661   Tool *buildAssembler() const override;
662   Tool *buildLinker() const override;
663 
664 private:
665   static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
666                                        StringRef GCCTriple,
667                                        StringRef GCCMultiarchTriple,
668                                        StringRef TargetMultiarchTriple,
669                                        Twine IncludeSuffix,
670                                        const llvm::opt::ArgList &DriverArgs,
671                                        llvm::opt::ArgStringList &CC1Args);
672 
673   std::string computeSysRoot() const;
674 };
675 
676 class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
677 protected:
678   GCCVersion GCCLibAndIncVersion;
679   Tool *buildAssembler() const override;
680   Tool *buildLinker() const override;
681 
682 public:
683   Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
684              const llvm::opt::ArgList &Args);
685   ~Hexagon_TC();
686 
687   void
688   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
689                             llvm::opt::ArgStringList &CC1Args) const override;
690   void
691   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
692                               llvm::opt::ArgStringList &CC1Args) const override;
693   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
694 
GetGCCLibAndIncVersion()695   StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
696 
697   static std::string GetGnuDir(const std::string &InstalledDir,
698                                const llvm::opt::ArgList &Args);
699 
700   static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
701 };
702 
703 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
704 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
705 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
706 public:
707   TCEToolChain(const Driver &D, const llvm::Triple &Triple,
708                const llvm::opt::ArgList &Args);
709   ~TCEToolChain();
710 
711   bool IsMathErrnoDefault() const override;
712   bool isPICDefault() const override;
713   bool isPIEDefault() const override;
714   bool isPICDefaultForced() const override;
715 };
716 
717 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
718 public:
719   MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
720                 const llvm::opt::ArgList &Args);
721 
722   bool IsIntegratedAssemblerDefault() const override;
723   bool IsUnwindTablesDefault() const override;
724   bool isPICDefault() const override;
725   bool isPIEDefault() const override;
726   bool isPICDefaultForced() const override;
727 
728   void
729   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
730                             llvm::opt::ArgStringList &CC1Args) const override;
731   void
732   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
733                                llvm::opt::ArgStringList &CC1Args) const override;
734 
735   bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
736   bool getWindowsSDKLibraryPath(std::string &path) const;
737   bool getVisualStudioInstallDir(std::string &path) const;
738   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
739                                      std::string &path) const;
740 
741 protected:
742   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
743                                      llvm::opt::ArgStringList &CC1Args,
744                                      const std::string &folder,
745                                      const char *subfolder) const;
746 
747   Tool *buildLinker() const override;
748   Tool *buildAssembler() const override;
749 };
750 
751 class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
752 public:
753   CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
754                         const llvm::opt::ArgList &Args);
755 
IsIntegratedAssemblerDefault()756   bool IsIntegratedAssemblerDefault() const override { return true; }
757   bool IsUnwindTablesDefault() const override;
758   bool isPICDefault() const override;
759   bool isPIEDefault() const override;
760   bool isPICDefaultForced() const override;
761 
GetDefaultStackProtectorLevel(bool KernelOrKext)762   unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
763     return 0;
764   }
765 
766   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
767                                  llvm::opt::ArgStringList &CC1Args)
768       const override;
769   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
770                                     llvm::opt::ArgStringList &CC1Args)
771       const override;
772   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
773                            llvm::opt::ArgStringList &CmdArgs) const override;
774 
775 protected:
776   Tool *buildLinker() const override;
777   Tool *buildAssembler() const override;
778 };
779 
780 class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
781 public:
782   XCore(const Driver &D, const llvm::Triple &Triple,
783           const llvm::opt::ArgList &Args);
784 protected:
785   Tool *buildAssembler() const override;
786   Tool *buildLinker() const override;
787 public:
788   bool isPICDefault() const override;
789   bool isPIEDefault() const override;
790   bool isPICDefaultForced() const override;
791   bool SupportsProfiling() const override;
792   bool hasBlocksRuntime() const override;
793   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
794                     llvm::opt::ArgStringList &CC1Args) const override;
795   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
796                              llvm::opt::ArgStringList &CC1Args) const override;
797   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
798                        llvm::opt::ArgStringList &CC1Args) const override;
799   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
800                            llvm::opt::ArgStringList &CmdArgs) const override;
801 };
802 
803 } // end namespace toolchains
804 } // end namespace driver
805 } // end namespace clang
806 
807 #endif
808