blob: 4a9be0ef76b18660edad786d31cb87bea9702505 [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 Dunbarbbe8e3e2011-03-01 18:49:30 +0000921bool Darwin::SupportsProfiling() const {
922 // Profiling instrumentation is only supported on x86.
923 return getArchName() == "i386" || getArchName() == "x86_64";
924}
925
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000926bool Darwin::SupportsObjCGC() const {
927 // Garbage collection is supported everywhere except on iPhone OS.
928 return !isTargetIPhoneOS();
929}
930
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000931std::string
932Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const {
933 return ComputeLLVMTriple(Args);
934}
935
Daniel Dunbar39176082009-03-20 00:20:03 +0000936/// Generic_GCC - A tool chain using the 'gcc' command to perform
937/// all subcommands; this relies on gcc translating the majority of
938/// command line options.
939
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000940Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000941 : ToolChain(Host, Triple) {
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000942 getProgramPaths().push_back(getDriver().getInstalledDir());
943 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
944 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000945}
946
Daniel Dunbar39176082009-03-20 00:20:03 +0000947Generic_GCC::~Generic_GCC() {
948 // Free tool implementations.
949 for (llvm::DenseMap<unsigned, Tool*>::iterator
950 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
951 delete it->second;
952}
953
Mike Stump1eb44332009-09-09 15:08:12 +0000954Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000955 const JobAction &JA) const {
956 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000957 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000958 Key = Action::AnalyzeJobClass;
959 else
960 Key = JA.getKind();
961
962 Tool *&T = Tools[Key];
963 if (!T) {
964 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000965 case Action::InputClass:
966 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000967 assert(0 && "Invalid tool kind.");
968 case Action::PreprocessJobClass:
969 T = new tools::gcc::Preprocess(*this); break;
970 case Action::PrecompileJobClass:
971 T = new tools::gcc::Precompile(*this); break;
972 case Action::AnalyzeJobClass:
973 T = new tools::Clang(*this); break;
974 case Action::CompileJobClass:
975 T = new tools::gcc::Compile(*this); break;
976 case Action::AssembleJobClass:
977 T = new tools::gcc::Assemble(*this); break;
978 case Action::LinkJobClass:
979 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000980
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000981 // This is a bit ungeneric, but the only platform using a driver
982 // driver is Darwin.
983 case Action::LipoJobClass:
984 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000985 case Action::DsymutilJobClass:
986 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000987 }
988 }
989
990 return *T;
991}
992
Daniel Dunbar39176082009-03-20 00:20:03 +0000993bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000994 // FIXME: Gross; we should probably have some separate target
995 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000996 return getArchName() == "x86_64";
997}
998
999const char *Generic_GCC::GetDefaultRelocationModel() const {
1000 return "static";
1001}
1002
1003const char *Generic_GCC::GetForcedPicModel() const {
1004 return 0;
1005}
Daniel Dunbarf3cad362009-03-25 04:13:45 +00001006
Chris Lattner3a47c4e2010-03-04 21:07:38 +00001007/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
1008/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
1009/// Currently does not support anything else but compilation.
1010
1011TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple)
1012 : ToolChain(Host, Triple) {
1013 // Path mangling to find libexec
1014 std::string Path(getDriver().Dir);
1015
1016 Path += "/../libexec";
1017 getProgramPaths().push_back(Path);
1018}
1019
1020TCEToolChain::~TCEToolChain() {
1021 for (llvm::DenseMap<unsigned, Tool*>::iterator
1022 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
1023 delete it->second;
1024}
1025
1026bool TCEToolChain::IsMathErrnoDefault() const {
1027 return true;
1028}
1029
1030bool TCEToolChain::IsUnwindTablesDefault() const {
1031 return false;
1032}
1033
1034const char *TCEToolChain::GetDefaultRelocationModel() const {
1035 return "static";
1036}
1037
1038const char *TCEToolChain::GetForcedPicModel() const {
1039 return 0;
1040}
1041
1042Tool &TCEToolChain::SelectTool(const Compilation &C,
1043 const JobAction &JA) const {
1044 Action::ActionClass Key;
1045 Key = Action::AnalyzeJobClass;
1046
1047 Tool *&T = Tools[Key];
1048 if (!T) {
1049 switch (Key) {
1050 case Action::PreprocessJobClass:
1051 T = new tools::gcc::Preprocess(*this); break;
1052 case Action::AnalyzeJobClass:
1053 T = new tools::Clang(*this); break;
1054 default:
1055 assert(false && "Unsupported action for TCE target.");
1056 }
1057 }
1058 return *T;
1059}
1060
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001061/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
1062
1063OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001064 : Generic_ELF(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +00001065 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001066 getFilePaths().push_back("/usr/lib");
1067}
1068
1069Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
1070 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001071 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001072 Key = Action::AnalyzeJobClass;
1073 else
1074 Key = JA.getKind();
1075
Rafael Espindoladda5b922010-11-07 23:13:01 +00001076 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1077 options::OPT_no_integrated_as,
1078 IsIntegratedAssemblerDefault());
1079
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001080 Tool *&T = Tools[Key];
1081 if (!T) {
1082 switch (Key) {
Rafael Espindoladda5b922010-11-07 23:13:01 +00001083 case Action::AssembleJobClass: {
1084 if (UseIntegratedAs)
1085 T = new tools::ClangAs(*this);
1086 else
1087 T = new tools::openbsd::Assemble(*this);
1088 break;
1089 }
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001090 case Action::LinkJobClass:
1091 T = new tools::openbsd::Link(*this); break;
1092 default:
1093 T = &Generic_GCC::SelectTool(C, JA);
1094 }
1095 }
1096
1097 return *T;
1098}
1099
Daniel Dunbar75358d22009-03-30 21:06:03 +00001100/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
1101
Daniel Dunbar214afe92010-08-02 05:43:59 +00001102FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001103 : Generic_ELF(Host, Triple) {
Daniel Dunbar214afe92010-08-02 05:43:59 +00001104
1105 // Determine if we are compiling 32-bit code on an x86_64 platform.
1106 bool Lib32 = false;
1107 if (Triple.getArch() == llvm::Triple::x86 &&
1108 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1109 llvm::Triple::x86_64)
1110 Lib32 = true;
1111
Daniel Dunbarbc534662009-04-02 18:30:04 +00001112 if (Lib32) {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001113 getFilePaths().push_back("/usr/lib32");
1114 } else {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001115 getFilePaths().push_back("/usr/lib");
1116 }
Daniel Dunbar75358d22009-03-30 21:06:03 +00001117}
1118
1119Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
1120 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001121 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +00001122 Key = Action::AnalyzeJobClass;
1123 else
1124 Key = JA.getKind();
1125
Roman Divacky67dece72010-11-08 17:46:39 +00001126 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1127 options::OPT_no_integrated_as,
1128 IsIntegratedAssemblerDefault());
1129
Daniel Dunbar75358d22009-03-30 21:06:03 +00001130 Tool *&T = Tools[Key];
1131 if (!T) {
1132 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +00001133 case Action::AssembleJobClass:
Roman Divacky67dece72010-11-08 17:46:39 +00001134 if (UseIntegratedAs)
1135 T = new tools::ClangAs(*this);
1136 else
1137 T = new tools::freebsd::Assemble(*this);
Roman Divackyfe3a7ea2010-11-08 19:39:10 +00001138 break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +00001139 case Action::LinkJobClass:
1140 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +00001141 default:
1142 T = &Generic_GCC::SelectTool(C, JA);
1143 }
1144 }
1145
1146 return *T;
1147}
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001148
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001149/// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly.
1150
1151NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple)
1152 : Generic_ELF(Host, Triple) {
1153
1154 // Determine if we are compiling 32-bit code on an x86_64 platform.
1155 bool Lib32 = false;
1156 if (Triple.getArch() == llvm::Triple::x86 &&
1157 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1158 llvm::Triple::x86_64)
1159 Lib32 = true;
1160
1161 getProgramPaths().push_back(getDriver().Dir + "/../libexec");
1162 getProgramPaths().push_back("/usr/libexec");
1163 if (Lib32) {
1164 getFilePaths().push_back("/usr/lib/i386");
1165 } else {
1166 getFilePaths().push_back("/usr/lib");
1167 }
1168}
1169
1170Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
1171 Action::ActionClass Key;
1172 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1173 Key = Action::AnalyzeJobClass;
1174 else
1175 Key = JA.getKind();
1176
1177 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1178 options::OPT_no_integrated_as,
1179 IsIntegratedAssemblerDefault());
1180
1181 Tool *&T = Tools[Key];
1182 if (!T) {
1183 switch (Key) {
1184 case Action::AssembleJobClass:
1185 if (UseIntegratedAs)
1186 T = new tools::ClangAs(*this);
1187 else
1188 T = new tools::netbsd::Assemble(*this);
1189 break;
1190 case Action::LinkJobClass:
1191 T = new tools::netbsd::Link(*this); break;
1192 default:
1193 T = &Generic_GCC::SelectTool(C, JA);
1194 }
1195 }
1196
1197 return *T;
1198}
1199
Chris Lattner38e317d2010-07-07 16:01:42 +00001200/// Minix - Minix tool chain which can call as(1) and ld(1) directly.
1201
1202Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple)
1203 : Generic_GCC(Host, Triple) {
1204 getFilePaths().push_back(getDriver().Dir + "/../lib");
1205 getFilePaths().push_back("/usr/lib");
1206 getFilePaths().push_back("/usr/gnu/lib");
1207 getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
1208}
1209
1210Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA) const {
1211 Action::ActionClass Key;
1212 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1213 Key = Action::AnalyzeJobClass;
1214 else
1215 Key = JA.getKind();
1216
1217 Tool *&T = Tools[Key];
1218 if (!T) {
1219 switch (Key) {
1220 case Action::AssembleJobClass:
1221 T = new tools::minix::Assemble(*this); break;
1222 case Action::LinkJobClass:
1223 T = new tools::minix::Link(*this); break;
1224 default:
1225 T = &Generic_GCC::SelectTool(C, JA);
1226 }
1227 }
1228
1229 return *T;
1230}
1231
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001232/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
1233
1234AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
1235 : Generic_GCC(Host, Triple) {
1236
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001237 getProgramPaths().push_back(getDriver().getInstalledDir());
1238 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
1239 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001240
Daniel Dunbaree788e72009-12-21 18:54:17 +00001241 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001242 getFilePaths().push_back("/usr/lib");
1243 getFilePaths().push_back("/usr/sfw/lib");
1244 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +00001245 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001246
1247}
1248
1249Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
1250 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001251 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001252 Key = Action::AnalyzeJobClass;
1253 else
1254 Key = JA.getKind();
1255
1256 Tool *&T = Tools[Key];
1257 if (!T) {
1258 switch (Key) {
1259 case Action::AssembleJobClass:
1260 T = new tools::auroraux::Assemble(*this); break;
1261 case Action::LinkJobClass:
1262 T = new tools::auroraux::Link(*this); break;
1263 default:
1264 T = &Generic_GCC::SelectTool(C, JA);
1265 }
1266 }
1267
1268 return *T;
1269}
1270
1271
Eli Friedman6b3454a2009-05-26 07:52:18 +00001272/// Linux toolchain (very bare-bones at the moment).
1273
Rafael Espindolac1da9812010-11-07 20:14:31 +00001274enum LinuxDistro {
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001275 ArchLinux,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001276 DebianLenny,
1277 DebianSqueeze,
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001278 Exherbo,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001279 Fedora13,
1280 Fedora14,
1281 OpenSuse11_3,
Rafael Espindola021aaa42010-11-10 05:00:22 +00001282 UbuntuJaunty,
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001283 UbuntuKarmic,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001284 UbuntuLucid,
1285 UbuntuMaverick,
1286 UnknownDistro
1287};
1288
1289static bool IsFedora(enum LinuxDistro Distro) {
1290 return Distro == Fedora13 || Distro == Fedora14;
1291}
1292
1293static bool IsOpenSuse(enum LinuxDistro Distro) {
1294 return Distro == OpenSuse11_3;
1295}
1296
1297static bool IsDebian(enum LinuxDistro Distro) {
1298 return Distro == DebianLenny || Distro == DebianSqueeze;
1299}
1300
1301static bool IsUbuntu(enum LinuxDistro Distro) {
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001302 return Distro == UbuntuLucid || Distro == UbuntuMaverick ||
1303 Distro == UbuntuJaunty || Distro == UbuntuKarmic;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001304}
1305
1306static bool IsDebianBased(enum LinuxDistro Distro) {
1307 return IsDebian(Distro) || IsUbuntu(Distro);
1308}
1309
1310static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) {
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001311 if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001312 bool Exists;
1313 if (Distro == Exherbo &&
1314 (llvm::sys::fs::exists("/usr/lib32/libc.so", Exists) || !Exists))
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001315 return false;
1316
Rafael Espindolac1da9812010-11-07 20:14:31 +00001317 return true;
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001318 }
Rafael Espindolac1da9812010-11-07 20:14:31 +00001319 if (Arch == llvm::Triple::x86 && IsDebianBased(Distro))
1320 return true;
1321 return false;
1322}
1323
1324static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001325 llvm::OwningPtr<llvm::MemoryBuffer> File;
1326 if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) {
1327 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001328 llvm::SmallVector<llvm::StringRef, 8> Lines;
1329 Data.split(Lines, "\n");
1330 for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) {
1331 if (Lines[i] == "DISTRIB_CODENAME=maverick")
1332 return UbuntuMaverick;
1333 else if (Lines[i] == "DISTRIB_CODENAME=lucid")
1334 return UbuntuLucid;
Rafael Espindola021aaa42010-11-10 05:00:22 +00001335 else if (Lines[i] == "DISTRIB_CODENAME=jaunty")
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001336 return UbuntuJaunty;
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001337 else if (Lines[i] == "DISTRIB_CODENAME=karmic")
1338 return UbuntuKarmic;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001339 }
1340 return UnknownDistro;
1341 }
1342
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001343 if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) {
1344 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001345 if (Data.startswith("Fedora release 14 (Laughlin)"))
1346 return Fedora14;
1347 else if (Data.startswith("Fedora release 13 (Goddard)"))
1348 return Fedora13;
1349 return UnknownDistro;
1350 }
1351
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001352 if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) {
1353 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001354 if (Data[0] == '5')
1355 return DebianLenny;
1356 else if (Data.startswith("squeeze/sid"))
1357 return DebianSqueeze;
1358 return UnknownDistro;
1359 }
1360
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001361 if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) {
1362 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001363 if (Data.startswith("openSUSE 11.3"))
1364 return OpenSuse11_3;
1365 return UnknownDistro;
1366 }
1367
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001368 bool Exists;
1369 if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001370 return Exherbo;
1371
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001372 if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists)
1373 return ArchLinux;
1374
Rafael Espindolac1da9812010-11-07 20:14:31 +00001375 return UnknownDistro;
1376}
1377
Nick Lewycky3fdcc6f2010-12-31 17:31:54 +00001378Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001379 : Generic_ELF(Host, Triple) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001380 llvm::Triple::ArchType Arch =
1381 llvm::Triple(getDriver().DefaultHostTriple).getArch();
Daniel Dunbara9822de2009-08-06 01:47:11 +00001382
Rafael Espindolac1da9812010-11-07 20:14:31 +00001383 std::string Suffix32 = "";
1384 if (Arch == llvm::Triple::x86_64)
1385 Suffix32 = "/32";
Daniel Dunbara9822de2009-08-06 01:47:11 +00001386
Rafael Espindolac1da9812010-11-07 20:14:31 +00001387 std::string Suffix64 = "";
1388 if (Arch == llvm::Triple::x86)
1389 Suffix64 = "/64";
1390
1391 std::string Lib32 = "lib";
1392
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001393 bool Exists;
1394 if (!llvm::sys::fs::exists("/lib32", Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001395 Lib32 = "lib32";
1396
1397 std::string Lib64 = "lib";
Michael J. Spencer2dea7c72011-01-12 23:54:48 +00001398 bool Symlink;
Chris Lattner48aef362011-01-13 01:35:58 +00001399 if (!llvm::sys::fs::exists("/lib64", Exists) && Exists &&
1400 (llvm::sys::fs::is_symlink("/lib64", Symlink) || !Symlink))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001401 Lib64 = "lib64";
1402
1403 std::string GccTriple = "";
1404 if (Arch == llvm::Triple::arm) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001405 if (!llvm::sys::fs::exists("/usr/lib/gcc/arm-linux-gnueabi", Exists) &&
1406 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001407 GccTriple = "arm-linux-gnueabi";
1408 } else if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001409 if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-linux-gnu", Exists) &&
1410 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001411 GccTriple = "x86_64-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001412 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-unknown-linux-gnu",
1413 Exists) && Exists)
Rafael Espindola53dd00b2010-11-17 00:25:26 +00001414 GccTriple = "x86_64-unknown-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001415 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-pc-linux-gnu",
1416 Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001417 GccTriple = "x86_64-pc-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001418 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-redhat-linux",
1419 Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001420 GccTriple = "x86_64-redhat-linux";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001421 else if (!llvm::sys::fs::exists("/usr/lib64/gcc/x86_64-suse-linux",
1422 Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001423 GccTriple = "x86_64-suse-linux";
Nick Lewyckye10f9002011-02-01 23:03:29 +00001424 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-manbo-linux-gnu",
1425 Exists) && Exists)
1426 GccTriple = "x86_64-manbo-linux-gnu";
Rafael Espindolac1da9812010-11-07 20:14:31 +00001427 } else if (Arch == llvm::Triple::x86) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001428 if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-linux-gnu", Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001429 GccTriple = "i686-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001430 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-pc-linux-gnu", Exists) &&
1431 Exists)
Nuno Lopes2a69ddd2010-11-19 17:26:57 +00001432 GccTriple = "i686-pc-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001433 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-linux-gnu", Exists) &&
1434 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001435 GccTriple = "i486-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001436 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-redhat-linux", Exists) &&
1437 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001438 GccTriple = "i686-redhat-linux";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001439 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i586-suse-linux", Exists) &&
1440 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001441 GccTriple = "i586-suse-linux";
1442 }
1443
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001444 const char* GccVersions[] = {"4.5.2", "4.5.1", "4.5", "4.4.5", "4.4.4",
1445 "4.4.3", "4.4", "4.3.4", "4.3.3", "4.3.2",
1446 "4.3"};
Rafael Espindolac1da9812010-11-07 20:14:31 +00001447 std::string Base = "";
1448 for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) {
1449 std::string Suffix = GccTriple + "/" + GccVersions[i];
1450 std::string t1 = "/usr/lib/gcc/" + Suffix;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001451 if (!llvm::sys::fs::exists(t1 + "/crtbegin.o", Exists) && Exists) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001452 Base = t1;
1453 break;
1454 }
1455 std::string t2 = "/usr/lib64/gcc/" + Suffix;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001456 if (!llvm::sys::fs::exists(t2 + "/crtbegin.o", Exists) && Exists) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001457 Base = t2;
1458 break;
1459 }
1460 }
1461
1462 path_list &Paths = getFilePaths();
1463 bool Is32Bits = getArch() == llvm::Triple::x86;
1464
1465 std::string Suffix;
1466 std::string Lib;
1467
1468 if (Is32Bits) {
1469 Suffix = Suffix32;
1470 Lib = Lib32;
1471 } else {
1472 Suffix = Suffix64;
1473 Lib = Lib64;
1474 }
1475
1476 llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld");
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001477 if (!llvm::sys::fs::exists(LinkerPath.str(), Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001478 Linker = LinkerPath.str();
1479 else
1480 Linker = GetProgramPath("ld");
1481
1482 LinuxDistro Distro = DetectLinuxDistro(Arch);
1483
Rafael Espindola94c80222010-11-08 14:48:47 +00001484 if (IsUbuntu(Distro)) {
1485 ExtraOpts.push_back("-z");
1486 ExtraOpts.push_back("relro");
1487 }
Rafael Espindolac1da9812010-11-07 20:14:31 +00001488
1489 if (Arch == llvm::Triple::arm)
1490 ExtraOpts.push_back("-X");
1491
1492 if (IsFedora(Distro) || Distro == UbuntuMaverick)
1493 ExtraOpts.push_back("--hash-style=gnu");
1494
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001495 if (IsDebian(Distro) || Distro == UbuntuLucid || Distro == UbuntuJaunty ||
1496 Distro == UbuntuKarmic)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001497 ExtraOpts.push_back("--hash-style=both");
1498
1499 if (IsFedora(Distro))
1500 ExtraOpts.push_back("--no-add-needed");
1501
Rafael Espindola021aaa42010-11-10 05:00:22 +00001502 if (Distro == DebianSqueeze || IsOpenSuse(Distro) ||
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001503 IsFedora(Distro) || Distro == UbuntuLucid || Distro == UbuntuMaverick ||
1504 Distro == UbuntuKarmic)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001505 ExtraOpts.push_back("--build-id");
1506
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001507 if (Distro == ArchLinux)
1508 Lib = "lib";
1509
Rafael Espindolac1da9812010-11-07 20:14:31 +00001510 Paths.push_back(Base + Suffix);
1511 if (HasMultilib(Arch, Distro)) {
1512 if (IsOpenSuse(Distro) && Is32Bits)
1513 Paths.push_back(Base + "/../../../../" + GccTriple + "/lib/../lib");
1514 Paths.push_back(Base + "/../../../../" + Lib);
1515 Paths.push_back("/lib/../" + Lib);
1516 Paths.push_back("/usr/lib/../" + Lib);
1517 }
1518 if (!Suffix.empty())
1519 Paths.push_back(Base);
1520 if (IsOpenSuse(Distro))
1521 Paths.push_back(Base + "/../../../../" + GccTriple + "/lib");
1522 Paths.push_back(Base + "/../../..");
1523 if (Arch == getArch() && IsUbuntu(Distro))
1524 Paths.push_back("/usr/lib/" + GccTriple);
1525}
1526
1527bool Linux::HasNativeLLVMSupport() const {
1528 return true;
Eli Friedman6b3454a2009-05-26 07:52:18 +00001529}
1530
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001531Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA) const {
1532 Action::ActionClass Key;
1533 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1534 Key = Action::AnalyzeJobClass;
1535 else
1536 Key = JA.getKind();
1537
Rafael Espindoladda5b922010-11-07 23:13:01 +00001538 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1539 options::OPT_no_integrated_as,
1540 IsIntegratedAssemblerDefault());
1541
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001542 Tool *&T = Tools[Key];
1543 if (!T) {
1544 switch (Key) {
1545 case Action::AssembleJobClass:
Rafael Espindoladda5b922010-11-07 23:13:01 +00001546 if (UseIntegratedAs)
1547 T = new tools::ClangAs(*this);
1548 else
1549 T = new tools::linuxtools::Assemble(*this);
1550 break;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001551 case Action::LinkJobClass:
1552 T = new tools::linuxtools::Link(*this); break;
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001553 default:
1554 T = &Generic_GCC::SelectTool(C, JA);
1555 }
1556 }
1557
1558 return *T;
1559}
1560
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001561/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
1562
Daniel Dunbarcb8ab232009-05-22 02:53:45 +00001563DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001564 : Generic_ELF(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001565
1566 // Path mangling to find libexec
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001567 getProgramPaths().push_back(getDriver().getInstalledDir());
1568 if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
1569 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001570
Daniel Dunbaree788e72009-12-21 18:54:17 +00001571 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001572 getFilePaths().push_back("/usr/lib");
1573 getFilePaths().push_back("/usr/lib/gcc41");
1574}
1575
1576Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
1577 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001578 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001579 Key = Action::AnalyzeJobClass;
1580 else
1581 Key = JA.getKind();
1582
1583 Tool *&T = Tools[Key];
1584 if (!T) {
1585 switch (Key) {
1586 case Action::AssembleJobClass:
1587 T = new tools::dragonfly::Assemble(*this); break;
1588 case Action::LinkJobClass:
1589 T = new tools::dragonfly::Link(*this); break;
1590 default:
1591 T = &Generic_GCC::SelectTool(C, JA);
1592 }
1593 }
1594
1595 return *T;
1596}
Michael J. Spencerff58e362010-08-21 21:55:07 +00001597
1598Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple)
1599 : ToolChain(Host, Triple) {
1600}
1601
1602Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA) const {
1603 Action::ActionClass Key;
1604 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1605 Key = Action::AnalyzeJobClass;
1606 else
1607 Key = JA.getKind();
1608
1609 Tool *&T = Tools[Key];
1610 if (!T) {
1611 switch (Key) {
1612 case Action::InputClass:
1613 case Action::BindArchClass:
Chandler Carruthe97673f2010-08-22 06:56:37 +00001614 case Action::LipoJobClass:
1615 case Action::DsymutilJobClass:
Michael J. Spencerff58e362010-08-21 21:55:07 +00001616 assert(0 && "Invalid tool kind.");
1617 case Action::PreprocessJobClass:
1618 case Action::PrecompileJobClass:
1619 case Action::AnalyzeJobClass:
1620 case Action::CompileJobClass:
1621 T = new tools::Clang(*this); break;
1622 case Action::AssembleJobClass:
1623 T = new tools::ClangAs(*this); break;
1624 case Action::LinkJobClass:
1625 T = new tools::visualstudio::Link(*this); break;
1626 }
1627 }
1628
1629 return *T;
1630}
1631
1632bool Windows::IsIntegratedAssemblerDefault() const {
1633 return true;
1634}
1635
1636bool Windows::IsUnwindTablesDefault() const {
1637 // FIXME: Gross; we should probably have some separate target
1638 // definition, possibly even reusing the one in clang.
1639 return getArchName() == "x86_64";
1640}
1641
1642const char *Windows::GetDefaultRelocationModel() const {
1643 return "static";
1644}
1645
1646const char *Windows::GetForcedPicModel() const {
1647 if (getArchName() == "x86_64")
1648 return "pic";
1649 return 0;
1650}