blob: e2d72e61dc4b5e39c8affb41781907b4c9e43d7b [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
Daniel Dunbar670b7f42009-03-17 22:07:31 +000013#include "clang/Driver/Action.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000014#include "clang/Driver/ToolChain.h"
15
Daniel Dunbar670b7f42009-03-17 22:07:31 +000016#include "llvm/ADT/DenseMap.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000017#include "llvm/Support/Compiler.h"
18
Daniel Dunbar670b7f42009-03-17 22:07:31 +000019#include "Tools.h"
20
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000021namespace clang {
22namespace driver {
Daniel Dunbar985b8252009-03-17 22:18:43 +000023namespace toolchains {
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000024
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000025/// Generic_GCC - A tool chain using the 'gcc' command to perform
26/// all subcommands; this relies on gcc translating the majority of
27/// command line options.
Duncan Sands92dd1912010-05-11 20:16:05 +000028class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
Daniel Dunbar75358d22009-03-30 21:06:03 +000029protected:
Daniel Dunbar670b7f42009-03-17 22:07:31 +000030 mutable llvm::DenseMap<unsigned, Tool*> Tools;
31
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000032public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000033 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar39176082009-03-20 00:20:03 +000034 ~Generic_GCC();
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000035
Daniel Dunbar39176082009-03-20 00:20:03 +000036 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000037
Daniel Dunbar39176082009-03-20 00:20:03 +000038 virtual bool IsUnwindTablesDefault() const;
39 virtual const char *GetDefaultRelocationModel() const;
40 virtual const char *GetForcedPicModel() const;
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000041};
42
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000043/// Darwin - The base Darwin tool chain.
Duncan Sands92dd1912010-05-11 20:16:05 +000044class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000045public:
46 /// The host version.
47 unsigned DarwinVersion[3];
48
49private:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000050 mutable llvm::DenseMap<unsigned, Tool*> Tools;
51
Daniel Dunbar26031372010-01-27 00:56:25 +000052 /// Whether the information on the target has been initialized.
53 //
54 // FIXME: This should be eliminated. What we want to do is make this part of
55 // the "default target for arguments" selection process, once we get out of
56 // the argument translation business.
57 mutable bool TargetInitialized;
58
59 /// Whether we are targetting iPhoneOS target.
60 mutable bool TargetIsIPhoneOS;
Daniel Dunbareb840bd2010-05-14 02:03:00 +000061
Daniel Dunbar26031372010-01-27 00:56:25 +000062 /// The OS version we are targetting.
63 mutable unsigned TargetVersion[3];
64
Daniel Dunbar02633b52009-03-26 16:23:12 +000065 /// The default macosx-version-min of this tool chain; empty until
66 /// initialized.
Daniel Dunbar816bc312010-01-26 01:45:19 +000067 std::string MacosxVersionMin;
Daniel Dunbar02633b52009-03-26 16:23:12 +000068
Daniel Dunbarc0e665e2010-07-19 17:11:33 +000069private:
Daniel Dunbar60baf0f2010-07-19 17:11:36 +000070 void AddDeploymentTarget(DerivedArgList &Args) const;
Daniel Dunbarc0e665e2010-07-19 17:11:33 +000071
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000072public:
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000073 Darwin(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarf3955282009-09-04 18:34:51 +000074 ~Darwin();
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000075
Daniel Dunbar6b200b22009-09-18 08:14:36 +000076 /// @name Darwin Specific Toolchain API
77 /// {
78
Daniel Dunbar26031372010-01-27 00:56:25 +000079 // FIXME: Eliminate these ...Target functions and derive separate tool chains
80 // for these targets and put version in constructor.
81 void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor,
82 unsigned Micro) const {
83 // FIXME: For now, allow reinitialization as long as values don't
84 // change. This will go away when we move away from argument translation.
85 if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS &&
86 TargetVersion[0] == Major && TargetVersion[1] == Minor &&
87 TargetVersion[2] == Micro)
88 return;
89
90 assert(!TargetInitialized && "Target already initialized!");
91 TargetInitialized = true;
92 TargetIsIPhoneOS = isIPhoneOS;
93 TargetVersion[0] = Major;
94 TargetVersion[1] = Minor;
95 TargetVersion[2] = Micro;
96 }
97
98 bool isTargetIPhoneOS() const {
99 assert(TargetInitialized && "Target not initialized!");
100 return TargetIsIPhoneOS;
101 }
102
Daniel Dunbar03d87ee2010-03-20 00:50:21 +0000103 bool isTargetInitialized() const { return TargetInitialized; }
104
Daniel Dunbar26031372010-01-27 00:56:25 +0000105 void getTargetVersion(unsigned (&Res)[3]) const {
106 assert(TargetInitialized && "Target not initialized!");
107 Res[0] = TargetVersion[0];
108 Res[1] = TargetVersion[1];
109 Res[2] = TargetVersion[2];
110 }
111
Daniel Dunbareeff4062010-01-22 02:04:58 +0000112 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
113 /// invocation. For example, Darwin treats different ARM variations as
114 /// distinct architectures.
115 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
116
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000117 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
Daniel Dunbar608d04c2009-09-18 08:14:55 +0000118 for (unsigned i=0; i < 3; ++i) {
119 if (A[i] > B[i]) return false;
120 if (A[i] < B[i]) return true;
121 }
122 return false;
123 }
124
Daniel Dunbarcacb0f02010-01-27 00:56:56 +0000125 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
126 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
127 unsigned B[3] = { V0, V1, V2 };
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000128 return isVersionLT(TargetVersion, B);
129 }
130
131 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
132 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
133 unsigned B[3] = { V0, V1, V2 };
134 return isVersionLT(TargetVersion, B);
Daniel Dunbarcacb0f02010-01-27 00:56:56 +0000135 }
136
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000137 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
138 ///
139 /// \param Args - The input argument list.
140 /// \param CmdArgs [out] - The command argument list to append the paths
141 /// (prefixed by -L) to.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000142 virtual void AddLinkSearchPathArgs(const ArgList &Args,
143 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar02633b52009-03-26 16:23:12 +0000144
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000145 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
146 /// runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000147 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
148 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000149
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000150 /// }
151 /// @name ToolChain Implementation
152 /// {
153
Daniel Dunbar41800112010-08-02 05:43:56 +0000154 virtual types::ID LookupTypeForExtension(const char *Ext) const;
155
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000156 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000157 const char *BoundArch) const;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000158
159 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
160
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000161 virtual bool IsBlocksDefault() const {
Daniel Dunbaref44a5d2010-07-22 00:40:31 +0000162 // Always allow blocks on Darwin; users interested in versioning are
163 // expected to use /usr/include/Blocks.h.
164 return true;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000165 }
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000166 virtual bool IsIntegratedAssemblerDefault() const {
Daniel Dunbar71a6cbc2010-06-23 18:15:13 +0000167#ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
168 return false;
169#else
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000170 // Default integrated assembler to on for x86.
171 return (getTriple().getArch() == llvm::Triple::x86 ||
172 getTriple().getArch() == llvm::Triple::x86_64);
Daniel Dunbar71a6cbc2010-06-23 18:15:13 +0000173#endif
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000174 }
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000175 virtual bool IsObjCNonFragileABIDefault() const {
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000176 // Non-fragile ABI is default for everything but i386.
177 return getTriple().getArch() != llvm::Triple::x86;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000178 }
Daniel Dunbar609508c2010-02-01 21:07:43 +0000179 virtual bool IsObjCLegacyDispatchDefault() const {
180 // This is only used with the non-fragile ABI.
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000181
182 // Legacy dispatch is used everywhere except on x86_64.
183 return getTriple().getArch() != llvm::Triple::x86_64;
Daniel Dunbar609508c2010-02-01 21:07:43 +0000184 }
Daniel Dunbarf643b9b2010-04-24 17:56:46 +0000185 virtual bool UseObjCMixedDispatch() const {
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000186 // This is only used with the non-fragile ABI and non-legacy dispatch.
187
188 // Mixed dispatch is used everywhere except OS X before 10.6.
189 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
Daniel Dunbarf643b9b2010-04-24 17:56:46 +0000190 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000191 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000192 virtual unsigned GetDefaultStackProtectorLevel() const {
Daniel Dunbar5435fc92010-01-27 00:57:11 +0000193 // Stack protectors default to on for 10.6 and beyond.
194 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000195 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000196 virtual const char *GetDefaultRelocationModel() const;
197 virtual const char *GetForcedPicModel() const;
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000198
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000199 virtual bool SupportsObjCGC() const;
200
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000201 virtual bool UseDwarfDebugFlags() const;
202
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000203 virtual bool UseSjLjExceptions() const;
204
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000205 /// }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000206};
207
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000208/// DarwinClang - The Darwin toolchain used by Clang.
Duncan Sands92dd1912010-05-11 20:16:05 +0000209class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000210public:
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000211 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000212
213 /// @name Darwin ToolChain Implementation
214 /// {
215
216 virtual void AddLinkSearchPathArgs(const ArgList &Args,
217 ArgStringList &CmdArgs) const;
218
219 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
220 ArgStringList &CmdArgs) const;
221
222 /// }
223};
224
225/// DarwinGCC - The Darwin toolchain used by GCC.
Duncan Sands92dd1912010-05-11 20:16:05 +0000226class LLVM_LIBRARY_VISIBILITY DarwinGCC : public Darwin {
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000227 /// GCC version to use.
Ted Kremenek55bac532009-10-07 03:21:11 +0000228 unsigned GCCVersion[3];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000229
230 /// The directory suffix for this tool chain.
231 std::string ToolChainDir;
232
233public:
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000234 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000235
236 /// @name Darwin ToolChain Implementation
237 /// {
238
239 virtual void AddLinkSearchPathArgs(const ArgList &Args,
240 ArgStringList &CmdArgs) const;
241
242 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
243 ArgStringList &CmdArgs) const;
244
245 /// }
246};
247
248/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
Duncan Sands92dd1912010-05-11 20:16:05 +0000249class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000250public:
251 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000252 : Generic_GCC(Host, Triple) {}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000253
254 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
255};
256
Duncan Sands92dd1912010-05-11 20:16:05 +0000257class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000258public:
259 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
260
261 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
262};
263
Duncan Sands92dd1912010-05-11 20:16:05 +0000264class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_GCC {
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000265public:
266 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
267
268 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
269};
270
Duncan Sands92dd1912010-05-11 20:16:05 +0000271class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_GCC {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000272public:
Daniel Dunbar214afe92010-08-02 05:43:59 +0000273 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000274
275 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
276};
277
Chris Lattner38e317d2010-07-07 16:01:42 +0000278class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
279public:
280 Minix(const HostInfo &Host, const llvm::Triple& Triple);
281
282 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
283};
284
Duncan Sands92dd1912010-05-11 20:16:05 +0000285class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_GCC {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000286public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000287 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000288
289 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
290};
291
Duncan Sands92dd1912010-05-11 20:16:05 +0000292class LLVM_LIBRARY_VISIBILITY Linux : public Generic_GCC {
Eli Friedman6b3454a2009-05-26 07:52:18 +0000293public:
294 Linux(const HostInfo &Host, const llvm::Triple& Triple);
Rafael Espindolaba30bbe2010-08-10 00:25:48 +0000295
296 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Eli Friedman6b3454a2009-05-26 07:52:18 +0000297};
298
299
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000300/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
301/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
Duncan Sands92dd1912010-05-11 20:16:05 +0000302class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000303public:
304 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
305 ~TCEToolChain();
306
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000307 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
308 bool IsMathErrnoDefault() const;
309 bool IsUnwindTablesDefault() const;
310 const char* GetDefaultRelocationModel() const;
311 const char* GetForcedPicModel() const;
312
313private:
314 mutable llvm::DenseMap<unsigned, Tool*> Tools;
315
316};
317
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000318} // end namespace toolchains
319} // end namespace driver
320} // end namespace clang
321
322#endif