xref: /minix3/external/bsd/llvm/dist/clang/lib/Driver/ToolChains.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
11*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc #include "Tools.h"
14f4a2713aSLionel Sambuc #include "clang/Basic/VersionTuple.h"
15f4a2713aSLionel Sambuc #include "clang/Driver/Action.h"
16*0a6a1f1dSLionel Sambuc #include "clang/Driver/Multilib.h"
17f4a2713aSLionel Sambuc #include "clang/Driver/ToolChain.h"
18f4a2713aSLionel Sambuc #include "llvm/ADT/DenseMap.h"
19*0a6a1f1dSLionel Sambuc #include "llvm/ADT/Optional.h"
20f4a2713aSLionel Sambuc #include "llvm/Support/Compiler.h"
21f4a2713aSLionel Sambuc #include <set>
22*0a6a1f1dSLionel Sambuc #include <vector>
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc namespace clang {
25f4a2713aSLionel Sambuc namespace driver {
26f4a2713aSLionel Sambuc namespace toolchains {
27f4a2713aSLionel Sambuc 
28f4a2713aSLionel Sambuc /// Generic_GCC - A tool chain using the 'gcc' command to perform
29f4a2713aSLionel Sambuc /// all subcommands; this relies on gcc translating the majority of
30f4a2713aSLionel Sambuc /// command line options.
31f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
32f4a2713aSLionel Sambuc protected:
33f4a2713aSLionel Sambuc   /// \brief Struct to store and manipulate GCC versions.
34f4a2713aSLionel Sambuc   ///
35f4a2713aSLionel Sambuc   /// We rely on assumptions about the form and structure of GCC version
36f4a2713aSLionel Sambuc   /// numbers: they consist of at most three '.'-separated components, and each
37f4a2713aSLionel Sambuc   /// component is a non-negative integer except for the last component. For
38f4a2713aSLionel Sambuc   /// the last component we are very flexible in order to tolerate release
39f4a2713aSLionel Sambuc   /// candidates or 'x' wildcards.
40f4a2713aSLionel Sambuc   ///
41f4a2713aSLionel Sambuc   /// Note that the ordering established among GCCVersions is based on the
42f4a2713aSLionel Sambuc   /// preferred version string to use. For example we prefer versions without
43f4a2713aSLionel Sambuc   /// a hard-coded patch number to those with a hard coded patch number.
44f4a2713aSLionel Sambuc   ///
45f4a2713aSLionel Sambuc   /// Currently this doesn't provide any logic for textual suffixes to patches
46f4a2713aSLionel Sambuc   /// in the way that (for example) Debian's version format does. If that ever
47f4a2713aSLionel Sambuc   /// becomes necessary, it can be added.
48f4a2713aSLionel Sambuc   struct GCCVersion {
49f4a2713aSLionel Sambuc     /// \brief The unparsed text of the version.
50f4a2713aSLionel Sambuc     std::string Text;
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc     /// \brief The parsed major, minor, and patch numbers.
53f4a2713aSLionel Sambuc     int Major, Minor, Patch;
54f4a2713aSLionel Sambuc 
55f4a2713aSLionel Sambuc     /// \brief The text of the parsed major, and major+minor versions.
56f4a2713aSLionel Sambuc     std::string MajorStr, MinorStr;
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc     /// \brief Any textual suffix on the patch number.
59f4a2713aSLionel Sambuc     std::string PatchSuffix;
60f4a2713aSLionel Sambuc 
61f4a2713aSLionel Sambuc     static GCCVersion Parse(StringRef VersionText);
62f4a2713aSLionel Sambuc     bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch,
63f4a2713aSLionel Sambuc                      StringRef RHSPatchSuffix = StringRef()) const;
64f4a2713aSLionel Sambuc     bool operator<(const GCCVersion &RHS) const {
65f4a2713aSLionel Sambuc       return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix);
66f4a2713aSLionel Sambuc     }
67f4a2713aSLionel Sambuc     bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
68f4a2713aSLionel Sambuc     bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
69f4a2713aSLionel Sambuc     bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
70f4a2713aSLionel Sambuc   };
71f4a2713aSLionel Sambuc 
72f4a2713aSLionel Sambuc   /// \brief This is a class to find a viable GCC installation for Clang to
73f4a2713aSLionel Sambuc   /// use.
74f4a2713aSLionel Sambuc   ///
75f4a2713aSLionel Sambuc   /// This class tries to find a GCC installation on the system, and report
76f4a2713aSLionel Sambuc   /// information about it. It starts from the host information provided to the
77f4a2713aSLionel Sambuc   /// Driver, and has logic for fuzzing that where appropriate.
78f4a2713aSLionel Sambuc   class GCCInstallationDetector {
79f4a2713aSLionel Sambuc     bool IsValid;
80f4a2713aSLionel Sambuc     llvm::Triple GCCTriple;
81f4a2713aSLionel Sambuc 
82f4a2713aSLionel Sambuc     // FIXME: These might be better as path objects.
83f4a2713aSLionel Sambuc     std::string GCCInstallPath;
84f4a2713aSLionel Sambuc     std::string GCCParentLibPath;
85*0a6a1f1dSLionel Sambuc 
86*0a6a1f1dSLionel Sambuc     /// The primary multilib appropriate for the given flags.
87*0a6a1f1dSLionel Sambuc     Multilib SelectedMultilib;
88*0a6a1f1dSLionel Sambuc     /// On Biarch systems, this corresponds to the default multilib when
89*0a6a1f1dSLionel Sambuc     /// targeting the non-default multilib. Otherwise, it is empty.
90*0a6a1f1dSLionel Sambuc     llvm::Optional<Multilib> BiarchSibling;
91f4a2713aSLionel Sambuc 
92f4a2713aSLionel Sambuc     GCCVersion Version;
93f4a2713aSLionel Sambuc 
94f4a2713aSLionel Sambuc     // We retain the list of install paths that were considered and rejected in
95f4a2713aSLionel Sambuc     // order to print out detailed information in verbose mode.
96f4a2713aSLionel Sambuc     std::set<std::string> CandidateGCCInstallPaths;
97f4a2713aSLionel Sambuc 
98*0a6a1f1dSLionel Sambuc     /// The set of multilibs that the detected installation supports.
99*0a6a1f1dSLionel Sambuc     MultilibSet Multilibs;
100*0a6a1f1dSLionel Sambuc 
101f4a2713aSLionel Sambuc   public:
GCCInstallationDetector()102*0a6a1f1dSLionel Sambuc     GCCInstallationDetector() : IsValid(false) {}
103*0a6a1f1dSLionel Sambuc     void init(const Driver &D, const llvm::Triple &TargetTriple,
104f4a2713aSLionel Sambuc                             const llvm::opt::ArgList &Args);
105f4a2713aSLionel Sambuc 
106f4a2713aSLionel Sambuc     /// \brief Check whether we detected a valid GCC install.
isValid()107f4a2713aSLionel Sambuc     bool isValid() const { return IsValid; }
108f4a2713aSLionel Sambuc 
109f4a2713aSLionel Sambuc     /// \brief Get the GCC triple for the detected install.
getTriple()110f4a2713aSLionel Sambuc     const llvm::Triple &getTriple() const { return GCCTriple; }
111f4a2713aSLionel Sambuc 
112f4a2713aSLionel Sambuc     /// \brief Get the detected GCC installation path.
getInstallPath()113f4a2713aSLionel Sambuc     StringRef getInstallPath() const { return GCCInstallPath; }
114f4a2713aSLionel Sambuc 
115f4a2713aSLionel Sambuc     /// \brief Get the detected GCC parent lib path.
getParentLibPath()116f4a2713aSLionel Sambuc     StringRef getParentLibPath() const { return GCCParentLibPath; }
117f4a2713aSLionel Sambuc 
118*0a6a1f1dSLionel Sambuc     /// \brief Get the detected Multilib
getMultilib()119*0a6a1f1dSLionel Sambuc     const Multilib &getMultilib() const { return SelectedMultilib; }
120*0a6a1f1dSLionel Sambuc 
121*0a6a1f1dSLionel Sambuc     /// \brief Get the whole MultilibSet
getMultilibs()122*0a6a1f1dSLionel Sambuc     const MultilibSet &getMultilibs() const { return Multilibs; }
123*0a6a1f1dSLionel Sambuc 
124*0a6a1f1dSLionel Sambuc     /// Get the biarch sibling multilib (if it exists).
125*0a6a1f1dSLionel Sambuc     /// \return true iff such a sibling exists
126*0a6a1f1dSLionel Sambuc     bool getBiarchSibling(Multilib &M) const;
127f4a2713aSLionel Sambuc 
128f4a2713aSLionel Sambuc     /// \brief Get the detected GCC version string.
getVersion()129f4a2713aSLionel Sambuc     const GCCVersion &getVersion() const { return Version; }
130f4a2713aSLionel Sambuc 
131f4a2713aSLionel Sambuc     /// \brief Print information about the detected GCC installation.
132f4a2713aSLionel Sambuc     void print(raw_ostream &OS) const;
133f4a2713aSLionel Sambuc 
134f4a2713aSLionel Sambuc   private:
135f4a2713aSLionel Sambuc     static void
136f4a2713aSLionel Sambuc     CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
137f4a2713aSLionel Sambuc                              const llvm::Triple &BiarchTriple,
138f4a2713aSLionel Sambuc                              SmallVectorImpl<StringRef> &LibDirs,
139f4a2713aSLionel Sambuc                              SmallVectorImpl<StringRef> &TripleAliases,
140f4a2713aSLionel Sambuc                              SmallVectorImpl<StringRef> &BiarchLibDirs,
141f4a2713aSLionel Sambuc                              SmallVectorImpl<StringRef> &BiarchTripleAliases);
142f4a2713aSLionel Sambuc 
143*0a6a1f1dSLionel Sambuc     void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch,
144f4a2713aSLionel Sambuc                                 const llvm::opt::ArgList &Args,
145f4a2713aSLionel Sambuc                                 const std::string &LibDir,
146f4a2713aSLionel Sambuc                                 StringRef CandidateTriple,
147f4a2713aSLionel Sambuc                                 bool NeedsBiarchSuffix = false);
148f4a2713aSLionel Sambuc   };
149f4a2713aSLionel Sambuc 
150f4a2713aSLionel Sambuc   GCCInstallationDetector GCCInstallation;
151f4a2713aSLionel Sambuc 
152f4a2713aSLionel Sambuc public:
153f4a2713aSLionel Sambuc   Generic_GCC(const Driver &D, const llvm::Triple &Triple,
154f4a2713aSLionel Sambuc               const llvm::opt::ArgList &Args);
155f4a2713aSLionel Sambuc   ~Generic_GCC();
156f4a2713aSLionel Sambuc 
157*0a6a1f1dSLionel Sambuc   void printVerboseInfo(raw_ostream &OS) const override;
158f4a2713aSLionel Sambuc 
159*0a6a1f1dSLionel Sambuc   bool IsUnwindTablesDefault() const override;
160*0a6a1f1dSLionel Sambuc   bool isPICDefault() const override;
161*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override;
162*0a6a1f1dSLionel Sambuc   bool isPICDefaultForced() const override;
163*0a6a1f1dSLionel Sambuc   bool IsIntegratedAssemblerDefault() const override;
164f4a2713aSLionel Sambuc 
165f4a2713aSLionel Sambuc protected:
166*0a6a1f1dSLionel Sambuc   Tool *getTool(Action::ActionClass AC) const override;
167*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
168*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
169f4a2713aSLionel Sambuc 
170f4a2713aSLionel Sambuc   /// \name ToolChain Implementation Helper Functions
171f4a2713aSLionel Sambuc   /// @{
172f4a2713aSLionel Sambuc 
173f4a2713aSLionel Sambuc   /// \brief Check whether the target triple's architecture is 64-bits.
isTarget64Bit()174f4a2713aSLionel Sambuc   bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
175f4a2713aSLionel Sambuc 
176f4a2713aSLionel Sambuc   /// \brief Check whether the target triple's architecture is 32-bits.
isTarget32Bit()177f4a2713aSLionel Sambuc   bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
178f4a2713aSLionel Sambuc 
179f4a2713aSLionel Sambuc   /// @}
180f4a2713aSLionel Sambuc 
181f4a2713aSLionel Sambuc private:
182*0a6a1f1dSLionel Sambuc   mutable std::unique_ptr<tools::gcc::Preprocess> Preprocess;
183*0a6a1f1dSLionel Sambuc   mutable std::unique_ptr<tools::gcc::Compile> Compile;
184*0a6a1f1dSLionel Sambuc };
185*0a6a1f1dSLionel Sambuc 
186*0a6a1f1dSLionel Sambuc class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
187*0a6a1f1dSLionel Sambuc protected:
188*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
189*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
190*0a6a1f1dSLionel Sambuc   Tool *getTool(Action::ActionClass AC) const override;
191*0a6a1f1dSLionel Sambuc private:
192*0a6a1f1dSLionel Sambuc   mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
193*0a6a1f1dSLionel Sambuc   mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
194*0a6a1f1dSLionel Sambuc   mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug;
195*0a6a1f1dSLionel Sambuc 
196*0a6a1f1dSLionel Sambuc public:
197*0a6a1f1dSLionel Sambuc   MachO(const Driver &D, const llvm::Triple &Triple,
198*0a6a1f1dSLionel Sambuc              const llvm::opt::ArgList &Args);
199*0a6a1f1dSLionel Sambuc   ~MachO();
200*0a6a1f1dSLionel Sambuc 
201*0a6a1f1dSLionel Sambuc   /// @name MachO specific toolchain API
202*0a6a1f1dSLionel Sambuc   /// {
203*0a6a1f1dSLionel Sambuc 
204*0a6a1f1dSLionel Sambuc   /// Get the "MachO" arch name for a particular compiler invocation. For
205*0a6a1f1dSLionel Sambuc   /// example, Apple treats different ARM variations as distinct architectures.
206*0a6a1f1dSLionel Sambuc   StringRef getMachOArchName(const llvm::opt::ArgList &Args) const;
207*0a6a1f1dSLionel Sambuc 
208*0a6a1f1dSLionel Sambuc 
209*0a6a1f1dSLionel Sambuc   /// Add the linker arguments to link the ARC runtime library.
AddLinkARCArgs(const llvm::opt::ArgList & Args,llvm::opt::ArgStringList & CmdArgs)210*0a6a1f1dSLionel Sambuc   virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
211*0a6a1f1dSLionel Sambuc                               llvm::opt::ArgStringList &CmdArgs) const {}
212*0a6a1f1dSLionel Sambuc 
213*0a6a1f1dSLionel Sambuc   /// Add the linker arguments to link the compiler runtime library.
214*0a6a1f1dSLionel Sambuc   virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
215*0a6a1f1dSLionel Sambuc                                      llvm::opt::ArgStringList &CmdArgs) const;
216*0a6a1f1dSLionel Sambuc 
217*0a6a1f1dSLionel Sambuc   virtual void
addStartObjectFileArgs(const llvm::opt::ArgList & Args,llvm::opt::ArgStringList & CmdArgs)218*0a6a1f1dSLionel Sambuc   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
219*0a6a1f1dSLionel Sambuc                          llvm::opt::ArgStringList &CmdArgs) const {}
220*0a6a1f1dSLionel Sambuc 
addMinVersionArgs(const llvm::opt::ArgList & Args,llvm::opt::ArgStringList & CmdArgs)221*0a6a1f1dSLionel Sambuc   virtual void addMinVersionArgs(const llvm::opt::ArgList &Args,
222*0a6a1f1dSLionel Sambuc                                  llvm::opt::ArgStringList &CmdArgs) const {}
223*0a6a1f1dSLionel Sambuc 
224*0a6a1f1dSLionel Sambuc   /// On some iOS platforms, kernel and kernel modules were built statically. Is
225*0a6a1f1dSLionel Sambuc   /// this such a target?
isKernelStatic()226*0a6a1f1dSLionel Sambuc   virtual bool isKernelStatic() const {
227*0a6a1f1dSLionel Sambuc     return false;
228*0a6a1f1dSLionel Sambuc   }
229*0a6a1f1dSLionel Sambuc 
230*0a6a1f1dSLionel Sambuc   /// Is the target either iOS or an iOS simulator?
isTargetIOSBased()231*0a6a1f1dSLionel Sambuc   bool isTargetIOSBased() const {
232*0a6a1f1dSLionel Sambuc     return false;
233*0a6a1f1dSLionel Sambuc   }
234*0a6a1f1dSLionel Sambuc 
235*0a6a1f1dSLionel Sambuc   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
236*0a6a1f1dSLionel Sambuc                          llvm::opt::ArgStringList &CmdArgs,
237*0a6a1f1dSLionel Sambuc                          StringRef DarwinLibName,
238*0a6a1f1dSLionel Sambuc                          bool AlwaysLink = false,
239*0a6a1f1dSLionel Sambuc                          bool IsEmbedded = false,
240*0a6a1f1dSLionel Sambuc                          bool AddRPath = false) const;
241*0a6a1f1dSLionel Sambuc 
242*0a6a1f1dSLionel Sambuc   /// }
243*0a6a1f1dSLionel Sambuc   /// @name ToolChain Implementation
244*0a6a1f1dSLionel Sambuc   /// {
245*0a6a1f1dSLionel Sambuc 
246*0a6a1f1dSLionel Sambuc   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
247*0a6a1f1dSLionel Sambuc                                           types::ID InputType) const override;
248*0a6a1f1dSLionel Sambuc 
249*0a6a1f1dSLionel Sambuc   types::ID LookupTypeForExtension(const char *Ext) const override;
250*0a6a1f1dSLionel Sambuc 
251*0a6a1f1dSLionel Sambuc   bool HasNativeLLVMSupport() const override;
252*0a6a1f1dSLionel Sambuc 
253*0a6a1f1dSLionel Sambuc   llvm::opt::DerivedArgList *
254*0a6a1f1dSLionel Sambuc   TranslateArgs(const llvm::opt::DerivedArgList &Args,
255*0a6a1f1dSLionel Sambuc                 const char *BoundArch) const override;
256*0a6a1f1dSLionel Sambuc 
IsBlocksDefault()257*0a6a1f1dSLionel Sambuc   bool IsBlocksDefault() const override {
258*0a6a1f1dSLionel Sambuc     // Always allow blocks on Apple; users interested in versioning are
259*0a6a1f1dSLionel Sambuc     // expected to use /usr/include/Block.h.
260*0a6a1f1dSLionel Sambuc     return true;
261*0a6a1f1dSLionel Sambuc   }
IsIntegratedAssemblerDefault()262*0a6a1f1dSLionel Sambuc   bool IsIntegratedAssemblerDefault() const override {
263*0a6a1f1dSLionel Sambuc     // Default integrated assembler to on for Apple's MachO targets.
264*0a6a1f1dSLionel Sambuc     return true;
265*0a6a1f1dSLionel Sambuc   }
266*0a6a1f1dSLionel Sambuc 
IsMathErrnoDefault()267*0a6a1f1dSLionel Sambuc   bool IsMathErrnoDefault() const override {
268*0a6a1f1dSLionel Sambuc     return false;
269*0a6a1f1dSLionel Sambuc   }
270*0a6a1f1dSLionel Sambuc 
IsEncodeExtendedBlockSignatureDefault()271*0a6a1f1dSLionel Sambuc   bool IsEncodeExtendedBlockSignatureDefault() const override {
272*0a6a1f1dSLionel Sambuc     return true;
273*0a6a1f1dSLionel Sambuc   }
274*0a6a1f1dSLionel Sambuc 
IsObjCNonFragileABIDefault()275*0a6a1f1dSLionel Sambuc   bool IsObjCNonFragileABIDefault() const override {
276*0a6a1f1dSLionel Sambuc     // Non-fragile ABI is default for everything but i386.
277*0a6a1f1dSLionel Sambuc     return getTriple().getArch() != llvm::Triple::x86;
278*0a6a1f1dSLionel Sambuc   }
279*0a6a1f1dSLionel Sambuc 
UseObjCMixedDispatch()280*0a6a1f1dSLionel Sambuc   bool UseObjCMixedDispatch() const override {
281*0a6a1f1dSLionel Sambuc     return true;
282*0a6a1f1dSLionel Sambuc   }
283*0a6a1f1dSLionel Sambuc 
284*0a6a1f1dSLionel Sambuc   bool IsUnwindTablesDefault() const override;
285*0a6a1f1dSLionel Sambuc 
GetDefaultRuntimeLibType()286*0a6a1f1dSLionel Sambuc   RuntimeLibType GetDefaultRuntimeLibType() const override {
287*0a6a1f1dSLionel Sambuc     return ToolChain::RLT_CompilerRT;
288*0a6a1f1dSLionel Sambuc   }
289*0a6a1f1dSLionel Sambuc 
290*0a6a1f1dSLionel Sambuc   bool isPICDefault() const override;
291*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override;
292*0a6a1f1dSLionel Sambuc   bool isPICDefaultForced() const override;
293*0a6a1f1dSLionel Sambuc 
294*0a6a1f1dSLionel Sambuc   bool SupportsProfiling() const override;
295*0a6a1f1dSLionel Sambuc 
SupportsObjCGC()296*0a6a1f1dSLionel Sambuc   bool SupportsObjCGC() const override {
297*0a6a1f1dSLionel Sambuc     return false;
298*0a6a1f1dSLionel Sambuc   }
299*0a6a1f1dSLionel Sambuc 
300*0a6a1f1dSLionel Sambuc   bool UseDwarfDebugFlags() const override;
301*0a6a1f1dSLionel Sambuc 
UseSjLjExceptions()302*0a6a1f1dSLionel Sambuc   bool UseSjLjExceptions() const override {
303*0a6a1f1dSLionel Sambuc     return false;
304*0a6a1f1dSLionel Sambuc   }
305*0a6a1f1dSLionel Sambuc 
306*0a6a1f1dSLionel Sambuc   /// }
307f4a2713aSLionel Sambuc };
308f4a2713aSLionel Sambuc 
309f4a2713aSLionel Sambuc   /// Darwin - The base Darwin tool chain.
310*0a6a1f1dSLionel Sambuc class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
311f4a2713aSLionel Sambuc public:
312f4a2713aSLionel Sambuc   /// The host version.
313f4a2713aSLionel Sambuc   unsigned DarwinVersion[3];
314f4a2713aSLionel Sambuc 
315f4a2713aSLionel Sambuc   /// Whether the information on the target has been initialized.
316f4a2713aSLionel Sambuc   //
317f4a2713aSLionel Sambuc   // FIXME: This should be eliminated. What we want to do is make this part of
318f4a2713aSLionel Sambuc   // the "default target for arguments" selection process, once we get out of
319f4a2713aSLionel Sambuc   // the argument translation business.
320f4a2713aSLionel Sambuc   mutable bool TargetInitialized;
321f4a2713aSLionel Sambuc 
322*0a6a1f1dSLionel Sambuc   enum DarwinPlatformKind {
323*0a6a1f1dSLionel Sambuc     MacOS,
324*0a6a1f1dSLionel Sambuc     IPhoneOS,
325*0a6a1f1dSLionel Sambuc     IPhoneOSSimulator
326*0a6a1f1dSLionel Sambuc   };
327f4a2713aSLionel Sambuc 
328*0a6a1f1dSLionel Sambuc   mutable DarwinPlatformKind TargetPlatform;
329f4a2713aSLionel Sambuc 
330f4a2713aSLionel Sambuc   /// The OS version we are targeting.
331f4a2713aSLionel Sambuc   mutable VersionTuple TargetVersion;
332f4a2713aSLionel Sambuc 
333f4a2713aSLionel Sambuc private:
334f4a2713aSLionel Sambuc   /// The default macosx-version-min of this tool chain; empty until
335f4a2713aSLionel Sambuc   /// initialized.
336f4a2713aSLionel Sambuc   std::string MacosxVersionMin;
337f4a2713aSLionel Sambuc 
338f4a2713aSLionel Sambuc   /// The default ios-version-min of this tool chain; empty until
339f4a2713aSLionel Sambuc   /// initialized.
340f4a2713aSLionel Sambuc   std::string iOSVersionMin;
341f4a2713aSLionel Sambuc 
342f4a2713aSLionel Sambuc private:
343f4a2713aSLionel Sambuc   void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
344f4a2713aSLionel Sambuc 
345f4a2713aSLionel Sambuc public:
346f4a2713aSLionel Sambuc   Darwin(const Driver &D, const llvm::Triple &Triple,
347f4a2713aSLionel Sambuc          const llvm::opt::ArgList &Args);
348f4a2713aSLionel Sambuc   ~Darwin();
349f4a2713aSLionel Sambuc 
350f4a2713aSLionel Sambuc   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
351*0a6a1f1dSLionel Sambuc                                           types::ID InputType) const override;
352f4a2713aSLionel Sambuc 
353*0a6a1f1dSLionel Sambuc   /// @name Apple Specific Toolchain Implementation
354*0a6a1f1dSLionel Sambuc   /// {
355*0a6a1f1dSLionel Sambuc 
356*0a6a1f1dSLionel Sambuc   void
357*0a6a1f1dSLionel Sambuc   addMinVersionArgs(const llvm::opt::ArgList &Args,
358*0a6a1f1dSLionel Sambuc                     llvm::opt::ArgStringList &CmdArgs) const override;
359*0a6a1f1dSLionel Sambuc 
360*0a6a1f1dSLionel Sambuc   void
361*0a6a1f1dSLionel Sambuc   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
362*0a6a1f1dSLionel Sambuc                          llvm::opt::ArgStringList &CmdArgs) const override;
363*0a6a1f1dSLionel Sambuc 
isKernelStatic()364*0a6a1f1dSLionel Sambuc   bool isKernelStatic() const override {
365*0a6a1f1dSLionel Sambuc     return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0) ||
366*0a6a1f1dSLionel Sambuc            getTriple().getArch() == llvm::Triple::aarch64;
367*0a6a1f1dSLionel Sambuc   }
368*0a6a1f1dSLionel Sambuc 
369*0a6a1f1dSLionel Sambuc protected:
370*0a6a1f1dSLionel Sambuc   /// }
371*0a6a1f1dSLionel Sambuc   /// @name Darwin specific Toolchain functions
372f4a2713aSLionel Sambuc   /// {
373f4a2713aSLionel Sambuc 
374f4a2713aSLionel Sambuc   // FIXME: Eliminate these ...Target functions and derive separate tool chains
375f4a2713aSLionel Sambuc   // for these targets and put version in constructor.
setTarget(DarwinPlatformKind Platform,unsigned Major,unsigned Minor,unsigned Micro)376*0a6a1f1dSLionel Sambuc   void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
377*0a6a1f1dSLionel Sambuc                  unsigned Micro) const {
378f4a2713aSLionel Sambuc     // FIXME: For now, allow reinitialization as long as values don't
379f4a2713aSLionel Sambuc     // change. This will go away when we move away from argument translation.
380*0a6a1f1dSLionel Sambuc     if (TargetInitialized && TargetPlatform == Platform &&
381f4a2713aSLionel Sambuc         TargetVersion == VersionTuple(Major, Minor, Micro))
382f4a2713aSLionel Sambuc       return;
383f4a2713aSLionel Sambuc 
384f4a2713aSLionel Sambuc     assert(!TargetInitialized && "Target already initialized!");
385f4a2713aSLionel Sambuc     TargetInitialized = true;
386*0a6a1f1dSLionel Sambuc     TargetPlatform = Platform;
387f4a2713aSLionel Sambuc     TargetVersion = VersionTuple(Major, Minor, Micro);
388f4a2713aSLionel Sambuc   }
389f4a2713aSLionel Sambuc 
isTargetIPhoneOS()390f4a2713aSLionel Sambuc   bool isTargetIPhoneOS() const {
391f4a2713aSLionel Sambuc     assert(TargetInitialized && "Target not initialized!");
392*0a6a1f1dSLionel Sambuc     return TargetPlatform == IPhoneOS;
393f4a2713aSLionel Sambuc   }
394f4a2713aSLionel Sambuc 
isTargetIOSSimulator()395f4a2713aSLionel Sambuc   bool isTargetIOSSimulator() const {
396f4a2713aSLionel Sambuc     assert(TargetInitialized && "Target not initialized!");
397*0a6a1f1dSLionel Sambuc     return TargetPlatform == IPhoneOSSimulator;
398*0a6a1f1dSLionel Sambuc   }
399*0a6a1f1dSLionel Sambuc 
isTargetIOSBased()400*0a6a1f1dSLionel Sambuc   bool isTargetIOSBased() const {
401*0a6a1f1dSLionel Sambuc     assert(TargetInitialized && "Target not initialized!");
402*0a6a1f1dSLionel Sambuc     return isTargetIPhoneOS() || isTargetIOSSimulator();
403f4a2713aSLionel Sambuc   }
404f4a2713aSLionel Sambuc 
isTargetMacOS()405f4a2713aSLionel Sambuc   bool isTargetMacOS() const {
406*0a6a1f1dSLionel Sambuc     return TargetPlatform == MacOS;
407f4a2713aSLionel Sambuc   }
408f4a2713aSLionel Sambuc 
isTargetInitialized()409f4a2713aSLionel Sambuc   bool isTargetInitialized() const { return TargetInitialized; }
410f4a2713aSLionel Sambuc 
getTargetVersion()411f4a2713aSLionel Sambuc   VersionTuple getTargetVersion() const {
412f4a2713aSLionel Sambuc     assert(TargetInitialized && "Target not initialized!");
413f4a2713aSLionel Sambuc     return TargetVersion;
414f4a2713aSLionel Sambuc   }
415f4a2713aSLionel Sambuc 
416f4a2713aSLionel Sambuc   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
417*0a6a1f1dSLionel Sambuc     assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
418f4a2713aSLionel Sambuc     return TargetVersion < VersionTuple(V0, V1, V2);
419f4a2713aSLionel Sambuc   }
420f4a2713aSLionel Sambuc 
421f4a2713aSLionel Sambuc   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
422*0a6a1f1dSLionel Sambuc     assert(isTargetMacOS() && "Unexpected call for non OS X target!");
423f4a2713aSLionel Sambuc     return TargetVersion < VersionTuple(V0, V1, V2);
424f4a2713aSLionel Sambuc   }
425f4a2713aSLionel Sambuc 
426*0a6a1f1dSLionel Sambuc public:
427f4a2713aSLionel Sambuc   /// }
428f4a2713aSLionel Sambuc   /// @name ToolChain Implementation
429f4a2713aSLionel Sambuc   /// {
430f4a2713aSLionel Sambuc 
431*0a6a1f1dSLionel Sambuc   // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
432*0a6a1f1dSLionel Sambuc   // most development is done against SDKs, so compiling for a different
433*0a6a1f1dSLionel Sambuc   // architecture should not get any special treatment.
isCrossCompiling()434*0a6a1f1dSLionel Sambuc   bool isCrossCompiling() const override { return false; }
435f4a2713aSLionel Sambuc 
436*0a6a1f1dSLionel Sambuc   llvm::opt::DerivedArgList *
437f4a2713aSLionel Sambuc   TranslateArgs(const llvm::opt::DerivedArgList &Args,
438*0a6a1f1dSLionel Sambuc                 const char *BoundArch) const override;
439f4a2713aSLionel Sambuc 
440*0a6a1f1dSLionel Sambuc   ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
441*0a6a1f1dSLionel Sambuc   bool hasBlocksRuntime() const override;
442f4a2713aSLionel Sambuc 
UseObjCMixedDispatch()443*0a6a1f1dSLionel Sambuc   bool UseObjCMixedDispatch() const override {
444f4a2713aSLionel Sambuc     // This is only used with the non-fragile ABI and non-legacy dispatch.
445f4a2713aSLionel Sambuc 
446f4a2713aSLionel Sambuc     // Mixed dispatch is used everywhere except OS X before 10.6.
447*0a6a1f1dSLionel Sambuc     return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
448f4a2713aSLionel Sambuc   }
449*0a6a1f1dSLionel Sambuc 
GetDefaultStackProtectorLevel(bool KernelOrKext)450*0a6a1f1dSLionel Sambuc   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
451f4a2713aSLionel Sambuc     // Stack protectors default to on for user code on 10.5,
452f4a2713aSLionel Sambuc     // and for everything in 10.6 and beyond
453*0a6a1f1dSLionel Sambuc     if (isTargetIOSBased())
454*0a6a1f1dSLionel Sambuc       return 1;
455*0a6a1f1dSLionel Sambuc     else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
456*0a6a1f1dSLionel Sambuc       return 1;
457*0a6a1f1dSLionel Sambuc     else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
458*0a6a1f1dSLionel Sambuc       return 1;
459*0a6a1f1dSLionel Sambuc 
460*0a6a1f1dSLionel Sambuc     return 0;
461f4a2713aSLionel Sambuc   }
462f4a2713aSLionel Sambuc 
463*0a6a1f1dSLionel Sambuc   bool SupportsObjCGC() const override;
464f4a2713aSLionel Sambuc 
465*0a6a1f1dSLionel Sambuc   void CheckObjCARC() const override;
466f4a2713aSLionel Sambuc 
467*0a6a1f1dSLionel Sambuc   bool UseSjLjExceptions() const override;
468f4a2713aSLionel Sambuc };
469f4a2713aSLionel Sambuc 
470f4a2713aSLionel Sambuc /// DarwinClang - The Darwin toolchain used by Clang.
471f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
472f4a2713aSLionel Sambuc public:
473f4a2713aSLionel Sambuc   DarwinClang(const Driver &D, const llvm::Triple &Triple,
474f4a2713aSLionel Sambuc               const llvm::opt::ArgList &Args);
475f4a2713aSLionel Sambuc 
476*0a6a1f1dSLionel Sambuc   /// @name Apple ToolChain Implementation
477f4a2713aSLionel Sambuc   /// {
478f4a2713aSLionel Sambuc 
479*0a6a1f1dSLionel Sambuc   void
480*0a6a1f1dSLionel Sambuc   AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
481*0a6a1f1dSLionel Sambuc                         llvm::opt::ArgStringList &CmdArgs) const override;
482f4a2713aSLionel Sambuc 
483*0a6a1f1dSLionel Sambuc   void
484*0a6a1f1dSLionel Sambuc   AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
485*0a6a1f1dSLionel Sambuc                       llvm::opt::ArgStringList &CmdArgs) const override;
486f4a2713aSLionel Sambuc 
487*0a6a1f1dSLionel Sambuc   void
488*0a6a1f1dSLionel Sambuc   AddCCKextLibArgs(const llvm::opt::ArgList &Args,
489*0a6a1f1dSLionel Sambuc                    llvm::opt::ArgStringList &CmdArgs) const override;
490f4a2713aSLionel Sambuc 
491*0a6a1f1dSLionel Sambuc   virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args)
492*0a6a1f1dSLionel Sambuc                                                       const override;
493*0a6a1f1dSLionel Sambuc 
494*0a6a1f1dSLionel Sambuc   void
495*0a6a1f1dSLionel Sambuc   AddLinkARCArgs(const llvm::opt::ArgList &Args,
496*0a6a1f1dSLionel Sambuc                  llvm::opt::ArgStringList &CmdArgs) const override;
497f4a2713aSLionel Sambuc   /// }
498f4a2713aSLionel Sambuc };
499f4a2713aSLionel Sambuc 
500f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
501f4a2713aSLionel Sambuc   virtual void anchor();
502f4a2713aSLionel Sambuc public:
Generic_ELF(const Driver & D,const llvm::Triple & Triple,const llvm::opt::ArgList & Args)503f4a2713aSLionel Sambuc   Generic_ELF(const Driver &D, const llvm::Triple &Triple,
504f4a2713aSLionel Sambuc               const llvm::opt::ArgList &Args)
505f4a2713aSLionel Sambuc       : Generic_GCC(D, Triple, Args) {}
506f4a2713aSLionel Sambuc 
507*0a6a1f1dSLionel Sambuc   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
508*0a6a1f1dSLionel Sambuc                              llvm::opt::ArgStringList &CC1Args) const override;
509f4a2713aSLionel Sambuc };
510f4a2713aSLionel Sambuc 
511f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
512f4a2713aSLionel Sambuc public:
513f4a2713aSLionel Sambuc   Solaris(const Driver &D, const llvm::Triple &Triple,
514f4a2713aSLionel Sambuc           const llvm::opt::ArgList &Args);
515f4a2713aSLionel Sambuc 
IsIntegratedAssemblerDefault()516*0a6a1f1dSLionel Sambuc   bool IsIntegratedAssemblerDefault() const override { return true; }
517f4a2713aSLionel Sambuc protected:
518*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
519*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
520f4a2713aSLionel Sambuc 
521f4a2713aSLionel Sambuc };
522f4a2713aSLionel Sambuc 
523f4a2713aSLionel Sambuc 
524f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
525f4a2713aSLionel Sambuc public:
526f4a2713aSLionel Sambuc   OpenBSD(const Driver &D, const llvm::Triple &Triple,
527f4a2713aSLionel Sambuc           const llvm::opt::ArgList &Args);
528f4a2713aSLionel Sambuc 
IsMathErrnoDefault()529*0a6a1f1dSLionel Sambuc   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()530*0a6a1f1dSLionel Sambuc   bool IsObjCNonFragileABIDefault() const override { return true; }
isPIEDefault()531*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override { return true; }
532f4a2713aSLionel Sambuc 
GetDefaultStackProtectorLevel(bool KernelOrKext)533*0a6a1f1dSLionel Sambuc   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
534*0a6a1f1dSLionel Sambuc     return 2;
535f4a2713aSLionel Sambuc   }
536f4a2713aSLionel Sambuc 
537f4a2713aSLionel Sambuc protected:
538*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
539*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
540f4a2713aSLionel Sambuc };
541f4a2713aSLionel Sambuc 
542f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
543f4a2713aSLionel Sambuc public:
544f4a2713aSLionel Sambuc   Bitrig(const Driver &D, const llvm::Triple &Triple,
545f4a2713aSLionel Sambuc          const llvm::opt::ArgList &Args);
546f4a2713aSLionel Sambuc 
IsMathErrnoDefault()547*0a6a1f1dSLionel Sambuc   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()548*0a6a1f1dSLionel Sambuc   bool IsObjCNonFragileABIDefault() const override { return true; }
549f4a2713aSLionel Sambuc 
550*0a6a1f1dSLionel Sambuc   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
551*0a6a1f1dSLionel Sambuc   void
552f4a2713aSLionel Sambuc   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
553*0a6a1f1dSLionel Sambuc                               llvm::opt::ArgStringList &CC1Args) const override;
554*0a6a1f1dSLionel Sambuc   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
555*0a6a1f1dSLionel Sambuc                            llvm::opt::ArgStringList &CmdArgs) const override;
GetDefaultStackProtectorLevel(bool KernelOrKext)556*0a6a1f1dSLionel Sambuc   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
557f4a2713aSLionel Sambuc      return 1;
558f4a2713aSLionel Sambuc   }
559f4a2713aSLionel Sambuc 
560f4a2713aSLionel Sambuc protected:
561*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
562*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
563f4a2713aSLionel Sambuc };
564f4a2713aSLionel Sambuc 
565f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
566f4a2713aSLionel Sambuc public:
567f4a2713aSLionel Sambuc   FreeBSD(const Driver &D, const llvm::Triple &Triple,
568f4a2713aSLionel Sambuc           const llvm::opt::ArgList &Args);
569*0a6a1f1dSLionel Sambuc   bool HasNativeLLVMSupport() const override;
570f4a2713aSLionel Sambuc 
IsMathErrnoDefault()571*0a6a1f1dSLionel Sambuc   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()572*0a6a1f1dSLionel Sambuc   bool IsObjCNonFragileABIDefault() const override { return true; }
573f4a2713aSLionel Sambuc 
574*0a6a1f1dSLionel Sambuc   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
575*0a6a1f1dSLionel Sambuc   void
576f4a2713aSLionel Sambuc   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
577*0a6a1f1dSLionel Sambuc                                llvm::opt::ArgStringList &CC1Args) const override;
578f4a2713aSLionel Sambuc 
579*0a6a1f1dSLionel Sambuc   bool UseSjLjExceptions() const override;
580*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override;
581f4a2713aSLionel Sambuc protected:
582*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
583*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
584f4a2713aSLionel Sambuc };
585f4a2713aSLionel Sambuc 
586f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
587f4a2713aSLionel Sambuc public:
588f4a2713aSLionel Sambuc   NetBSD(const Driver &D, const llvm::Triple &Triple,
589f4a2713aSLionel Sambuc          const llvm::opt::ArgList &Args);
590f4a2713aSLionel Sambuc 
IsMathErrnoDefault()591*0a6a1f1dSLionel Sambuc   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()592*0a6a1f1dSLionel Sambuc   bool IsObjCNonFragileABIDefault() const override { return true; }
593f4a2713aSLionel Sambuc 
594*0a6a1f1dSLionel Sambuc   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
595f4a2713aSLionel Sambuc 
596*0a6a1f1dSLionel Sambuc   void
597f4a2713aSLionel Sambuc   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
598*0a6a1f1dSLionel Sambuc                               llvm::opt::ArgStringList &CC1Args) const override;
IsUnwindTablesDefault()599*0a6a1f1dSLionel Sambuc   bool IsUnwindTablesDefault() const override {
600f4a2713aSLionel Sambuc     return true;
601f4a2713aSLionel Sambuc   }
602f4a2713aSLionel Sambuc 
603f4a2713aSLionel Sambuc protected:
604*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
605*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
606f4a2713aSLionel Sambuc };
607f4a2713aSLionel Sambuc 
608f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
609f4a2713aSLionel Sambuc public:
610f4a2713aSLionel Sambuc   Minix(const Driver &D, const llvm::Triple &Triple,
611f4a2713aSLionel Sambuc          const llvm::opt::ArgList &Args);
612f4a2713aSLionel Sambuc 
IsMathErrnoDefault()613*0a6a1f1dSLionel Sambuc   bool IsMathErrnoDefault() const override { return false; }
IsObjCNonFragileABIDefault()614*0a6a1f1dSLionel Sambuc   bool IsObjCNonFragileABIDefault() const override { return true; }
6154684ddb6SLionel Sambuc 
616*0a6a1f1dSLionel Sambuc   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
6174684ddb6SLionel Sambuc 
618*0a6a1f1dSLionel Sambuc   void
6194684ddb6SLionel Sambuc   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
620*0a6a1f1dSLionel Sambuc                               llvm::opt::ArgStringList &CC1Args) const override;
IsUnwindTablesDefault()621*0a6a1f1dSLionel Sambuc   bool IsUnwindTablesDefault() const override {
6224684ddb6SLionel Sambuc     return true;
6234684ddb6SLionel Sambuc   }
6244684ddb6SLionel Sambuc 
625f4a2713aSLionel Sambuc protected:
626*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
627*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
628f4a2713aSLionel Sambuc };
629f4a2713aSLionel Sambuc 
630f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
631f4a2713aSLionel Sambuc public:
632f4a2713aSLionel Sambuc   DragonFly(const Driver &D, const llvm::Triple &Triple,
633f4a2713aSLionel Sambuc             const llvm::opt::ArgList &Args);
634f4a2713aSLionel Sambuc 
IsMathErrnoDefault()635*0a6a1f1dSLionel Sambuc   bool IsMathErrnoDefault() const override { return false; }
636f4a2713aSLionel Sambuc 
637f4a2713aSLionel Sambuc protected:
638*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
639*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
640f4a2713aSLionel Sambuc };
641f4a2713aSLionel Sambuc 
642f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
643f4a2713aSLionel Sambuc public:
644f4a2713aSLionel Sambuc   Linux(const Driver &D, const llvm::Triple &Triple,
645f4a2713aSLionel Sambuc         const llvm::opt::ArgList &Args);
646f4a2713aSLionel Sambuc 
647*0a6a1f1dSLionel Sambuc   bool HasNativeLLVMSupport() const override;
648f4a2713aSLionel Sambuc 
649*0a6a1f1dSLionel Sambuc   void
650f4a2713aSLionel Sambuc   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
651*0a6a1f1dSLionel Sambuc                             llvm::opt::ArgStringList &CC1Args) const override;
652*0a6a1f1dSLionel Sambuc   void
653f4a2713aSLionel Sambuc   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
654*0a6a1f1dSLionel Sambuc                                llvm::opt::ArgStringList &CC1Args) const override;
655*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override;
656f4a2713aSLionel Sambuc 
657f4a2713aSLionel Sambuc   std::string Linker;
658f4a2713aSLionel Sambuc   std::vector<std::string> ExtraOpts;
659f4a2713aSLionel Sambuc 
660f4a2713aSLionel Sambuc protected:
661*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
662*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
663f4a2713aSLionel Sambuc 
664f4a2713aSLionel Sambuc private:
665f4a2713aSLionel Sambuc   static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
666*0a6a1f1dSLionel Sambuc                                        StringRef GCCTriple,
667*0a6a1f1dSLionel Sambuc                                        StringRef GCCMultiarchTriple,
668*0a6a1f1dSLionel Sambuc                                        StringRef TargetMultiarchTriple,
669*0a6a1f1dSLionel Sambuc                                        Twine IncludeSuffix,
670f4a2713aSLionel Sambuc                                        const llvm::opt::ArgList &DriverArgs,
671f4a2713aSLionel Sambuc                                        llvm::opt::ArgStringList &CC1Args);
672f4a2713aSLionel Sambuc 
673f4a2713aSLionel Sambuc   std::string computeSysRoot() const;
674f4a2713aSLionel Sambuc };
675f4a2713aSLionel Sambuc 
676f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
677f4a2713aSLionel Sambuc protected:
678f4a2713aSLionel Sambuc   GCCVersion GCCLibAndIncVersion;
679*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
680*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
681f4a2713aSLionel Sambuc 
682f4a2713aSLionel Sambuc public:
683f4a2713aSLionel Sambuc   Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
684f4a2713aSLionel Sambuc              const llvm::opt::ArgList &Args);
685f4a2713aSLionel Sambuc   ~Hexagon_TC();
686f4a2713aSLionel Sambuc 
687*0a6a1f1dSLionel Sambuc   void
688f4a2713aSLionel Sambuc   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
689*0a6a1f1dSLionel Sambuc                             llvm::opt::ArgStringList &CC1Args) const override;
690*0a6a1f1dSLionel Sambuc   void
691f4a2713aSLionel Sambuc   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
692*0a6a1f1dSLionel Sambuc                               llvm::opt::ArgStringList &CC1Args) const override;
693*0a6a1f1dSLionel Sambuc   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
694f4a2713aSLionel Sambuc 
GetGCCLibAndIncVersion()695f4a2713aSLionel Sambuc   StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
696f4a2713aSLionel Sambuc 
697*0a6a1f1dSLionel Sambuc   static std::string GetGnuDir(const std::string &InstalledDir,
698*0a6a1f1dSLionel Sambuc                                const llvm::opt::ArgList &Args);
699f4a2713aSLionel Sambuc 
700f4a2713aSLionel Sambuc   static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
701f4a2713aSLionel Sambuc };
702f4a2713aSLionel Sambuc 
703f4a2713aSLionel Sambuc /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
704f4a2713aSLionel Sambuc /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
705f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
706f4a2713aSLionel Sambuc public:
707f4a2713aSLionel Sambuc   TCEToolChain(const Driver &D, const llvm::Triple &Triple,
708f4a2713aSLionel Sambuc                const llvm::opt::ArgList &Args);
709f4a2713aSLionel Sambuc   ~TCEToolChain();
710f4a2713aSLionel Sambuc 
711*0a6a1f1dSLionel Sambuc   bool IsMathErrnoDefault() const override;
712*0a6a1f1dSLionel Sambuc   bool isPICDefault() const override;
713*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override;
714*0a6a1f1dSLionel Sambuc   bool isPICDefaultForced() const override;
715f4a2713aSLionel Sambuc };
716f4a2713aSLionel Sambuc 
717*0a6a1f1dSLionel Sambuc class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
718f4a2713aSLionel Sambuc public:
719*0a6a1f1dSLionel Sambuc   MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
720f4a2713aSLionel Sambuc                 const llvm::opt::ArgList &Args);
721f4a2713aSLionel Sambuc 
722*0a6a1f1dSLionel Sambuc   bool IsIntegratedAssemblerDefault() const override;
723*0a6a1f1dSLionel Sambuc   bool IsUnwindTablesDefault() const override;
724*0a6a1f1dSLionel Sambuc   bool isPICDefault() const override;
725*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override;
726*0a6a1f1dSLionel Sambuc   bool isPICDefaultForced() const override;
727f4a2713aSLionel Sambuc 
728*0a6a1f1dSLionel Sambuc   void
729f4a2713aSLionel Sambuc   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
730*0a6a1f1dSLionel Sambuc                             llvm::opt::ArgStringList &CC1Args) const override;
731*0a6a1f1dSLionel Sambuc   void
732f4a2713aSLionel Sambuc   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
733*0a6a1f1dSLionel Sambuc                                llvm::opt::ArgStringList &CC1Args) const override;
734*0a6a1f1dSLionel Sambuc 
735*0a6a1f1dSLionel Sambuc   bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
736*0a6a1f1dSLionel Sambuc   bool getWindowsSDKLibraryPath(std::string &path) const;
737*0a6a1f1dSLionel Sambuc   bool getVisualStudioInstallDir(std::string &path) const;
738*0a6a1f1dSLionel Sambuc   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
739*0a6a1f1dSLionel Sambuc                                      std::string &path) const;
740f4a2713aSLionel Sambuc 
741f4a2713aSLionel Sambuc protected:
742*0a6a1f1dSLionel Sambuc   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
743*0a6a1f1dSLionel Sambuc                                      llvm::opt::ArgStringList &CC1Args,
744*0a6a1f1dSLionel Sambuc                                      const std::string &folder,
745*0a6a1f1dSLionel Sambuc                                      const char *subfolder) const;
746*0a6a1f1dSLionel Sambuc 
747*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
748*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
749f4a2713aSLionel Sambuc };
750f4a2713aSLionel Sambuc 
751*0a6a1f1dSLionel Sambuc class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
752*0a6a1f1dSLionel Sambuc public:
753*0a6a1f1dSLionel Sambuc   CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
754*0a6a1f1dSLionel Sambuc                         const llvm::opt::ArgList &Args);
755*0a6a1f1dSLionel Sambuc 
IsIntegratedAssemblerDefault()756*0a6a1f1dSLionel Sambuc   bool IsIntegratedAssemblerDefault() const override { return true; }
757*0a6a1f1dSLionel Sambuc   bool IsUnwindTablesDefault() const override;
758*0a6a1f1dSLionel Sambuc   bool isPICDefault() const override;
759*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override;
760*0a6a1f1dSLionel Sambuc   bool isPICDefaultForced() const override;
761*0a6a1f1dSLionel Sambuc 
GetDefaultStackProtectorLevel(bool KernelOrKext)762*0a6a1f1dSLionel Sambuc   unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
763*0a6a1f1dSLionel Sambuc     return 0;
764*0a6a1f1dSLionel Sambuc   }
765*0a6a1f1dSLionel Sambuc 
766*0a6a1f1dSLionel Sambuc   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
767*0a6a1f1dSLionel Sambuc                                  llvm::opt::ArgStringList &CC1Args)
768*0a6a1f1dSLionel Sambuc       const override;
769*0a6a1f1dSLionel Sambuc   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
770*0a6a1f1dSLionel Sambuc                                     llvm::opt::ArgStringList &CC1Args)
771*0a6a1f1dSLionel Sambuc       const override;
772*0a6a1f1dSLionel Sambuc   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
773*0a6a1f1dSLionel Sambuc                            llvm::opt::ArgStringList &CmdArgs) const override;
774*0a6a1f1dSLionel Sambuc 
775*0a6a1f1dSLionel Sambuc protected:
776*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
777*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
778*0a6a1f1dSLionel Sambuc };
779f4a2713aSLionel Sambuc 
780f4a2713aSLionel Sambuc class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
781f4a2713aSLionel Sambuc public:
782f4a2713aSLionel Sambuc   XCore(const Driver &D, const llvm::Triple &Triple,
783f4a2713aSLionel Sambuc           const llvm::opt::ArgList &Args);
784f4a2713aSLionel Sambuc protected:
785*0a6a1f1dSLionel Sambuc   Tool *buildAssembler() const override;
786*0a6a1f1dSLionel Sambuc   Tool *buildLinker() const override;
787f4a2713aSLionel Sambuc public:
788*0a6a1f1dSLionel Sambuc   bool isPICDefault() const override;
789*0a6a1f1dSLionel Sambuc   bool isPIEDefault() const override;
790*0a6a1f1dSLionel Sambuc   bool isPICDefaultForced() const override;
791*0a6a1f1dSLionel Sambuc   bool SupportsProfiling() const override;
792*0a6a1f1dSLionel Sambuc   bool hasBlocksRuntime() const override;
793*0a6a1f1dSLionel Sambuc   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
794*0a6a1f1dSLionel Sambuc                     llvm::opt::ArgStringList &CC1Args) const override;
795*0a6a1f1dSLionel Sambuc   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
796*0a6a1f1dSLionel Sambuc                              llvm::opt::ArgStringList &CC1Args) const override;
797*0a6a1f1dSLionel Sambuc   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
798*0a6a1f1dSLionel Sambuc                        llvm::opt::ArgStringList &CC1Args) const override;
799*0a6a1f1dSLionel Sambuc   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
800*0a6a1f1dSLionel Sambuc                            llvm::opt::ArgStringList &CmdArgs) const override;
801f4a2713aSLionel Sambuc };
802f4a2713aSLionel Sambuc 
803f4a2713aSLionel Sambuc } // end namespace toolchains
804f4a2713aSLionel Sambuc } // end namespace driver
805f4a2713aSLionel Sambuc } // end namespace clang
806f4a2713aSLionel Sambuc 
807f4a2713aSLionel Sambuc #endif
808