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 | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 21 | #include "llvm/System/Path.h" |
| 22 | |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 23 | #include <cstdlib> // ::getenv |
| 24 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 25 | using namespace clang::driver; |
| 26 | using namespace clang::driver::toolchains; |
| 27 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 28 | /// Darwin_X86 - Darwin tool chain for i386 and x86_64. |
| 29 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 30 | Darwin_X86::Darwin_X86(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 31 | const unsigned (&_DarwinVersion)[3], |
| 32 | const unsigned (&_GCCVersion)[3]) |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 33 | : ToolChain(Host, Triple) { |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 34 | DarwinVersion[0] = _DarwinVersion[0]; |
| 35 | DarwinVersion[1] = _DarwinVersion[1]; |
| 36 | DarwinVersion[2] = _DarwinVersion[2]; |
| 37 | GCCVersion[0] = _GCCVersion[0]; |
| 38 | GCCVersion[1] = _GCCVersion[1]; |
| 39 | GCCVersion[2] = _GCCVersion[2]; |
| 40 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 41 | llvm::raw_string_ostream(MacosxVersionMin) |
| 42 | << "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1]; |
| 43 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 44 | ToolChainDir = "i686-apple-darwin"; |
| 45 | ToolChainDir += llvm::utostr(DarwinVersion[0]); |
| 46 | ToolChainDir += "/"; |
| 47 | ToolChainDir += llvm::utostr(GCCVersion[0]); |
| 48 | ToolChainDir += '.'; |
| 49 | ToolChainDir += llvm::utostr(GCCVersion[1]); |
| 50 | ToolChainDir += '.'; |
| 51 | ToolChainDir += llvm::utostr(GCCVersion[2]); |
| 52 | |
| 53 | std::string Path; |
| 54 | if (getArchName() == "x86_64") { |
| 55 | Path = getHost().getDriver().Dir; |
| 56 | Path += "/../lib/gcc/"; |
| 57 | Path += getToolChainDir(); |
| 58 | Path += "/x86_64"; |
| 59 | getFilePaths().push_back(Path); |
| 60 | |
| 61 | Path = "/usr/lib/gcc/"; |
| 62 | Path += getToolChainDir(); |
| 63 | Path += "/x86_64"; |
| 64 | getFilePaths().push_back(Path); |
| 65 | } |
| 66 | |
| 67 | Path = getHost().getDriver().Dir; |
| 68 | Path += "/../lib/gcc/"; |
| 69 | Path += getToolChainDir(); |
| 70 | getFilePaths().push_back(Path); |
| 71 | |
| 72 | Path = "/usr/lib/gcc/"; |
| 73 | Path += getToolChainDir(); |
| 74 | getFilePaths().push_back(Path); |
| 75 | |
| 76 | Path = getHost().getDriver().Dir; |
| 77 | Path += "/../libexec/gcc/"; |
| 78 | Path += getToolChainDir(); |
| 79 | getProgramPaths().push_back(Path); |
| 80 | |
| 81 | Path = "/usr/libexec/gcc/"; |
| 82 | Path += getToolChainDir(); |
| 83 | getProgramPaths().push_back(Path); |
| 84 | |
Daniel Dunbar | 82fa7c5 | 2009-03-24 04:07:10 +0000 | [diff] [blame] | 85 | Path = getHost().getDriver().Dir; |
| 86 | Path += "/../libexec"; |
| 87 | getProgramPaths().push_back(Path); |
| 88 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 89 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 90 | } |
| 91 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 92 | Darwin_X86::~Darwin_X86() { |
| 93 | // Free tool implementations. |
| 94 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 95 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 96 | delete it->second; |
| 97 | } |
| 98 | |
| 99 | Tool &Darwin_X86::SelectTool(const Compilation &C, |
| 100 | const JobAction &JA) const { |
| 101 | Action::ActionClass Key; |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 102 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 103 | Key = Action::AnalyzeJobClass; |
| 104 | else |
| 105 | Key = JA.getKind(); |
| 106 | |
| 107 | Tool *&T = Tools[Key]; |
| 108 | if (!T) { |
| 109 | switch (Key) { |
| 110 | case Action::InputClass: |
| 111 | case Action::BindArchClass: |
| 112 | assert(0 && "Invalid tool kind."); |
| 113 | case Action::PreprocessJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 114 | T = new tools::darwin::Preprocess(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 115 | case Action::AnalyzeJobClass: |
| 116 | T = new tools::Clang(*this); break; |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 117 | case Action::PrecompileJobClass: |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 118 | case Action::CompileJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 119 | T = new tools::darwin::Compile(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 120 | case Action::AssembleJobClass: |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 121 | T = new tools::darwin::Assemble(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 122 | case Action::LinkJobClass: |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 123 | T = new tools::darwin::Link(*this, MacosxVersionMin.c_str()); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 124 | case Action::LipoJobClass: |
| 125 | T = new tools::darwin::Lipo(*this); break; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return *T; |
| 130 | } |
| 131 | |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 132 | DerivedArgList *Darwin_X86::TranslateArgs(InputArgList &Args) const { |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 133 | DerivedArgList *DAL = new DerivedArgList(Args, false); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 134 | const OptTable &Opts = getHost().getDriver().getOpts(); |
| 135 | |
| 136 | // FIXME: We really want to get out of the tool chain level argument |
| 137 | // translation business, as it makes the driver functionality much |
| 138 | // more opaque. For now, we follow gcc closely solely for the |
| 139 | // purpose of easily achieving feature parity & testability. Once we |
| 140 | // have something that works, we should reevaluate each translation |
| 141 | // and try to push it down into tool specific logic. |
| 142 | |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 143 | Arg *OSXVersion = |
| 144 | Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false); |
| 145 | Arg *iPhoneVersion = |
| 146 | Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false); |
| 147 | if (OSXVersion && iPhoneVersion) { |
| 148 | getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 149 | << OSXVersion->getAsString(Args) |
| 150 | << iPhoneVersion->getAsString(Args); |
| 151 | } else if (!OSXVersion && !iPhoneVersion) { |
| 152 | // Chose the default version based on the arch. |
| 153 | // |
| 154 | // FIXME: This will need to be fixed when we merge in arm support. |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 155 | |
| 156 | // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version |
| 157 | // from the host. |
| 158 | const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET"); |
| 159 | if (!Version) |
| 160 | Version = MacosxVersionMin.c_str(); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 161 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 162 | DAL->append(DAL->MakeJoinedArg(0, O, Version)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 163 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 164 | |
| 165 | for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 166 | Arg *A = *it; |
| 167 | |
| 168 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 169 | // FIXME: Canonicalize name. |
| 170 | if (getArchName() != A->getValue(Args, 0)) |
| 171 | continue; |
| 172 | |
| 173 | // FIXME: The arg is leaked here, and we should have a nicer |
| 174 | // interface for this. |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 175 | unsigned Prev, Index = Prev = A->getIndex() + 1; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 176 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 177 | |
| 178 | // If the argument parsing failed or more than one argument was |
| 179 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 180 | // extra arguments. Emit an error and ignore. |
| 181 | // |
| 182 | // We also want to disallow any options which would alter the |
| 183 | // driver behavior; that isn't going to work in our model. We |
| 184 | // use isDriverOption() as an approximation, although things |
| 185 | // like -O4 are going to slip through. |
| 186 | if (!XarchArg || Index > Prev + 1 || |
| 187 | XarchArg->getOption().isDriverOption()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 188 | getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 189 | << A->getAsString(Args); |
| 190 | continue; |
| 191 | } |
| 192 | |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 193 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 194 | A = XarchArg; |
| 195 | } |
| 196 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 197 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 198 | // gcc translates options twice, which means that self-expanding |
| 199 | // options add duplicates. |
| 200 | options::ID id = A->getOption().getId(); |
| 201 | switch (id) { |
| 202 | default: |
| 203 | DAL->append(A); |
| 204 | break; |
| 205 | |
| 206 | case options::OPT_mkernel: |
| 207 | case options::OPT_fapple_kext: |
| 208 | DAL->append(A); |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 209 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
| 210 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 211 | break; |
| 212 | |
| 213 | case options::OPT_dependency_file: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 214 | DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF), |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 215 | A->getValue(Args))); |
| 216 | break; |
| 217 | |
| 218 | case options::OPT_gfull: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 219 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); |
| 220 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 221 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols))); |
| 222 | break; |
| 223 | |
| 224 | case options::OPT_gused: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 225 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); |
| 226 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 227 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols))); |
| 228 | break; |
| 229 | |
| 230 | case options::OPT_fterminated_vtables: |
| 231 | case options::OPT_findirect_virtual_calls: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 232 | DAL->append(DAL->MakeFlagArg(A, |
| 233 | Opts.getOption(options::OPT_fapple_kext))); |
| 234 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 235 | break; |
| 236 | |
| 237 | case options::OPT_shared: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 238 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 239 | break; |
| 240 | |
| 241 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 242 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 243 | Opts.getOption(options::OPT_mconstant_cfstrings))); |
| 244 | break; |
| 245 | |
| 246 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 247 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 248 | Opts.getOption(options::OPT_mno_constant_cfstrings))); |
| 249 | break; |
| 250 | |
| 251 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 252 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 253 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings))); |
| 254 | break; |
| 255 | |
| 256 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 257 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 258 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings))); |
| 259 | break; |
| 260 | |
| 261 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 262 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 263 | Opts.getOption(options::OPT_mpascal_strings))); |
| 264 | break; |
| 265 | |
| 266 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 267 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 268 | Opts.getOption(options::OPT_mno_pascal_strings))); |
| 269 | break; |
| 270 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 273 | // FIXME: Actually, gcc always adds this, but it is filtered for |
| 274 | // duplicates somewhere. This also changes the order of things, so |
| 275 | // look it up. |
| 276 | if (getArchName() == "x86_64") |
| 277 | if (!Args.hasArg(options::OPT_m64, false)) |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 278 | DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 279 | |
| 280 | if (!Args.hasArg(options::OPT_mtune_EQ, false)) |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 281 | DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 282 | "core2")); |
| 283 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 284 | return DAL; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | bool Darwin_X86::IsMathErrnoDefault() const { |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | bool Darwin_X86::IsUnwindTablesDefault() const { |
| 292 | // FIXME: Gross; we should probably have some separate target |
| 293 | // definition, possibly even reusing the one in clang. |
| 294 | return getArchName() == "x86_64"; |
| 295 | } |
| 296 | |
| 297 | const char *Darwin_X86::GetDefaultRelocationModel() const { |
| 298 | return "pic"; |
| 299 | } |
| 300 | |
| 301 | const char *Darwin_X86::GetForcedPicModel() const { |
| 302 | if (getArchName() == "x86_64") |
| 303 | return "pic"; |
| 304 | return 0; |
| 305 | } |
| 306 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 307 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 308 | /// all subcommands; this relies on gcc translating the majority of |
| 309 | /// command line options. |
| 310 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 311 | Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
| 312 | : ToolChain(Host, Triple) |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 313 | { |
Daniel Dunbar | 82fa7c5 | 2009-03-24 04:07:10 +0000 | [diff] [blame] | 314 | std::string Path(getHost().getDriver().Dir); |
| 315 | Path += "/../libexec"; |
| 316 | getProgramPaths().push_back(Path); |
| 317 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 318 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 319 | } |
| 320 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 321 | Generic_GCC::~Generic_GCC() { |
| 322 | // Free tool implementations. |
| 323 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 324 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 325 | delete it->second; |
| 326 | } |
| 327 | |
| 328 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
| 329 | const JobAction &JA) const { |
| 330 | Action::ActionClass Key; |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 331 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 332 | Key = Action::AnalyzeJobClass; |
| 333 | else |
| 334 | Key = JA.getKind(); |
| 335 | |
| 336 | Tool *&T = Tools[Key]; |
| 337 | if (!T) { |
| 338 | switch (Key) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 339 | case Action::InputClass: |
| 340 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 341 | assert(0 && "Invalid tool kind."); |
| 342 | case Action::PreprocessJobClass: |
| 343 | T = new tools::gcc::Preprocess(*this); break; |
| 344 | case Action::PrecompileJobClass: |
| 345 | T = new tools::gcc::Precompile(*this); break; |
| 346 | case Action::AnalyzeJobClass: |
| 347 | T = new tools::Clang(*this); break; |
| 348 | case Action::CompileJobClass: |
| 349 | T = new tools::gcc::Compile(*this); break; |
| 350 | case Action::AssembleJobClass: |
| 351 | T = new tools::gcc::Assemble(*this); break; |
| 352 | case Action::LinkJobClass: |
| 353 | T = new tools::gcc::Link(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 354 | |
| 355 | // This is a bit ungeneric, but the only platform using a driver |
| 356 | // driver is Darwin. |
| 357 | case Action::LipoJobClass: |
| 358 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | return *T; |
| 363 | } |
| 364 | |
| 365 | bool Generic_GCC::IsMathErrnoDefault() const { |
| 366 | return true; |
| 367 | } |
| 368 | |
| 369 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 370 | // FIXME: Gross; we should probably have some separate target |
| 371 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 372 | return getArchName() == "x86_64"; |
| 373 | } |
| 374 | |
| 375 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 376 | return "static"; |
| 377 | } |
| 378 | |
| 379 | const char *Generic_GCC::GetForcedPicModel() const { |
| 380 | return 0; |
| 381 | } |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 382 | |
| 383 | DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args) const { |
| 384 | return new DerivedArgList(Args, true); |
| 385 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 386 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 387 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 388 | |
| 389 | OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) |
| 390 | : Generic_GCC(Host, Triple) { |
| 391 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); |
| 392 | getFilePaths().push_back("/usr/lib"); |
| 393 | } |
| 394 | |
| 395 | Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 396 | Action::ActionClass Key; |
| 397 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
| 398 | Key = Action::AnalyzeJobClass; |
| 399 | else |
| 400 | Key = JA.getKind(); |
| 401 | |
| 402 | Tool *&T = Tools[Key]; |
| 403 | if (!T) { |
| 404 | switch (Key) { |
| 405 | case Action::AssembleJobClass: |
| 406 | T = new tools::openbsd::Assemble(*this); break; |
| 407 | case Action::LinkJobClass: |
| 408 | T = new tools::openbsd::Link(*this); break; |
| 409 | default: |
| 410 | T = &Generic_GCC::SelectTool(C, JA); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | return *T; |
| 415 | } |
| 416 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 417 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 418 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 419 | FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32) |
| 420 | : Generic_GCC(Host, Triple) { |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 421 | if (Lib32) { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 422 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 423 | getFilePaths().push_back("/usr/lib32"); |
| 424 | } else { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 425 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 426 | getFilePaths().push_back("/usr/lib"); |
| 427 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 431 | Action::ActionClass Key; |
| 432 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
| 433 | Key = Action::AnalyzeJobClass; |
| 434 | else |
| 435 | Key = JA.getKind(); |
| 436 | |
| 437 | Tool *&T = Tools[Key]; |
| 438 | if (!T) { |
| 439 | switch (Key) { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 440 | case Action::AssembleJobClass: |
| 441 | T = new tools::freebsd::Assemble(*this); break; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 442 | case Action::LinkJobClass: |
| 443 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 444 | default: |
| 445 | T = &Generic_GCC::SelectTool(C, JA); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return *T; |
| 450 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 451 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 452 | /// Linux toolchain (very bare-bones at the moment). |
| 453 | |
| 454 | Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple) |
| 455 | : Generic_GCC(Host, Triple) { |
| 456 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/"); |
| 457 | getFilePaths().push_back("/lib/"); |
| 458 | getFilePaths().push_back("/usr/lib/"); |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 459 | |
| 460 | // Depending on the Linux distribution, any combination of lib{,32,64} is |
| 461 | // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems, |
| 462 | // openSUSE uses lib and lib64 for the same purpose. |
| 463 | getFilePaths().push_back("/lib32/"); |
| 464 | getFilePaths().push_back("/usr/lib32/"); |
| 465 | getFilePaths().push_back("/lib64/"); |
| 466 | getFilePaths().push_back("/usr/lib64/"); |
| 467 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 468 | // FIXME: Figure out some way to get gcc's libdir |
| 469 | // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need |
| 470 | // crtbegin.o/crtend.o/etc., and want static versions of various |
| 471 | // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably |
| 472 | // get away with using shared versions in /usr/lib, though. |
| 473 | // We could fall back to the approach we used for includes (a massive |
| 474 | // list), but that's messy at best. |
| 475 | } |
| 476 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 477 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 478 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 479 | DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) |
| 480 | : Generic_GCC(Host, Triple) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 481 | |
| 482 | // Path mangling to find libexec |
| 483 | std::string Path(getHost().getDriver().Dir); |
| 484 | |
| 485 | Path += "/../libexec"; |
| 486 | getProgramPaths().push_back(Path); |
| 487 | getProgramPaths().push_back(getHost().getDriver().Dir); |
| 488 | |
| 489 | getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); |
| 490 | getFilePaths().push_back("/usr/lib"); |
| 491 | getFilePaths().push_back("/usr/lib/gcc41"); |
| 492 | } |
| 493 | |
| 494 | Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 495 | Action::ActionClass Key; |
| 496 | if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) |
| 497 | Key = Action::AnalyzeJobClass; |
| 498 | else |
| 499 | Key = JA.getKind(); |
| 500 | |
| 501 | Tool *&T = Tools[Key]; |
| 502 | if (!T) { |
| 503 | switch (Key) { |
| 504 | case Action::AssembleJobClass: |
| 505 | T = new tools::dragonfly::Assemble(*this); break; |
| 506 | case Action::LinkJobClass: |
| 507 | T = new tools::dragonfly::Link(*this); break; |
| 508 | default: |
| 509 | T = &Generic_GCC::SelectTool(C, JA); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | return *T; |
| 514 | } |