clang 19.0.0git
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
11#include "ToolChains/Arch/ARM.h"
12#include "ToolChains/Clang.h"
14#include "ToolChains/Flang.h"
18#include "clang/Config/config.h"
19#include "clang/Driver/Action.h"
20#include "clang/Driver/Driver.h"
23#include "clang/Driver/Job.h"
27#include "llvm/ADT/STLExtras.h"
28#include "llvm/ADT/SmallString.h"
29#include "llvm/ADT/StringExtras.h"
30#include "llvm/ADT/StringRef.h"
31#include "llvm/ADT/Twine.h"
32#include "llvm/Config/llvm-config.h"
33#include "llvm/MC/MCTargetOptions.h"
34#include "llvm/MC/TargetRegistry.h"
35#include "llvm/Option/Arg.h"
36#include "llvm/Option/ArgList.h"
37#include "llvm/Option/OptTable.h"
38#include "llvm/Option/Option.h"
39#include "llvm/Support/ErrorHandling.h"
40#include "llvm/Support/FileSystem.h"
41#include "llvm/Support/FileUtilities.h"
42#include "llvm/Support/Path.h"
43#include "llvm/Support/VersionTuple.h"
44#include "llvm/Support/VirtualFileSystem.h"
45#include "llvm/TargetParser/AArch64TargetParser.h"
46#include "llvm/TargetParser/TargetParser.h"
47#include "llvm/TargetParser/Triple.h"
48#include <cassert>
49#include <cstddef>
50#include <cstring>
51#include <string>
52
53using namespace clang;
54using namespace driver;
55using namespace tools;
56using namespace llvm;
57using namespace llvm::opt;
58
59static llvm::opt::Arg *GetRTTIArgument(const ArgList &Args) {
60 return Args.getLastArg(options::OPT_mkernel, options::OPT_fapple_kext,
61 options::OPT_fno_rtti, options::OPT_frtti);
62}
63
64static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args,
65 const llvm::Triple &Triple,
66 const Arg *CachedRTTIArg) {
67 // Explicit rtti/no-rtti args
68 if (CachedRTTIArg) {
69 if (CachedRTTIArg->getOption().matches(options::OPT_frtti))
71 else
73 }
74
75 // -frtti is default, except for the PS4/PS5 and DriverKit.
76 bool NoRTTI = Triple.isPS() || Triple.isDriverKit();
78}
79
81 if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
82 true)) {
84 }
86}
87
88ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
89 const ArgList &Args)
90 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
91 CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)),
92 CachedExceptionsMode(CalculateExceptionsMode(Args)) {
93 auto addIfExists = [this](path_list &List, const std::string &Path) {
94 if (getVFS().exists(Path))
95 List.push_back(Path);
96 };
97
98 if (std::optional<std::string> Path = getRuntimePath())
99 getLibraryPaths().push_back(*Path);
100 if (std::optional<std::string> Path = getStdlibPath())
101 getFilePaths().push_back(*Path);
102 for (const auto &Path : getArchSpecificLibPaths())
103 addIfExists(getFilePaths(), Path);
104}
105
108 unsigned SecondsToWait) const {
109 llvm::SmallString<64> OutputFile;
110 llvm::sys::fs::createTemporaryFile("toolchain-program", "txt", OutputFile);
111 llvm::FileRemover OutputRemover(OutputFile.c_str());
112 std::optional<llvm::StringRef> Redirects[] = {
113 {""},
114 OutputFile.str(),
115 {""},
116 };
117
118 std::string ErrorMessage;
119 if (llvm::sys::ExecuteAndWait(Executable, {}, {}, Redirects, SecondsToWait,
120 /*MemoryLimit=*/0, &ErrorMessage))
121 return llvm::createStringError(std::error_code(),
122 Executable + ": " + ErrorMessage);
123
124 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> OutputBuf =
125 llvm::MemoryBuffer::getFile(OutputFile.c_str());
126 if (!OutputBuf)
127 return llvm::createStringError(OutputBuf.getError(),
128 "Failed to read stdout of " + Executable +
129 ": " + OutputBuf.getError().message());
130 return std::move(*OutputBuf);
131}
132
133void ToolChain::setTripleEnvironment(llvm::Triple::EnvironmentType Env) {
134 Triple.setEnvironment(Env);
135 if (EffectiveTriple != llvm::Triple())
136 EffectiveTriple.setEnvironment(Env);
137}
138
139ToolChain::~ToolChain() = default;
140
141llvm::vfs::FileSystem &ToolChain::getVFS() const {
142 return getDriver().getVFS();
143}
144
146 return Args.hasFlag(options::OPT_fintegrated_as,
147 options::OPT_fno_integrated_as,
149}
150
152 assert(
155 "(Non-)integrated backend set incorrectly!");
156
157 bool IBackend = Args.hasFlag(options::OPT_fintegrated_objemitter,
158 options::OPT_fno_integrated_objemitter,
160
161 // Diagnose when integrated-objemitter options are not supported by this
162 // toolchain.
163 unsigned DiagID;
164 if ((IBackend && !IsIntegratedBackendSupported()) ||
165 (!IBackend && !IsNonIntegratedBackendSupported()))
166 DiagID = clang::diag::err_drv_unsupported_opt_for_target;
167 else
168 DiagID = clang::diag::warn_drv_unsupported_opt_for_target;
169 Arg *A = Args.getLastArg(options::OPT_fno_integrated_objemitter);
171 D.Diag(DiagID) << A->getAsString(Args) << Triple.getTriple();
172 A = Args.getLastArg(options::OPT_fintegrated_objemitter);
174 D.Diag(DiagID) << A->getAsString(Args) << Triple.getTriple();
175
176 return IBackend;
177}
178
180 return ENABLE_X86_RELAX_RELOCATIONS;
181}
182
184 return PPC_LINUX_DEFAULT_IEEELONGDOUBLE && getTriple().isOSLinux();
185}
186
188 const llvm::Triple &Triple,
189 const llvm::opt::ArgList &Args,
191 std::vector<StringRef> Features;
192 tools::aarch64::getAArch64TargetFeatures(D, Triple, Args, Features, false);
193 const auto UnifiedFeatures = tools::unifyTargetFeatures(Features);
194 llvm::DenseSet<StringRef> FeatureSet(UnifiedFeatures.begin(),
195 UnifiedFeatures.end());
196 std::vector<std::string> MArch;
197 for (const auto &Ext : AArch64::Extensions)
198 if (!Ext.UserVisibleName.empty())
199 if (FeatureSet.contains(Ext.PosTargetFeature))
200 MArch.push_back(Ext.UserVisibleName.str());
201 for (const auto &Ext : AArch64::Extensions)
202 if (!Ext.UserVisibleName.empty())
203 if (FeatureSet.contains(Ext.NegTargetFeature))
204 MArch.push_back(("no" + Ext.UserVisibleName).str());
205 StringRef ArchName;
206 for (const auto &ArchInfo : AArch64::ArchInfos)
207 if (FeatureSet.contains(ArchInfo->ArchFeature))
208 ArchName = ArchInfo->Name;
209 assert(!ArchName.empty() && "at least one architecture should be found");
210 MArch.insert(MArch.begin(), ("-march=" + ArchName).str());
211 Result.push_back(llvm::join(MArch, "+"));
212}
213
214static void getARMMultilibFlags(const Driver &D,
215 const llvm::Triple &Triple,
216 const llvm::opt::ArgList &Args,
218 std::vector<StringRef> Features;
219 llvm::ARM::FPUKind FPUKind = tools::arm::getARMTargetFeatures(
220 D, Triple, Args, Features, false /*ForAs*/, true /*ForMultilib*/);
221 const auto UnifiedFeatures = tools::unifyTargetFeatures(Features);
222 llvm::DenseSet<StringRef> FeatureSet(UnifiedFeatures.begin(),
223 UnifiedFeatures.end());
224 std::vector<std::string> MArch;
225 for (const auto &Ext : ARM::ARCHExtNames)
226 if (!Ext.Name.empty())
227 if (FeatureSet.contains(Ext.Feature))
228 MArch.push_back(Ext.Name.str());
229 for (const auto &Ext : ARM::ARCHExtNames)
230 if (!Ext.Name.empty())
231 if (FeatureSet.contains(Ext.NegFeature))
232 MArch.push_back(("no" + Ext.Name).str());
233 MArch.insert(MArch.begin(), ("-march=" + Triple.getArchName()).str());
234 Result.push_back(llvm::join(MArch, "+"));
235
236 switch (FPUKind) {
237#define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) \
238 case llvm::ARM::KIND: \
239 Result.push_back("-mfpu=" NAME); \
240 break;
241#include "llvm/TargetParser/ARMTargetParser.def"
242 default:
243 llvm_unreachable("Invalid FPUKind");
244 }
245
246 switch (arm::getARMFloatABI(D, Triple, Args)) {
247 case arm::FloatABI::Soft:
248 Result.push_back("-mfloat-abi=soft");
249 break;
250 case arm::FloatABI::SoftFP:
251 Result.push_back("-mfloat-abi=softfp");
252 break;
253 case arm::FloatABI::Hard:
254 Result.push_back("-mfloat-abi=hard");
255 break;
256 case arm::FloatABI::Invalid:
257 llvm_unreachable("Invalid float ABI");
258 }
259}
260
262ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
263 using namespace clang::driver::options;
264
265 std::vector<std::string> Result;
266 const llvm::Triple Triple(ComputeEffectiveClangTriple(Args));
267 Result.push_back("--target=" + Triple.str());
268
269 switch (Triple.getArch()) {
270 case llvm::Triple::aarch64:
271 case llvm::Triple::aarch64_32:
272 case llvm::Triple::aarch64_be:
273 getAArch64MultilibFlags(D, Triple, Args, Result);
274 break;
275 case llvm::Triple::arm:
276 case llvm::Triple::armeb:
277 case llvm::Triple::thumb:
278 case llvm::Triple::thumbeb:
279 getARMMultilibFlags(D, Triple, Args, Result);
280 break;
281 default:
282 break;
283 }
284
285 // Include fno-exceptions and fno-rtti
286 // to improve multilib selection
288 Result.push_back("-fno-rtti");
289 else
290 Result.push_back("-frtti");
291
293 Result.push_back("-fno-exceptions");
294 else
295 Result.push_back("-fexceptions");
296
297 // Sort and remove duplicates.
298 std::sort(Result.begin(), Result.end());
299 Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
300 return Result;
301}
302
304ToolChain::getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const {
305 SanitizerArgs SanArgs(*this, JobArgs, !SanitizerArgsChecked);
306 SanitizerArgsChecked = true;
307 return SanArgs;
308}
309
311 if (!XRayArguments)
312 XRayArguments.reset(new XRayArgs(*this, Args));
313 return *XRayArguments;
314}
315
316namespace {
317
318struct DriverSuffix {
319 const char *Suffix;
320 const char *ModeFlag;
321};
322
323} // namespace
324
325static const DriverSuffix *FindDriverSuffix(StringRef ProgName, size_t &Pos) {
326 // A list of known driver suffixes. Suffixes are compared against the
327 // program name in order. If there is a match, the frontend type is updated as
328 // necessary by applying the ModeFlag.
329 static const DriverSuffix DriverSuffixes[] = {
330 {"clang", nullptr},
331 {"clang++", "--driver-mode=g++"},
332 {"clang-c++", "--driver-mode=g++"},
333 {"clang-cc", nullptr},
334 {"clang-cpp", "--driver-mode=cpp"},
335 {"clang-g++", "--driver-mode=g++"},
336 {"clang-gcc", nullptr},
337 {"clang-cl", "--driver-mode=cl"},
338 {"cc", nullptr},
339 {"cpp", "--driver-mode=cpp"},
340 {"cl", "--driver-mode=cl"},
341 {"++", "--driver-mode=g++"},
342 {"flang", "--driver-mode=flang"},
343 {"clang-dxc", "--driver-mode=dxc"},
344 };
345
346 for (const auto &DS : DriverSuffixes) {
347 StringRef Suffix(DS.Suffix);
348 if (ProgName.ends_with(Suffix)) {
349 Pos = ProgName.size() - Suffix.size();
350 return &DS;
351 }
352 }
353 return nullptr;
354}
355
356/// Normalize the program name from argv[0] by stripping the file extension if
357/// present and lower-casing the string on Windows.
358static std::string normalizeProgramName(llvm::StringRef Argv0) {
359 std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
360 if (is_style_windows(llvm::sys::path::Style::native)) {
361 // Transform to lowercase for case insensitive file systems.
362 std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
363 ::tolower);
364 }
365 return ProgName;
366}
367
368static const DriverSuffix *parseDriverSuffix(StringRef ProgName, size_t &Pos) {
369 // Try to infer frontend type and default target from the program name by
370 // comparing it against DriverSuffixes in order.
371
372 // If there is a match, the function tries to identify a target as prefix.
373 // E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target
374 // prefix "x86_64-linux". If such a target prefix is found, it may be
375 // added via -target as implicit first argument.
376 const DriverSuffix *DS = FindDriverSuffix(ProgName, Pos);
377
378 if (!DS && ProgName.ends_with(".exe")) {
379 // Try again after stripping the executable suffix:
380 // clang++.exe -> clang++
381 ProgName = ProgName.drop_back(StringRef(".exe").size());
382 DS = FindDriverSuffix(ProgName, Pos);
383 }
384
385 if (!DS) {
386 // Try again after stripping any trailing version number:
387 // clang++3.5 -> clang++
388 ProgName = ProgName.rtrim("0123456789.");
389 DS = FindDriverSuffix(ProgName, Pos);
390 }
391
392 if (!DS) {
393 // Try again after stripping trailing -component.
394 // clang++-tot -> clang++
395 ProgName = ProgName.slice(0, ProgName.rfind('-'));
396 DS = FindDriverSuffix(ProgName, Pos);
397 }
398 return DS;
399}
400
403 std::string ProgName = normalizeProgramName(PN);
404 size_t SuffixPos;
405 const DriverSuffix *DS = parseDriverSuffix(ProgName, SuffixPos);
406 if (!DS)
407 return {};
408 size_t SuffixEnd = SuffixPos + strlen(DS->Suffix);
409
410 size_t LastComponent = ProgName.rfind('-', SuffixPos);
411 if (LastComponent == std::string::npos)
412 return ParsedClangName(ProgName.substr(0, SuffixEnd), DS->ModeFlag);
413 std::string ModeSuffix = ProgName.substr(LastComponent + 1,
414 SuffixEnd - LastComponent - 1);
415
416 // Infer target from the prefix.
417 StringRef Prefix(ProgName);
418 Prefix = Prefix.slice(0, LastComponent);
419 std::string IgnoredError;
420 bool IsRegistered =
421 llvm::TargetRegistry::lookupTarget(std::string(Prefix), IgnoredError);
422 return ParsedClangName{std::string(Prefix), ModeSuffix, DS->ModeFlag,
423 IsRegistered};
424}
425
427 // In universal driver terms, the arch name accepted by -arch isn't exactly
428 // the same as the ones that appear in the triple. Roughly speaking, this is
429 // an inverse of the darwin::getArchTypeForDarwinArchName() function.
430 switch (Triple.getArch()) {
431 case llvm::Triple::aarch64: {
432 if (getTriple().isArm64e())
433 return "arm64e";
434 return "arm64";
435 }
436 case llvm::Triple::aarch64_32:
437 return "arm64_32";
438 case llvm::Triple::ppc:
439 return "ppc";
440 case llvm::Triple::ppcle:
441 return "ppcle";
442 case llvm::Triple::ppc64:
443 return "ppc64";
444 case llvm::Triple::ppc64le:
445 return "ppc64le";
446 default:
447 return Triple.getArchName();
448 }
449}
450
451std::string ToolChain::getInputFilename(const InputInfo &Input) const {
452 return Input.getFilename();
453}
454
456ToolChain::getDefaultUnwindTableLevel(const ArgList &Args) const {
458}
459
460Tool *ToolChain::getClang() const {
461 if (!Clang)
462 Clang.reset(new tools::Clang(*this, useIntegratedBackend()));
463 return Clang.get();
464}
465
466Tool *ToolChain::getFlang() const {
467 if (!Flang)
468 Flang.reset(new tools::Flang(*this));
469 return Flang.get();
470}
471
473 return new tools::ClangAs(*this);
474}
475
477 llvm_unreachable("Linking is not supported by this toolchain");
478}
479
481 llvm_unreachable("Creating static lib is not supported by this toolchain");
482}
483
484Tool *ToolChain::getAssemble() const {
485 if (!Assemble)
486 Assemble.reset(buildAssembler());
487 return Assemble.get();
488}
489
490Tool *ToolChain::getClangAs() const {
491 if (!Assemble)
492 Assemble.reset(new tools::ClangAs(*this));
493 return Assemble.get();
494}
495
496Tool *ToolChain::getLink() const {
497 if (!Link)
498 Link.reset(buildLinker());
499 return Link.get();
500}
501
502Tool *ToolChain::getStaticLibTool() const {
503 if (!StaticLibTool)
504 StaticLibTool.reset(buildStaticLibTool());
505 return StaticLibTool.get();
506}
507
508Tool *ToolChain::getIfsMerge() const {
509 if (!IfsMerge)
510 IfsMerge.reset(new tools::ifstool::Merger(*this));
511 return IfsMerge.get();
512}
513
514Tool *ToolChain::getOffloadBundler() const {
515 if (!OffloadBundler)
516 OffloadBundler.reset(new tools::OffloadBundler(*this));
517 return OffloadBundler.get();
518}
519
520Tool *ToolChain::getOffloadPackager() const {
521 if (!OffloadPackager)
522 OffloadPackager.reset(new tools::OffloadPackager(*this));
523 return OffloadPackager.get();
524}
525
526Tool *ToolChain::getLinkerWrapper() const {
527 if (!LinkerWrapper)
528 LinkerWrapper.reset(new tools::LinkerWrapper(*this, getLink()));
529 return LinkerWrapper.get();
530}
531
533 switch (AC) {
535 return getAssemble();
536
538 return getIfsMerge();
539
541 return getLink();
542
544 return getStaticLibTool();
545
553 llvm_unreachable("Invalid tool kind.");
554
563 return getClang();
564
567 return getOffloadBundler();
568
570 return getOffloadPackager();
572 return getLinkerWrapper();
573 }
574
575 llvm_unreachable("Invalid tool kind.");
576}
577
578static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
579 const ArgList &Args) {
580 const llvm::Triple &Triple = TC.getTriple();
581 bool IsWindows = Triple.isOSWindows();
582
583 if (TC.isBareMetal())
584 return Triple.getArchName();
585
586 if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb)
587 return (arm::getARMFloatABI(TC, Args) == arm::FloatABI::Hard && !IsWindows)
588 ? "armhf"
589 : "arm";
590
591 // For historic reasons, Android library is using i686 instead of i386.
592 if (TC.getArch() == llvm::Triple::x86 && Triple.isAndroid())
593 return "i686";
594
595 if (TC.getArch() == llvm::Triple::x86_64 && Triple.isX32())
596 return "x32";
597
598 return llvm::Triple::getArchTypeName(TC.getArch());
599}
600
601StringRef ToolChain::getOSLibName() const {
602 if (Triple.isOSDarwin())
603 return "darwin";
604
605 switch (Triple.getOS()) {
606 case llvm::Triple::FreeBSD:
607 return "freebsd";
608 case llvm::Triple::NetBSD:
609 return "netbsd";
610 case llvm::Triple::OpenBSD:
611 return "openbsd";
612 case llvm::Triple::Solaris:
613 return "sunos";
614 case llvm::Triple::AIX:
615 return "aix";
616 default:
617 return getOS();
618 }
619}
620
621std::string ToolChain::getCompilerRTPath() const {
622 SmallString<128> Path(getDriver().ResourceDir);
623 if (isBareMetal()) {
624 llvm::sys::path::append(Path, "lib", getOSLibName());
625 if (!SelectedMultilibs.empty()) {
626 Path += SelectedMultilibs.back().gccSuffix();
627 }
628 } else if (Triple.isOSUnknown()) {
629 llvm::sys::path::append(Path, "lib");
630 } else {
631 llvm::sys::path::append(Path, "lib", getOSLibName());
632 }
633 return std::string(Path);
634}
635
636std::string ToolChain::getCompilerRTBasename(const ArgList &Args,
637 StringRef Component,
638 FileType Type) const {
639 std::string CRTAbsolutePath = getCompilerRT(Args, Component, Type);
640 return llvm::sys::path::filename(CRTAbsolutePath).str();
641}
642
643std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args,
644 StringRef Component,
646 bool AddArch) const {
647 const llvm::Triple &TT = getTriple();
648 bool IsITANMSVCWindows =
649 TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
650
651 const char *Prefix =
652 IsITANMSVCWindows || Type == ToolChain::FT_Object ? "" : "lib";
653 const char *Suffix;
654 switch (Type) {
656 Suffix = IsITANMSVCWindows ? ".obj" : ".o";
657 break;
659 Suffix = IsITANMSVCWindows ? ".lib" : ".a";
660 break;
662 Suffix = TT.isOSWindows()
663 ? (TT.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
664 : ".so";
665 break;
666 }
667
668 std::string ArchAndEnv;
669 if (AddArch) {
670 StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
671 const char *Env = TT.isAndroid() ? "-android" : "";
672 ArchAndEnv = ("-" + Arch + Env).str();
673 }
674 return (Prefix + Twine("clang_rt.") + Component + ArchAndEnv + Suffix).str();
675}
676
677std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
678 FileType Type) const {
679 // Check for runtime files in the new layout without the architecture first.
680 std::string CRTBasename =
681 buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
683 for (const auto &LibPath : getLibraryPaths()) {
684 SmallString<128> P(LibPath);
685 llvm::sys::path::append(P, CRTBasename);
686 if (getVFS().exists(P))
687 return std::string(P);
688 if (Path.empty())
689 Path = P;
690 }
691 if (getTriple().isOSAIX())
692 Path.clear();
693
694 // Check the filename for the old layout if the new one does not exist.
695 CRTBasename =
696 buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
698 llvm::sys::path::append(OldPath, CRTBasename);
699 if (Path.empty() || getVFS().exists(OldPath))
700 return std::string(OldPath);
701
702 // If none is found, use a file name from the new layout, which may get
703 // printed in an error message, aiding users in knowing what Clang is
704 // looking for.
705 return std::string(Path);
706}
707
708const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
709 StringRef Component,
710 FileType Type) const {
711 return Args.MakeArgString(getCompilerRT(Args, Component, Type));
712}
713
714// Android target triples contain a target version. If we don't have libraries
715// for the exact target version, we should fall back to the next newest version
716// or a versionless path, if any.
717std::optional<std::string>
718ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) const {
719 llvm::Triple TripleWithoutLevel(getTriple());
720 TripleWithoutLevel.setEnvironmentName("android"); // remove any version number
721 const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str();
722 unsigned TripleVersion = getTriple().getEnvironmentVersion().getMajor();
723 unsigned BestVersion = 0;
724
725 SmallString<32> TripleDir;
726 bool UsingUnversionedDir = false;
727 std::error_code EC;
728 for (llvm::vfs::directory_iterator LI = getVFS().dir_begin(BaseDir, EC), LE;
729 !EC && LI != LE; LI = LI.increment(EC)) {
730 StringRef DirName = llvm::sys::path::filename(LI->path());
731 StringRef DirNameSuffix = DirName;
732 if (DirNameSuffix.consume_front(TripleWithoutLevelStr)) {
733 if (DirNameSuffix.empty() && TripleDir.empty()) {
734 TripleDir = DirName;
735 UsingUnversionedDir = true;
736 } else {
737 unsigned Version;
738 if (!DirNameSuffix.getAsInteger(10, Version) && Version > BestVersion &&
739 Version < TripleVersion) {
740 BestVersion = Version;
741 TripleDir = DirName;
742 UsingUnversionedDir = false;
743 }
744 }
745 }
746 }
747
748 if (TripleDir.empty())
749 return {};
750
751 SmallString<128> P(BaseDir);
752 llvm::sys::path::append(P, TripleDir);
753 if (UsingUnversionedDir)
754 D.Diag(diag::warn_android_unversioned_fallback) << P << getTripleString();
755 return std::string(P);
756}
757
758std::optional<std::string>
759ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
760 auto getPathForTriple =
761 [&](const llvm::Triple &Triple) -> std::optional<std::string> {
762 SmallString<128> P(BaseDir);
763 llvm::sys::path::append(P, Triple.str());
764 if (getVFS().exists(P))
765 return std::string(P);
766 return {};
767 };
768
769 if (auto Path = getPathForTriple(getTriple()))
770 return *Path;
771
772 // When building with per target runtime directories, various ways of naming
773 // the Arm architecture may have been normalised to simply "arm".
774 // For example "armv8l" (Armv8 AArch32 little endian) is replaced with "arm".
775 // Since an armv8l system can use libraries built for earlier architecture
776 // versions assuming endian and float ABI match.
777 //
778 // Original triple: armv8l-unknown-linux-gnueabihf
779 // Runtime triple: arm-unknown-linux-gnueabihf
780 //
781 // We do not do this for armeb (big endian) because doing so could make us
782 // select little endian libraries. In addition, all known armeb triples only
783 // use the "armeb" architecture name.
784 //
785 // M profile Arm is bare metal and we know they will not be using the per
786 // target runtime directory layout.
787 if (getTriple().getArch() == Triple::arm && !getTriple().isArmMClass()) {
788 llvm::Triple ArmTriple = getTriple();
789 ArmTriple.setArch(Triple::arm);
790 if (auto Path = getPathForTriple(ArmTriple))
791 return *Path;
792 }
793
794 if (getTriple().isAndroid())
795 return getFallbackAndroidTargetPath(BaseDir);
796
797 return {};
798}
799
800std::optional<std::string> ToolChain::getRuntimePath() const {
802 llvm::sys::path::append(P, "lib");
803 if (auto Ret = getTargetSubDirPath(P))
804 return Ret;
805 // Darwin does not use per-target runtime directory.
806 if (Triple.isOSDarwin())
807 return {};
808 llvm::sys::path::append(P, Triple.str());
809 return std::string(P);
810}
811
812std::optional<std::string> ToolChain::getStdlibPath() const {
814 llvm::sys::path::append(P, "..", "lib");
815 return getTargetSubDirPath(P);
816}
817
818std::optional<std::string> ToolChain::getStdlibIncludePath() const {
820 llvm::sys::path::append(P, "..", "include");
821 return getTargetSubDirPath(P);
822}
823
825 path_list Paths;
826
827 auto AddPath = [&](const ArrayRef<StringRef> &SS) {
828 SmallString<128> Path(getDriver().ResourceDir);
829 llvm::sys::path::append(Path, "lib");
830 for (auto &S : SS)
831 llvm::sys::path::append(Path, S);
832 Paths.push_back(std::string(Path));
833 };
834
835 AddPath({getTriple().str()});
836 AddPath({getOSLibName(), llvm::Triple::getArchTypeName(getArch())});
837 return Paths;
838}
839
840bool ToolChain::needsProfileRT(const ArgList &Args) {
841 if (Args.hasArg(options::OPT_noprofilelib))
842 return false;
843
844 return Args.hasArg(options::OPT_fprofile_generate) ||
845 Args.hasArg(options::OPT_fprofile_generate_EQ) ||
846 Args.hasArg(options::OPT_fcs_profile_generate) ||
847 Args.hasArg(options::OPT_fcs_profile_generate_EQ) ||
848 Args.hasArg(options::OPT_fprofile_instr_generate) ||
849 Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
850 Args.hasArg(options::OPT_fcreate_profile) ||
851 Args.hasArg(options::OPT_forder_file_instrumentation);
852}
853
854bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) {
855 return Args.hasArg(options::OPT_coverage) ||
856 Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
857 false);
858}
859
861 if (D.IsFlangMode() && getDriver().ShouldUseFlangCompiler(JA)) return getFlang();
862 if (getDriver().ShouldUseClangCompiler(JA)) return getClang();
865 !getTriple().isOSAIX())
866 return getClangAs();
867 return getTool(AC);
868}
869
870std::string ToolChain::GetFilePath(const char *Name) const {
871 return D.GetFilePath(Name, *this);
872}
873
874std::string ToolChain::GetProgramPath(const char *Name) const {
875 return D.GetProgramPath(Name, *this);
876}
877
878std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const {
879 if (LinkerIsLLD)
880 *LinkerIsLLD = false;
881
882 // Get -fuse-ld= first to prevent -Wunused-command-line-argument. -fuse-ld= is
883 // considered as the linker flavor, e.g. "bfd", "gold", or "lld".
884 const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
885 StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
886
887 // --ld-path= takes precedence over -fuse-ld= and specifies the executable
888 // name. -B, COMPILER_PATH and PATH and consulted if the value does not
889 // contain a path component separator.
890 // -fuse-ld=lld can be used with --ld-path= to inform clang that the binary
891 // that --ld-path= points to is lld.
892 if (const Arg *A = Args.getLastArg(options::OPT_ld_path_EQ)) {
893 std::string Path(A->getValue());
894 if (!Path.empty()) {
895 if (llvm::sys::path::parent_path(Path).empty())
896 Path = GetProgramPath(A->getValue());
897 if (llvm::sys::fs::can_execute(Path)) {
898 if (LinkerIsLLD)
899 *LinkerIsLLD = UseLinker == "lld";
900 return std::string(Path);
901 }
902 }
903 getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
905 }
906 // If we're passed -fuse-ld= with no argument, or with the argument ld,
907 // then use whatever the default system linker is.
908 if (UseLinker.empty() || UseLinker == "ld") {
909 const char *DefaultLinker = getDefaultLinker();
910 if (llvm::sys::path::is_absolute(DefaultLinker))
911 return std::string(DefaultLinker);
912 else
913 return GetProgramPath(DefaultLinker);
914 }
915
916 // Extending -fuse-ld= to an absolute or relative path is unexpected. Checking
917 // for the linker flavor is brittle. In addition, prepending "ld." or "ld64."
918 // to a relative path is surprising. This is more complex due to priorities
919 // among -B, COMPILER_PATH and PATH. --ld-path= should be used instead.
920 if (UseLinker.contains('/'))
921 getDriver().Diag(diag::warn_drv_fuse_ld_path);
922
923 if (llvm::sys::path::is_absolute(UseLinker)) {
924 // If we're passed what looks like an absolute path, don't attempt to
925 // second-guess that.
926 if (llvm::sys::fs::can_execute(UseLinker))
927 return std::string(UseLinker);
928 } else {
929 llvm::SmallString<8> LinkerName;
930 if (Triple.isOSDarwin())
931 LinkerName.append("ld64.");
932 else
933 LinkerName.append("ld.");
934 LinkerName.append(UseLinker);
935
936 std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
937 if (llvm::sys::fs::can_execute(LinkerPath)) {
938 if (LinkerIsLLD)
939 *LinkerIsLLD = UseLinker == "lld";
940 return LinkerPath;
941 }
942 }
943
944 if (A)
945 getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
946
948}
949
951 // TODO: Add support for static lib archiving on Windows
952 if (Triple.isOSDarwin())
953 return GetProgramPath("libtool");
954 return GetProgramPath("llvm-ar");
955}
956
959
960 // Flang always runs the preprocessor and has no notion of "preprocessed
961 // fortran". Here, TY_PP_Fortran is coerced to TY_Fortran to avoid treating
962 // them differently.
963 if (D.IsFlangMode() && id == types::TY_PP_Fortran)
964 id = types::TY_Fortran;
965
966 return id;
967}
968
970 return false;
971}
972
974 llvm::Triple HostTriple(LLVM_HOST_TRIPLE);
975 switch (HostTriple.getArch()) {
976 // The A32/T32/T16 instruction sets are not separate architectures in this
977 // context.
978 case llvm::Triple::arm:
979 case llvm::Triple::armeb:
980 case llvm::Triple::thumb:
981 case llvm::Triple::thumbeb:
982 return getArch() != llvm::Triple::arm && getArch() != llvm::Triple::thumb &&
983 getArch() != llvm::Triple::armeb && getArch() != llvm::Triple::thumbeb;
984 default:
985 return HostTriple.getArch() != getArch();
986 }
987}
988
990 return ObjCRuntime(isNonFragile ? ObjCRuntime::GNUstep : ObjCRuntime::GCC,
991 VersionTuple());
992}
993
994llvm::ExceptionHandling
995ToolChain::GetExceptionModel(const llvm::opt::ArgList &Args) const {
996 return llvm::ExceptionHandling::None;
997}
998
999bool ToolChain::isThreadModelSupported(const StringRef Model) const {
1000 if (Model == "single") {
1001 // FIXME: 'single' is only supported on ARM and WebAssembly so far.
1002 return Triple.getArch() == llvm::Triple::arm ||
1003 Triple.getArch() == llvm::Triple::armeb ||
1004 Triple.getArch() == llvm::Triple::thumb ||
1005 Triple.getArch() == llvm::Triple::thumbeb || Triple.isWasm();
1006 } else if (Model == "posix")
1007 return true;
1008
1009 return false;
1010}
1011
1012std::string ToolChain::ComputeLLVMTriple(const ArgList &Args,
1013 types::ID InputType) const {
1014 switch (getTriple().getArch()) {
1015 default:
1016 return getTripleString();
1017
1018 case llvm::Triple::x86_64: {
1019 llvm::Triple Triple = getTriple();
1020 if (!Triple.isOSBinFormatMachO())
1021 return getTripleString();
1022
1023 if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
1024 // x86_64h goes in the triple. Other -march options just use the
1025 // vanilla triple we already have.
1026 StringRef MArch = A->getValue();
1027 if (MArch == "x86_64h")
1028 Triple.setArchName(MArch);
1029 }
1030 return Triple.getTriple();
1031 }
1032 case llvm::Triple::aarch64: {
1033 llvm::Triple Triple = getTriple();
1034 if (!Triple.isOSBinFormatMachO())
1035 return getTripleString();
1036
1037 if (Triple.isArm64e())
1038 return getTripleString();
1039
1040 // FIXME: older versions of ld64 expect the "arm64" component in the actual
1041 // triple string and query it to determine whether an LTO file can be
1042 // handled. Remove this when we don't care any more.
1043 Triple.setArchName("arm64");
1044 return Triple.getTriple();
1045 }
1046 case llvm::Triple::aarch64_32:
1047 return getTripleString();
1048 case llvm::Triple::arm:
1049 case llvm::Triple::armeb:
1050 case llvm::Triple::thumb:
1051 case llvm::Triple::thumbeb: {
1052 llvm::Triple Triple = getTriple();
1053 tools::arm::setArchNameInTriple(getDriver(), Args, InputType, Triple);
1055 return Triple.getTriple();
1056 }
1057 }
1058}
1059
1060std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
1061 types::ID InputType) const {
1062 return ComputeLLVMTriple(Args, InputType);
1063}
1064
1065std::string ToolChain::computeSysRoot() const {
1066 return D.SysRoot;
1067}
1068
1069void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
1070 ArgStringList &CC1Args) const {
1071 // Each toolchain should provide the appropriate include flags.
1072}
1073
1075 const ArgList &DriverArgs, ArgStringList &CC1Args,
1076 Action::OffloadKind DeviceOffloadKind) const {}
1077
1079 ArgStringList &CC1ASArgs) const {}
1080
1081void ToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {}
1082
1083void ToolChain::addProfileRTLibs(const llvm::opt::ArgList &Args,
1084 llvm::opt::ArgStringList &CmdArgs) const {
1085 if (!needsProfileRT(Args) && !needsGCovInstrumentation(Args))
1086 return;
1087
1088 CmdArgs.push_back(getCompilerRTArgString(Args, "profile"));
1089}
1090
1092 const ArgList &Args) const {
1093 if (runtimeLibType)
1094 return *runtimeLibType;
1095
1096 const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
1097 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
1098
1099 // Only use "platform" in tests to override CLANG_DEFAULT_RTLIB!
1100 if (LibName == "compiler-rt")
1101 runtimeLibType = ToolChain::RLT_CompilerRT;
1102 else if (LibName == "libgcc")
1103 runtimeLibType = ToolChain::RLT_Libgcc;
1104 else if (LibName == "platform")
1105 runtimeLibType = GetDefaultRuntimeLibType();
1106 else {
1107 if (A)
1108 getDriver().Diag(diag::err_drv_invalid_rtlib_name)
1109 << A->getAsString(Args);
1110
1111 runtimeLibType = GetDefaultRuntimeLibType();
1112 }
1113
1114 return *runtimeLibType;
1115}
1116
1118 const ArgList &Args) const {
1119 if (unwindLibType)
1120 return *unwindLibType;
1121
1122 const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
1123 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;
1124
1125 if (LibName == "none")
1126 unwindLibType = ToolChain::UNW_None;
1127 else if (LibName == "platform" || LibName == "") {
1129 if (RtLibType == ToolChain::RLT_CompilerRT) {
1130 if (getTriple().isAndroid() || getTriple().isOSAIX())
1131 unwindLibType = ToolChain::UNW_CompilerRT;
1132 else
1133 unwindLibType = ToolChain::UNW_None;
1134 } else if (RtLibType == ToolChain::RLT_Libgcc)
1135 unwindLibType = ToolChain::UNW_Libgcc;
1136 } else if (LibName == "libunwind") {
1137 if (GetRuntimeLibType(Args) == RLT_Libgcc)
1138 getDriver().Diag(diag::err_drv_incompatible_unwindlib);
1139 unwindLibType = ToolChain::UNW_CompilerRT;
1140 } else if (LibName == "libgcc")
1141 unwindLibType = ToolChain::UNW_Libgcc;
1142 else {
1143 if (A)
1144 getDriver().Diag(diag::err_drv_invalid_unwindlib_name)
1145 << A->getAsString(Args);
1146
1147 unwindLibType = GetDefaultUnwindLibType();
1148 }
1149
1150 return *unwindLibType;
1151}
1152
1154 if (cxxStdlibType)
1155 return *cxxStdlibType;
1156
1157 const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
1158 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB;
1159
1160 // Only use "platform" in tests to override CLANG_DEFAULT_CXX_STDLIB!
1161 if (LibName == "libc++")
1162 cxxStdlibType = ToolChain::CST_Libcxx;
1163 else if (LibName == "libstdc++")
1164 cxxStdlibType = ToolChain::CST_Libstdcxx;
1165 else if (LibName == "platform")
1166 cxxStdlibType = GetDefaultCXXStdlibType();
1167 else {
1168 if (A)
1169 getDriver().Diag(diag::err_drv_invalid_stdlib_name)
1170 << A->getAsString(Args);
1171
1172 cxxStdlibType = GetDefaultCXXStdlibType();
1173 }
1174
1175 return *cxxStdlibType;
1176}
1177
1178/// Utility function to add a system include directory to CC1 arguments.
1179/*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs,
1180 ArgStringList &CC1Args,
1181 const Twine &Path) {
1182 CC1Args.push_back("-internal-isystem");
1183 CC1Args.push_back(DriverArgs.MakeArgString(Path));
1184}
1185
1186/// Utility function to add a system include directory with extern "C"
1187/// semantics to CC1 arguments.
1188///
1189/// Note that this should be used rarely, and only for directories that
1190/// historically and for legacy reasons are treated as having implicit extern
1191/// "C" semantics. These semantics are *ignored* by and large today, but its
1192/// important to preserve the preprocessor changes resulting from the
1193/// classification.
1194/*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
1195 ArgStringList &CC1Args,
1196 const Twine &Path) {
1197 CC1Args.push_back("-internal-externc-isystem");
1198 CC1Args.push_back(DriverArgs.MakeArgString(Path));
1199}
1200
1201void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
1202 ArgStringList &CC1Args,
1203 const Twine &Path) {
1204 if (llvm::sys::fs::exists(Path))
1205 addExternCSystemInclude(DriverArgs, CC1Args, Path);
1206}
1207
1208/// Utility function to add a list of system include directories to CC1.
1209/*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs,
1210 ArgStringList &CC1Args,
1211 ArrayRef<StringRef> Paths) {
1212 for (const auto &Path : Paths) {
1213 CC1Args.push_back("-internal-isystem");
1214 CC1Args.push_back(DriverArgs.MakeArgString(Path));
1215 }
1216}
1217
1218/*static*/ std::string ToolChain::concat(StringRef Path, const Twine &A,
1219 const Twine &B, const Twine &C,
1220 const Twine &D) {
1222 llvm::sys::path::append(Result, llvm::sys::path::Style::posix, A, B, C, D);
1223 return std::string(Result);
1224}
1225
1226std::string ToolChain::detectLibcxxVersion(StringRef IncludePath) const {
1227 std::error_code EC;
1228 int MaxVersion = 0;
1229 std::string MaxVersionString;
1230 SmallString<128> Path(IncludePath);
1231 llvm::sys::path::append(Path, "c++");
1232 for (llvm::vfs::directory_iterator LI = getVFS().dir_begin(Path, EC), LE;
1233 !EC && LI != LE; LI = LI.increment(EC)) {
1234 StringRef VersionText = llvm::sys::path::filename(LI->path());
1235 int Version;
1236 if (VersionText[0] == 'v' &&
1237 !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
1238 if (Version > MaxVersion) {
1239 MaxVersion = Version;
1240 MaxVersionString = std::string(VersionText);
1241 }
1242 }
1243 }
1244 if (!MaxVersion)
1245 return "";
1246 return MaxVersionString;
1247}
1248
1249void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
1250 ArgStringList &CC1Args) const {
1251 // Header search paths should be handled by each of the subclasses.
1252 // Historically, they have not been, and instead have been handled inside of
1253 // the CC1-layer frontend. As the logic is hoisted out, this generic function
1254 // will slowly stop being called.
1255 //
1256 // While it is being called, replicate a bit of a hack to propagate the
1257 // '-stdlib=' flag down to CC1 so that it can in turn customize the C++
1258 // header search paths with it. Once all systems are overriding this
1259 // function, the CC1 flag and this line can be removed.
1260 DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
1261}
1262
1264 const llvm::opt::ArgList &DriverArgs,
1265 llvm::opt::ArgStringList &CC1Args) const {
1266 DriverArgs.ClaimAllArgs(options::OPT_stdlibxx_isystem);
1267 // This intentionally only looks at -nostdinc++, and not -nostdinc or
1268 // -nostdlibinc. The purpose of -stdlib++-isystem is to support toolchain
1269 // setups with non-standard search logic for the C++ headers, while still
1270 // allowing users of the toolchain to bring their own C++ headers. Such a
1271 // toolchain likely also has non-standard search logic for the C headers and
1272 // uses -nostdinc to suppress the default logic, but -stdlib++-isystem should
1273 // still work in that case and only be suppressed by an explicit -nostdinc++
1274 // in a project using the toolchain.
1275 if (!DriverArgs.hasArg(options::OPT_nostdincxx))
1276 for (const auto &P :
1277 DriverArgs.getAllArgValues(options::OPT_stdlibxx_isystem))
1278 addSystemInclude(DriverArgs, CC1Args, P);
1279}
1280
1281bool ToolChain::ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const {
1282 return getDriver().CCCIsCXX() &&
1283 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
1284 options::OPT_nostdlibxx);
1285}
1286
1287void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
1288 ArgStringList &CmdArgs) const {
1289 assert(!Args.hasArg(options::OPT_nostdlibxx) &&
1290 "should not have called this");
1292
1293 switch (Type) {
1295 CmdArgs.push_back("-lc++");
1296 if (Args.hasArg(options::OPT_fexperimental_library))
1297 CmdArgs.push_back("-lc++experimental");
1298 break;
1299
1301 CmdArgs.push_back("-lstdc++");
1302 break;
1303 }
1304}
1305
1306void ToolChain::AddFilePathLibArgs(const ArgList &Args,
1307 ArgStringList &CmdArgs) const {
1308 for (const auto &LibPath : getFilePaths())
1309 if(LibPath.length() > 0)
1310 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
1311}
1312
1313void ToolChain::AddCCKextLibArgs(const ArgList &Args,
1314 ArgStringList &CmdArgs) const {
1315 CmdArgs.push_back("-lcc_kext");
1316}
1317
1319 std::string &Path) const {
1320 // Don't implicitly link in mode-changing libraries in a shared library, since
1321 // this can have very deleterious effects. See the various links from
1322 // https://github.com/llvm/llvm-project/issues/57589 for more information.
1323 bool Default = !Args.hasArgNoClaim(options::OPT_shared);
1324
1325 // Do not check for -fno-fast-math or -fno-unsafe-math when -Ofast passed
1326 // (to keep the linker options consistent with gcc and clang itself).
1327 if (Default && !isOptimizationLevelFast(Args)) {
1328 // Check if -ffast-math or -funsafe-math.
1329 Arg *A = Args.getLastArg(
1330 options::OPT_ffast_math, options::OPT_fno_fast_math,
1331 options::OPT_funsafe_math_optimizations,
1332 options::OPT_fno_unsafe_math_optimizations, options::OPT_ffp_model_EQ);
1333
1334 if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
1335 A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
1336 Default = false;
1337 if (A && A->getOption().getID() == options::OPT_ffp_model_EQ) {
1338 StringRef Model = A->getValue();
1339 if (Model != "fast")
1340 Default = false;
1341 }
1342 }
1343
1344 // Whatever decision came as a result of the above implicit settings, either
1345 // -mdaz-ftz or -mno-daz-ftz is capable of overriding it.
1346 if (!Args.hasFlag(options::OPT_mdaz_ftz, options::OPT_mno_daz_ftz, Default))
1347 return false;
1348
1349 // If crtfastmath.o exists add it to the arguments.
1350 Path = GetFilePath("crtfastmath.o");
1351 return (Path != "crtfastmath.o"); // Not found.
1352}
1353
1355 ArgStringList &CmdArgs) const {
1356 std::string Path;
1357 if (isFastMathRuntimeAvailable(Args, Path)) {
1358 CmdArgs.push_back(Args.MakeArgString(Path));
1359 return true;
1360 }
1361
1362 return false;
1363}
1364
1366ToolChain::getSystemGPUArchs(const llvm::opt::ArgList &Args) const {
1367 return SmallVector<std::string>();
1368}
1369
1371 // Return sanitizers which don't require runtime support and are not
1372 // platform dependent.
1373
1374 SanitizerMask Res =
1375 (SanitizerKind::Undefined & ~SanitizerKind::Vptr) |
1376 (SanitizerKind::CFI & ~SanitizerKind::CFIICall) |
1377 SanitizerKind::CFICastStrict | SanitizerKind::FloatDivideByZero |
1378 SanitizerKind::KCFI | SanitizerKind::UnsignedIntegerOverflow |
1379 SanitizerKind::UnsignedShiftBase | SanitizerKind::ImplicitConversion |
1380 SanitizerKind::Nullability | SanitizerKind::LocalBounds;
1381 if (getTriple().getArch() == llvm::Triple::x86 ||
1382 getTriple().getArch() == llvm::Triple::x86_64 ||
1383 getTriple().getArch() == llvm::Triple::arm || getTriple().isWasm() ||
1384 getTriple().isAArch64() || getTriple().isRISCV() ||
1385 getTriple().isLoongArch64())
1386 Res |= SanitizerKind::CFIICall;
1387 if (getTriple().getArch() == llvm::Triple::x86_64 ||
1388 getTriple().isAArch64(64) || getTriple().isRISCV())
1389 Res |= SanitizerKind::ShadowCallStack;
1390 if (getTriple().isAArch64(64))
1391 Res |= SanitizerKind::MemTag;
1392 return Res;
1393}
1394
1395void ToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
1396 ArgStringList &CC1Args) const {}
1397
1398void ToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
1399 ArgStringList &CC1Args) const {}
1400
1402ToolChain::getDeviceLibs(const ArgList &DriverArgs) const {
1403 return {};
1404}
1405
1406void ToolChain::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
1407 ArgStringList &CC1Args) const {}
1408
1409static VersionTuple separateMSVCFullVersion(unsigned Version) {
1410 if (Version < 100)
1411 return VersionTuple(Version);
1412
1413 if (Version < 10000)
1414 return VersionTuple(Version / 100, Version % 100);
1415
1416 unsigned Build = 0, Factor = 1;
1417 for (; Version > 10000; Version = Version / 10, Factor = Factor * 10)
1418 Build = Build + (Version % 10) * Factor;
1419 return VersionTuple(Version / 100, Version % 100, Build);
1420}
1421
1422VersionTuple
1424 const llvm::opt::ArgList &Args) const {
1425 const Arg *MSCVersion = Args.getLastArg(options::OPT_fmsc_version);
1426 const Arg *MSCompatibilityVersion =
1427 Args.getLastArg(options::OPT_fms_compatibility_version);
1428
1429 if (MSCVersion && MSCompatibilityVersion) {
1430 if (D)
1431 D->Diag(diag::err_drv_argument_not_allowed_with)
1432 << MSCVersion->getAsString(Args)
1433 << MSCompatibilityVersion->getAsString(Args);
1434 return VersionTuple();
1435 }
1436
1437 if (MSCompatibilityVersion) {
1438 VersionTuple MSVT;
1439 if (MSVT.tryParse(MSCompatibilityVersion->getValue())) {
1440 if (D)
1441 D->Diag(diag::err_drv_invalid_value)
1442 << MSCompatibilityVersion->getAsString(Args)
1443 << MSCompatibilityVersion->getValue();
1444 } else {
1445 return MSVT;
1446 }
1447 }
1448
1449 if (MSCVersion) {
1450 unsigned Version = 0;
1451 if (StringRef(MSCVersion->getValue()).getAsInteger(10, Version)) {
1452 if (D)
1453 D->Diag(diag::err_drv_invalid_value)
1454 << MSCVersion->getAsString(Args) << MSCVersion->getValue();
1455 } else {
1456 return separateMSVCFullVersion(Version);
1457 }
1458 }
1459
1460 return VersionTuple();
1461}
1462
1463llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs(
1464 const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,
1465 SmallVectorImpl<llvm::opt::Arg *> &AllocatedArgs) const {
1466 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
1467 const OptTable &Opts = getDriver().getOpts();
1468 bool Modified = false;
1469
1470 // Handle -Xopenmp-target flags
1471 for (auto *A : Args) {
1472 // Exclude flags which may only apply to the host toolchain.
1473 // Do not exclude flags when the host triple (AuxTriple)
1474 // matches the current toolchain triple. If it is not present
1475 // at all, target and host share a toolchain.
1476 if (A->getOption().matches(options::OPT_m_Group)) {
1477 // Pass code object version to device toolchain
1478 // to correctly set metadata in intermediate files.
1479 if (SameTripleAsHost ||
1480 A->getOption().matches(options::OPT_mcode_object_version_EQ))
1481 DAL->append(A);
1482 else
1483 Modified = true;
1484 continue;
1485 }
1486
1487 unsigned Index;
1488 unsigned Prev;
1489 bool XOpenMPTargetNoTriple =
1490 A->getOption().matches(options::OPT_Xopenmp_target);
1491
1492 if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
1493 llvm::Triple TT(getOpenMPTriple(A->getValue(0)));
1494
1495 // Passing device args: -Xopenmp-target=<triple> -opt=val.
1496 if (TT.getTriple() == getTripleString())
1497 Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
1498 else
1499 continue;
1500 } else if (XOpenMPTargetNoTriple) {
1501 // Passing device args: -Xopenmp-target -opt=val.
1502 Index = Args.getBaseArgs().MakeIndex(A->getValue(0));
1503 } else {
1504 DAL->append(A);
1505 continue;
1506 }
1507
1508 // Parse the argument to -Xopenmp-target.
1509 Prev = Index;
1510 std::unique_ptr<Arg> XOpenMPTargetArg(Opts.ParseOneArg(Args, Index));
1511 if (!XOpenMPTargetArg || Index > Prev + 1) {
1512 getDriver().Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
1513 << A->getAsString(Args);
1514 continue;
1515 }
1516 if (XOpenMPTargetNoTriple && XOpenMPTargetArg &&
1517 Args.getAllArgValues(options::OPT_fopenmp_targets_EQ).size() != 1) {
1518 getDriver().Diag(diag::err_drv_Xopenmp_target_missing_triple);
1519 continue;
1520 }
1521 XOpenMPTargetArg->setBaseArg(A);
1522 A = XOpenMPTargetArg.release();
1523 AllocatedArgs.push_back(A);
1524 DAL->append(A);
1525 Modified = true;
1526 }
1527
1528 if (Modified)
1529 return DAL;
1530
1531 delete DAL;
1532 return nullptr;
1533}
1534
1535// TODO: Currently argument values separated by space e.g.
1536// -Xclang -mframe-pointer=no cannot be passed by -Xarch_. This should be
1537// fixed.
1539 const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A,
1540 llvm::opt::DerivedArgList *DAL,
1541 SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs) const {
1542 const OptTable &Opts = getDriver().getOpts();
1543 unsigned ValuePos = 1;
1544 if (A->getOption().matches(options::OPT_Xarch_device) ||
1545 A->getOption().matches(options::OPT_Xarch_host))
1546 ValuePos = 0;
1547
1548 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(ValuePos));
1549 unsigned Prev = Index;
1550 std::unique_ptr<llvm::opt::Arg> XarchArg(Opts.ParseOneArg(Args, Index));
1551
1552 // If the argument parsing failed or more than one argument was
1553 // consumed, the -Xarch_ argument's parameter tried to consume
1554 // extra arguments. Emit an error and ignore.
1555 //
1556 // We also want to disallow any options which would alter the
1557 // driver behavior; that isn't going to work in our model. We
1558 // use options::NoXarchOption to control this.
1559 if (!XarchArg || Index > Prev + 1) {
1560 getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args)
1561 << A->getAsString(Args);
1562 return;
1563 } else if (XarchArg->getOption().hasFlag(options::NoXarchOption)) {
1564 auto &Diags = getDriver().getDiags();
1565 unsigned DiagID =
1567 "invalid Xarch argument: '%0', not all driver "
1568 "options can be forwared via Xarch argument");
1569 Diags.Report(DiagID) << A->getAsString(Args);
1570 return;
1571 }
1572 XarchArg->setBaseArg(A);
1573 A = XarchArg.release();
1574 if (!AllocatedArgs)
1575 DAL->AddSynthesizedArg(A);
1576 else
1577 AllocatedArgs->push_back(A);
1578}
1579
1580llvm::opt::DerivedArgList *ToolChain::TranslateXarchArgs(
1581 const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
1583 SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs) const {
1584 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
1585 bool Modified = false;
1586
1587 bool IsDevice = OFK != Action::OFK_None && OFK != Action::OFK_Host;
1588 for (Arg *A : Args) {
1589 bool NeedTrans = false;
1590 bool Skip = false;
1591 if (A->getOption().matches(options::OPT_Xarch_device)) {
1592 NeedTrans = IsDevice;
1593 Skip = !IsDevice;
1594 } else if (A->getOption().matches(options::OPT_Xarch_host)) {
1595 NeedTrans = !IsDevice;
1596 Skip = IsDevice;
1597 } else if (A->getOption().matches(options::OPT_Xarch__) && IsDevice) {
1598 // Do not translate -Xarch_ options for non CUDA/HIP toolchain since
1599 // they may need special translation.
1600 // Skip this argument unless the architecture matches BoundArch
1601 if (BoundArch.empty() || A->getValue(0) != BoundArch)
1602 Skip = true;
1603 else
1604 NeedTrans = true;
1605 }
1606 if (NeedTrans || Skip)
1607 Modified = true;
1608 if (NeedTrans)
1609 TranslateXarchArgs(Args, A, DAL, AllocatedArgs);
1610 if (!Skip)
1611 DAL->append(A);
1612 }
1613
1614 if (Modified)
1615 return DAL;
1616
1617 delete DAL;
1618 return nullptr;
1619}
StringRef P
const Decl * D
IndirectLocalPath & Path
const Environment & Env
Definition: HTMLLogger.cpp:148
Defines types useful for describing an Objective-C runtime.
Defines the clang::SanitizerKind enum.
static const DriverSuffix * parseDriverSuffix(StringRef ProgName, size_t &Pos)
Definition: ToolChain.cpp:368
static void getAArch64MultilibFlags(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, Multilib::flags_list &Result)
Definition: ToolChain.cpp:187
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:358
static StringRef getArchNameForCompilerRTLib(const ToolChain &TC, const ArgList &Args)
Definition: ToolChain.cpp:578
static VersionTuple separateMSVCFullVersion(unsigned Version)
Definition: ToolChain.cpp:1409
static const DriverSuffix * FindDriverSuffix(StringRef ProgName, size_t &Pos)
Definition: ToolChain.cpp:325
static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args)
Definition: ToolChain.cpp:80
static llvm::opt::Arg * GetRTTIArgument(const ArgList &Args)
Definition: ToolChain.cpp:59
static void getARMMultilibFlags(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, Multilib::flags_list &Result)
Definition: ToolChain.cpp:214
static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, const llvm::Triple &Triple, const Arg *CachedRTTIArg)
Definition: ToolChain.cpp:64
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:873
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
@ GNUstep
'gnustep' is the modern non-fragile GNUstep runtime.
Definition: ObjCRuntime.h:56
@ GCC
'gcc' is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI
Definition: ObjCRuntime.h:53
The base class of the type hierarchy.
Definition: Type.h:1829
ActionClass getKind() const
Definition: Action.h:147
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
std::string SysRoot
sysroot, if present
Definition: Driver.h:180
std::string GetFilePath(StringRef Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
Definition: Driver.cpp:6140
DiagnosticsEngine & getDiags() const
Definition: Driver.h:401
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:144
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:399
std::string GetProgramPath(StringRef Name, const ToolChain &TC) const
GetProgramPath - Lookup Name in the list of program search paths.
Definition: Driver.cpp:6200
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:164
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:403
std::string Dir
The path the driver executable was in, as invoked from the command line.
Definition: Driver.h:155
bool IsFlangMode() const
Whether the driver should invoke flang for fortran inputs.
Definition: Driver.h:226
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:213
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
const char * getFilename() const
Definition: InputInfo.h:83
std::vector< std::string > flags_list
Definition: Multilib.h:34
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
virtual bool isFastMathRuntimeAvailable(const llvm::opt::ArgList &Args, std::string &Path) const
If a runtime library exists that sets global flags for unsafe floating point math,...
Definition: ToolChain.cpp:1318
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:1060
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:1313
virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const
Add warning options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:1081
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:1179
virtual std::string computeSysRoot() const
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
Definition: ToolChain.cpp:1065
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > executeToolChainProgram(StringRef Executable, unsigned SecondsToWait=0) const
Executes the given Executable and returns the stdout.
Definition: ToolChain.cpp:107
virtual bool useIntegratedAs() const
Check if the toolchain should use the integrated assembler.
Definition: ToolChain.cpp:145
static llvm::Triple getOpenMPTriple(StringRef TripleStr)
Definition: ToolChain.h:806
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:1463
std::optional< std::string > getStdlibPath() const
Definition: ToolChain.cpp:812
virtual RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:1091
virtual UnwindTableLevel getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const
How detailed should the unwind tables be by default.
Definition: ToolChain.cpp:456
const char * getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:708
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
Definition: ToolChain.cpp:1281
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:1194
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:451
virtual Tool * buildStaticLibTool() const
Definition: ToolChain.cpp:480
virtual bool IsIntegratedBackendSupported() const
IsIntegratedBackendSupported - Does this tool chain support -fintegrated-objemitter.
Definition: ToolChain.h:443
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:870
path_list & getFilePaths()
Definition: ToolChain.h:295
virtual Tool * SelectTool(const JobAction &JA) const
Choose a tool to use to handle the action JA.
Definition: ToolChain.cpp:860
static bool needsProfileRT(const llvm::opt::ArgList &Args)
needsProfileRT - returns true if instrumentation profile is on.
Definition: ToolChain.cpp:840
StringRef getOS() const
Definition: ToolChain.h:272
virtual bool isBareMetal() const
isBareMetal - Is this a bare metal target.
Definition: ToolChain.h:629
virtual bool isThreadModelSupported(const StringRef Model) const
isThreadModelSupported() - Does this target support a thread model?
Definition: ToolChain.cpp:999
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:269
const Driver & getDriver() const
Definition: ToolChain.h:253
virtual std::string detectLibcxxVersion(StringRef IncludePath) const
Definition: ToolChain.cpp:1226
static std::string concat(StringRef Path, const Twine &A, const Twine &B="", const Twine &C="", const Twine &D="")
Definition: ToolChain.cpp:1218
RTTIMode getRTTIMode() const
Definition: ToolChain.h:327
ExceptionsMode getExceptionsMode() const
Definition: ToolChain.h:330
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:141
Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const
Get flags suitable for multilib selection, based on the provided clang command line arguments.
Definition: ToolChain.cpp:262
static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args)
Returns true if gcov instrumentation (-fprofile-arcs or –coverage) is on.
Definition: ToolChain.cpp:854
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:1012
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition: ToolChain.cpp:88
const XRayArgs & getXRayArgs() const
Definition: ToolChain.cpp:310
void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set the specified include paths ...
Definition: ToolChain.cpp:1263
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:1354
static void addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Definition: ToolChain.cpp:1201
virtual bool useIntegratedBackend() const
Check if the toolchain should use the integrated backend.
Definition: ToolChain.cpp:151
std::string GetStaticLibToolPath() const
Returns the linker path for emitting a static library.
Definition: ToolChain.cpp:950
virtual llvm::ExceptionHandling GetExceptionModel(const llvm::opt::ArgList &Args) const
GetExceptionModel - Return the tool chain exception model.
Definition: ToolChain.cpp:995
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:1287
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:402
virtual bool IsIntegratedBackendDefault() const
IsIntegratedBackendDefault - Does this tool chain enable -fintegrated-objemitter by default.
Definition: ToolChain.h:439
virtual const char * getDefaultLinker() const
GetDefaultLinker - Get the default linker to use.
Definition: ToolChain.h:494
virtual Tool * buildLinker() const
Definition: ToolChain.cpp:476
const llvm::Triple & getTriple() const
Definition: ToolChain.h:255
bool defaultToIEEELongDouble() const
Check whether use IEEE binary128 as long double format by default.
Definition: ToolChain.cpp:183
virtual types::ID LookupTypeForExtension(StringRef Ext) const
LookupTypeForExtension - Return the default language type to use for the given extension.
Definition: ToolChain.cpp:957
virtual bool HasNativeLLVMSupport() const
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition: ToolChain.cpp:969
virtual llvm::SmallVector< BitCodeLibraryInfo, 12 > getDeviceLibs(const llvm::opt::ArgList &Args) const
Get paths for device libraries.
Definition: ToolChain.cpp:1402
virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:1117
std::optional< std::string > getTargetSubDirPath(StringRef BaseDir) const
Find the target-specific subdirectory for the current target triple under BaseDir,...
Definition: ToolChain.cpp:759
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:1083
virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use system-specific CUDA includes.
Definition: ToolChain.cpp:1395
virtual std::string getCompilerRTPath() const
Definition: ToolChain.cpp:621
virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, FileType Type, bool AddArch) const
Definition: ToolChain.cpp:643
std::string GetLinkerPath(bool *LinkerIsLLD=nullptr) const
Returns the linker path, respecting the -fuse-ld= argument to determine the linker suffix or name.
Definition: ToolChain.cpp:878
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:677
virtual Expected< SmallVector< std::string > > getSystemGPUArchs(const llvm::opt::ArgList &Args) const
getSystemGPUArchs - Use a tool to detect the user's availible GPUs.
Definition: ToolChain.cpp:1366
std::string GetProgramPath(const char *Name) const
Definition: ToolChain.cpp:874
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:1209
virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use system-specific HIP includes.
Definition: ToolChain.cpp:1398
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:1249
virtual VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const
On Windows, returns the MSVC compatibility version.
Definition: ToolChain.cpp:1423
virtual StringRef getOSLibName() const
Definition: ToolChain.cpp:601
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use MCU GCC toolchain includes.
Definition: ToolChain.cpp:1406
virtual CXXStdlibType GetDefaultCXXStdlibType() const
Definition: ToolChain.h:501
std::optional< std::string > getStdlibIncludePath() const
Definition: ToolChain.cpp:818
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:1306
std::string getTripleString() const
Definition: ToolChain.h:278
virtual RuntimeLibType GetDefaultRuntimeLibType() const
GetDefaultRuntimeLibType - Get the default runtime library variant to use.
Definition: ToolChain.h:497
StringRef getDefaultUniversalArchName() const
Provide the default architecture name (as expected by -arch) for this toolchain.
Definition: ToolChain.cpp:426
virtual Tool * buildAssembler() const
Definition: ToolChain.cpp:472
void setTripleEnvironment(llvm::Triple::EnvironmentType Env)
Definition: ToolChain.cpp:133
virtual void addClangCC1ASTargetOptions(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1ASArgs) const
Add options that need to be passed to cc1as for this target.
Definition: ToolChain.cpp:1078
virtual bool IsIntegratedAssemblerDefault() const
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: ToolChain.h:435
SanitizerArgs getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const
Definition: ToolChain.cpp:304
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:1153
llvm::SmallVector< Multilib > SelectedMultilibs
Definition: ToolChain.h:201
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:1074
path_list & getLibraryPaths()
Definition: ToolChain.h:292
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:1069
virtual UnwindLibType GetDefaultUnwindLibType() const
Definition: ToolChain.h:505
std::optional< std::string > getRuntimePath() const
Definition: ToolChain.cpp:800
virtual Tool * getTool(Action::ActionClass AC) const
Definition: ToolChain.cpp:532
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1370
virtual path_list getArchSpecificLibPaths() const
Definition: ToolChain.cpp:824
virtual bool isCrossCompiling() const
Returns true if the toolchain is targeting a non-native architecture.
Definition: ToolChain.cpp:973
std::string getCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:636
virtual bool IsNonIntegratedBackendSupported() const
IsNonIntegratedBackendSupported - Does this tool chain support -fno-integrated-objemitter.
Definition: ToolChain.h:447
virtual void TranslateXarchArgs(const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A, llvm::opt::DerivedArgList *DAL, SmallVectorImpl< llvm::opt::Arg * > *AllocatedArgs=nullptr) const
Append the argument following A to DAL assuming A is an Xarch argument.
Definition: ToolChain.cpp:1538
virtual bool useRelaxRelocations() const
Check whether to enable x86 relax relocations by default.
Definition: ToolChain.cpp:179
virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const
getDefaultObjCRuntime - Return the default Objective-C runtime for this platform.
Definition: ToolChain.cpp:989
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
Clang integrated assembler tool.
Definition: Clang.h:122
Clang compiler tool.
Definition: Clang.h:28
Flang compiler tool.
Definition: Flang.h:25
Linker wrapper tool.
Definition: Clang.h:176
Offload bundler tool.
Definition: Clang.h:145
Offload binary tool.
Definition: Clang.h:163
void getAArch64TargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< llvm::StringRef > &Features, bool ForAS)
void setArchNameInTriple(const Driver &D, const llvm::opt::ArgList &Args, types::ID InputType, llvm::Triple &Triple)
void setFloatABIInTriple(const Driver &D, const llvm::opt::ArgList &Args, llvm::Triple &triple)
FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args)
llvm::ARM::FPUKind getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< llvm::StringRef > &Features, bool ForAS, bool ForMultilib=false)
SmallVector< StringRef > unifyTargetFeatures(ArrayRef< StringRef > Features)
If there are multiple +xxx or -xxx features, keep the last one.
Definition: CommonArgs.cpp:378
ID lookupTypeForExtension(llvm::StringRef Ext)
lookupTypeForExtension - Lookup the type to use for the file extension Ext.
Definition: Types.cpp:298
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
Helper structure used to pass information extracted from clang executable name such as i686-linux-and...
Definition: ToolChain.h:65