blob: 9e34b0288cddc57bab198359b3640acc67654736 [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"
John McCall9f084a32011-07-06 00:26:06 +000022#include "clang/Driver/ObjCRuntime.h"
Daniel Dunbar27e738d2009-11-19 00:15:11 +000023#include "clang/Driver/OptTable.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000024#include "clang/Driver/Option.h"
Daniel Dunbar265e9ef2009-11-19 04:25:22 +000025#include "clang/Driver/Options.h"
Douglas Gregor34916db2010-09-03 17:16:03 +000026#include "clang/Basic/Version.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000027
Daniel Dunbar00577ad2010-08-23 22:35:37 +000028#include "llvm/ADT/SmallString.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000029#include "llvm/ADT/StringExtras.h"
Bob Wilsona59956b2011-10-07 00:37:57 +000030#include "llvm/ADT/StringSwitch.h"
John McCallf85e1932011-06-15 23:02:42 +000031#include "llvm/ADT/STLExtras.h"
Daniel Dunbar84ec96c2009-09-09 22:33:15 +000032#include "llvm/Support/ErrorHandling.h"
Michael J. Spencer32bef4e2011-01-10 02:34:13 +000033#include "llvm/Support/FileSystem.h"
Rafael Espindolac1da9812010-11-07 20:14:31 +000034#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000035#include "llvm/Support/raw_ostream.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000036#include "llvm/Support/Path.h"
Michael J. Spencer3a321e22010-12-09 17:36:38 +000037#include "llvm/Support/system_error.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000038
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000039#include <cstdlib> // ::getenv
40
Dylan Noblesmith89bb6142011-06-23 13:50:47 +000041#include "llvm/Config/config.h" // for CXX_INCLUDE_ROOT
42
Chandler Carruthca234192011-11-04 23:49:05 +000043// Include the necessary headers to interface with the Windows registry and
44// environment.
45#ifdef _MSC_VER
46 #define WIN32_LEAN_AND_MEAN 1
47 #include <windows.h>
48#endif
49
Daniel Dunbar39176082009-03-20 00:20:03 +000050using namespace clang::driver;
51using namespace clang::driver::toolchains;
Chris Lattner5f9e2722011-07-23 10:55:15 +000052using namespace clang;
Daniel Dunbar39176082009-03-20 00:20:03 +000053
Daniel Dunbarf3955282009-09-04 18:34:51 +000054/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000055
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000056Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple)
John McCallf85e1932011-06-15 23:02:42 +000057 : ToolChain(Host, Triple), TargetInitialized(false),
Bob Wilson163b1512011-10-07 17:54:41 +000058 ARCRuntimeForSimulator(ARCSimulator_None),
59 LibCXXForSimulator(LibCXXSimulator_None)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000060{
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000061 // Compute the initial Darwin version based on the host.
62 bool HadExtra;
63 std::string OSName = Triple.getOSName();
Daniel Dunbar34f9e292011-02-25 21:20:15 +000064 if (!Driver::GetReleaseVersion(&OSName.c_str()[6],
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000065 DarwinVersion[0], DarwinVersion[1],
66 DarwinVersion[2], HadExtra))
Chris Lattner5f9e2722011-07-23 10:55:15 +000067 getDriver().Diag(diag::err_drv_invalid_darwin_version) << OSName;
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000068
Daniel Dunbar02633b52009-03-26 16:23:12 +000069 llvm::raw_string_ostream(MacosxVersionMin)
Daniel Dunbar25b58eb2010-08-02 05:44:07 +000070 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.'
71 << DarwinVersion[1];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000072}
73
Daniel Dunbar41800112010-08-02 05:43:56 +000074types::ID Darwin::LookupTypeForExtension(const char *Ext) const {
75 types::ID Ty = types::lookupTypeForExtension(Ext);
76
77 // Darwin always preprocesses assembly files (unless -x is used explicitly).
78 if (Ty == types::TY_PP_Asm)
79 return types::TY_Asm;
80
81 return Ty;
82}
83
Daniel Dunbarb993f5d2010-09-17 00:24:52 +000084bool Darwin::HasNativeLLVMSupport() const {
85 return true;
86}
87
John McCall9f084a32011-07-06 00:26:06 +000088bool Darwin::hasARCRuntime() const {
John McCallf85e1932011-06-15 23:02:42 +000089 // FIXME: Remove this once there is a proper way to detect an ARC runtime
90 // for the simulator.
91 switch (ARCRuntimeForSimulator) {
92 case ARCSimulator_None:
93 break;
94 case ARCSimulator_HasARCRuntime:
95 return true;
96 case ARCSimulator_NoARCRuntime:
97 return false;
98 }
99
100 if (isTargetIPhoneOS())
101 return !isIPhoneOSVersionLT(5);
102 else
103 return !isMacosxVersionLT(10, 7);
104}
105
John McCall9f084a32011-07-06 00:26:06 +0000106/// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0.
107void Darwin::configureObjCRuntime(ObjCRuntime &runtime) const {
108 if (runtime.getKind() != ObjCRuntime::NeXT)
109 return ToolChain::configureObjCRuntime(runtime);
110
111 runtime.HasARC = runtime.HasWeak = hasARCRuntime();
John McCall256a76e2011-07-06 01:22:26 +0000112
113 // So far, objc_terminate is only available in iOS 5.
114 // FIXME: do the simulator logic properly.
115 if (!ARCRuntimeForSimulator && isTargetIPhoneOS())
116 runtime.HasTerminate = !isIPhoneOSVersionLT(5);
117 else
118 runtime.HasTerminate = false;
John McCall9f084a32011-07-06 00:26:06 +0000119}
120
John McCall13db5cf2011-09-09 20:41:01 +0000121/// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2.
122bool Darwin::hasBlocksRuntime() const {
123 if (isTargetIPhoneOS())
124 return !isIPhoneOSVersionLT(3, 2);
125 else
126 return !isMacosxVersionLT(10, 6);
127}
128
Chris Lattner5f9e2722011-07-23 10:55:15 +0000129static const char *GetArmArchForMArch(StringRef Value) {
Bob Wilsona59956b2011-10-07 00:37:57 +0000130 return llvm::StringSwitch<const char*>(Value)
131 .Case("armv6k", "armv6")
132 .Case("armv5tej", "armv5")
133 .Case("xscale", "xscale")
134 .Case("armv4t", "armv4t")
135 .Case("armv7", "armv7")
136 .Cases("armv7a", "armv7-a", "armv7")
137 .Cases("armv7r", "armv7-r", "armv7")
138 .Cases("armv7m", "armv7-m", "armv7")
139 .Default(0);
Daniel Dunbareeff4062010-01-22 02:04:58 +0000140}
141
Chris Lattner5f9e2722011-07-23 10:55:15 +0000142static const char *GetArmArchForMCpu(StringRef Value) {
Bob Wilsona59956b2011-10-07 00:37:57 +0000143 return llvm::StringSwitch<const char *>(Value)
144 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "arm926ej-s","armv5")
145 .Cases("arm10e", "arm10tdmi", "armv5")
146 .Cases("arm1020t", "arm1020e", "arm1022e", "arm1026ej-s", "armv5")
147 .Case("xscale", "xscale")
148 .Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s",
149 "arm1176jzf-s", "cortex-m0", "armv6")
150 .Cases("cortex-a8", "cortex-r4", "cortex-m3", "cortex-a9", "armv7")
151 .Default(0);
Daniel Dunbareeff4062010-01-22 02:04:58 +0000152}
153
Chris Lattner5f9e2722011-07-23 10:55:15 +0000154StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
Daniel Dunbareeff4062010-01-22 02:04:58 +0000155 switch (getTriple().getArch()) {
156 default:
157 return getArchName();
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000158
Douglas Gregorf0594d82011-03-06 19:11:49 +0000159 case llvm::Triple::thumb:
Daniel Dunbareeff4062010-01-22 02:04:58 +0000160 case llvm::Triple::arm: {
161 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
162 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
163 return Arch;
164
165 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
166 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
167 return Arch;
168
169 return "arm";
170 }
171 }
172}
173
Daniel Dunbarf3955282009-09-04 18:34:51 +0000174Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000175 // Free tool implementations.
176 for (llvm::DenseMap<unsigned, Tool*>::iterator
177 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
178 delete it->second;
179}
180
Chad Rosier61ab80a2011-09-20 20:44:06 +0000181std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args,
182 types::ID InputType) const {
183 llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000184
185 // If the target isn't initialized (e.g., an unknown Darwin platform, return
186 // the default triple).
187 if (!isTargetInitialized())
188 return Triple.getTriple();
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000189
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000190 unsigned Version[3];
191 getTargetVersion(Version);
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000192
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000193 llvm::SmallString<16> Str;
Daniel Dunbar729f38e2011-04-19 21:45:47 +0000194 llvm::raw_svector_ostream(Str)
Daniel Dunbar659d23a2011-04-19 23:34:17 +0000195 << (isTargetIPhoneOS() ? "ios" : "macosx")
Daniel Dunbar729f38e2011-04-19 21:45:47 +0000196 << Version[0] << "." << Version[1] << "." << Version[2];
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000197 Triple.setOSName(Str.str());
198
199 return Triple.getTriple();
200}
201
Daniel Dunbarac0659a2011-03-18 20:14:00 +0000202Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA,
203 const ActionList &Inputs) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000204 Action::ActionClass Key;
Daniel Dunbar5ce872f2011-03-18 20:14:03 +0000205
206 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) {
207 // Fallback to llvm-gcc for i386 kext compiles, we don't support that ABI.
208 if (Inputs.size() == 1 &&
209 types::isCXX(Inputs[0]->getType()) &&
Bob Wilson905c45f2011-10-14 05:03:44 +0000210 getTriple().isOSDarwin() &&
Daniel Dunbar5ce872f2011-03-18 20:14:03 +0000211 getTriple().getArch() == llvm::Triple::x86 &&
Bob Wilsona544aee2011-08-13 23:48:55 +0000212 (C.getArgs().getLastArg(options::OPT_fapple_kext) ||
213 C.getArgs().getLastArg(options::OPT_mkernel)))
Daniel Dunbar5ce872f2011-03-18 20:14:03 +0000214 Key = JA.getKind();
215 else
216 Key = Action::AnalyzeJobClass;
217 } else
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000218 Key = JA.getKind();
219
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000220 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
221 options::OPT_no_integrated_as,
Bob Wilson1a1764b2011-10-30 00:20:28 +0000222 IsIntegratedAssemblerDefault());
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000223
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000224 Tool *&T = Tools[Key];
225 if (!T) {
226 switch (Key) {
227 case Action::InputClass:
228 case Action::BindArchClass:
David Blaikieb219cfc2011-09-23 05:06:16 +0000229 llvm_unreachable("Invalid tool kind.");
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000230 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000231 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000232 case Action::AnalyzeJobClass:
233 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000234 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000235 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000236 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar0f602de2010-05-20 21:48:38 +0000237 case Action::AssembleJobClass: {
238 if (UseIntegratedAs)
239 T = new tools::ClangAs(*this);
240 else
241 T = new tools::darwin::Assemble(*this);
242 break;
243 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000244 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000245 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000246 case Action::LipoJobClass:
247 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +0000248 case Action::DsymutilJobClass:
249 T = new tools::darwin::Dsymutil(*this); break;
Eric Christopherf8571862011-08-23 17:56:55 +0000250 case Action::VerifyJobClass:
251 T = new tools::darwin::VerifyDebug(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000252 }
253 }
254
255 return *T;
256}
257
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000258
Daniel Dunbar25b58eb2010-08-02 05:44:07 +0000259DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple)
260 : Darwin(Host, Triple)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000261{
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000262 getProgramPaths().push_back(getDriver().getInstalledDir());
263 if (getDriver().getInstalledDir() != getDriver().Dir)
264 getProgramPaths().push_back(getDriver().Dir);
265
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000266 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000267 getProgramPaths().push_back(getDriver().getInstalledDir());
268 if (getDriver().getInstalledDir() != getDriver().Dir)
269 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000270
271 // For fallback, we need to know how to find the GCC cc1 executables, so we
Daniel Dunbar47023092011-03-18 19:25:15 +0000272 // also add the GCC libexec paths. This is legacy code that can be removed
273 // once fallback is no longer useful.
Bob Wilson8aa76ea2011-09-20 22:00:38 +0000274 AddGCCLibexecPath(DarwinVersion[0]);
275 AddGCCLibexecPath(DarwinVersion[0] - 2);
276 AddGCCLibexecPath(DarwinVersion[0] - 1);
277 AddGCCLibexecPath(DarwinVersion[0] + 1);
278 AddGCCLibexecPath(DarwinVersion[0] + 2);
279}
280
281void DarwinClang::AddGCCLibexecPath(unsigned darwinVersion) {
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000282 std::string ToolChainDir = "i686-apple-darwin";
Bob Wilson8aa76ea2011-09-20 22:00:38 +0000283 ToolChainDir += llvm::utostr(darwinVersion);
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000284 ToolChainDir += "/4.2.1";
285
286 std::string Path = getDriver().Dir;
Bob Wilson8aa76ea2011-09-20 22:00:38 +0000287 Path += "/../llvm-gcc-4.2/libexec/gcc/";
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000288 Path += ToolChainDir;
289 getProgramPaths().push_back(Path);
290
Bob Wilson8aa76ea2011-09-20 22:00:38 +0000291 Path = "/usr/llvm-gcc-4.2/libexec/gcc/";
Daniel Dunbar0e50ee42010-09-17 08:22:12 +0000292 Path += ToolChainDir;
293 getProgramPaths().push_back(Path);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000294}
295
296void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
297 ArgStringList &CmdArgs) const {
298 // The Clang toolchain uses explicit paths for internal libraries.
Daniel Dunbar424b6612010-06-30 23:56:13 +0000299
300 // Unfortunately, we still might depend on a few of the libraries that are
301 // only available in the gcc library directory (in particular
302 // libstdc++.dylib). For now, hardcode the path to the known install location.
303 llvm::sys::Path P(getDriver().Dir);
304 P.eraseComponent(); // .../usr/bin -> ../usr
305 P.appendComponent("lib");
306 P.appendComponent("gcc");
307 switch (getTriple().getArch()) {
308 default:
David Blaikieb219cfc2011-09-23 05:06:16 +0000309 llvm_unreachable("Invalid Darwin arch!");
Daniel Dunbar424b6612010-06-30 23:56:13 +0000310 case llvm::Triple::x86:
311 case llvm::Triple::x86_64:
312 P.appendComponent("i686-apple-darwin10");
313 break;
314 case llvm::Triple::arm:
315 case llvm::Triple::thumb:
316 P.appendComponent("arm-apple-darwin10");
317 break;
318 case llvm::Triple::ppc:
319 case llvm::Triple::ppc64:
320 P.appendComponent("powerpc-apple-darwin10");
321 break;
322 }
323 P.appendComponent("4.2.1");
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000324
325 // Determine the arch specific GCC subdirectory.
326 const char *ArchSpecificDir = 0;
327 switch (getTriple().getArch()) {
328 default:
329 break;
330 case llvm::Triple::arm:
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000331 case llvm::Triple::thumb: {
332 std::string Triple = ComputeLLVMTriple(Args);
Chris Lattner5f9e2722011-07-23 10:55:15 +0000333 StringRef TripleStr = Triple;
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000334 if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5"))
335 ArchSpecificDir = "v5";
336 else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6"))
337 ArchSpecificDir = "v6";
338 else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7"))
339 ArchSpecificDir = "v7";
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000340 break;
Daniel Dunbar3a0e3922010-08-26 00:55:52 +0000341 }
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000342 case llvm::Triple::ppc64:
343 ArchSpecificDir = "ppc64";
344 break;
345 case llvm::Triple::x86_64:
346 ArchSpecificDir = "x86_64";
347 break;
348 }
349
350 if (ArchSpecificDir) {
351 P.appendComponent(ArchSpecificDir);
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000352 bool Exists;
353 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbareab3bc42010-08-23 20:58:52 +0000354 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
355 P.eraseComponent();
356 }
357
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000358 bool Exists;
359 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Daniel Dunbar424b6612010-06-30 23:56:13 +0000360 CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000361}
362
John McCallf85e1932011-06-15 23:02:42 +0000363void DarwinClang::AddLinkARCArgs(const ArgList &Args,
364 ArgStringList &CmdArgs) const {
Eric Christopherf8571862011-08-23 17:56:55 +0000365
366 CmdArgs.push_back("-force_load");
John McCallf85e1932011-06-15 23:02:42 +0000367 llvm::sys::Path P(getDriver().ClangExecutable);
368 P.eraseComponent(); // 'clang'
369 P.eraseComponent(); // 'bin'
370 P.appendComponent("lib");
371 P.appendComponent("arc");
372 P.appendComponent("libarclite_");
373 std::string s = P.str();
374 // Mash in the platform.
Argyrios Kyrtzidisc19981c2011-10-18 17:40:15 +0000375 if (isTargetIOSSimulator())
376 s += "iphonesimulator";
377 else if (isTargetIPhoneOS())
John McCallf85e1932011-06-15 23:02:42 +0000378 s += "iphoneos";
Argyrios Kyrtzidisc19981c2011-10-18 17:40:15 +0000379 // FIXME: Remove this once we depend fully on -mios-simulator-version-min.
John McCallf85e1932011-06-15 23:02:42 +0000380 else if (ARCRuntimeForSimulator != ARCSimulator_None)
381 s += "iphonesimulator";
382 else
383 s += "macosx";
384 s += ".a";
385
386 CmdArgs.push_back(Args.MakeArgString(s));
387}
388
Eric Christopher3404fe72011-06-22 17:41:40 +0000389void DarwinClang::AddLinkRuntimeLib(const ArgList &Args,
Eric Christopherf8571862011-08-23 17:56:55 +0000390 ArgStringList &CmdArgs,
Eric Christopher3404fe72011-06-22 17:41:40 +0000391 const char *DarwinStaticLib) const {
392 llvm::sys::Path P(getDriver().ResourceDir);
393 P.appendComponent("lib");
394 P.appendComponent("darwin");
395 P.appendComponent(DarwinStaticLib);
Eric Christopherf8571862011-08-23 17:56:55 +0000396
Eric Christopher3404fe72011-06-22 17:41:40 +0000397 // For now, allow missing resource libraries to support developers who may
398 // not have compiler-rt checked out or integrated into their build.
399 bool Exists;
400 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
401 CmdArgs.push_back(Args.MakeArgString(P.str()));
402}
403
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000404void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
405 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000406 // Darwin doesn't support real static executables, don't link any runtime
407 // libraries with -static.
408 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000409 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000410
411 // Reject -static-libgcc for now, we can deal with this when and if someone
412 // cares. This is useful in situations where someone wants to statically link
413 // something like libstdc++, and needs its runtime support routines.
414 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000415 getDriver().Diag(diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000416 << A->getAsString(Args);
417 return;
418 }
419
Daniel Dunbareec99102010-01-22 03:38:14 +0000420 // Otherwise link libSystem, then the dynamic runtime library, and finally any
421 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000422 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000423
424 // Select the dynamic runtime library and the target specific static library.
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000425 if (isTargetIPhoneOS()) {
Daniel Dunbar87e945f2011-04-30 04:25:16 +0000426 // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
427 // it never went into the SDK.
Bob Wilson163b1512011-10-07 17:54:41 +0000428 // Linking against libgcc_s.1 isn't needed for iOS 5.0+
429 if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator())
430 CmdArgs.push_back("-lgcc_s.1");
Daniel Dunbareec99102010-01-22 03:38:14 +0000431
Daniel Dunbar3cceec52011-04-18 23:48:36 +0000432 // We currently always need a static runtime library for iOS.
Eric Christopher3404fe72011-06-22 17:41:40 +0000433 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a");
Daniel Dunbareec99102010-01-22 03:38:14 +0000434 } else {
Daniel Dunbareec99102010-01-22 03:38:14 +0000435 // The dynamic runtime library was merged with libSystem for 10.6 and
436 // beyond; only 10.4 and 10.5 need an additional runtime library.
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000437 if (isMacosxVersionLT(10, 5))
Daniel Dunbareec99102010-01-22 03:38:14 +0000438 CmdArgs.push_back("-lgcc_s.10.4");
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000439 else if (isMacosxVersionLT(10, 6))
Daniel Dunbareec99102010-01-22 03:38:14 +0000440 CmdArgs.push_back("-lgcc_s.10.5");
441
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000442 // For OS X, we thought we would only need a static runtime library when
Chris Lattnerfc8f0e12011-04-15 05:22:18 +0000443 // targeting 10.4, to provide versions of the static functions which were
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000444 // omitted from 10.4.dylib.
445 //
446 // Unfortunately, that turned out to not be true, because Darwin system
447 // headers can still use eprintf on i386, and it is not exported from
448 // libSystem. Therefore, we still must provide a runtime library just for
449 // the tiny tiny handful of projects that *might* use that symbol.
450 if (isMacosxVersionLT(10, 5)) {
Eric Christopher3404fe72011-06-22 17:41:40 +0000451 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a");
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000452 } else {
453 if (getTriple().getArch() == llvm::Triple::x86)
Eric Christopher3404fe72011-06-22 17:41:40 +0000454 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a");
455 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a");
Daniel Dunbar885b1db2010-09-22 00:03:52 +0000456 }
Daniel Dunbareec99102010-01-22 03:38:14 +0000457 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000458}
459
Argyrios Kyrtzidisdceb11f2011-10-18 00:22:49 +0000460static inline StringRef SimulatorVersionDefineName() {
461 return "__IPHONE_OS_VERSION_MIN_REQUIRED";
462}
463
464/// \brief Parse the simulator version define:
465/// __IPHONE_OS_VERSION_MIN_REQUIRED=([0-9])([0-9][0-9])([0-9][0-9])
466// and return the grouped values as integers, e.g:
467// __IPHONE_OS_VERSION_MIN_REQUIRED=40201
468// will return Major=4, Minor=2, Micro=1.
469static bool GetVersionFromSimulatorDefine(StringRef define,
470 unsigned &Major, unsigned &Minor,
471 unsigned &Micro) {
472 assert(define.startswith(SimulatorVersionDefineName()));
473 StringRef name, version;
474 llvm::tie(name, version) = define.split('=');
475 if (version.empty())
476 return false;
477 std::string verstr = version.str();
478 char *end;
479 unsigned num = (unsigned) strtol(verstr.c_str(), &end, 10);
480 if (*end != '\0')
481 return false;
482 Major = num / 10000;
483 num = num % 10000;
484 Minor = num / 100;
485 Micro = num % 100;
486 return true;
487}
488
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000489void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000490 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000491
Daniel Dunbar26031372010-01-27 00:56:25 +0000492 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000493 Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
494 Arg *iOSSimVersion = Args.getLastArg(
495 options::OPT_mios_simulator_version_min_EQ);
John McCallf85e1932011-06-15 23:02:42 +0000496
Argyrios Kyrtzidisdceb11f2011-10-18 00:22:49 +0000497 // FIXME: HACK! When compiling for the simulator we don't get a
498 // '-miphoneos-version-min' to help us know whether there is an ARC runtime
499 // or not; try to parse a __IPHONE_OS_VERSION_MIN_REQUIRED
500 // define passed in command-line.
Argyrios Kyrtzidisc19981c2011-10-18 17:40:15 +0000501 if (!iOSVersion && !iOSSimVersion) {
Argyrios Kyrtzidisdceb11f2011-10-18 00:22:49 +0000502 for (arg_iterator it = Args.filtered_begin(options::OPT_D),
503 ie = Args.filtered_end(); it != ie; ++it) {
504 StringRef define = (*it)->getValue(Args);
505 if (define.startswith(SimulatorVersionDefineName())) {
506 unsigned Major = 0, Minor = 0, Micro = 0;
507 if (GetVersionFromSimulatorDefine(define, Major, Minor, Micro) &&
508 Major < 10 && Minor < 100 && Micro < 100) {
509 ARCRuntimeForSimulator = Major < 5 ? ARCSimulator_NoARCRuntime
510 : ARCSimulator_HasARCRuntime;
511 LibCXXForSimulator = Major < 5 ? LibCXXSimulator_NotAvailable
512 : LibCXXSimulator_Available;
513 }
514 break;
515 }
516 }
517 }
518
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000519 if (OSXVersion && (iOSVersion || iOSSimVersion)) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000520 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000521 << OSXVersion->getAsString(Args)
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000522 << (iOSVersion ? iOSVersion : iOSSimVersion)->getAsString(Args);
523 iOSVersion = iOSSimVersion = 0;
524 } else if (iOSVersion && iOSSimVersion) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000525 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000526 << iOSVersion->getAsString(Args)
527 << iOSSimVersion->getAsString(Args);
528 iOSSimVersion = 0;
529 } else if (!OSXVersion && !iOSVersion && !iOSSimVersion) {
Chad Rosiera4884972011-08-31 20:56:25 +0000530 // If no deployment target was specified on the command line, check for
Daniel Dunbar816bc312010-01-26 01:45:19 +0000531 // environment defines.
Chad Rosiera4884972011-08-31 20:56:25 +0000532 StringRef OSXTarget;
533 StringRef iOSTarget;
534 StringRef iOSSimTarget;
535 if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET"))
536 OSXTarget = env;
537 if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET"))
538 iOSTarget = env;
539 if (char *env = ::getenv("IOS_SIMULATOR_DEPLOYMENT_TARGET"))
540 iOSSimTarget = env;
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000541
NAKAMURA Takumia789ca92011-10-08 11:31:46 +0000542 // If no '-miphoneos-version-min' specified on the command line and
Chad Rosiera4884972011-08-31 20:56:25 +0000543 // IPHONEOS_DEPLOYMENT_TARGET is not defined, see if we can set the default
544 // based on isysroot.
545 if (iOSTarget.empty()) {
546 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
547 StringRef first, second;
548 StringRef isysroot = A->getValue(Args);
549 llvm::tie(first, second) = isysroot.split(StringRef("SDKs/iPhoneOS"));
550 if (second != "")
551 iOSTarget = second.substr(0,3);
552 }
553 }
Daniel Dunbar816bc312010-01-26 01:45:19 +0000554
Chad Rosier4f8de272011-09-28 00:46:32 +0000555 // If no OSX or iOS target has been specified and we're compiling for armv7,
556 // go ahead as assume we're targeting iOS.
557 if (OSXTarget.empty() && iOSTarget.empty())
558 if (getDarwinArchName(Args) == "armv7")
559 iOSTarget = "0.0";
560
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000561 // Handle conflicting deployment targets
Daniel Dunbar39053672010-02-02 17:31:12 +0000562 //
563 // FIXME: Don't hardcode default here.
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000564
565 // Do not allow conflicts with the iOS simulator target.
Chad Rosiera4884972011-08-31 20:56:25 +0000566 if (!iOSSimTarget.empty() && (!OSXTarget.empty() || !iOSTarget.empty())) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000567 getDriver().Diag(diag::err_drv_conflicting_deployment_targets)
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000568 << "IOS_SIMULATOR_DEPLOYMENT_TARGET"
Chad Rosiera4884972011-08-31 20:56:25 +0000569 << (!OSXTarget.empty() ? "MACOSX_DEPLOYMENT_TARGET" :
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000570 "IPHONEOS_DEPLOYMENT_TARGET");
571 }
572
573 // Allow conflicts among OSX and iOS for historical reasons, but choose the
574 // default platform.
Chad Rosiera4884972011-08-31 20:56:25 +0000575 if (!OSXTarget.empty() && !iOSTarget.empty()) {
Daniel Dunbar39053672010-02-02 17:31:12 +0000576 if (getTriple().getArch() == llvm::Triple::arm ||
577 getTriple().getArch() == llvm::Triple::thumb)
Chad Rosiera4884972011-08-31 20:56:25 +0000578 OSXTarget = "";
Daniel Dunbar39053672010-02-02 17:31:12 +0000579 else
Chad Rosiera4884972011-08-31 20:56:25 +0000580 iOSTarget = "";
Daniel Dunbar39053672010-02-02 17:31:12 +0000581 }
Daniel Dunbar1a3c1d92010-01-29 17:02:25 +0000582
Chad Rosiera4884972011-08-31 20:56:25 +0000583 if (!OSXTarget.empty()) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000584 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000585 OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget);
586 Args.append(OSXVersion);
Chad Rosiera4884972011-08-31 20:56:25 +0000587 } else if (!iOSTarget.empty()) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000588 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000589 iOSVersion = Args.MakeJoinedArg(0, O, iOSTarget);
590 Args.append(iOSVersion);
Chad Rosiera4884972011-08-31 20:56:25 +0000591 } else if (!iOSSimTarget.empty()) {
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000592 const Option *O = Opts.getOption(
593 options::OPT_mios_simulator_version_min_EQ);
594 iOSSimVersion = Args.MakeJoinedArg(0, O, iOSSimTarget);
595 Args.append(iOSSimVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000596 } else {
Daniel Dunbar2bb38d02010-07-15 16:18:06 +0000597 // Otherwise, assume we are targeting OS X.
598 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000599 OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin);
600 Args.append(OSXVersion);
Daniel Dunbar30392de2009-09-04 18:35:21 +0000601 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000602 }
Mike Stump1eb44332009-09-09 15:08:12 +0000603
Daniel Dunbar3fd823b2011-04-30 04:20:40 +0000604 // Reject invalid architecture combinations.
605 if (iOSSimVersion && (getTriple().getArch() != llvm::Triple::x86 &&
606 getTriple().getArch() != llvm::Triple::x86_64)) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000607 getDriver().Diag(diag::err_drv_invalid_arch_for_deployment_target)
Daniel Dunbar3fd823b2011-04-30 04:20:40 +0000608 << getTriple().getArchName() << iOSSimVersion->getAsString(Args);
609 }
610
Daniel Dunbar26031372010-01-27 00:56:25 +0000611 // Set the tool chain target information.
612 unsigned Major, Minor, Micro;
613 bool HadExtra;
614 if (OSXVersion) {
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000615 assert((!iOSVersion && !iOSSimVersion) && "Unknown target platform!");
Daniel Dunbar26031372010-01-27 00:56:25 +0000616 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
617 Micro, HadExtra) || HadExtra ||
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000618 Major != 10 || Minor >= 100 || Micro >= 100)
Chris Lattner5f9e2722011-07-23 10:55:15 +0000619 getDriver().Diag(diag::err_drv_invalid_version_number)
Daniel Dunbar26031372010-01-27 00:56:25 +0000620 << OSXVersion->getAsString(Args);
621 } else {
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000622 const Arg *Version = iOSVersion ? iOSVersion : iOSSimVersion;
623 assert(Version && "Unknown target platform!");
624 if (!Driver::GetReleaseVersion(Version->getValue(Args), Major, Minor,
Daniel Dunbar26031372010-01-27 00:56:25 +0000625 Micro, HadExtra) || HadExtra ||
626 Major >= 10 || Minor >= 100 || Micro >= 100)
Chris Lattner5f9e2722011-07-23 10:55:15 +0000627 getDriver().Diag(diag::err_drv_invalid_version_number)
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000628 << Version->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000629 }
Daniel Dunbar9d609f22011-04-30 04:15:58 +0000630
Daniel Dunbar5f5c37b2011-04-30 04:18:16 +0000631 bool IsIOSSim = bool(iOSSimVersion);
632
633 // In GCC, the simulator historically was treated as being OS X in some
634 // contexts, like determining the link logic, despite generally being called
635 // with an iOS deployment target. For compatibility, we detect the
636 // simulator as iOS + x86, and treat it differently in a few contexts.
637 if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 ||
638 getTriple().getArch() == llvm::Triple::x86_64))
639 IsIOSSim = true;
640
641 setTarget(/*IsIPhoneOS=*/ !OSXVersion, Major, Minor, Micro, IsIOSSim);
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000642}
643
Daniel Dunbar132e35d2010-09-17 01:20:05 +0000644void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args,
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000645 ArgStringList &CmdArgs) const {
646 CXXStdlibType Type = GetCXXStdlibType(Args);
647
648 switch (Type) {
649 case ToolChain::CST_Libcxx:
650 CmdArgs.push_back("-lc++");
651 break;
652
653 case ToolChain::CST_Libstdcxx: {
654 // Unfortunately, -lstdc++ doesn't always exist in the standard search path;
655 // it was previously found in the gcc lib dir. However, for all the Darwin
656 // platforms we care about it was -lstdc++.6, so we search for that
657 // explicitly if we can't see an obvious -lstdc++ candidate.
658
659 // Check in the sysroot first.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000660 bool Exists;
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000661 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
662 llvm::sys::Path P(A->getValue(Args));
663 P.appendComponent("usr");
664 P.appendComponent("lib");
665 P.appendComponent("libstdc++.dylib");
666
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000667 if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) {
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000668 P.eraseComponent();
669 P.appendComponent("libstdc++.6.dylib");
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000670 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) {
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000671 CmdArgs.push_back(Args.MakeArgString(P.str()));
672 return;
673 }
674 }
675 }
676
677 // Otherwise, look in the root.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000678 if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&&
679 (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){
Daniel Dunbarefe91ea2010-09-17 01:16:06 +0000680 CmdArgs.push_back("/usr/lib/libstdc++.6.dylib");
681 return;
682 }
683
684 // Otherwise, let the linker search.
685 CmdArgs.push_back("-lstdc++");
686 break;
687 }
688 }
689}
690
Shantonu Sen7433fed2010-09-17 18:39:08 +0000691void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
692 ArgStringList &CmdArgs) const {
693
694 // For Darwin platforms, use the compiler-rt-based support library
695 // instead of the gcc-provided one (which is also incidentally
696 // only present in the gcc lib dir, which makes it hard to find).
697
698 llvm::sys::Path P(getDriver().ResourceDir);
699 P.appendComponent("lib");
700 P.appendComponent("darwin");
701 P.appendComponent("libclang_rt.cc_kext.a");
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000702
Shantonu Sen7433fed2010-09-17 18:39:08 +0000703 // For now, allow missing resource libraries to support developers who may
704 // not have compiler-rt checked out or integrated into their build.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000705 bool Exists;
706 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
Shantonu Sen7433fed2010-09-17 18:39:08 +0000707 CmdArgs.push_back(Args.MakeArgString(P.str()));
708}
709
Daniel Dunbarc0e665e2010-07-19 17:11:33 +0000710DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
711 const char *BoundArch) const {
712 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
713 const OptTable &Opts = getDriver().getOpts();
714
715 // FIXME: We really want to get out of the tool chain level argument
716 // translation business, as it makes the driver functionality much
717 // more opaque. For now, we follow gcc closely solely for the
718 // purpose of easily achieving feature parity & testability. Once we
719 // have something that works, we should reevaluate each translation
720 // and try to push it down into tool specific logic.
Daniel Dunbar26031372010-01-27 00:56:25 +0000721
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000722 for (ArgList::const_iterator it = Args.begin(),
723 ie = Args.end(); it != ie; ++it) {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000724 Arg *A = *it;
725
726 if (A->getOption().matches(options::OPT_Xarch__)) {
Daniel Dunbar2a45fa72011-06-21 00:20:17 +0000727 // Skip this argument unless the architecture matches either the toolchain
728 // triple arch, or the arch being bound.
729 //
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000730 // FIXME: Canonicalize name.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000731 StringRef XarchArch = A->getValue(Args, 0);
Daniel Dunbar2a45fa72011-06-21 00:20:17 +0000732 if (!(XarchArch == getArchName() ||
733 (BoundArch && XarchArch == BoundArch)))
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000734 continue;
735
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000736 Arg *OriginalArg = A;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000737 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1));
738 unsigned Prev = Index;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000739 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000740
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000741 // If the argument parsing failed or more than one argument was
742 // consumed, the -Xarch_ argument's parameter tried to consume
743 // extra arguments. Emit an error and ignore.
744 //
745 // We also want to disallow any options which would alter the
746 // driver behavior; that isn't going to work in our model. We
747 // use isDriverOption() as an approximation, although things
748 // like -O4 are going to slip through.
Daniel Dunbar0e02f6e2011-04-21 17:41:34 +0000749 if (!XarchArg || Index > Prev + 1) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000750 getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args)
Daniel Dunbar7e9293b2011-04-21 17:32:21 +0000751 << A->getAsString(Args);
752 continue;
753 } else if (XarchArg->getOption().isDriverOption()) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000754 getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000755 << A->getAsString(Args);
756 continue;
757 }
758
Daniel Dunbar478edc22009-03-29 22:29:05 +0000759 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000760 A = XarchArg;
Daniel Dunbar0e100312010-06-14 21:23:08 +0000761
762 DAL->AddSynthesizedArg(A);
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000763
764 // Linker input arguments require custom handling. The problem is that we
765 // have already constructed the phase actions, so we can not treat them as
766 // "input arguments".
767 if (A->getOption().isLinkerInput()) {
768 // Convert the argument into individual Zlinker_input_args.
769 for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
770 DAL->AddSeparateArg(OriginalArg,
771 Opts.getOption(options::OPT_Zlinker_input),
772 A->getValue(Args, i));
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +0000773
Daniel Dunbar8ac38d72011-02-19 05:33:51 +0000774 }
775 continue;
776 }
Mike Stump1eb44332009-09-09 15:08:12 +0000777 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000778
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000779 // Sob. These is strictly gcc compatible for the time being. Apple
780 // gcc translates options twice, which means that self-expanding
781 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000782 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000783 default:
784 DAL->append(A);
785 break;
786
787 case options::OPT_mkernel:
788 case options::OPT_fapple_kext:
789 DAL->append(A);
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000790 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000791 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000792
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000793 case options::OPT_dependency_file:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000794 DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF),
795 A->getValue(Args));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000796 break;
797
798 case options::OPT_gfull:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000799 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
800 DAL->AddFlagArg(A,
801 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000802 break;
803
804 case options::OPT_gused:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000805 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
806 DAL->AddFlagArg(A,
807 Opts.getOption(options::OPT_feliminate_unused_debug_symbols));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000808 break;
809
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000810 case options::OPT_shared:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000811 DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000812 break;
813
814 case options::OPT_fconstant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000815 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000816 break;
817
818 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000819 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000820 break;
821
822 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000823 DAL->AddFlagArg(A,
824 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000825 break;
826
827 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000828 DAL->AddFlagArg(A,
829 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000830 break;
831
832 case options::OPT_fpascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000833 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000834 break;
835
836 case options::OPT_fno_pascal_strings:
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000837 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000838 break;
839 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000840 }
841
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000842 if (getTriple().getArch() == llvm::Triple::x86 ||
843 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000844 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000845 DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000846
847 // Add the arch options based on the particular spelling of -arch, to match
848 // how the driver driver works.
849 if (BoundArch) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000850 StringRef Name = BoundArch;
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000851 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
852 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
853
854 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
855 // which defines the list of which architectures we accept.
856 if (Name == "ppc")
857 ;
858 else if (Name == "ppc601")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000859 DAL->AddJoinedArg(0, MCpu, "601");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000860 else if (Name == "ppc603")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000861 DAL->AddJoinedArg(0, MCpu, "603");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000862 else if (Name == "ppc604")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000863 DAL->AddJoinedArg(0, MCpu, "604");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000864 else if (Name == "ppc604e")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000865 DAL->AddJoinedArg(0, MCpu, "604e");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000866 else if (Name == "ppc750")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000867 DAL->AddJoinedArg(0, MCpu, "750");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000868 else if (Name == "ppc7400")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000869 DAL->AddJoinedArg(0, MCpu, "7400");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000870 else if (Name == "ppc7450")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000871 DAL->AddJoinedArg(0, MCpu, "7450");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000872 else if (Name == "ppc970")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000873 DAL->AddJoinedArg(0, MCpu, "970");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000874
875 else if (Name == "ppc64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000876 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000877
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000878 else if (Name == "i386")
879 ;
880 else if (Name == "i486")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000881 DAL->AddJoinedArg(0, MArch, "i486");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000882 else if (Name == "i586")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000883 DAL->AddJoinedArg(0, MArch, "i586");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000884 else if (Name == "i686")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000885 DAL->AddJoinedArg(0, MArch, "i686");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000886 else if (Name == "pentium")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000887 DAL->AddJoinedArg(0, MArch, "pentium");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000888 else if (Name == "pentium2")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000889 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000890 else if (Name == "pentpro")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000891 DAL->AddJoinedArg(0, MArch, "pentiumpro");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000892 else if (Name == "pentIIm3")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000893 DAL->AddJoinedArg(0, MArch, "pentium2");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000894
895 else if (Name == "x86_64")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000896 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64));
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000897
898 else if (Name == "arm")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000899 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000900 else if (Name == "armv4t")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000901 DAL->AddJoinedArg(0, MArch, "armv4t");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000902 else if (Name == "armv5")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000903 DAL->AddJoinedArg(0, MArch, "armv5tej");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000904 else if (Name == "xscale")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000905 DAL->AddJoinedArg(0, MArch, "xscale");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000906 else if (Name == "armv6")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000907 DAL->AddJoinedArg(0, MArch, "armv6k");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000908 else if (Name == "armv7")
Daniel Dunbar9d0863b2010-06-14 20:20:41 +0000909 DAL->AddJoinedArg(0, MArch, "armv7a");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000910
911 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000912 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000913 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000914
Daniel Dunbar60baf0f2010-07-19 17:11:36 +0000915 // Add an explicit version min argument for the deployment target. We do this
916 // after argument translation because -Xarch_ arguments may add a version min
917 // argument.
918 AddDeploymentTarget(*DAL);
919
Bob Wilson163b1512011-10-07 17:54:41 +0000920 // Validate the C++ standard library choice.
921 CXXStdlibType Type = GetCXXStdlibType(*DAL);
922 if (Type == ToolChain::CST_Libcxx) {
923 switch (LibCXXForSimulator) {
924 case LibCXXSimulator_None:
925 // Handle non-simulator cases.
926 if (isTargetIPhoneOS()) {
927 if (isIPhoneOSVersionLT(5, 0)) {
928 getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment)
929 << "iOS 5.0";
930 }
Bob Wilson163b1512011-10-07 17:54:41 +0000931 }
932 break;
933 case LibCXXSimulator_NotAvailable:
934 getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment)
935 << "iOS 5.0";
936 break;
937 case LibCXXSimulator_Available:
938 break;
939 }
940 }
941
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000942 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000943}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000944
Daniel Dunbarf3955282009-09-04 18:34:51 +0000945bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000946 // FIXME: Gross; we should probably have some separate target
947 // definition, possibly even reusing the one in clang.
948 return getArchName() == "x86_64";
949}
950
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000951bool Darwin::UseDwarfDebugFlags() const {
952 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
953 return S[0] != '\0';
954 return false;
955}
956
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000957bool Darwin::UseSjLjExceptions() const {
958 // Darwin uses SjLj exceptions on ARM.
959 return (getTriple().getArch() == llvm::Triple::arm ||
960 getTriple().getArch() == llvm::Triple::thumb);
961}
962
Daniel Dunbarf3955282009-09-04 18:34:51 +0000963const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000964 return "pic";
965}
966
Daniel Dunbarf3955282009-09-04 18:34:51 +0000967const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000968 if (getArchName() == "x86_64")
969 return "pic";
970 return 0;
971}
972
Daniel Dunbarbbe8e3e2011-03-01 18:49:30 +0000973bool Darwin::SupportsProfiling() const {
974 // Profiling instrumentation is only supported on x86.
975 return getArchName() == "i386" || getArchName() == "x86_64";
976}
977
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000978bool Darwin::SupportsObjCGC() const {
979 // Garbage collection is supported everywhere except on iPhone OS.
980 return !isTargetIPhoneOS();
981}
982
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000983std::string
Chad Rosier61ab80a2011-09-20 20:44:06 +0000984Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args,
985 types::ID InputType) const {
986 return ComputeLLVMTriple(Args, InputType);
Daniel Dunbar00577ad2010-08-23 22:35:37 +0000987}
988
Daniel Dunbar39176082009-03-20 00:20:03 +0000989/// Generic_GCC - A tool chain using the 'gcc' command to perform
990/// all subcommands; this relies on gcc translating the majority of
991/// command line options.
992
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000993Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000994 : ToolChain(Host, Triple) {
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000995 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +0000996 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000997 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000998}
999
Daniel Dunbar39176082009-03-20 00:20:03 +00001000Generic_GCC::~Generic_GCC() {
1001 // Free tool implementations.
1002 for (llvm::DenseMap<unsigned, Tool*>::iterator
1003 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
1004 delete it->second;
1005}
1006
Mike Stump1eb44332009-09-09 15:08:12 +00001007Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001008 const JobAction &JA,
1009 const ActionList &Inputs) const {
Daniel Dunbar39176082009-03-20 00:20:03 +00001010 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001011 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +00001012 Key = Action::AnalyzeJobClass;
1013 else
1014 Key = JA.getKind();
1015
1016 Tool *&T = Tools[Key];
1017 if (!T) {
1018 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +00001019 case Action::InputClass:
1020 case Action::BindArchClass:
David Blaikieb219cfc2011-09-23 05:06:16 +00001021 llvm_unreachable("Invalid tool kind.");
Daniel Dunbar39176082009-03-20 00:20:03 +00001022 case Action::PreprocessJobClass:
1023 T = new tools::gcc::Preprocess(*this); break;
1024 case Action::PrecompileJobClass:
1025 T = new tools::gcc::Precompile(*this); break;
1026 case Action::AnalyzeJobClass:
1027 T = new tools::Clang(*this); break;
1028 case Action::CompileJobClass:
1029 T = new tools::gcc::Compile(*this); break;
1030 case Action::AssembleJobClass:
1031 T = new tools::gcc::Assemble(*this); break;
1032 case Action::LinkJobClass:
1033 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +00001035 // This is a bit ungeneric, but the only platform using a driver
1036 // driver is Darwin.
1037 case Action::LipoJobClass:
1038 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar6e0f2542010-06-04 18:28:36 +00001039 case Action::DsymutilJobClass:
1040 T = new tools::darwin::Dsymutil(*this); break;
Eric Christopherf8571862011-08-23 17:56:55 +00001041 case Action::VerifyJobClass:
1042 T = new tools::darwin::VerifyDebug(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +00001043 }
1044 }
1045
1046 return *T;
1047}
1048
Daniel Dunbar39176082009-03-20 00:20:03 +00001049bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +00001050 // FIXME: Gross; we should probably have some separate target
1051 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +00001052 return getArchName() == "x86_64";
1053}
1054
1055const char *Generic_GCC::GetDefaultRelocationModel() const {
1056 return "static";
1057}
1058
1059const char *Generic_GCC::GetForcedPicModel() const {
1060 return 0;
1061}
Daniel Dunbarf3cad362009-03-25 04:13:45 +00001062
Chris Lattner3a47c4e2010-03-04 21:07:38 +00001063/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
1064/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
1065/// Currently does not support anything else but compilation.
1066
1067TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple)
1068 : ToolChain(Host, Triple) {
1069 // Path mangling to find libexec
1070 std::string Path(getDriver().Dir);
1071
1072 Path += "/../libexec";
1073 getProgramPaths().push_back(Path);
1074}
1075
1076TCEToolChain::~TCEToolChain() {
1077 for (llvm::DenseMap<unsigned, Tool*>::iterator
1078 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
1079 delete it->second;
1080}
1081
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001082bool TCEToolChain::IsMathErrnoDefault() const {
1083 return true;
Chris Lattner3a47c4e2010-03-04 21:07:38 +00001084}
1085
1086bool TCEToolChain::IsUnwindTablesDefault() const {
1087 return false;
1088}
1089
1090const char *TCEToolChain::GetDefaultRelocationModel() const {
1091 return "static";
1092}
1093
1094const char *TCEToolChain::GetForcedPicModel() const {
1095 return 0;
1096}
1097
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001098Tool &TCEToolChain::SelectTool(const Compilation &C,
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001099 const JobAction &JA,
1100 const ActionList &Inputs) const {
Chris Lattner3a47c4e2010-03-04 21:07:38 +00001101 Action::ActionClass Key;
1102 Key = Action::AnalyzeJobClass;
1103
1104 Tool *&T = Tools[Key];
1105 if (!T) {
1106 switch (Key) {
1107 case Action::PreprocessJobClass:
1108 T = new tools::gcc::Preprocess(*this); break;
1109 case Action::AnalyzeJobClass:
1110 T = new tools::Clang(*this); break;
1111 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001112 llvm_unreachable("Unsupported action for TCE target.");
Chris Lattner3a47c4e2010-03-04 21:07:38 +00001113 }
1114 }
1115 return *T;
1116}
1117
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001118/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
1119
1120OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001121 : Generic_ELF(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +00001122 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001123 getFilePaths().push_back("/usr/lib");
1124}
1125
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001126Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA,
1127 const ActionList &Inputs) const {
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001128 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001129 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001130 Key = Action::AnalyzeJobClass;
1131 else
1132 Key = JA.getKind();
1133
Rafael Espindoladda5b922010-11-07 23:13:01 +00001134 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1135 options::OPT_no_integrated_as,
1136 IsIntegratedAssemblerDefault());
1137
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001138 Tool *&T = Tools[Key];
1139 if (!T) {
1140 switch (Key) {
Rafael Espindoladda5b922010-11-07 23:13:01 +00001141 case Action::AssembleJobClass: {
1142 if (UseIntegratedAs)
1143 T = new tools::ClangAs(*this);
1144 else
1145 T = new tools::openbsd::Assemble(*this);
1146 break;
1147 }
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001148 case Action::LinkJobClass:
1149 T = new tools::openbsd::Link(*this); break;
1150 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001151 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001152 }
1153 }
1154
1155 return *T;
1156}
1157
Daniel Dunbar75358d22009-03-30 21:06:03 +00001158/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
1159
Daniel Dunbar214afe92010-08-02 05:43:59 +00001160FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001161 : Generic_ELF(Host, Triple) {
Daniel Dunbar214afe92010-08-02 05:43:59 +00001162
1163 // Determine if we are compiling 32-bit code on an x86_64 platform.
1164 bool Lib32 = false;
1165 if (Triple.getArch() == llvm::Triple::x86 &&
1166 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1167 llvm::Triple::x86_64)
1168 Lib32 = true;
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001169
Roman Divacky3393cef2011-06-04 07:37:31 +00001170 if (Triple.getArch() == llvm::Triple::ppc &&
1171 llvm::Triple(getDriver().DefaultHostTriple).getArch() ==
1172 llvm::Triple::ppc64)
1173 Lib32 = true;
1174
Daniel Dunbarbc534662009-04-02 18:30:04 +00001175 if (Lib32) {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001176 getFilePaths().push_back("/usr/lib32");
1177 } else {
Daniel Dunbarbc534662009-04-02 18:30:04 +00001178 getFilePaths().push_back("/usr/lib");
1179 }
Daniel Dunbar75358d22009-03-30 21:06:03 +00001180}
1181
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001182Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA,
1183 const ActionList &Inputs) const {
Daniel Dunbar75358d22009-03-30 21:06:03 +00001184 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001185 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +00001186 Key = Action::AnalyzeJobClass;
1187 else
1188 Key = JA.getKind();
1189
Roman Divacky67dece72010-11-08 17:46:39 +00001190 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1191 options::OPT_no_integrated_as,
1192 IsIntegratedAssemblerDefault());
1193
Daniel Dunbar75358d22009-03-30 21:06:03 +00001194 Tool *&T = Tools[Key];
1195 if (!T) {
1196 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +00001197 case Action::AssembleJobClass:
Roman Divacky67dece72010-11-08 17:46:39 +00001198 if (UseIntegratedAs)
1199 T = new tools::ClangAs(*this);
1200 else
1201 T = new tools::freebsd::Assemble(*this);
Roman Divackyfe3a7ea2010-11-08 19:39:10 +00001202 break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +00001203 case Action::LinkJobClass:
1204 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +00001205 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001206 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbar75358d22009-03-30 21:06:03 +00001207 }
1208 }
1209
1210 return *T;
1211}
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001212
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001213/// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly.
1214
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001215NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple,
1216 const llvm::Triple& ToolTriple)
1217 : Generic_ELF(Host, Triple), ToolTriple(ToolTriple) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001218
1219 // Determine if we are compiling 32-bit code on an x86_64 platform.
1220 bool Lib32 = false;
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001221 if (ToolTriple.getArch() == llvm::Triple::x86_64 &&
1222 Triple.getArch() == llvm::Triple::x86)
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001223 Lib32 = true;
1224
Joerg Sonnenberger05e59302011-03-21 13:59:26 +00001225 if (getDriver().UseStdLib) {
1226 if (Lib32)
1227 getFilePaths().push_back("=/usr/lib/i386");
1228 else
1229 getFilePaths().push_back("=/usr/lib");
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001230 }
1231}
1232
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001233Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA,
1234 const ActionList &Inputs) const {
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001235 Action::ActionClass Key;
1236 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1237 Key = Action::AnalyzeJobClass;
1238 else
1239 Key = JA.getKind();
1240
1241 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1242 options::OPT_no_integrated_as,
1243 IsIntegratedAssemblerDefault());
1244
1245 Tool *&T = Tools[Key];
1246 if (!T) {
1247 switch (Key) {
1248 case Action::AssembleJobClass:
1249 if (UseIntegratedAs)
1250 T = new tools::ClangAs(*this);
1251 else
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001252 T = new tools::netbsd::Assemble(*this, ToolTriple);
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001253 break;
1254 case Action::LinkJobClass:
Joerg Sonnenberger182564c2011-05-16 13:35:02 +00001255 T = new tools::netbsd::Link(*this, ToolTriple);
1256 break;
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001257 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001258 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Benjamin Kramer8e50a962011-02-02 18:59:27 +00001259 }
1260 }
1261
1262 return *T;
1263}
1264
Chris Lattner38e317d2010-07-07 16:01:42 +00001265/// Minix - Minix tool chain which can call as(1) and ld(1) directly.
1266
1267Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple)
1268 : Generic_GCC(Host, Triple) {
1269 getFilePaths().push_back(getDriver().Dir + "/../lib");
1270 getFilePaths().push_back("/usr/lib");
1271 getFilePaths().push_back("/usr/gnu/lib");
1272 getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
1273}
1274
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001275Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA,
1276 const ActionList &Inputs) const {
Chris Lattner38e317d2010-07-07 16:01:42 +00001277 Action::ActionClass Key;
1278 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1279 Key = Action::AnalyzeJobClass;
1280 else
1281 Key = JA.getKind();
1282
1283 Tool *&T = Tools[Key];
1284 if (!T) {
1285 switch (Key) {
1286 case Action::AssembleJobClass:
1287 T = new tools::minix::Assemble(*this); break;
1288 case Action::LinkJobClass:
1289 T = new tools::minix::Link(*this); break;
1290 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001291 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Chris Lattner38e317d2010-07-07 16:01:42 +00001292 }
1293 }
1294
1295 return *T;
1296}
1297
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001298/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
1299
1300AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
1301 : Generic_GCC(Host, Triple) {
1302
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001303 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +00001304 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001305 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001306
Daniel Dunbaree788e72009-12-21 18:54:17 +00001307 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001308 getFilePaths().push_back("/usr/lib");
1309 getFilePaths().push_back("/usr/sfw/lib");
1310 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +00001311 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001312
1313}
1314
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001315Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA,
1316 const ActionList &Inputs) const {
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001317 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001318 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001319 Key = Action::AnalyzeJobClass;
1320 else
1321 Key = JA.getKind();
1322
1323 Tool *&T = Tools[Key];
1324 if (!T) {
1325 switch (Key) {
1326 case Action::AssembleJobClass:
1327 T = new tools::auroraux::Assemble(*this); break;
1328 case Action::LinkJobClass:
1329 T = new tools::auroraux::Link(*this); break;
1330 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001331 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Edward O'Callaghane7925a02009-08-22 01:06:46 +00001332 }
1333 }
1334
1335 return *T;
1336}
1337
1338
Eli Friedman6b3454a2009-05-26 07:52:18 +00001339/// Linux toolchain (very bare-bones at the moment).
1340
Rafael Espindolac1da9812010-11-07 20:14:31 +00001341enum LinuxDistro {
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001342 ArchLinux,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001343 DebianLenny,
1344 DebianSqueeze,
Eli Friedman0b200f62011-06-02 21:36:53 +00001345 DebianWheezy,
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001346 Exherbo,
Chris Lattnerd753b562011-05-22 05:36:06 +00001347 RHEL4,
1348 RHEL5,
1349 RHEL6,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001350 Fedora13,
1351 Fedora14,
Eric Christopher8f1cc072011-04-06 18:22:53 +00001352 Fedora15,
1353 FedoraRawhide,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001354 OpenSuse11_3,
David Chisnallde5c0482011-05-19 13:26:33 +00001355 OpenSuse11_4,
1356 OpenSuse12_1,
Douglas Gregor814638e2011-03-14 15:39:50 +00001357 UbuntuHardy,
1358 UbuntuIntrepid,
Rafael Espindola021aaa42010-11-10 05:00:22 +00001359 UbuntuJaunty,
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001360 UbuntuKarmic,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001361 UbuntuLucid,
1362 UbuntuMaverick,
Ted Kremenek43ac2972011-04-05 22:04:27 +00001363 UbuntuNatty,
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001364 UbuntuOneiric,
Rafael Espindolac1da9812010-11-07 20:14:31 +00001365 UnknownDistro
1366};
1367
Chris Lattnerd753b562011-05-22 05:36:06 +00001368static bool IsRedhat(enum LinuxDistro Distro) {
Eric Christopher8f1cc072011-04-06 18:22:53 +00001369 return Distro == Fedora13 || Distro == Fedora14 ||
Rafael Espindola5a640ef2011-06-03 15:23:24 +00001370 Distro == Fedora15 || Distro == FedoraRawhide ||
1371 Distro == RHEL4 || Distro == RHEL5 || Distro == RHEL6;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001372}
1373
1374static bool IsOpenSuse(enum LinuxDistro Distro) {
David Chisnallde5c0482011-05-19 13:26:33 +00001375 return Distro == OpenSuse11_3 || Distro == OpenSuse11_4 ||
1376 Distro == OpenSuse12_1;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001377}
1378
1379static bool IsDebian(enum LinuxDistro Distro) {
Eli Friedman0b200f62011-06-02 21:36:53 +00001380 return Distro == DebianLenny || Distro == DebianSqueeze ||
1381 Distro == DebianWheezy;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001382}
1383
1384static bool IsUbuntu(enum LinuxDistro Distro) {
Douglas Gregor814638e2011-03-14 15:39:50 +00001385 return Distro == UbuntuHardy || Distro == UbuntuIntrepid ||
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001386 Distro == UbuntuLucid || Distro == UbuntuMaverick ||
Ted Kremenek43ac2972011-04-05 22:04:27 +00001387 Distro == UbuntuJaunty || Distro == UbuntuKarmic ||
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001388 Distro == UbuntuNatty || Distro == UbuntuOneiric;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001389}
1390
Chandler Carruth38ec5462011-10-03 09:00:50 +00001391// FIXME: This should be deleted. We should assume a multilib environment, and
1392// fallback gracefully if any parts of it are absent.
Rafael Espindolac1da9812010-11-07 20:14:31 +00001393static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) {
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001394 if (Arch == llvm::Triple::x86_64) {
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001395 bool Exists;
1396 if (Distro == Exherbo &&
1397 (llvm::sys::fs::exists("/usr/lib32/libc.so", Exists) || !Exists))
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001398 return false;
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001399 }
Chandler Carruth38ec5462011-10-03 09:00:50 +00001400
1401 return true;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001402}
1403
1404static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001405 llvm::OwningPtr<llvm::MemoryBuffer> File;
1406 if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001407 StringRef Data = File.get()->getBuffer();
1408 SmallVector<StringRef, 8> Lines;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001409 Data.split(Lines, "\n");
1410 for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) {
Douglas Gregor814638e2011-03-14 15:39:50 +00001411 if (Lines[i] == "DISTRIB_CODENAME=hardy")
1412 return UbuntuHardy;
Ted Kremenek43ac2972011-04-05 22:04:27 +00001413 else if (Lines[i] == "DISTRIB_CODENAME=intrepid")
1414 return UbuntuIntrepid;
Rafael Espindola021aaa42010-11-10 05:00:22 +00001415 else if (Lines[i] == "DISTRIB_CODENAME=jaunty")
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001416 return UbuntuJaunty;
Zhongxing Xu5ede8072010-11-15 09:01:52 +00001417 else if (Lines[i] == "DISTRIB_CODENAME=karmic")
1418 return UbuntuKarmic;
Ted Kremenek43ac2972011-04-05 22:04:27 +00001419 else if (Lines[i] == "DISTRIB_CODENAME=lucid")
1420 return UbuntuLucid;
1421 else if (Lines[i] == "DISTRIB_CODENAME=maverick")
1422 return UbuntuMaverick;
1423 else if (Lines[i] == "DISTRIB_CODENAME=natty")
1424 return UbuntuNatty;
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001425 else if (Lines[i] == "DISTRIB_CODENAME=oneiric")
1426 return UbuntuOneiric;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001427 }
1428 return UnknownDistro;
1429 }
1430
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001431 if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001432 StringRef Data = File.get()->getBuffer();
Eric Christopher8f1cc072011-04-06 18:22:53 +00001433 if (Data.startswith("Fedora release 15"))
1434 return Fedora15;
1435 else if (Data.startswith("Fedora release 14"))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001436 return Fedora14;
Eric Christopher8f1cc072011-04-06 18:22:53 +00001437 else if (Data.startswith("Fedora release 13"))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001438 return Fedora13;
Eric Christopher8f1cc072011-04-06 18:22:53 +00001439 else if (Data.startswith("Fedora release") &&
Chris Lattner5f9e2722011-07-23 10:55:15 +00001440 Data.find("Rawhide") != StringRef::npos)
Eric Christopher8f1cc072011-04-06 18:22:53 +00001441 return FedoraRawhide;
Chris Lattnerd753b562011-05-22 05:36:06 +00001442 else if (Data.startswith("Red Hat Enterprise Linux") &&
Chris Lattner5f9e2722011-07-23 10:55:15 +00001443 Data.find("release 6") != StringRef::npos)
Chris Lattnerd753b562011-05-22 05:36:06 +00001444 return RHEL6;
Rafael Espindola5a640ef2011-06-03 15:23:24 +00001445 else if ((Data.startswith("Red Hat Enterprise Linux") ||
1446 Data.startswith("CentOS")) &&
Chris Lattner5f9e2722011-07-23 10:55:15 +00001447 Data.find("release 5") != StringRef::npos)
Chris Lattnerd753b562011-05-22 05:36:06 +00001448 return RHEL5;
Rafael Espindola5a640ef2011-06-03 15:23:24 +00001449 else if ((Data.startswith("Red Hat Enterprise Linux") ||
1450 Data.startswith("CentOS")) &&
Chris Lattner5f9e2722011-07-23 10:55:15 +00001451 Data.find("release 4") != StringRef::npos)
Chris Lattnerd753b562011-05-22 05:36:06 +00001452 return RHEL4;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001453 return UnknownDistro;
1454 }
1455
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001456 if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001457 StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001458 if (Data[0] == '5')
1459 return DebianLenny;
1460 else if (Data.startswith("squeeze/sid"))
1461 return DebianSqueeze;
Eli Friedman0b200f62011-06-02 21:36:53 +00001462 else if (Data.startswith("wheezy/sid"))
1463 return DebianWheezy;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001464 return UnknownDistro;
1465 }
1466
Michael J. Spencer4eeebc42010-12-16 03:28:14 +00001467 if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) {
Chris Lattner5f9e2722011-07-23 10:55:15 +00001468 StringRef Data = File.get()->getBuffer();
Rafael Espindolac1da9812010-11-07 20:14:31 +00001469 if (Data.startswith("openSUSE 11.3"))
1470 return OpenSuse11_3;
David Chisnallde5c0482011-05-19 13:26:33 +00001471 else if (Data.startswith("openSUSE 11.4"))
1472 return OpenSuse11_4;
1473 else if (Data.startswith("openSUSE 12.1"))
1474 return OpenSuse12_1;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001475 return UnknownDistro;
1476 }
1477
Michael J. Spencer32bef4e2011-01-10 02:34:13 +00001478 bool Exists;
1479 if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists)
Rafael Espindola0a84aee2010-11-11 02:07:13 +00001480 return Exherbo;
1481
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001482 if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists)
1483 return ArchLinux;
1484
Rafael Espindolac1da9812010-11-07 20:14:31 +00001485 return UnknownDistro;
1486}
1487
Chandler Carruth048e6492011-10-03 18:16:54 +00001488/// \brief Trivial helper function to simplify code checking path existence.
Chandler Carruthadc4afb2011-10-04 02:28:41 +00001489static bool PathExists(StringRef Path) {
Rafael Espindola14ea13c2011-06-02 22:18:46 +00001490 bool Exists;
Chandler Carruth048e6492011-10-03 18:16:54 +00001491 if (!llvm::sys::fs::exists(Path, Exists))
1492 return Exists;
1493 return false;
1494}
1495
1496namespace {
1497/// \brief This is a class to find a viable GCC installation for Clang to use.
1498///
1499/// This class tries to find a GCC installation on the system, and report
1500/// information about it. It starts from the host information provided to the
1501/// Driver, and has logic for fuzzing that where appropriate.
1502class GCCInstallationDetector {
Chandler Carruth6d9694c2011-10-04 21:22:33 +00001503 /// \brief Struct to store and manipulate GCC versions.
1504 ///
1505 /// We rely on assumptions about the form and structure of GCC version
1506 /// numbers: they consist of at most three '.'-separated components, and each
1507 /// component is a non-negative integer.
1508 struct GCCVersion {
1509 unsigned Major, Minor, Patch;
1510
1511 static GCCVersion Parse(StringRef VersionText) {
NAKAMURA Takumi96e21712011-10-08 11:31:53 +00001512 const GCCVersion BadVersion = {0, 0, 0};
Chandler Carruth6d9694c2011-10-04 21:22:33 +00001513 std::pair<StringRef, StringRef> First = VersionText.split('.');
1514 std::pair<StringRef, StringRef> Second = First.second.split('.');
1515
NAKAMURA Takumi96e21712011-10-08 11:31:53 +00001516 GCCVersion GoodVersion = {0, 0, 0};
Chandler Carruth6d9694c2011-10-04 21:22:33 +00001517 if (First.first.getAsInteger(10, GoodVersion.Major))
1518 return BadVersion;
1519 if (Second.first.getAsInteger(10, GoodVersion.Minor))
1520 return BadVersion;
Chandler Carruthdbc21442011-10-05 03:09:51 +00001521 // We accept a number, or a string for the patch version, in case there
1522 // is a strang suffix, or other mangling: '4.1.x', '4.1.2-rc3'. When it
1523 // isn't a number, we just use '0' as the number but accept it.
1524 if (Second.first.getAsInteger(10, GoodVersion.Patch))
1525 GoodVersion.Patch = 0;
Chandler Carruth6d9694c2011-10-04 21:22:33 +00001526 return GoodVersion;
1527 }
1528
1529 bool operator<(const GCCVersion &RHS) const {
1530 if (Major < RHS.Major) return true;
1531 if (Major > RHS.Major) return false;
1532 if (Minor < RHS.Minor) return true;
1533 if (Minor > RHS.Minor) return false;
1534 return Patch < RHS.Patch;
1535 }
1536 bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
1537 bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
1538 bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
1539 };
1540
Chandler Carruth048e6492011-10-03 18:16:54 +00001541 bool IsValid;
1542 std::string GccTriple;
1543
1544 // FIXME: These might be better as path objects.
1545 std::string GccInstallPath;
1546 std::string GccParentLibPath;
1547
1548 llvm::SmallString<128> CxxIncludeRoot;
1549
1550public:
1551 /// \brief Construct a GCCInstallationDetector from the driver.
1552 ///
1553 /// This performs all of the autodetection and sets up the various paths.
1554 /// Once constructed, a GCCInstallation is esentially immutable.
1555 GCCInstallationDetector(const Driver &D)
1556 : IsValid(false),
1557 GccTriple(D.DefaultHostTriple),
1558 CxxIncludeRoot(CXX_INCLUDE_ROOT) {
1559 // FIXME: Using CXX_INCLUDE_ROOT is here is a bit of a hack, but
1560 // avoids adding yet another option to configure/cmake.
1561 // It would probably be cleaner to break it in two variables
1562 // CXX_GCC_ROOT with just /foo/bar
1563 // CXX_GCC_VER with 4.5.2
1564 // Then we would have
1565 // CXX_INCLUDE_ROOT = CXX_GCC_ROOT/include/c++/CXX_GCC_VER
1566 // and this function would return
1567 // CXX_GCC_ROOT/lib/gcc/CXX_INCLUDE_ARCH/CXX_GCC_VER
1568 if (CxxIncludeRoot != "") {
1569 // This is of the form /foo/bar/include/c++/4.5.2/
1570 if (CxxIncludeRoot.back() == '/')
1571 llvm::sys::path::remove_filename(CxxIncludeRoot); // remove the /
1572 StringRef Version = llvm::sys::path::filename(CxxIncludeRoot);
1573 llvm::sys::path::remove_filename(CxxIncludeRoot); // remove the version
1574 llvm::sys::path::remove_filename(CxxIncludeRoot); // remove the c++
1575 llvm::sys::path::remove_filename(CxxIncludeRoot); // remove the include
1576 GccInstallPath = CxxIncludeRoot.str();
1577 GccInstallPath.append("/lib/gcc/");
1578 GccInstallPath.append(CXX_INCLUDE_ARCH);
1579 GccInstallPath.append("/");
1580 GccInstallPath.append(Version);
Rafael Espindolaf886d6f2011-10-14 19:50:08 +00001581 GccParentLibPath = GccInstallPath + "/../../..";
Chandler Carruth048e6492011-10-03 18:16:54 +00001582 IsValid = true;
1583 return;
1584 }
1585
1586 llvm::Triple::ArchType HostArch = llvm::Triple(GccTriple).getArch();
Chandler Carruth810e0812011-10-04 08:32:14 +00001587 // The library directories which may contain GCC installations.
Chandler Carrutha24b9802011-10-04 09:47:17 +00001588 SmallVector<StringRef, 4> CandidateLibDirs;
Chandler Carruth810e0812011-10-04 08:32:14 +00001589 // The compatible GCC triples for this particular architecture.
Chandler Carruthadc4afb2011-10-04 02:28:41 +00001590 SmallVector<StringRef, 10> CandidateTriples;
Chandler Carruth4c9403c2011-10-04 22:58:04 +00001591 CollectLibDirsAndTriples(HostArch, CandidateLibDirs, CandidateTriples);
Chandler Carruthadc4afb2011-10-04 02:28:41 +00001592
Chandler Carruth810e0812011-10-04 08:32:14 +00001593 // Always include the default host triple as the final fallback if no
1594 // specific triple is detected.
1595 CandidateTriples.push_back(D.DefaultHostTriple);
Chandler Carruth048e6492011-10-03 18:16:54 +00001596
Chandler Carruth6d9694c2011-10-04 21:22:33 +00001597 // Compute the set of prefixes for our search.
Chandler Carruth810e0812011-10-04 08:32:14 +00001598 SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(),
1599 D.PrefixDirs.end());
Chandler Carruth6ab8e622011-10-04 21:22:42 +00001600 Prefixes.push_back(D.SysRoot);
Chandler Carruth810e0812011-10-04 08:32:14 +00001601 Prefixes.push_back(D.SysRoot + "/usr");
Chandler Carruth12036002011-10-05 06:38:03 +00001602 Prefixes.push_back(D.InstalledDir + "/..");
Chandler Carruth810e0812011-10-04 08:32:14 +00001603
Chandler Carruth6d9694c2011-10-04 21:22:33 +00001604 // Loop over the various components which exist and select the best GCC
1605 // installation available. GCC installs are ranked by version number.
NAKAMURA Takumi96e21712011-10-08 11:31:53 +00001606 GCCVersion BestVersion = {0, 0, 0};
Chandler Carruth6d9694c2011-10-04 21:22:33 +00001607 for (unsigned i = 0, ie = Prefixes.size(); i < ie; ++i) {
1608 if (!PathExists(Prefixes[i]))
1609 continue;
1610 for (unsigned j = 0, je = CandidateLibDirs.size(); j < je; ++j) {
1611 const std::string LibDir = Prefixes[i] + CandidateLibDirs[j].str();
1612 if (!PathExists(LibDir))
1613 continue;
Chandler Carruthe0890882011-10-04 23:17:12 +00001614 for (unsigned k = 0, ke = CandidateTriples.size(); k < ke; ++k)
1615 ScanLibDirForGCCTriple(LibDir, CandidateTriples[k], BestVersion);
David Chisnall5adcec12011-09-27 22:03:18 +00001616 }
Eli Friedman733a83b2011-09-16 21:04:38 +00001617 }
Rafael Espindola14ea13c2011-06-02 22:18:46 +00001618 }
Chandler Carruth048e6492011-10-03 18:16:54 +00001619
1620 /// \brief Check whether we detected a valid GCC install.
1621 bool isValid() const { return IsValid; }
1622
1623 /// \brief Get the GCC triple for the detected install.
1624 const std::string &getTriple() const { return GccTriple; }
1625
1626 /// \brief Get the detected GCC installation path.
1627 const std::string &getInstallPath() const { return GccInstallPath; }
1628
1629 /// \brief Get the detected GCC parent lib path.
1630 const std::string &getParentLibPath() const { return GccParentLibPath; }
Chandler Carruth4c9403c2011-10-04 22:58:04 +00001631
1632private:
1633 static void CollectLibDirsAndTriples(llvm::Triple::ArchType HostArch,
1634 SmallVectorImpl<StringRef> &LibDirs,
1635 SmallVectorImpl<StringRef> &Triples) {
1636 if (HostArch == llvm::Triple::arm || HostArch == llvm::Triple::thumb) {
Chandler Carruth7a09d012011-10-16 10:54:30 +00001637 static const char *const ARMLibDirs[] = { "/lib" };
Chandler Carruth4c9403c2011-10-04 22:58:04 +00001638 static const char *const ARMTriples[] = { "arm-linux-gnueabi" };
1639 LibDirs.append(ARMLibDirs, ARMLibDirs + llvm::array_lengthof(ARMLibDirs));
1640 Triples.append(ARMTriples, ARMTriples + llvm::array_lengthof(ARMTriples));
1641 } else if (HostArch == llvm::Triple::x86_64) {
Chandler Carruth7a09d012011-10-16 10:54:30 +00001642 static const char *const X86_64LibDirs[] = { "/lib64", "/lib" };
Chandler Carruth4c9403c2011-10-04 22:58:04 +00001643 static const char *const X86_64Triples[] = {
1644 "x86_64-linux-gnu",
1645 "x86_64-unknown-linux-gnu",
1646 "x86_64-pc-linux-gnu",
1647 "x86_64-redhat-linux6E",
1648 "x86_64-redhat-linux",
1649 "x86_64-suse-linux",
1650 "x86_64-manbo-linux-gnu",
1651 "x86_64-linux-gnu",
1652 "x86_64-slackware-linux"
1653 };
1654 LibDirs.append(X86_64LibDirs,
1655 X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs));
1656 Triples.append(X86_64Triples,
1657 X86_64Triples + llvm::array_lengthof(X86_64Triples));
1658 } else if (HostArch == llvm::Triple::x86) {
Chandler Carruth7a09d012011-10-16 10:54:30 +00001659 static const char *const X86LibDirs[] = { "/lib32", "/lib" };
Chandler Carruth4c9403c2011-10-04 22:58:04 +00001660 static const char *const X86Triples[] = {
1661 "i686-linux-gnu",
1662 "i386-linux-gnu",
1663 "i686-pc-linux-gnu",
1664 "i486-linux-gnu",
1665 "i686-redhat-linux",
Benjamin Kramer84cbd4b2011-10-13 20:45:37 +00001666 "i386-redhat-linux",
Chandler Carruth4c9403c2011-10-04 22:58:04 +00001667 "i586-suse-linux",
1668 "i486-slackware-linux"
1669 };
1670 LibDirs.append(X86LibDirs, X86LibDirs + llvm::array_lengthof(X86LibDirs));
1671 Triples.append(X86Triples, X86Triples + llvm::array_lengthof(X86Triples));
1672 } else if (HostArch == llvm::Triple::ppc) {
Chandler Carruth7a09d012011-10-16 10:54:30 +00001673 static const char *const PPCLibDirs[] = { "/lib32", "/lib" };
Chandler Carruth4c9403c2011-10-04 22:58:04 +00001674 static const char *const PPCTriples[] = {
1675 "powerpc-linux-gnu",
1676 "powerpc-unknown-linux-gnu"
1677 };
1678 LibDirs.append(PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs));
1679 Triples.append(PPCTriples, PPCTriples + llvm::array_lengthof(PPCTriples));
1680 } else if (HostArch == llvm::Triple::ppc64) {
Chandler Carruth7a09d012011-10-16 10:54:30 +00001681 static const char *const PPC64LibDirs[] = { "/lib64", "/lib" };
Chandler Carruth4c9403c2011-10-04 22:58:04 +00001682 static const char *const PPC64Triples[] = {
1683 "powerpc64-unknown-linux-gnu"
1684 };
1685 LibDirs.append(PPC64LibDirs,
1686 PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs));
1687 Triples.append(PPC64Triples,
1688 PPC64Triples + llvm::array_lengthof(PPC64Triples));
1689 }
1690 }
Chandler Carruthe0890882011-10-04 23:17:12 +00001691
1692 void ScanLibDirForGCCTriple(const std::string &LibDir,
1693 StringRef CandidateTriple,
1694 GCCVersion &BestVersion) {
Chandler Carruth7a09d012011-10-16 10:54:30 +00001695 // There are various different suffixes involving the triple we
Chandler Carruthe0890882011-10-04 23:17:12 +00001696 // check for. We also record what is necessary to walk from each back
1697 // up to the lib directory.
Chandler Carruth7a09d012011-10-16 10:54:30 +00001698 const std::string Suffixes[] = {
1699 "/gcc/" + CandidateTriple.str(),
Chandler Carruth16a63552011-10-16 11:05:04 +00001700 "/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(),
Chandler Carruth7a09d012011-10-16 10:54:30 +00001701
1702 // Ubuntu has a strange mis-matched pair of triples that this happens to
1703 // match.
1704 // FIXME: It may be worthwhile to generalize this and look for a second
1705 // triple.
Chandler Carruth16a63552011-10-16 11:05:04 +00001706 "/" + CandidateTriple.str() + "/gcc/i686-linux-gnu"
Chandler Carruth7a09d012011-10-16 10:54:30 +00001707 };
1708 const std::string InstallSuffixes[] = {
1709 "/../../..",
1710 "/../../../..",
1711 "/../../../.."
1712 };
1713 // Only look at the final, weird Ubuntu suffix for i386-linux-gnu.
Chandler Carruthe0890882011-10-04 23:17:12 +00001714 const unsigned NumSuffixes = (llvm::array_lengthof(Suffixes) -
1715 (CandidateTriple != "i386-linux-gnu"));
1716 for (unsigned i = 0; i < NumSuffixes; ++i) {
1717 StringRef Suffix = Suffixes[i];
1718 llvm::error_code EC;
Chandler Carruth7a09d012011-10-16 10:54:30 +00001719 for (llvm::sys::fs::directory_iterator LI(LibDir + Suffix, EC), LE;
Chandler Carruthe0890882011-10-04 23:17:12 +00001720 !EC && LI != LE; LI = LI.increment(EC)) {
1721 StringRef VersionText = llvm::sys::path::filename(LI->path());
1722 GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
1723 static const GCCVersion MinVersion = { 4, 1, 1 };
1724 if (CandidateVersion < MinVersion)
1725 continue;
1726 if (CandidateVersion <= BestVersion)
1727 continue;
1728 if (!PathExists(LI->path() + "/crtbegin.o"))
1729 continue;
1730
1731 BestVersion = CandidateVersion;
1732 GccTriple = CandidateTriple.str();
1733 // FIXME: We hack together the directory name here instead of
1734 // using LI to ensure stable path separators across Windows and
1735 // Linux.
Chandler Carruth7a09d012011-10-16 10:54:30 +00001736 GccInstallPath = LibDir + Suffixes[i] + "/" + VersionText.str();
Chandler Carruthe0890882011-10-04 23:17:12 +00001737 GccParentLibPath = GccInstallPath + InstallSuffixes[i];
1738 IsValid = true;
1739 }
1740 }
1741 }
Chandler Carruth048e6492011-10-03 18:16:54 +00001742};
Rafael Espindola14ea13c2011-06-02 22:18:46 +00001743}
1744
Chandler Carruthd2deee12011-10-03 05:28:29 +00001745static void addPathIfExists(const std::string &Path,
1746 ToolChain::path_list &Paths) {
Chandler Carruth048e6492011-10-03 18:16:54 +00001747 if (PathExists(Path)) Paths.push_back(Path);
Chandler Carruthd2deee12011-10-03 05:28:29 +00001748}
1749
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001750/// \brief Get our best guess at the multiarch triple for a target.
1751///
1752/// Debian-based systems are starting to use a multiarch setup where they use
1753/// a target-triple directory in the library and header search paths.
1754/// Unfortunately, this triple does not align with the vanilla target triple,
1755/// so we provide a rough mapping here.
1756static std::string getMultiarchTriple(const llvm::Triple TargetTriple,
1757 StringRef SysRoot) {
1758 // For most architectures, just use whatever we have rather than trying to be
1759 // clever.
1760 switch (TargetTriple.getArch()) {
1761 default:
1762 return TargetTriple.str();
1763
1764 // We use the existence of '/lib/<triple>' as a directory to detect some
1765 // common linux triples that don't quite match the Clang triple for both
Chandler Carruth236e0b62011-10-31 09:06:40 +00001766 // 32-bit and 64-bit targets. Multiarch fixes its install triples to these
1767 // regardless of what the actual target triple is.
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001768 case llvm::Triple::x86:
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001769 if (llvm::sys::fs::exists(SysRoot + "/lib/i386-linux-gnu"))
1770 return "i386-linux-gnu";
1771 return TargetTriple.str();
1772 case llvm::Triple::x86_64:
1773 if (llvm::sys::fs::exists(SysRoot + "/lib/x86_64-linux-gnu"))
1774 return "x86_64-linux-gnu";
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001775 return TargetTriple.str();
1776 }
1777}
1778
Nick Lewycky3fdcc6f2010-12-31 17:31:54 +00001779Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001780 : Generic_ELF(Host, Triple) {
Rafael Espindolac1da9812010-11-07 20:14:31 +00001781 llvm::Triple::ArchType Arch =
1782 llvm::Triple(getDriver().DefaultHostTriple).getArch();
Chandler Carruthfde8d142011-10-03 06:41:08 +00001783 const std::string &SysRoot = getDriver().SysRoot;
Chandler Carruth048e6492011-10-03 18:16:54 +00001784 GCCInstallationDetector GCCInstallation(getDriver());
Rafael Espindolac1da9812010-11-07 20:14:31 +00001785
Rafael Espindolaab784082011-09-01 16:25:49 +00001786 // OpenSuse stores the linker with the compiler, add that to the search
1787 // path.
1788 ToolChain::path_list &PPaths = getProgramPaths();
Chandler Carruth048e6492011-10-03 18:16:54 +00001789 PPaths.push_back(GCCInstallation.getParentLibPath() + "/../" +
1790 GCCInstallation.getTriple() + "/bin");
Rafael Espindolaab784082011-09-01 16:25:49 +00001791
1792 Linker = GetProgramPath("ld");
Rafael Espindolac1da9812010-11-07 20:14:31 +00001793
1794 LinuxDistro Distro = DetectLinuxDistro(Arch);
1795
Chris Lattner64a89172011-05-22 16:45:07 +00001796 if (IsOpenSuse(Distro) || IsUbuntu(Distro)) {
Rafael Espindola94c80222010-11-08 14:48:47 +00001797 ExtraOpts.push_back("-z");
1798 ExtraOpts.push_back("relro");
1799 }
Rafael Espindolac1da9812010-11-07 20:14:31 +00001800
Douglas Gregorf0594d82011-03-06 19:11:49 +00001801 if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001802 ExtraOpts.push_back("-X");
1803
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001804 if (IsRedhat(Distro) || IsOpenSuse(Distro) || Distro == UbuntuMaverick ||
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001805 Distro == UbuntuNatty || Distro == UbuntuOneiric)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001806 ExtraOpts.push_back("--hash-style=gnu");
1807
NAKAMURA Takumi304ed3f2011-06-03 03:49:51 +00001808 if (IsDebian(Distro) || IsOpenSuse(Distro) || Distro == UbuntuLucid ||
Chris Lattner64a89172011-05-22 16:45:07 +00001809 Distro == UbuntuJaunty || Distro == UbuntuKarmic)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001810 ExtraOpts.push_back("--hash-style=both");
1811
Chris Lattnerd753b562011-05-22 05:36:06 +00001812 if (IsRedhat(Distro))
Rafael Espindolac1da9812010-11-07 20:14:31 +00001813 ExtraOpts.push_back("--no-add-needed");
1814
Eli Friedman0b200f62011-06-02 21:36:53 +00001815 if (Distro == DebianSqueeze || Distro == DebianWheezy ||
Rafael Espindola5a640ef2011-06-03 15:23:24 +00001816 IsOpenSuse(Distro) ||
1817 (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) ||
1818 Distro == UbuntuLucid ||
Eli Friedman0b200f62011-06-02 21:36:53 +00001819 Distro == UbuntuMaverick || Distro == UbuntuKarmic ||
Benjamin Kramer25a857b2011-06-05 16:08:59 +00001820 Distro == UbuntuNatty || Distro == UbuntuOneiric)
Rafael Espindolac1da9812010-11-07 20:14:31 +00001821 ExtraOpts.push_back("--build-id");
1822
Chris Lattner64a89172011-05-22 16:45:07 +00001823 if (IsOpenSuse(Distro))
Chandler Carruthf0b60ec2011-05-24 07:51:17 +00001824 ExtraOpts.push_back("--enable-new-dtags");
Chris Lattner64a89172011-05-22 16:45:07 +00001825
Chandler Carruthd2deee12011-10-03 05:28:29 +00001826 // The selection of paths to try here is designed to match the patterns which
1827 // the GCC driver itself uses, as this is part of the GCC-compatible driver.
1828 // This was determined by running GCC in a fake filesystem, creating all
1829 // possible permutations of these directories, and seeing which ones it added
1830 // to the link paths.
1831 path_list &Paths = getFilePaths();
1832 const bool Is32Bits = (getArch() == llvm::Triple::x86 ||
1833 getArch() == llvm::Triple::ppc);
Chandler Carruth3fd345a2011-02-25 06:39:53 +00001834
Chandler Carruthd2deee12011-10-03 05:28:29 +00001835 const std::string Suffix32 = Arch == llvm::Triple::x86_64 ? "/32" : "";
Chandler Carruth38ec5462011-10-03 09:00:50 +00001836 const std::string Suffix64 = Arch == llvm::Triple::x86_64 ? "" : "/64";
Chandler Carruthd2deee12011-10-03 05:28:29 +00001837 const std::string Suffix = Is32Bits ? Suffix32 : Suffix64;
1838 const std::string Multilib = Is32Bits ? "lib32" : "lib64";
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001839 const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot);
Chandler Carruthd2deee12011-10-03 05:28:29 +00001840
1841 // FIXME: Because we add paths only when they exist on the system, I think we
1842 // should remove the concept of 'HasMultilib'. It's more likely to break the
1843 // behavior than to preserve any useful invariant on the system.
Rafael Espindolac1da9812010-11-07 20:14:31 +00001844 if (HasMultilib(Arch, Distro)) {
Chandler Carruthd2deee12011-10-03 05:28:29 +00001845 // Add the multilib suffixed paths.
Chandler Carruth048e6492011-10-03 18:16:54 +00001846 if (GCCInstallation.isValid()) {
1847 const std::string &LibPath = GCCInstallation.getParentLibPath();
1848 const std::string &GccTriple = GCCInstallation.getTriple();
1849 // FIXME: This OpenSuse-specific path shouldn't be needed any more, but
1850 // I don't want to remove it without finding someone to test.
1851 if (IsOpenSuse(Distro) && Is32Bits)
1852 Paths.push_back(LibPath + "/../" + GccTriple + "/lib/../lib");
1853
1854 addPathIfExists(GCCInstallation.getInstallPath() + Suffix, Paths);
1855 addPathIfExists(LibPath + "/../" + GccTriple + "/lib/../" + Multilib,
1856 Paths);
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001857 addPathIfExists(LibPath + "/" + MultiarchTriple, Paths);
Chandler Carruth048e6492011-10-03 18:16:54 +00001858 addPathIfExists(LibPath + "/../" + Multilib, Paths);
Chandler Carruthd2deee12011-10-03 05:28:29 +00001859 }
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001860 addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths);
Chandler Carruthfde8d142011-10-03 06:41:08 +00001861 addPathIfExists(SysRoot + "/lib/../" + Multilib, Paths);
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001862 addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
Chandler Carruthfde8d142011-10-03 06:41:08 +00001863 addPathIfExists(SysRoot + "/usr/lib/../" + Multilib, Paths);
Chandler Carruth7a09d012011-10-16 10:54:30 +00001864
1865 // Try walking via the GCC triple path in case of multiarch GCC
1866 // installations with strange symlinks.
1867 if (GCCInstallation.isValid())
1868 addPathIfExists(SysRoot + "/usr/lib/" + GCCInstallation.getTriple() +
1869 "/../../" + Multilib, Paths);
Rafael Espindolac1da9812010-11-07 20:14:31 +00001870 }
Rafael Espindolac7409a02011-06-03 15:39:42 +00001871
Chandler Carruth7a09d012011-10-16 10:54:30 +00001872 // Add the non-multilib suffixed paths (if potentially different).
Chandler Carruth048e6492011-10-03 18:16:54 +00001873 if (GCCInstallation.isValid()) {
1874 const std::string &LibPath = GCCInstallation.getParentLibPath();
1875 const std::string &GccTriple = GCCInstallation.getTriple();
Chandler Carruth663abc92011-10-03 08:02:58 +00001876 if (!Suffix.empty() || !HasMultilib(Arch, Distro))
Chandler Carruth048e6492011-10-03 18:16:54 +00001877 addPathIfExists(GCCInstallation.getInstallPath(), Paths);
1878 addPathIfExists(LibPath + "/../" + GccTriple + "/lib", Paths);
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001879 addPathIfExists(LibPath + "/" + MultiarchTriple, Paths);
Chandler Carruth048e6492011-10-03 18:16:54 +00001880 addPathIfExists(LibPath, Paths);
Chandler Carruthd2deee12011-10-03 05:28:29 +00001881 }
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001882 addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths);
Chandler Carruthfde8d142011-10-03 06:41:08 +00001883 addPathIfExists(SysRoot + "/lib", Paths);
Chandler Carruthdeb73f82011-10-31 08:42:24 +00001884 addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
Chandler Carruthfde8d142011-10-03 06:41:08 +00001885 addPathIfExists(SysRoot + "/usr/lib", Paths);
Rafael Espindolac1da9812010-11-07 20:14:31 +00001886}
1887
1888bool Linux::HasNativeLLVMSupport() const {
1889 return true;
Eli Friedman6b3454a2009-05-26 07:52:18 +00001890}
1891
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001892Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA,
1893 const ActionList &Inputs) const {
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001894 Action::ActionClass Key;
1895 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1896 Key = Action::AnalyzeJobClass;
1897 else
1898 Key = JA.getKind();
1899
Rafael Espindoladda5b922010-11-07 23:13:01 +00001900 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1901 options::OPT_no_integrated_as,
1902 IsIntegratedAssemblerDefault());
1903
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001904 Tool *&T = Tools[Key];
1905 if (!T) {
1906 switch (Key) {
1907 case Action::AssembleJobClass:
Rafael Espindoladda5b922010-11-07 23:13:01 +00001908 if (UseIntegratedAs)
1909 T = new tools::ClangAs(*this);
1910 else
1911 T = new tools::linuxtools::Assemble(*this);
1912 break;
Rafael Espindolac1da9812010-11-07 20:14:31 +00001913 case Action::LinkJobClass:
1914 T = new tools::linuxtools::Link(*this); break;
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001915 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001916 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Rafael Espindolaba30bbe2010-08-10 00:25:48 +00001917 }
1918 }
1919
1920 return *T;
1921}
1922
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001923/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
1924
Daniel Dunbarcb8ab232009-05-22 02:53:45 +00001925DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
Rafael Espindolae43cfa12010-10-29 20:14:02 +00001926 : Generic_ELF(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001927
1928 // Path mangling to find libexec
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001929 getProgramPaths().push_back(getDriver().getInstalledDir());
Benjamin Kramer86643b82011-03-01 22:50:47 +00001930 if (getDriver().getInstalledDir() != getDriver().Dir)
Daniel Dunbaredf29b02010-08-01 22:29:51 +00001931 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001932
Daniel Dunbaree788e72009-12-21 18:54:17 +00001933 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001934 getFilePaths().push_back("/usr/lib");
1935 getFilePaths().push_back("/usr/lib/gcc41");
1936}
1937
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001938Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA,
1939 const ActionList &Inputs) const {
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001940 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +00001941 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001942 Key = Action::AnalyzeJobClass;
1943 else
1944 Key = JA.getKind();
1945
1946 Tool *&T = Tools[Key];
1947 if (!T) {
1948 switch (Key) {
1949 case Action::AssembleJobClass:
1950 T = new tools::dragonfly::Assemble(*this); break;
1951 case Action::LinkJobClass:
1952 T = new tools::dragonfly::Link(*this); break;
1953 default:
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001954 T = &Generic_GCC::SelectTool(C, JA, Inputs);
Daniel Dunbar11e1b402009-05-02 18:28:39 +00001955 }
1956 }
1957
1958 return *T;
1959}
Michael J. Spencerff58e362010-08-21 21:55:07 +00001960
1961Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple)
1962 : ToolChain(Host, Triple) {
1963}
1964
Daniel Dunbarac0659a2011-03-18 20:14:00 +00001965Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA,
1966 const ActionList &Inputs) const {
Michael J. Spencerff58e362010-08-21 21:55:07 +00001967 Action::ActionClass Key;
1968 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
1969 Key = Action::AnalyzeJobClass;
1970 else
1971 Key = JA.getKind();
1972
Chad Rosierc57114a2011-07-20 19:14:30 +00001973 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as,
1974 options::OPT_no_integrated_as,
1975 IsIntegratedAssemblerDefault());
1976
Michael J. Spencerff58e362010-08-21 21:55:07 +00001977 Tool *&T = Tools[Key];
1978 if (!T) {
1979 switch (Key) {
1980 case Action::InputClass:
1981 case Action::BindArchClass:
Chandler Carruthe97673f2010-08-22 06:56:37 +00001982 case Action::LipoJobClass:
1983 case Action::DsymutilJobClass:
Eric Christopherf8571862011-08-23 17:56:55 +00001984 case Action::VerifyJobClass:
David Blaikieb219cfc2011-09-23 05:06:16 +00001985 llvm_unreachable("Invalid tool kind.");
Michael J. Spencerff58e362010-08-21 21:55:07 +00001986 case Action::PreprocessJobClass:
1987 case Action::PrecompileJobClass:
1988 case Action::AnalyzeJobClass:
1989 case Action::CompileJobClass:
1990 T = new tools::Clang(*this); break;
1991 case Action::AssembleJobClass:
Chad Rosierc57114a2011-07-20 19:14:30 +00001992 if (!UseIntegratedAs && getTriple().getEnvironment() == llvm::Triple::MachO)
1993 T = new tools::darwin::Assemble(*this);
1994 else
1995 T = new tools::ClangAs(*this);
1996 break;
Michael J. Spencerff58e362010-08-21 21:55:07 +00001997 case Action::LinkJobClass:
1998 T = new tools::visualstudio::Link(*this); break;
1999 }
2000 }
2001
2002 return *T;
2003}
2004
2005bool Windows::IsIntegratedAssemblerDefault() const {
2006 return true;
2007}
2008
2009bool Windows::IsUnwindTablesDefault() const {
2010 // FIXME: Gross; we should probably have some separate target
2011 // definition, possibly even reusing the one in clang.
2012 return getArchName() == "x86_64";
2013}
2014
2015const char *Windows::GetDefaultRelocationModel() const {
2016 return "static";
2017}
2018
2019const char *Windows::GetForcedPicModel() const {
2020 if (getArchName() == "x86_64")
2021 return "pic";
2022 return 0;
2023}
Chandler Carruthca234192011-11-04 23:49:05 +00002024
2025// FIXME: This probably should goto to some platform utils place.
2026#ifdef _MSC_VER
2027
2028/// \brief Read registry string.
2029/// This also supports a means to look for high-versioned keys by use
2030/// of a $VERSION placeholder in the key path.
2031/// $VERSION in the key path is a placeholder for the version number,
2032/// causing the highest value path to be searched for and used.
2033/// I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION".
2034/// There can be additional characters in the component. Only the numberic
2035/// characters are compared.
2036static bool getSystemRegistryString(const char *keyPath, const char *valueName,
2037 char *value, size_t maxLength) {
2038 HKEY hRootKey = NULL;
2039 HKEY hKey = NULL;
2040 const char* subKey = NULL;
2041 DWORD valueType;
2042 DWORD valueSize = maxLength - 1;
2043 long lResult;
2044 bool returnValue = false;
2045
2046 if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) {
2047 hRootKey = HKEY_CLASSES_ROOT;
2048 subKey = keyPath + 18;
2049 } else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) {
2050 hRootKey = HKEY_USERS;
2051 subKey = keyPath + 11;
2052 } else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) {
2053 hRootKey = HKEY_LOCAL_MACHINE;
2054 subKey = keyPath + 19;
2055 } else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) {
2056 hRootKey = HKEY_CURRENT_USER;
2057 subKey = keyPath + 18;
2058 } else {
2059 return false;
2060 }
2061
2062 const char *placeHolder = strstr(subKey, "$VERSION");
2063 char bestName[256];
2064 bestName[0] = '\0';
2065 // If we have a $VERSION placeholder, do the highest-version search.
2066 if (placeHolder) {
2067 const char *keyEnd = placeHolder - 1;
2068 const char *nextKey = placeHolder;
2069 // Find end of previous key.
2070 while ((keyEnd > subKey) && (*keyEnd != '\\'))
2071 keyEnd--;
2072 // Find end of key containing $VERSION.
2073 while (*nextKey && (*nextKey != '\\'))
2074 nextKey++;
2075 size_t partialKeyLength = keyEnd - subKey;
2076 char partialKey[256];
2077 if (partialKeyLength > sizeof(partialKey))
2078 partialKeyLength = sizeof(partialKey);
2079 strncpy(partialKey, subKey, partialKeyLength);
2080 partialKey[partialKeyLength] = '\0';
2081 HKEY hTopKey = NULL;
2082 lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey);
2083 if (lResult == ERROR_SUCCESS) {
2084 char keyName[256];
2085 int bestIndex = -1;
2086 double bestValue = 0.0;
2087 DWORD index, size = sizeof(keyName) - 1;
2088 for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL,
2089 NULL, NULL, NULL) == ERROR_SUCCESS; index++) {
2090 const char *sp = keyName;
2091 while (*sp && !isdigit(*sp))
2092 sp++;
2093 if (!*sp)
2094 continue;
2095 const char *ep = sp + 1;
2096 while (*ep && (isdigit(*ep) || (*ep == '.')))
2097 ep++;
2098 char numBuf[32];
2099 strncpy(numBuf, sp, sizeof(numBuf) - 1);
2100 numBuf[sizeof(numBuf) - 1] = '\0';
2101 double value = strtod(numBuf, NULL);
2102 if (value > bestValue) {
2103 bestIndex = (int)index;
2104 bestValue = value;
2105 strcpy(bestName, keyName);
2106 }
2107 size = sizeof(keyName) - 1;
2108 }
2109 // If we found the highest versioned key, open the key and get the value.
2110 if (bestIndex != -1) {
2111 // Append rest of key.
2112 strncat(bestName, nextKey, sizeof(bestName) - 1);
2113 bestName[sizeof(bestName) - 1] = '\0';
2114 // Open the chosen key path remainder.
2115 lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey);
2116 if (lResult == ERROR_SUCCESS) {
2117 lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
2118 (LPBYTE)value, &valueSize);
2119 if (lResult == ERROR_SUCCESS)
2120 returnValue = true;
2121 RegCloseKey(hKey);
2122 }
2123 }
2124 RegCloseKey(hTopKey);
2125 }
2126 } else {
2127 lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey);
2128 if (lResult == ERROR_SUCCESS) {
2129 lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
2130 (LPBYTE)value, &valueSize);
2131 if (lResult == ERROR_SUCCESS)
2132 returnValue = true;
2133 RegCloseKey(hKey);
2134 }
2135 }
2136 return returnValue;
2137}
2138
2139/// \brief Get Windows SDK installation directory.
2140static bool getWindowsSDKDir(std::string &path) {
2141 char windowsSDKInstallDir[256];
2142 // Try the Windows registry.
2143 bool hasSDKDir = getSystemRegistryString(
2144 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
2145 "InstallationFolder",
2146 windowsSDKInstallDir,
2147 sizeof(windowsSDKInstallDir) - 1);
2148 // If we have both vc80 and vc90, pick version we were compiled with.
2149 if (hasSDKDir && windowsSDKInstallDir[0]) {
2150 path = windowsSDKInstallDir;
2151 return true;
2152 }
2153 return false;
2154}
2155
2156 // Get Visual Studio installation directory.
2157static bool getVisualStudioDir(std::string &path) {
2158 // First check the environment variables that vsvars32.bat sets.
2159 const char* vcinstalldir = getenv("VCINSTALLDIR");
2160 if (vcinstalldir) {
2161 char *p = const_cast<char *>(strstr(vcinstalldir, "\\VC"));
2162 if (p)
2163 *p = '\0';
2164 path = vcinstalldir;
2165 return true;
2166 }
2167
2168 char vsIDEInstallDir[256];
2169 char vsExpressIDEInstallDir[256];
2170 // Then try the windows registry.
2171 bool hasVCDir = getSystemRegistryString(
2172 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION",
2173 "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1);
2174 bool hasVCExpressDir = getSystemRegistryString(
2175 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION",
2176 "InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1);
2177 // If we have both vc80 and vc90, pick version we were compiled with.
2178 if (hasVCDir && vsIDEInstallDir[0]) {
2179 char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
2180 if (p)
2181 *p = '\0';
2182 path = vsIDEInstallDir;
2183 return true;
2184 }
2185
2186 if (hasVCExpressDir && vsExpressIDEInstallDir[0]) {
2187 char *p = (char*)strstr(vsExpressIDEInstallDir, "\\Common7\\IDE");
2188 if (p)
2189 *p = '\0';
2190 path = vsExpressIDEInstallDir;
2191 return true;
2192 }
2193
2194 // Try the environment.
2195 const char *vs100comntools = getenv("VS100COMNTOOLS");
2196 const char *vs90comntools = getenv("VS90COMNTOOLS");
2197 const char *vs80comntools = getenv("VS80COMNTOOLS");
2198 const char *vscomntools = NULL;
2199
2200 // Try to find the version that we were compiled with
2201 if(false) {}
2202 #if (_MSC_VER >= 1600) // VC100
2203 else if(vs100comntools) {
2204 vscomntools = vs100comntools;
2205 }
2206 #elif (_MSC_VER == 1500) // VC80
2207 else if(vs90comntools) {
2208 vscomntools = vs90comntools;
2209 }
2210 #elif (_MSC_VER == 1400) // VC80
2211 else if(vs80comntools) {
2212 vscomntools = vs80comntools;
2213 }
2214 #endif
2215 // Otherwise find any version we can
2216 else if (vs100comntools)
2217 vscomntools = vs100comntools;
2218 else if (vs90comntools)
2219 vscomntools = vs90comntools;
2220 else if (vs80comntools)
2221 vscomntools = vs80comntools;
2222
2223 if (vscomntools && *vscomntools) {
2224 const char *p = strstr(vscomntools, "\\Common7\\Tools");
2225 path = p ? std::string(vscomntools, p) : vscomntools;
2226 return true;
2227 }
2228 return false;
2229}
2230
2231// FIXME: Hoist this up, generalize, and document it as more stuff begins using
2232// it.
2233static void addSystemInclude(const ArgList &DriverArgs, ArgStringList &CC1Args,
2234 const Twine &Path) {
2235 CC1Args.push_back("-isystem");
2236 CC1Args.push_back(DriverArgs.MakeArgString(Path));
2237}
2238
2239#endif // _MSC_VER
2240
2241// FIXME: Generalize this and document it as more clients begin to use it.
2242static void addSystemIncludes(const ArgList &DriverArgs,
2243 ArgStringList &CC1Args,
2244 ArrayRef<StringRef> Paths) {
2245 for (ArrayRef<StringRef>::iterator I = Paths.begin(), E = Paths.end();
2246 I != E; ++I) {
2247 CC1Args.push_back("-isystem");
2248 CC1Args.push_back(DriverArgs.MakeArgString(*I));
2249 }
2250}
2251
2252void Windows::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
2253 ArgStringList &CC1Args) const {
2254 std::string VSDir;
2255 std::string WindowsSDKDir;
2256
2257#ifdef _MSC_VER
2258 // When built with access to the proper Windows APIs, try to actually find
2259 // the correct include paths first.
2260 if (getVisualStudioDir(VSDir)) {
2261 addSystemInclude(DriverArgs, CC1Args, VSDir + "\\VC\\include");
2262 if (getWindowsSDKDir(WindowsSDKDir))
2263 addSystemInclude(DriverArgs, CC1Args, WindowsSDKDir + "\\include");
2264 else
2265 addSystemInclude(DriverArgs, CC1Args,
2266 VSDir + "\\VC\\PlatformSDK\\Include");
2267 return;
2268 }
2269#endif // _MSC_VER
2270
2271 // As a fallback, select default install paths.
2272 const StringRef Paths[] = {
2273 "C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
2274 "C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
2275 "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
2276 "C:/Program Files/Microsoft Visual Studio 8/VC/include",
2277 "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
2278 };
2279 addSystemIncludes(DriverArgs, CC1Args, Paths);
2280}
2281
2282void Windows::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
2283 ArgStringList &CC1Args) const {
2284 // FIXME: There should probably be logic here to find libc++ on Windows.
2285}