1 //===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
11 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
14 #include "clang/Basic/VersionTuple.h"
15 #include "clang/Driver/Action.h"
16 #include "clang/Driver/Multilib.h"
17 #include "clang/Driver/ToolChain.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/Support/Compiler.h"
26 namespace toolchains {
28 /// Generic_GCC - A tool chain using the 'gcc' command to perform
29 /// all subcommands; this relies on gcc translating the majority of
30 /// command line options.
31 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
33 /// \brief Struct to store and manipulate GCC versions.
35 /// We rely on assumptions about the form and structure of GCC version
36 /// numbers: they consist of at most three '.'-separated components, and each
37 /// component is a non-negative integer except for the last component. For
38 /// the last component we are very flexible in order to tolerate release
39 /// candidates or 'x' wildcards.
41 /// Note that the ordering established among GCCVersions is based on the
42 /// preferred version string to use. For example we prefer versions without
43 /// a hard-coded patch number to those with a hard coded patch number.
45 /// Currently this doesn't provide any logic for textual suffixes to patches
46 /// in the way that (for example) Debian's version format does. If that ever
47 /// becomes necessary, it can be added.
49 /// \brief The unparsed text of the version.
52 /// \brief The parsed major, minor, and patch numbers.
53 int Major, Minor, Patch;
55 /// \brief The text of the parsed major, and major+minor versions.
56 std::string MajorStr, MinorStr;
58 /// \brief Any textual suffix on the patch number.
59 std::string PatchSuffix;
61 static GCCVersion Parse(StringRef VersionText);
62 bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch,
63 StringRef RHSPatchSuffix = StringRef()) const;
64 bool operator<(const GCCVersion &RHS) const {
65 return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix);
67 bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
68 bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
69 bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
72 /// \brief This is a class to find a viable GCC installation for Clang to
75 /// This class tries to find a GCC installation on the system, and report
76 /// information about it. It starts from the host information provided to the
77 /// Driver, and has logic for fuzzing that where appropriate.
78 class GCCInstallationDetector {
80 llvm::Triple GCCTriple;
83 // FIXME: These might be better as path objects.
84 std::string GCCInstallPath;
85 std::string GCCParentLibPath;
87 /// The primary multilib appropriate for the given flags.
88 Multilib SelectedMultilib;
89 /// On Biarch systems, this corresponds to the default multilib when
90 /// targeting the non-default multilib. Otherwise, it is empty.
91 llvm::Optional<Multilib> BiarchSibling;
95 // We retain the list of install paths that were considered and rejected in
96 // order to print out detailed information in verbose mode.
97 std::set<std::string> CandidateGCCInstallPaths;
99 /// The set of multilibs that the detected installation supports.
100 MultilibSet Multilibs;
103 explicit GCCInstallationDetector(const Driver &D) : IsValid(false), D(D) {}
104 void init(const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args,
105 ArrayRef<std::string> ExtraTripleAliases = None);
107 /// \brief Check whether we detected a valid GCC install.
108 bool isValid() const { return IsValid; }
110 /// \brief Get the GCC triple for the detected install.
111 const llvm::Triple &getTriple() const { return GCCTriple; }
113 /// \brief Get the detected GCC installation path.
114 StringRef getInstallPath() const { return GCCInstallPath; }
116 /// \brief Get the detected GCC parent lib path.
117 StringRef getParentLibPath() const { return GCCParentLibPath; }
119 /// \brief Get the detected Multilib
120 const Multilib &getMultilib() const { return SelectedMultilib; }
122 /// \brief Get the whole MultilibSet
123 const MultilibSet &getMultilibs() const { return Multilibs; }
125 /// Get the biarch sibling multilib (if it exists).
126 /// \return true iff such a sibling exists
127 bool getBiarchSibling(Multilib &M) const;
129 /// \brief Get the detected GCC version string.
130 const GCCVersion &getVersion() const { return Version; }
132 /// \brief Print information about the detected GCC installation.
133 void print(raw_ostream &OS) const;
137 CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
138 const llvm::Triple &BiarchTriple,
139 SmallVectorImpl<StringRef> &LibDirs,
140 SmallVectorImpl<StringRef> &TripleAliases,
141 SmallVectorImpl<StringRef> &BiarchLibDirs,
142 SmallVectorImpl<StringRef> &BiarchTripleAliases);
144 void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch,
145 const llvm::opt::ArgList &Args,
146 const std::string &LibDir,
147 StringRef CandidateTriple,
148 bool NeedsBiarchSuffix = false);
150 void scanLibDirForGCCTripleSolaris(const llvm::Triple &TargetArch,
151 const llvm::opt::ArgList &Args,
152 const std::string &LibDir,
153 StringRef CandidateTriple,
154 bool NeedsBiarchSuffix = false);
158 GCCInstallationDetector GCCInstallation;
160 // \brief A class to find a viable CUDA installation
162 class CudaInstallationDetector {
165 std::string CudaInstallPath;
166 std::string CudaLibPath;
167 std::string CudaLibDevicePath;
168 std::string CudaIncludePath;
169 llvm::StringMap<std::string> CudaLibDeviceMap;
172 CudaInstallationDetector(const Driver &D) : IsValid(false), D(D) {}
173 void init(const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args);
175 /// \brief Check whether we detected a valid Cuda install.
176 bool isValid() const { return IsValid; }
177 /// \brief Print information about the detected CUDA installation.
178 void print(raw_ostream &OS) const;
180 /// \brief Get the detected Cuda installation path.
181 StringRef getInstallPath() const { return CudaInstallPath; }
182 /// \brief Get the detected Cuda Include path.
183 StringRef getIncludePath() const { return CudaIncludePath; }
184 /// \brief Get the detected Cuda library path.
185 StringRef getLibPath() const { return CudaLibPath; }
186 /// \brief Get the detected Cuda device library path.
187 StringRef getLibDevicePath() const { return CudaLibDevicePath; }
188 /// \brief Get libdevice file for given architecture
189 std::string getLibDeviceFile(StringRef Gpu) const {
190 return CudaLibDeviceMap.lookup(Gpu);
194 CudaInstallationDetector CudaInstallation;
197 Generic_GCC(const Driver &D, const llvm::Triple &Triple,
198 const llvm::opt::ArgList &Args);
199 ~Generic_GCC() override;
201 void printVerboseInfo(raw_ostream &OS) const override;
203 bool IsUnwindTablesDefault() const override;
204 bool isPICDefault() const override;
205 bool isPIEDefault() const override;
206 bool isPICDefaultForced() const override;
207 bool IsIntegratedAssemblerDefault() const override;
210 Tool *getTool(Action::ActionClass AC) const override;
211 Tool *buildAssembler() const override;
212 Tool *buildLinker() const override;
214 /// \name ToolChain Implementation Helper Functions
217 /// \brief Check whether the target triple's architecture is 64-bits.
218 bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
220 /// \brief Check whether the target triple's architecture is 32-bits.
221 bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
223 bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix, StringRef GCCTriple,
224 StringRef GCCMultiarchTriple,
225 StringRef TargetMultiarchTriple,
227 const llvm::opt::ArgList &DriverArgs,
228 llvm::opt::ArgStringList &CC1Args) const;
233 mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocess;
234 mutable std::unique_ptr<tools::gcc::Compiler> Compile;
237 class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
239 Tool *buildAssembler() const override;
240 Tool *buildLinker() const override;
241 Tool *getTool(Action::ActionClass AC) const override;
244 mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
245 mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
246 mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug;
249 MachO(const Driver &D, const llvm::Triple &Triple,
250 const llvm::opt::ArgList &Args);
253 /// @name MachO specific toolchain API
256 /// Get the "MachO" arch name for a particular compiler invocation. For
257 /// example, Apple treats different ARM variations as distinct architectures.
258 StringRef getMachOArchName(const llvm::opt::ArgList &Args) const;
260 /// Add the linker arguments to link the ARC runtime library.
261 virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
262 llvm::opt::ArgStringList &CmdArgs) const {}
264 /// Add the linker arguments to link the compiler runtime library.
265 virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
266 llvm::opt::ArgStringList &CmdArgs) const;
268 virtual void addStartObjectFileArgs(const llvm::opt::ArgList &Args,
269 llvm::opt::ArgStringList &CmdArgs) const {
272 virtual void addMinVersionArgs(const llvm::opt::ArgList &Args,
273 llvm::opt::ArgStringList &CmdArgs) const {}
275 /// On some iOS platforms, kernel and kernel modules were built statically. Is
276 /// this such a target?
277 virtual bool isKernelStatic() const { return false; }
279 /// Is the target either iOS or an iOS simulator?
280 bool isTargetIOSBased() const { return false; }
282 void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
283 llvm::opt::ArgStringList &CmdArgs,
284 StringRef DarwinLibName, bool AlwaysLink = false,
285 bool IsEmbedded = false, bool AddRPath = false) const;
287 /// Add any profiling runtime libraries that are needed. This is essentially a
288 /// MachO specific version of addProfileRT in Tools.cpp.
289 void addProfileRTLibs(const llvm::opt::ArgList &Args,
290 llvm::opt::ArgStringList &CmdArgs) const override {
291 // There aren't any profiling libs for embedded targets currently.
295 /// @name ToolChain Implementation
298 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
299 types::ID InputType) const override;
301 types::ID LookupTypeForExtension(const char *Ext) const override;
303 bool HasNativeLLVMSupport() const override;
305 llvm::opt::DerivedArgList *
306 TranslateArgs(const llvm::opt::DerivedArgList &Args,
307 const char *BoundArch) const override;
309 bool IsBlocksDefault() const override {
310 // Always allow blocks on Apple; users interested in versioning are
311 // expected to use /usr/include/Block.h.
314 bool IsIntegratedAssemblerDefault() const override {
315 // Default integrated assembler to on for Apple's MachO targets.
319 bool IsMathErrnoDefault() const override { return false; }
321 bool IsEncodeExtendedBlockSignatureDefault() const override { return true; }
323 bool IsObjCNonFragileABIDefault() const override {
324 // Non-fragile ABI is default for everything but i386.
325 return getTriple().getArch() != llvm::Triple::x86;
328 bool UseObjCMixedDispatch() const override { return true; }
330 bool IsUnwindTablesDefault() const override;
332 RuntimeLibType GetDefaultRuntimeLibType() const override {
333 return ToolChain::RLT_CompilerRT;
336 bool isPICDefault() const override;
337 bool isPIEDefault() const override;
338 bool isPICDefaultForced() const override;
340 bool SupportsProfiling() const override;
342 bool SupportsObjCGC() const override { return false; }
344 bool UseDwarfDebugFlags() const override;
346 bool UseSjLjExceptions(const llvm::opt::ArgList &Args) const override {
353 /// Darwin - The base Darwin tool chain.
354 class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
356 /// Whether the information on the target has been initialized.
358 // FIXME: This should be eliminated. What we want to do is make this part of
359 // the "default target for arguments" selection process, once we get out of
360 // the argument translation business.
361 mutable bool TargetInitialized;
363 enum DarwinPlatformKind {
373 mutable DarwinPlatformKind TargetPlatform;
375 /// The OS version we are targeting.
376 mutable VersionTuple TargetVersion;
379 void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
382 Darwin(const Driver &D, const llvm::Triple &Triple,
383 const llvm::opt::ArgList &Args);
386 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
387 types::ID InputType) const override;
389 /// @name Apple Specific Toolchain Implementation
392 void addMinVersionArgs(const llvm::opt::ArgList &Args,
393 llvm::opt::ArgStringList &CmdArgs) const override;
395 void addStartObjectFileArgs(const llvm::opt::ArgList &Args,
396 llvm::opt::ArgStringList &CmdArgs) const override;
398 bool isKernelStatic() const override {
399 return (!(isTargetIPhoneOS() && !isIPhoneOSVersionLT(6, 0)) &&
403 void addProfileRTLibs(const llvm::opt::ArgList &Args,
404 llvm::opt::ArgStringList &CmdArgs) const override;
408 /// @name Darwin specific Toolchain functions
411 // FIXME: Eliminate these ...Target functions and derive separate tool chains
412 // for these targets and put version in constructor.
413 void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
414 unsigned Micro) const {
415 // FIXME: For now, allow reinitialization as long as values don't
416 // change. This will go away when we move away from argument translation.
417 if (TargetInitialized && TargetPlatform == Platform &&
418 TargetVersion == VersionTuple(Major, Minor, Micro))
421 assert(!TargetInitialized && "Target already initialized!");
422 TargetInitialized = true;
423 TargetPlatform = Platform;
424 TargetVersion = VersionTuple(Major, Minor, Micro);
427 bool isTargetIPhoneOS() const {
428 assert(TargetInitialized && "Target not initialized!");
429 return TargetPlatform == IPhoneOS || TargetPlatform == TvOS;
432 bool isTargetIOSSimulator() const {
433 assert(TargetInitialized && "Target not initialized!");
434 return TargetPlatform == IPhoneOSSimulator ||
435 TargetPlatform == TvOSSimulator;
438 bool isTargetIOSBased() const {
439 assert(TargetInitialized && "Target not initialized!");
440 return isTargetIPhoneOS() || isTargetIOSSimulator();
443 bool isTargetTvOS() const {
444 assert(TargetInitialized && "Target not initialized!");
445 return TargetPlatform == TvOS;
448 bool isTargetTvOSSimulator() const {
449 assert(TargetInitialized && "Target not initialized!");
450 return TargetPlatform == TvOSSimulator;
453 bool isTargetTvOSBased() const {
454 assert(TargetInitialized && "Target not initialized!");
455 return TargetPlatform == TvOS || TargetPlatform == TvOSSimulator;
458 bool isTargetWatchOS() const {
459 assert(TargetInitialized && "Target not initialized!");
460 return TargetPlatform == WatchOS;
463 bool isTargetWatchOSSimulator() const {
464 assert(TargetInitialized && "Target not initialized!");
465 return TargetPlatform == WatchOSSimulator;
468 bool isTargetWatchOSBased() const {
469 assert(TargetInitialized && "Target not initialized!");
470 return TargetPlatform == WatchOS || TargetPlatform == WatchOSSimulator;
473 bool isTargetMacOS() const {
474 assert(TargetInitialized && "Target not initialized!");
475 return TargetPlatform == MacOS;
478 bool isTargetInitialized() const { return TargetInitialized; }
480 VersionTuple getTargetVersion() const {
481 assert(TargetInitialized && "Target not initialized!");
482 return TargetVersion;
485 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1 = 0,
486 unsigned V2 = 0) const {
487 assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
488 return TargetVersion < VersionTuple(V0, V1, V2);
491 bool isMacosxVersionLT(unsigned V0, unsigned V1 = 0, unsigned V2 = 0) const {
492 assert(isTargetMacOS() && "Unexpected call for non OS X target!");
493 return TargetVersion < VersionTuple(V0, V1, V2);
498 /// @name ToolChain Implementation
501 // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
502 // most development is done against SDKs, so compiling for a different
503 // architecture should not get any special treatment.
504 bool isCrossCompiling() const override { return false; }
506 llvm::opt::DerivedArgList *
507 TranslateArgs(const llvm::opt::DerivedArgList &Args,
508 const char *BoundArch) const override;
510 ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
511 bool hasBlocksRuntime() const override;
513 bool UseObjCMixedDispatch() const override {
514 // This is only used with the non-fragile ABI and non-legacy dispatch.
516 // Mixed dispatch is used everywhere except OS X before 10.6.
517 return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
520 unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
521 // Stack protectors default to on for user code on 10.5,
522 // and for everything in 10.6 and beyond
523 if (isTargetIOSBased() || isTargetWatchOSBased())
525 else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
527 else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
533 bool SupportsObjCGC() const override;
535 void CheckObjCARC() const override;
537 bool UseSjLjExceptions(const llvm::opt::ArgList &Args) const override;
539 SanitizerMask getSupportedSanitizers() const override;
542 /// DarwinClang - The Darwin toolchain used by Clang.
543 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
545 DarwinClang(const Driver &D, const llvm::Triple &Triple,
546 const llvm::opt::ArgList &Args);
548 /// @name Apple ToolChain Implementation
551 void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
552 llvm::opt::ArgStringList &CmdArgs) const override;
554 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
555 llvm::opt::ArgStringList &CmdArgs) const override;
557 void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
558 llvm::opt::ArgStringList &CmdArgs) const override;
560 void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
562 void AddLinkARCArgs(const llvm::opt::ArgList &Args,
563 llvm::opt::ArgStringList &CmdArgs) const override;
565 unsigned GetDefaultDwarfVersion() const override { return 2; }
566 // Until dtrace (via CTF) and LLDB can deal with distributed debug info,
567 // Darwin defaults to standalone/full debug info.
568 bool GetDefaultStandaloneDebug() const override { return true; }
569 llvm::DebuggerKind getDefaultDebuggerTuning() const override {
570 return llvm::DebuggerKind::LLDB;
576 void AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
577 llvm::opt::ArgStringList &CmdArgs,
578 StringRef Sanitizer) const;
581 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
582 virtual void anchor();
585 Generic_ELF(const Driver &D, const llvm::Triple &Triple,
586 const llvm::opt::ArgList &Args)
587 : Generic_GCC(D, Triple, Args) {}
589 void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
590 llvm::opt::ArgStringList &CC1Args) const override;
593 class LLVM_LIBRARY_VISIBILITY CloudABI : public Generic_ELF {
595 CloudABI(const Driver &D, const llvm::Triple &Triple,
596 const llvm::opt::ArgList &Args);
597 bool HasNativeLLVMSupport() const override { return true; }
599 bool IsMathErrnoDefault() const override { return false; }
600 bool IsObjCNonFragileABIDefault() const override { return true; }
603 GetCXXStdlibType(const llvm::opt::ArgList &Args) const override {
604 return ToolChain::CST_Libcxx;
606 void AddClangCXXStdlibIncludeArgs(
607 const llvm::opt::ArgList &DriverArgs,
608 llvm::opt::ArgStringList &CC1Args) const override;
609 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
610 llvm::opt::ArgStringList &CmdArgs) const override;
612 bool isPIEDefault() const override { return false; }
615 Tool *buildLinker() const override;
618 class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
620 Solaris(const Driver &D, const llvm::Triple &Triple,
621 const llvm::opt::ArgList &Args);
623 bool IsIntegratedAssemblerDefault() const override { return true; }
625 void AddClangCXXStdlibIncludeArgs(
626 const llvm::opt::ArgList &DriverArgs,
627 llvm::opt::ArgStringList &CC1Args) const override;
629 unsigned GetDefaultDwarfVersion() const override { return 2; }
632 Tool *buildAssembler() const override;
633 Tool *buildLinker() const override;
636 class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {
638 MinGW(const Driver &D, const llvm::Triple &Triple,
639 const llvm::opt::ArgList &Args);
641 bool IsIntegratedAssemblerDefault() const override;
642 bool IsUnwindTablesDefault() const override;
643 bool isPICDefault() const override;
644 bool isPIEDefault() const override;
645 bool isPICDefaultForced() const override;
646 bool UseSEHExceptions() const;
649 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
650 llvm::opt::ArgStringList &CC1Args) const override;
651 void AddClangCXXStdlibIncludeArgs(
652 const llvm::opt::ArgList &DriverArgs,
653 llvm::opt::ArgStringList &CC1Args) const override;
656 Tool *getTool(Action::ActionClass AC) const override;
657 Tool *buildLinker() const override;
658 Tool *buildAssembler() const override;
662 std::string GccLibDir;
665 mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocessor;
666 mutable std::unique_ptr<tools::gcc::Compiler> Compiler;
667 void findGccLibDir();
670 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
672 OpenBSD(const Driver &D, const llvm::Triple &Triple,
673 const llvm::opt::ArgList &Args);
675 bool IsMathErrnoDefault() const override { return false; }
676 bool IsObjCNonFragileABIDefault() const override { return true; }
677 bool isPIEDefault() const override { return true; }
679 unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
682 unsigned GetDefaultDwarfVersion() const override { return 2; }
685 Tool *buildAssembler() const override;
686 Tool *buildLinker() const override;
689 class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
691 Bitrig(const Driver &D, const llvm::Triple &Triple,
692 const llvm::opt::ArgList &Args);
694 bool IsMathErrnoDefault() const override { return false; }
695 bool IsObjCNonFragileABIDefault() const override { return true; }
697 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
698 void AddClangCXXStdlibIncludeArgs(
699 const llvm::opt::ArgList &DriverArgs,
700 llvm::opt::ArgStringList &CC1Args) const override;
701 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
702 llvm::opt::ArgStringList &CmdArgs) const override;
703 unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
708 Tool *buildAssembler() const override;
709 Tool *buildLinker() const override;
712 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
714 FreeBSD(const Driver &D, const llvm::Triple &Triple,
715 const llvm::opt::ArgList &Args);
716 bool HasNativeLLVMSupport() const override;
718 bool IsMathErrnoDefault() const override { return false; }
719 bool IsObjCNonFragileABIDefault() const override { return true; }
721 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
722 void AddClangCXXStdlibIncludeArgs(
723 const llvm::opt::ArgList &DriverArgs,
724 llvm::opt::ArgStringList &CC1Args) const override;
725 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
726 llvm::opt::ArgStringList &CmdArgs) const override;
728 bool UseSjLjExceptions(const llvm::opt::ArgList &Args) const override;
729 bool isPIEDefault() const override;
730 SanitizerMask getSupportedSanitizers() const override;
731 unsigned GetDefaultDwarfVersion() const override { return 2; }
732 // Until dtrace (via CTF) and LLDB can deal with distributed debug info,
733 // FreeBSD defaults to standalone/full debug info.
734 bool GetDefaultStandaloneDebug() const override { return true; }
737 Tool *buildAssembler() const override;
738 Tool *buildLinker() const override;
741 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
743 NetBSD(const Driver &D, const llvm::Triple &Triple,
744 const llvm::opt::ArgList &Args);
746 bool IsMathErrnoDefault() const override { return false; }
747 bool IsObjCNonFragileABIDefault() const override { return true; }
749 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
751 void AddClangCXXStdlibIncludeArgs(
752 const llvm::opt::ArgList &DriverArgs,
753 llvm::opt::ArgStringList &CC1Args) const override;
754 bool IsUnwindTablesDefault() const override { return true; }
757 Tool *buildAssembler() const override;
758 Tool *buildLinker() const override;
761 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
763 Minix(const Driver &D, const llvm::Triple &Triple,
764 const llvm::opt::ArgList &Args);
767 Tool *buildAssembler() const override;
768 Tool *buildLinker() const override;
771 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
773 DragonFly(const Driver &D, const llvm::Triple &Triple,
774 const llvm::opt::ArgList &Args);
776 bool IsMathErrnoDefault() const override { return false; }
779 Tool *buildAssembler() const override;
780 Tool *buildLinker() const override;
783 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
785 Linux(const Driver &D, const llvm::Triple &Triple,
786 const llvm::opt::ArgList &Args);
788 bool HasNativeLLVMSupport() const override;
791 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
792 llvm::opt::ArgStringList &CC1Args) const override;
793 void AddClangCXXStdlibIncludeArgs(
794 const llvm::opt::ArgList &DriverArgs,
795 llvm::opt::ArgStringList &CC1Args) const override;
796 void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
797 llvm::opt::ArgStringList &CC1Args) const override;
798 bool isPIEDefault() const override;
799 SanitizerMask getSupportedSanitizers() const override;
800 void addProfileRTLibs(const llvm::opt::ArgList &Args,
801 llvm::opt::ArgStringList &CmdArgs) const override;
802 virtual std::string computeSysRoot() const;
804 std::vector<std::string> ExtraOpts;
807 Tool *buildAssembler() const override;
808 Tool *buildLinker() const override;
811 class LLVM_LIBRARY_VISIBILITY CudaToolChain : public Linux {
813 CudaToolChain(const Driver &D, const llvm::Triple &Triple,
814 const llvm::opt::ArgList &Args);
816 llvm::opt::DerivedArgList *
817 TranslateArgs(const llvm::opt::DerivedArgList &Args,
818 const char *BoundArch) const override;
819 void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
820 llvm::opt::ArgStringList &CC1Args) const override;
823 class LLVM_LIBRARY_VISIBILITY MipsLLVMToolChain : public Linux {
825 Tool *buildLinker() const override;
828 MipsLLVMToolChain(const Driver &D, const llvm::Triple &Triple,
829 const llvm::opt::ArgList &Args);
832 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
833 llvm::opt::ArgStringList &CC1Args) const override;
835 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
837 void AddClangCXXStdlibIncludeArgs(
838 const llvm::opt::ArgList &DriverArgs,
839 llvm::opt::ArgStringList &CC1Args) const override;
841 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
842 llvm::opt::ArgStringList &CmdArgs) const override;
844 std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
845 bool Shared = false) const override;
847 std::string computeSysRoot() const override;
849 RuntimeLibType GetDefaultRuntimeLibType() const override {
850 return GCCInstallation.isValid() ? RuntimeLibType::RLT_Libgcc
851 : RuntimeLibType::RLT_CompilerRT;
855 Multilib SelectedMultilib;
856 std::string LibSuffix;
859 class LLVM_LIBRARY_VISIBILITY HexagonToolChain : public Linux {
861 GCCVersion GCCLibAndIncVersion;
862 Tool *buildAssembler() const override;
863 Tool *buildLinker() const override;
866 HexagonToolChain(const Driver &D, const llvm::Triple &Triple,
867 const llvm::opt::ArgList &Args);
868 ~HexagonToolChain() override;
871 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
872 llvm::opt::ArgStringList &CC1Args) const override;
873 void AddClangCXXStdlibIncludeArgs(
874 const llvm::opt::ArgList &DriverArgs,
875 llvm::opt::ArgStringList &CC1Args) const override;
876 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
878 StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
879 bool IsIntegratedAssemblerDefault() const override {
883 std::string getHexagonTargetDir(
884 const std::string &InstalledDir,
885 const SmallVectorImpl<std::string> &PrefixDirs) const;
886 void getHexagonLibraryPaths(const llvm::opt::ArgList &Args,
887 ToolChain::path_list &LibPaths) const;
889 static const StringRef GetDefaultCPU();
890 static const StringRef GetTargetCPUVersion(const llvm::opt::ArgList &Args);
892 static Optional<unsigned> getSmallDataThreshold(
893 const llvm::opt::ArgList &Args);
896 class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
898 Tool *buildLinker() const override;
901 AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
902 const llvm::opt::ArgList &Args);
903 bool IsIntegratedAssemblerDefault() const override { return true; }
906 class LLVM_LIBRARY_VISIBILITY NaClToolChain : public Generic_ELF {
908 NaClToolChain(const Driver &D, const llvm::Triple &Triple,
909 const llvm::opt::ArgList &Args);
912 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
913 llvm::opt::ArgStringList &CC1Args) const override;
914 void AddClangCXXStdlibIncludeArgs(
915 const llvm::opt::ArgList &DriverArgs,
916 llvm::opt::ArgStringList &CC1Args) const override;
918 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
920 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
921 llvm::opt::ArgStringList &CmdArgs) const override;
923 bool IsIntegratedAssemblerDefault() const override {
924 return getTriple().getArch() == llvm::Triple::mipsel;
927 // Get the path to the file containing NaCl's ARM macros.
928 // It lives in NaClToolChain because the ARMAssembler tool needs a
929 // const char * that it can pass around,
930 const char *GetNaClArmMacrosPath() const { return NaClArmMacrosPath.c_str(); }
932 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
933 types::ID InputType) const override;
936 Tool *buildLinker() const override;
937 Tool *buildAssembler() const override;
940 std::string NaClArmMacrosPath;
943 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
944 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
945 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
947 TCEToolChain(const Driver &D, const llvm::Triple &Triple,
948 const llvm::opt::ArgList &Args);
949 ~TCEToolChain() override;
951 bool IsMathErrnoDefault() const override;
952 bool isPICDefault() const override;
953 bool isPIEDefault() const override;
954 bool isPICDefaultForced() const override;
957 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
959 MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
960 const llvm::opt::ArgList &Args);
962 llvm::opt::DerivedArgList *
963 TranslateArgs(const llvm::opt::DerivedArgList &Args,
964 const char *BoundArch) const override;
966 bool IsIntegratedAssemblerDefault() const override;
967 bool IsUnwindTablesDefault() const override;
968 bool isPICDefault() const override;
969 bool isPIEDefault() const override;
970 bool isPICDefaultForced() const override;
973 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
974 llvm::opt::ArgStringList &CC1Args) const override;
975 void AddClangCXXStdlibIncludeArgs(
976 const llvm::opt::ArgList &DriverArgs,
977 llvm::opt::ArgStringList &CC1Args) const override;
979 bool getWindowsSDKDir(std::string &path, int &major,
980 std::string &windowsSDKIncludeVersion,
981 std::string &windowsSDKLibVersion) const;
982 bool getWindowsSDKLibraryPath(std::string &path) const;
983 /// \brief Check if Universal CRT should be used if available
984 bool useUniversalCRT(std::string &visualStudioDir) const;
985 bool getUniversalCRTSdkDir(std::string &path, std::string &ucrtVersion) const;
986 bool getUniversalCRTLibraryPath(std::string &path) const;
987 bool getVisualStudioInstallDir(std::string &path) const;
988 bool getVisualStudioBinariesFolder(const char *clangProgramPath,
989 std::string &path) const;
991 std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
992 types::ID InputType) const override;
993 SanitizerMask getSupportedSanitizers() const override;
996 void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
997 llvm::opt::ArgStringList &CC1Args,
998 const std::string &folder,
999 const Twine &subfolder1,
1000 const Twine &subfolder2 = "",
1001 const Twine &subfolder3 = "") const;
1003 Tool *buildLinker() const override;
1004 Tool *buildAssembler() const override;
1007 class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
1009 CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
1010 const llvm::opt::ArgList &Args);
1012 bool IsIntegratedAssemblerDefault() const override { return true; }
1013 bool IsUnwindTablesDefault() const override;
1014 bool isPICDefault() const override;
1015 bool isPIEDefault() const override;
1016 bool isPICDefaultForced() const override;
1018 unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
1023 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
1024 llvm::opt::ArgStringList &CC1Args) const override;
1025 void AddClangCXXStdlibIncludeArgs(
1026 const llvm::opt::ArgList &DriverArgs,
1027 llvm::opt::ArgStringList &CC1Args) const override;
1028 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
1029 llvm::opt::ArgStringList &CmdArgs) const override;
1031 SanitizerMask getSupportedSanitizers() const override;
1034 Tool *buildLinker() const override;
1035 Tool *buildAssembler() const override;
1038 class LLVM_LIBRARY_VISIBILITY XCoreToolChain : public ToolChain {
1040 XCoreToolChain(const Driver &D, const llvm::Triple &Triple,
1041 const llvm::opt::ArgList &Args);
1044 Tool *buildAssembler() const override;
1045 Tool *buildLinker() const override;
1048 bool isPICDefault() const override;
1049 bool isPIEDefault() const override;
1050 bool isPICDefaultForced() const override;
1051 bool SupportsProfiling() const override;
1052 bool hasBlocksRuntime() const override;
1054 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
1055 llvm::opt::ArgStringList &CC1Args) const override;
1056 void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
1057 llvm::opt::ArgStringList &CC1Args) const override;
1058 void AddClangCXXStdlibIncludeArgs(
1059 const llvm::opt::ArgList &DriverArgs,
1060 llvm::opt::ArgStringList &CC1Args) const override;
1061 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
1062 llvm::opt::ArgStringList &CmdArgs) const override;
1065 /// MyriadToolChain - A tool chain using either clang or the external compiler
1066 /// installed by the Movidius SDK to perform all subcommands.
1067 class LLVM_LIBRARY_VISIBILITY MyriadToolChain : public Generic_GCC {
1069 MyriadToolChain(const Driver &D, const llvm::Triple &Triple,
1070 const llvm::opt::ArgList &Args);
1071 ~MyriadToolChain() override;
1074 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
1075 llvm::opt::ArgStringList &CC1Args) const override;
1076 void AddClangCXXStdlibIncludeArgs(
1077 const llvm::opt::ArgList &DriverArgs,
1078 llvm::opt::ArgStringList &CC1Args) const override;
1079 Tool *SelectTool(const JobAction &JA) const override;
1080 unsigned GetDefaultDwarfVersion() const override { return 2; }
1083 Tool *buildLinker() const override;
1084 bool isShaveCompilation(const llvm::Triple &T) const {
1085 return T.getArch() == llvm::Triple::shave;
1089 mutable std::unique_ptr<Tool> Compiler;
1090 mutable std::unique_ptr<Tool> Assembler;
1093 class LLVM_LIBRARY_VISIBILITY WebAssembly final : public ToolChain {
1095 WebAssembly(const Driver &D, const llvm::Triple &Triple,
1096 const llvm::opt::ArgList &Args);
1099 bool IsMathErrnoDefault() const override;
1100 bool IsObjCNonFragileABIDefault() const override;
1101 bool UseObjCMixedDispatch() const override;
1102 bool isPICDefault() const override;
1103 bool isPIEDefault() const override;
1104 bool isPICDefaultForced() const override;
1105 bool IsIntegratedAssemblerDefault() const override;
1106 bool hasBlocksRuntime() const override;
1107 bool SupportsObjCGC() const override;
1108 bool SupportsProfiling() const override;
1109 bool HasNativeLLVMSupport() const override;
1110 void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
1111 llvm::opt::ArgStringList &CC1Args) const override;
1113 Tool *buildLinker() const override;
1116 class LLVM_LIBRARY_VISIBILITY PS4CPU : public Generic_ELF {
1118 PS4CPU(const Driver &D, const llvm::Triple &Triple,
1119 const llvm::opt::ArgList &Args);
1121 bool IsMathErrnoDefault() const override { return false; }
1122 bool IsObjCNonFragileABIDefault() const override { return true; }
1123 bool HasNativeLLVMSupport() const override;
1124 bool isPICDefault() const override;
1126 unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
1127 return 2; // SSPStrong
1130 llvm::DebuggerKind getDefaultDebuggerTuning() const override {
1131 return llvm::DebuggerKind::SCE;
1134 SanitizerMask getSupportedSanitizers() const override;
1137 Tool *buildAssembler() const override;
1138 Tool *buildLinker() const override;
1141 } // end namespace toolchains
1142 } // end namespace driver
1143 } // end namespace clang
1145 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H