clang  3.9.0
CrossWindowsToolChain.cpp
Go to the documentation of this file.
1 //===--- CrossWindowsToolChain.cpp - Cross Windows Tool Chain -------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "ToolChains.h"
11 #include "clang/Driver/Driver.h"
12 #include "clang/Driver/Options.h"
13 #include "llvm/Option/ArgList.h"
14 
15 using namespace clang::driver;
16 using namespace clang::driver::toolchains;
17 
19  const llvm::Triple &T,
20  const llvm::opt::ArgList &Args)
21  : Generic_GCC(D, T, Args) {
23  const std::string &SysRoot = D.SysRoot;
24 
25  // libstdc++ resides in /usr/lib, but depends on libgcc which is placed in
26  // /usr/lib/gcc.
27  getFilePaths().push_back(SysRoot + "/usr/lib");
28  getFilePaths().push_back(SysRoot + "/usr/lib/gcc");
29  }
30 }
31 
33  // FIXME: all non-x86 targets need unwind tables, however, LLVM currently does
34  // not know how to emit them.
35  return getArch() == llvm::Triple::x86_64;
36 }
37 
39  return getArch() == llvm::Triple::x86_64;
40 }
41 
43  return getArch() == llvm::Triple::x86_64;
44 }
45 
47  return getArch() == llvm::Triple::x86_64;
48 }
49 
51 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
52  llvm::opt::ArgStringList &CC1Args) const {
53  const Driver &D = getDriver();
54  const std::string &SysRoot = D.SysRoot;
55 
56  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
57  return;
58 
59  addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
60  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
61  SmallString<128> ResourceDir(D.ResourceDir);
62  llvm::sys::path::append(ResourceDir, "include");
63  addSystemInclude(DriverArgs, CC1Args, ResourceDir);
64  }
65  for (const auto &P : DriverArgs.getAllArgValues(options::OPT_isystem_after))
66  addSystemInclude(DriverArgs, CC1Args, P);
67  addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
68 }
69 
71 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
72  llvm::opt::ArgStringList &CC1Args) const {
73  const llvm::Triple &Triple = getTriple();
74  const std::string &SysRoot = getDriver().SysRoot;
75 
76  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
77  DriverArgs.hasArg(options::OPT_nostdincxx))
78  return;
79 
80  switch (GetCXXStdlibType(DriverArgs)) {
82  addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/v1");
83  break;
84 
86  addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++");
87  addSystemInclude(DriverArgs, CC1Args,
88  SysRoot + "/usr/include/c++/" + Triple.str());
89  addSystemInclude(DriverArgs, CC1Args,
90  SysRoot + "/usr/include/c++/backwards");
91  }
92 }
93 
95 AddCXXStdlibLibArgs(const llvm::opt::ArgList &DriverArgs,
96  llvm::opt::ArgStringList &CC1Args) const {
97  switch (GetCXXStdlibType(DriverArgs)) {
99  CC1Args.push_back("-lc++");
100  break;
102  CC1Args.push_back("-lstdc++");
103  CC1Args.push_back("-lmingw32");
104  CC1Args.push_back("-lmingwex");
105  CC1Args.push_back("-lgcc");
106  CC1Args.push_back("-lmoldname");
107  CC1Args.push_back("-lmingw32");
108  break;
109  }
110 }
111 
114  Res |= SanitizerKind::Address;
115  return Res;
116 }
117 
119  return new tools::CrossWindows::Linker(*this);
120 }
121 
123  return new tools::CrossWindows::Assembler(*this);
124 }
const llvm::Triple & getTriple() const
Definition: ToolChain.h:130
static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory with extern "C" semantics to CC1 arguments...
Definition: ToolChain.cpp:595
Generic_GCC - A tool chain using the 'gcc' command to perform all subcommands; this relies on gcc tra...
Definition: ToolChains.h:33
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:554
bool IsUnwindTablesDefault() const override
IsUnwindTablesDefault - Does this tool chain use -funwind-tables by default.
StringRef P
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:132
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...
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:684
path_list & getFilePaths()
Definition: ToolChain.h:145
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:66
const Driver & getDriver() const
Definition: ToolChain.h:128
CrossWindowsToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:580
uint64_t SanitizerMask
Definition: Sanitizers.h:24
std::string SysRoot
sysroot, if present
Definition: Driver.h:127
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:117