blob: 5db58c1691ff8bf3a4c9176d35e89e08767febab [file] [log] [blame]
Daniel Dunbar39176082009-03-20 00:20:03 +00001//===--- ToolChains.cpp - ToolChain Implementations ---------------------*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "ToolChains.h"
11
Daniel Dunbarf3cad362009-03-25 04:13:45 +000012#include "clang/Driver/Arg.h"
13#include "clang/Driver/ArgList.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000014#include "clang/Driver/Driver.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000015#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000016#include "clang/Driver/HostInfo.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000017#include "clang/Driver/Option.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000018
19#include "llvm/ADT/StringExtras.h"
Daniel Dunbar84ec96c2009-09-09 22:33:15 +000020#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000021#include "llvm/Support/raw_ostream.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000022#include "llvm/System/Path.h"
23
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000024#include <cstdlib> // ::getenv
25
Daniel Dunbar39176082009-03-20 00:20:03 +000026using namespace clang::driver;
27using namespace clang::driver::toolchains;
28
Daniel Dunbarf3955282009-09-04 18:34:51 +000029/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000030
Daniel Dunbarf3955282009-09-04 18:34:51 +000031Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
32 const unsigned (&_DarwinVersion)[3],
Daniel Dunbar30392de2009-09-04 18:35:21 +000033 const unsigned (&_GCCVersion)[3],
34 bool _IsIPhone)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000035 : ToolChain(Host, Triple) {
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000036 DarwinVersion[0] = _DarwinVersion[0];
37 DarwinVersion[1] = _DarwinVersion[1];
38 DarwinVersion[2] = _DarwinVersion[2];
39 GCCVersion[0] = _GCCVersion[0];
40 GCCVersion[1] = _GCCVersion[1];
41 GCCVersion[2] = _GCCVersion[2];
Daniel Dunbar30392de2009-09-04 18:35:21 +000042 IsIPhone = _IsIPhone;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000043
Daniel Dunbar02633b52009-03-26 16:23:12 +000044 llvm::raw_string_ostream(MacosxVersionMin)
45 << "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1];
46
Daniel Dunbar30392de2009-09-04 18:35:21 +000047 // FIXME: Lift default up.
48 IPhoneOSVersionMin = "3.0";
49
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000050 ToolChainDir = "i686-apple-darwin";
51 ToolChainDir += llvm::utostr(DarwinVersion[0]);
52 ToolChainDir += "/";
53 ToolChainDir += llvm::utostr(GCCVersion[0]);
54 ToolChainDir += '.';
55 ToolChainDir += llvm::utostr(GCCVersion[1]);
56 ToolChainDir += '.';
57 ToolChainDir += llvm::utostr(GCCVersion[2]);
58
59 std::string Path;
60 if (getArchName() == "x86_64") {
61 Path = getHost().getDriver().Dir;
62 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000063 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000064 Path += "/x86_64";
65 getFilePaths().push_back(Path);
66
67 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000068 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000069 Path += "/x86_64";
70 getFilePaths().push_back(Path);
71 }
Mike Stump1eb44332009-09-09 15:08:12 +000072
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000073 Path = getHost().getDriver().Dir;
74 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000075 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000076 getFilePaths().push_back(Path);
77
78 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000079 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000080 getFilePaths().push_back(Path);
81
82 Path = getHost().getDriver().Dir;
83 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000084 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000085 getProgramPaths().push_back(Path);
86
87 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000088 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000089 getProgramPaths().push_back(Path);
90
Daniel Dunbar82fa7c52009-03-24 04:07:10 +000091 Path = getHost().getDriver().Dir;
92 Path += "/../libexec";
93 getProgramPaths().push_back(Path);
94
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000095 getProgramPaths().push_back(getHost().getDriver().Dir);
96}
97
Daniel Dunbarf3955282009-09-04 18:34:51 +000098Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000099 // Free tool implementations.
100 for (llvm::DenseMap<unsigned, Tool*>::iterator
101 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
102 delete it->second;
103}
104
Daniel Dunbarf3955282009-09-04 18:34:51 +0000105Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000106 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000107 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000108 Key = Action::AnalyzeJobClass;
109 else
110 Key = JA.getKind();
111
112 Tool *&T = Tools[Key];
113 if (!T) {
114 switch (Key) {
115 case Action::InputClass:
116 case Action::BindArchClass:
117 assert(0 && "Invalid tool kind.");
118 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000119 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000120 case Action::AnalyzeJobClass:
121 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000122 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000123 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000124 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000125 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000126 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000127 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000128 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000129 case Action::LipoJobClass:
130 T = new tools::darwin::Lipo(*this); break;
131 }
132 }
133
134 return *T;
135}
136
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000137void Darwin::AddLinkSearchPathArgs(const ArgList &Args,
138 ArgStringList &CmdArgs) const {
139 // FIXME: Derive these correctly.
140 if (getArchName() == "x86_64") {
141 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
142 "/x86_64"));
143 // Intentionally duplicated for (temporary) gcc bug compatibility.
144 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
145 "/x86_64"));
146 }
147 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
148 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
149 // Intentionally duplicated for (temporary) gcc bug compatibility.
150 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
151 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
152 "/../../../" + ToolChainDir));
153 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
154 "/../../.."));
155}
156
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000157void Darwin::AddLinkRuntimeLibArgs(const ArgList &Args,
158 ArgStringList &CmdArgs) const {
159 unsigned MacosxVersionMin[3];
160 getMacosxVersionMin(Args, MacosxVersionMin);
161
162 // Derived from libgcc and lib specs but refactored.
163 if (Args.hasArg(options::OPT_static)) {
164 CmdArgs.push_back("-lgcc_static");
165 } else {
166 if (Args.hasArg(options::OPT_static_libgcc)) {
167 CmdArgs.push_back("-lgcc_eh");
168 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
169 // Derived from darwin_iphoneos_libgcc spec.
170 if (isIPhone()) {
171 CmdArgs.push_back("-lgcc_s.1");
172 } else {
173 CmdArgs.push_back("-lgcc_s.10.5");
174 }
175 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
176 // FIXME: -fexceptions -fno-exceptions means no exceptions
177 Args.hasArg(options::OPT_fexceptions) ||
178 Args.hasArg(options::OPT_fgnu_runtime)) {
179 // FIXME: This is probably broken on 10.3?
180 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
181 CmdArgs.push_back("-lgcc_s.10.4");
182 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
183 CmdArgs.push_back("-lgcc_s.10.5");
184 } else {
185 if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9))
186 ; // Do nothing.
187 else if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
188 CmdArgs.push_back("-lgcc_s.10.4");
189 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
190 CmdArgs.push_back("-lgcc_s.10.5");
191 }
192
193 if (isIPhone() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
194 CmdArgs.push_back("-lgcc");
195 CmdArgs.push_back("-lSystem");
196 } else {
197 CmdArgs.push_back("-lSystem");
198 CmdArgs.push_back("-lgcc");
199 }
200 }
201}
202
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000203void Darwin::getMacosxVersionMin(const ArgList &Args,
204 unsigned (&Res)[3]) const {
205 if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
206 bool HadExtra;
207 if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2],
208 HadExtra) ||
209 HadExtra) {
210 const Driver &D = getHost().getDriver();
211 D.Diag(clang::diag::err_drv_invalid_version_number)
212 << A->getAsString(Args);
213 }
214 } else
215 return getMacosxVersion(Res);
216}
217
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000218DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
219 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000220 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000221 const OptTable &Opts = getHost().getDriver().getOpts();
222
223 // FIXME: We really want to get out of the tool chain level argument
224 // translation business, as it makes the driver functionality much
225 // more opaque. For now, we follow gcc closely solely for the
226 // purpose of easily achieving feature parity & testability. Once we
227 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000228 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000229
Mike Stump1eb44332009-09-09 15:08:12 +0000230 Arg *OSXVersion =
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000231 Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
232 Arg *iPhoneVersion =
Mike Stump1eb44332009-09-09 15:08:12 +0000233 Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000234 if (OSXVersion && iPhoneVersion) {
235 getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
236 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000237 << iPhoneVersion->getAsString(Args);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000238 } else if (!OSXVersion && !iPhoneVersion) {
239 // Chose the default version based on the arch.
240 //
Daniel Dunbar30392de2009-09-04 18:35:21 +0000241 // FIXME: Are there iPhone overrides for this?
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000242
Daniel Dunbar30392de2009-09-04 18:35:21 +0000243 if (!isIPhone()) {
244 // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
245 // from the host.
246 const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
247 if (!Version)
248 Version = MacosxVersionMin.c_str();
249 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
250 DAL->append(DAL->MakeJoinedArg(0, O, Version));
251 } else {
252 const char *Version = IPhoneOSVersionMin.c_str();
253 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
254 DAL->append(DAL->MakeJoinedArg(0, O, Version));
255 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000256 }
Mike Stump1eb44332009-09-09 15:08:12 +0000257
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000258 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
259 Arg *A = *it;
260
261 if (A->getOption().matches(options::OPT_Xarch__)) {
262 // FIXME: Canonicalize name.
263 if (getArchName() != A->getValue(Args, 0))
264 continue;
265
266 // FIXME: The arg is leaked here, and we should have a nicer
267 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000268 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000269 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000270
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000271 // If the argument parsing failed or more than one argument was
272 // consumed, the -Xarch_ argument's parameter tried to consume
273 // extra arguments. Emit an error and ignore.
274 //
275 // We also want to disallow any options which would alter the
276 // driver behavior; that isn't going to work in our model. We
277 // use isDriverOption() as an approximation, although things
278 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000279 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000280 XarchArg->getOption().isDriverOption()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000281 getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000282 << A->getAsString(Args);
283 continue;
284 }
285
Daniel Dunbar478edc22009-03-29 22:29:05 +0000286 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000287 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000288 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000289
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000290 // Sob. These is strictly gcc compatible for the time being. Apple
291 // gcc translates options twice, which means that self-expanding
292 // options add duplicates.
293 options::ID id = A->getOption().getId();
294 switch (id) {
295 default:
296 DAL->append(A);
297 break;
298
299 case options::OPT_mkernel:
300 case options::OPT_fapple_kext:
301 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000302 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
303 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000304 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000306 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000307 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000308 A->getValue(Args)));
309 break;
310
311 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000312 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
313 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000314 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
315 break;
316
317 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000318 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
319 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000320 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
321 break;
322
323 case options::OPT_fterminated_vtables:
324 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000325 DAL->append(DAL->MakeFlagArg(A,
326 Opts.getOption(options::OPT_fapple_kext)));
327 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000328 break;
329
330 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000331 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000332 break;
333
334 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000335 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000336 Opts.getOption(options::OPT_mconstant_cfstrings)));
337 break;
338
339 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000340 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000341 Opts.getOption(options::OPT_mno_constant_cfstrings)));
342 break;
343
344 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000345 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000346 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
347 break;
348
349 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000350 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000351 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
352 break;
353
354 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000355 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000356 Opts.getOption(options::OPT_mpascal_strings)));
357 break;
358
359 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000360 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000361 Opts.getOption(options::OPT_mno_pascal_strings)));
362 break;
363 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000364 }
365
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000366 if (getTriple().getArch() == llvm::Triple::x86 ||
367 getTriple().getArch() == llvm::Triple::x86_64)
368 if (!Args.hasArg(options::OPT_mtune_EQ, false))
369 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
370 "core2"));
371
372 // Add the arch options based on the particular spelling of -arch, to match
373 // how the driver driver works.
374 if (BoundArch) {
375 llvm::StringRef Name = BoundArch;
376 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
377 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
378
379 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
380 // which defines the list of which architectures we accept.
381 if (Name == "ppc")
382 ;
383 else if (Name == "ppc601")
384 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
385 else if (Name == "ppc603")
386 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
387 else if (Name == "ppc604")
388 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
389 else if (Name == "ppc604e")
390 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
391 else if (Name == "ppc750")
392 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
393 else if (Name == "ppc7400")
394 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
395 else if (Name == "ppc7450")
396 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
397 else if (Name == "ppc970")
398 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
399
400 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000401 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000402
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000403 else if (Name == "i386")
404 ;
405 else if (Name == "i486")
406 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
407 else if (Name == "i586")
408 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
409 else if (Name == "i686")
410 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
411 else if (Name == "pentium")
412 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
413 else if (Name == "pentium2")
414 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
415 else if (Name == "pentpro")
416 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
417 else if (Name == "pentIIm3")
418 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
419
420 else if (Name == "x86_64")
421 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
422
423 else if (Name == "arm")
424 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
425 else if (Name == "armv4t")
426 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
427 else if (Name == "armv5")
428 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
429 else if (Name == "xscale")
430 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
431 else if (Name == "armv6")
432 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
433 else if (Name == "armv7")
434 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
435
436 else
437 llvm::llvm_unreachable("invalid Darwin arch");
438 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000439
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000440 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000441}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000442
Daniel Dunbarf3955282009-09-04 18:34:51 +0000443bool Darwin::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000444 return false;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000445}
446
Daniel Dunbarf3955282009-09-04 18:34:51 +0000447bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000448 // FIXME: Gross; we should probably have some separate target
449 // definition, possibly even reusing the one in clang.
450 return getArchName() == "x86_64";
451}
452
Daniel Dunbarf3955282009-09-04 18:34:51 +0000453const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000454 return "pic";
455}
456
Daniel Dunbarf3955282009-09-04 18:34:51 +0000457const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000458 if (getArchName() == "x86_64")
459 return "pic";
460 return 0;
461}
462
Daniel Dunbar39176082009-03-20 00:20:03 +0000463/// Generic_GCC - A tool chain using the 'gcc' command to perform
464/// all subcommands; this relies on gcc translating the majority of
465/// command line options.
466
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000467Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000468 : ToolChain(Host, Triple) {
Daniel Dunbar82fa7c52009-03-24 04:07:10 +0000469 std::string Path(getHost().getDriver().Dir);
470 Path += "/../libexec";
471 getProgramPaths().push_back(Path);
472
Mike Stump1eb44332009-09-09 15:08:12 +0000473 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000474}
475
Daniel Dunbar39176082009-03-20 00:20:03 +0000476Generic_GCC::~Generic_GCC() {
477 // Free tool implementations.
478 for (llvm::DenseMap<unsigned, Tool*>::iterator
479 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
480 delete it->second;
481}
482
Mike Stump1eb44332009-09-09 15:08:12 +0000483Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000484 const JobAction &JA) const {
485 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000486 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000487 Key = Action::AnalyzeJobClass;
488 else
489 Key = JA.getKind();
490
491 Tool *&T = Tools[Key];
492 if (!T) {
493 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000494 case Action::InputClass:
495 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000496 assert(0 && "Invalid tool kind.");
497 case Action::PreprocessJobClass:
498 T = new tools::gcc::Preprocess(*this); break;
499 case Action::PrecompileJobClass:
500 T = new tools::gcc::Precompile(*this); break;
501 case Action::AnalyzeJobClass:
502 T = new tools::Clang(*this); break;
503 case Action::CompileJobClass:
504 T = new tools::gcc::Compile(*this); break;
505 case Action::AssembleJobClass:
506 T = new tools::gcc::Assemble(*this); break;
507 case Action::LinkJobClass:
508 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000509
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000510 // This is a bit ungeneric, but the only platform using a driver
511 // driver is Darwin.
512 case Action::LipoJobClass:
513 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000514 }
515 }
516
517 return *T;
518}
519
Daniel Dunbarf3955282009-09-04 18:34:51 +0000520bool Generic_GCC::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000521 return true;
Daniel Dunbar39176082009-03-20 00:20:03 +0000522}
523
524bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000525 // FIXME: Gross; we should probably have some separate target
526 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000527 return getArchName() == "x86_64";
528}
529
530const char *Generic_GCC::GetDefaultRelocationModel() const {
531 return "static";
532}
533
534const char *Generic_GCC::GetForcedPicModel() const {
535 return 0;
536}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000537
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000538DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
539 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000540 return new DerivedArgList(Args, true);
541}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000542
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000543/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
544
545OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
546 : Generic_GCC(Host, Triple) {
547 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
548 getFilePaths().push_back("/usr/lib");
549}
550
551Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
552 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000553 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000554 Key = Action::AnalyzeJobClass;
555 else
556 Key = JA.getKind();
557
558 Tool *&T = Tools[Key];
559 if (!T) {
560 switch (Key) {
561 case Action::AssembleJobClass:
562 T = new tools::openbsd::Assemble(*this); break;
563 case Action::LinkJobClass:
564 T = new tools::openbsd::Link(*this); break;
565 default:
566 T = &Generic_GCC::SelectTool(C, JA);
567 }
568 }
569
570 return *T;
571}
572
Daniel Dunbar75358d22009-03-30 21:06:03 +0000573/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
574
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000575FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
576 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000577 if (Lib32) {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000578 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000579 getFilePaths().push_back("/usr/lib32");
580 } else {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000581 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000582 getFilePaths().push_back("/usr/lib");
583 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000584}
585
586Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
587 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000588 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000589 Key = Action::AnalyzeJobClass;
590 else
591 Key = JA.getKind();
592
593 Tool *&T = Tools[Key];
594 if (!T) {
595 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000596 case Action::AssembleJobClass:
597 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000598 case Action::LinkJobClass:
599 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000600 default:
601 T = &Generic_GCC::SelectTool(C, JA);
602 }
603 }
604
605 return *T;
606}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000607
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000608/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
609
610AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
611 : Generic_GCC(Host, Triple) {
612
613 // Path mangling to find libexec
614 std::string Path(getHost().getDriver().Dir);
615
616 Path += "/../libexec";
617 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000618 getProgramPaths().push_back(getHost().getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000619
620 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
621 getFilePaths().push_back("/usr/lib");
622 getFilePaths().push_back("/usr/sfw/lib");
623 getFilePaths().push_back("/opt/gcc4/lib");
624
625}
626
627Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
628 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000629 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000630 Key = Action::AnalyzeJobClass;
631 else
632 Key = JA.getKind();
633
634 Tool *&T = Tools[Key];
635 if (!T) {
636 switch (Key) {
637 case Action::AssembleJobClass:
638 T = new tools::auroraux::Assemble(*this); break;
639 case Action::LinkJobClass:
640 T = new tools::auroraux::Link(*this); break;
641 default:
642 T = &Generic_GCC::SelectTool(C, JA);
643 }
644 }
645
646 return *T;
647}
648
649
Eli Friedman6b3454a2009-05-26 07:52:18 +0000650/// Linux toolchain (very bare-bones at the moment).
651
652Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
653 : Generic_GCC(Host, Triple) {
654 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/");
655 getFilePaths().push_back("/lib/");
656 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000657
658 // Depending on the Linux distribution, any combination of lib{,32,64} is
659 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
660 // openSUSE uses lib and lib64 for the same purpose.
661 getFilePaths().push_back("/lib32/");
662 getFilePaths().push_back("/usr/lib32/");
663 getFilePaths().push_back("/lib64/");
664 getFilePaths().push_back("/usr/lib64/");
665
Eli Friedman6b3454a2009-05-26 07:52:18 +0000666 // FIXME: Figure out some way to get gcc's libdir
667 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
668 // crtbegin.o/crtend.o/etc., and want static versions of various
669 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
670 // get away with using shared versions in /usr/lib, though.
671 // We could fall back to the approach we used for includes (a massive
672 // list), but that's messy at best.
673}
674
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000675/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
676
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000677DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
678 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000679
680 // Path mangling to find libexec
681 std::string Path(getHost().getDriver().Dir);
682
683 Path += "/../libexec";
684 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000685 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000686
687 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
688 getFilePaths().push_back("/usr/lib");
689 getFilePaths().push_back("/usr/lib/gcc41");
690}
691
692Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
693 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000694 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000695 Key = Action::AnalyzeJobClass;
696 else
697 Key = JA.getKind();
698
699 Tool *&T = Tools[Key];
700 if (!T) {
701 switch (Key) {
702 case Action::AssembleJobClass:
703 T = new tools::dragonfly::Assemble(*this); break;
704 case Action::LinkJobClass:
705 T = new tools::dragonfly::Link(*this); break;
706 default:
707 T = &Generic_GCC::SelectTool(C, JA);
708 }
709 }
710
711 return *T;
712}