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