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