blob: 561476ecdf0d575652c4a0919661dd0a61df15e2 [file] [log] [blame]
Nick Lewycky3fdcc6f2010-12-31 17:31:54 +00001//===--- ToolChains.cpp - ToolChain Implementations -----------------------===//
Daniel Dunbar39176082009-03-20 00:20:03 +00002//
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"
Michael J. Spencer32bef4e2011-01-10 02:34:13 +000026#include "llvm/Support/FileSystem.h"
Rafael Espindolac1da9812010-11-07 20:14:31 +000027#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000028#include "llvm/Support/raw_ostream.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000029#include "llvm/Support/Path.h"
Michael J. Spencer3a321e22010-12-09 17:36:38 +000030#include "llvm/Support/system_error.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000031
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000032#include <cstdlib> // ::getenv
33
Daniel Dunbar39176082009-03-20 00:20:03 +000034using namespace clang::driver;
35using namespace clang::driver::toolchains;
36
Daniel Dunbarf3955282009-09-04 18:34:51 +000037/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000038
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000039Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcc8e1892010-01-27 00:56:44 +000040 : ToolChain(Host, Triple), TargetInitialized(false)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000041{
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000042 // Compute the initial Darwin version based on the host.
43 bool HadExtra;
44 std::string OSName = Triple.getOSName();
Daniel Dunbar34f9e292011-02-25 21:20:15 +000045 if (!Driver::GetReleaseVersion(&OSName.c_str()[6],
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000046 DarwinVersion[0], DarwinVersion[1],
47 DarwinVersion[2], HadExtra))
48 getDriver().Diag(clang::diag::err_drv_invalid_darwin_version) << OSName;
49
Daniel Dunbar02633b52009-03-26 16:23:12 +000050 llvm::raw_string_ostream(MacosxVersionMin)
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000051 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.'
52 << DarwinVersion[1];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000053}
54
Daniel Dunbar41800112010-08-02 05:43:56 +000055types::ID Darwin::LookupTypeForExtension(const char *Ext) const {
56 types::ID Ty = types::lookupTypeForExtension(Ext);
57
58 // Darwin always preprocesses assembly files (unless -x is used explicitly).
59 if (Ty == types::TY_PP_Asm)
60 return types::TY_Asm;
61
62 return Ty;
63}
64
Daniel Dunbarb993f5d2010-09-17 00:24:52 +000065bool Darwin::HasNativeLLVMSupport() const {
66 return true;
67}
68
Daniel Dunbareeff4062010-01-22 02:04:58 +000069// FIXME: Can we tablegen this?
70static const char *GetArmArchForMArch(llvm::StringRef Value) {
71 if (Value == "armv6k")
72 return "armv6";
73
74 if (Value == "armv5tej")
75 return "armv5";
76
77 if (Value == "xscale")
78 return "xscale";
79
80 if (Value == "armv4t")
81 return "armv4t";
82
83 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
84 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
85 Value == "armv7m")
86 return "armv7";
87
88 return 0;
89}
90
91// FIXME: Can we tablegen this?
92static const char *GetArmArchForMCpu(llvm::StringRef Value) {
93 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
94 Value == "arm946e-s" || Value == "arm966e-s" ||
95 Value == "arm968e-s" || Value == "arm10e" ||
96 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
97 Value == "arm1026ej-s")
98 return "armv5";
99
100 if (Value == "xscale")
101 return "xscale";
102
103 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
104 Value == "arm1176jz-s" || Value == "arm1176jzf-s")
105 return "armv6";
106
107 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
108 return "armv7";
109
110 return 0;
111}
112
113llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
114 switch (getTriple().getArch()) {
115 default:
116 return getArchName();
117
118 case llvm::Triple::arm: {
119 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
120 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
121 return Arch;
122
123 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
124 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
125 return Arch;
126
127 return "arm";
128 }
129 }
130}
131
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000132DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple)
133 : Darwin(Host, Triple)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000134{
Daniel Dunbarc2bda622010-08-02 05:44:01 +0000135 // We can only work with 4.2.1 currently.
136 GCCVersion[0] = 4;
137 GCCVersion[1] = 2;
138 GCCVersion[2] = 1;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000139
140 // Set up the tool chain paths to match gcc.
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000141 ToolChainDir = "i686-apple-darwin";
Ted Kremenek55bac532009-10-07 03:21:11 +0000142 ToolChainDir += llvm::utostr(DarwinVersion[0]);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000143 ToolChainDir += "/";
144 ToolChainDir += llvm::utostr(GCCVersion[0]);
145 ToolChainDir += '.';
146 ToolChainDir += llvm::utostr(GCCVersion[1]);
147 ToolChainDir += '.';
148 ToolChainDir += llvm::utostr(GCCVersion[2]);
149
Daniel Dunbar74782b02009-10-20 19:25:43 +0000150 // Try the next major version if that tool chain dir is invalid.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000151 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000152 bool Exists;
153 if (llvm::sys::fs::exists(Tmp, Exists) || Exists) {
Daniel Dunbar74782b02009-10-20 19:25:43 +0000154 std::string Next = "i686-apple-darwin";
155 Next += llvm::utostr(DarwinVersion[0] + 1);
156 Next += "/";
157 Next += llvm::utostr(GCCVersion[0]);
158 Next += '.';
159 Next += llvm::utostr(GCCVersion[1]);
160 Next += '.';
161 Next += llvm::utostr(GCCVersion[2]);
162
163 // Use that if it exists, otherwise hope the user isn't linking.
164 //
165 // FIXME: Drop dependency on gcc's tool chain.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000166 Tmp = "/usr/lib/gcc/" + Next;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000167 if (!llvm::sys::fs::exists(Tmp, Exists) && Exists)
Daniel Dunbar74782b02009-10-20 19:25:43 +0000168 ToolChainDir = Next;
169 }
170
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000171 std::string Path;
172 if (getArchName() == "x86_64") {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000173 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000174 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000175 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000176 Path += "/x86_64";
177 getFilePaths().push_back(Path);
178
179 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000180 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000181 Path += "/x86_64";
182 getFilePaths().push_back(Path);
183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Daniel Dunbaree788e72009-12-21 18:54:17 +0000185 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000186 Path += "/../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
190 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000191 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000192 getFilePaths().push_back(Path);
193
Daniel Dunbaree788e72009-12-21 18:54:17 +0000194 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000195 Path += "/../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
199 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000200 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000201 getProgramPaths().push_back(Path);
202
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000203 getProgramPaths().push_back(getDriver().getInstalledDir());
204 if (getDriver().getInstalledDir() != getDriver().Dir)
205 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000206}
207
Daniel Dunbarf3955282009-09-04 18:34:51 +0000208Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000209 // Free tool implementations.
210 for (llvm::DenseMap<unsigned, Tool*>::iterator
211 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
212 delete it->second;
213}
214
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000215std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args) const {
216 llvm::Triple Triple(ComputeLLVMTriple(Args));
217
218 // If the target isn't initialized (e.g., an unknown Darwin platform, return
219 // the default triple).
220 if (!isTargetInitialized())
221 return Triple.getTriple();
222
223 unsigned Version[3];
224 getTargetVersion(Version);
225
226 // Mangle the target version into the OS triple component. For historical
227 // reasons that make little sense, the version passed here is the "darwin"
228 // version, which drops the 10 and offsets by 4. See inverse code when
229 // setting the OS version preprocessor define.
230 if (!isTargetIPhoneOS()) {
231 Version[0] = Version[1] + 4;
232 Version[1] = Version[2];
233 Version[2] = 0;
234 } else {
235 // Use the environment to communicate that we are targetting iPhoneOS.
236 Triple.setEnvironmentName("iphoneos");
237 }
238
239 llvm::SmallString<16> Str;
240 llvm::raw_svector_ostream(Str) << "darwin" << Version[0]
241 << "." << Version[1] << "." << Version[2];
242 Triple.setOSName(Str.str());
243
244 return Triple.getTriple();
245}
246
Daniel Dunbarf3955282009-09-04 18:34:51 +0000247Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000248 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000249 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000250 Key = Action::AnalyzeJobClass;
251 else
252 Key = JA.getKind();
253
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000254 // FIXME: This doesn't belong here, but ideally we will support static soon
255 // anyway.
256 bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) ||
257 C.getArgs().hasArg(options::OPT_static) ||
258 C.getArgs().hasArg(options::OPT_fapple_kext));
259 bool IsIADefault = IsIntegratedAssemblerDefault() && !HasStatic;
260 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
261 options::OPT_no_integrated_as,
262 IsIADefault);
263
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000264 Tool *&T = Tools[Key];
265 if (!T) {
266 switch (Key) {
267 case Action::InputClass:
268 case Action::BindArchClass:
269 assert(0 && "Invalid tool kind.");
270 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000271 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000272 case Action::AnalyzeJobClass:
273 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000274 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000275 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000276 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000277 case Action::AssembleJobClass: {
278 if (UseIntegratedAs)
279 T = new tools::ClangAs(*this);
280 else
281 T = new tools::darwin::Assemble(*this);
282 break;
283 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000284 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000285 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000286 case Action::LipoJobClass:
287 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000288 case Action::DsymutilJobClass:
289 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000290 }
291 }
292
293 return *T;
294}
295
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000296void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
297 ArgStringList &CmdArgs) const {
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000298 std::string Tmp;
299
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000300 // FIXME: Derive these correctly.
301 if (getArchName() == "x86_64") {
302 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
303 "/x86_64"));
304 // Intentionally duplicated for (temporary) gcc bug compatibility.
305 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
306 "/x86_64"));
307 }
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000308
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000309 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000310
311 Tmp = getDriver().Dir + "/../lib/gcc/" + ToolChainDir;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000312 bool Exists;
313 if (!llvm::sys::fs::exists(Tmp, Exists) && Exists)
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000314 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
315 Tmp = getDriver().Dir + "/../lib/gcc";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000316 if (!llvm::sys::fs::exists(Tmp, Exists) && Exists)
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000317 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000318 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
319 // Intentionally duplicated for (temporary) gcc bug compatibility.
320 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000321 Tmp = getDriver().Dir + "/../lib/" + ToolChainDir;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000322 if (!llvm::sys::fs::exists(Tmp, Exists) && Exists)
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000323 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
324 Tmp = getDriver().Dir + "/../lib";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000325 if (!llvm::sys::fs::exists(Tmp, Exists) && Exists)
Daniel Dunbare3c153a2010-04-10 18:18:57 +0000326 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp));
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000327 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
328 "/../../../" + ToolChainDir));
329 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
330 "/../../.."));
331}
332
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000333void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
334 ArgStringList &CmdArgs) const {
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000335 // Note that this routine is only used for targetting OS X.
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000336
337 // Derived from libgcc and lib specs but refactored.
338 if (Args.hasArg(options::OPT_static)) {
339 CmdArgs.push_back("-lgcc_static");
340 } else {
341 if (Args.hasArg(options::OPT_static_libgcc)) {
342 CmdArgs.push_back("-lgcc_eh");
343 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
344 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000345 if (isTargetIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000346 CmdArgs.push_back("-lgcc_s.1");
347 } else {
348 CmdArgs.push_back("-lgcc_s.10.5");
349 }
350 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
Daniel Dunbar8a0d94d2010-01-10 00:46:10 +0000351 Args.hasFlag(options::OPT_fexceptions,
352 options::OPT_fno_exceptions) ||
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000353 Args.hasArg(options::OPT_fgnu_runtime)) {
354 // FIXME: This is probably broken on 10.3?
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000355 if (isMacosxVersionLT(10, 5))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000356 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000357 else if (isMacosxVersionLT(10, 6))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000358 CmdArgs.push_back("-lgcc_s.10.5");
359 } else {
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000360 if (isMacosxVersionLT(10, 3, 9))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000361 ; // Do nothing.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000362 else if (isMacosxVersionLT(10, 5))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000363 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000364 else if (isMacosxVersionLT(10, 6))
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000365 CmdArgs.push_back("-lgcc_s.10.5");
366 }
367
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000368 if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000369 CmdArgs.push_back("-lgcc");
370 CmdArgs.push_back("-lSystem");
371 } else {
372 CmdArgs.push_back("-lSystem");
373 CmdArgs.push_back("-lgcc");
374 }
375 }
376}
377
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000378DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple)
379 : Darwin(Host, Triple)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000380{
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000381 getProgramPaths().push_back(getDriver().getInstalledDir());
382 if (getDriver().getInstalledDir() != getDriver().Dir)
383 getProgramPaths().push_back(getDriver().Dir);
384
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000385 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000386 getProgramPaths().push_back(getDriver().getInstalledDir());
387 if (getDriver().getInstalledDir() != getDriver().Dir)
388 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000389
390 // For fallback, we need to know how to find the GCC cc1 executables, so we
391 // also add the GCC libexec paths. This is legiy code that can be removed once
392 // fallback is no longer useful.
393 std::string ToolChainDir = "i686-apple-darwin";
394 ToolChainDir += llvm::utostr(DarwinVersion[0]);
395 ToolChainDir += "/4.2.1";
396
397 std::string Path = getDriver().Dir;
398 Path += "/../libexec/gcc/";
399 Path += ToolChainDir;
400 getProgramPaths().push_back(Path);
401
402 Path = "/usr/libexec/gcc/";
403 Path += ToolChainDir;
404 getProgramPaths().push_back(Path);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000405}
406
407void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
408 ArgStringList &CmdArgs) const {
409 // The Clang toolchain uses explicit paths for internal libraries.
Daniel Dunbar424b6612010-06-30 23:56:13 +0000410
411 // Unfortunately, we still might depend on a few of the libraries that are
412 // only available in the gcc library directory (in particular
413 // libstdc++.dylib). For now, hardcode the path to the known install location.
414 llvm::sys::Path P(getDriver().Dir);
415 P.eraseComponent(); // .../usr/bin -> ../usr
416 P.appendComponent("lib");
417 P.appendComponent("gcc");
418 switch (getTriple().getArch()) {
419 default:
420 assert(0 && "Invalid Darwin arch!");
421 case llvm::Triple::x86:
422 case llvm::Triple::x86_64:
423 P.appendComponent("i686-apple-darwin10");
424 break;
425 case llvm::Triple::arm:
426 case llvm::Triple::thumb:
427 P.appendComponent("arm-apple-darwin10");
428 break;
429 case llvm::Triple::ppc:
430 case llvm::Triple::ppc64:
431 P.appendComponent("powerpc-apple-darwin10");
432 break;
433 }
434 P.appendComponent("4.2.1");
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000435
436 // Determine the arch specific GCC subdirectory.
437 const char *ArchSpecificDir = 0;
438 switch (getTriple().getArch()) {
439 default:
440 break;
441 case llvm::Triple::arm:
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000442 case llvm::Triple::thumb: {
443 std::string Triple = ComputeLLVMTriple(Args);
444 llvm::StringRef TripleStr = Triple;
445 if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5"))
446 ArchSpecificDir = "v5";
447 else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6"))
448 ArchSpecificDir = "v6";
449 else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7"))
450 ArchSpecificDir = "v7";
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000451 break;
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000452 }
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000453 case llvm::Triple::ppc64:
454 ArchSpecificDir = "ppc64";
455 break;
456 case llvm::Triple::x86_64:
457 ArchSpecificDir = "x86_64";
458 break;
459 }
460
461 if (ArchSpecificDir) {
462 P.appendComponent(ArchSpecificDir);
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000463 bool Exists;
464 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000465 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
466 P.eraseComponent();
467 }
468
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000469 bool Exists;
470 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbar424b6612010-06-30 23:56:13 +0000471 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000472}
473
474void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
475 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000476 // Darwin doesn't support real static executables, don't link any runtime
477 // libraries with -static.
478 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000479 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000480
481 // Reject -static-libgcc for now, we can deal with this when and if someone
482 // cares. This is useful in situations where someone wants to statically link
483 // something like libstdc++, and needs its runtime support routines.
484 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000485 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000486 << A->getAsString(Args);
487 return;
488 }
489
Daniel Dunbareec99102010-01-22 03:38:14 +0000490 // Otherwise link libSystem, then the dynamic runtime library, and finally any
491 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000492 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000493
494 // Select the dynamic runtime library and the target specific static library.
495 const char *DarwinStaticLib = 0;
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000496 if (isTargetIPhoneOS()) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000497 CmdArgs.push_back("-lgcc_s.1");
498
499 // We may need some static functions for armv6/thumb which are required to
500 // be in the same linkage unit as their caller.
501 if (getDarwinArchName(Args) == "armv6")
502 DarwinStaticLib = "libclang_rt.armv6.a";
503 } else {
Daniel Dunbareec99102010-01-22 03:38:14 +0000504 // The dynamic runtime library was merged with libSystem for 10.6 and
505 // beyond; only 10.4 and 10.5 need an additional runtime library.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000506 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000507 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000508 else if (isMacosxVersionLT(10, 6))
Daniel Dunbareec99102010-01-22 03:38:14 +0000509 CmdArgs.push_back("-lgcc_s.10.5");
510
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000511 // For OS X, we thought we would only need a static runtime library when
512 // targetting 10.4, to provide versions of the static functions which were
513 // omitted from 10.4.dylib.
514 //
515 // Unfortunately, that turned out to not be true, because Darwin system
516 // headers can still use eprintf on i386, and it is not exported from
517 // libSystem. Therefore, we still must provide a runtime library just for
518 // the tiny tiny handful of projects that *might* use that symbol.
519 if (isMacosxVersionLT(10, 5)) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000520 DarwinStaticLib = "libclang_rt.10.4.a";
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000521 } else {
522 if (getTriple().getArch() == llvm::Triple::x86)
523 DarwinStaticLib = "libclang_rt.eprintf.a";
524 }
Daniel Dunbareec99102010-01-22 03:38:14 +0000525 }
526
527 /// Add the target specific static library, if needed.
528 if (DarwinStaticLib) {
529 llvm::sys::Path P(getDriver().ResourceDir);
530 P.appendComponent("lib");
531 P.appendComponent("darwin");
532 P.appendComponent(DarwinStaticLib);
533
534 // For now, allow missing resource libraries to support developers who may
535 // not have compiler-rt checked out or integrated into their build.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000536 bool Exists;
537 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbareec99102010-01-22 03:38:14 +0000538 CmdArgs.push_back(Args.MakeArgString(P.str()));
539 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000540}
541
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000542void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000543 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000544
Daniel Dunbar26031372010-01-27 00:56:25 +0000545 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
546 Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000547 if (OSXVersion && iPhoneVersion) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000548 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000549 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000550 << iPhoneVersion->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000551 iPhoneVersion = 0;
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000552 } else if (!OSXVersion && !iPhoneVersion) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000553 // If neither OS X nor iPhoneOS targets were specified, check for
554 // environment defines.
555 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
556 const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000557
Daniel Dunbar816bc312010-01-26 01:45:19 +0000558 // Ignore empty strings.
559 if (OSXTarget && OSXTarget[0] == '\0')
560 OSXTarget = 0;
561 if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0')
562 iPhoneOSTarget = 0;
563
Daniel Dunbar39053672010-02-02 17:31:12 +0000564 // Diagnose conflicting deployment targets, and choose default platform
565 // based on the tool chain.
566 //
567 // FIXME: Don't hardcode default here.
568 if (OSXTarget && iPhoneOSTarget) {
569 // FIXME: We should see if we can get away with warning or erroring on
570 // this. Perhaps put under -pedantic?
571 if (getTriple().getArch() == llvm::Triple::arm ||
572 getTriple().getArch() == llvm::Triple::thumb)
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000573 OSXTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000574 else
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000575 iPhoneOSTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000576 }
Daniel Dunbar1a3c1d92010-01-29 17:02:25 +0000577
Daniel Dunbar39053672010-02-02 17:31:12 +0000578 if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000579 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000580 OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget);
581 Args.append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000582 } else if (iPhoneOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000583 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000584 iPhoneVersion = Args.MakeJoinedArg(0, O, iPhoneOSTarget);
585 Args.append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000586 } else {
Daniel Dunbar2bb38d02010-07-15 16:18:06 +0000587 // Otherwise, assume we are targeting OS X.
588 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000589 OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin);
590 Args.append(OSXVersion);
Daniel Dunbar30392de2009-09-04 18:35:21 +0000591 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000592 }
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Daniel Dunbar26031372010-01-27 00:56:25 +0000594 // Set the tool chain target information.
595 unsigned Major, Minor, Micro;
596 bool HadExtra;
597 if (OSXVersion) {
598 assert(!iPhoneVersion && "Unknown target platform!");
599 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
600 Micro, HadExtra) || HadExtra ||
601 Major != 10 || Minor >= 10 || Micro >= 10)
602 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
603 << OSXVersion->getAsString(Args);
604 } else {
605 assert(iPhoneVersion && "Unknown target platform!");
606 if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor,
607 Micro, HadExtra) || HadExtra ||
608 Major >= 10 || Minor >= 100 || Micro >= 100)
609 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
610 << iPhoneVersion->getAsString(Args);
611 }
612 setTarget(iPhoneVersion, Major, Minor, Micro);
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000613}
614
Daniel Dunbar132e35d2010-09-17 01:20:05 +0000615void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args,
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000616 ArgStringList &CmdArgs) const {
617 CXXStdlibType Type = GetCXXStdlibType(Args);
618
619 switch (Type) {
620 case ToolChain::CST_Libcxx:
621 CmdArgs.push_back("-lc++");
622 break;
623
624 case ToolChain::CST_Libstdcxx: {
625 // Unfortunately, -lstdc++ doesn't always exist in the standard search path;
626 // it was previously found in the gcc lib dir. However, for all the Darwin
627 // platforms we care about it was -lstdc++.6, so we search for that
628 // explicitly if we can't see an obvious -lstdc++ candidate.
629
630 // Check in the sysroot first.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000631 bool Exists;
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000632 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
633 llvm::sys::Path P(A->getValue(Args));
634 P.appendComponent("usr");
635 P.appendComponent("lib");
636 P.appendComponent("libstdc++.dylib");
637
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000638 if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) {
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000639 P.eraseComponent();
640 P.appendComponent("libstdc++.6.dylib");
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000641 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) {
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000642 CmdArgs.push_back(Args.MakeArgString(P.str()));
643 return;
644 }
645 }
646 }
647
648 // Otherwise, look in the root.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000649 if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&&
650 (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000651 CmdArgs.push_back("/usr/lib/libstdc++.6.dylib");
652 return;
653 }
654
655 // Otherwise, let the linker search.
656 CmdArgs.push_back("-lstdc++");
657 break;
658 }
659 }
660}
661
Shantonu Sen7433fed2010-09-17 18:39:08 +0000662void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
663 ArgStringList &CmdArgs) const {
664
665 // For Darwin platforms, use the compiler-rt-based support library
666 // instead of the gcc-provided one (which is also incidentally
667 // only present in the gcc lib dir, which makes it hard to find).
668
669 llvm::sys::Path P(getDriver().ResourceDir);
670 P.appendComponent("lib");
671 P.appendComponent("darwin");
672 P.appendComponent("libclang_rt.cc_kext.a");
673
674 // For now, allow missing resource libraries to support developers who may
675 // not have compiler-rt checked out or integrated into their build.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000676 bool Exists;
677 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Shantonu Sen7433fed2010-09-17 18:39:08 +0000678 CmdArgs.push_back(Args.MakeArgString(P.str()));
679}
680
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000681DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
682 const char *BoundArch) const {
683 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
684 const OptTable &Opts = getDriver().getOpts();
685
686 // FIXME: We really want to get out of the tool chain level argument
687 // translation business, as it makes the driver functionality much
688 // more opaque. For now, we follow gcc closely solely for the
689 // purpose of easily achieving feature parity & testability. Once we
690 // have something that works, we should reevaluate each translation
691 // and try to push it down into tool specific logic.
Daniel Dunbar26031372010-01-27 00:56:25 +0000692
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000693 for (ArgList::const_iterator it = Args.begin(),
694 ie = Args.end(); it != ie; ++it) {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000695 Arg *A = *it;
696
697 if (A->getOption().matches(options::OPT_Xarch__)) {
698 // FIXME: Canonicalize name.
699 if (getArchName() != A->getValue(Args, 0))
700 continue;
701
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000702 Arg *OriginalArg = A;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000703 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1));
704 unsigned Prev = Index;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000705 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000706
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000707 // If the argument parsing failed or more than one argument was
708 // consumed, the -Xarch_ argument's parameter tried to consume
709 // extra arguments. Emit an error and ignore.
710 //
711 // We also want to disallow any options which would alter the
712 // driver behavior; that isn't going to work in our model. We
713 // use isDriverOption() as an approximation, although things
714 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000715 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000716 XarchArg->getOption().isDriverOption()) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000717 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000718 << A->getAsString(Args);
719 continue;
720 }
721
Daniel Dunbar478edc22009-03-29 22:29:05 +0000722 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000723 A = XarchArg;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000724
725 DAL->AddSynthesizedArg(A);
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000726
727 // Linker input arguments require custom handling. The problem is that we
728 // have already constructed the phase actions, so we can not treat them as
729 // "input arguments".
730 if (A->getOption().isLinkerInput()) {
731 // Convert the argument into individual Zlinker_input_args.
732 for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
733 DAL->AddSeparateArg(OriginalArg,
734 Opts.getOption(options::OPT_Zlinker_input),
735 A->getValue(Args, i));
736
737 }
738 continue;
739 }
Mike Stump1eb44332009-09-09 15:08:12 +0000740 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000741
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000742 // Sob. These is strictly gcc compatible for the time being. Apple
743 // gcc translates options twice, which means that self-expanding
744 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000745 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000746 default:
747 DAL->append(A);
748 break;
749
750 case options::OPT_mkernel:
751 case options::OPT_fapple_kext:
752 DAL->append(A);
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000753 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
754 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000755 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000756
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000757 case options::OPT_dependency_file:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000758 DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF),
759 A->getValue(Args));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000760 break;
761
762 case options::OPT_gfull:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000763 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
764 DAL->AddFlagArg(A,
765 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000766 break;
767
768 case options::OPT_gused:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000769 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
770 DAL->AddFlagArg(A,
771 Opts.getOption(options::OPT_feliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000772 break;
773
774 case options::OPT_fterminated_vtables:
775 case options::OPT_findirect_virtual_calls:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000776 DAL->AddFlagArg(A, Opts.getOption(options::OPT_fapple_kext));
777 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000778 break;
779
780 case options::OPT_shared:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000781 DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000782 break;
783
784 case options::OPT_fconstant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000785 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000786 break;
787
788 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000789 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000790 break;
791
792 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000793 DAL->AddFlagArg(A,
794 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000795 break;
796
797 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000798 DAL->AddFlagArg(A,
799 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000800 break;
801
802 case options::OPT_fpascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000803 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000804 break;
805
806 case options::OPT_fno_pascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000807 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000808 break;
809 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000810 }
811
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000812 if (getTriple().getArch() == llvm::Triple::x86 ||
813 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000814 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000815 DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000816
817 // Add the arch options based on the particular spelling of -arch, to match
818 // how the driver driver works.
819 if (BoundArch) {
820 llvm::StringRef Name = BoundArch;
821 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
822 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
823
824 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
825 // which defines the list of which architectures we accept.
826 if (Name == "ppc")
827 ;
828 else if (Name == "ppc601")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000829 DAL->AddJoinedArg(0, MCpu, "601");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000830 else if (Name == "ppc603")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000831 DAL->AddJoinedArg(0, MCpu, "603");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000832 else if (Name == "ppc604")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000833 DAL->AddJoinedArg(0, MCpu, "604");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000834 else if (Name == "ppc604e")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000835 DAL->AddJoinedArg(0, MCpu, "604e");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000836 else if (Name == "ppc750")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000837 DAL->AddJoinedArg(0, MCpu, "750");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000838 else if (Name == "ppc7400")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000839 DAL->AddJoinedArg(0, MCpu, "7400");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000840 else if (Name == "ppc7450")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000841 DAL->AddJoinedArg(0, MCpu, "7450");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000842 else if (Name == "ppc970")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000843 DAL->AddJoinedArg(0, MCpu, "970");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000844
845 else if (Name == "ppc64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000846 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000847
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000848 else if (Name == "i386")
849 ;
850 else if (Name == "i486")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000851 DAL->AddJoinedArg(0, MArch, "i486");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000852 else if (Name == "i586")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000853 DAL->AddJoinedArg(0, MArch, "i586");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000854 else if (Name == "i686")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000855 DAL->AddJoinedArg(0, MArch, "i686");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000856 else if (Name == "pentium")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000857 DAL->AddJoinedArg(0, MArch, "pentium");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000858 else if (Name == "pentium2")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000859 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000860 else if (Name == "pentpro")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000861 DAL->AddJoinedArg(0, MArch, "pentiumpro");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000862 else if (Name == "pentIIm3")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000863 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000864
865 else if (Name == "x86_64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000866 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000867
868 else if (Name == "arm")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000869 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000870 else if (Name == "armv4t")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000871 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000872 else if (Name == "armv5")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000873 DAL->AddJoinedArg(0, MArch, "armv5tej");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000874 else if (Name == "xscale")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000875 DAL->AddJoinedArg(0, MArch, "xscale");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000876 else if (Name == "armv6")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000877 DAL->AddJoinedArg(0, MArch, "armv6k");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000878 else if (Name == "armv7")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000879 DAL->AddJoinedArg(0, MArch, "armv7a");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000880
881 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000882 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000883 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000884
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000885 // Add an explicit version min argument for the deployment target. We do this
886 // after argument translation because -Xarch_ arguments may add a version min
887 // argument.
888 AddDeploymentTarget(*DAL);
889
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000890 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000891}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000892
Daniel Dunbarf3955282009-09-04 18:34:51 +0000893bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000894 // FIXME: Gross; we should probably have some separate target
895 // definition, possibly even reusing the one in clang.
896 return getArchName() == "x86_64";
897}
898
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000899bool Darwin::UseDwarfDebugFlags() const {
900 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
901 return S[0] != '\0';
902 return false;
903}
904
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000905bool Darwin::UseSjLjExceptions() const {
906 // Darwin uses SjLj exceptions on ARM.
907 return (getTriple().getArch() == llvm::Triple::arm ||
908 getTriple().getArch() == llvm::Triple::thumb);
909}
910
Daniel Dunbarf3955282009-09-04 18:34:51 +0000911const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000912 return "pic";
913}
914
Daniel Dunbarf3955282009-09-04 18:34:51 +0000915const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000916 if (getArchName() == "x86_64")
917 return "pic";
918 return 0;
919}
920
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000921bool Darwin::SupportsObjCGC() const {
922 // Garbage collection is supported everywhere except on iPhone OS.
923 return !isTargetIPhoneOS();
924}
925
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000926std::string
927Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const {
928 return ComputeLLVMTriple(Args);
929}
930
Daniel Dunbar39176082009-03-20 00:20:03 +0000931/// Generic_GCC - A tool chain using the 'gcc' command to perform
932/// all subcommands; this relies on gcc translating the majority of
933/// command line options.
934
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000935Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000936 : ToolChain(Host, Triple) {
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000937 getProgramPaths().push_back(getDriver().getInstalledDir());
938 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
939 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000940}
941
Daniel Dunbar39176082009-03-20 00:20:03 +0000942Generic_GCC::~Generic_GCC() {
943 // Free tool implementations.
944 for (llvm::DenseMap<unsigned, Tool*>::iterator
945 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
946 delete it->second;
947}
948
Mike Stump1eb44332009-09-09 15:08:12 +0000949Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000950 const JobAction &JA) const {
951 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000952 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000953 Key = Action::AnalyzeJobClass;
954 else
955 Key = JA.getKind();
956
957 Tool *&T = Tools[Key];
958 if (!T) {
959 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000960 case Action::InputClass:
961 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000962 assert(0 && "Invalid tool kind.");
963 case Action::PreprocessJobClass:
964 T = new tools::gcc::Preprocess(*this); break;
965 case Action::PrecompileJobClass:
966 T = new tools::gcc::Precompile(*this); break;
967 case Action::AnalyzeJobClass:
968 T = new tools::Clang(*this); break;
969 case Action::CompileJobClass:
970 T = new tools::gcc::Compile(*this); break;
971 case Action::AssembleJobClass:
972 T = new tools::gcc::Assemble(*this); break;
973 case Action::LinkJobClass:
974 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000975
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000976 // This is a bit ungeneric, but the only platform using a driver
977 // driver is Darwin.
978 case Action::LipoJobClass:
979 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000980 case Action::DsymutilJobClass:
981 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000982 }
983 }
984
985 return *T;
986}
987
Daniel Dunbar39176082009-03-20 00:20:03 +0000988bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000989 // FIXME: Gross; we should probably have some separate target
990 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000991 return getArchName() == "x86_64";
992}
993
994const char *Generic_GCC::GetDefaultRelocationModel() const {
995 return "static";
996}
997
998const char *Generic_GCC::GetForcedPicModel() const {
999 return 0;
1000}
Daniel Dunbarf3cad362009-03-25 04:13:45 +00001001
Chris Lattner3a47c4e2010-03-04 21:07:38 +00001002/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
1003/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
1004/// Currently does not support anything else but compilation.
1005
1006TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple)
1007 : ToolChain(Host, Triple) {
1008 // Path mangling to find libexec
1009 std::string Path(getDriver().Dir);
1010
1011 Path += "/../libexec";
1012 getProgramPaths().push_back(Path);
1013}
1014
1015TCEToolChain::~TCEToolChain() {
1016 for (llvm::DenseMap<unsigned, Tool*>::iterator
1017 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
1018 delete it->second;
1019}
1020
1021bool TCEToolChain::IsMathErrnoDefault() const {
1022 return true;
1023}
1024
1025bool TCEToolChain::IsUnwindTablesDefault() const {
1026 return false;
1027}
1028
1029const char *TCEToolChain::GetDefaultRelocationModel() const {
1030 return "static";
1031}
1032
1033const char *TCEToolChain::GetForcedPicModel() const {
1034 return 0;
1035}
1036
1037Tool &TCEToolChain::SelectTool(const Compilation &C,
1038 const JobAction &JA) const {
1039 Action::ActionClass Key;
1040 Key = Action::AnalyzeJobClass;
1041
1042 Tool *&T = Tools[Key];
1043 if (!T) {
1044 switch (Key) {
1045 case Action::PreprocessJobClass:
1046 T = new tools::gcc::Preprocess(*this); break;
1047 case Action::AnalyzeJobClass:
1048 T = new tools::Clang(*this); break;
1049 default:
1050 assert(false && "Unsupported action for TCE target.");
1051 }
1052 }
1053 return *T;
1054}
1055
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001056/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
1057
1058OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001059 : Generic_ELF(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +00001060 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001061 getFilePaths().push_back("/usr/lib");
1062}
1063
1064Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
1065 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001066 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001067 Key = Action::AnalyzeJobClass;
1068 else
1069 Key = JA.getKind();
1070
Rafael Espindoladda5b922010-11-07 23:13:01 +00001071 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1072 options::OPT_no_integrated_as,
1073 IsIntegratedAssemblerDefault());
1074
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001075 Tool *&T = Tools[Key];
1076 if (!T) {
1077 switch (Key) {
Rafael Espindoladda5b922010-11-07 23:13:01 +00001078 case Action::AssembleJobClass: {
1079 if (UseIntegratedAs)
1080 T = new tools::ClangAs(*this);
1081 else
1082 T = new tools::openbsd::Assemble(*this);
1083 break;
1084 }
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001085 case Action::LinkJobClass:
1086 T = new tools::openbsd::Link(*this); break;
1087 default:
1088 T = &Generic_GCC::SelectTool(C, JA);
1089 }
1090 }
1091
1092 return *T;
1093}
1094
Daniel Dunbar75358d22009-03-30 21:06:03 +00001095/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
1096
Daniel Dunbar214afe92010-08-02 05:43:59 +00001097FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001098 : Generic_ELF(Host, Triple) {
Daniel Dunbar214afe92010-08-02 05:43:59 +00001099
1100 // Determine if we are compiling 32-bit code on an x86_64 platform.
1101 bool Lib32 = false;
1102 if (Triple.getArch() == llvm::Triple::x86 &&
1103 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1104 llvm::Triple::x86_64)
1105 Lib32 = true;
1106
Daniel Dunbarbc534662009-04-02 18:30:04 +00001107 if (Lib32) {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001108 getFilePaths().push_back("/usr/lib32");
1109 } else {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001110 getFilePaths().push_back("/usr/lib");
1111 }
Daniel Dunbar75358d22009-03-30 21:06:03 +00001112}
1113
1114Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
1115 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001116 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +00001117 Key = Action::AnalyzeJobClass;
1118 else
1119 Key = JA.getKind();
1120
Roman Divacky67dece72010-11-08 17:46:39 +00001121 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1122 options::OPT_no_integrated_as,
1123 IsIntegratedAssemblerDefault());
1124
Daniel Dunbar75358d22009-03-30 21:06:03 +00001125 Tool *&T = Tools[Key];
1126 if (!T) {
1127 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +00001128 case Action::AssembleJobClass:
Roman Divacky67dece72010-11-08 17:46:39 +00001129 if (UseIntegratedAs)
1130 T = new tools::ClangAs(*this);
1131 else
1132 T = new tools::freebsd::Assemble(*this);
Roman Divackyfe3a7ea2010-11-08 19:39:10 +00001133 break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +00001134 case Action::LinkJobClass:
1135 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +00001136 default:
1137 T = &Generic_GCC::SelectTool(C, JA);
1138 }
1139 }
1140
1141 return *T;
1142}
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001143
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001144/// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly.
1145
1146NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple)
1147 : Generic_ELF(Host, Triple) {
1148
1149 // Determine if we are compiling 32-bit code on an x86_64 platform.
1150 bool Lib32 = false;
1151 if (Triple.getArch() == llvm::Triple::x86 &&
1152 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1153 llvm::Triple::x86_64)
1154 Lib32 = true;
1155
1156 getProgramPaths().push_back(getDriver().Dir + "/../libexec");
1157 getProgramPaths().push_back("/usr/libexec");
1158 if (Lib32) {
1159 getFilePaths().push_back("/usr/lib/i386");
1160 } else {
1161 getFilePaths().push_back("/usr/lib");
1162 }
1163}
1164
1165Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
1166 Action::ActionClass Key;
1167 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1168 Key = Action::AnalyzeJobClass;
1169 else
1170 Key = JA.getKind();
1171
1172 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1173 options::OPT_no_integrated_as,
1174 IsIntegratedAssemblerDefault());
1175
1176 Tool *&T = Tools[Key];
1177 if (!T) {
1178 switch (Key) {
1179 case Action::AssembleJobClass:
1180 if (UseIntegratedAs)
1181 T = new tools::ClangAs(*this);
1182 else
1183 T = new tools::netbsd::Assemble(*this);
1184 break;
1185 case Action::LinkJobClass:
1186 T = new tools::netbsd::Link(*this); break;
1187 default:
1188 T = &Generic_GCC::SelectTool(C, JA);
1189 }
1190 }
1191
1192 return *T;
1193}
1194
Chris Lattner38e317d2010-07-07 16:01:42 +00001195/// Minix - Minix tool chain which can call as(1) and ld(1) directly.
1196
1197Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple)
1198 : Generic_GCC(Host, Triple) {
1199 getFilePaths().push_back(getDriver().Dir + "/../lib");
1200 getFilePaths().push_back("/usr/lib");
1201 getFilePaths().push_back("/usr/gnu/lib");
1202 getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
1203}
1204
1205Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA) const {
1206 Action::ActionClass Key;
1207 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1208 Key = Action::AnalyzeJobClass;
1209 else
1210 Key = JA.getKind();
1211
1212 Tool *&T = Tools[Key];
1213 if (!T) {
1214 switch (Key) {
1215 case Action::AssembleJobClass:
1216 T = new tools::minix::Assemble(*this); break;
1217 case Action::LinkJobClass:
1218 T = new tools::minix::Link(*this); break;
1219 default:
1220 T = &Generic_GCC::SelectTool(C, JA);
1221 }
1222 }
1223
1224 return *T;
1225}
1226
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001227/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
1228
1229AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
1230 : Generic_GCC(Host, Triple) {
1231
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001232 getProgramPaths().push_back(getDriver().getInstalledDir());
1233 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
1234 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001235
Daniel Dunbaree788e72009-12-21 18:54:17 +00001236 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001237 getFilePaths().push_back("/usr/lib");
1238 getFilePaths().push_back("/usr/sfw/lib");
1239 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +00001240 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001241
1242}
1243
1244Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
1245 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001246 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001247 Key = Action::AnalyzeJobClass;
1248 else
1249 Key = JA.getKind();
1250
1251 Tool *&T = Tools[Key];
1252 if (!T) {
1253 switch (Key) {
1254 case Action::AssembleJobClass:
1255 T = new tools::auroraux::Assemble(*this); break;
1256 case Action::LinkJobClass:
1257 T = new tools::auroraux::Link(*this); break;
1258 default:
1259 T = &Generic_GCC::SelectTool(C, JA);
1260 }
1261 }
1262
1263 return *T;
1264}
1265
1266
Eli Friedman6b3454a2009-05-26 07:52:18 +00001267/// Linux toolchain (very bare-bones at the moment).
1268
Rafael Espindolac1da9812010-11-07 20:14:31 +00001269enum LinuxDistro {
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001270 ArchLinux,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001271 DebianLenny,
1272 DebianSqueeze,
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001273 Exherbo,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001274 Fedora13,
1275 Fedora14,
1276 OpenSuse11_3,
Rafael Espindola021aaa42010-11-10 05:00:22 +00001277 UbuntuJaunty,
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001278 UbuntuKarmic,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001279 UbuntuLucid,
1280 UbuntuMaverick,
1281 UnknownDistro
1282};
1283
1284static bool IsFedora(enum LinuxDistro Distro) {
1285 return Distro == Fedora13 || Distro == Fedora14;
1286}
1287
1288static bool IsOpenSuse(enum LinuxDistro Distro) {
1289 return Distro == OpenSuse11_3;
1290}
1291
1292static bool IsDebian(enum LinuxDistro Distro) {
1293 return Distro == DebianLenny || Distro == DebianSqueeze;
1294}
1295
1296static bool IsUbuntu(enum LinuxDistro Distro) {
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001297 return Distro == UbuntuLucid || Distro == UbuntuMaverick ||
1298 Distro == UbuntuJaunty || Distro == UbuntuKarmic;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001299}
1300
1301static bool IsDebianBased(enum LinuxDistro Distro) {
1302 return IsDebian(Distro) || IsUbuntu(Distro);
1303}
1304
1305static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) {
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001306 if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001307 bool Exists;
1308 if (Distro == Exherbo &&
1309 (llvm::sys::fs::exists("/usr/lib32/libc.so", Exists) || !Exists))
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001310 return false;
1311
Rafael Espindolac1da9812010-11-07 20:14:31 +00001312 return true;
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001313 }
Rafael Espindolac1da9812010-11-07 20:14:31 +00001314 if (Arch == llvm::Triple::x86 && IsDebianBased(Distro))
1315 return true;
1316 return false;
1317}
1318
1319static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001320 llvm::OwningPtr<llvm::MemoryBuffer> File;
1321 if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) {
1322 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001323 llvm::SmallVector<llvm::StringRef, 8> Lines;
1324 Data.split(Lines, "\n");
1325 for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) {
1326 if (Lines[i] == "DISTRIB_CODENAME=maverick")
1327 return UbuntuMaverick;
1328 else if (Lines[i] == "DISTRIB_CODENAME=lucid")
1329 return UbuntuLucid;
Rafael Espindola021aaa42010-11-10 05:00:22 +00001330 else if (Lines[i] == "DISTRIB_CODENAME=jaunty")
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001331 return UbuntuJaunty;
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001332 else if (Lines[i] == "DISTRIB_CODENAME=karmic")
1333 return UbuntuKarmic;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001334 }
1335 return UnknownDistro;
1336 }
1337
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001338 if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) {
1339 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001340 if (Data.startswith("Fedora release 14 (Laughlin)"))
1341 return Fedora14;
1342 else if (Data.startswith("Fedora release 13 (Goddard)"))
1343 return Fedora13;
1344 return UnknownDistro;
1345 }
1346
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001347 if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) {
1348 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001349 if (Data[0] == '5')
1350 return DebianLenny;
1351 else if (Data.startswith("squeeze/sid"))
1352 return DebianSqueeze;
1353 return UnknownDistro;
1354 }
1355
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001356 if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) {
1357 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001358 if (Data.startswith("openSUSE 11.3"))
1359 return OpenSuse11_3;
1360 return UnknownDistro;
1361 }
1362
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001363 bool Exists;
1364 if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001365 return Exherbo;
1366
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001367 if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists)
1368 return ArchLinux;
1369
Rafael Espindolac1da9812010-11-07 20:14:31 +00001370 return UnknownDistro;
1371}
1372
Nick Lewycky3fdcc6f2010-12-31 17:31:54 +00001373Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001374 : Generic_ELF(Host, Triple) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001375 llvm::Triple::ArchType Arch =
1376 llvm::Triple(getDriver().DefaultHostTriple).getArch();
Daniel Dunbara9822de2009-08-06 01:47:11 +00001377
Rafael Espindolac1da9812010-11-07 20:14:31 +00001378 std::string Suffix32 = "";
1379 if (Arch == llvm::Triple::x86_64)
1380 Suffix32 = "/32";
Daniel Dunbara9822de2009-08-06 01:47:11 +00001381
Rafael Espindolac1da9812010-11-07 20:14:31 +00001382 std::string Suffix64 = "";
1383 if (Arch == llvm::Triple::x86)
1384 Suffix64 = "/64";
1385
1386 std::string Lib32 = "lib";
1387
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001388 bool Exists;
1389 if (!llvm::sys::fs::exists("/lib32", Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001390 Lib32 = "lib32";
1391
1392 std::string Lib64 = "lib";
Michael J. Spencer2dea7c72011-01-12 23:54:48 +00001393 bool Symlink;
Chris Lattner48aef362011-01-13 01:35:58 +00001394 if (!llvm::sys::fs::exists("/lib64", Exists) && Exists &&
1395 (llvm::sys::fs::is_symlink("/lib64", Symlink) || !Symlink))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001396 Lib64 = "lib64";
1397
1398 std::string GccTriple = "";
1399 if (Arch == llvm::Triple::arm) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001400 if (!llvm::sys::fs::exists("/usr/lib/gcc/arm-linux-gnueabi", Exists) &&
1401 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001402 GccTriple = "arm-linux-gnueabi";
1403 } else if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001404 if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-linux-gnu", Exists) &&
1405 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001406 GccTriple = "x86_64-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001407 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-unknown-linux-gnu",
1408 Exists) && Exists)
Rafael Espindola53dd00b2010-11-17 00:25:26 +00001409 GccTriple = "x86_64-unknown-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001410 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-pc-linux-gnu",
1411 Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001412 GccTriple = "x86_64-pc-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001413 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-redhat-linux",
1414 Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001415 GccTriple = "x86_64-redhat-linux";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001416 else if (!llvm::sys::fs::exists("/usr/lib64/gcc/x86_64-suse-linux",
1417 Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001418 GccTriple = "x86_64-suse-linux";
Nick Lewyckye10f9002011-02-01 23:03:29 +00001419 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-manbo-linux-gnu",
1420 Exists) && Exists)
1421 GccTriple = "x86_64-manbo-linux-gnu";
Rafael Espindolac1da9812010-11-07 20:14:31 +00001422 } else if (Arch == llvm::Triple::x86) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001423 if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-linux-gnu", Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001424 GccTriple = "i686-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001425 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-pc-linux-gnu", Exists) &&
1426 Exists)
Nuno Lopes2a69ddd2010-11-19 17:26:57 +00001427 GccTriple = "i686-pc-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001428 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-linux-gnu", Exists) &&
1429 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001430 GccTriple = "i486-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001431 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-redhat-linux", Exists) &&
1432 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001433 GccTriple = "i686-redhat-linux";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001434 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i586-suse-linux", Exists) &&
1435 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001436 GccTriple = "i586-suse-linux";
1437 }
1438
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001439 const char* GccVersions[] = {"4.5.2", "4.5.1", "4.5", "4.4.5", "4.4.4",
1440 "4.4.3", "4.4", "4.3.4", "4.3.3", "4.3.2",
1441 "4.3"};
Rafael Espindolac1da9812010-11-07 20:14:31 +00001442 std::string Base = "";
1443 for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) {
1444 std::string Suffix = GccTriple + "/" + GccVersions[i];
1445 std::string t1 = "/usr/lib/gcc/" + Suffix;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001446 if (!llvm::sys::fs::exists(t1 + "/crtbegin.o", Exists) && Exists) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001447 Base = t1;
1448 break;
1449 }
1450 std::string t2 = "/usr/lib64/gcc/" + Suffix;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001451 if (!llvm::sys::fs::exists(t2 + "/crtbegin.o", Exists) && Exists) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001452 Base = t2;
1453 break;
1454 }
1455 }
1456
1457 path_list &Paths = getFilePaths();
1458 bool Is32Bits = getArch() == llvm::Triple::x86;
1459
1460 std::string Suffix;
1461 std::string Lib;
1462
1463 if (Is32Bits) {
1464 Suffix = Suffix32;
1465 Lib = Lib32;
1466 } else {
1467 Suffix = Suffix64;
1468 Lib = Lib64;
1469 }
1470
1471 llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld");
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001472 if (!llvm::sys::fs::exists(LinkerPath.str(), Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001473 Linker = LinkerPath.str();
1474 else
1475 Linker = GetProgramPath("ld");
1476
1477 LinuxDistro Distro = DetectLinuxDistro(Arch);
1478
Rafael Espindola94c80222010-11-08 14:48:47 +00001479 if (IsUbuntu(Distro)) {
1480 ExtraOpts.push_back("-z");
1481 ExtraOpts.push_back("relro");
1482 }
Rafael Espindolac1da9812010-11-07 20:14:31 +00001483
1484 if (Arch == llvm::Triple::arm)
1485 ExtraOpts.push_back("-X");
1486
1487 if (IsFedora(Distro) || Distro == UbuntuMaverick)
1488 ExtraOpts.push_back("--hash-style=gnu");
1489
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001490 if (IsDebian(Distro) || Distro == UbuntuLucid || Distro == UbuntuJaunty ||
1491 Distro == UbuntuKarmic)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001492 ExtraOpts.push_back("--hash-style=both");
1493
1494 if (IsFedora(Distro))
1495 ExtraOpts.push_back("--no-add-needed");
1496
Rafael Espindola021aaa42010-11-10 05:00:22 +00001497 if (Distro == DebianSqueeze || IsOpenSuse(Distro) ||
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001498 IsFedora(Distro) || Distro == UbuntuLucid || Distro == UbuntuMaverick ||
1499 Distro == UbuntuKarmic)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001500 ExtraOpts.push_back("--build-id");
1501
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001502 if (Distro == ArchLinux)
1503 Lib = "lib";
1504
Rafael Espindolac1da9812010-11-07 20:14:31 +00001505 Paths.push_back(Base + Suffix);
1506 if (HasMultilib(Arch, Distro)) {
1507 if (IsOpenSuse(Distro) && Is32Bits)
1508 Paths.push_back(Base + "/../../../../" + GccTriple + "/lib/../lib");
1509 Paths.push_back(Base + "/../../../../" + Lib);
1510 Paths.push_back("/lib/../" + Lib);
1511 Paths.push_back("/usr/lib/../" + Lib);
1512 }
1513 if (!Suffix.empty())
1514 Paths.push_back(Base);
1515 if (IsOpenSuse(Distro))
1516 Paths.push_back(Base + "/../../../../" + GccTriple + "/lib");
1517 Paths.push_back(Base + "/../../..");
1518 if (Arch == getArch() && IsUbuntu(Distro))
1519 Paths.push_back("/usr/lib/" + GccTriple);
1520}
1521
1522bool Linux::HasNativeLLVMSupport() const {
1523 return true;
Eli Friedman6b3454a2009-05-26 07:52:18 +00001524}
1525
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001526Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA) const {
1527 Action::ActionClass Key;
1528 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1529 Key = Action::AnalyzeJobClass;
1530 else
1531 Key = JA.getKind();
1532
Rafael Espindoladda5b922010-11-07 23:13:01 +00001533 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1534 options::OPT_no_integrated_as,
1535 IsIntegratedAssemblerDefault());
1536
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001537 Tool *&T = Tools[Key];
1538 if (!T) {
1539 switch (Key) {
1540 case Action::AssembleJobClass:
Rafael Espindoladda5b922010-11-07 23:13:01 +00001541 if (UseIntegratedAs)
1542 T = new tools::ClangAs(*this);
1543 else
1544 T = new tools::linuxtools::Assemble(*this);
1545 break;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001546 case Action::LinkJobClass:
1547 T = new tools::linuxtools::Link(*this); break;
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001548 default:
1549 T = &Generic_GCC::SelectTool(C, JA);
1550 }
1551 }
1552
1553 return *T;
1554}
1555
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001556/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
1557
Daniel Dunbarcb8ab232009-05-22 02:53:45 +00001558DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001559 : Generic_ELF(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001560
1561 // Path mangling to find libexec
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001562 getProgramPaths().push_back(getDriver().getInstalledDir());
1563 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
1564 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001565
Daniel Dunbaree788e72009-12-21 18:54:17 +00001566 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001567 getFilePaths().push_back("/usr/lib");
1568 getFilePaths().push_back("/usr/lib/gcc41");
1569}
1570
1571Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
1572 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001573 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001574 Key = Action::AnalyzeJobClass;
1575 else
1576 Key = JA.getKind();
1577
1578 Tool *&T = Tools[Key];
1579 if (!T) {
1580 switch (Key) {
1581 case Action::AssembleJobClass:
1582 T = new tools::dragonfly::Assemble(*this); break;
1583 case Action::LinkJobClass:
1584 T = new tools::dragonfly::Link(*this); break;
1585 default:
1586 T = &Generic_GCC::SelectTool(C, JA);
1587 }
1588 }
1589
1590 return *T;
1591}
Michael J. Spencerff58e362010-08-21 21:55:07 +00001592
1593Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple)
1594 : ToolChain(Host, Triple) {
1595}
1596
1597Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA) const {
1598 Action::ActionClass Key;
1599 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1600 Key = Action::AnalyzeJobClass;
1601 else
1602 Key = JA.getKind();
1603
1604 Tool *&T = Tools[Key];
1605 if (!T) {
1606 switch (Key) {
1607 case Action::InputClass:
1608 case Action::BindArchClass:
Chandler Carruthe97673f2010-08-22 06:56:37 +00001609 case Action::LipoJobClass:
1610 case Action::DsymutilJobClass:
Michael J. Spencerff58e362010-08-21 21:55:07 +00001611 assert(0 && "Invalid tool kind.");
1612 case Action::PreprocessJobClass:
1613 case Action::PrecompileJobClass:
1614 case Action::AnalyzeJobClass:
1615 case Action::CompileJobClass:
1616 T = new tools::Clang(*this); break;
1617 case Action::AssembleJobClass:
1618 T = new tools::ClangAs(*this); break;
1619 case Action::LinkJobClass:
1620 T = new tools::visualstudio::Link(*this); break;
1621 }
1622 }
1623
1624 return *T;
1625}
1626
1627bool Windows::IsIntegratedAssemblerDefault() const {
1628 return true;
1629}
1630
1631bool Windows::IsUnwindTablesDefault() const {
1632 // FIXME: Gross; we should probably have some separate target
1633 // definition, possibly even reusing the one in clang.
1634 return getArchName() == "x86_64";
1635}
1636
1637const char *Windows::GetDefaultRelocationModel() const {
1638 return "static";
1639}
1640
1641const char *Windows::GetForcedPicModel() const {
1642 if (getArchName() == "x86_64")
1643 return "pic";
1644 return 0;
1645}