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