blob: ca613e3d6c849d71fdfc39d25e7e871c5850f81c [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
Rafael Espindola14ea13c2011-06-02 22:18:46 +000012#ifdef HAVE_CLANG_CONFIG_H
13# include "clang/Config/config.h"
14#endif
15
Daniel Dunbarf3cad362009-03-25 04:13:45 +000016#include "clang/Driver/Arg.h"
17#include "clang/Driver/ArgList.h"
Daniel Dunbar0f602de2010-05-20 21:48:38 +000018#include "clang/Driver/Compilation.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000019#include "clang/Driver/Driver.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000020#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000021#include "clang/Driver/HostInfo.h"
Daniel Dunbar27e738d2009-11-19 00:15:11 +000022#include "clang/Driver/OptTable.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000023#include "clang/Driver/Option.h"
Daniel Dunbar265e9ef2009-11-19 04:25:22 +000024#include "clang/Driver/Options.h"
Douglas Gregor34916db2010-09-03 17:16:03 +000025#include "clang/Basic/Version.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000026
Daniel Dunbar00577ad2010-08-23 22:35:37 +000027#include "llvm/ADT/SmallString.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000028#include "llvm/ADT/StringExtras.h"
Daniel Dunbar84ec96c2009-09-09 22:33:15 +000029#include "llvm/Support/ErrorHandling.h"
Michael J. Spencer32bef4e2011-01-10 02:34:13 +000030#include "llvm/Support/FileSystem.h"
Rafael Espindolac1da9812010-11-07 20:14:31 +000031#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000032#include "llvm/Support/raw_ostream.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000033#include "llvm/Support/Path.h"
Michael J. Spencer3a321e22010-12-09 17:36:38 +000034#include "llvm/Support/system_error.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000035
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000036#include <cstdlib> // ::getenv
37
Daniel Dunbar39176082009-03-20 00:20:03 +000038using namespace clang::driver;
39using namespace clang::driver::toolchains;
40
Daniel Dunbarf3955282009-09-04 18:34:51 +000041/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000042
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000043Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcc8e1892010-01-27 00:56:44 +000044 : ToolChain(Host, Triple), TargetInitialized(false)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000045{
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000046 // Compute the initial Darwin version based on the host.
47 bool HadExtra;
48 std::string OSName = Triple.getOSName();
Daniel Dunbar34f9e292011-02-25 21:20:15 +000049 if (!Driver::GetReleaseVersion(&OSName.c_str()[6],
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000050 DarwinVersion[0], DarwinVersion[1],
51 DarwinVersion[2], HadExtra))
52 getDriver().Diag(clang::diag::err_drv_invalid_darwin_version) << OSName;
53
Daniel Dunbar02633b52009-03-26 16:23:12 +000054 llvm::raw_string_ostream(MacosxVersionMin)
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000055 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.'
56 << DarwinVersion[1];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000057}
58
Daniel Dunbar41800112010-08-02 05:43:56 +000059types::ID Darwin::LookupTypeForExtension(const char *Ext) const {
60 types::ID Ty = types::lookupTypeForExtension(Ext);
61
62 // Darwin always preprocesses assembly files (unless -x is used explicitly).
63 if (Ty == types::TY_PP_Asm)
64 return types::TY_Asm;
65
66 return Ty;
67}
68
Daniel Dunbarb993f5d2010-09-17 00:24:52 +000069bool Darwin::HasNativeLLVMSupport() const {
70 return true;
71}
72
Daniel Dunbareeff4062010-01-22 02:04:58 +000073// FIXME: Can we tablegen this?
74static const char *GetArmArchForMArch(llvm::StringRef Value) {
75 if (Value == "armv6k")
76 return "armv6";
77
78 if (Value == "armv5tej")
79 return "armv5";
80
81 if (Value == "xscale")
82 return "xscale";
83
84 if (Value == "armv4t")
85 return "armv4t";
86
87 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
88 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
89 Value == "armv7m")
90 return "armv7";
91
92 return 0;
93}
94
95// FIXME: Can we tablegen this?
96static const char *GetArmArchForMCpu(llvm::StringRef Value) {
97 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
98 Value == "arm946e-s" || Value == "arm966e-s" ||
99 Value == "arm968e-s" || Value == "arm10e" ||
100 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
101 Value == "arm1026ej-s")
102 return "armv5";
103
104 if (Value == "xscale")
105 return "xscale";
106
107 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
Bob Wilson1ec0ade2011-03-21 20:40:05 +0000108 Value == "arm1176jz-s" || Value == "arm1176jzf-s" ||
109 Value == "cortex-m0" )
Daniel Dunbareeff4062010-01-22 02:04:58 +0000110 return "armv6";
111
112 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
113 return "armv7";
114
115 return 0;
116}
117
118llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
119 switch (getTriple().getArch()) {
120 default:
121 return getArchName();
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000122
Douglas Gregorf0594d82011-03-06 19:11:49 +0000123 case llvm::Triple::thumb:
Daniel Dunbareeff4062010-01-22 02:04:58 +0000124 case llvm::Triple::arm: {
125 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
126 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
127 return Arch;
128
129 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
130 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
131 return Arch;
132
133 return "arm";
134 }
135 }
136}
137
Daniel Dunbarf3955282009-09-04 18:34:51 +0000138Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000139 // Free tool implementations.
140 for (llvm::DenseMap<unsigned, Tool*>::iterator
141 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
142 delete it->second;
143}
144
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000145std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args) const {
146 llvm::Triple Triple(ComputeLLVMTriple(Args));
147
148 // If the target isn't initialized (e.g., an unknown Darwin platform, return
149 // the default triple).
150 if (!isTargetInitialized())
151 return Triple.getTriple();
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000152
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000153 unsigned Version[3];
154 getTargetVersion(Version);
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000155
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000156 llvm::SmallString<16> Str;
Daniel Dunbar729f38e2011-04-19 21:45:47 +0000157 llvm::raw_svector_ostream(Str)
Daniel Dunbar659d23a2011-04-19 23:34:17 +0000158 << (isTargetIPhoneOS() ? "ios" : "macosx")
Daniel Dunbar729f38e2011-04-19 21:45:47 +0000159 << Version[0] << "." << Version[1] << "." << Version[2];
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000160 Triple.setOSName(Str.str());
161
162 return Triple.getTriple();
163}
164
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000165Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA,
166 const ActionList &Inputs) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000167 Action::ActionClass Key;
Daniel Dunbar5ce872f2011-03-18 20:14:03 +0000168
169 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) {
170 // Fallback to llvm-gcc for i386 kext compiles, we don't support that ABI.
171 if (Inputs.size() == 1 &&
172 types::isCXX(Inputs[0]->getType()) &&
173 getTriple().getOS() == llvm::Triple::Darwin &&
174 getTriple().getArch() == llvm::Triple::x86 &&
175 C.getArgs().getLastArg(options::OPT_fapple_kext))
176 Key = JA.getKind();
177 else
178 Key = Action::AnalyzeJobClass;
179 } else
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000180 Key = JA.getKind();
181
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000182 // FIXME: This doesn't belong here, but ideally we will support static soon
183 // anyway.
184 bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) ||
185 C.getArgs().hasArg(options::OPT_static) ||
186 C.getArgs().hasArg(options::OPT_fapple_kext));
187 bool IsIADefault = IsIntegratedAssemblerDefault() && !HasStatic;
188 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
189 options::OPT_no_integrated_as,
190 IsIADefault);
191
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000192 Tool *&T = Tools[Key];
193 if (!T) {
194 switch (Key) {
195 case Action::InputClass:
196 case Action::BindArchClass:
197 assert(0 && "Invalid tool kind.");
198 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000199 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000200 case Action::AnalyzeJobClass:
201 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000202 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000203 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000204 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000205 case Action::AssembleJobClass: {
206 if (UseIntegratedAs)
207 T = new tools::ClangAs(*this);
208 else
209 T = new tools::darwin::Assemble(*this);
210 break;
211 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000212 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000213 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000214 case Action::LipoJobClass:
215 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000216 case Action::DsymutilJobClass:
217 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000218 }
219 }
220
221 return *T;
222}
223
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000224
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000225DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple)
226 : Darwin(Host, Triple)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000227{
Daniel Dunbar47023092011-03-18 19:25:15 +0000228 std::string UsrPrefix = "llvm-gcc-4.2/";
229
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000230 getProgramPaths().push_back(getDriver().getInstalledDir());
231 if (getDriver().getInstalledDir() != getDriver().Dir)
232 getProgramPaths().push_back(getDriver().Dir);
233
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000234 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000235 getProgramPaths().push_back(getDriver().getInstalledDir());
236 if (getDriver().getInstalledDir() != getDriver().Dir)
237 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000238
239 // For fallback, we need to know how to find the GCC cc1 executables, so we
Daniel Dunbar47023092011-03-18 19:25:15 +0000240 // also add the GCC libexec paths. This is legacy code that can be removed
241 // once fallback is no longer useful.
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000242 std::string ToolChainDir = "i686-apple-darwin";
243 ToolChainDir += llvm::utostr(DarwinVersion[0]);
244 ToolChainDir += "/4.2.1";
245
246 std::string Path = getDriver().Dir;
Daniel Dunbar47023092011-03-18 19:25:15 +0000247 Path += "/../" + UsrPrefix + "libexec/gcc/";
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000248 Path += ToolChainDir;
249 getProgramPaths().push_back(Path);
250
Daniel Dunbar47023092011-03-18 19:25:15 +0000251 Path = "/usr/" + UsrPrefix + "libexec/gcc/";
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000252 Path += ToolChainDir;
253 getProgramPaths().push_back(Path);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000254}
255
256void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
257 ArgStringList &CmdArgs) const {
258 // The Clang toolchain uses explicit paths for internal libraries.
Daniel Dunbar424b6612010-06-30 23:56:13 +0000259
260 // Unfortunately, we still might depend on a few of the libraries that are
261 // only available in the gcc library directory (in particular
262 // libstdc++.dylib). For now, hardcode the path to the known install location.
263 llvm::sys::Path P(getDriver().Dir);
264 P.eraseComponent(); // .../usr/bin -> ../usr
265 P.appendComponent("lib");
266 P.appendComponent("gcc");
267 switch (getTriple().getArch()) {
268 default:
269 assert(0 && "Invalid Darwin arch!");
270 case llvm::Triple::x86:
271 case llvm::Triple::x86_64:
272 P.appendComponent("i686-apple-darwin10");
273 break;
274 case llvm::Triple::arm:
275 case llvm::Triple::thumb:
276 P.appendComponent("arm-apple-darwin10");
277 break;
278 case llvm::Triple::ppc:
279 case llvm::Triple::ppc64:
280 P.appendComponent("powerpc-apple-darwin10");
281 break;
282 }
283 P.appendComponent("4.2.1");
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000284
285 // Determine the arch specific GCC subdirectory.
286 const char *ArchSpecificDir = 0;
287 switch (getTriple().getArch()) {
288 default:
289 break;
290 case llvm::Triple::arm:
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000291 case llvm::Triple::thumb: {
292 std::string Triple = ComputeLLVMTriple(Args);
293 llvm::StringRef TripleStr = Triple;
294 if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5"))
295 ArchSpecificDir = "v5";
296 else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6"))
297 ArchSpecificDir = "v6";
298 else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7"))
299 ArchSpecificDir = "v7";
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000300 break;
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000301 }
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000302 case llvm::Triple::ppc64:
303 ArchSpecificDir = "ppc64";
304 break;
305 case llvm::Triple::x86_64:
306 ArchSpecificDir = "x86_64";
307 break;
308 }
309
310 if (ArchSpecificDir) {
311 P.appendComponent(ArchSpecificDir);
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000312 bool Exists;
313 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000314 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
315 P.eraseComponent();
316 }
317
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000318 bool Exists;
319 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbar424b6612010-06-30 23:56:13 +0000320 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000321}
322
323void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
324 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000325 // Darwin doesn't support real static executables, don't link any runtime
326 // libraries with -static.
327 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000328 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000329
330 // Reject -static-libgcc for now, we can deal with this when and if someone
331 // cares. This is useful in situations where someone wants to statically link
332 // something like libstdc++, and needs its runtime support routines.
333 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000334 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000335 << A->getAsString(Args);
336 return;
337 }
338
Daniel Dunbareec99102010-01-22 03:38:14 +0000339 // Otherwise link libSystem, then the dynamic runtime library, and finally any
340 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000341 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000342
343 // Select the dynamic runtime library and the target specific static library.
344 const char *DarwinStaticLib = 0;
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000345 if (isTargetIPhoneOS()) {
Daniel Dunbar87e945f2011-04-30 04:25:16 +0000346 // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
347 // it never went into the SDK.
348 if (!isTargetIOSSimulator())
349 CmdArgs.push_back("-lgcc_s.1");
Daniel Dunbareec99102010-01-22 03:38:14 +0000350
Daniel Dunbar3cceec52011-04-18 23:48:36 +0000351 // We currently always need a static runtime library for iOS.
352 DarwinStaticLib = "libclang_rt.ios.a";
Daniel Dunbareec99102010-01-22 03:38:14 +0000353 } else {
Daniel Dunbareec99102010-01-22 03:38:14 +0000354 // The dynamic runtime library was merged with libSystem for 10.6 and
355 // beyond; only 10.4 and 10.5 need an additional runtime library.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000356 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000357 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000358 else if (isMacosxVersionLT(10, 6))
Daniel Dunbareec99102010-01-22 03:38:14 +0000359 CmdArgs.push_back("-lgcc_s.10.5");
360
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000361 // For OS X, we thought we would only need a static runtime library when
Chris Lattnerfc8f0e12011-04-15 05:22:18 +0000362 // targeting 10.4, to provide versions of the static functions which were
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000363 // omitted from 10.4.dylib.
364 //
365 // Unfortunately, that turned out to not be true, because Darwin system
366 // headers can still use eprintf on i386, and it is not exported from
367 // libSystem. Therefore, we still must provide a runtime library just for
368 // the tiny tiny handful of projects that *might* use that symbol.
369 if (isMacosxVersionLT(10, 5)) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000370 DarwinStaticLib = "libclang_rt.10.4.a";
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000371 } else {
372 if (getTriple().getArch() == llvm::Triple::x86)
373 DarwinStaticLib = "libclang_rt.eprintf.a";
374 }
Daniel Dunbareec99102010-01-22 03:38:14 +0000375 }
376
377 /// Add the target specific static library, if needed.
378 if (DarwinStaticLib) {
379 llvm::sys::Path P(getDriver().ResourceDir);
380 P.appendComponent("lib");
381 P.appendComponent("darwin");
382 P.appendComponent(DarwinStaticLib);
383
384 // For now, allow missing resource libraries to support developers who may
385 // not have compiler-rt checked out or integrated into their build.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000386 bool Exists;
387 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbareec99102010-01-22 03:38:14 +0000388 CmdArgs.push_back(Args.MakeArgString(P.str()));
389 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000390}
391
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000392void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000393 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000394
Daniel Dunbar26031372010-01-27 00:56:25 +0000395 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000396 Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
397 Arg *iOSSimVersion = Args.getLastArg(
398 options::OPT_mios_simulator_version_min_EQ);
399 if (OSXVersion && (iOSVersion || iOSSimVersion)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000400 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000401 << OSXVersion->getAsString(Args)
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000402 << (iOSVersion ? iOSVersion : iOSSimVersion)->getAsString(Args);
403 iOSVersion = iOSSimVersion = 0;
404 } else if (iOSVersion && iOSSimVersion) {
405 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
406 << iOSVersion->getAsString(Args)
407 << iOSSimVersion->getAsString(Args);
408 iOSSimVersion = 0;
409 } else if (!OSXVersion && !iOSVersion && !iOSSimVersion) {
410 // If not deployment target was specified on the command line, check for
Daniel Dunbar816bc312010-01-26 01:45:19 +0000411 // environment defines.
412 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000413 const char *iOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
414 const char *iOSSimTarget = ::getenv("IOS_SIMULATOR_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000415
Daniel Dunbar816bc312010-01-26 01:45:19 +0000416 // Ignore empty strings.
417 if (OSXTarget && OSXTarget[0] == '\0')
418 OSXTarget = 0;
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000419 if (iOSTarget && iOSTarget[0] == '\0')
420 iOSTarget = 0;
421 if (iOSSimTarget && iOSSimTarget[0] == '\0')
422 iOSSimTarget = 0;
Daniel Dunbar816bc312010-01-26 01:45:19 +0000423
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000424 // Handle conflicting deployment targets
Daniel Dunbar39053672010-02-02 17:31:12 +0000425 //
426 // FIXME: Don't hardcode default here.
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000427
428 // Do not allow conflicts with the iOS simulator target.
429 if (iOSSimTarget && (OSXTarget || iOSTarget)) {
430 getDriver().Diag(clang::diag::err_drv_conflicting_deployment_targets)
431 << "IOS_SIMULATOR_DEPLOYMENT_TARGET"
432 << (OSXTarget ? "MACOSX_DEPLOYMENT_TARGET" :
433 "IPHONEOS_DEPLOYMENT_TARGET");
434 }
435
436 // Allow conflicts among OSX and iOS for historical reasons, but choose the
437 // default platform.
438 if (OSXTarget && iOSTarget) {
Daniel Dunbar39053672010-02-02 17:31:12 +0000439 if (getTriple().getArch() == llvm::Triple::arm ||
440 getTriple().getArch() == llvm::Triple::thumb)
Daniel Dunbar84d1e6e2010-03-20 08:47:42 +0000441 OSXTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000442 else
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000443 iOSTarget = 0;
Daniel Dunbar39053672010-02-02 17:31:12 +0000444 }
Daniel Dunbar1a3c1d92010-01-29 17:02:25 +0000445
Daniel Dunbar39053672010-02-02 17:31:12 +0000446 if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000447 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000448 OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget);
449 Args.append(OSXVersion);
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000450 } else if (iOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000451 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000452 iOSVersion = Args.MakeJoinedArg(0, O, iOSTarget);
453 Args.append(iOSVersion);
454 } else if (iOSSimTarget) {
455 const Option *O = Opts.getOption(
456 options::OPT_mios_simulator_version_min_EQ);
457 iOSSimVersion = Args.MakeJoinedArg(0, O, iOSSimTarget);
458 Args.append(iOSSimVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000459 } else {
Daniel Dunbar2bb38d02010-07-15 16:18:06 +0000460 // Otherwise, assume we are targeting OS X.
461 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000462 OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin);
463 Args.append(OSXVersion);
Daniel Dunbar30392de2009-09-04 18:35:21 +0000464 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000465 }
Mike Stump1eb44332009-09-09 15:08:12 +0000466
Daniel Dunbar3fd823b2011-04-30 04:20:40 +0000467 // Reject invalid architecture combinations.
468 if (iOSSimVersion && (getTriple().getArch() != llvm::Triple::x86 &&
469 getTriple().getArch() != llvm::Triple::x86_64)) {
470 getDriver().Diag(clang::diag::err_drv_invalid_arch_for_deployment_target)
471 << getTriple().getArchName() << iOSSimVersion->getAsString(Args);
472 }
473
Daniel Dunbar26031372010-01-27 00:56:25 +0000474 // Set the tool chain target information.
475 unsigned Major, Minor, Micro;
476 bool HadExtra;
477 if (OSXVersion) {
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000478 assert((!iOSVersion && !iOSSimVersion) && "Unknown target platform!");
Daniel Dunbar26031372010-01-27 00:56:25 +0000479 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
480 Micro, HadExtra) || HadExtra ||
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000481 Major != 10 || Minor >= 100 || Micro >= 100)
Daniel Dunbar26031372010-01-27 00:56:25 +0000482 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
483 << OSXVersion->getAsString(Args);
484 } else {
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000485 const Arg *Version = iOSVersion ? iOSVersion : iOSSimVersion;
486 assert(Version && "Unknown target platform!");
487 if (!Driver::GetReleaseVersion(Version->getValue(Args), Major, Minor,
Daniel Dunbar26031372010-01-27 00:56:25 +0000488 Micro, HadExtra) || HadExtra ||
489 Major >= 10 || Minor >= 100 || Micro >= 100)
490 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000491 << Version->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000492 }
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000493
Daniel Dunbar5f5c37b2011-04-30 04:18:16 +0000494 bool IsIOSSim = bool(iOSSimVersion);
495
496 // In GCC, the simulator historically was treated as being OS X in some
497 // contexts, like determining the link logic, despite generally being called
498 // with an iOS deployment target. For compatibility, we detect the
499 // simulator as iOS + x86, and treat it differently in a few contexts.
500 if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 ||
501 getTriple().getArch() == llvm::Triple::x86_64))
502 IsIOSSim = true;
503
504 setTarget(/*IsIPhoneOS=*/ !OSXVersion, Major, Minor, Micro, IsIOSSim);
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000505}
506
Daniel Dunbar132e35d2010-09-17 01:20:05 +0000507void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args,
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000508 ArgStringList &CmdArgs) const {
509 CXXStdlibType Type = GetCXXStdlibType(Args);
510
511 switch (Type) {
512 case ToolChain::CST_Libcxx:
513 CmdArgs.push_back("-lc++");
514 break;
515
516 case ToolChain::CST_Libstdcxx: {
517 // Unfortunately, -lstdc++ doesn't always exist in the standard search path;
518 // it was previously found in the gcc lib dir. However, for all the Darwin
519 // platforms we care about it was -lstdc++.6, so we search for that
520 // explicitly if we can't see an obvious -lstdc++ candidate.
521
522 // Check in the sysroot first.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000523 bool Exists;
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000524 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
525 llvm::sys::Path P(A->getValue(Args));
526 P.appendComponent("usr");
527 P.appendComponent("lib");
528 P.appendComponent("libstdc++.dylib");
529
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000530 if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) {
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000531 P.eraseComponent();
532 P.appendComponent("libstdc++.6.dylib");
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000533 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) {
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000534 CmdArgs.push_back(Args.MakeArgString(P.str()));
535 return;
536 }
537 }
538 }
539
540 // Otherwise, look in the root.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000541 if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&&
542 (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000543 CmdArgs.push_back("/usr/lib/libstdc++.6.dylib");
544 return;
545 }
546
547 // Otherwise, let the linker search.
548 CmdArgs.push_back("-lstdc++");
549 break;
550 }
551 }
552}
553
Shantonu Sen7433fed2010-09-17 18:39:08 +0000554void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
555 ArgStringList &CmdArgs) const {
556
557 // For Darwin platforms, use the compiler-rt-based support library
558 // instead of the gcc-provided one (which is also incidentally
559 // only present in the gcc lib dir, which makes it hard to find).
560
561 llvm::sys::Path P(getDriver().ResourceDir);
562 P.appendComponent("lib");
563 P.appendComponent("darwin");
564 P.appendComponent("libclang_rt.cc_kext.a");
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000565
Shantonu Sen7433fed2010-09-17 18:39:08 +0000566 // For now, allow missing resource libraries to support developers who may
567 // not have compiler-rt checked out or integrated into their build.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000568 bool Exists;
569 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Shantonu Sen7433fed2010-09-17 18:39:08 +0000570 CmdArgs.push_back(Args.MakeArgString(P.str()));
571}
572
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000573DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
574 const char *BoundArch) const {
575 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
576 const OptTable &Opts = getDriver().getOpts();
577
578 // FIXME: We really want to get out of the tool chain level argument
579 // translation business, as it makes the driver functionality much
580 // more opaque. For now, we follow gcc closely solely for the
581 // purpose of easily achieving feature parity & testability. Once we
582 // have something that works, we should reevaluate each translation
583 // and try to push it down into tool specific logic.
Daniel Dunbar26031372010-01-27 00:56:25 +0000584
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000585 for (ArgList::const_iterator it = Args.begin(),
586 ie = Args.end(); it != ie; ++it) {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000587 Arg *A = *it;
588
589 if (A->getOption().matches(options::OPT_Xarch__)) {
590 // FIXME: Canonicalize name.
591 if (getArchName() != A->getValue(Args, 0))
592 continue;
593
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000594 Arg *OriginalArg = A;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000595 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1));
596 unsigned Prev = Index;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000597 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000598
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000599 // If the argument parsing failed or more than one argument was
600 // consumed, the -Xarch_ argument's parameter tried to consume
601 // extra arguments. Emit an error and ignore.
602 //
603 // We also want to disallow any options which would alter the
604 // driver behavior; that isn't going to work in our model. We
605 // use isDriverOption() as an approximation, although things
606 // like -O4 are going to slip through.
Daniel Dunbar0e02f6e2011-04-21 17:41:34 +0000607 if (!XarchArg || Index > Prev + 1) {
Daniel Dunbar7e9293b2011-04-21 17:32:21 +0000608 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument_with_args)
609 << A->getAsString(Args);
610 continue;
611 } else if (XarchArg->getOption().isDriverOption()) {
612 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument_isdriver)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000613 << A->getAsString(Args);
614 continue;
615 }
616
Daniel Dunbar478edc22009-03-29 22:29:05 +0000617 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000618 A = XarchArg;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000619
620 DAL->AddSynthesizedArg(A);
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000621
622 // Linker input arguments require custom handling. The problem is that we
623 // have already constructed the phase actions, so we can not treat them as
624 // "input arguments".
625 if (A->getOption().isLinkerInput()) {
626 // Convert the argument into individual Zlinker_input_args.
627 for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
628 DAL->AddSeparateArg(OriginalArg,
629 Opts.getOption(options::OPT_Zlinker_input),
630 A->getValue(Args, i));
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000631
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000632 }
633 continue;
634 }
Mike Stump1eb44332009-09-09 15:08:12 +0000635 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000636
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000637 // Sob. These is strictly gcc compatible for the time being. Apple
638 // gcc translates options twice, which means that self-expanding
639 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000640 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000641 default:
642 DAL->append(A);
643 break;
644
645 case options::OPT_mkernel:
646 case options::OPT_fapple_kext:
647 DAL->append(A);
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000648 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
649 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000650 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000651
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000652 case options::OPT_dependency_file:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000653 DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF),
654 A->getValue(Args));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000655 break;
656
657 case options::OPT_gfull:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000658 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
659 DAL->AddFlagArg(A,
660 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000661 break;
662
663 case options::OPT_gused:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000664 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
665 DAL->AddFlagArg(A,
666 Opts.getOption(options::OPT_feliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000667 break;
668
669 case options::OPT_fterminated_vtables:
670 case options::OPT_findirect_virtual_calls:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000671 DAL->AddFlagArg(A, Opts.getOption(options::OPT_fapple_kext));
672 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000673 break;
674
675 case options::OPT_shared:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000676 DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000677 break;
678
679 case options::OPT_fconstant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000680 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000681 break;
682
683 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000684 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000685 break;
686
687 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000688 DAL->AddFlagArg(A,
689 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000690 break;
691
692 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000693 DAL->AddFlagArg(A,
694 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000695 break;
696
697 case options::OPT_fpascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000698 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000699 break;
700
701 case options::OPT_fno_pascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000702 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000703 break;
704 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000705 }
706
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000707 if (getTriple().getArch() == llvm::Triple::x86 ||
708 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000709 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000710 DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000711
712 // Add the arch options based on the particular spelling of -arch, to match
713 // how the driver driver works.
714 if (BoundArch) {
715 llvm::StringRef Name = BoundArch;
716 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
717 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
718
719 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
720 // which defines the list of which architectures we accept.
721 if (Name == "ppc")
722 ;
723 else if (Name == "ppc601")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000724 DAL->AddJoinedArg(0, MCpu, "601");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000725 else if (Name == "ppc603")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000726 DAL->AddJoinedArg(0, MCpu, "603");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000727 else if (Name == "ppc604")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000728 DAL->AddJoinedArg(0, MCpu, "604");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000729 else if (Name == "ppc604e")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000730 DAL->AddJoinedArg(0, MCpu, "604e");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000731 else if (Name == "ppc750")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000732 DAL->AddJoinedArg(0, MCpu, "750");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000733 else if (Name == "ppc7400")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000734 DAL->AddJoinedArg(0, MCpu, "7400");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000735 else if (Name == "ppc7450")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000736 DAL->AddJoinedArg(0, MCpu, "7450");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000737 else if (Name == "ppc970")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000738 DAL->AddJoinedArg(0, MCpu, "970");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000739
740 else if (Name == "ppc64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000741 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000742
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000743 else if (Name == "i386")
744 ;
745 else if (Name == "i486")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000746 DAL->AddJoinedArg(0, MArch, "i486");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000747 else if (Name == "i586")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000748 DAL->AddJoinedArg(0, MArch, "i586");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000749 else if (Name == "i686")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000750 DAL->AddJoinedArg(0, MArch, "i686");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000751 else if (Name == "pentium")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000752 DAL->AddJoinedArg(0, MArch, "pentium");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000753 else if (Name == "pentium2")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000754 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000755 else if (Name == "pentpro")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000756 DAL->AddJoinedArg(0, MArch, "pentiumpro");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000757 else if (Name == "pentIIm3")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000758 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000759
760 else if (Name == "x86_64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000761 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000762
763 else if (Name == "arm")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000764 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000765 else if (Name == "armv4t")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000766 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000767 else if (Name == "armv5")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000768 DAL->AddJoinedArg(0, MArch, "armv5tej");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000769 else if (Name == "xscale")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000770 DAL->AddJoinedArg(0, MArch, "xscale");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000771 else if (Name == "armv6")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000772 DAL->AddJoinedArg(0, MArch, "armv6k");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000773 else if (Name == "armv7")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000774 DAL->AddJoinedArg(0, MArch, "armv7a");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000775
776 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000777 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000778 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000779
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000780 // Add an explicit version min argument for the deployment target. We do this
781 // after argument translation because -Xarch_ arguments may add a version min
782 // argument.
783 AddDeploymentTarget(*DAL);
784
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000785 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000786}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000787
Daniel Dunbarf3955282009-09-04 18:34:51 +0000788bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000789 // FIXME: Gross; we should probably have some separate target
790 // definition, possibly even reusing the one in clang.
791 return getArchName() == "x86_64";
792}
793
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000794bool Darwin::UseDwarfDebugFlags() const {
795 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
796 return S[0] != '\0';
797 return false;
798}
799
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000800bool Darwin::UseSjLjExceptions() const {
801 // Darwin uses SjLj exceptions on ARM.
802 return (getTriple().getArch() == llvm::Triple::arm ||
803 getTriple().getArch() == llvm::Triple::thumb);
804}
805
Daniel Dunbarf3955282009-09-04 18:34:51 +0000806const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000807 return "pic";
808}
809
Daniel Dunbarf3955282009-09-04 18:34:51 +0000810const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000811 if (getArchName() == "x86_64")
812 return "pic";
813 return 0;
814}
815
Daniel Dunbarbbe8e3e2011-03-01 18:49:30 +0000816bool Darwin::SupportsProfiling() const {
817 // Profiling instrumentation is only supported on x86.
818 return getArchName() == "i386" || getArchName() == "x86_64";
819}
820
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000821bool Darwin::SupportsObjCGC() const {
822 // Garbage collection is supported everywhere except on iPhone OS.
823 return !isTargetIPhoneOS();
824}
825
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000826std::string
827Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const {
828 return ComputeLLVMTriple(Args);
829}
830
Daniel Dunbar39176082009-03-20 00:20:03 +0000831/// Generic_GCC - A tool chain using the 'gcc' command to perform
832/// all subcommands; this relies on gcc translating the majority of
833/// command line options.
834
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000835Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000836 : ToolChain(Host, Triple) {
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000837 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +0000838 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000839 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000840}
841
Daniel Dunbar39176082009-03-20 00:20:03 +0000842Generic_GCC::~Generic_GCC() {
843 // Free tool implementations.
844 for (llvm::DenseMap<unsigned, Tool*>::iterator
845 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
846 delete it->second;
847}
848
Mike Stump1eb44332009-09-09 15:08:12 +0000849Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000850 const JobAction &JA,
851 const ActionList &Inputs) const {
Daniel Dunbar39176082009-03-20 00:20:03 +0000852 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000853 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000854 Key = Action::AnalyzeJobClass;
855 else
856 Key = JA.getKind();
857
858 Tool *&T = Tools[Key];
859 if (!T) {
860 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000861 case Action::InputClass:
862 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000863 assert(0 && "Invalid tool kind.");
864 case Action::PreprocessJobClass:
865 T = new tools::gcc::Preprocess(*this); break;
866 case Action::PrecompileJobClass:
867 T = new tools::gcc::Precompile(*this); break;
868 case Action::AnalyzeJobClass:
869 T = new tools::Clang(*this); break;
870 case Action::CompileJobClass:
871 T = new tools::gcc::Compile(*this); break;
872 case Action::AssembleJobClass:
873 T = new tools::gcc::Assemble(*this); break;
874 case Action::LinkJobClass:
875 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000876
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000877 // This is a bit ungeneric, but the only platform using a driver
878 // driver is Darwin.
879 case Action::LipoJobClass:
880 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000881 case Action::DsymutilJobClass:
882 T = new tools::darwin::Dsymutil(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000883 }
884 }
885
886 return *T;
887}
888
Daniel Dunbar39176082009-03-20 00:20:03 +0000889bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000890 // FIXME: Gross; we should probably have some separate target
891 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000892 return getArchName() == "x86_64";
893}
894
895const char *Generic_GCC::GetDefaultRelocationModel() const {
896 return "static";
897}
898
899const char *Generic_GCC::GetForcedPicModel() const {
900 return 0;
901}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000902
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000903/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
904/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
905/// Currently does not support anything else but compilation.
906
907TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple)
908 : ToolChain(Host, Triple) {
909 // Path mangling to find libexec
910 std::string Path(getDriver().Dir);
911
912 Path += "/../libexec";
913 getProgramPaths().push_back(Path);
914}
915
916TCEToolChain::~TCEToolChain() {
917 for (llvm::DenseMap<unsigned, Tool*>::iterator
918 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
919 delete it->second;
920}
921
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000922bool TCEToolChain::IsMathErrnoDefault() const {
923 return true;
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000924}
925
926bool TCEToolChain::IsUnwindTablesDefault() const {
927 return false;
928}
929
930const char *TCEToolChain::GetDefaultRelocationModel() const {
931 return "static";
932}
933
934const char *TCEToolChain::GetForcedPicModel() const {
935 return 0;
936}
937
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000938Tool &TCEToolChain::SelectTool(const Compilation &C,
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000939 const JobAction &JA,
940 const ActionList &Inputs) const {
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000941 Action::ActionClass Key;
942 Key = Action::AnalyzeJobClass;
943
944 Tool *&T = Tools[Key];
945 if (!T) {
946 switch (Key) {
947 case Action::PreprocessJobClass:
948 T = new tools::gcc::Preprocess(*this); break;
949 case Action::AnalyzeJobClass:
950 T = new tools::Clang(*this); break;
951 default:
952 assert(false && "Unsupported action for TCE target.");
953 }
954 }
955 return *T;
956}
957
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000958/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
959
960OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +0000961 : Generic_ELF(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000962 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000963 getFilePaths().push_back("/usr/lib");
964}
965
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000966Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA,
967 const ActionList &Inputs) const {
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000968 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000969 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000970 Key = Action::AnalyzeJobClass;
971 else
972 Key = JA.getKind();
973
Rafael Espindoladda5b922010-11-07 23:13:01 +0000974 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
975 options::OPT_no_integrated_as,
976 IsIntegratedAssemblerDefault());
977
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000978 Tool *&T = Tools[Key];
979 if (!T) {
980 switch (Key) {
Rafael Espindoladda5b922010-11-07 23:13:01 +0000981 case Action::AssembleJobClass: {
982 if (UseIntegratedAs)
983 T = new tools::ClangAs(*this);
984 else
985 T = new tools::openbsd::Assemble(*this);
986 break;
987 }
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000988 case Action::LinkJobClass:
989 T = new tools::openbsd::Link(*this); break;
990 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000991 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000992 }
993 }
994
995 return *T;
996}
997
Daniel Dunbar75358d22009-03-30 21:06:03 +0000998/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
999
Daniel Dunbar214afe92010-08-02 05:43:59 +00001000FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001001 : Generic_ELF(Host, Triple) {
Daniel Dunbar214afe92010-08-02 05:43:59 +00001002
1003 // Determine if we are compiling 32-bit code on an x86_64 platform.
1004 bool Lib32 = false;
1005 if (Triple.getArch() == llvm::Triple::x86 &&
1006 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1007 llvm::Triple::x86_64)
1008 Lib32 = true;
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001009
Roman Divacky3393cef2011-06-04 07:37:31 +00001010 if (Triple.getArch() == llvm::Triple::ppc &&
1011 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1012 llvm::Triple::ppc64)
1013 Lib32 = true;
1014
Daniel Dunbarbc534662009-04-02 18:30:04 +00001015 if (Lib32) {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001016 getFilePaths().push_back("/usr/lib32");
1017 } else {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001018 getFilePaths().push_back("/usr/lib");
1019 }
Daniel Dunbar75358d22009-03-30 21:06:03 +00001020}
1021
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001022Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA,
1023 const ActionList &Inputs) const {
Daniel Dunbar75358d22009-03-30 21:06:03 +00001024 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001025 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +00001026 Key = Action::AnalyzeJobClass;
1027 else
1028 Key = JA.getKind();
1029
Roman Divacky67dece72010-11-08 17:46:39 +00001030 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1031 options::OPT_no_integrated_as,
1032 IsIntegratedAssemblerDefault());
1033
Daniel Dunbar75358d22009-03-30 21:06:03 +00001034 Tool *&T = Tools[Key];
1035 if (!T) {
1036 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +00001037 case Action::AssembleJobClass:
Roman Divacky67dece72010-11-08 17:46:39 +00001038 if (UseIntegratedAs)
1039 T = new tools::ClangAs(*this);
1040 else
1041 T = new tools::freebsd::Assemble(*this);
Roman Divackyfe3a7ea2010-11-08 19:39:10 +00001042 break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +00001043 case Action::LinkJobClass:
1044 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +00001045 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001046 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbar75358d22009-03-30 21:06:03 +00001047 }
1048 }
1049
1050 return *T;
1051}
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001052
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001053/// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly.
1054
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001055NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple,
1056 const llvm::Triple& ToolTriple)
1057 : Generic_ELF(Host, Triple), ToolTriple(ToolTriple) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001058
1059 // Determine if we are compiling 32-bit code on an x86_64 platform.
1060 bool Lib32 = false;
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001061 if (ToolTriple.getArch() == llvm::Triple::x86_64 &&
1062 Triple.getArch() == llvm::Triple::x86)
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001063 Lib32 = true;
1064
Joerg Sonnenberger05e59302011-03-21 13:59:26 +00001065 if (getDriver().UseStdLib) {
1066 if (Lib32)
1067 getFilePaths().push_back("=/usr/lib/i386");
1068 else
1069 getFilePaths().push_back("=/usr/lib");
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001070 }
1071}
1072
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001073Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA,
1074 const ActionList &Inputs) const {
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001075 Action::ActionClass Key;
1076 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1077 Key = Action::AnalyzeJobClass;
1078 else
1079 Key = JA.getKind();
1080
1081 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1082 options::OPT_no_integrated_as,
1083 IsIntegratedAssemblerDefault());
1084
1085 Tool *&T = Tools[Key];
1086 if (!T) {
1087 switch (Key) {
1088 case Action::AssembleJobClass:
1089 if (UseIntegratedAs)
1090 T = new tools::ClangAs(*this);
1091 else
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001092 T = new tools::netbsd::Assemble(*this, ToolTriple);
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001093 break;
1094 case Action::LinkJobClass:
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001095 T = new tools::netbsd::Link(*this, ToolTriple);
1096 break;
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001097 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001098 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001099 }
1100 }
1101
1102 return *T;
1103}
1104
Chris Lattner38e317d2010-07-07 16:01:42 +00001105/// Minix - Minix tool chain which can call as(1) and ld(1) directly.
1106
1107Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple)
1108 : Generic_GCC(Host, Triple) {
1109 getFilePaths().push_back(getDriver().Dir + "/../lib");
1110 getFilePaths().push_back("/usr/lib");
1111 getFilePaths().push_back("/usr/gnu/lib");
1112 getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
1113}
1114
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001115Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA,
1116 const ActionList &Inputs) const {
Chris Lattner38e317d2010-07-07 16:01:42 +00001117 Action::ActionClass Key;
1118 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1119 Key = Action::AnalyzeJobClass;
1120 else
1121 Key = JA.getKind();
1122
1123 Tool *&T = Tools[Key];
1124 if (!T) {
1125 switch (Key) {
1126 case Action::AssembleJobClass:
1127 T = new tools::minix::Assemble(*this); break;
1128 case Action::LinkJobClass:
1129 T = new tools::minix::Link(*this); break;
1130 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001131 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Chris Lattner38e317d2010-07-07 16:01:42 +00001132 }
1133 }
1134
1135 return *T;
1136}
1137
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001138/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
1139
1140AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
1141 : Generic_GCC(Host, Triple) {
1142
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001143 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +00001144 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001145 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001146
Daniel Dunbaree788e72009-12-21 18:54:17 +00001147 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001148 getFilePaths().push_back("/usr/lib");
1149 getFilePaths().push_back("/usr/sfw/lib");
1150 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +00001151 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001152
1153}
1154
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001155Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA,
1156 const ActionList &Inputs) const {
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001157 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001158 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001159 Key = Action::AnalyzeJobClass;
1160 else
1161 Key = JA.getKind();
1162
1163 Tool *&T = Tools[Key];
1164 if (!T) {
1165 switch (Key) {
1166 case Action::AssembleJobClass:
1167 T = new tools::auroraux::Assemble(*this); break;
1168 case Action::LinkJobClass:
1169 T = new tools::auroraux::Link(*this); break;
1170 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001171 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001172 }
1173 }
1174
1175 return *T;
1176}
1177
1178
Eli Friedman6b3454a2009-05-26 07:52:18 +00001179/// Linux toolchain (very bare-bones at the moment).
1180
Rafael Espindolac1da9812010-11-07 20:14:31 +00001181enum LinuxDistro {
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001182 ArchLinux,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001183 DebianLenny,
1184 DebianSqueeze,
Eli Friedman0b200f62011-06-02 21:36:53 +00001185 DebianWheezy,
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001186 Exherbo,
Chris Lattnerd753b562011-05-22 05:36:06 +00001187 RHEL4,
1188 RHEL5,
1189 RHEL6,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001190 Fedora13,
1191 Fedora14,
Eric Christopher8f1cc072011-04-06 18:22:53 +00001192 Fedora15,
1193 FedoraRawhide,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001194 OpenSuse11_3,
David Chisnallde5c0482011-05-19 13:26:33 +00001195 OpenSuse11_4,
1196 OpenSuse12_1,
Douglas Gregor814638e2011-03-14 15:39:50 +00001197 UbuntuHardy,
1198 UbuntuIntrepid,
Rafael Espindola021aaa42010-11-10 05:00:22 +00001199 UbuntuJaunty,
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001200 UbuntuKarmic,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001201 UbuntuLucid,
1202 UbuntuMaverick,
Ted Kremenek43ac2972011-04-05 22:04:27 +00001203 UbuntuNatty,
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001204 UbuntuOneiric,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001205 UnknownDistro
1206};
1207
Chris Lattnerd753b562011-05-22 05:36:06 +00001208static bool IsRedhat(enum LinuxDistro Distro) {
Eric Christopher8f1cc072011-04-06 18:22:53 +00001209 return Distro == Fedora13 || Distro == Fedora14 ||
Rafael Espindola5a640ef2011-06-03 15:23:24 +00001210 Distro == Fedora15 || Distro == FedoraRawhide ||
1211 Distro == RHEL4 || Distro == RHEL5 || Distro == RHEL6;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001212}
1213
1214static bool IsOpenSuse(enum LinuxDistro Distro) {
David Chisnallde5c0482011-05-19 13:26:33 +00001215 return Distro == OpenSuse11_3 || Distro == OpenSuse11_4 ||
1216 Distro == OpenSuse12_1;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001217}
1218
1219static bool IsDebian(enum LinuxDistro Distro) {
Eli Friedman0b200f62011-06-02 21:36:53 +00001220 return Distro == DebianLenny || Distro == DebianSqueeze ||
1221 Distro == DebianWheezy;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001222}
1223
1224static bool IsUbuntu(enum LinuxDistro Distro) {
Douglas Gregor814638e2011-03-14 15:39:50 +00001225 return Distro == UbuntuHardy || Distro == UbuntuIntrepid ||
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001226 Distro == UbuntuLucid || Distro == UbuntuMaverick ||
Ted Kremenek43ac2972011-04-05 22:04:27 +00001227 Distro == UbuntuJaunty || Distro == UbuntuKarmic ||
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001228 Distro == UbuntuNatty || Distro == UbuntuOneiric;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001229}
1230
1231static bool IsDebianBased(enum LinuxDistro Distro) {
1232 return IsDebian(Distro) || IsUbuntu(Distro);
1233}
1234
1235static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) {
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001236 if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001237 bool Exists;
1238 if (Distro == Exherbo &&
1239 (llvm::sys::fs::exists("/usr/lib32/libc.so", Exists) || !Exists))
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001240 return false;
1241
Rafael Espindolac1da9812010-11-07 20:14:31 +00001242 return true;
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001243 }
Ted Kremenek43ac2972011-04-05 22:04:27 +00001244 if (Arch == llvm::Triple::ppc64)
1245 return true;
Eric Christopher9af535a2011-06-03 13:28:31 +00001246 if ((Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc) &&
1247 IsDebianBased(Distro))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001248 return true;
1249 return false;
1250}
1251
1252static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001253 llvm::OwningPtr<llvm::MemoryBuffer> File;
1254 if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) {
1255 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001256 llvm::SmallVector<llvm::StringRef, 8> Lines;
1257 Data.split(Lines, "\n");
1258 for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) {
Douglas Gregor814638e2011-03-14 15:39:50 +00001259 if (Lines[i] == "DISTRIB_CODENAME=hardy")
1260 return UbuntuHardy;
Ted Kremenek43ac2972011-04-05 22:04:27 +00001261 else if (Lines[i] == "DISTRIB_CODENAME=intrepid")
1262 return UbuntuIntrepid;
Rafael Espindola021aaa42010-11-10 05:00:22 +00001263 else if (Lines[i] == "DISTRIB_CODENAME=jaunty")
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001264 return UbuntuJaunty;
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001265 else if (Lines[i] == "DISTRIB_CODENAME=karmic")
1266 return UbuntuKarmic;
Ted Kremenek43ac2972011-04-05 22:04:27 +00001267 else if (Lines[i] == "DISTRIB_CODENAME=lucid")
1268 return UbuntuLucid;
1269 else if (Lines[i] == "DISTRIB_CODENAME=maverick")
1270 return UbuntuMaverick;
1271 else if (Lines[i] == "DISTRIB_CODENAME=natty")
1272 return UbuntuNatty;
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001273 else if (Lines[i] == "DISTRIB_CODENAME=oneiric")
1274 return UbuntuOneiric;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001275 }
1276 return UnknownDistro;
1277 }
1278
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001279 if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) {
1280 llvm::StringRef Data = File.get()->getBuffer();
Eric Christopher8f1cc072011-04-06 18:22:53 +00001281 if (Data.startswith("Fedora release 15"))
1282 return Fedora15;
1283 else if (Data.startswith("Fedora release 14"))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001284 return Fedora14;
Eric Christopher8f1cc072011-04-06 18:22:53 +00001285 else if (Data.startswith("Fedora release 13"))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001286 return Fedora13;
Eric Christopher8f1cc072011-04-06 18:22:53 +00001287 else if (Data.startswith("Fedora release") &&
1288 Data.find("Rawhide") != llvm::StringRef::npos)
1289 return FedoraRawhide;
Chris Lattnerd753b562011-05-22 05:36:06 +00001290 else if (Data.startswith("Red Hat Enterprise Linux") &&
1291 Data.find("release 6") != llvm::StringRef::npos)
1292 return RHEL6;
Rafael Espindola5a640ef2011-06-03 15:23:24 +00001293 else if ((Data.startswith("Red Hat Enterprise Linux") ||
1294 Data.startswith("CentOS")) &&
Chris Lattnerd753b562011-05-22 05:36:06 +00001295 Data.find("release 5") != llvm::StringRef::npos)
1296 return RHEL5;
Rafael Espindola5a640ef2011-06-03 15:23:24 +00001297 else if ((Data.startswith("Red Hat Enterprise Linux") ||
1298 Data.startswith("CentOS")) &&
Chris Lattnerd753b562011-05-22 05:36:06 +00001299 Data.find("release 4") != llvm::StringRef::npos)
1300 return RHEL4;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001301 return UnknownDistro;
1302 }
1303
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001304 if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) {
1305 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001306 if (Data[0] == '5')
1307 return DebianLenny;
1308 else if (Data.startswith("squeeze/sid"))
1309 return DebianSqueeze;
Eli Friedman0b200f62011-06-02 21:36:53 +00001310 else if (Data.startswith("wheezy/sid"))
1311 return DebianWheezy;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001312 return UnknownDistro;
1313 }
1314
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001315 if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) {
1316 llvm::StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001317 if (Data.startswith("openSUSE 11.3"))
1318 return OpenSuse11_3;
David Chisnallde5c0482011-05-19 13:26:33 +00001319 else if (Data.startswith("openSUSE 11.4"))
1320 return OpenSuse11_4;
1321 else if (Data.startswith("openSUSE 12.1"))
1322 return OpenSuse12_1;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001323 return UnknownDistro;
1324 }
1325
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001326 bool Exists;
1327 if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001328 return Exherbo;
1329
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001330 if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists)
1331 return ArchLinux;
1332
Rafael Espindolac1da9812010-11-07 20:14:31 +00001333 return UnknownDistro;
1334}
1335
Rafael Espindola14ea13c2011-06-02 22:18:46 +00001336static std::string findGCCBaseLibDir(const std::string &GccTriple) {
1337 // FIXME: Using CXX_INCLUDE_ROOT is here is a bit of a hack, but
1338 // avoids adding yet another option to configure/cmake.
1339 // It would probably be cleaner to break it in two variables
1340 // CXX_GCC_ROOT with just /foo/bar
1341 // CXX_GCC_VER with 4.5.2
1342 // Then we would have
1343 // CXX_INCLUDE_ROOT = CXX_GCC_ROOT/include/c++/CXX_GCC_VER
1344 // and this function would return
1345 // CXX_GCC_ROOT/lib/gcc/CXX_INCLUDE_ARCH/CXX_GCC_VER
1346 llvm::SmallString<128> CxxIncludeRoot(CXX_INCLUDE_ROOT);
1347 if (CxxIncludeRoot != "") {
1348 // This is of the form /foo/bar/include/c++/4.5.2/
1349 if (CxxIncludeRoot.back() == '/')
1350 llvm::sys::path::remove_filename(CxxIncludeRoot); // remove the /
1351 llvm::StringRef Version = llvm::sys::path::filename(CxxIncludeRoot);
1352 llvm::sys::path::remove_filename(CxxIncludeRoot); // remove the version
1353 llvm::sys::path::remove_filename(CxxIncludeRoot); // remove the c++
1354 llvm::sys::path::remove_filename(CxxIncludeRoot); // remove the include
1355 std::string ret(CxxIncludeRoot.c_str());
1356 ret.append("/lib/gcc/");
1357 ret.append(CXX_INCLUDE_ARCH);
1358 ret.append("/");
1359 ret.append(Version);
1360 return ret;
1361 }
1362 static const char* GccVersions[] = {"4.6.0", "4.6",
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001363 "4.5.2", "4.5.1", "4.5",
1364 "4.4.5", "4.4.4", "4.4.3", "4.4",
1365 "4.3.4", "4.3.3", "4.3.2", "4.3",
1366 "4.2.4", "4.2.3", "4.2.2", "4.2.1",
1367 "4.2", "4.1.1"};
Rafael Espindola14ea13c2011-06-02 22:18:46 +00001368 bool Exists;
1369 for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) {
1370 std::string Suffix = GccTriple + "/" + GccVersions[i];
1371 std::string t1 = "/usr/lib/gcc/" + Suffix;
1372 if (!llvm::sys::fs::exists(t1 + "/crtbegin.o", Exists) && Exists)
1373 return t1;
1374 std::string t2 = "/usr/lib64/gcc/" + Suffix;
1375 if (!llvm::sys::fs::exists(t2 + "/crtbegin.o", Exists) && Exists)
1376 return t2;
1377 std::string t3 = "/usr/lib/" + GccTriple + "/gcc/" + Suffix;
1378 if (!llvm::sys::fs::exists(t3 + "/crtbegin.o", Exists) && Exists)
1379 return t3;
1380 }
1381 return "";
1382}
1383
Nick Lewycky3fdcc6f2010-12-31 17:31:54 +00001384Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001385 : Generic_ELF(Host, Triple) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001386 llvm::Triple::ArchType Arch =
1387 llvm::Triple(getDriver().DefaultHostTriple).getArch();
Daniel Dunbara9822de2009-08-06 01:47:11 +00001388
Rafael Espindolac1da9812010-11-07 20:14:31 +00001389 std::string Suffix32 = "";
1390 if (Arch == llvm::Triple::x86_64)
1391 Suffix32 = "/32";
Daniel Dunbara9822de2009-08-06 01:47:11 +00001392
Rafael Espindolac1da9812010-11-07 20:14:31 +00001393 std::string Suffix64 = "";
Ted Kremenek43ac2972011-04-05 22:04:27 +00001394 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001395 Suffix64 = "/64";
1396
1397 std::string Lib32 = "lib";
1398
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001399 bool Exists;
1400 if (!llvm::sys::fs::exists("/lib32", Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001401 Lib32 = "lib32";
1402
1403 std::string Lib64 = "lib";
Michael J. Spencer2dea7c72011-01-12 23:54:48 +00001404 bool Symlink;
Chris Lattner48aef362011-01-13 01:35:58 +00001405 if (!llvm::sys::fs::exists("/lib64", Exists) && Exists &&
1406 (llvm::sys::fs::is_symlink("/lib64", Symlink) || !Symlink))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001407 Lib64 = "lib64";
1408
1409 std::string GccTriple = "";
Douglas Gregorf0594d82011-03-06 19:11:49 +00001410 if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001411 if (!llvm::sys::fs::exists("/usr/lib/gcc/arm-linux-gnueabi", Exists) &&
1412 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001413 GccTriple = "arm-linux-gnueabi";
1414 } else if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001415 if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-linux-gnu", Exists) &&
1416 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001417 GccTriple = "x86_64-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001418 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-unknown-linux-gnu",
1419 Exists) && Exists)
Rafael Espindola53dd00b2010-11-17 00:25:26 +00001420 GccTriple = "x86_64-unknown-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001421 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-pc-linux-gnu",
1422 Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001423 GccTriple = "x86_64-pc-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001424 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-redhat-linux",
1425 Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001426 GccTriple = "x86_64-redhat-linux";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001427 else if (!llvm::sys::fs::exists("/usr/lib64/gcc/x86_64-suse-linux",
1428 Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001429 GccTriple = "x86_64-suse-linux";
Nick Lewyckye10f9002011-02-01 23:03:29 +00001430 else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-manbo-linux-gnu",
1431 Exists) && Exists)
1432 GccTriple = "x86_64-manbo-linux-gnu";
Nico Weber80585d82011-04-25 03:17:35 +00001433 else if (!llvm::sys::fs::exists("/usr/lib/x86_64-linux-gnu/gcc",
1434 Exists) && Exists)
1435 GccTriple = "x86_64-linux-gnu";
Rafael Espindolac1da9812010-11-07 20:14:31 +00001436 } else if (Arch == llvm::Triple::x86) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001437 if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-linux-gnu", Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001438 GccTriple = "i686-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001439 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-pc-linux-gnu", Exists) &&
1440 Exists)
Nuno Lopes2a69ddd2010-11-19 17:26:57 +00001441 GccTriple = "i686-pc-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001442 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-linux-gnu", Exists) &&
1443 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001444 GccTriple = "i486-linux-gnu";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001445 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-redhat-linux", Exists) &&
1446 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001447 GccTriple = "i686-redhat-linux";
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001448 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i586-suse-linux", Exists) &&
1449 Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001450 GccTriple = "i586-suse-linux";
Ted Kremenekd130c7d2011-04-18 17:50:19 +00001451 else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-slackware-linux", Exists)
1452 && Exists)
1453 GccTriple = "i486-slackware-linux";
Ted Kremenek43ac2972011-04-05 22:04:27 +00001454 } else if (Arch == llvm::Triple::ppc) {
1455 if (!llvm::sys::fs::exists("/usr/lib/powerpc-linux-gnu", Exists) && Exists)
1456 GccTriple = "powerpc-linux-gnu";
Eric Christopher9af535a2011-06-03 13:28:31 +00001457 else if (!llvm::sys::fs::exists("/usr/lib/gcc/powerpc-unknown-linux-gnu",
1458 Exists) && Exists)
Ted Kremenek43ac2972011-04-05 22:04:27 +00001459 GccTriple = "powerpc-unknown-linux-gnu";
1460 } else if (Arch == llvm::Triple::ppc64) {
Eric Christopher9af535a2011-06-03 13:28:31 +00001461 if (!llvm::sys::fs::exists("/usr/lib/gcc/powerpc64-unknown-linux-gnu",
1462 Exists) && Exists)
Ted Kremenek43ac2972011-04-05 22:04:27 +00001463 GccTriple = "powerpc64-unknown-linux-gnu";
Eric Christopher9af535a2011-06-03 13:28:31 +00001464 else if (!llvm::sys::fs::exists("/usr/lib64/gcc/"
1465 "powerpc64-unknown-linux-gnu", Exists) &&
1466 Exists)
Ted Kremenek43ac2972011-04-05 22:04:27 +00001467 GccTriple = "powerpc64-unknown-linux-gnu";
Rafael Espindolac1da9812010-11-07 20:14:31 +00001468 }
1469
Rafael Espindola14ea13c2011-06-02 22:18:46 +00001470 std::string Base = findGCCBaseLibDir(GccTriple);
Rafael Espindolac1da9812010-11-07 20:14:31 +00001471 path_list &Paths = getFilePaths();
Eric Christopher9af535a2011-06-03 13:28:31 +00001472 bool Is32Bits = (getArch() == llvm::Triple::x86 ||
1473 getArch() == llvm::Triple::ppc);
Rafael Espindolac1da9812010-11-07 20:14:31 +00001474
1475 std::string Suffix;
1476 std::string Lib;
1477
1478 if (Is32Bits) {
1479 Suffix = Suffix32;
1480 Lib = Lib32;
1481 } else {
1482 Suffix = Suffix64;
1483 Lib = Lib64;
1484 }
1485
1486 llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld");
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001487 if (!llvm::sys::fs::exists(LinkerPath.str(), Exists) && Exists)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001488 Linker = LinkerPath.str();
1489 else
1490 Linker = GetProgramPath("ld");
1491
1492 LinuxDistro Distro = DetectLinuxDistro(Arch);
1493
Chris Lattner64a89172011-05-22 16:45:07 +00001494 if (IsOpenSuse(Distro) || IsUbuntu(Distro)) {
Rafael Espindola94c80222010-11-08 14:48:47 +00001495 ExtraOpts.push_back("-z");
1496 ExtraOpts.push_back("relro");
1497 }
Rafael Espindolac1da9812010-11-07 20:14:31 +00001498
Douglas Gregorf0594d82011-03-06 19:11:49 +00001499 if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001500 ExtraOpts.push_back("-X");
1501
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001502 if (IsRedhat(Distro) || IsOpenSuse(Distro) || Distro == UbuntuMaverick ||
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001503 Distro == UbuntuNatty || Distro == UbuntuOneiric)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001504 ExtraOpts.push_back("--hash-style=gnu");
1505
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001506 if (IsDebian(Distro) || IsOpenSuse(Distro) || Distro == UbuntuLucid ||
Chris Lattner64a89172011-05-22 16:45:07 +00001507 Distro == UbuntuJaunty || Distro == UbuntuKarmic)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001508 ExtraOpts.push_back("--hash-style=both");
1509
Chris Lattnerd753b562011-05-22 05:36:06 +00001510 if (IsRedhat(Distro))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001511 ExtraOpts.push_back("--no-add-needed");
1512
Eli Friedman0b200f62011-06-02 21:36:53 +00001513 if (Distro == DebianSqueeze || Distro == DebianWheezy ||
Rafael Espindola5a640ef2011-06-03 15:23:24 +00001514 IsOpenSuse(Distro) ||
1515 (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) ||
1516 Distro == UbuntuLucid ||
Eli Friedman0b200f62011-06-02 21:36:53 +00001517 Distro == UbuntuMaverick || Distro == UbuntuKarmic ||
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001518 Distro == UbuntuNatty || Distro == UbuntuOneiric)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001519 ExtraOpts.push_back("--build-id");
1520
Chris Lattner64a89172011-05-22 16:45:07 +00001521 if (IsOpenSuse(Distro))
Chandler Carruthf0b60ec2011-05-24 07:51:17 +00001522 ExtraOpts.push_back("--enable-new-dtags");
Chris Lattner64a89172011-05-22 16:45:07 +00001523
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001524 if (Distro == ArchLinux)
1525 Lib = "lib";
1526
Rafael Espindolac1da9812010-11-07 20:14:31 +00001527 Paths.push_back(Base + Suffix);
1528 if (HasMultilib(Arch, Distro)) {
1529 if (IsOpenSuse(Distro) && Is32Bits)
1530 Paths.push_back(Base + "/../../../../" + GccTriple + "/lib/../lib");
1531 Paths.push_back(Base + "/../../../../" + Lib);
Rafael Espindolac1da9812010-11-07 20:14:31 +00001532 }
Rafael Espindolac7409a02011-06-03 15:39:42 +00001533
1534 // FIXME: This is in here to find crt1.o. It is provided by libc, and
1535 // libc (like gcc), can be installed in any directory. Once we are
1536 // fetching this from a config file, we should have a libc prefix.
1537 Paths.push_back("/lib/../" + Lib);
1538 Paths.push_back("/usr/lib/../" + Lib);
1539
Rafael Espindolac1da9812010-11-07 20:14:31 +00001540 if (!Suffix.empty())
1541 Paths.push_back(Base);
1542 if (IsOpenSuse(Distro))
1543 Paths.push_back(Base + "/../../../../" + GccTriple + "/lib");
1544 Paths.push_back(Base + "/../../..");
1545 if (Arch == getArch() && IsUbuntu(Distro))
1546 Paths.push_back("/usr/lib/" + GccTriple);
1547}
1548
1549bool Linux::HasNativeLLVMSupport() const {
1550 return true;
Eli Friedman6b3454a2009-05-26 07:52:18 +00001551}
1552
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001553Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA,
1554 const ActionList &Inputs) const {
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001555 Action::ActionClass Key;
1556 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1557 Key = Action::AnalyzeJobClass;
1558 else
1559 Key = JA.getKind();
1560
Rafael Espindoladda5b922010-11-07 23:13:01 +00001561 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1562 options::OPT_no_integrated_as,
1563 IsIntegratedAssemblerDefault());
1564
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001565 Tool *&T = Tools[Key];
1566 if (!T) {
1567 switch (Key) {
1568 case Action::AssembleJobClass:
Rafael Espindoladda5b922010-11-07 23:13:01 +00001569 if (UseIntegratedAs)
1570 T = new tools::ClangAs(*this);
1571 else
1572 T = new tools::linuxtools::Assemble(*this);
1573 break;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001574 case Action::LinkJobClass:
1575 T = new tools::linuxtools::Link(*this); break;
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001576 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001577 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001578 }
1579 }
1580
1581 return *T;
1582}
1583
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001584/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
1585
Daniel Dunbarcb8ab232009-05-22 02:53:45 +00001586DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001587 : Generic_ELF(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001588
1589 // Path mangling to find libexec
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001590 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +00001591 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001592 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001593
Daniel Dunbaree788e72009-12-21 18:54:17 +00001594 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001595 getFilePaths().push_back("/usr/lib");
1596 getFilePaths().push_back("/usr/lib/gcc41");
1597}
1598
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001599Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA,
1600 const ActionList &Inputs) const {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001601 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001602 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001603 Key = Action::AnalyzeJobClass;
1604 else
1605 Key = JA.getKind();
1606
1607 Tool *&T = Tools[Key];
1608 if (!T) {
1609 switch (Key) {
1610 case Action::AssembleJobClass:
1611 T = new tools::dragonfly::Assemble(*this); break;
1612 case Action::LinkJobClass:
1613 T = new tools::dragonfly::Link(*this); break;
1614 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001615 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001616 }
1617 }
1618
1619 return *T;
1620}
Michael J. Spencerff58e362010-08-21 21:55:07 +00001621
1622Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple)
1623 : ToolChain(Host, Triple) {
1624}
1625
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001626Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA,
1627 const ActionList &Inputs) const {
Michael J. Spencerff58e362010-08-21 21:55:07 +00001628 Action::ActionClass Key;
1629 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1630 Key = Action::AnalyzeJobClass;
1631 else
1632 Key = JA.getKind();
1633
1634 Tool *&T = Tools[Key];
1635 if (!T) {
1636 switch (Key) {
1637 case Action::InputClass:
1638 case Action::BindArchClass:
Chandler Carruthe97673f2010-08-22 06:56:37 +00001639 case Action::LipoJobClass:
1640 case Action::DsymutilJobClass:
Michael J. Spencerff58e362010-08-21 21:55:07 +00001641 assert(0 && "Invalid tool kind.");
1642 case Action::PreprocessJobClass:
1643 case Action::PrecompileJobClass:
1644 case Action::AnalyzeJobClass:
1645 case Action::CompileJobClass:
1646 T = new tools::Clang(*this); break;
1647 case Action::AssembleJobClass:
1648 T = new tools::ClangAs(*this); break;
1649 case Action::LinkJobClass:
1650 T = new tools::visualstudio::Link(*this); break;
1651 }
1652 }
1653
1654 return *T;
1655}
1656
1657bool Windows::IsIntegratedAssemblerDefault() const {
1658 return true;
1659}
1660
1661bool Windows::IsUnwindTablesDefault() const {
1662 // FIXME: Gross; we should probably have some separate target
1663 // definition, possibly even reusing the one in clang.
1664 return getArchName() == "x86_64";
1665}
1666
1667const char *Windows::GetDefaultRelocationModel() const {
1668 return "static";
1669}
1670
1671const char *Windows::GetForcedPicModel() const {
1672 if (getArchName() == "x86_64")
1673 return "pic";
1674 return 0;
1675}