clang  3.8.0
ToolChain.cpp
Go to the documentation of this file.
1 //===--- ToolChain.cpp - Collections of tools for one platform ------------===//
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 "Tools.h"
12 #include "clang/Driver/Action.h"
13 #include "clang/Driver/Driver.h"
15 #include "clang/Driver/Options.h"
17 #include "clang/Driver/ToolChain.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/Option/Arg.h"
21 #include "llvm/Option/ArgList.h"
22 #include "llvm/Option/Option.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/FileSystem.h"
25 #include "llvm/Support/TargetRegistry.h"
26 #include "llvm/Support/TargetParser.h"
27 
28 using namespace clang::driver;
29 using namespace clang::driver::tools;
30 using namespace clang;
31 using namespace llvm;
32 using namespace llvm::opt;
33 
34 static llvm::opt::Arg *GetRTTIArgument(const ArgList &Args) {
35  return Args.getLastArg(options::OPT_mkernel, options::OPT_fapple_kext,
36  options::OPT_fno_rtti, options::OPT_frtti);
37 }
38 
39 static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args,
40  const llvm::Triple &Triple,
41  const Arg *CachedRTTIArg) {
42  // Explicit rtti/no-rtti args
43  if (CachedRTTIArg) {
44  if (CachedRTTIArg->getOption().matches(options::OPT_frtti))
46  else
48  }
49 
50  // -frtti is default, except for the PS4 CPU.
51  if (!Triple.isPS4CPU())
53 
54  // On the PS4, turning on c++ exceptions turns on rtti.
55  // We're assuming that, if we see -fexceptions, rtti gets turned on.
56  Arg *Exceptions = Args.getLastArgNoClaim(
57  options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,
58  options::OPT_fexceptions, options::OPT_fno_exceptions);
59  if (Exceptions &&
60  (Exceptions->getOption().matches(options::OPT_fexceptions) ||
61  Exceptions->getOption().matches(options::OPT_fcxx_exceptions)))
63 
65 }
66 
67 ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
68  const ArgList &Args)
69  : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
70  CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
71  if (Arg *A = Args.getLastArg(options::OPT_mthread_model))
72  if (!isThreadModelSupported(A->getValue()))
73  D.Diag(diag::err_drv_invalid_thread_model_for_target)
74  << A->getValue() << A->getAsString(Args);
75 }
76 
78 }
79 
81 
83  return Args.hasFlag(options::OPT_fintegrated_as,
84  options::OPT_fno_integrated_as,
86 }
87 
89  if (!SanitizerArguments.get())
90  SanitizerArguments.reset(new SanitizerArgs(*this, Args));
91  return *SanitizerArguments.get();
92 }
93 
94 namespace {
95 struct DriverSuffix {
96  const char *Suffix;
97  const char *ModeFlag;
98 };
99 
100 const DriverSuffix *FindDriverSuffix(StringRef ProgName) {
101  // A list of known driver suffixes. Suffixes are compared against the
102  // program name in order. If there is a match, the frontend type is updated as
103  // necessary by applying the ModeFlag.
104  static const DriverSuffix DriverSuffixes[] = {
105  {"clang", nullptr},
106  {"clang++", "--driver-mode=g++"},
107  {"clang-c++", "--driver-mode=g++"},
108  {"clang-cc", nullptr},
109  {"clang-cpp", "--driver-mode=cpp"},
110  {"clang-g++", "--driver-mode=g++"},
111  {"clang-gcc", nullptr},
112  {"clang-cl", "--driver-mode=cl"},
113  {"cc", nullptr},
114  {"cpp", "--driver-mode=cpp"},
115  {"cl", "--driver-mode=cl"},
116  {"++", "--driver-mode=g++"},
117  };
118 
119  for (size_t i = 0; i < llvm::array_lengthof(DriverSuffixes); ++i)
120  if (ProgName.endswith(DriverSuffixes[i].Suffix))
121  return &DriverSuffixes[i];
122  return nullptr;
123 }
124 
125 /// Normalize the program name from argv[0] by stripping the file extension if
126 /// present and lower-casing the string on Windows.
127 std::string normalizeProgramName(llvm::StringRef Argv0) {
128  std::string ProgName = llvm::sys::path::stem(Argv0);
129 #ifdef LLVM_ON_WIN32
130  // Transform to lowercase for case insensitive file systems.
131  std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(), ::tolower);
132 #endif
133  return ProgName;
134 }
135 
136 const DriverSuffix *parseDriverSuffix(StringRef ProgName) {
137  // Try to infer frontend type and default target from the program name by
138  // comparing it against DriverSuffixes in order.
139 
140  // If there is a match, the function tries to identify a target as prefix.
141  // E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target
142  // prefix "x86_64-linux". If such a target prefix is found, it may be
143  // added via -target as implicit first argument.
144  const DriverSuffix *DS = FindDriverSuffix(ProgName);
145 
146  if (!DS) {
147  // Try again after stripping any trailing version number:
148  // clang++3.5 -> clang++
149  ProgName = ProgName.rtrim("0123456789.");
150  DS = FindDriverSuffix(ProgName);
151  }
152 
153  if (!DS) {
154  // Try again after stripping trailing -component.
155  // clang++-tot -> clang++
156  ProgName = ProgName.slice(0, ProgName.rfind('-'));
157  DS = FindDriverSuffix(ProgName);
158  }
159  return DS;
160 }
161 } // anonymous namespace
162 
163 std::pair<std::string, std::string>
165  std::string ProgName = normalizeProgramName(PN);
166  const DriverSuffix *DS = parseDriverSuffix(ProgName);
167  if (!DS)
168  return std::make_pair("", "");
169  std::string ModeFlag = DS->ModeFlag == nullptr ? "" : DS->ModeFlag;
170 
171  std::string::size_type LastComponent =
172  ProgName.rfind('-', ProgName.size() - strlen(DS->Suffix));
173  if (LastComponent == std::string::npos)
174  return std::make_pair("", ModeFlag);
175 
176  // Infer target from the prefix.
177  StringRef Prefix(ProgName);
178  Prefix = Prefix.slice(0, LastComponent);
179  std::string IgnoredError;
180  std::string Target;
181  if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
182  Target = Prefix;
183  }
184  return std::make_pair(Target, ModeFlag);
185 }
186 
188  // In universal driver terms, the arch name accepted by -arch isn't exactly
189  // the same as the ones that appear in the triple. Roughly speaking, this is
190  // an inverse of the darwin::getArchTypeForDarwinArchName() function, but the
191  // only interesting special case is powerpc.
192  switch (Triple.getArch()) {
193  case llvm::Triple::ppc:
194  return "ppc";
195  case llvm::Triple::ppc64:
196  return "ppc64";
197  case llvm::Triple::ppc64le:
198  return "ppc64le";
199  default:
200  return Triple.getArchName();
201  }
202 }
203 
205  return false;
206 }
207 
208 Tool *ToolChain::getClang() const {
209  if (!Clang)
210  Clang.reset(new tools::Clang(*this));
211  return Clang.get();
212 }
213 
215  return new tools::ClangAs(*this);
216 }
217 
219  llvm_unreachable("Linking is not supported by this toolchain");
220 }
221 
222 Tool *ToolChain::getAssemble() const {
223  if (!Assemble)
224  Assemble.reset(buildAssembler());
225  return Assemble.get();
226 }
227 
228 Tool *ToolChain::getClangAs() const {
229  if (!Assemble)
230  Assemble.reset(new tools::ClangAs(*this));
231  return Assemble.get();
232 }
233 
234 Tool *ToolChain::getLink() const {
235  if (!Link)
236  Link.reset(buildLinker());
237  return Link.get();
238 }
239 
241  switch (AC) {
243  return getAssemble();
244 
246  return getLink();
247 
248  case Action::InputClass:
255  llvm_unreachable("Invalid tool kind.");
256 
264  return getClang();
265  }
266 
267  llvm_unreachable("Invalid tool kind.");
268 }
269 
270 static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
271  const ArgList &Args) {
272  const llvm::Triple &Triple = TC.getTriple();
273  bool IsWindows = Triple.isOSWindows();
274 
275  if (Triple.isWindowsMSVCEnvironment() && TC.getArch() == llvm::Triple::x86)
276  return "i386";
277 
278  if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb)
279  return (arm::getARMFloatABI(TC, Args) == arm::FloatABI::Hard && !IsWindows)
280  ? "armhf"
281  : "arm";
282 
283  return TC.getArchName();
284 }
285 
286 std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
287  bool Shared) const {
288  const llvm::Triple &TT = getTriple();
289  const char *Env = TT.isAndroid() ? "-android" : "";
290  bool IsITANMSVCWindows =
291  TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
292 
293  StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
294  const char *Prefix = IsITANMSVCWindows ? "" : "lib";
295  const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so")
296  : (IsITANMSVCWindows ? ".lib" : ".a");
297 
298  SmallString<128> Path(getDriver().ResourceDir);
299  StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
300  llvm::sys::path::append(Path, "lib", OSLibName);
301  llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
302  Arch + Env + Suffix);
303  return Path.str();
304 }
305 
306 const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
307  StringRef Component,
308  bool Shared) const {
309  return Args.MakeArgString(getCompilerRT(Args, Component, Shared));
310 }
311 
312 bool ToolChain::needsProfileRT(const ArgList &Args) {
313  if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
314  false) ||
315  Args.hasArg(options::OPT_fprofile_generate) ||
316  Args.hasArg(options::OPT_fprofile_generate_EQ) ||
317  Args.hasArg(options::OPT_fprofile_instr_generate) ||
318  Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
319  Args.hasArg(options::OPT_fcreate_profile) ||
320  Args.hasArg(options::OPT_coverage))
321  return true;
322 
323  return false;
324 }
325 
327  if (getDriver().ShouldUseClangCompiler(JA)) return getClang();
328  Action::ActionClass AC = JA.getKind();
330  return getClangAs();
331  return getTool(AC);
332 }
333 
334 std::string ToolChain::GetFilePath(const char *Name) const {
335  return D.GetFilePath(Name, *this);
336 }
337 
338 std::string ToolChain::GetProgramPath(const char *Name) const {
339  return D.GetProgramPath(Name, *this);
340 }
341 
342 std::string ToolChain::GetLinkerPath() const {
343  if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
344  StringRef Suffix = A->getValue();
345 
346  // If we're passed -fuse-ld= with no argument, or with the argument ld,
347  // then use whatever the default system linker is.
348  if (Suffix.empty() || Suffix == "ld")
349  return GetProgramPath("ld");
350 
351  llvm::SmallString<8> LinkerName("ld.");
352  LinkerName.append(Suffix);
353 
354  std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
355  if (llvm::sys::fs::exists(LinkerPath))
356  return LinkerPath;
357 
358  getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
359  return "";
360  }
361 
363 }
364 
366  return types::lookupTypeForExtension(Ext);
367 }
368 
370  return false;
371 }
372 
374  llvm::Triple HostTriple(LLVM_HOST_TRIPLE);
375  switch (HostTriple.getArch()) {
376  // The A32/T32/T16 instruction sets are not separate architectures in this
377  // context.
378  case llvm::Triple::arm:
379  case llvm::Triple::armeb:
380  case llvm::Triple::thumb:
381  case llvm::Triple::thumbeb:
382  return getArch() != llvm::Triple::arm && getArch() != llvm::Triple::thumb &&
383  getArch() != llvm::Triple::armeb && getArch() != llvm::Triple::thumbeb;
384  default:
385  return HostTriple.getArch() != getArch();
386  }
387 }
388 
390  return ObjCRuntime(isNonFragile ? ObjCRuntime::GNUstep : ObjCRuntime::GCC,
391  VersionTuple());
392 }
393 
394 bool ToolChain::isThreadModelSupported(const StringRef Model) const {
395  if (Model == "single") {
396  // FIXME: 'single' is only supported on ARM and WebAssembly so far.
397  return Triple.getArch() == llvm::Triple::arm ||
398  Triple.getArch() == llvm::Triple::armeb ||
399  Triple.getArch() == llvm::Triple::thumb ||
400  Triple.getArch() == llvm::Triple::thumbeb ||
401  Triple.getArch() == llvm::Triple::wasm32 ||
402  Triple.getArch() == llvm::Triple::wasm64;
403  } else if (Model == "posix")
404  return true;
405 
406  return false;
407 }
408 
409 std::string ToolChain::ComputeLLVMTriple(const ArgList &Args,
410  types::ID InputType) const {
411  switch (getTriple().getArch()) {
412  default:
413  return getTripleString();
414 
415  case llvm::Triple::x86_64: {
416  llvm::Triple Triple = getTriple();
417  if (!Triple.isOSBinFormatMachO())
418  return getTripleString();
419 
420  if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
421  // x86_64h goes in the triple. Other -march options just use the
422  // vanilla triple we already have.
423  StringRef MArch = A->getValue();
424  if (MArch == "x86_64h")
425  Triple.setArchName(MArch);
426  }
427  return Triple.getTriple();
428  }
429  case llvm::Triple::aarch64: {
430  llvm::Triple Triple = getTriple();
431  if (!Triple.isOSBinFormatMachO())
432  return getTripleString();
433 
434  // FIXME: older versions of ld64 expect the "arm64" component in the actual
435  // triple string and query it to determine whether an LTO file can be
436  // handled. Remove this when we don't care any more.
437  Triple.setArchName("arm64");
438  return Triple.getTriple();
439  }
440  case llvm::Triple::arm:
441  case llvm::Triple::armeb:
442  case llvm::Triple::thumb:
443  case llvm::Triple::thumbeb: {
444  // FIXME: Factor into subclasses.
445  llvm::Triple Triple = getTriple();
446  bool IsBigEndian = getTriple().getArch() == llvm::Triple::armeb ||
447  getTriple().getArch() == llvm::Triple::thumbeb;
448 
449  // Handle pseudo-target flags '-mlittle-endian'/'-EL' and
450  // '-mbig-endian'/'-EB'.
451  if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
452  options::OPT_mbig_endian)) {
453  IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
454  }
455 
456  // Thumb2 is the default for V7 on Darwin.
457  //
458  // FIXME: Thumb should just be another -target-feaure, not in the triple.
459  StringRef MCPU, MArch;
460  if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
461  MCPU = A->getValue();
462  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
463  MArch = A->getValue();
464  std::string CPU =
465  Triple.isOSBinFormatMachO()
466  ? tools::arm::getARMCPUForMArch(MArch, Triple).str()
467  : tools::arm::getARMTargetCPU(MCPU, MArch, Triple);
468  StringRef Suffix =
469  tools::arm::getLLVMArchSuffixForARM(CPU, MArch, Triple);
470  bool IsMProfile = ARM::parseArchProfile(Suffix) == ARM::PK_M;
471  bool ThumbDefault = IsMProfile || (ARM::parseArchVersion(Suffix) == 7 &&
472  getTriple().isOSBinFormatMachO());
473  // FIXME: this is invalid for WindowsCE
474  if (getTriple().isOSWindows())
475  ThumbDefault = true;
476  std::string ArchName;
477  if (IsBigEndian)
478  ArchName = "armeb";
479  else
480  ArchName = "arm";
481 
482  // Assembly files should start in ARM mode, unless arch is M-profile.
483  if ((InputType != types::TY_PP_Asm && Args.hasFlag(options::OPT_mthumb,
484  options::OPT_mno_thumb, ThumbDefault)) || IsMProfile) {
485  if (IsBigEndian)
486  ArchName = "thumbeb";
487  else
488  ArchName = "thumb";
489  }
490  Triple.setArchName(ArchName + Suffix.str());
491 
492  return Triple.getTriple();
493  }
494  }
495 }
496 
497 std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
498  types::ID InputType) const {
499  return ComputeLLVMTriple(Args, InputType);
500 }
501 
502 void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
503  ArgStringList &CC1Args) const {
504  // Each toolchain should provide the appropriate include flags.
505 }
506 
507 void ToolChain::addClangTargetOptions(const ArgList &DriverArgs,
508  ArgStringList &CC1Args) const {
509 }
510 
511 void ToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {}
512 
513 void ToolChain::addProfileRTLibs(const llvm::opt::ArgList &Args,
514  llvm::opt::ArgStringList &CmdArgs) const {
515  if (!needsProfileRT(Args)) return;
516 
517  CmdArgs.push_back(getCompilerRTArgString(Args, "profile"));
518  return;
519 }
520 
522  const ArgList &Args) const {
523  if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
524  StringRef Value = A->getValue();
525  if (Value == "compiler-rt")
527  if (Value == "libgcc")
528  return ToolChain::RLT_Libgcc;
529  getDriver().Diag(diag::err_drv_invalid_rtlib_name)
530  << A->getAsString(Args);
531  }
532 
533  return GetDefaultRuntimeLibType();
534 }
535 
537  if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
538  StringRef Value = A->getValue();
539  if (Value == "libc++")
540  return ToolChain::CST_Libcxx;
541  if (Value == "libstdc++")
543  getDriver().Diag(diag::err_drv_invalid_stdlib_name)
544  << A->getAsString(Args);
545  }
546 
548 }
549 
550 /// \brief Utility function to add a system include directory to CC1 arguments.
551 /*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs,
552  ArgStringList &CC1Args,
553  const Twine &Path) {
554  CC1Args.push_back("-internal-isystem");
555  CC1Args.push_back(DriverArgs.MakeArgString(Path));
556 }
557 
558 /// \brief Utility function to add a system include directory with extern "C"
559 /// semantics to CC1 arguments.
560 ///
561 /// Note that this should be used rarely, and only for directories that
562 /// historically and for legacy reasons are treated as having implicit extern
563 /// "C" semantics. These semantics are *ignored* by and large today, but its
564 /// important to preserve the preprocessor changes resulting from the
565 /// classification.
566 /*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
567  ArgStringList &CC1Args,
568  const Twine &Path) {
569  CC1Args.push_back("-internal-externc-isystem");
570  CC1Args.push_back(DriverArgs.MakeArgString(Path));
571 }
572 
573 void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
574  ArgStringList &CC1Args,
575  const Twine &Path) {
576  if (llvm::sys::fs::exists(Path))
577  addExternCSystemInclude(DriverArgs, CC1Args, Path);
578 }
579 
580 /// \brief Utility function to add a list of system include directories to CC1.
581 /*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs,
582  ArgStringList &CC1Args,
583  ArrayRef<StringRef> Paths) {
584  for (StringRef Path : Paths) {
585  CC1Args.push_back("-internal-isystem");
586  CC1Args.push_back(DriverArgs.MakeArgString(Path));
587  }
588 }
589 
590 void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
591  ArgStringList &CC1Args) const {
592  // Header search paths should be handled by each of the subclasses.
593  // Historically, they have not been, and instead have been handled inside of
594  // the CC1-layer frontend. As the logic is hoisted out, this generic function
595  // will slowly stop being called.
596  //
597  // While it is being called, replicate a bit of a hack to propagate the
598  // '-stdlib=' flag down to CC1 so that it can in turn customize the C++
599  // header search paths with it. Once all systems are overriding this
600  // function, the CC1 flag and this line can be removed.
601  DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
602 }
603 
604 void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
605  ArgStringList &CmdArgs) const {
607 
608  switch (Type) {
610  CmdArgs.push_back("-lc++");
611  break;
612 
614  CmdArgs.push_back("-lstdc++");
615  break;
616  }
617 }
618 
619 void ToolChain::AddFilePathLibArgs(const ArgList &Args,
620  ArgStringList &CmdArgs) const {
621  for (const auto &LibPath : getFilePaths())
622  if(LibPath.length() > 0)
623  CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
624 }
625 
626 void ToolChain::AddCCKextLibArgs(const ArgList &Args,
627  ArgStringList &CmdArgs) const {
628  CmdArgs.push_back("-lcc_kext");
629 }
630 
632  ArgStringList &CmdArgs) const {
633  // Do not check for -fno-fast-math or -fno-unsafe-math when -Ofast passed
634  // (to keep the linker options consistent with gcc and clang itself).
635  if (!isOptimizationLevelFast(Args)) {
636  // Check if -ffast-math or -funsafe-math.
637  Arg *A =
638  Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math,
639  options::OPT_funsafe_math_optimizations,
640  options::OPT_fno_unsafe_math_optimizations);
641 
642  if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
643  A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
644  return false;
645  }
646  // If crtfastmath.o exists add it to the arguments.
647  std::string Path = GetFilePath("crtfastmath.o");
648  if (Path == "crtfastmath.o") // Not found.
649  return false;
650 
651  CmdArgs.push_back(Args.MakeArgString(Path));
652  return true;
653 }
654 
656  // Return sanitizers which don't require runtime support and are not
657  // platform dependent.
658  using namespace SanitizerKind;
659  SanitizerMask Res = (Undefined & ~Vptr & ~Function) | (CFI & ~CFIICall) |
660  CFICastStrict | UnsignedIntegerOverflow | LocalBounds;
661  if (getTriple().getArch() == llvm::Triple::x86 ||
662  getTriple().getArch() == llvm::Triple::x86_64)
663  Res |= CFIICall;
664  return Res;
665 }
666 
667 void ToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
668  ArgStringList &CC1Args) const {}
const llvm::Triple & getTriple() const
Definition: ToolChain.h:129
static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory with extern "C" semantics to CC1 arguments...
Definition: ToolChain.cpp:566
virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass a suitable profile runtime ...
Definition: ToolChain.cpp:513
virtual Tool * getTool(Action::ActionClass AC) const
Definition: ToolChain.cpp:240
virtual Tool * SelectTool(const JobAction &JA) const
Choose a tool to use to handle the action JA.
Definition: ToolChain.cpp:326
ID lookupTypeForExtension(const char *Ext)
lookupTypeForExtension - Lookup the type to use for the file extension Ext.
Definition: Types.cpp:156
static void addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Definition: ToolChain.cpp:573
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
std::string GetProgramPath(const char *Name) const
Definition: ToolChain.cpp:338
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:536
virtual bool AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFastMathRuntimeIfAvailable - If a runtime library exists that sets global flags for unsafe floatin...
Definition: ToolChain.cpp:631
Defines types useful for describing an Objective-C runtime.
The base class of the type hierarchy.
Definition: Type.h:1249
StringRef getARMCPUForMArch(StringRef Arch, const llvm::Triple &Triple)
Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
Definition: Tools.cpp:6593
bool useIntegratedAs() const
Check if the toolchain should use the integrated assembler.
Definition: ToolChain.cpp:82
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:90
StringRef getLLVMArchSuffixForARM(StringRef CPU, StringRef Arch, const llvm::Triple &Triple)
getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular CPU (or Arch, if CPU is generic).
Definition: Tools.cpp:6625
'gcc' is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI ...
Definition: ObjCRuntime.h:50
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:131
virtual Tool * buildAssembler() const
Definition: ToolChain.cpp:214
FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args)
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:655
Clang integrated assembler tool.
Definition: Tools.h:121
virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddCCKextLibArgs - Add the system specific linker arguments to use for kernel extensions (Darwin-spec...
Definition: ToolChain.cpp:626
virtual bool isThreadModelSupported(const StringRef Model) const
isThreadModelSupported() - Does this target support a thread model?
Definition: ToolChain.cpp:394
The virtual file system interface.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4381
virtual bool HasNativeLLVMSupport() const
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition: ToolChain.cpp:369
static StringRef getArchNameForCompilerRTLib(const ToolChain &TC, const ArgList &Args)
Definition: ToolChain.cpp:270
ActionClass getKind() const
Definition: Action.h:93
std::string getARMTargetCPU(StringRef CPU, StringRef Arch, const llvm::Triple &Triple)
getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
Definition: Tools.cpp:6606
virtual bool isCrossCompiling() const
Returns true if the toolchain is targeting a non-native architecture.
Definition: ToolChain.cpp:373
static bool needsProfileRT(const llvm::opt::ArgList &Args)
needsProfileRT - returns true if instrumentation profile is on.
Definition: ToolChain.cpp:312
std::string GetFilePath(const char *Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
Definition: Driver.cpp:2103
virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
Definition: ToolChain.cpp:604
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
std::string getTripleString() const
Definition: ToolChain.h:140
path_list & getFilePaths()
Definition: ToolChain.h:144
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:65
const Driver & getDriver() const
Definition: ToolChain.h:127
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition: ToolChain.cpp:67
StringRef getArchName() const
Definition: ToolChain.h:132
virtual RuntimeLibType GetDefaultRuntimeLibType() const
GetDefaultRuntimeLibType - Get the default runtime library variant to use.
Definition: ToolChain.h:255
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, bool Shared=false) const
Definition: ToolChain.cpp:286
StringRef getOS() const
Definition: ToolChain.h:134
virtual RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:521
static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, ArrayRef< StringRef > Paths)
Utility function to add a list of system include directories to CC1.
Definition: ToolChain.cpp:581
static llvm::opt::Arg * GetRTTIArgument(const ArgList &Args)
Definition: ToolChain.cpp:34
virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const
Add warning options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:511
virtual std::string ComputeLLVMTriple(const llvm::opt::ArgList &Args, types::ID InputType=types::TY_INVALID) const
ComputeLLVMTriple - Return the LLVM target triple to use, after taking command line arguments into ac...
Definition: ToolChain.cpp:409
static std::pair< std::string, std::string > getTargetAndModeFromProgramName(StringRef ProgName)
Return any implicit target and/or mode flag for an invocation of the compiler driver as ProgName...
Definition: ToolChain.cpp:164
vfs::FileSystem & getVFS() const
Definition: Driver.h:237
'gnustep' is the modern non-fragile GNUstep runtime.
Definition: ObjCRuntime.h:53
std::string GetProgramPath(const char *Name, const ToolChain &TC) const
GetProgramPath - Lookup Name in the list of program search paths.
Definition: Driver.cpp:2156
virtual void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: ToolChain.cpp:590
StringRef getDefaultUniversalArchName() const
Provide the default architecture name (as expected by -arch) for this toolchain.
Definition: ToolChain.cpp:187
virtual std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType=types::TY_INVALID) const
ComputeEffectiveClangTriple - Return the Clang triple to use for this target, which may take into acc...
Definition: ToolChain.cpp:497
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:507
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:551
virtual void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add the clang cc1 arguments for system include paths.
Definition: ToolChain.cpp:502
uint64_t SanitizerMask
Definition: Sanitizers.h:24
Clang compiler tool.
Definition: Tools.h:46
static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, const llvm::Triple &Triple, const Arg *CachedRTTIArg)
Definition: ToolChain.cpp:39
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:25
const char * getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, bool Shared=false) const
Definition: ToolChain.cpp:306
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
virtual Tool * buildLinker() const
Definition: ToolChain.cpp:218
void AddFilePathLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
Definition: ToolChain.cpp:619
vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:80
virtual bool IsUnwindTablesDefault() const
IsUnwindTablesDefault - Does this tool chain use -funwind-tables by default.
Definition: ToolChain.cpp:204
virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const
getDefaultObjCRuntime - Return the default Objective-C runtime for this platform. ...
Definition: ToolChain.cpp:389
virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use system-specific CUDA includes.
Definition: ToolChain.cpp:667
const char * DefaultLinker
Definition: ToolChain.h:96
virtual bool IsIntegratedAssemblerDefault() const
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: ToolChain.h:228
std::string GetLinkerPath() const
Returns the linker path, respecting the -fuse-ld= argument to determine the linker suffix or name...
Definition: ToolChain.cpp:342
const SanitizerArgs & getSanitizerArgs() const
Definition: ToolChain.cpp:88
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:334
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:47
virtual types::ID LookupTypeForExtension(const char *Ext) const
LookupTypeForExtension - Return the default language type to use for the given extension.
Definition: ToolChain.cpp:365