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