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