blob: 89478d5f157a0ef7c67af4aaafef6db0edfe9dcf [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.
Daniel Dunbar15abb2e2009-03-17 22:18:43 +000028class VISIBILITY_HIDDEN 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 Dunbare7af3412009-09-09 18:36:12 +000036 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
37 const char *BoundArch) const;
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000038
Daniel Dunbar59e5e882009-03-20 00:20:03 +000039 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar04cb0292009-03-17 22:07:31 +000040
Daniel Dunbar59e5e882009-03-20 00:20:03 +000041 virtual bool IsUnwindTablesDefault() const;
42 virtual const char *GetDefaultRelocationModel() const;
43 virtual const char *GetForcedPicModel() const;
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000044};
45
Daniel Dunbar6276f992009-09-18 08:15:13 +000046/// Darwin - The base Darwin tool chain.
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000047class VISIBILITY_HIDDEN Darwin : public ToolChain {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000048 mutable llvm::DenseMap<unsigned, Tool*> Tools;
49
Daniel Dunbar76ce7412009-03-23 16:15:50 +000050 /// Darwin version of tool chain.
51 unsigned DarwinVersion[3];
52
Daniel Dunbar6276f992009-09-18 08:15:13 +000053 /// Whether this is this an iPhoneOS toolchain.
54 //
55 // FIXME: This should go away, such differences should be completely
56 // determined by the target triple.
Daniel Dunbard54669d2010-01-26 01:45:19 +000057 //
58 // FIXME: It is also broken, we need to distinguish the "default target" from
59 // the actual target. The -m...-version-min strings and deployment targets can
60 // change this.
Daniel Dunbar6276f992009-09-18 08:15:13 +000061 bool IsIPhoneOS;
Daniel Dunbar76ce7412009-03-23 16:15:50 +000062
Daniel Dunbarc1964212009-03-26 16:23:12 +000063 /// The default macosx-version-min of this tool chain; empty until
64 /// initialized.
Daniel Dunbard54669d2010-01-26 01:45:19 +000065 std::string MacosxVersionMin;
Daniel Dunbarc1964212009-03-26 16:23:12 +000066
Daniel Dunbar84e727f2009-09-04 18:35:21 +000067 /// The default iphoneos-version-min of this tool chain.
68 std::string IPhoneOSVersionMin;
69
Daniel Dunbarc1964212009-03-26 16:23:12 +000070 const char *getMacosxVersionMin() const;
Daniel Dunbar0af75a12009-03-25 06:58:31 +000071
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000072public:
Mike Stump11289f42009-09-09 15:08:12 +000073 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar6276f992009-09-18 08:15:13 +000074 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000075 ~Darwin();
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000076
Daniel Dunbar4c30b892009-09-18 08:14:36 +000077 /// @name Darwin Specific Toolchain API
78 /// {
79
Daniel Dunbarc1964212009-03-26 16:23:12 +000080 void getDarwinVersion(unsigned (&Res)[3]) const {
81 Res[0] = DarwinVersion[0];
82 Res[1] = DarwinVersion[1];
83 Res[2] = DarwinVersion[2];
84 }
85
86 void getMacosxVersion(unsigned (&Res)[3]) const {
87 Res[0] = 10;
88 Res[1] = DarwinVersion[0] - 4;
89 Res[2] = DarwinVersion[1];
90 }
91
Daniel Dunbardcc3b652010-01-22 02:04:58 +000092 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
93 /// invocation. For example, Darwin treats different ARM variations as
94 /// distinct architectures.
95 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
96
Daniel Dunbar510d8a82009-09-18 08:14:46 +000097 /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
98 /// either the -mmacosx-version-min, or the current version if unspecified.
99 void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
100
Daniel Dunbard5bd81e2009-09-18 08:14:55 +0000101 static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
102 for (unsigned i=0; i < 3; ++i) {
103 if (A[i] > B[i]) return false;
104 if (A[i] < B[i]) return true;
105 }
106 return false;
107 }
108
109 static bool isMacosxVersionLT(unsigned (&A)[3],
110 unsigned V0, unsigned V1=0, unsigned V2=0) {
111 unsigned B[3] = { V0, V1, V2 };
112 return isMacosxVersionLT(A, B);
113 }
114
Daniel Dunbarc1964212009-03-26 16:23:12 +0000115 const char *getMacosxVersionStr() const {
116 return MacosxVersionMin.c_str();
117 }
118
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000119 const char *getIPhoneOSVersionStr() const {
120 return IPhoneOSVersionMin.c_str();
121 }
122
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000123 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
124 ///
125 /// \param Args - The input argument list.
126 /// \param CmdArgs [out] - The command argument list to append the paths
127 /// (prefixed by -L) to.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000128 virtual void AddLinkSearchPathArgs(const ArgList &Args,
129 ArgStringList &CmdArgs) const = 0;
Daniel Dunbarc1964212009-03-26 16:23:12 +0000130
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000131 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
132 /// runtime library.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000133 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
134 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000135
Daniel Dunbar6276f992009-09-18 08:15:13 +0000136 bool isIPhoneOS() const { return IsIPhoneOS; }
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000137
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000138 /// }
139 /// @name ToolChain Implementation
140 /// {
141
Daniel Dunbare7af3412009-09-09 18:36:12 +0000142 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
143 const char *BoundArch) const;
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000144
145 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
146
Daniel Dunbar4930e332009-11-17 08:07:36 +0000147 virtual bool IsBlocksDefault() const {
148 // Blocks default to on for 10.6 (darwin10) and beyond.
149 return (DarwinVersion[0] > 9);
150 }
151 virtual bool IsObjCNonFragileABIDefault() const {
152 // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64.
153 return (DarwinVersion[0] >= 9 &&
154 getTriple().getArch() == llvm::Triple::x86_64);
155 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000156 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000157 virtual unsigned GetDefaultStackProtectorLevel() const {
158 // Stack protectors default to on for 10.6 (darwin10) and beyond.
159 return (DarwinVersion[0] > 9) ? 1 : 0;
160 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000161 virtual const char *GetDefaultRelocationModel() const;
162 virtual const char *GetForcedPicModel() const;
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000163
Daniel Dunbar24c7f5e2009-12-18 02:43:17 +0000164 virtual bool UseDwarfDebugFlags() const;
165
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000166 /// }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000167};
168
Daniel Dunbar6276f992009-09-18 08:15:13 +0000169/// DarwinClang - The Darwin toolchain used by Clang.
170class VISIBILITY_HIDDEN DarwinClang : public Darwin {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000171public:
Daniel Dunbar6276f992009-09-18 08:15:13 +0000172 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
173 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
174
175 /// @name Darwin ToolChain Implementation
176 /// {
177
178 virtual void AddLinkSearchPathArgs(const ArgList &Args,
179 ArgStringList &CmdArgs) const;
180
181 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
182 ArgStringList &CmdArgs) const;
183
184 /// }
185};
186
187/// DarwinGCC - The Darwin toolchain used by GCC.
188class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
189 /// GCC version to use.
Ted Kremenek7881ac92009-10-07 03:21:11 +0000190 unsigned GCCVersion[3];
Daniel Dunbar6276f992009-09-18 08:15:13 +0000191
192 /// The directory suffix for this tool chain.
193 std::string ToolChainDir;
194
195public:
196 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Ted Kremenek7881ac92009-10-07 03:21:11 +0000197 const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3],
Daniel Dunbar6276f992009-09-18 08:15:13 +0000198 bool IsIPhoneOS);
199
200 /// @name Darwin ToolChain Implementation
201 /// {
202
203 virtual void AddLinkSearchPathArgs(const ArgList &Args,
204 ArgStringList &CmdArgs) const;
205
206 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
207 ArgStringList &CmdArgs) const;
208
209 /// }
210};
211
212/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
213class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
214public:
215 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000216 : Generic_GCC(Host, Triple) {}
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000217
218 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
219};
220
Edward O'Callaghan856e4ff2009-08-22 01:06:46 +0000221class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
222public:
223 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
224
225 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
226};
227
Daniel Dunbar10de9e62009-06-29 20:52:51 +0000228class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
229public:
230 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
231
232 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
233};
234
Daniel Dunbare24297c2009-03-30 21:06:03 +0000235class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
236public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000237 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbare24297c2009-03-30 21:06:03 +0000238
239 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
240};
241
Daniel Dunbarcc912342009-05-02 18:28:39 +0000242class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
243public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000244 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarcc912342009-05-02 18:28:39 +0000245
246 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
247};
248
Eli Friedman5cd659f2009-05-26 07:52:18 +0000249class VISIBILITY_HIDDEN Linux : public Generic_GCC {
250public:
251 Linux(const HostInfo &Host, const llvm::Triple& Triple);
252};
253
254
Daniel Dunbar0a248bb2009-03-17 21:38:00 +0000255} // end namespace toolchains
256} // end namespace driver
257} // end namespace clang
258
259#endif