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