clang 23.0.0git
Linux.cpp
Go to the documentation of this file.
1//===--- Linux.h - Linux ToolChain Implementations --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "Linux.h"
10#include "Arch/ARM.h"
11#include "Arch/LoongArch.h"
12#include "Arch/Mips.h"
13#include "Arch/PPC.h"
14#include "Arch/RISCV.h"
15#include "clang/Config/config.h"
17#include "clang/Driver/Distro.h"
18#include "clang/Driver/Driver.h"
21#include "llvm/Option/ArgList.h"
22#include "llvm/ProfileData/InstrProf.h"
23#include "llvm/Support/Path.h"
24#include "llvm/Support/ScopedPrinter.h"
25#include "llvm/Support/VirtualFileSystem.h"
26
27using namespace clang::driver;
28using namespace clang::driver::toolchains;
29using namespace clang;
30using namespace llvm::opt;
31
33
34/// Get our best guess at the multiarch triple for a target.
35///
36/// Debian-based systems are starting to use a multiarch setup where they use
37/// a target-triple directory in the library and header search paths.
38/// Unfortunately, this triple does not align with the vanilla target triple,
39/// so we provide a rough mapping here.
40std::string Linux::getMultiarchTriple(const Driver &D,
41 const llvm::Triple &TargetTriple,
42 StringRef SysRoot) const {
43 llvm::Triple::EnvironmentType TargetEnvironment =
44 TargetTriple.getEnvironment();
45 bool IsAndroid = TargetTriple.isAndroid();
46 bool IsMipsR6 = TargetTriple.getSubArch() == llvm::Triple::MipsSubArch_r6;
47 bool IsMipsN32Abi = TargetTriple.getEnvironment() == llvm::Triple::GNUABIN32;
48
49 // For most architectures, just use whatever we have rather than trying to be
50 // clever.
51 switch (TargetTriple.getArch()) {
52 default:
53 break;
54
55 // We use the existence of '/lib/<triple>' as a directory to detect some
56 // common linux triples that don't quite match the Clang triple for both
57 // 32-bit and 64-bit targets. Multiarch fixes its install triples to these
58 // regardless of what the actual target triple is.
59 case llvm::Triple::arm:
60 case llvm::Triple::thumb:
61 if (IsAndroid)
62 return "arm-linux-androideabi";
63 if (TargetEnvironment == llvm::Triple::GNUEABIHF ||
64 TargetEnvironment == llvm::Triple::MuslEABIHF ||
65 TargetEnvironment == llvm::Triple::EABIHF)
66 return "arm-linux-gnueabihf";
67 return "arm-linux-gnueabi";
68 case llvm::Triple::armeb:
69 case llvm::Triple::thumbeb:
70 if (TargetEnvironment == llvm::Triple::GNUEABIHF ||
71 TargetEnvironment == llvm::Triple::MuslEABIHF ||
72 TargetEnvironment == llvm::Triple::EABIHF)
73 return "armeb-linux-gnueabihf";
74 return "armeb-linux-gnueabi";
75 case llvm::Triple::x86:
76 if (IsAndroid)
77 return "i686-linux-android";
78 return "i386-linux-gnu";
79 case llvm::Triple::x86_64:
80 if (IsAndroid)
81 return "x86_64-linux-android";
82 if (TargetEnvironment == llvm::Triple::GNUX32)
83 return "x86_64-linux-gnux32";
84 return "x86_64-linux-gnu";
85 case llvm::Triple::aarch64:
86 if (IsAndroid)
87 return "aarch64-linux-android";
88 if (hasEffectiveTriple() &&
89 getEffectiveTriple().getEnvironment() == llvm::Triple::PAuthTest)
90 return "aarch64-linux-pauthtest";
91 return "aarch64-linux-gnu";
92 case llvm::Triple::aarch64_be:
93 return "aarch64_be-linux-gnu";
94
95 case llvm::Triple::loongarch64: {
96 const char *Libc;
97 const char *FPFlavor;
98
99 if (TargetTriple.isGNUEnvironment()) {
100 Libc = "gnu";
101 } else if (TargetTriple.isMusl()) {
102 Libc = "musl";
103 } else {
104 return TargetTriple.str();
105 }
106
107 switch (TargetEnvironment) {
108 default:
109 return TargetTriple.str();
110 case llvm::Triple::GNUSF:
111 case llvm::Triple::MuslSF:
112 FPFlavor = "sf";
113 break;
114 case llvm::Triple::GNUF32:
115 case llvm::Triple::MuslF32:
116 FPFlavor = "f32";
117 break;
118 case llvm::Triple::GNU:
119 case llvm::Triple::GNUF64:
120 case llvm::Triple::Musl:
121 // This was going to be "f64" in an earlier Toolchain Conventions
122 // revision, but starting from Feb 2023 the F64 ABI variants are
123 // unmarked in their canonical forms.
124 FPFlavor = "";
125 break;
126 }
127
128 return (Twine("loongarch64-linux-") + Libc + FPFlavor).str();
129 }
130
131 case llvm::Triple::m68k:
132 return "m68k-linux-gnu";
133
134 case llvm::Triple::mips:
135 return IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu";
136 case llvm::Triple::mipsel:
137 return IsMipsR6 ? "mipsisa32r6el-linux-gnu" : "mipsel-linux-gnu";
138 case llvm::Triple::mips64: {
139 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6" : "mips64") +
140 "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
141 if (D.getVFS().exists(concat(SysRoot, "/lib", MT)))
142 return MT;
143 if (D.getVFS().exists(concat(SysRoot, "/lib/mips64-linux-gnu")))
144 return "mips64-linux-gnu";
145 break;
146 }
147 case llvm::Triple::mips64el: {
148 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6el" : "mips64el") +
149 "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
150 if (D.getVFS().exists(concat(SysRoot, "/lib", MT)))
151 return MT;
152 if (D.getVFS().exists(concat(SysRoot, "/lib/mips64el-linux-gnu")))
153 return "mips64el-linux-gnu";
154 break;
155 }
156 case llvm::Triple::ppc:
157 if (D.getVFS().exists(concat(SysRoot, "/lib/powerpc-linux-gnuspe")))
158 return "powerpc-linux-gnuspe";
159 return "powerpc-linux-gnu";
160 case llvm::Triple::ppcle:
161 return "powerpcle-linux-gnu";
162 case llvm::Triple::ppc64:
163 return "powerpc64-linux-gnu";
164 case llvm::Triple::ppc64le:
165 return "powerpc64le-linux-gnu";
166 case llvm::Triple::riscv64:
167 if (IsAndroid)
168 return "riscv64-linux-android";
169 return "riscv64-linux-gnu";
170 case llvm::Triple::sparc:
171 return "sparc-linux-gnu";
172 case llvm::Triple::sparcv9:
173 return "sparc64-linux-gnu";
174 case llvm::Triple::systemz:
175 return "s390x-linux-gnu";
176 }
177 return TargetTriple.str();
178}
179
180static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
181 if (Triple.isMIPS()) {
182 // lib32 directory has a special meaning on MIPS targets.
183 // It contains N32 ABI binaries. Use this folder if produce
184 // code for N32 ABI only.
185 if (tools::mips::hasMipsAbiArg(Args, "n32"))
186 return "lib32";
187 return Triple.isArch32Bit() ? "lib" : "lib64";
188 }
189
190 // It happens that only x86, PPC and SPARC use the 'lib32' variant of
191 // oslibdir, and using that variant while targeting other architectures causes
192 // problems because the libraries are laid out in shared system roots that
193 // can't cope with a 'lib32' library search path being considered. So we only
194 // enable them when we know we may need it.
195 //
196 // FIXME: This is a bit of a hack. We should really unify this code for
197 // reasoning about oslibdir spellings with the lib dir spellings in the
198 // GCCInstallationDetector, but that is a more significant refactoring.
199 if (Triple.getArch() == llvm::Triple::x86 || Triple.isPPC32() ||
200 Triple.getArch() == llvm::Triple::sparc)
201 return "lib32";
202
203 if (Triple.getArch() == llvm::Triple::x86_64 && Triple.isX32())
204 return "libx32";
205
206 if (Triple.isRISCV32())
207 return "lib32";
208
209 if (Triple.getArch() == llvm::Triple::loongarch32) {
210 switch (Triple.getEnvironment()) {
211 default:
212 return "lib32";
213 case llvm::Triple::GNUSF:
214 case llvm::Triple::MuslSF:
215 return "lib32/sf";
216 case llvm::Triple::GNUF32:
217 case llvm::Triple::MuslF32:
218 return "lib32/f32";
219 }
220 }
221
222 return Triple.isArch32Bit() ? "lib" : "lib64";
223}
224
225Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
226 : Generic_ELF(D, Triple, Args) {
227 GCCInstallation.TripleToDebianMultiarch = [](const llvm::Triple &T) {
228 StringRef TripleStr = T.str();
229 StringRef DebianMultiarch =
230 T.getArch() == llvm::Triple::x86 ? "i386-linux-gnu" : TripleStr;
231 return DebianMultiarch;
232 };
233
234 GCCInstallation.init(Triple, Args);
235 Multilibs = GCCInstallation.getMultilibs();
236 SelectedMultilibs.assign({GCCInstallation.getMultilib()});
237
238 loadMultilibsFromYAML(Args, D);
239
240 llvm::Triple::ArchType Arch = Triple.getArch();
241 std::string SysRoot = computeSysRoot();
243
245
246 Distro Distro(D.getVFS(), Triple);
247
248 if (Distro.IsAlpineLinux() || Triple.isAndroid()) {
249 ExtraOpts.push_back("-z");
250 ExtraOpts.push_back("now");
251 }
252
254 Triple.isAndroid()) {
255 ExtraOpts.push_back("-z");
256 ExtraOpts.push_back("relro");
257 }
258
259 // Note, lld from 11 onwards default max-page-size to 65536 for both ARM and
260 // AArch64.
261 if (Triple.isAndroid()) {
262 if (Triple.isARM()) {
263 // Android ARM uses max-page-size=4096 to reduce VMA usage.
264 ExtraOpts.push_back("-z");
265 ExtraOpts.push_back("max-page-size=4096");
266 } else if (Triple.isAArch64() || Triple.getArch() == llvm::Triple::x86_64) {
267 // Android AArch64 uses max-page-size=16384 to support 4k/16k page sizes.
268 // Android emulates a 16k page size for app testing on x86_64 machines.
269 ExtraOpts.push_back("-z");
270 ExtraOpts.push_back("max-page-size=16384");
271 }
272 if (Triple.isAndroidVersionLT(29)) {
273 // https://github.com/android/ndk/issues/1196
274 // The unwinder used by the crash handler on versions of Android prior to
275 // API 29 did not correctly handle binaries built with rosegment, which is
276 // enabled by default for LLD. Android only supports LLD, so it's not an
277 // issue that this flag is not accepted by other linkers.
278 ExtraOpts.push_back("--no-rosegment");
279 }
280 // SHT_RELR relocations are only supported at API level >= 30.
281 // ANDROID_RELR relocations were supported at API level >= 28.
282 // Relocation packer was supported at API level >= 23.
283 if (!Triple.isAndroidVersionLT(30)) {
284 ExtraOpts.push_back("--pack-dyn-relocs=android+relr");
285 } else if (!Triple.isAndroidVersionLT(28)) {
286 ExtraOpts.push_back("--pack-dyn-relocs=android+relr");
287 ExtraOpts.push_back("--use-android-relr-tags");
288 } else if (!Triple.isAndroidVersionLT(23)) {
289 ExtraOpts.push_back("--pack-dyn-relocs=android");
290 }
291 }
292
293 if (GCCInstallation.getParentLibPath().contains("opt/rh/"))
294 // With devtoolset on RHEL, we want to add a bin directory that is relative
295 // to the detected gcc install, because if we are using devtoolset gcc then
296 // we want to use other tools from devtoolset (e.g. ld) instead of the
297 // standard system tools.
298 PPaths.push_back(Twine(GCCInstallation.getParentLibPath() +
299 "/../bin").str());
300
301 if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)
302 ExtraOpts.push_back("-X");
303
304 const bool IsAndroid = Triple.isAndroid();
305 const bool IsMips = Triple.isMIPS();
306 const bool IsHexagon = Arch == llvm::Triple::hexagon;
307 const bool IsRISCV = Triple.isRISCV();
308 const bool IsCSKY = Triple.isCSKY();
309
310 if (IsCSKY && !SelectedMultilibs.empty())
311 SysRoot = SysRoot + SelectedMultilibs.back().osSuffix();
312
313 if ((IsMips || IsCSKY) && !SysRoot.empty())
314 ExtraOpts.push_back("--sysroot=" + SysRoot);
315
316 // Do not use 'gnu' hash style for Mips targets because .gnu.hash
317 // and the MIPS ABI require .dynsym to be sorted in different ways.
318 // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS
319 // ABI requires a mapping between the GOT and the symbol table.
320 // Android loader does not support .gnu.hash until API 23.
321 // Hexagon linker/loader does not support .gnu.hash.
322 // SUSE SLES 11 will stop being supported Mar 2028.
323 if (!IsMips && !IsHexagon) {
324 if (Distro.IsOpenSUSE() || (IsAndroid && Triple.isAndroidVersionLT(23)))
325 ExtraOpts.push_back("--hash-style=both");
326 else
327 ExtraOpts.push_back("--hash-style=gnu");
328 }
329
330#ifdef ENABLE_LINKER_BUILD_ID
331 ExtraOpts.push_back("--build-id");
332#endif
333
334 // The selection of paths to try here is designed to match the patterns which
335 // the GCC driver itself uses, as this is part of the GCC-compatible driver.
336 // This was determined by running GCC in a fake filesystem, creating all
337 // possible permutations of these directories, and seeing which ones it added
338 // to the link paths.
339 path_list &Paths = getFilePaths();
340
341 const std::string OSLibDir = std::string(getOSLibDir(Triple, Args));
342 const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
343
344 // mips32: Debian multilib, we use /libo32, while in other case, /lib is
345 // used. We need add both libo32 and /lib.
346 if (Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel) {
347 Generic_GCC::AddMultilibPaths(D, SysRoot, "libo32", MultiarchTriple, Paths);
348 addPathIfExists(D, concat(SysRoot, "/libo32"), Paths);
349 addPathIfExists(D, concat(SysRoot, "/usr/libo32"), Paths);
350 }
351 Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths);
352
353 addPathIfExists(D, concat(SysRoot, "/lib", MultiarchTriple), Paths);
354 addPathIfExists(D, concat(SysRoot, "/lib/..", OSLibDir), Paths);
355
356 if (IsAndroid) {
357 // Android sysroots contain a library directory for each supported OS
358 // version as well as some unversioned libraries in the usual multiarch
359 // directory.
360 addPathIfExists(
361 D,
362 concat(SysRoot, "/usr/lib", MultiarchTriple,
363 llvm::to_string(Triple.getEnvironmentVersion().getMajor())),
364 Paths);
365 }
366
367 addPathIfExists(D, concat(SysRoot, "/usr/lib", MultiarchTriple), Paths);
368 addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir), Paths);
369 if (IsRISCV) {
370 StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
371 addPathIfExists(D, concat(SysRoot, "/", OSLibDir, ABIName), Paths);
372 addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir, ABIName), Paths);
373 }
374
375 Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
376
377 addPathIfExists(D, concat(SysRoot, "/lib"), Paths);
378 addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths);
379}
380
386
388 if (getTriple().isAndroid())
389 return 4;
391}
392
398
399bool Linux::HasNativeLLVMSupport() const { return true; }
400
401Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); }
402
404 return new tools::gnutools::StaticLibTool(*this);
405}
406
408 return new tools::gnutools::Assembler(*this);
409}
410
411std::string Linux::computeSysRoot() const {
412 if (!getDriver().SysRoot.empty())
413 return getDriver().SysRoot;
414
415 if (getTriple().isAndroid()) {
416 // Android toolchains typically include a sysroot at ../sysroot relative to
417 // the clang binary.
418 const StringRef ClangDir = getDriver().Dir;
419 std::string AndroidSysRootPath = (ClangDir + "/../sysroot").str();
420 if (getVFS().exists(AndroidSysRootPath))
421 return AndroidSysRootPath;
422 }
423
424 if (getTriple().isCSKY()) {
425 // CSKY toolchains use different names for sysroot folder.
426 if (!GCCInstallation.isValid())
427 return std::string();
428 // GCCInstallation.getInstallPath() =
429 // $GCCToolchainPath/lib/gcc/csky-linux-gnuabiv2/6.3.0
430 // Path = $GCCToolchainPath/csky-linux-gnuabiv2/libc
431 std::string Path = (GCCInstallation.getInstallPath() + "/../../../../" +
432 GCCInstallation.getTriple().str() + "/libc")
433 .str();
434 if (getVFS().exists(Path))
435 return Path;
436 return std::string();
437 }
438
439 if (!GCCInstallation.isValid() || !getTriple().isMIPS())
440 return std::string();
441
442 // Standalone MIPS toolchains use different names for sysroot folder
443 // and put it into different places. Here we try to check some known
444 // variants.
445
446 const StringRef InstallDir = GCCInstallation.getInstallPath();
447 const StringRef TripleStr = GCCInstallation.getTriple().str();
448 const Multilib &Multilib = GCCInstallation.getMultilib();
449
450 std::string Path =
451 (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix())
452 .str();
453
454 if (getVFS().exists(Path))
455 return Path;
456
457 Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str();
458
459 if (getVFS().exists(Path))
460 return Path;
461
462 return std::string();
463}
464
465static void setPAuthABIInTriple(const Driver &D, const ArgList &Args,
466 llvm::Triple &Triple) {
467 Arg *ABIArg = Args.getLastArg(options::OPT_mabi_EQ);
468 bool HasPAuthABI =
469 ABIArg ? (StringRef(ABIArg->getValue()) == "pauthtest") : false;
470
471 switch (Triple.getEnvironment()) {
472 case llvm::Triple::UnknownEnvironment:
473 if (HasPAuthABI)
474 Triple.setEnvironment(llvm::Triple::PAuthTest);
475 break;
476 case llvm::Triple::PAuthTest:
477 break;
478 default:
479 if (HasPAuthABI)
480 D.Diag(diag::err_drv_unsupported_opt_for_target)
481 << ABIArg->getAsString(Args) << Triple.getTriple();
482 break;
483 }
484}
485
486std::string Linux::ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
487 llvm::StringRef BoundArch,
488 types::ID InputType) const {
489 std::string TripleString =
490 Generic_ELF::ComputeEffectiveClangTriple(Args, BoundArch, InputType);
491 if (getTriple().isAArch64()) {
492 llvm::Triple Triple(TripleString);
493 setPAuthABIInTriple(getDriver(), Args, Triple);
494 return Triple.getTriple();
495 }
496 return TripleString;
497}
498
499// Each combination of options here forms a signing schema, and in most cases
500// each signing schema is its own incompatible ABI. The default values of the
501// options represent the default signing schema.
502static void handlePAuthABI(const Driver &D, const ArgList &DriverArgs,
503 ArgStringList &CC1Args) {
504 if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
505 options::OPT_fno_ptrauth_intrinsics))
506 CC1Args.push_back("-fptrauth-intrinsics");
507
508 if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
509 options::OPT_fno_ptrauth_calls))
510 CC1Args.push_back("-fptrauth-calls");
511
512 if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
513 options::OPT_fno_ptrauth_returns))
514 CC1Args.push_back("-fptrauth-returns");
515
516 if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
517 options::OPT_fno_ptrauth_auth_traps))
518 CC1Args.push_back("-fptrauth-auth-traps");
519
520 if (!DriverArgs.hasArg(
521 options::OPT_fptrauth_vtable_pointer_address_discrimination,
522 options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
523 CC1Args.push_back("-fptrauth-vtable-pointer-address-discrimination");
524
525 if (!DriverArgs.hasArg(
526 options::OPT_fptrauth_vtable_pointer_type_discrimination,
527 options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
528 CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
529
530 if (!DriverArgs.hasArg(
531 options::OPT_fptrauth_type_info_vtable_pointer_discrimination,
532 options::OPT_fno_ptrauth_type_info_vtable_pointer_discrimination))
533 CC1Args.push_back("-fptrauth-type-info-vtable-pointer-discrimination");
534
535 if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
536 options::OPT_fno_ptrauth_indirect_gotos))
537 CC1Args.push_back("-fptrauth-indirect-gotos");
538
539 if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
540 options::OPT_fno_ptrauth_init_fini))
541 CC1Args.push_back("-fptrauth-init-fini");
542
543 if (!DriverArgs.hasArg(
544 options::OPT_fptrauth_init_fini_address_discrimination,
545 options::OPT_fno_ptrauth_init_fini_address_discrimination))
546 CC1Args.push_back("-fptrauth-init-fini-address-discrimination");
547
548 if (!DriverArgs.hasArg(options::OPT_faarch64_jump_table_hardening,
549 options::OPT_fno_aarch64_jump_table_hardening))
550 CC1Args.push_back("-faarch64-jump-table-hardening");
551}
552
553void Linux::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
554 llvm::opt::ArgStringList &CC1Args,
555 StringRef BoundArch,
556 Action::OffloadKind DeviceOffloadKind) const {
557 llvm::Triple Triple(ComputeEffectiveClangTriple(DriverArgs));
558 if (Triple.isAArch64() && Triple.getEnvironment() == llvm::Triple::PAuthTest)
559 handlePAuthABI(getDriver(), DriverArgs, CC1Args);
560 Generic_ELF::addClangTargetOptions(DriverArgs, CC1Args, BoundArch,
561 DeviceOffloadKind);
562}
563
564std::string Linux::getDynamicLinker(const ArgList &Args) const {
565 const llvm::Triple::ArchType Arch = getArch();
566 const llvm::Triple &Triple = getTriple();
567
568 const Distro Distro(getDriver().getVFS(), Triple);
569
570 if (Triple.isAndroid()) {
571 if (getSanitizerArgs(Args).needsHwasanRt() &&
572 !Triple.isAndroidVersionLT(34) && Triple.isArch64Bit()) {
573 // On Android 14 and newer, there is a special linker_hwasan64 that
574 // allows to run HWASan binaries on non-HWASan system images. This
575 // is also available on HWASan system images, so we can just always
576 // use that instead.
577 return "/system/bin/linker_hwasan64";
578 }
579 return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker";
580 }
581 if (Triple.isMusl()) {
582 std::string ArchName;
583 bool IsArm = false;
584
585 switch (Arch) {
586 case llvm::Triple::arm:
587 case llvm::Triple::thumb:
588 ArchName = "arm";
589 IsArm = true;
590 break;
591 case llvm::Triple::armeb:
592 case llvm::Triple::thumbeb:
593 ArchName = "armeb";
594 IsArm = true;
595 break;
596 case llvm::Triple::x86:
597 ArchName = "i386";
598 break;
599 case llvm::Triple::x86_64:
600 ArchName = Triple.isX32() ? "x32" : Triple.getArchName().str();
601 break;
602 default:
603 ArchName = Triple.getArchName().str();
604 }
605 if (IsArm &&
606 (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
608 ArchName += "hf";
609 if (Arch == llvm::Triple::ppc &&
610 Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
611 ArchName = "powerpc-sf";
612
613 return "/lib/ld-musl-" + ArchName + ".so.1";
614 }
615
616 std::string LibDir;
617 std::string Loader;
618
619 switch (Arch) {
620 default:
621 llvm_unreachable("unsupported architecture");
622
623 case llvm::Triple::aarch64:
624 LibDir = "lib";
625 Loader = "ld-linux-aarch64.so.1";
626 break;
627 case llvm::Triple::aarch64_be:
628 LibDir = "lib";
629 Loader = "ld-linux-aarch64_be.so.1";
630 break;
631 case llvm::Triple::arm:
632 case llvm::Triple::thumb:
633 case llvm::Triple::armeb:
634 case llvm::Triple::thumbeb: {
635 const bool HF =
636 Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
637 Triple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
639
640 LibDir = "lib";
641 Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3";
642 break;
643 }
644 case llvm::Triple::loongarch32: {
645 LibDir = "lib32";
646 Loader =
647 ("ld-linux-loongarch-" +
648 tools::loongarch::getLoongArchABI(getDriver(), Args, Triple) + ".so.1")
649 .str();
650 break;
651 }
652 case llvm::Triple::loongarch64: {
653 LibDir = "lib64";
654 Loader =
655 ("ld-linux-loongarch-" +
656 tools::loongarch::getLoongArchABI(getDriver(), Args, Triple) + ".so.1")
657 .str();
658 break;
659 }
660 case llvm::Triple::m68k:
661 LibDir = "lib";
662 Loader = "ld.so.1";
663 break;
664 case llvm::Triple::mips:
665 case llvm::Triple::mipsel:
666 case llvm::Triple::mips64:
667 case llvm::Triple::mips64el: {
668 bool IsNaN2008 = tools::mips::isNaN2008(getDriver(), Args, Triple);
669
670 LibDir = "lib" + tools::mips::getMipsABILibSuffix(Args, Triple);
671
672 if (tools::mips::isUCLibc(Args))
673 Loader = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0";
674 else if (!Triple.hasEnvironment() &&
675 Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies)
676 Loader =
677 Triple.isLittleEndian() ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1";
678 else
679 Loader = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1";
680
681 break;
682 }
683 case llvm::Triple::ppc:
684 LibDir = "lib";
685 Loader = "ld.so.1";
686 break;
687 case llvm::Triple::ppcle:
688 LibDir = "lib";
689 Loader = "ld.so.1";
690 break;
691 case llvm::Triple::ppc64:
692 LibDir = "lib64";
693 Loader =
694 (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2" : "ld64.so.1";
695 break;
696 case llvm::Triple::ppc64le:
697 LibDir = "lib64";
698 Loader =
699 (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2";
700 break;
701 case llvm::Triple::riscv32:
702 case llvm::Triple::riscv64:
703 case llvm::Triple::riscv32be:
704 case llvm::Triple::riscv64be: {
705 StringRef ArchName = llvm::Triple::getArchTypeName(Arch);
706 StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
707 LibDir = "lib";
708 Loader = ("ld-linux-" + ArchName + "-" + ABIName + ".so.1").str();
709 break;
710 }
711 case llvm::Triple::sparc:
712 case llvm::Triple::sparcel:
713 LibDir = "lib";
714 Loader = "ld-linux.so.2";
715 break;
716 case llvm::Triple::sparcv9:
717 LibDir = "lib64";
718 Loader = "ld-linux.so.2";
719 break;
720 case llvm::Triple::systemz:
721 LibDir = "lib";
722 Loader = "ld64.so.1";
723 break;
724 case llvm::Triple::x86:
725 LibDir = "lib";
726 Loader = "ld-linux.so.2";
727 break;
728 case llvm::Triple::x86_64: {
729 bool X32 = Triple.isX32();
730
731 LibDir = X32 ? "libx32" : "lib64";
732 Loader = X32 ? "ld-linux-x32.so.2" : "ld-linux-x86-64.so.2";
733 break;
734 }
735 case llvm::Triple::ve:
736 return "/opt/nec/ve/lib/ld-linux-ve.so.1";
737 case llvm::Triple::csky: {
738 LibDir = "lib";
739 Loader = "ld.so.1";
740 break;
741 }
742 }
743
744 if (Distro == Distro::Exherbo &&
745 (Triple.getVendor() == llvm::Triple::UnknownVendor ||
746 Triple.getVendor() == llvm::Triple::PC))
747 return "/usr/" + Triple.str() + "/lib/" + Loader;
748 return "/" + LibDir + "/" + Loader;
749}
750
751void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
752 ArgStringList &CC1Args) const {
753 const Driver &D = getDriver();
754 std::string SysRoot = computeSysRoot();
755
756 if (DriverArgs.hasArg(options::OPT_nostdinc))
757 return;
758
759 // Add 'include' in the resource directory, which is similar to
760 // GCC_INCLUDE_DIR (private headers) in GCC. Note: the include directory
761 // contains some files conflicting with system /usr/include. musl systems
762 // prefer the /usr/include copies which are more relevant.
763 SmallString<128> ResourceDirInclude(D.ResourceDir);
764 llvm::sys::path::append(ResourceDirInclude, "include");
765 if (!DriverArgs.hasArg(options::OPT_nobuiltininc) &&
766 (!getTriple().isMusl() || DriverArgs.hasArg(options::OPT_nostdlibinc)))
767 addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
768
769 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
770 return;
771
772 // Add multilib variant include paths in priority order.
773 for (const Multilib &M : getOrderedMultilibs()) {
774 if (M.isDefault())
775 continue;
776 if (std::optional<std::string> StdlibIncDir = getStdlibIncludePath()) {
777 SmallString<128> Dir(*StdlibIncDir);
778 llvm::sys::path::append(Dir, M.includeSuffix());
779 if (D.getVFS().exists(Dir))
780 addSystemInclude(DriverArgs, CC1Args, Dir);
781 }
782 }
783
784 // After the resource directory, we prioritize the standard clang include
785 // directory.
786 if (std::optional<std::string> Path = getStdlibIncludePath())
787 addSystemInclude(DriverArgs, CC1Args, *Path);
788
789 // LOCAL_INCLUDE_DIR
790 addSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/local/include"));
791 // TOOL_INCLUDE_DIR
792 AddMultilibIncludeArgs(DriverArgs, CC1Args);
793
794 // Check for configure-time C include directories.
795 StringRef CIncludeDirs(C_INCLUDE_DIRS);
796 if (CIncludeDirs != "") {
798 CIncludeDirs.split(dirs, ":");
799 for (StringRef dir : dirs) {
800 StringRef Prefix =
801 llvm::sys::path::is_absolute(dir) ? "" : StringRef(SysRoot);
802 addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
803 }
804 return;
805 }
806
807 // On systems using multiarch and Android, add /usr/include/$triple before
808 // /usr/include.
809 std::string MultiarchIncludeDir = getMultiarchTriple(D, getTriple(), SysRoot);
810 if (!MultiarchIncludeDir.empty() &&
811 D.getVFS().exists(concat(SysRoot, "/usr/include", MultiarchIncludeDir)))
813 DriverArgs, CC1Args,
814 concat(SysRoot, "/usr/include", MultiarchIncludeDir));
815
816 if (getTriple().getOS() == llvm::Triple::RTEMS)
817 return;
818
819 // Add an include of '/include' directly. This isn't provided by default by
820 // system GCCs, but is often used with cross-compiling GCCs, and harmless to
821 // add even when Clang is acting as-if it were a system compiler.
822 addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include"));
823
824 addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include"));
825
826 if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl())
827 addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
828}
829
830void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
831 llvm::opt::ArgStringList &CC1Args) const {
832 // We need a detected GCC installation on Linux to provide libstdc++'s
833 // headers in odd Linuxish places.
834 if (!GCCInstallation.isValid())
835 return;
836
837 // Try generic GCC detection first.
838 if (Generic_GCC::addGCCLibStdCxxIncludePaths(DriverArgs, CC1Args))
839 return;
840
841 StringRef LibDir = GCCInstallation.getParentLibPath();
842 const Multilib &Multilib = GCCInstallation.getMultilib();
843 const GCCVersion &Version = GCCInstallation.getVersion();
844
845 StringRef TripleStr = GCCInstallation.getTriple().str();
846 const std::string LibStdCXXIncludePathCandidates[] = {
847 // Android standalone toolchain has C++ headers in yet another place.
848 LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,
849 // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++,
850 // without a subdirectory corresponding to the gcc version.
851 LibDir.str() + "/../include/c++",
852 // Cray's gcc installation puts headers under "g++" without a
853 // version suffix.
854 LibDir.str() + "/../include/g++",
855 };
856
857 for (const auto &IncludePath : LibStdCXXIncludePathCandidates) {
858 if (addLibStdCXXIncludePaths(IncludePath, TripleStr,
859 Multilib.includeSuffix(), DriverArgs, CC1Args))
860 break;
861 }
862}
863
864void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
865 ArgStringList &CC1Args) const {
866 CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
867}
868
869void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs,
870 ArgStringList &CC1Args) const {
871 RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
872}
873
874void Linux::addOffloadRTLibs(unsigned ActiveKinds, const ArgList &Args,
875 ArgStringList &CmdArgs) const {
876 if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
877 true) ||
878 Args.hasArg(options::OPT_nostdlib) ||
879 Args.hasArg(options::OPT_no_hip_rt) || Args.hasArg(options::OPT_r))
880 return;
881
883 if (ActiveKinds & Action::OFK_HIP)
884 Libraries.emplace_back(RocmInstallation->getLibPath(), "libamdhip64.so");
885 else if ((ActiveKinds & Action::OFK_SYCL) &&
886 !Args.hasArg(options::OPT_nolibsycl))
887 Libraries.emplace_back(SYCLInstallation->getSYCLRTLibPath(),
888 "libLLVMSYCL.so");
889
890 for (auto [Path, Library] : Libraries) {
891 if (Args.hasFlag(options::OPT_frtlib_add_rpath,
892 options::OPT_fno_rtlib_add_rpath, false)) {
893 SmallString<0> p = Path;
894 llvm::sys::path::remove_dots(p, true);
895 CmdArgs.append({"-rpath", Args.MakeArgString(p)});
896 }
897
898 SmallString<0> p = Path;
899 llvm::sys::path::append(p, Library);
900 CmdArgs.push_back(Args.MakeArgString(p));
901 }
902
903 // FIXME: The ROCm builds implicitly depends on this being present.
904 if (ActiveKinds & Action::OFK_HIP)
905 CmdArgs.push_back(
906 Args.MakeArgString(StringRef("-L") + RocmInstallation->getLibPath()));
907
908 // For HIP device PGO, link clang_rt.profile_rocm when available. It is a
909 // self-contained superset of clang_rt.profile, emitted first so the base
910 // archive stays inert.
911 if ((ActiveKinds & Action::OFK_HIP) && needsProfileRT(Args) &&
912 getVFS().exists(getCompilerRT(Args, "profile_rocm", FT_Static))) {
913 CmdArgs.push_back(getCompilerRTArgString(Args, "profile_rocm"));
914 // Force-retain the constructor-only hipModuleLoad* interceptor object; its
915 // constructor self-skips when the program does not use hipModuleLoad.
916 CmdArgs.push_back("-u");
917 CmdArgs.push_back("__llvm_profile_offload_register_dynamic_module");
918 }
919}
920
921void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
922 ArgStringList &CC1Args) const {
923 if (GCCInstallation.isValid()) {
924 CC1Args.push_back("-isystem");
925 CC1Args.push_back(DriverArgs.MakeArgString(
926 GCCInstallation.getParentLibPath() + "/../" +
927 GCCInstallation.getTriple().str() + "/include"));
928 }
929}
930
931void Linux::addSYCLIncludeArgs(const ArgList &DriverArgs,
932 ArgStringList &CC1Args) const {
933 SYCLInstallation->addSYCLIncludeArgs(DriverArgs, CC1Args);
934}
935
936bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const {
937 return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
938 getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE();
939}
940
941bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const {
942 // Outline atomics for AArch64 are supported by compiler-rt
943 // and libgcc since 9.3.1
944 assert(getTriple().isAArch64() && "expected AArch64 target!");
946 if (RtLib == ToolChain::RLT_CompilerRT)
947 return true;
948 assert(RtLib == ToolChain::RLT_Libgcc && "unexpected runtime library type!");
949 if (GCCInstallation.getVersion().isOlderThan(9, 3, 1))
950 return false;
951 return true;
952}
953
955 if (getTriple().isAndroid() || getTriple().isMusl())
956 return false;
958}
959
962 Action::OffloadKind DeviceOffloadKind) const {
963 const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
964 const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
965 const bool IsMIPS = getTriple().isMIPS32();
966 const bool IsMIPS64 = getTriple().isMIPS64();
967 const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 ||
968 getTriple().getArch() == llvm::Triple::ppc64le;
969 const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 ||
970 getTriple().getArch() == llvm::Triple::aarch64_be;
971 const bool IsArmArch = getTriple().getArch() == llvm::Triple::arm ||
972 getTriple().getArch() == llvm::Triple::thumb ||
973 getTriple().getArch() == llvm::Triple::armeb ||
974 getTriple().getArch() == llvm::Triple::thumbeb;
975 const bool IsLoongArch64 = getTriple().getArch() == llvm::Triple::loongarch64;
976 const bool IsRISCV64 = getTriple().isRISCV64();
977 const bool IsSystemZ = getTriple().getArch() == llvm::Triple::systemz;
978 const bool IsHexagon = getTriple().getArch() == llvm::Triple::hexagon;
979 const bool IsAndroid = getTriple().isAndroid();
980 SanitizerMask Res =
981 ToolChain::getSupportedSanitizers(BoundArch, DeviceOffloadKind);
982 Res |= SanitizerKind::Address;
983 Res |= SanitizerKind::PointerCompare;
984 Res |= SanitizerKind::PointerSubtract;
985 Res |= SanitizerKind::Realtime;
986 Res |= SanitizerKind::Fuzzer;
987 Res |= SanitizerKind::FuzzerNoLink;
988 Res |= SanitizerKind::KernelAddress;
989 Res |= SanitizerKind::Vptr;
990 Res |= SanitizerKind::SafeStack;
991 if (IsX86_64 || IsMIPS64 || IsAArch64 || IsLoongArch64 || IsSystemZ)
992 Res |= SanitizerKind::DataFlow;
993 if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64 ||
994 IsRISCV64 || IsSystemZ || IsHexagon || IsLoongArch64)
995 Res |= SanitizerKind::Leak;
996 if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ ||
997 IsLoongArch64 || IsRISCV64)
998 Res |= SanitizerKind::Thread;
999 if (IsX86_64 || IsAArch64 || IsSystemZ || IsHexagon)
1000 Res |= SanitizerKind::Type;
1001 if (IsX86_64 || IsSystemZ || IsPowerPC64)
1002 Res |= SanitizerKind::KernelMemory;
1003 if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsMIPS || IsArmArch ||
1004 IsPowerPC64 || IsHexagon || IsLoongArch64 || IsRISCV64 || IsSystemZ)
1005 Res |= SanitizerKind::Scudo;
1006 if (IsX86_64 || IsAArch64 || IsRISCV64) {
1007 Res |= SanitizerKind::HWAddress;
1008 }
1009 if (IsX86_64 || IsAArch64) {
1010 Res |= SanitizerKind::KernelHWAddress;
1011 }
1012 if (IsX86_64)
1013 Res |= SanitizerKind::NumericalStability;
1014 if (!IsAndroid)
1015 Res |= SanitizerKind::Memory;
1016
1017 // Work around "Cannot represent a difference across sections".
1018 if (getTriple().getArch() == llvm::Triple::ppc64)
1020 return Res;
1021}
1022
1023void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args,
1024 llvm::opt::ArgStringList &CmdArgs) const {
1025 // Add linker option -u__llvm_profile_runtime to cause runtime
1026 // initialization module to be linked in.
1027 if (needsProfileRT(Args))
1028 CmdArgs.push_back(Args.MakeArgString(
1029 Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
1030 ToolChain::addProfileRTLibs(Args, CmdArgs);
1031}
1032
1033void Linux::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
1034 for (const auto &Opt : ExtraOpts)
1035 CmdArgs.push_back(Opt.c_str());
1036}
1037
1038const char *Linux::getDefaultLinker() const {
1039 if (getTriple().isAndroid())
1040 return "ld.lld";
1042}
static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args)
Definition Hurd.cpp:61
static void handlePAuthABI(const Driver &D, const ArgList &DriverArgs, ArgStringList &CC1Args)
Definition Linux.cpp:502
static void setPAuthABIInTriple(const Driver &D, const ArgList &Args, llvm::Triple &Triple)
Definition Linux.cpp:465
Distro - Helper class for detecting and classifying Linux distributions.
Definition Distro.h:23
bool IsOpenSUSE() const
Definition Distro.h:122
bool IsAlpineLinux() const
Definition Distro.h:132
bool IsUbuntu() const
Definition Distro.h:128
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:94
std::string SysRoot
sysroot, if present
Definition Driver.h:194
DiagnosticBuilder Diag(unsigned DiagID) const
Definition Driver.h:158
std::string Dir
The path the driver executable was in, as invoked from the command line.
Definition Driver.h:169
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag.
Definition Multilib.h:35
const std::string & osSuffix() const
Get the detected os path suffix for the multi-arch target variant.
Definition Multilib.h:74
const std::string & includeSuffix() const
Get the include directory suffix.
Definition Multilib.h:78
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
virtual unsigned GetDefaultDwarfVersion() const
Definition ToolChain.h:661
virtual RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const
static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory with extern "C" semantics to CC1 arguments.
path_list & getFilePaths()
Definition ToolChain.h:325
static bool needsProfileRT(const llvm::opt::ArgList &Args)
needsProfileRT - returns true if instrumentation profile is on.
StringRef getOS() const
Definition ToolChain.h:304
llvm::Triple::ArchType getArch() const
Definition ToolChain.h:301
const Driver & getDriver() const
Definition ToolChain.h:285
static std::string concat(StringRef Path, const Twine &A, const Twine &B="", const Twine &C="", const Twine &D="")
llvm::vfs::FileSystem & getVFS() const
bool loadMultilibsFromYAML(const llvm::opt::ArgList &Args, const Driver &D, StringRef Fallback={})
Discover and load a multilib.yaml configuration.
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static, bool IsFortran=false) const
path_list & getProgramPaths()
Definition ToolChain.h:328
bool hasEffectiveTriple() const
Definition ToolChain.h:318
virtual SanitizerMask getSupportedSanitizers(StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const
Return sanitizers which are available in this toolchain.
const llvm::Triple & getEffectiveTriple() const
Get the toolchain's effective clang triple.
Definition ToolChain.h:313
virtual bool IsMathErrnoDefault() const
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition ToolChain.h:512
virtual const char * getDefaultLinker() const
GetDefaultLinker - Get the default linker to use.
Definition ToolChain.h:546
const llvm::Triple & getTriple() const
Definition ToolChain.h:287
virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass a suitable profile runtime ...
OrderedMultilibs getOrderedMultilibs() const
Get selected multilibs in priority order with default fallback.
std::optional< std::string > getStdlibIncludePath() const
virtual RuntimeLibType GetDefaultRuntimeLibType() const
GetDefaultRuntimeLibType - Get the default runtime library variant to use.
Definition ToolChain.h:549
llvm::SmallVector< Multilib > SelectedMultilibs
Definition ToolChain.h:216
virtual std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, StringRef BoundArch={}, types::ID InputType=types::TY_INVALID) const
ComputeEffectiveClangTriple - Return the Clang triple to use for this target, which may take into acc...
const char * getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static, bool IsFortran=false) const
SanitizerArgs getSanitizerArgs(const llvm::opt::ArgList &JobArgs, StringRef BoundArch="", Action::OffloadKind DeviceOffloadKind=Action::OFK_None) const
SmallVector< std::string, 16 > path_list
Definition ToolChain.h:97
Tool - Information on a specific compilation tool.
Definition Tool.h:32
Generic_ELF(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition Gnu.h:439
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, llvm::StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition Gnu.cpp:3500
void AddMultilibPaths(const Driver &D, const std::string &SysRoot, const std::string &OSLibDir, const std::string &MultiarchTriple, path_list &Paths)
Definition Gnu.cpp:3133
LazyDetector< CudaInstallationDetector > CudaInstallation
Definition Gnu.h:358
void PushPPaths(ToolChain::path_list &PPaths)
Definition Gnu.cpp:3118
GCCInstallationDetector GCCInstallation
Definition Gnu.h:357
LazyDetector< SYCLInstallationDetector > SYCLInstallation
Definition Gnu.h:360
void AddMultilibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition Gnu.cpp:3213
void AddMultiarchPaths(const Driver &D, const std::string &SysRoot, const std::string &OSLibDir, path_list &Paths)
Definition Gnu.cpp:3198
bool addLibStdCXXIncludePaths(Twine IncludeDir, StringRef Triple, Twine IncludeSuffix, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, bool DetectDebian=false) const
Definition Gnu.cpp:3346
bool addGCCLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC) const
Definition Gnu.cpp:3433
LazyDetector< RocmInstallationDetector > RocmInstallation
Definition Gnu.h:359
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition Linux.cpp:936
std::vector< std::string > ExtraOpts
Definition Linux.h:73
const char * getDefaultLinker() const override
GetDefaultLinker - Get the default linker to use.
Definition Linux.cpp:1038
RuntimeLibType GetDefaultRuntimeLibType() const override
GetDefaultRuntimeLibType - Get the default runtime library variant to use.
Definition Linux.cpp:381
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition Linux.cpp:399
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition Linux.cpp:954
Tool * buildAssembler() const override
Definition Linux.cpp:407
std::string computeSysRoot() const override
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
Definition Linux.cpp:411
SanitizerMask getSupportedSanitizers(StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
Return sanitizers which are available in this toolchain.
Definition Linux.cpp:961
void addOffloadRTLibs(unsigned ActiveKinds, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
Add the system specific libraries for the active offload kinds.
Definition Linux.cpp:874
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition Linux.cpp:751
Linux(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition Linux.cpp:225
unsigned GetDefaultDwarfVersion() const override
Definition Linux.cpp:387
bool IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain supports outline atomics by default.
Definition Linux.cpp:941
void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass a suitable profile runtime ...
Definition Linux.cpp:1023
CXXStdlibType GetDefaultCXXStdlibType() const override
Definition Linux.cpp:393
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific HIP includes.
Definition Linux.cpp:869
std::string getDynamicLinker(const llvm::opt::ArgList &Args) const override
Definition Linux.cpp:564
Tool * buildStaticLibTool() const override
Definition Linux.cpp:403
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, llvm::StringRef BoundArch={}, types::ID InputType=types::TY_INVALID) const override
Definition Linux.cpp:486
void addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Definition Linux.cpp:830
void addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const override
Definition Linux.cpp:1033
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, llvm::StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition Linux.cpp:553
std::string getMultiarchTriple(const Driver &D, const llvm::Triple &TargetTriple, StringRef SysRoot) const override
Get our best guess at the multiarch triple for a target.
Definition Linux.cpp:40
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific SYCL includes.
Definition Linux.cpp:931
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use MCU GCC toolchain includes.
Definition Linux.cpp:921
Tool * buildLinker() const override
Definition Linux.cpp:401
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific CUDA includes.
Definition Linux.cpp:864
FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args)
StringRef getLoongArchABI(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
bool isNaN2008(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
bool hasMipsAbiArg(const llvm::opt::ArgList &Args, const char *Value)
std::string getMipsABILibSuffix(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
bool isUCLibc(const llvm::opt::ArgList &Args)
bool hasPPCAbiArg(const llvm::opt::ArgList &Args, const char *Value)
StringRef getRISCVABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
void addPathIfExists(const Driver &D, const Twine &Path, ToolChain::path_list &Paths)
The JSON file list parser is used to communicate input to InstallAPI.
Struct to store and manipulate GCC versions.
Definition Gnu.h:163
std::string Text
The unparsed text of the version.
Definition Gnu.h:165