blob: 3d692b0404012d692a48f74ad56e6ac6bbb8f971 [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,
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000032 const unsigned (&_DarwinVersion)[3], bool _IsIPhoneOS)
33 : ToolChain(Host, Triple),
34 IsIPhoneOS(_IsIPhoneOS)
35{
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000036 DarwinVersion[0] = _DarwinVersion[0];
37 DarwinVersion[1] = _DarwinVersion[1];
38 DarwinVersion[2] = _DarwinVersion[2];
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000039
Daniel Dunbar02633b52009-03-26 16:23:12 +000040 llvm::raw_string_ostream(MacosxVersionMin)
41 << "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1];
42
Daniel Dunbar30392de2009-09-04 18:35:21 +000043 // FIXME: Lift default up.
44 IPhoneOSVersionMin = "3.0";
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000045}
46
47DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
48 const unsigned (&DarwinVersion)[3],
49 const unsigned (&_GCCVersion)[3], bool IsIPhoneOS)
50 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
51{
52 GCCVersion[0] = _GCCVersion[0];
53 GCCVersion[1] = _GCCVersion[1];
54 GCCVersion[2] = _GCCVersion[2];
55
56 // Set up the tool chain paths to match gcc.
Daniel Dunbar30392de2009-09-04 18:35:21 +000057
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000058 ToolChainDir = "i686-apple-darwin";
59 ToolChainDir += llvm::utostr(DarwinVersion[0]);
60 ToolChainDir += "/";
61 ToolChainDir += llvm::utostr(GCCVersion[0]);
62 ToolChainDir += '.';
63 ToolChainDir += llvm::utostr(GCCVersion[1]);
64 ToolChainDir += '.';
65 ToolChainDir += llvm::utostr(GCCVersion[2]);
66
67 std::string Path;
68 if (getArchName() == "x86_64") {
69 Path = getHost().getDriver().Dir;
70 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000071 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000072 Path += "/x86_64";
73 getFilePaths().push_back(Path);
74
75 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000076 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000077 Path += "/x86_64";
78 getFilePaths().push_back(Path);
79 }
Mike Stump1eb44332009-09-09 15:08:12 +000080
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000081 Path = getHost().getDriver().Dir;
82 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000083 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000084 getFilePaths().push_back(Path);
85
86 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000087 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000088 getFilePaths().push_back(Path);
89
90 Path = getHost().getDriver().Dir;
91 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000092 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000093 getProgramPaths().push_back(Path);
94
95 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +000096 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000097 getProgramPaths().push_back(Path);
98
Daniel Dunbar82fa7c52009-03-24 04:07:10 +000099 Path = getHost().getDriver().Dir;
100 Path += "/../libexec";
101 getProgramPaths().push_back(Path);
102
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000103 getProgramPaths().push_back(getHost().getDriver().Dir);
104}
105
Daniel Dunbarf3955282009-09-04 18:34:51 +0000106Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000107 // Free tool implementations.
108 for (llvm::DenseMap<unsigned, Tool*>::iterator
109 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
110 delete it->second;
111}
112
Daniel Dunbarf3955282009-09-04 18:34:51 +0000113Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000114 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000115 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000116 Key = Action::AnalyzeJobClass;
117 else
118 Key = JA.getKind();
119
120 Tool *&T = Tools[Key];
121 if (!T) {
122 switch (Key) {
123 case Action::InputClass:
124 case Action::BindArchClass:
125 assert(0 && "Invalid tool kind.");
126 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000127 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000128 case Action::AnalyzeJobClass:
129 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000130 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000131 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000132 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000133 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000134 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000135 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000136 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000137 case Action::LipoJobClass:
138 T = new tools::darwin::Lipo(*this); break;
139 }
140 }
141
142 return *T;
143}
144
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000145void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
146 ArgStringList &CmdArgs) const {
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000147 // FIXME: Derive these correctly.
148 if (getArchName() == "x86_64") {
149 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
150 "/x86_64"));
151 // Intentionally duplicated for (temporary) gcc bug compatibility.
152 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
153 "/x86_64"));
154 }
155 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
156 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
157 // Intentionally duplicated for (temporary) gcc bug compatibility.
158 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
159 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
160 "/../../../" + ToolChainDir));
161 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
162 "/../../.."));
163}
164
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000165void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
166 ArgStringList &CmdArgs) const {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000167 unsigned MacosxVersionMin[3];
168 getMacosxVersionMin(Args, MacosxVersionMin);
169
170 // Derived from libgcc and lib specs but refactored.
171 if (Args.hasArg(options::OPT_static)) {
172 CmdArgs.push_back("-lgcc_static");
173 } else {
174 if (Args.hasArg(options::OPT_static_libgcc)) {
175 CmdArgs.push_back("-lgcc_eh");
176 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
177 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000178 if (isIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000179 CmdArgs.push_back("-lgcc_s.1");
180 } else {
181 CmdArgs.push_back("-lgcc_s.10.5");
182 }
183 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
184 // FIXME: -fexceptions -fno-exceptions means no exceptions
185 Args.hasArg(options::OPT_fexceptions) ||
186 Args.hasArg(options::OPT_fgnu_runtime)) {
187 // FIXME: This is probably broken on 10.3?
188 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
189 CmdArgs.push_back("-lgcc_s.10.4");
190 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
191 CmdArgs.push_back("-lgcc_s.10.5");
192 } else {
193 if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9))
194 ; // Do nothing.
195 else if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
196 CmdArgs.push_back("-lgcc_s.10.4");
197 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
198 CmdArgs.push_back("-lgcc_s.10.5");
199 }
200
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000201 if (isIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000202 CmdArgs.push_back("-lgcc");
203 CmdArgs.push_back("-lSystem");
204 } else {
205 CmdArgs.push_back("-lSystem");
206 CmdArgs.push_back("-lgcc");
207 }
208 }
209}
210
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000211DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
212 const unsigned (&DarwinVersion)[3],
213 bool IsIPhoneOS)
214 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
215{
216 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
217 getProgramPaths().push_back(getHost().getDriver().Dir);
218}
219
220void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
221 ArgStringList &CmdArgs) const {
222 // The Clang toolchain uses explicit paths for internal libraries.
223}
224
225void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
226 ArgStringList &CmdArgs) const {
227 // Check for static linking.
228 if (Args.hasArg(options::OPT_static)) {
229 // FIXME: We need to have compiler-rt available (perhaps as
230 // libclang_static.a) to link against.
231 return;
232 }
233
234 // Reject -static-libgcc for now, we can deal with this when and if someone
235 // cares. This is useful in situations where someone wants to statically link
236 // something like libstdc++, and needs its runtime support routines.
237 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
238 getHost().getDriver().Diag(clang::diag::err_drv_unsupported_opt)
239 << A->getAsString(Args);
240 return;
241 }
242
243 // Otherwise link libSystem, which should have the support routines.
244 //
245 // FIXME: This is only true for 10.6 and beyond. Legacy support isn't
246 // critical, but it should work... we should just link in the static
247 // compiler-rt library.
248 CmdArgs.push_back("-lSystem");
249}
250
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000251void Darwin::getMacosxVersionMin(const ArgList &Args,
252 unsigned (&Res)[3]) const {
253 if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
254 bool HadExtra;
255 if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2],
256 HadExtra) ||
257 HadExtra) {
258 const Driver &D = getHost().getDriver();
259 D.Diag(clang::diag::err_drv_invalid_version_number)
260 << A->getAsString(Args);
261 }
262 } else
263 return getMacosxVersion(Res);
264}
265
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000266DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
267 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000268 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000269 const OptTable &Opts = getHost().getDriver().getOpts();
270
271 // FIXME: We really want to get out of the tool chain level argument
272 // translation business, as it makes the driver functionality much
273 // more opaque. For now, we follow gcc closely solely for the
274 // purpose of easily achieving feature parity & testability. Once we
275 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000276 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000277
Mike Stump1eb44332009-09-09 15:08:12 +0000278 Arg *OSXVersion =
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000279 Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
280 Arg *iPhoneVersion =
Mike Stump1eb44332009-09-09 15:08:12 +0000281 Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000282 if (OSXVersion && iPhoneVersion) {
283 getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
284 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000285 << iPhoneVersion->getAsString(Args);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000286 } else if (!OSXVersion && !iPhoneVersion) {
287 // Chose the default version based on the arch.
288 //
Daniel Dunbar30392de2009-09-04 18:35:21 +0000289 // FIXME: Are there iPhone overrides for this?
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000290
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000291 if (!isIPhoneOS()) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000292 // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
293 // from the host.
294 const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
295 if (!Version)
296 Version = MacosxVersionMin.c_str();
297 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
298 DAL->append(DAL->MakeJoinedArg(0, O, Version));
299 } else {
300 const char *Version = IPhoneOSVersionMin.c_str();
301 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
302 DAL->append(DAL->MakeJoinedArg(0, O, Version));
303 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000304 }
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000306 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
307 Arg *A = *it;
308
309 if (A->getOption().matches(options::OPT_Xarch__)) {
310 // FIXME: Canonicalize name.
311 if (getArchName() != A->getValue(Args, 0))
312 continue;
313
314 // FIXME: The arg is leaked here, and we should have a nicer
315 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000316 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000317 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000318
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000319 // If the argument parsing failed or more than one argument was
320 // consumed, the -Xarch_ argument's parameter tried to consume
321 // extra arguments. Emit an error and ignore.
322 //
323 // We also want to disallow any options which would alter the
324 // driver behavior; that isn't going to work in our model. We
325 // use isDriverOption() as an approximation, although things
326 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000327 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000328 XarchArg->getOption().isDriverOption()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000329 getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000330 << A->getAsString(Args);
331 continue;
332 }
333
Daniel Dunbar478edc22009-03-29 22:29:05 +0000334 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000335 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000336 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000337
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000338 // Sob. These is strictly gcc compatible for the time being. Apple
339 // gcc translates options twice, which means that self-expanding
340 // options add duplicates.
341 options::ID id = A->getOption().getId();
342 switch (id) {
343 default:
344 DAL->append(A);
345 break;
346
347 case options::OPT_mkernel:
348 case options::OPT_fapple_kext:
349 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000350 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
351 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000352 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000353
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000354 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000355 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000356 A->getValue(Args)));
357 break;
358
359 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000360 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
361 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000362 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
363 break;
364
365 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000366 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
367 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000368 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
369 break;
370
371 case options::OPT_fterminated_vtables:
372 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000373 DAL->append(DAL->MakeFlagArg(A,
374 Opts.getOption(options::OPT_fapple_kext)));
375 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000376 break;
377
378 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000379 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000380 break;
381
382 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000383 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000384 Opts.getOption(options::OPT_mconstant_cfstrings)));
385 break;
386
387 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000388 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000389 Opts.getOption(options::OPT_mno_constant_cfstrings)));
390 break;
391
392 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000393 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000394 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
395 break;
396
397 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000398 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000399 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
400 break;
401
402 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000403 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000404 Opts.getOption(options::OPT_mpascal_strings)));
405 break;
406
407 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000408 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000409 Opts.getOption(options::OPT_mno_pascal_strings)));
410 break;
411 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000412 }
413
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000414 if (getTriple().getArch() == llvm::Triple::x86 ||
415 getTriple().getArch() == llvm::Triple::x86_64)
416 if (!Args.hasArg(options::OPT_mtune_EQ, false))
417 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
418 "core2"));
419
420 // Add the arch options based on the particular spelling of -arch, to match
421 // how the driver driver works.
422 if (BoundArch) {
423 llvm::StringRef Name = BoundArch;
424 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
425 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
426
427 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
428 // which defines the list of which architectures we accept.
429 if (Name == "ppc")
430 ;
431 else if (Name == "ppc601")
432 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
433 else if (Name == "ppc603")
434 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
435 else if (Name == "ppc604")
436 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
437 else if (Name == "ppc604e")
438 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
439 else if (Name == "ppc750")
440 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
441 else if (Name == "ppc7400")
442 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
443 else if (Name == "ppc7450")
444 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
445 else if (Name == "ppc970")
446 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
447
448 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000449 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000450
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000451 else if (Name == "i386")
452 ;
453 else if (Name == "i486")
454 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
455 else if (Name == "i586")
456 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
457 else if (Name == "i686")
458 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
459 else if (Name == "pentium")
460 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
461 else if (Name == "pentium2")
462 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
463 else if (Name == "pentpro")
464 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
465 else if (Name == "pentIIm3")
466 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
467
468 else if (Name == "x86_64")
469 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
470
471 else if (Name == "arm")
472 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
473 else if (Name == "armv4t")
474 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
475 else if (Name == "armv5")
476 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
477 else if (Name == "xscale")
478 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
479 else if (Name == "armv6")
480 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
481 else if (Name == "armv7")
482 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
483
484 else
485 llvm::llvm_unreachable("invalid Darwin arch");
486 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000487
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000488 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000489}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000490
Daniel Dunbarf3955282009-09-04 18:34:51 +0000491bool Darwin::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000492 return false;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000493}
494
Daniel Dunbarf3955282009-09-04 18:34:51 +0000495bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000496 // FIXME: Gross; we should probably have some separate target
497 // definition, possibly even reusing the one in clang.
498 return getArchName() == "x86_64";
499}
500
Daniel Dunbarf3955282009-09-04 18:34:51 +0000501const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000502 return "pic";
503}
504
Daniel Dunbarf3955282009-09-04 18:34:51 +0000505const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000506 if (getArchName() == "x86_64")
507 return "pic";
508 return 0;
509}
510
Daniel Dunbar39176082009-03-20 00:20:03 +0000511/// Generic_GCC - A tool chain using the 'gcc' command to perform
512/// all subcommands; this relies on gcc translating the majority of
513/// command line options.
514
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000515Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000516 : ToolChain(Host, Triple) {
Daniel Dunbar82fa7c52009-03-24 04:07:10 +0000517 std::string Path(getHost().getDriver().Dir);
518 Path += "/../libexec";
519 getProgramPaths().push_back(Path);
520
Mike Stump1eb44332009-09-09 15:08:12 +0000521 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000522}
523
Daniel Dunbar39176082009-03-20 00:20:03 +0000524Generic_GCC::~Generic_GCC() {
525 // Free tool implementations.
526 for (llvm::DenseMap<unsigned, Tool*>::iterator
527 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
528 delete it->second;
529}
530
Mike Stump1eb44332009-09-09 15:08:12 +0000531Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000532 const JobAction &JA) const {
533 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000534 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000535 Key = Action::AnalyzeJobClass;
536 else
537 Key = JA.getKind();
538
539 Tool *&T = Tools[Key];
540 if (!T) {
541 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000542 case Action::InputClass:
543 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000544 assert(0 && "Invalid tool kind.");
545 case Action::PreprocessJobClass:
546 T = new tools::gcc::Preprocess(*this); break;
547 case Action::PrecompileJobClass:
548 T = new tools::gcc::Precompile(*this); break;
549 case Action::AnalyzeJobClass:
550 T = new tools::Clang(*this); break;
551 case Action::CompileJobClass:
552 T = new tools::gcc::Compile(*this); break;
553 case Action::AssembleJobClass:
554 T = new tools::gcc::Assemble(*this); break;
555 case Action::LinkJobClass:
556 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000557
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000558 // This is a bit ungeneric, but the only platform using a driver
559 // driver is Darwin.
560 case Action::LipoJobClass:
561 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000562 }
563 }
564
565 return *T;
566}
567
Daniel Dunbarf3955282009-09-04 18:34:51 +0000568bool Generic_GCC::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000569 return true;
Daniel Dunbar39176082009-03-20 00:20:03 +0000570}
571
572bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000573 // FIXME: Gross; we should probably have some separate target
574 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000575 return getArchName() == "x86_64";
576}
577
578const char *Generic_GCC::GetDefaultRelocationModel() const {
579 return "static";
580}
581
582const char *Generic_GCC::GetForcedPicModel() const {
583 return 0;
584}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000585
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000586DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
587 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000588 return new DerivedArgList(Args, true);
589}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000590
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000591/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
592
593OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
594 : Generic_GCC(Host, Triple) {
595 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
596 getFilePaths().push_back("/usr/lib");
597}
598
599Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
600 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000601 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000602 Key = Action::AnalyzeJobClass;
603 else
604 Key = JA.getKind();
605
606 Tool *&T = Tools[Key];
607 if (!T) {
608 switch (Key) {
609 case Action::AssembleJobClass:
610 T = new tools::openbsd::Assemble(*this); break;
611 case Action::LinkJobClass:
612 T = new tools::openbsd::Link(*this); break;
613 default:
614 T = &Generic_GCC::SelectTool(C, JA);
615 }
616 }
617
618 return *T;
619}
620
Daniel Dunbar75358d22009-03-30 21:06:03 +0000621/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
622
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000623FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
624 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000625 if (Lib32) {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000626 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000627 getFilePaths().push_back("/usr/lib32");
628 } else {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000629 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000630 getFilePaths().push_back("/usr/lib");
631 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000632}
633
634Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
635 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000636 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000637 Key = Action::AnalyzeJobClass;
638 else
639 Key = JA.getKind();
640
641 Tool *&T = Tools[Key];
642 if (!T) {
643 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000644 case Action::AssembleJobClass:
645 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000646 case Action::LinkJobClass:
647 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000648 default:
649 T = &Generic_GCC::SelectTool(C, JA);
650 }
651 }
652
653 return *T;
654}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000655
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000656/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
657
658AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
659 : Generic_GCC(Host, Triple) {
660
661 // Path mangling to find libexec
662 std::string Path(getHost().getDriver().Dir);
663
664 Path += "/../libexec";
665 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000666 getProgramPaths().push_back(getHost().getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000667
668 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
669 getFilePaths().push_back("/usr/lib");
670 getFilePaths().push_back("/usr/sfw/lib");
671 getFilePaths().push_back("/opt/gcc4/lib");
672
673}
674
675Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
676 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000677 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000678 Key = Action::AnalyzeJobClass;
679 else
680 Key = JA.getKind();
681
682 Tool *&T = Tools[Key];
683 if (!T) {
684 switch (Key) {
685 case Action::AssembleJobClass:
686 T = new tools::auroraux::Assemble(*this); break;
687 case Action::LinkJobClass:
688 T = new tools::auroraux::Link(*this); break;
689 default:
690 T = &Generic_GCC::SelectTool(C, JA);
691 }
692 }
693
694 return *T;
695}
696
697
Eli Friedman6b3454a2009-05-26 07:52:18 +0000698/// Linux toolchain (very bare-bones at the moment).
699
700Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
701 : Generic_GCC(Host, Triple) {
702 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/");
703 getFilePaths().push_back("/lib/");
704 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000705
706 // Depending on the Linux distribution, any combination of lib{,32,64} is
707 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
708 // openSUSE uses lib and lib64 for the same purpose.
709 getFilePaths().push_back("/lib32/");
710 getFilePaths().push_back("/usr/lib32/");
711 getFilePaths().push_back("/lib64/");
712 getFilePaths().push_back("/usr/lib64/");
713
Eli Friedman6b3454a2009-05-26 07:52:18 +0000714 // FIXME: Figure out some way to get gcc's libdir
715 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
716 // crtbegin.o/crtend.o/etc., and want static versions of various
717 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
718 // get away with using shared versions in /usr/lib, though.
719 // We could fall back to the approach we used for includes (a massive
720 // list), but that's messy at best.
721}
722
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000723/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
724
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000725DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
726 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000727
728 // Path mangling to find libexec
729 std::string Path(getHost().getDriver().Dir);
730
731 Path += "/../libexec";
732 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000733 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000734
735 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
736 getFilePaths().push_back("/usr/lib");
737 getFilePaths().push_back("/usr/lib/gcc41");
738}
739
740Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
741 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000742 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000743 Key = Action::AnalyzeJobClass;
744 else
745 Key = JA.getKind();
746
747 Tool *&T = Tools[Key];
748 if (!T) {
749 switch (Key) {
750 case Action::AssembleJobClass:
751 T = new tools::dragonfly::Assemble(*this); break;
752 case Action::LinkJobClass:
753 T = new tools::dragonfly::Link(*this); break;
754 default:
755 T = &Generic_GCC::SelectTool(C, JA);
756 }
757 }
758
759 return *T;
760}