ToolChains.cpp revision a194695df4e2812e0ceb8f92f52902bb534bbcde
1//===--- 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
12#include "clang/Driver/Arg.h"
13#include "clang/Driver/ArgList.h"
14#include "clang/Driver/Driver.h"
15#include "clang/Driver/DriverDiagnostic.h"
16#include "clang/Driver/HostInfo.h"
17#include "clang/Driver/Option.h"
18
19#include "llvm/ADT/StringExtras.h"
20#include "llvm/Support/ErrorHandling.h"
21#include "llvm/Support/raw_ostream.h"
22#include "llvm/System/Path.h"
23
24#include <cstdlib> // ::getenv
25
26using namespace clang::driver;
27using namespace clang::driver::toolchains;
28
29/// Darwin - Darwin tool chain for i386 and x86_64.
30
31Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
32               const unsigned (&_DarwinVersion)[3], bool _IsIPhoneOS)
33  : ToolChain(Host, Triple),
34    IsIPhoneOS(_IsIPhoneOS)
35{
36  DarwinVersion[0] = _DarwinVersion[0];
37  DarwinVersion[1] = _DarwinVersion[1];
38  DarwinVersion[2] = _DarwinVersion[2];
39
40  llvm::raw_string_ostream(MacosxVersionMin)
41    << "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1];
42
43  // FIXME: Lift default up.
44  IPhoneOSVersionMin = "3.0";
45}
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.
57
58  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/";
71    Path += ToolChainDir;
72    Path += "/x86_64";
73    getFilePaths().push_back(Path);
74
75    Path = "/usr/lib/gcc/";
76    Path += ToolChainDir;
77    Path += "/x86_64";
78    getFilePaths().push_back(Path);
79  }
80
81  Path = getHost().getDriver().Dir;
82  Path += "/../lib/gcc/";
83  Path += ToolChainDir;
84  getFilePaths().push_back(Path);
85
86  Path = "/usr/lib/gcc/";
87  Path += ToolChainDir;
88  getFilePaths().push_back(Path);
89
90  Path = getHost().getDriver().Dir;
91  Path += "/../libexec/gcc/";
92  Path += ToolChainDir;
93  getProgramPaths().push_back(Path);
94
95  Path = "/usr/libexec/gcc/";
96  Path += ToolChainDir;
97  getProgramPaths().push_back(Path);
98
99  Path = getHost().getDriver().Dir;
100  Path += "/../libexec";
101  getProgramPaths().push_back(Path);
102
103  getProgramPaths().push_back(getHost().getDriver().Dir);
104}
105
106Darwin::~Darwin() {
107  // 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
113Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
114  Action::ActionClass Key;
115  if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
116    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:
127      T = new tools::darwin::Preprocess(*this); break;
128    case Action::AnalyzeJobClass:
129      T = new tools::Clang(*this); break;
130    case Action::PrecompileJobClass:
131    case Action::CompileJobClass:
132      T = new tools::darwin::Compile(*this); break;
133    case Action::AssembleJobClass:
134      T = new tools::darwin::Assemble(*this); break;
135    case Action::LinkJobClass:
136      T = new tools::darwin::Link(*this); break;
137    case Action::LipoJobClass:
138      T = new tools::darwin::Lipo(*this); break;
139    }
140  }
141
142  return *T;
143}
144
145void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
146                                      ArgStringList &CmdArgs) const {
147  // 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
165void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
166                                      ArgStringList &CmdArgs) const {
167  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.
178      if (isIPhoneOS()) {
179        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
201    if (isIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
202      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
211DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
212                         const unsigned (&DarwinVersion)[3],
213                         bool IsIPhoneOS)
214  : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
215{
216  // Add the relative libexec dir (for clang-cc).
217  //
218  // FIXME: We should sink clang-cc into libexec/clang/<version>/.
219  std::string Path = getHost().getDriver().Dir;
220  Path += "/../libexec";
221  getProgramPaths().push_back(Path);
222
223  // We expect 'as', 'ld', etc. to be adjacent to our install dir.
224  getProgramPaths().push_back(getHost().getDriver().Dir);
225}
226
227void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
228                                       ArgStringList &CmdArgs) const {
229  // The Clang toolchain uses explicit paths for internal libraries.
230}
231
232void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
233                                        ArgStringList &CmdArgs) const {
234  // Check for static linking.
235  if (Args.hasArg(options::OPT_static)) {
236    // FIXME: We need to have compiler-rt available (perhaps as
237    // libclang_static.a) to link against.
238    return;
239  }
240
241  // Reject -static-libgcc for now, we can deal with this when and if someone
242  // cares. This is useful in situations where someone wants to statically link
243  // something like libstdc++, and needs its runtime support routines.
244  if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
245    getHost().getDriver().Diag(clang::diag::err_drv_unsupported_opt)
246      << A->getAsString(Args);
247    return;
248  }
249
250  // Otherwise link libSystem, which should have the support routines.
251  //
252  // FIXME: This is only true for 10.6 and beyond. Legacy support isn't
253  // critical, but it should work... we should just link in the static
254  // compiler-rt library.
255  CmdArgs.push_back("-lSystem");
256}
257
258void Darwin::getMacosxVersionMin(const ArgList &Args,
259                                 unsigned (&Res)[3]) const {
260  if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
261    bool HadExtra;
262    if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2],
263                                   HadExtra) ||
264        HadExtra) {
265      const Driver &D = getHost().getDriver();
266      D.Diag(clang::diag::err_drv_invalid_version_number)
267        << A->getAsString(Args);
268    }
269  } else
270    return getMacosxVersion(Res);
271}
272
273DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
274                                      const char *BoundArch) const {
275  DerivedArgList *DAL = new DerivedArgList(Args, false);
276  const OptTable &Opts = getHost().getDriver().getOpts();
277
278  // FIXME: We really want to get out of the tool chain level argument
279  // translation business, as it makes the driver functionality much
280  // more opaque. For now, we follow gcc closely solely for the
281  // purpose of easily achieving feature parity & testability. Once we
282  // have something that works, we should reevaluate each translation
283  // and try to push it down into tool specific logic.
284
285  Arg *OSXVersion =
286    Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
287  Arg *iPhoneVersion =
288    Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
289  if (OSXVersion && iPhoneVersion) {
290    getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
291          << OSXVersion->getAsString(Args)
292          << iPhoneVersion->getAsString(Args);
293  } else if (!OSXVersion && !iPhoneVersion) {
294    // Chose the default version based on the arch.
295    //
296    // FIXME: Are there iPhone overrides for this?
297
298    if (!isIPhoneOS()) {
299      // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
300      // from the host.
301      const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
302      if (!Version)
303        Version = MacosxVersionMin.c_str();
304      const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
305      DAL->append(DAL->MakeJoinedArg(0, O, Version));
306    } else {
307      const char *Version = IPhoneOSVersionMin.c_str();
308      const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
309      DAL->append(DAL->MakeJoinedArg(0, O, Version));
310    }
311  }
312
313  for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
314    Arg *A = *it;
315
316    if (A->getOption().matches(options::OPT_Xarch__)) {
317      // FIXME: Canonicalize name.
318      if (getArchName() != A->getValue(Args, 0))
319        continue;
320
321      // FIXME: The arg is leaked here, and we should have a nicer
322      // interface for this.
323      unsigned Prev, Index = Prev = A->getIndex() + 1;
324      Arg *XarchArg = Opts.ParseOneArg(Args, Index);
325
326      // If the argument parsing failed or more than one argument was
327      // consumed, the -Xarch_ argument's parameter tried to consume
328      // extra arguments. Emit an error and ignore.
329      //
330      // We also want to disallow any options which would alter the
331      // driver behavior; that isn't going to work in our model. We
332      // use isDriverOption() as an approximation, although things
333      // like -O4 are going to slip through.
334      if (!XarchArg || Index > Prev + 1 ||
335          XarchArg->getOption().isDriverOption()) {
336       getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
337          << A->getAsString(Args);
338        continue;
339      }
340
341      XarchArg->setBaseArg(A);
342      A = XarchArg;
343    }
344
345    // Sob. These is strictly gcc compatible for the time being. Apple
346    // gcc translates options twice, which means that self-expanding
347    // options add duplicates.
348    options::ID id = A->getOption().getId();
349    switch (id) {
350    default:
351      DAL->append(A);
352      break;
353
354    case options::OPT_mkernel:
355    case options::OPT_fapple_kext:
356      DAL->append(A);
357      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
358      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
359      break;
360
361    case options::OPT_dependency_file:
362      DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
363                                       A->getValue(Args)));
364      break;
365
366    case options::OPT_gfull:
367      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
368      DAL->append(DAL->MakeFlagArg(A,
369             Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
370      break;
371
372    case options::OPT_gused:
373      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
374      DAL->append(DAL->MakeFlagArg(A,
375             Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
376      break;
377
378    case options::OPT_fterminated_vtables:
379    case options::OPT_findirect_virtual_calls:
380      DAL->append(DAL->MakeFlagArg(A,
381                                   Opts.getOption(options::OPT_fapple_kext)));
382      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
383      break;
384
385    case options::OPT_shared:
386      DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
387      break;
388
389    case options::OPT_fconstant_cfstrings:
390      DAL->append(DAL->MakeFlagArg(A,
391                             Opts.getOption(options::OPT_mconstant_cfstrings)));
392      break;
393
394    case options::OPT_fno_constant_cfstrings:
395      DAL->append(DAL->MakeFlagArg(A,
396                          Opts.getOption(options::OPT_mno_constant_cfstrings)));
397      break;
398
399    case options::OPT_Wnonportable_cfstrings:
400      DAL->append(DAL->MakeFlagArg(A,
401                     Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
402      break;
403
404    case options::OPT_Wno_nonportable_cfstrings:
405      DAL->append(DAL->MakeFlagArg(A,
406                  Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
407      break;
408
409    case options::OPT_fpascal_strings:
410      DAL->append(DAL->MakeFlagArg(A,
411                                 Opts.getOption(options::OPT_mpascal_strings)));
412      break;
413
414    case options::OPT_fno_pascal_strings:
415      DAL->append(DAL->MakeFlagArg(A,
416                              Opts.getOption(options::OPT_mno_pascal_strings)));
417      break;
418    }
419  }
420
421  if (getTriple().getArch() == llvm::Triple::x86 ||
422      getTriple().getArch() == llvm::Triple::x86_64)
423    if (!Args.hasArg(options::OPT_mtune_EQ, false))
424      DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
425                                     "core2"));
426
427  // Add the arch options based on the particular spelling of -arch, to match
428  // how the driver driver works.
429  if (BoundArch) {
430    llvm::StringRef Name = BoundArch;
431    const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
432    const Option *MArch = Opts.getOption(options::OPT_march_EQ);
433
434    // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
435    // which defines the list of which architectures we accept.
436    if (Name == "ppc")
437      ;
438    else if (Name == "ppc601")
439      DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
440    else if (Name == "ppc603")
441      DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
442    else if (Name == "ppc604")
443      DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
444    else if (Name == "ppc604e")
445      DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
446    else if (Name == "ppc750")
447      DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
448    else if (Name == "ppc7400")
449      DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
450    else if (Name == "ppc7450")
451      DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
452    else if (Name == "ppc970")
453      DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
454
455    else if (Name == "ppc64")
456      DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
457
458    else if (Name == "i386")
459      ;
460    else if (Name == "i486")
461      DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
462    else if (Name == "i586")
463      DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
464    else if (Name == "i686")
465      DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
466    else if (Name == "pentium")
467      DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
468    else if (Name == "pentium2")
469      DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
470    else if (Name == "pentpro")
471      DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
472    else if (Name == "pentIIm3")
473      DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
474
475    else if (Name == "x86_64")
476      DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
477
478    else if (Name == "arm")
479      DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
480    else if (Name == "armv4t")
481      DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
482    else if (Name == "armv5")
483      DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
484    else if (Name == "xscale")
485      DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
486    else if (Name == "armv6")
487      DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
488    else if (Name == "armv7")
489      DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
490
491    else
492      llvm::llvm_unreachable("invalid Darwin arch");
493  }
494
495  return DAL;
496}
497
498bool Darwin::IsMathErrnoDefault() const {
499  return false;
500}
501
502bool Darwin::IsUnwindTablesDefault() const {
503  // FIXME: Gross; we should probably have some separate target
504  // definition, possibly even reusing the one in clang.
505  return getArchName() == "x86_64";
506}
507
508const char *Darwin::GetDefaultRelocationModel() const {
509  return "pic";
510}
511
512const char *Darwin::GetForcedPicModel() const {
513  if (getArchName() == "x86_64")
514    return "pic";
515  return 0;
516}
517
518/// Generic_GCC - A tool chain using the 'gcc' command to perform
519/// all subcommands; this relies on gcc translating the majority of
520/// command line options.
521
522Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
523  : ToolChain(Host, Triple) {
524  std::string Path(getHost().getDriver().Dir);
525  Path += "/../libexec";
526  getProgramPaths().push_back(Path);
527
528  getProgramPaths().push_back(getHost().getDriver().Dir);
529}
530
531Generic_GCC::~Generic_GCC() {
532  // Free tool implementations.
533  for (llvm::DenseMap<unsigned, Tool*>::iterator
534         it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
535    delete it->second;
536}
537
538Tool &Generic_GCC::SelectTool(const Compilation &C,
539                              const JobAction &JA) const {
540  Action::ActionClass Key;
541  if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
542    Key = Action::AnalyzeJobClass;
543  else
544    Key = JA.getKind();
545
546  Tool *&T = Tools[Key];
547  if (!T) {
548    switch (Key) {
549    case Action::InputClass:
550    case Action::BindArchClass:
551      assert(0 && "Invalid tool kind.");
552    case Action::PreprocessJobClass:
553      T = new tools::gcc::Preprocess(*this); break;
554    case Action::PrecompileJobClass:
555      T = new tools::gcc::Precompile(*this); break;
556    case Action::AnalyzeJobClass:
557      T = new tools::Clang(*this); break;
558    case Action::CompileJobClass:
559      T = new tools::gcc::Compile(*this); break;
560    case Action::AssembleJobClass:
561      T = new tools::gcc::Assemble(*this); break;
562    case Action::LinkJobClass:
563      T = new tools::gcc::Link(*this); break;
564
565      // This is a bit ungeneric, but the only platform using a driver
566      // driver is Darwin.
567    case Action::LipoJobClass:
568      T = new tools::darwin::Lipo(*this); break;
569    }
570  }
571
572  return *T;
573}
574
575bool Generic_GCC::IsMathErrnoDefault() const {
576  return true;
577}
578
579bool Generic_GCC::IsUnwindTablesDefault() const {
580  // FIXME: Gross; we should probably have some separate target
581  // definition, possibly even reusing the one in clang.
582  return getArchName() == "x86_64";
583}
584
585const char *Generic_GCC::GetDefaultRelocationModel() const {
586  return "static";
587}
588
589const char *Generic_GCC::GetForcedPicModel() const {
590  return 0;
591}
592
593DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
594                                           const char *BoundArch) const {
595  return new DerivedArgList(Args, true);
596}
597
598/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
599
600OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
601  : Generic_GCC(Host, Triple) {
602  getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
603  getFilePaths().push_back("/usr/lib");
604}
605
606Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
607  Action::ActionClass Key;
608  if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
609    Key = Action::AnalyzeJobClass;
610  else
611    Key = JA.getKind();
612
613  Tool *&T = Tools[Key];
614  if (!T) {
615    switch (Key) {
616    case Action::AssembleJobClass:
617      T = new tools::openbsd::Assemble(*this); break;
618    case Action::LinkJobClass:
619      T = new tools::openbsd::Link(*this); break;
620    default:
621      T = &Generic_GCC::SelectTool(C, JA);
622    }
623  }
624
625  return *T;
626}
627
628/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
629
630FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
631  : Generic_GCC(Host, Triple) {
632  if (Lib32) {
633    getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
634    getFilePaths().push_back("/usr/lib32");
635  } else {
636    getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
637    getFilePaths().push_back("/usr/lib");
638  }
639}
640
641Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
642  Action::ActionClass Key;
643  if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
644    Key = Action::AnalyzeJobClass;
645  else
646    Key = JA.getKind();
647
648  Tool *&T = Tools[Key];
649  if (!T) {
650    switch (Key) {
651    case Action::AssembleJobClass:
652      T = new tools::freebsd::Assemble(*this); break;
653    case Action::LinkJobClass:
654      T = new tools::freebsd::Link(*this); break;
655    default:
656      T = &Generic_GCC::SelectTool(C, JA);
657    }
658  }
659
660  return *T;
661}
662
663/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
664
665AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
666  : Generic_GCC(Host, Triple) {
667
668  // Path mangling to find libexec
669  std::string Path(getHost().getDriver().Dir);
670
671  Path += "/../libexec";
672  getProgramPaths().push_back(Path);
673  getProgramPaths().push_back(getHost().getDriver().Dir);
674
675  getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
676  getFilePaths().push_back("/usr/lib");
677  getFilePaths().push_back("/usr/sfw/lib");
678  getFilePaths().push_back("/opt/gcc4/lib");
679  getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
680
681}
682
683Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
684  Action::ActionClass Key;
685  if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
686    Key = Action::AnalyzeJobClass;
687  else
688    Key = JA.getKind();
689
690  Tool *&T = Tools[Key];
691  if (!T) {
692    switch (Key) {
693    case Action::AssembleJobClass:
694      T = new tools::auroraux::Assemble(*this); break;
695    case Action::LinkJobClass:
696      T = new tools::auroraux::Link(*this); break;
697    default:
698      T = &Generic_GCC::SelectTool(C, JA);
699    }
700  }
701
702  return *T;
703}
704
705
706/// Linux toolchain (very bare-bones at the moment).
707
708Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
709  : Generic_GCC(Host, Triple) {
710  getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/");
711  getFilePaths().push_back("/lib/");
712  getFilePaths().push_back("/usr/lib/");
713
714  // Depending on the Linux distribution, any combination of lib{,32,64} is
715  // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
716  // openSUSE uses lib and lib64 for the same purpose.
717  getFilePaths().push_back("/lib32/");
718  getFilePaths().push_back("/usr/lib32/");
719  getFilePaths().push_back("/lib64/");
720  getFilePaths().push_back("/usr/lib64/");
721
722  // FIXME: Figure out some way to get gcc's libdir
723  // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
724  // crtbegin.o/crtend.o/etc., and want static versions of various
725  // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
726  // get away with using shared versions in /usr/lib, though.
727  // We could fall back to the approach we used for includes (a massive
728  // list), but that's messy at best.
729}
730
731/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
732
733DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
734  : Generic_GCC(Host, Triple) {
735
736  // Path mangling to find libexec
737  std::string Path(getHost().getDriver().Dir);
738
739  Path += "/../libexec";
740  getProgramPaths().push_back(Path);
741  getProgramPaths().push_back(getHost().getDriver().Dir);
742
743  getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
744  getFilePaths().push_back("/usr/lib");
745  getFilePaths().push_back("/usr/lib/gcc41");
746}
747
748Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
749  Action::ActionClass Key;
750  if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
751    Key = Action::AnalyzeJobClass;
752  else
753    Key = JA.getKind();
754
755  Tool *&T = Tools[Key];
756  if (!T) {
757    switch (Key) {
758    case Action::AssembleJobClass:
759      T = new tools::dragonfly::Assemble(*this); break;
760    case Action::LinkJobClass:
761      T = new tools::dragonfly::Link(*this); break;
762    default:
763      T = &Generic_GCC::SelectTool(C, JA);
764    }
765  }
766
767  return *T;
768}
769