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