blob: 005597dccc28d6da8b84e7d44fd628f62d698964 [file] [log] [blame]
Daniel Dunbar0a248bb2009-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 Dunbar04cb0292009-03-17 22:07:31 +000013#include "clang/Driver/Action.h"
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000014#include "clang/Driver/ToolChain.h"
15
Daniel Dunbar04cb0292009-03-17 22:07:31 +000016#include "llvm/ADT/DenseMap.h"
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000017#include "llvm/Support/Compiler.h"
18
Daniel Dunbar04cb0292009-03-17 22:07:31 +000019#include "Tools.h"
20
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000021namespace clang {
22namespace driver {
Daniel Dunbar15abb2e2009-03-17 22:18:43 +000023namespace toolchains {
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000024
Daniel Dunbar6276f992009-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 Sandsaf260b92010-05-11 20:16:05 +000028class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
Daniel Dunbare24297c2009-03-30 21:06:03 +000029protected:
Daniel Dunbar04cb0292009-03-17 22:07:31 +000030 mutable llvm::DenseMap<unsigned, Tool*> Tools;
31
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000032public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +000033 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar59e5e882009-03-20 00:20:03 +000034 ~Generic_GCC();
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000035
Daniel Dunbar59e5e882009-03-20 00:20:03 +000036 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar04cb0292009-03-17 22:07:31 +000037
Daniel Dunbar59e5e882009-03-20 00:20:03 +000038 virtual bool IsUnwindTablesDefault() const;
39 virtual const char *GetDefaultRelocationModel() const;
40 virtual const char *GetForcedPicModel() const;
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000041};
42
Daniel Dunbar6276f992009-09-18 08:15:13 +000043/// Darwin - The base Darwin tool chain.
Duncan Sandsaf260b92010-05-11 20:16:05 +000044class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
Daniel Dunbar71c723d2010-08-02 05:44:07 +000045public:
46 /// The host version.
47 unsigned DarwinVersion[3];
48
49private:
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000050 mutable llvm::DenseMap<unsigned, Tool*> Tools;
51
Daniel Dunbar3b8e50d2010-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 Dunbarf9ff3502010-05-14 02:03:00 +000061
Daniel Dunbar3b8e50d2010-01-27 00:56:25 +000062 /// The OS version we are targetting.
63 mutable unsigned TargetVersion[3];
64
Daniel Dunbarc1964212009-03-26 16:23:12 +000065 /// The default macosx-version-min of this tool chain; empty until
66 /// initialized.
Daniel Dunbard54669d2010-01-26 01:45:19 +000067 std::string MacosxVersionMin;
Daniel Dunbarc1964212009-03-26 16:23:12 +000068
Daniel Dunbarb2b8a912010-07-19 17:11:33 +000069private:
Daniel Dunbar354e96d2010-07-19 17:11:36 +000070 void AddDeploymentTarget(DerivedArgList &Args) const;
Daniel Dunbarb2b8a912010-07-19 17:11:33 +000071
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000072public:
Daniel Dunbar71c723d2010-08-02 05:44:07 +000073 Darwin(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000074 ~Darwin();
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000075
Daniel Dunbar82eb4ce2010-08-23 22:35:37 +000076 std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
77
Daniel Dunbar4c30b892009-09-18 08:14:36 +000078 /// @name Darwin Specific Toolchain API
79 /// {
80
Daniel Dunbar3b8e50d2010-01-27 00:56:25 +000081 // FIXME: Eliminate these ...Target functions and derive separate tool chains
82 // for these targets and put version in constructor.
83 void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor,
84 unsigned Micro) const {
85 // FIXME: For now, allow reinitialization as long as values don't
86 // change. This will go away when we move away from argument translation.
87 if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS &&
88 TargetVersion[0] == Major && TargetVersion[1] == Minor &&
89 TargetVersion[2] == Micro)
90 return;
91
92 assert(!TargetInitialized && "Target already initialized!");
93 TargetInitialized = true;
94 TargetIsIPhoneOS = isIPhoneOS;
95 TargetVersion[0] = Major;
96 TargetVersion[1] = Minor;
97 TargetVersion[2] = Micro;
98 }
99
100 bool isTargetIPhoneOS() const {
101 assert(TargetInitialized && "Target not initialized!");
102 return TargetIsIPhoneOS;
103 }
104
Daniel Dunbar47d25b12010-03-20 00:50:21 +0000105 bool isTargetInitialized() const { return TargetInitialized; }
106
Daniel Dunbar3b8e50d2010-01-27 00:56:25 +0000107 void getTargetVersion(unsigned (&Res)[3]) const {
108 assert(TargetInitialized && "Target not initialized!");
109 Res[0] = TargetVersion[0];
110 Res[1] = TargetVersion[1];
111 Res[2] = TargetVersion[2];
112 }
113
Daniel Dunbardcc3b652010-01-22 02:04:58 +0000114 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
115 /// invocation. For example, Darwin treats different ARM variations as
116 /// distinct architectures.
117 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
118
Daniel Dunbar6d23b2f2010-01-27 00:57:03 +0000119 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
Daniel Dunbard5bd81e2009-09-18 08:14:55 +0000120 for (unsigned i=0; i < 3; ++i) {
121 if (A[i] > B[i]) return false;
122 if (A[i] < B[i]) return true;
123 }
124 return false;
125 }
126
Daniel Dunbar83608032010-01-27 00:56:56 +0000127 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
128 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
129 unsigned B[3] = { V0, V1, V2 };
Daniel Dunbar6d23b2f2010-01-27 00:57:03 +0000130 return isVersionLT(TargetVersion, B);
131 }
132
133 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
134 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
135 unsigned B[3] = { V0, V1, V2 };
136 return isVersionLT(TargetVersion, B);
Daniel Dunbar83608032010-01-27 00:56:56 +0000137 }
138
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000139 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
140 ///
141 /// \param Args - The input argument list.
142 /// \param CmdArgs [out] - The command argument list to append the paths
143 /// (prefixed by -L) to.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000144 virtual void AddLinkSearchPathArgs(const ArgList &Args,
145 ArgStringList &CmdArgs) const = 0;
Daniel Dunbarc1964212009-03-26 16:23:12 +0000146
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000147 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
148 /// runtime library.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000149 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
150 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000151
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000152 /// }
153 /// @name ToolChain Implementation
154 /// {
155
Daniel Dunbarcc7df6c2010-08-02 05:43:56 +0000156 virtual types::ID LookupTypeForExtension(const char *Ext) const;
157
Daniel Dunbar62123a12010-09-17 00:24:52 +0000158 virtual bool HasNativeLLVMSupport() const;
159
Daniel Dunbar775d4062010-06-11 22:00:26 +0000160 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
Daniel Dunbare7af3412009-09-09 18:36:12 +0000161 const char *BoundArch) const;
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000162
163 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
164
Daniel Dunbar4930e332009-11-17 08:07:36 +0000165 virtual bool IsBlocksDefault() const {
Daniel Dunbara66a4d12010-07-22 00:40:31 +0000166 // Always allow blocks on Darwin; users interested in versioning are
167 // expected to use /usr/include/Blocks.h.
168 return true;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000169 }
Daniel Dunbarf9ff3502010-05-14 02:03:00 +0000170 virtual bool IsIntegratedAssemblerDefault() const {
Daniel Dunbara99a3c12010-06-23 18:15:13 +0000171#ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
172 return false;
173#else
Daniel Dunbarf9ff3502010-05-14 02:03:00 +0000174 // Default integrated assembler to on for x86.
175 return (getTriple().getArch() == llvm::Triple::x86 ||
176 getTriple().getArch() == llvm::Triple::x86_64);
Daniel Dunbara99a3c12010-06-23 18:15:13 +0000177#endif
Daniel Dunbarf9ff3502010-05-14 02:03:00 +0000178 }
Ted Kremenek1d56c9e2010-12-23 21:35:43 +0000179
180 virtual bool IsObjCDefaultSynthPropertiesDefault() const {
181 // Always allow default synthesized properties on Darwin.
182 return true;
183 }
184
Daniel Dunbar4930e332009-11-17 08:07:36 +0000185 virtual bool IsObjCNonFragileABIDefault() const {
Daniel Dunbardf3d1c22010-04-24 18:37:41 +0000186 // Non-fragile ABI is default for everything but i386.
187 return getTriple().getArch() != llvm::Triple::x86;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000188 }
Daniel Dunbar98188412010-02-01 21:07:43 +0000189 virtual bool IsObjCLegacyDispatchDefault() const {
190 // This is only used with the non-fragile ABI.
Daniel Dunbardf3d1c22010-04-24 18:37:41 +0000191
192 // Legacy dispatch is used everywhere except on x86_64.
193 return getTriple().getArch() != llvm::Triple::x86_64;
Daniel Dunbar98188412010-02-01 21:07:43 +0000194 }
Daniel Dunbarfca18c1b42010-04-24 17:56:46 +0000195 virtual bool UseObjCMixedDispatch() const {
Daniel Dunbardf3d1c22010-04-24 18:37:41 +0000196 // This is only used with the non-fragile ABI and non-legacy dispatch.
197
198 // Mixed dispatch is used everywhere except OS X before 10.6.
199 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
Daniel Dunbarfca18c1b42010-04-24 17:56:46 +0000200 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000201 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000202 virtual unsigned GetDefaultStackProtectorLevel() const {
Daniel Dunbarf48d51d2010-01-27 00:57:11 +0000203 // Stack protectors default to on for 10.6 and beyond.
204 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
Daniel Dunbar4930e332009-11-17 08:07:36 +0000205 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000206 virtual const char *GetDefaultRelocationModel() const;
207 virtual const char *GetForcedPicModel() const;
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000208
Daniel Dunbar16334e12010-04-10 16:20:23 +0000209 virtual bool SupportsObjCGC() const;
210
Daniel Dunbar24c7f5e2009-12-18 02:43:17 +0000211 virtual bool UseDwarfDebugFlags() const;
212
Daniel Dunbar3241d402010-02-10 18:49:11 +0000213 virtual bool UseSjLjExceptions() const;
214
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000215 /// }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000216};
217
Daniel Dunbar6276f992009-09-18 08:15:13 +0000218/// DarwinClang - The Darwin toolchain used by Clang.
Duncan Sandsaf260b92010-05-11 20:16:05 +0000219class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000220public:
Daniel Dunbar71c723d2010-08-02 05:44:07 +0000221 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar6276f992009-09-18 08:15:13 +0000222
223 /// @name Darwin ToolChain Implementation
224 /// {
225
226 virtual void AddLinkSearchPathArgs(const ArgList &Args,
227 ArgStringList &CmdArgs) const;
228
229 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
230 ArgStringList &CmdArgs) const;
231
Daniel Dunbar3f7796f2010-09-17 01:20:05 +0000232 virtual void AddCXXStdlibLibArgs(const ArgList &Args,
233 ArgStringList &CmdArgs) const;
Daniel Dunbar8fa86b12010-09-17 01:16:06 +0000234
Shantonu Senafeb03b2010-09-17 18:39:08 +0000235 virtual void AddCCKextLibArgs(const ArgList &Args,
236 ArgStringList &CmdArgs) const;
237
Daniel Dunbar6276f992009-09-18 08:15:13 +0000238 /// }
239};
240
241/// DarwinGCC - The Darwin toolchain used by GCC.
Duncan Sandsaf260b92010-05-11 20:16:05 +0000242class LLVM_LIBRARY_VISIBILITY DarwinGCC : public Darwin {
Daniel Dunbar6276f992009-09-18 08:15:13 +0000243 /// GCC version to use.
Ted Kremenek7881ac92009-10-07 03:21:11 +0000244 unsigned GCCVersion[3];
Daniel Dunbar6276f992009-09-18 08:15:13 +0000245
246 /// The directory suffix for this tool chain.
247 std::string ToolChainDir;
248
249public:
Daniel Dunbar71c723d2010-08-02 05:44:07 +0000250 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar6276f992009-09-18 08:15:13 +0000251
252 /// @name Darwin ToolChain Implementation
253 /// {
254
255 virtual void AddLinkSearchPathArgs(const ArgList &Args,
256 ArgStringList &CmdArgs) const;
257
258 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
259 ArgStringList &CmdArgs) const;
260
261 /// }
262};
263
264/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
Duncan Sandsaf260b92010-05-11 20:16:05 +0000265class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
Daniel Dunbar6276f992009-09-18 08:15:13 +0000266public:
267 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000268 : Generic_GCC(Host, Triple) {}
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000269
Daniel Dunbar82eb4ce2010-08-23 22:35:37 +0000270 std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
271
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000272 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
273};
274
Rafael Espindolaacc87092010-10-29 20:14:02 +0000275class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
276 public:
277 Generic_ELF(const HostInfo &Host, const llvm::Triple& Triple)
278 : Generic_GCC(Host, Triple) {}
279
280 virtual bool IsIntegratedAssemblerDefault() const {
281 // Default integrated assembler to on for x86.
282 return (getTriple().getArch() == llvm::Triple::x86 ||
283 getTriple().getArch() == llvm::Triple::x86_64);
284 }
285};
286
Duncan Sandsaf260b92010-05-11 20:16:05 +0000287class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
Edward O'Callaghan856e4ff2009-08-22 01:06:46 +0000288public:
289 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
290
291 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
292};
293
Rafael Espindolaacc87092010-10-29 20:14:02 +0000294class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
Daniel Dunbar10de9e62009-06-29 20:52:51 +0000295public:
296 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
297
298 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
299};
300
Rafael Espindolaacc87092010-10-29 20:14:02 +0000301class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
Daniel Dunbare24297c2009-03-30 21:06:03 +0000302public:
Daniel Dunbara18a4872010-08-02 05:43:59 +0000303 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbare24297c2009-03-30 21:06:03 +0000304
305 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
306};
307
Benjamin Kramer24f1d3e2011-02-02 18:59:27 +0000308class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
309public:
310 NetBSD(const HostInfo &Host, const llvm::Triple& Triple);
311
312 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
313};
314
Chris Lattner3e2ee142010-07-07 16:01:42 +0000315class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
316public:
317 Minix(const HostInfo &Host, const llvm::Triple& Triple);
318
319 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
320};
321
Rafael Espindolaacc87092010-10-29 20:14:02 +0000322class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
Daniel Dunbarcc912342009-05-02 18:28:39 +0000323public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000324 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarcc912342009-05-02 18:28:39 +0000325
326 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
327};
328
Rafael Espindolaacc87092010-10-29 20:14:02 +0000329class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
Eli Friedman5cd659f2009-05-26 07:52:18 +0000330public:
331 Linux(const HostInfo &Host, const llvm::Triple& Triple);
Rafael Espindola92b00932010-08-10 00:25:48 +0000332
Rafael Espindolac8f008f2010-11-07 20:14:31 +0000333 virtual bool HasNativeLLVMSupport() const;
334
Rafael Espindola92b00932010-08-10 00:25:48 +0000335 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Rafael Espindolac8f008f2010-11-07 20:14:31 +0000336
337 std::string Linker;
338 std::vector<std::string> ExtraOpts;
Eli Friedman5cd659f2009-05-26 07:52:18 +0000339};
340
341
Chris Lattner09797542010-03-04 21:07:38 +0000342/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
343/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
Duncan Sandsaf260b92010-05-11 20:16:05 +0000344class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
Chris Lattner09797542010-03-04 21:07:38 +0000345public:
346 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
347 ~TCEToolChain();
348
Chris Lattner09797542010-03-04 21:07:38 +0000349 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
350 bool IsMathErrnoDefault() const;
351 bool IsUnwindTablesDefault() const;
352 const char* GetDefaultRelocationModel() const;
353 const char* GetForcedPicModel() const;
354
355private:
356 mutable llvm::DenseMap<unsigned, Tool*> Tools;
357
358};
359
Michael J. Spencerb186bc32010-08-21 21:55:07 +0000360class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain {
361 mutable llvm::DenseMap<unsigned, Tool*> Tools;
362
363public:
364 Windows(const HostInfo &Host, const llvm::Triple& Triple);
365
366 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
367
368 virtual bool IsIntegratedAssemblerDefault() const;
369 virtual bool IsUnwindTablesDefault() const;
370 virtual const char *GetDefaultRelocationModel() const;
371 virtual const char *GetForcedPicModel() const;
372};
373
Daniel Dunbar0a248bb2009-03-17 21:38:00 +0000374} // end namespace toolchains
375} // end namespace driver
376} // end namespace clang
377
378#endif