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