blob: 1cd8ee186cae2c38bb7420fa5941b1af30aa183b [file] [log] [blame]
Daniel Dunbar39176082009-03-20 00:20:03 +00001//===--- ToolChains.cpp - ToolChain Implementations ---------------------*-===//
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#include "ToolChains.h"
11
Daniel Dunbarf3cad362009-03-25 04:13:45 +000012#include "clang/Driver/Arg.h"
13#include "clang/Driver/ArgList.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000014#include "clang/Driver/Driver.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000015#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000016#include "clang/Driver/HostInfo.h"
Daniel Dunbar27e738d2009-11-19 00:15:11 +000017#include "clang/Driver/OptTable.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000018#include "clang/Driver/Option.h"
Daniel Dunbar265e9ef2009-11-19 04:25:22 +000019#include "clang/Driver/Options.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000020
21#include "llvm/ADT/StringExtras.h"
Daniel Dunbar84ec96c2009-09-09 22:33:15 +000022#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000023#include "llvm/Support/raw_ostream.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000024#include "llvm/System/Path.h"
25
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000026#include <cstdlib> // ::getenv
27
Daniel Dunbar39176082009-03-20 00:20:03 +000028using namespace clang::driver;
29using namespace clang::driver::toolchains;
30
Daniel Dunbarf3955282009-09-04 18:34:51 +000031/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000032
Daniel Dunbarf3955282009-09-04 18:34:51 +000033Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +000034 const unsigned (&_DarwinVersion)[3])
35 : ToolChain(Host, Triple), TargetInitialized(false)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000036{
Daniel Dunbar02633b52009-03-26 16:23:12 +000037 llvm::raw_string_ostream(MacosxVersionMin)
Daniel Dunbar5435fc92010-01-27 00:57:11 +000038 << "10." << std::max(0, (int)_DarwinVersion[0] - 4) << '.'
39 << _DarwinVersion[1];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000040}
41
Daniel Dunbareeff4062010-01-22 02:04:58 +000042// FIXME: Can we tablegen this?
43static const char *GetArmArchForMArch(llvm::StringRef Value) {
44 if (Value == "armv6k")
45 return "armv6";
46
47 if (Value == "armv5tej")
48 return "armv5";
49
50 if (Value == "xscale")
51 return "xscale";
52
53 if (Value == "armv4t")
54 return "armv4t";
55
56 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
57 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
58 Value == "armv7m")
59 return "armv7";
60
61 return 0;
62}
63
64// FIXME: Can we tablegen this?
65static const char *GetArmArchForMCpu(llvm::StringRef Value) {
66 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
67 Value == "arm946e-s" || Value == "arm966e-s" ||
68 Value == "arm968e-s" || Value == "arm10e" ||
69 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
70 Value == "arm1026ej-s")
71 return "armv5";
72
73 if (Value == "xscale")
74 return "xscale";
75
76 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
77 Value == "arm1176jz-s" || Value == "arm1176jzf-s")
78 return "armv6";
79
80 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
81 return "armv7";
82
83 return 0;
84}
85
86llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
87 switch (getTriple().getArch()) {
88 default:
89 return getArchName();
90
91 case llvm::Triple::arm: {
92 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
93 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
94 return Arch;
95
96 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
97 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
98 return Arch;
99
100 return "arm";
101 }
102 }
103}
104
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000105DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
106 const unsigned (&DarwinVersion)[3],
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000107 const unsigned (&_GCCVersion)[3])
108 : Darwin(Host, Triple, DarwinVersion)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000109{
110 GCCVersion[0] = _GCCVersion[0];
111 GCCVersion[1] = _GCCVersion[1];
112 GCCVersion[2] = _GCCVersion[2];
113
114 // Set up the tool chain paths to match gcc.
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000115 ToolChainDir = "i686-apple-darwin";
Ted Kremenek55bac532009-10-07 03:21:11 +0000116 ToolChainDir += llvm::utostr(DarwinVersion[0]);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000117 ToolChainDir += "/";
118 ToolChainDir += llvm::utostr(GCCVersion[0]);
119 ToolChainDir += '.';
120 ToolChainDir += llvm::utostr(GCCVersion[1]);
121 ToolChainDir += '.';
122 ToolChainDir += llvm::utostr(GCCVersion[2]);
123
Daniel Dunbar74782b02009-10-20 19:25:43 +0000124 // Try the next major version if that tool chain dir is invalid.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000125 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir;
126 if (!llvm::sys::Path(Tmp).exists()) {
Daniel Dunbar74782b02009-10-20 19:25:43 +0000127 std::string Next = "i686-apple-darwin";
128 Next += llvm::utostr(DarwinVersion[0] + 1);
129 Next += "/";
130 Next += llvm::utostr(GCCVersion[0]);
131 Next += '.';
132 Next += llvm::utostr(GCCVersion[1]);
133 Next += '.';
134 Next += llvm::utostr(GCCVersion[2]);
135
136 // Use that if it exists, otherwise hope the user isn't linking.
137 //
138 // FIXME: Drop dependency on gcc's tool chain.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000139 Tmp = "/usr/lib/gcc/" + Next;
140 if (llvm::sys::Path(Tmp).exists())
Daniel Dunbar74782b02009-10-20 19:25:43 +0000141 ToolChainDir = Next;
142 }
143
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000144 std::string Path;
145 if (getArchName() == "x86_64") {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000146 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000147 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000148 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000149 Path += "/x86_64";
150 getFilePaths().push_back(Path);
151
152 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000153 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000154 Path += "/x86_64";
155 getFilePaths().push_back(Path);
156 }
Mike Stump1eb44332009-09-09 15:08:12 +0000157
Daniel Dunbaree788e72009-12-21 18:54:17 +0000158 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000159 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000160 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000161 getFilePaths().push_back(Path);
162
163 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000164 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000165 getFilePaths().push_back(Path);
166
Daniel Dunbaree788e72009-12-21 18:54:17 +0000167 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000168 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000169 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000170 getProgramPaths().push_back(Path);
171
172 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000173 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000174 getProgramPaths().push_back(Path);
175
Daniel Dunbaree788e72009-12-21 18:54:17 +0000176 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000177}
178
Daniel Dunbarf3955282009-09-04 18:34:51 +0000179Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000180 // Free tool implementations.
181 for (llvm::DenseMap<unsigned, Tool*>::iterator
182 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
183 delete it->second;
184}
185
Daniel Dunbarf3955282009-09-04 18:34:51 +0000186Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000187 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000188 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000189 Key = Action::AnalyzeJobClass;
190 else
191 Key = JA.getKind();
192
193 Tool *&T = Tools[Key];
194 if (!T) {
195 switch (Key) {
196 case Action::InputClass:
197 case Action::BindArchClass:
198 assert(0 && "Invalid tool kind.");
199 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000200 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000201 case Action::AnalyzeJobClass:
202 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000203 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000204 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000205 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000206 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000207 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000208 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000209 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000210 case Action::LipoJobClass:
211 T = new tools::darwin::Lipo(*this); break;
212 }
213 }
214
215 return *T;
216}
217
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000218void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
219 ArgStringList &CmdArgs) const {
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000220 std::string Tmp;
221
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000222 // FIXME: Derive these correctly.
223 if (getArchName() == "x86_64") {
224 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
225 "/x86_64"));
226 // Intentionally duplicated for (temporary) gcc bug compatibility.
227 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
228 "/x86_64"));
229 }
Daniel Dunbar8bc9c552010-04-10 01:24:22 +0000230
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000231 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000232
233 Tmp = getDriver().Dir + "/../lib/gcc/" + ToolChainDir;
234 if (llvm::sys::Path(Tmp).exists())
235 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
236 Tmp = getDriver().Dir + "/../lib/gcc";
237 if (llvm::sys::Path(Tmp).exists())
238 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000239 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
240 // Intentionally duplicated for (temporary) gcc bug compatibility.
241 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000242 Tmp = getDriver().Dir + "/../lib/" + ToolChainDir;
243 if (llvm::sys::Path(Tmp).exists())
244 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
245 Tmp = getDriver().Dir + "/../lib";
246 if (llvm::sys::Path(Tmp).exists())
247 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000248 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
249 "/../../../" + ToolChainDir));
250 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
251 "/../../.."));
252}
253
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000254void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
255 ArgStringList &CmdArgs) const {
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000256 // Note that this routine is only used for targetting OS X.
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000257
258 // Derived from libgcc and lib specs but refactored.
259 if (Args.hasArg(options::OPT_static)) {
260 CmdArgs.push_back("-lgcc_static");
261 } else {
262 if (Args.hasArg(options::OPT_static_libgcc)) {
263 CmdArgs.push_back("-lgcc_eh");
264 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
265 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000266 if (isTargetIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000267 CmdArgs.push_back("-lgcc_s.1");
268 } else {
269 CmdArgs.push_back("-lgcc_s.10.5");
270 }
271 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
Daniel Dunbar8a0d94d2010-01-10 00:46:10 +0000272 Args.hasFlag(options::OPT_fexceptions,
273 options::OPT_fno_exceptions) ||
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000274 Args.hasArg(options::OPT_fgnu_runtime)) {
275 // FIXME: This is probably broken on 10.3?
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000276 if (isMacosxVersionLT(10, 5))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000277 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000278 else if (isMacosxVersionLT(10, 6))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000279 CmdArgs.push_back("-lgcc_s.10.5");
280 } else {
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000281 if (isMacosxVersionLT(10, 3, 9))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000282 ; // Do nothing.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000283 else if (isMacosxVersionLT(10, 5))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000284 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000285 else if (isMacosxVersionLT(10, 6))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000286 CmdArgs.push_back("-lgcc_s.10.5");
287 }
288
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000289 if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000290 CmdArgs.push_back("-lgcc");
291 CmdArgs.push_back("-lSystem");
292 } else {
293 CmdArgs.push_back("-lSystem");
294 CmdArgs.push_back("-lgcc");
295 }
296 }
297}
298
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000299DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000300 const unsigned (&DarwinVersion)[3])
301 : Darwin(Host, Triple, DarwinVersion)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000302{
303 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaree788e72009-12-21 18:54:17 +0000304 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000305}
306
307void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
308 ArgStringList &CmdArgs) const {
309 // The Clang toolchain uses explicit paths for internal libraries.
310}
311
312void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
313 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000314 // Darwin doesn't support real static executables, don't link any runtime
315 // libraries with -static.
316 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000317 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000318
319 // Reject -static-libgcc for now, we can deal with this when and if someone
320 // cares. This is useful in situations where someone wants to statically link
321 // something like libstdc++, and needs its runtime support routines.
322 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000323 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000324 << A->getAsString(Args);
325 return;
326 }
327
Daniel Dunbareec99102010-01-22 03:38:14 +0000328 // Otherwise link libSystem, then the dynamic runtime library, and finally any
329 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000330 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000331
332 // Select the dynamic runtime library and the target specific static library.
333 const char *DarwinStaticLib = 0;
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000334 if (isTargetIPhoneOS()) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000335 CmdArgs.push_back("-lgcc_s.1");
336
337 // We may need some static functions for armv6/thumb which are required to
338 // be in the same linkage unit as their caller.
339 if (getDarwinArchName(Args) == "armv6")
340 DarwinStaticLib = "libclang_rt.armv6.a";
341 } else {
Daniel Dunbareec99102010-01-22 03:38:14 +0000342 // The dynamic runtime library was merged with libSystem for 10.6 and
343 // beyond; only 10.4 and 10.5 need an additional runtime library.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000344 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000345 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000346 else if (isMacosxVersionLT(10, 6))
Daniel Dunbareec99102010-01-22 03:38:14 +0000347 CmdArgs.push_back("-lgcc_s.10.5");
348
349 // For OS X, we only need a static runtime library when targetting 10.4, to
350 // provide versions of the static functions which were omitted from
351 // 10.4.dylib.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000352 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000353 DarwinStaticLib = "libclang_rt.10.4.a";
354 }
355
356 /// Add the target specific static library, if needed.
357 if (DarwinStaticLib) {
358 llvm::sys::Path P(getDriver().ResourceDir);
359 P.appendComponent("lib");
360 P.appendComponent("darwin");
361 P.appendComponent(DarwinStaticLib);
362
363 // For now, allow missing resource libraries to support developers who may
364 // not have compiler-rt checked out or integrated into their build.
365 if (!P.exists())
366 getDriver().Diag(clang::diag::warn_drv_missing_resource_library)
367 << P.str();
368 else
369 CmdArgs.push_back(Args.MakeArgString(P.str()));
370 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000371}
372
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000373DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
374 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000375 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbaree788e72009-12-21 18:54:17 +0000376 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000377
378 // FIXME: We really want to get out of the tool chain level argument
379 // translation business, as it makes the driver functionality much
380 // more opaque. For now, we follow gcc closely solely for the
381 // purpose of easily achieving feature parity & testability. Once we
382 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000383 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000384
Daniel Dunbar26031372010-01-27 00:56:25 +0000385 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
386 Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000387 if (OSXVersion && iPhoneVersion) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000388 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000389 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000390 << iPhoneVersion->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000391 iPhoneVersion = 0;
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000392 } else if (!OSXVersion && !iPhoneVersion) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000393 // If neither OS X nor iPhoneOS targets were specified, check for
394 // environment defines.
395 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
396 const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000397
Daniel Dunbar816bc312010-01-26 01:45:19 +0000398 // Ignore empty strings.
399 if (OSXTarget && OSXTarget[0] == '\0')
400 OSXTarget = 0;
401 if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0')
402 iPhoneOSTarget = 0;
403
Daniel Dunbar39053672010-02-02 17:31:12 +0000404 // Diagnose conflicting deployment targets, and choose default platform
405 // based on the tool chain.
406 //
407 // FIXME: Don't hardcode default here.
408 if (OSXTarget && iPhoneOSTarget) {
409 // FIXME: We should see if we can get away with warning or erroring on
410 // this. Perhaps put under -pedantic?
411 if (getTriple().getArch() == llvm::Triple::arm ||
412 getTriple().getArch() == llvm::Triple::thumb)
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000413 OSXTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000414 else
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000415 iPhoneOSTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000416 }
Daniel Dunbar1a3c1d92010-01-29 17:02:25 +0000417
Daniel Dunbar39053672010-02-02 17:31:12 +0000418 if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000419 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000420 OSXVersion = DAL->MakeJoinedArg(0, O, OSXTarget);
421 DAL->append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000422 } else if (iPhoneOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000423 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000424 iPhoneVersion = DAL->MakeJoinedArg(0, O, iPhoneOSTarget);
425 DAL->append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000426 } else {
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000427 // Otherwise, choose a default platform based on the tool chain.
428 //
429 // FIXME: Don't hardcode default here.
430 if (getTriple().getArch() == llvm::Triple::arm ||
431 getTriple().getArch() == llvm::Triple::thumb) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000432 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000433 iPhoneVersion = DAL->MakeJoinedArg(0, O, "3.0");
Daniel Dunbar26031372010-01-27 00:56:25 +0000434 DAL->append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000435 } else {
436 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000437 OSXVersion = DAL->MakeJoinedArg(0, O, MacosxVersionMin);
438 DAL->append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000439 }
Daniel Dunbar30392de2009-09-04 18:35:21 +0000440 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000441 }
Mike Stump1eb44332009-09-09 15:08:12 +0000442
Daniel Dunbar26031372010-01-27 00:56:25 +0000443 // Set the tool chain target information.
444 unsigned Major, Minor, Micro;
445 bool HadExtra;
446 if (OSXVersion) {
447 assert(!iPhoneVersion && "Unknown target platform!");
448 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
449 Micro, HadExtra) || HadExtra ||
450 Major != 10 || Minor >= 10 || Micro >= 10)
451 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
452 << OSXVersion->getAsString(Args);
453 } else {
454 assert(iPhoneVersion && "Unknown target platform!");
455 if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor,
456 Micro, HadExtra) || HadExtra ||
457 Major >= 10 || Minor >= 100 || Micro >= 100)
458 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
459 << iPhoneVersion->getAsString(Args);
460 }
461 setTarget(iPhoneVersion, Major, Minor, Micro);
462
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000463 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
464 Arg *A = *it;
465
466 if (A->getOption().matches(options::OPT_Xarch__)) {
467 // FIXME: Canonicalize name.
468 if (getArchName() != A->getValue(Args, 0))
469 continue;
470
471 // FIXME: The arg is leaked here, and we should have a nicer
472 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000473 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000474 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000475
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000476 // If the argument parsing failed or more than one argument was
477 // consumed, the -Xarch_ argument's parameter tried to consume
478 // extra arguments. Emit an error and ignore.
479 //
480 // We also want to disallow any options which would alter the
481 // driver behavior; that isn't going to work in our model. We
482 // use isDriverOption() as an approximation, although things
483 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000484 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000485 XarchArg->getOption().isDriverOption()) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000486 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000487 << A->getAsString(Args);
488 continue;
489 }
490
Daniel Dunbar478edc22009-03-29 22:29:05 +0000491 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000492 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000493 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000494
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000495 // Sob. These is strictly gcc compatible for the time being. Apple
496 // gcc translates options twice, which means that self-expanding
497 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000498 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000499 default:
500 DAL->append(A);
501 break;
502
503 case options::OPT_mkernel:
504 case options::OPT_fapple_kext:
505 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000506 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
507 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000508 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000509
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000510 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000511 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000512 A->getValue(Args)));
513 break;
514
515 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000516 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
517 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000518 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
519 break;
520
521 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000522 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
523 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000524 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
525 break;
526
527 case options::OPT_fterminated_vtables:
528 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000529 DAL->append(DAL->MakeFlagArg(A,
530 Opts.getOption(options::OPT_fapple_kext)));
531 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000532 break;
533
534 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000535 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000536 break;
537
538 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000539 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000540 Opts.getOption(options::OPT_mconstant_cfstrings)));
541 break;
542
543 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000544 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000545 Opts.getOption(options::OPT_mno_constant_cfstrings)));
546 break;
547
548 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000549 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000550 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
551 break;
552
553 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000554 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000555 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
556 break;
557
558 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000559 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000560 Opts.getOption(options::OPT_mpascal_strings)));
561 break;
562
563 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000564 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000565 Opts.getOption(options::OPT_mno_pascal_strings)));
566 break;
567 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000568 }
569
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000570 if (getTriple().getArch() == llvm::Triple::x86 ||
571 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000572 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000573 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
574 "core2"));
575
576 // Add the arch options based on the particular spelling of -arch, to match
577 // how the driver driver works.
578 if (BoundArch) {
579 llvm::StringRef Name = BoundArch;
580 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
581 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
582
583 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
584 // which defines the list of which architectures we accept.
585 if (Name == "ppc")
586 ;
587 else if (Name == "ppc601")
588 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
589 else if (Name == "ppc603")
590 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
591 else if (Name == "ppc604")
592 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
593 else if (Name == "ppc604e")
594 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
595 else if (Name == "ppc750")
596 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
597 else if (Name == "ppc7400")
598 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
599 else if (Name == "ppc7450")
600 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
601 else if (Name == "ppc970")
602 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
603
604 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000605 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000606
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000607 else if (Name == "i386")
608 ;
609 else if (Name == "i486")
610 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
611 else if (Name == "i586")
612 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
613 else if (Name == "i686")
614 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
615 else if (Name == "pentium")
616 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
617 else if (Name == "pentium2")
618 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
619 else if (Name == "pentpro")
620 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
621 else if (Name == "pentIIm3")
622 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
623
624 else if (Name == "x86_64")
625 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
626
627 else if (Name == "arm")
628 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
629 else if (Name == "armv4t")
630 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
631 else if (Name == "armv5")
632 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
633 else if (Name == "xscale")
634 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
635 else if (Name == "armv6")
636 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
637 else if (Name == "armv7")
638 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
639
640 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000641 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000642 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000643
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000644 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000645}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000646
Daniel Dunbarf3955282009-09-04 18:34:51 +0000647bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000648 // FIXME: Gross; we should probably have some separate target
649 // definition, possibly even reusing the one in clang.
650 return getArchName() == "x86_64";
651}
652
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000653bool Darwin::UseDwarfDebugFlags() const {
654 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
655 return S[0] != '\0';
656 return false;
657}
658
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000659bool Darwin::UseSjLjExceptions() const {
660 // Darwin uses SjLj exceptions on ARM.
661 return (getTriple().getArch() == llvm::Triple::arm ||
662 getTriple().getArch() == llvm::Triple::thumb);
663}
664
Daniel Dunbarf3955282009-09-04 18:34:51 +0000665const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000666 return "pic";
667}
668
Daniel Dunbarf3955282009-09-04 18:34:51 +0000669const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000670 if (getArchName() == "x86_64")
671 return "pic";
672 return 0;
673}
674
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000675bool Darwin::SupportsObjCGC() const {
676 // Garbage collection is supported everywhere except on iPhone OS.
677 return !isTargetIPhoneOS();
678}
679
Daniel Dunbar39176082009-03-20 00:20:03 +0000680/// Generic_GCC - A tool chain using the 'gcc' command to perform
681/// all subcommands; this relies on gcc translating the majority of
682/// command line options.
683
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000684Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000685 : ToolChain(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000686 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000687}
688
Daniel Dunbar39176082009-03-20 00:20:03 +0000689Generic_GCC::~Generic_GCC() {
690 // Free tool implementations.
691 for (llvm::DenseMap<unsigned, Tool*>::iterator
692 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
693 delete it->second;
694}
695
Mike Stump1eb44332009-09-09 15:08:12 +0000696Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000697 const JobAction &JA) const {
698 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000699 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000700 Key = Action::AnalyzeJobClass;
701 else
702 Key = JA.getKind();
703
704 Tool *&T = Tools[Key];
705 if (!T) {
706 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000707 case Action::InputClass:
708 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000709 assert(0 && "Invalid tool kind.");
710 case Action::PreprocessJobClass:
711 T = new tools::gcc::Preprocess(*this); break;
712 case Action::PrecompileJobClass:
713 T = new tools::gcc::Precompile(*this); break;
714 case Action::AnalyzeJobClass:
715 T = new tools::Clang(*this); break;
716 case Action::CompileJobClass:
717 T = new tools::gcc::Compile(*this); break;
718 case Action::AssembleJobClass:
719 T = new tools::gcc::Assemble(*this); break;
720 case Action::LinkJobClass:
721 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000722
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000723 // This is a bit ungeneric, but the only platform using a driver
724 // driver is Darwin.
725 case Action::LipoJobClass:
726 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000727 }
728 }
729
730 return *T;
731}
732
Daniel Dunbar39176082009-03-20 00:20:03 +0000733bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000734 // FIXME: Gross; we should probably have some separate target
735 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000736 return getArchName() == "x86_64";
737}
738
739const char *Generic_GCC::GetDefaultRelocationModel() const {
740 return "static";
741}
742
743const char *Generic_GCC::GetForcedPicModel() const {
744 return 0;
745}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000746
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000747DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
748 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000749 return new DerivedArgList(Args, true);
750}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000751
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000752
753/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
754/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
755/// Currently does not support anything else but compilation.
756
757TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple)
758 : ToolChain(Host, Triple) {
759 // Path mangling to find libexec
760 std::string Path(getDriver().Dir);
761
762 Path += "/../libexec";
763 getProgramPaths().push_back(Path);
764}
765
766TCEToolChain::~TCEToolChain() {
767 for (llvm::DenseMap<unsigned, Tool*>::iterator
768 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
769 delete it->second;
770}
771
772bool TCEToolChain::IsMathErrnoDefault() const {
773 return true;
774}
775
776bool TCEToolChain::IsUnwindTablesDefault() const {
777 return false;
778}
779
780const char *TCEToolChain::GetDefaultRelocationModel() const {
781 return "static";
782}
783
784const char *TCEToolChain::GetForcedPicModel() const {
785 return 0;
786}
787
788Tool &TCEToolChain::SelectTool(const Compilation &C,
789 const JobAction &JA) const {
790 Action::ActionClass Key;
791 Key = Action::AnalyzeJobClass;
792
793 Tool *&T = Tools[Key];
794 if (!T) {
795 switch (Key) {
796 case Action::PreprocessJobClass:
797 T = new tools::gcc::Preprocess(*this); break;
798 case Action::AnalyzeJobClass:
799 T = new tools::Clang(*this); break;
800 default:
801 assert(false && "Unsupported action for TCE target.");
802 }
803 }
804 return *T;
805}
806
807DerivedArgList *TCEToolChain::TranslateArgs(InputArgList &Args,
808 const char *BoundArch) const {
809 return new DerivedArgList(Args, true);
810}
811
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000812/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
813
814OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
815 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000816 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000817 getFilePaths().push_back("/usr/lib");
818}
819
820Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
821 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000822 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000823 Key = Action::AnalyzeJobClass;
824 else
825 Key = JA.getKind();
826
827 Tool *&T = Tools[Key];
828 if (!T) {
829 switch (Key) {
830 case Action::AssembleJobClass:
831 T = new tools::openbsd::Assemble(*this); break;
832 case Action::LinkJobClass:
833 T = new tools::openbsd::Link(*this); break;
834 default:
835 T = &Generic_GCC::SelectTool(C, JA);
836 }
837 }
838
839 return *T;
840}
841
Daniel Dunbar75358d22009-03-30 21:06:03 +0000842/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
843
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000844FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
845 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000846 if (Lib32) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000847 getFilePaths().push_back(getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000848 getFilePaths().push_back("/usr/lib32");
849 } else {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000850 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000851 getFilePaths().push_back("/usr/lib");
852 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000853}
854
855Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
856 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000857 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000858 Key = Action::AnalyzeJobClass;
859 else
860 Key = JA.getKind();
861
862 Tool *&T = Tools[Key];
863 if (!T) {
864 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000865 case Action::AssembleJobClass:
866 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000867 case Action::LinkJobClass:
868 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000869 default:
870 T = &Generic_GCC::SelectTool(C, JA);
871 }
872 }
873
874 return *T;
875}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000876
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000877/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
878
879AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
880 : Generic_GCC(Host, Triple) {
881
Daniel Dunbaree788e72009-12-21 18:54:17 +0000882 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000883
Daniel Dunbaree788e72009-12-21 18:54:17 +0000884 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000885 getFilePaths().push_back("/usr/lib");
886 getFilePaths().push_back("/usr/sfw/lib");
887 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +0000888 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000889
890}
891
892Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
893 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000894 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000895 Key = Action::AnalyzeJobClass;
896 else
897 Key = JA.getKind();
898
899 Tool *&T = Tools[Key];
900 if (!T) {
901 switch (Key) {
902 case Action::AssembleJobClass:
903 T = new tools::auroraux::Assemble(*this); break;
904 case Action::LinkJobClass:
905 T = new tools::auroraux::Link(*this); break;
906 default:
907 T = &Generic_GCC::SelectTool(C, JA);
908 }
909 }
910
911 return *T;
912}
913
914
Eli Friedman6b3454a2009-05-26 07:52:18 +0000915/// Linux toolchain (very bare-bones at the moment).
916
917Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
918 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000919 getFilePaths().push_back(getDriver().Dir + "/../lib/clang/1.0/");
Eli Friedman6b3454a2009-05-26 07:52:18 +0000920 getFilePaths().push_back("/lib/");
921 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000922
923 // Depending on the Linux distribution, any combination of lib{,32,64} is
924 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
925 // openSUSE uses lib and lib64 for the same purpose.
926 getFilePaths().push_back("/lib32/");
927 getFilePaths().push_back("/usr/lib32/");
928 getFilePaths().push_back("/lib64/");
929 getFilePaths().push_back("/usr/lib64/");
930
Eli Friedman6b3454a2009-05-26 07:52:18 +0000931 // FIXME: Figure out some way to get gcc's libdir
932 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
933 // crtbegin.o/crtend.o/etc., and want static versions of various
934 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
935 // get away with using shared versions in /usr/lib, though.
936 // We could fall back to the approach we used for includes (a massive
937 // list), but that's messy at best.
938}
939
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000940/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
941
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000942DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
943 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000944
945 // Path mangling to find libexec
Daniel Dunbaree788e72009-12-21 18:54:17 +0000946 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000947
Daniel Dunbaree788e72009-12-21 18:54:17 +0000948 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000949 getFilePaths().push_back("/usr/lib");
950 getFilePaths().push_back("/usr/lib/gcc41");
951}
952
953Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
954 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000955 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000956 Key = Action::AnalyzeJobClass;
957 else
958 Key = JA.getKind();
959
960 Tool *&T = Tools[Key];
961 if (!T) {
962 switch (Key) {
963 case Action::AssembleJobClass:
964 T = new tools::dragonfly::Assemble(*this); break;
965 case Action::LinkJobClass:
966 T = new tools::dragonfly::Link(*this); break;
967 default:
968 T = &Generic_GCC::SelectTool(C, JA);
969 }
970 }
971
972 return *T;
973}