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