blob: 9417a99786912ac349580bfa63146704b988d954 [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"
Douglas Gregor34916db2010-09-03 17:16:03 +000021#include "clang/Basic/Version.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000022
Daniel Dunbar00577ad2010-08-23 22:35:37 +000023#include "llvm/ADT/SmallString.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000024#include "llvm/ADT/StringExtras.h"
Daniel Dunbar84ec96c2009-09-09 22:33:15 +000025#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000026#include "llvm/Support/raw_ostream.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000027#include "llvm/System/Path.h"
28
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000029#include <cstdlib> // ::getenv
30
Daniel Dunbar39176082009-03-20 00:20:03 +000031using namespace clang::driver;
32using namespace clang::driver::toolchains;
33
Daniel Dunbarf3955282009-09-04 18:34:51 +000034/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000035
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000036Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcc8e1892010-01-27 00:56:44 +000037 : ToolChain(Host, Triple), TargetInitialized(false)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000038{
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000039 // Compute the initial Darwin version based on the host.
40 bool HadExtra;
41 std::string OSName = Triple.getOSName();
42 if (!Driver::GetReleaseVersion(&OSName[6],
43 DarwinVersion[0], DarwinVersion[1],
44 DarwinVersion[2], HadExtra))
45 getDriver().Diag(clang::diag::err_drv_invalid_darwin_version) << OSName;
46
Daniel Dunbar02633b52009-03-26 16:23:12 +000047 llvm::raw_string_ostream(MacosxVersionMin)
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000048 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.'
49 << DarwinVersion[1];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000050}
51
Daniel Dunbar41800112010-08-02 05:43:56 +000052types::ID Darwin::LookupTypeForExtension(const char *Ext) const {
53 types::ID Ty = types::lookupTypeForExtension(Ext);
54
55 // Darwin always preprocesses assembly files (unless -x is used explicitly).
56 if (Ty == types::TY_PP_Asm)
57 return types::TY_Asm;
58
59 return Ty;
60}
61
Daniel Dunbarb993f5d2010-09-17 00:24:52 +000062bool Darwin::HasNativeLLVMSupport() const {
63 return true;
64}
65
Daniel Dunbareeff4062010-01-22 02:04:58 +000066// FIXME: Can we tablegen this?
67static const char *GetArmArchForMArch(llvm::StringRef Value) {
68 if (Value == "armv6k")
69 return "armv6";
70
71 if (Value == "armv5tej")
72 return "armv5";
73
74 if (Value == "xscale")
75 return "xscale";
76
77 if (Value == "armv4t")
78 return "armv4t";
79
80 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
81 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
82 Value == "armv7m")
83 return "armv7";
84
85 return 0;
86}
87
88// FIXME: Can we tablegen this?
89static const char *GetArmArchForMCpu(llvm::StringRef Value) {
90 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
91 Value == "arm946e-s" || Value == "arm966e-s" ||
92 Value == "arm968e-s" || Value == "arm10e" ||
93 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
94 Value == "arm1026ej-s")
95 return "armv5";
96
97 if (Value == "xscale")
98 return "xscale";
99
100 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
101 Value == "arm1176jz-s" || Value == "arm1176jzf-s")
102 return "armv6";
103
104 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
105 return "armv7";
106
107 return 0;
108}
109
110llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
111 switch (getTriple().getArch()) {
112 default:
113 return getArchName();
114
115 case llvm::Triple::arm: {
116 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
117 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
118 return Arch;
119
120 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
121 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
122 return Arch;
123
124 return "arm";
125 }
126 }
127}
128
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000129DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple)
130 : Darwin(Host, Triple)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000131{
Daniel Dunbarc2bda622010-08-02 05:44:01 +0000132 // We can only work with 4.2.1 currently.
133 GCCVersion[0] = 4;
134 GCCVersion[1] = 2;
135 GCCVersion[2] = 1;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000136
137 // Set up the tool chain paths to match gcc.
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000138 ToolChainDir = "i686-apple-darwin";
Ted Kremenek55bac532009-10-07 03:21:11 +0000139 ToolChainDir += llvm::utostr(DarwinVersion[0]);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000140 ToolChainDir += "/";
141 ToolChainDir += llvm::utostr(GCCVersion[0]);
142 ToolChainDir += '.';
143 ToolChainDir += llvm::utostr(GCCVersion[1]);
144 ToolChainDir += '.';
145 ToolChainDir += llvm::utostr(GCCVersion[2]);
146
Daniel Dunbar74782b02009-10-20 19:25:43 +0000147 // Try the next major version if that tool chain dir is invalid.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000148 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir;
149 if (!llvm::sys::Path(Tmp).exists()) {
Daniel Dunbar74782b02009-10-20 19:25:43 +0000150 std::string Next = "i686-apple-darwin";
151 Next += llvm::utostr(DarwinVersion[0] + 1);
152 Next += "/";
153 Next += llvm::utostr(GCCVersion[0]);
154 Next += '.';
155 Next += llvm::utostr(GCCVersion[1]);
156 Next += '.';
157 Next += llvm::utostr(GCCVersion[2]);
158
159 // Use that if it exists, otherwise hope the user isn't linking.
160 //
161 // FIXME: Drop dependency on gcc's tool chain.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000162 Tmp = "/usr/lib/gcc/" + Next;
163 if (llvm::sys::Path(Tmp).exists())
Daniel Dunbar74782b02009-10-20 19:25:43 +0000164 ToolChainDir = Next;
165 }
166
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000167 std::string Path;
168 if (getArchName() == "x86_64") {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000169 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000170 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000171 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000172 Path += "/x86_64";
173 getFilePaths().push_back(Path);
174
175 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000176 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000177 Path += "/x86_64";
178 getFilePaths().push_back(Path);
179 }
Mike Stump1eb44332009-09-09 15:08:12 +0000180
Daniel Dunbaree788e72009-12-21 18:54:17 +0000181 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000182 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000183 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000184 getFilePaths().push_back(Path);
185
186 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000187 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000188 getFilePaths().push_back(Path);
189
Daniel Dunbaree788e72009-12-21 18:54:17 +0000190 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000191 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000192 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000193 getProgramPaths().push_back(Path);
194
195 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000196 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000197 getProgramPaths().push_back(Path);
198
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000199 getProgramPaths().push_back(getDriver().getInstalledDir());
200 if (getDriver().getInstalledDir() != getDriver().Dir)
201 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000202}
203
Daniel Dunbarf3955282009-09-04 18:34:51 +0000204Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000205 // Free tool implementations.
206 for (llvm::DenseMap<unsigned, Tool*>::iterator
207 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
208 delete it->second;
209}
210
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000211std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args) const {
212 llvm::Triple Triple(ComputeLLVMTriple(Args));
213
214 // If the target isn't initialized (e.g., an unknown Darwin platform, return
215 // the default triple).
216 if (!isTargetInitialized())
217 return Triple.getTriple();
218
219 unsigned Version[3];
220 getTargetVersion(Version);
221
222 // Mangle the target version into the OS triple component. For historical
223 // reasons that make little sense, the version passed here is the "darwin"
224 // version, which drops the 10 and offsets by 4. See inverse code when
225 // setting the OS version preprocessor define.
226 if (!isTargetIPhoneOS()) {
227 Version[0] = Version[1] + 4;
228 Version[1] = Version[2];
229 Version[2] = 0;
230 } else {
231 // Use the environment to communicate that we are targetting iPhoneOS.
232 Triple.setEnvironmentName("iphoneos");
233 }
234
235 llvm::SmallString<16> Str;
236 llvm::raw_svector_ostream(Str) << "darwin" << Version[0]
237 << "." << Version[1] << "." << Version[2];
238 Triple.setOSName(Str.str());
239
240 return Triple.getTriple();
241}
242
Daniel Dunbarf3955282009-09-04 18:34:51 +0000243Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000244 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000245 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000246 Key = Action::AnalyzeJobClass;
247 else
248 Key = JA.getKind();
249
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000250 // FIXME: This doesn't belong here, but ideally we will support static soon
251 // anyway.
252 bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) ||
253 C.getArgs().hasArg(options::OPT_static) ||
254 C.getArgs().hasArg(options::OPT_fapple_kext));
255 bool IsIADefault = IsIntegratedAssemblerDefault() && !HasStatic;
256 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
257 options::OPT_no_integrated_as,
258 IsIADefault);
259
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000260 Tool *&T = Tools[Key];
261 if (!T) {
262 switch (Key) {
263 case Action::InputClass:
264 case Action::BindArchClass:
265 assert(0 && "Invalid tool kind.");
266 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000267 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000268 case Action::AnalyzeJobClass:
269 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000270 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000271 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000272 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000273 case Action::AssembleJobClass: {
274 if (UseIntegratedAs)
275 T = new tools::ClangAs(*this);
276 else
277 T = new tools::darwin::Assemble(*this);
278 break;
279 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000280 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000281 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000282 case Action::LipoJobClass:
283 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000284 case Action::DsymutilJobClass:
285 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000286 }
287 }
288
289 return *T;
290}
291
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000292void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
293 ArgStringList &CmdArgs) const {
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000294 std::string Tmp;
295
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000296 // FIXME: Derive these correctly.
297 if (getArchName() == "x86_64") {
298 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
299 "/x86_64"));
300 // Intentionally duplicated for (temporary) gcc bug compatibility.
301 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
302 "/x86_64"));
303 }
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000304
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000305 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000306
307 Tmp = getDriver().Dir + "/../lib/gcc/" + ToolChainDir;
308 if (llvm::sys::Path(Tmp).exists())
309 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
310 Tmp = getDriver().Dir + "/../lib/gcc";
311 if (llvm::sys::Path(Tmp).exists())
312 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000313 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
314 // Intentionally duplicated for (temporary) gcc bug compatibility.
315 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000316 Tmp = getDriver().Dir + "/../lib/" + ToolChainDir;
317 if (llvm::sys::Path(Tmp).exists())
318 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
319 Tmp = getDriver().Dir + "/../lib";
320 if (llvm::sys::Path(Tmp).exists())
321 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000322 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
323 "/../../../" + ToolChainDir));
324 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
325 "/../../.."));
326}
327
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000328void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
329 ArgStringList &CmdArgs) const {
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000330 // Note that this routine is only used for targetting OS X.
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000331
332 // Derived from libgcc and lib specs but refactored.
333 if (Args.hasArg(options::OPT_static)) {
334 CmdArgs.push_back("-lgcc_static");
335 } else {
336 if (Args.hasArg(options::OPT_static_libgcc)) {
337 CmdArgs.push_back("-lgcc_eh");
338 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
339 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000340 if (isTargetIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000341 CmdArgs.push_back("-lgcc_s.1");
342 } else {
343 CmdArgs.push_back("-lgcc_s.10.5");
344 }
345 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
Daniel Dunbar8a0d94d2010-01-10 00:46:10 +0000346 Args.hasFlag(options::OPT_fexceptions,
347 options::OPT_fno_exceptions) ||
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000348 Args.hasArg(options::OPT_fgnu_runtime)) {
349 // FIXME: This is probably broken on 10.3?
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000350 if (isMacosxVersionLT(10, 5))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000351 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000352 else if (isMacosxVersionLT(10, 6))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000353 CmdArgs.push_back("-lgcc_s.10.5");
354 } else {
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000355 if (isMacosxVersionLT(10, 3, 9))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000356 ; // Do nothing.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000357 else if (isMacosxVersionLT(10, 5))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000358 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000359 else if (isMacosxVersionLT(10, 6))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000360 CmdArgs.push_back("-lgcc_s.10.5");
361 }
362
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000363 if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000364 CmdArgs.push_back("-lgcc");
365 CmdArgs.push_back("-lSystem");
366 } else {
367 CmdArgs.push_back("-lSystem");
368 CmdArgs.push_back("-lgcc");
369 }
370 }
371}
372
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000373DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple)
374 : Darwin(Host, Triple)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000375{
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000376 getProgramPaths().push_back(getDriver().getInstalledDir());
377 if (getDriver().getInstalledDir() != getDriver().Dir)
378 getProgramPaths().push_back(getDriver().Dir);
379
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000380 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000381 getProgramPaths().push_back(getDriver().getInstalledDir());
382 if (getDriver().getInstalledDir() != getDriver().Dir)
383 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000384
385 // For fallback, we need to know how to find the GCC cc1 executables, so we
386 // also add the GCC libexec paths. This is legiy code that can be removed once
387 // fallback is no longer useful.
388 std::string ToolChainDir = "i686-apple-darwin";
389 ToolChainDir += llvm::utostr(DarwinVersion[0]);
390 ToolChainDir += "/4.2.1";
391
392 std::string Path = getDriver().Dir;
393 Path += "/../libexec/gcc/";
394 Path += ToolChainDir;
395 getProgramPaths().push_back(Path);
396
397 Path = "/usr/libexec/gcc/";
398 Path += ToolChainDir;
399 getProgramPaths().push_back(Path);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000400}
401
402void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
403 ArgStringList &CmdArgs) const {
404 // The Clang toolchain uses explicit paths for internal libraries.
Daniel Dunbar424b6612010-06-30 23:56:13 +0000405
406 // Unfortunately, we still might depend on a few of the libraries that are
407 // only available in the gcc library directory (in particular
408 // libstdc++.dylib). For now, hardcode the path to the known install location.
409 llvm::sys::Path P(getDriver().Dir);
410 P.eraseComponent(); // .../usr/bin -> ../usr
411 P.appendComponent("lib");
412 P.appendComponent("gcc");
413 switch (getTriple().getArch()) {
414 default:
415 assert(0 && "Invalid Darwin arch!");
416 case llvm::Triple::x86:
417 case llvm::Triple::x86_64:
418 P.appendComponent("i686-apple-darwin10");
419 break;
420 case llvm::Triple::arm:
421 case llvm::Triple::thumb:
422 P.appendComponent("arm-apple-darwin10");
423 break;
424 case llvm::Triple::ppc:
425 case llvm::Triple::ppc64:
426 P.appendComponent("powerpc-apple-darwin10");
427 break;
428 }
429 P.appendComponent("4.2.1");
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000430
431 // Determine the arch specific GCC subdirectory.
432 const char *ArchSpecificDir = 0;
433 switch (getTriple().getArch()) {
434 default:
435 break;
436 case llvm::Triple::arm:
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000437 case llvm::Triple::thumb: {
438 std::string Triple = ComputeLLVMTriple(Args);
439 llvm::StringRef TripleStr = Triple;
440 if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5"))
441 ArchSpecificDir = "v5";
442 else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6"))
443 ArchSpecificDir = "v6";
444 else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7"))
445 ArchSpecificDir = "v7";
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000446 break;
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000447 }
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000448 case llvm::Triple::ppc64:
449 ArchSpecificDir = "ppc64";
450 break;
451 case llvm::Triple::x86_64:
452 ArchSpecificDir = "x86_64";
453 break;
454 }
455
456 if (ArchSpecificDir) {
457 P.appendComponent(ArchSpecificDir);
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000458 if (P.exists())
459 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
460 P.eraseComponent();
461 }
462
Daniel Dunbar424b6612010-06-30 23:56:13 +0000463 if (P.exists())
464 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000465}
466
467void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
468 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000469 // Darwin doesn't support real static executables, don't link any runtime
470 // libraries with -static.
471 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000472 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000473
474 // Reject -static-libgcc for now, we can deal with this when and if someone
475 // cares. This is useful in situations where someone wants to statically link
476 // something like libstdc++, and needs its runtime support routines.
477 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000478 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000479 << A->getAsString(Args);
480 return;
481 }
482
Daniel Dunbareec99102010-01-22 03:38:14 +0000483 // Otherwise link libSystem, then the dynamic runtime library, and finally any
484 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000485 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000486
487 // Select the dynamic runtime library and the target specific static library.
488 const char *DarwinStaticLib = 0;
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000489 if (isTargetIPhoneOS()) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000490 CmdArgs.push_back("-lgcc_s.1");
491
492 // We may need some static functions for armv6/thumb which are required to
493 // be in the same linkage unit as their caller.
494 if (getDarwinArchName(Args) == "armv6")
495 DarwinStaticLib = "libclang_rt.armv6.a";
496 } else {
Daniel Dunbareec99102010-01-22 03:38:14 +0000497 // The dynamic runtime library was merged with libSystem for 10.6 and
498 // beyond; only 10.4 and 10.5 need an additional runtime library.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000499 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000500 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000501 else if (isMacosxVersionLT(10, 6))
Daniel Dunbareec99102010-01-22 03:38:14 +0000502 CmdArgs.push_back("-lgcc_s.10.5");
503
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000504 // For OS X, we thought we would only need a static runtime library when
505 // targetting 10.4, to provide versions of the static functions which were
506 // omitted from 10.4.dylib.
507 //
508 // Unfortunately, that turned out to not be true, because Darwin system
509 // headers can still use eprintf on i386, and it is not exported from
510 // libSystem. Therefore, we still must provide a runtime library just for
511 // the tiny tiny handful of projects that *might* use that symbol.
512 if (isMacosxVersionLT(10, 5)) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000513 DarwinStaticLib = "libclang_rt.10.4.a";
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000514 } else {
515 if (getTriple().getArch() == llvm::Triple::x86)
516 DarwinStaticLib = "libclang_rt.eprintf.a";
517 }
Daniel Dunbareec99102010-01-22 03:38:14 +0000518 }
519
520 /// Add the target specific static library, if needed.
521 if (DarwinStaticLib) {
522 llvm::sys::Path P(getDriver().ResourceDir);
523 P.appendComponent("lib");
524 P.appendComponent("darwin");
525 P.appendComponent(DarwinStaticLib);
526
527 // For now, allow missing resource libraries to support developers who may
528 // not have compiler-rt checked out or integrated into their build.
Daniel Dunbar362ed702010-10-11 23:31:07 +0000529 if (P.exists())
Daniel Dunbareec99102010-01-22 03:38:14 +0000530 CmdArgs.push_back(Args.MakeArgString(P.str()));
531 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000532}
533
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000534void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000535 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000536
Daniel Dunbar26031372010-01-27 00:56:25 +0000537 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
538 Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000539 if (OSXVersion && iPhoneVersion) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000540 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000541 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000542 << iPhoneVersion->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000543 iPhoneVersion = 0;
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000544 } else if (!OSXVersion && !iPhoneVersion) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000545 // If neither OS X nor iPhoneOS targets were specified, check for
546 // environment defines.
547 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
548 const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000549
Daniel Dunbar816bc312010-01-26 01:45:19 +0000550 // Ignore empty strings.
551 if (OSXTarget && OSXTarget[0] == '\0')
552 OSXTarget = 0;
553 if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0')
554 iPhoneOSTarget = 0;
555
Daniel Dunbar39053672010-02-02 17:31:12 +0000556 // Diagnose conflicting deployment targets, and choose default platform
557 // based on the tool chain.
558 //
559 // FIXME: Don't hardcode default here.
560 if (OSXTarget && iPhoneOSTarget) {
561 // FIXME: We should see if we can get away with warning or erroring on
562 // this. Perhaps put under -pedantic?
563 if (getTriple().getArch() == llvm::Triple::arm ||
564 getTriple().getArch() == llvm::Triple::thumb)
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000565 OSXTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000566 else
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000567 iPhoneOSTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000568 }
Daniel Dunbar1a3c1d92010-01-29 17:02:25 +0000569
Daniel Dunbar39053672010-02-02 17:31:12 +0000570 if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000571 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000572 OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget);
573 Args.append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000574 } else if (iPhoneOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000575 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000576 iPhoneVersion = Args.MakeJoinedArg(0, O, iPhoneOSTarget);
577 Args.append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000578 } else {
Daniel Dunbar2bb38d02010-07-15 16:18:06 +0000579 // Otherwise, assume we are targeting OS X.
580 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000581 OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin);
582 Args.append(OSXVersion);
Daniel Dunbar30392de2009-09-04 18:35:21 +0000583 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000584 }
Mike Stump1eb44332009-09-09 15:08:12 +0000585
Daniel Dunbar26031372010-01-27 00:56:25 +0000586 // Set the tool chain target information.
587 unsigned Major, Minor, Micro;
588 bool HadExtra;
589 if (OSXVersion) {
590 assert(!iPhoneVersion && "Unknown target platform!");
591 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
592 Micro, HadExtra) || HadExtra ||
593 Major != 10 || Minor >= 10 || Micro >= 10)
594 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
595 << OSXVersion->getAsString(Args);
596 } else {
597 assert(iPhoneVersion && "Unknown target platform!");
598 if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor,
599 Micro, HadExtra) || HadExtra ||
600 Major >= 10 || Minor >= 100 || Micro >= 100)
601 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
602 << iPhoneVersion->getAsString(Args);
603 }
604 setTarget(iPhoneVersion, Major, Minor, Micro);
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000605}
606
Daniel Dunbar132e35d2010-09-17 01:20:05 +0000607void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args,
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000608 ArgStringList &CmdArgs) const {
609 CXXStdlibType Type = GetCXXStdlibType(Args);
610
611 switch (Type) {
612 case ToolChain::CST_Libcxx:
613 CmdArgs.push_back("-lc++");
614 break;
615
616 case ToolChain::CST_Libstdcxx: {
617 // Unfortunately, -lstdc++ doesn't always exist in the standard search path;
618 // it was previously found in the gcc lib dir. However, for all the Darwin
619 // platforms we care about it was -lstdc++.6, so we search for that
620 // explicitly if we can't see an obvious -lstdc++ candidate.
621
622 // Check in the sysroot first.
623 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
624 llvm::sys::Path P(A->getValue(Args));
625 P.appendComponent("usr");
626 P.appendComponent("lib");
627 P.appendComponent("libstdc++.dylib");
628
629 if (!P.exists()) {
630 P.eraseComponent();
631 P.appendComponent("libstdc++.6.dylib");
632 if (P.exists()) {
633 CmdArgs.push_back(Args.MakeArgString(P.str()));
634 return;
635 }
636 }
637 }
638
639 // Otherwise, look in the root.
640 if (!llvm::sys::Path("/usr/lib/libstdc++.dylib").exists() &&
641 llvm::sys::Path("/usr/lib/libstdc++.6.dylib").exists()) {
642 CmdArgs.push_back("/usr/lib/libstdc++.6.dylib");
643 return;
644 }
645
646 // Otherwise, let the linker search.
647 CmdArgs.push_back("-lstdc++");
648 break;
649 }
650 }
651}
652
Shantonu Sen7433fed2010-09-17 18:39:08 +0000653void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
654 ArgStringList &CmdArgs) const {
655
656 // For Darwin platforms, use the compiler-rt-based support library
657 // instead of the gcc-provided one (which is also incidentally
658 // only present in the gcc lib dir, which makes it hard to find).
659
660 llvm::sys::Path P(getDriver().ResourceDir);
661 P.appendComponent("lib");
662 P.appendComponent("darwin");
663 P.appendComponent("libclang_rt.cc_kext.a");
664
665 // For now, allow missing resource libraries to support developers who may
666 // not have compiler-rt checked out or integrated into their build.
Daniel Dunbar362ed702010-10-11 23:31:07 +0000667 if (P.exists())
Shantonu Sen7433fed2010-09-17 18:39:08 +0000668 CmdArgs.push_back(Args.MakeArgString(P.str()));
669}
670
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000671DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
672 const char *BoundArch) const {
673 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
674 const OptTable &Opts = getDriver().getOpts();
675
676 // FIXME: We really want to get out of the tool chain level argument
677 // translation business, as it makes the driver functionality much
678 // more opaque. For now, we follow gcc closely solely for the
679 // purpose of easily achieving feature parity & testability. Once we
680 // have something that works, we should reevaluate each translation
681 // and try to push it down into tool specific logic.
Daniel Dunbar26031372010-01-27 00:56:25 +0000682
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000683 for (ArgList::const_iterator it = Args.begin(),
684 ie = Args.end(); it != ie; ++it) {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000685 Arg *A = *it;
686
687 if (A->getOption().matches(options::OPT_Xarch__)) {
688 // FIXME: Canonicalize name.
689 if (getArchName() != A->getValue(Args, 0))
690 continue;
691
Daniel Dunbar0e100312010-06-14 21:23:08 +0000692 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1));
693 unsigned Prev = Index;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000694 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000695
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000696 // If the argument parsing failed or more than one argument was
697 // consumed, the -Xarch_ argument's parameter tried to consume
698 // extra arguments. Emit an error and ignore.
699 //
700 // We also want to disallow any options which would alter the
701 // driver behavior; that isn't going to work in our model. We
702 // use isDriverOption() as an approximation, although things
703 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000704 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000705 XarchArg->getOption().isDriverOption()) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000706 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000707 << A->getAsString(Args);
708 continue;
709 }
710
Daniel Dunbar478edc22009-03-29 22:29:05 +0000711 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000712 A = XarchArg;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000713
714 DAL->AddSynthesizedArg(A);
Mike Stump1eb44332009-09-09 15:08:12 +0000715 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000716
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000717 // Sob. These is strictly gcc compatible for the time being. Apple
718 // gcc translates options twice, which means that self-expanding
719 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000720 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000721 default:
722 DAL->append(A);
723 break;
724
725 case options::OPT_mkernel:
726 case options::OPT_fapple_kext:
727 DAL->append(A);
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000728 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
729 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000730 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000732 case options::OPT_dependency_file:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000733 DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF),
734 A->getValue(Args));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000735 break;
736
737 case options::OPT_gfull:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000738 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
739 DAL->AddFlagArg(A,
740 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000741 break;
742
743 case options::OPT_gused:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000744 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
745 DAL->AddFlagArg(A,
746 Opts.getOption(options::OPT_feliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000747 break;
748
749 case options::OPT_fterminated_vtables:
750 case options::OPT_findirect_virtual_calls:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000751 DAL->AddFlagArg(A, Opts.getOption(options::OPT_fapple_kext));
752 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000753 break;
754
755 case options::OPT_shared:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000756 DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000757 break;
758
759 case options::OPT_fconstant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000760 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000761 break;
762
763 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000764 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000765 break;
766
767 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000768 DAL->AddFlagArg(A,
769 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000770 break;
771
772 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000773 DAL->AddFlagArg(A,
774 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000775 break;
776
777 case options::OPT_fpascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000778 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000779 break;
780
781 case options::OPT_fno_pascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000782 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000783 break;
784 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000785 }
786
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000787 if (getTriple().getArch() == llvm::Triple::x86 ||
788 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000789 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000790 DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000791
792 // Add the arch options based on the particular spelling of -arch, to match
793 // how the driver driver works.
794 if (BoundArch) {
795 llvm::StringRef Name = BoundArch;
796 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
797 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
798
799 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
800 // which defines the list of which architectures we accept.
801 if (Name == "ppc")
802 ;
803 else if (Name == "ppc601")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000804 DAL->AddJoinedArg(0, MCpu, "601");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000805 else if (Name == "ppc603")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000806 DAL->AddJoinedArg(0, MCpu, "603");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000807 else if (Name == "ppc604")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000808 DAL->AddJoinedArg(0, MCpu, "604");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000809 else if (Name == "ppc604e")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000810 DAL->AddJoinedArg(0, MCpu, "604e");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000811 else if (Name == "ppc750")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000812 DAL->AddJoinedArg(0, MCpu, "750");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000813 else if (Name == "ppc7400")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000814 DAL->AddJoinedArg(0, MCpu, "7400");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000815 else if (Name == "ppc7450")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000816 DAL->AddJoinedArg(0, MCpu, "7450");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000817 else if (Name == "ppc970")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000818 DAL->AddJoinedArg(0, MCpu, "970");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000819
820 else if (Name == "ppc64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000821 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000822
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000823 else if (Name == "i386")
824 ;
825 else if (Name == "i486")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000826 DAL->AddJoinedArg(0, MArch, "i486");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000827 else if (Name == "i586")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000828 DAL->AddJoinedArg(0, MArch, "i586");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000829 else if (Name == "i686")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000830 DAL->AddJoinedArg(0, MArch, "i686");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000831 else if (Name == "pentium")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000832 DAL->AddJoinedArg(0, MArch, "pentium");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000833 else if (Name == "pentium2")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000834 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000835 else if (Name == "pentpro")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000836 DAL->AddJoinedArg(0, MArch, "pentiumpro");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000837 else if (Name == "pentIIm3")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000838 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000839
840 else if (Name == "x86_64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000841 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000842
843 else if (Name == "arm")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000844 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000845 else if (Name == "armv4t")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000846 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000847 else if (Name == "armv5")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000848 DAL->AddJoinedArg(0, MArch, "armv5tej");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000849 else if (Name == "xscale")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000850 DAL->AddJoinedArg(0, MArch, "xscale");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000851 else if (Name == "armv6")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000852 DAL->AddJoinedArg(0, MArch, "armv6k");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000853 else if (Name == "armv7")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000854 DAL->AddJoinedArg(0, MArch, "armv7a");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000855
856 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000857 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000858 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000859
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000860 // Add an explicit version min argument for the deployment target. We do this
861 // after argument translation because -Xarch_ arguments may add a version min
862 // argument.
863 AddDeploymentTarget(*DAL);
864
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000865 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000866}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000867
Daniel Dunbarf3955282009-09-04 18:34:51 +0000868bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000869 // FIXME: Gross; we should probably have some separate target
870 // definition, possibly even reusing the one in clang.
871 return getArchName() == "x86_64";
872}
873
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000874bool Darwin::UseDwarfDebugFlags() const {
875 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
876 return S[0] != '\0';
877 return false;
878}
879
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000880bool Darwin::UseSjLjExceptions() const {
881 // Darwin uses SjLj exceptions on ARM.
882 return (getTriple().getArch() == llvm::Triple::arm ||
883 getTriple().getArch() == llvm::Triple::thumb);
884}
885
Daniel Dunbarf3955282009-09-04 18:34:51 +0000886const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000887 return "pic";
888}
889
Daniel Dunbarf3955282009-09-04 18:34:51 +0000890const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000891 if (getArchName() == "x86_64")
892 return "pic";
893 return 0;
894}
895
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000896bool Darwin::SupportsObjCGC() const {
897 // Garbage collection is supported everywhere except on iPhone OS.
898 return !isTargetIPhoneOS();
899}
900
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000901std::string
902Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const {
903 return ComputeLLVMTriple(Args);
904}
905
Daniel Dunbar39176082009-03-20 00:20:03 +0000906/// Generic_GCC - A tool chain using the 'gcc' command to perform
907/// all subcommands; this relies on gcc translating the majority of
908/// command line options.
909
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000910Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000911 : ToolChain(Host, Triple) {
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000912 getProgramPaths().push_back(getDriver().getInstalledDir());
913 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
914 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000915}
916
Daniel Dunbar39176082009-03-20 00:20:03 +0000917Generic_GCC::~Generic_GCC() {
918 // Free tool implementations.
919 for (llvm::DenseMap<unsigned, Tool*>::iterator
920 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
921 delete it->second;
922}
923
Mike Stump1eb44332009-09-09 15:08:12 +0000924Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000925 const JobAction &JA) const {
926 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000927 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000928 Key = Action::AnalyzeJobClass;
929 else
930 Key = JA.getKind();
931
932 Tool *&T = Tools[Key];
933 if (!T) {
934 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000935 case Action::InputClass:
936 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000937 assert(0 && "Invalid tool kind.");
938 case Action::PreprocessJobClass:
939 T = new tools::gcc::Preprocess(*this); break;
940 case Action::PrecompileJobClass:
941 T = new tools::gcc::Precompile(*this); break;
942 case Action::AnalyzeJobClass:
943 T = new tools::Clang(*this); break;
944 case Action::CompileJobClass:
945 T = new tools::gcc::Compile(*this); break;
946 case Action::AssembleJobClass:
947 T = new tools::gcc::Assemble(*this); break;
948 case Action::LinkJobClass:
949 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000950
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000951 // This is a bit ungeneric, but the only platform using a driver
952 // driver is Darwin.
953 case Action::LipoJobClass:
954 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000955 case Action::DsymutilJobClass:
956 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000957 }
958 }
959
960 return *T;
961}
962
Daniel Dunbar39176082009-03-20 00:20:03 +0000963bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000964 // FIXME: Gross; we should probably have some separate target
965 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000966 return getArchName() == "x86_64";
967}
968
969const char *Generic_GCC::GetDefaultRelocationModel() const {
970 return "static";
971}
972
973const char *Generic_GCC::GetForcedPicModel() const {
974 return 0;
975}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000976
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000977/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
978/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
979/// Currently does not support anything else but compilation.
980
981TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple)
982 : ToolChain(Host, Triple) {
983 // Path mangling to find libexec
984 std::string Path(getDriver().Dir);
985
986 Path += "/../libexec";
987 getProgramPaths().push_back(Path);
988}
989
990TCEToolChain::~TCEToolChain() {
991 for (llvm::DenseMap<unsigned, Tool*>::iterator
992 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
993 delete it->second;
994}
995
996bool TCEToolChain::IsMathErrnoDefault() const {
997 return true;
998}
999
1000bool TCEToolChain::IsUnwindTablesDefault() const {
1001 return false;
1002}
1003
1004const char *TCEToolChain::GetDefaultRelocationModel() const {
1005 return "static";
1006}
1007
1008const char *TCEToolChain::GetForcedPicModel() const {
1009 return 0;
1010}
1011
1012Tool &TCEToolChain::SelectTool(const Compilation &C,
1013 const JobAction &JA) const {
1014 Action::ActionClass Key;
1015 Key = Action::AnalyzeJobClass;
1016
1017 Tool *&T = Tools[Key];
1018 if (!T) {
1019 switch (Key) {
1020 case Action::PreprocessJobClass:
1021 T = new tools::gcc::Preprocess(*this); break;
1022 case Action::AnalyzeJobClass:
1023 T = new tools::Clang(*this); break;
1024 default:
1025 assert(false && "Unsupported action for TCE target.");
1026 }
1027 }
1028 return *T;
1029}
1030
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001031/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
1032
1033OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
1034 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +00001035 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001036 getFilePaths().push_back("/usr/lib");
1037}
1038
1039Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
1040 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001041 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001042 Key = Action::AnalyzeJobClass;
1043 else
1044 Key = JA.getKind();
1045
1046 Tool *&T = Tools[Key];
1047 if (!T) {
1048 switch (Key) {
1049 case Action::AssembleJobClass:
1050 T = new tools::openbsd::Assemble(*this); break;
1051 case Action::LinkJobClass:
1052 T = new tools::openbsd::Link(*this); break;
1053 default:
1054 T = &Generic_GCC::SelectTool(C, JA);
1055 }
1056 }
1057
1058 return *T;
1059}
1060
Daniel Dunbar75358d22009-03-30 21:06:03 +00001061/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
1062
Daniel Dunbar214afe92010-08-02 05:43:59 +00001063FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +00001064 : Generic_GCC(Host, Triple) {
Daniel Dunbar214afe92010-08-02 05:43:59 +00001065
1066 // Determine if we are compiling 32-bit code on an x86_64 platform.
1067 bool Lib32 = false;
1068 if (Triple.getArch() == llvm::Triple::x86 &&
1069 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1070 llvm::Triple::x86_64)
1071 Lib32 = true;
1072
Daniel Dunbar7fb2c252010-06-15 15:03:31 +00001073 getProgramPaths().push_back(getDriver().Dir + "/../libexec");
1074 getProgramPaths().push_back("/usr/libexec");
Daniel Dunbarbc534662009-04-02 18:30:04 +00001075 if (Lib32) {
Daniel Dunbaree788e72009-12-21 18:54:17 +00001076 getFilePaths().push_back(getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +00001077 getFilePaths().push_back("/usr/lib32");
1078 } else {
Daniel Dunbaree788e72009-12-21 18:54:17 +00001079 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +00001080 getFilePaths().push_back("/usr/lib");
1081 }
Daniel Dunbar75358d22009-03-30 21:06:03 +00001082}
1083
1084Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
1085 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001086 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +00001087 Key = Action::AnalyzeJobClass;
1088 else
1089 Key = JA.getKind();
1090
1091 Tool *&T = Tools[Key];
1092 if (!T) {
1093 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +00001094 case Action::AssembleJobClass:
1095 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +00001096 case Action::LinkJobClass:
1097 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +00001098 default:
1099 T = &Generic_GCC::SelectTool(C, JA);
1100 }
1101 }
1102
1103 return *T;
1104}
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001105
Chris Lattner38e317d2010-07-07 16:01:42 +00001106/// Minix - Minix tool chain which can call as(1) and ld(1) directly.
1107
1108Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple)
1109 : Generic_GCC(Host, Triple) {
1110 getFilePaths().push_back(getDriver().Dir + "/../lib");
1111 getFilePaths().push_back("/usr/lib");
1112 getFilePaths().push_back("/usr/gnu/lib");
1113 getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
1114}
1115
1116Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA) const {
1117 Action::ActionClass Key;
1118 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1119 Key = Action::AnalyzeJobClass;
1120 else
1121 Key = JA.getKind();
1122
1123 Tool *&T = Tools[Key];
1124 if (!T) {
1125 switch (Key) {
1126 case Action::AssembleJobClass:
1127 T = new tools::minix::Assemble(*this); break;
1128 case Action::LinkJobClass:
1129 T = new tools::minix::Link(*this); break;
1130 default:
1131 T = &Generic_GCC::SelectTool(C, JA);
1132 }
1133 }
1134
1135 return *T;
1136}
1137
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001138/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
1139
1140AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
1141 : Generic_GCC(Host, Triple) {
1142
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001143 getProgramPaths().push_back(getDriver().getInstalledDir());
1144 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
1145 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001146
Daniel Dunbaree788e72009-12-21 18:54:17 +00001147 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001148 getFilePaths().push_back("/usr/lib");
1149 getFilePaths().push_back("/usr/sfw/lib");
1150 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +00001151 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001152
1153}
1154
1155Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
1156 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001157 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001158 Key = Action::AnalyzeJobClass;
1159 else
1160 Key = JA.getKind();
1161
1162 Tool *&T = Tools[Key];
1163 if (!T) {
1164 switch (Key) {
1165 case Action::AssembleJobClass:
1166 T = new tools::auroraux::Assemble(*this); break;
1167 case Action::LinkJobClass:
1168 T = new tools::auroraux::Link(*this); break;
1169 default:
1170 T = &Generic_GCC::SelectTool(C, JA);
1171 }
1172 }
1173
1174 return *T;
1175}
1176
1177
Eli Friedman6b3454a2009-05-26 07:52:18 +00001178/// Linux toolchain (very bare-bones at the moment).
1179
1180Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
1181 : Generic_GCC(Host, Triple) {
Chris Lattner3f2cc6f2010-09-03 16:47:03 +00001182 getFilePaths().push_back(getDriver().Dir +
1183 "/../lib/clang/" CLANG_VERSION_STRING "/");
Eli Friedman6b3454a2009-05-26 07:52:18 +00001184 getFilePaths().push_back("/lib/");
1185 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +00001186
1187 // Depending on the Linux distribution, any combination of lib{,32,64} is
1188 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
1189 // openSUSE uses lib and lib64 for the same purpose.
1190 getFilePaths().push_back("/lib32/");
1191 getFilePaths().push_back("/usr/lib32/");
1192 getFilePaths().push_back("/lib64/");
1193 getFilePaths().push_back("/usr/lib64/");
1194
Eli Friedman6b3454a2009-05-26 07:52:18 +00001195 // FIXME: Figure out some way to get gcc's libdir
1196 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
1197 // crtbegin.o/crtend.o/etc., and want static versions of various
1198 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
1199 // get away with using shared versions in /usr/lib, though.
1200 // We could fall back to the approach we used for includes (a massive
1201 // list), but that's messy at best.
1202}
1203
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001204Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA) const {
1205 Action::ActionClass Key;
1206 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1207 Key = Action::AnalyzeJobClass;
1208 else
1209 Key = JA.getKind();
1210
1211 Tool *&T = Tools[Key];
1212 if (!T) {
1213 switch (Key) {
1214 case Action::AssembleJobClass:
1215 T = new tools::linuxtools::Assemble(*this); break;
1216 default:
1217 T = &Generic_GCC::SelectTool(C, JA);
1218 }
1219 }
1220
1221 return *T;
1222}
1223
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001224/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
1225
Daniel Dunbarcb8ab232009-05-22 02:53:45 +00001226DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
1227 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001228
1229 // Path mangling to find libexec
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001230 getProgramPaths().push_back(getDriver().getInstalledDir());
1231 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
1232 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001233
Daniel Dunbaree788e72009-12-21 18:54:17 +00001234 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001235 getFilePaths().push_back("/usr/lib");
1236 getFilePaths().push_back("/usr/lib/gcc41");
1237}
1238
1239Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
1240 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001241 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001242 Key = Action::AnalyzeJobClass;
1243 else
1244 Key = JA.getKind();
1245
1246 Tool *&T = Tools[Key];
1247 if (!T) {
1248 switch (Key) {
1249 case Action::AssembleJobClass:
1250 T = new tools::dragonfly::Assemble(*this); break;
1251 case Action::LinkJobClass:
1252 T = new tools::dragonfly::Link(*this); break;
1253 default:
1254 T = &Generic_GCC::SelectTool(C, JA);
1255 }
1256 }
1257
1258 return *T;
1259}
Michael J. Spencerff58e362010-08-21 21:55:07 +00001260
1261Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple)
1262 : ToolChain(Host, Triple) {
1263}
1264
1265Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA) const {
1266 Action::ActionClass Key;
1267 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1268 Key = Action::AnalyzeJobClass;
1269 else
1270 Key = JA.getKind();
1271
1272 Tool *&T = Tools[Key];
1273 if (!T) {
1274 switch (Key) {
1275 case Action::InputClass:
1276 case Action::BindArchClass:
Chandler Carruthe97673f2010-08-22 06:56:37 +00001277 case Action::LipoJobClass:
1278 case Action::DsymutilJobClass:
Michael J. Spencerff58e362010-08-21 21:55:07 +00001279 assert(0 && "Invalid tool kind.");
1280 case Action::PreprocessJobClass:
1281 case Action::PrecompileJobClass:
1282 case Action::AnalyzeJobClass:
1283 case Action::CompileJobClass:
1284 T = new tools::Clang(*this); break;
1285 case Action::AssembleJobClass:
1286 T = new tools::ClangAs(*this); break;
1287 case Action::LinkJobClass:
1288 T = new tools::visualstudio::Link(*this); break;
1289 }
1290 }
1291
1292 return *T;
1293}
1294
1295bool Windows::IsIntegratedAssemblerDefault() const {
1296 return true;
1297}
1298
1299bool Windows::IsUnwindTablesDefault() const {
1300 // FIXME: Gross; we should probably have some separate target
1301 // definition, possibly even reusing the one in clang.
1302 return getArchName() == "x86_64";
1303}
1304
1305const char *Windows::GetDefaultRelocationModel() const {
1306 return "static";
1307}
1308
1309const char *Windows::GetForcedPicModel() const {
1310 if (getArchName() == "x86_64")
1311 return "pic";
1312 return 0;
1313}