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 | 27e738d | 2009-11-19 00:15:11 +0000 | [diff] [blame] | 17 | #include "clang/Driver/OptTable.h" |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 18 | #include "clang/Driver/Option.h" |
Daniel Dunbar | 265e9ef | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Options.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 20 | |
| 21 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 23 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 24 | #include "llvm/System/Path.h" |
| 25 | |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 26 | #include <cstdlib> // ::getenv |
| 27 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 28 | using namespace clang::driver; |
| 29 | using namespace clang::driver::toolchains; |
| 30 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 31 | /// Darwin - Darwin tool chain for i386 and x86_64. |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 32 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 33 | Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 34 | const unsigned (&_DarwinVersion)[3]) |
| 35 | : ToolChain(Host, Triple), TargetInitialized(false) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 36 | { |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 37 | llvm::raw_string_ostream(MacosxVersionMin) |
Daniel Dunbar | 5435fc9 | 2010-01-27 00:57:11 +0000 | [diff] [blame] | 38 | << "10." << std::max(0, (int)_DarwinVersion[0] - 4) << '.' |
| 39 | << _DarwinVersion[1]; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 42 | // FIXME: Can we tablegen this? |
| 43 | static const char *GetArmArchForMArch(llvm::StringRef Value) { |
| 44 | if (Value == "armv6k") |
| 45 | return "armv6"; |
| 46 | |
| 47 | if (Value == "armv5tej") |
| 48 | return "armv5"; |
| 49 | |
| 50 | if (Value == "xscale") |
| 51 | return "xscale"; |
| 52 | |
| 53 | if (Value == "armv4t") |
| 54 | return "armv4t"; |
| 55 | |
| 56 | if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" || |
| 57 | Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" || |
| 58 | Value == "armv7m") |
| 59 | return "armv7"; |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | // FIXME: Can we tablegen this? |
| 65 | static const char *GetArmArchForMCpu(llvm::StringRef Value) { |
| 66 | if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" || |
| 67 | Value == "arm946e-s" || Value == "arm966e-s" || |
| 68 | Value == "arm968e-s" || Value == "arm10e" || |
| 69 | Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" || |
| 70 | Value == "arm1026ej-s") |
| 71 | return "armv5"; |
| 72 | |
| 73 | if (Value == "xscale") |
| 74 | return "xscale"; |
| 75 | |
| 76 | if (Value == "arm1136j-s" || Value == "arm1136jf-s" || |
| 77 | Value == "arm1176jz-s" || Value == "arm1176jzf-s") |
| 78 | return "armv6"; |
| 79 | |
| 80 | if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3") |
| 81 | return "armv7"; |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const { |
| 87 | switch (getTriple().getArch()) { |
| 88 | default: |
| 89 | return getArchName(); |
| 90 | |
| 91 | case llvm::Triple::arm: { |
| 92 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
| 93 | if (const char *Arch = GetArmArchForMArch(A->getValue(Args))) |
| 94 | return Arch; |
| 95 | |
| 96 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
| 97 | if (const char *Arch = GetArmArchForMCpu(A->getValue(Args))) |
| 98 | return Arch; |
| 99 | |
| 100 | return "arm"; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 105 | DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, |
| 106 | const unsigned (&DarwinVersion)[3], |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 107 | const unsigned (&_GCCVersion)[3]) |
| 108 | : Darwin(Host, Triple, DarwinVersion) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 109 | { |
| 110 | GCCVersion[0] = _GCCVersion[0]; |
| 111 | GCCVersion[1] = _GCCVersion[1]; |
| 112 | GCCVersion[2] = _GCCVersion[2]; |
| 113 | |
| 114 | // Set up the tool chain paths to match gcc. |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 115 | ToolChainDir = "i686-apple-darwin"; |
Ted Kremenek | 55bac53 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 116 | ToolChainDir += llvm::utostr(DarwinVersion[0]); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 117 | ToolChainDir += "/"; |
| 118 | ToolChainDir += llvm::utostr(GCCVersion[0]); |
| 119 | ToolChainDir += '.'; |
| 120 | ToolChainDir += llvm::utostr(GCCVersion[1]); |
| 121 | ToolChainDir += '.'; |
| 122 | ToolChainDir += llvm::utostr(GCCVersion[2]); |
| 123 | |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 124 | // Try the next major version if that tool chain dir is invalid. |
Daniel Dunbar | 080fb19 | 2009-10-22 00:12:00 +0000 | [diff] [blame] | 125 | std::string Tmp = "/usr/lib/gcc/" + ToolChainDir; |
| 126 | if (!llvm::sys::Path(Tmp).exists()) { |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 127 | std::string Next = "i686-apple-darwin"; |
| 128 | Next += llvm::utostr(DarwinVersion[0] + 1); |
| 129 | Next += "/"; |
| 130 | Next += llvm::utostr(GCCVersion[0]); |
| 131 | Next += '.'; |
| 132 | Next += llvm::utostr(GCCVersion[1]); |
| 133 | Next += '.'; |
| 134 | Next += llvm::utostr(GCCVersion[2]); |
| 135 | |
| 136 | // Use that if it exists, otherwise hope the user isn't linking. |
| 137 | // |
| 138 | // FIXME: Drop dependency on gcc's tool chain. |
Daniel Dunbar | 080fb19 | 2009-10-22 00:12:00 +0000 | [diff] [blame] | 139 | Tmp = "/usr/lib/gcc/" + Next; |
| 140 | if (llvm::sys::Path(Tmp).exists()) |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 141 | ToolChainDir = Next; |
| 142 | } |
| 143 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 144 | std::string Path; |
| 145 | if (getArchName() == "x86_64") { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 146 | Path = getDriver().Dir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 147 | Path += "/../lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 148 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 149 | Path += "/x86_64"; |
| 150 | getFilePaths().push_back(Path); |
| 151 | |
| 152 | Path = "/usr/lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 153 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 154 | Path += "/x86_64"; |
| 155 | getFilePaths().push_back(Path); |
| 156 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 158 | Path = getDriver().Dir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 159 | Path += "/../lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 160 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 161 | getFilePaths().push_back(Path); |
| 162 | |
| 163 | Path = "/usr/lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 164 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 165 | getFilePaths().push_back(Path); |
| 166 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 167 | Path = getDriver().Dir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 168 | Path += "/../libexec/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 169 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 170 | getProgramPaths().push_back(Path); |
| 171 | |
| 172 | Path = "/usr/libexec/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 173 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 174 | getProgramPaths().push_back(Path); |
| 175 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 176 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 179 | Darwin::~Darwin() { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 180 | // Free tool implementations. |
| 181 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 182 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 183 | delete it->second; |
| 184 | } |
| 185 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 186 | Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 187 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 188 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 189 | Key = Action::AnalyzeJobClass; |
| 190 | else |
| 191 | Key = JA.getKind(); |
| 192 | |
| 193 | Tool *&T = Tools[Key]; |
| 194 | if (!T) { |
| 195 | switch (Key) { |
| 196 | case Action::InputClass: |
| 197 | case Action::BindArchClass: |
| 198 | assert(0 && "Invalid tool kind."); |
| 199 | case Action::PreprocessJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 200 | T = new tools::darwin::Preprocess(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 201 | case Action::AnalyzeJobClass: |
| 202 | T = new tools::Clang(*this); break; |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 203 | case Action::PrecompileJobClass: |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 204 | case Action::CompileJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 205 | T = new tools::darwin::Compile(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 206 | case Action::AssembleJobClass: |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 207 | T = new tools::darwin::Assemble(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 208 | case Action::LinkJobClass: |
Daniel Dunbar | 8f28962 | 2009-09-04 17:39:02 +0000 | [diff] [blame] | 209 | T = new tools::darwin::Link(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 210 | case Action::LipoJobClass: |
| 211 | T = new tools::darwin::Lipo(*this); break; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return *T; |
| 216 | } |
| 217 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 218 | void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args, |
| 219 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 220 | // FIXME: Derive these correctly. |
| 221 | if (getArchName() == "x86_64") { |
| 222 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 223 | "/x86_64")); |
| 224 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 225 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 226 | "/x86_64")); |
| 227 | } |
Daniel Dunbar | 8bc9c55 | 2010-04-10 01:24:22 +0000 | [diff] [blame] | 228 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 229 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir)); |
Daniel Dunbar | 8bc9c55 | 2010-04-10 01:24:22 +0000 | [diff] [blame] | 230 | CmdArgs.push_back(Args.MakeArgString("-L" + getDriver().Dir + "/../lib/gcc/" + |
| 231 | ToolChainDir)); |
| 232 | CmdArgs.push_back(Args.MakeArgString("-L" + getDriver().Dir + "/../lib/gcc")); |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 233 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); |
| 234 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 235 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); |
Daniel Dunbar | 8bc9c55 | 2010-04-10 01:24:22 +0000 | [diff] [blame] | 236 | CmdArgs.push_back(Args.MakeArgString("-L" + getDriver().Dir + "/../lib/" + |
| 237 | ToolChainDir)); |
| 238 | CmdArgs.push_back(Args.MakeArgString("-L" + getDriver().Dir + "/../lib")); |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 239 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 240 | "/../../../" + ToolChainDir)); |
| 241 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 242 | "/../../..")); |
| 243 | } |
| 244 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 245 | void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 246 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 247 | // Note that this routine is only used for targetting OS X. |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 248 | |
| 249 | // Derived from libgcc and lib specs but refactored. |
| 250 | if (Args.hasArg(options::OPT_static)) { |
| 251 | CmdArgs.push_back("-lgcc_static"); |
| 252 | } else { |
| 253 | if (Args.hasArg(options::OPT_static_libgcc)) { |
| 254 | CmdArgs.push_back("-lgcc_eh"); |
| 255 | } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
| 256 | // Derived from darwin_iphoneos_libgcc spec. |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 257 | if (isTargetIPhoneOS()) { |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 258 | CmdArgs.push_back("-lgcc_s.1"); |
| 259 | } else { |
| 260 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 261 | } |
| 262 | } else if (Args.hasArg(options::OPT_shared_libgcc) || |
Daniel Dunbar | 8a0d94d | 2010-01-10 00:46:10 +0000 | [diff] [blame] | 263 | Args.hasFlag(options::OPT_fexceptions, |
| 264 | options::OPT_fno_exceptions) || |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 265 | Args.hasArg(options::OPT_fgnu_runtime)) { |
| 266 | // FIXME: This is probably broken on 10.3? |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 267 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 268 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 269 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 270 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 271 | } else { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 272 | if (isMacosxVersionLT(10, 3, 9)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 273 | ; // Do nothing. |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 274 | else if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 275 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 276 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 277 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 278 | } |
| 279 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 280 | if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) { |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 281 | CmdArgs.push_back("-lgcc"); |
| 282 | CmdArgs.push_back("-lSystem"); |
| 283 | } else { |
| 284 | CmdArgs.push_back("-lSystem"); |
| 285 | CmdArgs.push_back("-lgcc"); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 290 | DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 291 | const unsigned (&DarwinVersion)[3]) |
| 292 | : Darwin(Host, Triple, DarwinVersion) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 293 | { |
| 294 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 295 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, |
| 299 | ArgStringList &CmdArgs) const { |
| 300 | // The Clang toolchain uses explicit paths for internal libraries. |
| 301 | } |
| 302 | |
| 303 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 304 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 305 | // Darwin doesn't support real static executables, don't link any runtime |
| 306 | // libraries with -static. |
| 307 | if (Args.hasArg(options::OPT_static)) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 308 | return; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 309 | |
| 310 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 311 | // cares. This is useful in situations where someone wants to statically link |
| 312 | // something like libstdc++, and needs its runtime support routines. |
| 313 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 314 | getDriver().Diag(clang::diag::err_drv_unsupported_opt) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 315 | << A->getAsString(Args); |
| 316 | return; |
| 317 | } |
| 318 | |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 319 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 320 | // target specific static runtime library. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 321 | CmdArgs.push_back("-lSystem"); |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 322 | |
| 323 | // Select the dynamic runtime library and the target specific static library. |
| 324 | const char *DarwinStaticLib = 0; |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 325 | if (isTargetIPhoneOS()) { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 326 | CmdArgs.push_back("-lgcc_s.1"); |
| 327 | |
| 328 | // We may need some static functions for armv6/thumb which are required to |
| 329 | // be in the same linkage unit as their caller. |
| 330 | if (getDarwinArchName(Args) == "armv6") |
| 331 | DarwinStaticLib = "libclang_rt.armv6.a"; |
| 332 | } else { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 333 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 334 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 335 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 336 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 337 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 338 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 339 | |
| 340 | // For OS X, we only need a static runtime library when targetting 10.4, to |
| 341 | // provide versions of the static functions which were omitted from |
| 342 | // 10.4.dylib. |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 343 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 344 | DarwinStaticLib = "libclang_rt.10.4.a"; |
| 345 | } |
| 346 | |
| 347 | /// Add the target specific static library, if needed. |
| 348 | if (DarwinStaticLib) { |
| 349 | llvm::sys::Path P(getDriver().ResourceDir); |
| 350 | P.appendComponent("lib"); |
| 351 | P.appendComponent("darwin"); |
| 352 | P.appendComponent(DarwinStaticLib); |
| 353 | |
| 354 | // For now, allow missing resource libraries to support developers who may |
| 355 | // not have compiler-rt checked out or integrated into their build. |
| 356 | if (!P.exists()) |
| 357 | getDriver().Diag(clang::diag::warn_drv_missing_resource_library) |
| 358 | << P.str(); |
| 359 | else |
| 360 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 361 | } |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 364 | DerivedArgList *Darwin::TranslateArgs(InputArgList &Args, |
| 365 | const char *BoundArch) const { |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 366 | DerivedArgList *DAL = new DerivedArgList(Args, false); |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 367 | const OptTable &Opts = getDriver().getOpts(); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 368 | |
| 369 | // FIXME: We really want to get out of the tool chain level argument |
| 370 | // translation business, as it makes the driver functionality much |
| 371 | // more opaque. For now, we follow gcc closely solely for the |
| 372 | // purpose of easily achieving feature parity & testability. Once we |
| 373 | // have something that works, we should reevaluate each translation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | // and try to push it down into tool specific logic. |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 375 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 376 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
| 377 | Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 378 | if (OSXVersion && iPhoneVersion) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 379 | getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 380 | << OSXVersion->getAsString(Args) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | << iPhoneVersion->getAsString(Args); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 382 | iPhoneVersion = 0; |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 383 | } else if (!OSXVersion && !iPhoneVersion) { |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 384 | // If neither OS X nor iPhoneOS targets were specified, check for |
| 385 | // environment defines. |
| 386 | const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET"); |
| 387 | const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET"); |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 388 | |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 389 | // Ignore empty strings. |
| 390 | if (OSXTarget && OSXTarget[0] == '\0') |
| 391 | OSXTarget = 0; |
| 392 | if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0') |
| 393 | iPhoneOSTarget = 0; |
| 394 | |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 395 | // Diagnose conflicting deployment targets, and choose default platform |
| 396 | // based on the tool chain. |
| 397 | // |
| 398 | // FIXME: Don't hardcode default here. |
| 399 | if (OSXTarget && iPhoneOSTarget) { |
| 400 | // FIXME: We should see if we can get away with warning or erroring on |
| 401 | // this. Perhaps put under -pedantic? |
| 402 | if (getTriple().getArch() == llvm::Triple::arm || |
| 403 | getTriple().getArch() == llvm::Triple::thumb) |
Daniel Dunbar | 84d1e6e | 2010-03-20 08:47:42 +0000 | [diff] [blame] | 404 | OSXTarget = 0; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 405 | else |
Daniel Dunbar | 84d1e6e | 2010-03-20 08:47:42 +0000 | [diff] [blame] | 406 | iPhoneOSTarget = 0; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 407 | } |
Daniel Dunbar | 1a3c1d9 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 408 | |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 409 | if (OSXTarget) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 410 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 411 | OSXVersion = DAL->MakeJoinedArg(0, O, OSXTarget); |
| 412 | DAL->append(OSXVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 413 | } else if (iPhoneOSTarget) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 414 | const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 415 | iPhoneVersion = DAL->MakeJoinedArg(0, O, iPhoneOSTarget); |
| 416 | DAL->append(iPhoneVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 417 | } else { |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 418 | // Otherwise, choose a default platform based on the tool chain. |
| 419 | // |
| 420 | // FIXME: Don't hardcode default here. |
| 421 | if (getTriple().getArch() == llvm::Triple::arm || |
| 422 | getTriple().getArch() == llvm::Triple::thumb) { |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 423 | const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 424 | iPhoneVersion = DAL->MakeJoinedArg(0, O, "3.0"); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 425 | DAL->append(iPhoneVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 426 | } else { |
| 427 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 428 | OSXVersion = DAL->MakeJoinedArg(0, O, MacosxVersionMin); |
| 429 | DAL->append(OSXVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 430 | } |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 431 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 432 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 434 | // Set the tool chain target information. |
| 435 | unsigned Major, Minor, Micro; |
| 436 | bool HadExtra; |
| 437 | if (OSXVersion) { |
| 438 | assert(!iPhoneVersion && "Unknown target platform!"); |
| 439 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor, |
| 440 | Micro, HadExtra) || HadExtra || |
| 441 | Major != 10 || Minor >= 10 || Micro >= 10) |
| 442 | getDriver().Diag(clang::diag::err_drv_invalid_version_number) |
| 443 | << OSXVersion->getAsString(Args); |
| 444 | } else { |
| 445 | assert(iPhoneVersion && "Unknown target platform!"); |
| 446 | if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor, |
| 447 | Micro, HadExtra) || HadExtra || |
| 448 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 449 | getDriver().Diag(clang::diag::err_drv_invalid_version_number) |
| 450 | << iPhoneVersion->getAsString(Args); |
| 451 | } |
| 452 | setTarget(iPhoneVersion, Major, Minor, Micro); |
| 453 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 454 | for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 455 | Arg *A = *it; |
| 456 | |
| 457 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 458 | // FIXME: Canonicalize name. |
| 459 | if (getArchName() != A->getValue(Args, 0)) |
| 460 | continue; |
| 461 | |
| 462 | // FIXME: The arg is leaked here, and we should have a nicer |
| 463 | // interface for this. |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 464 | unsigned Prev, Index = Prev = A->getIndex() + 1; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 465 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 467 | // If the argument parsing failed or more than one argument was |
| 468 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 469 | // extra arguments. Emit an error and ignore. |
| 470 | // |
| 471 | // We also want to disallow any options which would alter the |
| 472 | // driver behavior; that isn't going to work in our model. We |
| 473 | // use isDriverOption() as an approximation, although things |
| 474 | // like -O4 are going to slip through. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | if (!XarchArg || Index > Prev + 1 || |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 476 | XarchArg->getOption().isDriverOption()) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 477 | getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 478 | << A->getAsString(Args); |
| 479 | continue; |
| 480 | } |
| 481 | |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 482 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 483 | A = XarchArg; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 484 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 485 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 486 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 487 | // gcc translates options twice, which means that self-expanding |
| 488 | // options add duplicates. |
Daniel Dunbar | 9e1f982 | 2009-11-19 04:14:53 +0000 | [diff] [blame] | 489 | switch ((options::ID) A->getOption().getID()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 490 | default: |
| 491 | DAL->append(A); |
| 492 | break; |
| 493 | |
| 494 | case options::OPT_mkernel: |
| 495 | case options::OPT_fapple_kext: |
| 496 | DAL->append(A); |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 497 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
| 498 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 499 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 501 | case options::OPT_dependency_file: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 502 | DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF), |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 503 | A->getValue(Args))); |
| 504 | break; |
| 505 | |
| 506 | case options::OPT_gfull: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 507 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); |
| 508 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 509 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols))); |
| 510 | break; |
| 511 | |
| 512 | case options::OPT_gused: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 513 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); |
| 514 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 515 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols))); |
| 516 | break; |
| 517 | |
| 518 | case options::OPT_fterminated_vtables: |
| 519 | case options::OPT_findirect_virtual_calls: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 520 | DAL->append(DAL->MakeFlagArg(A, |
| 521 | Opts.getOption(options::OPT_fapple_kext))); |
| 522 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 523 | break; |
| 524 | |
| 525 | case options::OPT_shared: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 526 | DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 527 | break; |
| 528 | |
| 529 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 530 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 531 | Opts.getOption(options::OPT_mconstant_cfstrings))); |
| 532 | break; |
| 533 | |
| 534 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 535 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 536 | Opts.getOption(options::OPT_mno_constant_cfstrings))); |
| 537 | break; |
| 538 | |
| 539 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 540 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 541 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings))); |
| 542 | break; |
| 543 | |
| 544 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 545 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 546 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings))); |
| 547 | break; |
| 548 | |
| 549 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 550 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 551 | Opts.getOption(options::OPT_mpascal_strings))); |
| 552 | break; |
| 553 | |
| 554 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 555 | DAL->append(DAL->MakeFlagArg(A, |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 556 | Opts.getOption(options::OPT_mno_pascal_strings))); |
| 557 | break; |
| 558 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 561 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 562 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 563 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 564 | DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), |
| 565 | "core2")); |
| 566 | |
| 567 | // Add the arch options based on the particular spelling of -arch, to match |
| 568 | // how the driver driver works. |
| 569 | if (BoundArch) { |
| 570 | llvm::StringRef Name = BoundArch; |
| 571 | const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 572 | const Option *MArch = Opts.getOption(options::OPT_march_EQ); |
| 573 | |
| 574 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 575 | // which defines the list of which architectures we accept. |
| 576 | if (Name == "ppc") |
| 577 | ; |
| 578 | else if (Name == "ppc601") |
| 579 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "601")); |
| 580 | else if (Name == "ppc603") |
| 581 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "603")); |
| 582 | else if (Name == "ppc604") |
| 583 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "604")); |
| 584 | else if (Name == "ppc604e") |
| 585 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e")); |
| 586 | else if (Name == "ppc750") |
| 587 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "750")); |
| 588 | else if (Name == "ppc7400") |
| 589 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400")); |
| 590 | else if (Name == "ppc7450") |
| 591 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450")); |
| 592 | else if (Name == "ppc970") |
| 593 | DAL->append(DAL->MakeJoinedArg(0, MCpu, "970")); |
| 594 | |
| 595 | else if (Name == "ppc64") |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 596 | DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64))); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 597 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 598 | else if (Name == "i386") |
| 599 | ; |
| 600 | else if (Name == "i486") |
| 601 | DAL->append(DAL->MakeJoinedArg(0, MArch, "i486")); |
| 602 | else if (Name == "i586") |
| 603 | DAL->append(DAL->MakeJoinedArg(0, MArch, "i586")); |
| 604 | else if (Name == "i686") |
| 605 | DAL->append(DAL->MakeJoinedArg(0, MArch, "i686")); |
| 606 | else if (Name == "pentium") |
| 607 | DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium")); |
| 608 | else if (Name == "pentium2") |
| 609 | DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2")); |
| 610 | else if (Name == "pentpro") |
| 611 | DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro")); |
| 612 | else if (Name == "pentIIm3") |
| 613 | DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2")); |
| 614 | |
| 615 | else if (Name == "x86_64") |
| 616 | DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64))); |
| 617 | |
| 618 | else if (Name == "arm") |
| 619 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t")); |
| 620 | else if (Name == "armv4t") |
| 621 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t")); |
| 622 | else if (Name == "armv5") |
| 623 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej")); |
| 624 | else if (Name == "xscale") |
| 625 | DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale")); |
| 626 | else if (Name == "armv6") |
| 627 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k")); |
| 628 | else if (Name == "armv7") |
| 629 | DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a")); |
| 630 | |
| 631 | else |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 632 | llvm_unreachable("invalid Darwin arch"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 633 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 634 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 635 | return DAL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 637 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 638 | bool Darwin::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 639 | // FIXME: Gross; we should probably have some separate target |
| 640 | // definition, possibly even reusing the one in clang. |
| 641 | return getArchName() == "x86_64"; |
| 642 | } |
| 643 | |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 644 | bool Darwin::UseDwarfDebugFlags() const { |
| 645 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 646 | return S[0] != '\0'; |
| 647 | return false; |
| 648 | } |
| 649 | |
Daniel Dunbar | b2987d1 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 650 | bool Darwin::UseSjLjExceptions() const { |
| 651 | // Darwin uses SjLj exceptions on ARM. |
| 652 | return (getTriple().getArch() == llvm::Triple::arm || |
| 653 | getTriple().getArch() == llvm::Triple::thumb); |
| 654 | } |
| 655 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 656 | const char *Darwin::GetDefaultRelocationModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 657 | return "pic"; |
| 658 | } |
| 659 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 660 | const char *Darwin::GetForcedPicModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 661 | if (getArchName() == "x86_64") |
| 662 | return "pic"; |
| 663 | return 0; |
| 664 | } |
| 665 | |
Daniel Dunbar | 43a9b32 | 2010-04-10 16:20:23 +0000 | [diff] [blame^] | 666 | bool Darwin::SupportsObjCGC() const { |
| 667 | // Garbage collection is supported everywhere except on iPhone OS. |
| 668 | return !isTargetIPhoneOS(); |
| 669 | } |
| 670 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 671 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 672 | /// all subcommands; this relies on gcc translating the majority of |
| 673 | /// command line options. |
| 674 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 675 | Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | : ToolChain(Host, Triple) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 677 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 680 | Generic_GCC::~Generic_GCC() { |
| 681 | // Free tool implementations. |
| 682 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 683 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 684 | delete it->second; |
| 685 | } |
| 686 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 688 | const JobAction &JA) const { |
| 689 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 690 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 691 | Key = Action::AnalyzeJobClass; |
| 692 | else |
| 693 | Key = JA.getKind(); |
| 694 | |
| 695 | Tool *&T = Tools[Key]; |
| 696 | if (!T) { |
| 697 | switch (Key) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 698 | case Action::InputClass: |
| 699 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 700 | assert(0 && "Invalid tool kind."); |
| 701 | case Action::PreprocessJobClass: |
| 702 | T = new tools::gcc::Preprocess(*this); break; |
| 703 | case Action::PrecompileJobClass: |
| 704 | T = new tools::gcc::Precompile(*this); break; |
| 705 | case Action::AnalyzeJobClass: |
| 706 | T = new tools::Clang(*this); break; |
| 707 | case Action::CompileJobClass: |
| 708 | T = new tools::gcc::Compile(*this); break; |
| 709 | case Action::AssembleJobClass: |
| 710 | T = new tools::gcc::Assemble(*this); break; |
| 711 | case Action::LinkJobClass: |
| 712 | T = new tools::gcc::Link(*this); break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 714 | // This is a bit ungeneric, but the only platform using a driver |
| 715 | // driver is Darwin. |
| 716 | case Action::LipoJobClass: |
| 717 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | return *T; |
| 722 | } |
| 723 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 724 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 725 | // FIXME: Gross; we should probably have some separate target |
| 726 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 727 | return getArchName() == "x86_64"; |
| 728 | } |
| 729 | |
| 730 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 731 | return "static"; |
| 732 | } |
| 733 | |
| 734 | const char *Generic_GCC::GetForcedPicModel() const { |
| 735 | return 0; |
| 736 | } |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 737 | |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 738 | DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args, |
| 739 | const char *BoundArch) const { |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 740 | return new DerivedArgList(Args, true); |
| 741 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 742 | |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 743 | |
| 744 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 745 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 746 | /// Currently does not support anything else but compilation. |
| 747 | |
| 748 | TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple) |
| 749 | : ToolChain(Host, Triple) { |
| 750 | // Path mangling to find libexec |
| 751 | std::string Path(getDriver().Dir); |
| 752 | |
| 753 | Path += "/../libexec"; |
| 754 | getProgramPaths().push_back(Path); |
| 755 | } |
| 756 | |
| 757 | TCEToolChain::~TCEToolChain() { |
| 758 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 759 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 760 | delete it->second; |
| 761 | } |
| 762 | |
| 763 | bool TCEToolChain::IsMathErrnoDefault() const { |
| 764 | return true; |
| 765 | } |
| 766 | |
| 767 | bool TCEToolChain::IsUnwindTablesDefault() const { |
| 768 | return false; |
| 769 | } |
| 770 | |
| 771 | const char *TCEToolChain::GetDefaultRelocationModel() const { |
| 772 | return "static"; |
| 773 | } |
| 774 | |
| 775 | const char *TCEToolChain::GetForcedPicModel() const { |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | Tool &TCEToolChain::SelectTool(const Compilation &C, |
| 780 | const JobAction &JA) const { |
| 781 | Action::ActionClass Key; |
| 782 | Key = Action::AnalyzeJobClass; |
| 783 | |
| 784 | Tool *&T = Tools[Key]; |
| 785 | if (!T) { |
| 786 | switch (Key) { |
| 787 | case Action::PreprocessJobClass: |
| 788 | T = new tools::gcc::Preprocess(*this); break; |
| 789 | case Action::AnalyzeJobClass: |
| 790 | T = new tools::Clang(*this); break; |
| 791 | default: |
| 792 | assert(false && "Unsupported action for TCE target."); |
| 793 | } |
| 794 | } |
| 795 | return *T; |
| 796 | } |
| 797 | |
| 798 | DerivedArgList *TCEToolChain::TranslateArgs(InputArgList &Args, |
| 799 | const char *BoundArch) const { |
| 800 | return new DerivedArgList(Args, true); |
| 801 | } |
| 802 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 803 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 804 | |
| 805 | OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) |
| 806 | : Generic_GCC(Host, Triple) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 807 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 808 | getFilePaths().push_back("/usr/lib"); |
| 809 | } |
| 810 | |
| 811 | Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 812 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 813 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 814 | Key = Action::AnalyzeJobClass; |
| 815 | else |
| 816 | Key = JA.getKind(); |
| 817 | |
| 818 | Tool *&T = Tools[Key]; |
| 819 | if (!T) { |
| 820 | switch (Key) { |
| 821 | case Action::AssembleJobClass: |
| 822 | T = new tools::openbsd::Assemble(*this); break; |
| 823 | case Action::LinkJobClass: |
| 824 | T = new tools::openbsd::Link(*this); break; |
| 825 | default: |
| 826 | T = &Generic_GCC::SelectTool(C, JA); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | return *T; |
| 831 | } |
| 832 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 833 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 834 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 835 | FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32) |
| 836 | : Generic_GCC(Host, Triple) { |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 837 | if (Lib32) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 838 | getFilePaths().push_back(getDriver().Dir + "/../lib32"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 839 | getFilePaths().push_back("/usr/lib32"); |
| 840 | } else { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 841 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 842 | getFilePaths().push_back("/usr/lib"); |
| 843 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 847 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 848 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 849 | Key = Action::AnalyzeJobClass; |
| 850 | else |
| 851 | Key = JA.getKind(); |
| 852 | |
| 853 | Tool *&T = Tools[Key]; |
| 854 | if (!T) { |
| 855 | switch (Key) { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 856 | case Action::AssembleJobClass: |
| 857 | T = new tools::freebsd::Assemble(*this); break; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 858 | case Action::LinkJobClass: |
| 859 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 860 | default: |
| 861 | T = &Generic_GCC::SelectTool(C, JA); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | return *T; |
| 866 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 867 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 868 | /// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. |
| 869 | |
| 870 | AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) |
| 871 | : Generic_GCC(Host, Triple) { |
| 872 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 873 | getProgramPaths().push_back(getDriver().Dir); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 874 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 875 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 876 | getFilePaths().push_back("/usr/lib"); |
| 877 | getFilePaths().push_back("/usr/sfw/lib"); |
| 878 | getFilePaths().push_back("/opt/gcc4/lib"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 879 | getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 880 | |
| 881 | } |
| 882 | |
| 883 | Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 884 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 885 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 886 | Key = Action::AnalyzeJobClass; |
| 887 | else |
| 888 | Key = JA.getKind(); |
| 889 | |
| 890 | Tool *&T = Tools[Key]; |
| 891 | if (!T) { |
| 892 | switch (Key) { |
| 893 | case Action::AssembleJobClass: |
| 894 | T = new tools::auroraux::Assemble(*this); break; |
| 895 | case Action::LinkJobClass: |
| 896 | T = new tools::auroraux::Link(*this); break; |
| 897 | default: |
| 898 | T = &Generic_GCC::SelectTool(C, JA); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | return *T; |
| 903 | } |
| 904 | |
| 905 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 906 | /// Linux toolchain (very bare-bones at the moment). |
| 907 | |
| 908 | Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple) |
| 909 | : Generic_GCC(Host, Triple) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 910 | getFilePaths().push_back(getDriver().Dir + "/../lib/clang/1.0/"); |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 911 | getFilePaths().push_back("/lib/"); |
| 912 | getFilePaths().push_back("/usr/lib/"); |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 913 | |
| 914 | // Depending on the Linux distribution, any combination of lib{,32,64} is |
| 915 | // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems, |
| 916 | // openSUSE uses lib and lib64 for the same purpose. |
| 917 | getFilePaths().push_back("/lib32/"); |
| 918 | getFilePaths().push_back("/usr/lib32/"); |
| 919 | getFilePaths().push_back("/lib64/"); |
| 920 | getFilePaths().push_back("/usr/lib64/"); |
| 921 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 922 | // FIXME: Figure out some way to get gcc's libdir |
| 923 | // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need |
| 924 | // crtbegin.o/crtend.o/etc., and want static versions of various |
| 925 | // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably |
| 926 | // get away with using shared versions in /usr/lib, though. |
| 927 | // We could fall back to the approach we used for includes (a massive |
| 928 | // list), but that's messy at best. |
| 929 | } |
| 930 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 931 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 932 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 933 | DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) |
| 934 | : Generic_GCC(Host, Triple) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 935 | |
| 936 | // Path mangling to find libexec |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 937 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 938 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 939 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 940 | getFilePaths().push_back("/usr/lib"); |
| 941 | getFilePaths().push_back("/usr/lib/gcc41"); |
| 942 | } |
| 943 | |
| 944 | Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 945 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 946 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 947 | Key = Action::AnalyzeJobClass; |
| 948 | else |
| 949 | Key = JA.getKind(); |
| 950 | |
| 951 | Tool *&T = Tools[Key]; |
| 952 | if (!T) { |
| 953 | switch (Key) { |
| 954 | case Action::AssembleJobClass: |
| 955 | T = new tools::dragonfly::Assemble(*this); break; |
| 956 | case Action::LinkJobClass: |
| 957 | T = new tools::dragonfly::Link(*this); break; |
| 958 | default: |
| 959 | T = &Generic_GCC::SelectTool(C, JA); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | return *T; |
| 964 | } |