1//===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
11#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
12
13#include "Tools.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"
21#include <set>
22#include <vector>
23
24namespace clang {
25namespace driver {
26namespace toolchains {
27
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.
31class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
32protected:
33  /// \brief Struct to store and manipulate GCC versions.
34  ///
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.
40  ///
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.
44  ///
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.
48  struct GCCVersion {
49    /// \brief The unparsed text of the version.
50    std::string Text;
51
52    /// \brief The parsed major, minor, and patch numbers.
53    int Major, Minor, Patch;
54
55    /// \brief The text of the parsed major, and major+minor versions.
56    std::string MajorStr, MinorStr;
57
58    /// \brief Any textual suffix on the patch number.
59    std::string PatchSuffix;
60
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);
66    }
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); }
70  };
71
72  /// \brief This is a class to find a viable GCC installation for Clang to
73  /// use.
74  ///
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 {
79    bool IsValid;
80    llvm::Triple GCCTriple;
81
82    // FIXME: These might be better as path objects.
83    std::string GCCInstallPath;
84    std::string GCCParentLibPath;
85
86    /// The primary multilib appropriate for the given flags.
87    Multilib SelectedMultilib;
88    /// On Biarch systems, this corresponds to the default multilib when
89    /// targeting the non-default multilib. Otherwise, it is empty.
90    llvm::Optional<Multilib> BiarchSibling;
91
92    GCCVersion Version;
93
94    // We retain the list of install paths that were considered and rejected in
95    // order to print out detailed information in verbose mode.
96    std::set<std::string> CandidateGCCInstallPaths;
97
98    /// The set of multilibs that the detected installation supports.
99    MultilibSet Multilibs;
100
101  public:
102    GCCInstallationDetector() : IsValid(false) {}
103    void init(const Driver &D, const llvm::Triple &TargetTriple,
104                            const llvm::opt::ArgList &Args);
105
106    /// \brief Check whether we detected a valid GCC install.
107    bool isValid() const { return IsValid; }
108
109    /// \brief Get the GCC triple for the detected install.
110    const llvm::Triple &getTriple() const { return GCCTriple; }
111
112    /// \brief Get the detected GCC installation path.
113    StringRef getInstallPath() const { return GCCInstallPath; }
114
115    /// \brief Get the detected GCC parent lib path.
116    StringRef getParentLibPath() const { return GCCParentLibPath; }
117
118    /// \brief Get the detected Multilib
119    const Multilib &getMultilib() const { return SelectedMultilib; }
120
121    /// \brief Get the whole MultilibSet
122    const MultilibSet &getMultilibs() const { return Multilibs; }
123
124    /// Get the biarch sibling multilib (if it exists).
125    /// \return true iff such a sibling exists
126    bool getBiarchSibling(Multilib &M) const;
127
128    /// \brief Get the detected GCC version string.
129    const GCCVersion &getVersion() const { return Version; }
130
131    /// \brief Print information about the detected GCC installation.
132    void print(raw_ostream &OS) const;
133
134  private:
135    static void
136    CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
137                             const llvm::Triple &BiarchTriple,
138                             SmallVectorImpl<StringRef> &LibDirs,
139                             SmallVectorImpl<StringRef> &TripleAliases,
140                             SmallVectorImpl<StringRef> &BiarchLibDirs,
141                             SmallVectorImpl<StringRef> &BiarchTripleAliases);
142
143    void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch,
144                                const llvm::opt::ArgList &Args,
145                                const std::string &LibDir,
146                                StringRef CandidateTriple,
147                                bool NeedsBiarchSuffix = false);
148  };
149
150  GCCInstallationDetector GCCInstallation;
151
152public:
153  Generic_GCC(const Driver &D, const llvm::Triple &Triple,
154              const llvm::opt::ArgList &Args);
155  ~Generic_GCC() override;
156
157  void printVerboseInfo(raw_ostream &OS) const override;
158
159  bool IsUnwindTablesDefault() const override;
160  bool isPICDefault() const override;
161  bool isPIEDefault() const override;
162  bool isPICDefaultForced() const override;
163  bool IsIntegratedAssemblerDefault() const override;
164
165protected:
166  Tool *getTool(Action::ActionClass AC) const override;
167  Tool *buildAssembler() const override;
168  Tool *buildLinker() const override;
169
170  /// \name ToolChain Implementation Helper Functions
171  /// @{
172
173  /// \brief Check whether the target triple's architecture is 64-bits.
174  bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
175
176  /// \brief Check whether the target triple's architecture is 32-bits.
177  bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
178
179  /// @}
180
181private:
182  mutable std::unique_ptr<tools::gcc::Preprocess> Preprocess;
183  mutable std::unique_ptr<tools::gcc::Compile> Compile;
184};
185
186class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
187protected:
188  Tool *buildAssembler() const override;
189  Tool *buildLinker() const override;
190  Tool *getTool(Action::ActionClass AC) const override;
191private:
192  mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
193  mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
194  mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug;
195
196public:
197  MachO(const Driver &D, const llvm::Triple &Triple,
198             const llvm::opt::ArgList &Args);
199  ~MachO() override;
200
201  /// @name MachO specific toolchain API
202  /// {
203
204  /// Get the "MachO" arch name for a particular compiler invocation. For
205  /// example, Apple treats different ARM variations as distinct architectures.
206  StringRef getMachOArchName(const llvm::opt::ArgList &Args) const;
207
208
209  /// Add the linker arguments to link the ARC runtime library.
210  virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
211                              llvm::opt::ArgStringList &CmdArgs) const {}
212
213  /// Add the linker arguments to link the compiler runtime library.
214  virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
215                                     llvm::opt::ArgStringList &CmdArgs) const;
216
217  virtual void
218  addStartObjectFileArgs(const llvm::opt::ArgList &Args,
219                         llvm::opt::ArgStringList &CmdArgs) const {}
220
221  virtual void addMinVersionArgs(const llvm::opt::ArgList &Args,
222                                 llvm::opt::ArgStringList &CmdArgs) const {}
223
224  /// On some iOS platforms, kernel and kernel modules were built statically. Is
225  /// this such a target?
226  virtual bool isKernelStatic() const {
227    return false;
228  }
229
230  /// Is the target either iOS or an iOS simulator?
231  bool isTargetIOSBased() const {
232    return false;
233  }
234
235  void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
236                         llvm::opt::ArgStringList &CmdArgs,
237                         StringRef DarwinLibName,
238                         bool AlwaysLink = false,
239                         bool IsEmbedded = false,
240                         bool AddRPath = false) const;
241
242  /// }
243  /// @name ToolChain Implementation
244  /// {
245
246  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
247                                          types::ID InputType) const override;
248
249  types::ID LookupTypeForExtension(const char *Ext) const override;
250
251  bool HasNativeLLVMSupport() const override;
252
253  llvm::opt::DerivedArgList *
254  TranslateArgs(const llvm::opt::DerivedArgList &Args,
255                const char *BoundArch) const override;
256
257  bool IsBlocksDefault() const override {
258    // Always allow blocks on Apple; users interested in versioning are
259    // expected to use /usr/include/Block.h.
260    return true;
261  }
262  bool IsIntegratedAssemblerDefault() const override {
263    // Default integrated assembler to on for Apple's MachO targets.
264    return true;
265  }
266
267  bool IsMathErrnoDefault() const override {
268    return false;
269  }
270
271  bool IsEncodeExtendedBlockSignatureDefault() const override {
272    return true;
273  }
274
275  bool IsObjCNonFragileABIDefault() const override {
276    // Non-fragile ABI is default for everything but i386.
277    return getTriple().getArch() != llvm::Triple::x86;
278  }
279
280  bool UseObjCMixedDispatch() const override {
281    return true;
282  }
283
284  bool IsUnwindTablesDefault() const override;
285
286  RuntimeLibType GetDefaultRuntimeLibType() const override {
287    return ToolChain::RLT_CompilerRT;
288  }
289
290  bool isPICDefault() const override;
291  bool isPIEDefault() const override;
292  bool isPICDefaultForced() const override;
293
294  bool SupportsProfiling() const override;
295
296  bool SupportsObjCGC() const override {
297    return false;
298  }
299
300  bool UseDwarfDebugFlags() const override;
301
302  bool UseSjLjExceptions() const override {
303    return false;
304  }
305
306  /// }
307};
308
309  /// Darwin - The base Darwin tool chain.
310class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
311public:
312  /// The host version.
313  unsigned DarwinVersion[3];
314
315  /// Whether the information on the target has been initialized.
316  //
317  // FIXME: This should be eliminated. What we want to do is make this part of
318  // the "default target for arguments" selection process, once we get out of
319  // the argument translation business.
320  mutable bool TargetInitialized;
321
322  enum DarwinPlatformKind {
323    MacOS,
324    IPhoneOS,
325    IPhoneOSSimulator
326  };
327
328  mutable DarwinPlatformKind TargetPlatform;
329
330  /// The OS version we are targeting.
331  mutable VersionTuple TargetVersion;
332
333private:
334  /// The default macosx-version-min of this tool chain; empty until
335  /// initialized.
336  std::string MacosxVersionMin;
337
338  /// The default ios-version-min of this tool chain; empty until
339  /// initialized.
340  std::string iOSVersionMin;
341
342private:
343  void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
344
345public:
346  Darwin(const Driver &D, const llvm::Triple &Triple,
347         const llvm::opt::ArgList &Args);
348  ~Darwin() override;
349
350  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
351                                          types::ID InputType) const override;
352
353  /// @name Apple Specific Toolchain Implementation
354  /// {
355
356  void
357  addMinVersionArgs(const llvm::opt::ArgList &Args,
358                    llvm::opt::ArgStringList &CmdArgs) const override;
359
360  void
361  addStartObjectFileArgs(const llvm::opt::ArgList &Args,
362                         llvm::opt::ArgStringList &CmdArgs) const override;
363
364  bool isKernelStatic() const override {
365    return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0);
366  }
367
368protected:
369  /// }
370  /// @name Darwin specific Toolchain functions
371  /// {
372
373  // FIXME: Eliminate these ...Target functions and derive separate tool chains
374  // for these targets and put version in constructor.
375  void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
376                 unsigned Micro) const {
377    // FIXME: For now, allow reinitialization as long as values don't
378    // change. This will go away when we move away from argument translation.
379    if (TargetInitialized && TargetPlatform == Platform &&
380        TargetVersion == VersionTuple(Major, Minor, Micro))
381      return;
382
383    assert(!TargetInitialized && "Target already initialized!");
384    TargetInitialized = true;
385    TargetPlatform = Platform;
386    TargetVersion = VersionTuple(Major, Minor, Micro);
387  }
388
389  bool isTargetIPhoneOS() const {
390    assert(TargetInitialized && "Target not initialized!");
391    return TargetPlatform == IPhoneOS;
392  }
393
394  bool isTargetIOSSimulator() const {
395    assert(TargetInitialized && "Target not initialized!");
396    return TargetPlatform == IPhoneOSSimulator;
397  }
398
399  bool isTargetIOSBased() const {
400    assert(TargetInitialized && "Target not initialized!");
401    return isTargetIPhoneOS() || isTargetIOSSimulator();
402  }
403
404  bool isTargetMacOS() const {
405    return TargetPlatform == MacOS;
406  }
407
408  bool isTargetInitialized() const { return TargetInitialized; }
409
410  VersionTuple getTargetVersion() const {
411    assert(TargetInitialized && "Target not initialized!");
412    return TargetVersion;
413  }
414
415  bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
416    assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
417    return TargetVersion < VersionTuple(V0, V1, V2);
418  }
419
420  bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
421    assert(isTargetMacOS() && "Unexpected call for non OS X target!");
422    return TargetVersion < VersionTuple(V0, V1, V2);
423  }
424
425public:
426  /// }
427  /// @name ToolChain Implementation
428  /// {
429
430  // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
431  // most development is done against SDKs, so compiling for a different
432  // architecture should not get any special treatment.
433  bool isCrossCompiling() const override { return false; }
434
435  llvm::opt::DerivedArgList *
436  TranslateArgs(const llvm::opt::DerivedArgList &Args,
437                const char *BoundArch) const override;
438
439  ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
440  bool hasBlocksRuntime() const override;
441
442  bool UseObjCMixedDispatch() const override {
443    // This is only used with the non-fragile ABI and non-legacy dispatch.
444
445    // Mixed dispatch is used everywhere except OS X before 10.6.
446    return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
447  }
448
449  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
450    // Stack protectors default to on for user code on 10.5,
451    // and for everything in 10.6 and beyond
452    if (isTargetIOSBased())
453      return 1;
454    else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
455      return 1;
456    else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
457      return 1;
458
459    return 0;
460  }
461
462  bool SupportsObjCGC() const override;
463
464  void CheckObjCARC() const override;
465
466  bool UseSjLjExceptions() const override;
467};
468
469/// DarwinClang - The Darwin toolchain used by Clang.
470class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
471public:
472  DarwinClang(const Driver &D, const llvm::Triple &Triple,
473              const llvm::opt::ArgList &Args);
474
475  /// @name Apple ToolChain Implementation
476  /// {
477
478  void
479  AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
480                        llvm::opt::ArgStringList &CmdArgs) const override;
481
482  void
483  AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
484                      llvm::opt::ArgStringList &CmdArgs) const override;
485
486  void
487  AddCCKextLibArgs(const llvm::opt::ArgList &Args,
488                   llvm::opt::ArgStringList &CmdArgs) const override;
489
490  void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
491
492  void
493  AddLinkARCArgs(const llvm::opt::ArgList &Args,
494                 llvm::opt::ArgStringList &CmdArgs) const override;
495  /// }
496
497private:
498  void AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
499                               llvm::opt::ArgStringList &CmdArgs,
500                               StringRef Sanitizer) const;
501};
502
503class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
504  virtual void anchor();
505public:
506  Generic_ELF(const Driver &D, const llvm::Triple &Triple,
507              const llvm::opt::ArgList &Args)
508      : Generic_GCC(D, Triple, Args) {}
509
510  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
511                             llvm::opt::ArgStringList &CC1Args) const override;
512};
513
514class LLVM_LIBRARY_VISIBILITY CloudABI : public Generic_ELF {
515public:
516  CloudABI(const Driver &D, const llvm::Triple &Triple,
517           const llvm::opt::ArgList &Args);
518  bool HasNativeLLVMSupport() const override { return true; }
519
520  bool IsMathErrnoDefault() const override { return false; }
521  bool IsObjCNonFragileABIDefault() const override { return true; }
522
523  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args)
524      const override {
525    return ToolChain::CST_Libcxx;
526  }
527  void AddClangCXXStdlibIncludeArgs(
528      const llvm::opt::ArgList &DriverArgs,
529      llvm::opt::ArgStringList &CC1Args) const override;
530  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
531                           llvm::opt::ArgStringList &CmdArgs) const override;
532
533  bool isPIEDefault() const override { return false; }
534
535protected:
536  Tool *buildLinker() const override;
537};
538
539class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
540public:
541  Solaris(const Driver &D, const llvm::Triple &Triple,
542          const llvm::opt::ArgList &Args);
543
544  bool IsIntegratedAssemblerDefault() const override { return true; }
545protected:
546  Tool *buildAssembler() const override;
547  Tool *buildLinker() const override;
548
549};
550
551
552class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
553public:
554  OpenBSD(const Driver &D, const llvm::Triple &Triple,
555          const llvm::opt::ArgList &Args);
556
557  bool IsMathErrnoDefault() const override { return false; }
558  bool IsObjCNonFragileABIDefault() const override { return true; }
559  bool isPIEDefault() const override { return true; }
560
561  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
562    return 2;
563  }
564
565protected:
566  Tool *buildAssembler() const override;
567  Tool *buildLinker() const override;
568};
569
570class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
571public:
572  Bitrig(const Driver &D, const llvm::Triple &Triple,
573         const llvm::opt::ArgList &Args);
574
575  bool IsMathErrnoDefault() const override { return false; }
576  bool IsObjCNonFragileABIDefault() const override { return true; }
577
578  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
579  void
580  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
581                              llvm::opt::ArgStringList &CC1Args) const override;
582  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
583                           llvm::opt::ArgStringList &CmdArgs) const override;
584  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
585     return 1;
586  }
587
588protected:
589  Tool *buildAssembler() const override;
590  Tool *buildLinker() const override;
591};
592
593class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
594public:
595  FreeBSD(const Driver &D, const llvm::Triple &Triple,
596          const llvm::opt::ArgList &Args);
597  bool HasNativeLLVMSupport() const override;
598
599  bool IsMathErrnoDefault() const override { return false; }
600  bool IsObjCNonFragileABIDefault() const override { return true; }
601
602  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
603  void
604  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
605                               llvm::opt::ArgStringList &CC1Args) const override;
606
607  bool UseSjLjExceptions() const override;
608  bool isPIEDefault() const override;
609protected:
610  Tool *buildAssembler() const override;
611  Tool *buildLinker() const override;
612};
613
614class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
615public:
616  NetBSD(const Driver &D, const llvm::Triple &Triple,
617         const llvm::opt::ArgList &Args);
618
619  bool IsMathErrnoDefault() const override { return false; }
620  bool IsObjCNonFragileABIDefault() const override { return true; }
621
622  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
623
624  void
625  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
626                              llvm::opt::ArgStringList &CC1Args) const override;
627  bool IsUnwindTablesDefault() const override {
628    return true;
629  }
630
631protected:
632  Tool *buildAssembler() const override;
633  Tool *buildLinker() const override;
634};
635
636class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
637public:
638  Minix(const Driver &D, const llvm::Triple &Triple,
639        const llvm::opt::ArgList &Args);
640
641protected:
642  Tool *buildAssembler() const override;
643  Tool *buildLinker() const override;
644};
645
646class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
647public:
648  DragonFly(const Driver &D, const llvm::Triple &Triple,
649            const llvm::opt::ArgList &Args);
650
651  bool IsMathErrnoDefault() const override { return false; }
652
653protected:
654  Tool *buildAssembler() const override;
655  Tool *buildLinker() const override;
656};
657
658class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
659public:
660  Linux(const Driver &D, const llvm::Triple &Triple,
661        const llvm::opt::ArgList &Args);
662
663  bool HasNativeLLVMSupport() const override;
664
665  void
666  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
667                            llvm::opt::ArgStringList &CC1Args) const override;
668  void
669  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
670                               llvm::opt::ArgStringList &CC1Args) const override;
671  bool isPIEDefault() const override;
672
673  std::string Linker;
674  std::vector<std::string> ExtraOpts;
675
676protected:
677  Tool *buildAssembler() const override;
678  Tool *buildLinker() const override;
679
680private:
681  static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
682                                       StringRef GCCTriple,
683                                       StringRef GCCMultiarchTriple,
684                                       StringRef TargetMultiarchTriple,
685                                       Twine IncludeSuffix,
686                                       const llvm::opt::ArgList &DriverArgs,
687                                       llvm::opt::ArgStringList &CC1Args);
688
689  std::string computeSysRoot() const;
690};
691
692class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
693protected:
694  GCCVersion GCCLibAndIncVersion;
695  Tool *buildAssembler() const override;
696  Tool *buildLinker() const override;
697
698public:
699  Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
700             const llvm::opt::ArgList &Args);
701  ~Hexagon_TC() override;
702
703  void
704  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
705                            llvm::opt::ArgStringList &CC1Args) const override;
706  void
707  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
708                              llvm::opt::ArgStringList &CC1Args) const override;
709  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
710
711  StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
712
713  static std::string GetGnuDir(const std::string &InstalledDir,
714                               const llvm::opt::ArgList &Args);
715
716  static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
717};
718
719class LLVM_LIBRARY_VISIBILITY NaCl_TC : public Generic_ELF {
720public:
721  NaCl_TC(const Driver &D, const llvm::Triple &Triple,
722          const llvm::opt::ArgList &Args);
723
724  void
725  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
726                            llvm::opt::ArgStringList &CC1Args) const override;
727  void
728  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
729                               llvm::opt::ArgStringList &CC1Args) const override;
730
731  CXXStdlibType
732  GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
733
734  void
735  AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
736                      llvm::opt::ArgStringList &CmdArgs) const override;
737
738  bool
739  IsIntegratedAssemblerDefault() const override { return false; }
740
741  // Get the path to the file containing NaCl's ARM macros. It lives in NaCl_TC
742  // because the AssembleARM tool needs a const char * that it can pass around
743  // and the toolchain outlives all the jobs.
744  const char *GetNaClArmMacrosPath() const { return NaClArmMacrosPath.c_str(); }
745
746  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
747                                          types::ID InputType) const override;
748  std::string Linker;
749
750protected:
751  Tool *buildLinker() const override;
752  Tool *buildAssembler() const override;
753
754private:
755  std::string NaClArmMacrosPath;
756};
757
758/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
759/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
760class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
761public:
762  TCEToolChain(const Driver &D, const llvm::Triple &Triple,
763               const llvm::opt::ArgList &Args);
764  ~TCEToolChain() override;
765
766  bool IsMathErrnoDefault() const override;
767  bool isPICDefault() const override;
768  bool isPIEDefault() const override;
769  bool isPICDefaultForced() const override;
770};
771
772class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
773public:
774  MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
775                const llvm::opt::ArgList &Args);
776
777  bool IsIntegratedAssemblerDefault() const override;
778  bool IsUnwindTablesDefault() const override;
779  bool isPICDefault() const override;
780  bool isPIEDefault() const override;
781  bool isPICDefaultForced() const override;
782
783  void
784  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
785                            llvm::opt::ArgStringList &CC1Args) const override;
786  void
787  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
788                               llvm::opt::ArgStringList &CC1Args) const override;
789
790  bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
791  bool getWindowsSDKLibraryPath(std::string &path) const;
792  bool getVisualStudioInstallDir(std::string &path) const;
793  bool getVisualStudioBinariesFolder(const char *clangProgramPath,
794                                     std::string &path) const;
795
796protected:
797  void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
798                                     llvm::opt::ArgStringList &CC1Args,
799                                     const std::string &folder,
800                                     const char *subfolder) const;
801
802  Tool *buildLinker() const override;
803  Tool *buildAssembler() const override;
804};
805
806class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
807public:
808  CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
809                        const llvm::opt::ArgList &Args);
810
811  bool IsIntegratedAssemblerDefault() const override { return true; }
812  bool IsUnwindTablesDefault() const override;
813  bool isPICDefault() const override;
814  bool isPIEDefault() const override;
815  bool isPICDefaultForced() const override;
816
817  unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
818    return 0;
819  }
820
821  void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
822                                 llvm::opt::ArgStringList &CC1Args)
823      const override;
824  void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
825                                    llvm::opt::ArgStringList &CC1Args)
826      const override;
827  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
828                           llvm::opt::ArgStringList &CmdArgs) const override;
829
830protected:
831  Tool *buildLinker() const override;
832  Tool *buildAssembler() const override;
833};
834
835class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
836public:
837  XCore(const Driver &D, const llvm::Triple &Triple,
838          const llvm::opt::ArgList &Args);
839protected:
840  Tool *buildAssembler() const override;
841  Tool *buildLinker() const override;
842public:
843  bool isPICDefault() const override;
844  bool isPIEDefault() const override;
845  bool isPICDefaultForced() const override;
846  bool SupportsProfiling() const override;
847  bool hasBlocksRuntime() const override;
848  void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
849                    llvm::opt::ArgStringList &CC1Args) const override;
850  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
851                             llvm::opt::ArgStringList &CC1Args) const override;
852  void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
853                       llvm::opt::ArgStringList &CC1Args) const override;
854  void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
855                           llvm::opt::ArgStringList &CmdArgs) const override;
856};
857
858} // end namespace toolchains
859} // end namespace driver
860} // end namespace clang
861
862#endif
863