clang  14.0.0git
MinGW.cpp
Go to the documentation of this file.
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"
13 #include "clang/Driver/Driver.h"
15 #include "clang/Driver/InputInfo.h"
16 #include "clang/Driver/Options.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  const char *LinkingOutput) const {
35  claimNoWarnArgs(Args);
36  ArgStringList CmdArgs;
37 
38  if (getToolChain().getArch() == llvm::Triple::x86) {
39  CmdArgs.push_back("--32");
40  } else if (getToolChain().getArch() == llvm::Triple::x86_64) {
41  CmdArgs.push_back("--64");
42  }
43 
44  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
45 
46  CmdArgs.push_back("-o");
47  CmdArgs.push_back(Output.getFilename());
48 
49  for (const auto &II : Inputs)
50  CmdArgs.push_back(II.getFilename());
51 
52  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
53  C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
54  Exec, CmdArgs, Inputs, Output));
55 
56  if (Args.hasArg(options::OPT_gsplit_dwarf))
57  SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
58  SplitDebugName(JA, Args, Inputs[0], Output));
59 }
60 
61 void tools::MinGW::Linker::AddLibGCC(const ArgList &Args,
62  ArgStringList &CmdArgs) const {
63  if (Args.hasArg(options::OPT_mthreads))
64  CmdArgs.push_back("-lmingwthrd");
65  CmdArgs.push_back("-lmingw32");
66 
67  // Make use of compiler-rt if --rtlib option is used
68  ToolChain::RuntimeLibType RLT = getToolChain().GetRuntimeLibType(Args);
69  if (RLT == ToolChain::RLT_Libgcc) {
70  bool Static = Args.hasArg(options::OPT_static_libgcc) ||
71  Args.hasArg(options::OPT_static);
72  bool Shared = Args.hasArg(options::OPT_shared);
73  bool CXX = getToolChain().getDriver().CCCIsCXX();
74 
75  if (Static || (!CXX && !Shared)) {
76  CmdArgs.push_back("-lgcc");
77  CmdArgs.push_back("-lgcc_eh");
78  } else {
79  CmdArgs.push_back("-lgcc_s");
80  CmdArgs.push_back("-lgcc");
81  }
82  } else {
83  AddRunTimeLibs(getToolChain(), getToolChain().getDriver(), CmdArgs, Args);
84  }
85 
86  CmdArgs.push_back("-lmoldname");
87  CmdArgs.push_back("-lmingwex");
88  for (auto Lib : Args.getAllArgValues(options::OPT_l))
89  if (StringRef(Lib).startswith("msvcr") || StringRef(Lib).startswith("ucrt"))
90  return;
91  CmdArgs.push_back("-lmsvcrt");
92 }
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  const char *LinkingOutput) const {
99  const ToolChain &TC = getToolChain();
100  const Driver &D = TC.getDriver();
101  const SanitizerArgs &Sanitize = TC.getSanitizerArgs();
102 
103  ArgStringList CmdArgs;
104 
105  // Silence warning for "clang -g foo.o -o foo"
106  Args.ClaimAllArgs(options::OPT_g_Group);
107  // and "clang -emit-llvm foo.o -o foo"
108  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  Args.ClaimAllArgs(options::OPT_w);
112 
113  if (!D.SysRoot.empty())
114  CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
115 
116  if (Args.hasArg(options::OPT_s))
117  CmdArgs.push_back("-s");
118 
119  CmdArgs.push_back("-m");
120  switch (TC.getArch()) {
121  case llvm::Triple::x86:
122  CmdArgs.push_back("i386pe");
123  break;
124  case llvm::Triple::x86_64:
125  CmdArgs.push_back("i386pep");
126  break;
127  case llvm::Triple::arm:
128  case llvm::Triple::thumb:
129  // FIXME: this is incorrect for WinCE
130  CmdArgs.push_back("thumb2pe");
131  break;
132  case llvm::Triple::aarch64:
133  CmdArgs.push_back("arm64pe");
134  break;
135  default:
136  llvm_unreachable("Unsupported target architecture.");
137  }
138 
139  Arg *SubsysArg =
140  Args.getLastArg(options::OPT_mwindows, options::OPT_mconsole);
141  if (SubsysArg && SubsysArg->getOption().matches(options::OPT_mwindows)) {
142  CmdArgs.push_back("--subsystem");
143  CmdArgs.push_back("windows");
144  } else if (SubsysArg &&
145  SubsysArg->getOption().matches(options::OPT_mconsole)) {
146  CmdArgs.push_back("--subsystem");
147  CmdArgs.push_back("console");
148  }
149 
150  if (Args.hasArg(options::OPT_mdll))
151  CmdArgs.push_back("--dll");
152  else if (Args.hasArg(options::OPT_shared))
153  CmdArgs.push_back("--shared");
154  if (Args.hasArg(options::OPT_static))
155  CmdArgs.push_back("-Bstatic");
156  else
157  CmdArgs.push_back("-Bdynamic");
158  if (Args.hasArg(options::OPT_mdll) || Args.hasArg(options::OPT_shared)) {
159  CmdArgs.push_back("-e");
160  if (TC.getArch() == llvm::Triple::x86)
161  CmdArgs.push_back("_DllMainCRTStartup@12");
162  else
163  CmdArgs.push_back("DllMainCRTStartup");
164  CmdArgs.push_back("--enable-auto-image-base");
165  }
166 
167  CmdArgs.push_back("-o");
168  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  if (!llvm::sys::path::has_extension(OutputFile)) {
174  CmdArgs.push_back(Args.MakeArgString(Twine(OutputFile) + ".exe"));
175  OutputFile = CmdArgs.back();
176  } else
177  CmdArgs.push_back(OutputFile);
178 
179  Args.AddAllArgs(CmdArgs, options::OPT_e);
180  // FIXME: add -N, -n flags
181  Args.AddLastArg(CmdArgs, options::OPT_r);
182  Args.AddLastArg(CmdArgs, options::OPT_s);
183  Args.AddLastArg(CmdArgs, options::OPT_t);
184  Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
185  Args.AddLastArg(CmdArgs, options::OPT_Z_Flag);
186 
187  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
188  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_mdll)) {
189  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("dllcrt2.o")));
190  } else {
191  if (Args.hasArg(options::OPT_municode))
192  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt2u.o")));
193  else
194  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt2.o")));
195  }
196  if (Args.hasArg(options::OPT_pg))
197  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("gcrt2.o")));
198  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtbegin.o")));
199  }
200 
201  Args.AddAllArgs(CmdArgs, options::OPT_L);
202  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  for (const auto &LibPath : TC.getLibraryPaths()) {
207  if (TC.getVFS().exists(LibPath))
208  CmdArgs.push_back(Args.MakeArgString("-L" + LibPath));
209  }
210  auto CRTPath = TC.getCompilerRTPath();
211  if (TC.getVFS().exists(CRTPath))
212  CmdArgs.push_back(Args.MakeArgString("-L" + CRTPath));
213 
214  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
215 
216  // TODO: Add profile stuff here
217 
218  if (TC.ShouldLinkCXXStdlib(Args)) {
219  bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
220  !Args.hasArg(options::OPT_static);
221  if (OnlyLibstdcxxStatic)
222  CmdArgs.push_back("-Bstatic");
223  TC.AddCXXStdlibLibArgs(Args, CmdArgs);
224  if (OnlyLibstdcxxStatic)
225  CmdArgs.push_back("-Bdynamic");
226  }
227 
228  bool HasWindowsApp = false;
229  for (auto Lib : Args.getAllArgValues(options::OPT_l)) {
230  if (Lib == "windowsapp") {
231  HasWindowsApp = true;
232  break;
233  }
234  }
235 
236  if (!Args.hasArg(options::OPT_nostdlib)) {
237  if (!Args.hasArg(options::OPT_nodefaultlibs)) {
238  if (Args.hasArg(options::OPT_static))
239  CmdArgs.push_back("--start-group");
240 
241  if (Args.hasArg(options::OPT_fstack_protector) ||
242  Args.hasArg(options::OPT_fstack_protector_strong) ||
243  Args.hasArg(options::OPT_fstack_protector_all)) {
244  CmdArgs.push_back("-lssp_nonshared");
245  CmdArgs.push_back("-lssp");
246  }
247 
248  if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
249  options::OPT_fno_openmp, false)) {
250  switch (TC.getDriver().getOpenMPRuntime(Args)) {
251  case Driver::OMPRT_OMP:
252  CmdArgs.push_back("-lomp");
253  break;
254  case Driver::OMPRT_IOMP5:
255  CmdArgs.push_back("-liomp5md");
256  break;
257  case Driver::OMPRT_GOMP:
258  CmdArgs.push_back("-lgomp");
259  break;
260  case Driver::OMPRT_Unknown:
261  // Already diagnosed.
262  break;
263  }
264  }
265 
266  AddLibGCC(Args, CmdArgs);
267 
268  if (Args.hasArg(options::OPT_pg))
269  CmdArgs.push_back("-lgmon");
270 
271  if (Args.hasArg(options::OPT_pthread))
272  CmdArgs.push_back("-lpthread");
273 
274  if (Sanitize.needsAsanRt()) {
275  // MinGW always links against a shared MSVCRT.
276  CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dynamic",
277  ToolChain::FT_Shared));
278  CmdArgs.push_back(
279  TC.getCompilerRTArgString(Args, "asan_dynamic_runtime_thunk"));
280  CmdArgs.push_back("--require-defined");
281  CmdArgs.push_back(TC.getArch() == llvm::Triple::x86
282  ? "___asan_seh_interceptor"
283  : "__asan_seh_interceptor");
284  // Make sure the linker consider all object files from the dynamic
285  // runtime thunk.
286  CmdArgs.push_back("--whole-archive");
287  CmdArgs.push_back(
288  TC.getCompilerRTArgString(Args, "asan_dynamic_runtime_thunk"));
289  CmdArgs.push_back("--no-whole-archive");
290  }
291 
292  TC.addProfileRTLibs(Args, CmdArgs);
293 
294  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  if (Args.hasArg(options::OPT_mwindows)) {
299  CmdArgs.push_back("-lgdi32");
300  CmdArgs.push_back("-lcomdlg32");
301  }
302  CmdArgs.push_back("-ladvapi32");
303  CmdArgs.push_back("-lshell32");
304  CmdArgs.push_back("-luser32");
305  CmdArgs.push_back("-lkernel32");
306  }
307 
308  if (Args.hasArg(options::OPT_static)) {
309  CmdArgs.push_back("--end-group");
310  } else {
311  AddLibGCC(Args, CmdArgs);
312  if (!HasWindowsApp)
313  CmdArgs.push_back("-lkernel32");
314  }
315  }
316 
317  if (!Args.hasArg(options::OPT_nostartfiles)) {
318  // Add crtfastmath.o if available and fast math is enabled.
319  TC.addFastMathRuntimeIfAvailable(Args, CmdArgs);
320 
321  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtend.o")));
322  }
323  }
324  const char *Exec = Args.MakeArgString(TC.GetLinkerPath());
325  C.addCommand(std::make_unique<Command>(JA, *this,
326  ResponseFileSupport::AtFileUTF8(),
327  Exec, CmdArgs, Inputs, Output));
328 }
329 
330 // Simplified from Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple.
331 static bool findGccVersion(StringRef LibDir, std::string &GccLibDir,
332  std::string &Ver) {
333  auto Version = toolchains::Generic_GCC::GCCVersion::Parse("0.0.0");
334  std::error_code EC;
335  for (llvm::sys::fs::directory_iterator LI(LibDir, EC), LE; !EC && LI != LE;
336  LI = LI.increment(EC)) {
337  StringRef VersionText = llvm::sys::path::filename(LI->path());
338  auto CandidateVersion =
339  toolchains::Generic_GCC::GCCVersion::Parse(VersionText);
340  if (CandidateVersion.Major == -1)
341  continue;
342  if (CandidateVersion <= Version)
343  continue;
344  Version = CandidateVersion;
345  Ver = std::string(VersionText);
346  GccLibDir = LI->path();
347  }
348  return Ver.size();
349 }
350 
351 void toolchains::MinGW::findGccLibDir() {
353  Archs.emplace_back(getTriple().getArchName());
354  Archs[0] += "-w64-mingw32";
355  Archs.emplace_back("mingw32");
356  if (Arch.empty())
357  Arch = std::string(Archs[0].str());
358  // lib: Arch Linux, Ubuntu, Windows
359  // lib64: openSUSE Linux
360  for (StringRef CandidateLib : {"lib", "lib64"}) {
361  for (StringRef CandidateArch : Archs) {
363  llvm::sys::path::append(LibDir, CandidateLib, "gcc", CandidateArch);
364  if (findGccVersion(LibDir, GccLibDir, Ver)) {
365  Arch = std::string(CandidateArch);
366  return;
367  }
368  }
369  }
370 }
371 
372 llvm::ErrorOr<std::string> toolchains::MinGW::findGcc() {
374  Gccs.emplace_back(getTriple().getArchName());
375  Gccs[0] += "-w64-mingw32-gcc";
376  Gccs.emplace_back("mingw32-gcc");
377  // Please do not add "gcc" here
378  for (StringRef CandidateGcc : Gccs)
379  if (llvm::ErrorOr<std::string> GPPName = llvm::sys::findProgramByName(CandidateGcc))
380  return GPPName;
381  return make_error_code(std::errc::no_such_file_or_directory);
382 }
383 
384 llvm::ErrorOr<std::string> toolchains::MinGW::findClangRelativeSysroot() {
386  Subdirs.emplace_back(getTriple().str());
387  Subdirs.emplace_back(getTriple().getArchName());
388  Subdirs[1] += "-w64-mingw32";
389  StringRef ClangRoot =
390  llvm::sys::path::parent_path(getDriver().getInstalledDir());
391  StringRef Sep = llvm::sys::path::get_separator();
392  for (StringRef CandidateSubdir : Subdirs) {
393  if (llvm::sys::fs::is_directory(ClangRoot + Sep + CandidateSubdir)) {
394  Arch = std::string(CandidateSubdir);
395  return (ClangRoot + Sep + CandidateSubdir).str();
396  }
397  }
398  return make_error_code(std::errc::no_such_file_or_directory);
399 }
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  RocmInstallation(D, Triple, Args) {
405  getProgramPaths().push_back(getDriver().getInstalledDir());
406 
407  if (getDriver().SysRoot.size())
408  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  else if (llvm::ErrorOr<std::string> TargetSubdir = findClangRelativeSysroot())
412  Base = std::string(llvm::sys::path::parent_path(TargetSubdir.get()));
413  else if (llvm::ErrorOr<std::string> GPPName = findGcc())
414  Base = std::string(llvm::sys::path::parent_path(
415  llvm::sys::path::parent_path(GPPName.get())));
416  else
417  Base = std::string(
418  llvm::sys::path::parent_path(getDriver().getInstalledDir()));
419 
420  Base += llvm::sys::path::get_separator();
421  findGccLibDir();
422  // GccLibDir must precede Base/lib so that the
423  // correct crtbegin.o ,cetend.o would be found.
424  getFilePaths().push_back(GccLibDir);
425  getFilePaths().push_back(
426  (Base + Arch + llvm::sys::path::get_separator() + "lib").str());
427  getFilePaths().push_back(Base + "lib");
428  // openSUSE
429  getFilePaths().push_back(Base + Arch + "/sys-root/mingw/lib");
430 
431  NativeLLVMSupport =
432  Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER)
433  .equals_insensitive("lld");
434 }
435 
437 
439  switch (AC) {
441  if (!Preprocessor)
442  Preprocessor.reset(new tools::gcc::Preprocessor(*this));
443  return Preprocessor.get();
445  if (!Compiler)
446  Compiler.reset(new tools::gcc::Compiler(*this));
447  return Compiler.get();
448  default:
449  return ToolChain::getTool(AC);
450  }
451 }
452 
454  return new tools::MinGW::Assembler(*this);
455 }
456 
458  return new tools::MinGW::Linker(*this);
459 }
460 
462  return NativeLLVMSupport;
463 }
464 
465 bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList &Args) const {
466  Arg *ExceptionArg = Args.getLastArg(options::OPT_fsjlj_exceptions,
467  options::OPT_fseh_exceptions,
468  options::OPT_fdwarf_exceptions);
469  if (ExceptionArg &&
470  ExceptionArg->getOption().matches(options::OPT_fseh_exceptions))
471  return true;
472  return getArch() == llvm::Triple::x86_64 ||
473  getArch() == llvm::Triple::aarch64;
474 }
475 
477  return getArch() == llvm::Triple::x86_64 ||
478  getArch() == llvm::Triple::aarch64;
479 }
480 
481 bool toolchains::MinGW::isPIEDefault() const { return false; }
482 
484  return getArch() == llvm::Triple::x86_64 ||
485  getArch() == llvm::Triple::aarch64;
486 }
487 
488 llvm::ExceptionHandling
489 toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
490  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64)
491  return llvm::ExceptionHandling::WinEH;
492  return llvm::ExceptionHandling::DwarfCFI;
493 }
494 
497  Res |= SanitizerKind::Address;
498  Res |= SanitizerKind::PointerCompare;
499  Res |= SanitizerKind::PointerSubtract;
500  Res |= SanitizerKind::Vptr;
501  return Res;
502 }
503 
504 void toolchains::MinGW::AddCudaIncludeArgs(const ArgList &DriverArgs,
505  ArgStringList &CC1Args) const {
506  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
507 }
508 
509 void toolchains::MinGW::AddHIPIncludeArgs(const ArgList &DriverArgs,
510  ArgStringList &CC1Args) const {
511  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
512 }
513 
514 void toolchains::MinGW::printVerboseInfo(raw_ostream &OS) const {
515  CudaInstallation.print(OS);
516  RocmInstallation.print(OS);
517 }
518 
519 // Include directories for various hosts:
520 
521 // Windows, mingw.org
522 // c:\mingw\lib\gcc\mingw32\4.8.1\include\c++
523 // c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32
524 // c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\backward
525 // c:\mingw\include
526 // c:\mingw\mingw32\include
527 
528 // Windows, mingw-w64 mingw-builds
529 // c:\mingw32\i686-w64-mingw32\include
530 // c:\mingw32\i686-w64-mingw32\include\c++
531 // c:\mingw32\i686-w64-mingw32\include\c++\i686-w64-mingw32
532 // c:\mingw32\i686-w64-mingw32\include\c++\backward
533 
534 // Windows, mingw-w64 msys2
535 // c:\msys64\mingw32\include
536 // c:\msys64\mingw32\i686-w64-mingw32\include
537 // c:\msys64\mingw32\include\c++\4.9.2
538 // c:\msys64\mingw32\include\c++\4.9.2\i686-w64-mingw32
539 // c:\msys64\mingw32\include\c++\4.9.2\backward
540 
541 // openSUSE
542 // /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++
543 // /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32
544 // /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward
545 // /usr/x86_64-w64-mingw32/sys-root/mingw/include
546 
547 // Arch Linux
548 // /usr/i686-w64-mingw32/include/c++/5.1.0
549 // /usr/i686-w64-mingw32/include/c++/5.1.0/i686-w64-mingw32
550 // /usr/i686-w64-mingw32/include/c++/5.1.0/backward
551 // /usr/i686-w64-mingw32/include
552 
553 // Ubuntu
554 // /usr/include/c++/4.8
555 // /usr/include/c++/4.8/x86_64-w64-mingw32
556 // /usr/include/c++/4.8/backward
557 // /usr/x86_64-w64-mingw32/include
558 
559 void toolchains::MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
560  ArgStringList &CC1Args) const {
561  if (DriverArgs.hasArg(options::OPT_nostdinc))
562  return;
563 
564  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
565  SmallString<1024> P(getDriver().ResourceDir);
566  llvm::sys::path::append(P, "include");
567  addSystemInclude(DriverArgs, CC1Args, P.str());
568  }
569 
570  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
571  return;
572 
573  if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) {
574  // openSUSE
575  addSystemInclude(DriverArgs, CC1Args,
576  Base + Arch + "/sys-root/mingw/include");
577  }
578 
579  addSystemInclude(DriverArgs, CC1Args,
580  Base + Arch + llvm::sys::path::get_separator() + "include");
581  addSystemInclude(DriverArgs, CC1Args, Base + "include");
582 }
583 
585  const ArgList &DriverArgs, ArgStringList &CC1Args) const {
586  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
587  DriverArgs.hasArg(options::OPT_nostdincxx))
588  return;
589 
590  StringRef Slash = llvm::sys::path::get_separator();
591 
592  switch (GetCXXStdlibType(DriverArgs)) {
593  case ToolChain::CST_Libcxx: {
594  std::string TargetDir = (Base + "include" + Slash + getTripleString() +
595  Slash + "c++" + Slash + "v1")
596  .str();
597  if (getDriver().getVFS().exists(TargetDir))
598  addSystemInclude(DriverArgs, CC1Args, TargetDir);
599  addSystemInclude(DriverArgs, CC1Args, Base + Arch + Slash + "include" +
600  Slash + "c++" + Slash + "v1");
601  addSystemInclude(DriverArgs, CC1Args,
602  Base + "include" + Slash + "c++" + Slash + "v1");
603  break;
604  }
605 
607  llvm::SmallVector<llvm::SmallString<1024>, 4> CppIncludeBases;
608  CppIncludeBases.emplace_back(Base);
609  llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++");
610  CppIncludeBases.emplace_back(Base);
611  llvm::sys::path::append(CppIncludeBases[1], Arch, "include", "c++", Ver);
612  CppIncludeBases.emplace_back(Base);
613  llvm::sys::path::append(CppIncludeBases[2], "include", "c++", Ver);
614  CppIncludeBases.emplace_back(GccLibDir);
615  llvm::sys::path::append(CppIncludeBases[3], "include", "c++");
616  for (auto &CppIncludeBase : CppIncludeBases) {
617  addSystemInclude(DriverArgs, CC1Args, CppIncludeBase);
618  CppIncludeBase += Slash;
619  addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch);
620  addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward");
621  }
622  break;
623  }
624 }
clang::driver::ToolChain::getSanitizerArgs
const SanitizerArgs & getSanitizerArgs() const
Definition: ToolChain.cpp:117
clang::driver::ToolChain::getVFS
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:99
clang::driver::ToolChain::getProgramPaths
path_list & getProgramPaths()
Definition: ToolChain.h:262
clang::diag
Definition: CLWarnings.h:16
Driver.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::driver::toolchains::MinGW::GetExceptionModel
llvm::ExceptionHandling GetExceptionModel(const llvm::opt::ArgList &Args) const override
GetExceptionModel - Return the tool chain exception model.
Definition: MinGW.cpp:489
clang::driver::toolchains::MinGW::buildAssembler
Tool * buildAssembler() const override
Definition: MinGW.cpp:453
llvm::SmallVector
Definition: LLVM.h:38
clang::driver::Action::ActionClass
ActionClass
Definition: Action.h:55
clang::driver::toolchains::MinGW::IsIntegratedAssemblerDefault
bool IsIntegratedAssemblerDefault() const override
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: MinGW.cpp:436
findGccVersion
static bool findGccVersion(StringRef LibDir, std::string &GccLibDir, std::string &Ver)
Definition: MinGW.cpp:331
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:221
clang::driver::toolchains::MinGW::printVerboseInfo
void printVerboseInfo(raw_ostream &OS) const override
Dispatch to the specific toolchain for verbose printing.
Definition: MinGW.cpp:514
clang::driver::ToolChain::addFastMathRuntimeIfAvailable
bool addFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFastMathRuntimeIfAvailable - If a runtime library exists that sets global flags for unsafe floatin...
Definition: ToolChain.cpp:987
clang::driver::ToolChain::getCompilerRTPath
virtual std::string getCompilerRTPath() const
Definition: ToolChain.cpp:412
clang::driver::Driver::getOpenMPRuntime
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
Definition: Driver.cpp:622
clang::driver::ToolChain::GetFilePath
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:538
clang::driver::toolchains::MinGW::getSupportedSanitizers
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: MinGW.cpp:495
clang::driver::tools::SplitDebugInfo
void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T, const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Output, const char *OutFile)
clang::make_error_code
std::error_code make_error_code(BuildPreambleError Error)
Definition: PrecompiledPreamble.cpp:860
clang::driver::ToolChain::GetLinkerPath
std::string GetLinkerPath(bool *LinkerIsLLD=nullptr, bool *LinkerIsLLDDarwinNew=nullptr) const
Returns the linker path, respecting the -fuse-ld= argument to determine the linker suffix or name.
Definition: ToolChain.cpp:546
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
clang::driver::ToolChain::RuntimeLibType
RuntimeLibType
Definition: ToolChain.h:100
InputInfo.h
clang::driver::toolchains::MinGW::AddClangSystemIncludeArgs
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: MinGW.cpp:559
clang::driver::tools::AddLinkerInputs
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
clang::driver::Action::PreprocessJobClass
@ PreprocessJobClass
Definition: Action.h:59
clang::driver::toolchains::MinGW::isPICDefaultForced
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: MinGW.cpp:483
clang::driver::ToolChain::getFilePaths
path_list & getFilePaths()
Definition: ToolChain.h:259
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
clang::driver::tools::claimNoWarnArgs
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
Options.h
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::interp::LE
bool LE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:239
clang::driver::toolchains::MinGW::buildLinker
Tool * buildLinker() const override
Definition: MinGW.cpp:457
llvm::opt
Definition: DiagnosticOptions.h:19
DriverDiagnostic.h
clang::driver::ToolChain::RLT_Libgcc
@ RLT_Libgcc
Definition: ToolChain.h:102
clang::driver::toolchains::MinGW::getTool
Tool * getTool(Action::ActionClass AC) const override
Definition: MinGW.cpp:438
clang::AttrSyntax::CXX
@ CXX
llvm::SmallString
Definition: LLVM.h:37
clang::driver::Driver::SysRoot
std::string SysRoot
sysroot, if present
Definition: Driver.h:151
clang::driver::SanitizerArgs::needsAsanRt
bool needsAsanRt() const
Definition: SanitizerArgs.h:73
clang::driver::ToolChain::CST_Libcxx
@ CST_Libcxx
Definition: ToolChain.h:96
Base
clang::driver::SanitizerArgs
Definition: SanitizerArgs.h:24
SanitizerArgs.h
clang::driver::ToolChain::CST_Libstdcxx
@ CST_Libstdcxx
Definition: ToolChain.h:97
clang::driver::ToolChain::getArch
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:237
clang::driver::ToolChain::AddFilePathLibArgs
void AddFilePathLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
Definition: ToolChain.cpp:955
clang::driver::ToolChain::ShouldLinkCXXStdlib
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
Definition: ToolChain.cpp:932
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
MinGW.h
clang::driver::ToolChain::getSupportedSanitizers
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:998
clang::driver::ToolChain::getTool
virtual Tool * getTool(Action::ActionClass AC) const
Definition: ToolChain.cpp:329
clang::driver::ToolChain::AddCXXStdlibLibArgs
virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
Definition: ToolChain.cpp:938
clang::driver::toolchains::MinGW::AddHIPIncludeArgs
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific HIP includes.
Definition: MinGW.cpp:509
Compilation.h
clang::driver::ToolChain::addProfileRTLibs
virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass a suitable profile runtime ...
Definition: ToolChain.cpp:749
clang::driver::ToolChain::getCompilerRTArgString
const char * getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
Definition: ToolChain.cpp:484
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
clang::driver::tools::AddRunTimeLibs
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
clang::driver::ToolChain::getLibraryPaths
path_list & getLibraryPaths()
Definition: ToolChain.h:256
clang::driver::toolchains::MinGW::isPICDefault
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: MinGW.cpp:476
clang::driver::tools::gcc::Preprocessor
Definition: Gnu.h:103
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::driver::Action::CompileJobClass
@ CompileJobClass
Definition: Action.h:64
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:83
clang::driver::toolchains::MinGW::IsUnwindTablesDefault
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override
IsUnwindTablesDefault - Does this tool chain use -funwind-tables by default.
Definition: MinGW.cpp:465
CommonArgs.h
clang
Definition: CalledOnceCheck.h:17
clang::driver::toolchains::MinGW::AddCudaIncludeArgs
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific CUDA includes.
Definition: MinGW.cpp:504
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
clang::driver::toolchains::MinGW::HasNativeLLVMSupport
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition: MinGW.cpp:461
clang::driver::tools::gcc::Compiler
Definition: Gnu.h:115
clang::driver::tools::MinGW::Assembler
Definition: MinGW.h:25
clang::driver
Definition: Action.h:31
clang::driver::toolchains::MinGW::AddClangCXXStdlibIncludeArgs
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: MinGW.cpp:584
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:130
clang::driver::JobAction
Definition: Action.h:380
clang::driver::tools::MinGW::Linker
Definition: MinGW.h:37
clang::driver::tools::SplitDebugName
const char * SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Input, const InputInfo &Output)
clang::SanitizerMask
Definition: Sanitizers.h:30
clang::driver::toolchains::MinGW::isPIEDefault
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: MinGW.cpp:481