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