clang 8.0.0

Gnu.h
Go to the documentation of this file.
1 //===--- Gnu.h - Gnu Tool and 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_GNU_H
11 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_GNU_H
12
13 #include "Cuda.h"
14 #include "clang/Driver/Tool.h"
15 #include "clang/Driver/ToolChain.h"
16 #include <set>
17
18 namespace clang {
19 namespace driver {
20
21 struct DetectedMultilibs {
22 /// The set of multilibs that the detected installation supports.
23 MultilibSet Multilibs;
24
25 /// The primary multilib appropriate for the given flags.
26 Multilib SelectedMultilib;
27
28 /// On Biarch systems, this corresponds to the default multilib when
29 /// targeting the non-default multilib. Otherwise, it is empty.
30 llvm::Optional<Multilib> BiarchSibling;
31 };
32
33 bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple,
34 StringRef Path, const llvm::opt::ArgList &Args,
35 DetectedMultilibs &Result);
36
37 namespace tools {
38
39 /// Base class for all GNU tools that provide the same behavior when
40 /// it comes to response files support
41 class LLVM_LIBRARY_VISIBILITY GnuTool : public Tool {
42 virtual void anchor();
43
44 public:
45 GnuTool(const char *Name, const char *ShortName, const ToolChain &TC)
46 : Tool(Name, ShortName, TC, RF_Full, llvm::sys::WEM_CurrentCodePage) {}
47 };
48
49 /// Directly call GNU Binutils' assembler and linker.
50 namespace gnutools {
51 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
52 public:
53 Assembler(const ToolChain &TC) : GnuTool("GNU::Assembler", "assembler", TC) {}
54
55 bool hasIntegratedCPP() const override { return false; }
56
57 void ConstructJob(Compilation &C, const JobAction &JA,
58 const InputInfo &Output, const InputInfoList &Inputs,
59 const llvm::opt::ArgList &TCArgs,
60 const char *LinkingOutput) const override;
61 };
62
63 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
64 public:
65 Linker(const ToolChain &TC) : GnuTool("GNU::Linker", "linker", TC) {}
66
67 bool hasIntegratedCPP() const override { return false; }
68 bool isLinkJob() const override { return true; }
69
70 void ConstructJob(Compilation &C, const JobAction &JA,
71 const InputInfo &Output, const InputInfoList &Inputs,
72 const llvm::opt::ArgList &TCArgs,
73 const char *LinkingOutput) const override;
74 };
75 } // end namespace gnutools
76
77 /// gcc - Generic GCC tool implementations.
78 namespace gcc {
79 class LLVM_LIBRARY_VISIBILITY Common : public GnuTool {
80 public:
81 Common(const char *Name, const char *ShortName, const ToolChain &TC)
82 : GnuTool(Name, ShortName, TC) {}
83
84 // A gcc tool has an "integrated" assembler that it will call to produce an
85 // object. Let it use that assembler so that we don't have to deal with
86 // assembly syntax incompatibilities.
87 bool hasIntegratedAssembler() const override { return true; }
88 void ConstructJob(Compilation &C, const JobAction &JA,
89 const InputInfo &Output, const InputInfoList &Inputs,
90 const llvm::opt::ArgList &TCArgs,
91 const char *LinkingOutput) const override;
92
93 /// RenderExtraToolArgs - Render any arguments necessary to force
94 /// the particular tool mode.
95 virtual void RenderExtraToolArgs(const JobAction &JA,
96 llvm::opt::ArgStringList &CmdArgs) const = 0;
97 };
98
99 class LLVM_LIBRARY_VISIBILITY Preprocessor : public Common {
100 public:
101 Preprocessor(const ToolChain &TC)
102 : Common("gcc::Preprocessor", "gcc preprocessor", TC) {}
103
104 bool hasGoodDiagnostics() const override { return true; }
105 bool hasIntegratedCPP() const override { return false; }
106
107 void RenderExtraToolArgs(const JobAction &JA,
108 llvm::opt::ArgStringList &CmdArgs) const override;
109 };
110
111 class LLVM_LIBRARY_VISIBILITY Compiler : public Common {
112 public:
113 Compiler(const ToolChain &TC) : Common("gcc::Compiler", "gcc frontend", TC) {}
114
115 bool hasGoodDiagnostics() const override { return true; }
116 bool hasIntegratedCPP() const override { return true; }
117
118 void RenderExtraToolArgs(const JobAction &JA,
119 llvm::opt::ArgStringList &CmdArgs) const override;
120 };
121
122 class LLVM_LIBRARY_VISIBILITY Linker : public Common {
123 public:
124 Linker(const ToolChain &TC) : Common("gcc::Linker", "linker (via gcc)", TC) {}
125
126 bool hasIntegratedCPP() const override { return false; }
127 bool isLinkJob() const override { return true; }
128
129 void RenderExtraToolArgs(const JobAction &JA,
130 llvm::opt::ArgStringList &CmdArgs) const override;
131 };
132 } // end namespace gcc
133 } // end namespace tools
134
135 namespace toolchains {
136
137 /// Generic_GCC - A tool chain using the 'gcc' command to perform
138 /// all subcommands; this relies on gcc translating the majority of
139 /// command line options.
140 class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
141 public:
142 /// Struct to store and manipulate GCC versions.
143 ///
144 /// We rely on assumptions about the form and structure of GCC version
145 /// numbers: they consist of at most three '.'-separated components, and each
146 /// component is a non-negative integer except for the last component. For
147 /// the last component we are very flexible in order to tolerate release
148 /// candidates or 'x' wildcards.
149 ///
150 /// Note that the ordering established among GCCVersions is based on the
151 /// preferred version string to use. For example we prefer versions without
152 /// a hard-coded patch number to those with a hard coded patch number.
153 ///
154 /// Currently this doesn't provide any logic for textual suffixes to patches
155 /// in the way that (for example) Debian's version format does. If that ever
156 /// becomes necessary, it can be added.
157 struct GCCVersion {
158 /// The unparsed text of the version.
159 std::string Text;
160
161 /// The parsed major, minor, and patch numbers.
162 int Major, Minor, Patch;
163
164 /// The text of the parsed major, and major+minor versions.
165 std::string MajorStr, MinorStr;
166
167 /// Any textual suffix on the patch number.
168 std::string PatchSuffix;
169
170 static GCCVersion Parse(StringRef VersionText);
171 bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch,
172 StringRef RHSPatchSuffix = StringRef()) const;
173 bool operator<(const GCCVersion &RHS) const {
174 return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix);
175 }
176 bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
177 bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
178 bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
179 };
180
181 /// This is a class to find a viable GCC installation for Clang to
182 /// use.
183 ///
184 /// This class tries to find a GCC installation on the system, and report
185 /// information about it. It starts from the host information provided to the
186 /// Driver, and has logic for fuzzing that where appropriate.
187 class GCCInstallationDetector {
188 bool IsValid;
189 llvm::Triple GCCTriple;
190 const Driver &D;
191
192 // FIXME: These might be better as path objects.
193 std::string GCCInstallPath;
194 std::string GCCParentLibPath;
195
196 /// The primary multilib appropriate for the given flags.
197 Multilib SelectedMultilib;
198 /// On Biarch systems, this corresponds to the default multilib when
199 /// targeting the non-default multilib. Otherwise, it is empty.
200 llvm::Optional<Multilib> BiarchSibling;
201
202 GCCVersion Version;
203
204 // We retain the list of install paths that were considered and rejected in
205 // order to print out detailed information in verbose mode.
206 std::set<std::string> CandidateGCCInstallPaths;
207
208 /// The set of multilibs that the detected installation supports.
209 MultilibSet Multilibs;
210
211 public:
212 explicit GCCInstallationDetector(const Driver &D) : IsValid(false), D(D) {}
213 void init(const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args,
214 ArrayRef<std::string> ExtraTripleAliases = None);
215
216 /// Check whether we detected a valid GCC install.
217 bool isValid() const { return IsValid; }
218
219 /// Get the GCC triple for the detected install.
220 const llvm::Triple &getTriple() const { return GCCTriple; }
221
222 /// Get the detected GCC installation path.
223 StringRef getInstallPath() const { return GCCInstallPath; }
224
225 /// Get the detected GCC parent lib path.
226 StringRef getParentLibPath() const { return GCCParentLibPath; }
227
228 /// Get the detected Multilib
229 const Multilib &getMultilib() const { return SelectedMultilib; }
230
231 /// Get the whole MultilibSet
232 const MultilibSet &getMultilibs() const { return Multilibs; }
233
234 /// Get the biarch sibling multilib (if it exists).
235 /// \return true iff such a sibling exists
236 bool getBiarchSibling(Multilib &M) const;
237
238 /// Get the detected GCC version string.
239 const GCCVersion &getVersion() const { return Version; }
240
241 /// Print information about the detected GCC installation.
242 void print(raw_ostream &OS) const;
243
244 private:
245 static void
246 CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
247 const llvm::Triple &BiarchTriple,
248 SmallVectorImpl<StringRef> &LibDirs,
249 SmallVectorImpl<StringRef> &TripleAliases,
250 SmallVectorImpl<StringRef> &BiarchLibDirs,
251 SmallVectorImpl<StringRef> &BiarchTripleAliases);
252
253 void AddDefaultGCCPrefixes(const llvm::Triple &TargetTriple,
254 SmallVectorImpl<std::string> &Prefixes,
255 StringRef SysRoot);
256
257 bool ScanGCCForMultilibs(const llvm::Triple &TargetTriple,
258 const llvm::opt::ArgList &Args,
259 StringRef Path,
260 bool NeedsBiarchSuffix = false);
261
262 void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch,
263 const llvm::opt::ArgList &Args,
264 const std::string &LibDir,
265 StringRef CandidateTriple,
266 bool NeedsBiarchSuffix = false);
267
268 bool ScanGentooConfigs(const llvm::Triple &TargetTriple,
269 const llvm::opt::ArgList &Args,
270 const SmallVectorImpl<StringRef> &CandidateTriples,
271 const SmallVectorImpl<StringRef> &BiarchTriples);
272
273 bool ScanGentooGccConfig(const llvm::Triple &TargetTriple,
274 const llvm::opt::ArgList &Args,
275 StringRef CandidateTriple,
276 bool NeedsBiarchSuffix = false);
277 };
278
279 protected:
280 GCCInstallationDetector GCCInstallation;
281 CudaInstallationDetector CudaInstallation;
282
283 public:
284 Generic_GCC(const Driver &D, const llvm::Triple &Triple,
285 const llvm::opt::ArgList &Args);
286 ~Generic_GCC() override;
287
288 void printVerboseInfo(raw_ostream &OS) const override;
289
290 bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
291 bool isPICDefault() const override;
292 bool isPIEDefault() const override;
293 bool isPICDefaultForced() const override;
294 bool IsIntegratedAssemblerDefault() const override;
295 llvm::opt::DerivedArgList *
296 TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
297 Action::OffloadKind DeviceOffloadKind) const override;
298
299 protected:
300 Tool *getTool(Action::ActionClass AC) const override;
301 Tool *buildAssembler() const override;
302 Tool *buildLinker() const override;
303
304 /// \name ToolChain Implementation Helper Functions
305 /// @{
306
307 /// Check whether the target triple's architecture is 64-bits.
308 bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
309
310 /// Check whether the target triple's architecture is 32-bits.
311 bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
312
313 // FIXME: This should be final, but the CrossWindows toolchain does weird
314 // things that can't be easily generalized.
315 void AddClangCXXStdlibIncludeArgs(
316 const llvm::opt::ArgList &DriverArgs,
317 llvm::opt::ArgStringList &CC1Args) const override;
318
319 virtual void
320 addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
321 llvm::opt::ArgStringList &CC1Args) const;
322 virtual void
323 addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
324 llvm::opt::ArgStringList &CC1Args) const;
325
326 bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix, StringRef GCCTriple,
327 StringRef GCCMultiarchTriple,
328 StringRef TargetMultiarchTriple,
329 Twine IncludeSuffix,
330 const llvm::opt::ArgList &DriverArgs,
331 llvm::opt::ArgStringList &CC1Args) const;
332
333 /// @}
334
335 private:
336 mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocess;
337 mutable std::unique_ptr<tools::gcc::Compiler> Compile;
338 };
339
340 class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
341 virtual void anchor();
342
343 public:
344 Generic_ELF(const Driver &D, const llvm::Triple &Triple,
345 const llvm::opt::ArgList &Args)
346 : Generic_GCC(D, Triple, Args) {}
347
348 void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
349 llvm::opt::ArgStringList &CC1Args,
350 Action::OffloadKind DeviceOffloadKind) const override;
351 };
352
353 } // end namespace toolchains
354 } // end namespace driver
355 } // end namespace clang
356
357 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_GNU_H
Cuda.h
clang::driver::toolchains::Generic_GCC
Generic_GCC - A tool chain using the &#39;gcc&#39; command to perform all subcommands; this relies on gcc tra...
Definition: Gnu.h:140
llvm
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
Base
Tool.h
clang::driver::DetectedMultilibs::BiarchSibling
llvm::Optional< Multilib > BiarchSibling
On Biarch systems, this corresponds to the default multilib when targeting the non-default multilib...
Definition: Gnu.h:30
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getTriple
const llvm::Triple & getTriple() const
Get the GCC triple for the detected install.
Definition: Gnu.h:220
clang::driver::tools::gnutools::Linker::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Gnu.h:67
clang::driver::toolchains::Generic_GCC::GCCVersion
Struct to store and manipulate GCC versions.
Definition: Gnu.h:157
clang::driver::toolchains::Generic_GCC::GCCVersion::operator<=
bool operator<=(const GCCVersion &RHS) const
Definition: Gnu.h:177
clang::driver::toolchains::Generic_GCC::GCCVersion::PatchSuffix
std::string PatchSuffix
Any textual suffix on the patch number.
Definition: Gnu.h:168
clang::driver::CudaInstallationDetector
A class to find a viable CUDA installation.
Definition: Cuda.h:29
llvm::Optional
Definition: LLVM.h:38
clang::driver::toolchains::Generic_GCC::GCCInstallation
GCCInstallationDetector GCCInstallation
Definition: Gnu.h:280
clang::driver::JobAction
Definition: Action.h:374
clang::driver::tools::gcc::Preprocessor::hasGoodDiagnostics
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Gnu.h:104
clang::driver::tools::gcc::Compiler::Compiler
Compiler(const ToolChain &TC)
Definition: Gnu.h:113
llvm::SmallVectorImpl
Definition: LLVM.h:37
clang::driver::Action::ActionClass
ActionClass
Definition: Action.h:56
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
clang::driver::tools::GnuTool::GnuTool
GnuTool(const char *Name, const char *ShortName, const ToolChain &TC)
Definition: Gnu.h:45
clang::driver::MultilibSet
Definition: Multilib.h:110
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:58
clang::driver::tools::gcc::Common
Definition: Gnu.h:79
llvm::ArrayRef
Definition: LLVM.h:32
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getVersion
const GCCVersion & getVersion() const
Get the detected GCC version string.
Definition: Gnu.h:239
clang::driver::toolchains::Generic_GCC::CudaInstallation
CudaInstallationDetector CudaInstallation
Definition: Gnu.h:281
clang::driver::tools::gcc::Common::hasIntegratedAssembler
bool hasIntegratedAssembler() const override
Definition: Gnu.h:87
clang::driver::tools::gcc::Preprocessor
Definition: Gnu.h:99
clang::driver::toolchains::Generic_ELF
Definition: Gnu.h:340
clang::driver::tools::gcc::Linker
Definition: Gnu.h:122
clang::driver::tools::gnutools::Linker::Linker
Linker(const ToolChain &TC)
Definition: Gnu.h:65
clang::driver::toolchains::Generic_GCC::GCCVersion::operator>
bool operator>(const GCCVersion &RHS) const
Definition: Gnu.h:176
clang::driver::toolchains::Generic_GCC::GCCVersion::Minor
int Minor
Definition: Gnu.h:162
clang::driver::tools::gcc::Preprocessor::Preprocessor
Preprocessor(const ToolChain &TC)
Definition: Gnu.h:101
clang::driver::toolchains::Generic_GCC::GCCVersion::operator>=
bool operator>=(const GCCVersion &RHS) const
Definition: Gnu.h:178
clang::driver::Multilib
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag...
Definition: Multilib.h:29
clang::driver::tools::gnutools::Assembler::Assembler
Assembler(const ToolChain &TC)
Definition: Gnu.h:53
clang::driver::tools::gcc::Common::Common
Common(const char *Name, const char *ShortName, const ToolChain &TC)
Definition: Gnu.h:81
clang::driver::tools::gcc::Linker::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Gnu.h:126
false
#define false
Definition: stdbool.h:33
clang::driver::toolchains::Generic_GCC::isTarget32Bit
bool isTarget32Bit() const
Check whether the target triple&#39;s architecture is 32-bits.
Definition: Gnu.h:311
clang::driver::tools::GnuTool
Base class for all GNU tools that provide the same behavior when it comes to response files support...
Definition: Gnu.h:41
clang::driver::DetectedMultilibs
Definition: Gnu.h:21
clang::driver::toolchains::Generic_GCC::GCCVersion::Patch
int Patch
Definition: Gnu.h:162
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector
This is a class to find a viable GCC installation for Clang to use.
Definition: Gnu.h:187
ToolChain.h
llvm::SmallVector
Definition: LLVM.h:36
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getParentLibPath
StringRef getParentLibPath() const
Get the detected GCC parent lib path.
Definition: Gnu.h:226
clang::driver::toolchains::Generic_GCC::GCCVersion::operator<
bool operator<(const GCCVersion &RHS) const
Definition: Gnu.h:173
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:83
clang::driver::tools::gcc::Preprocessor::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Gnu.h:105
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::driver::tools::gcc::Compiler::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Gnu.h:116
clang::driver::tools::gnutools::Linker::isLinkJob
bool isLinkJob() const override
Definition: Gnu.h:68
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
clang::driver::tools::gcc::Compiler
Definition: Gnu.h:111
clang::driver::phases::Compile
Definition: Phases.h:21
clang::driver::toolchains::Generic_GCC::GCCVersion::Text
std::string Text
The unparsed text of the version.
Definition: Gnu.h:159
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:46
clang::driver::findMIPSMultilibs
bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const llvm::opt::ArgList &Args, DetectedMultilibs &Result)
clang::driver::tools::gnutools::Assembler::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: Gnu.h:55
clang::driver::tools::gnutools::Linker
Definition: Gnu.h:63
clang::driver::toolchains::Generic_GCC::GCCVersion::MinorStr
std::string MinorStr
Definition: Gnu.h:165
clang::driver::toolchains::Generic_ELF::Generic_ELF
Generic_ELF(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: Gnu.h:344
clang::driver::phases::Preprocess
Definition: Phases.h:19
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::GCCInstallationDetector
GCCInstallationDetector(const Driver &D)
Definition: Gnu.h:212
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getMultilibs
const MultilibSet & getMultilibs() const
Get the whole MultilibSet.
Definition: Gnu.h:232
clang::driver::tools::gcc::Linker::Linker
Linker(const ToolChain &TC)
Definition: Gnu.h:124
clang::driver::DetectedMultilibs::Multilibs
MultilibSet Multilibs
The set of multilibs that the detected installation supports.
Definition: Gnu.h:23
clang::driver::toolchains::Generic_GCC::isTarget64Bit
bool isTarget64Bit() const
Check whether the target triple&#39;s architecture is 64-bits.
Definition: Gnu.h:308
clang::driver::toolchains::Generic_GCC::GCCVersion::Major
int Major
The parsed major, minor, and patch numbers.
Definition: Gnu.h:162
clang::driver::tools::gcc::Linker::isLinkJob
bool isLinkJob() const override
Definition: Gnu.h:127
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getInstallPath
StringRef getInstallPath() const
Get the detected GCC installation path.
Definition: Gnu.h:223
clang::driver::tools::gcc::Compiler::hasGoodDiagnostics
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Gnu.h:115
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getMultilib
const Multilib & getMultilib() const
Get the detected Multilib.
Definition: Gnu.h:229
clang::driver::tools::gnutools::Assembler
Definition: Gnu.h:51
clang::driver::DetectedMultilibs::SelectedMultilib
Multilib SelectedMultilib
The primary multilib appropriate for the given flags.
Definition: Gnu.h:26
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:89
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::isValid
bool isValid() const
Check whether we detected a valid GCC install.
Definition: Gnu.h:217