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 | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 15 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 16 | #include "clang/Driver/HostInfo.h" |
Daniel Dunbar | 27e738d | 2009-11-19 00:15:11 +0000 | [diff] [blame] | 17 | #include "clang/Driver/OptTable.h" |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 18 | #include "clang/Driver/Option.h" |
Daniel Dunbar | 265e9ef | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Options.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 20 | |
| 21 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 23 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 24 | #include "llvm/System/Path.h" |
| 25 | |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 26 | #include <cstdlib> // ::getenv |
| 27 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 28 | using namespace clang::driver; |
| 29 | using namespace clang::driver::toolchains; |
| 30 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 31 | /// Darwin - Darwin tool chain for i386 and x86_64. |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 32 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 33 | Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 34 | const unsigned (&_DarwinVersion)[3], bool _IsIPhoneOS) |
| 35 | : ToolChain(Host, Triple), |
| 36 | IsIPhoneOS(_IsIPhoneOS) |
| 37 | { |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 38 | DarwinVersion[0] = _DarwinVersion[0]; |
| 39 | DarwinVersion[1] = _DarwinVersion[1]; |
| 40 | DarwinVersion[2] = _DarwinVersion[2]; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 41 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 42 | llvm::raw_string_ostream(MacosxVersionMin) |
Benjamin Kramer | 87f9fd9 | 2009-10-21 21:05:07 +0000 | [diff] [blame] | 43 | << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.' |
| 44 | << DarwinVersion[1]; |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 45 | |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 46 | // FIXME: Lift default up. |
| 47 | IPhoneOSVersionMin = "3.0"; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, |
| 51 | const unsigned (&DarwinVersion)[3], |
Ted Kremenek | 55bac53 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 52 | const unsigned (&_GCCVersion)[3], bool IsIPhoneOS) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 53 | : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS) |
| 54 | { |
| 55 | GCCVersion[0] = _GCCVersion[0]; |
| 56 | GCCVersion[1] = _GCCVersion[1]; |
| 57 | GCCVersion[2] = _GCCVersion[2]; |
| 58 | |
| 59 | // Set up the tool chain paths to match gcc. |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 60 | ToolChainDir = "i686-apple-darwin"; |
Ted Kremenek | 55bac53 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 61 | ToolChainDir += llvm::utostr(DarwinVersion[0]); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 62 | ToolChainDir += "/"; |
| 63 | ToolChainDir += llvm::utostr(GCCVersion[0]); |
| 64 | ToolChainDir += '.'; |
| 65 | ToolChainDir += llvm::utostr(GCCVersion[1]); |
| 66 | ToolChainDir += '.'; |
| 67 | ToolChainDir += llvm::utostr(GCCVersion[2]); |
| 68 | |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 69 | // Try the next major version if that tool chain dir is invalid. |
Daniel Dunbar | 080fb19 | 2009-10-22 00:12:00 +0000 | [diff] [blame] | 70 | std::string Tmp = "/usr/lib/gcc/" + ToolChainDir; |
| 71 | if (!llvm::sys::Path(Tmp).exists()) { |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 72 | std::string Next = "i686-apple-darwin"; |
| 73 | Next += llvm::utostr(DarwinVersion[0] + 1); |
| 74 | Next += "/"; |
| 75 | Next += llvm::utostr(GCCVersion[0]); |
| 76 | Next += '.'; |
| 77 | Next += llvm::utostr(GCCVersion[1]); |
| 78 | Next += '.'; |
| 79 | Next += llvm::utostr(GCCVersion[2]); |
| 80 | |
| 81 | // Use that if it exists, otherwise hope the user isn't linking. |
| 82 | // |
| 83 | // FIXME: Drop dependency on gcc's tool chain. |
Daniel Dunbar | 080fb19 | 2009-10-22 00:12:00 +0000 | [diff] [blame] | 84 | Tmp = "/usr/lib/gcc/" + Next; |
| 85 | if (llvm::sys::Path(Tmp).exists()) |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 86 | ToolChainDir = Next; |
| 87 | } |
| 88 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 89 | std::string Path; |
| 90 | if (getArchName() == "x86_64") { |
| 91 | Path = getHost().getDriver().Dir; |
| 92 | Path += "/../lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 93 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 94 | Path += "/x86_64"; |
| 95 | getFilePaths().push_back(Path); |
| 96 | |
| 97 | Path = "/usr/lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 98 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 99 | Path += "/x86_64"; |
| 100 | getFilePaths().push_back(Path); |
| 101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 103 | Path = getHost().getDriver().Dir; |
| 104 | Path += "/../lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 105 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 106 | getFilePaths().push_back(Path); |
| 107 | |
| 108 | Path = "/usr/lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 109 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 110 | getFilePaths().push_back(Path); |
| 111 | |
| 112 | Path = getHost().getDriver().Dir; |
| 113 | Path += "/../libexec/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 114 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 115 | getProgramPaths().push_back(Path); |
| 116 | |
| 117 | Path = "/usr/libexec/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 118 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 119 | getProgramPaths().push_back(Path); |
| 120 | |
Daniel Dunbar | 82fa7c5 | 2009-03-24 04:07:10 +0000 | [diff] [blame] | 121 | Path = getHost().getDriver().Dir; |
| 122 | Path += "/../libexec"; |
| 123 | getProgramPaths().push_back(Path); |
| 124 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 125 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 126 | } |
| 127 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 128 | Darwin::~Darwin() { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 129 | // Free tool implementations. |
| 130 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 131 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 132 | delete it->second; |
| 133 | } |
| 134 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 135 | Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 136 | Action::ActionClass Key; |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 137 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 138 | Key = Action::AnalyzeJobClass; |
| 139 | else |
| 140 | Key = JA.getKind(); |
| 141 | |
| 142 | Tool *&T = Tools[Key]; |
| 143 | if (!T) { |
| 144 | switch (Key) { |
| 145 | case Action::InputClass: |
| 146 | case Action::BindArchClass: |
| 147 | assert(0 && "Invalid tool kind."); |
| 148 | case Action::PreprocessJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 149 | T = new tools::darwin::Preprocess(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 150 | case Action::AnalyzeJobClass: |
| 151 | T = new tools::Clang(*this); break; |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 152 | case Action::PrecompileJobClass: |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 153 | case Action::CompileJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 154 | T = new tools::darwin::Compile(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 155 | case Action::AssembleJobClass: |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 156 | T = new tools::darwin::Assemble(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 157 | case Action::LinkJobClass: |
Daniel Dunbar | 8f28962 | 2009-09-04 17:39:02 +0000 | [diff] [blame] | 158 | T = new tools::darwin::Link(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 159 | case Action::LipoJobClass: |
| 160 | T = new tools::darwin::Lipo(*this); break; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return *T; |
| 165 | } |
| 166 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 167 | void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args, |
| 168 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 169 | // FIXME: Derive these correctly. |
| 170 | if (getArchName() == "x86_64") { |
| 171 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 172 | "/x86_64")); |
| 173 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 174 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 175 | "/x86_64")); |
| 176 | } |
| 177 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir)); |
| 178 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); |
| 179 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 180 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); |
| 181 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 182 | "/../../../" + ToolChainDir)); |
| 183 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 184 | "/../../..")); |
| 185 | } |
| 186 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 187 | void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 188 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 189 | unsigned MacosxVersionMin[3]; |
| 190 | getMacosxVersionMin(Args, MacosxVersionMin); |
| 191 | |
| 192 | // Derived from libgcc and lib specs but refactored. |
| 193 | if (Args.hasArg(options::OPT_static)) { |
| 194 | CmdArgs.push_back("-lgcc_static"); |
| 195 | } else { |
| 196 | if (Args.hasArg(options::OPT_static_libgcc)) { |
| 197 | CmdArgs.push_back("-lgcc_eh"); |
| 198 | } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
| 199 | // Derived from darwin_iphoneos_libgcc spec. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 200 | if (isIPhoneOS()) { |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 201 | CmdArgs.push_back("-lgcc_s.1"); |
| 202 | } else { |
| 203 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 204 | } |
| 205 | } else if (Args.hasArg(options::OPT_shared_libgcc) || |
| 206 | // FIXME: -fexceptions -fno-exceptions means no exceptions |
| 207 | Args.hasArg(options::OPT_fexceptions) || |
| 208 | Args.hasArg(options::OPT_fgnu_runtime)) { |
| 209 | // FIXME: This is probably broken on 10.3? |
| 210 | if (isMacosxVersionLT(MacosxVersionMin, 10, 5)) |
| 211 | CmdArgs.push_back("-lgcc_s.10.4"); |
| 212 | else if (isMacosxVersionLT(MacosxVersionMin, 10, 6)) |
| 213 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 214 | } else { |
| 215 | if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9)) |
| 216 | ; // Do nothing. |
| 217 | else if (isMacosxVersionLT(MacosxVersionMin, 10, 5)) |
| 218 | CmdArgs.push_back("-lgcc_s.10.4"); |
| 219 | else if (isMacosxVersionLT(MacosxVersionMin, 10, 6)) |
| 220 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 221 | } |
| 222 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 223 | if (isIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) { |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 224 | CmdArgs.push_back("-lgcc"); |
| 225 | CmdArgs.push_back("-lSystem"); |
| 226 | } else { |
| 227 | CmdArgs.push_back("-lSystem"); |
| 228 | CmdArgs.push_back("-lgcc"); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 233 | DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, |
| 234 | const unsigned (&DarwinVersion)[3], |
| 235 | bool IsIPhoneOS) |
| 236 | : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS) |
| 237 | { |
Daniel Dunbar | a92ba27 | 2009-09-29 18:52:10 +0000 | [diff] [blame] | 238 | // Add the relative libexec dir (for clang-cc). |
| 239 | // |
| 240 | // FIXME: We should sink clang-cc into libexec/clang/<version>/. |
| 241 | std::string Path = getHost().getDriver().Dir; |
| 242 | Path += "/../libexec"; |
| 243 | getProgramPaths().push_back(Path); |
| 244 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 245 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
| 246 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 247 | } |
| 248 | |
| 249 | void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, |
| 250 | ArgStringList &CmdArgs) const { |
| 251 | // The Clang toolchain uses explicit paths for internal libraries. |
| 252 | } |
| 253 | |
| 254 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 255 | ArgStringList &CmdArgs) const { |
| 256 | // Check for static linking. |
| 257 | if (Args.hasArg(options::OPT_static)) { |
| 258 | // FIXME: We need to have compiler-rt available (perhaps as |
| 259 | // libclang_static.a) to link against. |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 264 | // cares. This is useful in situations where someone wants to statically link |
| 265 | // something like libstdc++, and needs its runtime support routines. |
| 266 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
| 267 | getHost().getDriver().Diag(clang::diag::err_drv_unsupported_opt) |
| 268 | << A->getAsString(Args); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | // Otherwise link libSystem, which should have the support routines. |
| 273 | // |
| 274 | // FIXME: This is only true for 10.6 and beyond. Legacy support isn't |
| 275 | // critical, but it should work... we should just link in the static |
| 276 | // compiler-rt library. |
| 277 | CmdArgs.push_back("-lSystem"); |
| 278 | } |
| 279 | |
Daniel Dunbar | 48d5aae | 2009-09-18 08:14:46 +0000 | [diff] [blame] | 280 | void Darwin::getMacosxVersionMin(const ArgList &Args, |
| 281 | unsigned (&Res)[3]) const { |
| 282 | if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) { |
| 283 | bool HadExtra; |
| 284 | if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2], |
| 285 | HadExtra) || |
| 286 | HadExtra) { |
| 287 | const Driver &D = getHost().getDriver(); |
| 288 | D.Diag(clang::diag::err_drv_invalid_version_number) |
| 289 | << A->getAsString(Args); |
| 290 | } |
| 291 | } else |
| 292 | return getMacosxVersion(Res); |
| 293 | } |
| 294 | |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 295 | DerivedArgList *Darwin::TranslateArgs(InputArgList &Args, |
| 296 | const char *BoundArch) const { |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 297 | DerivedArgList *DAL = new DerivedArgList(Args, false); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 298 | const OptTable &Opts = getHost().getDriver().getOpts(); |
| 299 | |
| 300 | // FIXME: We really want to get out of the tool chain level argument |
| 301 | // translation business, as it makes the driver functionality much |
| 302 | // more opaque. For now, we follow gcc closely solely for the |
| 303 | // purpose of easily achieving feature parity & testability. Once we |
| 304 | // have something that works, we should reevaluate each translation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | // and try to push it down into tool specific logic. |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 306 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | Arg *OSXVersion = |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 308 | Args.getLastArgNoClaim(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 309 | Arg *iPhoneVersion = |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 310 | Args.getLastArgNoClaim(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 311 | if (OSXVersion && iPhoneVersion) { |
| 312 | getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 313 | << OSXVersion->getAsString(Args) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 314 | << iPhoneVersion->getAsString(Args); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 315 | } else if (!OSXVersion && !iPhoneVersion) { |
| 316 | // Chose the default version based on the arch. |
| 317 | // |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 318 | // FIXME: Are there iPhone overrides for this? |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 319 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 320 | if (!isIPhoneOS()) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 321 | // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version |
| 322 | // from the host. |
| 323 | const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET"); |
| 324 | if (!Version) |
| 325 | Version = MacosxVersionMin.c_str(); |
| 326 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
| 327 | DAL->append(DAL->MakeJoinedArg(0, O, Version)); |
| 328 | } else { |
| 329 | const char *Version = IPhoneOSVersionMin.c_str(); |
| 330 | const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
| 331 | DAL->append(DAL->MakeJoinedArg(0, O, Version)); |
| 332 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 334 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 335 | for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 336 | Arg *A = *it; |
| 337 | |
| 338 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 339 | // FIXME: Canonicalize name. |
| 340 | if (getArchName() != A->getValue(Args, 0)) |
| 341 | continue; |
| 342 | |
| 343 | // FIXME: The arg is leaked here, and we should have a nicer |
| 344 | // interface for this. |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 345 | unsigned Prev, Index = Prev = A->getIndex() + 1; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 346 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 347 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 348 | // If the argument parsing failed or more than one argument was |
| 349 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 350 | // extra arguments. Emit an error and ignore. |
| 351 | // |
| 352 | // We also want to disallow any options which would alter the |
| 353 | // driver behavior; that isn't going to work in our model. We |
| 354 | // use isDriverOption() as an approximation, although things |
| 355 | // like -O4 are going to slip through. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | if (!XarchArg || Index > Prev + 1 || |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 357 | XarchArg->getOption().isDriverOption()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 358 | getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 359 | << A->getAsString(Args); |
| 360 | continue; |
| 361 | } |
| 362 | |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 363 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 364 | A = XarchArg; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 366 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 367 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 368 | // gcc translates options twice, which means that self-expanding |
| 369 | // options add duplicates. |
Daniel Dunbar | 9e1f982 | 2009-11-19 04:14:53 +0000 | [diff] [blame] | 370 | switch ((options::ID) A->getOption().getID()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 371 | default: |
| 372 | DAL->append(A); |
| 373 | break; |
| 374 | |
| 375 | case options::OPT_mkernel: |
| 376 | case options::OPT_fapple_kext: |
| 377 | DAL->append(A); |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 378 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
| 379 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 380 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 382 | case options::OPT_dependency_file: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 383 | DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF), |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 384 | A->getValue(Args))); |
| 385 | break; |
| 386 | |
| 387 | case options::OPT_gfull: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 388 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); |
| 389 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 390 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols))); |
| 391 | break; |
| 392 | |
| 393 | case options::OPT_gused: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 394 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); |
| 395 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 396 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols))); |
| 397 | break; |
| 398 | |
| 399 | case options::OPT_fterminated_vtables: |
| 400 | case options::OPT_findirect_virtual_calls: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 401 | DAL->append(DAL->MakeFlagArg(A, |
| 402 | Opts.getOption(options::OPT_fapple_kext))); |
| 403 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 404 | break; |
| 405 | |
| 406 | case options::OPT_shared: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 407 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 408 | break; |
| 409 | |
| 410 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 411 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 412 | Opts.getOption(options::OPT_mconstant_cfstrings))); |
| 413 | break; |
| 414 | |
| 415 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 416 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 417 | Opts.getOption(options::OPT_mno_constant_cfstrings))); |
| 418 | break; |
| 419 | |
| 420 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 421 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 422 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings))); |
| 423 | break; |
| 424 | |
| 425 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 426 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 427 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings))); |
| 428 | break; |
| 429 | |
| 430 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 431 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 432 | Opts.getOption(options::OPT_mpascal_strings))); |
| 433 | break; |
| 434 | |
| 435 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 436 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 437 | Opts.getOption(options::OPT_mno_pascal_strings))); |
| 438 | break; |
| 439 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 442 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 443 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 444 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 445 | DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), |
| 446 | "core2")); |
| 447 | |
| 448 | // Add the arch options based on the particular spelling of -arch, to match |
| 449 | // how the driver driver works. |
| 450 | if (BoundArch) { |
| 451 | llvm::StringRef Name = BoundArch; |
| 452 | const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 453 | const Option *MArch = Opts.getOption(options::OPT_march_EQ); |
| 454 | |
| 455 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 456 | // which defines the list of which architectures we accept. |
| 457 | if (Name == "ppc") |
| 458 | ; |
| 459 | else if (Name == "ppc601") |
| 460 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "601")); |
| 461 | else if (Name == "ppc603") |
| 462 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "603")); |
| 463 | else if (Name == "ppc604") |
| 464 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "604")); |
| 465 | else if (Name == "ppc604e") |
| 466 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e")); |
| 467 | else if (Name == "ppc750") |
| 468 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "750")); |
| 469 | else if (Name == "ppc7400") |
| 470 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400")); |
| 471 | else if (Name == "ppc7450") |
| 472 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450")); |
| 473 | else if (Name == "ppc970") |
| 474 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "970")); |
| 475 | |
| 476 | else if (Name == "ppc64") |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 477 | DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 478 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 479 | else if (Name == "i386") |
| 480 | ; |
| 481 | else if (Name == "i486") |
| 482 | DAL->append(DAL->MakeJoinedArg(0, MArch, "i486")); |
| 483 | else if (Name == "i586") |
| 484 | DAL->append(DAL->MakeJoinedArg(0, MArch, "i586")); |
| 485 | else if (Name == "i686") |
| 486 | DAL->append(DAL->MakeJoinedArg(0, MArch, "i686")); |
| 487 | else if (Name == "pentium") |
| 488 | DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium")); |
| 489 | else if (Name == "pentium2") |
| 490 | DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2")); |
| 491 | else if (Name == "pentpro") |
| 492 | DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro")); |
| 493 | else if (Name == "pentIIm3") |
| 494 | DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2")); |
| 495 | |
| 496 | else if (Name == "x86_64") |
| 497 | DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64))); |
| 498 | |
| 499 | else if (Name == "arm") |
| 500 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t")); |
| 501 | else if (Name == "armv4t") |
| 502 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t")); |
| 503 | else if (Name == "armv5") |
| 504 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej")); |
| 505 | else if (Name == "xscale") |
| 506 | DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale")); |
| 507 | else if (Name == "armv6") |
| 508 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k")); |
| 509 | else if (Name == "armv7") |
| 510 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a")); |
| 511 | |
| 512 | else |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame^] | 513 | llvm_unreachable("invalid Darwin arch"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 514 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 515 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 516 | return DAL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 518 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 519 | bool Darwin::IsMathErrnoDefault() const { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | return false; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 523 | bool Darwin::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 524 | // FIXME: Gross; we should probably have some separate target |
| 525 | // definition, possibly even reusing the one in clang. |
| 526 | return getArchName() == "x86_64"; |
| 527 | } |
| 528 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 529 | const char *Darwin::GetDefaultRelocationModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 530 | return "pic"; |
| 531 | } |
| 532 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 533 | const char *Darwin::GetForcedPicModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 534 | if (getArchName() == "x86_64") |
| 535 | return "pic"; |
| 536 | return 0; |
| 537 | } |
| 538 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 539 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 540 | /// all subcommands; this relies on gcc translating the majority of |
| 541 | /// command line options. |
| 542 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 543 | Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | : ToolChain(Host, Triple) { |
Daniel Dunbar | 82fa7c5 | 2009-03-24 04:07:10 +0000 | [diff] [blame] | 545 | std::string Path(getHost().getDriver().Dir); |
| 546 | Path += "/../libexec"; |
| 547 | getProgramPaths().push_back(Path); |
| 548 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | getProgramPaths().push_back(getHost().getDriver().Dir); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 552 | Generic_GCC::~Generic_GCC() { |
| 553 | // Free tool implementations. |
| 554 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 555 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 556 | delete it->second; |
| 557 | } |
| 558 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 560 | const JobAction &JA) const { |
| 561 | Action::ActionClass Key; |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 562 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 563 | Key = Action::AnalyzeJobClass; |
| 564 | else |
| 565 | Key = JA.getKind(); |
| 566 | |
| 567 | Tool *&T = Tools[Key]; |
| 568 | if (!T) { |
| 569 | switch (Key) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 570 | case Action::InputClass: |
| 571 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 572 | assert(0 && "Invalid tool kind."); |
| 573 | case Action::PreprocessJobClass: |
| 574 | T = new tools::gcc::Preprocess(*this); break; |
| 575 | case Action::PrecompileJobClass: |
| 576 | T = new tools::gcc::Precompile(*this); break; |
| 577 | case Action::AnalyzeJobClass: |
| 578 | T = new tools::Clang(*this); break; |
| 579 | case Action::CompileJobClass: |
| 580 | T = new tools::gcc::Compile(*this); break; |
| 581 | case Action::AssembleJobClass: |
| 582 | T = new tools::gcc::Assemble(*this); break; |
| 583 | case Action::LinkJobClass: |
| 584 | T = new tools::gcc::Link(*this); break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 586 | // This is a bit ungeneric, but the only platform using a driver |
| 587 | // driver is Darwin. |
| 588 | case Action::LipoJobClass: |
| 589 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
| 593 | return *T; |
| 594 | } |
| 595 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 596 | bool Generic_GCC::IsMathErrnoDefault() const { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 597 | return true; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 601 | // FIXME: Gross; we should probably have some separate target |
| 602 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 603 | return getArchName() == "x86_64"; |
| 604 | } |
| 605 | |
| 606 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 607 | return "static"; |
| 608 | } |
| 609 | |
| 610 | const char *Generic_GCC::GetForcedPicModel() const { |
| 611 | return 0; |
| 612 | } |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 613 | |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 614 | DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args, |
| 615 | const char *BoundArch) const { |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 616 | return new DerivedArgList(Args, true); |
| 617 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 618 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 619 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 620 | |
| 621 | OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) |
| 622 | : Generic_GCC(Host, Triple) { |
| 623 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); |
| 624 | getFilePaths().push_back("/usr/lib"); |
| 625 | } |
| 626 | |
| 627 | Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 628 | Action::ActionClass Key; |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 629 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 630 | Key = Action::AnalyzeJobClass; |
| 631 | else |
| 632 | Key = JA.getKind(); |
| 633 | |
| 634 | Tool *&T = Tools[Key]; |
| 635 | if (!T) { |
| 636 | switch (Key) { |
| 637 | case Action::AssembleJobClass: |
| 638 | T = new tools::openbsd::Assemble(*this); break; |
| 639 | case Action::LinkJobClass: |
| 640 | T = new tools::openbsd::Link(*this); break; |
| 641 | default: |
| 642 | T = &Generic_GCC::SelectTool(C, JA); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | return *T; |
| 647 | } |
| 648 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 649 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 650 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 651 | FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32) |
| 652 | : Generic_GCC(Host, Triple) { |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 653 | if (Lib32) { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 654 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 655 | getFilePaths().push_back("/usr/lib32"); |
| 656 | } else { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 657 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 658 | getFilePaths().push_back("/usr/lib"); |
| 659 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 663 | Action::ActionClass Key; |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 664 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 665 | Key = Action::AnalyzeJobClass; |
| 666 | else |
| 667 | Key = JA.getKind(); |
| 668 | |
| 669 | Tool *&T = Tools[Key]; |
| 670 | if (!T) { |
| 671 | switch (Key) { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 672 | case Action::AssembleJobClass: |
| 673 | T = new tools::freebsd::Assemble(*this); break; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 674 | case Action::LinkJobClass: |
| 675 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 676 | default: |
| 677 | T = &Generic_GCC::SelectTool(C, JA); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | return *T; |
| 682 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 683 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 684 | /// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. |
| 685 | |
| 686 | AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) |
| 687 | : Generic_GCC(Host, Triple) { |
| 688 | |
| 689 | // Path mangling to find libexec |
| 690 | std::string Path(getHost().getDriver().Dir); |
| 691 | |
| 692 | Path += "/../libexec"; |
| 693 | getProgramPaths().push_back(Path); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | getProgramPaths().push_back(getHost().getDriver().Dir); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 695 | |
| 696 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); |
| 697 | getFilePaths().push_back("/usr/lib"); |
| 698 | getFilePaths().push_back("/usr/sfw/lib"); |
| 699 | getFilePaths().push_back("/opt/gcc4/lib"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 700 | 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] | 701 | |
| 702 | } |
| 703 | |
| 704 | Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 705 | Action::ActionClass Key; |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 706 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 707 | Key = Action::AnalyzeJobClass; |
| 708 | else |
| 709 | Key = JA.getKind(); |
| 710 | |
| 711 | Tool *&T = Tools[Key]; |
| 712 | if (!T) { |
| 713 | switch (Key) { |
| 714 | case Action::AssembleJobClass: |
| 715 | T = new tools::auroraux::Assemble(*this); break; |
| 716 | case Action::LinkJobClass: |
| 717 | T = new tools::auroraux::Link(*this); break; |
| 718 | default: |
| 719 | T = &Generic_GCC::SelectTool(C, JA); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | return *T; |
| 724 | } |
| 725 | |
| 726 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 727 | /// Linux toolchain (very bare-bones at the moment). |
| 728 | |
| 729 | Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple) |
| 730 | : Generic_GCC(Host, Triple) { |
| 731 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/"); |
| 732 | getFilePaths().push_back("/lib/"); |
| 733 | getFilePaths().push_back("/usr/lib/"); |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 734 | |
| 735 | // Depending on the Linux distribution, any combination of lib{,32,64} is |
| 736 | // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems, |
| 737 | // openSUSE uses lib and lib64 for the same purpose. |
| 738 | getFilePaths().push_back("/lib32/"); |
| 739 | getFilePaths().push_back("/usr/lib32/"); |
| 740 | getFilePaths().push_back("/lib64/"); |
| 741 | getFilePaths().push_back("/usr/lib64/"); |
| 742 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 743 | // FIXME: Figure out some way to get gcc's libdir |
| 744 | // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need |
| 745 | // crtbegin.o/crtend.o/etc., and want static versions of various |
| 746 | // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably |
| 747 | // get away with using shared versions in /usr/lib, though. |
| 748 | // We could fall back to the approach we used for includes (a massive |
| 749 | // list), but that's messy at best. |
| 750 | } |
| 751 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 752 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 753 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 754 | DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) |
| 755 | : Generic_GCC(Host, Triple) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 756 | |
| 757 | // Path mangling to find libexec |
| 758 | std::string Path(getHost().getDriver().Dir); |
| 759 | |
| 760 | Path += "/../libexec"; |
| 761 | getProgramPaths().push_back(Path); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | getProgramPaths().push_back(getHost().getDriver().Dir); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 763 | |
| 764 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); |
| 765 | getFilePaths().push_back("/usr/lib"); |
| 766 | getFilePaths().push_back("/usr/lib/gcc41"); |
| 767 | } |
| 768 | |
| 769 | Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 770 | Action::ActionClass Key; |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 771 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 772 | Key = Action::AnalyzeJobClass; |
| 773 | else |
| 774 | Key = JA.getKind(); |
| 775 | |
| 776 | Tool *&T = Tools[Key]; |
| 777 | if (!T) { |
| 778 | switch (Key) { |
| 779 | case Action::AssembleJobClass: |
| 780 | T = new tools::dragonfly::Assemble(*this); break; |
| 781 | case Action::LinkJobClass: |
| 782 | T = new tools::dragonfly::Link(*this); break; |
| 783 | default: |
| 784 | T = &Generic_GCC::SelectTool(C, JA); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | return *T; |
| 789 | } |