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