]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Driver/ToolChain.h
Upgrade to OpenSSH 6.7p1, retaining libwrap support (which has been removed
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Driver / ToolChain.h
1 //===--- ToolChain.h - Collections of tools for one platform ----*- 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_DRIVER_TOOLCHAIN_H
11 #define LLVM_CLANG_DRIVER_TOOLCHAIN_H
12
13 #include "clang/Basic/Sanitizers.h"
14 #include "clang/Driver/Action.h"
15 #include "clang/Driver/Multilib.h"
16 #include "clang/Driver/Types.h"
17 #include "clang/Driver/Util.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Path.h"
21 #include <memory>
22 #include <string>
23
24 namespace llvm {
25 namespace opt {
26   class ArgList;
27   class DerivedArgList;
28   class InputArgList;
29 }
30 }
31
32 namespace clang {
33   class ObjCRuntime;
34
35 namespace driver {
36   class Compilation;
37   class Driver;
38   class JobAction;
39   class SanitizerArgs;
40   class Tool;
41
42 /// ToolChain - Access to tools for a single platform.
43 class ToolChain {
44 public:
45   typedef SmallVector<std::string, 16> path_list;
46
47   enum CXXStdlibType {
48     CST_Libcxx,
49     CST_Libstdcxx
50   };
51
52   enum RuntimeLibType {
53     RLT_CompilerRT,
54     RLT_Libgcc
55   };
56
57   enum RTTIMode {
58     RM_EnabledExplicitly,
59     RM_EnabledImplicitly,
60     RM_DisabledExplicitly,
61     RM_DisabledImplicitly
62   };
63
64 private:
65   const Driver &D;
66   const llvm::Triple Triple;
67   const llvm::opt::ArgList &Args;
68   // We need to initialize CachedRTTIArg before CachedRTTIMode
69   const llvm::opt::Arg *const CachedRTTIArg;
70   const RTTIMode CachedRTTIMode;
71
72   /// The list of toolchain specific path prefixes to search for
73   /// files.
74   path_list FilePaths;
75
76   /// The list of toolchain specific path prefixes to search for
77   /// programs.
78   path_list ProgramPaths;
79
80   mutable std::unique_ptr<Tool> Clang;
81   mutable std::unique_ptr<Tool> Assemble;
82   mutable std::unique_ptr<Tool> Link;
83   Tool *getClang() const;
84   Tool *getAssemble() const;
85   Tool *getLink() const;
86   Tool *getClangAs() const;
87
88   mutable std::unique_ptr<SanitizerArgs> SanitizerArguments;
89
90 protected:
91   MultilibSet Multilibs;
92
93   ToolChain(const Driver &D, const llvm::Triple &T,
94             const llvm::opt::ArgList &Args);
95
96   virtual Tool *buildAssembler() const;
97   virtual Tool *buildLinker() const;
98   virtual Tool *getTool(Action::ActionClass AC) const;
99
100   /// \name Utilities for implementing subclasses.
101   ///@{
102   static void addSystemInclude(const llvm::opt::ArgList &DriverArgs,
103                                llvm::opt::ArgStringList &CC1Args,
104                                const Twine &Path);
105   static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs,
106                                       llvm::opt::ArgStringList &CC1Args,
107                                       const Twine &Path);
108   static void
109       addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs,
110                                       llvm::opt::ArgStringList &CC1Args,
111                                       const Twine &Path);
112   static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs,
113                                 llvm::opt::ArgStringList &CC1Args,
114                                 ArrayRef<StringRef> Paths);
115   ///@}
116
117 public:
118   virtual ~ToolChain();
119
120   // Accessors
121
122   const Driver &getDriver() const;
123   const llvm::Triple &getTriple() const { return Triple; }
124
125   llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
126   StringRef getArchName() const { return Triple.getArchName(); }
127   StringRef getPlatform() const { return Triple.getVendorName(); }
128   StringRef getOS() const { return Triple.getOSName(); }
129
130   /// \brief Provide the default architecture name (as expected by -arch) for
131   /// this toolchain. Note t
132   StringRef getDefaultUniversalArchName() const;
133
134   std::string getTripleString() const {
135     return Triple.getTriple();
136   }
137
138   path_list &getFilePaths() { return FilePaths; }
139   const path_list &getFilePaths() const { return FilePaths; }
140
141   path_list &getProgramPaths() { return ProgramPaths; }
142   const path_list &getProgramPaths() const { return ProgramPaths; }
143
144   const MultilibSet &getMultilibs() const { return Multilibs; }
145
146   const SanitizerArgs& getSanitizerArgs() const;
147
148   // Returns the Arg * that explicitly turned on/off rtti, or nullptr.
149   const llvm::opt::Arg *getRTTIArg() const { return CachedRTTIArg; }
150
151   // Returns the RTTIMode for the toolchain with the current arguments.
152   RTTIMode getRTTIMode() const { return CachedRTTIMode; }
153
154   // Tool access.
155
156   /// TranslateArgs - Create a new derived argument list for any argument
157   /// translations this ToolChain may wish to perform, or 0 if no tool chain
158   /// specific translations are needed.
159   ///
160   /// \param BoundArch - The bound architecture name, or 0.
161   virtual llvm::opt::DerivedArgList *
162   TranslateArgs(const llvm::opt::DerivedArgList &Args,
163                 const char *BoundArch) const {
164     return nullptr;
165   }
166
167   /// Choose a tool to use to handle the action \p JA.
168   ///
169   /// This can be overridden when a particular ToolChain needs to use
170   /// a C compiler other than Clang.
171   virtual Tool *SelectTool(const JobAction &JA) const;
172
173   // Helper methods
174
175   std::string GetFilePath(const char *Name) const;
176   std::string GetProgramPath(const char *Name) const;
177
178   /// Returns the linker path, respecting the -fuse-ld= argument to determine
179   /// the linker suffix or name.
180   std::string GetLinkerPath() const;
181
182   /// \brief Dispatch to the specific toolchain for verbose printing.
183   ///
184   /// This is used when handling the verbose option to print detailed,
185   /// toolchain-specific information useful for understanding the behavior of
186   /// the driver on a specific platform.
187   virtual void printVerboseInfo(raw_ostream &OS) const {};
188
189   // Platform defaults information
190
191   /// \brief Returns true if the toolchain is targeting a non-native
192   /// architecture.
193   virtual bool isCrossCompiling() const;
194
195   /// HasNativeLTOLinker - Check whether the linker and related tools have
196   /// native LLVM support.
197   virtual bool HasNativeLLVMSupport() const;
198
199   /// LookupTypeForExtension - Return the default language type to use for the
200   /// given extension.
201   virtual types::ID LookupTypeForExtension(const char *Ext) const;
202
203   /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
204   virtual bool IsBlocksDefault() const { return false; }
205
206   /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
207   /// by default.
208   virtual bool IsIntegratedAssemblerDefault() const { return false; }
209
210   /// \brief Check if the toolchain should use the integrated assembler.
211   bool useIntegratedAs() const;
212
213   /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
214   virtual bool IsMathErrnoDefault() const { return true; }
215
216   /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
217   /// -fencode-extended-block-signature by default.
218   virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
219
220   /// IsObjCNonFragileABIDefault - Does this tool chain set
221   /// -fobjc-nonfragile-abi by default.
222   virtual bool IsObjCNonFragileABIDefault() const { return false; }
223
224   /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
225   /// mixed dispatch method be used?
226   virtual bool UseObjCMixedDispatch() const { return false; }
227
228   /// GetDefaultStackProtectorLevel - Get the default stack protector level for
229   /// this tool chain (0=off, 1=on, 2=strong, 3=all).
230   virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
231     return 0;
232   }
233
234   /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
235   virtual RuntimeLibType GetDefaultRuntimeLibType() const {
236     return ToolChain::RLT_Libgcc;
237   }
238
239   /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
240   /// by default.
241   virtual bool IsUnwindTablesDefault() const;
242
243   /// \brief Test whether this toolchain defaults to PIC.
244   virtual bool isPICDefault() const = 0;
245
246   /// \brief Test whether this toolchain defaults to PIE.
247   virtual bool isPIEDefault() const = 0;
248
249   /// \brief Tests whether this toolchain forces its default for PIC, PIE or
250   /// non-PIC.  If this returns true, any PIC related flags should be ignored
251   /// and instead the results of \c isPICDefault() and \c isPIEDefault() are
252   /// used exclusively.
253   virtual bool isPICDefaultForced() const = 0;
254
255   /// SupportsProfiling - Does this tool chain support -pg.
256   virtual bool SupportsProfiling() const { return true; }
257
258   /// Does this tool chain support Objective-C garbage collection.
259   virtual bool SupportsObjCGC() const { return true; }
260
261   /// Complain if this tool chain doesn't support Objective-C ARC.
262   virtual void CheckObjCARC() const {}
263
264   /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
265   /// compile unit information.
266   virtual bool UseDwarfDebugFlags() const { return false; }
267
268   /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
269   virtual bool UseSjLjExceptions() const { return false; }
270
271   /// getThreadModel() - Which thread model does this target use?
272   virtual std::string getThreadModel() const { return "posix"; }
273
274   /// isThreadModelSupported() - Does this target support a thread model?
275   virtual bool isThreadModelSupported(const StringRef Model) const;
276
277   /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
278   /// command line arguments into account.
279   virtual std::string
280   ComputeLLVMTriple(const llvm::opt::ArgList &Args,
281                     types::ID InputType = types::TY_INVALID) const;
282
283   /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
284   /// target, which may take into account the command line arguments. For
285   /// example, on Darwin the -mmacosx-version-min= command line argument (which
286   /// sets the deployment target) determines the version in the triple passed to
287   /// Clang.
288   virtual std::string ComputeEffectiveClangTriple(
289       const llvm::opt::ArgList &Args,
290       types::ID InputType = types::TY_INVALID) const;
291
292   /// getDefaultObjCRuntime - Return the default Objective-C runtime
293   /// for this platform.
294   ///
295   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
296   virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
297
298   /// hasBlocksRuntime - Given that the user is compiling with
299   /// -fblocks, does this tool chain guarantee the existence of a
300   /// blocks runtime?
301   ///
302   /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
303   virtual bool hasBlocksRuntime() const { return true; }
304
305   /// \brief Add the clang cc1 arguments for system include paths.
306   ///
307   /// This routine is responsible for adding the necessary cc1 arguments to
308   /// include headers from standard system header directories.
309   virtual void
310   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
311                             llvm::opt::ArgStringList &CC1Args) const;
312
313   /// \brief Add options that need to be passed to cc1 for this target.
314   virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
315                                      llvm::opt::ArgStringList &CC1Args) const;
316
317   /// \brief Add warning options that need to be passed to cc1 for this target.
318   virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const;
319
320   // GetRuntimeLibType - Determine the runtime library type to use with the
321   // given compilation arguments.
322   virtual RuntimeLibType
323   GetRuntimeLibType(const llvm::opt::ArgList &Args) const;
324
325   // GetCXXStdlibType - Determine the C++ standard library type to use with the
326   // given compilation arguments.
327   virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
328
329   /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
330   /// the include paths to use for the given C++ standard library type.
331   virtual void
332   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
333                                llvm::opt::ArgStringList &CC1Args) const;
334
335   /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
336   /// for the given C++ standard library type.
337   virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
338                                    llvm::opt::ArgStringList &CmdArgs) const;
339
340   /// AddCCKextLibArgs - Add the system specific linker arguments to use
341   /// for kernel extensions (Darwin-specific).
342   virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
343                                 llvm::opt::ArgStringList &CmdArgs) const;
344
345   /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
346   /// global flags for unsafe floating point math, add it and return true.
347   ///
348   /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
349   virtual bool
350   AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args,
351                                 llvm::opt::ArgStringList &CmdArgs) const;
352
353   /// \brief Return sanitizers which are available in this toolchain.
354   virtual SanitizerMask getSupportedSanitizers() const;
355 };
356
357 } // end namespace driver
358 } // end namespace clang
359
360 #endif