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 CLANG_LIB_DRIVER_TOOLCHAINS_H_
11 #define 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/ToolChain.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/Support/Compiler.h"
19 #include <vector>
20 #include <set>
21 
22 namespace clang {
23 namespace driver {
24 namespace toolchains {
25 
26 /// Generic_GCC - A tool chain using the 'gcc' command to perform
27 /// all subcommands; this relies on gcc translating the majority of
28 /// command line options.
29 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
30 protected:
31   /// \brief Struct to store and manipulate GCC versions.
32   ///
33   /// We rely on assumptions about the form and structure of GCC version
34   /// numbers: they consist of at most three '.'-separated components, and each
35   /// component is a non-negative integer except for the last component. For
36   /// the last component we are very flexible in order to tolerate release
37   /// candidates or 'x' wildcards.
38   ///
39   /// Note that the ordering established among GCCVersions is based on the
40   /// preferred version string to use. For example we prefer versions without
41   /// a hard-coded patch number to those with a hard coded patch number.
42   ///
43   /// Currently this doesn't provide any logic for textual suffixes to patches
44   /// in the way that (for example) Debian's version format does. If that ever
45   /// becomes necessary, it can be added.
46   struct GCCVersion {
47     /// \brief The unparsed text of the version.
48     std::string Text;
49 
50     /// \brief The parsed major, minor, and patch numbers.
51     int Major, Minor, Patch;
52 
53     /// \brief The text of the parsed major, and major+minor versions.
54     std::string MajorStr, MinorStr;
55 
56     /// \brief Any textual suffix on the patch number.
57     std::string PatchSuffix;
58 
59     static GCCVersion Parse(StringRef VersionText);
60     bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch,
61                      StringRef RHSPatchSuffix = StringRef()) const;
62     bool operator<(const GCCVersion &RHS) const {
63       return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix);
64     }
65     bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
66     bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
67     bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
68   };
69 
70 
71   /// \brief This is a class to find a viable GCC installation for Clang to
72   /// use.
73   ///
74   /// This class tries to find a GCC installation on the system, and report
75   /// information about it. It starts from the host information provided to the
76   /// Driver, and has logic for fuzzing that where appropriate.
77   class GCCInstallationDetector {
78     bool IsValid;
79     const Driver &D;
80     llvm::Triple GCCTriple;
81 
82     // FIXME: These might be better as path objects.
83     std::string GCCInstallPath;
84     std::string GCCBiarchSuffix;
85     std::string GCCParentLibPath;
86     std::string GCCMIPSABIDirSuffix;
87 
88     GCCVersion Version;
89 
90     // We retain the list of install paths that were considered and rejected in
91     // order to print out detailed information in verbose mode.
92     std::set<std::string> CandidateGCCInstallPaths;
93 
94   public:
95     GCCInstallationDetector(const Driver &D, const llvm::Triple &TargetTriple,
96                             const llvm::opt::ArgList &Args);
97 
98     /// \brief Check whether we detected a valid GCC install.
99     bool isValid() const { return IsValid; }
100 
101     /// \brief Get the GCC triple for the detected install.
102     const llvm::Triple &getTriple() const { return GCCTriple; }
103 
104     /// \brief Get the detected GCC installation path.
105     StringRef getInstallPath() const { return GCCInstallPath; }
106 
107     /// \brief Get the detected GCC installation path suffix for the bi-arch
108     /// target variant.
109     StringRef getBiarchSuffix() const { return GCCBiarchSuffix; }
110 
111     /// \brief Get the detected GCC parent lib path.
112     StringRef getParentLibPath() const { return GCCParentLibPath; }
113 
114     /// \brief Get the detected GCC MIPS ABI directory suffix.
115     ///
116     /// This is used as a suffix both to the install directory of GCC and as
117     /// a suffix to its parent lib path in order to select a MIPS ABI-specific
118     /// subdirectory.
119     ///
120     /// This will always be empty for any non-MIPS target.
121     ///
122     // FIXME: This probably shouldn't exist at all, and should be factored
123     // into the multiarch and/or biarch support. Please don't add more uses of
124     // this interface, it is meant as a legacy crutch for the MIPS driver
125     // logic.
126     StringRef getMIPSABIDirSuffix() const { return GCCMIPSABIDirSuffix; }
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(llvm::Triple::ArchType TargetArch,
144                                 const llvm::opt::ArgList &Args,
145                                 const std::string &LibDir,
146                                 StringRef CandidateTriple,
147                                 bool NeedsBiarchSuffix = false);
148 
149     void findMIPSABIDirSuffix(std::string &Suffix,
150                               llvm::Triple::ArchType TargetArch, StringRef Path,
151                               const llvm::opt::ArgList &Args);
152   };
153 
154   GCCInstallationDetector GCCInstallation;
155 
156 public:
157   Generic_GCC(const Driver &D, const llvm::Triple &Triple,
158               const llvm::opt::ArgList &Args);
159   ~Generic_GCC();
160 
161   virtual void printVerboseInfo(raw_ostream &OS) const;
162 
163   virtual bool IsUnwindTablesDefault() const;
164   virtual bool isPICDefault() const;
165   virtual bool isPIEDefault() const;
166   virtual bool isPICDefaultForced() const;
167 
168 protected:
169   virtual Tool *getTool(Action::ActionClass AC) const;
170   virtual Tool *buildAssembler() const;
171   virtual Tool *buildLinker() const;
172 
173   /// \name ToolChain Implementation Helper Functions
174   /// @{
175 
176   /// \brief Check whether the target triple's architecture is 64-bits.
177   bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
178 
179   /// \brief Check whether the target triple's architecture is 32-bits.
180   bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
181 
182   /// @}
183 
184 private:
185   mutable OwningPtr<tools::gcc::Preprocess> Preprocess;
186   mutable OwningPtr<tools::gcc::Precompile> Precompile;
187   mutable OwningPtr<tools::gcc::Compile> Compile;
188 };
189 
190   /// Darwin - The base Darwin tool chain.
191 class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
192 public:
193   /// The host version.
194   unsigned DarwinVersion[3];
195 
196 protected:
197   virtual Tool *buildAssembler() const;
198   virtual Tool *buildLinker() const;
199   virtual Tool *getTool(Action::ActionClass AC) const;
200 
201 private:
202   mutable OwningPtr<tools::darwin::Lipo> Lipo;
203   mutable OwningPtr<tools::darwin::Dsymutil> Dsymutil;
204   mutable OwningPtr<tools::darwin::VerifyDebug> VerifyDebug;
205 
206   /// Whether the information on the target has been initialized.
207   //
208   // FIXME: This should be eliminated. What we want to do is make this part of
209   // the "default target for arguments" selection process, once we get out of
210   // the argument translation business.
211   mutable bool TargetInitialized;
212 
213   /// Whether we are targeting iPhoneOS target.
214   mutable bool TargetIsIPhoneOS;
215 
216   /// Whether we are targeting the iPhoneOS simulator target.
217   mutable bool TargetIsIPhoneOSSimulator;
218 
219   /// The OS version we are targeting.
220   mutable VersionTuple TargetVersion;
221 
222 private:
223   /// The default macosx-version-min of this tool chain; empty until
224   /// initialized.
225   std::string MacosxVersionMin;
226 
227   /// The default ios-version-min of this tool chain; empty until
228   /// initialized.
229   std::string iOSVersionMin;
230 
231 private:
232   void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
233 
234 public:
235   Darwin(const Driver &D, const llvm::Triple &Triple,
236          const llvm::opt::ArgList &Args);
237   ~Darwin();
238 
239   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
240                                           types::ID InputType) const;
241 
242   /// @name Darwin Specific Toolchain API
243   /// {
244 
245   // FIXME: Eliminate these ...Target functions and derive separate tool chains
246   // for these targets and put version in constructor.
247   void setTarget(bool IsIPhoneOS, unsigned Major, unsigned Minor,
248                  unsigned Micro, bool IsIOSSim) const {
249     assert((!IsIOSSim || IsIPhoneOS) && "Unexpected deployment target!");
250 
251     // FIXME: For now, allow reinitialization as long as values don't
252     // change. This will go away when we move away from argument translation.
253     if (TargetInitialized && TargetIsIPhoneOS == IsIPhoneOS &&
254         TargetIsIPhoneOSSimulator == IsIOSSim &&
255         TargetVersion == VersionTuple(Major, Minor, Micro))
256       return;
257 
258     assert(!TargetInitialized && "Target already initialized!");
259     TargetInitialized = true;
260     TargetIsIPhoneOS = IsIPhoneOS;
261     TargetIsIPhoneOSSimulator = IsIOSSim;
262     TargetVersion = VersionTuple(Major, Minor, Micro);
263   }
264 
265   bool isTargetIPhoneOS() const {
266     assert(TargetInitialized && "Target not initialized!");
267     return TargetIsIPhoneOS;
268   }
269 
270   bool isTargetIOSSimulator() const {
271     assert(TargetInitialized && "Target not initialized!");
272     return TargetIsIPhoneOSSimulator;
273   }
274 
275   bool isTargetMacOS() const {
276     return !isTargetIOSSimulator() && !isTargetIPhoneOS();
277   }
278 
279   bool isTargetInitialized() const { return TargetInitialized; }
280 
281   VersionTuple getTargetVersion() const {
282     assert(TargetInitialized && "Target not initialized!");
283     return TargetVersion;
284   }
285 
286   /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
287   /// invocation. For example, Darwin treats different ARM variations as
288   /// distinct architectures.
289   StringRef getDarwinArchName(const llvm::opt::ArgList &Args) const;
290 
291   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
292     assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
293     return TargetVersion < VersionTuple(V0, V1, V2);
294   }
295 
296   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
297     assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
298     return TargetVersion < VersionTuple(V0, V1, V2);
299   }
300 
301   /// AddLinkARCArgs - Add the linker arguments to link the ARC runtime library.
302   virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
303                               llvm::opt::ArgStringList &CmdArgs) const = 0;
304 
305   /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
306   /// runtime library.
307   virtual void
308   AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
309                         llvm::opt::ArgStringList &CmdArgs) const = 0;
310 
311   /// }
312   /// @name ToolChain Implementation
313   /// {
314 
315   virtual types::ID LookupTypeForExtension(const char *Ext) const;
316 
317   virtual bool HasNativeLLVMSupport() const;
318 
319   virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
320   virtual bool hasBlocksRuntime() const;
321 
322   virtual llvm::opt::DerivedArgList *
323   TranslateArgs(const llvm::opt::DerivedArgList &Args,
324                 const char *BoundArch) const;
325 
326   virtual bool IsBlocksDefault() const {
327     // Always allow blocks on Darwin; users interested in versioning are
328     // expected to use /usr/include/Blocks.h.
329     return true;
330   }
331   virtual bool IsIntegratedAssemblerDefault() const {
332     // Default integrated assembler to on for Darwin.
333     return true;
334   }
335 
336   virtual bool IsMathErrnoDefault() const {
337     return false;
338   }
339 
340   virtual bool IsEncodeExtendedBlockSignatureDefault() const {
341     return true;
342   }
343 
344   virtual bool IsObjCNonFragileABIDefault() const {
345     // Non-fragile ABI is default for everything but i386.
346     return getTriple().getArch() != llvm::Triple::x86;
347   }
348 
349   virtual bool UseObjCMixedDispatch() const {
350     // This is only used with the non-fragile ABI and non-legacy dispatch.
351 
352     // Mixed dispatch is used everywhere except OS X before 10.6.
353     return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
354   }
355   virtual bool IsUnwindTablesDefault() const;
356   virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
357     // Stack protectors default to on for user code on 10.5,
358     // and for everything in 10.6 and beyond
359     return isTargetIPhoneOS() ||
360       (!isMacosxVersionLT(10, 6) ||
361          (!isMacosxVersionLT(10, 5) && !KernelOrKext));
362   }
363   virtual RuntimeLibType GetDefaultRuntimeLibType() const {
364     return ToolChain::RLT_CompilerRT;
365   }
366   virtual bool isPICDefault() const;
367   virtual bool isPIEDefault() const;
368   virtual bool isPICDefaultForced() const;
369 
370   virtual bool SupportsProfiling() const;
371 
372   virtual bool SupportsObjCGC() const;
373 
374   virtual void CheckObjCARC() const;
375 
376   virtual bool UseDwarfDebugFlags() const;
377 
378   virtual bool UseSjLjExceptions() const;
379 
380   /// }
381 };
382 
383 /// DarwinClang - The Darwin toolchain used by Clang.
384 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
385 public:
386   DarwinClang(const Driver &D, const llvm::Triple &Triple,
387               const llvm::opt::ArgList &Args);
388 
389   /// @name Darwin ToolChain Implementation
390   /// {
391 
392   virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
393                                      llvm::opt::ArgStringList &CmdArgs) const;
394   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
395                          llvm::opt::ArgStringList &CmdArgs,
396                          const char *DarwinStaticLib,
397                          bool AlwaysLink = false) const;
398 
399   virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
400                                    llvm::opt::ArgStringList &CmdArgs) const;
401 
402   virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
403                                 llvm::opt::ArgStringList &CmdArgs) const;
404 
405   virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
406                               llvm::opt::ArgStringList &CmdArgs) const;
407   /// }
408 };
409 
410 /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
411 class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
412 public:
413   Darwin_Generic_GCC(const Driver &D, const llvm::Triple &Triple,
414                      const llvm::opt::ArgList &Args)
415       : Generic_GCC(D, Triple, Args) {}
416 
417   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
418                                           types::ID InputType) const;
419 
420   virtual bool isPICDefault() const { return false; }
421 };
422 
423 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
424   virtual void anchor();
425 public:
426   Generic_ELF(const Driver &D, const llvm::Triple &Triple,
427               const llvm::opt::ArgList &Args)
428       : Generic_GCC(D, Triple, Args) {}
429 
430   virtual bool IsIntegratedAssemblerDefault() const {
431     // Default integrated assembler to on for x86.
432     return (getTriple().getArch() == llvm::Triple::aarch64 ||
433             getTriple().getArch() == llvm::Triple::x86 ||
434             getTriple().getArch() == llvm::Triple::x86_64);
435   }
436 };
437 
438 class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
439 public:
440   AuroraUX(const Driver &D, const llvm::Triple &Triple,
441            const llvm::opt::ArgList &Args);
442 
443 protected:
444   virtual Tool *buildAssembler() const;
445   virtual Tool *buildLinker() const;
446 };
447 
448 class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
449 public:
450   Solaris(const Driver &D, const llvm::Triple &Triple,
451           const llvm::opt::ArgList &Args);
452 
453   virtual bool IsIntegratedAssemblerDefault() const { return true; }
454 protected:
455   virtual Tool *buildAssembler() const;
456   virtual Tool *buildLinker() const;
457 
458 };
459 
460 
461 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
462 public:
463   OpenBSD(const Driver &D, const llvm::Triple &Triple,
464           const llvm::opt::ArgList &Args);
465 
466   virtual bool IsMathErrnoDefault() const { return false; }
467   virtual bool IsObjCNonFragileABIDefault() const { return true; }
468   virtual bool isPIEDefault() const { return true; }
469 
470   virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
471     return 1;
472   }
473 
474 protected:
475   virtual Tool *buildAssembler() const;
476   virtual Tool *buildLinker() const;
477 };
478 
479 class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
480 public:
481   Bitrig(const Driver &D, const llvm::Triple &Triple,
482          const llvm::opt::ArgList &Args);
483 
484   virtual bool IsMathErrnoDefault() const { return false; }
485   virtual bool IsObjCNonFragileABIDefault() const { return true; }
486   virtual bool IsObjCLegacyDispatchDefault() const { return false; }
487 
488   virtual void
489   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
490                                llvm::opt::ArgStringList &CC1Args) const;
491   virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
492                                    llvm::opt::ArgStringList &CmdArgs) const;
493   virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
494      return 1;
495   }
496 
497 protected:
498   virtual Tool *buildAssembler() const;
499   virtual Tool *buildLinker() const;
500 };
501 
502 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
503 public:
504   FreeBSD(const Driver &D, const llvm::Triple &Triple,
505           const llvm::opt::ArgList &Args);
506   virtual bool HasNativeLLVMSupport() const;
507 
508   virtual bool IsMathErrnoDefault() const { return false; }
509   virtual bool IsObjCNonFragileABIDefault() const { return true; }
510 
511   virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
512   virtual void
513   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
514                                llvm::opt::ArgStringList &CC1Args) const;
515 
516 
517   virtual bool UseSjLjExceptions() const;
518 protected:
519   virtual Tool *buildAssembler() const;
520   virtual Tool *buildLinker() const;
521 };
522 
523 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
524 public:
525   NetBSD(const Driver &D, const llvm::Triple &Triple,
526          const llvm::opt::ArgList &Args);
527 
528   virtual bool IsMathErrnoDefault() const { return false; }
529   virtual bool IsObjCNonFragileABIDefault() const { return true; }
530 
531   virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
532 
533   virtual void
534   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
535                                llvm::opt::ArgStringList &CC1Args) const;
536   virtual bool IsUnwindTablesDefault() const {
537     return true;
538   }
539   virtual bool IsIntegratedAssemblerDefault() const {
540     if (getTriple().getArch() == llvm::Triple::ppc)
541       return true;
542     return Generic_ELF::IsIntegratedAssemblerDefault();
543   }
544 
545 protected:
546   virtual Tool *buildAssembler() const;
547   virtual Tool *buildLinker() const;
548 };
549 
550 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
551 public:
552   Minix(const Driver &D, const llvm::Triple &Triple,
553         const llvm::opt::ArgList &Args);
554 
555   virtual bool IsMathErrnoDefault() const { return false; }
556   virtual bool IsObjCNonFragileABIDefault() const { return true; }
557 
558   virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
559 
560   virtual void
561   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
562                                llvm::opt::ArgStringList &CC1Args) const;
563   virtual bool IsUnwindTablesDefault() const {
564     return true;
565   }
566   virtual bool IsIntegratedAssemblerDefault() const {
567     if (getTriple().getArch() == llvm::Triple::ppc)
568       return true;
569     return Generic_ELF::IsIntegratedAssemblerDefault();
570   }
571 
572 protected:
573   virtual Tool *buildAssembler() const;
574   virtual Tool *buildLinker() const;
575 };
576 
577 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
578 public:
579   DragonFly(const Driver &D, const llvm::Triple &Triple,
580             const llvm::opt::ArgList &Args);
581 
582   virtual bool IsMathErrnoDefault() const { return false; }
583 
584 protected:
585   virtual Tool *buildAssembler() const;
586   virtual Tool *buildLinker() const;
587 };
588 
589 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
590 public:
591   Linux(const Driver &D, const llvm::Triple &Triple,
592         const llvm::opt::ArgList &Args);
593 
594   virtual bool HasNativeLLVMSupport() const;
595 
596   virtual void
597   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
598                             llvm::opt::ArgStringList &CC1Args) const;
599   virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
600                                      llvm::opt::ArgStringList &CC1Args) const;
601   virtual void
602   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
603                                llvm::opt::ArgStringList &CC1Args) const;
604   virtual bool isPIEDefault() const;
605 
606   std::string Linker;
607   std::vector<std::string> ExtraOpts;
608 
609 protected:
610   virtual Tool *buildAssembler() const;
611   virtual Tool *buildLinker() const;
612 
613 private:
614   static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
615                                        Twine TargetArchDir,
616                                        Twine BiarchSuffix,
617                                        Twine MIPSABIDirSuffix,
618                                        const llvm::opt::ArgList &DriverArgs,
619                                        llvm::opt::ArgStringList &CC1Args);
620   static bool addLibStdCXXIncludePaths(Twine Base, Twine TargetArchDir,
621                                        const llvm::opt::ArgList &DriverArgs,
622                                        llvm::opt::ArgStringList &CC1Args);
623 
624   std::string computeSysRoot() const;
625 };
626 
627 class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
628 protected:
629   GCCVersion GCCLibAndIncVersion;
630   virtual Tool *buildAssembler() const;
631   virtual Tool *buildLinker() const;
632 
633 public:
634   Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
635              const llvm::opt::ArgList &Args);
636   ~Hexagon_TC();
637 
638   virtual void
639   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
640                             llvm::opt::ArgStringList &CC1Args) const;
641   virtual void
642   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
643                                llvm::opt::ArgStringList &CC1Args) const;
644   virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
645 
646   StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
647 
648   static std::string GetGnuDir(const std::string &InstalledDir);
649 
650   static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
651 };
652 
653 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
654 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
655 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
656 public:
657   TCEToolChain(const Driver &D, const llvm::Triple &Triple,
658                const llvm::opt::ArgList &Args);
659   ~TCEToolChain();
660 
661   bool IsMathErrnoDefault() const;
662   bool isPICDefault() const;
663   bool isPIEDefault() const;
664   bool isPICDefaultForced() const;
665 };
666 
667 class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain {
668 public:
669   Windows(const Driver &D, const llvm::Triple &Triple,
670           const llvm::opt::ArgList &Args);
671 
672   virtual bool IsIntegratedAssemblerDefault() const;
673   virtual bool IsUnwindTablesDefault() const;
674   virtual bool isPICDefault() const;
675   virtual bool isPIEDefault() const;
676   virtual bool isPICDefaultForced() const;
677 
678   virtual void
679   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
680                             llvm::opt::ArgStringList &CC1Args) const;
681   virtual void
682   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
683                                llvm::opt::ArgStringList &CC1Args) const;
684 
685 protected:
686   virtual Tool *buildLinker() const;
687   virtual Tool *buildAssembler() const;
688 };
689 
690 
691 class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
692 public:
693   XCore(const Driver &D, const llvm::Triple &Triple,
694           const llvm::opt::ArgList &Args);
695 protected:
696   virtual Tool *buildAssembler() const;
697   virtual Tool *buildLinker() const;
698 public:
699   virtual bool isPICDefault() const;
700   virtual bool isPIEDefault() const;
701   virtual bool isPICDefaultForced() const;
702   virtual bool SupportsProfiling() const;
703   virtual bool hasBlocksRuntime() const;
704   virtual void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
705                             llvm::opt::ArgStringList &CC1Args) const;
706   virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
707                                      llvm::opt::ArgStringList &CC1Args) const;
708   virtual void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
709                                llvm::opt::ArgStringList &CC1Args) const;
710   virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
711                                    llvm::opt::ArgStringList &CmdArgs) const;
712 };
713 
714 } // end namespace toolchains
715 } // end namespace driver
716 } // end namespace clang
717 
718 #endif
719