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) |
Daniel Dunbar | 659d23a | 2011-04-19 23:34:17 +0000 | [diff] [blame] | 154 | << (isTargetIPhoneOS() ? "ios" : "macosx") |
Daniel Dunbar | 729f38e | 2011-04-19 21:45:47 +0000 | [diff] [blame] | 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); |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 389 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
| 390 | Arg *iOSSimVersion = Args.getLastArg( |
| 391 | options::OPT_mios_simulator_version_min_EQ); |
| 392 | if (OSXVersion && (iOSVersion || iOSSimVersion)) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 393 | getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 394 | << OSXVersion->getAsString(Args) |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 395 | << (iOSVersion ? iOSVersion : iOSSimVersion)->getAsString(Args); |
| 396 | iOSVersion = iOSSimVersion = 0; |
| 397 | } else if (iOSVersion && iOSSimVersion) { |
| 398 | getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 399 | << iOSVersion->getAsString(Args) |
| 400 | << iOSSimVersion->getAsString(Args); |
| 401 | iOSSimVersion = 0; |
| 402 | } else if (!OSXVersion && !iOSVersion && !iOSSimVersion) { |
| 403 | // If not deployment target was specified on the command line, check for |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 404 | // environment defines. |
| 405 | const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET"); |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 406 | const char *iOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET"); |
| 407 | const char *iOSSimTarget = ::getenv("IOS_SIMULATOR_DEPLOYMENT_TARGET"); |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 408 | |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 409 | // Ignore empty strings. |
| 410 | if (OSXTarget && OSXTarget[0] == '\0') |
| 411 | OSXTarget = 0; |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 412 | if (iOSTarget && iOSTarget[0] == '\0') |
| 413 | iOSTarget = 0; |
| 414 | if (iOSSimTarget && iOSSimTarget[0] == '\0') |
| 415 | iOSSimTarget = 0; |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 416 | |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 417 | // Handle conflicting deployment targets |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 418 | // |
| 419 | // FIXME: Don't hardcode default here. |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 420 | |
| 421 | // Do not allow conflicts with the iOS simulator target. |
| 422 | if (iOSSimTarget && (OSXTarget || iOSTarget)) { |
| 423 | getDriver().Diag(clang::diag::err_drv_conflicting_deployment_targets) |
| 424 | << "IOS_SIMULATOR_DEPLOYMENT_TARGET" |
| 425 | << (OSXTarget ? "MACOSX_DEPLOYMENT_TARGET" : |
| 426 | "IPHONEOS_DEPLOYMENT_TARGET"); |
| 427 | } |
| 428 | |
| 429 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 430 | // default platform. |
| 431 | if (OSXTarget && iOSTarget) { |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 432 | if (getTriple().getArch() == llvm::Triple::arm || |
| 433 | getTriple().getArch() == llvm::Triple::thumb) |
Daniel Dunbar | 84d1e6e | 2010-03-20 08:47:42 +0000 | [diff] [blame] | 434 | OSXTarget = 0; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 435 | else |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 436 | iOSTarget = 0; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 437 | } |
Daniel Dunbar | 1a3c1d9 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 438 | |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 439 | if (OSXTarget) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 440 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 441 | OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget); |
| 442 | Args.append(OSXVersion); |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 443 | } else if (iOSTarget) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 444 | const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 445 | iOSVersion = Args.MakeJoinedArg(0, O, iOSTarget); |
| 446 | Args.append(iOSVersion); |
| 447 | } else if (iOSSimTarget) { |
| 448 | const Option *O = Opts.getOption( |
| 449 | options::OPT_mios_simulator_version_min_EQ); |
| 450 | iOSSimVersion = Args.MakeJoinedArg(0, O, iOSSimTarget); |
| 451 | Args.append(iOSSimVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 452 | } else { |
Daniel Dunbar | 2bb38d0 | 2010-07-15 16:18:06 +0000 | [diff] [blame] | 453 | // Otherwise, assume we are targeting OS X. |
| 454 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 455 | OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin); |
| 456 | Args.append(OSXVersion); |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 457 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 458 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 459 | |
Daniel Dunbar | 3fd823b | 2011-04-30 04:20:40 +0000 | [diff] [blame^] | 460 | // Reject invalid architecture combinations. |
| 461 | if (iOSSimVersion && (getTriple().getArch() != llvm::Triple::x86 && |
| 462 | getTriple().getArch() != llvm::Triple::x86_64)) { |
| 463 | getDriver().Diag(clang::diag::err_drv_invalid_arch_for_deployment_target) |
| 464 | << getTriple().getArchName() << iOSSimVersion->getAsString(Args); |
| 465 | } |
| 466 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 467 | // Set the tool chain target information. |
| 468 | unsigned Major, Minor, Micro; |
| 469 | bool HadExtra; |
| 470 | if (OSXVersion) { |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 471 | assert((!iOSVersion && !iOSSimVersion) && "Unknown target platform!"); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 472 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor, |
| 473 | Micro, HadExtra) || HadExtra || |
Daniel Dunbar | 8a3a7f3 | 2011-04-21 21:27:33 +0000 | [diff] [blame] | 474 | Major != 10 || Minor >= 100 || Micro >= 100) |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 475 | getDriver().Diag(clang::diag::err_drv_invalid_version_number) |
| 476 | << OSXVersion->getAsString(Args); |
| 477 | } else { |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 478 | const Arg *Version = iOSVersion ? iOSVersion : iOSSimVersion; |
| 479 | assert(Version && "Unknown target platform!"); |
| 480 | if (!Driver::GetReleaseVersion(Version->getValue(Args), Major, Minor, |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 481 | Micro, HadExtra) || HadExtra || |
| 482 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 483 | getDriver().Diag(clang::diag::err_drv_invalid_version_number) |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 484 | << Version->getAsString(Args); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 485 | } |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 486 | |
Daniel Dunbar | 5f5c37b | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 487 | bool IsIOSSim = bool(iOSSimVersion); |
| 488 | |
| 489 | // In GCC, the simulator historically was treated as being OS X in some |
| 490 | // contexts, like determining the link logic, despite generally being called |
| 491 | // with an iOS deployment target. For compatibility, we detect the |
| 492 | // simulator as iOS + x86, and treat it differently in a few contexts. |
| 493 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 494 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 495 | IsIOSSim = true; |
| 496 | |
| 497 | setTarget(/*IsIPhoneOS=*/ !OSXVersion, Major, Minor, Micro, IsIOSSim); |
Daniel Dunbar | c0e665e | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 500 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 501 | ArgStringList &CmdArgs) const { |
| 502 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 503 | |
| 504 | switch (Type) { |
| 505 | case ToolChain::CST_Libcxx: |
| 506 | CmdArgs.push_back("-lc++"); |
| 507 | break; |
| 508 | |
| 509 | case ToolChain::CST_Libstdcxx: { |
| 510 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 511 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 512 | // platforms we care about it was -lstdc++.6, so we search for that |
| 513 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 514 | |
| 515 | // Check in the sysroot first. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 516 | bool Exists; |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 517 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 518 | llvm::sys::Path P(A->getValue(Args)); |
| 519 | P.appendComponent("usr"); |
| 520 | P.appendComponent("lib"); |
| 521 | P.appendComponent("libstdc++.dylib"); |
| 522 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 523 | if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) { |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 524 | P.eraseComponent(); |
| 525 | P.appendComponent("libstdc++.6.dylib"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 526 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 527 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 528 | return; |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | // Otherwise, look in the root. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 534 | if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&& |
| 535 | (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){ |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 536 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | // Otherwise, let the linker search. |
| 541 | CmdArgs.push_back("-lstdc++"); |
| 542 | break; |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 547 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 548 | ArgStringList &CmdArgs) const { |
| 549 | |
| 550 | // For Darwin platforms, use the compiler-rt-based support library |
| 551 | // instead of the gcc-provided one (which is also incidentally |
| 552 | // only present in the gcc lib dir, which makes it hard to find). |
| 553 | |
| 554 | llvm::sys::Path P(getDriver().ResourceDir); |
| 555 | P.appendComponent("lib"); |
| 556 | P.appendComponent("darwin"); |
| 557 | P.appendComponent("libclang_rt.cc_kext.a"); |
| 558 | |
| 559 | // For now, allow missing resource libraries to support developers who may |
| 560 | // not have compiler-rt checked out or integrated into their build. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 561 | bool Exists; |
| 562 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 563 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 564 | } |
| 565 | |
Daniel Dunbar | c0e665e | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 566 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 567 | const char *BoundArch) const { |
| 568 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 569 | const OptTable &Opts = getDriver().getOpts(); |
| 570 | |
| 571 | // FIXME: We really want to get out of the tool chain level argument |
| 572 | // translation business, as it makes the driver functionality much |
| 573 | // more opaque. For now, we follow gcc closely solely for the |
| 574 | // purpose of easily achieving feature parity & testability. Once we |
| 575 | // have something that works, we should reevaluate each translation |
| 576 | // and try to push it down into tool specific logic. |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 577 | |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 578 | for (ArgList::const_iterator it = Args.begin(), |
| 579 | ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 580 | Arg *A = *it; |
| 581 | |
| 582 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 583 | // FIXME: Canonicalize name. |
| 584 | if (getArchName() != A->getValue(Args, 0)) |
| 585 | continue; |
| 586 | |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 587 | Arg *OriginalArg = A; |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 588 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1)); |
| 589 | unsigned Prev = Index; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 590 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 592 | // If the argument parsing failed or more than one argument was |
| 593 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 594 | // extra arguments. Emit an error and ignore. |
| 595 | // |
| 596 | // We also want to disallow any options which would alter the |
| 597 | // driver behavior; that isn't going to work in our model. We |
| 598 | // use isDriverOption() as an approximation, although things |
| 599 | // like -O4 are going to slip through. |
Daniel Dunbar | 0e02f6e | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 600 | if (!XarchArg || Index > Prev + 1) { |
Daniel Dunbar | 7e9293b | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 601 | getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument_with_args) |
| 602 | << A->getAsString(Args); |
| 603 | continue; |
| 604 | } else if (XarchArg->getOption().isDriverOption()) { |
| 605 | getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument_isdriver) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 606 | << A->getAsString(Args); |
| 607 | continue; |
| 608 | } |
| 609 | |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 610 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 611 | A = XarchArg; |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 612 | |
| 613 | DAL->AddSynthesizedArg(A); |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 614 | |
| 615 | // Linker input arguments require custom handling. The problem is that we |
| 616 | // have already constructed the phase actions, so we can not treat them as |
| 617 | // "input arguments". |
| 618 | if (A->getOption().isLinkerInput()) { |
| 619 | // Convert the argument into individual Zlinker_input_args. |
| 620 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { |
| 621 | DAL->AddSeparateArg(OriginalArg, |
| 622 | Opts.getOption(options::OPT_Zlinker_input), |
| 623 | A->getValue(Args, i)); |
| 624 | |
| 625 | } |
| 626 | continue; |
| 627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 629 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 630 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 631 | // gcc translates options twice, which means that self-expanding |
| 632 | // options add duplicates. |
Daniel Dunbar | 9e1f982 | 2009-11-19 04:14:53 +0000 | [diff] [blame] | 633 | switch ((options::ID) A->getOption().getID()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 634 | default: |
| 635 | DAL->append(A); |
| 636 | break; |
| 637 | |
| 638 | case options::OPT_mkernel: |
| 639 | case options::OPT_fapple_kext: |
| 640 | DAL->append(A); |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 641 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
| 642 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 643 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 644 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 645 | case options::OPT_dependency_file: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 646 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), |
| 647 | A->getValue(Args)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 648 | break; |
| 649 | |
| 650 | case options::OPT_gfull: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 651 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 652 | DAL->AddFlagArg(A, |
| 653 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 654 | break; |
| 655 | |
| 656 | case options::OPT_gused: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 657 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 658 | DAL->AddFlagArg(A, |
| 659 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case options::OPT_fterminated_vtables: |
| 663 | case options::OPT_findirect_virtual_calls: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 664 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_fapple_kext)); |
| 665 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 666 | break; |
| 667 | |
| 668 | case options::OPT_shared: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 669 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 670 | break; |
| 671 | |
| 672 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 673 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 674 | break; |
| 675 | |
| 676 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 677 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 678 | break; |
| 679 | |
| 680 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 681 | DAL->AddFlagArg(A, |
| 682 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 683 | break; |
| 684 | |
| 685 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 686 | DAL->AddFlagArg(A, |
| 687 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 691 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 692 | break; |
| 693 | |
| 694 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 695 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 696 | break; |
| 697 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 700 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 701 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 702 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 703 | DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 704 | |
| 705 | // Add the arch options based on the particular spelling of -arch, to match |
| 706 | // how the driver driver works. |
| 707 | if (BoundArch) { |
| 708 | llvm::StringRef Name = BoundArch; |
| 709 | const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 710 | const Option *MArch = Opts.getOption(options::OPT_march_EQ); |
| 711 | |
| 712 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 713 | // which defines the list of which architectures we accept. |
| 714 | if (Name == "ppc") |
| 715 | ; |
| 716 | else if (Name == "ppc601") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 717 | DAL->AddJoinedArg(0, MCpu, "601"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 718 | else if (Name == "ppc603") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 719 | DAL->AddJoinedArg(0, MCpu, "603"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 720 | else if (Name == "ppc604") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 721 | DAL->AddJoinedArg(0, MCpu, "604"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 722 | else if (Name == "ppc604e") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 723 | DAL->AddJoinedArg(0, MCpu, "604e"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 724 | else if (Name == "ppc750") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 725 | DAL->AddJoinedArg(0, MCpu, "750"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 726 | else if (Name == "ppc7400") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 727 | DAL->AddJoinedArg(0, MCpu, "7400"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 728 | else if (Name == "ppc7450") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 729 | DAL->AddJoinedArg(0, MCpu, "7450"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 730 | else if (Name == "ppc970") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 731 | DAL->AddJoinedArg(0, MCpu, "970"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 732 | |
| 733 | else if (Name == "ppc64") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 734 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 735 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 736 | else if (Name == "i386") |
| 737 | ; |
| 738 | else if (Name == "i486") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 739 | DAL->AddJoinedArg(0, MArch, "i486"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 740 | else if (Name == "i586") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 741 | DAL->AddJoinedArg(0, MArch, "i586"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 742 | else if (Name == "i686") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 743 | DAL->AddJoinedArg(0, MArch, "i686"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 744 | else if (Name == "pentium") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 745 | DAL->AddJoinedArg(0, MArch, "pentium"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 746 | else if (Name == "pentium2") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 747 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 748 | else if (Name == "pentpro") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 749 | DAL->AddJoinedArg(0, MArch, "pentiumpro"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 750 | else if (Name == "pentIIm3") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 751 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 752 | |
| 753 | else if (Name == "x86_64") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 754 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 755 | |
| 756 | else if (Name == "arm") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 757 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 758 | else if (Name == "armv4t") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 759 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 760 | else if (Name == "armv5") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 761 | DAL->AddJoinedArg(0, MArch, "armv5tej"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 762 | else if (Name == "xscale") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 763 | DAL->AddJoinedArg(0, MArch, "xscale"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 764 | else if (Name == "armv6") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 765 | DAL->AddJoinedArg(0, MArch, "armv6k"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 766 | else if (Name == "armv7") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 767 | DAL->AddJoinedArg(0, MArch, "armv7a"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 768 | |
| 769 | else |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 770 | llvm_unreachable("invalid Darwin arch"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 771 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 772 | |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 773 | // Add an explicit version min argument for the deployment target. We do this |
| 774 | // after argument translation because -Xarch_ arguments may add a version min |
| 775 | // argument. |
| 776 | AddDeploymentTarget(*DAL); |
| 777 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 778 | return DAL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 779 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 780 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 781 | bool Darwin::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 782 | // FIXME: Gross; we should probably have some separate target |
| 783 | // definition, possibly even reusing the one in clang. |
| 784 | return getArchName() == "x86_64"; |
| 785 | } |
| 786 | |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 787 | bool Darwin::UseDwarfDebugFlags() const { |
| 788 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 789 | return S[0] != '\0'; |
| 790 | return false; |
| 791 | } |
| 792 | |
Daniel Dunbar | b2987d1 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 793 | bool Darwin::UseSjLjExceptions() const { |
| 794 | // Darwin uses SjLj exceptions on ARM. |
| 795 | return (getTriple().getArch() == llvm::Triple::arm || |
| 796 | getTriple().getArch() == llvm::Triple::thumb); |
| 797 | } |
| 798 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 799 | const char *Darwin::GetDefaultRelocationModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 800 | return "pic"; |
| 801 | } |
| 802 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 803 | const char *Darwin::GetForcedPicModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 804 | if (getArchName() == "x86_64") |
| 805 | return "pic"; |
| 806 | return 0; |
| 807 | } |
| 808 | |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 809 | bool Darwin::SupportsProfiling() const { |
| 810 | // Profiling instrumentation is only supported on x86. |
| 811 | return getArchName() == "i386" || getArchName() == "x86_64"; |
| 812 | } |
| 813 | |
Daniel Dunbar | 43a9b32 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 814 | bool Darwin::SupportsObjCGC() const { |
| 815 | // Garbage collection is supported everywhere except on iPhone OS. |
| 816 | return !isTargetIPhoneOS(); |
| 817 | } |
| 818 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 819 | std::string |
| 820 | Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const { |
| 821 | return ComputeLLVMTriple(Args); |
| 822 | } |
| 823 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 824 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 825 | /// all subcommands; this relies on gcc translating the majority of |
| 826 | /// command line options. |
| 827 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 828 | Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 829 | : ToolChain(Host, Triple) { |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 830 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 831 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 832 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 835 | Generic_GCC::~Generic_GCC() { |
| 836 | // Free tool implementations. |
| 837 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 838 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 839 | delete it->second; |
| 840 | } |
| 841 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 843 | const JobAction &JA, |
| 844 | const ActionList &Inputs) const { |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 845 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 846 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 847 | Key = Action::AnalyzeJobClass; |
| 848 | else |
| 849 | Key = JA.getKind(); |
| 850 | |
| 851 | Tool *&T = Tools[Key]; |
| 852 | if (!T) { |
| 853 | switch (Key) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 854 | case Action::InputClass: |
| 855 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 856 | assert(0 && "Invalid tool kind."); |
| 857 | case Action::PreprocessJobClass: |
| 858 | T = new tools::gcc::Preprocess(*this); break; |
| 859 | case Action::PrecompileJobClass: |
| 860 | T = new tools::gcc::Precompile(*this); break; |
| 861 | case Action::AnalyzeJobClass: |
| 862 | T = new tools::Clang(*this); break; |
| 863 | case Action::CompileJobClass: |
| 864 | T = new tools::gcc::Compile(*this); break; |
| 865 | case Action::AssembleJobClass: |
| 866 | T = new tools::gcc::Assemble(*this); break; |
| 867 | case Action::LinkJobClass: |
| 868 | T = new tools::gcc::Link(*this); break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 870 | // This is a bit ungeneric, but the only platform using a driver |
| 871 | // driver is Darwin. |
| 872 | case Action::LipoJobClass: |
| 873 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 874 | case Action::DsymutilJobClass: |
| 875 | T = new tools::darwin::Dsymutil(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 876 | } |
| 877 | } |
| 878 | |
| 879 | return *T; |
| 880 | } |
| 881 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 882 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 883 | // FIXME: Gross; we should probably have some separate target |
| 884 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 885 | return getArchName() == "x86_64"; |
| 886 | } |
| 887 | |
| 888 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 889 | return "static"; |
| 890 | } |
| 891 | |
| 892 | const char *Generic_GCC::GetForcedPicModel() const { |
| 893 | return 0; |
| 894 | } |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 895 | |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 896 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 897 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 898 | /// Currently does not support anything else but compilation. |
| 899 | |
| 900 | TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple) |
| 901 | : ToolChain(Host, Triple) { |
| 902 | // Path mangling to find libexec |
| 903 | std::string Path(getDriver().Dir); |
| 904 | |
| 905 | Path += "/../libexec"; |
| 906 | getProgramPaths().push_back(Path); |
| 907 | } |
| 908 | |
| 909 | TCEToolChain::~TCEToolChain() { |
| 910 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 911 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 912 | delete it->second; |
| 913 | } |
| 914 | |
| 915 | bool TCEToolChain::IsMathErrnoDefault() const { |
| 916 | return true; |
| 917 | } |
| 918 | |
| 919 | bool TCEToolChain::IsUnwindTablesDefault() const { |
| 920 | return false; |
| 921 | } |
| 922 | |
| 923 | const char *TCEToolChain::GetDefaultRelocationModel() const { |
| 924 | return "static"; |
| 925 | } |
| 926 | |
| 927 | const char *TCEToolChain::GetForcedPicModel() const { |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | Tool &TCEToolChain::SelectTool(const Compilation &C, |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 932 | const JobAction &JA, |
| 933 | const ActionList &Inputs) const { |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 934 | Action::ActionClass Key; |
| 935 | Key = Action::AnalyzeJobClass; |
| 936 | |
| 937 | Tool *&T = Tools[Key]; |
| 938 | if (!T) { |
| 939 | switch (Key) { |
| 940 | case Action::PreprocessJobClass: |
| 941 | T = new tools::gcc::Preprocess(*this); break; |
| 942 | case Action::AnalyzeJobClass: |
| 943 | T = new tools::Clang(*this); break; |
| 944 | default: |
| 945 | assert(false && "Unsupported action for TCE target."); |
| 946 | } |
| 947 | } |
| 948 | return *T; |
| 949 | } |
| 950 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 951 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 952 | |
| 953 | OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 954 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 955 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 956 | getFilePaths().push_back("/usr/lib"); |
| 957 | } |
| 958 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 959 | Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 960 | const ActionList &Inputs) const { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 961 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 962 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 963 | Key = Action::AnalyzeJobClass; |
| 964 | else |
| 965 | Key = JA.getKind(); |
| 966 | |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 967 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 968 | options::OPT_no_integrated_as, |
| 969 | IsIntegratedAssemblerDefault()); |
| 970 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 971 | Tool *&T = Tools[Key]; |
| 972 | if (!T) { |
| 973 | switch (Key) { |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 974 | case Action::AssembleJobClass: { |
| 975 | if (UseIntegratedAs) |
| 976 | T = new tools::ClangAs(*this); |
| 977 | else |
| 978 | T = new tools::openbsd::Assemble(*this); |
| 979 | break; |
| 980 | } |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 981 | case Action::LinkJobClass: |
| 982 | T = new tools::openbsd::Link(*this); break; |
| 983 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 984 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
| 988 | return *T; |
| 989 | } |
| 990 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 991 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 992 | |
Daniel Dunbar | 214afe9 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 993 | FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 994 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | 214afe9 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 995 | |
| 996 | // Determine if we are compiling 32-bit code on an x86_64 platform. |
| 997 | bool Lib32 = false; |
| 998 | if (Triple.getArch() == llvm::Triple::x86 && |
| 999 | llvm::Triple(getDriver().DefaultHostTriple).getArch() == |
| 1000 | llvm::Triple::x86_64) |
| 1001 | Lib32 = true; |
| 1002 | |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 1003 | if (Lib32) { |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 1004 | getFilePaths().push_back("/usr/lib32"); |
| 1005 | } else { |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 1006 | getFilePaths().push_back("/usr/lib"); |
| 1007 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1010 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 1011 | const ActionList &Inputs) const { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1012 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1013 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1014 | Key = Action::AnalyzeJobClass; |
| 1015 | else |
| 1016 | Key = JA.getKind(); |
| 1017 | |
Roman Divacky | 67dece7 | 2010-11-08 17:46:39 +0000 | [diff] [blame] | 1018 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1019 | options::OPT_no_integrated_as, |
| 1020 | IsIntegratedAssemblerDefault()); |
| 1021 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1022 | Tool *&T = Tools[Key]; |
| 1023 | if (!T) { |
| 1024 | switch (Key) { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1025 | case Action::AssembleJobClass: |
Roman Divacky | 67dece7 | 2010-11-08 17:46:39 +0000 | [diff] [blame] | 1026 | if (UseIntegratedAs) |
| 1027 | T = new tools::ClangAs(*this); |
| 1028 | else |
| 1029 | T = new tools::freebsd::Assemble(*this); |
Roman Divacky | fe3a7ea | 2010-11-08 19:39:10 +0000 | [diff] [blame] | 1030 | break; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1031 | case Action::LinkJobClass: |
| 1032 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1033 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1034 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | return *T; |
| 1039 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1040 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1041 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 1042 | |
| 1043 | NetBSD::NetBSD(const HostInfo &Host, const llvm::Triple& Triple) |
| 1044 | : Generic_ELF(Host, Triple) { |
| 1045 | |
| 1046 | // Determine if we are compiling 32-bit code on an x86_64 platform. |
| 1047 | bool Lib32 = false; |
| 1048 | if (Triple.getArch() == llvm::Triple::x86 && |
| 1049 | llvm::Triple(getDriver().DefaultHostTriple).getArch() == |
| 1050 | llvm::Triple::x86_64) |
| 1051 | Lib32 = true; |
| 1052 | |
Joerg Sonnenberger | 05e5930 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 1053 | if (getDriver().UseStdLib) { |
| 1054 | if (Lib32) |
| 1055 | getFilePaths().push_back("=/usr/lib/i386"); |
| 1056 | else |
| 1057 | getFilePaths().push_back("=/usr/lib"); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1061 | Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 1062 | const ActionList &Inputs) const { |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1063 | Action::ActionClass Key; |
| 1064 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1065 | Key = Action::AnalyzeJobClass; |
| 1066 | else |
| 1067 | Key = JA.getKind(); |
| 1068 | |
| 1069 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1070 | options::OPT_no_integrated_as, |
| 1071 | IsIntegratedAssemblerDefault()); |
| 1072 | |
| 1073 | Tool *&T = Tools[Key]; |
| 1074 | if (!T) { |
| 1075 | switch (Key) { |
| 1076 | case Action::AssembleJobClass: |
| 1077 | if (UseIntegratedAs) |
| 1078 | T = new tools::ClangAs(*this); |
| 1079 | else |
| 1080 | T = new tools::netbsd::Assemble(*this); |
| 1081 | break; |
| 1082 | case Action::LinkJobClass: |
| 1083 | T = new tools::netbsd::Link(*this); break; |
| 1084 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1085 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | return *T; |
| 1090 | } |
| 1091 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1092 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 1093 | |
| 1094 | Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple) |
| 1095 | : Generic_GCC(Host, Triple) { |
| 1096 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 1097 | getFilePaths().push_back("/usr/lib"); |
| 1098 | getFilePaths().push_back("/usr/gnu/lib"); |
| 1099 | getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3"); |
| 1100 | } |
| 1101 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1102 | Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA, |
| 1103 | const ActionList &Inputs) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1104 | Action::ActionClass Key; |
| 1105 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1106 | Key = Action::AnalyzeJobClass; |
| 1107 | else |
| 1108 | Key = JA.getKind(); |
| 1109 | |
| 1110 | Tool *&T = Tools[Key]; |
| 1111 | if (!T) { |
| 1112 | switch (Key) { |
| 1113 | case Action::AssembleJobClass: |
| 1114 | T = new tools::minix::Assemble(*this); break; |
| 1115 | case Action::LinkJobClass: |
| 1116 | T = new tools::minix::Link(*this); break; |
| 1117 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1118 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | return *T; |
| 1123 | } |
| 1124 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1125 | /// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. |
| 1126 | |
| 1127 | AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) |
| 1128 | : Generic_GCC(Host, Triple) { |
| 1129 | |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1130 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 1131 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1132 | getProgramPaths().push_back(getDriver().Dir); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1133 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1134 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1135 | getFilePaths().push_back("/usr/lib"); |
| 1136 | getFilePaths().push_back("/usr/sfw/lib"); |
| 1137 | getFilePaths().push_back("/opt/gcc4/lib"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 1138 | 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] | 1139 | |
| 1140 | } |
| 1141 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1142 | Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA, |
| 1143 | const ActionList &Inputs) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1144 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1145 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1146 | Key = Action::AnalyzeJobClass; |
| 1147 | else |
| 1148 | Key = JA.getKind(); |
| 1149 | |
| 1150 | Tool *&T = Tools[Key]; |
| 1151 | if (!T) { |
| 1152 | switch (Key) { |
| 1153 | case Action::AssembleJobClass: |
| 1154 | T = new tools::auroraux::Assemble(*this); break; |
| 1155 | case Action::LinkJobClass: |
| 1156 | T = new tools::auroraux::Link(*this); break; |
| 1157 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1158 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | return *T; |
| 1163 | } |
| 1164 | |
| 1165 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1166 | /// Linux toolchain (very bare-bones at the moment). |
| 1167 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1168 | enum LinuxDistro { |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1169 | ArchLinux, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1170 | DebianLenny, |
| 1171 | DebianSqueeze, |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1172 | Exherbo, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1173 | Fedora13, |
| 1174 | Fedora14, |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1175 | Fedora15, |
| 1176 | FedoraRawhide, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1177 | OpenSuse11_3, |
Douglas Gregor | 814638e | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 1178 | UbuntuHardy, |
| 1179 | UbuntuIntrepid, |
Rafael Espindola | 021aaa4 | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 1180 | UbuntuJaunty, |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1181 | UbuntuKarmic, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1182 | UbuntuLucid, |
| 1183 | UbuntuMaverick, |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1184 | UbuntuNatty, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1185 | UnknownDistro |
| 1186 | }; |
| 1187 | |
| 1188 | static bool IsFedora(enum LinuxDistro Distro) { |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1189 | return Distro == Fedora13 || Distro == Fedora14 || |
| 1190 | Distro == Fedora15 || Distro == FedoraRawhide; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | static bool IsOpenSuse(enum LinuxDistro Distro) { |
| 1194 | return Distro == OpenSuse11_3; |
| 1195 | } |
| 1196 | |
| 1197 | static bool IsDebian(enum LinuxDistro Distro) { |
| 1198 | return Distro == DebianLenny || Distro == DebianSqueeze; |
| 1199 | } |
| 1200 | |
| 1201 | static bool IsUbuntu(enum LinuxDistro Distro) { |
Douglas Gregor | 814638e | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 1202 | return Distro == UbuntuHardy || Distro == UbuntuIntrepid || |
| 1203 | Distro == UbuntuLucid || Distro == UbuntuMaverick || |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1204 | Distro == UbuntuJaunty || Distro == UbuntuKarmic || |
| 1205 | Distro == UbuntuNatty; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | static bool IsDebianBased(enum LinuxDistro Distro) { |
| 1209 | return IsDebian(Distro) || IsUbuntu(Distro); |
| 1210 | } |
| 1211 | |
| 1212 | static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) { |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1213 | if (Arch == llvm::Triple::x86_64) { |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1214 | bool Exists; |
| 1215 | if (Distro == Exherbo && |
| 1216 | (llvm::sys::fs::exists("/usr/lib32/libc.so", Exists) || !Exists)) |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1217 | return false; |
| 1218 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1219 | return true; |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1220 | } |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1221 | if (Arch == llvm::Triple::ppc64) |
| 1222 | return true; |
| 1223 | if ((Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc) && IsDebianBased(Distro)) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1224 | return true; |
| 1225 | return false; |
| 1226 | } |
| 1227 | |
| 1228 | static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) { |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1229 | llvm::OwningPtr<llvm::MemoryBuffer> File; |
| 1230 | if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) { |
| 1231 | llvm::StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1232 | llvm::SmallVector<llvm::StringRef, 8> Lines; |
| 1233 | Data.split(Lines, "\n"); |
| 1234 | for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) { |
Douglas Gregor | 814638e | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 1235 | if (Lines[i] == "DISTRIB_CODENAME=hardy") |
| 1236 | return UbuntuHardy; |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1237 | else if (Lines[i] == "DISTRIB_CODENAME=intrepid") |
| 1238 | return UbuntuIntrepid; |
Rafael Espindola | 021aaa4 | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 1239 | else if (Lines[i] == "DISTRIB_CODENAME=jaunty") |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1240 | return UbuntuJaunty; |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1241 | else if (Lines[i] == "DISTRIB_CODENAME=karmic") |
| 1242 | return UbuntuKarmic; |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1243 | else if (Lines[i] == "DISTRIB_CODENAME=lucid") |
| 1244 | return UbuntuLucid; |
| 1245 | else if (Lines[i] == "DISTRIB_CODENAME=maverick") |
| 1246 | return UbuntuMaverick; |
| 1247 | else if (Lines[i] == "DISTRIB_CODENAME=natty") |
| 1248 | return UbuntuNatty; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1249 | } |
| 1250 | return UnknownDistro; |
| 1251 | } |
| 1252 | |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1253 | if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) { |
| 1254 | llvm::StringRef Data = File.get()->getBuffer(); |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1255 | if (Data.startswith("Fedora release 15")) |
| 1256 | return Fedora15; |
| 1257 | else if (Data.startswith("Fedora release 14")) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1258 | return Fedora14; |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1259 | else if (Data.startswith("Fedora release 13")) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1260 | return Fedora13; |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1261 | else if (Data.startswith("Fedora release") && |
| 1262 | Data.find("Rawhide") != llvm::StringRef::npos) |
| 1263 | return FedoraRawhide; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1264 | return UnknownDistro; |
| 1265 | } |
| 1266 | |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1267 | if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) { |
| 1268 | llvm::StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1269 | if (Data[0] == '5') |
| 1270 | return DebianLenny; |
| 1271 | else if (Data.startswith("squeeze/sid")) |
| 1272 | return DebianSqueeze; |
| 1273 | return UnknownDistro; |
| 1274 | } |
| 1275 | |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1276 | if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) { |
| 1277 | llvm::StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1278 | if (Data.startswith("openSUSE 11.3")) |
| 1279 | return OpenSuse11_3; |
| 1280 | return UnknownDistro; |
| 1281 | } |
| 1282 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1283 | bool Exists; |
| 1284 | if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists) |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1285 | return Exherbo; |
| 1286 | |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1287 | if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists) |
| 1288 | return ArchLinux; |
| 1289 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1290 | return UnknownDistro; |
| 1291 | } |
| 1292 | |
Nick Lewycky | 3fdcc6f | 2010-12-31 17:31:54 +0000 | [diff] [blame] | 1293 | Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 1294 | : Generic_ELF(Host, Triple) { |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1295 | llvm::Triple::ArchType Arch = |
| 1296 | llvm::Triple(getDriver().DefaultHostTriple).getArch(); |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 1297 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1298 | std::string Suffix32 = ""; |
| 1299 | if (Arch == llvm::Triple::x86_64) |
| 1300 | Suffix32 = "/32"; |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 1301 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1302 | std::string Suffix64 = ""; |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1303 | if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1304 | Suffix64 = "/64"; |
| 1305 | |
| 1306 | std::string Lib32 = "lib"; |
| 1307 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1308 | bool Exists; |
| 1309 | if (!llvm::sys::fs::exists("/lib32", Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1310 | Lib32 = "lib32"; |
| 1311 | |
| 1312 | std::string Lib64 = "lib"; |
Michael J. Spencer | 2dea7c7 | 2011-01-12 23:54:48 +0000 | [diff] [blame] | 1313 | bool Symlink; |
Chris Lattner | 48aef36 | 2011-01-13 01:35:58 +0000 | [diff] [blame] | 1314 | if (!llvm::sys::fs::exists("/lib64", Exists) && Exists && |
| 1315 | (llvm::sys::fs::is_symlink("/lib64", Symlink) || !Symlink)) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1316 | Lib64 = "lib64"; |
| 1317 | |
| 1318 | std::string GccTriple = ""; |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 1319 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) { |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1320 | if (!llvm::sys::fs::exists("/usr/lib/gcc/arm-linux-gnueabi", Exists) && |
| 1321 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1322 | GccTriple = "arm-linux-gnueabi"; |
| 1323 | } else if (Arch == llvm::Triple::x86_64) { |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1324 | if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-linux-gnu", Exists) && |
| 1325 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1326 | GccTriple = "x86_64-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1327 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-unknown-linux-gnu", |
| 1328 | Exists) && Exists) |
Rafael Espindola | 53dd00b | 2010-11-17 00:25:26 +0000 | [diff] [blame] | 1329 | GccTriple = "x86_64-unknown-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1330 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-pc-linux-gnu", |
| 1331 | Exists) && Exists) |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1332 | GccTriple = "x86_64-pc-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1333 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-redhat-linux", |
| 1334 | Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1335 | GccTriple = "x86_64-redhat-linux"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1336 | else if (!llvm::sys::fs::exists("/usr/lib64/gcc/x86_64-suse-linux", |
| 1337 | Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1338 | GccTriple = "x86_64-suse-linux"; |
Nick Lewycky | e10f900 | 2011-02-01 23:03:29 +0000 | [diff] [blame] | 1339 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-manbo-linux-gnu", |
| 1340 | Exists) && Exists) |
| 1341 | GccTriple = "x86_64-manbo-linux-gnu"; |
Nico Weber | 80585d8 | 2011-04-25 03:17:35 +0000 | [diff] [blame] | 1342 | else if (!llvm::sys::fs::exists("/usr/lib/x86_64-linux-gnu/gcc", |
| 1343 | Exists) && Exists) |
| 1344 | GccTriple = "x86_64-linux-gnu"; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1345 | } else if (Arch == llvm::Triple::x86) { |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1346 | 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] | 1347 | GccTriple = "i686-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1348 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-pc-linux-gnu", Exists) && |
| 1349 | Exists) |
Nuno Lopes | 2a69ddd | 2010-11-19 17:26:57 +0000 | [diff] [blame] | 1350 | GccTriple = "i686-pc-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1351 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-linux-gnu", Exists) && |
| 1352 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1353 | GccTriple = "i486-linux-gnu"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1354 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-redhat-linux", Exists) && |
| 1355 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1356 | GccTriple = "i686-redhat-linux"; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1357 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i586-suse-linux", Exists) && |
| 1358 | Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1359 | GccTriple = "i586-suse-linux"; |
Ted Kremenek | d130c7d | 2011-04-18 17:50:19 +0000 | [diff] [blame] | 1360 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-slackware-linux", Exists) |
| 1361 | && Exists) |
| 1362 | GccTriple = "i486-slackware-linux"; |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1363 | } else if (Arch == llvm::Triple::ppc) { |
| 1364 | if (!llvm::sys::fs::exists("/usr/lib/powerpc-linux-gnu", Exists) && Exists) |
| 1365 | GccTriple = "powerpc-linux-gnu"; |
| 1366 | else if (!llvm::sys::fs::exists("/usr/lib/gcc/powerpc-unknown-linux-gnu", Exists) && Exists) |
| 1367 | GccTriple = "powerpc-unknown-linux-gnu"; |
| 1368 | } else if (Arch == llvm::Triple::ppc64) { |
| 1369 | if (!llvm::sys::fs::exists("/usr/lib/gcc/powerpc64-unknown-linux-gnu", Exists) && Exists) |
| 1370 | GccTriple = "powerpc64-unknown-linux-gnu"; |
| 1371 | else if (!llvm::sys::fs::exists("/usr/lib64/gcc/powerpc64-unknown-linux-gnu", Exists) && Exists) |
| 1372 | GccTriple = "powerpc64-unknown-linux-gnu"; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1375 | const char* GccVersions[] = {"4.6.0", |
| 1376 | "4.5.2", "4.5.1", "4.5", |
| 1377 | "4.4.5", "4.4.4", "4.4.3", "4.4", |
| 1378 | "4.3.4", "4.3.3", "4.3.2", "4.3", |
| 1379 | "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] | 1380 | std::string Base = ""; |
| 1381 | for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) { |
| 1382 | std::string Suffix = GccTriple + "/" + GccVersions[i]; |
| 1383 | std::string t1 = "/usr/lib/gcc/" + Suffix; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1384 | if (!llvm::sys::fs::exists(t1 + "/crtbegin.o", Exists) && Exists) { |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1385 | Base = t1; |
| 1386 | break; |
| 1387 | } |
| 1388 | std::string t2 = "/usr/lib64/gcc/" + Suffix; |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1389 | if (!llvm::sys::fs::exists(t2 + "/crtbegin.o", Exists) && Exists) { |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1390 | Base = t2; |
| 1391 | break; |
| 1392 | } |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1393 | std::string t3 = "/usr/lib/" + GccTriple + "/gcc/" + Suffix; |
| 1394 | if (!llvm::sys::fs::exists(t3 + "/crtbegin.o", Exists) && Exists) { |
| 1395 | Base = t3; |
| 1396 | break; |
| 1397 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | path_list &Paths = getFilePaths(); |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1401 | bool Is32Bits = (getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::ppc); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1402 | |
| 1403 | std::string Suffix; |
| 1404 | std::string Lib; |
| 1405 | |
| 1406 | if (Is32Bits) { |
| 1407 | Suffix = Suffix32; |
| 1408 | Lib = Lib32; |
| 1409 | } else { |
| 1410 | Suffix = Suffix64; |
| 1411 | Lib = Lib64; |
| 1412 | } |
| 1413 | |
| 1414 | llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1415 | if (!llvm::sys::fs::exists(LinkerPath.str(), Exists) && Exists) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1416 | Linker = LinkerPath.str(); |
| 1417 | else |
| 1418 | Linker = GetProgramPath("ld"); |
| 1419 | |
| 1420 | LinuxDistro Distro = DetectLinuxDistro(Arch); |
| 1421 | |
Rafael Espindola | 94c8022 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 1422 | if (IsUbuntu(Distro)) { |
| 1423 | ExtraOpts.push_back("-z"); |
| 1424 | ExtraOpts.push_back("relro"); |
| 1425 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1426 | |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 1427 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1428 | ExtraOpts.push_back("-X"); |
| 1429 | |
Nico Weber | 80585d8 | 2011-04-25 03:17:35 +0000 | [diff] [blame] | 1430 | if (IsFedora(Distro) || Distro == UbuntuMaverick || Distro == UbuntuNatty) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1431 | ExtraOpts.push_back("--hash-style=gnu"); |
| 1432 | |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1433 | if (IsDebian(Distro) || Distro == UbuntuLucid || Distro == UbuntuJaunty || |
| 1434 | Distro == UbuntuKarmic) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1435 | ExtraOpts.push_back("--hash-style=both"); |
| 1436 | |
| 1437 | if (IsFedora(Distro)) |
| 1438 | ExtraOpts.push_back("--no-add-needed"); |
| 1439 | |
Rafael Espindola | 021aaa4 | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 1440 | if (Distro == DebianSqueeze || IsOpenSuse(Distro) || |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1441 | IsFedora(Distro) || Distro == UbuntuLucid || Distro == UbuntuMaverick || |
Nico Weber | 80585d8 | 2011-04-25 03:17:35 +0000 | [diff] [blame] | 1442 | Distro == UbuntuKarmic || Distro == UbuntuNatty) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1443 | ExtraOpts.push_back("--build-id"); |
| 1444 | |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1445 | if (Distro == ArchLinux) |
| 1446 | Lib = "lib"; |
| 1447 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1448 | Paths.push_back(Base + Suffix); |
| 1449 | if (HasMultilib(Arch, Distro)) { |
| 1450 | if (IsOpenSuse(Distro) && Is32Bits) |
| 1451 | Paths.push_back(Base + "/../../../../" + GccTriple + "/lib/../lib"); |
| 1452 | Paths.push_back(Base + "/../../../../" + Lib); |
| 1453 | Paths.push_back("/lib/../" + Lib); |
| 1454 | Paths.push_back("/usr/lib/../" + Lib); |
| 1455 | } |
| 1456 | if (!Suffix.empty()) |
| 1457 | Paths.push_back(Base); |
| 1458 | if (IsOpenSuse(Distro)) |
| 1459 | Paths.push_back(Base + "/../../../../" + GccTriple + "/lib"); |
| 1460 | Paths.push_back(Base + "/../../.."); |
| 1461 | if (Arch == getArch() && IsUbuntu(Distro)) |
| 1462 | Paths.push_back("/usr/lib/" + GccTriple); |
| 1463 | } |
| 1464 | |
| 1465 | bool Linux::HasNativeLLVMSupport() const { |
| 1466 | return true; |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1469 | Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA, |
| 1470 | const ActionList &Inputs) const { |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1471 | Action::ActionClass Key; |
| 1472 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1473 | Key = Action::AnalyzeJobClass; |
| 1474 | else |
| 1475 | Key = JA.getKind(); |
| 1476 | |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1477 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1478 | options::OPT_no_integrated_as, |
| 1479 | IsIntegratedAssemblerDefault()); |
| 1480 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1481 | Tool *&T = Tools[Key]; |
| 1482 | if (!T) { |
| 1483 | switch (Key) { |
| 1484 | case Action::AssembleJobClass: |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1485 | if (UseIntegratedAs) |
| 1486 | T = new tools::ClangAs(*this); |
| 1487 | else |
| 1488 | T = new tools::linuxtools::Assemble(*this); |
| 1489 | break; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1490 | case Action::LinkJobClass: |
| 1491 | T = new tools::linuxtools::Link(*this); break; |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1492 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1493 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | return *T; |
| 1498 | } |
| 1499 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1500 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 1501 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1502 | DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 1503 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1504 | |
| 1505 | // Path mangling to find libexec |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1506 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 1507 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1508 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1509 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1510 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1511 | getFilePaths().push_back("/usr/lib"); |
| 1512 | getFilePaths().push_back("/usr/lib/gcc41"); |
| 1513 | } |
| 1514 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1515 | Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA, |
| 1516 | const ActionList &Inputs) const { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1517 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1518 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1519 | Key = Action::AnalyzeJobClass; |
| 1520 | else |
| 1521 | Key = JA.getKind(); |
| 1522 | |
| 1523 | Tool *&T = Tools[Key]; |
| 1524 | if (!T) { |
| 1525 | switch (Key) { |
| 1526 | case Action::AssembleJobClass: |
| 1527 | T = new tools::dragonfly::Assemble(*this); break; |
| 1528 | case Action::LinkJobClass: |
| 1529 | T = new tools::dragonfly::Link(*this); break; |
| 1530 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1531 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | return *T; |
| 1536 | } |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 1537 | |
| 1538 | Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple) |
| 1539 | : ToolChain(Host, Triple) { |
| 1540 | } |
| 1541 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1542 | Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA, |
| 1543 | const ActionList &Inputs) const { |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 1544 | Action::ActionClass Key; |
| 1545 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1546 | Key = Action::AnalyzeJobClass; |
| 1547 | else |
| 1548 | Key = JA.getKind(); |
| 1549 | |
| 1550 | Tool *&T = Tools[Key]; |
| 1551 | if (!T) { |
| 1552 | switch (Key) { |
| 1553 | case Action::InputClass: |
| 1554 | case Action::BindArchClass: |
Chandler Carruth | e97673f | 2010-08-22 06:56:37 +0000 | [diff] [blame] | 1555 | case Action::LipoJobClass: |
| 1556 | case Action::DsymutilJobClass: |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 1557 | assert(0 && "Invalid tool kind."); |
| 1558 | case Action::PreprocessJobClass: |
| 1559 | case Action::PrecompileJobClass: |
| 1560 | case Action::AnalyzeJobClass: |
| 1561 | case Action::CompileJobClass: |
| 1562 | T = new tools::Clang(*this); break; |
| 1563 | case Action::AssembleJobClass: |
| 1564 | T = new tools::ClangAs(*this); break; |
| 1565 | case Action::LinkJobClass: |
| 1566 | T = new tools::visualstudio::Link(*this); break; |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | return *T; |
| 1571 | } |
| 1572 | |
| 1573 | bool Windows::IsIntegratedAssemblerDefault() const { |
| 1574 | return true; |
| 1575 | } |
| 1576 | |
| 1577 | bool Windows::IsUnwindTablesDefault() const { |
| 1578 | // FIXME: Gross; we should probably have some separate target |
| 1579 | // definition, possibly even reusing the one in clang. |
| 1580 | return getArchName() == "x86_64"; |
| 1581 | } |
| 1582 | |
| 1583 | const char *Windows::GetDefaultRelocationModel() const { |
| 1584 | return "static"; |
| 1585 | } |
| 1586 | |
| 1587 | const char *Windows::GetForcedPicModel() const { |
| 1588 | if (getArchName() == "x86_64") |
| 1589 | return "pic"; |
| 1590 | return 0; |
| 1591 | } |