clang API Documentation

ToolChains.h
Go to the documentation of this file.
00001 //===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
00011 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
00012 
00013 #include "Tools.h"
00014 #include "clang/Basic/VersionTuple.h"
00015 #include "clang/Driver/Action.h"
00016 #include "clang/Driver/Multilib.h"
00017 #include "clang/Driver/ToolChain.h"
00018 #include "llvm/ADT/DenseMap.h"
00019 #include "llvm/ADT/Optional.h"
00020 #include "llvm/Support/Compiler.h"
00021 #include <set>
00022 #include <vector>
00023 
00024 namespace clang {
00025 namespace driver {
00026 namespace toolchains {
00027 
00028 /// Generic_GCC - A tool chain using the 'gcc' command to perform
00029 /// all subcommands; this relies on gcc translating the majority of
00030 /// command line options.
00031 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
00032 protected:
00033   /// \brief Struct to store and manipulate GCC versions.
00034   ///
00035   /// We rely on assumptions about the form and structure of GCC version
00036   /// numbers: they consist of at most three '.'-separated components, and each
00037   /// component is a non-negative integer except for the last component. For
00038   /// the last component we are very flexible in order to tolerate release
00039   /// candidates or 'x' wildcards.
00040   ///
00041   /// Note that the ordering established among GCCVersions is based on the
00042   /// preferred version string to use. For example we prefer versions without
00043   /// a hard-coded patch number to those with a hard coded patch number.
00044   ///
00045   /// Currently this doesn't provide any logic for textual suffixes to patches
00046   /// in the way that (for example) Debian's version format does. If that ever
00047   /// becomes necessary, it can be added.
00048   struct GCCVersion {
00049     /// \brief The unparsed text of the version.
00050     std::string Text;
00051 
00052     /// \brief The parsed major, minor, and patch numbers.
00053     int Major, Minor, Patch;
00054 
00055     /// \brief The text of the parsed major, and major+minor versions.
00056     std::string MajorStr, MinorStr;
00057 
00058     /// \brief Any textual suffix on the patch number.
00059     std::string PatchSuffix;
00060 
00061     static GCCVersion Parse(StringRef VersionText);
00062     bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch,
00063                      StringRef RHSPatchSuffix = StringRef()) const;
00064     bool operator<(const GCCVersion &RHS) const {
00065       return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix);
00066     }
00067     bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
00068     bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
00069     bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
00070   };
00071 
00072   /// \brief This is a class to find a viable GCC installation for Clang to
00073   /// use.
00074   ///
00075   /// This class tries to find a GCC installation on the system, and report
00076   /// information about it. It starts from the host information provided to the
00077   /// Driver, and has logic for fuzzing that where appropriate.
00078   class GCCInstallationDetector {
00079     bool IsValid;
00080     llvm::Triple GCCTriple;
00081 
00082     // FIXME: These might be better as path objects.
00083     std::string GCCInstallPath;
00084     std::string GCCParentLibPath;
00085 
00086     /// The primary multilib appropriate for the given flags.
00087     Multilib SelectedMultilib;
00088     /// On Biarch systems, this corresponds to the default multilib when
00089     /// targeting the non-default multilib. Otherwise, it is empty.
00090     llvm::Optional<Multilib> BiarchSibling;
00091 
00092     GCCVersion Version;
00093 
00094     // We retain the list of install paths that were considered and rejected in
00095     // order to print out detailed information in verbose mode.
00096     std::set<std::string> CandidateGCCInstallPaths;
00097 
00098     /// The set of multilibs that the detected installation supports.
00099     MultilibSet Multilibs;
00100 
00101   public:
00102     GCCInstallationDetector() : IsValid(false) {}
00103     void init(const Driver &D, const llvm::Triple &TargetTriple,
00104                             const llvm::opt::ArgList &Args);
00105 
00106     /// \brief Check whether we detected a valid GCC install.
00107     bool isValid() const { return IsValid; }
00108 
00109     /// \brief Get the GCC triple for the detected install.
00110     const llvm::Triple &getTriple() const { return GCCTriple; }
00111 
00112     /// \brief Get the detected GCC installation path.
00113     StringRef getInstallPath() const { return GCCInstallPath; }
00114 
00115     /// \brief Get the detected GCC parent lib path.
00116     StringRef getParentLibPath() const { return GCCParentLibPath; }
00117 
00118     /// \brief Get the detected Multilib
00119     const Multilib &getMultilib() const { return SelectedMultilib; }
00120 
00121     /// \brief Get the whole MultilibSet
00122     const MultilibSet &getMultilibs() const { return Multilibs; }
00123 
00124     /// Get the biarch sibling multilib (if it exists).
00125     /// \return true iff such a sibling exists
00126     bool getBiarchSibling(Multilib &M) const;
00127 
00128     /// \brief Get the detected GCC version string.
00129     const GCCVersion &getVersion() const { return Version; }
00130 
00131     /// \brief Print information about the detected GCC installation.
00132     void print(raw_ostream &OS) const;
00133 
00134   private:
00135     static void
00136     CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
00137                              const llvm::Triple &BiarchTriple,
00138                              SmallVectorImpl<StringRef> &LibDirs,
00139                              SmallVectorImpl<StringRef> &TripleAliases,
00140                              SmallVectorImpl<StringRef> &BiarchLibDirs,
00141                              SmallVectorImpl<StringRef> &BiarchTripleAliases);
00142 
00143     void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch,
00144                                 const llvm::opt::ArgList &Args,
00145                                 const std::string &LibDir,
00146                                 StringRef CandidateTriple,
00147                                 bool NeedsBiarchSuffix = false);
00148   };
00149 
00150   GCCInstallationDetector GCCInstallation;
00151 
00152 public:
00153   Generic_GCC(const Driver &D, const llvm::Triple &Triple,
00154               const llvm::opt::ArgList &Args);
00155   ~Generic_GCC();
00156 
00157   void printVerboseInfo(raw_ostream &OS) const override;
00158 
00159   bool IsUnwindTablesDefault() const override;
00160   bool isPICDefault() const override;
00161   bool isPIEDefault() const override;
00162   bool isPICDefaultForced() const override;
00163   bool IsIntegratedAssemblerDefault() const override;
00164 
00165 protected:
00166   Tool *getTool(Action::ActionClass AC) const override;
00167   Tool *buildAssembler() const override;
00168   Tool *buildLinker() const override;
00169 
00170   /// \name ToolChain Implementation Helper Functions
00171   /// @{
00172 
00173   /// \brief Check whether the target triple's architecture is 64-bits.
00174   bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
00175 
00176   /// \brief Check whether the target triple's architecture is 32-bits.
00177   bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
00178 
00179   /// @}
00180 
00181 private:
00182   mutable std::unique_ptr<tools::gcc::Preprocess> Preprocess;
00183   mutable std::unique_ptr<tools::gcc::Compile> Compile;
00184 };
00185 
00186 class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
00187 protected:
00188   Tool *buildAssembler() const override;
00189   Tool *buildLinker() const override;
00190   Tool *getTool(Action::ActionClass AC) const override;
00191 private:
00192   mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
00193   mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
00194   mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug;
00195 
00196 public:
00197   MachO(const Driver &D, const llvm::Triple &Triple,
00198              const llvm::opt::ArgList &Args);
00199   ~MachO();
00200 
00201   /// @name MachO specific toolchain API
00202   /// {
00203 
00204   /// Get the "MachO" arch name for a particular compiler invocation. For
00205   /// example, Apple treats different ARM variations as distinct architectures.
00206   StringRef getMachOArchName(const llvm::opt::ArgList &Args) const;
00207 
00208 
00209   /// Add the linker arguments to link the ARC runtime library.
00210   virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
00211                               llvm::opt::ArgStringList &CmdArgs) const {}
00212 
00213   /// Add the linker arguments to link the compiler runtime library.
00214   virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
00215                                      llvm::opt::ArgStringList &CmdArgs) const;
00216 
00217   virtual void
00218   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
00219                          llvm::opt::ArgStringList &CmdArgs) const {}
00220 
00221   virtual void addMinVersionArgs(const llvm::opt::ArgList &Args,
00222                                  llvm::opt::ArgStringList &CmdArgs) const {}
00223 
00224   /// On some iOS platforms, kernel and kernel modules were built statically. Is
00225   /// this such a target?
00226   virtual bool isKernelStatic() const {
00227     return false;
00228   }
00229 
00230   /// Is the target either iOS or an iOS simulator?
00231   bool isTargetIOSBased() const {
00232     return false;
00233   }
00234 
00235   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
00236                          llvm::opt::ArgStringList &CmdArgs,
00237                          StringRef DarwinLibName,
00238                          bool AlwaysLink = false,
00239                          bool IsEmbedded = false,
00240                          bool AddRPath = false) const;
00241 
00242   /// }
00243   /// @name ToolChain Implementation
00244   /// {
00245 
00246   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
00247                                           types::ID InputType) const override;
00248 
00249   types::ID LookupTypeForExtension(const char *Ext) const override;
00250 
00251   bool HasNativeLLVMSupport() const override;
00252 
00253   llvm::opt::DerivedArgList *
00254   TranslateArgs(const llvm::opt::DerivedArgList &Args,
00255                 const char *BoundArch) const override;
00256 
00257   bool IsBlocksDefault() const override {
00258     // Always allow blocks on Apple; users interested in versioning are
00259     // expected to use /usr/include/Blocks.h.
00260     return true;
00261   }
00262   bool IsIntegratedAssemblerDefault() const override {
00263     // Default integrated assembler to on for Apple's MachO targets.
00264     return true;
00265   }
00266 
00267   bool IsMathErrnoDefault() const override {
00268     return false;
00269   }
00270 
00271   bool IsEncodeExtendedBlockSignatureDefault() const override {
00272     return true;
00273   }
00274 
00275   bool IsObjCNonFragileABIDefault() const override {
00276     // Non-fragile ABI is default for everything but i386.
00277     return getTriple().getArch() != llvm::Triple::x86;
00278   }
00279 
00280   bool UseObjCMixedDispatch() const override {
00281     return true;
00282   }
00283 
00284   bool IsUnwindTablesDefault() const override;
00285 
00286   RuntimeLibType GetDefaultRuntimeLibType() const override {
00287     return ToolChain::RLT_CompilerRT;
00288   }
00289 
00290   bool isPICDefault() const override;
00291   bool isPIEDefault() const override;
00292   bool isPICDefaultForced() const override;
00293 
00294   bool SupportsProfiling() const override;
00295 
00296   bool SupportsObjCGC() const override {
00297     return false;
00298   }
00299 
00300   bool UseDwarfDebugFlags() const override;
00301 
00302   bool UseSjLjExceptions() const override {
00303     return false;
00304   }
00305 
00306   /// }
00307 };
00308 
00309   /// Darwin - The base Darwin tool chain.
00310 class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
00311 public:
00312   /// The host version.
00313   unsigned DarwinVersion[3];
00314 
00315   /// Whether the information on the target has been initialized.
00316   //
00317   // FIXME: This should be eliminated. What we want to do is make this part of
00318   // the "default target for arguments" selection process, once we get out of
00319   // the argument translation business.
00320   mutable bool TargetInitialized;
00321 
00322   enum DarwinPlatformKind {
00323     MacOS,
00324     IPhoneOS,
00325     IPhoneOSSimulator
00326   };
00327 
00328   mutable DarwinPlatformKind TargetPlatform;
00329 
00330   /// The OS version we are targeting.
00331   mutable VersionTuple TargetVersion;
00332 
00333 private:
00334   /// The default macosx-version-min of this tool chain; empty until
00335   /// initialized.
00336   std::string MacosxVersionMin;
00337 
00338   /// The default ios-version-min of this tool chain; empty until
00339   /// initialized.
00340   std::string iOSVersionMin;
00341 
00342 private:
00343   void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
00344 
00345 public:
00346   Darwin(const Driver &D, const llvm::Triple &Triple,
00347          const llvm::opt::ArgList &Args);
00348   ~Darwin();
00349 
00350   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
00351                                           types::ID InputType) const override;
00352 
00353   /// @name Apple Specific Toolchain Implementation
00354   /// {
00355 
00356   void
00357   addMinVersionArgs(const llvm::opt::ArgList &Args,
00358                     llvm::opt::ArgStringList &CmdArgs) const override;
00359 
00360   void
00361   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
00362                          llvm::opt::ArgStringList &CmdArgs) const override;
00363 
00364   bool isKernelStatic() const override {
00365     return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0) ||
00366            getTriple().getArch() == llvm::Triple::aarch64;
00367   }
00368 
00369 protected:
00370   /// }
00371   /// @name Darwin specific Toolchain functions
00372   /// {
00373 
00374   // FIXME: Eliminate these ...Target functions and derive separate tool chains
00375   // for these targets and put version in constructor.
00376   void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
00377                  unsigned Micro) const {
00378     // FIXME: For now, allow reinitialization as long as values don't
00379     // change. This will go away when we move away from argument translation.
00380     if (TargetInitialized && TargetPlatform == Platform &&
00381         TargetVersion == VersionTuple(Major, Minor, Micro))
00382       return;
00383 
00384     assert(!TargetInitialized && "Target already initialized!");
00385     TargetInitialized = true;
00386     TargetPlatform = Platform;
00387     TargetVersion = VersionTuple(Major, Minor, Micro);
00388   }
00389 
00390   bool isTargetIPhoneOS() const {
00391     assert(TargetInitialized && "Target not initialized!");
00392     return TargetPlatform == IPhoneOS;
00393   }
00394 
00395   bool isTargetIOSSimulator() const {
00396     assert(TargetInitialized && "Target not initialized!");
00397     return TargetPlatform == IPhoneOSSimulator;
00398   }
00399 
00400   bool isTargetIOSBased() const {
00401     assert(TargetInitialized && "Target not initialized!");
00402     return isTargetIPhoneOS() || isTargetIOSSimulator();
00403   }
00404 
00405   bool isTargetMacOS() const {
00406     return TargetPlatform == MacOS;
00407   }
00408 
00409   bool isTargetInitialized() const { return TargetInitialized; }
00410 
00411   VersionTuple getTargetVersion() const {
00412     assert(TargetInitialized && "Target not initialized!");
00413     return TargetVersion;
00414   }
00415 
00416   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
00417     assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
00418     return TargetVersion < VersionTuple(V0, V1, V2);
00419   }
00420 
00421   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
00422     assert(isTargetMacOS() && "Unexpected call for non OS X target!");
00423     return TargetVersion < VersionTuple(V0, V1, V2);
00424   }
00425 
00426 public:
00427   /// }
00428   /// @name ToolChain Implementation
00429   /// {
00430 
00431   // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
00432   // most development is done against SDKs, so compiling for a different
00433   // architecture should not get any special treatment.
00434   bool isCrossCompiling() const override { return false; }
00435 
00436   llvm::opt::DerivedArgList *
00437   TranslateArgs(const llvm::opt::DerivedArgList &Args,
00438                 const char *BoundArch) const override;
00439 
00440   ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
00441   bool hasBlocksRuntime() const override;
00442 
00443   bool UseObjCMixedDispatch() const override {
00444     // This is only used with the non-fragile ABI and non-legacy dispatch.
00445 
00446     // Mixed dispatch is used everywhere except OS X before 10.6.
00447     return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
00448   }
00449 
00450   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
00451     // Stack protectors default to on for user code on 10.5,
00452     // and for everything in 10.6 and beyond
00453     if (isTargetIOSBased())
00454       return 1;
00455     else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
00456       return 1;
00457     else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
00458       return 1;
00459 
00460     return 0;
00461   }
00462 
00463   bool SupportsObjCGC() const override;
00464 
00465   void CheckObjCARC() const override;
00466 
00467   bool UseSjLjExceptions() const override;
00468 };
00469 
00470 /// DarwinClang - The Darwin toolchain used by Clang.
00471 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
00472 public:
00473   DarwinClang(const Driver &D, const llvm::Triple &Triple,
00474               const llvm::opt::ArgList &Args);
00475 
00476   /// @name Apple ToolChain Implementation
00477   /// {
00478 
00479   void
00480   AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
00481                         llvm::opt::ArgStringList &CmdArgs) const override;
00482 
00483   void
00484   AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
00485                       llvm::opt::ArgStringList &CmdArgs) const override;
00486 
00487   void
00488   AddCCKextLibArgs(const llvm::opt::ArgList &Args,
00489                    llvm::opt::ArgStringList &CmdArgs) const override;
00490 
00491   virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args)
00492                                                       const override;
00493 
00494   void
00495   AddLinkARCArgs(const llvm::opt::ArgList &Args,
00496                  llvm::opt::ArgStringList &CmdArgs) const override;
00497   /// }
00498 };
00499 
00500 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
00501   virtual void anchor();
00502 public:
00503   Generic_ELF(const Driver &D, const llvm::Triple &Triple,
00504               const llvm::opt::ArgList &Args)
00505       : Generic_GCC(D, Triple, Args) {}
00506 
00507   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
00508                              llvm::opt::ArgStringList &CC1Args) const override;
00509 };
00510 
00511 class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
00512 public:
00513   Solaris(const Driver &D, const llvm::Triple &Triple,
00514           const llvm::opt::ArgList &Args);
00515 
00516   bool IsIntegratedAssemblerDefault() const override { return true; }
00517 protected:
00518   Tool *buildAssembler() const override;
00519   Tool *buildLinker() const override;
00520 
00521 };
00522 
00523 
00524 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
00525 public:
00526   OpenBSD(const Driver &D, const llvm::Triple &Triple,
00527           const llvm::opt::ArgList &Args);
00528 
00529   bool IsMathErrnoDefault() const override { return false; }
00530   bool IsObjCNonFragileABIDefault() const override { return true; }
00531   bool isPIEDefault() const override { return true; }
00532 
00533   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
00534     return 2;
00535   }
00536 
00537   virtual bool IsIntegratedAssemblerDefault() const override {
00538     switch (getTriple().getArch()) {
00539     case llvm::Triple::ppc:
00540     case llvm::Triple::sparc:
00541     case llvm::Triple::sparcv9:
00542       return true;
00543     default:
00544       return Generic_ELF::IsIntegratedAssemblerDefault();
00545     }
00546   }
00547 
00548 protected:
00549   Tool *buildAssembler() const override;
00550   Tool *buildLinker() const override;
00551 };
00552 
00553 class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
00554 public:
00555   Bitrig(const Driver &D, const llvm::Triple &Triple,
00556          const llvm::opt::ArgList &Args);
00557 
00558   bool IsMathErrnoDefault() const override { return false; }
00559   bool IsObjCNonFragileABIDefault() const override { return true; }
00560 
00561   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
00562   void
00563   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00564                               llvm::opt::ArgStringList &CC1Args) const override;
00565   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
00566                            llvm::opt::ArgStringList &CmdArgs) const override;
00567   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
00568      return 1;
00569   }
00570 
00571 protected:
00572   Tool *buildAssembler() const override;
00573   Tool *buildLinker() const override;
00574 };
00575 
00576 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
00577 public:
00578   FreeBSD(const Driver &D, const llvm::Triple &Triple,
00579           const llvm::opt::ArgList &Args);
00580   bool HasNativeLLVMSupport() const override;
00581 
00582   bool IsMathErrnoDefault() const override { return false; }
00583   bool IsObjCNonFragileABIDefault() const override { return true; }
00584 
00585   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
00586   void
00587   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00588                                llvm::opt::ArgStringList &CC1Args) const override;
00589   bool IsIntegratedAssemblerDefault() const override {
00590     switch (getTriple().getArch()) {
00591     case llvm::Triple::ppc:
00592       return true;
00593     default:
00594       return Generic_ELF::IsIntegratedAssemblerDefault();
00595     }
00596   }
00597 
00598   bool UseSjLjExceptions() const override;
00599   bool isPIEDefault() const override;
00600 protected:
00601   Tool *buildAssembler() const override;
00602   Tool *buildLinker() const override;
00603 };
00604 
00605 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
00606 public:
00607   NetBSD(const Driver &D, const llvm::Triple &Triple,
00608          const llvm::opt::ArgList &Args);
00609 
00610   bool IsMathErrnoDefault() const override { return false; }
00611   bool IsObjCNonFragileABIDefault() const override { return true; }
00612 
00613   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
00614 
00615   void
00616   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00617                               llvm::opt::ArgStringList &CC1Args) const override;
00618   bool IsUnwindTablesDefault() const override {
00619     return true;
00620   }
00621   bool IsIntegratedAssemblerDefault() const override {
00622     switch (getTriple().getArch()) {
00623     case llvm::Triple::ppc:
00624       return true;
00625     default:
00626       return Generic_ELF::IsIntegratedAssemblerDefault();
00627     }
00628   }
00629 
00630 protected:
00631   Tool *buildAssembler() const override;
00632   Tool *buildLinker() const override;
00633 };
00634 
00635 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
00636 public:
00637   Minix(const Driver &D, const llvm::Triple &Triple,
00638         const llvm::opt::ArgList &Args);
00639 
00640 protected:
00641   Tool *buildAssembler() const override;
00642   Tool *buildLinker() const override;
00643 };
00644 
00645 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
00646 public:
00647   DragonFly(const Driver &D, const llvm::Triple &Triple,
00648             const llvm::opt::ArgList &Args);
00649 
00650   bool IsMathErrnoDefault() const override { return false; }
00651 
00652 protected:
00653   Tool *buildAssembler() const override;
00654   Tool *buildLinker() const override;
00655 };
00656 
00657 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
00658 public:
00659   Linux(const Driver &D, const llvm::Triple &Triple,
00660         const llvm::opt::ArgList &Args);
00661 
00662   bool HasNativeLLVMSupport() const override;
00663 
00664   void
00665   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00666                             llvm::opt::ArgStringList &CC1Args) const override;
00667   void
00668   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00669                                llvm::opt::ArgStringList &CC1Args) const override;
00670   bool isPIEDefault() const override;
00671 
00672   std::string Linker;
00673   std::vector<std::string> ExtraOpts;
00674 
00675 protected:
00676   Tool *buildAssembler() const override;
00677   Tool *buildLinker() const override;
00678 
00679 private:
00680   static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
00681                                        StringRef GCCTriple,
00682                                        StringRef GCCMultiarchTriple,
00683                                        StringRef TargetMultiarchTriple,
00684                                        Twine IncludeSuffix,
00685                                        const llvm::opt::ArgList &DriverArgs,
00686                                        llvm::opt::ArgStringList &CC1Args);
00687 
00688   std::string computeSysRoot() const;
00689 };
00690 
00691 class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
00692 protected:
00693   GCCVersion GCCLibAndIncVersion;
00694   Tool *buildAssembler() const override;
00695   Tool *buildLinker() const override;
00696 
00697 public:
00698   Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
00699              const llvm::opt::ArgList &Args);
00700   ~Hexagon_TC();
00701 
00702   void
00703   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00704                             llvm::opt::ArgStringList &CC1Args) const override;
00705   void
00706   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00707                               llvm::opt::ArgStringList &CC1Args) const override;
00708   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
00709 
00710   StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
00711 
00712   static std::string GetGnuDir(const std::string &InstalledDir,
00713                                const llvm::opt::ArgList &Args);
00714 
00715   static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
00716 };
00717 
00718 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
00719 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
00720 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
00721 public:
00722   TCEToolChain(const Driver &D, const llvm::Triple &Triple,
00723                const llvm::opt::ArgList &Args);
00724   ~TCEToolChain();
00725 
00726   bool IsMathErrnoDefault() const override;
00727   bool isPICDefault() const override;
00728   bool isPIEDefault() const override;
00729   bool isPICDefaultForced() const override;
00730 };
00731 
00732 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
00733 public:
00734   MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
00735                 const llvm::opt::ArgList &Args);
00736 
00737   bool IsIntegratedAssemblerDefault() const override;
00738   bool IsUnwindTablesDefault() const override;
00739   bool isPICDefault() const override;
00740   bool isPIEDefault() const override;
00741   bool isPICDefaultForced() const override;
00742 
00743   void
00744   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00745                             llvm::opt::ArgStringList &CC1Args) const override;
00746   void
00747   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00748                                llvm::opt::ArgStringList &CC1Args) const override;
00749 
00750   bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
00751   bool getWindowsSDKLibraryPath(std::string &path) const;
00752   bool getVisualStudioInstallDir(std::string &path) const;
00753   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
00754                                      std::string &path) const;
00755 
00756 protected:
00757   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
00758                                      llvm::opt::ArgStringList &CC1Args,
00759                                      const std::string &folder,
00760                                      const char *subfolder) const;
00761 
00762   Tool *buildLinker() const override;
00763   Tool *buildAssembler() const override;
00764 };
00765 
00766 class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
00767 public:
00768   CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
00769                         const llvm::opt::ArgList &Args);
00770 
00771   bool IsIntegratedAssemblerDefault() const override { return true; }
00772   bool IsUnwindTablesDefault() const override;
00773   bool isPICDefault() const override;
00774   bool isPIEDefault() const override;
00775   bool isPICDefaultForced() const override;
00776 
00777   unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
00778     return 0;
00779   }
00780 
00781   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00782                                  llvm::opt::ArgStringList &CC1Args)
00783       const override;
00784   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00785                                     llvm::opt::ArgStringList &CC1Args)
00786       const override;
00787   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
00788                            llvm::opt::ArgStringList &CmdArgs) const override;
00789 
00790 protected:
00791   Tool *buildLinker() const override;
00792   Tool *buildAssembler() const override;
00793 };
00794 
00795 class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
00796 public:
00797   XCore(const Driver &D, const llvm::Triple &Triple,
00798           const llvm::opt::ArgList &Args);
00799 protected:
00800   Tool *buildAssembler() const override;
00801   Tool *buildLinker() const override;
00802 public:
00803   bool isPICDefault() const override;
00804   bool isPIEDefault() const override;
00805   bool isPICDefaultForced() const override;
00806   bool SupportsProfiling() const override;
00807   bool hasBlocksRuntime() const override;
00808   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00809                     llvm::opt::ArgStringList &CC1Args) const override;
00810   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
00811                              llvm::opt::ArgStringList &CC1Args) const override;
00812   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00813                        llvm::opt::ArgStringList &CC1Args) const override;
00814   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
00815                            llvm::opt::ArgStringList &CmdArgs) const override;
00816 };
00817 
00818 } // end namespace toolchains
00819 } // end namespace driver
00820 } // end namespace clang
00821 
00822 #endif