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