/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/Linux.cpp
Line | Count | Source (jump to first uncovered line) |
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 "CommonArgs.h" |
16 | | #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" |
24 | | #include "llvm/Support/ScopedPrinter.h" |
25 | | #include "llvm/Support/VirtualFileSystem.h" |
26 | | #include <system_error> |
27 | | |
28 | | using namespace clang::driver; |
29 | | using namespace clang::driver::toolchains; |
30 | | using namespace clang; |
31 | | using namespace llvm::opt; |
32 | | |
33 | | using tools::addPathIfExists; |
34 | | |
35 | | /// Get our best guess at the multiarch triple for a target. |
36 | | /// |
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. |
41 | | std::string Linux::getMultiarchTriple(const Driver &D, |
42 | | const llvm::Triple &TargetTriple, |
43 | 11.1k | StringRef SysRoot) const { |
44 | 11.1k | llvm::Triple::EnvironmentType TargetEnvironment = |
45 | 11.1k | TargetTriple.getEnvironment(); |
46 | 11.1k | bool IsAndroid = TargetTriple.isAndroid(); |
47 | 11.1k | bool IsMipsR6 = TargetTriple.getSubArch() == llvm::Triple::MipsSubArch_r6; |
48 | 11.1k | bool IsMipsN32Abi = TargetTriple.getEnvironment() == llvm::Triple::GNUABIN32; |
49 | | |
50 | | // For most architectures, just use whatever we have rather than trying to be |
51 | | // clever. |
52 | 11.1k | switch (TargetTriple.getArch()) { |
53 | 448 | default: |
54 | 448 | break; |
55 | | |
56 | | // We use the existence of '/lib/<triple>' as a directory to detect some |
57 | | // common linux triples that don't quite match the Clang triple for both |
58 | | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
59 | | // regardless of what the actual target triple is. |
60 | 1.16k | case llvm::Triple::arm: |
61 | 1.19k | case llvm::Triple::thumb: |
62 | 1.19k | if (IsAndroid) |
63 | 176 | return "arm-linux-androideabi"; |
64 | 1.01k | if (TargetEnvironment == llvm::Triple::GNUEABIHF) |
65 | 90 | return "arm-linux-gnueabihf"; |
66 | 925 | return "arm-linux-gnueabi"; |
67 | 88 | case llvm::Triple::armeb: |
68 | 110 | case llvm::Triple::thumbeb: |
69 | 110 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) |
70 | 5 | return "armeb-linux-gnueabihf"; |
71 | 105 | return "armeb-linux-gnueabi"; |
72 | 853 | case llvm::Triple::x86: |
73 | 853 | if (IsAndroid) |
74 | 32 | return "i686-linux-android"; |
75 | 821 | return "i386-linux-gnu"; |
76 | 5.87k | case llvm::Triple::x86_64: |
77 | 5.87k | if (IsAndroid) |
78 | 36 | return "x86_64-linux-android"; |
79 | 5.84k | if (TargetEnvironment == llvm::Triple::GNUX32) |
80 | 25 | return "x86_64-linux-gnux32"; |
81 | 5.81k | return "x86_64-linux-gnu"; |
82 | 907 | case llvm::Triple::aarch64: |
83 | 907 | if (IsAndroid) |
84 | 158 | return "aarch64-linux-android"; |
85 | 749 | return "aarch64-linux-gnu"; |
86 | 16 | case llvm::Triple::aarch64_be: |
87 | 16 | return "aarch64_be-linux-gnu"; |
88 | | |
89 | 38 | case llvm::Triple::loongarch64: { |
90 | 38 | const char *Libc; |
91 | 38 | const char *FPFlavor; |
92 | | |
93 | 38 | if (TargetTriple.isGNUEnvironment()) { |
94 | 38 | Libc = "gnu"; |
95 | 38 | } else if (0 TargetTriple.isMusl()0 ) { |
96 | 0 | Libc = "musl"; |
97 | 0 | } else { |
98 | 0 | return TargetTriple.str(); |
99 | 0 | } |
100 | | |
101 | 38 | switch (TargetEnvironment) { |
102 | 0 | default: |
103 | 0 | return TargetTriple.str(); |
104 | 4 | case llvm::Triple::GNUSF: |
105 | 4 | FPFlavor = "sf"; |
106 | 4 | break; |
107 | 4 | case llvm::Triple::GNUF32: |
108 | 4 | FPFlavor = "f32"; |
109 | 4 | break; |
110 | 20 | case llvm::Triple::GNU: |
111 | 30 | case llvm::Triple::GNUF64: |
112 | | // This was going to be "f64" in an earlier Toolchain Conventions |
113 | | // revision, but starting from Feb 2023 the F64 ABI variants are |
114 | | // unmarked in their canonical forms. |
115 | 30 | FPFlavor = ""; |
116 | 30 | break; |
117 | 38 | } |
118 | | |
119 | 38 | return (Twine("loongarch64-linux-") + Libc + FPFlavor).str(); |
120 | 38 | } |
121 | | |
122 | 94 | case llvm::Triple::m68k: |
123 | 94 | return "m68k-linux-gnu"; |
124 | | |
125 | 418 | case llvm::Triple::mips: |
126 | 418 | return IsMipsR6 ? "mipsisa32r6-linux-gnu"2 : "mips-linux-gnu"416 ; |
127 | 62 | case llvm::Triple::mipsel: |
128 | 62 | return IsMipsR6 ? "mipsisa32r6el-linux-gnu"2 : "mipsel-linux-gnu"60 ; |
129 | 106 | case llvm::Triple::mips64: { |
130 | 106 | std::string MT = std::string(IsMipsR6 ? "mipsisa64r6"6 : "mips64"100 ) + |
131 | 106 | "-linux-" + (IsMipsN32Abi ? "gnuabin32"18 : "gnuabi64"88 ); |
132 | 106 | if (D.getVFS().exists(concat(SysRoot, "/lib", MT))) |
133 | 6 | return MT; |
134 | 100 | if (D.getVFS().exists(concat(SysRoot, "/lib/mips64-linux-gnu"))) |
135 | 0 | return "mips64-linux-gnu"; |
136 | 100 | break; |
137 | 100 | } |
138 | 100 | case llvm::Triple::mips64el: { |
139 | 70 | std::string MT = std::string(IsMipsR6 ? "mipsisa64r6el"6 : "mips64el"64 ) + |
140 | 70 | "-linux-" + (IsMipsN32Abi ? "gnuabin32"12 : "gnuabi64"58 ); |
141 | 70 | if (D.getVFS().exists(concat(SysRoot, "/lib", MT))) |
142 | 6 | return MT; |
143 | 64 | if (D.getVFS().exists(concat(SysRoot, "/lib/mips64el-linux-gnu"))) |
144 | 0 | return "mips64el-linux-gnu"; |
145 | 64 | break; |
146 | 64 | } |
147 | 66 | case llvm::Triple::ppc: |
148 | 66 | if (D.getVFS().exists(concat(SysRoot, "/lib/powerpc-linux-gnuspe"))) |
149 | 0 | return "powerpc-linux-gnuspe"; |
150 | 66 | return "powerpc-linux-gnu"; |
151 | 6 | case llvm::Triple::ppcle: |
152 | 6 | return "powerpcle-linux-gnu"; |
153 | 208 | case llvm::Triple::ppc64: |
154 | 208 | return "powerpc64-linux-gnu"; |
155 | 216 | case llvm::Triple::ppc64le: |
156 | 216 | return "powerpc64le-linux-gnu"; |
157 | 331 | case llvm::Triple::riscv64: |
158 | 331 | if (IsAndroid) |
159 | 24 | return "riscv64-linux-android"; |
160 | 307 | return "riscv64-linux-gnu"; |
161 | 26 | case llvm::Triple::sparc: |
162 | 26 | return "sparc-linux-gnu"; |
163 | 28 | case llvm::Triple::sparcv9: |
164 | 28 | return "sparc64-linux-gnu"; |
165 | 91 | case llvm::Triple::systemz: |
166 | 91 | return "s390x-linux-gnu"; |
167 | 11.1k | } |
168 | 612 | return TargetTriple.str(); |
169 | 11.1k | } |
170 | | |
171 | 5.38k | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { |
172 | 5.38k | if (Triple.isMIPS()) { |
173 | 374 | if (Triple.isAndroid()) { |
174 | 0 | StringRef CPUName; |
175 | 0 | StringRef ABIName; |
176 | 0 | tools::mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName); |
177 | 0 | if (CPUName == "mips32r6") |
178 | 0 | return "libr6"; |
179 | 0 | if (CPUName == "mips32r2") |
180 | 0 | return "libr2"; |
181 | 0 | } |
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 | 374 | if (tools::mips::hasMipsAbiArg(Args, "n32")) |
186 | 11 | return "lib32"; |
187 | 363 | return Triple.isArch32Bit() ? "lib"281 : "lib64"82 ; |
188 | 374 | } |
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 | 5.00k | if (Triple.getArch() == llvm::Triple::x86 || Triple.isPPC32()4.56k || |
200 | 5.00k | Triple.getArch() == llvm::Triple::sparc4.53k ) |
201 | 489 | return "lib32"; |
202 | | |
203 | 4.51k | if (Triple.getArch() == llvm::Triple::x86_64 && Triple.isX32()2.54k ) |
204 | 15 | return "libx32"; |
205 | | |
206 | 4.50k | if (Triple.getArch() == llvm::Triple::riscv32) |
207 | 122 | return "lib32"; |
208 | | |
209 | 4.38k | return Triple.isArch32Bit() ? "lib"908 : "lib64"3.47k ; |
210 | 4.50k | } |
211 | | |
212 | | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
213 | 5.38k | : Generic_ELF(D, Triple, Args) { |
214 | 5.38k | GCCInstallation.init(Triple, Args); |
215 | 5.38k | Multilibs = GCCInstallation.getMultilibs(); |
216 | 5.38k | SelectedMultilibs.assign({GCCInstallation.getMultilib()}); |
217 | 5.38k | llvm::Triple::ArchType Arch = Triple.getArch(); |
218 | 5.38k | std::string SysRoot = computeSysRoot(); |
219 | 5.38k | ToolChain::path_list &PPaths = getProgramPaths(); |
220 | | |
221 | 5.38k | Generic_GCC::PushPPaths(PPaths); |
222 | | |
223 | 5.38k | Distro Distro(D.getVFS(), Triple); |
224 | | |
225 | 5.38k | if (Distro.IsAlpineLinux() || Triple.isAndroid()) { |
226 | 223 | ExtraOpts.push_back("-z"); |
227 | 223 | ExtraOpts.push_back("now"); |
228 | 223 | } |
229 | | |
230 | 5.38k | if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() || |
231 | 5.38k | Triple.isAndroid()) { |
232 | 223 | ExtraOpts.push_back("-z"); |
233 | 223 | ExtraOpts.push_back("relro"); |
234 | 223 | } |
235 | | |
236 | | // Android ARM/AArch64 use max-page-size=4096 to reduce VMA usage. Note, lld |
237 | | // from 11 onwards default max-page-size to 65536 for both ARM and AArch64. |
238 | 5.38k | if ((Triple.isARM() || Triple.isAArch64()4.71k ) && Triple.isAndroid()1.14k ) { |
239 | 173 | ExtraOpts.push_back("-z"); |
240 | 173 | ExtraOpts.push_back("max-page-size=4096"); |
241 | 173 | } |
242 | | |
243 | 5.38k | if (GCCInstallation.getParentLibPath().contains("opt/rh/")) |
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 | 1 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + |
249 | 1 | "/../bin").str()); |
250 | | |
251 | 5.38k | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb4.75k ) |
252 | 639 | ExtraOpts.push_back("-X"); |
253 | | |
254 | 5.38k | const bool IsAndroid = Triple.isAndroid(); |
255 | 5.38k | const bool IsMips = Triple.isMIPS(); |
256 | 5.38k | const bool IsHexagon = Arch == llvm::Triple::hexagon; |
257 | 5.38k | const bool IsRISCV = Triple.isRISCV(); |
258 | 5.38k | const bool IsCSKY = Triple.isCSKY(); |
259 | | |
260 | 5.38k | if (IsCSKY && !SelectedMultilibs.empty()15 ) |
261 | 15 | SysRoot = SysRoot + SelectedMultilibs.back().osSuffix(); |
262 | | |
263 | 5.38k | if ((IsMips || IsCSKY5.00k ) && !SysRoot.empty()389 ) |
264 | 30 | ExtraOpts.push_back("--sysroot=" + SysRoot); |
265 | | |
266 | | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
267 | | // and the MIPS ABI require .dynsym to be sorted in different ways. |
268 | | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
269 | | // ABI requires a mapping between the GOT and the symbol table. |
270 | | // Android loader does not support .gnu.hash until API 23. |
271 | | // Hexagon linker/loader does not support .gnu.hash |
272 | 5.38k | if (!IsMips && !IsHexagon5.00k ) { |
273 | 4.87k | if (Distro.IsOpenSUSE() || Distro == Distro::UbuntuLucid || |
274 | 4.87k | Distro == Distro::UbuntuJaunty || Distro == Distro::UbuntuKarmic || |
275 | 4.87k | (IsAndroid && Triple.isAndroidVersionLT(23)223 )) |
276 | 191 | ExtraOpts.push_back("--hash-style=both"); |
277 | 4.67k | else |
278 | 4.67k | ExtraOpts.push_back("--hash-style=gnu"); |
279 | 4.87k | } |
280 | | |
281 | | #ifdef ENABLE_LINKER_BUILD_ID |
282 | | ExtraOpts.push_back("--build-id"); |
283 | | #endif |
284 | | |
285 | | // The selection of paths to try here is designed to match the patterns which |
286 | | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
287 | | // This was determined by running GCC in a fake filesystem, creating all |
288 | | // possible permutations of these directories, and seeing which ones it added |
289 | | // to the link paths. |
290 | 5.38k | path_list &Paths = getFilePaths(); |
291 | | |
292 | 5.38k | const std::string OSLibDir = std::string(getOSLibDir(Triple, Args)); |
293 | 5.38k | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); |
294 | | |
295 | | // mips32: Debian multilib, we use /libo32, while in other case, /lib is |
296 | | // used. We need add both libo32 and /lib. |
297 | 5.38k | if (Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel5.13k ) { |
298 | 281 | Generic_GCC::AddMultilibPaths(D, SysRoot, "libo32", MultiarchTriple, Paths); |
299 | 281 | addPathIfExists(D, concat(SysRoot, "/libo32"), Paths); |
300 | 281 | addPathIfExists(D, concat(SysRoot, "/usr/libo32"), Paths); |
301 | 281 | } |
302 | 5.38k | Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths); |
303 | | |
304 | 5.38k | addPathIfExists(D, concat(SysRoot, "/lib", MultiarchTriple), Paths); |
305 | 5.38k | addPathIfExists(D, concat(SysRoot, "/lib/..", OSLibDir), Paths); |
306 | | |
307 | 5.38k | if (IsAndroid) { |
308 | | // Android sysroots contain a library directory for each supported OS |
309 | | // version as well as some unversioned libraries in the usual multiarch |
310 | | // directory. |
311 | 223 | addPathIfExists( |
312 | 223 | D, |
313 | 223 | concat(SysRoot, "/usr/lib", MultiarchTriple, |
314 | 223 | llvm::to_string(Triple.getEnvironmentVersion().getMajor())), |
315 | 223 | Paths); |
316 | 223 | } |
317 | | |
318 | 5.38k | addPathIfExists(D, concat(SysRoot, "/usr/lib", MultiarchTriple), Paths); |
319 | | // 64-bit OpenEmbedded sysroots may not have a /usr/lib dir. So they cannot |
320 | | // find /usr/lib64 as it is referenced as /usr/lib/../lib64. So we handle |
321 | | // this here. |
322 | 5.38k | if (Triple.getVendor() == llvm::Triple::OpenEmbedded && |
323 | 5.38k | Triple.isArch64Bit()4 ) |
324 | 2 | addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir), Paths); |
325 | 5.37k | else |
326 | 5.37k | addPathIfExists(D, concat(SysRoot, "/usr/lib/..", OSLibDir), Paths); |
327 | 5.38k | if (IsRISCV) { |
328 | 288 | StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple); |
329 | 288 | addPathIfExists(D, concat(SysRoot, "/", OSLibDir, ABIName), Paths); |
330 | 288 | addPathIfExists(D, concat(SysRoot, "/usr", OSLibDir, ABIName), Paths); |
331 | 288 | } |
332 | | |
333 | 5.38k | Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths); |
334 | | |
335 | 5.38k | addPathIfExists(D, concat(SysRoot, "/lib"), Paths); |
336 | 5.38k | addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths); |
337 | 5.38k | } |
338 | | |
339 | 1.78k | ToolChain::RuntimeLibType Linux::GetDefaultRuntimeLibType() const { |
340 | 1.78k | if (getTriple().isAndroid()) |
341 | 158 | return ToolChain::RLT_CompilerRT; |
342 | 1.62k | return Generic_ELF::GetDefaultRuntimeLibType(); |
343 | 1.78k | } |
344 | | |
345 | 272 | unsigned Linux::GetDefaultDwarfVersion() const { |
346 | 272 | if (getTriple().isAndroid()) |
347 | 1 | return 4; |
348 | 271 | return ToolChain::GetDefaultDwarfVersion(); |
349 | 272 | } |
350 | | |
351 | 1.62k | ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const { |
352 | 1.62k | if (getTriple().isAndroid()) |
353 | 27 | return ToolChain::CST_Libcxx; |
354 | 1.59k | return ToolChain::CST_Libstdcxx; |
355 | 1.62k | } |
356 | | |
357 | 1.63k | bool Linux::HasNativeLLVMSupport() const { return true; } |
358 | | |
359 | 1.54k | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } |
360 | | |
361 | 7 | Tool *Linux::buildStaticLibTool() const { |
362 | 7 | return new tools::gnutools::StaticLibTool(*this); |
363 | 7 | } |
364 | | |
365 | 180 | Tool *Linux::buildAssembler() const { |
366 | 180 | return new tools::gnutools::Assembler(*this); |
367 | 180 | } |
368 | | |
369 | 11.2k | std::string Linux::computeSysRoot() const { |
370 | 11.2k | if (!getDriver().SysRoot.empty()) |
371 | 772 | return getDriver().SysRoot; |
372 | | |
373 | 10.4k | if (getTriple().isAndroid()) { |
374 | | // Android toolchains typically include a sysroot at ../sysroot relative to |
375 | | // the clang binary. |
376 | 252 | const StringRef ClangDir = getDriver().getInstalledDir(); |
377 | 252 | std::string AndroidSysRootPath = (ClangDir + "/../sysroot").str(); |
378 | 252 | if (getVFS().exists(AndroidSysRootPath)) |
379 | 0 | return AndroidSysRootPath; |
380 | 252 | } |
381 | | |
382 | 10.4k | if (getTriple().isCSKY()) { |
383 | | // CSKY toolchains use different names for sysroot folder. |
384 | 30 | if (!GCCInstallation.isValid()) |
385 | 26 | return std::string(); |
386 | | // GCCInstallation.getInstallPath() = |
387 | | // $GCCToolchainPath/lib/gcc/csky-linux-gnuabiv2/6.3.0 |
388 | | // Path = $GCCToolchainPath/csky-linux-gnuabiv2/libc |
389 | 4 | std::string Path = (GCCInstallation.getInstallPath() + "/../../../../" + |
390 | 4 | GCCInstallation.getTriple().str() + "/libc") |
391 | 4 | .str(); |
392 | 4 | if (getVFS().exists(Path)) |
393 | 4 | return Path; |
394 | 0 | return std::string(); |
395 | 4 | } |
396 | | |
397 | 10.4k | if (!GCCInstallation.isValid() || !getTriple().isMIPS()90 ) |
398 | 10.3k | return std::string(); |
399 | | |
400 | | // Standalone MIPS toolchains use different names for sysroot folder |
401 | | // and put it into different places. Here we try to check some known |
402 | | // variants. |
403 | | |
404 | 32 | const StringRef InstallDir = GCCInstallation.getInstallPath(); |
405 | 32 | const StringRef TripleStr = GCCInstallation.getTriple().str(); |
406 | 32 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
407 | | |
408 | 32 | std::string Path = |
409 | 32 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) |
410 | 32 | .str(); |
411 | | |
412 | 32 | if (getVFS().exists(Path)) |
413 | 0 | return Path; |
414 | | |
415 | 32 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); |
416 | | |
417 | 32 | if (getVFS().exists(Path)) |
418 | 32 | return Path; |
419 | | |
420 | 0 | return std::string(); |
421 | 32 | } |
422 | | |
423 | 1.46k | std::string Linux::getDynamicLinker(const ArgList &Args) const { |
424 | 1.46k | const llvm::Triple::ArchType Arch = getArch(); |
425 | 1.46k | const llvm::Triple &Triple = getTriple(); |
426 | | |
427 | 1.46k | const Distro Distro(getDriver().getVFS(), Triple); |
428 | | |
429 | 1.46k | if (Triple.isAndroid()) { |
430 | 118 | if (getSanitizerArgs(Args).needsHwasanRt() && |
431 | 118 | !Triple.isAndroidVersionLT(34)3 && Triple.isArch64Bit()1 ) { |
432 | | // On Android 14 and newer, there is a special linker_hwasan64 that |
433 | | // allows to run HWASan binaries on non-HWASan system images. This |
434 | | // is also available on HWASan system images, so we can just always |
435 | | // use that instead. |
436 | 1 | return "/system/bin/linker_hwasan64"; |
437 | 1 | } |
438 | 117 | return Triple.isArch64Bit() ? "/system/bin/linker64"52 : "/system/bin/linker"65 ; |
439 | 118 | } |
440 | 1.34k | if (Triple.isMusl()) { |
441 | 31 | std::string ArchName; |
442 | 31 | bool IsArm = false; |
443 | | |
444 | 31 | switch (Arch) { |
445 | 4 | case llvm::Triple::arm: |
446 | 7 | case llvm::Triple::thumb: |
447 | 7 | ArchName = "arm"; |
448 | 7 | IsArm = true; |
449 | 7 | break; |
450 | 3 | case llvm::Triple::armeb: |
451 | 6 | case llvm::Triple::thumbeb: |
452 | 6 | ArchName = "armeb"; |
453 | 6 | IsArm = true; |
454 | 6 | break; |
455 | 2 | case llvm::Triple::x86: |
456 | 2 | ArchName = "i386"; |
457 | 2 | break; |
458 | 6 | case llvm::Triple::x86_64: |
459 | 6 | ArchName = Triple.isX32() ? "x32"2 : Triple.getArchName().str()4 ; |
460 | 6 | break; |
461 | 10 | default: |
462 | 10 | ArchName = Triple.getArchName().str(); |
463 | 31 | } |
464 | 31 | if (IsArm && |
465 | 31 | (13 Triple.getEnvironment() == llvm::Triple::MuslEABIHF13 || |
466 | 13 | tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard8 )) |
467 | 9 | ArchName += "hf"; |
468 | 31 | if (Arch == llvm::Triple::ppc && |
469 | 31 | Triple.getSubArch() == llvm::Triple::PPCSubArch_spe2 ) |
470 | 1 | ArchName = "powerpc-sf"; |
471 | | |
472 | 31 | return "/lib/ld-musl-" + ArchName + ".so.1"; |
473 | 31 | } |
474 | | |
475 | 1.31k | std::string LibDir; |
476 | 1.31k | std::string Loader; |
477 | | |
478 | 1.31k | switch (Arch) { |
479 | 0 | default: |
480 | 0 | llvm_unreachable("unsupported architecture"); |
481 | |
|
482 | 89 | case llvm::Triple::aarch64: |
483 | 89 | LibDir = "lib"; |
484 | 89 | Loader = "ld-linux-aarch64.so.1"; |
485 | 89 | break; |
486 | 3 | case llvm::Triple::aarch64_be: |
487 | 3 | LibDir = "lib"; |
488 | 3 | Loader = "ld-linux-aarch64_be.so.1"; |
489 | 3 | break; |
490 | 131 | case llvm::Triple::arm: |
491 | 133 | case llvm::Triple::thumb: |
492 | 139 | case llvm::Triple::armeb: |
493 | 141 | case llvm::Triple::thumbeb: { |
494 | 141 | const bool HF = |
495 | 141 | Triple.getEnvironment() == llvm::Triple::GNUEABIHF || |
496 | 141 | tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard123 ; |
497 | | |
498 | 141 | LibDir = "lib"; |
499 | 141 | Loader = HF ? "ld-linux-armhf.so.3"20 : "ld-linux.so.3"121 ; |
500 | 141 | break; |
501 | 139 | } |
502 | 0 | case llvm::Triple::loongarch32: { |
503 | 0 | LibDir = "lib32"; |
504 | 0 | Loader = |
505 | 0 | ("ld-linux-loongarch-" + |
506 | 0 | tools::loongarch::getLoongArchABI(getDriver(), Args, Triple) + ".so.1") |
507 | 0 | .str(); |
508 | 0 | break; |
509 | 139 | } |
510 | 10 | case llvm::Triple::loongarch64: { |
511 | 10 | LibDir = "lib64"; |
512 | 10 | Loader = |
513 | 10 | ("ld-linux-loongarch-" + |
514 | 10 | tools::loongarch::getLoongArchABI(getDriver(), Args, Triple) + ".so.1") |
515 | 10 | .str(); |
516 | 10 | break; |
517 | 139 | } |
518 | 24 | case llvm::Triple::m68k: |
519 | 24 | LibDir = "lib"; |
520 | 24 | Loader = "ld.so.1"; |
521 | 24 | break; |
522 | 11 | case llvm::Triple::mips: |
523 | 26 | case llvm::Triple::mipsel: |
524 | 37 | case llvm::Triple::mips64: |
525 | 51 | case llvm::Triple::mips64el: { |
526 | 51 | bool IsNaN2008 = tools::mips::isNaN2008(getDriver(), Args, Triple); |
527 | | |
528 | 51 | LibDir = "lib" + tools::mips::getMipsABILibSuffix(Args, Triple); |
529 | | |
530 | 51 | if (tools::mips::isUCLibc(Args)) |
531 | 4 | Loader = IsNaN2008 ? "ld-uClibc-mipsn8.so.0"2 : "ld-uClibc.so.0"2 ; |
532 | 47 | else if (!Triple.hasEnvironment() && |
533 | 47 | Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies3 ) |
534 | 0 | Loader = |
535 | 0 | Triple.isLittleEndian() ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1"; |
536 | 47 | else |
537 | 47 | Loader = IsNaN2008 ? "ld-linux-mipsn8.so.1"8 : "ld.so.1"39 ; |
538 | | |
539 | 51 | break; |
540 | 37 | } |
541 | 17 | case llvm::Triple::ppc: |
542 | 17 | LibDir = "lib"; |
543 | 17 | Loader = "ld.so.1"; |
544 | 17 | break; |
545 | 3 | case llvm::Triple::ppcle: |
546 | 3 | LibDir = "lib"; |
547 | 3 | Loader = "ld.so.1"; |
548 | 3 | break; |
549 | 50 | case llvm::Triple::ppc64: |
550 | 50 | LibDir = "lib64"; |
551 | 50 | Loader = |
552 | 50 | (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2"3 : "ld64.so.1"47 ; |
553 | 50 | break; |
554 | 44 | case llvm::Triple::ppc64le: |
555 | 44 | LibDir = "lib64"; |
556 | 44 | Loader = |
557 | 44 | (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1"4 : "ld64.so.2"40 ; |
558 | 44 | break; |
559 | 4 | case llvm::Triple::riscv32: { |
560 | 4 | StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple); |
561 | 4 | LibDir = "lib"; |
562 | 4 | Loader = ("ld-linux-riscv32-" + ABIName + ".so.1").str(); |
563 | 4 | break; |
564 | 37 | } |
565 | 13 | case llvm::Triple::riscv64: { |
566 | 13 | StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple); |
567 | 13 | LibDir = "lib"; |
568 | 13 | Loader = ("ld-linux-riscv64-" + ABIName + ".so.1").str(); |
569 | 13 | break; |
570 | 37 | } |
571 | 1 | case llvm::Triple::sparc: |
572 | 2 | case llvm::Triple::sparcel: |
573 | 2 | LibDir = "lib"; |
574 | 2 | Loader = "ld-linux.so.2"; |
575 | 2 | break; |
576 | 1 | case llvm::Triple::sparcv9: |
577 | 1 | LibDir = "lib64"; |
578 | 1 | Loader = "ld-linux.so.2"; |
579 | 1 | break; |
580 | 10 | case llvm::Triple::systemz: |
581 | 10 | LibDir = "lib"; |
582 | 10 | Loader = "ld64.so.1"; |
583 | 10 | break; |
584 | 128 | case llvm::Triple::x86: |
585 | 128 | LibDir = "lib"; |
586 | 128 | Loader = "ld-linux.so.2"; |
587 | 128 | break; |
588 | 710 | case llvm::Triple::x86_64: { |
589 | 710 | bool X32 = Triple.isX32(); |
590 | | |
591 | 710 | LibDir = X32 ? "libx32"11 : "lib64"699 ; |
592 | 710 | Loader = X32 ? "ld-linux-x32.so.2"11 : "ld-linux-x86-64.so.2"699 ; |
593 | 710 | break; |
594 | 1 | } |
595 | 2 | case llvm::Triple::ve: |
596 | 2 | return "/opt/nec/ve/lib/ld-linux-ve.so.1"; |
597 | 14 | case llvm::Triple::csky: { |
598 | 14 | LibDir = "lib"; |
599 | 14 | Loader = "ld.so.1"; |
600 | 14 | break; |
601 | 1 | } |
602 | 1.31k | } |
603 | | |
604 | 1.31k | if (Distro == Distro::Exherbo && |
605 | 1.31k | (0 Triple.getVendor() == llvm::Triple::UnknownVendor0 || |
606 | 0 | Triple.getVendor() == llvm::Triple::PC)) |
607 | 0 | return "/usr/" + Triple.str() + "/lib/" + Loader; |
608 | 1.31k | return "/" + LibDir + "/" + Loader; |
609 | 1.31k | } |
610 | | |
611 | | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
612 | 5.78k | ArgStringList &CC1Args) const { |
613 | 5.78k | const Driver &D = getDriver(); |
614 | 5.78k | std::string SysRoot = computeSysRoot(); |
615 | | |
616 | 5.78k | if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) |
617 | 2 | return; |
618 | | |
619 | | // Add 'include' in the resource directory, which is similar to |
620 | | // GCC_INCLUDE_DIR (private headers) in GCC. Note: the include directory |
621 | | // contains some files conflicting with system /usr/include. musl systems |
622 | | // prefer the /usr/include copies which are more relevant. |
623 | 5.78k | SmallString<128> ResourceDirInclude(D.ResourceDir); |
624 | 5.78k | llvm::sys::path::append(ResourceDirInclude, "include"); |
625 | 5.78k | if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && |
626 | 5.78k | (5.77k !getTriple().isMusl()5.77k || DriverArgs.hasArg(options::OPT_nostdlibinc)45 )) |
627 | 5.73k | addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); |
628 | | |
629 | 5.78k | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
630 | 1 | return; |
631 | | |
632 | | // LOCAL_INCLUDE_DIR |
633 | 5.78k | addSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/local/include")); |
634 | | // TOOL_INCLUDE_DIR |
635 | 5.78k | AddMultilibIncludeArgs(DriverArgs, CC1Args); |
636 | | |
637 | | // Check for configure-time C include directories. |
638 | 5.78k | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
639 | 5.78k | if (CIncludeDirs != "") { |
640 | 0 | SmallVector<StringRef, 5> dirs; |
641 | 0 | CIncludeDirs.split(dirs, ":"); |
642 | 0 | for (StringRef dir : dirs) { |
643 | 0 | StringRef Prefix = |
644 | 0 | llvm::sys::path::is_absolute(dir) ? "" : StringRef(SysRoot); |
645 | 0 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
646 | 0 | } |
647 | 0 | return; |
648 | 0 | } |
649 | | |
650 | | // On systems using multiarch and Android, add /usr/include/$triple before |
651 | | // /usr/include. |
652 | 5.78k | std::string MultiarchIncludeDir = getMultiarchTriple(D, getTriple(), SysRoot); |
653 | 5.78k | if (!MultiarchIncludeDir.empty() && |
654 | 5.78k | D.getVFS().exists(concat(SysRoot, "/usr/include", MultiarchIncludeDir))) |
655 | 49 | addExternCSystemInclude( |
656 | 49 | DriverArgs, CC1Args, |
657 | 49 | concat(SysRoot, "/usr/include", MultiarchIncludeDir)); |
658 | | |
659 | 5.78k | if (getTriple().getOS() == llvm::Triple::RTEMS) |
660 | 0 | return; |
661 | | |
662 | | // Add an include of '/include' directly. This isn't provided by default by |
663 | | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
664 | | // add even when Clang is acting as-if it were a system compiler. |
665 | 5.78k | addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include")); |
666 | | |
667 | 5.78k | addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include")); |
668 | | |
669 | 5.78k | if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl()5.77k ) |
670 | 44 | addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); |
671 | 5.78k | } |
672 | | |
673 | | void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
674 | 2.59k | llvm::opt::ArgStringList &CC1Args) const { |
675 | | // We need a detected GCC installation on Linux to provide libstdc++'s |
676 | | // headers in odd Linuxish places. |
677 | 2.59k | if (!GCCInstallation.isValid()) |
678 | 2.52k | return; |
679 | | |
680 | | // Detect Debian g++-multiarch-incdir.diff. |
681 | 67 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
682 | 67 | StringRef DebianMultiarch = |
683 | 67 | GCCInstallation.getTriple().getArch() == llvm::Triple::x86 |
684 | 67 | ? "i386-linux-gnu"7 |
685 | 67 | : TripleStr60 ; |
686 | | |
687 | | // Try generic GCC detection first. |
688 | 67 | if (Generic_GCC::addGCCLibStdCxxIncludePaths(DriverArgs, CC1Args, |
689 | 67 | DebianMultiarch)) |
690 | 53 | return; |
691 | | |
692 | 14 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
693 | 14 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
694 | 14 | const GCCVersion &Version = GCCInstallation.getVersion(); |
695 | | |
696 | 14 | const std::string LibStdCXXIncludePathCandidates[] = { |
697 | | // Android standalone toolchain has C++ headers in yet another place. |
698 | 14 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
699 | | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, |
700 | | // without a subdirectory corresponding to the gcc version. |
701 | 14 | LibDir.str() + "/../include/c++", |
702 | | // Cray's gcc installation puts headers under "g++" without a |
703 | | // version suffix. |
704 | 14 | LibDir.str() + "/../include/g++", |
705 | 14 | }; |
706 | | |
707 | 42 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { |
708 | 42 | if (addLibStdCXXIncludePaths(IncludePath, TripleStr, |
709 | 42 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
710 | 1 | break; |
711 | 42 | } |
712 | 14 | } |
713 | | |
714 | | void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, |
715 | 38 | ArgStringList &CC1Args) const { |
716 | 38 | CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args); |
717 | 38 | } |
718 | | |
719 | | void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs, |
720 | 207 | ArgStringList &CC1Args) const { |
721 | 207 | RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args); |
722 | 207 | } |
723 | | |
724 | | void Linux::AddHIPRuntimeLibArgs(const ArgList &Args, |
725 | 151 | ArgStringList &CmdArgs) const { |
726 | 151 | CmdArgs.push_back( |
727 | 151 | Args.MakeArgString(StringRef("-L") + RocmInstallation->getLibPath())); |
728 | | |
729 | 151 | if (Args.hasFlag(options::OPT_frtlib_add_rpath, |
730 | 151 | options::OPT_fno_rtlib_add_rpath, false)) |
731 | 2 | CmdArgs.append( |
732 | 2 | {"-rpath", Args.MakeArgString(RocmInstallation->getLibPath())}); |
733 | | |
734 | 151 | CmdArgs.push_back("-lamdhip64"); |
735 | 151 | } |
736 | | |
737 | | void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs, |
738 | 9 | ArgStringList &CC1Args) const { |
739 | 9 | if (GCCInstallation.isValid()) { |
740 | 0 | CC1Args.push_back("-isystem"); |
741 | 0 | CC1Args.push_back(DriverArgs.MakeArgString( |
742 | 0 | GCCInstallation.getParentLibPath() + "/../" + |
743 | 0 | GCCInstallation.getTriple().str() + "/include")); |
744 | 0 | } |
745 | 9 | } |
746 | | |
747 | 6.95k | bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const { |
748 | 6.95k | return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid()0 || |
749 | 6.95k | getTriple().isMusl()0 || getSanitizerArgs(Args).requiresPIE()0 ; |
750 | 6.95k | } |
751 | | |
752 | 442 | bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const { |
753 | | // Outline atomics for AArch64 are supported by compiler-rt |
754 | | // and libgcc since 9.3.1 |
755 | 442 | assert(getTriple().isAArch64() && "expected AArch64 target!"); |
756 | 442 | ToolChain::RuntimeLibType RtLib = GetRuntimeLibType(Args); |
757 | 442 | if (RtLib == ToolChain::RLT_CompilerRT) |
758 | 75 | return true; |
759 | 367 | assert(RtLib == ToolChain::RLT_Libgcc && "unexpected runtime library type!"); |
760 | 367 | if (GCCInstallation.getVersion().isOlderThan(9, 3, 1)) |
761 | 364 | return false; |
762 | 3 | return true; |
763 | 367 | } |
764 | | |
765 | 4.99k | bool Linux::IsMathErrnoDefault() const { |
766 | 4.99k | if (getTriple().isAndroid() || getTriple().isMusl()4.78k ) |
767 | 259 | return false; |
768 | 4.73k | return Generic_ELF::IsMathErrnoDefault(); |
769 | 4.99k | } |
770 | | |
771 | 8.71k | SanitizerMask Linux::getSupportedSanitizers() const { |
772 | 8.71k | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
773 | 8.71k | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
774 | 8.71k | const bool IsMIPS = getTriple().isMIPS32(); |
775 | 8.71k | const bool IsMIPS64 = getTriple().isMIPS64(); |
776 | 8.71k | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || |
777 | 8.71k | getTriple().getArch() == llvm::Triple::ppc64le8.50k ; |
778 | 8.71k | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || |
779 | 8.71k | getTriple().getArch() == llvm::Triple::aarch64_be7.96k ; |
780 | 8.71k | const bool IsArmArch = getTriple().getArch() == llvm::Triple::arm || |
781 | 8.71k | getTriple().getArch() == llvm::Triple::thumb7.72k || |
782 | 8.71k | getTriple().getArch() == llvm::Triple::armeb7.69k || |
783 | 8.71k | getTriple().getArch() == llvm::Triple::thumbeb7.63k ; |
784 | 8.71k | const bool IsLoongArch64 = getTriple().getArch() == llvm::Triple::loongarch64; |
785 | 8.71k | const bool IsRISCV64 = getTriple().getArch() == llvm::Triple::riscv64; |
786 | 8.71k | const bool IsSystemZ = getTriple().getArch() == llvm::Triple::systemz; |
787 | 8.71k | const bool IsHexagon = getTriple().getArch() == llvm::Triple::hexagon; |
788 | 8.71k | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
789 | 8.71k | Res |= SanitizerKind::Address; |
790 | 8.71k | Res |= SanitizerKind::PointerCompare; |
791 | 8.71k | Res |= SanitizerKind::PointerSubtract; |
792 | 8.71k | Res |= SanitizerKind::Fuzzer; |
793 | 8.71k | Res |= SanitizerKind::FuzzerNoLink; |
794 | 8.71k | Res |= SanitizerKind::KernelAddress; |
795 | 8.71k | Res |= SanitizerKind::Memory; |
796 | 8.71k | Res |= SanitizerKind::Vptr; |
797 | 8.71k | Res |= SanitizerKind::SafeStack; |
798 | 8.71k | if (IsX86_64 || IsMIPS644.31k || IsAArch644.17k || IsLoongArch643.40k ) |
799 | 5.35k | Res |= SanitizerKind::DataFlow; |
800 | 8.71k | if (IsX86_64 || IsMIPS644.31k || IsAArch644.17k || IsX863.40k || IsArmArch2.65k || IsPowerPC641.55k || |
801 | 8.71k | IsRISCV641.15k || IsSystemZ954 || IsHexagon890 || IsLoongArch64699 ) |
802 | 8.05k | Res |= SanitizerKind::Leak; |
803 | 8.71k | if (IsX86_64 || IsMIPS644.31k || IsAArch644.17k || IsPowerPC643.40k || IsSystemZ3.00k || |
804 | 8.71k | IsLoongArch642.93k ) |
805 | 5.81k | Res |= SanitizerKind::Thread; |
806 | 8.71k | if (IsX86_64 || IsSystemZ4.31k ) |
807 | 4.46k | Res |= SanitizerKind::KernelMemory; |
808 | 8.71k | if (IsX86_64 || IsMIPS644.31k || IsAArch644.17k || IsX863.40k || IsMIPS2.65k || IsArmArch2.40k || |
809 | 8.71k | IsPowerPC641.29k || IsHexagon899 || IsLoongArch64708 || IsRISCV64669 ) |
810 | 8.25k | Res |= SanitizerKind::Scudo; |
811 | 8.71k | if (IsX86_64 || IsAArch644.31k || IsRISCV643.54k ) { |
812 | 5.37k | Res |= SanitizerKind::HWAddress; |
813 | 5.37k | } |
814 | 8.71k | if (IsX86_64 || IsAArch644.31k ) { |
815 | 5.17k | Res |= SanitizerKind::KernelHWAddress; |
816 | 5.17k | } |
817 | | // Work around "Cannot represent a difference across sections". |
818 | 8.71k | if (getTriple().getArch() == llvm::Triple::ppc64) |
819 | 210 | Res &= ~SanitizerKind::Function; |
820 | 8.71k | return Res; |
821 | 8.71k | } |
822 | | |
823 | | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, |
824 | 1.53k | llvm::opt::ArgStringList &CmdArgs) const { |
825 | | // Add linker option -u__llvm_profile_runtime to cause runtime |
826 | | // initialization module to be linked in. |
827 | 1.53k | if (needsProfileRT(Args)) |
828 | 7 | CmdArgs.push_back(Args.MakeArgString( |
829 | 7 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); |
830 | 1.53k | ToolChain::addProfileRTLibs(Args, CmdArgs); |
831 | 1.53k | } |
832 | | |
833 | | llvm::DenormalMode |
834 | | Linux::getDefaultDenormalModeForType(const llvm::opt::ArgList &DriverArgs, |
835 | | const JobAction &JA, |
836 | 9.96k | const llvm::fltSemantics *FPType) const { |
837 | 9.96k | switch (getTriple().getArch()) { |
838 | 818 | case llvm::Triple::x86: |
839 | 5.62k | case llvm::Triple::x86_64: { |
840 | 5.62k | std::string Unused; |
841 | | // DAZ and FTZ are turned on in crtfastmath.o |
842 | 5.62k | if (!DriverArgs.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) && |
843 | 5.62k | isFastMathRuntimeAvailable(DriverArgs, Unused)5.60k ) |
844 | 20 | return llvm::DenormalMode::getPreserveSign(); |
845 | 5.60k | return llvm::DenormalMode::getIEEE(); |
846 | 5.62k | } |
847 | 4.34k | default: |
848 | 4.34k | return llvm::DenormalMode::getIEEE(); |
849 | 9.96k | } |
850 | 9.96k | } |
851 | | |
852 | 1.53k | void Linux::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const { |
853 | 1.53k | for (const auto &Opt : ExtraOpts) |
854 | 2.51k | CmdArgs.push_back(Opt.c_str()); |
855 | 1.53k | } |
856 | | |
857 | 1.57k | const char *Linux::getDefaultLinker() const { |
858 | 1.57k | if (getTriple().isAndroid()) |
859 | 141 | return "ld.lld"; |
860 | 1.43k | return Generic_ELF::getDefaultLinker(); |
861 | 1.57k | } |