Nick Lewycky | 3fdcc6f | 2010-12-31 17:31:54 +0000 | [diff] [blame] | 1 | //===--- ToolChains.cpp - ToolChain Implementations -----------------------===// |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +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 | |
| 10 | #include "ToolChains.h" |
| 11 | |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Arg.h" |
| 13 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | 0f602de | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Compilation.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 16 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 17 | #include "clang/Driver/HostInfo.h" |
Daniel Dunbar | 27e738d | 2009-11-19 00:15:11 +0000 | [diff] [blame] | 18 | #include "clang/Driver/OptTable.h" |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Option.h" |
Daniel Dunbar | 265e9ef | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 20 | #include "clang/Driver/Options.h" |
Douglas Gregor | 34916db | 2010-09-03 17:16:03 +0000 | [diff] [blame] | 21 | #include "clang/Basic/Version.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallString.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 26 | #include "llvm/Support/FileSystem.h" |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 27 | #include "llvm/Support/MemoryBuffer.h" |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 30 | #include "llvm/Support/system_error.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 31 | |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 32 | #include <cstdlib> // ::getenv |
| 33 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 34 | using namespace clang::driver; |
| 35 | using namespace clang::driver::toolchains; |
| 36 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 37 | /// Darwin - Darwin tool chain for i386 and x86_64. |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 38 | |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 39 | Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple) |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 40 | : ToolChain(Host, Triple), TargetInitialized(false) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 41 | { |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 42 | // Compute the initial Darwin version based on the host. |
| 43 | bool HadExtra; |
| 44 | std::string OSName = Triple.getOSName(); |
Daniel Dunbar | 34f9e29 | 2011-02-25 21:20:15 +0000 | [diff] [blame] | 45 | if (!Driver::GetReleaseVersion(&OSName.c_str()[6], |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 46 | DarwinVersion[0], DarwinVersion[1], |
| 47 | DarwinVersion[2], HadExtra)) |
| 48 | getDriver().Diag(clang::diag::err_drv_invalid_darwin_version) << OSName; |
| 49 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 50 | llvm::raw_string_ostream(MacosxVersionMin) |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 51 | << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.' |
| 52 | << DarwinVersion[1]; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Daniel Dunbar | 4180011 | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 55 | types::ID Darwin::LookupTypeForExtension(const char *Ext) const { |
| 56 | types::ID Ty = types::lookupTypeForExtension(Ext); |
| 57 | |
| 58 | // Darwin always preprocesses assembly files (unless -x is used explicitly). |
| 59 | if (Ty == types::TY_PP_Asm) |
| 60 | return types::TY_Asm; |
| 61 | |
| 62 | return Ty; |
| 63 | } |
| 64 | |
Daniel Dunbar | b993f5d | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 65 | bool Darwin::HasNativeLLVMSupport() const { |
| 66 | return true; |
| 67 | } |
| 68 | |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 69 | // FIXME: Can we tablegen this? |
| 70 | static const char *GetArmArchForMArch(llvm::StringRef Value) { |
| 71 | if (Value == "armv6k") |
| 72 | return "armv6"; |
| 73 | |
| 74 | if (Value == "armv5tej") |
| 75 | return "armv5"; |
| 76 | |
| 77 | if (Value == "xscale") |
| 78 | return "xscale"; |
| 79 | |
| 80 | if (Value == "armv4t") |
| 81 | return "armv4t"; |
| 82 | |
| 83 | if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" || |
| 84 | Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" || |
| 85 | Value == "armv7m") |
| 86 | return "armv7"; |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | // FIXME: Can we tablegen this? |
| 92 | static const char *GetArmArchForMCpu(llvm::StringRef Value) { |
| 93 | if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" || |
| 94 | Value == "arm946e-s" || Value == "arm966e-s" || |
| 95 | Value == "arm968e-s" || Value == "arm10e" || |
| 96 | Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" || |
| 97 | Value == "arm1026ej-s") |
| 98 | return "armv5"; |
| 99 | |
| 100 | if (Value == "xscale") |
| 101 | return "xscale"; |
| 102 | |
| 103 | if (Value == "arm1136j-s" || Value == "arm1136jf-s" || |
| 104 | Value == "arm1176jz-s" || Value == "arm1176jzf-s") |
| 105 | return "armv6"; |
| 106 | |
| 107 | if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3") |
| 108 | return "armv7"; |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const { |
| 114 | switch (getTriple().getArch()) { |
| 115 | default: |
| 116 | return getArchName(); |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 117 | |
| 118 | case llvm::Triple::thumb: |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 119 | case llvm::Triple::arm: { |
| 120 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
| 121 | if (const char *Arch = GetArmArchForMArch(A->getValue(Args))) |
| 122 | return Arch; |
| 123 | |
| 124 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
| 125 | if (const char *Arch = GetArmArchForMCpu(A->getValue(Args))) |
| 126 | return Arch; |
| 127 | |
| 128 | return "arm"; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 133 | Darwin::~Darwin() { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 134 | // Free tool implementations. |
| 135 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 136 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 137 | delete it->second; |
| 138 | } |
| 139 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 140 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args) const { |
| 141 | llvm::Triple Triple(ComputeLLVMTriple(Args)); |
| 142 | |
| 143 | // If the target isn't initialized (e.g., an unknown Darwin platform, return |
| 144 | // the default triple). |
| 145 | if (!isTargetInitialized()) |
| 146 | return Triple.getTriple(); |
| 147 | |
| 148 | unsigned Version[3]; |
| 149 | getTargetVersion(Version); |
| 150 | |
| 151 | // Mangle the target version into the OS triple component. For historical |
| 152 | // reasons that make little sense, the version passed here is the "darwin" |
| 153 | // version, which drops the 10 and offsets by 4. See inverse code when |
| 154 | // setting the OS version preprocessor define. |
| 155 | if (!isTargetIPhoneOS()) { |
| 156 | Version[0] = Version[1] + 4; |
| 157 | Version[1] = Version[2]; |
| 158 | Version[2] = 0; |
| 159 | } else { |
| 160 | // Use the environment to communicate that we are targetting iPhoneOS. |
| 161 | Triple.setEnvironmentName("iphoneos"); |
| 162 | } |
| 163 | |
| 164 | llvm::SmallString<16> Str; |
| 165 | llvm::raw_svector_ostream(Str) << "darwin" << Version[0] |
| 166 | << "." << Version[1] << "." << Version[2]; |
| 167 | Triple.setOSName(Str.str()); |
| 168 | |
| 169 | return Triple.getTriple(); |
| 170 | } |
| 171 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 172 | Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA, |
| 173 | const ActionList &Inputs) const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 174 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 175 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 176 | Key = Action::AnalyzeJobClass; |
| 177 | else |
| 178 | Key = JA.getKind(); |
| 179 | |
Daniel Dunbar | 0f602de | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 180 | // FIXME: This doesn't belong here, but ideally we will support static soon |
| 181 | // anyway. |
| 182 | bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) || |
| 183 | C.getArgs().hasArg(options::OPT_static) || |
| 184 | C.getArgs().hasArg(options::OPT_fapple_kext)); |
| 185 | bool IsIADefault = IsIntegratedAssemblerDefault() && !HasStatic; |
| 186 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 187 | options::OPT_no_integrated_as, |
| 188 | IsIADefault); |
| 189 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 190 | Tool *&T = Tools[Key]; |
| 191 | if (!T) { |
| 192 | switch (Key) { |
| 193 | case Action::InputClass: |
| 194 | case Action::BindArchClass: |
| 195 | assert(0 && "Invalid tool kind."); |
| 196 | case Action::PreprocessJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 197 | T = new tools::darwin::Preprocess(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 198 | case Action::AnalyzeJobClass: |
| 199 | T = new tools::Clang(*this); break; |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 200 | case Action::PrecompileJobClass: |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 201 | case Action::CompileJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 202 | T = new tools::darwin::Compile(*this); break; |
Daniel Dunbar | 0f602de | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 203 | case Action::AssembleJobClass: { |
| 204 | if (UseIntegratedAs) |
| 205 | T = new tools::ClangAs(*this); |
| 206 | else |
| 207 | T = new tools::darwin::Assemble(*this); |
| 208 | break; |
| 209 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 210 | case Action::LinkJobClass: |
Daniel Dunbar | 8f28962 | 2009-09-04 17:39:02 +0000 | [diff] [blame] | 211 | T = new tools::darwin::Link(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 212 | case Action::LipoJobClass: |
| 213 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 214 | case Action::DsymutilJobClass: |
| 215 | T = new tools::darwin::Dsymutil(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| 219 | return *T; |
| 220 | } |
| 221 | |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 222 | |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 223 | DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple) |
| 224 | : Darwin(Host, Triple) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 225 | { |
Daniel Dunbar | 4702309 | 2011-03-18 19:25:15 +0000 | [diff] [blame] | 226 | std::string UsrPrefix = "llvm-gcc-4.2/"; |
| 227 | |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 228 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 229 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 230 | getProgramPaths().push_back(getDriver().Dir); |
| 231 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 232 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 233 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 234 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 235 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 236 | |
| 237 | // For fallback, we need to know how to find the GCC cc1 executables, so we |
Daniel Dunbar | 4702309 | 2011-03-18 19:25:15 +0000 | [diff] [blame] | 238 | // also add the GCC libexec paths. This is legacy code that can be removed |
| 239 | // once fallback is no longer useful. |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 240 | std::string ToolChainDir = "i686-apple-darwin"; |
| 241 | ToolChainDir += llvm::utostr(DarwinVersion[0]); |
| 242 | ToolChainDir += "/4.2.1"; |
| 243 | |
| 244 | std::string Path = getDriver().Dir; |
Daniel Dunbar | 4702309 | 2011-03-18 19:25:15 +0000 | [diff] [blame] | 245 | Path += "/../" + UsrPrefix + "libexec/gcc/"; |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 246 | Path += ToolChainDir; |
| 247 | getProgramPaths().push_back(Path); |
| 248 | |
Daniel Dunbar | 4702309 | 2011-03-18 19:25:15 +0000 | [diff] [blame] | 249 | Path = "/usr/" + UsrPrefix + "libexec/gcc/"; |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 250 | Path += ToolChainDir; |
| 251 | getProgramPaths().push_back(Path); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, |
| 255 | ArgStringList &CmdArgs) const { |
| 256 | // The Clang toolchain uses explicit paths for internal libraries. |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 257 | |
| 258 | // Unfortunately, we still might depend on a few of the libraries that are |
| 259 | // only available in the gcc library directory (in particular |
| 260 | // libstdc++.dylib). For now, hardcode the path to the known install location. |
| 261 | llvm::sys::Path P(getDriver().Dir); |
| 262 | P.eraseComponent(); // .../usr/bin -> ../usr |
| 263 | P.appendComponent("lib"); |
| 264 | P.appendComponent("gcc"); |
| 265 | switch (getTriple().getArch()) { |
| 266 | default: |
| 267 | assert(0 && "Invalid Darwin arch!"); |
| 268 | case llvm::Triple::x86: |
| 269 | case llvm::Triple::x86_64: |
| 270 | P.appendComponent("i686-apple-darwin10"); |
| 271 | break; |
| 272 | case llvm::Triple::arm: |
| 273 | case llvm::Triple::thumb: |
| 274 | P.appendComponent("arm-apple-darwin10"); |
| 275 | break; |
| 276 | case llvm::Triple::ppc: |
| 277 | case llvm::Triple::ppc64: |
| 278 | P.appendComponent("powerpc-apple-darwin10"); |
| 279 | break; |
| 280 | } |
| 281 | P.appendComponent("4.2.1"); |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 282 | |
| 283 | // Determine the arch specific GCC subdirectory. |
| 284 | const char *ArchSpecificDir = 0; |
| 285 | switch (getTriple().getArch()) { |
| 286 | default: |
| 287 | break; |
| 288 | case llvm::Triple::arm: |
Daniel Dunbar | 3a0e392 | 2010-08-26 00:55:52 +0000 | [diff] [blame] | 289 | case llvm::Triple::thumb: { |
| 290 | std::string Triple = ComputeLLVMTriple(Args); |
| 291 | llvm::StringRef TripleStr = Triple; |
| 292 | if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5")) |
| 293 | ArchSpecificDir = "v5"; |
| 294 | else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6")) |
| 295 | ArchSpecificDir = "v6"; |
| 296 | else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7")) |
| 297 | ArchSpecificDir = "v7"; |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 298 | break; |
Daniel Dunbar | 3a0e392 | 2010-08-26 00:55:52 +0000 | [diff] [blame] | 299 | } |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 300 | case llvm::Triple::ppc64: |
| 301 | ArchSpecificDir = "ppc64"; |
| 302 | break; |
| 303 | case llvm::Triple::x86_64: |
| 304 | ArchSpecificDir = "x86_64"; |
| 305 | break; |
| 306 | } |
| 307 | |
| 308 | if (ArchSpecificDir) { |
| 309 | P.appendComponent(ArchSpecificDir); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 310 | bool Exists; |
| 311 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 312 | CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); |
| 313 | P.eraseComponent(); |
| 314 | } |
| 315 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 316 | bool Exists; |
| 317 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 318 | CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 322 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 323 | // Darwin doesn't support real static executables, don't link any runtime |
| 324 | // libraries with -static. |
| 325 | if (Args.hasArg(options::OPT_static)) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 326 | return; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 327 | |
| 328 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 329 | // cares. This is useful in situations where someone wants to statically link |
| 330 | // something like libstdc++, and needs its runtime support routines. |
| 331 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 332 | getDriver().Diag(clang::diag::err_drv_unsupported_opt) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 333 | << A->getAsString(Args); |
| 334 | return; |
| 335 | } |
| 336 | |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 337 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 338 | // target specific static runtime library. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 339 | CmdArgs.push_back("-lSystem"); |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 340 | |
| 341 | // Select the dynamic runtime library and the target specific static library. |
| 342 | const char *DarwinStaticLib = 0; |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 343 | if (isTargetIPhoneOS()) { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 344 | CmdArgs.push_back("-lgcc_s.1"); |
| 345 | |
| 346 | // We may need some static functions for armv6/thumb which are required to |
| 347 | // be in the same linkage unit as their caller. |
| 348 | if (getDarwinArchName(Args) == "armv6") |
| 349 | DarwinStaticLib = "libclang_rt.armv6.a"; |
| 350 | } else { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 351 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 352 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 353 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 354 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 355 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 356 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 357 | |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 358 | // For OS X, we thought we would only need a static runtime library when |
| 359 | // targetting 10.4, to provide versions of the static functions which were |
| 360 | // omitted from 10.4.dylib. |
| 361 | // |
| 362 | // Unfortunately, that turned out to not be true, because Darwin system |
| 363 | // headers can still use eprintf on i386, and it is not exported from |
| 364 | // libSystem. Therefore, we still must provide a runtime library just for |
| 365 | // the tiny tiny handful of projects that *might* use that symbol. |
| 366 | if (isMacosxVersionLT(10, 5)) { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 367 | DarwinStaticLib = "libclang_rt.10.4.a"; |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 368 | } else { |
| 369 | if (getTriple().getArch() == llvm::Triple::x86) |
| 370 | DarwinStaticLib = "libclang_rt.eprintf.a"; |
| 371 | } |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /// Add the target specific static library, if needed. |
| 375 | if (DarwinStaticLib) { |
| 376 | llvm::sys::Path P(getDriver().ResourceDir); |
| 377 | P.appendComponent("lib"); |
| 378 | P.appendComponent("darwin"); |
| 379 | P.appendComponent(DarwinStaticLib); |
| 380 | |
| 381 | // For now, allow missing resource libraries to support developers who may |
| 382 | // not have compiler-rt checked out or integrated into their build. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 383 | bool Exists; |
| 384 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 385 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 386 | } |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 389 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 390 | const OptTable &Opts = getDriver().getOpts(); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 391 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 392 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
| 393 | Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 394 | if (OSXVersion && iPhoneVersion) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 395 | getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 396 | << OSXVersion->getAsString(Args) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | << iPhoneVersion->getAsString(Args); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 398 | iPhoneVersion = 0; |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 399 | } else if (!OSXVersion && !iPhoneVersion) { |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 400 | // If neither OS X nor iPhoneOS targets were specified, check for |
| 401 | // environment defines. |
| 402 | const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET"); |
| 403 | const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET"); |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 404 | |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 405 | // Ignore empty strings. |
| 406 | if (OSXTarget && OSXTarget[0] == '\0') |
| 407 | OSXTarget = 0; |
| 408 | if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0') |
| 409 | iPhoneOSTarget = 0; |
| 410 | |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 411 | // Diagnose conflicting deployment targets, and choose default platform |
| 412 | // based on the tool chain. |
| 413 | // |
| 414 | // FIXME: Don't hardcode default here. |
| 415 | if (OSXTarget && iPhoneOSTarget) { |
| 416 | // FIXME: We should see if we can get away with warning or erroring on |
| 417 | // this. Perhaps put under -pedantic? |
| 418 | if (getTriple().getArch() == llvm::Triple::arm || |
| 419 | getTriple().getArch() == llvm::Triple::thumb) |
Daniel Dunbar | 84d1e6e | 2010-03-20 08:47:42 +0000 | [diff] [blame] | 420 | OSXTarget = 0; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 421 | else |
Daniel Dunbar | 84d1e6e | 2010-03-20 08:47:42 +0000 | [diff] [blame] | 422 | iPhoneOSTarget = 0; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 423 | } |
Daniel Dunbar | 1a3c1d9 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 424 | |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 425 | if (OSXTarget) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 426 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 427 | OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget); |
| 428 | Args.append(OSXVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 429 | } else if (iPhoneOSTarget) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 430 | const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 431 | iPhoneVersion = Args.MakeJoinedArg(0, O, iPhoneOSTarget); |
| 432 | Args.append(iPhoneVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 433 | } else { |
Daniel Dunbar | 2bb38d0 | 2010-07-15 16:18:06 +0000 | [diff] [blame] | 434 | // Otherwise, assume we are targeting OS X. |
| 435 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 436 | OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin); |
| 437 | Args.append(OSXVersion); |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 438 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 439 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 441 | // Set the tool chain target information. |
| 442 | unsigned Major, Minor, Micro; |
| 443 | bool HadExtra; |
| 444 | if (OSXVersion) { |
| 445 | assert(!iPhoneVersion && "Unknown target platform!"); |
| 446 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor, |
| 447 | Micro, HadExtra) || HadExtra || |
| 448 | Major != 10 || Minor >= 10 || Micro >= 10) |
| 449 | getDriver().Diag(clang::diag::err_drv_invalid_version_number) |
| 450 | << OSXVersion->getAsString(Args); |
| 451 | } else { |
| 452 | assert(iPhoneVersion && "Unknown target platform!"); |
| 453 | if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor, |
| 454 | Micro, HadExtra) || HadExtra || |
| 455 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 456 | getDriver().Diag(clang::diag::err_drv_invalid_version_number) |
| 457 | << iPhoneVersion->getAsString(Args); |
| 458 | } |
| 459 | setTarget(iPhoneVersion, Major, Minor, Micro); |
Daniel Dunbar | c0e665e | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 462 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 463 | ArgStringList &CmdArgs) const { |
| 464 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 465 | |
| 466 | switch (Type) { |
| 467 | case ToolChain::CST_Libcxx: |
| 468 | CmdArgs.push_back("-lc++"); |
| 469 | break; |
| 470 | |
| 471 | case ToolChain::CST_Libstdcxx: { |
| 472 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 473 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 474 | // platforms we care about it was -lstdc++.6, so we search for that |
| 475 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 476 | |
| 477 | // Check in the sysroot first. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 478 | bool Exists; |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 479 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 480 | llvm::sys::Path P(A->getValue(Args)); |
| 481 | P.appendComponent("usr"); |
| 482 | P.appendComponent("lib"); |
| 483 | P.appendComponent("libstdc++.dylib"); |
| 484 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 485 | if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) { |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 486 | P.eraseComponent(); |
| 487 | P.appendComponent("libstdc++.6.dylib"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 488 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 489 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 490 | return; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | // Otherwise, look in the root. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 496 | if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&& |
| 497 | (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){ |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 498 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 499 | return; |
| 500 | } |
| 501 | |
| 502 | // Otherwise, let the linker search. |
| 503 | CmdArgs.push_back("-lstdc++"); |
| 504 | break; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 509 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 510 | ArgStringList &CmdArgs) const { |
| 511 | |
| 512 | // For Darwin platforms, use the compiler-rt-based support library |
| 513 | // instead of the gcc-provided one (which is also incidentally |
| 514 | // only present in the gcc lib dir, which makes it hard to find). |
| 515 | |
| 516 | llvm::sys::Path P(getDriver().ResourceDir); |
| 517 | P.appendComponent("lib"); |
| 518 | P.appendComponent("darwin"); |
| 519 | P.appendComponent("libclang_rt.cc_kext.a"); |
| 520 | |
| 521 | // For now, allow missing resource libraries to support developers who may |
| 522 | // not have compiler-rt checked out or integrated into their build. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 523 | bool Exists; |
| 524 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 525 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 526 | } |
| 527 | |
Daniel Dunbar | c0e665e | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 528 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 529 | const char *BoundArch) const { |
| 530 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 531 | const OptTable &Opts = getDriver().getOpts(); |
| 532 | |
| 533 | // FIXME: We really want to get out of the tool chain level argument |
| 534 | // translation business, as it makes the driver functionality much |
| 535 | // more opaque. For now, we follow gcc closely solely for the |
| 536 | // purpose of easily achieving feature parity & testability. Once we |
| 537 | // have something that works, we should reevaluate each translation |
| 538 | // and try to push it down into tool specific logic. |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 539 | |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 540 | for (ArgList::const_iterator it = Args.begin(), |
| 541 | ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 542 | Arg *A = *it; |
| 543 | |
| 544 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 545 | // FIXME: Canonicalize name. |
| 546 | if (getArchName() != A->getValue(Args, 0)) |
| 547 | continue; |
| 548 | |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 549 | Arg *OriginalArg = A; |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 550 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1)); |
| 551 | unsigned Prev = Index; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 552 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 553 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 554 | // If the argument parsing failed or more than one argument was |
| 555 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 556 | // extra arguments. Emit an error and ignore. |
| 557 | // |
| 558 | // We also want to disallow any options which would alter the |
| 559 | // driver behavior; that isn't going to work in our model. We |
| 560 | // use isDriverOption() as an approximation, although things |
| 561 | // like -O4 are going to slip through. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 562 | if (!XarchArg || Index > Prev + 1 || |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 563 | XarchArg->getOption().isDriverOption()) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 564 | getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 565 | << A->getAsString(Args); |
| 566 | continue; |
| 567 | } |
| 568 | |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 569 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 570 | A = XarchArg; |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 571 | |
| 572 | DAL->AddSynthesizedArg(A); |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 573 | |
| 574 | // Linker input arguments require custom handling. The problem is that we |
| 575 | // have already constructed the phase actions, so we can not treat them as |
| 576 | // "input arguments". |
| 577 | if (A->getOption().isLinkerInput()) { |
| 578 | // Convert the argument into individual Zlinker_input_args. |
| 579 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { |
| 580 | DAL->AddSeparateArg(OriginalArg, |
| 581 | Opts.getOption(options::OPT_Zlinker_input), |
| 582 | A->getValue(Args, i)); |
| 583 | |
| 584 | } |
| 585 | continue; |
| 586 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 587 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 588 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 589 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 590 | // gcc translates options twice, which means that self-expanding |
| 591 | // options add duplicates. |
Daniel Dunbar | 9e1f982 | 2009-11-19 04:14:53 +0000 | [diff] [blame] | 592 | switch ((options::ID) A->getOption().getID()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 593 | default: |
| 594 | DAL->append(A); |
| 595 | break; |
| 596 | |
| 597 | case options::OPT_mkernel: |
| 598 | case options::OPT_fapple_kext: |
| 599 | DAL->append(A); |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 600 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
| 601 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 602 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 604 | case options::OPT_dependency_file: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 605 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), |
| 606 | A->getValue(Args)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 607 | break; |
| 608 | |
| 609 | case options::OPT_gfull: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 610 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 611 | DAL->AddFlagArg(A, |
| 612 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 613 | break; |
| 614 | |
| 615 | case options::OPT_gused: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 616 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 617 | DAL->AddFlagArg(A, |
| 618 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 619 | break; |
| 620 | |
| 621 | case options::OPT_fterminated_vtables: |
| 622 | case options::OPT_findirect_virtual_calls: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 623 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_fapple_kext)); |
| 624 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 625 | break; |
| 626 | |
| 627 | case options::OPT_shared: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 628 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 629 | break; |
| 630 | |
| 631 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 632 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 633 | break; |
| 634 | |
| 635 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 636 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 637 | break; |
| 638 | |
| 639 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 640 | DAL->AddFlagArg(A, |
| 641 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 642 | break; |
| 643 | |
| 644 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 645 | DAL->AddFlagArg(A, |
| 646 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 650 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 651 | break; |
| 652 | |
| 653 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 654 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 655 | break; |
| 656 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 659 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 660 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 661 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 662 | DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 663 | |
| 664 | // Add the arch options based on the particular spelling of -arch, to match |
| 665 | // how the driver driver works. |
| 666 | if (BoundArch) { |
| 667 | llvm::StringRef Name = BoundArch; |
| 668 | const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 669 | const Option *MArch = Opts.getOption(options::OPT_march_EQ); |
| 670 | |
| 671 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 672 | // which defines the list of which architectures we accept. |
| 673 | if (Name == "ppc") |
| 674 | ; |
| 675 | else if (Name == "ppc601") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 676 | DAL->AddJoinedArg(0, MCpu, "601"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 677 | else if (Name == "ppc603") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 678 | DAL->AddJoinedArg(0, MCpu, "603"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 679 | else if (Name == "ppc604") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 680 | DAL->AddJoinedArg(0, MCpu, "604"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 681 | else if (Name == "ppc604e") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 682 | DAL->AddJoinedArg(0, MCpu, "604e"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 683 | else if (Name == "ppc750") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 684 | DAL->AddJoinedArg(0, MCpu, "750"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 685 | else if (Name == "ppc7400") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 686 | DAL->AddJoinedArg(0, MCpu, "7400"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 687 | else if (Name == "ppc7450") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 688 | DAL->AddJoinedArg(0, MCpu, "7450"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 689 | else if (Name == "ppc970") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 690 | DAL->AddJoinedArg(0, MCpu, "970"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 691 | |
| 692 | else if (Name == "ppc64") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 693 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 694 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 695 | else if (Name == "i386") |
| 696 | ; |
| 697 | else if (Name == "i486") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 698 | DAL->AddJoinedArg(0, MArch, "i486"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 699 | else if (Name == "i586") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 700 | DAL->AddJoinedArg(0, MArch, "i586"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 701 | else if (Name == "i686") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 702 | DAL->AddJoinedArg(0, MArch, "i686"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 703 | else if (Name == "pentium") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 704 | DAL->AddJoinedArg(0, MArch, "pentium"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 705 | else if (Name == "pentium2") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 706 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 707 | else if (Name == "pentpro") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 708 | DAL->AddJoinedArg(0, MArch, "pentiumpro"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 709 | else if (Name == "pentIIm3") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 710 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 711 | |
| 712 | else if (Name == "x86_64") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 713 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 714 | |
| 715 | else if (Name == "arm") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 716 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 717 | else if (Name == "armv4t") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 718 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 719 | else if (Name == "armv5") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 720 | DAL->AddJoinedArg(0, MArch, "armv5tej"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 721 | else if (Name == "xscale") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 722 | DAL->AddJoinedArg(0, MArch, "xscale"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 723 | else if (Name == "armv6") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 724 | DAL->AddJoinedArg(0, MArch, "armv6k"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 725 | else if (Name == "armv7") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 726 | DAL->AddJoinedArg(0, MArch, "armv7a"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 727 | |
| 728 | else |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 729 | llvm_unreachable("invalid Darwin arch"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 730 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 731 | |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 732 | // Add an explicit version min argument for the deployment target. We do this |
| 733 | // after argument translation because -Xarch_ arguments may add a version min |
| 734 | // argument. |
| 735 | AddDeploymentTarget(*DAL); |
| 736 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 737 | return DAL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 739 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 740 | bool Darwin::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 741 | // FIXME: Gross; we should probably have some separate target |
| 742 | // definition, possibly even reusing the one in clang. |
| 743 | return getArchName() == "x86_64"; |
| 744 | } |
| 745 | |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 746 | bool Darwin::UseDwarfDebugFlags() const { |
| 747 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 748 | return S[0] != '\0'; |
| 749 | return false; |
| 750 | } |
| 751 | |
Daniel Dunbar | b2987d1 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 752 | bool Darwin::UseSjLjExceptions() const { |
| 753 | // Darwin uses SjLj exceptions on ARM. |
| 754 | return (getTriple().getArch() == llvm::Triple::arm || |
| 755 | getTriple().getArch() == llvm::Triple::thumb); |
| 756 | } |
| 757 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 758 | const char *Darwin::GetDefaultRelocationModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 759 | return "pic"; |
| 760 | } |
| 761 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 762 | const char *Darwin::GetForcedPicModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 763 | if (getArchName() == "x86_64") |
| 764 | return "pic"; |
| 765 | return 0; |
| 766 | } |
| 767 | |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 768 | bool Darwin::SupportsProfiling() const { |
| 769 | // Profiling instrumentation is only supported on x86. |
| 770 | return getArchName() == "i386" || getArchName() == "x86_64"; |
| 771 | } |
| 772 | |
Daniel Dunbar | 43a9b32 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 773 | bool Darwin::SupportsObjCGC() const { |
| 774 | // Garbage collection is supported everywhere except on iPhone OS. |
| 775 | return !isTargetIPhoneOS(); |
| 776 | } |
| 777 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 778 | std::string |
| 779 | Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const { |
| 780 | return ComputeLLVMTriple(Args); |
| 781 | } |
| 782 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 783 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 784 | /// all subcommands; this relies on gcc translating the majority of |
| 785 | /// command line options. |
| 786 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 787 | Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 788 | : ToolChain(Host, Triple) { |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 789 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 790 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 791 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 794 | Generic_GCC::~Generic_GCC() { |
| 795 | // Free tool implementations. |
| 796 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 797 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 798 | delete it->second; |
| 799 | } |
| 800 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 801 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 802 | const JobAction &JA, |
| 803 | const ActionList &Inputs) const { |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 804 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 805 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 806 | Key = Action::AnalyzeJobClass; |
| 807 | else |
| 808 | Key = JA.getKind(); |
| 809 | |
| 810 | Tool *&T = Tools[Key]; |
| 811 | if (!T) { |
| 812 | switch (Key) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 813 | case Action::InputClass: |
| 814 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 815 | assert(0 && "Invalid tool kind."); |
| 816 | case Action::PreprocessJobClass: |
| 817 | T = new tools::gcc::Preprocess(*this); break; |
| 818 | case Action::PrecompileJobClass: |
| 819 | T = new tools::gcc::Precompile(*this); break; |
| 820 | case Action::AnalyzeJobClass: |
| 821 | T = new tools::Clang(*this); break; |
| 822 | case Action::CompileJobClass: |
| 823 | T = new tools::gcc::Compile(*this); break; |
| 824 | case Action::AssembleJobClass: |
| 825 | T = new tools::gcc::Assemble(*this); break; |
| 826 | case Action::LinkJobClass: |
| 827 | T = new tools::gcc::Link(*this); break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 828 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 829 | // This is a bit ungeneric, but the only platform using a driver |
| 830 | // driver is Darwin. |
| 831 | case Action::LipoJobClass: |
| 832 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 833 | case Action::DsymutilJobClass: |
| 834 | T = new tools::darwin::Dsymutil(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
| 838 | return *T; |
| 839 | } |
| 840 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 841 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 842 | // FIXME: Gross; we should probably have some separate target |
| 843 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 844 | return getArchName() == "x86_64"; |
| 845 | } |
| 846 | |
| 847 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 848 | return "static"; |
| 849 | } |
| 850 | |
| 851 | const char *Generic_GCC::GetForcedPicModel() const { |
| 852 | return 0; |
| 853 | } |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 854 | |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 855 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 856 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 857 | /// Currently does not support anything else but compilation. |
| 858 | |
| 859 | TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple) |
| 860 | : ToolChain(Host, Triple) { |
| 861 | // Path mangling to find libexec |
| 862 | std::string Path(getDriver().Dir); |
| 863 | |
| 864 | Path += "/../libexec"; |
| 865 | getProgramPaths().push_back(Path); |
| 866 | } |
| 867 | |
| 868 | TCEToolChain::~TCEToolChain() { |
| 869 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 870 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 871 | delete it->second; |
| 872 | } |
| 873 | |
| 874 | bool TCEToolChain::IsMathErrnoDefault() const { |
| 875 | return true; |
| 876 | } |
| 877 | |
| 878 | bool TCEToolChain::IsUnwindTablesDefault() const { |
| 879 | return false; |
| 880 | } |
| 881 | |
| 882 | const char *TCEToolChain::GetDefaultRelocationModel() const { |
| 883 | return "static"; |
| 884 | } |
| 885 | |
| 886 | const char *TCEToolChain::GetForcedPicModel() const { |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | Tool &TCEToolChain::SelectTool(const Compilation &C, |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 891 | const JobAction &JA, |
| 892 | const ActionList &Inputs) const { |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 893 | Action::ActionClass Key; |
| 894 | Key = Action::AnalyzeJobClass; |
| 895 | |
| 896 | Tool *&T = Tools[Key]; |
| 897 | if (!T) { |
| 898 | switch (Key) { |
| 899 | case Action::PreprocessJobClass: |
| 900 | T = new tools::gcc::Preprocess(*this); break; |
| 901 | case Action::AnalyzeJobClass: |
| 902 | T = new tools::Clang(*this); break; |
| 903 | default: |
| 904 | assert(false && "Unsupported action for TCE target."); |
| 905 | } |
| 906 | } |
| 907 | return *T; |
| 908 | } |
| 909 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 910 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 911 | |
| 912 | OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 913 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 914 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 915 | getFilePaths().push_back("/usr/lib"); |
| 916 | } |
| 917 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 918 | Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 919 | const ActionList &Inputs) const { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 920 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 921 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 922 | Key = Action::AnalyzeJobClass; |
| 923 | else |
| 924 | Key = JA.getKind(); |
| 925 | |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 926 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 927 | options::OPT_no_integrated_as, |
| 928 | IsIntegratedAssemblerDefault()); |
| 929 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 930 | Tool *&T = Tools[Key]; |
| 931 | if (!T) { |
| 932 | switch (Key) { |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 933 | case Action::AssembleJobClass: { |
| 934 | if (UseIntegratedAs) |
| 935 | T = new tools::ClangAs(*this); |
| 936 | else |
| 937 | T = new tools::openbsd::Assemble(*this); |
| 938 | break; |
| 939 | } |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 940 | case Action::LinkJobClass: |
| 941 | T = new tools::openbsd::Link(*this); break; |
| 942 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 943 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
| 947 | return *T; |
| 948 | } |
| 949 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 950 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 951 | |
Daniel Dunbar | 214afe9 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 952 | FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 953 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | 214afe9 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 954 | |
| 955 | // Determine if we are compiling 32-bit code on an x86_64 platform. |
| 956 | bool Lib32 = false; |
| 957 | if (Triple.getArch() == llvm::Triple::x86 && |
| 958 | llvm::Triple(getDriver().DefaultHostTriple).getArch() == |
| 959 | llvm::Triple::x86_64) |
| 960 | Lib32 = true; |
| 961 | |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 962 | if (Lib32) { |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 963 | getFilePaths().push_back("/usr/lib32"); |
| 964 | } else { |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 965 | getFilePaths().push_back("/usr/lib"); |
| 966 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 969 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 970 | const ActionList &Inputs) const { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 971 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 972 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 973 | Key = Action::AnalyzeJobClass; |
| 974 | else |
| 975 | Key = JA.getKind(); |
| 976 | |
Roman Divacky | 67dece7 | 2010-11-08 17:46:39 +0000 | [diff] [blame] | 977 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 978 | options::OPT_no_integrated_as, |
| 979 | IsIntegratedAssemblerDefault()); |
| 980 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 981 | Tool *&T = Tools[Key]; |
| 982 | if (!T) { |
| 983 | switch (Key) { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 984 | case Action::AssembleJobClass: |
Roman Divacky | 67dece7 | 2010-11-08 17:46:39 +0000 | [diff] [blame] | 985 | if (UseIntegratedAs) |
| 986 | T = new tools::ClangAs(*this); |
| 987 | else |
| 988 | T = new tools::freebsd::Assemble(*this); |
Roman Divacky | fe3a7ea | 2010-11-08 19:39:10 +0000 | [diff] [blame] | 989 | break; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 990 | case Action::LinkJobClass: |
| 991 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 992 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 993 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
| 997 | return *T; |
| 998 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 999 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1000 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 1001 | |
| 1002 | NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple) |
| 1003 | : Generic_ELF(Host, Triple) { |
| 1004 | |
| 1005 | // Determine if we are compiling 32-bit code on an x86_64 platform. |
| 1006 | bool Lib32 = false; |
| 1007 | if (Triple.getArch() == llvm::Triple::x86 && |
| 1008 | llvm::Triple(getDriver().DefaultHostTriple).getArch() == |
| 1009 | llvm::Triple::x86_64) |
| 1010 | Lib32 = true; |
| 1011 | |
| 1012 | getProgramPaths().push_back(getDriver().Dir + "/../libexec"); |
| 1013 | getProgramPaths().push_back("/usr/libexec"); |
| 1014 | if (Lib32) { |
| 1015 | getFilePaths().push_back("/usr/lib/i386"); |
| 1016 | } else { |
| 1017 | getFilePaths().push_back("/usr/lib"); |
| 1018 | } |
| 1019 | } |
| 1020 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1021 | Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 1022 | const ActionList &Inputs) const { |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1023 | Action::ActionClass Key; |
| 1024 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1025 | Key = Action::AnalyzeJobClass; |
| 1026 | else |
| 1027 | Key = JA.getKind(); |
| 1028 | |
| 1029 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1030 | options::OPT_no_integrated_as, |
| 1031 | IsIntegratedAssemblerDefault()); |
| 1032 | |
| 1033 | Tool *&T = Tools[Key]; |
| 1034 | if (!T) { |
| 1035 | switch (Key) { |
| 1036 | case Action::AssembleJobClass: |
| 1037 | if (UseIntegratedAs) |
| 1038 | T = new tools::ClangAs(*this); |
| 1039 | else |
| 1040 | T = new tools::netbsd::Assemble(*this); |
| 1041 | break; |
| 1042 | case Action::LinkJobClass: |
| 1043 | T = new tools::netbsd::Link(*this); break; |
| 1044 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1045 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | return *T; |
| 1050 | } |
| 1051 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1052 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 1053 | |
| 1054 | Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple) |
| 1055 | : Generic_GCC(Host, Triple) { |
| 1056 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 1057 | getFilePaths().push_back("/usr/lib"); |
| 1058 | getFilePaths().push_back("/usr/gnu/lib"); |
| 1059 | getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3"); |
| 1060 | } |
| 1061 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1062 | Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA, |
| 1063 | const ActionList &Inputs) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1064 | Action::ActionClass Key; |
| 1065 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1066 | Key = Action::AnalyzeJobClass; |
| 1067 | else |
| 1068 | Key = JA.getKind(); |
| 1069 | |
| 1070 | Tool *&T = Tools[Key]; |
| 1071 | if (!T) { |
| 1072 | switch (Key) { |
| 1073 | case Action::AssembleJobClass: |
| 1074 | T = new tools::minix::Assemble(*this); break; |
| 1075 | case Action::LinkJobClass: |
| 1076 | T = new tools::minix::Link(*this); break; |
| 1077 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1078 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | return *T; |
| 1083 | } |
| 1084 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1085 | /// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. |
| 1086 | |
| 1087 | AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) |
| 1088 | : Generic_GCC(Host, Triple) { |
| 1089 | |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1090 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 1091 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1092 | getProgramPaths().push_back(getDriver().Dir); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1093 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1094 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1095 | getFilePaths().push_back("/usr/lib"); |
| 1096 | getFilePaths().push_back("/usr/sfw/lib"); |
| 1097 | getFilePaths().push_back("/opt/gcc4/lib"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 1098 | getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1099 | |
| 1100 | } |
| 1101 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1102 | Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA, |
| 1103 | const ActionList &Inputs) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1104 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1105 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1106 | Key = Action::AnalyzeJobClass; |
| 1107 | else |
| 1108 | Key = JA.getKind(); |
| 1109 | |
| 1110 | Tool *&T = Tools[Key]; |
| 1111 | if (!T) { |
| 1112 | switch (Key) { |
| 1113 | case Action::AssembleJobClass: |
| 1114 | T = new tools::auroraux::Assemble(*this); break; |
| 1115 | case Action::LinkJobClass: |
| 1116 | T = new tools::auroraux::Link(*this); break; |
| 1117 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1118 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | return *T; |
| 1123 | } |
| 1124 | |
| 1125 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1126 | /// Linux toolchain (very bare-bones at the moment). |
| 1127 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1128 | enum LinuxDistro { |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1129 | ArchLinux, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1130 | DebianLenny, |
| 1131 | DebianSqueeze, |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1132 | Exherbo, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1133 | Fedora13, |
| 1134 | Fedora14, |
| 1135 | OpenSuse11_3, |
Douglas Gregor | 814638e | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 1136 | UbuntuHardy, |
| 1137 | UbuntuIntrepid, |
Rafael Espindola | 021aaa4 | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 1138 | UbuntuJaunty, |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1139 | UbuntuKarmic, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1140 | UbuntuLucid, |
| 1141 | UbuntuMaverick, |
| 1142 | UnknownDistro |
| 1143 | }; |
| 1144 | |
| 1145 | static bool IsFedora(enum LinuxDistro Distro) { |
| 1146 | return Distro == Fedora13 || Distro == Fedora14; |
| 1147 | } |
| 1148 | |
| 1149 | static bool IsOpenSuse(enum LinuxDistro Distro) { |
| 1150 | return Distro == OpenSuse11_3; |
| 1151 | } |
| 1152 | |
| 1153 | static bool IsDebian(enum LinuxDistro Distro) { |
| 1154 | return Distro == DebianLenny || Distro == DebianSqueeze; |
| 1155 | } |
| 1156 | |
| 1157 | static bool IsUbuntu(enum LinuxDistro Distro) { |
Douglas Gregor | 814638e | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 1158 | return Distro == UbuntuHardy || Distro == UbuntuIntrepid || |
| 1159 | Distro == UbuntuLucid || Distro == UbuntuMaverick || |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1160 | Distro == UbuntuJaunty || Distro == UbuntuKarmic; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | static bool IsDebianBased(enum LinuxDistro Distro) { |
| 1164 | return IsDebian(Distro) || IsUbuntu(Distro); |
| 1165 | } |
| 1166 | |
| 1167 | static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) { |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1168 | if (Arch == llvm::Triple::x86_64) { |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1169 | bool Exists; |
| 1170 | if (Distro == Exherbo && |
| 1171 | (llvm::sys::fs::exists("/usr/lib32/libc.so", Exists) || !Exists)) |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1172 | return false; |
| 1173 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1174 | return true; |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1175 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1176 | if (Arch == llvm::Triple::x86 && IsDebianBased(Distro)) |
| 1177 | return true; |
| 1178 | return false; |
| 1179 | } |
| 1180 | |
| 1181 | static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) { |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1182 | llvm::OwningPtr<llvm::MemoryBuffer> File; |
| 1183 | if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) { |
| 1184 | llvm::StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1185 | llvm::SmallVector<llvm::StringRef, 8> Lines; |
| 1186 | Data.split(Lines, "\n"); |
| 1187 | for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) { |
Douglas Gregor | 814638e | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 1188 | if (Lines[i] == "DISTRIB_CODENAME=hardy") |
| 1189 | return UbuntuHardy; |
| 1190 | if (Lines[i] == "DISTRIB_CODENAME=intrepid") |
| 1191 | return UbuntuIntrepid; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1192 | if (Lines[i] == "DISTRIB_CODENAME=maverick") |
| 1193 | return UbuntuMaverick; |
| 1194 | else if (Lines[i] == "DISTRIB_CODENAME=lucid") |
| 1195 | return UbuntuLucid; |
Rafael Espindola | 021aaa4 | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 1196 | else if (Lines[i] == "DISTRIB_CODENAME=jaunty") |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1197 | return UbuntuJaunty; |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1198 | else if (Lines[i] == "DISTRIB_CODENAME=karmic") |
| 1199 | return UbuntuKarmic; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1200 | } |
| 1201 | return UnknownDistro; |
| 1202 | } |
| 1203 | |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1204 | if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) { |
| 1205 | llvm::StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1206 | if (Data.startswith("Fedora release 14 (Laughlin)")) |
| 1207 | return Fedora14; |
| 1208 | else if (Data.startswith("Fedora release 13 (Goddard)")) |
| 1209 | return Fedora13; |
| 1210 | return UnknownDistro; |
| 1211 | } |
| 1212 | |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1213 | if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) { |
| 1214 | llvm::StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1215 | if (Data[0] == '5') |
| 1216 | return DebianLenny; |
| 1217 | else if (Data.startswith("squeeze/sid")) |
| 1218 | return DebianSqueeze; |
| 1219 | return UnknownDistro; |
| 1220 | } |
| 1221 | |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1222 | if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) { |
| 1223 | llvm::StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1224 | if (Data.startswith("openSUSE 11.3")) |
| 1225 | return OpenSuse11_3; |
| 1226 | return UnknownDistro; |
| 1227 | } |
| 1228 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1229 | bool Exists; |
| 1230 | if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists) |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1231 | return Exherbo; |
| 1232 | |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1233 | if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists) |
| 1234 | return ArchLinux; |
| 1235 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1236 | return UnknownDistro; |
| 1237 | } |
| 1238 | |
Nick Lewycky | 3fdcc6f | 2010-12-31 17:31:54 +0000 | [diff] [blame] | 1239 | Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 1240 | : Generic_ELF(Host, Triple) { |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1241 | llvm::Triple::ArchType Arch = |
| 1242 | llvm::Triple(getDriver().DefaultHostTriple).getArch(); |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 1243 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1244 | std::string Suffix32 = ""; |
| 1245 | if (Arch == llvm::Triple::x86_64) |
| 1246 | Suffix32 = "/32"; |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 1247 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1248 | std::string Suffix64 = ""; |
| 1249 | if (Arch == llvm::Triple::x86) |
| 1250 | Suffix64 = "/64"; |
| 1251 | |
| 1252 | std::string Lib32 = "lib"; |
| 1253 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1254 | bool Exists; |
| 1255 | if (!llvm::sys::fs::exists("/lib32", Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1256 | Lib32 = "lib32"; |
| 1257 | |
| 1258 | std::string Lib64 = "lib"; |
Michael J. Spencer | 2dea7c7 | 2011-01-12 23:54:48 +0000 | [diff] [blame] | 1259 | bool Symlink; |
Chris Lattner | 48aef36 | 2011-01-13 01:35:58 +0000 | [diff] [blame] | 1260 | if (!llvm::sys::fs::exists("/lib64", Exists) && Exists && |
| 1261 | (llvm::sys::fs::is_symlink("/lib64", Symlink) || !Symlink)) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1262 | Lib64 = "lib64"; |
| 1263 | |
| 1264 | std::string GccTriple = ""; |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 1265 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) { |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1266 | if (!llvm::sys::fs::exists("/usr/lib/gcc/arm-linux-gnueabi", Exists) && |
| 1267 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1268 | GccTriple = "arm-linux-gnueabi"; |
| 1269 | } else if (Arch == llvm::Triple::x86_64) { |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1270 | if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-linux-gnu", Exists) && |
| 1271 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1272 | GccTriple = "x86_64-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1273 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-unknown-linux-gnu", |
| 1274 | Exists) && Exists) |
Rafael Espindola | 53dd00b | 2010-11-17 00:25:26 +0000 | [diff] [blame] | 1275 | GccTriple = "x86_64-unknown-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1276 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-pc-linux-gnu", |
| 1277 | Exists) && Exists) |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1278 | GccTriple = "x86_64-pc-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1279 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-redhat-linux", |
| 1280 | Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1281 | GccTriple = "x86_64-redhat-linux"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1282 | else if (!llvm::sys::fs::exists("/usr/lib64/gcc/x86_64-suse-linux", |
| 1283 | Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1284 | GccTriple = "x86_64-suse-linux"; |
Nick Lewycky | e10f900 | 2011-02-01 23:03:29 +0000 | [diff] [blame] | 1285 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-manbo-linux-gnu", |
| 1286 | Exists) && Exists) |
| 1287 | GccTriple = "x86_64-manbo-linux-gnu"; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1288 | } else if (Arch == llvm::Triple::x86) { |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1289 | if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-linux-gnu", Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1290 | GccTriple = "i686-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1291 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-pc-linux-gnu", Exists) && |
| 1292 | Exists) |
Nuno Lopes | 2a69ddd | 2010-11-19 17:26:57 +0000 | [diff] [blame] | 1293 | GccTriple = "i686-pc-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1294 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-linux-gnu", Exists) && |
| 1295 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1296 | GccTriple = "i486-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1297 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-redhat-linux", Exists) && |
| 1298 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1299 | GccTriple = "i686-redhat-linux"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1300 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i586-suse-linux", Exists) && |
| 1301 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1302 | GccTriple = "i586-suse-linux"; |
| 1303 | } |
| 1304 | |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1305 | const char* GccVersions[] = {"4.5.2", "4.5.1", "4.5", "4.4.5", "4.4.4", |
| 1306 | "4.4.3", "4.4", "4.3.4", "4.3.3", "4.3.2", |
Douglas Gregor | 814638e | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 1307 | "4.3", "4.2.4", "4.2.3", "4.2.2", "4.2.1", |
| 1308 | "4.2"}; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1309 | std::string Base = ""; |
| 1310 | for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) { |
| 1311 | std::string Suffix = GccTriple + "/" + GccVersions[i]; |
| 1312 | std::string t1 = "/usr/lib/gcc/" + Suffix; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1313 | if (!llvm::sys::fs::exists(t1 + "/crtbegin.o", Exists) && Exists) { |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1314 | Base = t1; |
| 1315 | break; |
| 1316 | } |
| 1317 | std::string t2 = "/usr/lib64/gcc/" + Suffix; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1318 | if (!llvm::sys::fs::exists(t2 + "/crtbegin.o", Exists) && Exists) { |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1319 | Base = t2; |
| 1320 | break; |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | path_list &Paths = getFilePaths(); |
| 1325 | bool Is32Bits = getArch() == llvm::Triple::x86; |
| 1326 | |
| 1327 | std::string Suffix; |
| 1328 | std::string Lib; |
| 1329 | |
| 1330 | if (Is32Bits) { |
| 1331 | Suffix = Suffix32; |
| 1332 | Lib = Lib32; |
| 1333 | } else { |
| 1334 | Suffix = Suffix64; |
| 1335 | Lib = Lib64; |
| 1336 | } |
| 1337 | |
| 1338 | llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1339 | if (!llvm::sys::fs::exists(LinkerPath.str(), Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1340 | Linker = LinkerPath.str(); |
| 1341 | else |
| 1342 | Linker = GetProgramPath("ld"); |
| 1343 | |
| 1344 | LinuxDistro Distro = DetectLinuxDistro(Arch); |
| 1345 | |
Rafael Espindola | 94c8022 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 1346 | if (IsUbuntu(Distro)) { |
| 1347 | ExtraOpts.push_back("-z"); |
| 1348 | ExtraOpts.push_back("relro"); |
| 1349 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1350 | |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 1351 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1352 | ExtraOpts.push_back("-X"); |
| 1353 | |
| 1354 | if (IsFedora(Distro) || Distro == UbuntuMaverick) |
| 1355 | ExtraOpts.push_back("--hash-style=gnu"); |
| 1356 | |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1357 | if (IsDebian(Distro) || Distro == UbuntuLucid || Distro == UbuntuJaunty || |
| 1358 | Distro == UbuntuKarmic) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1359 | ExtraOpts.push_back("--hash-style=both"); |
| 1360 | |
| 1361 | if (IsFedora(Distro)) |
| 1362 | ExtraOpts.push_back("--no-add-needed"); |
| 1363 | |
Rafael Espindola | 021aaa4 | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 1364 | if (Distro == DebianSqueeze || IsOpenSuse(Distro) || |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1365 | IsFedora(Distro) || Distro == UbuntuLucid || Distro == UbuntuMaverick || |
| 1366 | Distro == UbuntuKarmic) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1367 | ExtraOpts.push_back("--build-id"); |
| 1368 | |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1369 | if (Distro == ArchLinux) |
| 1370 | Lib = "lib"; |
| 1371 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1372 | Paths.push_back(Base + Suffix); |
| 1373 | if (HasMultilib(Arch, Distro)) { |
| 1374 | if (IsOpenSuse(Distro) && Is32Bits) |
| 1375 | Paths.push_back(Base + "/../../../../" + GccTriple + "/lib/../lib"); |
| 1376 | Paths.push_back(Base + "/../../../../" + Lib); |
| 1377 | Paths.push_back("/lib/../" + Lib); |
| 1378 | Paths.push_back("/usr/lib/../" + Lib); |
| 1379 | } |
| 1380 | if (!Suffix.empty()) |
| 1381 | Paths.push_back(Base); |
| 1382 | if (IsOpenSuse(Distro)) |
| 1383 | Paths.push_back(Base + "/../../../../" + GccTriple + "/lib"); |
| 1384 | Paths.push_back(Base + "/../../.."); |
| 1385 | if (Arch == getArch() && IsUbuntu(Distro)) |
| 1386 | Paths.push_back("/usr/lib/" + GccTriple); |
| 1387 | } |
| 1388 | |
| 1389 | bool Linux::HasNativeLLVMSupport() const { |
| 1390 | return true; |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1393 | Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA, |
| 1394 | const ActionList &Inputs) const { |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1395 | Action::ActionClass Key; |
| 1396 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1397 | Key = Action::AnalyzeJobClass; |
| 1398 | else |
| 1399 | Key = JA.getKind(); |
| 1400 | |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1401 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1402 | options::OPT_no_integrated_as, |
| 1403 | IsIntegratedAssemblerDefault()); |
| 1404 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1405 | Tool *&T = Tools[Key]; |
| 1406 | if (!T) { |
| 1407 | switch (Key) { |
| 1408 | case Action::AssembleJobClass: |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1409 | if (UseIntegratedAs) |
| 1410 | T = new tools::ClangAs(*this); |
| 1411 | else |
| 1412 | T = new tools::linuxtools::Assemble(*this); |
| 1413 | break; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1414 | case Action::LinkJobClass: |
| 1415 | T = new tools::linuxtools::Link(*this); break; |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1416 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1417 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | return *T; |
| 1422 | } |
| 1423 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1424 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 1425 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1426 | DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 1427 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1428 | |
| 1429 | // Path mangling to find libexec |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1430 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 1431 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1432 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1433 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1434 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1435 | getFilePaths().push_back("/usr/lib"); |
| 1436 | getFilePaths().push_back("/usr/lib/gcc41"); |
| 1437 | } |
| 1438 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1439 | Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA, |
| 1440 | const ActionList &Inputs) const { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1441 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1442 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1443 | Key = Action::AnalyzeJobClass; |
| 1444 | else |
| 1445 | Key = JA.getKind(); |
| 1446 | |
| 1447 | Tool *&T = Tools[Key]; |
| 1448 | if (!T) { |
| 1449 | switch (Key) { |
| 1450 | case Action::AssembleJobClass: |
| 1451 | T = new tools::dragonfly::Assemble(*this); break; |
| 1452 | case Action::LinkJobClass: |
| 1453 | T = new tools::dragonfly::Link(*this); break; |
| 1454 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1455 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | return *T; |
| 1460 | } |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 1461 | |
| 1462 | Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple) |
| 1463 | : ToolChain(Host, Triple) { |
| 1464 | } |
| 1465 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame^] | 1466 | Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA, |
| 1467 | const ActionList &Inputs) const { |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 1468 | Action::ActionClass Key; |
| 1469 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1470 | Key = Action::AnalyzeJobClass; |
| 1471 | else |
| 1472 | Key = JA.getKind(); |
| 1473 | |
| 1474 | Tool *&T = Tools[Key]; |
| 1475 | if (!T) { |
| 1476 | switch (Key) { |
| 1477 | case Action::InputClass: |
| 1478 | case Action::BindArchClass: |
Chandler Carruth | e97673f | 2010-08-22 06:56:37 +0000 | [diff] [blame] | 1479 | case Action::LipoJobClass: |
| 1480 | case Action::DsymutilJobClass: |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 1481 | assert(0 && "Invalid tool kind."); |
| 1482 | case Action::PreprocessJobClass: |
| 1483 | case Action::PrecompileJobClass: |
| 1484 | case Action::AnalyzeJobClass: |
| 1485 | case Action::CompileJobClass: |
| 1486 | T = new tools::Clang(*this); break; |
| 1487 | case Action::AssembleJobClass: |
| 1488 | T = new tools::ClangAs(*this); break; |
| 1489 | case Action::LinkJobClass: |
| 1490 | T = new tools::visualstudio::Link(*this); break; |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | return *T; |
| 1495 | } |
| 1496 | |
| 1497 | bool Windows::IsIntegratedAssemblerDefault() const { |
| 1498 | return true; |
| 1499 | } |
| 1500 | |
| 1501 | bool Windows::IsUnwindTablesDefault() const { |
| 1502 | // FIXME: Gross; we should probably have some separate target |
| 1503 | // definition, possibly even reusing the one in clang. |
| 1504 | return getArchName() == "x86_64"; |
| 1505 | } |
| 1506 | |
| 1507 | const char *Windows::GetDefaultRelocationModel() const { |
| 1508 | return "static"; |
| 1509 | } |
| 1510 | |
| 1511 | const char *Windows::GetForcedPicModel() const { |
| 1512 | if (getArchName() == "x86_64") |
| 1513 | return "pic"; |
| 1514 | return 0; |
| 1515 | } |