blob: d0622904576f814f4a7b79df7b6269e02e8a6fad [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" ||
Bob Wilson1ec0ade2011-03-21 20:40:05 +0000104 Value == "arm1176jz-s" || Value == "arm1176jzf-s" ||
105 Value == "cortex-m0" )
Daniel Dunbareeff4062010-01-22 02:04:58 +0000106 return "armv6";
107
108 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
109 return "armv7";
110
111 return 0;
112}
113
114llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
115 switch (getTriple().getArch()) {
116 default:
117 return getArchName();
Douglas Gregorf0594d82011-03-06 19:11:49 +0000118
119 case llvm::Triple::thumb:
Daniel Dunbareeff4062010-01-22 02:04:58 +0000120 case llvm::Triple::arm: {
121 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
122 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
123 return Arch;
124
125 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
126 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
127 return Arch;
128
129 return "arm";
130 }
131 }
132}
133
Daniel Dunbarf3955282009-09-04 18:34:51 +0000134Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000135 // Free tool implementations.
136 for (llvm::DenseMap<unsigned, Tool*>::iterator
137 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
138 delete it->second;
139}
140
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000141std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args) const {
142 llvm::Triple Triple(ComputeLLVMTriple(Args));
143
144 // If the target isn't initialized (e.g., an unknown Darwin platform, return
145 // the default triple).
146 if (!isTargetInitialized())
147 return Triple.getTriple();
148
149 unsigned Version[3];
150 getTargetVersion(Version);
Daniel Dunbar729f38e2011-04-19 21:45:47 +0000151
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000152 llvm::SmallString<16> Str;
Daniel Dunbar729f38e2011-04-19 21:45:47 +0000153 llvm::raw_svector_ostream(Str)
Daniel Dunbar659d23a2011-04-19 23:34:17 +0000154 << (isTargetIPhoneOS() ? "ios" : "macosx")
Daniel Dunbar729f38e2011-04-19 21:45:47 +0000155 << Version[0] << "." << Version[1] << "." << Version[2];
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000156 Triple.setOSName(Str.str());
157
158 return Triple.getTriple();
159}
160
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000161Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA,
162 const ActionList &Inputs) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000163 Action::ActionClass Key;
Daniel Dunbar5ce872f2011-03-18 20:14:03 +0000164
165 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) {
166 // Fallback to llvm-gcc for i386 kext compiles, we don't support that ABI.
167 if (Inputs.size() == 1 &&
168 types::isCXX(Inputs[0]->getType()) &&
169 getTriple().getOS() == llvm::Triple::Darwin &&
170 getTriple().getArch() == llvm::Triple::x86 &&
171 C.getArgs().getLastArg(options::OPT_fapple_kext))
172 Key = JA.getKind();
173 else
174 Key = Action::AnalyzeJobClass;
175 } else
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000176 Key = JA.getKind();
177
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000178 // FIXME: This doesn't belong here, but ideally we will support static soon
179 // anyway.
180 bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) ||
181 C.getArgs().hasArg(options::OPT_static) ||
182 C.getArgs().hasArg(options::OPT_fapple_kext));
183 bool IsIADefault = IsIntegratedAssemblerDefault() && !HasStatic;
184 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
185 options::OPT_no_integrated_as,
186 IsIADefault);
187
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000188 Tool *&T = Tools[Key];
189 if (!T) {
190 switch (Key) {
191 case Action::InputClass:
192 case Action::BindArchClass:
193 assert(0 && "Invalid tool kind.");
194 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000195 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000196 case Action::AnalyzeJobClass:
197 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000198 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000199 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000200 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000201 case Action::AssembleJobClass: {
202 if (UseIntegratedAs)
203 T = new tools::ClangAs(*this);
204 else
205 T = new tools::darwin::Assemble(*this);
206 break;
207 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000208 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000209 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000210 case Action::LipoJobClass:
211 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000212 case Action::DsymutilJobClass:
213 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000214 }
215 }
216
217 return *T;
218}
219
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000220
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000221DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple)
222 : Darwin(Host, Triple)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000223{
Daniel Dunbar47023092011-03-18 19:25:15 +0000224 std::string UsrPrefix = "llvm-gcc-4.2/";
225
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000226 getProgramPaths().push_back(getDriver().getInstalledDir());
227 if (getDriver().getInstalledDir() != getDriver().Dir)
228 getProgramPaths().push_back(getDriver().Dir);
229
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000230 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000231 getProgramPaths().push_back(getDriver().getInstalledDir());
232 if (getDriver().getInstalledDir() != getDriver().Dir)
233 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000234
235 // For fallback, we need to know how to find the GCC cc1 executables, so we
Daniel Dunbar47023092011-03-18 19:25:15 +0000236 // also add the GCC libexec paths. This is legacy code that can be removed
237 // once fallback is no longer useful.
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000238 std::string ToolChainDir = "i686-apple-darwin";
239 ToolChainDir += llvm::utostr(DarwinVersion[0]);
240 ToolChainDir += "/4.2.1";
241
242 std::string Path = getDriver().Dir;
Daniel Dunbar47023092011-03-18 19:25:15 +0000243 Path += "/../" + UsrPrefix + "libexec/gcc/";
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000244 Path += ToolChainDir;
245 getProgramPaths().push_back(Path);
246
Daniel Dunbar47023092011-03-18 19:25:15 +0000247 Path = "/usr/" + UsrPrefix + "libexec/gcc/";
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000248 Path += ToolChainDir;
249 getProgramPaths().push_back(Path);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000250}
251
252void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
253 ArgStringList &CmdArgs) const {
254 // The Clang toolchain uses explicit paths for internal libraries.
Daniel Dunbar424b6612010-06-30 23:56:13 +0000255
256 // Unfortunately, we still might depend on a few of the libraries that are
257 // only available in the gcc library directory (in particular
258 // libstdc++.dylib). For now, hardcode the path to the known install location.
259 llvm::sys::Path P(getDriver().Dir);
260 P.eraseComponent(); // .../usr/bin -> ../usr
261 P.appendComponent("lib");
262 P.appendComponent("gcc");
263 switch (getTriple().getArch()) {
264 default:
265 assert(0 && "Invalid Darwin arch!");
266 case llvm::Triple::x86:
267 case llvm::Triple::x86_64:
268 P.appendComponent("i686-apple-darwin10");
269 break;
270 case llvm::Triple::arm:
271 case llvm::Triple::thumb:
272 P.appendComponent("arm-apple-darwin10");
273 break;
274 case llvm::Triple::ppc:
275 case llvm::Triple::ppc64:
276 P.appendComponent("powerpc-apple-darwin10");
277 break;
278 }
279 P.appendComponent("4.2.1");
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000280
281 // Determine the arch specific GCC subdirectory.
282 const char *ArchSpecificDir = 0;
283 switch (getTriple().getArch()) {
284 default:
285 break;
286 case llvm::Triple::arm:
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000287 case llvm::Triple::thumb: {
288 std::string Triple = ComputeLLVMTriple(Args);
289 llvm::StringRef TripleStr = Triple;
290 if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5"))
291 ArchSpecificDir = "v5";
292 else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6"))
293 ArchSpecificDir = "v6";
294 else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7"))
295 ArchSpecificDir = "v7";
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000296 break;
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000297 }
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000298 case llvm::Triple::ppc64:
299 ArchSpecificDir = "ppc64";
300 break;
301 case llvm::Triple::x86_64:
302 ArchSpecificDir = "x86_64";
303 break;
304 }
305
306 if (ArchSpecificDir) {
307 P.appendComponent(ArchSpecificDir);
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000308 bool Exists;
309 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000310 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
311 P.eraseComponent();
312 }
313
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000314 bool Exists;
315 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbar424b6612010-06-30 23:56:13 +0000316 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000317}
318
319void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
320 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000321 // Darwin doesn't support real static executables, don't link any runtime
322 // libraries with -static.
323 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000324 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000325
326 // Reject -static-libgcc for now, we can deal with this when and if someone
327 // cares. This is useful in situations where someone wants to statically link
328 // something like libstdc++, and needs its runtime support routines.
329 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000330 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000331 << A->getAsString(Args);
332 return;
333 }
334
Daniel Dunbareec99102010-01-22 03:38:14 +0000335 // Otherwise link libSystem, then the dynamic runtime library, and finally any
336 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000337 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000338
339 // Select the dynamic runtime library and the target specific static library.
340 const char *DarwinStaticLib = 0;
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000341 if (isTargetIPhoneOS()) {
Daniel Dunbar87e945f2011-04-30 04:25:16 +0000342 // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
343 // it never went into the SDK.
344 if (!isTargetIOSSimulator())
345 CmdArgs.push_back("-lgcc_s.1");
Daniel Dunbareec99102010-01-22 03:38:14 +0000346
Daniel Dunbar3cceec52011-04-18 23:48:36 +0000347 // We currently always need a static runtime library for iOS.
348 DarwinStaticLib = "libclang_rt.ios.a";
Daniel Dunbareec99102010-01-22 03:38:14 +0000349 } else {
Daniel Dunbareec99102010-01-22 03:38:14 +0000350 // The dynamic runtime library was merged with libSystem for 10.6 and
351 // beyond; only 10.4 and 10.5 need an additional runtime library.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000352 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000353 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000354 else if (isMacosxVersionLT(10, 6))
Daniel Dunbareec99102010-01-22 03:38:14 +0000355 CmdArgs.push_back("-lgcc_s.10.5");
356
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000357 // For OS X, we thought we would only need a static runtime library when
Chris Lattnerfc8f0e12011-04-15 05:22:18 +0000358 // targeting 10.4, to provide versions of the static functions which were
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000359 // omitted from 10.4.dylib.
360 //
361 // Unfortunately, that turned out to not be true, because Darwin system
362 // headers can still use eprintf on i386, and it is not exported from
363 // libSystem. Therefore, we still must provide a runtime library just for
364 // the tiny tiny handful of projects that *might* use that symbol.
365 if (isMacosxVersionLT(10, 5)) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000366 DarwinStaticLib = "libclang_rt.10.4.a";
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000367 } else {
368 if (getTriple().getArch() == llvm::Triple::x86)
369 DarwinStaticLib = "libclang_rt.eprintf.a";
370 }
Daniel Dunbareec99102010-01-22 03:38:14 +0000371 }
372
373 /// Add the target specific static library, if needed.
374 if (DarwinStaticLib) {
375 llvm::sys::Path P(getDriver().ResourceDir);
376 P.appendComponent("lib");
377 P.appendComponent("darwin");
378 P.appendComponent(DarwinStaticLib);
379
380 // For now, allow missing resource libraries to support developers who may
381 // not have compiler-rt checked out or integrated into their build.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000382 bool Exists;
383 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbareec99102010-01-22 03:38:14 +0000384 CmdArgs.push_back(Args.MakeArgString(P.str()));
385 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000386}
387
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000388void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000389 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000390
Daniel Dunbar26031372010-01-27 00:56:25 +0000391 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000392 Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
393 Arg *iOSSimVersion = Args.getLastArg(
394 options::OPT_mios_simulator_version_min_EQ);
395 if (OSXVersion && (iOSVersion || iOSSimVersion)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000396 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000397 << OSXVersion->getAsString(Args)
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000398 << (iOSVersion ? iOSVersion : iOSSimVersion)->getAsString(Args);
399 iOSVersion = iOSSimVersion = 0;
400 } else if (iOSVersion && iOSSimVersion) {
401 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
402 << iOSVersion->getAsString(Args)
403 << iOSSimVersion->getAsString(Args);
404 iOSSimVersion = 0;
405 } else if (!OSXVersion && !iOSVersion && !iOSSimVersion) {
406 // If not deployment target was specified on the command line, check for
Daniel Dunbar816bc312010-01-26 01:45:19 +0000407 // environment defines.
408 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000409 const char *iOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
410 const char *iOSSimTarget = ::getenv("IOS_SIMULATOR_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000411
Daniel Dunbar816bc312010-01-26 01:45:19 +0000412 // Ignore empty strings.
413 if (OSXTarget && OSXTarget[0] == '\0')
414 OSXTarget = 0;
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000415 if (iOSTarget && iOSTarget[0] == '\0')
416 iOSTarget = 0;
417 if (iOSSimTarget && iOSSimTarget[0] == '\0')
418 iOSSimTarget = 0;
Daniel Dunbar816bc312010-01-26 01:45:19 +0000419
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000420 // Handle conflicting deployment targets
Daniel Dunbar39053672010-02-02 17:31:12 +0000421 //
422 // FIXME: Don't hardcode default here.
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000423
424 // Do not allow conflicts with the iOS simulator target.
425 if (iOSSimTarget && (OSXTarget || iOSTarget)) {
426 getDriver().Diag(clang::diag::err_drv_conflicting_deployment_targets)
427 << "IOS_SIMULATOR_DEPLOYMENT_TARGET"
428 << (OSXTarget ? "MACOSX_DEPLOYMENT_TARGET" :
429 "IPHONEOS_DEPLOYMENT_TARGET");
430 }
431
432 // Allow conflicts among OSX and iOS for historical reasons, but choose the
433 // default platform.
434 if (OSXTarget && iOSTarget) {
Daniel Dunbar39053672010-02-02 17:31:12 +0000435 if (getTriple().getArch() == llvm::Triple::arm ||
436 getTriple().getArch() == llvm::Triple::thumb)
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000437 OSXTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000438 else
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000439 iOSTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000440 }
Daniel Dunbar1a3c1d92010-01-29 17:02:25 +0000441
Daniel Dunbar39053672010-02-02 17:31:12 +0000442 if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000443 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000444 OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget);
445 Args.append(OSXVersion);
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000446 } else if (iOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000447 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000448 iOSVersion = Args.MakeJoinedArg(0, O, iOSTarget);
449 Args.append(iOSVersion);
450 } else if (iOSSimTarget) {
451 const Option *O = Opts.getOption(
452 options::OPT_mios_simulator_version_min_EQ);
453 iOSSimVersion = Args.MakeJoinedArg(0, O, iOSSimTarget);
454 Args.append(iOSSimVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000455 } else {
Daniel Dunbar2bb38d02010-07-15 16:18:06 +0000456 // Otherwise, assume we are targeting OS X.
457 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000458 OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin);
459 Args.append(OSXVersion);
Daniel Dunbar30392de2009-09-04 18:35:21 +0000460 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000461 }
Mike Stump1eb44332009-09-09 15:08:12 +0000462
Daniel Dunbar3fd823b2011-04-30 04:20:40 +0000463 // Reject invalid architecture combinations.
464 if (iOSSimVersion && (getTriple().getArch() != llvm::Triple::x86 &&
465 getTriple().getArch() != llvm::Triple::x86_64)) {
466 getDriver().Diag(clang::diag::err_drv_invalid_arch_for_deployment_target)
467 << getTriple().getArchName() << iOSSimVersion->getAsString(Args);
468 }
469
Daniel Dunbar26031372010-01-27 00:56:25 +0000470 // Set the tool chain target information.
471 unsigned Major, Minor, Micro;
472 bool HadExtra;
473 if (OSXVersion) {
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000474 assert((!iOSVersion && !iOSSimVersion) && "Unknown target platform!");
Daniel Dunbar26031372010-01-27 00:56:25 +0000475 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
476 Micro, HadExtra) || HadExtra ||
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000477 Major != 10 || Minor >= 100 || Micro >= 100)
Daniel Dunbar26031372010-01-27 00:56:25 +0000478 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
479 << OSXVersion->getAsString(Args);
480 } else {
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000481 const Arg *Version = iOSVersion ? iOSVersion : iOSSimVersion;
482 assert(Version && "Unknown target platform!");
483 if (!Driver::GetReleaseVersion(Version->getValue(Args), Major, Minor,
Daniel Dunbar26031372010-01-27 00:56:25 +0000484 Micro, HadExtra) || HadExtra ||
485 Major >= 10 || Minor >= 100 || Micro >= 100)
486 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000487 << Version->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000488 }
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000489
Daniel Dunbar5f5c37b2011-04-30 04:18:16 +0000490 bool IsIOSSim = bool(iOSSimVersion);
491
492 // In GCC, the simulator historically was treated as being OS X in some
493 // contexts, like determining the link logic, despite generally being called
494 // with an iOS deployment target. For compatibility, we detect the
495 // simulator as iOS + x86, and treat it differently in a few contexts.
496 if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 ||
497 getTriple().getArch() == llvm::Triple::x86_64))
498 IsIOSSim = true;
499
500 setTarget(/*IsIPhoneOS=*/ !OSXVersion, Major, Minor, Micro, IsIOSSim);
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000501}
502
Daniel Dunbar132e35d2010-09-17 01:20:05 +0000503void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args,
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000504 ArgStringList &CmdArgs) const {
505 CXXStdlibType Type = GetCXXStdlibType(Args);
506
507 switch (Type) {
508 case ToolChain::CST_Libcxx:
509 CmdArgs.push_back("-lc++");
510 break;
511
512 case ToolChain::CST_Libstdcxx: {
513 // Unfortunately, -lstdc++ doesn't always exist in the standard search path;
514 // it was previously found in the gcc lib dir. However, for all the Darwin
515 // platforms we care about it was -lstdc++.6, so we search for that
516 // explicitly if we can't see an obvious -lstdc++ candidate.
517
518 // Check in the sysroot first.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000519 bool Exists;
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000520 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
521 llvm::sys::Path P(A->getValue(Args));
522 P.appendComponent("usr");
523 P.appendComponent("lib");
524 P.appendComponent("libstdc++.dylib");
525
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000526 if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) {
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000527 P.eraseComponent();
528 P.appendComponent("libstdc++.6.dylib");
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000529 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) {
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000530 CmdArgs.push_back(Args.MakeArgString(P.str()));
531 return;
532 }
533 }
534 }
535
536 // Otherwise, look in the root.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000537 if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&&
538 (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000539 CmdArgs.push_back("/usr/lib/libstdc++.6.dylib");
540 return;
541 }
542
543 // Otherwise, let the linker search.
544 CmdArgs.push_back("-lstdc++");
545 break;
546 }
547 }
548}
549
Shantonu Sen7433fed2010-09-17 18:39:08 +0000550void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
551 ArgStringList &CmdArgs) const {
552
553 // For Darwin platforms, use the compiler-rt-based support library
554 // instead of the gcc-provided one (which is also incidentally
555 // only present in the gcc lib dir, which makes it hard to find).
556
557 llvm::sys::Path P(getDriver().ResourceDir);
558 P.appendComponent("lib");
559 P.appendComponent("darwin");
560 P.appendComponent("libclang_rt.cc_kext.a");
561
562 // For now, allow missing resource libraries to support developers who may
563 // not have compiler-rt checked out or integrated into their build.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000564 bool Exists;
565 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Shantonu Sen7433fed2010-09-17 18:39:08 +0000566 CmdArgs.push_back(Args.MakeArgString(P.str()));
567}
568
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000569DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
570 const char *BoundArch) const {
571 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
572 const OptTable &Opts = getDriver().getOpts();
573
574 // FIXME: We really want to get out of the tool chain level argument
575 // translation business, as it makes the driver functionality much
576 // more opaque. For now, we follow gcc closely solely for the
577 // purpose of easily achieving feature parity & testability. Once we
578 // have something that works, we should reevaluate each translation
579 // and try to push it down into tool specific logic.
Daniel Dunbar26031372010-01-27 00:56:25 +0000580
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000581 for (ArgList::const_iterator it = Args.begin(),
582 ie = Args.end(); it != ie; ++it) {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000583 Arg *A = *it;
584
585 if (A->getOption().matches(options::OPT_Xarch__)) {
586 // FIXME: Canonicalize name.
587 if (getArchName() != A->getValue(Args, 0))
588 continue;
589
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000590 Arg *OriginalArg = A;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000591 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1));
592 unsigned Prev = Index;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000593 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000594
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000595 // If the argument parsing failed or more than one argument was
596 // consumed, the -Xarch_ argument's parameter tried to consume
597 // extra arguments. Emit an error and ignore.
598 //
599 // We also want to disallow any options which would alter the
600 // driver behavior; that isn't going to work in our model. We
601 // use isDriverOption() as an approximation, although things
602 // like -O4 are going to slip through.
Daniel Dunbar0e02f6e2011-04-21 17:41:34 +0000603 if (!XarchArg || Index > Prev + 1) {
Daniel Dunbar7e9293b2011-04-21 17:32:21 +0000604 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument_with_args)
605 << A->getAsString(Args);
606 continue;
607 } else if (XarchArg->getOption().isDriverOption()) {
608 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument_isdriver)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000609 << A->getAsString(Args);
610 continue;
611 }
612
Daniel Dunbar478edc22009-03-29 22:29:05 +0000613 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000614 A = XarchArg;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000615
616 DAL->AddSynthesizedArg(A);
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000617
618 // Linker input arguments require custom handling. The problem is that we
619 // have already constructed the phase actions, so we can not treat them as
620 // "input arguments".
621 if (A->getOption().isLinkerInput()) {
622 // Convert the argument into individual Zlinker_input_args.
623 for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
624 DAL->AddSeparateArg(OriginalArg,
625 Opts.getOption(options::OPT_Zlinker_input),
626 A->getValue(Args, i));
627
628 }
629 continue;
630 }
Mike Stump1eb44332009-09-09 15:08:12 +0000631 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000632
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000633 // Sob. These is strictly gcc compatible for the time being. Apple
634 // gcc translates options twice, which means that self-expanding
635 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000636 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000637 default:
638 DAL->append(A);
639 break;
640
641 case options::OPT_mkernel:
642 case options::OPT_fapple_kext:
643 DAL->append(A);
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000644 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
645 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000646 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000647
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000648 case options::OPT_dependency_file:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000649 DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF),
650 A->getValue(Args));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000651 break;
652
653 case options::OPT_gfull:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000654 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
655 DAL->AddFlagArg(A,
656 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000657 break;
658
659 case options::OPT_gused:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000660 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
661 DAL->AddFlagArg(A,
662 Opts.getOption(options::OPT_feliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000663 break;
664
665 case options::OPT_fterminated_vtables:
666 case options::OPT_findirect_virtual_calls:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000667 DAL->AddFlagArg(A, Opts.getOption(options::OPT_fapple_kext));
668 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000669 break;
670
671 case options::OPT_shared:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000672 DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000673 break;
674
675 case options::OPT_fconstant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000676 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000677 break;
678
679 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000680 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000681 break;
682
683 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000684 DAL->AddFlagArg(A,
685 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000686 break;
687
688 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000689 DAL->AddFlagArg(A,
690 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000691 break;
692
693 case options::OPT_fpascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000694 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000695 break;
696
697 case options::OPT_fno_pascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000698 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000699 break;
700 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000701 }
702
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000703 if (getTriple().getArch() == llvm::Triple::x86 ||
704 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000705 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000706 DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000707
708 // Add the arch options based on the particular spelling of -arch, to match
709 // how the driver driver works.
710 if (BoundArch) {
711 llvm::StringRef Name = BoundArch;
712 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
713 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
714
715 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
716 // which defines the list of which architectures we accept.
717 if (Name == "ppc")
718 ;
719 else if (Name == "ppc601")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000720 DAL->AddJoinedArg(0, MCpu, "601");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000721 else if (Name == "ppc603")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000722 DAL->AddJoinedArg(0, MCpu, "603");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000723 else if (Name == "ppc604")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000724 DAL->AddJoinedArg(0, MCpu, "604");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000725 else if (Name == "ppc604e")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000726 DAL->AddJoinedArg(0, MCpu, "604e");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000727 else if (Name == "ppc750")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000728 DAL->AddJoinedArg(0, MCpu, "750");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000729 else if (Name == "ppc7400")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000730 DAL->AddJoinedArg(0, MCpu, "7400");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000731 else if (Name == "ppc7450")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000732 DAL->AddJoinedArg(0, MCpu, "7450");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000733 else if (Name == "ppc970")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000734 DAL->AddJoinedArg(0, MCpu, "970");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000735
736 else if (Name == "ppc64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000737 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000738
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000739 else if (Name == "i386")
740 ;
741 else if (Name == "i486")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000742 DAL->AddJoinedArg(0, MArch, "i486");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000743 else if (Name == "i586")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000744 DAL->AddJoinedArg(0, MArch, "i586");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000745 else if (Name == "i686")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000746 DAL->AddJoinedArg(0, MArch, "i686");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000747 else if (Name == "pentium")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000748 DAL->AddJoinedArg(0, MArch, "pentium");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000749 else if (Name == "pentium2")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000750 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000751 else if (Name == "pentpro")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000752 DAL->AddJoinedArg(0, MArch, "pentiumpro");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000753 else if (Name == "pentIIm3")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000754 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000755
756 else if (Name == "x86_64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000757 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000758
759 else if (Name == "arm")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000760 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000761 else if (Name == "armv4t")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000762 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000763 else if (Name == "armv5")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000764 DAL->AddJoinedArg(0, MArch, "armv5tej");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000765 else if (Name == "xscale")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000766 DAL->AddJoinedArg(0, MArch, "xscale");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000767 else if (Name == "armv6")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000768 DAL->AddJoinedArg(0, MArch, "armv6k");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000769 else if (Name == "armv7")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000770 DAL->AddJoinedArg(0, MArch, "armv7a");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000771
772 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000773 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000774 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000775
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000776 // Add an explicit version min argument for the deployment target. We do this
777 // after argument translation because -Xarch_ arguments may add a version min
778 // argument.
779 AddDeploymentTarget(*DAL);
780
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000781 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000782}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000783
Daniel Dunbarf3955282009-09-04 18:34:51 +0000784bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000785 // FIXME: Gross; we should probably have some separate target
786 // definition, possibly even reusing the one in clang.
787 return getArchName() == "x86_64";
788}
789
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000790bool Darwin::UseDwarfDebugFlags() const {
791 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
792 return S[0] != '\0';
793 return false;
794}
795
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000796bool Darwin::UseSjLjExceptions() const {
797 // Darwin uses SjLj exceptions on ARM.
798 return (getTriple().getArch() == llvm::Triple::arm ||
799 getTriple().getArch() == llvm::Triple::thumb);
800}
801
Daniel Dunbarf3955282009-09-04 18:34:51 +0000802const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000803 return "pic";
804}
805
Daniel Dunbarf3955282009-09-04 18:34:51 +0000806const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000807 if (getArchName() == "x86_64")
808 return "pic";
809 return 0;
810}
811
Daniel Dunbarbbe8e3e2011-03-01 18:49:30 +0000812bool Darwin::SupportsProfiling() const {
813 // Profiling instrumentation is only supported on x86.
814 return getArchName() == "i386" || getArchName() == "x86_64";
815}
816
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000817bool Darwin::SupportsObjCGC() const {
818 // Garbage collection is supported everywhere except on iPhone OS.
819 return !isTargetIPhoneOS();
820}
821
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000822std::string
823Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const {
824 return ComputeLLVMTriple(Args);
825}
826
Daniel Dunbar39176082009-03-20 00:20:03 +0000827/// Generic_GCC - A tool chain using the 'gcc' command to perform
828/// all subcommands; this relies on gcc translating the majority of
829/// command line options.
830
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000831Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000832 : ToolChain(Host, Triple) {
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000833 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +0000834 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000835 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000836}
837
Daniel Dunbar39176082009-03-20 00:20:03 +0000838Generic_GCC::~Generic_GCC() {
839 // Free tool implementations.
840 for (llvm::DenseMap<unsigned, Tool*>::iterator
841 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
842 delete it->second;
843}
844
Mike Stump1eb44332009-09-09 15:08:12 +0000845Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000846 const JobAction &JA,
847 const ActionList &Inputs) const {
Daniel Dunbar39176082009-03-20 00:20:03 +0000848 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000849 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000850 Key = Action::AnalyzeJobClass;
851 else
852 Key = JA.getKind();
853
854 Tool *&T = Tools[Key];
855 if (!T) {
856 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000857 case Action::InputClass:
858 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000859 assert(0 && "Invalid tool kind.");
860 case Action::PreprocessJobClass:
861 T = new tools::gcc::Preprocess(*this); break;
862 case Action::PrecompileJobClass:
863 T = new tools::gcc::Precompile(*this); break;
864 case Action::AnalyzeJobClass:
865 T = new tools::Clang(*this); break;
866 case Action::CompileJobClass:
867 T = new tools::gcc::Compile(*this); break;
868 case Action::AssembleJobClass:
869 T = new tools::gcc::Assemble(*this); break;
870 case Action::LinkJobClass:
871 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000872
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000873 // This is a bit ungeneric, but the only platform using a driver
874 // driver is Darwin.
875 case Action::LipoJobClass:
876 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000877 case Action::DsymutilJobClass:
878 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000879 }
880 }
881
882 return *T;
883}
884
Daniel Dunbar39176082009-03-20 00:20:03 +0000885bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000886 // FIXME: Gross; we should probably have some separate target
887 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000888 return getArchName() == "x86_64";
889}
890
891const char *Generic_GCC::GetDefaultRelocationModel() const {
892 return "static";
893}
894
895const char *Generic_GCC::GetForcedPicModel() const {
896 return 0;
897}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000898
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000899/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
900/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
901/// Currently does not support anything else but compilation.
902
903TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple)
904 : ToolChain(Host, Triple) {
905 // Path mangling to find libexec
906 std::string Path(getDriver().Dir);
907
908 Path += "/../libexec";
909 getProgramPaths().push_back(Path);
910}
911
912TCEToolChain::~TCEToolChain() {
913 for (llvm::DenseMap<unsigned, Tool*>::iterator
914 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
915 delete it->second;
916}
917
918bool TCEToolChain::IsMathErrnoDefault() const {
919 return true;
920}
921
922bool TCEToolChain::IsUnwindTablesDefault() const {
923 return false;
924}
925
926const char *TCEToolChain::GetDefaultRelocationModel() const {
927 return "static";
928}
929
930const char *TCEToolChain::GetForcedPicModel() const {
931 return 0;
932}
933
934Tool &TCEToolChain::SelectTool(const Compilation &C,
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000935 const JobAction &JA,
936 const ActionList &Inputs) const {
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000937 Action::ActionClass Key;
938 Key = Action::AnalyzeJobClass;
939
940 Tool *&T = Tools[Key];
941 if (!T) {
942 switch (Key) {
943 case Action::PreprocessJobClass:
944 T = new tools::gcc::Preprocess(*this); break;
945 case Action::AnalyzeJobClass:
946 T = new tools::Clang(*this); break;
947 default:
948 assert(false && "Unsupported action for TCE target.");
949 }
950 }
951 return *T;
952}
953
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000954/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
955
956OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000957 : Generic_ELF(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000958 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000959 getFilePaths().push_back("/usr/lib");
960}
961
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000962Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA,
963 const ActionList &Inputs) const {
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000964 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000965 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000966 Key = Action::AnalyzeJobClass;
967 else
968 Key = JA.getKind();
969
Rafael Espindoladda5b922010-11-07 23:13:01 +0000970 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
971 options::OPT_no_integrated_as,
972 IsIntegratedAssemblerDefault());
973
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000974 Tool *&T = Tools[Key];
975 if (!T) {
976 switch (Key) {
Rafael Espindoladda5b922010-11-07 23:13:01 +0000977 case Action::AssembleJobClass: {
978 if (UseIntegratedAs)
979 T = new tools::ClangAs(*this);
980 else
981 T = new tools::openbsd::Assemble(*this);
982 break;
983 }
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000984 case Action::LinkJobClass:
985 T = new tools::openbsd::Link(*this); break;
986 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000987 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000988 }
989 }
990
991 return *T;
992}
993
Daniel Dunbar75358d22009-03-30 21:06:03 +0000994/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
995
Daniel Dunbar214afe92010-08-02 05:43:59 +0000996FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000997 : Generic_ELF(Host, Triple) {
Daniel Dunbar214afe92010-08-02 05:43:59 +0000998
999 // Determine if we are compiling 32-bit code on an x86_64 platform.
1000 bool Lib32 = false;
1001 if (Triple.getArch() == llvm::Triple::x86 &&
1002 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1003 llvm::Triple::x86_64)
1004 Lib32 = true;
1005
Daniel Dunbarbc534662009-04-02 18:30:04 +00001006 if (Lib32) {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001007 getFilePaths().push_back("/usr/lib32");
1008 } else {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001009 getFilePaths().push_back("/usr/lib");
1010 }
Daniel Dunbar75358d22009-03-30 21:06:03 +00001011}
1012
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001013Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA,
1014 const ActionList &Inputs) const {
Daniel Dunbar75358d22009-03-30 21:06:03 +00001015 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001016 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +00001017 Key = Action::AnalyzeJobClass;
1018 else
1019 Key = JA.getKind();
1020
Roman Divacky67dece72010-11-08 17:46:39 +00001021 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1022 options::OPT_no_integrated_as,
1023 IsIntegratedAssemblerDefault());
1024
Daniel Dunbar75358d22009-03-30 21:06:03 +00001025 Tool *&T = Tools[Key];
1026 if (!T) {
1027 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +00001028 case Action::AssembleJobClass:
Roman Divacky67dece72010-11-08 17:46:39 +00001029 if (UseIntegratedAs)
1030 T = new tools::ClangAs(*this);
1031 else
1032 T = new tools::freebsd::Assemble(*this);
Roman Divackyfe3a7ea2010-11-08 19:39:10 +00001033 break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +00001034 case Action::LinkJobClass:
1035 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +00001036 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001037 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbar75358d22009-03-30 21:06:03 +00001038 }
1039 }
1040
1041 return *T;
1042}
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001043
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001044/// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly.
1045
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001046NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple,
1047 const llvm::Triple& ToolTriple)
1048 : Generic_ELF(Host, Triple), ToolTriple(ToolTriple) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001049
1050 // Determine if we are compiling 32-bit code on an x86_64 platform.
1051 bool Lib32 = false;
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001052 if (ToolTriple.getArch() == llvm::Triple::x86_64 &&
1053 Triple.getArch() == llvm::Triple::x86)
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001054 Lib32 = true;
1055
Joerg Sonnenberger05e59302011-03-21 13:59:26 +00001056 if (getDriver().UseStdLib) {
1057 if (Lib32)
1058 getFilePaths().push_back("=/usr/lib/i386");
1059 else
1060 getFilePaths().push_back("=/usr/lib");
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001061 }
1062}
1063
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001064Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA,
1065 const ActionList &Inputs) const {
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001066 Action::ActionClass Key;
1067 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1068 Key = Action::AnalyzeJobClass;
1069 else
1070 Key = JA.getKind();
1071
1072 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1073 options::OPT_no_integrated_as,
1074 IsIntegratedAssemblerDefault());
1075
1076 Tool *&T = Tools[Key];
1077 if (!T) {
1078 switch (Key) {
1079 case Action::AssembleJobClass:
1080 if (UseIntegratedAs)
1081 T = new tools::ClangAs(*this);
1082 else
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001083 T = new tools::netbsd::Assemble(*this, ToolTriple);
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001084 break;
1085 case Action::LinkJobClass:
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001086 T = new tools::netbsd::Link(*this, ToolTriple);
1087 break;
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001088 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001089 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001090 }
1091 }
1092
1093 return *T;
1094}
1095
Chris Lattner38e317d2010-07-07 16:01:42 +00001096/// Minix - Minix tool chain which can call as(1) and ld(1) directly.
1097
1098Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple)
1099 : Generic_GCC(Host, Triple) {
1100 getFilePaths().push_back(getDriver().Dir + "/../lib");
1101 getFilePaths().push_back("/usr/lib");
1102 getFilePaths().push_back("/usr/gnu/lib");
1103 getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
1104}
1105
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001106Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA,
1107 const ActionList &Inputs) const {
Chris Lattner38e317d2010-07-07 16:01:42 +00001108 Action::ActionClass Key;
1109 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1110 Key = Action::AnalyzeJobClass;
1111 else
1112 Key = JA.getKind();
1113
1114 Tool *&T = Tools[Key];
1115 if (!T) {
1116 switch (Key) {
1117 case Action::AssembleJobClass:
1118 T = new tools::minix::Assemble(*this); break;
1119 case Action::LinkJobClass:
1120 T = new tools::minix::Link(*this); break;
1121 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001122 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Chris Lattner38e317d2010-07-07 16:01:42 +00001123 }
1124 }
1125
1126 return *T;
1127}
1128
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001129/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
1130
1131AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
1132 : Generic_GCC(Host, Triple) {
1133
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001134 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +00001135 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001136 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001137
Daniel Dunbaree788e72009-12-21 18:54:17 +00001138 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001139 getFilePaths().push_back("/usr/lib");
1140 getFilePaths().push_back("/usr/sfw/lib");
1141 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +00001142 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001143
1144}
1145
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001146Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA,
1147 const ActionList &Inputs) const {
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001148 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001149 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001150 Key = Action::AnalyzeJobClass;
1151 else
1152 Key = JA.getKind();
1153
1154 Tool *&T = Tools[Key];
1155 if (!T) {
1156 switch (Key) {
1157 case Action::AssembleJobClass:
1158 T = new tools::auroraux::Assemble(*this); break;
1159 case Action::LinkJobClass:
1160 T = new tools::auroraux::Link(*this); break;
1161 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001162 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001163 }
1164 }
1165
1166 return *T;
1167}
1168
1169
Eli Friedman6b3454a2009-05-26 07:52:18 +00001170/// Linux toolchain (very bare-bones at the moment).
1171
Rafael Espindolac1da9812010-11-07 20:14:31 +00001172enum LinuxDistro {
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001173 ArchLinux,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001174 DebianLenny,
1175 DebianSqueeze,
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001176 Exherbo,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001177 Fedora13,
1178 Fedora14,
Eric Christopher8f1cc072011-04-06 18:22:53 +00001179 Fedora15,
1180 FedoraRawhide,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001181 OpenSuse11_3,
Douglas Gregor814638e2011-03-14 15:39:50 +00001182 UbuntuHardy,
1183 UbuntuIntrepid,
Rafael Espindola021aaa42010-11-10 05:00:22 +00001184 UbuntuJaunty,
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001185 UbuntuKarmic,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001186 UbuntuLucid,
1187 UbuntuMaverick,
Ted Kremenek43ac2972011-04-05 22:04:27 +00001188 UbuntuNatty,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001189 UnknownDistro
1190};
1191
1192static bool IsFedora(enum LinuxDistro Distro) {
Eric Christopher8f1cc072011-04-06 18:22:53 +00001193 return Distro == Fedora13 || Distro == Fedora14 ||
1194 Distro == Fedora15 || Distro == FedoraRawhide;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001195}
1196
1197static bool IsOpenSuse(enum LinuxDistro Distro) {
1198 return Distro == OpenSuse11_3;
1199}
1200
1201static bool IsDebian(enum LinuxDistro Distro) {
1202 return Distro == DebianLenny || Distro == DebianSqueeze;
1203}
1204
1205static bool IsUbuntu(enum LinuxDistro Distro) {
Douglas Gregor814638e2011-03-14 15:39:50 +00001206 return Distro == UbuntuHardy || Distro == UbuntuIntrepid ||
1207 Distro == UbuntuLucid || Distro == UbuntuMaverick ||
Ted Kremenek43ac2972011-04-05 22:04:27 +00001208 Distro == UbuntuJaunty || Distro == UbuntuKarmic ||
1209 Distro == UbuntuNatty;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001210}
1211
1212static bool IsDebianBased(enum LinuxDistro Distro) {
1213 return IsDebian(Distro) || IsUbuntu(Distro);
1214}
1215
1216static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) {
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001217 if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001218 bool Exists;
1219 if (Distro == Exherbo &&
1220 (llvm::sys::fs::exists("/usr/lib32/libc.so", Exists) || !Exists))
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001221 return false;
1222
Rafael Espindolac1da9812010-11-07 20:14:31 +00001223 return true;
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001224 }
Ted Kremenek43ac2972011-04-05 22:04:27 +00001225 if (Arch == llvm::Triple::ppc64)
1226 return true;
1227 if ((Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc) && IsDebianBased(Distro))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001228 return true;
1229 return false;
1230}
1231
1232static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001233 llvm::OwningPtr<llvm::MemoryBuffer> File;
1234 if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) {
1235 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001236 llvm::SmallVector<llvm::StringRef, 8> Lines;
1237 Data.split(Lines, "\n");
1238 for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) {
Douglas Gregor814638e2011-03-14 15:39:50 +00001239 if (Lines[i] == "DISTRIB_CODENAME=hardy")
1240 return UbuntuHardy;
Ted Kremenek43ac2972011-04-05 22:04:27 +00001241 else if (Lines[i] == "DISTRIB_CODENAME=intrepid")
1242 return UbuntuIntrepid;
Rafael Espindola021aaa42010-11-10 05:00:22 +00001243 else if (Lines[i] == "DISTRIB_CODENAME=jaunty")
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001244 return UbuntuJaunty;
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001245 else if (Lines[i] == "DISTRIB_CODENAME=karmic")
1246 return UbuntuKarmic;
Ted Kremenek43ac2972011-04-05 22:04:27 +00001247 else if (Lines[i] == "DISTRIB_CODENAME=lucid")
1248 return UbuntuLucid;
1249 else if (Lines[i] == "DISTRIB_CODENAME=maverick")
1250 return UbuntuMaverick;
1251 else if (Lines[i] == "DISTRIB_CODENAME=natty")
1252 return UbuntuNatty;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001253 }
1254 return UnknownDistro;
1255 }
1256
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001257 if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) {
1258 llvm::StringRef Data = File.get()->getBuffer();
Eric Christopher8f1cc072011-04-06 18:22:53 +00001259 if (Data.startswith("Fedora release 15"))
1260 return Fedora15;
1261 else if (Data.startswith("Fedora release 14"))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001262 return Fedora14;
Eric Christopher8f1cc072011-04-06 18:22:53 +00001263 else if (Data.startswith("Fedora release 13"))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001264 return Fedora13;
Eric Christopher8f1cc072011-04-06 18:22:53 +00001265 else if (Data.startswith("Fedora release") &&
1266 Data.find("Rawhide") != llvm::StringRef::npos)
1267 return FedoraRawhide;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001268 return UnknownDistro;
1269 }
1270
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001271 if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) {
1272 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001273 if (Data[0] == '5')
1274 return DebianLenny;
1275 else if (Data.startswith("squeeze/sid"))
1276 return DebianSqueeze;
1277 return UnknownDistro;
1278 }
1279
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001280 if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) {
1281 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001282 if (Data.startswith("openSUSE 11.3"))
1283 return OpenSuse11_3;
1284 return UnknownDistro;
1285 }
1286
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001287 bool Exists;
1288 if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001289 return Exherbo;
1290
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001291 if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists)
1292 return ArchLinux;
1293
Rafael Espindolac1da9812010-11-07 20:14:31 +00001294 return UnknownDistro;
1295}
1296
Nick Lewycky3fdcc6f2010-12-31 17:31:54 +00001297Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001298 : Generic_ELF(Host, Triple) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001299 llvm::Triple::ArchType Arch =
1300 llvm::Triple(getDriver().DefaultHostTriple).getArch();
Daniel Dunbara9822de2009-08-06 01:47:11 +00001301
Rafael Espindolac1da9812010-11-07 20:14:31 +00001302 std::string Suffix32 = "";
1303 if (Arch == llvm::Triple::x86_64)
1304 Suffix32 = "/32";
Daniel Dunbara9822de2009-08-06 01:47:11 +00001305
Rafael Espindolac1da9812010-11-07 20:14:31 +00001306 std::string Suffix64 = "";
Ted Kremenek43ac2972011-04-05 22:04:27 +00001307 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001308 Suffix64 = "/64";
1309
1310 std::string Lib32 = "lib";
1311
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001312 bool Exists;
1313 if (!llvm::sys::fs::exists("/lib32", Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001314 Lib32 = "lib32";
1315
1316 std::string Lib64 = "lib";
Michael J. Spencer2dea7c72011-01-12 23:54:48 +00001317 bool Symlink;
Chris Lattner48aef362011-01-13 01:35:58 +00001318 if (!llvm::sys::fs::exists("/lib64", Exists) && Exists &&
1319 (llvm::sys::fs::is_symlink("/lib64", Symlink) || !Symlink))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001320 Lib64 = "lib64";
1321
1322 std::string GccTriple = "";
Douglas Gregorf0594d82011-03-06 19:11:49 +00001323 if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001324 if (!llvm::sys::fs::exists("/usr/lib/gcc/arm-linux-gnueabi", Exists) &&
1325 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001326 GccTriple = "arm-linux-gnueabi";
1327 } else if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001328 if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-linux-gnu", Exists) &&
1329 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001330 GccTriple = "x86_64-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001331 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-unknown-linux-gnu",
1332 Exists) && Exists)
Rafael Espindola53dd00b2010-11-17 00:25:26 +00001333 GccTriple = "x86_64-unknown-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001334 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-pc-linux-gnu",
1335 Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001336 GccTriple = "x86_64-pc-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001337 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-redhat-linux",
1338 Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001339 GccTriple = "x86_64-redhat-linux";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001340 else if (!llvm::sys::fs::exists("/usr/lib64/gcc/x86_64-suse-linux",
1341 Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001342 GccTriple = "x86_64-suse-linux";
Nick Lewyckye10f9002011-02-01 23:03:29 +00001343 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-manbo-linux-gnu",
1344 Exists) && Exists)
1345 GccTriple = "x86_64-manbo-linux-gnu";
Nico Weber80585d82011-04-25 03:17:35 +00001346 else if (!llvm::sys::fs::exists("/usr/lib/x86_64-linux-gnu/gcc",
1347 Exists) && Exists)
1348 GccTriple = "x86_64-linux-gnu";
Rafael Espindolac1da9812010-11-07 20:14:31 +00001349 } else if (Arch == llvm::Triple::x86) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001350 if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-linux-gnu", Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001351 GccTriple = "i686-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001352 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-pc-linux-gnu", Exists) &&
1353 Exists)
Nuno Lopes2a69ddd2010-11-19 17:26:57 +00001354 GccTriple = "i686-pc-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001355 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-linux-gnu", Exists) &&
1356 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001357 GccTriple = "i486-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001358 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-redhat-linux", Exists) &&
1359 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001360 GccTriple = "i686-redhat-linux";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001361 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i586-suse-linux", Exists) &&
1362 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001363 GccTriple = "i586-suse-linux";
Ted Kremenekd130c7d2011-04-18 17:50:19 +00001364 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-slackware-linux", Exists)
1365 && Exists)
1366 GccTriple = "i486-slackware-linux";
Ted Kremenek43ac2972011-04-05 22:04:27 +00001367 } else if (Arch == llvm::Triple::ppc) {
1368 if (!llvm::sys::fs::exists("/usr/lib/powerpc-linux-gnu", Exists) && Exists)
1369 GccTriple = "powerpc-linux-gnu";
1370 else if (!llvm::sys::fs::exists("/usr/lib/gcc/powerpc-unknown-linux-gnu", Exists) && Exists)
1371 GccTriple = "powerpc-unknown-linux-gnu";
1372 } else if (Arch == llvm::Triple::ppc64) {
1373 if (!llvm::sys::fs::exists("/usr/lib/gcc/powerpc64-unknown-linux-gnu", Exists) && Exists)
1374 GccTriple = "powerpc64-unknown-linux-gnu";
1375 else if (!llvm::sys::fs::exists("/usr/lib64/gcc/powerpc64-unknown-linux-gnu", Exists) && Exists)
1376 GccTriple = "powerpc64-unknown-linux-gnu";
Rafael Espindolac1da9812010-11-07 20:14:31 +00001377 }
1378
Eric Christopher8f1cc072011-04-06 18:22:53 +00001379 const char* GccVersions[] = {"4.6.0",
1380 "4.5.2", "4.5.1", "4.5",
1381 "4.4.5", "4.4.4", "4.4.3", "4.4",
1382 "4.3.4", "4.3.3", "4.3.2", "4.3",
1383 "4.2.4", "4.2.3", "4.2.2", "4.2.1", "4.2"};
Rafael Espindolac1da9812010-11-07 20:14:31 +00001384 std::string Base = "";
1385 for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) {
1386 std::string Suffix = GccTriple + "/" + GccVersions[i];
1387 std::string t1 = "/usr/lib/gcc/" + Suffix;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001388 if (!llvm::sys::fs::exists(t1 + "/crtbegin.o", Exists) && Exists) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001389 Base = t1;
1390 break;
1391 }
1392 std::string t2 = "/usr/lib64/gcc/" + Suffix;
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001393 if (!llvm::sys::fs::exists(t2 + "/crtbegin.o", Exists) && Exists) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001394 Base = t2;
1395 break;
1396 }
Ted Kremenek43ac2972011-04-05 22:04:27 +00001397 std::string t3 = "/usr/lib/" + GccTriple + "/gcc/" + Suffix;
1398 if (!llvm::sys::fs::exists(t3 + "/crtbegin.o", Exists) && Exists) {
1399 Base = t3;
1400 break;
1401 }
Rafael Espindolac1da9812010-11-07 20:14:31 +00001402 }
1403
1404 path_list &Paths = getFilePaths();
Ted Kremenek43ac2972011-04-05 22:04:27 +00001405 bool Is32Bits = (getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::ppc);
Rafael Espindolac1da9812010-11-07 20:14:31 +00001406
1407 std::string Suffix;
1408 std::string Lib;
1409
1410 if (Is32Bits) {
1411 Suffix = Suffix32;
1412 Lib = Lib32;
1413 } else {
1414 Suffix = Suffix64;
1415 Lib = Lib64;
1416 }
1417
1418 llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld");
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001419 if (!llvm::sys::fs::exists(LinkerPath.str(), Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001420 Linker = LinkerPath.str();
1421 else
1422 Linker = GetProgramPath("ld");
1423
1424 LinuxDistro Distro = DetectLinuxDistro(Arch);
1425
Rafael Espindola94c80222010-11-08 14:48:47 +00001426 if (IsUbuntu(Distro)) {
1427 ExtraOpts.push_back("-z");
1428 ExtraOpts.push_back("relro");
1429 }
Rafael Espindolac1da9812010-11-07 20:14:31 +00001430
Douglas Gregorf0594d82011-03-06 19:11:49 +00001431 if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001432 ExtraOpts.push_back("-X");
1433
Nico Weber80585d82011-04-25 03:17:35 +00001434 if (IsFedora(Distro) || Distro == UbuntuMaverick || Distro == UbuntuNatty)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001435 ExtraOpts.push_back("--hash-style=gnu");
1436
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001437 if (IsDebian(Distro) || Distro == UbuntuLucid || Distro == UbuntuJaunty ||
1438 Distro == UbuntuKarmic)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001439 ExtraOpts.push_back("--hash-style=both");
1440
1441 if (IsFedora(Distro))
1442 ExtraOpts.push_back("--no-add-needed");
1443
Rafael Espindola021aaa42010-11-10 05:00:22 +00001444 if (Distro == DebianSqueeze || IsOpenSuse(Distro) ||
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001445 IsFedora(Distro) || Distro == UbuntuLucid || Distro == UbuntuMaverick ||
Nico Weber80585d82011-04-25 03:17:35 +00001446 Distro == UbuntuKarmic || Distro == UbuntuNatty)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001447 ExtraOpts.push_back("--build-id");
1448
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001449 if (Distro == ArchLinux)
1450 Lib = "lib";
1451
Rafael Espindolac1da9812010-11-07 20:14:31 +00001452 Paths.push_back(Base + Suffix);
1453 if (HasMultilib(Arch, Distro)) {
1454 if (IsOpenSuse(Distro) && Is32Bits)
1455 Paths.push_back(Base + "/../../../../" + GccTriple + "/lib/../lib");
1456 Paths.push_back(Base + "/../../../../" + Lib);
1457 Paths.push_back("/lib/../" + Lib);
1458 Paths.push_back("/usr/lib/../" + Lib);
1459 }
1460 if (!Suffix.empty())
1461 Paths.push_back(Base);
1462 if (IsOpenSuse(Distro))
1463 Paths.push_back(Base + "/../../../../" + GccTriple + "/lib");
1464 Paths.push_back(Base + "/../../..");
1465 if (Arch == getArch() && IsUbuntu(Distro))
1466 Paths.push_back("/usr/lib/" + GccTriple);
1467}
1468
1469bool Linux::HasNativeLLVMSupport() const {
1470 return true;
Eli Friedman6b3454a2009-05-26 07:52:18 +00001471}
1472
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001473Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA,
1474 const ActionList &Inputs) const {
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001475 Action::ActionClass Key;
1476 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1477 Key = Action::AnalyzeJobClass;
1478 else
1479 Key = JA.getKind();
1480
Rafael Espindoladda5b922010-11-07 23:13:01 +00001481 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1482 options::OPT_no_integrated_as,
1483 IsIntegratedAssemblerDefault());
1484
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001485 Tool *&T = Tools[Key];
1486 if (!T) {
1487 switch (Key) {
1488 case Action::AssembleJobClass:
Rafael Espindoladda5b922010-11-07 23:13:01 +00001489 if (UseIntegratedAs)
1490 T = new tools::ClangAs(*this);
1491 else
1492 T = new tools::linuxtools::Assemble(*this);
1493 break;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001494 case Action::LinkJobClass:
1495 T = new tools::linuxtools::Link(*this); break;
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001496 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001497 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001498 }
1499 }
1500
1501 return *T;
1502}
1503
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001504/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
1505
Daniel Dunbarcb8ab232009-05-22 02:53:45 +00001506DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001507 : Generic_ELF(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001508
1509 // Path mangling to find libexec
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001510 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +00001511 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001512 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001513
Daniel Dunbaree788e72009-12-21 18:54:17 +00001514 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001515 getFilePaths().push_back("/usr/lib");
1516 getFilePaths().push_back("/usr/lib/gcc41");
1517}
1518
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001519Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA,
1520 const ActionList &Inputs) const {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001521 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001522 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001523 Key = Action::AnalyzeJobClass;
1524 else
1525 Key = JA.getKind();
1526
1527 Tool *&T = Tools[Key];
1528 if (!T) {
1529 switch (Key) {
1530 case Action::AssembleJobClass:
1531 T = new tools::dragonfly::Assemble(*this); break;
1532 case Action::LinkJobClass:
1533 T = new tools::dragonfly::Link(*this); break;
1534 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001535 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001536 }
1537 }
1538
1539 return *T;
1540}
Michael J. Spencerff58e362010-08-21 21:55:07 +00001541
1542Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple)
1543 : ToolChain(Host, Triple) {
1544}
1545
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001546Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA,
1547 const ActionList &Inputs) const {
Michael J. Spencerff58e362010-08-21 21:55:07 +00001548 Action::ActionClass Key;
1549 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1550 Key = Action::AnalyzeJobClass;
1551 else
1552 Key = JA.getKind();
1553
1554 Tool *&T = Tools[Key];
1555 if (!T) {
1556 switch (Key) {
1557 case Action::InputClass:
1558 case Action::BindArchClass:
Chandler Carruthe97673f2010-08-22 06:56:37 +00001559 case Action::LipoJobClass:
1560 case Action::DsymutilJobClass:
Michael J. Spencerff58e362010-08-21 21:55:07 +00001561 assert(0 && "Invalid tool kind.");
1562 case Action::PreprocessJobClass:
1563 case Action::PrecompileJobClass:
1564 case Action::AnalyzeJobClass:
1565 case Action::CompileJobClass:
1566 T = new tools::Clang(*this); break;
1567 case Action::AssembleJobClass:
1568 T = new tools::ClangAs(*this); break;
1569 case Action::LinkJobClass:
1570 T = new tools::visualstudio::Link(*this); break;
1571 }
1572 }
1573
1574 return *T;
1575}
1576
1577bool Windows::IsIntegratedAssemblerDefault() const {
1578 return true;
1579}
1580
1581bool Windows::IsUnwindTablesDefault() const {
1582 // FIXME: Gross; we should probably have some separate target
1583 // definition, possibly even reusing the one in clang.
1584 return getArchName() == "x86_64";
1585}
1586
1587const char *Windows::GetDefaultRelocationModel() const {
1588 return "static";
1589}
1590
1591const char *Windows::GetForcedPicModel() const {
1592 if (getArchName() == "x86_64")
1593 return "pic";
1594 return 0;
1595}