Coverage Report

Created: 2020-09-19 12:23

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