blob: 0db75f71f3e51a475c5d6fecea28bf6ef62ba42d [file] [log] [blame]
David L. Jonesf561aba2017-03-08 01:02:16 +00001//===--- Linux.h - Linux 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#include "Linux.h"
11#include "Arch/ARM.h"
12#include "Arch/Mips.h"
13#include "Arch/PPC.h"
Alex Bradbury71f45452018-01-11 13:36:56 +000014#include "Arch/RISCV.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000015#include "CommonArgs.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000016#include "clang/Config/config.h"
17#include "clang/Driver/Distro.h"
18#include "clang/Driver/Driver.h"
19#include "clang/Driver/Options.h"
20#include "clang/Driver/SanitizerArgs.h"
21#include "llvm/Option/ArgList.h"
22#include "llvm/ProfileData/InstrProf.h"
23#include "llvm/Support/Path.h"
Dan Albertf4832792018-04-17 20:42:07 +000024#include "llvm/Support/ScopedPrinter.h"
Jonas Devliegherefc514902018-10-10 13:27:25 +000025#include "llvm/Support/VirtualFileSystem.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000026#include <system_error>
27
28using namespace clang::driver;
29using namespace clang::driver::toolchains;
30using namespace clang;
31using namespace llvm::opt;
32
33using tools::addPathIfExists;
34
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000035/// Get our best guess at the multiarch triple for a target.
David L. Jonesf561aba2017-03-08 01:02:16 +000036///
37/// Debian-based systems are starting to use a multiarch setup where they use
38/// a target-triple directory in the library and header search paths.
39/// Unfortunately, this triple does not align with the vanilla target triple,
40/// so we provide a rough mapping here.
41static std::string getMultiarchTriple(const Driver &D,
42 const llvm::Triple &TargetTriple,
43 StringRef SysRoot) {
44 llvm::Triple::EnvironmentType TargetEnvironment =
45 TargetTriple.getEnvironment();
Dan Alberte00799e2018-04-04 21:28:34 +000046 bool IsAndroid = TargetTriple.isAndroid();
David L. Jonesf561aba2017-03-08 01:02:16 +000047
48 // For most architectures, just use whatever we have rather than trying to be
49 // clever.
50 switch (TargetTriple.getArch()) {
51 default:
52 break;
53
54 // We use the existence of '/lib/<triple>' as a directory to detect some
55 // common linux triples that don't quite match the Clang triple for both
56 // 32-bit and 64-bit targets. Multiarch fixes its install triples to these
57 // regardless of what the actual target triple is.
58 case llvm::Triple::arm:
59 case llvm::Triple::thumb:
Dan Alberte00799e2018-04-04 21:28:34 +000060 if (IsAndroid) {
61 return "arm-linux-androideabi";
62 } else if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
David L. Jonesf561aba2017-03-08 01:02:16 +000063 if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf"))
64 return "arm-linux-gnueabihf";
65 } else {
66 if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi"))
67 return "arm-linux-gnueabi";
68 }
69 break;
70 case llvm::Triple::armeb:
71 case llvm::Triple::thumbeb:
72 if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
73 if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf"))
74 return "armeb-linux-gnueabihf";
75 } else {
76 if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi"))
77 return "armeb-linux-gnueabi";
78 }
79 break;
80 case llvm::Triple::x86:
Dan Alberte00799e2018-04-04 21:28:34 +000081 if (IsAndroid)
82 return "i686-linux-android";
David L. Jonesf561aba2017-03-08 01:02:16 +000083 if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu"))
84 return "i386-linux-gnu";
85 break;
86 case llvm::Triple::x86_64:
Dan Alberte00799e2018-04-04 21:28:34 +000087 if (IsAndroid)
88 return "x86_64-linux-android";
David L. Jonesf561aba2017-03-08 01:02:16 +000089 // We don't want this for x32, otherwise it will match x86_64 libs
90 if (TargetEnvironment != llvm::Triple::GNUX32 &&
91 D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
92 return "x86_64-linux-gnu";
93 break;
94 case llvm::Triple::aarch64:
Dan Alberte00799e2018-04-04 21:28:34 +000095 if (IsAndroid)
96 return "aarch64-linux-android";
David L. Jonesf561aba2017-03-08 01:02:16 +000097 if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu"))
98 return "aarch64-linux-gnu";
99 break;
100 case llvm::Triple::aarch64_be:
101 if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
102 return "aarch64_be-linux-gnu";
103 break;
104 case llvm::Triple::mips:
105 if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu"))
106 return "mips-linux-gnu";
107 break;
108 case llvm::Triple::mipsel:
Dan Alberte00799e2018-04-04 21:28:34 +0000109 if (IsAndroid)
110 return "mipsel-linux-android";
David L. Jonesf561aba2017-03-08 01:02:16 +0000111 if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu"))
112 return "mipsel-linux-gnu";
113 break;
114 case llvm::Triple::mips64:
115 if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu"))
116 return "mips64-linux-gnu";
117 if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64"))
118 return "mips64-linux-gnuabi64";
119 break;
120 case llvm::Triple::mips64el:
Dan Alberte00799e2018-04-04 21:28:34 +0000121 if (IsAndroid)
122 return "mips64el-linux-android";
David L. Jonesf561aba2017-03-08 01:02:16 +0000123 if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu"))
124 return "mips64el-linux-gnu";
125 if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64"))
126 return "mips64el-linux-gnuabi64";
127 break;
128 case llvm::Triple::ppc:
129 if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe"))
130 return "powerpc-linux-gnuspe";
131 if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu"))
132 return "powerpc-linux-gnu";
133 break;
134 case llvm::Triple::ppc64:
135 if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu"))
136 return "powerpc64-linux-gnu";
137 break;
138 case llvm::Triple::ppc64le:
139 if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu"))
140 return "powerpc64le-linux-gnu";
141 break;
142 case llvm::Triple::sparc:
143 if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu"))
144 return "sparc-linux-gnu";
145 break;
146 case llvm::Triple::sparcv9:
147 if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu"))
148 return "sparc64-linux-gnu";
149 break;
150 case llvm::Triple::systemz:
151 if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu"))
152 return "s390x-linux-gnu";
153 break;
154 }
155 return TargetTriple.str();
156}
157
158static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
Alexander Richardson742553d2018-06-25 16:49:52 +0000159 if (Triple.isMIPS()) {
David L. Jonesf561aba2017-03-08 01:02:16 +0000160 if (Triple.isAndroid()) {
161 StringRef CPUName;
162 StringRef ABIName;
163 tools::mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName);
164 if (CPUName == "mips32r6")
165 return "libr6";
166 if (CPUName == "mips32r2")
167 return "libr2";
168 }
169 // lib32 directory has a special meaning on MIPS targets.
170 // It contains N32 ABI binaries. Use this folder if produce
171 // code for N32 ABI only.
172 if (tools::mips::hasMipsAbiArg(Args, "n32"))
173 return "lib32";
174 return Triple.isArch32Bit() ? "lib" : "lib64";
175 }
176
177 // It happens that only x86 and PPC use the 'lib32' variant of oslibdir, and
178 // using that variant while targeting other architectures causes problems
179 // because the libraries are laid out in shared system roots that can't cope
180 // with a 'lib32' library search path being considered. So we only enable
181 // them when we know we may need it.
182 //
183 // FIXME: This is a bit of a hack. We should really unify this code for
184 // reasoning about oslibdir spellings with the lib dir spellings in the
185 // GCCInstallationDetector, but that is a more significant refactoring.
186 if (Triple.getArch() == llvm::Triple::x86 ||
187 Triple.getArch() == llvm::Triple::ppc)
188 return "lib32";
189
190 if (Triple.getArch() == llvm::Triple::x86_64 &&
191 Triple.getEnvironment() == llvm::Triple::GNUX32)
192 return "libx32";
193
Alex Bradbury71f45452018-01-11 13:36:56 +0000194 if (Triple.getArch() == llvm::Triple::riscv32)
195 return "lib32";
196
David L. Jonesf561aba2017-03-08 01:02:16 +0000197 return Triple.isArch32Bit() ? "lib" : "lib64";
198}
199
200static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs,
201 const Multilib &Multilib,
202 StringRef InstallPath,
203 ToolChain::path_list &Paths) {
204 if (const auto &PathsCallback = Multilibs.filePathsCallback())
205 for (const auto &Path : PathsCallback(Multilib))
206 addPathIfExists(D, InstallPath + Path, Paths);
207}
208
209Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
210 : Generic_ELF(D, Triple, Args) {
211 GCCInstallation.init(Triple, Args);
212 Multilibs = GCCInstallation.getMultilibs();
Christian Bruel6ccc4a72018-09-06 14:03:44 +0000213 SelectedMultilib = GCCInstallation.getMultilib();
David L. Jonesf561aba2017-03-08 01:02:16 +0000214 llvm::Triple::ArchType Arch = Triple.getArch();
215 std::string SysRoot = computeSysRoot();
216
217 // Cross-compiling binutils and GCC installations (vanilla and openSUSE at
218 // least) put various tools in a triple-prefixed directory off of the parent
219 // of the GCC installation. We use the GCC triple here to ensure that we end
220 // up with tools that support the same amount of cross compiling as the
221 // detected GCC installation. For example, if we find a GCC installation
222 // targeting x86_64, but it is a bi-arch GCC installation, it can also be
223 // used to target i386.
224 // FIXME: This seems unlikely to be Linux-specific.
225 ToolChain::path_list &PPaths = getProgramPaths();
226 PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
227 GCCInstallation.getTriple().str() + "/bin")
228 .str());
229
230 Distro Distro(D.getVFS());
231
Martell Malone13c5d732017-11-19 00:08:12 +0000232 if (Distro.IsAlpineLinux()) {
233 ExtraOpts.push_back("-z");
234 ExtraOpts.push_back("now");
235 }
236
237 if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux()) {
David L. Jonesf561aba2017-03-08 01:02:16 +0000238 ExtraOpts.push_back("-z");
239 ExtraOpts.push_back("relro");
240 }
241
Tom Stellardc5fe10f2018-06-30 02:55:54 +0000242 if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
243 StringRef::npos)
244 // With devtoolset on RHEL, we want to add a bin directory that is relative
245 // to the detected gcc install, because if we are using devtoolset gcc then
246 // we want to use other tools from devtoolset (e.g. ld) instead of the
247 // standard system tools.
248 PPaths.push_back(Twine(GCCInstallation.getParentLibPath() +
249 "/../bin").str());
250
David L. Jonesf561aba2017-03-08 01:02:16 +0000251 if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)
252 ExtraOpts.push_back("-X");
253
254 const bool IsAndroid = Triple.isAndroid();
Alexander Richardson742553d2018-06-25 16:49:52 +0000255 const bool IsMips = Triple.isMIPS();
David L. Jonesf561aba2017-03-08 01:02:16 +0000256 const bool IsHexagon = Arch == llvm::Triple::hexagon;
Alex Bradbury71f45452018-01-11 13:36:56 +0000257 const bool IsRISCV =
258 Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64;
David L. Jonesf561aba2017-03-08 01:02:16 +0000259
260 if (IsMips && !SysRoot.empty())
261 ExtraOpts.push_back("--sysroot=" + SysRoot);
262
263 // Do not use 'gnu' hash style for Mips targets because .gnu.hash
264 // and the MIPS ABI require .dynsym to be sorted in different ways.
265 // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS
266 // ABI requires a mapping between the GOT and the symbol table.
267 // Android loader does not support .gnu.hash.
268 // Hexagon linker/loader does not support .gnu.hash
269 if (!IsMips && !IsAndroid && !IsHexagon) {
Martell Malone13c5d732017-11-19 00:08:12 +0000270 if (Distro.IsRedhat() || Distro.IsOpenSUSE() || Distro.IsAlpineLinux() ||
David L. Jonesf561aba2017-03-08 01:02:16 +0000271 (Distro.IsUbuntu() && Distro >= Distro::UbuntuMaverick))
272 ExtraOpts.push_back("--hash-style=gnu");
273
274 if (Distro.IsDebian() || Distro.IsOpenSUSE() || Distro == Distro::UbuntuLucid ||
275 Distro == Distro::UbuntuJaunty || Distro == Distro::UbuntuKarmic)
276 ExtraOpts.push_back("--hash-style=both");
277 }
278
279 if (Distro.IsRedhat() && Distro != Distro::RHEL5 && Distro != Distro::RHEL6)
280 ExtraOpts.push_back("--no-add-needed");
281
282#ifdef ENABLE_LINKER_BUILD_ID
283 ExtraOpts.push_back("--build-id");
284#endif
285
Evgeniy Stepanov117627c2017-10-25 20:39:22 +0000286 if (IsAndroid || Distro.IsOpenSUSE())
David L. Jonesf561aba2017-03-08 01:02:16 +0000287 ExtraOpts.push_back("--enable-new-dtags");
288
289 // The selection of paths to try here is designed to match the patterns which
290 // the GCC driver itself uses, as this is part of the GCC-compatible driver.
291 // This was determined by running GCC in a fake filesystem, creating all
292 // possible permutations of these directories, and seeing which ones it added
293 // to the link paths.
294 path_list &Paths = getFilePaths();
295
296 const std::string OSLibDir = getOSLibDir(Triple, Args);
297 const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
298
299 // Add the multilib suffixed paths where they are available.
300 if (GCCInstallation.isValid()) {
301 const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
302 const std::string &LibPath = GCCInstallation.getParentLibPath();
David L. Jonesf561aba2017-03-08 01:02:16 +0000303
304 // Add toolchain / multilib specific file paths.
Christian Bruel6ccc4a72018-09-06 14:03:44 +0000305 addMultilibsFilePaths(D, Multilibs, SelectedMultilib,
David L. Jonesf561aba2017-03-08 01:02:16 +0000306 GCCInstallation.getInstallPath(), Paths);
307
308 // Sourcery CodeBench MIPS toolchain holds some libraries under
309 // a biarch-like suffix of the GCC installation.
Christian Bruel6ccc4a72018-09-06 14:03:44 +0000310 addPathIfExists(D, GCCInstallation.getInstallPath() + SelectedMultilib.gccSuffix(),
David L. Jonesf561aba2017-03-08 01:02:16 +0000311 Paths);
312
313 // GCC cross compiling toolchains will install target libraries which ship
314 // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as
315 // any part of the GCC installation in
316 // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat
317 // debatable, but is the reality today. We need to search this tree even
318 // when we have a sysroot somewhere else. It is the responsibility of
319 // whomever is doing the cross build targeting a sysroot using a GCC
320 // installation that is *not* within the system root to ensure two things:
321 //
322 // 1) Any DSOs that are linked in from this tree or from the install path
323 // above must be present on the system root and found via an
324 // appropriate rpath.
325 // 2) There must not be libraries installed into
326 // <prefix>/<triple>/<libdir> unless they should be preferred over
327 // those within the system root.
328 //
329 // Note that this matches the GCC behavior. See the below comment for where
330 // Clang diverges from GCC's behavior.
331 addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" +
Christian Bruel6ccc4a72018-09-06 14:03:44 +0000332 OSLibDir + SelectedMultilib.osSuffix(),
David L. Jonesf561aba2017-03-08 01:02:16 +0000333 Paths);
334
335 // If the GCC installation we found is inside of the sysroot, we want to
336 // prefer libraries installed in the parent prefix of the GCC installation.
337 // It is important to *not* use these paths when the GCC installation is
338 // outside of the system root as that can pick up unintended libraries.
339 // This usually happens when there is an external cross compiler on the
340 // host system, and a more minimal sysroot available that is the target of
341 // the cross. Note that GCC does include some of these directories in some
342 // configurations but this seems somewhere between questionable and simply
343 // a bug.
344 if (StringRef(LibPath).startswith(SysRoot)) {
345 addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths);
346 addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths);
347 }
348 }
349
350 // Similar to the logic for GCC above, if we currently running Clang inside
351 // of the requested system root, add its parent library paths to
352 // those searched.
353 // FIXME: It's not clear whether we should use the driver's installed
354 // directory ('Dir' below) or the ResourceDir.
355 if (StringRef(D.Dir).startswith(SysRoot)) {
356 addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths);
357 addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
358 }
359
360 addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
361 addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);
Dan Albertf4832792018-04-17 20:42:07 +0000362
363 if (IsAndroid) {
364 // Android sysroots contain a library directory for each supported OS
365 // version as well as some unversioned libraries in the usual multiarch
366 // directory.
367 unsigned Major;
368 unsigned Minor;
369 unsigned Micro;
370 Triple.getEnvironmentVersion(Major, Minor, Micro);
371 addPathIfExists(D,
372 SysRoot + "/usr/lib/" + MultiarchTriple + "/" +
373 llvm::to_string(Major),
374 Paths);
375 }
376
David L. Jonesf561aba2017-03-08 01:02:16 +0000377 addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
Mandeep Singh Grange9ddc442018-07-30 19:44:13 +0000378 // 64-bit OpenEmbedded sysroots may not have a /usr/lib dir. So they cannot
379 // find /usr/lib64 as it is referenced as /usr/lib/../lib64. So we handle
380 // this here.
381 if (Triple.getVendor() == llvm::Triple::OpenEmbedded &&
382 Triple.isArch64Bit())
383 addPathIfExists(D, SysRoot + "/usr/" + OSLibDir, Paths);
384 else
385 addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths);
Alex Bradbury71f45452018-01-11 13:36:56 +0000386 if (IsRISCV) {
387 StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
388 addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths);
389 addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths);
390 }
David L. Jonesf561aba2017-03-08 01:02:16 +0000391
392 // Try walking via the GCC triple path in case of biarch or multiarch GCC
393 // installations with strange symlinks.
394 if (GCCInstallation.isValid()) {
395 addPathIfExists(D,
396 SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
397 "/../../" + OSLibDir,
398 Paths);
399
400 // Add the 'other' biarch variant path
401 Multilib BiarchSibling;
402 if (GCCInstallation.getBiarchSibling(BiarchSibling)) {
403 addPathIfExists(D, GCCInstallation.getInstallPath() +
404 BiarchSibling.gccSuffix(),
405 Paths);
406 }
407
408 // See comments above on the multilib variant for details of why this is
409 // included even from outside the sysroot.
410 const std::string &LibPath = GCCInstallation.getParentLibPath();
411 const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
412 const Multilib &Multilib = GCCInstallation.getMultilib();
413 addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" +
414 Multilib.osSuffix(),
415 Paths);
416
417 // See comments above on the multilib variant for details of why this is
418 // only included from within the sysroot.
419 if (StringRef(LibPath).startswith(SysRoot))
420 addPathIfExists(D, LibPath, Paths);
421 }
422
423 // Similar to the logic for GCC above, if we are currently running Clang
424 // inside of the requested system root, add its parent library path to those
425 // searched.
426 // FIXME: It's not clear whether we should use the driver's installed
427 // directory ('Dir' below) or the ResourceDir.
428 if (StringRef(D.Dir).startswith(SysRoot))
429 addPathIfExists(D, D.Dir + "/../lib", Paths);
430
431 addPathIfExists(D, SysRoot + "/lib", Paths);
432 addPathIfExists(D, SysRoot + "/usr/lib", Paths);
433}
434
David L. Jonesf561aba2017-03-08 01:02:16 +0000435bool Linux::HasNativeLLVMSupport() const { return true; }
436
437Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); }
438
439Tool *Linux::buildAssembler() const {
440 return new tools::gnutools::Assembler(*this);
441}
442
443std::string Linux::computeSysRoot() const {
444 if (!getDriver().SysRoot.empty())
445 return getDriver().SysRoot;
446
Dan Albert4d643062018-05-02 19:38:37 +0000447 if (getTriple().isAndroid()) {
448 // Android toolchains typically include a sysroot at ../sysroot relative to
449 // the clang binary.
450 const StringRef ClangDir = getDriver().getInstalledDir();
451 std::string AndroidSysRootPath = (ClangDir + "/../sysroot").str();
452 if (getVFS().exists(AndroidSysRootPath))
453 return AndroidSysRootPath;
454 }
455
Alexander Richardson742553d2018-06-25 16:49:52 +0000456 if (!GCCInstallation.isValid() || !getTriple().isMIPS())
David L. Jonesf561aba2017-03-08 01:02:16 +0000457 return std::string();
458
459 // Standalone MIPS toolchains use different names for sysroot folder
460 // and put it into different places. Here we try to check some known
461 // variants.
462
463 const StringRef InstallDir = GCCInstallation.getInstallPath();
464 const StringRef TripleStr = GCCInstallation.getTriple().str();
465 const Multilib &Multilib = GCCInstallation.getMultilib();
466
467 std::string Path =
468 (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix())
469 .str();
470
471 if (getVFS().exists(Path))
472 return Path;
473
474 Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str();
475
476 if (getVFS().exists(Path))
477 return Path;
478
479 return std::string();
480}
481
482std::string Linux::getDynamicLinker(const ArgList &Args) const {
483 const llvm::Triple::ArchType Arch = getArch();
484 const llvm::Triple &Triple = getTriple();
485
486 const Distro Distro(getDriver().getVFS());
487
488 if (Triple.isAndroid())
489 return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker";
490
491 if (Triple.isMusl()) {
492 std::string ArchName;
493 bool IsArm = false;
494
495 switch (Arch) {
496 case llvm::Triple::arm:
497 case llvm::Triple::thumb:
498 ArchName = "arm";
499 IsArm = true;
500 break;
501 case llvm::Triple::armeb:
502 case llvm::Triple::thumbeb:
503 ArchName = "armeb";
504 IsArm = true;
505 break;
506 default:
507 ArchName = Triple.getArchName().str();
508 }
509 if (IsArm &&
510 (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
511 tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard))
512 ArchName += "hf";
513
514 return "/lib/ld-musl-" + ArchName + ".so.1";
515 }
516
517 std::string LibDir;
518 std::string Loader;
519
520 switch (Arch) {
521 default:
522 llvm_unreachable("unsupported architecture");
523
524 case llvm::Triple::aarch64:
525 LibDir = "lib";
526 Loader = "ld-linux-aarch64.so.1";
527 break;
528 case llvm::Triple::aarch64_be:
529 LibDir = "lib";
530 Loader = "ld-linux-aarch64_be.so.1";
531 break;
532 case llvm::Triple::arm:
533 case llvm::Triple::thumb:
534 case llvm::Triple::armeb:
535 case llvm::Triple::thumbeb: {
536 const bool HF =
537 Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
538 tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard;
539
540 LibDir = "lib";
541 Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3";
542 break;
543 }
544 case llvm::Triple::mips:
545 case llvm::Triple::mipsel:
546 case llvm::Triple::mips64:
547 case llvm::Triple::mips64el: {
David L. Jonesf561aba2017-03-08 01:02:16 +0000548 bool IsNaN2008 = tools::mips::isNaN2008(Args, Triple);
549
550 LibDir = "lib" + tools::mips::getMipsABILibSuffix(Args, Triple);
551
552 if (tools::mips::isUCLibc(Args))
553 Loader = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0";
554 else if (!Triple.hasEnvironment() &&
555 Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies)
Alexander Richardson742553d2018-06-25 16:49:52 +0000556 Loader =
557 Triple.isLittleEndian() ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1";
David L. Jonesf561aba2017-03-08 01:02:16 +0000558 else
559 Loader = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1";
560
561 break;
562 }
563 case llvm::Triple::ppc:
564 LibDir = "lib";
565 Loader = "ld.so.1";
566 break;
567 case llvm::Triple::ppc64:
568 LibDir = "lib64";
569 Loader =
570 (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2" : "ld64.so.1";
571 break;
572 case llvm::Triple::ppc64le:
573 LibDir = "lib64";
574 Loader =
575 (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2";
576 break;
Alex Bradbury71f45452018-01-11 13:36:56 +0000577 case llvm::Triple::riscv32: {
578 StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
579 LibDir = "lib";
580 Loader = ("ld-linux-riscv32-" + ABIName + ".so.1").str();
581 break;
582 }
583 case llvm::Triple::riscv64: {
584 StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
585 LibDir = "lib";
586 Loader = ("ld-linux-riscv64-" + ABIName + ".so.1").str();
587 break;
588 }
David L. Jonesf561aba2017-03-08 01:02:16 +0000589 case llvm::Triple::sparc:
590 case llvm::Triple::sparcel:
591 LibDir = "lib";
592 Loader = "ld-linux.so.2";
593 break;
594 case llvm::Triple::sparcv9:
595 LibDir = "lib64";
596 Loader = "ld-linux.so.2";
597 break;
598 case llvm::Triple::systemz:
599 LibDir = "lib";
600 Loader = "ld64.so.1";
601 break;
602 case llvm::Triple::x86:
603 LibDir = "lib";
604 Loader = "ld-linux.so.2";
605 break;
606 case llvm::Triple::x86_64: {
607 bool X32 = Triple.getEnvironment() == llvm::Triple::GNUX32;
608
609 LibDir = X32 ? "libx32" : "lib64";
610 Loader = X32 ? "ld-linux-x32.so.2" : "ld-linux-x86-64.so.2";
611 break;
612 }
613 }
614
615 if (Distro == Distro::Exherbo && (Triple.getVendor() == llvm::Triple::UnknownVendor ||
616 Triple.getVendor() == llvm::Triple::PC))
617 return "/usr/" + Triple.str() + "/lib/" + Loader;
618 return "/" + LibDir + "/" + Loader;
619}
620
621void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
622 ArgStringList &CC1Args) const {
623 const Driver &D = getDriver();
624 std::string SysRoot = computeSysRoot();
625
626 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
627 return;
628
629 if (!DriverArgs.hasArg(options::OPT_nostdlibinc))
630 addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
631
632 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
633 SmallString<128> P(D.ResourceDir);
634 llvm::sys::path::append(P, "include");
635 addSystemInclude(DriverArgs, CC1Args, P);
636 }
637
638 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
639 return;
640
641 // Check for configure-time C include directories.
642 StringRef CIncludeDirs(C_INCLUDE_DIRS);
643 if (CIncludeDirs != "") {
644 SmallVector<StringRef, 5> dirs;
645 CIncludeDirs.split(dirs, ":");
646 for (StringRef dir : dirs) {
647 StringRef Prefix =
648 llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : "";
649 addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
650 }
651 return;
652 }
653
654 // Lacking those, try to detect the correct set of system includes for the
655 // target triple.
656
657 // Add include directories specific to the selected multilib set and multilib.
658 if (GCCInstallation.isValid()) {
659 const auto &Callback = Multilibs.includeDirsCallback();
660 if (Callback) {
661 for (const auto &Path : Callback(GCCInstallation.getMultilib()))
662 addExternCSystemIncludeIfExists(
663 DriverArgs, CC1Args, GCCInstallation.getInstallPath() + Path);
664 }
665 }
666
667 // Implement generic Debian multiarch support.
668 const StringRef X86_64MultiarchIncludeDirs[] = {
669 "/usr/include/x86_64-linux-gnu",
670
671 // FIXME: These are older forms of multiarch. It's not clear that they're
672 // in use in any released version of Debian, so we should consider
673 // removing them.
674 "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"};
675 const StringRef X86MultiarchIncludeDirs[] = {
676 "/usr/include/i386-linux-gnu",
677
678 // FIXME: These are older forms of multiarch. It's not clear that they're
679 // in use in any released version of Debian, so we should consider
680 // removing them.
681 "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu",
682 "/usr/include/i486-linux-gnu"};
683 const StringRef AArch64MultiarchIncludeDirs[] = {
684 "/usr/include/aarch64-linux-gnu"};
685 const StringRef ARMMultiarchIncludeDirs[] = {
686 "/usr/include/arm-linux-gnueabi"};
687 const StringRef ARMHFMultiarchIncludeDirs[] = {
688 "/usr/include/arm-linux-gnueabihf"};
689 const StringRef ARMEBMultiarchIncludeDirs[] = {
690 "/usr/include/armeb-linux-gnueabi"};
691 const StringRef ARMEBHFMultiarchIncludeDirs[] = {
692 "/usr/include/armeb-linux-gnueabihf"};
693 const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"};
694 const StringRef MIPSELMultiarchIncludeDirs[] = {
695 "/usr/include/mipsel-linux-gnu"};
696 const StringRef MIPS64MultiarchIncludeDirs[] = {
697 "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"};
698 const StringRef MIPS64ELMultiarchIncludeDirs[] = {
699 "/usr/include/mips64el-linux-gnu",
700 "/usr/include/mips64el-linux-gnuabi64"};
701 const StringRef PPCMultiarchIncludeDirs[] = {
Kristina Brooks200cd742018-09-14 12:42:13 +0000702 "/usr/include/powerpc-linux-gnu",
703 "/usr/include/powerpc-linux-gnuspe"};
David L. Jonesf561aba2017-03-08 01:02:16 +0000704 const StringRef PPC64MultiarchIncludeDirs[] = {
705 "/usr/include/powerpc64-linux-gnu"};
706 const StringRef PPC64LEMultiarchIncludeDirs[] = {
707 "/usr/include/powerpc64le-linux-gnu"};
708 const StringRef SparcMultiarchIncludeDirs[] = {
709 "/usr/include/sparc-linux-gnu"};
710 const StringRef Sparc64MultiarchIncludeDirs[] = {
711 "/usr/include/sparc64-linux-gnu"};
712 const StringRef SYSTEMZMultiarchIncludeDirs[] = {
713 "/usr/include/s390x-linux-gnu"};
714 ArrayRef<StringRef> MultiarchIncludeDirs;
715 switch (getTriple().getArch()) {
716 case llvm::Triple::x86_64:
717 MultiarchIncludeDirs = X86_64MultiarchIncludeDirs;
718 break;
719 case llvm::Triple::x86:
720 MultiarchIncludeDirs = X86MultiarchIncludeDirs;
721 break;
722 case llvm::Triple::aarch64:
723 case llvm::Triple::aarch64_be:
724 MultiarchIncludeDirs = AArch64MultiarchIncludeDirs;
725 break;
726 case llvm::Triple::arm:
727 case llvm::Triple::thumb:
728 if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
729 MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs;
730 else
731 MultiarchIncludeDirs = ARMMultiarchIncludeDirs;
732 break;
733 case llvm::Triple::armeb:
734 case llvm::Triple::thumbeb:
735 if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
736 MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs;
737 else
738 MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs;
739 break;
740 case llvm::Triple::mips:
741 MultiarchIncludeDirs = MIPSMultiarchIncludeDirs;
742 break;
743 case llvm::Triple::mipsel:
744 MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs;
745 break;
746 case llvm::Triple::mips64:
747 MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs;
748 break;
749 case llvm::Triple::mips64el:
750 MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs;
751 break;
752 case llvm::Triple::ppc:
753 MultiarchIncludeDirs = PPCMultiarchIncludeDirs;
754 break;
755 case llvm::Triple::ppc64:
756 MultiarchIncludeDirs = PPC64MultiarchIncludeDirs;
757 break;
758 case llvm::Triple::ppc64le:
759 MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs;
760 break;
761 case llvm::Triple::sparc:
762 MultiarchIncludeDirs = SparcMultiarchIncludeDirs;
763 break;
764 case llvm::Triple::sparcv9:
765 MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs;
766 break;
767 case llvm::Triple::systemz:
768 MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs;
769 break;
770 default:
771 break;
772 }
Dan Alberte00799e2018-04-04 21:28:34 +0000773
774 const std::string AndroidMultiarchIncludeDir =
775 std::string("/usr/include/") +
776 getMultiarchTriple(D, getTriple(), SysRoot);
777 const StringRef AndroidMultiarchIncludeDirs[] = {AndroidMultiarchIncludeDir};
778 if (getTriple().isAndroid())
779 MultiarchIncludeDirs = AndroidMultiarchIncludeDirs;
780
David L. Jonesf561aba2017-03-08 01:02:16 +0000781 for (StringRef Dir : MultiarchIncludeDirs) {
782 if (D.getVFS().exists(SysRoot + Dir)) {
783 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir);
784 break;
785 }
786 }
787
788 if (getTriple().getOS() == llvm::Triple::RTEMS)
789 return;
790
791 // Add an include of '/include' directly. This isn't provided by default by
792 // system GCCs, but is often used with cross-compiling GCCs, and harmless to
793 // add even when Clang is acting as-if it were a system compiler.
794 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
795
796 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
797}
798
799static std::string DetectLibcxxIncludePath(StringRef base) {
800 std::error_code EC;
801 int MaxVersion = 0;
802 std::string MaxVersionString = "";
803 for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE;
804 LI = LI.increment(EC)) {
805 StringRef VersionText = llvm::sys::path::filename(LI->path());
806 int Version;
807 if (VersionText[0] == 'v' &&
808 !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
809 if (Version > MaxVersion) {
810 MaxVersion = Version;
811 MaxVersionString = VersionText;
812 }
813 }
814 }
815 return MaxVersion ? (base + "/" + MaxVersionString).str() : "";
816}
817
Petr Hosek8d612142018-04-10 19:55:55 +0000818void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
819 llvm::opt::ArgStringList &CC1Args) const {
Dan Albertf6f11492018-05-02 19:31:01 +0000820 const std::string& SysRoot = computeSysRoot();
David L. Jonesf561aba2017-03-08 01:02:16 +0000821 const std::string LibCXXIncludePathCandidates[] = {
Petr Hosek887f26d2018-06-28 03:11:52 +0000822 DetectLibcxxIncludePath(getDriver().ResourceDir + "/include/c++"),
David L. Jonesf561aba2017-03-08 01:02:16 +0000823 DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"),
824 // If this is a development, non-installed, clang, libcxx will
825 // not be found at ../include/c++ but it likely to be found at
826 // one of the following two locations:
Dan Albertf6f11492018-05-02 19:31:01 +0000827 DetectLibcxxIncludePath(SysRoot + "/usr/local/include/c++"),
828 DetectLibcxxIncludePath(SysRoot + "/usr/include/c++") };
David L. Jonesf561aba2017-03-08 01:02:16 +0000829 for (const auto &IncludePath : LibCXXIncludePathCandidates) {
830 if (IncludePath.empty() || !getVFS().exists(IncludePath))
831 continue;
832 // Use the first candidate that exists.
Petr Hosek8d612142018-04-10 19:55:55 +0000833 addSystemInclude(DriverArgs, CC1Args, IncludePath);
834 return;
David L. Jonesf561aba2017-03-08 01:02:16 +0000835 }
David L. Jonesf561aba2017-03-08 01:02:16 +0000836}
837
838void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
839 llvm::opt::ArgStringList &CC1Args) const {
840 // We need a detected GCC installation on Linux to provide libstdc++'s
841 // headers.
842 if (!GCCInstallation.isValid())
843 return;
844
845 // By default, look for the C++ headers in an include directory adjacent to
846 // the lib directory of the GCC installation. Note that this is expect to be
847 // equivalent to '/usr/include/c++/X.Y' in almost all cases.
848 StringRef LibDir = GCCInstallation.getParentLibPath();
849 StringRef InstallDir = GCCInstallation.getInstallPath();
850 StringRef TripleStr = GCCInstallation.getTriple().str();
851 const Multilib &Multilib = GCCInstallation.getMultilib();
852 const std::string GCCMultiarchTriple = getMultiarchTriple(
853 getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot);
854 const std::string TargetMultiarchTriple =
855 getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
856 const GCCVersion &Version = GCCInstallation.getVersion();
857
858 // The primary search for libstdc++ supports multiarch variants.
859 if (addLibStdCXXIncludePaths(LibDir.str() + "/../include",
860 "/c++/" + Version.Text, TripleStr,
861 GCCMultiarchTriple, TargetMultiarchTriple,
862 Multilib.includeSuffix(), DriverArgs, CC1Args))
863 return;
864
865 // Otherwise, fall back on a bunch of options which don't use multiarch
866 // layouts for simplicity.
867 const std::string LibStdCXXIncludePathCandidates[] = {
868 // Gentoo is weird and places its headers inside the GCC install,
869 // so if the first attempt to find the headers fails, try these patterns.
870 InstallDir.str() + "/include/g++-v" + Version.Text,
871 InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." +
872 Version.MinorStr,
873 InstallDir.str() + "/include/g++-v" + Version.MajorStr,
874 // Android standalone toolchain has C++ headers in yet another place.
875 LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,
876 // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++,
877 // without a subdirectory corresponding to the gcc version.
878 LibDir.str() + "/../include/c++",
879 };
880
881 for (const auto &IncludePath : LibStdCXXIncludePathCandidates) {
882 if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr,
883 /*GCCMultiarchTriple*/ "",
884 /*TargetMultiarchTriple*/ "",
885 Multilib.includeSuffix(), DriverArgs, CC1Args))
886 break;
887 }
888}
889
890void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
891 ArgStringList &CC1Args) const {
892 CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
893}
894
895void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
896 ArgStringList &CC1Args) const {
897 if (GCCInstallation.isValid()) {
898 CC1Args.push_back("-isystem");
899 CC1Args.push_back(DriverArgs.MakeArgString(
900 GCCInstallation.getParentLibPath() + "/../" +
901 GCCInstallation.getTriple().str() + "/include"));
902 }
903}
904
Evgeniy Stepanov117627c2017-10-25 20:39:22 +0000905bool Linux::isPIEDefault() const {
906 return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
Martell Malone13c5d732017-11-19 00:08:12 +0000907 getTriple().isMusl() || getSanitizerArgs().requiresPIE();
Evgeniy Stepanov117627c2017-10-25 20:39:22 +0000908}
David L. Jonesf561aba2017-03-08 01:02:16 +0000909
Pirama Arumuga Nainar569dd502018-08-22 17:43:05 +0000910bool Linux::IsMathErrnoDefault() const {
911 if (getTriple().isAndroid())
912 return false;
913 return Generic_ELF::IsMathErrnoDefault();
914}
915
David L. Jonesf561aba2017-03-08 01:02:16 +0000916SanitizerMask Linux::getSupportedSanitizers() const {
917 const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
918 const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
Alexander Richardson742553d2018-06-25 16:49:52 +0000919 const bool IsMIPS = getTriple().isMIPS32();
920 const bool IsMIPS64 = getTriple().isMIPS64();
David L. Jonesf561aba2017-03-08 01:02:16 +0000921 const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 ||
922 getTriple().getArch() == llvm::Triple::ppc64le;
923 const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 ||
924 getTriple().getArch() == llvm::Triple::aarch64_be;
Maxim Ostapenko2084b6b2017-04-11 07:22:11 +0000925 const bool IsArmArch = getTriple().getArch() == llvm::Triple::arm ||
Galina Kistanova8a338ea2017-06-03 16:47:06 +0000926 getTriple().getArch() == llvm::Triple::thumb ||
927 getTriple().getArch() == llvm::Triple::armeb ||
928 getTriple().getArch() == llvm::Triple::thumbeb;
David L. Jonesf561aba2017-03-08 01:02:16 +0000929 SanitizerMask Res = ToolChain::getSupportedSanitizers();
930 Res |= SanitizerKind::Address;
George Karpenkovf2fc5b02017-04-24 18:23:24 +0000931 Res |= SanitizerKind::Fuzzer;
George Karpenkov33613f62017-08-11 17:22:58 +0000932 Res |= SanitizerKind::FuzzerNoLink;
David L. Jonesf561aba2017-03-08 01:02:16 +0000933 Res |= SanitizerKind::KernelAddress;
Evgeniy Stepanov072b1a22018-04-04 23:48:06 +0000934 Res |= SanitizerKind::Memory;
David L. Jonesf561aba2017-03-08 01:02:16 +0000935 Res |= SanitizerKind::Vptr;
936 Res |= SanitizerKind::SafeStack;
937 if (IsX86_64 || IsMIPS64 || IsAArch64)
938 Res |= SanitizerKind::DataFlow;
Alex Shlyapnikov797bdbb2017-10-26 03:09:53 +0000939 if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64)
David L. Jonesf561aba2017-03-08 01:02:16 +0000940 Res |= SanitizerKind::Leak;
941 if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
942 Res |= SanitizerKind::Thread;
Alexander Potapenkod49c32c2018-09-07 09:21:09 +0000943 if (IsX86_64)
944 Res |= SanitizerKind::KernelMemory;
David L. Jonesf561aba2017-03-08 01:02:16 +0000945 if (IsX86_64 || IsMIPS64)
946 Res |= SanitizerKind::Efficiency;
Kostya Kortchinsky8acdc982017-11-03 17:04:13 +0000947 if (IsX86 || IsX86_64)
David L. Jonesf561aba2017-03-08 01:02:16 +0000948 Res |= SanitizerKind::Function;
Kostya Kortchinskyeb5b79b42018-07-03 14:39:29 +0000949 if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsMIPS || IsArmArch ||
950 IsPowerPC64)
Kostya Kortchinsky8acdc982017-11-03 17:04:13 +0000951 Res |= SanitizerKind::Scudo;
Andrey Konovalov1ba9d9c2018-04-13 18:05:21 +0000952 if (IsX86_64 || IsAArch64) {
Evgeniy Stepanov12817e52017-12-09 01:32:07 +0000953 Res |= SanitizerKind::HWAddress;
Andrey Konovalov1ba9d9c2018-04-13 18:05:21 +0000954 Res |= SanitizerKind::KernelHWAddress;
955 }
David L. Jonesf561aba2017-03-08 01:02:16 +0000956 return Res;
957}
958
959void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args,
960 llvm::opt::ArgStringList &CmdArgs) const {
961 if (!needsProfileRT(Args)) return;
962
963 // Add linker option -u__llvm_runtime_variable to cause runtime
964 // initialization module to be linked in.
965 if (!Args.hasArg(options::OPT_coverage))
966 CmdArgs.push_back(Args.MakeArgString(
967 Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
968 ToolChain::addProfileRTLibs(Args, CmdArgs);
969}