blob: deb06720f4978b5fe1289ec83de240317086c92a [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 Dunbar0dcb9a32009-09-09 18:36:12 +0000157DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
158 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000159 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000160 const OptTable &Opts = getHost().getDriver().getOpts();
161
162 // FIXME: We really want to get out of the tool chain level argument
163 // translation business, as it makes the driver functionality much
164 // more opaque. For now, we follow gcc closely solely for the
165 // purpose of easily achieving feature parity & testability. Once we
166 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000167 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000168
Mike Stump1eb44332009-09-09 15:08:12 +0000169 Arg *OSXVersion =
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000170 Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
171 Arg *iPhoneVersion =
Mike Stump1eb44332009-09-09 15:08:12 +0000172 Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000173 if (OSXVersion && iPhoneVersion) {
174 getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
175 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000176 << iPhoneVersion->getAsString(Args);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000177 } else if (!OSXVersion && !iPhoneVersion) {
178 // Chose the default version based on the arch.
179 //
Daniel Dunbar30392de2009-09-04 18:35:21 +0000180 // FIXME: Are there iPhone overrides for this?
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000181
Daniel Dunbar30392de2009-09-04 18:35:21 +0000182 if (!isIPhone()) {
183 // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
184 // from the host.
185 const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
186 if (!Version)
187 Version = MacosxVersionMin.c_str();
188 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
189 DAL->append(DAL->MakeJoinedArg(0, O, Version));
190 } else {
191 const char *Version = IPhoneOSVersionMin.c_str();
192 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
193 DAL->append(DAL->MakeJoinedArg(0, O, Version));
194 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000195 }
Mike Stump1eb44332009-09-09 15:08:12 +0000196
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000197 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
198 Arg *A = *it;
199
200 if (A->getOption().matches(options::OPT_Xarch__)) {
201 // FIXME: Canonicalize name.
202 if (getArchName() != A->getValue(Args, 0))
203 continue;
204
205 // FIXME: The arg is leaked here, and we should have a nicer
206 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000207 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000208 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000209
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000210 // If the argument parsing failed or more than one argument was
211 // consumed, the -Xarch_ argument's parameter tried to consume
212 // extra arguments. Emit an error and ignore.
213 //
214 // We also want to disallow any options which would alter the
215 // driver behavior; that isn't going to work in our model. We
216 // use isDriverOption() as an approximation, although things
217 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000218 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000219 XarchArg->getOption().isDriverOption()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000220 getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000221 << A->getAsString(Args);
222 continue;
223 }
224
Daniel Dunbar478edc22009-03-29 22:29:05 +0000225 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000226 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000227 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000228
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000229 // Sob. These is strictly gcc compatible for the time being. Apple
230 // gcc translates options twice, which means that self-expanding
231 // options add duplicates.
232 options::ID id = A->getOption().getId();
233 switch (id) {
234 default:
235 DAL->append(A);
236 break;
237
238 case options::OPT_mkernel:
239 case options::OPT_fapple_kext:
240 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000241 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
242 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000243 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000244
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000245 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000246 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000247 A->getValue(Args)));
248 break;
249
250 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000251 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
252 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000253 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
254 break;
255
256 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000257 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
258 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000259 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
260 break;
261
262 case options::OPT_fterminated_vtables:
263 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000264 DAL->append(DAL->MakeFlagArg(A,
265 Opts.getOption(options::OPT_fapple_kext)));
266 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000267 break;
268
269 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000270 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000271 break;
272
273 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000274 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000275 Opts.getOption(options::OPT_mconstant_cfstrings)));
276 break;
277
278 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000279 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000280 Opts.getOption(options::OPT_mno_constant_cfstrings)));
281 break;
282
283 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000284 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000285 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
286 break;
287
288 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000289 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000290 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
291 break;
292
293 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000294 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000295 Opts.getOption(options::OPT_mpascal_strings)));
296 break;
297
298 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000299 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000300 Opts.getOption(options::OPT_mno_pascal_strings)));
301 break;
302 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000303 }
304
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000305 if (getTriple().getArch() == llvm::Triple::x86 ||
306 getTriple().getArch() == llvm::Triple::x86_64)
307 if (!Args.hasArg(options::OPT_mtune_EQ, false))
308 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
309 "core2"));
310
311 // Add the arch options based on the particular spelling of -arch, to match
312 // how the driver driver works.
313 if (BoundArch) {
314 llvm::StringRef Name = BoundArch;
315 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
316 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
317
318 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
319 // which defines the list of which architectures we accept.
320 if (Name == "ppc")
321 ;
322 else if (Name == "ppc601")
323 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
324 else if (Name == "ppc603")
325 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
326 else if (Name == "ppc604")
327 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
328 else if (Name == "ppc604e")
329 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
330 else if (Name == "ppc750")
331 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
332 else if (Name == "ppc7400")
333 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
334 else if (Name == "ppc7450")
335 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
336 else if (Name == "ppc970")
337 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
338
339 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000340 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000341
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000342 else if (Name == "i386")
343 ;
344 else if (Name == "i486")
345 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
346 else if (Name == "i586")
347 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
348 else if (Name == "i686")
349 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
350 else if (Name == "pentium")
351 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
352 else if (Name == "pentium2")
353 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
354 else if (Name == "pentpro")
355 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
356 else if (Name == "pentIIm3")
357 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
358
359 else if (Name == "x86_64")
360 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
361
362 else if (Name == "arm")
363 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
364 else if (Name == "armv4t")
365 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
366 else if (Name == "armv5")
367 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
368 else if (Name == "xscale")
369 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
370 else if (Name == "armv6")
371 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
372 else if (Name == "armv7")
373 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
374
375 else
376 llvm::llvm_unreachable("invalid Darwin arch");
377 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000378
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000379 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000380}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000381
Daniel Dunbarf3955282009-09-04 18:34:51 +0000382bool Darwin::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000383 return false;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000384}
385
Daniel Dunbarf3955282009-09-04 18:34:51 +0000386bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000387 // FIXME: Gross; we should probably have some separate target
388 // definition, possibly even reusing the one in clang.
389 return getArchName() == "x86_64";
390}
391
Daniel Dunbarf3955282009-09-04 18:34:51 +0000392const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000393 return "pic";
394}
395
Daniel Dunbarf3955282009-09-04 18:34:51 +0000396const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000397 if (getArchName() == "x86_64")
398 return "pic";
399 return 0;
400}
401
Daniel Dunbar39176082009-03-20 00:20:03 +0000402/// Generic_GCC - A tool chain using the 'gcc' command to perform
403/// all subcommands; this relies on gcc translating the majority of
404/// command line options.
405
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000406Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000407 : ToolChain(Host, Triple) {
Daniel Dunbar82fa7c52009-03-24 04:07:10 +0000408 std::string Path(getHost().getDriver().Dir);
409 Path += "/../libexec";
410 getProgramPaths().push_back(Path);
411
Mike Stump1eb44332009-09-09 15:08:12 +0000412 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000413}
414
Daniel Dunbar39176082009-03-20 00:20:03 +0000415Generic_GCC::~Generic_GCC() {
416 // Free tool implementations.
417 for (llvm::DenseMap<unsigned, Tool*>::iterator
418 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
419 delete it->second;
420}
421
Mike Stump1eb44332009-09-09 15:08:12 +0000422Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000423 const JobAction &JA) const {
424 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000425 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000426 Key = Action::AnalyzeJobClass;
427 else
428 Key = JA.getKind();
429
430 Tool *&T = Tools[Key];
431 if (!T) {
432 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000433 case Action::InputClass:
434 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000435 assert(0 && "Invalid tool kind.");
436 case Action::PreprocessJobClass:
437 T = new tools::gcc::Preprocess(*this); break;
438 case Action::PrecompileJobClass:
439 T = new tools::gcc::Precompile(*this); break;
440 case Action::AnalyzeJobClass:
441 T = new tools::Clang(*this); break;
442 case Action::CompileJobClass:
443 T = new tools::gcc::Compile(*this); break;
444 case Action::AssembleJobClass:
445 T = new tools::gcc::Assemble(*this); break;
446 case Action::LinkJobClass:
447 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000448
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000449 // This is a bit ungeneric, but the only platform using a driver
450 // driver is Darwin.
451 case Action::LipoJobClass:
452 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000453 }
454 }
455
456 return *T;
457}
458
Daniel Dunbarf3955282009-09-04 18:34:51 +0000459bool Generic_GCC::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000460 return true;
Daniel Dunbar39176082009-03-20 00:20:03 +0000461}
462
463bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000464 // FIXME: Gross; we should probably have some separate target
465 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000466 return getArchName() == "x86_64";
467}
468
469const char *Generic_GCC::GetDefaultRelocationModel() const {
470 return "static";
471}
472
473const char *Generic_GCC::GetForcedPicModel() const {
474 return 0;
475}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000476
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000477DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
478 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000479 return new DerivedArgList(Args, true);
480}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000481
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000482/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
483
484OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
485 : Generic_GCC(Host, Triple) {
486 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
487 getFilePaths().push_back("/usr/lib");
488}
489
490Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
491 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000492 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000493 Key = Action::AnalyzeJobClass;
494 else
495 Key = JA.getKind();
496
497 Tool *&T = Tools[Key];
498 if (!T) {
499 switch (Key) {
500 case Action::AssembleJobClass:
501 T = new tools::openbsd::Assemble(*this); break;
502 case Action::LinkJobClass:
503 T = new tools::openbsd::Link(*this); break;
504 default:
505 T = &Generic_GCC::SelectTool(C, JA);
506 }
507 }
508
509 return *T;
510}
511
Daniel Dunbar75358d22009-03-30 21:06:03 +0000512/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
513
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000514FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
515 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000516 if (Lib32) {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000517 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000518 getFilePaths().push_back("/usr/lib32");
519 } else {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000520 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000521 getFilePaths().push_back("/usr/lib");
522 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000523}
524
525Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
526 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000527 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000528 Key = Action::AnalyzeJobClass;
529 else
530 Key = JA.getKind();
531
532 Tool *&T = Tools[Key];
533 if (!T) {
534 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000535 case Action::AssembleJobClass:
536 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000537 case Action::LinkJobClass:
538 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000539 default:
540 T = &Generic_GCC::SelectTool(C, JA);
541 }
542 }
543
544 return *T;
545}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000546
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000547/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
548
549AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
550 : Generic_GCC(Host, Triple) {
551
552 // Path mangling to find libexec
553 std::string Path(getHost().getDriver().Dir);
554
555 Path += "/../libexec";
556 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000557 getProgramPaths().push_back(getHost().getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000558
559 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
560 getFilePaths().push_back("/usr/lib");
561 getFilePaths().push_back("/usr/sfw/lib");
562 getFilePaths().push_back("/opt/gcc4/lib");
563
564}
565
566Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
567 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000568 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000569 Key = Action::AnalyzeJobClass;
570 else
571 Key = JA.getKind();
572
573 Tool *&T = Tools[Key];
574 if (!T) {
575 switch (Key) {
576 case Action::AssembleJobClass:
577 T = new tools::auroraux::Assemble(*this); break;
578 case Action::LinkJobClass:
579 T = new tools::auroraux::Link(*this); break;
580 default:
581 T = &Generic_GCC::SelectTool(C, JA);
582 }
583 }
584
585 return *T;
586}
587
588
Eli Friedman6b3454a2009-05-26 07:52:18 +0000589/// Linux toolchain (very bare-bones at the moment).
590
591Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
592 : Generic_GCC(Host, Triple) {
593 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/");
594 getFilePaths().push_back("/lib/");
595 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000596
597 // Depending on the Linux distribution, any combination of lib{,32,64} is
598 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
599 // openSUSE uses lib and lib64 for the same purpose.
600 getFilePaths().push_back("/lib32/");
601 getFilePaths().push_back("/usr/lib32/");
602 getFilePaths().push_back("/lib64/");
603 getFilePaths().push_back("/usr/lib64/");
604
Eli Friedman6b3454a2009-05-26 07:52:18 +0000605 // FIXME: Figure out some way to get gcc's libdir
606 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
607 // crtbegin.o/crtend.o/etc., and want static versions of various
608 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
609 // get away with using shared versions in /usr/lib, though.
610 // We could fall back to the approach we used for includes (a massive
611 // list), but that's messy at best.
612}
613
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000614/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
615
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000616DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
617 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000618
619 // Path mangling to find libexec
620 std::string Path(getHost().getDriver().Dir);
621
622 Path += "/../libexec";
623 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000624 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000625
626 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
627 getFilePaths().push_back("/usr/lib");
628 getFilePaths().push_back("/usr/lib/gcc41");
629}
630
631Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
632 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000633 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000634 Key = Action::AnalyzeJobClass;
635 else
636 Key = JA.getKind();
637
638 Tool *&T = Tools[Key];
639 if (!T) {
640 switch (Key) {
641 case Action::AssembleJobClass:
642 T = new tools::dragonfly::Assemble(*this); break;
643 case Action::LinkJobClass:
644 T = new tools::dragonfly::Link(*this); break;
645 default:
646 T = &Generic_GCC::SelectTool(C, JA);
647 }
648 }
649
650 return *T;
651}