Coverage Report

Created: 2021-01-19 06:58

/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/Mips.h"
12
#include "Arch/PPC.h"
13
#include "Arch/RISCV.h"
14
#include "CommonArgs.h"
15
#include "clang/Config/config.h"
16
#include "clang/Driver/Distro.h"
17
#include "clang/Driver/Driver.h"
18
#include "clang/Driver/Options.h"
19
#include "clang/Driver/SanitizerArgs.h"
20
#include "llvm/Option/ArgList.h"
21
#include "llvm/ProfileData/InstrProf.h"
22
#include "llvm/Support/Path.h"
23
#include "llvm/Support/ScopedPrinter.h"
24
#include "llvm/Support/VirtualFileSystem.h"
25
#include <system_error>
26
27
using namespace clang::driver;
28
using namespace clang::driver::toolchains;
29
using namespace clang;
30
using namespace llvm::opt;
31
32
using tools::addPathIfExists;
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.
40
std::string Linux::getMultiarchTriple(const Driver &D,
41
                                      const llvm::Triple &TargetTriple,
42
10.5k
                                      StringRef SysRoot) const {
43
10.5k
  llvm::Triple::EnvironmentType TargetEnvironment =
44
10.5k
      TargetTriple.getEnvironment();
45
10.5k
  bool IsAndroid = TargetTriple.isAndroid();
46
10.5k
  bool IsMipsR6 = TargetTriple.getSubArch() == llvm::Triple::MipsSubArch_r6;
47
10.5k
  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
10.5k
  switch (TargetTriple.getArch()) {
52
240
  default:
53
240
    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
1.08k
  case llvm::Triple::arm:
60
1.11k
  case llvm::Triple::thumb:
61
1.11k
    if (IsAndroid) {
62
200
      return "arm-linux-androideabi";
63
911
    } else if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
64
90
      if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf"))
65
5
        return "arm-linux-gnueabihf";
66
821
    } else {
67
821
      if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi"))
68
3
        return "arm-linux-gnueabi";
69
903
    }
70
903
    break;
71
86
  case llvm::Triple::armeb:
72
108
  case llvm::Triple::thumbeb:
73
108
    if (TargetEnvironment == llvm::Triple::GNUEABIHF) {
74
4
      if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf"))
75
0
        return "armeb-linux-gnueabihf";
76
104
    } else {
77
104
      if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi"))
78
0
        return "armeb-linux-gnueabi";
79
108
    }
80
108
    break;
81
1.00k
  case llvm::Triple::x86:
82
1.00k
    if (IsAndroid)
83
46
      return "i686-linux-android";
84
962
    if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu"))
85
17
      return "i386-linux-gnu";
86
945
    break;
87
5.38k
  case llvm::Triple::x86_64:
88
5.38k
    if (IsAndroid)
89
32
      return "x86_64-linux-android";
90
    // We don't want this for x32, otherwise it will match x86_64 libs
91
5.35k
    if (TargetEnvironment != llvm::Triple::GNUX32 &&
92
5.32k
        D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
93
26
      return "x86_64-linux-gnu";
94
5.32k
    break;
95
523
  case llvm::Triple::aarch64:
96
523
    if (IsAndroid)
97
100
      return "aarch64-linux-android";
98
423
    if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu"))
99
0
      return "aarch64-linux-gnu";
100
423
    break;
101
16
  case llvm::Triple::aarch64_be:
102
16
    if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
103
0
      return "aarch64_be-linux-gnu";
104
16
    break;
105
760
  case llvm::Triple::mips: {
106
758
    std::string MT = IsMipsR6 ? 
"mipsisa32r6-linux-gnu"2
: "mips-linux-gnu";
107
760
    if (D.getVFS().exists(SysRoot + "/lib/" + MT))
108
6
      return MT;
109
754
    break;
110
754
  }
111
260
  case llvm::Triple::mipsel: {
112
260
    if (IsAndroid)
113
47
      return "mipsel-linux-android";
114
213
    std::string MT = IsMipsR6 ? 
"mipsisa32r6el-linux-gnu"2
:
"mipsel-linux-gnu"211
;
115
213
    if (D.getVFS().exists(SysRoot + "/lib/" + MT))
116
6
      return MT;
117
207
    break;
118
207
  }
119
235
  case llvm::Triple::mips64: {
120
229
    std::string MT = std::string(IsMipsR6 ? 
"mipsisa64r6"6
: "mips64") +
121
176
                     "-linux-" + (IsMipsN32Abi ? 
"gnuabin32"59
: "gnuabi64");
122
235
    if (D.getVFS().exists(SysRoot + "/lib/" + MT))
123
8
      return MT;
124
227
    if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu"))
125
0
      return "mips64-linux-gnu";
126
227
    break;
127
227
  }
128
183
  case llvm::Triple::mips64el: {
129
183
    if (IsAndroid)
130
20
      return "mips64el-linux-android";
131
163
    std::string MT = std::string(IsMipsR6 ? 
"mipsisa64r6el"6
:
"mips64el"157
) +
132
112
                     "-linux-" + (IsMipsN32Abi ? 
"gnuabin32"51
: "gnuabi64");
133
163
    if (D.getVFS().exists(SysRoot + "/lib/" + MT))
134
8
      return MT;
135
155
    if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu"))
136
0
      return "mips64el-linux-gnu";
137
155
    break;
138
155
  }
139
66
  case llvm::Triple::ppc:
140
66
    if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe"))
141
0
      return "powerpc-linux-gnuspe";
142
66
    if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu"))
143
6
      return "powerpc-linux-gnu";
144
60
    break;
145
6
  case llvm::Triple::ppcle:
146
6
    if (D.getVFS().exists(SysRoot + "/lib/powerpcle-linux-gnu"))
147
0
      return "powerpcle-linux-gnu";
148
6
    break;
149
210
  case llvm::Triple::ppc64:
150
210
    if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu"))
151
6
      return "powerpc64-linux-gnu";
152
204
    break;
153
320
  case llvm::Triple::ppc64le:
154
320
    if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu"))
155
8
      return "powerpc64le-linux-gnu";
156
312
    break;
157
32
  case llvm::Triple::sparc:
158
32
    if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu"))
159
6
      return "sparc-linux-gnu";
160
26
    break;
161
34
  case llvm::Triple::sparcv9:
162
34
    if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu"))
163
6
      return "sparc64-linux-gnu";
164
28
    break;
165
85
  case llvm::Triple::systemz:
166
85
    if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu"))
167
0
      return "s390x-linux-gnu";
168
85
    break;
169
10.0k
  }
170
10.0k
  return TargetTriple.str();
171
10.0k
}
172
173
4.75k
static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
174
4.75k
  if (Triple.isMIPS()) {
175
597
    if (Triple.isAndroid()) {
176
32
      StringRef CPUName;
177
32
      StringRef ABIName;
178
32
      tools::mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName);
179
32
      if (CPUName == "mips32r6")
180
1
        return "libr6";
181
31
      if (CPUName == "mips32r2")
182
2
        return "libr2";
183
594
    }
184
    // lib32 directory has a special meaning on MIPS targets.
185
    // It contains N32 ABI binaries. Use this folder if produce
186
    // code for N32 ABI only.
187
594
    if (tools::mips::hasMipsAbiArg(Args, "n32"))
188
38
      return "lib32";
189
556
    return Triple.isArch32Bit() ? 
"lib"412
:
"lib64"144
;
190
556
  }
191
192
  // It happens that only x86, PPC and SPARC use the 'lib32' variant of
193
  // oslibdir, and using that variant while targeting other architectures causes
194
  // problems because the libraries are laid out in shared system roots that
195
  // can't cope with a 'lib32' library search path being considered. So we only
196
  // enable them when we know we may need it.
197
  //
198
  // FIXME: This is a bit of a hack. We should really unify this code for
199
  // reasoning about oslibdir spellings with the lib dir spellings in the
200
  // GCCInstallationDetector, but that is a more significant refactoring.
201
4.15k
  if (Triple.getArch() == llvm::Triple::x86 || 
Triple.isPPC32()3.67k
||
202
3.63k
      Triple.getArch() == llvm::Triple::sparc)
203
537
    return "lib32";
204
205
3.62k
  if (Triple.getArch() == llvm::Triple::x86_64 &&
206
2.26k
      Triple.getEnvironment() == llvm::Triple::GNUX32)
207
11
    return "libx32";
208
209
3.60k
  if (Triple.getArch() == llvm::Triple::riscv32)
210
31
    return "lib32";
211
212
3.57k
  return Triple.isArch32Bit() ? 
"lib"717
:
"lib64"2.86k
;
213
3.57k
}
214
215
Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
216
4.75k
    : Generic_ELF(D, Triple, Args) {
217
4.75k
  GCCInstallation.init(Triple, Args);
218
4.75k
  Multilibs = GCCInstallation.getMultilibs();
219
4.75k
  SelectedMultilib = GCCInstallation.getMultilib();
220
4.75k
  llvm::Triple::ArchType Arch = Triple.getArch();
221
4.75k
  std::string SysRoot = computeSysRoot();
222
4.75k
  ToolChain::path_list &PPaths = getProgramPaths();
223
224
4.75k
  Generic_GCC::PushPPaths(PPaths);
225
226
4.75k
  Distro Distro(D.getVFS(), Triple);
227
228
4.75k
  if (Distro.IsAlpineLinux() || Triple.isAndroid()) {
229
223
    ExtraOpts.push_back("-z");
230
223
    ExtraOpts.push_back("now");
231
223
  }
232
233
4.75k
  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() ||
234
4.75k
      Triple.isAndroid()) {
235
223
    ExtraOpts.push_back("-z");
236
223
    ExtraOpts.push_back("relro");
237
223
  }
238
239
  // Android ARM/AArch64 use max-page-size=4096 to reduce VMA usage. Note, lld
240
  // from 11 onwards default max-page-size to 65536 for both ARM and AArch64.
241
4.75k
  if ((Triple.isARM() || 
Triple.isAArch64()4.16k
) &&
Triple.isAndroid()857
) {
242
148
    ExtraOpts.push_back("-z");
243
148
    ExtraOpts.push_back("max-page-size=4096");
244
148
  }
245
246
4.75k
  if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
247
4.75k
      StringRef::npos)
248
    // With devtoolset on RHEL, we want to add a bin directory that is relative
249
    // to the detected gcc install, because if we are using devtoolset gcc then
250
    // we want to use other tools from devtoolset (e.g. ld) instead of the
251
    // standard system tools.
252
0
    PPaths.push_back(Twine(GCCInstallation.getParentLibPath() +
253
0
                     "/../bin").str());
254
255
4.75k
  if (Arch == llvm::Triple::arm || 
Arch == llvm::Triple::thumb4.20k
)
256
560
    ExtraOpts.push_back("-X");
257
258
4.75k
  const bool IsAndroid = Triple.isAndroid();
259
4.75k
  const bool IsMips = Triple.isMIPS();
260
4.75k
  const bool IsHexagon = Arch == llvm::Triple::hexagon;
261
4.75k
  const bool IsRISCV = Triple.isRISCV();
262
263
4.75k
  if (IsMips && 
!SysRoot.empty()597
)
264
200
    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
4.75k
  if (!IsMips && 
!IsHexagon4.15k
) {
273
4.06k
    if (Distro.IsRedhat() || Distro.IsOpenSUSE() || Distro.IsAlpineLinux() ||
274
4.06k
        (Distro.IsUbuntu() && 
Distro >= Distro::UbuntuMaverick0
) ||
275
4.06k
        (IsAndroid && 
!Triple.isAndroidVersionLT(23)191
))
276
15
      ExtraOpts.push_back("--hash-style=gnu");
277
278
4.06k
    if (Distro.IsDebian() || Distro.IsOpenSUSE() ||
279
4.06k
        Distro == Distro::UbuntuLucid || Distro == Distro::UbuntuJaunty ||
280
4.06k
        Distro == Distro::UbuntuKarmic ||
281
4.06k
        (IsAndroid && 
Triple.isAndroidVersionLT(23)191
))
282
176
      ExtraOpts.push_back("--hash-style=both");
283
4.06k
  }
284
285
#ifdef ENABLE_LINKER_BUILD_ID
286
  ExtraOpts.push_back("--build-id");
287
#endif
288
289
4.75k
  if (IsAndroid || 
Distro.IsOpenSUSE()4.53k
)
290
223
    ExtraOpts.push_back("--enable-new-dtags");
291
292
  // The selection of paths to try here is designed to match the patterns which
293
  // the GCC driver itself uses, as this is part of the GCC-compatible driver.
294
  // This was determined by running GCC in a fake filesystem, creating all
295
  // possible permutations of these directories, and seeing which ones it added
296
  // to the link paths.
297
4.75k
  path_list &Paths = getFilePaths();
298
299
4.75k
  const std::string OSLibDir = std::string(getOSLibDir(Triple, Args));
300
4.75k
  const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
301
302
4.75k
  Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths);
303
304
  // Similar to the logic for GCC above, if we currently running Clang inside
305
  // of the requested system root, add its parent library paths to
306
  // those searched.
307
  // FIXME: It's not clear whether we should use the driver's installed
308
  // directory ('Dir' below) or the ResourceDir.
309
4.75k
  if (StringRef(D.Dir).startswith(SysRoot)) {
310
4.18k
    addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths);
311
4.18k
    addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
312
4.18k
  }
313
314
4.75k
  addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
315
4.75k
  addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);
316
317
4.75k
  if (IsAndroid) {
318
    // Android sysroots contain a library directory for each supported OS
319
    // version as well as some unversioned libraries in the usual multiarch
320
    // directory.
321
223
    unsigned Major;
322
223
    unsigned Minor;
323
223
    unsigned Micro;
324
223
    Triple.getEnvironmentVersion(Major, Minor, Micro);
325
223
    addPathIfExists(D,
326
223
                    SysRoot + "/usr/lib/" + MultiarchTriple + "/" +
327
223
                        llvm::to_string(Major),
328
223
                    Paths);
329
223
  }
330
331
4.75k
  addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
332
  // 64-bit OpenEmbedded sysroots may not have a /usr/lib dir. So they cannot
333
  // find /usr/lib64 as it is referenced as /usr/lib/../lib64. So we handle
334
  // this here.
335
4.75k
  if (Triple.getVendor() == llvm::Triple::OpenEmbedded &&
336
4
      Triple.isArch64Bit())
337
2
    addPathIfExists(D, SysRoot + "/usr/" + OSLibDir, Paths);
338
4.75k
  else
339
4.75k
    addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths);
340
4.75k
  if (IsRISCV) {
341
63
    StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
342
63
    addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths);
343
63
    addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths);
344
63
  }
345
346
4.75k
  Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
347
348
  // Similar to the logic for GCC above, if we are currently running Clang
349
  // inside of the requested system root, add its parent library path to those
350
  // searched.
351
  // FIXME: It's not clear whether we should use the driver's installed
352
  // directory ('Dir' below) or the ResourceDir.
353
4.75k
  if (StringRef(D.Dir).startswith(SysRoot))
354
4.18k
    addPathIfExists(D, D.Dir + "/../lib", Paths);
355
356
4.75k
  addPathIfExists(D, SysRoot + "/lib", Paths);
357
4.75k
  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
358
4.75k
}
359
360
2.45k
ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const {
361
2.45k
  if (getTriple().isAndroid())
362
22
    return ToolChain::CST_Libcxx;
363
2.42k
  return ToolChain::CST_Libstdcxx;
364
2.42k
}
365
366
1.67k
bool Linux::HasNativeLLVMSupport() const { return true; }
367
368
1.53k
Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); }
369
370
7
Tool *Linux::buildStaticLibTool() const {
371
7
  return new tools::gnutools::StaticLibTool(*this);
372
7
}
373
374
201
Tool *Linux::buildAssembler() const {
375
201
  return new tools::gnutools::Assembler(*this);
376
201
}
377
378
10.1k
std::string Linux::computeSysRoot() const {
379
10.1k
  if (!getDriver().SysRoot.empty())
380
819
    return getDriver().SysRoot;
381
382
9.32k
  if (getTriple().isAndroid()) {
383
    // Android toolchains typically include a sysroot at ../sysroot relative to
384
    // the clang binary.
385
237
    const StringRef ClangDir = getDriver().getInstalledDir();
386
237
    std::string AndroidSysRootPath = (ClangDir + "/../sysroot").str();
387
237
    if (getVFS().exists(AndroidSysRootPath))
388
0
      return AndroidSysRootPath;
389
9.32k
  }
390
391
9.32k
  if (!GCCInstallation.isValid() || 
!getTriple().isMIPS()357
)
392
9.00k
    return std::string();
393
394
  // Standalone MIPS toolchains use different names for sysroot folder
395
  // and put it into different places. Here we try to check some known
396
  // variants.
397
398
324
  const StringRef InstallDir = GCCInstallation.getInstallPath();
399
324
  const StringRef TripleStr = GCCInstallation.getTriple().str();
400
324
  const Multilib &Multilib = GCCInstallation.getMultilib();
401
402
324
  std::string Path =
403
324
      (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix())
404
324
          .str();
405
406
324
  if (getVFS().exists(Path))
407
48
    return Path;
408
409
276
  Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str();
410
411
276
  if (getVFS().exists(Path))
412
276
    return Path;
413
414
0
  return std::string();
415
0
}
416
417
1.43k
std::string Linux::getDynamicLinker(const ArgList &Args) const {
418
1.43k
  const llvm::Triple::ArchType Arch = getArch();
419
1.43k
  const llvm::Triple &Triple = getTriple();
420
421
1.43k
  const Distro Distro(getDriver().getVFS(), Triple);
422
423
1.43k
  if (Triple.isAndroid())
424
133
    return Triple.isArch64Bit() ? 
"/system/bin/linker64"47
:
"/system/bin/linker"86
;
425
426
1.29k
  if (Triple.isMusl()) {
427
27
    std::string ArchName;
428
27
    bool IsArm = false;
429
430
27
    switch (Arch) {
431
4
    case llvm::Triple::arm:
432
7
    case llvm::Triple::thumb:
433
7
      ArchName = "arm";
434
7
      IsArm = true;
435
7
      break;
436
3
    case llvm::Triple::armeb:
437
6
    case llvm::Triple::thumbeb:
438
6
      ArchName = "armeb";
439
6
      IsArm = true;
440
6
      break;
441
14
    default:
442
14
      ArchName = Triple.getArchName().str();
443
27
    }
444
27
    if (IsArm &&
445
13
        (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
446
8
         tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard))
447
9
      ArchName += "hf";
448
449
27
    return "/lib/ld-musl-" + ArchName + ".so.1";
450
1.27k
  }
451
452
1.27k
  std::string LibDir;
453
1.27k
  std::string Loader;
454
455
1.27k
  switch (Arch) {
456
0
  default:
457
0
    llvm_unreachable("unsupported architecture");
458
459
33
  case llvm::Triple::aarch64:
460
33
    LibDir = "lib";
461
33
    Loader = "ld-linux-aarch64.so.1";
462
33
    break;
463
3
  case llvm::Triple::aarch64_be:
464
3
    LibDir = "lib";
465
3
    Loader = "ld-linux-aarch64_be.so.1";
466
3
    break;
467
103
  case llvm::Triple::arm:
468
105
  case llvm::Triple::thumb:
469
111
  case llvm::Triple::armeb:
470
113
  case llvm::Triple::thumbeb: {
471
113
    const bool HF =
472
113
        Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
473
96
        tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard;
474
475
113
    LibDir = "lib";
476
94
    Loader = HF ? 
"ld-linux-armhf.so.3"19
: "ld-linux.so.3";
477
113
    break;
478
111
  }
479
60
  case llvm::Triple::mips:
480
120
  case llvm::Triple::mipsel:
481
164
  case llvm::Triple::mips64:
482
207
  case llvm::Triple::mips64el: {
483
207
    bool IsNaN2008 = tools::mips::isNaN2008(Args, Triple);
484
485
207
    LibDir = "lib" + tools::mips::getMipsABILibSuffix(Args, Triple);
486
487
207
    if (tools::mips::isUCLibc(Args))
488
16
      Loader = IsNaN2008 ? 
"ld-uClibc-mipsn8.so.0"6
:
"ld-uClibc.so.0"10
;
489
191
    else if (!Triple.hasEnvironment() &&
490
5
             Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies)
491
2
      Loader =
492
1
          Triple.isLittleEndian() ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1";
493
189
    else
494
189
      Loader = IsNaN2008 ? 
"ld-linux-mipsn8.so.1"68
:
"ld.so.1"121
;
495
496
207
    break;
497
164
  }
498
18
  case llvm::Triple::ppc:
499
18
    LibDir = "lib";
500
18
    Loader = "ld.so.1";
501
18
    break;
502
3
  case llvm::Triple::ppcle:
503
3
    LibDir = "lib";
504
3
    Loader = "ld.so.1";
505
3
    break;
506
48
  case llvm::Triple::ppc64:
507
48
    LibDir = "lib64";
508
48
    Loader =
509
45
        (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? 
"ld64.so.2"3
: "ld64.so.1";
510
48
    break;
511
44
  case llvm::Triple::ppc64le:
512
44
    LibDir = "lib64";
513
44
    Loader =
514
40
        (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? 
"ld64.so.1"4
: "ld64.so.2";
515
44
    break;
516
4
  case llvm::Triple::riscv32: {
517
4
    StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
518
4
    LibDir = "lib";
519
4
    Loader = ("ld-linux-riscv32-" + ABIName + ".so.1").str();
520
4
    break;
521
164
  }
522
8
  case llvm::Triple::riscv64: {
523
8
    StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
524
8
    LibDir = "lib";
525
8
    Loader = ("ld-linux-riscv64-" + ABIName + ".so.1").str();
526
8
    break;
527
164
  }
528
2
  case llvm::Triple::sparc:
529
3
  case llvm::Triple::sparcel:
530
3
    LibDir = "lib";
531
3
    Loader = "ld-linux.so.2";
532
3
    break;
533
2
  case llvm::Triple::sparcv9:
534
2
    LibDir = "lib64";
535
2
    Loader = "ld-linux.so.2";
536
2
    break;
537
10
  case llvm::Triple::systemz:
538
10
    LibDir = "lib";
539
10
    Loader = "ld64.so.1";
540
10
    break;
541
223
  case llvm::Triple::x86:
542
223
    LibDir = "lib";
543
223
    Loader = "ld-linux.so.2";
544
223
    break;
545
553
  case llvm::Triple::x86_64: {
546
553
    bool X32 = Triple.getEnvironment() == llvm::Triple::GNUX32;
547
548
545
    LibDir = X32 ? 
"libx32"8
: "lib64";
549
545
    Loader = X32 ? 
"ld-linux-x32.so.2"8
: "ld-linux-x86-64.so.2";
550
553
    break;
551
2
  }
552
0
  case llvm::Triple::ve:
553
0
    return "/opt/nec/ve/lib/ld-linux-ve.so.1";
554
1.27k
  }
555
556
1.27k
  if (Distro == Distro::Exherbo &&
557
0
      (Triple.getVendor() == llvm::Triple::UnknownVendor ||
558
0
       Triple.getVendor() == llvm::Triple::PC))
559
0
    return "/usr/" + Triple.str() + "/lib/" + Loader;
560
1.27k
  return "/" + LibDir + "/" + Loader;
561
1.27k
}
562
563
void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
564
5.36k
                                      ArgStringList &CC1Args) const {
565
5.36k
  const Driver &D = getDriver();
566
5.36k
  std::string SysRoot = computeSysRoot();
567
568
5.36k
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
569
0
    return;
570
571
5.36k
  if (!DriverArgs.hasArg(options::OPT_nostdlibinc))
572
5.36k
    addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
573
574
5.36k
  SmallString<128> ResourceDirInclude(D.ResourceDir);
575
5.36k
  llvm::sys::path::append(ResourceDirInclude, "include");
576
5.36k
  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) &&
577
5.35k
      (!getTriple().isMusl() || 
DriverArgs.hasArg(options::OPT_nostdlibinc)40
))
578
5.32k
    addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
579
580
5.36k
  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
581
1
    return;
582
583
  // Check for configure-time C include directories.
584
5.36k
  StringRef CIncludeDirs(C_INCLUDE_DIRS);
585
5.36k
  if (CIncludeDirs != "") {
586
0
    SmallVector<StringRef, 5> dirs;
587
0
    CIncludeDirs.split(dirs, ":");
588
0
    for (StringRef dir : dirs) {
589
0
      StringRef Prefix =
590
0
          llvm::sys::path::is_absolute(dir) ? "" : StringRef(SysRoot);
591
0
      addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
592
0
    }
593
0
    return;
594
0
  }
595
596
  // Lacking those, try to detect the correct set of system includes for the
597
  // target triple.
598
599
5.36k
  AddMultilibIncludeArgs(DriverArgs, CC1Args);
600
601
  // Implement generic Debian multiarch support.
602
5.36k
  const StringRef X86_64MultiarchIncludeDirs[] = {
603
5.36k
      "/usr/include/x86_64-linux-gnu",
604
605
      // FIXME: These are older forms of multiarch. It's not clear that they're
606
      // in use in any released version of Debian, so we should consider
607
      // removing them.
608
5.36k
      "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"};
609
5.36k
  const StringRef X86MultiarchIncludeDirs[] = {
610
5.36k
      "/usr/include/i386-linux-gnu",
611
612
      // FIXME: These are older forms of multiarch. It's not clear that they're
613
      // in use in any released version of Debian, so we should consider
614
      // removing them.
615
5.36k
      "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu",
616
5.36k
      "/usr/include/i486-linux-gnu"};
617
5.36k
  const StringRef AArch64MultiarchIncludeDirs[] = {
618
5.36k
      "/usr/include/aarch64-linux-gnu"};
619
5.36k
  const StringRef ARMMultiarchIncludeDirs[] = {
620
5.36k
      "/usr/include/arm-linux-gnueabi"};
621
5.36k
  const StringRef ARMHFMultiarchIncludeDirs[] = {
622
5.36k
      "/usr/include/arm-linux-gnueabihf"};
623
5.36k
  const StringRef ARMEBMultiarchIncludeDirs[] = {
624
5.36k
      "/usr/include/armeb-linux-gnueabi"};
625
5.36k
  const StringRef ARMEBHFMultiarchIncludeDirs[] = {
626
5.36k
      "/usr/include/armeb-linux-gnueabihf"};
627
5.36k
  const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"};
628
5.36k
  const StringRef MIPSELMultiarchIncludeDirs[] = {
629
5.36k
      "/usr/include/mipsel-linux-gnu"};
630
5.36k
  const StringRef MIPS64MultiarchIncludeDirs[] = {
631
5.36k
      "/usr/include/mips64-linux-gnuabi64"};
632
5.36k
  const StringRef MIPS64ELMultiarchIncludeDirs[] = {
633
5.36k
      "/usr/include/mips64el-linux-gnuabi64"};
634
5.36k
  const StringRef MIPSN32MultiarchIncludeDirs[] = {
635
5.36k
      "/usr/include/mips64-linux-gnuabin32"};
636
5.36k
  const StringRef MIPSN32ELMultiarchIncludeDirs[] = {
637
5.36k
      "/usr/include/mips64el-linux-gnuabin32"};
638
5.36k
  const StringRef MIPSR6MultiarchIncludeDirs[] = {
639
5.36k
      "/usr/include/mipsisa32-linux-gnu"};
640
5.36k
  const StringRef MIPSR6ELMultiarchIncludeDirs[] = {
641
5.36k
      "/usr/include/mipsisa32r6el-linux-gnu"};
642
5.36k
  const StringRef MIPS64R6MultiarchIncludeDirs[] = {
643
5.36k
      "/usr/include/mipsisa64r6-linux-gnuabi64"};
644
5.36k
  const StringRef MIPS64R6ELMultiarchIncludeDirs[] = {
645
5.36k
      "/usr/include/mipsisa64r6el-linux-gnuabi64"};
646
5.36k
  const StringRef MIPSN32R6MultiarchIncludeDirs[] = {
647
5.36k
      "/usr/include/mipsisa64r6-linux-gnuabin32"};
648
5.36k
  const StringRef MIPSN32R6ELMultiarchIncludeDirs[] = {
649
5.36k
      "/usr/include/mipsisa64r6el-linux-gnuabin32"};
650
5.36k
  const StringRef PPCMultiarchIncludeDirs[] = {
651
5.36k
      "/usr/include/powerpc-linux-gnu",
652
5.36k
      "/usr/include/powerpc-linux-gnuspe"};
653
5.36k
  const StringRef PPCLEMultiarchIncludeDirs[] = {
654
5.36k
      "/usr/include/powerpcle-linux-gnu"};
655
5.36k
  const StringRef PPC64MultiarchIncludeDirs[] = {
656
5.36k
      "/usr/include/powerpc64-linux-gnu"};
657
5.36k
  const StringRef PPC64LEMultiarchIncludeDirs[] = {
658
5.36k
      "/usr/include/powerpc64le-linux-gnu"};
659
5.36k
  const StringRef SparcMultiarchIncludeDirs[] = {
660
5.36k
      "/usr/include/sparc-linux-gnu"};
661
5.36k
  const StringRef Sparc64MultiarchIncludeDirs[] = {
662
5.36k
      "/usr/include/sparc64-linux-gnu"};
663
5.36k
  const StringRef SYSTEMZMultiarchIncludeDirs[] = {
664
5.36k
      "/usr/include/s390x-linux-gnu"};
665
5.36k
  ArrayRef<StringRef> MultiarchIncludeDirs;
666
5.36k
  switch (getTriple().getArch()) {
667
3.04k
  case llvm::Triple::x86_64:
668
3.04k
    MultiarchIncludeDirs = X86_64MultiarchIncludeDirs;
669
3.04k
    break;
670
501
  case llvm::Triple::x86:
671
501
    MultiarchIncludeDirs = X86MultiarchIncludeDirs;
672
501
    break;
673
257
  case llvm::Triple::aarch64:
674
265
  case llvm::Triple::aarch64_be:
675
265
    MultiarchIncludeDirs = AArch64MultiarchIncludeDirs;
676
265
    break;
677
524
  case llvm::Triple::arm:
678
537
  case llvm::Triple::thumb:
679
537
    if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
680
42
      MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs;
681
495
    else
682
495
      MultiarchIncludeDirs = ARMMultiarchIncludeDirs;
683
537
    break;
684
43
  case llvm::Triple::armeb:
685
54
  case llvm::Triple::thumbeb:
686
54
    if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
687
2
      MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs;
688
52
    else
689
52
      MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs;
690
54
    break;
691
231
  case llvm::Triple::mips:
692
231
    if (getTriple().getSubArch() == llvm::Triple::MipsSubArch_r6)
693
1
      MultiarchIncludeDirs = MIPSR6MultiarchIncludeDirs;
694
230
    else
695
230
      MultiarchIncludeDirs = MIPSMultiarchIncludeDirs;
696
231
    break;
697
100
  case llvm::Triple::mipsel:
698
100
    if (getTriple().getSubArch() == llvm::Triple::MipsSubArch_r6)
699
1
      MultiarchIncludeDirs = MIPSR6ELMultiarchIncludeDirs;
700
99
    else
701
99
      MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs;
702
100
    break;
703
96
  case llvm::Triple::mips64:
704
96
    if (getTriple().getSubArch() == llvm::Triple::MipsSubArch_r6)
705
3
      if (getTriple().getEnvironment() == llvm::Triple::GNUABIN32)
706
1
        MultiarchIncludeDirs = MIPSN32R6MultiarchIncludeDirs;
707
2
      else
708
2
        MultiarchIncludeDirs = MIPS64R6MultiarchIncludeDirs;
709
93
    else if (getTriple().getEnvironment() == llvm::Triple::GNUABIN32)
710
21
      MultiarchIncludeDirs = MIPSN32MultiarchIncludeDirs;
711
72
    else
712
72
      MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs;
713
96
    break;
714
76
  case llvm::Triple::mips64el:
715
76
    if (getTriple().getSubArch() == llvm::Triple::MipsSubArch_r6)
716
3
      if (getTriple().getEnvironment() == llvm::Triple::GNUABIN32)
717
1
        MultiarchIncludeDirs = MIPSN32R6ELMultiarchIncludeDirs;
718
2
      else
719
2
        MultiarchIncludeDirs = MIPS64R6ELMultiarchIncludeDirs;
720
73
    else if (getTriple().getEnvironment() == llvm::Triple::GNUABIN32)
721
18
      MultiarchIncludeDirs = MIPSN32ELMultiarchIncludeDirs;
722
55
    else
723
55
      MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs;
724
76
    break;
725
32
  case llvm::Triple::ppc:
726
32
    MultiarchIncludeDirs = PPCMultiarchIncludeDirs;
727
32
    break;
728
3
  case llvm::Triple::ppcle:
729
3
    MultiarchIncludeDirs = PPCLEMultiarchIncludeDirs;
730
3
    break;
731
102
  case llvm::Triple::ppc64:
732
102
    MultiarchIncludeDirs = PPC64MultiarchIncludeDirs;
733
102
    break;
734
175
  case llvm::Triple::ppc64le:
735
175
    MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs;
736
175
    break;
737
15
  case llvm::Triple::sparc:
738
15
    MultiarchIncludeDirs = SparcMultiarchIncludeDirs;
739
15
    break;
740
16
  case llvm::Triple::sparcv9:
741
16
    MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs;
742
16
    break;
743
41
  case llvm::Triple::systemz:
744
41
    MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs;
745
41
    break;
746
71
  default:
747
71
    break;
748
5.36k
  }
749
750
5.36k
  const std::string AndroidMultiarchIncludeDir =
751
5.36k
      std::string("/usr/include/") +
752
5.36k
      getMultiarchTriple(D, getTriple(), SysRoot);
753
5.36k
  const StringRef AndroidMultiarchIncludeDirs[] = {AndroidMultiarchIncludeDir};
754
5.36k
  if (getTriple().isAndroid())
755
215
    MultiarchIncludeDirs = AndroidMultiarchIncludeDirs;
756
757
12.7k
  for (StringRef Dir : MultiarchIncludeDirs) {
758
12.7k
    if (D.getVFS().exists(SysRoot + Dir)) {
759
59
      addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir);
760
59
      break;
761
59
    }
762
12.7k
  }
763
764
5.36k
  if (getTriple().getOS() == llvm::Triple::RTEMS)
765
0
    return;
766
767
  // Add an include of '/include' directly. This isn't provided by default by
768
  // system GCCs, but is often used with cross-compiling GCCs, and harmless to
769
  // add even when Clang is acting as-if it were a system compiler.
770
5.36k
  addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
771
772
5.36k
  addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
773
774
5.36k
  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && 
getTriple().isMusl()5.35k
)
775
39
    addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
776
5.36k
}
777
778
void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
779
2.61k
                                     llvm::opt::ArgStringList &CC1Args) const {
780
  // Try generic GCC detection first.
781
2.61k
  if (Generic_GCC::addGCCLibStdCxxIncludePaths(DriverArgs, CC1Args))
782
37
    return;
783
784
  // We need a detected GCC installation on Linux to provide libstdc++'s
785
  // headers in odd Linuxish places.
786
2.57k
  if (!GCCInstallation.isValid())
787
2.37k
    return;
788
789
195
  StringRef LibDir = GCCInstallation.getParentLibPath();
790
195
  StringRef TripleStr = GCCInstallation.getTriple().str();
791
195
  const Multilib &Multilib = GCCInstallation.getMultilib();
792
195
  const GCCVersion &Version = GCCInstallation.getVersion();
793
794
195
  const std::string LibStdCXXIncludePathCandidates[] = {
795
      // Android standalone toolchain has C++ headers in yet another place.
796
195
      LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,
797
      // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++,
798
      // without a subdirectory corresponding to the gcc version.
799
195
      LibDir.str() + "/../include/c++",
800
      // Cray's gcc installation puts headers under "g++" without a
801
      // version suffix.
802
195
      LibDir.str() + "/../include/g++",
803
195
  };
804
805
249
  for (const auto &IncludePath : LibStdCXXIncludePathCandidates) {
806
249
    if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr,
807
249
                                 /*GCCMultiarchTriple*/ "",
808
249
                                 /*TargetMultiarchTriple*/ "",
809
249
                                 Multilib.includeSuffix(), DriverArgs, CC1Args))
810
169
      break;
811
249
  }
812
195
}
813
814
void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
815
164
                               ArgStringList &CC1Args) const {
816
164
  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
817
164
}
818
819
void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs,
820
110
                              ArgStringList &CC1Args) const {
821
110
  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
822
110
}
823
824
void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
825
9
                                ArgStringList &CC1Args) const {
826
9
  if (GCCInstallation.isValid()) {
827
0
    CC1Args.push_back("-isystem");
828
0
    CC1Args.push_back(DriverArgs.MakeArgString(
829
0
        GCCInstallation.getParentLibPath() + "/../" +
830
0
        GCCInstallation.getTriple().str() + "/include"));
831
0
  }
832
9
}
833
834
6.84k
bool Linux::isPIEDefault() const {
835
6.84k
  return (getTriple().isAndroid() && 
!getTriple().isAndroidVersionLT(16)367
) ||
836
6.65k
          getTriple().isMusl() || 
getSanitizerArgs().requiresPIE()6.57k
;
837
6.84k
}
838
839
4.12k
bool Linux::isNoExecStackDefault() const {
840
4.12k
    return getTriple().isAndroid();
841
4.12k
}
842
843
4.49k
bool Linux::IsMathErrnoDefault() const {
844
4.49k
  if (getTriple().isAndroid())
845
215
    return false;
846
4.28k
  return Generic_ELF::IsMathErrnoDefault();
847
4.28k
}
848
849
4.88k
SanitizerMask Linux::getSupportedSanitizers() const {
850
4.88k
  const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
851
4.88k
  const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
852
4.88k
  const bool IsMIPS = getTriple().isMIPS32();
853
4.88k
  const bool IsMIPS64 = getTriple().isMIPS64();
854
4.88k
  const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 ||
855
4.77k
                           getTriple().getArch() == llvm::Triple::ppc64le;
856
4.88k
  const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 ||
857
4.62k
                         getTriple().getArch() == llvm::Triple::aarch64_be;
858
4.88k
  const bool IsArmArch = getTriple().getArch() == llvm::Triple::arm ||
859
4.34k
                         getTriple().getArch() == llvm::Triple::thumb ||
860
4.33k
                         getTriple().getArch() == llvm::Triple::armeb ||
861
4.28k
                         getTriple().getArch() == llvm::Triple::thumbeb;
862
4.88k
  const bool IsSystemZ = getTriple().getArch() == llvm::Triple::systemz;
863
4.88k
  SanitizerMask Res = ToolChain::getSupportedSanitizers();
864
4.88k
  Res |= SanitizerKind::Address;
865
4.88k
  Res |= SanitizerKind::PointerCompare;
866
4.88k
  Res |= SanitizerKind::PointerSubtract;
867
4.88k
  Res |= SanitizerKind::Fuzzer;
868
4.88k
  Res |= SanitizerKind::FuzzerNoLink;
869
4.88k
  Res |= SanitizerKind::KernelAddress;
870
4.88k
  Res |= SanitizerKind::Memory;
871
4.88k
  Res |= SanitizerKind::Vptr;
872
4.88k
  Res |= SanitizerKind::SafeStack;
873
4.88k
  if (IsX86_64 || 
IsMIPS642.45k
||
IsAArch642.27k
)
874
2.87k
    Res |= SanitizerKind::DataFlow;
875
4.88k
  if (IsX86_64 || 
IsMIPS642.45k
||
IsAArch642.27k
||
IsX862.00k
||
IsArmArch1.52k
||
IsPowerPC64918
||
876
694
      IsSystemZ)
877
4.23k
    Res |= SanitizerKind::Leak;
878
4.88k
  if (IsX86_64 || 
IsMIPS642.45k
||
IsAArch642.27k
||
IsPowerPC642.00k
)
879
3.09k
    Res |= SanitizerKind::Thread;
880
4.88k
  if (IsX86_64)
881
2.42k
    Res |= SanitizerKind::KernelMemory;
882
4.88k
  if (IsX86 || 
IsX86_644.39k
)
883
2.90k
    Res |= SanitizerKind::Function;
884
4.88k
  if (IsX86_64 || 
IsMIPS642.45k
||
IsAArch642.27k
||
IsX862.00k
||
IsMIPS1.52k
||
IsArmArch1.10k
||
885
503
      IsPowerPC64)
886
4.60k
    Res |= SanitizerKind::Scudo;
887
4.88k
  if (IsX86_64 || 
IsAArch642.45k
) {
888
2.69k
    Res |= SanitizerKind::HWAddress;
889
2.69k
    Res |= SanitizerKind::KernelHWAddress;
890
2.69k
  }
891
4.88k
  return Res;
892
4.88k
}
893
894
void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args,
895
1.52k
                             llvm::opt::ArgStringList &CmdArgs) const {
896
  // Add linker option -u__llvm_profile_runtime to cause runtime
897
  // initialization module to be linked in.
898
1.52k
  if (needsProfileRT(Args))
899
5
    CmdArgs.push_back(Args.MakeArgString(
900
5
        Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
901
1.52k
  ToolChain::addProfileRTLibs(Args, CmdArgs);
902
1.52k
}
903
904
llvm::DenormalMode
905
Linux::getDefaultDenormalModeForType(const llvm::opt::ArgList &DriverArgs,
906
                                     const JobAction &JA,
907
8.97k
                                     const llvm::fltSemantics *FPType) const {
908
8.97k
  switch (getTriple().getArch()) {
909
904
  case llvm::Triple::x86:
910
5.22k
  case llvm::Triple::x86_64: {
911
5.22k
    std::string Unused;
912
    // DAZ and FTZ are turned on in crtfastmath.o
913
5.22k
    if (!DriverArgs.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
914
5.20k
        isFastMathRuntimeAvailable(DriverArgs, Unused))
915
20
      return llvm::DenormalMode::getPreserveSign();
916
5.20k
    return llvm::DenormalMode::getIEEE();
917
5.20k
  }
918
3.75k
  default:
919
3.75k
    return llvm::DenormalMode::getIEEE();
920
8.97k
  }
921
8.97k
}
922
923
1.52k
void Linux::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
924
1.52k
  for (const auto &Opt : ExtraOpts)
925
1.56k
    CmdArgs.push_back(Opt.c_str());
926
1.52k
}