Nick Lewycky | 6da9077 | 2010-12-31 17:31:54 +0000 | [diff] [blame] | 1 | //===--- ToolChain.cpp - Collections of tools for one platform ------------===// |
Daniel Dunbar | 9e2136d | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 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 | |
Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 10 | #include "Tools.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 11 | #include "clang/Basic/ObjCRuntime.h" |
Daniel Dunbar | 9e2136d | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Action.h" |
| 13 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 14 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Options.h" |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 16 | #include "clang/Driver/SanitizerArgs.h" |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 17 | #include "clang/Driver/ToolChain.h" |
Bob Wilson | 7f05ca3 | 2012-03-21 17:19:12 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringSwitch.h" |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 19 | #include "llvm/Option/Arg.h" |
| 20 | #include "llvm/Option/ArgList.h" |
| 21 | #include "llvm/Option/Option.h" |
John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 23 | #include "llvm/Support/FileSystem.h" |
Daniel Dunbar | 9e2136d | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 24 | using namespace clang::driver; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 25 | using namespace clang; |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 26 | using namespace llvm::opt; |
Daniel Dunbar | 9e2136d | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 27 | |
Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 28 | ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, |
| 29 | const ArgList &A) |
| 30 | : D(D), Triple(T), Args(A) { |
Daniel Dunbar | 9e2136d | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | ToolChain::~ToolChain() { |
| 34 | } |
| 35 | |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 36 | const Driver &ToolChain::getDriver() const { |
Chandler Carruth | b65b111 | 2012-01-25 09:12:06 +0000 | [diff] [blame] | 37 | return D; |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 40 | bool ToolChain::useIntegratedAs() const { |
Rafael Espindola | 248e219 | 2013-03-18 17:52:57 +0000 | [diff] [blame] | 41 | return Args.hasFlag(options::OPT_integrated_as, |
| 42 | options::OPT_no_integrated_as, |
| 43 | IsIntegratedAssemblerDefault()); |
| 44 | } |
| 45 | |
Alexey Samsonov | 609213f9 | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 46 | const SanitizerArgs& ToolChain::getSanitizerArgs() const { |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 47 | if (!SanitizerArguments.get()) |
| 48 | SanitizerArguments.reset(new SanitizerArgs(*this, Args)); |
| 49 | return *SanitizerArguments.get(); |
Alexey Samsonov | 609213f9 | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Daniel Dunbar | c3bd9f5 | 2012-11-08 03:38:26 +0000 | [diff] [blame] | 52 | std::string ToolChain::getDefaultUniversalArchName() const { |
| 53 | // In universal driver terms, the arch name accepted by -arch isn't exactly |
| 54 | // the same as the ones that appear in the triple. Roughly speaking, this is |
| 55 | // an inverse of the darwin::getArchTypeForDarwinArchName() function, but the |
| 56 | // only interesting special case is powerpc. |
| 57 | switch (Triple.getArch()) { |
| 58 | case llvm::Triple::ppc: |
| 59 | return "ppc"; |
| 60 | case llvm::Triple::ppc64: |
| 61 | return "ppc64"; |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 62 | case llvm::Triple::ppc64le: |
| 63 | return "ppc64le"; |
Daniel Dunbar | c3bd9f5 | 2012-11-08 03:38:26 +0000 | [diff] [blame] | 64 | default: |
| 65 | return Triple.getArchName(); |
| 66 | } |
| 67 | } |
| 68 | |
Rafael Espindola | 151a957 | 2012-09-23 03:05:41 +0000 | [diff] [blame] | 69 | bool ToolChain::IsUnwindTablesDefault() const { |
| 70 | return false; |
| 71 | } |
| 72 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 73 | Tool *ToolChain::getClang() const { |
| 74 | if (!Clang) |
| 75 | Clang.reset(new tools::Clang(*this)); |
| 76 | return Clang.get(); |
| 77 | } |
| 78 | |
| 79 | Tool *ToolChain::buildAssembler() const { |
| 80 | return new tools::ClangAs(*this); |
| 81 | } |
| 82 | |
| 83 | Tool *ToolChain::buildLinker() const { |
| 84 | llvm_unreachable("Linking is not supported by this toolchain"); |
| 85 | } |
| 86 | |
| 87 | Tool *ToolChain::getAssemble() const { |
| 88 | if (!Assemble) |
| 89 | Assemble.reset(buildAssembler()); |
| 90 | return Assemble.get(); |
| 91 | } |
| 92 | |
| 93 | Tool *ToolChain::getClangAs() const { |
| 94 | if (!Assemble) |
| 95 | Assemble.reset(new tools::ClangAs(*this)); |
| 96 | return Assemble.get(); |
| 97 | } |
| 98 | |
| 99 | Tool *ToolChain::getLink() const { |
| 100 | if (!Link) |
| 101 | Link.reset(buildLinker()); |
| 102 | return Link.get(); |
| 103 | } |
| 104 | |
| 105 | Tool *ToolChain::getTool(Action::ActionClass AC) const { |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 106 | switch (AC) { |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 107 | case Action::AssembleJobClass: |
| 108 | return getAssemble(); |
| 109 | |
| 110 | case Action::LinkJobClass: |
| 111 | return getLink(); |
| 112 | |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 113 | case Action::InputClass: |
| 114 | case Action::BindArchClass: |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 115 | case Action::LipoJobClass: |
| 116 | case Action::DsymutilJobClass: |
| 117 | case Action::VerifyJobClass: |
| 118 | llvm_unreachable("Invalid tool kind."); |
| 119 | |
| 120 | case Action::CompileJobClass: |
| 121 | case Action::PrecompileJobClass: |
| 122 | case Action::PreprocessJobClass: |
| 123 | case Action::AnalyzeJobClass: |
| 124 | case Action::MigrateJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 125 | return getClang(); |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 126 | } |
Benjamin Kramer | 5fbe262 | 2013-03-21 19:45:46 +0000 | [diff] [blame] | 127 | |
| 128 | llvm_unreachable("Invalid tool kind."); |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Rafael Espindola | 7976446 | 2013-03-24 15:06:53 +0000 | [diff] [blame] | 131 | Tool *ToolChain::SelectTool(const JobAction &JA) const { |
Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 132 | if (getDriver().ShouldUseClangCompiler(JA)) |
Rafael Espindola | 7976446 | 2013-03-24 15:06:53 +0000 | [diff] [blame] | 133 | return getClang(); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 134 | Action::ActionClass AC = JA.getKind(); |
| 135 | if (AC == Action::AssembleJobClass && useIntegratedAs()) |
Rafael Espindola | 7976446 | 2013-03-24 15:06:53 +0000 | [diff] [blame] | 136 | return getClangAs(); |
| 137 | return getTool(AC); |
Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Daniel Dunbar | 9c3ed5f | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 140 | std::string ToolChain::GetFilePath(const char *Name) const { |
Chandler Carruth | b65b111 | 2012-01-25 09:12:06 +0000 | [diff] [blame] | 141 | return D.GetFilePath(Name, *this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | |
Daniel Dunbar | 9e2136d | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Simon Atanasyan | b16488c | 2012-10-03 19:52:37 +0000 | [diff] [blame] | 145 | std::string ToolChain::GetProgramPath(const char *Name) const { |
| 146 | return D.GetProgramPath(Name, *this); |
Daniel Dunbar | 9e2136d | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 147 | } |
Daniel Dunbar | cc7df6c | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 148 | |
| 149 | types::ID ToolChain::LookupTypeForExtension(const char *Ext) const { |
| 150 | return types::lookupTypeForExtension(Ext); |
| 151 | } |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 152 | |
Daniel Dunbar | 62123a1 | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 153 | bool ToolChain::HasNativeLLVMSupport() const { |
| 154 | return false; |
| 155 | } |
| 156 | |
Richard Barton | 5828d7b | 2013-12-17 11:11:25 +0000 | [diff] [blame^] | 157 | bool ToolChain::isCrossCompiling() const { |
| 158 | llvm::Triple HostTriple(LLVM_HOST_TRIPLE); |
| 159 | switch (HostTriple.getArch()) { |
| 160 | // The A32/T32/T16 instruction sets are not seperate architectures in |
| 161 | // this context. |
| 162 | case llvm::Triple::arm: |
| 163 | case llvm::Triple::thumb: |
| 164 | return getArch() != llvm::Triple::arm && |
| 165 | getArch() != llvm::Triple::thumb; |
| 166 | default: |
| 167 | return HostTriple.getArch() != getArch(); |
| 168 | } |
| 169 | } |
| 170 | |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 171 | ObjCRuntime ToolChain::getDefaultObjCRuntime(bool isNonFragile) const { |
David Chisnall | b601c96 | 2012-07-03 20:49:52 +0000 | [diff] [blame] | 172 | return ObjCRuntime(isNonFragile ? ObjCRuntime::GNUstep : ObjCRuntime::GCC, |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 173 | VersionTuple()); |
John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 176 | std::string ToolChain::ComputeLLVMTriple(const ArgList &Args, |
Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 177 | types::ID InputType) const { |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 178 | switch (getTriple().getArch()) { |
| 179 | default: |
| 180 | return getTripleString(); |
| 181 | |
Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 182 | case llvm::Triple::x86_64: { |
| 183 | llvm::Triple Triple = getTriple(); |
| 184 | if (!Triple.isOSDarwin()) |
| 185 | return getTripleString(); |
| 186 | |
| 187 | if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
| 188 | // x86_64h goes in the triple. Other -march options just use the |
| 189 | // vanilla triple we already have. |
| 190 | StringRef MArch = A->getValue(); |
| 191 | if (MArch == "x86_64h") |
| 192 | Triple.setArchName(MArch); |
| 193 | } |
| 194 | return Triple.getTriple(); |
| 195 | } |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 196 | case llvm::Triple::arm: |
| 197 | case llvm::Triple::thumb: { |
| 198 | // FIXME: Factor into subclasses. |
| 199 | llvm::Triple Triple = getTriple(); |
| 200 | |
| 201 | // Thumb2 is the default for V7 on Darwin. |
| 202 | // |
| 203 | // FIXME: Thumb should just be another -target-feaure, not in the triple. |
Bernard Ogden | 3156176 | 2013-12-12 13:27:11 +0000 | [diff] [blame] | 204 | StringRef Suffix = Triple.isOSDarwin() |
| 205 | ? tools::arm::getLLVMArchSuffixForARM(tools::arm::getARMCPUForMArch(Args, Triple)) |
| 206 | : tools::arm::getLLVMArchSuffixForARM(tools::arm::getARMTargetCPU(Args, Triple)); |
Bernard Ogden | 8af41b5 | 2013-12-12 13:27:04 +0000 | [diff] [blame] | 207 | bool ThumbDefault = Suffix.startswith("v6m") || Suffix.startswith("v7m") || |
| 208 | Suffix.startswith("v7em") || |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 209 | (Suffix.startswith("v7") && getTriple().isOSDarwin()); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 210 | std::string ArchName = "arm"; |
Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 211 | |
| 212 | // Assembly files should start in ARM mode. |
| 213 | if (InputType != types::TY_PP_Asm && |
| 214 | Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault)) |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 215 | ArchName = "thumb"; |
| 216 | Triple.setArchName(ArchName + Suffix.str()); |
| 217 | |
| 218 | return Triple.getTriple(); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 223 | std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args, |
| 224 | types::ID InputType) const { |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 225 | // Diagnose use of Darwin OS deployment target arguments on non-Darwin. |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 226 | if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ, |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 227 | options::OPT_miphoneos_version_min_EQ, |
| 228 | options::OPT_mios_simulator_version_min_EQ)) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 229 | getDriver().Diag(diag::err_drv_clang_unsupported) |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 230 | << A->getAsString(Args); |
| 231 | |
Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 232 | return ComputeLLVMTriple(Args, InputType); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Chandler Carruth | 6bfd84f | 2011-11-04 07:12:53 +0000 | [diff] [blame] | 235 | void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 236 | ArgStringList &CC1Args) const { |
| 237 | // Each toolchain should provide the appropriate include flags. |
| 238 | } |
| 239 | |
Chandler Carruth | 05fb585 | 2012-11-21 23:40:23 +0000 | [diff] [blame] | 240 | void ToolChain::addClangTargetOptions(const ArgList &DriverArgs, |
| 241 | ArgStringList &CC1Args) const { |
Rafael Espindola | 66aa045 | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 244 | ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( |
| 245 | const ArgList &Args) const |
| 246 | { |
| 247 | if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) { |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 248 | StringRef Value = A->getValue(); |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 249 | if (Value == "compiler-rt") |
| 250 | return ToolChain::RLT_CompilerRT; |
| 251 | if (Value == "libgcc") |
| 252 | return ToolChain::RLT_Libgcc; |
| 253 | getDriver().Diag(diag::err_drv_invalid_rtlib_name) |
| 254 | << A->getAsString(Args); |
| 255 | } |
| 256 | |
| 257 | return GetDefaultRuntimeLibType(); |
| 258 | } |
| 259 | |
Daniel Dunbar | bf11f79 | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 260 | ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ |
Daniel Dunbar | 092b6fb | 2010-09-14 23:12:40 +0000 | [diff] [blame] | 261 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 262 | StringRef Value = A->getValue(); |
Daniel Dunbar | 092b6fb | 2010-09-14 23:12:40 +0000 | [diff] [blame] | 263 | if (Value == "libc++") |
| 264 | return ToolChain::CST_Libcxx; |
| 265 | if (Value == "libstdc++") |
| 266 | return ToolChain::CST_Libstdcxx; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 267 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) |
Daniel Dunbar | 092b6fb | 2010-09-14 23:12:40 +0000 | [diff] [blame] | 268 | << A->getAsString(Args); |
| 269 | } |
| 270 | |
Daniel Dunbar | bf11f79 | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 271 | return ToolChain::CST_Libstdcxx; |
| 272 | } |
| 273 | |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 274 | /// \brief Utility function to add a system include directory to CC1 arguments. |
| 275 | /*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs, |
| 276 | ArgStringList &CC1Args, |
| 277 | const Twine &Path) { |
| 278 | CC1Args.push_back("-internal-isystem"); |
| 279 | CC1Args.push_back(DriverArgs.MakeArgString(Path)); |
| 280 | } |
| 281 | |
| 282 | /// \brief Utility function to add a system include directory with extern "C" |
| 283 | /// semantics to CC1 arguments. |
| 284 | /// |
| 285 | /// Note that this should be used rarely, and only for directories that |
| 286 | /// historically and for legacy reasons are treated as having implicit extern |
| 287 | /// "C" semantics. These semantics are *ignored* by and large today, but its |
| 288 | /// important to preserve the preprocessor changes resulting from the |
| 289 | /// classification. |
| 290 | /*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs, |
| 291 | ArgStringList &CC1Args, |
| 292 | const Twine &Path) { |
| 293 | CC1Args.push_back("-internal-externc-isystem"); |
| 294 | CC1Args.push_back(DriverArgs.MakeArgString(Path)); |
| 295 | } |
| 296 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 297 | void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs, |
| 298 | ArgStringList &CC1Args, |
| 299 | const Twine &Path) { |
| 300 | if (llvm::sys::fs::exists(Path)) |
| 301 | addExternCSystemInclude(DriverArgs, CC1Args, Path); |
| 302 | } |
| 303 | |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 304 | /// \brief Utility function to add a list of system include directories to CC1. |
| 305 | /*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs, |
| 306 | ArgStringList &CC1Args, |
| 307 | ArrayRef<StringRef> Paths) { |
| 308 | for (ArrayRef<StringRef>::iterator I = Paths.begin(), E = Paths.end(); |
| 309 | I != E; ++I) { |
| 310 | CC1Args.push_back("-internal-isystem"); |
| 311 | CC1Args.push_back(DriverArgs.MakeArgString(*I)); |
| 312 | } |
| 313 | } |
| 314 | |
Chandler Carruth | 814db37 | 2011-11-04 23:49:01 +0000 | [diff] [blame] | 315 | void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 316 | ArgStringList &CC1Args) const { |
Chandler Carruth | 4c81dfa | 2011-11-04 07:43:33 +0000 | [diff] [blame] | 317 | // Header search paths should be handled by each of the subclasses. |
| 318 | // Historically, they have not been, and instead have been handled inside of |
| 319 | // the CC1-layer frontend. As the logic is hoisted out, this generic function |
| 320 | // will slowly stop being called. |
| 321 | // |
| 322 | // While it is being called, replicate a bit of a hack to propagate the |
| 323 | // '-stdlib=' flag down to CC1 so that it can in turn customize the C++ |
| 324 | // header search paths with it. Once all systems are overriding this |
| 325 | // function, the CC1 flag and this line can be removed. |
Chandler Carruth | 814db37 | 2011-11-04 23:49:01 +0000 | [diff] [blame] | 326 | DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ); |
Daniel Dunbar | bf11f79 | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 329 | void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 330 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | bf11f79 | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 331 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 332 | |
| 333 | switch (Type) { |
Daniel Dunbar | 092b6fb | 2010-09-14 23:12:40 +0000 | [diff] [blame] | 334 | case ToolChain::CST_Libcxx: |
| 335 | CmdArgs.push_back("-lc++"); |
| 336 | break; |
| 337 | |
Daniel Dunbar | bf11f79 | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 338 | case ToolChain::CST_Libstdcxx: |
| 339 | CmdArgs.push_back("-lstdc++"); |
| 340 | break; |
| 341 | } |
| 342 | } |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 343 | |
| 344 | void ToolChain::AddCCKextLibArgs(const ArgList &Args, |
| 345 | ArgStringList &CmdArgs) const { |
| 346 | CmdArgs.push_back("-lcc_kext"); |
| 347 | } |
Benjamin Kramer | 058666a | 2012-10-04 19:42:20 +0000 | [diff] [blame] | 348 | |
| 349 | bool ToolChain::AddFastMathRuntimeIfAvailable(const ArgList &Args, |
| 350 | ArgStringList &CmdArgs) const { |
| 351 | // Check if -ffast-math or -funsafe-math is enabled. |
| 352 | Arg *A = Args.getLastArg(options::OPT_ffast_math, |
| 353 | options::OPT_fno_fast_math, |
| 354 | options::OPT_funsafe_math_optimizations, |
| 355 | options::OPT_fno_unsafe_math_optimizations); |
| 356 | |
| 357 | if (!A || A->getOption().getID() == options::OPT_fno_fast_math || |
| 358 | A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations) |
| 359 | return false; |
| 360 | |
| 361 | // If crtfastmath.o exists add it to the arguments. |
| 362 | std::string Path = GetFilePath("crtfastmath.o"); |
| 363 | if (Path == "crtfastmath.o") // Not found. |
| 364 | return false; |
| 365 | |
| 366 | CmdArgs.push_back(Args.MakeArgString(Path)); |
| 367 | return true; |
| 368 | } |