clang  3.8.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  addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
66 }
67 
69 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
70  llvm::opt::ArgStringList &CC1Args) const {
71  const llvm::Triple &Triple = getTriple();
72  const std::string &SysRoot = getDriver().SysRoot;
73 
74  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
75  DriverArgs.hasArg(options::OPT_nostdincxx))
76  return;
77 
78  switch (GetCXXStdlibType(DriverArgs)) {
80  addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/v1");
81  break;
82 
84  addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++");
85  addSystemInclude(DriverArgs, CC1Args,
86  SysRoot + "/usr/include/c++/" + Triple.str());
87  addSystemInclude(DriverArgs, CC1Args,
88  SysRoot + "/usr/include/c++/backwards");
89  }
90 }
91 
93 AddCXXStdlibLibArgs(const llvm::opt::ArgList &DriverArgs,
94  llvm::opt::ArgStringList &CC1Args) const {
95  switch (GetCXXStdlibType(DriverArgs)) {
97  CC1Args.push_back("-lc++");
98  break;
100  CC1Args.push_back("-lstdc++");
101  CC1Args.push_back("-lmingw32");
102  CC1Args.push_back("-lmingwex");
103  CC1Args.push_back("-lgcc");
104  CC1Args.push_back("-lmoldname");
105  CC1Args.push_back("-lmingw32");
106  break;
107  }
108 }
109 
112  Res |= SanitizerKind::Address;
113  return Res;
114 }
115 
117  return new tools::CrossWindows::Linker(*this);
118 }
119 
121  return new tools::CrossWindows::Assembler(*this);
122 }
const llvm::Triple & getTriple() const
Definition: ToolChain.h:129
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:566
Generic_GCC - A tool chain using the 'gcc' command to perform all subcommands; this relies on gcc tra...
Definition: ToolChains.h:31
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:536
bool IsUnwindTablesDefault() const override
IsUnwindTablesDefault - Does this tool chain use -funwind-tables by default.
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:131
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:655
path_list & getFilePaths()
Definition: ToolChain.h:144
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:65
const Driver & getDriver() const
Definition: ToolChain.h:127
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:551
uint64_t SanitizerMask
Definition: Sanitizers.h:24
std::string SysRoot
sysroot, if present
Definition: Driver.h:120
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:110