1 //===--- ToolChain.h - Collections of tools for one platform ----*- 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 CLANG_DRIVER_TOOLCHAIN_H_
11 #define CLANG_DRIVER_TOOLCHAIN_H_
13 #include "clang/Driver/Action.h"
14 #include "clang/Driver/Multilib.h"
15 #include "clang/Driver/Types.h"
16 #include "clang/Driver/Util.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Path.h"
41 /// ToolChain - Access to tools for a single platform.
44 typedef SmallVector<std::string, 4> path_list;
58 const llvm::Triple Triple;
59 const llvm::opt::ArgList &Args;
61 /// The list of toolchain specific path prefixes to search for
65 /// The list of toolchain specific path prefixes to search for
67 path_list ProgramPaths;
69 mutable std::unique_ptr<Tool> Clang;
70 mutable std::unique_ptr<Tool> Assemble;
71 mutable std::unique_ptr<Tool> Link;
72 Tool *getClang() const;
73 Tool *getAssemble() const;
74 Tool *getLink() const;
75 Tool *getClangAs() const;
77 mutable std::unique_ptr<SanitizerArgs> SanitizerArguments;
80 MultilibSet Multilibs;
82 ToolChain(const Driver &D, const llvm::Triple &T,
83 const llvm::opt::ArgList &Args);
85 virtual Tool *buildAssembler() const;
86 virtual Tool *buildLinker() const;
87 virtual Tool *getTool(Action::ActionClass AC) const;
89 /// \name Utilities for implementing subclasses.
91 static void addSystemInclude(const llvm::opt::ArgList &DriverArgs,
92 llvm::opt::ArgStringList &CC1Args,
94 static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs,
95 llvm::opt::ArgStringList &CC1Args,
98 addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs,
99 llvm::opt::ArgStringList &CC1Args,
101 static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs,
102 llvm::opt::ArgStringList &CC1Args,
103 ArrayRef<StringRef> Paths);
107 virtual ~ToolChain();
111 const Driver &getDriver() const;
112 const llvm::Triple &getTriple() const { return Triple; }
114 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
115 StringRef getArchName() const { return Triple.getArchName(); }
116 StringRef getPlatform() const { return Triple.getVendorName(); }
117 StringRef getOS() const { return Triple.getOSName(); }
119 /// \brief Provide the default architecture name (as expected by -arch) for
120 /// this toolchain. Note t
121 std::string getDefaultUniversalArchName() const;
123 std::string getTripleString() const {
124 return Triple.getTriple();
127 path_list &getFilePaths() { return FilePaths; }
128 const path_list &getFilePaths() const { return FilePaths; }
130 path_list &getProgramPaths() { return ProgramPaths; }
131 const path_list &getProgramPaths() const { return ProgramPaths; }
133 const MultilibSet &getMultilibs() const { return Multilibs; }
135 const SanitizerArgs& getSanitizerArgs() const;
139 /// TranslateArgs - Create a new derived argument list for any argument
140 /// translations this ToolChain may wish to perform, or 0 if no tool chain
141 /// specific translations are needed.
143 /// \param BoundArch - The bound architecture name, or 0.
144 virtual llvm::opt::DerivedArgList *
145 TranslateArgs(const llvm::opt::DerivedArgList &Args,
146 const char *BoundArch) const {
150 /// Choose a tool to use to handle the action \p JA.
151 Tool *SelectTool(const JobAction &JA) const;
155 std::string GetFilePath(const char *Name) const;
156 std::string GetProgramPath(const char *Name) const;
158 /// Returns the linker path, respecting the -fuse-ld= argument to determine
159 /// the linker suffix or name.
160 std::string GetLinkerPath() const;
162 /// \brief Dispatch to the specific toolchain for verbose printing.
164 /// This is used when handling the verbose option to print detailed,
165 /// toolchain-specific information useful for understanding the behavior of
166 /// the driver on a specific platform.
167 virtual void printVerboseInfo(raw_ostream &OS) const {};
169 // Platform defaults information
171 /// \brief Returns true if the toolchain is targeting a non-native
173 virtual bool isCrossCompiling() const;
175 /// HasNativeLTOLinker - Check whether the linker and related tools have
176 /// native LLVM support.
177 virtual bool HasNativeLLVMSupport() const;
179 /// LookupTypeForExtension - Return the default language type to use for the
181 virtual types::ID LookupTypeForExtension(const char *Ext) const;
183 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
184 virtual bool IsBlocksDefault() const { return false; }
186 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
188 virtual bool IsIntegratedAssemblerDefault() const { return false; }
190 /// \brief Check if the toolchain should use the integrated assembler.
191 bool useIntegratedAs() const;
193 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
194 virtual bool IsMathErrnoDefault() const { return true; }
196 /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
197 /// -fencode-extended-block-signature by default.
198 virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
200 /// IsObjCNonFragileABIDefault - Does this tool chain set
201 /// -fobjc-nonfragile-abi by default.
202 virtual bool IsObjCNonFragileABIDefault() const { return false; }
204 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
205 /// mixed dispatch method be used?
206 virtual bool UseObjCMixedDispatch() const { return false; }
208 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
209 /// this tool chain (0=off, 1=on, 2=strong, 3=all).
210 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
214 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
215 virtual RuntimeLibType GetDefaultRuntimeLibType() const {
216 return ToolChain::RLT_Libgcc;
219 /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
221 virtual bool IsUnwindTablesDefault() const;
223 /// \brief Test whether this toolchain defaults to PIC.
224 virtual bool isPICDefault() const = 0;
226 /// \brief Test whether this toolchain defaults to PIE.
227 virtual bool isPIEDefault() const = 0;
229 /// \brief Tests whether this toolchain forces its default for PIC, PIE or
230 /// non-PIC. If this returns true, any PIC related flags should be ignored
231 /// and instead the results of \c isPICDefault() and \c isPIEDefault() are
232 /// used exclusively.
233 virtual bool isPICDefaultForced() const = 0;
235 /// SupportsProfiling - Does this tool chain support -pg.
236 virtual bool SupportsProfiling() const { return true; }
238 /// Does this tool chain support Objective-C garbage collection.
239 virtual bool SupportsObjCGC() const { return true; }
241 /// Complain if this tool chain doesn't support Objective-C ARC.
242 virtual void CheckObjCARC() const {}
244 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
245 /// compile unit information.
246 virtual bool UseDwarfDebugFlags() const { return false; }
248 /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
249 virtual bool UseSjLjExceptions() const { return false; }
251 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
252 /// command line arguments into account.
254 ComputeLLVMTriple(const llvm::opt::ArgList &Args,
255 types::ID InputType = types::TY_INVALID) const;
257 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
258 /// target, which may take into account the command line arguments. For
259 /// example, on Darwin the -mmacosx-version-min= command line argument (which
260 /// sets the deployment target) determines the version in the triple passed to
262 virtual std::string ComputeEffectiveClangTriple(
263 const llvm::opt::ArgList &Args,
264 types::ID InputType = types::TY_INVALID) const;
266 /// getDefaultObjCRuntime - Return the default Objective-C runtime
267 /// for this platform.
269 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
270 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
272 /// hasBlocksRuntime - Given that the user is compiling with
273 /// -fblocks, does this tool chain guarantee the existence of a
276 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
277 virtual bool hasBlocksRuntime() const { return true; }
279 /// \brief Add the clang cc1 arguments for system include paths.
281 /// This routine is responsible for adding the necessary cc1 arguments to
282 /// include headers from standard system header directories.
284 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
285 llvm::opt::ArgStringList &CC1Args) const;
287 /// \brief Add options that need to be passed to cc1 for this target.
288 virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
289 llvm::opt::ArgStringList &CC1Args) const;
291 /// \brief Add warning options that need to be passed to cc1 for this target.
292 virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const;
294 // GetRuntimeLibType - Determine the runtime library type to use with the
295 // given compilation arguments.
296 virtual RuntimeLibType
297 GetRuntimeLibType(const llvm::opt::ArgList &Args) const;
299 // GetCXXStdlibType - Determine the C++ standard library type to use with the
300 // given compilation arguments.
301 virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
303 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
304 /// the include paths to use for the given C++ standard library type.
306 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
307 llvm::opt::ArgStringList &CC1Args) const;
309 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
310 /// for the given C++ standard library type.
311 virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
312 llvm::opt::ArgStringList &CmdArgs) const;
314 /// AddCCKextLibArgs - Add the system specific linker arguments to use
315 /// for kernel extensions (Darwin-specific).
316 virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
317 llvm::opt::ArgStringList &CmdArgs) const;
319 /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
320 /// global flags for unsafe floating point math, add it and return true.
322 /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
324 AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args,
325 llvm::opt::ArgStringList &CmdArgs) const;
328 } // end namespace driver
329 } // end namespace clang