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