]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Driver/ToolChains.h
Merge ^/head r283596 through r283770.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Driver / ToolChains.h
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
24 namespace clang {
25 namespace driver {
26 namespace 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.
31 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
32 protected:
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
152 public:
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
165 protected:
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
181 private:
182   mutable std::unique_ptr<tools::gcc::Preprocess> Preprocess;
183   mutable std::unique_ptr<tools::gcc::Compile> Compile;
184 };
185
186 class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
187 protected:
188   Tool *buildAssembler() const override;
189   Tool *buildLinker() const override;
190   Tool *getTool(Action::ActionClass AC) const override;
191 private:
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
196 public:
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   /// Add any profiling runtime libraries that are needed. This is essentially a
243   /// MachO specific version of addProfileRT in Tools.cpp.
244   virtual void addProfileRTLibs(const llvm::opt::ArgList &Args,
245                                 llvm::opt::ArgStringList &CmdArgs) const {
246     // There aren't any profiling libs for embedded targets currently.
247   }
248
249   /// }
250   /// @name ToolChain Implementation
251   /// {
252
253   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
254                                           types::ID InputType) const override;
255
256   types::ID LookupTypeForExtension(const char *Ext) const override;
257
258   bool HasNativeLLVMSupport() const override;
259
260   llvm::opt::DerivedArgList *
261   TranslateArgs(const llvm::opt::DerivedArgList &Args,
262                 const char *BoundArch) const override;
263
264   bool IsBlocksDefault() const override {
265     // Always allow blocks on Apple; users interested in versioning are
266     // expected to use /usr/include/Block.h.
267     return true;
268   }
269   bool IsIntegratedAssemblerDefault() const override {
270     // Default integrated assembler to on for Apple's MachO targets.
271     return true;
272   }
273
274   bool IsMathErrnoDefault() const override {
275     return false;
276   }
277
278   bool IsEncodeExtendedBlockSignatureDefault() const override {
279     return true;
280   }
281
282   bool IsObjCNonFragileABIDefault() const override {
283     // Non-fragile ABI is default for everything but i386.
284     return getTriple().getArch() != llvm::Triple::x86;
285   }
286
287   bool UseObjCMixedDispatch() const override {
288     return true;
289   }
290
291   bool IsUnwindTablesDefault() const override;
292
293   RuntimeLibType GetDefaultRuntimeLibType() const override {
294     return ToolChain::RLT_CompilerRT;
295   }
296
297   bool isPICDefault() const override;
298   bool isPIEDefault() const override;
299   bool isPICDefaultForced() const override;
300
301   bool SupportsProfiling() const override;
302
303   bool SupportsObjCGC() const override {
304     return false;
305   }
306
307   bool UseDwarfDebugFlags() const override;
308
309   bool UseSjLjExceptions() const override {
310     return false;
311   }
312
313   /// }
314 };
315
316   /// Darwin - The base Darwin tool chain.
317 class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
318 public:
319   /// The host version.
320   unsigned DarwinVersion[3];
321
322   /// Whether the information on the target has been initialized.
323   //
324   // FIXME: This should be eliminated. What we want to do is make this part of
325   // the "default target for arguments" selection process, once we get out of
326   // the argument translation business.
327   mutable bool TargetInitialized;
328
329   enum DarwinPlatformKind {
330     MacOS,
331     IPhoneOS,
332     IPhoneOSSimulator
333   };
334
335   mutable DarwinPlatformKind TargetPlatform;
336
337   /// The OS version we are targeting.
338   mutable VersionTuple TargetVersion;
339
340 private:
341   /// The default macosx-version-min of this tool chain; empty until
342   /// initialized.
343   std::string MacosxVersionMin;
344
345   /// The default ios-version-min of this tool chain; empty until
346   /// initialized.
347   std::string iOSVersionMin;
348
349 private:
350   void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
351
352 public:
353   Darwin(const Driver &D, const llvm::Triple &Triple,
354          const llvm::opt::ArgList &Args);
355   ~Darwin() override;
356
357   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
358                                           types::ID InputType) const override;
359
360   /// @name Apple Specific Toolchain Implementation
361   /// {
362
363   void
364   addMinVersionArgs(const llvm::opt::ArgList &Args,
365                     llvm::opt::ArgStringList &CmdArgs) const override;
366
367   void
368   addStartObjectFileArgs(const llvm::opt::ArgList &Args,
369                          llvm::opt::ArgStringList &CmdArgs) const override;
370
371   bool isKernelStatic() const override {
372     return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0);
373   }
374
375   void addProfileRTLibs(const llvm::opt::ArgList &Args,
376                         llvm::opt::ArgStringList &CmdArgs) const override;
377
378 protected:
379   /// }
380   /// @name Darwin specific Toolchain functions
381   /// {
382
383   // FIXME: Eliminate these ...Target functions and derive separate tool chains
384   // for these targets and put version in constructor.
385   void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
386                  unsigned Micro) const {
387     // FIXME: For now, allow reinitialization as long as values don't
388     // change. This will go away when we move away from argument translation.
389     if (TargetInitialized && TargetPlatform == Platform &&
390         TargetVersion == VersionTuple(Major, Minor, Micro))
391       return;
392
393     assert(!TargetInitialized && "Target already initialized!");
394     TargetInitialized = true;
395     TargetPlatform = Platform;
396     TargetVersion = VersionTuple(Major, Minor, Micro);
397   }
398
399   bool isTargetIPhoneOS() const {
400     assert(TargetInitialized && "Target not initialized!");
401     return TargetPlatform == IPhoneOS;
402   }
403
404   bool isTargetIOSSimulator() const {
405     assert(TargetInitialized && "Target not initialized!");
406     return TargetPlatform == IPhoneOSSimulator;
407   }
408
409   bool isTargetIOSBased() const {
410     assert(TargetInitialized && "Target not initialized!");
411     return isTargetIPhoneOS() || isTargetIOSSimulator();
412   }
413
414   bool isTargetMacOS() const {
415     return TargetPlatform == MacOS;
416   }
417
418   bool isTargetInitialized() const { return TargetInitialized; }
419
420   VersionTuple getTargetVersion() const {
421     assert(TargetInitialized && "Target not initialized!");
422     return TargetVersion;
423   }
424
425   bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
426     assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
427     return TargetVersion < VersionTuple(V0, V1, V2);
428   }
429
430   bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
431     assert(isTargetMacOS() && "Unexpected call for non OS X target!");
432     return TargetVersion < VersionTuple(V0, V1, V2);
433   }
434
435 public:
436   /// }
437   /// @name ToolChain Implementation
438   /// {
439
440   // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
441   // most development is done against SDKs, so compiling for a different
442   // architecture should not get any special treatment.
443   bool isCrossCompiling() const override { return false; }
444
445   llvm::opt::DerivedArgList *
446   TranslateArgs(const llvm::opt::DerivedArgList &Args,
447                 const char *BoundArch) const override;
448
449   ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
450   bool hasBlocksRuntime() const override;
451
452   bool UseObjCMixedDispatch() const override {
453     // This is only used with the non-fragile ABI and non-legacy dispatch.
454
455     // Mixed dispatch is used everywhere except OS X before 10.6.
456     return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
457   }
458
459   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
460     // Stack protectors default to on for user code on 10.5,
461     // and for everything in 10.6 and beyond
462     if (isTargetIOSBased())
463       return 1;
464     else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
465       return 1;
466     else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
467       return 1;
468
469     return 0;
470   }
471
472   bool SupportsObjCGC() const override;
473
474   void CheckObjCARC() const override;
475
476   bool UseSjLjExceptions() const override;
477 };
478
479 /// DarwinClang - The Darwin toolchain used by Clang.
480 class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
481 public:
482   DarwinClang(const Driver &D, const llvm::Triple &Triple,
483               const llvm::opt::ArgList &Args);
484
485   /// @name Apple ToolChain Implementation
486   /// {
487
488   void
489   AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
490                         llvm::opt::ArgStringList &CmdArgs) const override;
491
492   void
493   AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
494                       llvm::opt::ArgStringList &CmdArgs) const override;
495
496   void
497   AddCCKextLibArgs(const llvm::opt::ArgList &Args,
498                    llvm::opt::ArgStringList &CmdArgs) const override;
499
500   void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
501
502   void
503   AddLinkARCArgs(const llvm::opt::ArgList &Args,
504                  llvm::opt::ArgStringList &CmdArgs) const override;
505   /// }
506
507 private:
508   void AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
509                                llvm::opt::ArgStringList &CmdArgs,
510                                StringRef Sanitizer) const;
511 };
512
513 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
514   virtual void anchor();
515 public:
516   Generic_ELF(const Driver &D, const llvm::Triple &Triple,
517               const llvm::opt::ArgList &Args)
518       : Generic_GCC(D, Triple, Args) {}
519
520   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
521                              llvm::opt::ArgStringList &CC1Args) const override;
522 };
523
524 class LLVM_LIBRARY_VISIBILITY CloudABI : public Generic_ELF {
525 public:
526   CloudABI(const Driver &D, const llvm::Triple &Triple,
527            const llvm::opt::ArgList &Args);
528   bool HasNativeLLVMSupport() const override { return true; }
529
530   bool IsMathErrnoDefault() const override { return false; }
531   bool IsObjCNonFragileABIDefault() const override { return true; }
532
533   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args)
534       const override {
535     return ToolChain::CST_Libcxx;
536   }
537   void AddClangCXXStdlibIncludeArgs(
538       const llvm::opt::ArgList &DriverArgs,
539       llvm::opt::ArgStringList &CC1Args) const override;
540   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
541                            llvm::opt::ArgStringList &CmdArgs) const override;
542
543   bool isPIEDefault() const override { return false; }
544
545 protected:
546   Tool *buildLinker() const override;
547 };
548
549 class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
550 public:
551   Solaris(const Driver &D, const llvm::Triple &Triple,
552           const llvm::opt::ArgList &Args);
553
554   bool IsIntegratedAssemblerDefault() const override { return true; }
555 protected:
556   Tool *buildAssembler() const override;
557   Tool *buildLinker() const override;
558
559 };
560
561
562 class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
563 public:
564   OpenBSD(const Driver &D, const llvm::Triple &Triple,
565           const llvm::opt::ArgList &Args);
566
567   bool IsMathErrnoDefault() const override { return false; }
568   bool IsObjCNonFragileABIDefault() const override { return true; }
569   bool isPIEDefault() const override { return true; }
570
571   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
572     return 2;
573   }
574
575 protected:
576   Tool *buildAssembler() const override;
577   Tool *buildLinker() const override;
578 };
579
580 class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
581 public:
582   Bitrig(const Driver &D, const llvm::Triple &Triple,
583          const llvm::opt::ArgList &Args);
584
585   bool IsMathErrnoDefault() const override { return false; }
586   bool IsObjCNonFragileABIDefault() const override { return true; }
587
588   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
589   void
590   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
591                               llvm::opt::ArgStringList &CC1Args) const override;
592   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
593                            llvm::opt::ArgStringList &CmdArgs) const override;
594   unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
595      return 1;
596   }
597
598 protected:
599   Tool *buildAssembler() const override;
600   Tool *buildLinker() const override;
601 };
602
603 class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
604 public:
605   FreeBSD(const Driver &D, const llvm::Triple &Triple,
606           const llvm::opt::ArgList &Args);
607   bool HasNativeLLVMSupport() const override;
608
609   bool IsMathErrnoDefault() const override { return false; }
610   bool IsObjCNonFragileABIDefault() const override { return true; }
611
612   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
613   void
614   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
615                                llvm::opt::ArgStringList &CC1Args) const override;
616
617   bool UseSjLjExceptions() const override;
618   bool isPIEDefault() const override;
619 protected:
620   Tool *buildAssembler() const override;
621   Tool *buildLinker() const override;
622 };
623
624 class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
625 public:
626   NetBSD(const Driver &D, const llvm::Triple &Triple,
627          const llvm::opt::ArgList &Args);
628
629   bool IsMathErrnoDefault() const override { return false; }
630   bool IsObjCNonFragileABIDefault() const override { return true; }
631
632   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
633
634   void
635   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
636                               llvm::opt::ArgStringList &CC1Args) const override;
637   bool IsUnwindTablesDefault() const override {
638     return true;
639   }
640
641 protected:
642   Tool *buildAssembler() const override;
643   Tool *buildLinker() const override;
644 };
645
646 class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
647 public:
648   Minix(const Driver &D, const llvm::Triple &Triple,
649         const llvm::opt::ArgList &Args);
650
651 protected:
652   Tool *buildAssembler() const override;
653   Tool *buildLinker() const override;
654 };
655
656 class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
657 public:
658   DragonFly(const Driver &D, const llvm::Triple &Triple,
659             const llvm::opt::ArgList &Args);
660
661   bool IsMathErrnoDefault() const override { return false; }
662
663 protected:
664   Tool *buildAssembler() const override;
665   Tool *buildLinker() const override;
666 };
667
668 class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
669 public:
670   Linux(const Driver &D, const llvm::Triple &Triple,
671         const llvm::opt::ArgList &Args);
672
673   bool HasNativeLLVMSupport() const override;
674
675   void
676   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
677                             llvm::opt::ArgStringList &CC1Args) const override;
678   void
679   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
680                                llvm::opt::ArgStringList &CC1Args) const override;
681   bool isPIEDefault() const override;
682
683   std::string Linker;
684   std::vector<std::string> ExtraOpts;
685
686 protected:
687   Tool *buildAssembler() const override;
688   Tool *buildLinker() const override;
689
690 private:
691   static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
692                                        StringRef GCCTriple,
693                                        StringRef GCCMultiarchTriple,
694                                        StringRef TargetMultiarchTriple,
695                                        Twine IncludeSuffix,
696                                        const llvm::opt::ArgList &DriverArgs,
697                                        llvm::opt::ArgStringList &CC1Args);
698
699   std::string computeSysRoot() const;
700 };
701
702 class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
703 protected:
704   GCCVersion GCCLibAndIncVersion;
705   Tool *buildAssembler() const override;
706   Tool *buildLinker() const override;
707
708 public:
709   Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
710              const llvm::opt::ArgList &Args);
711   ~Hexagon_TC() override;
712
713   void
714   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
715                             llvm::opt::ArgStringList &CC1Args) const override;
716   void
717   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
718                               llvm::opt::ArgStringList &CC1Args) const override;
719   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
720
721   StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
722
723   static std::string GetGnuDir(const std::string &InstalledDir,
724                                const llvm::opt::ArgList &Args);
725
726   static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
727
728   static const char *GetSmallDataThreshold(const llvm::opt::ArgList &Args);
729
730   static bool UsesG0(const char* smallDataThreshold);
731 };
732
733 class LLVM_LIBRARY_VISIBILITY NaCl_TC : public Generic_ELF {
734 public:
735   NaCl_TC(const Driver &D, const llvm::Triple &Triple,
736           const llvm::opt::ArgList &Args);
737
738   void
739   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
740                             llvm::opt::ArgStringList &CC1Args) const override;
741   void
742   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
743                                llvm::opt::ArgStringList &CC1Args) const override;
744
745   CXXStdlibType
746   GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
747
748   void
749   AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
750                       llvm::opt::ArgStringList &CmdArgs) const override;
751
752   bool
753   IsIntegratedAssemblerDefault() const override { return false; }
754
755   // Get the path to the file containing NaCl's ARM macros. It lives in NaCl_TC
756   // because the AssembleARM tool needs a const char * that it can pass around
757   // and the toolchain outlives all the jobs.
758   const char *GetNaClArmMacrosPath() const { return NaClArmMacrosPath.c_str(); }
759
760   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
761                                           types::ID InputType) const override;
762   std::string Linker;
763
764 protected:
765   Tool *buildLinker() const override;
766   Tool *buildAssembler() const override;
767
768 private:
769   std::string NaClArmMacrosPath;
770 };
771
772 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
773 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
774 class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
775 public:
776   TCEToolChain(const Driver &D, const llvm::Triple &Triple,
777                const llvm::opt::ArgList &Args);
778   ~TCEToolChain() override;
779
780   bool IsMathErrnoDefault() const override;
781   bool isPICDefault() const override;
782   bool isPIEDefault() const override;
783   bool isPICDefaultForced() const override;
784 };
785
786 class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
787 public:
788   MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
789                 const llvm::opt::ArgList &Args);
790
791   bool IsIntegratedAssemblerDefault() const override;
792   bool IsUnwindTablesDefault() const override;
793   bool isPICDefault() const override;
794   bool isPIEDefault() const override;
795   bool isPICDefaultForced() const override;
796
797   void
798   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
799                             llvm::opt::ArgStringList &CC1Args) const override;
800   void
801   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
802                                llvm::opt::ArgStringList &CC1Args) const override;
803
804   bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
805   bool getWindowsSDKLibraryPath(std::string &path) const;
806   bool getVisualStudioInstallDir(std::string &path) const;
807   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
808                                      std::string &path) const;
809
810 protected:
811   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
812                                      llvm::opt::ArgStringList &CC1Args,
813                                      const std::string &folder,
814                                      const char *subfolder) const;
815
816   Tool *buildLinker() const override;
817   Tool *buildAssembler() const override;
818 };
819
820 class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
821 public:
822   CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
823                         const llvm::opt::ArgList &Args);
824
825   bool IsIntegratedAssemblerDefault() const override { return true; }
826   bool IsUnwindTablesDefault() const override;
827   bool isPICDefault() const override;
828   bool isPIEDefault() const override;
829   bool isPICDefaultForced() const override;
830
831   unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
832     return 0;
833   }
834
835   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
836                                  llvm::opt::ArgStringList &CC1Args)
837       const override;
838   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
839                                     llvm::opt::ArgStringList &CC1Args)
840       const override;
841   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
842                            llvm::opt::ArgStringList &CmdArgs) const override;
843
844 protected:
845   Tool *buildLinker() const override;
846   Tool *buildAssembler() const override;
847 };
848
849 class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
850 public:
851   XCore(const Driver &D, const llvm::Triple &Triple,
852           const llvm::opt::ArgList &Args);
853 protected:
854   Tool *buildAssembler() const override;
855   Tool *buildLinker() const override;
856 public:
857   bool isPICDefault() const override;
858   bool isPIEDefault() const override;
859   bool isPICDefaultForced() const override;
860   bool SupportsProfiling() const override;
861   bool hasBlocksRuntime() const override;
862   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
863                     llvm::opt::ArgStringList &CC1Args) const override;
864   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
865                              llvm::opt::ArgStringList &CC1Args) const override;
866   void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
867                        llvm::opt::ArgStringList &CC1Args) const override;
868   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
869                            llvm::opt::ArgStringList &CmdArgs) const override;
870 };
871
872 } // end namespace toolchains
873 } // end namespace driver
874 } // end namespace clang
875
876 #endif