clang  9.0.0svn
ToolChain.cpp
Go to the documentation of this file.
1 //===- ToolChain.cpp - Collections of tools for one platform --------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "InputInfo.h"
11 #include "ToolChains/Arch/ARM.h"
12 #include "ToolChains/Clang.h"
14 #include "clang/Basic/Sanitizers.h"
15 #include "clang/Config/config.h"
16 #include "clang/Driver/Action.h"
17 #include "clang/Driver/Driver.h"
19 #include "clang/Driver/Job.h"
20 #include "clang/Driver/Options.h"
22 #include "clang/Driver/XRayArgs.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/SmallString.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/ADT/Triple.h"
27 #include "llvm/ADT/Twine.h"
28 #include "llvm/Config/llvm-config.h"
29 #include "llvm/MC/MCTargetOptions.h"
30 #include "llvm/Option/Arg.h"
31 #include "llvm/Option/ArgList.h"
32 #include "llvm/Option/OptTable.h"
33 #include "llvm/Option/Option.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/FileSystem.h"
36 #include "llvm/Support/Path.h"
37 #include "llvm/Support/TargetParser.h"
38 #include "llvm/Support/TargetRegistry.h"
39 #include "llvm/Support/VersionTuple.h"
40 #include "llvm/Support/VirtualFileSystem.h"
41 #include <cassert>
42 #include <cstddef>
43 #include <cstring>
44 #include <string>
45 
46 using namespace clang;
47 using namespace driver;
48 using namespace tools;
49 using namespace llvm;
50 using namespace llvm::opt;
51 
52 static llvm::opt::Arg *GetRTTIArgument(const ArgList &Args) {
53  return Args.getLastArg(options::OPT_mkernel, options::OPT_fapple_kext,
54  options::OPT_fno_rtti, options::OPT_frtti);
55 }
56 
57 static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args,
58  const llvm::Triple &Triple,
59  const Arg *CachedRTTIArg) {
60  // Explicit rtti/no-rtti args
61  if (CachedRTTIArg) {
62  if (CachedRTTIArg->getOption().matches(options::OPT_frtti))
63  return ToolChain::RM_Enabled;
64  else
66  }
67 
68  // -frtti is default, except for the PS4 CPU.
69  return (Triple.isPS4CPU()) ? ToolChain::RM_Disabled : ToolChain::RM_Enabled;
70 }
71 
72 ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
73  const ArgList &Args)
74  : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
75  CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
76  if (D.CCCIsCXX()) {
77  if (auto CXXStdlibPath = getCXXStdlibPath())
78  getFilePaths().push_back(*CXXStdlibPath);
79  }
80 
81  if (auto RuntimePath = getRuntimePath())
82  getLibraryPaths().push_back(*RuntimePath);
83 
84  std::string CandidateLibPath = getArchSpecificLibPath();
85  if (getVFS().exists(CandidateLibPath))
86  getFilePaths().push_back(CandidateLibPath);
87 }
88 
89 void ToolChain::setTripleEnvironment(llvm::Triple::EnvironmentType Env) {
90  Triple.setEnvironment(Env);
91  if (EffectiveTriple != llvm::Triple())
92  EffectiveTriple.setEnvironment(Env);
93 }
94 
95 ToolChain::~ToolChain() = default;
96 
97 llvm::vfs::FileSystem &ToolChain::getVFS() const {
98  return getDriver().getVFS();
99 }
100 
102  return Args.hasFlag(options::OPT_fintegrated_as,
103  options::OPT_fno_integrated_as,
105 }
106 
108  return ENABLE_X86_RELAX_RELOCATIONS;
109 }
110 
112  return false;
113 }
114 
116  if (!SanitizerArguments.get())
117  SanitizerArguments.reset(new SanitizerArgs(*this, Args));
118  return *SanitizerArguments.get();
119 }
120 
122  if (!XRayArguments.get())
123  XRayArguments.reset(new XRayArgs(*this, Args));
124  return *XRayArguments.get();
125 }
126 
127 namespace {
128 
129 struct DriverSuffix {
130  const char *Suffix;
131  const char *ModeFlag;
132 };
133 
134 } // namespace
135 
136 static const DriverSuffix *FindDriverSuffix(StringRef ProgName, size_t &Pos) {
137  // A list of known driver suffixes. Suffixes are compared against the
138  // program name in order. If there is a match, the frontend type is updated as
139  // necessary by applying the ModeFlag.
140  static const DriverSuffix DriverSuffixes[] = {
141  {"clang", nullptr},
142  {"clang++", "--driver-mode=g++"},
143  {"clang-c++", "--driver-mode=g++"},
144  {"clang-cc", nullptr},
145  {"clang-cpp", "--driver-mode=cpp"},
146  {"clang-g++", "--driver-mode=g++"},
147  {"clang-gcc", nullptr},
148  {"clang-cl", "--driver-mode=cl"},
149  {"cc", nullptr},
150  {"cpp", "--driver-mode=cpp"},
151  {"cl", "--driver-mode=cl"},
152  {"++", "--driver-mode=g++"},
153  };
154 
155  for (size_t i = 0; i < llvm::array_lengthof(DriverSuffixes); ++i) {
156  StringRef Suffix(DriverSuffixes[i].Suffix);
157  if (ProgName.endswith(Suffix)) {
158  Pos = ProgName.size() - Suffix.size();
159  return &DriverSuffixes[i];
160  }
161  }
162  return nullptr;
163 }
164 
165 /// Normalize the program name from argv[0] by stripping the file extension if
166 /// present and lower-casing the string on Windows.
167 static std::string normalizeProgramName(llvm::StringRef Argv0) {
168  std::string ProgName = llvm::sys::path::stem(Argv0);
169 #ifdef _WIN32
170  // Transform to lowercase for case insensitive file systems.
171  std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(), ::tolower);
172 #endif
173  return ProgName;
174 }
175 
176 static const DriverSuffix *parseDriverSuffix(StringRef ProgName, size_t &Pos) {
177  // Try to infer frontend type and default target from the program name by
178  // comparing it against DriverSuffixes in order.
179 
180  // If there is a match, the function tries to identify a target as prefix.
181  // E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target
182  // prefix "x86_64-linux". If such a target prefix is found, it may be
183  // added via -target as implicit first argument.
184  const DriverSuffix *DS = FindDriverSuffix(ProgName, Pos);
185 
186  if (!DS) {
187  // Try again after stripping any trailing version number:
188  // clang++3.5 -> clang++
189  ProgName = ProgName.rtrim("0123456789.");
190  DS = FindDriverSuffix(ProgName, Pos);
191  }
192 
193  if (!DS) {
194  // Try again after stripping trailing -component.
195  // clang++-tot -> clang++
196  ProgName = ProgName.slice(0, ProgName.rfind('-'));
197  DS = FindDriverSuffix(ProgName, Pos);
198  }
199  return DS;
200 }
201 
204  std::string ProgName = normalizeProgramName(PN);
205  size_t SuffixPos;
206  const DriverSuffix *DS = parseDriverSuffix(ProgName, SuffixPos);
207  if (!DS)
208  return {};
209  size_t SuffixEnd = SuffixPos + strlen(DS->Suffix);
210 
211  size_t LastComponent = ProgName.rfind('-', SuffixPos);
212  if (LastComponent == std::string::npos)
213  return ParsedClangName(ProgName.substr(0, SuffixEnd), DS->ModeFlag);
214  std::string ModeSuffix = ProgName.substr(LastComponent + 1,
215  SuffixEnd - LastComponent - 1);
216 
217  // Infer target from the prefix.
218  StringRef Prefix(ProgName);
219  Prefix = Prefix.slice(0, LastComponent);
220  std::string IgnoredError;
221  bool IsRegistered = llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError);
222  return ParsedClangName{Prefix, ModeSuffix, DS->ModeFlag, IsRegistered};
223 }
224 
226  // In universal driver terms, the arch name accepted by -arch isn't exactly
227  // the same as the ones that appear in the triple. Roughly speaking, this is
228  // an inverse of the darwin::getArchTypeForDarwinArchName() function, but the
229  // only interesting special case is powerpc.
230  switch (Triple.getArch()) {
231  case llvm::Triple::ppc:
232  return "ppc";
233  case llvm::Triple::ppc64:
234  return "ppc64";
235  case llvm::Triple::ppc64le:
236  return "ppc64le";
237  default:
238  return Triple.getArchName();
239  }
240 }
241 
242 std::string ToolChain::getInputFilename(const InputInfo &Input) const {
243  return Input.getFilename();
244 }
245 
246 bool ToolChain::IsUnwindTablesDefault(const ArgList &Args) const {
247  return false;
248 }
249 
250 Tool *ToolChain::getClang() const {
251  if (!Clang)
252  Clang.reset(new tools::Clang(*this));
253  return Clang.get();
254 }
255 
257  return new tools::ClangAs(*this);
258 }
259 
261  llvm_unreachable("Linking is not supported by this toolchain");
262 }
263 
264 Tool *ToolChain::getAssemble() const {
265  if (!Assemble)
266  Assemble.reset(buildAssembler());
267  return Assemble.get();
268 }
269 
270 Tool *ToolChain::getClangAs() const {
271  if (!Assemble)
272  Assemble.reset(new tools::ClangAs(*this));
273  return Assemble.get();
274 }
275 
276 Tool *ToolChain::getLink() const {
277  if (!Link)
278  Link.reset(buildLinker());
279  return Link.get();
280 }
281 
282 Tool *ToolChain::getOffloadBundler() const {
283  if (!OffloadBundler)
284  OffloadBundler.reset(new tools::OffloadBundler(*this));
285  return OffloadBundler.get();
286 }
287 
289  switch (AC) {
291  return getAssemble();
292 
294  return getLink();
295 
296  case Action::InputClass:
302  llvm_unreachable("Invalid tool kind.");
303 
312  return getClang();
313 
316  return getOffloadBundler();
317  }
318 
319  llvm_unreachable("Invalid tool kind.");
320 }
321 
322 static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
323  const ArgList &Args) {
324  const llvm::Triple &Triple = TC.getTriple();
325  bool IsWindows = Triple.isOSWindows();
326 
327  if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb)
328  return (arm::getARMFloatABI(TC, Args) == arm::FloatABI::Hard && !IsWindows)
329  ? "armhf"
330  : "arm";
331 
332  // For historic reasons, Android library is using i686 instead of i386.
333  if (TC.getArch() == llvm::Triple::x86 && Triple.isAndroid())
334  return "i686";
335 
336  return llvm::Triple::getArchTypeName(TC.getArch());
337 }
338 
339 StringRef ToolChain::getOSLibName() const {
340  switch (Triple.getOS()) {
341  case llvm::Triple::FreeBSD:
342  return "freebsd";
343  case llvm::Triple::NetBSD:
344  return "netbsd";
345  case llvm::Triple::OpenBSD:
346  return "openbsd";
347  case llvm::Triple::Solaris:
348  return "sunos";
349  default:
350  return getOS();
351  }
352 }
353 
354 std::string ToolChain::getCompilerRTPath() const {
355  SmallString<128> Path(getDriver().ResourceDir);
356  if (Triple.isOSUnknown()) {
357  llvm::sys::path::append(Path, "lib");
358  } else {
359  llvm::sys::path::append(Path, "lib", getOSLibName());
360  }
361  return Path.str();
362 }
363 
364 std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
365  FileType Type) const {
366  const llvm::Triple &TT = getTriple();
367  bool IsITANMSVCWindows =
368  TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
369 
370  const char *Prefix =
371  IsITANMSVCWindows || Type == ToolChain::FT_Object ? "" : "lib";
372  const char *Suffix;
373  switch (Type) {
375  Suffix = IsITANMSVCWindows ? ".obj" : ".o";
376  break;
378  Suffix = IsITANMSVCWindows ? ".lib" : ".a";
379  break;
381  Suffix = Triple.isOSWindows()
382  ? (Triple.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
383  : ".so";
384  break;
385  }
386 
387  for (const auto &LibPath : getLibraryPaths()) {
388  SmallString<128> P(LibPath);
389  llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix);
390  if (getVFS().exists(P))
391  return P.str();
392  }
393 
394  StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
395  const char *Env = TT.isAndroid() ? "-android" : "";
397  llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
398  Arch + Env + Suffix);
399  return Path.str();
400 }
401 
402 const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
403  StringRef Component,
404  FileType Type) const {
405  return Args.MakeArgString(getCompilerRT(Args, Component, Type));
406 }
407 
408 
411 
412  // First try the triple passed to driver as --target=<triple>.
413  P.assign(D.ResourceDir);
414  llvm::sys::path::append(P, "lib", D.getTargetTriple());
415  if (getVFS().exists(P))
416  return llvm::Optional<std::string>(P.str());
417 
418  // Second try the normalized triple.
419  P.assign(D.ResourceDir);
420  llvm::sys::path::append(P, "lib", Triple.str());
421  if (getVFS().exists(P))
422  return llvm::Optional<std::string>(P.str());
423 
424  return None;
425 }
426 
429 
430  // First try the triple passed to driver as --target=<triple>.
431  P.assign(D.Dir);
432  llvm::sys::path::append(P, "..", "lib", D.getTargetTriple(), "c++");
433  if (getVFS().exists(P))
434  return llvm::Optional<std::string>(P.str());
435 
436  // Second try the normalized triple.
437  P.assign(D.Dir);
438  llvm::sys::path::append(P, "..", "lib", Triple.str(), "c++");
439  if (getVFS().exists(P))
440  return llvm::Optional<std::string>(P.str());
441 
442  return None;
443 }
444 
446  SmallString<128> Path(getDriver().ResourceDir);
447  llvm::sys::path::append(Path, "lib", getOSLibName(),
448  llvm::Triple::getArchTypeName(getArch()));
449  return Path.str();
450 }
451 
452 bool ToolChain::needsProfileRT(const ArgList &Args) {
453  if (needsGCovInstrumentation(Args) ||
454  Args.hasArg(options::OPT_fprofile_generate) ||
455  Args.hasArg(options::OPT_fprofile_generate_EQ) ||
456  Args.hasArg(options::OPT_fcs_profile_generate) ||
457  Args.hasArg(options::OPT_fcs_profile_generate_EQ) ||
458  Args.hasArg(options::OPT_fprofile_instr_generate) ||
459  Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
460  Args.hasArg(options::OPT_fcreate_profile) ||
461  Args.hasArg(options::OPT_forder_file_instrumentation))
462  return true;
463 
464  return false;
465 }
466 
467 bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) {
468  return Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
469  false) ||
470  Args.hasArg(options::OPT_coverage);
471 }
472 
474  if (getDriver().ShouldUseClangCompiler(JA)) return getClang();
475  Action::ActionClass AC = JA.getKind();
477  return getClangAs();
478  return getTool(AC);
479 }
480 
481 std::string ToolChain::GetFilePath(const char *Name) const {
482  return D.GetFilePath(Name, *this);
483 }
484 
485 std::string ToolChain::GetProgramPath(const char *Name) const {
486  return D.GetProgramPath(Name, *this);
487 }
488 
489 std::string ToolChain::GetLinkerPath() const {
490  const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
491  StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
492 
493  if (llvm::sys::path::is_absolute(UseLinker)) {
494  // If we're passed what looks like an absolute path, don't attempt to
495  // second-guess that.
496  if (llvm::sys::fs::can_execute(UseLinker))
497  return UseLinker;
498  } else if (UseLinker.empty() || UseLinker == "ld") {
499  // If we're passed -fuse-ld= with no argument, or with the argument ld,
500  // then use whatever the default system linker is.
502  } else {
503  llvm::SmallString<8> LinkerName;
504  if (Triple.isOSDarwin())
505  LinkerName.append("ld64.");
506  else
507  LinkerName.append("ld.");
508  LinkerName.append(UseLinker);
509 
510  std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
511  if (llvm::sys::fs::can_execute(LinkerPath))
512  return LinkerPath;
513  }
514 
515  if (A)
516  getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
517 
519 }
520 
522  return types::lookupTypeForExtension(Ext);
523 }
524 
526  return false;
527 }
528 
530  llvm::Triple HostTriple(LLVM_HOST_TRIPLE);
531  switch (HostTriple.getArch()) {
532  // The A32/T32/T16 instruction sets are not separate architectures in this
533  // context.
534  case llvm::Triple::arm:
535  case llvm::Triple::armeb:
536  case llvm::Triple::thumb:
537  case llvm::Triple::thumbeb:
538  return getArch() != llvm::Triple::arm && getArch() != llvm::Triple::thumb &&
539  getArch() != llvm::Triple::armeb && getArch() != llvm::Triple::thumbeb;
540  default:
541  return HostTriple.getArch() != getArch();
542  }
543 }
544 
546  return ObjCRuntime(isNonFragile ? ObjCRuntime::GNUstep : ObjCRuntime::GCC,
547  VersionTuple());
548 }
549 
550 llvm::ExceptionHandling
551 ToolChain::GetExceptionModel(const llvm::opt::ArgList &Args) const {
553 }
554 
555 bool ToolChain::isThreadModelSupported(const StringRef Model) const {
556  if (Model == "single") {
557  // FIXME: 'single' is only supported on ARM and WebAssembly so far.
558  return Triple.getArch() == llvm::Triple::arm ||
559  Triple.getArch() == llvm::Triple::armeb ||
560  Triple.getArch() == llvm::Triple::thumb ||
561  Triple.getArch() == llvm::Triple::thumbeb ||
562  Triple.getArch() == llvm::Triple::wasm32 ||
563  Triple.getArch() == llvm::Triple::wasm64;
564  } else if (Model == "posix")
565  return true;
566 
567  return false;
568 }
569 
570 std::string ToolChain::ComputeLLVMTriple(const ArgList &Args,
571  types::ID InputType) const {
572  switch (getTriple().getArch()) {
573  default:
574  return getTripleString();
575 
576  case llvm::Triple::x86_64: {
577  llvm::Triple Triple = getTriple();
578  if (!Triple.isOSBinFormatMachO())
579  return getTripleString();
580 
581  if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
582  // x86_64h goes in the triple. Other -march options just use the
583  // vanilla triple we already have.
584  StringRef MArch = A->getValue();
585  if (MArch == "x86_64h")
586  Triple.setArchName(MArch);
587  }
588  return Triple.getTriple();
589  }
590  case llvm::Triple::aarch64: {
591  llvm::Triple Triple = getTriple();
592  if (!Triple.isOSBinFormatMachO())
593  return getTripleString();
594 
595  // FIXME: older versions of ld64 expect the "arm64" component in the actual
596  // triple string and query it to determine whether an LTO file can be
597  // handled. Remove this when we don't care any more.
598  Triple.setArchName("arm64");
599  return Triple.getTriple();
600  }
601  case llvm::Triple::arm:
602  case llvm::Triple::armeb:
603  case llvm::Triple::thumb:
604  case llvm::Triple::thumbeb: {
605  // FIXME: Factor into subclasses.
606  llvm::Triple Triple = getTriple();
607  bool IsBigEndian = getTriple().getArch() == llvm::Triple::armeb ||
608  getTriple().getArch() == llvm::Triple::thumbeb;
609 
610  // Handle pseudo-target flags '-mlittle-endian'/'-EL' and
611  // '-mbig-endian'/'-EB'.
612  if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
613  options::OPT_mbig_endian)) {
614  IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
615  }
616 
617  // Thumb2 is the default for V7 on Darwin.
618  //
619  // FIXME: Thumb should just be another -target-feaure, not in the triple.
620  StringRef MCPU, MArch;
621  if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
622  MCPU = A->getValue();
623  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
624  MArch = A->getValue();
625  std::string CPU =
626  Triple.isOSBinFormatMachO()
627  ? tools::arm::getARMCPUForMArch(MArch, Triple).str()
628  : tools::arm::getARMTargetCPU(MCPU, MArch, Triple);
629  StringRef Suffix =
630  tools::arm::getLLVMArchSuffixForARM(CPU, MArch, Triple);
631  bool IsMProfile = ARM::parseArchProfile(Suffix) == ARM::ProfileKind::M;
632  bool ThumbDefault = IsMProfile || (ARM::parseArchVersion(Suffix) == 7 &&
633  getTriple().isOSBinFormatMachO());
634  // FIXME: this is invalid for WindowsCE
635  if (getTriple().isOSWindows())
636  ThumbDefault = true;
637  std::string ArchName;
638  if (IsBigEndian)
639  ArchName = "armeb";
640  else
641  ArchName = "arm";
642 
643  // Check if ARM ISA was explicitly selected (using -mno-thumb or -marm) for
644  // M-Class CPUs/architecture variants, which is not supported.
645  bool ARMModeRequested = !Args.hasFlag(options::OPT_mthumb,
646  options::OPT_mno_thumb, ThumbDefault);
647  if (IsMProfile && ARMModeRequested) {
648  if (!MCPU.empty())
649  getDriver().Diag(diag::err_cpu_unsupported_isa) << CPU << "ARM";
650  else
651  getDriver().Diag(diag::err_arch_unsupported_isa)
652  << tools::arm::getARMArch(MArch, getTriple()) << "ARM";
653  }
654 
655  // Check to see if an explicit choice to use thumb has been made via
656  // -mthumb. For assembler files we must check for -mthumb in the options
657  // passed to the assembler via -Wa or -Xassembler.
658  bool IsThumb = false;
659  if (InputType != types::TY_PP_Asm)
660  IsThumb = Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb,
661  ThumbDefault);
662  else {
663  // Ideally we would check for these flags in
664  // CollectArgsForIntegratedAssembler but we can't change the ArchName at
665  // that point. There is no assembler equivalent of -mno-thumb, -marm, or
666  // -mno-arm.
667  for (const auto *A :
668  Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
669  for (StringRef Value : A->getValues()) {
670  if (Value == "-mthumb")
671  IsThumb = true;
672  }
673  }
674  }
675  // Assembly files should start in ARM mode, unless arch is M-profile, or
676  // -mthumb has been passed explicitly to the assembler. Windows is always
677  // thumb.
678  if (IsThumb || IsMProfile || getTriple().isOSWindows()) {
679  if (IsBigEndian)
680  ArchName = "thumbeb";
681  else
682  ArchName = "thumb";
683  }
684  Triple.setArchName(ArchName + Suffix.str());
685 
686  return Triple.getTriple();
687  }
688  }
689 }
690 
691 std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
692  types::ID InputType) const {
693  return ComputeLLVMTriple(Args, InputType);
694 }
695 
696 void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
697  ArgStringList &CC1Args) const {
698  // Each toolchain should provide the appropriate include flags.
699 }
700 
702  const ArgList &DriverArgs, ArgStringList &CC1Args,
703  Action::OffloadKind DeviceOffloadKind) const {}
704 
705 void ToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {}
706 
707 void ToolChain::addProfileRTLibs(const llvm::opt::ArgList &Args,
708  llvm::opt::ArgStringList &CmdArgs) const {
709  if (!needsProfileRT(Args)) return;
710 
711  CmdArgs.push_back(getCompilerRTArgString(Args, "profile"));
712 }
713 
715  const ArgList &Args) const {
716  const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
717  StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
718 
719  // Only use "platform" in tests to override CLANG_DEFAULT_RTLIB!
720  if (LibName == "compiler-rt")
722  else if (LibName == "libgcc")
723  return ToolChain::RLT_Libgcc;
724  else if (LibName == "platform")
725  return GetDefaultRuntimeLibType();
726 
727  if (A)
728  getDriver().Diag(diag::err_drv_invalid_rtlib_name) << A->getAsString(Args);
729 
730  return GetDefaultRuntimeLibType();
731 }
732 
734  const ArgList &Args) const {
735  const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
736  StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;
737 
738  if (LibName == "none")
739  return ToolChain::UNW_None;
740  else if (LibName == "platform" || LibName == "") {
742  if (RtLibType == ToolChain::RLT_CompilerRT)
743  return ToolChain::UNW_None;
744  else if (RtLibType == ToolChain::RLT_Libgcc)
745  return ToolChain::UNW_Libgcc;
746  } else if (LibName == "libunwind") {
747  if (GetRuntimeLibType(Args) == RLT_Libgcc)
748  getDriver().Diag(diag::err_drv_incompatible_unwindlib);
750  } else if (LibName == "libgcc")
751  return ToolChain::UNW_Libgcc;
752 
753  if (A)
754  getDriver().Diag(diag::err_drv_invalid_unwindlib_name)
755  << A->getAsString(Args);
756 
757  return GetDefaultUnwindLibType();
758 }
759 
761  const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
762  StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB;
763 
764  // Only use "platform" in tests to override CLANG_DEFAULT_CXX_STDLIB!
765  if (LibName == "libc++")
766  return ToolChain::CST_Libcxx;
767  else if (LibName == "libstdc++")
769  else if (LibName == "platform")
770  return GetDefaultCXXStdlibType();
771 
772  if (A)
773  getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args);
774 
775  return GetDefaultCXXStdlibType();
776 }
777 
778 /// Utility function to add a system include directory to CC1 arguments.
779 /*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs,
780  ArgStringList &CC1Args,
781  const Twine &Path) {
782  CC1Args.push_back("-internal-isystem");
783  CC1Args.push_back(DriverArgs.MakeArgString(Path));
784 }
785 
786 /// Utility function to add a system include directory with extern "C"
787 /// semantics to CC1 arguments.
788 ///
789 /// Note that this should be used rarely, and only for directories that
790 /// historically and for legacy reasons are treated as having implicit extern
791 /// "C" semantics. These semantics are *ignored* by and large today, but its
792 /// important to preserve the preprocessor changes resulting from the
793 /// classification.
794 /*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
795  ArgStringList &CC1Args,
796  const Twine &Path) {
797  CC1Args.push_back("-internal-externc-isystem");
798  CC1Args.push_back(DriverArgs.MakeArgString(Path));
799 }
800 
801 void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
802  ArgStringList &CC1Args,
803  const Twine &Path) {
804  if (llvm::sys::fs::exists(Path))
805  addExternCSystemInclude(DriverArgs, CC1Args, Path);
806 }
807 
808 /// Utility function to add a list of system include directories to CC1.
809 /*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs,
810  ArgStringList &CC1Args,
811  ArrayRef<StringRef> Paths) {
812  for (const auto Path : Paths) {
813  CC1Args.push_back("-internal-isystem");
814  CC1Args.push_back(DriverArgs.MakeArgString(Path));
815  }
816 }
817 
818 void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
819  ArgStringList &CC1Args) const {
820  // Header search paths should be handled by each of the subclasses.
821  // Historically, they have not been, and instead have been handled inside of
822  // the CC1-layer frontend. As the logic is hoisted out, this generic function
823  // will slowly stop being called.
824  //
825  // While it is being called, replicate a bit of a hack to propagate the
826  // '-stdlib=' flag down to CC1 so that it can in turn customize the C++
827  // header search paths with it. Once all systems are overriding this
828  // function, the CC1 flag and this line can be removed.
829  DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
830 }
831 
832 bool ToolChain::ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const {
833  return getDriver().CCCIsCXX() &&
834  !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
835  options::OPT_nostdlibxx);
836 }
837 
838 void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
839  ArgStringList &CmdArgs) const {
840  assert(!Args.hasArg(options::OPT_nostdlibxx) &&
841  "should not have called this");
843 
844  switch (Type) {
846  CmdArgs.push_back("-lc++");
847  break;
848 
850  CmdArgs.push_back("-lstdc++");
851  break;
852  }
853 }
854 
855 void ToolChain::AddFilePathLibArgs(const ArgList &Args,
856  ArgStringList &CmdArgs) const {
857  for (const auto &LibPath : getFilePaths())
858  if(LibPath.length() > 0)
859  CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
860 }
861 
862 void ToolChain::AddCCKextLibArgs(const ArgList &Args,
863  ArgStringList &CmdArgs) const {
864  CmdArgs.push_back("-lcc_kext");
865 }
866 
868  ArgStringList &CmdArgs) const {
869  // Do not check for -fno-fast-math or -fno-unsafe-math when -Ofast passed
870  // (to keep the linker options consistent with gcc and clang itself).
871  if (!isOptimizationLevelFast(Args)) {
872  // Check if -ffast-math or -funsafe-math.
873  Arg *A =
874  Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math,
875  options::OPT_funsafe_math_optimizations,
876  options::OPT_fno_unsafe_math_optimizations);
877 
878  if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
879  A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
880  return false;
881  }
882  // If crtfastmath.o exists add it to the arguments.
883  std::string Path = GetFilePath("crtfastmath.o");
884  if (Path == "crtfastmath.o") // Not found.
885  return false;
886 
887  CmdArgs.push_back(Args.MakeArgString(Path));
888  return true;
889 }
890 
892  // Return sanitizers which don't require runtime support and are not
893  // platform dependent.
894 
895  SanitizerMask Res = (SanitizerKind::Undefined & ~SanitizerKind::Vptr &
896  ~SanitizerKind::Function) |
897  (SanitizerKind::CFI & ~SanitizerKind::CFIICall) |
898  SanitizerKind::CFICastStrict |
899  SanitizerKind::UnsignedIntegerOverflow |
900  SanitizerKind::ImplicitConversion |
901  SanitizerKind::Nullability | SanitizerKind::LocalBounds;
902  if (getTriple().getArch() == llvm::Triple::x86 ||
903  getTriple().getArch() == llvm::Triple::x86_64 ||
904  getTriple().getArch() == llvm::Triple::arm ||
905  getTriple().getArch() == llvm::Triple::aarch64 ||
906  getTriple().getArch() == llvm::Triple::wasm32 ||
907  getTriple().getArch() == llvm::Triple::wasm64)
908  Res |= SanitizerKind::CFIICall;
909  if (getTriple().getArch() == llvm::Triple::x86_64 ||
910  getTriple().getArch() == llvm::Triple::aarch64)
911  Res |= SanitizerKind::ShadowCallStack;
912  return Res;
913 }
914 
915 void ToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
916  ArgStringList &CC1Args) const {}
917 
918 void ToolChain::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
919  ArgStringList &CC1Args) const {}
920 
921 static VersionTuple separateMSVCFullVersion(unsigned Version) {
922  if (Version < 100)
923  return VersionTuple(Version);
924 
925  if (Version < 10000)
926  return VersionTuple(Version / 100, Version % 100);
927 
928  unsigned Build = 0, Factor = 1;
929  for (; Version > 10000; Version = Version / 10, Factor = Factor * 10)
930  Build = Build + (Version % 10) * Factor;
931  return VersionTuple(Version / 100, Version % 100, Build);
932 }
933 
934 VersionTuple
936  const llvm::opt::ArgList &Args) const {
937  const Arg *MSCVersion = Args.getLastArg(options::OPT_fmsc_version);
938  const Arg *MSCompatibilityVersion =
939  Args.getLastArg(options::OPT_fms_compatibility_version);
940 
941  if (MSCVersion && MSCompatibilityVersion) {
942  if (D)
943  D->Diag(diag::err_drv_argument_not_allowed_with)
944  << MSCVersion->getAsString(Args)
945  << MSCompatibilityVersion->getAsString(Args);
946  return VersionTuple();
947  }
948 
949  if (MSCompatibilityVersion) {
950  VersionTuple MSVT;
951  if (MSVT.tryParse(MSCompatibilityVersion->getValue())) {
952  if (D)
953  D->Diag(diag::err_drv_invalid_value)
954  << MSCompatibilityVersion->getAsString(Args)
955  << MSCompatibilityVersion->getValue();
956  } else {
957  return MSVT;
958  }
959  }
960 
961  if (MSCVersion) {
962  unsigned Version = 0;
963  if (StringRef(MSCVersion->getValue()).getAsInteger(10, Version)) {
964  if (D)
965  D->Diag(diag::err_drv_invalid_value)
966  << MSCVersion->getAsString(Args) << MSCVersion->getValue();
967  } else {
968  return separateMSVCFullVersion(Version);
969  }
970  }
971 
972  return VersionTuple();
973 }
974 
975 llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs(
976  const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,
977  SmallVectorImpl<llvm::opt::Arg *> &AllocatedArgs) const {
978  DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
979  const OptTable &Opts = getDriver().getOpts();
980  bool Modified = false;
981 
982  // Handle -Xopenmp-target flags
983  for (auto *A : Args) {
984  // Exclude flags which may only apply to the host toolchain.
985  // Do not exclude flags when the host triple (AuxTriple)
986  // matches the current toolchain triple. If it is not present
987  // at all, target and host share a toolchain.
988  if (A->getOption().matches(options::OPT_m_Group)) {
989  if (SameTripleAsHost)
990  DAL->append(A);
991  else
992  Modified = true;
993  continue;
994  }
995 
996  unsigned Index;
997  unsigned Prev;
998  bool XOpenMPTargetNoTriple =
999  A->getOption().matches(options::OPT_Xopenmp_target);
1000 
1001  if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
1002  // Passing device args: -Xopenmp-target=<triple> -opt=val.
1003  if (A->getValue(0) == getTripleString())
1004  Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
1005  else
1006  continue;
1007  } else if (XOpenMPTargetNoTriple) {
1008  // Passing device args: -Xopenmp-target -opt=val.
1009  Index = Args.getBaseArgs().MakeIndex(A->getValue(0));
1010  } else {
1011  DAL->append(A);
1012  continue;
1013  }
1014 
1015  // Parse the argument to -Xopenmp-target.
1016  Prev = Index;
1017  std::unique_ptr<Arg> XOpenMPTargetArg(Opts.ParseOneArg(Args, Index));
1018  if (!XOpenMPTargetArg || Index > Prev + 1) {
1019  getDriver().Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
1020  << A->getAsString(Args);
1021  continue;
1022  }
1023  if (XOpenMPTargetNoTriple && XOpenMPTargetArg &&
1024  Args.getAllArgValues(options::OPT_fopenmp_targets_EQ).size() != 1) {
1025  getDriver().Diag(diag::err_drv_Xopenmp_target_missing_triple);
1026  continue;
1027  }
1028  XOpenMPTargetArg->setBaseArg(A);
1029  A = XOpenMPTargetArg.release();
1030  AllocatedArgs.push_back(A);
1031  DAL->append(A);
1032  Modified = true;
1033  }
1034 
1035  if (Modified)
1036  return DAL;
1037 
1038  delete DAL;
1039  return nullptr;
1040 }
virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const
Add warning options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:705
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:794
void setTripleEnvironment(llvm::Triple::EnvironmentType Env)
Definition: ToolChain.cpp:89
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:570
static void addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Definition: ToolChain.cpp:801
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:862
virtual const char * getDefaultLinker() const
GetDefaultLinker - Get the default linker to use.
Definition: ToolChain.h:367
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:29
virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const
getDefaultObjCRuntime - Return the default Objective-C runtime for this platform. ...
Definition: ToolChain.cpp:545
StringRef P
Defines types useful for describing an Objective-C runtime.
The base class of the type hierarchy.
Definition: Type.h:1418
const XRayArgs & getXRayArgs() const
Definition: ToolChain.cpp:121
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:818
StringRef getOS() const
Definition: ToolChain.h:212
virtual bool isThreadModelSupported(const StringRef Model) const
isThreadModelSupported() - Does this target support a thread model?
Definition: ToolChain.cpp:555
virtual bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const
IsUnwindTablesDefault - Does this tool chain use -funwind-tables by default.
Definition: ToolChain.cpp:246
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:108
&#39;gcc&#39; is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI ...
Definition: ObjCRuntime.h:52
static ParsedClangName getTargetAndModeFromProgramName(StringRef ProgName)
Return any implicit target and/or mode flag for an invocation of the compiler driver as ProgName...
Definition: ToolChain.cpp:203
static VersionTuple separateMSVCFullVersion(unsigned Version)
Definition: ToolChain.cpp:921
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:707
std::string GetLinkerPath() const
Returns the linker path, respecting the -fuse-ld= argument to determine the linker suffix or name...
Definition: ToolChain.cpp:489
FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args)
Clang integrated assembler tool.
Definition: Clang.h:114
long i
Definition: xmmintrin.h:1456
Defines the clang::SanitizerKind enum.
const std::string getARMArch(llvm::StringRef Arch, const llvm::Triple &Triple)
const char * getFilename() const
Definition: InputInfo.h:83
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:696
static StringRef getArchNameForCompilerRTLib(const ToolChain &TC, const ArgList &Args)
Definition: ToolChain.cpp:322
StringRef getOSLibName() const
Definition: ToolChain.cpp:339
static bool needsProfileRT(const llvm::opt::ArgList &Args)
needsProfileRT - returns true if instrumentation profile is on.
Definition: ToolChain.cpp:452
std::string getTripleString() const
Definition: ToolChain.h:218
StringRef getARMCPUForMArch(llvm::StringRef Arch, const llvm::Triple &Triple)
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:481
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
path_list & getFilePaths()
Definition: ToolChain.h:231
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:867
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:57
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition: ToolChain.cpp:72
virtual bool IsIntegratedAssemblerDefault() const
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: ToolChain.h:331
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:302
virtual bool useRelaxRelocations() const
Check whether to enable x86 relax relocations by default.
Definition: ToolChain.cpp:107
virtual bool useIntegratedAs() const
Check if the toolchain should use the integrated assembler.
Definition: ToolChain.cpp:101
ActionClass getKind() const
Definition: Action.h:139
virtual VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const
On Windows, returns the MSVC compatibility version.
Definition: ToolChain.cpp:935
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:809
virtual llvm::ExceptionHandling GetExceptionModel(const llvm::opt::ArgList &Args) const
GetExceptionModel - Return the tool chain exception model.
Definition: ToolChain.cpp:551
static llvm::opt::Arg * GetRTTIArgument(const ArgList &Args)
Definition: ToolChain.cpp:52
virtual UnwindLibType GetDefaultUnwindLibType() const
Definition: ToolChain.h:378
virtual Tool * buildLinker() const
Definition: ToolChain.cpp:260
static const DriverSuffix * parseDriverSuffix(StringRef ProgName, size_t &Pos)
Definition: ToolChain.cpp:176
virtual llvm::opt::DerivedArgList * TranslateOpenMPTargetArgs(const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost, SmallVectorImpl< llvm::opt::Arg *> &AllocatedArgs) const
TranslateOpenMPTargetArgs - Create a new derived argument list for that contains the OpenMP target sp...
Definition: ToolChain.cpp:975
virtual types::ID LookupTypeForExtension(StringRef Ext) const
LookupTypeForExtension - Return the default language type to use for the given extension.
Definition: ToolChain.cpp:521
virtual Optional< std::string > getCXXStdlibPath() const
Definition: ToolChain.cpp:427
virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:733
static const DriverSuffix * FindDriverSuffix(StringRef ProgName, size_t &Pos)
Definition: ToolChain.cpp:136
virtual bool isNoExecStackDefault() const
Test whether this toolchaind defaults to non-executable stacks.
Definition: ToolChain.cpp:111
&#39;gnustep&#39; is the modern non-fragile GNUstep runtime.
Definition: ObjCRuntime.h:55
virtual CXXStdlibType GetDefaultCXXStdlibType() const
Definition: ToolChain.h:374
path_list & getLibraryPaths()
Definition: ToolChain.h:228
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:209
virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use system-specific CUDA includes.
Definition: ToolChain.cpp:915
virtual std::string getInputFilename(const InputInfo &Input) const
Some toolchains need to modify the file name, for example to replace the extension for object files w...
Definition: ToolChain.cpp:242
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:364
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:855
Offload bundler tool.
Definition: Clang.h:135
const Driver & getDriver() const
Definition: ToolChain.h:193
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:172
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:779
virtual bool HasNativeLLVMSupport() const
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition: ToolChain.cpp:525
constexpr XRayInstrMask None
Definition: XRayInstr.h:37
virtual RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:714
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:97
virtual Tool * buildAssembler() const
Definition: ToolChain.cpp:256
Helper structure used to pass information extracted from clang executable name such as i686-linux-and...
Definition: ToolChain.h:61
std::string getARMTargetCPU(StringRef CPU, llvm::StringRef Arch, const llvm::Triple &Triple)
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
Definition: ToolChain.cpp:832
Dataflow Directional Tag Classes.
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:691
Clang compiler tool.
Definition: Clang.h:28
static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, const llvm::Triple &Triple, const Arg *CachedRTTIArg)
Definition: ToolChain.cpp:57
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:27
Tool - Information on a specific compilation tool.
Definition: Tool.h:33
const SanitizerArgs & getSanitizerArgs() const
Definition: ToolChain.cpp:115
static std::string normalizeProgramName(llvm::StringRef Argv0)
Normalize the program name from argv[0] by stripping the file extension if present and lower-casing t...
Definition: ToolChain.cpp:167
virtual Optional< std::string > getRuntimePath() const
Definition: ToolChain.cpp:409
StringRef getDefaultUniversalArchName() const
Provide the default architecture name (as expected by -arch) for this toolchain.
Definition: ToolChain.cpp:225
const llvm::Triple & getTriple() const
Definition: ToolChain.h:195
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:891
ID lookupTypeForExtension(llvm::StringRef Ext)
lookupTypeForExtension - Lookup the type to use for the file extension Ext.
Definition: Types.cpp:194
std::string getArchSpecificLibPath() const
Definition: ToolChain.cpp:445
virtual Tool * getTool(Action::ActionClass AC) const
Definition: ToolChain.cpp:288
virtual std::string getCompilerRTPath() const
Definition: ToolChain.cpp:354
const char * getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:402
std::string GetProgramPath(const char *Name) const
Definition: ToolChain.cpp:485
static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args)
Returns true if gcov instrumentation (-fprofile-arcs or –coverage) is on.
Definition: ToolChain.cpp:467
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:298
virtual bool isCrossCompiling() const
Returns true if the toolchain is targeting a non-native architecture.
Definition: ToolChain.cpp:529
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:760
virtual Tool * SelectTool(const JobAction &JA) const
Choose a tool to use to handle the action JA.
Definition: ToolChain.cpp:473
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use MCU GCC toolchain includes.
Definition: ToolChain.cpp:918
StringRef getLLVMArchSuffixForARM(llvm::StringRef CPU, llvm::StringRef Arch, const llvm::Triple &Triple)
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const
Add options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:701
virtual RuntimeLibType GetDefaultRuntimeLibType() const
GetDefaultRuntimeLibType - Get the default runtime library variant to use.
Definition: ToolChain.h:370
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:838
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88