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
CrossWindowsToolChain(const Driver & D,const llvm::Triple & T,const llvm::opt::ArgList & Args)18 CrossWindowsToolChain::CrossWindowsToolChain(const Driver &D,
19 const llvm::Triple &T,
20 const llvm::opt::ArgList &Args)
21 : Generic_GCC(D, T, Args) {
22 if (GetCXXStdlibType(Args) == ToolChain::CST_Libstdcxx) {
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
IsUnwindTablesDefault() const32 bool CrossWindowsToolChain::IsUnwindTablesDefault() const {
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
isPICDefault() const38 bool CrossWindowsToolChain::isPICDefault() const {
39 return getArch() == llvm::Triple::x86_64;
40 }
41
isPIEDefault() const42 bool CrossWindowsToolChain::isPIEDefault() const {
43 return getArch() == llvm::Triple::x86_64;
44 }
45
isPICDefaultForced() const46 bool CrossWindowsToolChain::isPICDefaultForced() const {
47 return getArch() == llvm::Triple::x86_64;
48 }
49
50 void CrossWindowsToolChain::
AddClangSystemIncludeArgs(const llvm::opt::ArgList & DriverArgs,llvm::opt::ArgStringList & CC1Args) const51 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
70 void CrossWindowsToolChain::
AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList & DriverArgs,llvm::opt::ArgStringList & CC1Args) const71 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)) {
81 case ToolChain::CST_Libcxx:
82 addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/v1");
83 break;
84
85 case ToolChain::CST_Libstdcxx:
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
94 void CrossWindowsToolChain::
AddCXXStdlibLibArgs(const llvm::opt::ArgList & DriverArgs,llvm::opt::ArgStringList & CC1Args) const95 AddCXXStdlibLibArgs(const llvm::opt::ArgList &DriverArgs,
96 llvm::opt::ArgStringList &CC1Args) const {
97 switch (GetCXXStdlibType(DriverArgs)) {
98 case ToolChain::CST_Libcxx:
99 CC1Args.push_back("-lc++");
100 break;
101 case ToolChain::CST_Libstdcxx:
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
getSupportedSanitizers() const112 clang::SanitizerMask CrossWindowsToolChain::getSupportedSanitizers() const {
113 SanitizerMask Res = ToolChain::getSupportedSanitizers();
114 Res |= SanitizerKind::Address;
115 return Res;
116 }
117
buildLinker() const118 Tool *CrossWindowsToolChain::buildLinker() const {
119 return new tools::CrossWindows::Linker(*this);
120 }
121
buildAssembler() const122 Tool *CrossWindowsToolChain::buildAssembler() const {
123 return new tools::CrossWindows::Assembler(*this);
124 }
125