blob: 0873ca1e3cca04ad90df552f746ca2ec35531ea3 [file] [log] [blame]
Daniel Dunbar83b08eb2009-03-17 21:38:00 +00001//===--- 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
Chandler Carruth55fc8732012-12-04 09:13:33 +000013#include "Tools.h"
14#include "clang/Basic/VersionTuple.h"
Daniel Dunbar670b7f42009-03-17 22:07:31 +000015#include "clang/Driver/Action.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000016#include "clang/Driver/ToolChain.h"
Daniel Dunbar670b7f42009-03-17 22:07:31 +000017#include "llvm/ADT/DenseMap.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000018#include "llvm/Support/Compiler.h"
19
Rafael Espindolaa2654612013-06-11 20:06:05 +000020#include <vector>
21
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000022namespace clang {
23namespace driver {
Daniel Dunbar985b8252009-03-17 22:18:43 +000024namespace toolchains {
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000025
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000026/// 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.
Duncan Sands92dd1912010-05-11 20:16:05 +000029class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
Daniel Dunbar75358d22009-03-30 21:06:03 +000030protected:
Chandler Carruth19347ed2011-11-06 23:39:34 +000031 /// \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 Any textual suffix on the patch number.
54 std::string PatchSuffix;
55
56 static GCCVersion Parse(StringRef VersionText);
57 bool operator<(const GCCVersion &RHS) const;
58 bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
59 bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
60 bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
61 };
62
63
64 /// \brief This is a class to find a viable GCC installation for Clang to
65 /// use.
66 ///
67 /// This class tries to find a GCC installation on the system, and report
68 /// information about it. It starts from the host information provided to the
69 /// Driver, and has logic for fuzzing that where appropriate.
70 class GCCInstallationDetector {
71
72 bool IsValid;
Chandler Carruthfa5be912012-01-24 19:28:29 +000073 llvm::Triple GCCTriple;
Chandler Carruth19347ed2011-11-06 23:39:34 +000074
75 // FIXME: These might be better as path objects.
Chandler Carruth5d84bb42012-01-24 19:21:42 +000076 std::string GCCInstallPath;
Chandler Carruthd79486a2013-06-22 11:35:51 +000077 std::string GCCBiarchSuffix;
Chandler Carruth5d84bb42012-01-24 19:21:42 +000078 std::string GCCParentLibPath;
Chandler Carruth19347ed2011-11-06 23:39:34 +000079
80 GCCVersion Version;
81
82 public:
Rafael Espindola0e659592012-02-19 01:38:32 +000083 GCCInstallationDetector(const Driver &D, const llvm::Triple &TargetTriple,
Reid Klecknerdd0b3c42013-06-17 13:59:19 +000084 const llvm::opt::ArgList &Args);
Chandler Carruth19347ed2011-11-06 23:39:34 +000085
86 /// \brief Check whether we detected a valid GCC install.
87 bool isValid() const { return IsValid; }
88
89 /// \brief Get the GCC triple for the detected install.
Chandler Carruthfa5be912012-01-24 19:28:29 +000090 const llvm::Triple &getTriple() const { return GCCTriple; }
Chandler Carruth19347ed2011-11-06 23:39:34 +000091
92 /// \brief Get the detected GCC installation path.
Chandler Carruth5d84bb42012-01-24 19:21:42 +000093 StringRef getInstallPath() const { return GCCInstallPath; }
Chandler Carruth19347ed2011-11-06 23:39:34 +000094
Chandler Carruthd79486a2013-06-22 11:35:51 +000095 /// \brief Get the detected GCC installation path suffix for the bi-arch
96 /// target variant.
97 StringRef getBiarchSuffix() const { return GCCBiarchSuffix; }
Chandler Carruth1c6f04a2012-01-25 07:21:38 +000098
Chandler Carruth19347ed2011-11-06 23:39:34 +000099 /// \brief Get the detected GCC parent lib path.
Chandler Carruth5d84bb42012-01-24 19:21:42 +0000100 StringRef getParentLibPath() const { return GCCParentLibPath; }
Chandler Carruth19347ed2011-11-06 23:39:34 +0000101
102 /// \brief Get the detected GCC version string.
Rafael Espindola8af669f2012-06-19 01:26:10 +0000103 const GCCVersion &getVersion() const { return Version; }
Chandler Carruth19347ed2011-11-06 23:39:34 +0000104
105 private:
Chandler Carruthd79486a2013-06-22 11:35:51 +0000106 static void
107 CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
108 const llvm::Triple &BiarchTriple,
109 SmallVectorImpl<StringRef> &LibDirs,
110 SmallVectorImpl<StringRef> &TripleAliases,
111 SmallVectorImpl<StringRef> &BiarchLibDirs,
112 SmallVectorImpl<StringRef> &BiarchTripleAliases);
Chandler Carruth19347ed2011-11-06 23:39:34 +0000113
Chandler Carruth1c6f04a2012-01-25 07:21:38 +0000114 void ScanLibDirForGCCTriple(llvm::Triple::ArchType TargetArch,
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000115 const llvm::opt::ArgList &Args,
Chandler Carruthd936d9d2011-11-09 03:46:20 +0000116 const std::string &LibDir,
Chandler Carruth1c6f04a2012-01-25 07:21:38 +0000117 StringRef CandidateTriple,
Chandler Carruthd79486a2013-06-22 11:35:51 +0000118 bool NeedsBiarchSuffix = false);
Chandler Carruth19347ed2011-11-06 23:39:34 +0000119 };
120
121 GCCInstallationDetector GCCInstallation;
122
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000123public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000124 Generic_GCC(const Driver &D, const llvm::Triple &Triple,
125 const llvm::opt::ArgList &Args);
Daniel Dunbar39176082009-03-20 00:20:03 +0000126 ~Generic_GCC();
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000127
Daniel Dunbar39176082009-03-20 00:20:03 +0000128 virtual bool IsUnwindTablesDefault() const;
Chandler Carruth7ce816a2012-11-19 03:52:03 +0000129 virtual bool isPICDefault() const;
Peter Collingbourne52ca70d2013-04-09 04:35:11 +0000130 virtual bool isPIEDefault() const;
Chandler Carruth7ce816a2012-11-19 03:52:03 +0000131 virtual bool isPICDefaultForced() const;
Chandler Carruthb37fe612011-11-06 23:39:37 +0000132
133protected:
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000134 virtual Tool *getTool(Action::ActionClass AC) const;
135 virtual Tool *buildAssembler() const;
136 virtual Tool *buildLinker() const;
137
Chandler Carruthb37fe612011-11-06 23:39:37 +0000138 /// \name ToolChain Implementation Helper Functions
139 /// @{
140
141 /// \brief Check whether the target triple's architecture is 64-bits.
Chandler Carruthd747efa2012-02-11 03:31:12 +0000142 bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
143
Chandler Carruthb37fe612011-11-06 23:39:37 +0000144 /// \brief Check whether the target triple's architecture is 32-bits.
Chandler Carruthd747efa2012-02-11 03:31:12 +0000145 bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
Chandler Carruthb37fe612011-11-06 23:39:37 +0000146
147 /// @}
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000148
149private:
150 mutable OwningPtr<tools::gcc::Preprocess> Preprocess;
151 mutable OwningPtr<tools::gcc::Precompile> Precompile;
152 mutable OwningPtr<tools::gcc::Compile> Compile;
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000153};
154
Tony Linthicum96319392011-12-12 21:14:55 +0000155 /// Darwin - The base Darwin tool chain.
Duncan Sands92dd1912010-05-11 20:16:05 +0000156class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000157public:
158 /// The host version.
159 unsigned DarwinVersion[3];
160
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000161protected:
162 virtual Tool *buildAssembler() const;
163 virtual Tool *buildLinker() const;
164 virtual Tool *getTool(Action::ActionClass AC) const;
165
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000166private:
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000167 mutable OwningPtr<tools::darwin::Lipo> Lipo;
168 mutable OwningPtr<tools::darwin::Dsymutil> Dsymutil;
169 mutable OwningPtr<tools::darwin::VerifyDebug> VerifyDebug;
170
Daniel Dunbar26031372010-01-27 00:56:25 +0000171 /// Whether the information on the target has been initialized.
172 //
173 // FIXME: This should be eliminated. What we want to do is make this part of
174 // the "default target for arguments" selection process, once we get out of
175 // the argument translation business.
176 mutable bool TargetInitialized;
177
Chris Lattnerfc8f0e12011-04-15 05:22:18 +0000178 /// Whether we are targeting iPhoneOS target.
Daniel Dunbar26031372010-01-27 00:56:25 +0000179 mutable bool TargetIsIPhoneOS;
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000180
Daniel Dunbar5f5c37b2011-04-30 04:18:16 +0000181 /// Whether we are targeting the iPhoneOS simulator target.
182 mutable bool TargetIsIPhoneOSSimulator;
183
Chris Lattnerfc8f0e12011-04-15 05:22:18 +0000184 /// The OS version we are targeting.
Benjamin Kramer09c9a562012-03-10 20:55:36 +0000185 mutable VersionTuple TargetVersion;
Daniel Dunbar26031372010-01-27 00:56:25 +0000186
John McCall260611a2012-06-20 06:18:46 +0000187private:
Daniel Dunbar02633b52009-03-26 16:23:12 +0000188 /// The default macosx-version-min of this tool chain; empty until
189 /// initialized.
Daniel Dunbar816bc312010-01-26 01:45:19 +0000190 std::string MacosxVersionMin;
Daniel Dunbar02633b52009-03-26 16:23:12 +0000191
Chad Rosier4ec26782012-05-09 18:37:26 +0000192 /// The default ios-version-min of this tool chain; empty until
193 /// initialized.
194 std::string iOSVersionMin;
195
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000196private:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000197 void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000198
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000199public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000200 Darwin(const Driver &D, const llvm::Triple &Triple,
201 const llvm::opt::ArgList &Args);
Daniel Dunbarf3955282009-09-04 18:34:51 +0000202 ~Darwin();
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000203
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000204 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
Chad Rosier61ab80a2011-09-20 20:44:06 +0000205 types::ID InputType) const;
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000206
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000207 /// @name Darwin Specific Toolchain API
208 /// {
209
Daniel Dunbar26031372010-01-27 00:56:25 +0000210 // FIXME: Eliminate these ...Target functions and derive separate tool chains
211 // for these targets and put version in constructor.
Daniel Dunbar5f5c37b2011-04-30 04:18:16 +0000212 void setTarget(bool IsIPhoneOS, unsigned Major, unsigned Minor,
213 unsigned Micro, bool IsIOSSim) const {
214 assert((!IsIOSSim || IsIPhoneOS) && "Unexpected deployment target!");
215
Daniel Dunbar26031372010-01-27 00:56:25 +0000216 // FIXME: For now, allow reinitialization as long as values don't
217 // change. This will go away when we move away from argument translation.
Daniel Dunbar5f5c37b2011-04-30 04:18:16 +0000218 if (TargetInitialized && TargetIsIPhoneOS == IsIPhoneOS &&
219 TargetIsIPhoneOSSimulator == IsIOSSim &&
Benjamin Kramer09c9a562012-03-10 20:55:36 +0000220 TargetVersion == VersionTuple(Major, Minor, Micro))
Daniel Dunbar26031372010-01-27 00:56:25 +0000221 return;
222
223 assert(!TargetInitialized && "Target already initialized!");
224 TargetInitialized = true;
Daniel Dunbar5f5c37b2011-04-30 04:18:16 +0000225 TargetIsIPhoneOS = IsIPhoneOS;
226 TargetIsIPhoneOSSimulator = IsIOSSim;
Benjamin Kramer09c9a562012-03-10 20:55:36 +0000227 TargetVersion = VersionTuple(Major, Minor, Micro);
Daniel Dunbar26031372010-01-27 00:56:25 +0000228 }
229
230 bool isTargetIPhoneOS() const {
231 assert(TargetInitialized && "Target not initialized!");
232 return TargetIsIPhoneOS;
233 }
234
Daniel Dunbar40355802011-03-31 17:12:33 +0000235 bool isTargetIOSSimulator() const {
Daniel Dunbar5f5c37b2011-04-30 04:18:16 +0000236 assert(TargetInitialized && "Target not initialized!");
237 return TargetIsIPhoneOSSimulator;
Daniel Dunbar40355802011-03-31 17:12:33 +0000238 }
239
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000240 bool isTargetMacOS() const {
Bob Wilson377e5c12012-11-09 01:59:30 +0000241 return !isTargetIOSSimulator() && !isTargetIPhoneOS();
Ted Kremenekebcb57a2012-03-06 20:05:56 +0000242 }
243
Daniel Dunbar03d87ee2010-03-20 00:50:21 +0000244 bool isTargetInitialized() const { return TargetInitialized; }
245
Benjamin Kramer09c9a562012-03-10 20:55:36 +0000246 VersionTuple getTargetVersion() const {
Daniel Dunbar26031372010-01-27 00:56:25 +0000247 assert(TargetInitialized && "Target not initialized!");
Benjamin Kramer09c9a562012-03-10 20:55:36 +0000248 return TargetVersion;
Daniel Dunbar26031372010-01-27 00:56:25 +0000249 }
250
Daniel Dunbareeff4062010-01-22 02:04:58 +0000251 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
252 /// invocation. For example, Darwin treats different ARM variations as
253 /// distinct architectures.
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000254 StringRef getDarwinArchName(const llvm::opt::ArgList &Args) const;
Daniel Dunbareeff4062010-01-22 02:04:58 +0000255
Daniel Dunbarcacb0f02010-01-27 00:56:56 +0000256 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
257 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
Benjamin Kramer09c9a562012-03-10 20:55:36 +0000258 return TargetVersion < VersionTuple(V0, V1, V2);
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000259 }
260
261 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
262 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
Benjamin Kramer09c9a562012-03-10 20:55:36 +0000263 return TargetVersion < VersionTuple(V0, V1, V2);
Daniel Dunbarcacb0f02010-01-27 00:56:56 +0000264 }
265
John McCallf85e1932011-06-15 23:02:42 +0000266 /// AddLinkARCArgs - Add the linker arguments to link the ARC runtime library.
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000267 virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
268 llvm::opt::ArgStringList &CmdArgs) const = 0;
269
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000270 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
271 /// runtime library.
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000272 virtual void
273 AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
274 llvm::opt::ArgStringList &CmdArgs) const = 0;
275
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000276 /// }
277 /// @name ToolChain Implementation
278 /// {
279
Daniel Dunbar41800112010-08-02 05:43:56 +0000280 virtual types::ID LookupTypeForExtension(const char *Ext) const;
281
Daniel Dunbarb993f5d2010-09-17 00:24:52 +0000282 virtual bool HasNativeLLVMSupport() const;
283
John McCall260611a2012-06-20 06:18:46 +0000284 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
John McCall13db5cf2011-09-09 20:41:01 +0000285 virtual bool hasBlocksRuntime() const;
John McCallf85e1932011-06-15 23:02:42 +0000286
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000287 virtual llvm::opt::DerivedArgList *
288 TranslateArgs(const llvm::opt::DerivedArgList &Args,
289 const char *BoundArch) const;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000290
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000291 virtual bool IsBlocksDefault() const {
Daniel Dunbaref44a5d2010-07-22 00:40:31 +0000292 // Always allow blocks on Darwin; users interested in versioning are
293 // expected to use /usr/include/Blocks.h.
294 return true;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000295 }
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000296 virtual bool IsIntegratedAssemblerDefault() const {
Daniel Dunbar71a6cbc2010-06-23 18:15:13 +0000297#ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
298 return false;
299#else
Jim Grosbach033d3002012-02-27 23:55:25 +0000300 // Default integrated assembler to on for Darwin.
301 return true;
Daniel Dunbar71a6cbc2010-06-23 18:15:13 +0000302#endif
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000303 }
Daniel Dunbar398c6102011-02-04 02:20:39 +0000304 virtual bool IsStrictAliasingDefault() const {
305#ifdef DISABLE_DEFAULT_STRICT_ALIASING
306 return false;
307#else
308 return ToolChain::IsStrictAliasingDefault();
309#endif
310 }
Benjamin Kramer769aa2d2012-05-02 14:55:48 +0000311
312 virtual bool IsMathErrnoDefault() const {
313 return false;
314 }
315
Fariborz Jahanian3d145f62012-11-15 19:02:45 +0000316 virtual bool IsEncodeExtendedBlockSignatureDefault() const {
317 return true;
318 }
319
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000320 virtual bool IsObjCNonFragileABIDefault() const {
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000321 // Non-fragile ABI is default for everything but i386.
322 return getTriple().getArch() != llvm::Triple::x86;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000323 }
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000324
Daniel Dunbarf643b9b2010-04-24 17:56:46 +0000325 virtual bool UseObjCMixedDispatch() const {
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000326 // This is only used with the non-fragile ABI and non-legacy dispatch.
327
328 // Mixed dispatch is used everywhere except OS X before 10.6.
329 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
Daniel Dunbarf643b9b2010-04-24 17:56:46 +0000330 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000331 virtual bool IsUnwindTablesDefault() const;
Nico Weber2fef1112011-08-23 07:38:27 +0000332 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
333 // Stack protectors default to on for user code on 10.5,
334 // and for everything in 10.6 and beyond
Bob Wilsondfba0272011-12-14 06:08:25 +0000335 return isTargetIPhoneOS() ||
Nico Weber2fef1112011-08-23 07:38:27 +0000336 (!isMacosxVersionLT(10, 6) ||
337 (!isMacosxVersionLT(10, 5) && !KernelOrKext));
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000338 }
Daniel Dunbarc24767c2011-12-07 23:03:15 +0000339 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
340 return ToolChain::RLT_CompilerRT;
341 }
Chandler Carruth7ce816a2012-11-19 03:52:03 +0000342 virtual bool isPICDefault() const;
Peter Collingbourne52ca70d2013-04-09 04:35:11 +0000343 virtual bool isPIEDefault() const;
Chandler Carruth7ce816a2012-11-19 03:52:03 +0000344 virtual bool isPICDefaultForced() const;
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000345
Daniel Dunbarbbe8e3e2011-03-01 18:49:30 +0000346 virtual bool SupportsProfiling() const;
347
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000348 virtual bool SupportsObjCGC() const;
349
John McCall0a7dd782012-08-21 02:47:43 +0000350 virtual void CheckObjCARC() const;
Argyrios Kyrtzidis5840dd92012-02-29 03:43:52 +0000351
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000352 virtual bool UseDwarfDebugFlags() const;
353
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000354 virtual bool UseSjLjExceptions() const;
355
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000356 /// }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000357};
358
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000359/// DarwinClang - The Darwin toolchain used by Clang.
Duncan Sands92dd1912010-05-11 20:16:05 +0000360class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000361public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000362 DarwinClang(const Driver &D, const llvm::Triple &Triple,
363 const llvm::opt::ArgList &Args);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000364
365 /// @name Darwin ToolChain Implementation
366 /// {
367
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000368 virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
369 llvm::opt::ArgStringList &CmdArgs) const;
370 void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
371 llvm::opt::ArgStringList &CmdArgs,
Alexey Samsonov69b77d72012-11-21 14:17:42 +0000372 const char *DarwinStaticLib,
373 bool AlwaysLink = false) const;
374
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000375 virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
376 llvm::opt::ArgStringList &CmdArgs) const;
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000377
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000378 virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
379 llvm::opt::ArgStringList &CmdArgs) const;
Shantonu Sen7433fed2010-09-17 18:39:08 +0000380
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000381 virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
382 llvm::opt::ArgStringList &CmdArgs) const;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000383 /// }
384};
385
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000386/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
Duncan Sands92dd1912010-05-11 20:16:05 +0000387class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000388public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000389 Darwin_Generic_GCC(const Driver &D, const llvm::Triple &Triple,
390 const llvm::opt::ArgList &Args)
391 : Generic_GCC(D, Triple, Args) {}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000392
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000393 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
Chad Rosier61ab80a2011-09-20 20:44:06 +0000394 types::ID InputType) const;
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000395
Chad Rosierf8fc6272012-11-27 17:31:26 +0000396 virtual bool isPICDefault() const { return false; }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000397};
398
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000399class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
David Blaikie99ba9e32011-12-20 02:48:34 +0000400 virtual void anchor();
401public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000402 Generic_ELF(const Driver &D, const llvm::Triple &Triple,
403 const llvm::opt::ArgList &Args)
404 : Generic_GCC(D, Triple, Args) {}
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000405
406 virtual bool IsIntegratedAssemblerDefault() const {
407 // Default integrated assembler to on for x86.
Tim Northoverc264e162013-01-31 12:13:10 +0000408 return (getTriple().getArch() == llvm::Triple::aarch64 ||
409 getTriple().getArch() == llvm::Triple::x86 ||
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000410 getTriple().getArch() == llvm::Triple::x86_64);
411 }
412};
413
Duncan Sands92dd1912010-05-11 20:16:05 +0000414class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000415public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000416 AuroraUX(const Driver &D, const llvm::Triple &Triple,
417 const llvm::opt::ArgList &Args);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000418
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000419protected:
420 virtual Tool *buildAssembler() const;
421 virtual Tool *buildLinker() const;
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000422};
423
David Chisnall31c46902012-02-15 13:39:01 +0000424class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
425public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000426 Solaris(const Driver &D, const llvm::Triple &Triple,
427 const llvm::opt::ArgList &Args);
David Chisnall31c46902012-02-15 13:39:01 +0000428
David Chisnall31c46902012-02-15 13:39:01 +0000429 virtual bool IsIntegratedAssemblerDefault() const { return true; }
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000430protected:
431 virtual Tool *buildAssembler() const;
432 virtual Tool *buildLinker() const;
433
David Chisnall31c46902012-02-15 13:39:01 +0000434};
435
436
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000437class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000438public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000439 OpenBSD(const Driver &D, const llvm::Triple &Triple,
440 const llvm::opt::ArgList &Args);
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000441
Benjamin Kramer769aa2d2012-05-02 14:55:48 +0000442 virtual bool IsMathErrnoDefault() const { return false; }
David Chisnallc3cb0722012-04-09 12:33:41 +0000443 virtual bool IsObjCNonFragileABIDefault() const { return true; }
Rafael Espindola9adba392013-06-05 04:28:55 +0000444 virtual bool isPIEDefault() const { return true; }
445
446 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
447 return 1;
448 }
David Chisnallc3cb0722012-04-09 12:33:41 +0000449
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000450protected:
451 virtual Tool *buildAssembler() const;
452 virtual Tool *buildLinker() const;
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000453};
454
Eli Friedman42f74f22012-08-08 23:57:20 +0000455class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
456public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000457 Bitrig(const Driver &D, const llvm::Triple &Triple,
458 const llvm::opt::ArgList &Args);
Eli Friedman42f74f22012-08-08 23:57:20 +0000459
460 virtual bool IsMathErrnoDefault() const { return false; }
461 virtual bool IsObjCNonFragileABIDefault() const { return true; }
462 virtual bool IsObjCLegacyDispatchDefault() const { return false; }
463
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000464 virtual void
465 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
466 llvm::opt::ArgStringList &CC1Args) const;
467 virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
468 llvm::opt::ArgStringList &CmdArgs) const;
Eli Friedman42f74f22012-08-08 23:57:20 +0000469 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
470 return 1;
471 }
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000472
473protected:
474 virtual Tool *buildAssembler() const;
475 virtual Tool *buildLinker() const;
Eli Friedman42f74f22012-08-08 23:57:20 +0000476};
477
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000478class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000479public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000480 FreeBSD(const Driver &D, const llvm::Triple &Triple,
481 const llvm::opt::ArgList &Args);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000482
Benjamin Kramer769aa2d2012-05-02 14:55:48 +0000483 virtual bool IsMathErrnoDefault() const { return false; }
David Chisnallc3cb0722012-04-09 12:33:41 +0000484 virtual bool IsObjCNonFragileABIDefault() const { return true; }
David Chisnallc3cb0722012-04-09 12:33:41 +0000485
Rafael Espindola27fa2362012-12-13 04:17:14 +0000486 virtual bool UseSjLjExceptions() const;
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000487protected:
488 virtual Tool *buildAssembler() const;
489 virtual Tool *buildLinker() const;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000490};
491
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000492class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
493public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000494 NetBSD(const Driver &D, const llvm::Triple &Triple,
495 const llvm::opt::ArgList &Args);
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000496
Benjamin Kramer769aa2d2012-05-02 14:55:48 +0000497 virtual bool IsMathErrnoDefault() const { return false; }
David Chisnallc3cb0722012-04-09 12:33:41 +0000498 virtual bool IsObjCNonFragileABIDefault() const { return true; }
David Chisnallc3cb0722012-04-09 12:33:41 +0000499
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000500 virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
Joerg Sonnenbergera7efaf92013-04-30 01:21:43 +0000501
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000502 virtual void
503 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
504 llvm::opt::ArgStringList &CC1Args) const;
Joerg Sonnenbergera7efaf92013-04-30 01:21:43 +0000505
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000506protected:
507 virtual Tool *buildAssembler() const;
508 virtual Tool *buildLinker() const;
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000509};
510
Eli Friedman6d402dc2011-12-08 23:54:21 +0000511class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
Chris Lattner38e317d2010-07-07 16:01:42 +0000512public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000513 Minix(const Driver &D, const llvm::Triple &Triple,
514 const llvm::opt::ArgList &Args);
Chris Lattner38e317d2010-07-07 16:01:42 +0000515
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000516protected:
517 virtual Tool *buildAssembler() const;
518 virtual Tool *buildLinker() const;
Chris Lattner38e317d2010-07-07 16:01:42 +0000519};
520
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000521class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000522public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000523 DragonFly(const Driver &D, const llvm::Triple &Triple,
524 const llvm::opt::ArgList &Args);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000525
Benjamin Kramer769aa2d2012-05-02 14:55:48 +0000526 virtual bool IsMathErrnoDefault() const { return false; }
527
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000528protected:
529 virtual Tool *buildAssembler() const;
530 virtual Tool *buildLinker() const;
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000531};
532
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000533class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
Eli Friedman6b3454a2009-05-26 07:52:18 +0000534public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000535 Linux(const Driver &D, const llvm::Triple &Triple,
536 const llvm::opt::ArgList &Args);
Rafael Espindolaba30bbe2010-08-10 00:25:48 +0000537
Rafael Espindolac1da9812010-11-07 20:14:31 +0000538 virtual bool HasNativeLLVMSupport() const;
539
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000540 virtual void
541 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
542 llvm::opt::ArgStringList &CC1Args) const;
543 virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
544 llvm::opt::ArgStringList &CC1Args) const;
545 virtual void
546 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
547 llvm::opt::ArgStringList &CC1Args) const;
Peter Collingbourne52ca70d2013-04-09 04:35:11 +0000548 virtual bool isPIEDefault() const;
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000549
Rafael Espindolac1da9812010-11-07 20:14:31 +0000550 std::string Linker;
551 std::vector<std::string> ExtraOpts;
Peter Collingbourne52ca70d2013-04-09 04:35:11 +0000552 bool IsPIEDefault;
Chandler Carruth79cbbdc2011-12-17 23:10:01 +0000553
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000554protected:
555 virtual Tool *buildAssembler() const;
556 virtual Tool *buildLinker() const;
557
Chandler Carruth79cbbdc2011-12-17 23:10:01 +0000558private:
Dmitri Gribenkof2e7c352013-03-06 17:14:05 +0000559 static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
560 Twine TargetArchDir,
561 Twine MultiLibSuffix,
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000562 const llvm::opt::ArgList &DriverArgs,
563 llvm::opt::ArgStringList &CC1Args);
Chandler Carruth79cbbdc2011-12-17 23:10:01 +0000564 static bool addLibStdCXXIncludePaths(Twine Base, Twine TargetArchDir,
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000565 const llvm::opt::ArgList &DriverArgs,
566 llvm::opt::ArgStringList &CC1Args);
Simon Atanasyan8e8e95c2013-04-20 08:15:03 +0000567
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000568 std::string computeSysRoot(const llvm::opt::ArgList &Args) const;
Eli Friedman6b3454a2009-05-26 07:52:18 +0000569};
570
Matthew Curtisb3489a02012-12-06 12:43:18 +0000571class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
572protected:
Matthew Curtisb3489a02012-12-06 12:43:18 +0000573 GCCVersion GCCLibAndIncVersion;
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000574 virtual Tool *buildAssembler() const;
575 virtual Tool *buildLinker() const;
Matthew Curtisb3489a02012-12-06 12:43:18 +0000576
577public:
578 Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000579 const llvm::opt::ArgList &Args);
Matthew Curtisb3489a02012-12-06 12:43:18 +0000580 ~Hexagon_TC();
581
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000582 virtual void
583 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
584 llvm::opt::ArgStringList &CC1Args) const;
585 virtual void
586 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
587 llvm::opt::ArgStringList &CC1Args) const;
588 virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
Matthew Curtisb3489a02012-12-06 12:43:18 +0000589
590 StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
591
592 static std::string GetGnuDir(const std::string &InstalledDir);
Matthew Curtis67814152012-12-06 14:16:43 +0000593
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000594 static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
Matthew Curtisb3489a02012-12-06 12:43:18 +0000595};
Eli Friedman6b3454a2009-05-26 07:52:18 +0000596
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000597/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
598/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
Duncan Sands92dd1912010-05-11 20:16:05 +0000599class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000600public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000601 TCEToolChain(const Driver &D, const llvm::Triple &Triple,
602 const llvm::opt::ArgList &Args);
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000603 ~TCEToolChain();
604
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000605 bool IsMathErrnoDefault() const;
Chandler Carruth7ce816a2012-11-19 03:52:03 +0000606 bool isPICDefault() const;
Peter Collingbourne52ca70d2013-04-09 04:35:11 +0000607 bool isPIEDefault() const;
Chandler Carruth7ce816a2012-11-19 03:52:03 +0000608 bool isPICDefaultForced() const;
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000609};
610
Michael J. Spencerff58e362010-08-21 21:55:07 +0000611class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain {
Michael J. Spencerff58e362010-08-21 21:55:07 +0000612public:
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000613 Windows(const Driver &D, const llvm::Triple &Triple,
614 const llvm::opt::ArgList &Args);
Michael J. Spencerff58e362010-08-21 21:55:07 +0000615
Michael J. Spencerff58e362010-08-21 21:55:07 +0000616 virtual bool IsIntegratedAssemblerDefault() const;
617 virtual bool IsUnwindTablesDefault() const;
Chandler Carruth7ce816a2012-11-19 03:52:03 +0000618 virtual bool isPICDefault() const;
Peter Collingbourne52ca70d2013-04-09 04:35:11 +0000619 virtual bool isPIEDefault() const;
Chandler Carruth7ce816a2012-11-19 03:52:03 +0000620 virtual bool isPICDefaultForced() const;
Chandler Carruthca234192011-11-04 23:49:05 +0000621
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000622 virtual void
623 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
624 llvm::opt::ArgStringList &CC1Args) const;
625 virtual void
626 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
627 llvm::opt::ArgStringList &CC1Args) const;
628
Rafael Espindolaf48b93c2013-03-20 03:05:54 +0000629protected:
630 virtual Tool *buildLinker() const;
631 virtual Tool *buildAssembler() const;
Michael J. Spencerff58e362010-08-21 21:55:07 +0000632};
633
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000634} // end namespace toolchains
635} // end namespace driver
636} // end namespace clang
637
638#endif