Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/MinGW.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- MinGW.cpp - MinGWToolChain Implementation ------------------------===//
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 "MinGW.h"
10
#include "CommonArgs.h"
11
#include "clang/Config/config.h"
12
#include "clang/Driver/Compilation.h"
13
#include "clang/Driver/Driver.h"
14
#include "clang/Driver/DriverDiagnostic.h"
15
#include "clang/Driver/InputInfo.h"
16
#include "clang/Driver/Options.h"
17
#include "clang/Driver/SanitizerArgs.h"
18
#include "llvm/Option/ArgList.h"
19
#include "llvm/Support/FileSystem.h"
20
#include "llvm/Support/Path.h"
21
#include "llvm/Support/VirtualFileSystem.h"
22
#include <system_error>
23
24
using namespace clang::diag;
25
using namespace clang::driver;
26
using namespace clang;
27
using namespace llvm::opt;
28
29
/// MinGW Tools
30
void tools::MinGW::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
31
                                           const InputInfo &Output,
32
                                           const InputInfoList &Inputs,
33
                                           const ArgList &Args,
34
1
                                           const char *LinkingOutput) const {
35
1
  claimNoWarnArgs(Args);
36
1
  ArgStringList CmdArgs;
37
38
1
  if (getToolChain().getArch() == llvm::Triple::x86) {
39
1
    CmdArgs.push_back("--32");
40
1
  } else 
if (0
getToolChain().getArch() == llvm::Triple::x86_640
) {
41
0
    CmdArgs.push_back("--64");
42
0
  }
43
44
1
  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
45
46
1
  CmdArgs.push_back("-o");
47
1
  CmdArgs.push_back(Output.getFilename());
48
49
1
  for (const auto &II : Inputs)
50
1
    CmdArgs.push_back(II.getFilename());
51
52
1
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
53
1
  C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
54
1
                                         Exec, CmdArgs, Inputs, Output));
55
56
1
  if (Args.hasArg(options::OPT_gsplit_dwarf))
57
0
    SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
58
0
                   SplitDebugName(JA, Args, Inputs[0], Output));
59
1
}
60
61
void tools::MinGW::Linker::AddLibGCC(const ArgList &Args,
62
114
                                     ArgStringList &CmdArgs) const {
63
114
  if (Args.hasArg(options::OPT_mthreads))
64
0
    CmdArgs.push_back("-lmingwthrd");
65
114
  CmdArgs.push_back("-lmingw32");
66
67
  // Make use of compiler-rt if --rtlib option is used
68
114
  ToolChain::RuntimeLibType RLT = getToolChain().GetRuntimeLibType(Args);
69
114
  if (RLT == ToolChain::RLT_Libgcc) {
70
106
    bool Static = Args.hasArg(options::OPT_static_libgcc) ||
71
106
                  
Args.hasArg(options::OPT_static)98
;
72
106
    bool Shared = Args.hasArg(options::OPT_shared);
73
106
    bool CXX = getToolChain().getDriver().CCCIsCXX();
74
75
106
    if (Static || 
(94
!CXX94
&&
!Shared90
)) {
76
100
      CmdArgs.push_back("-lgcc");
77
100
      CmdArgs.push_back("-lgcc_eh");
78
100
    } else {
79
6
      CmdArgs.push_back("-lgcc_s");
80
6
      CmdArgs.push_back("-lgcc");
81
6
    }
82
106
  } else {
83
8
    AddRunTimeLibs(getToolChain(), getToolChain().getDriver(), CmdArgs, Args);
84
8
  }
85
86
114
  CmdArgs.push_back("-lmoldname");
87
114
  CmdArgs.push_back("-lmingwex");
88
114
  for (auto Lib : Args.getAllArgValues(options::OPT_l))
89
8
    if (StringRef(Lib).startswith("msvcr") || 
StringRef(Lib).startswith("ucrt")6
)
90
6
      return;
91
108
  CmdArgs.push_back("-lmsvcrt");
92
108
}
93
94
void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
95
                                        const InputInfo &Output,
96
                                        const InputInfoList &Inputs,
97
                                        const ArgList &Args,
98
62
                                        const char *LinkingOutput) const {
99
62
  const ToolChain &TC = getToolChain();
100
62
  const Driver &D = TC.getDriver();
101
62
  const SanitizerArgs &Sanitize = TC.getSanitizerArgs();
102
103
62
  ArgStringList CmdArgs;
104
105
  // Silence warning for "clang -g foo.o -o foo"
106
62
  Args.ClaimAllArgs(options::OPT_g_Group);
107
  // and "clang -emit-llvm foo.o -o foo"
108
62
  Args.ClaimAllArgs(options::OPT_emit_llvm);
109
  // and for "clang -w foo.o -o foo". Other warning options are already
110
  // handled somewhere else.
111
62
  Args.ClaimAllArgs(options::OPT_w);
112
113
62
  if (!D.SysRoot.empty())
114
3
    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
115
116
62
  if (Args.hasArg(options::OPT_s))
117
0
    CmdArgs.push_back("-s");
118
119
62
  CmdArgs.push_back("-m");
120
62
  switch (TC.getArch()) {
121
37
  case llvm::Triple::x86:
122
37
    CmdArgs.push_back("i386pe");
123
37
    break;
124
25
  case llvm::Triple::x86_64:
125
25
    CmdArgs.push_back("i386pep");
126
25
    break;
127
0
  case llvm::Triple::arm:
128
0
  case llvm::Triple::thumb:
129
    // FIXME: this is incorrect for WinCE
130
0
    CmdArgs.push_back("thumb2pe");
131
0
    break;
132
0
  case llvm::Triple::aarch64:
133
0
    CmdArgs.push_back("arm64pe");
134
0
    break;
135
0
  default:
136
0
    llvm_unreachable("Unsupported target architecture.");
137
62
  }
138
139
62
  Arg *SubsysArg =
140
62
      Args.getLastArg(options::OPT_mwindows, options::OPT_mconsole);
141
62
  if (SubsysArg && 
SubsysArg->getOption().matches(options::OPT_mwindows)2
) {
142
1
    CmdArgs.push_back("--subsystem");
143
1
    CmdArgs.push_back("windows");
144
61
  } else if (SubsysArg &&
145
61
             
SubsysArg->getOption().matches(options::OPT_mconsole)1
) {
146
1
    CmdArgs.push_back("--subsystem");
147
1
    CmdArgs.push_back("console");
148
1
  }
149
150
62
  if (Args.hasArg(options::OPT_mdll))
151
0
    CmdArgs.push_back("--dll");
152
62
  else if (Args.hasArg(options::OPT_shared))
153
6
    CmdArgs.push_back("--shared");
154
62
  if (Args.hasArg(options::OPT_static))
155
4
    CmdArgs.push_back("-Bstatic");
156
58
  else
157
58
    CmdArgs.push_back("-Bdynamic");
158
62
  if (Args.hasArg(options::OPT_mdll) || Args.hasArg(options::OPT_shared)) {
159
6
    CmdArgs.push_back("-e");
160
6
    if (TC.getArch() == llvm::Triple::x86)
161
6
      CmdArgs.push_back("_DllMainCRTStartup@12");
162
0
    else
163
0
      CmdArgs.push_back("DllMainCRTStartup");
164
6
    CmdArgs.push_back("--enable-auto-image-base");
165
6
  }
166
167
62
  CmdArgs.push_back("-o");
168
62
  const char *OutputFile = Output.getFilename();
169
  // GCC implicitly adds an .exe extension if it is given an output file name
170
  // that lacks an extension.
171
  // GCC used to do this only when the compiler itself runs on windows, but
172
  // since GCC 8 it does the same when cross compiling as well.
173
62
  if (!llvm::sys::path::has_extension(OutputFile)) {
174
1
    CmdArgs.push_back(Args.MakeArgString(Twine(OutputFile) + ".exe"));
175
1
    OutputFile = CmdArgs.back();
176
1
  } else
177
61
    CmdArgs.push_back(OutputFile);
178
179
62
  Args.AddAllArgs(CmdArgs, options::OPT_e);
180
  // FIXME: add -N, -n flags
181
62
  Args.AddLastArg(CmdArgs, options::OPT_r);
182
62
  Args.AddLastArg(CmdArgs, options::OPT_s);
183
62
  Args.AddLastArg(CmdArgs, options::OPT_t);
184
62
  Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
185
62
  Args.AddLastArg(CmdArgs, options::OPT_Z_Flag);
186
187
62
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
188
59
    if (Args.hasArg(options::OPT_shared) || 
Args.hasArg(options::OPT_mdll)53
) {
189
6
      CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("dllcrt2.o")));
190
53
    } else {
191
53
      if (Args.hasArg(options::OPT_municode))
192
0
        CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt2u.o")));
193
53
      else
194
53
        CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt2.o")));
195
53
    }
196
59
    if (Args.hasArg(options::OPT_pg))
197
0
      CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("gcrt2.o")));
198
59
    CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtbegin.o")));
199
59
  }
200
201
62
  Args.AddAllArgs(CmdArgs, options::OPT_L);
202
62
  TC.AddFilePathLibArgs(Args, CmdArgs);
203
204
  // Add the compiler-rt library directories if they exist to help
205
  // the linker find the various sanitizer, builtin, and profiling runtimes.
206
62
  for (const auto &LibPath : TC.getLibraryPaths()) {
207
0
    if (TC.getVFS().exists(LibPath))
208
0
      CmdArgs.push_back(Args.MakeArgString("-L" + LibPath));
209
0
  }
210
62
  auto CRTPath = TC.getCompilerRTPath();
211
62
  if (TC.getVFS().exists(CRTPath))
212
1
    CmdArgs.push_back(Args.MakeArgString("-L" + CRTPath));
213
214
62
  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
215
216
  // TODO: Add profile stuff here
217
218
62
  if (TC.ShouldLinkCXXStdlib(Args)) {
219
7
    bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
220
7
                               
!Args.hasArg(options::OPT_static)0
;
221
7
    if (OnlyLibstdcxxStatic)
222
0
      CmdArgs.push_back("-Bstatic");
223
7
    TC.AddCXXStdlibLibArgs(Args, CmdArgs);
224
7
    if (OnlyLibstdcxxStatic)
225
0
      CmdArgs.push_back("-Bdynamic");
226
7
  }
227
228
62
  bool HasWindowsApp = false;
229
62
  for (auto Lib : Args.getAllArgValues(options::OPT_l)) {
230
4
    if (Lib == "windowsapp") {
231
1
      HasWindowsApp = true;
232
1
      break;
233
1
    }
234
4
  }
235
236
62
  if (!Args.hasArg(options::OPT_nostdlib)) {
237
59
    if (!Args.hasArg(options::OPT_nodefaultlibs)) {
238
59
      if (Args.hasArg(options::OPT_static))
239
4
        CmdArgs.push_back("--start-group");
240
241
59
      if (Args.hasArg(options::OPT_fstack_protector) ||
242
59
          Args.hasArg(options::OPT_fstack_protector_strong) ||
243
59
          Args.hasArg(options::OPT_fstack_protector_all)) {
244
0
        CmdArgs.push_back("-lssp_nonshared");
245
0
        CmdArgs.push_back("-lssp");
246
0
      }
247
248
59
      if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
249
59
                       options::OPT_fno_openmp, false)) {
250
4
        switch (TC.getDriver().getOpenMPRuntime(Args)) {
251
2
        case Driver::OMPRT_OMP:
252
2
          CmdArgs.push_back("-lomp");
253
2
          break;
254
1
        case Driver::OMPRT_IOMP5:
255
1
          CmdArgs.push_back("-liomp5md");
256
1
          break;
257
1
        case Driver::OMPRT_GOMP:
258
1
          CmdArgs.push_back("-lgomp");
259
1
          break;
260
0
        case Driver::OMPRT_Unknown:
261
          // Already diagnosed.
262
0
          break;
263
4
        }
264
4
      }
265
266
59
      AddLibGCC(Args, CmdArgs);
267
268
59
      if (Args.hasArg(options::OPT_pg))
269
0
        CmdArgs.push_back("-lgmon");
270
271
59
      if (Args.hasArg(options::OPT_pthread))
272
0
        CmdArgs.push_back("-lpthread");
273
274
59
      if (Sanitize.needsAsanRt()) {
275
        // MinGW always links against a shared MSVCRT.
276
2
        CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dynamic",
277
2
                                                    ToolChain::FT_Shared));
278
2
        CmdArgs.push_back(
279
2
            TC.getCompilerRTArgString(Args, "asan_dynamic_runtime_thunk"));
280
2
        CmdArgs.push_back("--require-defined");
281
2
        CmdArgs.push_back(TC.getArch() == llvm::Triple::x86
282
2
                              ? 
"___asan_seh_interceptor"1
283
2
                              : 
"__asan_seh_interceptor"1
);
284
        // Make sure the linker consider all object files from the dynamic
285
        // runtime thunk.
286
2
        CmdArgs.push_back("--whole-archive");
287
2
        CmdArgs.push_back(
288
2
            TC.getCompilerRTArgString(Args, "asan_dynamic_runtime_thunk"));
289
2
        CmdArgs.push_back("--no-whole-archive");
290
2
      }
291
292
59
      TC.addProfileRTLibs(Args, CmdArgs);
293
294
59
      if (!HasWindowsApp) {
295
        // Add system libraries. If linking to libwindowsapp.a, that import
296
        // library replaces all these and we shouldn't accidentally try to
297
        // link to the normal desktop mode dlls.
298
58
        if (Args.hasArg(options::OPT_mwindows)) {
299
2
          CmdArgs.push_back("-lgdi32");
300
2
          CmdArgs.push_back("-lcomdlg32");
301
2
        }
302
58
        CmdArgs.push_back("-ladvapi32");
303
58
        CmdArgs.push_back("-lshell32");
304
58
        CmdArgs.push_back("-luser32");
305
58
        CmdArgs.push_back("-lkernel32");
306
58
      }
307
308
59
      if (Args.hasArg(options::OPT_static)) {
309
4
        CmdArgs.push_back("--end-group");
310
55
      } else {
311
55
        AddLibGCC(Args, CmdArgs);
312
55
        if (!HasWindowsApp)
313
54
          CmdArgs.push_back("-lkernel32");
314
55
      }
315
59
    }
316
317
59
    if (!Args.hasArg(options::OPT_nostartfiles)) {
318
      // Add crtfastmath.o if available and fast math is enabled.
319
59
      TC.addFastMathRuntimeIfAvailable(Args, CmdArgs);
320
321
59
      CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtend.o")));
322
59
    }
323
59
  }
324
62
  const char *Exec = Args.MakeArgString(TC.GetLinkerPath());
325
62
  C.addCommand(std::make_unique<Command>(JA, *this,
326
62
                                         ResponseFileSupport::AtFileUTF8(),
327
62
                                         Exec, CmdArgs, Inputs, Output));
328
62
}
329
330
// Simplified from Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple.
331
static bool findGccVersion(StringRef LibDir, std::string &GccLibDir,
332
400
                           std::string &Ver) {
333
400
  auto Version = toolchains::Generic_GCC::GCCVersion::Parse("0.0.0");
334
400
  std::error_code EC;
335
412
  for (llvm::sys::fs::directory_iterator LI(LibDir, EC), LE; !EC && 
LI != LE21
;
336
400
       
LI = LI.increment(EC)12
) {
337
12
    StringRef VersionText = llvm::sys::path::filename(LI->path());
338
12
    auto CandidateVersion =
339
12
        toolchains::Generic_GCC::GCCVersion::Parse(VersionText);
340
12
    if (CandidateVersion.Major == -1)
341
0
      continue;
342
12
    if (CandidateVersion <= Version)
343
0
      continue;
344
12
    Version = CandidateVersion;
345
12
    Ver = std::string(VersionText);
346
12
    GccLibDir = LI->path();
347
12
  }
348
400
  return Ver.size();
349
400
}
350
351
106
void toolchains::MinGW::findGccLibDir() {
352
106
  llvm::SmallVector<llvm::SmallString<32>, 2> Archs;
353
106
  Archs.emplace_back(getTriple().getArchName());
354
106
  Archs[0] += "-w64-mingw32";
355
106
  Archs.emplace_back("mingw32");
356
106
  if (Arch.empty())
357
104
    Arch = std::string(Archs[0].str());
358
  // lib: Arch Linux, Ubuntu, Windows
359
  // lib64: openSUSE Linux
360
204
  for (StringRef CandidateLib : {"lib", "lib64"}) {
361
400
    for (StringRef CandidateArch : Archs) {
362
400
      llvm::SmallString<1024> LibDir(Base);
363
400
      llvm::sys::path::append(LibDir, CandidateLib, "gcc", CandidateArch);
364
400
      if (findGccVersion(LibDir, GccLibDir, Ver)) {
365
9
        Arch = std::string(CandidateArch);
366
9
        return;
367
9
      }
368
400
    }
369
204
  }
370
106
}
371
372
92
llvm::ErrorOr<std::string> toolchains::MinGW::findGcc() {
373
92
  llvm::SmallVector<llvm::SmallString<32>, 2> Gccs;
374
92
  Gccs.emplace_back(getTriple().getArchName());
375
92
  Gccs[0] += "-w64-mingw32-gcc";
376
92
  Gccs.emplace_back("mingw32-gcc");
377
  // Please do not add "gcc" here
378
92
  for (StringRef CandidateGcc : Gccs)
379
183
    if (llvm::ErrorOr<std::string> GPPName = llvm::sys::findProgramByName(CandidateGcc))
380
1
      return GPPName;
381
91
  return make_error_code(std::errc::no_such_file_or_directory);
382
92
}
383
384
94
llvm::ErrorOr<std::string> toolchains::MinGW::findClangRelativeSysroot() {
385
94
  llvm::SmallVector<llvm::SmallString<32>, 2> Subdirs;
386
94
  Subdirs.emplace_back(getTriple().str());
387
94
  Subdirs.emplace_back(getTriple().getArchName());
388
94
  Subdirs[1] += "-w64-mingw32";
389
94
  StringRef ClangRoot =
390
94
      llvm::sys::path::parent_path(getDriver().getInstalledDir());
391
94
  StringRef Sep = llvm::sys::path::get_separator();
392
188
  for (StringRef CandidateSubdir : Subdirs) {
393
188
    if (llvm::sys::fs::is_directory(ClangRoot + Sep + CandidateSubdir)) {
394
2
      Arch = std::string(CandidateSubdir);
395
2
      return (ClangRoot + Sep + CandidateSubdir).str();
396
2
    }
397
188
  }
398
92
  return make_error_code(std::errc::no_such_file_or_directory);
399
94
}
400
401
toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple,
402
                         const ArgList &Args)
403
    : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
404
106
      RocmInstallation(D, Triple, Args) {
405
106
  getProgramPaths().push_back(getDriver().getInstalledDir());
406
407
106
  if (getDriver().SysRoot.size())
408
12
    Base = getDriver().SysRoot;
409
  // Look for <clang-bin>/../<triplet>; if found, use <clang-bin>/.. as the
410
  // base as it could still be a base for a gcc setup with libgcc.
411
94
  else if (llvm::ErrorOr<std::string> TargetSubdir = findClangRelativeSysroot())
412
2
    Base = std::string(llvm::sys::path::parent_path(TargetSubdir.get()));
413
92
  else if (llvm::ErrorOr<std::string> GPPName = findGcc())
414
1
    Base = std::string(llvm::sys::path::parent_path(
415
1
        llvm::sys::path::parent_path(GPPName.get())));
416
91
  else
417
91
    Base = std::string(
418
91
        llvm::sys::path::parent_path(getDriver().getInstalledDir()));
419
420
106
  Base += llvm::sys::path::get_separator();
421
106
  findGccLibDir();
422
  // GccLibDir must precede Base/lib so that the
423
  // correct crtbegin.o ,cetend.o would be found.
424
106
  getFilePaths().push_back(GccLibDir);
425
106
  getFilePaths().push_back(
426
106
      (Base + Arch + llvm::sys::path::get_separator() + "lib").str());
427
106
  getFilePaths().push_back(Base + "lib");
428
  // openSUSE
429
106
  getFilePaths().push_back(Base + Arch + "/sys-root/mingw/lib");
430
431
106
  NativeLLVMSupport =
432
106
      Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER)
433
106
          .equals_insensitive("lld");
434
106
}
435
436
659
bool toolchains::MinGW::IsIntegratedAssemblerDefault() const { return true; }
437
438
63
Tool *toolchains::MinGW::getTool(Action::ActionClass AC) const {
439
63
  switch (AC) {
440
0
  case Action::PreprocessJobClass:
441
0
    if (!Preprocessor)
442
0
      Preprocessor.reset(new tools::gcc::Preprocessor(*this));
443
0
    return Preprocessor.get();
444
0
  case Action::CompileJobClass:
445
0
    if (!Compiler)
446
0
      Compiler.reset(new tools::gcc::Compiler(*this));
447
0
    return Compiler.get();
448
63
  default:
449
63
    return ToolChain::getTool(AC);
450
63
  }
451
63
}
452
453
1
Tool *toolchains::MinGW::buildAssembler() const {
454
1
  return new tools::MinGW::Assembler(*this);
455
1
}
456
457
62
Tool *toolchains::MinGW::buildLinker() const {
458
62
  return new tools::MinGW::Linker(*this);
459
62
}
460
461
66
bool toolchains::MinGW::HasNativeLLVMSupport() const {
462
66
  return NativeLLVMSupport;
463
66
}
464
465
106
bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList &Args) const {
466
106
  Arg *ExceptionArg = Args.getLastArg(options::OPT_fsjlj_exceptions,
467
106
                                      options::OPT_fseh_exceptions,
468
106
                                      options::OPT_fdwarf_exceptions);
469
106
  if (ExceptionArg &&
470
106
      
ExceptionArg->getOption().matches(options::OPT_fseh_exceptions)7
)
471
1
    return true;
472
105
  return getArch() == llvm::Triple::x86_64 ||
473
105
         
getArch() == llvm::Triple::aarch6459
;
474
106
}
475
476
106
bool toolchains::MinGW::isPICDefault() const {
477
106
  return getArch() == llvm::Triple::x86_64;
478
106
}
479
480
106
bool toolchains::MinGW::isPIEDefault() const { return false; }
481
482
98
bool toolchains::MinGW::isPICDefaultForced() const {
483
98
  return getArch() == llvm::Triple::x86_64;
484
98
}
485
486
llvm::ExceptionHandling
487
99
toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
488
99
  if (getArch() == llvm::Triple::x86_64 || 
getArch() == llvm::Triple::aarch6457
)
489
45
    return llvm::ExceptionHandling::WinEH;
490
54
  return llvm::ExceptionHandling::DwarfCFI;
491
99
}
492
493
106
SanitizerMask toolchains::MinGW::getSupportedSanitizers() const {
494
106
  SanitizerMask Res = ToolChain::getSupportedSanitizers();
495
106
  Res |= SanitizerKind::Address;
496
106
  Res |= SanitizerKind::PointerCompare;
497
106
  Res |= SanitizerKind::PointerSubtract;
498
106
  Res |= SanitizerKind::Vptr;
499
106
  return Res;
500
106
}
501
502
void toolchains::MinGW::AddCudaIncludeArgs(const ArgList &DriverArgs,
503
0
                                           ArgStringList &CC1Args) const {
504
0
  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
505
0
}
506
507
void toolchains::MinGW::AddHIPIncludeArgs(const ArgList &DriverArgs,
508
0
                                          ArgStringList &CC1Args) const {
509
0
  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
510
0
}
511
512
18
void toolchains::MinGW::printVerboseInfo(raw_ostream &OS) const {
513
18
  CudaInstallation.print(OS);
514
18
  RocmInstallation.print(OS);
515
18
}
516
517
// Include directories for various hosts:
518
519
// Windows, mingw.org
520
// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++
521
// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32
522
// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\backward
523
// c:\mingw\include
524
// c:\mingw\mingw32\include
525
526
// Windows, mingw-w64 mingw-builds
527
// c:\mingw32\i686-w64-mingw32\include
528
// c:\mingw32\i686-w64-mingw32\include\c++
529
// c:\mingw32\i686-w64-mingw32\include\c++\i686-w64-mingw32
530
// c:\mingw32\i686-w64-mingw32\include\c++\backward
531
532
// Windows, mingw-w64 msys2
533
// c:\msys64\mingw32\include
534
// c:\msys64\mingw32\i686-w64-mingw32\include
535
// c:\msys64\mingw32\include\c++\4.9.2
536
// c:\msys64\mingw32\include\c++\4.9.2\i686-w64-mingw32
537
// c:\msys64\mingw32\include\c++\4.9.2\backward
538
539
// openSUSE
540
// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++
541
// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32
542
// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward
543
// /usr/x86_64-w64-mingw32/sys-root/mingw/include
544
545
// Arch Linux
546
// /usr/i686-w64-mingw32/include/c++/5.1.0
547
// /usr/i686-w64-mingw32/include/c++/5.1.0/i686-w64-mingw32
548
// /usr/i686-w64-mingw32/include/c++/5.1.0/backward
549
// /usr/i686-w64-mingw32/include
550
551
// Ubuntu
552
// /usr/include/c++/4.8
553
// /usr/include/c++/4.8/x86_64-w64-mingw32
554
// /usr/include/c++/4.8/backward
555
// /usr/x86_64-w64-mingw32/include
556
557
void toolchains::MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
558
106
                                                  ArgStringList &CC1Args) const {
559
106
  if (DriverArgs.hasArg(options::OPT_nostdinc))
560
0
    return;
561
562
106
  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
563
106
    SmallString<1024> P(getDriver().ResourceDir);
564
106
    llvm::sys::path::append(P, "include");
565
106
    addSystemInclude(DriverArgs, CC1Args, P.str());
566
106
  }
567
568
106
  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
569
0
    return;
570
571
106
  if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) {
572
    // openSUSE
573
100
    addSystemInclude(DriverArgs, CC1Args,
574
100
                     Base + Arch + "/sys-root/mingw/include");
575
100
  }
576
577
106
  addSystemInclude(DriverArgs, CC1Args,
578
106
                   Base + Arch + llvm::sys::path::get_separator() + "include");
579
106
  addSystemInclude(DriverArgs, CC1Args, Base + "include");
580
106
}
581
582
void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
583
49
    const ArgList &DriverArgs, ArgStringList &CC1Args) const {
584
49
  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
585
49
      DriverArgs.hasArg(options::OPT_nostdincxx))
586
0
    return;
587
588
49
  StringRef Slash = llvm::sys::path::get_separator();
589
590
49
  switch (GetCXXStdlibType(DriverArgs)) {
591
1
  case ToolChain::CST_Libcxx: {
592
1
    std::string TargetDir = (Base + "include" + Slash + getTripleString() +
593
1
                             Slash + "c++" + Slash + "v1")
594
1
                                .str();
595
1
    if (getDriver().getVFS().exists(TargetDir))
596
1
      addSystemInclude(DriverArgs, CC1Args, TargetDir);
597
1
    addSystemInclude(DriverArgs, CC1Args, Base + Arch + Slash + "include" +
598
1
                                              Slash + "c++" + Slash + "v1");
599
1
    addSystemInclude(DriverArgs, CC1Args,
600
1
                     Base + "include" + Slash + "c++" + Slash + "v1");
601
1
    break;
602
0
  }
603
604
48
  case ToolChain::CST_Libstdcxx:
605
48
    llvm::SmallVector<llvm::SmallString<1024>, 4> CppIncludeBases;
606
48
    CppIncludeBases.emplace_back(Base);
607
48
    llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++");
608
48
    CppIncludeBases.emplace_back(Base);
609
48
    llvm::sys::path::append(CppIncludeBases[1], Arch, "include", "c++", Ver);
610
48
    CppIncludeBases.emplace_back(Base);
611
48
    llvm::sys::path::append(CppIncludeBases[2], "include", "c++", Ver);
612
48
    CppIncludeBases.emplace_back(GccLibDir);
613
48
    llvm::sys::path::append(CppIncludeBases[3], "include", "c++");
614
192
    for (auto &CppIncludeBase : CppIncludeBases) {
615
192
      addSystemInclude(DriverArgs, CC1Args, CppIncludeBase);
616
192
      CppIncludeBase += Slash;
617
192
      addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch);
618
192
      addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward");
619
192
    }
620
48
    break;
621
49
  }
622
49
}