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