blob: 92c7d793f9abf6c893854bfcac76676b9622d1db [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 Dunbar0f602de2010-05-20 21:48:38 +000014#include "clang/Driver/Compilation.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000015#include "clang/Driver/Driver.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000016#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000017#include "clang/Driver/HostInfo.h"
Daniel Dunbar27e738d2009-11-19 00:15:11 +000018#include "clang/Driver/OptTable.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000019#include "clang/Driver/Option.h"
Daniel Dunbar265e9ef2009-11-19 04:25:22 +000020#include "clang/Driver/Options.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000021
22#include "llvm/ADT/StringExtras.h"
Daniel Dunbar84ec96c2009-09-09 22:33:15 +000023#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000024#include "llvm/Support/raw_ostream.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000025#include "llvm/System/Path.h"
26
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000027#include <cstdlib> // ::getenv
28
Daniel Dunbar39176082009-03-20 00:20:03 +000029using namespace clang::driver;
30using namespace clang::driver::toolchains;
31
Daniel Dunbarf3955282009-09-04 18:34:51 +000032/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000033
Daniel Dunbarf3955282009-09-04 18:34:51 +000034Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +000035 const unsigned (&_DarwinVersion)[3])
36 : ToolChain(Host, Triple), TargetInitialized(false)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000037{
Daniel Dunbar02633b52009-03-26 16:23:12 +000038 llvm::raw_string_ostream(MacosxVersionMin)
Daniel Dunbar5435fc92010-01-27 00:57:11 +000039 << "10." << std::max(0, (int)_DarwinVersion[0] - 4) << '.'
40 << _DarwinVersion[1];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000041}
42
Daniel Dunbareeff4062010-01-22 02:04:58 +000043// FIXME: Can we tablegen this?
44static const char *GetArmArchForMArch(llvm::StringRef Value) {
45 if (Value == "armv6k")
46 return "armv6";
47
48 if (Value == "armv5tej")
49 return "armv5";
50
51 if (Value == "xscale")
52 return "xscale";
53
54 if (Value == "armv4t")
55 return "armv4t";
56
57 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
58 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
59 Value == "armv7m")
60 return "armv7";
61
62 return 0;
63}
64
65// FIXME: Can we tablegen this?
66static const char *GetArmArchForMCpu(llvm::StringRef Value) {
67 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
68 Value == "arm946e-s" || Value == "arm966e-s" ||
69 Value == "arm968e-s" || Value == "arm10e" ||
70 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
71 Value == "arm1026ej-s")
72 return "armv5";
73
74 if (Value == "xscale")
75 return "xscale";
76
77 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
78 Value == "arm1176jz-s" || Value == "arm1176jzf-s")
79 return "armv6";
80
81 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
82 return "armv7";
83
84 return 0;
85}
86
87llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
88 switch (getTriple().getArch()) {
89 default:
90 return getArchName();
91
92 case llvm::Triple::arm: {
93 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
94 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
95 return Arch;
96
97 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
98 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
99 return Arch;
100
101 return "arm";
102 }
103 }
104}
105
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000106DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
107 const unsigned (&DarwinVersion)[3],
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000108 const unsigned (&_GCCVersion)[3])
109 : Darwin(Host, Triple, DarwinVersion)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000110{
111 GCCVersion[0] = _GCCVersion[0];
112 GCCVersion[1] = _GCCVersion[1];
113 GCCVersion[2] = _GCCVersion[2];
114
115 // Set up the tool chain paths to match gcc.
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000116 ToolChainDir = "i686-apple-darwin";
Ted Kremenek55bac532009-10-07 03:21:11 +0000117 ToolChainDir += llvm::utostr(DarwinVersion[0]);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000118 ToolChainDir += "/";
119 ToolChainDir += llvm::utostr(GCCVersion[0]);
120 ToolChainDir += '.';
121 ToolChainDir += llvm::utostr(GCCVersion[1]);
122 ToolChainDir += '.';
123 ToolChainDir += llvm::utostr(GCCVersion[2]);
124
Daniel Dunbar74782b02009-10-20 19:25:43 +0000125 // Try the next major version if that tool chain dir is invalid.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000126 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir;
127 if (!llvm::sys::Path(Tmp).exists()) {
Daniel Dunbar74782b02009-10-20 19:25:43 +0000128 std::string Next = "i686-apple-darwin";
129 Next += llvm::utostr(DarwinVersion[0] + 1);
130 Next += "/";
131 Next += llvm::utostr(GCCVersion[0]);
132 Next += '.';
133 Next += llvm::utostr(GCCVersion[1]);
134 Next += '.';
135 Next += llvm::utostr(GCCVersion[2]);
136
137 // Use that if it exists, otherwise hope the user isn't linking.
138 //
139 // FIXME: Drop dependency on gcc's tool chain.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000140 Tmp = "/usr/lib/gcc/" + Next;
141 if (llvm::sys::Path(Tmp).exists())
Daniel Dunbar74782b02009-10-20 19:25:43 +0000142 ToolChainDir = Next;
143 }
144
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000145 std::string Path;
146 if (getArchName() == "x86_64") {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000147 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000148 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000149 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000150 Path += "/x86_64";
151 getFilePaths().push_back(Path);
152
153 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000154 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000155 Path += "/x86_64";
156 getFilePaths().push_back(Path);
157 }
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Daniel Dunbaree788e72009-12-21 18:54:17 +0000159 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000160 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000161 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000162 getFilePaths().push_back(Path);
163
164 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000165 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000166 getFilePaths().push_back(Path);
167
Daniel Dunbaree788e72009-12-21 18:54:17 +0000168 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000169 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000170 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000171 getProgramPaths().push_back(Path);
172
173 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000174 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000175 getProgramPaths().push_back(Path);
176
Daniel Dunbaree788e72009-12-21 18:54:17 +0000177 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000178}
179
Daniel Dunbarf3955282009-09-04 18:34:51 +0000180Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000181 // Free tool implementations.
182 for (llvm::DenseMap<unsigned, Tool*>::iterator
183 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
184 delete it->second;
185}
186
Daniel Dunbarf3955282009-09-04 18:34:51 +0000187Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000188 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000189 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000190 Key = Action::AnalyzeJobClass;
191 else
192 Key = JA.getKind();
193
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000194 // FIXME: This doesn't belong here, but ideally we will support static soon
195 // anyway.
196 bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) ||
197 C.getArgs().hasArg(options::OPT_static) ||
198 C.getArgs().hasArg(options::OPT_fapple_kext));
199 bool IsIADefault = IsIntegratedAssemblerDefault() && !HasStatic;
200 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
201 options::OPT_no_integrated_as,
202 IsIADefault);
203
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000204 Tool *&T = Tools[Key];
205 if (!T) {
206 switch (Key) {
207 case Action::InputClass:
208 case Action::BindArchClass:
209 assert(0 && "Invalid tool kind.");
210 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000211 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000212 case Action::AnalyzeJobClass:
213 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000214 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000215 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000216 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000217 case Action::AssembleJobClass: {
218 if (UseIntegratedAs)
219 T = new tools::ClangAs(*this);
220 else
221 T = new tools::darwin::Assemble(*this);
222 break;
223 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000224 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000225 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000226 case Action::LipoJobClass:
227 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000228 case Action::DsymutilJobClass:
229 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000230 }
231 }
232
233 return *T;
234}
235
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000236void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
237 ArgStringList &CmdArgs) const {
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000238 std::string Tmp;
239
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000240 // FIXME: Derive these correctly.
241 if (getArchName() == "x86_64") {
242 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
243 "/x86_64"));
244 // Intentionally duplicated for (temporary) gcc bug compatibility.
245 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
246 "/x86_64"));
247 }
Daniel Dunbar8bc9c552010-04-10 01:24:22 +0000248
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000249 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000250
251 Tmp = getDriver().Dir + "/../lib/gcc/" + ToolChainDir;
252 if (llvm::sys::Path(Tmp).exists())
253 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
254 Tmp = getDriver().Dir + "/../lib/gcc";
255 if (llvm::sys::Path(Tmp).exists())
256 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000257 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
258 // Intentionally duplicated for (temporary) gcc bug compatibility.
259 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000260 Tmp = getDriver().Dir + "/../lib/" + ToolChainDir;
261 if (llvm::sys::Path(Tmp).exists())
262 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
263 Tmp = getDriver().Dir + "/../lib";
264 if (llvm::sys::Path(Tmp).exists())
265 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000266 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
267 "/../../../" + ToolChainDir));
268 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
269 "/../../.."));
270}
271
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000272void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
273 ArgStringList &CmdArgs) const {
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000274 // Note that this routine is only used for targetting OS X.
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000275
276 // Derived from libgcc and lib specs but refactored.
277 if (Args.hasArg(options::OPT_static)) {
278 CmdArgs.push_back("-lgcc_static");
279 } else {
280 if (Args.hasArg(options::OPT_static_libgcc)) {
281 CmdArgs.push_back("-lgcc_eh");
282 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
283 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000284 if (isTargetIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000285 CmdArgs.push_back("-lgcc_s.1");
286 } else {
287 CmdArgs.push_back("-lgcc_s.10.5");
288 }
289 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
Daniel Dunbar8a0d94d2010-01-10 00:46:10 +0000290 Args.hasFlag(options::OPT_fexceptions,
291 options::OPT_fno_exceptions) ||
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000292 Args.hasArg(options::OPT_fgnu_runtime)) {
293 // FIXME: This is probably broken on 10.3?
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000294 if (isMacosxVersionLT(10, 5))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000295 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000296 else if (isMacosxVersionLT(10, 6))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000297 CmdArgs.push_back("-lgcc_s.10.5");
298 } else {
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000299 if (isMacosxVersionLT(10, 3, 9))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000300 ; // Do nothing.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000301 else if (isMacosxVersionLT(10, 5))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000302 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000303 else if (isMacosxVersionLT(10, 6))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000304 CmdArgs.push_back("-lgcc_s.10.5");
305 }
306
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000307 if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000308 CmdArgs.push_back("-lgcc");
309 CmdArgs.push_back("-lSystem");
310 } else {
311 CmdArgs.push_back("-lSystem");
312 CmdArgs.push_back("-lgcc");
313 }
314 }
315}
316
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000317DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000318 const unsigned (&DarwinVersion)[3])
319 : Darwin(Host, Triple, DarwinVersion)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000320{
321 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaree788e72009-12-21 18:54:17 +0000322 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000323}
324
325void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
326 ArgStringList &CmdArgs) const {
327 // The Clang toolchain uses explicit paths for internal libraries.
328}
329
330void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
331 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000332 // Darwin doesn't support real static executables, don't link any runtime
333 // libraries with -static.
334 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000335 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000336
337 // Reject -static-libgcc for now, we can deal with this when and if someone
338 // cares. This is useful in situations where someone wants to statically link
339 // something like libstdc++, and needs its runtime support routines.
340 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000341 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000342 << A->getAsString(Args);
343 return;
344 }
345
Daniel Dunbareec99102010-01-22 03:38:14 +0000346 // Otherwise link libSystem, then the dynamic runtime library, and finally any
347 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000348 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000349
350 // Select the dynamic runtime library and the target specific static library.
351 const char *DarwinStaticLib = 0;
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000352 if (isTargetIPhoneOS()) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000353 CmdArgs.push_back("-lgcc_s.1");
354
355 // We may need some static functions for armv6/thumb which are required to
356 // be in the same linkage unit as their caller.
357 if (getDarwinArchName(Args) == "armv6")
358 DarwinStaticLib = "libclang_rt.armv6.a";
359 } else {
Daniel Dunbareec99102010-01-22 03:38:14 +0000360 // The dynamic runtime library was merged with libSystem for 10.6 and
361 // beyond; only 10.4 and 10.5 need an additional runtime library.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000362 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000363 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000364 else if (isMacosxVersionLT(10, 6))
Daniel Dunbareec99102010-01-22 03:38:14 +0000365 CmdArgs.push_back("-lgcc_s.10.5");
366
367 // For OS X, we only need a static runtime library when targetting 10.4, to
368 // provide versions of the static functions which were omitted from
369 // 10.4.dylib.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000370 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000371 DarwinStaticLib = "libclang_rt.10.4.a";
372 }
373
374 /// Add the target specific static library, if needed.
375 if (DarwinStaticLib) {
376 llvm::sys::Path P(getDriver().ResourceDir);
377 P.appendComponent("lib");
378 P.appendComponent("darwin");
379 P.appendComponent(DarwinStaticLib);
380
381 // For now, allow missing resource libraries to support developers who may
382 // not have compiler-rt checked out or integrated into their build.
383 if (!P.exists())
384 getDriver().Diag(clang::diag::warn_drv_missing_resource_library)
385 << P.str();
386 else
387 CmdArgs.push_back(Args.MakeArgString(P.str()));
388 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000389}
390
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000391DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
392 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000393 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbaree788e72009-12-21 18:54:17 +0000394 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000395
396 // FIXME: We really want to get out of the tool chain level argument
397 // translation business, as it makes the driver functionality much
398 // more opaque. For now, we follow gcc closely solely for the
399 // purpose of easily achieving feature parity & testability. Once we
400 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000401 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000402
Daniel Dunbar26031372010-01-27 00:56:25 +0000403 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
404 Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000405 if (OSXVersion && iPhoneVersion) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000406 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000407 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000408 << iPhoneVersion->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000409 iPhoneVersion = 0;
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000410 } else if (!OSXVersion && !iPhoneVersion) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000411 // If neither OS X nor iPhoneOS targets were specified, check for
412 // environment defines.
413 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
414 const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000415
Daniel Dunbar816bc312010-01-26 01:45:19 +0000416 // Ignore empty strings.
417 if (OSXTarget && OSXTarget[0] == '\0')
418 OSXTarget = 0;
419 if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0')
420 iPhoneOSTarget = 0;
421
Daniel Dunbar39053672010-02-02 17:31:12 +0000422 // Diagnose conflicting deployment targets, and choose default platform
423 // based on the tool chain.
424 //
425 // FIXME: Don't hardcode default here.
426 if (OSXTarget && iPhoneOSTarget) {
427 // FIXME: We should see if we can get away with warning or erroring on
428 // this. Perhaps put under -pedantic?
429 if (getTriple().getArch() == llvm::Triple::arm ||
430 getTriple().getArch() == llvm::Triple::thumb)
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000431 OSXTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000432 else
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000433 iPhoneOSTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000434 }
Daniel Dunbar1a3c1d92010-01-29 17:02:25 +0000435
Daniel Dunbar39053672010-02-02 17:31:12 +0000436 if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000437 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000438 OSXVersion = DAL->MakeJoinedArg(0, O, OSXTarget);
439 DAL->append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000440 } else if (iPhoneOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000441 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000442 iPhoneVersion = DAL->MakeJoinedArg(0, O, iPhoneOSTarget);
443 DAL->append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000444 } else {
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000445 // Otherwise, choose a default platform based on the tool chain.
446 //
447 // FIXME: Don't hardcode default here.
448 if (getTriple().getArch() == llvm::Triple::arm ||
449 getTriple().getArch() == llvm::Triple::thumb) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000450 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000451 iPhoneVersion = DAL->MakeJoinedArg(0, O, "3.0");
Daniel Dunbar26031372010-01-27 00:56:25 +0000452 DAL->append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000453 } else {
454 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000455 OSXVersion = DAL->MakeJoinedArg(0, O, MacosxVersionMin);
456 DAL->append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000457 }
Daniel Dunbar30392de2009-09-04 18:35:21 +0000458 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000459 }
Mike Stump1eb44332009-09-09 15:08:12 +0000460
Daniel Dunbar26031372010-01-27 00:56:25 +0000461 // Set the tool chain target information.
462 unsigned Major, Minor, Micro;
463 bool HadExtra;
464 if (OSXVersion) {
465 assert(!iPhoneVersion && "Unknown target platform!");
466 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
467 Micro, HadExtra) || HadExtra ||
468 Major != 10 || Minor >= 10 || Micro >= 10)
469 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
470 << OSXVersion->getAsString(Args);
471 } else {
472 assert(iPhoneVersion && "Unknown target platform!");
473 if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor,
474 Micro, HadExtra) || HadExtra ||
475 Major >= 10 || Minor >= 100 || Micro >= 100)
476 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
477 << iPhoneVersion->getAsString(Args);
478 }
479 setTarget(iPhoneVersion, Major, Minor, Micro);
480
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000481 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
482 Arg *A = *it;
483
484 if (A->getOption().matches(options::OPT_Xarch__)) {
485 // FIXME: Canonicalize name.
486 if (getArchName() != A->getValue(Args, 0))
487 continue;
488
489 // FIXME: The arg is leaked here, and we should have a nicer
490 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000491 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000492 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000493
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000494 // If the argument parsing failed or more than one argument was
495 // consumed, the -Xarch_ argument's parameter tried to consume
496 // extra arguments. Emit an error and ignore.
497 //
498 // We also want to disallow any options which would alter the
499 // driver behavior; that isn't going to work in our model. We
500 // use isDriverOption() as an approximation, although things
501 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000502 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000503 XarchArg->getOption().isDriverOption()) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000504 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000505 << A->getAsString(Args);
506 continue;
507 }
508
Daniel Dunbar478edc22009-03-29 22:29:05 +0000509 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000510 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000511 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000512
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000513 // Sob. These is strictly gcc compatible for the time being. Apple
514 // gcc translates options twice, which means that self-expanding
515 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000516 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000517 default:
518 DAL->append(A);
519 break;
520
521 case options::OPT_mkernel:
522 case options::OPT_fapple_kext:
523 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000524 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
525 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000526 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000527
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000528 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000529 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000530 A->getValue(Args)));
531 break;
532
533 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000534 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
535 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000536 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
537 break;
538
539 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000540 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
541 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000542 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
543 break;
544
545 case options::OPT_fterminated_vtables:
546 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000547 DAL->append(DAL->MakeFlagArg(A,
548 Opts.getOption(options::OPT_fapple_kext)));
549 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000550 break;
551
552 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000553 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000554 break;
555
556 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000557 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000558 Opts.getOption(options::OPT_mconstant_cfstrings)));
559 break;
560
561 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000562 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000563 Opts.getOption(options::OPT_mno_constant_cfstrings)));
564 break;
565
566 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000567 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000568 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
569 break;
570
571 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000572 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000573 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
574 break;
575
576 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000577 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000578 Opts.getOption(options::OPT_mpascal_strings)));
579 break;
580
581 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000582 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000583 Opts.getOption(options::OPT_mno_pascal_strings)));
584 break;
585 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000586 }
587
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000588 if (getTriple().getArch() == llvm::Triple::x86 ||
589 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000590 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000591 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
592 "core2"));
593
594 // Add the arch options based on the particular spelling of -arch, to match
595 // how the driver driver works.
596 if (BoundArch) {
597 llvm::StringRef Name = BoundArch;
598 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
599 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
600
601 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
602 // which defines the list of which architectures we accept.
603 if (Name == "ppc")
604 ;
605 else if (Name == "ppc601")
606 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
607 else if (Name == "ppc603")
608 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
609 else if (Name == "ppc604")
610 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
611 else if (Name == "ppc604e")
612 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
613 else if (Name == "ppc750")
614 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
615 else if (Name == "ppc7400")
616 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
617 else if (Name == "ppc7450")
618 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
619 else if (Name == "ppc970")
620 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
621
622 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000623 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000624
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000625 else if (Name == "i386")
626 ;
627 else if (Name == "i486")
628 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
629 else if (Name == "i586")
630 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
631 else if (Name == "i686")
632 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
633 else if (Name == "pentium")
634 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
635 else if (Name == "pentium2")
636 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
637 else if (Name == "pentpro")
638 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
639 else if (Name == "pentIIm3")
640 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
641
642 else if (Name == "x86_64")
643 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
644
645 else if (Name == "arm")
646 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
647 else if (Name == "armv4t")
648 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
649 else if (Name == "armv5")
650 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
651 else if (Name == "xscale")
652 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
653 else if (Name == "armv6")
654 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
655 else if (Name == "armv7")
656 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
657
658 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000659 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000660 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000661
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000662 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000663}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000664
Daniel Dunbarf3955282009-09-04 18:34:51 +0000665bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000666 // FIXME: Gross; we should probably have some separate target
667 // definition, possibly even reusing the one in clang.
668 return getArchName() == "x86_64";
669}
670
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000671bool Darwin::UseDwarfDebugFlags() const {
672 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
673 return S[0] != '\0';
674 return false;
675}
676
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000677bool Darwin::UseSjLjExceptions() const {
678 // Darwin uses SjLj exceptions on ARM.
679 return (getTriple().getArch() == llvm::Triple::arm ||
680 getTriple().getArch() == llvm::Triple::thumb);
681}
682
Daniel Dunbarf3955282009-09-04 18:34:51 +0000683const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000684 return "pic";
685}
686
Daniel Dunbarf3955282009-09-04 18:34:51 +0000687const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000688 if (getArchName() == "x86_64")
689 return "pic";
690 return 0;
691}
692
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000693bool Darwin::SupportsObjCGC() const {
694 // Garbage collection is supported everywhere except on iPhone OS.
695 return !isTargetIPhoneOS();
696}
697
Daniel Dunbar39176082009-03-20 00:20:03 +0000698/// Generic_GCC - A tool chain using the 'gcc' command to perform
699/// all subcommands; this relies on gcc translating the majority of
700/// command line options.
701
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000702Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000703 : ToolChain(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000704 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000705}
706
Daniel Dunbar39176082009-03-20 00:20:03 +0000707Generic_GCC::~Generic_GCC() {
708 // Free tool implementations.
709 for (llvm::DenseMap<unsigned, Tool*>::iterator
710 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
711 delete it->second;
712}
713
Mike Stump1eb44332009-09-09 15:08:12 +0000714Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000715 const JobAction &JA) const {
716 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000717 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000718 Key = Action::AnalyzeJobClass;
719 else
720 Key = JA.getKind();
721
722 Tool *&T = Tools[Key];
723 if (!T) {
724 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000725 case Action::InputClass:
726 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000727 assert(0 && "Invalid tool kind.");
728 case Action::PreprocessJobClass:
729 T = new tools::gcc::Preprocess(*this); break;
730 case Action::PrecompileJobClass:
731 T = new tools::gcc::Precompile(*this); break;
732 case Action::AnalyzeJobClass:
733 T = new tools::Clang(*this); break;
734 case Action::CompileJobClass:
735 T = new tools::gcc::Compile(*this); break;
736 case Action::AssembleJobClass:
737 T = new tools::gcc::Assemble(*this); break;
738 case Action::LinkJobClass:
739 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000740
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000741 // This is a bit ungeneric, but the only platform using a driver
742 // driver is Darwin.
743 case Action::LipoJobClass:
744 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000745 case Action::DsymutilJobClass:
746 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000747 }
748 }
749
750 return *T;
751}
752
Daniel Dunbar39176082009-03-20 00:20:03 +0000753bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000754 // FIXME: Gross; we should probably have some separate target
755 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000756 return getArchName() == "x86_64";
757}
758
759const char *Generic_GCC::GetDefaultRelocationModel() const {
760 return "static";
761}
762
763const char *Generic_GCC::GetForcedPicModel() const {
764 return 0;
765}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000766
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000767DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
768 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000769 return new DerivedArgList(Args, true);
770}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000771
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000772
773/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
774/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
775/// Currently does not support anything else but compilation.
776
777TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple)
778 : ToolChain(Host, Triple) {
779 // Path mangling to find libexec
780 std::string Path(getDriver().Dir);
781
782 Path += "/../libexec";
783 getProgramPaths().push_back(Path);
784}
785
786TCEToolChain::~TCEToolChain() {
787 for (llvm::DenseMap<unsigned, Tool*>::iterator
788 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
789 delete it->second;
790}
791
792bool TCEToolChain::IsMathErrnoDefault() const {
793 return true;
794}
795
796bool TCEToolChain::IsUnwindTablesDefault() const {
797 return false;
798}
799
800const char *TCEToolChain::GetDefaultRelocationModel() const {
801 return "static";
802}
803
804const char *TCEToolChain::GetForcedPicModel() const {
805 return 0;
806}
807
808Tool &TCEToolChain::SelectTool(const Compilation &C,
809 const JobAction &JA) const {
810 Action::ActionClass Key;
811 Key = Action::AnalyzeJobClass;
812
813 Tool *&T = Tools[Key];
814 if (!T) {
815 switch (Key) {
816 case Action::PreprocessJobClass:
817 T = new tools::gcc::Preprocess(*this); break;
818 case Action::AnalyzeJobClass:
819 T = new tools::Clang(*this); break;
820 default:
821 assert(false && "Unsupported action for TCE target.");
822 }
823 }
824 return *T;
825}
826
827DerivedArgList *TCEToolChain::TranslateArgs(InputArgList &Args,
828 const char *BoundArch) const {
829 return new DerivedArgList(Args, true);
830}
831
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000832/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
833
834OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
835 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000836 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000837 getFilePaths().push_back("/usr/lib");
838}
839
840Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
841 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000842 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000843 Key = Action::AnalyzeJobClass;
844 else
845 Key = JA.getKind();
846
847 Tool *&T = Tools[Key];
848 if (!T) {
849 switch (Key) {
850 case Action::AssembleJobClass:
851 T = new tools::openbsd::Assemble(*this); break;
852 case Action::LinkJobClass:
853 T = new tools::openbsd::Link(*this); break;
854 default:
855 T = &Generic_GCC::SelectTool(C, JA);
856 }
857 }
858
859 return *T;
860}
861
Daniel Dunbar75358d22009-03-30 21:06:03 +0000862/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
863
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000864FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
865 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000866 if (Lib32) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000867 getFilePaths().push_back(getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000868 getFilePaths().push_back("/usr/lib32");
869 } else {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000870 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000871 getFilePaths().push_back("/usr/lib");
872 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000873}
874
875Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
876 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000877 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000878 Key = Action::AnalyzeJobClass;
879 else
880 Key = JA.getKind();
881
882 Tool *&T = Tools[Key];
883 if (!T) {
884 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000885 case Action::AssembleJobClass:
886 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000887 case Action::LinkJobClass:
888 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000889 default:
890 T = &Generic_GCC::SelectTool(C, JA);
891 }
892 }
893
894 return *T;
895}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000896
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000897/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
898
899AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
900 : Generic_GCC(Host, Triple) {
901
Daniel Dunbaree788e72009-12-21 18:54:17 +0000902 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000903
Daniel Dunbaree788e72009-12-21 18:54:17 +0000904 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000905 getFilePaths().push_back("/usr/lib");
906 getFilePaths().push_back("/usr/sfw/lib");
907 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +0000908 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000909
910}
911
912Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
913 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000914 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000915 Key = Action::AnalyzeJobClass;
916 else
917 Key = JA.getKind();
918
919 Tool *&T = Tools[Key];
920 if (!T) {
921 switch (Key) {
922 case Action::AssembleJobClass:
923 T = new tools::auroraux::Assemble(*this); break;
924 case Action::LinkJobClass:
925 T = new tools::auroraux::Link(*this); break;
926 default:
927 T = &Generic_GCC::SelectTool(C, JA);
928 }
929 }
930
931 return *T;
932}
933
934
Eli Friedman6b3454a2009-05-26 07:52:18 +0000935/// Linux toolchain (very bare-bones at the moment).
936
937Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
938 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000939 getFilePaths().push_back(getDriver().Dir + "/../lib/clang/1.0/");
Eli Friedman6b3454a2009-05-26 07:52:18 +0000940 getFilePaths().push_back("/lib/");
941 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000942
943 // Depending on the Linux distribution, any combination of lib{,32,64} is
944 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
945 // openSUSE uses lib and lib64 for the same purpose.
946 getFilePaths().push_back("/lib32/");
947 getFilePaths().push_back("/usr/lib32/");
948 getFilePaths().push_back("/lib64/");
949 getFilePaths().push_back("/usr/lib64/");
950
Eli Friedman6b3454a2009-05-26 07:52:18 +0000951 // FIXME: Figure out some way to get gcc's libdir
952 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
953 // crtbegin.o/crtend.o/etc., and want static versions of various
954 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
955 // get away with using shared versions in /usr/lib, though.
956 // We could fall back to the approach we used for includes (a massive
957 // list), but that's messy at best.
958}
959
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000960/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
961
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000962DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
963 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000964
965 // Path mangling to find libexec
Daniel Dunbaree788e72009-12-21 18:54:17 +0000966 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000967
Daniel Dunbaree788e72009-12-21 18:54:17 +0000968 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000969 getFilePaths().push_back("/usr/lib");
970 getFilePaths().push_back("/usr/lib/gcc41");
971}
972
973Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
974 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000975 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000976 Key = Action::AnalyzeJobClass;
977 else
978 Key = JA.getKind();
979
980 Tool *&T = Tools[Key];
981 if (!T) {
982 switch (Key) {
983 case Action::AssembleJobClass:
984 T = new tools::dragonfly::Assemble(*this); break;
985 case Action::LinkJobClass:
986 T = new tools::dragonfly::Link(*this); break;
987 default:
988 T = &Generic_GCC::SelectTool(C, JA);
989 }
990 }
991
992 return *T;
993}