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