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" |
Douglas Gregor | 34916db | 2010-09-03 17:16:03 +0000 | [diff] [blame] | 21 | #include "clang/Basic/Version.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallString.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MemoryBuffer.h" |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 28 | #include "llvm/System/Path.h" |
| 29 | |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 30 | #include <cstdlib> // ::getenv |
| 31 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 32 | using namespace clang::driver; |
| 33 | using namespace clang::driver::toolchains; |
| 34 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 35 | /// Darwin - Darwin tool chain for i386 and x86_64. |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 36 | |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 37 | Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple) |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 38 | : ToolChain(Host, Triple), TargetInitialized(false) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 39 | { |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 40 | // Compute the initial Darwin version based on the host. |
| 41 | bool HadExtra; |
| 42 | std::string OSName = Triple.getOSName(); |
| 43 | if (!Driver::GetReleaseVersion(&OSName[6], |
| 44 | DarwinVersion[0], DarwinVersion[1], |
| 45 | DarwinVersion[2], HadExtra)) |
| 46 | getDriver().Diag(clang::diag::err_drv_invalid_darwin_version) << OSName; |
| 47 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 48 | llvm::raw_string_ostream(MacosxVersionMin) |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 49 | << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.' |
| 50 | << DarwinVersion[1]; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Daniel Dunbar | 4180011 | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 53 | types::ID Darwin::LookupTypeForExtension(const char *Ext) const { |
| 54 | types::ID Ty = types::lookupTypeForExtension(Ext); |
| 55 | |
| 56 | // Darwin always preprocesses assembly files (unless -x is used explicitly). |
| 57 | if (Ty == types::TY_PP_Asm) |
| 58 | return types::TY_Asm; |
| 59 | |
| 60 | return Ty; |
| 61 | } |
| 62 | |
Daniel Dunbar | b993f5d | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 63 | bool Darwin::HasNativeLLVMSupport() const { |
| 64 | return true; |
| 65 | } |
| 66 | |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 67 | // FIXME: Can we tablegen this? |
| 68 | static const char *GetArmArchForMArch(llvm::StringRef Value) { |
| 69 | if (Value == "armv6k") |
| 70 | return "armv6"; |
| 71 | |
| 72 | if (Value == "armv5tej") |
| 73 | return "armv5"; |
| 74 | |
| 75 | if (Value == "xscale") |
| 76 | return "xscale"; |
| 77 | |
| 78 | if (Value == "armv4t") |
| 79 | return "armv4t"; |
| 80 | |
| 81 | if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" || |
| 82 | Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" || |
| 83 | Value == "armv7m") |
| 84 | return "armv7"; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | // FIXME: Can we tablegen this? |
| 90 | static const char *GetArmArchForMCpu(llvm::StringRef Value) { |
| 91 | if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" || |
| 92 | Value == "arm946e-s" || Value == "arm966e-s" || |
| 93 | Value == "arm968e-s" || Value == "arm10e" || |
| 94 | Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" || |
| 95 | Value == "arm1026ej-s") |
| 96 | return "armv5"; |
| 97 | |
| 98 | if (Value == "xscale") |
| 99 | return "xscale"; |
| 100 | |
| 101 | if (Value == "arm1136j-s" || Value == "arm1136jf-s" || |
| 102 | Value == "arm1176jz-s" || Value == "arm1176jzf-s") |
| 103 | return "armv6"; |
| 104 | |
| 105 | if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3") |
| 106 | return "armv7"; |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const { |
| 112 | switch (getTriple().getArch()) { |
| 113 | default: |
| 114 | return getArchName(); |
| 115 | |
| 116 | case llvm::Triple::arm: { |
| 117 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
| 118 | if (const char *Arch = GetArmArchForMArch(A->getValue(Args))) |
| 119 | return Arch; |
| 120 | |
| 121 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
| 122 | if (const char *Arch = GetArmArchForMCpu(A->getValue(Args))) |
| 123 | return Arch; |
| 124 | |
| 125 | return "arm"; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 130 | DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple) |
| 131 | : Darwin(Host, Triple) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 132 | { |
Daniel Dunbar | c2bda62 | 2010-08-02 05:44:01 +0000 | [diff] [blame] | 133 | // We can only work with 4.2.1 currently. |
| 134 | GCCVersion[0] = 4; |
| 135 | GCCVersion[1] = 2; |
| 136 | GCCVersion[2] = 1; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 137 | |
| 138 | // Set up the tool chain paths to match gcc. |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 139 | ToolChainDir = "i686-apple-darwin"; |
Ted Kremenek | 55bac53 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 140 | ToolChainDir += llvm::utostr(DarwinVersion[0]); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 141 | ToolChainDir += "/"; |
| 142 | ToolChainDir += llvm::utostr(GCCVersion[0]); |
| 143 | ToolChainDir += '.'; |
| 144 | ToolChainDir += llvm::utostr(GCCVersion[1]); |
| 145 | ToolChainDir += '.'; |
| 146 | ToolChainDir += llvm::utostr(GCCVersion[2]); |
| 147 | |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 148 | // Try the next major version if that tool chain dir is invalid. |
Daniel Dunbar | 080fb19 | 2009-10-22 00:12:00 +0000 | [diff] [blame] | 149 | std::string Tmp = "/usr/lib/gcc/" + ToolChainDir; |
| 150 | if (!llvm::sys::Path(Tmp).exists()) { |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 151 | std::string Next = "i686-apple-darwin"; |
| 152 | Next += llvm::utostr(DarwinVersion[0] + 1); |
| 153 | Next += "/"; |
| 154 | Next += llvm::utostr(GCCVersion[0]); |
| 155 | Next += '.'; |
| 156 | Next += llvm::utostr(GCCVersion[1]); |
| 157 | Next += '.'; |
| 158 | Next += llvm::utostr(GCCVersion[2]); |
| 159 | |
| 160 | // Use that if it exists, otherwise hope the user isn't linking. |
| 161 | // |
| 162 | // FIXME: Drop dependency on gcc's tool chain. |
Daniel Dunbar | 080fb19 | 2009-10-22 00:12:00 +0000 | [diff] [blame] | 163 | Tmp = "/usr/lib/gcc/" + Next; |
| 164 | if (llvm::sys::Path(Tmp).exists()) |
Daniel Dunbar | 74782b0 | 2009-10-20 19:25:43 +0000 | [diff] [blame] | 165 | ToolChainDir = Next; |
| 166 | } |
| 167 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 168 | std::string Path; |
| 169 | if (getArchName() == "x86_64") { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 170 | Path = getDriver().Dir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 171 | Path += "/../lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 172 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 173 | Path += "/x86_64"; |
| 174 | getFilePaths().push_back(Path); |
| 175 | |
| 176 | Path = "/usr/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 | Path += "/x86_64"; |
| 179 | getFilePaths().push_back(Path); |
| 180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 182 | Path = getDriver().Dir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 183 | Path += "/../lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 184 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 185 | getFilePaths().push_back(Path); |
| 186 | |
| 187 | Path = "/usr/lib/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 188 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 189 | getFilePaths().push_back(Path); |
| 190 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 191 | Path = getDriver().Dir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 192 | Path += "/../libexec/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 193 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 194 | getProgramPaths().push_back(Path); |
| 195 | |
| 196 | Path = "/usr/libexec/gcc/"; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 197 | Path += ToolChainDir; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 198 | getProgramPaths().push_back(Path); |
| 199 | |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 200 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 201 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 202 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 205 | Darwin::~Darwin() { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 206 | // Free tool implementations. |
| 207 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 208 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 209 | delete it->second; |
| 210 | } |
| 211 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 212 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args) const { |
| 213 | llvm::Triple Triple(ComputeLLVMTriple(Args)); |
| 214 | |
| 215 | // If the target isn't initialized (e.g., an unknown Darwin platform, return |
| 216 | // the default triple). |
| 217 | if (!isTargetInitialized()) |
| 218 | return Triple.getTriple(); |
| 219 | |
| 220 | unsigned Version[3]; |
| 221 | getTargetVersion(Version); |
| 222 | |
| 223 | // Mangle the target version into the OS triple component. For historical |
| 224 | // reasons that make little sense, the version passed here is the "darwin" |
| 225 | // version, which drops the 10 and offsets by 4. See inverse code when |
| 226 | // setting the OS version preprocessor define. |
| 227 | if (!isTargetIPhoneOS()) { |
| 228 | Version[0] = Version[1] + 4; |
| 229 | Version[1] = Version[2]; |
| 230 | Version[2] = 0; |
| 231 | } else { |
| 232 | // Use the environment to communicate that we are targetting iPhoneOS. |
| 233 | Triple.setEnvironmentName("iphoneos"); |
| 234 | } |
| 235 | |
| 236 | llvm::SmallString<16> Str; |
| 237 | llvm::raw_svector_ostream(Str) << "darwin" << Version[0] |
| 238 | << "." << Version[1] << "." << Version[2]; |
| 239 | Triple.setOSName(Str.str()); |
| 240 | |
| 241 | return Triple.getTriple(); |
| 242 | } |
| 243 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 244 | Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 245 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 246 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 247 | Key = Action::AnalyzeJobClass; |
| 248 | else |
| 249 | Key = JA.getKind(); |
| 250 | |
Daniel Dunbar | 0f602de | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 251 | // FIXME: This doesn't belong here, but ideally we will support static soon |
| 252 | // anyway. |
| 253 | bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) || |
| 254 | C.getArgs().hasArg(options::OPT_static) || |
| 255 | C.getArgs().hasArg(options::OPT_fapple_kext)); |
| 256 | bool IsIADefault = IsIntegratedAssemblerDefault() && !HasStatic; |
| 257 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 258 | options::OPT_no_integrated_as, |
| 259 | IsIADefault); |
| 260 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 261 | Tool *&T = Tools[Key]; |
| 262 | if (!T) { |
| 263 | switch (Key) { |
| 264 | case Action::InputClass: |
| 265 | case Action::BindArchClass: |
| 266 | assert(0 && "Invalid tool kind."); |
| 267 | case Action::PreprocessJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 268 | T = new tools::darwin::Preprocess(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 269 | case Action::AnalyzeJobClass: |
| 270 | T = new tools::Clang(*this); break; |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 271 | case Action::PrecompileJobClass: |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 272 | case Action::CompileJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 273 | T = new tools::darwin::Compile(*this); break; |
Daniel Dunbar | 0f602de | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 274 | case Action::AssembleJobClass: { |
| 275 | if (UseIntegratedAs) |
| 276 | T = new tools::ClangAs(*this); |
| 277 | else |
| 278 | T = new tools::darwin::Assemble(*this); |
| 279 | break; |
| 280 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 281 | case Action::LinkJobClass: |
Daniel Dunbar | 8f28962 | 2009-09-04 17:39:02 +0000 | [diff] [blame] | 282 | T = new tools::darwin::Link(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 283 | case Action::LipoJobClass: |
| 284 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 285 | case Action::DsymutilJobClass: |
| 286 | T = new tools::darwin::Dsymutil(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | return *T; |
| 291 | } |
| 292 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 293 | void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args, |
| 294 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | e3c153a | 2010-04-10 18:18:57 +0000 | [diff] [blame] | 295 | std::string Tmp; |
| 296 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 297 | // FIXME: Derive these correctly. |
| 298 | if (getArchName() == "x86_64") { |
| 299 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 300 | "/x86_64")); |
| 301 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 302 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 303 | "/x86_64")); |
| 304 | } |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 305 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 306 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir)); |
Daniel Dunbar | e3c153a | 2010-04-10 18:18:57 +0000 | [diff] [blame] | 307 | |
| 308 | Tmp = getDriver().Dir + "/../lib/gcc/" + ToolChainDir; |
| 309 | if (llvm::sys::Path(Tmp).exists()) |
| 310 | CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); |
| 311 | Tmp = getDriver().Dir + "/../lib/gcc"; |
| 312 | if (llvm::sys::Path(Tmp).exists()) |
| 313 | CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 314 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); |
| 315 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 316 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); |
Daniel Dunbar | e3c153a | 2010-04-10 18:18:57 +0000 | [diff] [blame] | 317 | Tmp = getDriver().Dir + "/../lib/" + ToolChainDir; |
| 318 | if (llvm::sys::Path(Tmp).exists()) |
| 319 | CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); |
| 320 | Tmp = getDriver().Dir + "/../lib"; |
| 321 | if (llvm::sys::Path(Tmp).exists()) |
| 322 | CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 323 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 324 | "/../../../" + ToolChainDir)); |
| 325 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + |
| 326 | "/../../..")); |
| 327 | } |
| 328 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 329 | void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 330 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 331 | // Note that this routine is only used for targetting OS X. |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 332 | |
| 333 | // Derived from libgcc and lib specs but refactored. |
| 334 | if (Args.hasArg(options::OPT_static)) { |
| 335 | CmdArgs.push_back("-lgcc_static"); |
| 336 | } else { |
| 337 | if (Args.hasArg(options::OPT_static_libgcc)) { |
| 338 | CmdArgs.push_back("-lgcc_eh"); |
| 339 | } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
| 340 | // Derived from darwin_iphoneos_libgcc spec. |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 341 | if (isTargetIPhoneOS()) { |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 342 | CmdArgs.push_back("-lgcc_s.1"); |
| 343 | } else { |
| 344 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 345 | } |
| 346 | } else if (Args.hasArg(options::OPT_shared_libgcc) || |
Daniel Dunbar | 8a0d94d | 2010-01-10 00:46:10 +0000 | [diff] [blame] | 347 | Args.hasFlag(options::OPT_fexceptions, |
| 348 | options::OPT_fno_exceptions) || |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 349 | Args.hasArg(options::OPT_fgnu_runtime)) { |
| 350 | // FIXME: This is probably broken on 10.3? |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 351 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 352 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 353 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 354 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 355 | } else { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 356 | if (isMacosxVersionLT(10, 3, 9)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 357 | ; // Do nothing. |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 358 | else if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 359 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 360 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 361 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 362 | } |
| 363 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 364 | if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) { |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 365 | CmdArgs.push_back("-lgcc"); |
| 366 | CmdArgs.push_back("-lSystem"); |
| 367 | } else { |
| 368 | CmdArgs.push_back("-lSystem"); |
| 369 | CmdArgs.push_back("-lgcc"); |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | |
Daniel Dunbar | 25b58eb | 2010-08-02 05:44:07 +0000 | [diff] [blame] | 374 | DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple) |
| 375 | : Darwin(Host, Triple) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 376 | { |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 377 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 378 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 379 | getProgramPaths().push_back(getDriver().Dir); |
| 380 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 381 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 382 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 383 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 384 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 385 | |
| 386 | // For fallback, we need to know how to find the GCC cc1 executables, so we |
| 387 | // also add the GCC libexec paths. This is legiy code that can be removed once |
| 388 | // fallback is no longer useful. |
| 389 | std::string ToolChainDir = "i686-apple-darwin"; |
| 390 | ToolChainDir += llvm::utostr(DarwinVersion[0]); |
| 391 | ToolChainDir += "/4.2.1"; |
| 392 | |
| 393 | std::string Path = getDriver().Dir; |
| 394 | Path += "/../libexec/gcc/"; |
| 395 | Path += ToolChainDir; |
| 396 | getProgramPaths().push_back(Path); |
| 397 | |
| 398 | Path = "/usr/libexec/gcc/"; |
| 399 | Path += ToolChainDir; |
| 400 | getProgramPaths().push_back(Path); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, |
| 404 | ArgStringList &CmdArgs) const { |
| 405 | // The Clang toolchain uses explicit paths for internal libraries. |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 406 | |
| 407 | // Unfortunately, we still might depend on a few of the libraries that are |
| 408 | // only available in the gcc library directory (in particular |
| 409 | // libstdc++.dylib). For now, hardcode the path to the known install location. |
| 410 | llvm::sys::Path P(getDriver().Dir); |
| 411 | P.eraseComponent(); // .../usr/bin -> ../usr |
| 412 | P.appendComponent("lib"); |
| 413 | P.appendComponent("gcc"); |
| 414 | switch (getTriple().getArch()) { |
| 415 | default: |
| 416 | assert(0 && "Invalid Darwin arch!"); |
| 417 | case llvm::Triple::x86: |
| 418 | case llvm::Triple::x86_64: |
| 419 | P.appendComponent("i686-apple-darwin10"); |
| 420 | break; |
| 421 | case llvm::Triple::arm: |
| 422 | case llvm::Triple::thumb: |
| 423 | P.appendComponent("arm-apple-darwin10"); |
| 424 | break; |
| 425 | case llvm::Triple::ppc: |
| 426 | case llvm::Triple::ppc64: |
| 427 | P.appendComponent("powerpc-apple-darwin10"); |
| 428 | break; |
| 429 | } |
| 430 | P.appendComponent("4.2.1"); |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 431 | |
| 432 | // Determine the arch specific GCC subdirectory. |
| 433 | const char *ArchSpecificDir = 0; |
| 434 | switch (getTriple().getArch()) { |
| 435 | default: |
| 436 | break; |
| 437 | case llvm::Triple::arm: |
Daniel Dunbar | 3a0e392 | 2010-08-26 00:55:52 +0000 | [diff] [blame] | 438 | case llvm::Triple::thumb: { |
| 439 | std::string Triple = ComputeLLVMTriple(Args); |
| 440 | llvm::StringRef TripleStr = Triple; |
| 441 | if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5")) |
| 442 | ArchSpecificDir = "v5"; |
| 443 | else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6")) |
| 444 | ArchSpecificDir = "v6"; |
| 445 | else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7")) |
| 446 | ArchSpecificDir = "v7"; |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 447 | break; |
Daniel Dunbar | 3a0e392 | 2010-08-26 00:55:52 +0000 | [diff] [blame] | 448 | } |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 449 | case llvm::Triple::ppc64: |
| 450 | ArchSpecificDir = "ppc64"; |
| 451 | break; |
| 452 | case llvm::Triple::x86_64: |
| 453 | ArchSpecificDir = "x86_64"; |
| 454 | break; |
| 455 | } |
| 456 | |
| 457 | if (ArchSpecificDir) { |
| 458 | P.appendComponent(ArchSpecificDir); |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 459 | if (P.exists()) |
| 460 | CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); |
| 461 | P.eraseComponent(); |
| 462 | } |
| 463 | |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 464 | if (P.exists()) |
| 465 | CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 469 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 470 | // Darwin doesn't support real static executables, don't link any runtime |
| 471 | // libraries with -static. |
| 472 | if (Args.hasArg(options::OPT_static)) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 473 | return; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 474 | |
| 475 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 476 | // cares. This is useful in situations where someone wants to statically link |
| 477 | // something like libstdc++, and needs its runtime support routines. |
| 478 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 479 | getDriver().Diag(clang::diag::err_drv_unsupported_opt) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 480 | << A->getAsString(Args); |
| 481 | return; |
| 482 | } |
| 483 | |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 484 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 485 | // target specific static runtime library. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 486 | CmdArgs.push_back("-lSystem"); |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 487 | |
| 488 | // Select the dynamic runtime library and the target specific static library. |
| 489 | const char *DarwinStaticLib = 0; |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 490 | if (isTargetIPhoneOS()) { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 491 | CmdArgs.push_back("-lgcc_s.1"); |
| 492 | |
| 493 | // We may need some static functions for armv6/thumb which are required to |
| 494 | // be in the same linkage unit as their caller. |
| 495 | if (getDarwinArchName(Args) == "armv6") |
| 496 | DarwinStaticLib = "libclang_rt.armv6.a"; |
| 497 | } else { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 498 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 499 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 500 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 501 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 502 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 503 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 504 | |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 505 | // For OS X, we thought we would only need a static runtime library when |
| 506 | // targetting 10.4, to provide versions of the static functions which were |
| 507 | // omitted from 10.4.dylib. |
| 508 | // |
| 509 | // Unfortunately, that turned out to not be true, because Darwin system |
| 510 | // headers can still use eprintf on i386, and it is not exported from |
| 511 | // libSystem. Therefore, we still must provide a runtime library just for |
| 512 | // the tiny tiny handful of projects that *might* use that symbol. |
| 513 | if (isMacosxVersionLT(10, 5)) { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 514 | DarwinStaticLib = "libclang_rt.10.4.a"; |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 515 | } else { |
| 516 | if (getTriple().getArch() == llvm::Triple::x86) |
| 517 | DarwinStaticLib = "libclang_rt.eprintf.a"; |
| 518 | } |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /// Add the target specific static library, if needed. |
| 522 | if (DarwinStaticLib) { |
| 523 | llvm::sys::Path P(getDriver().ResourceDir); |
| 524 | P.appendComponent("lib"); |
| 525 | P.appendComponent("darwin"); |
| 526 | P.appendComponent(DarwinStaticLib); |
| 527 | |
| 528 | // For now, allow missing resource libraries to support developers who may |
| 529 | // not have compiler-rt checked out or integrated into their build. |
Daniel Dunbar | 362ed70 | 2010-10-11 23:31:07 +0000 | [diff] [blame] | 530 | if (P.exists()) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 531 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 532 | } |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 535 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 536 | const OptTable &Opts = getDriver().getOpts(); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 537 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 538 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
| 539 | Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 540 | if (OSXVersion && iPhoneVersion) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 541 | getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 542 | << OSXVersion->getAsString(Args) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | << iPhoneVersion->getAsString(Args); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 544 | iPhoneVersion = 0; |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 545 | } else if (!OSXVersion && !iPhoneVersion) { |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 546 | // If neither OS X nor iPhoneOS targets were specified, check for |
| 547 | // environment defines. |
| 548 | const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET"); |
| 549 | const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET"); |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 550 | |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 551 | // Ignore empty strings. |
| 552 | if (OSXTarget && OSXTarget[0] == '\0') |
| 553 | OSXTarget = 0; |
| 554 | if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0') |
| 555 | iPhoneOSTarget = 0; |
| 556 | |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 557 | // Diagnose conflicting deployment targets, and choose default platform |
| 558 | // based on the tool chain. |
| 559 | // |
| 560 | // FIXME: Don't hardcode default here. |
| 561 | if (OSXTarget && iPhoneOSTarget) { |
| 562 | // FIXME: We should see if we can get away with warning or erroring on |
| 563 | // this. Perhaps put under -pedantic? |
| 564 | if (getTriple().getArch() == llvm::Triple::arm || |
| 565 | getTriple().getArch() == llvm::Triple::thumb) |
Daniel Dunbar | 84d1e6e | 2010-03-20 08:47:42 +0000 | [diff] [blame] | 566 | OSXTarget = 0; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 567 | else |
Daniel Dunbar | 84d1e6e | 2010-03-20 08:47:42 +0000 | [diff] [blame] | 568 | iPhoneOSTarget = 0; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 569 | } |
Daniel Dunbar | 1a3c1d9 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 570 | |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 571 | if (OSXTarget) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 572 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 573 | OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget); |
| 574 | Args.append(OSXVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 575 | } else if (iPhoneOSTarget) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 576 | const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 577 | iPhoneVersion = Args.MakeJoinedArg(0, O, iPhoneOSTarget); |
| 578 | Args.append(iPhoneVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 579 | } else { |
Daniel Dunbar | 2bb38d0 | 2010-07-15 16:18:06 +0000 | [diff] [blame] | 580 | // Otherwise, assume we are targeting OS X. |
| 581 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 582 | OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin); |
| 583 | Args.append(OSXVersion); |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 584 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 585 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 586 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 587 | // Set the tool chain target information. |
| 588 | unsigned Major, Minor, Micro; |
| 589 | bool HadExtra; |
| 590 | if (OSXVersion) { |
| 591 | assert(!iPhoneVersion && "Unknown target platform!"); |
| 592 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor, |
| 593 | Micro, HadExtra) || HadExtra || |
| 594 | Major != 10 || Minor >= 10 || Micro >= 10) |
| 595 | getDriver().Diag(clang::diag::err_drv_invalid_version_number) |
| 596 | << OSXVersion->getAsString(Args); |
| 597 | } else { |
| 598 | assert(iPhoneVersion && "Unknown target platform!"); |
| 599 | if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor, |
| 600 | Micro, HadExtra) || HadExtra || |
| 601 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 602 | getDriver().Diag(clang::diag::err_drv_invalid_version_number) |
| 603 | << iPhoneVersion->getAsString(Args); |
| 604 | } |
| 605 | setTarget(iPhoneVersion, Major, Minor, Micro); |
Daniel Dunbar | c0e665e | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 608 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 609 | ArgStringList &CmdArgs) const { |
| 610 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 611 | |
| 612 | switch (Type) { |
| 613 | case ToolChain::CST_Libcxx: |
| 614 | CmdArgs.push_back("-lc++"); |
| 615 | break; |
| 616 | |
| 617 | case ToolChain::CST_Libstdcxx: { |
| 618 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 619 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 620 | // platforms we care about it was -lstdc++.6, so we search for that |
| 621 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 622 | |
| 623 | // Check in the sysroot first. |
| 624 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 625 | llvm::sys::Path P(A->getValue(Args)); |
| 626 | P.appendComponent("usr"); |
| 627 | P.appendComponent("lib"); |
| 628 | P.appendComponent("libstdc++.dylib"); |
| 629 | |
| 630 | if (!P.exists()) { |
| 631 | P.eraseComponent(); |
| 632 | P.appendComponent("libstdc++.6.dylib"); |
| 633 | if (P.exists()) { |
| 634 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 635 | return; |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | // Otherwise, look in the root. |
| 641 | if (!llvm::sys::Path("/usr/lib/libstdc++.dylib").exists() && |
| 642 | llvm::sys::Path("/usr/lib/libstdc++.6.dylib").exists()) { |
| 643 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | // Otherwise, let the linker search. |
| 648 | CmdArgs.push_back("-lstdc++"); |
| 649 | break; |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 654 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 655 | ArgStringList &CmdArgs) const { |
| 656 | |
| 657 | // For Darwin platforms, use the compiler-rt-based support library |
| 658 | // instead of the gcc-provided one (which is also incidentally |
| 659 | // only present in the gcc lib dir, which makes it hard to find). |
| 660 | |
| 661 | llvm::sys::Path P(getDriver().ResourceDir); |
| 662 | P.appendComponent("lib"); |
| 663 | P.appendComponent("darwin"); |
| 664 | P.appendComponent("libclang_rt.cc_kext.a"); |
| 665 | |
| 666 | // For now, allow missing resource libraries to support developers who may |
| 667 | // not have compiler-rt checked out or integrated into their build. |
Daniel Dunbar | 362ed70 | 2010-10-11 23:31:07 +0000 | [diff] [blame] | 668 | if (P.exists()) |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 669 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 670 | } |
| 671 | |
Daniel Dunbar | c0e665e | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 672 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 673 | const char *BoundArch) const { |
| 674 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 675 | const OptTable &Opts = getDriver().getOpts(); |
| 676 | |
| 677 | // FIXME: We really want to get out of the tool chain level argument |
| 678 | // translation business, as it makes the driver functionality much |
| 679 | // more opaque. For now, we follow gcc closely solely for the |
| 680 | // purpose of easily achieving feature parity & testability. Once we |
| 681 | // have something that works, we should reevaluate each translation |
| 682 | // and try to push it down into tool specific logic. |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 683 | |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 684 | for (ArgList::const_iterator it = Args.begin(), |
| 685 | ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 686 | Arg *A = *it; |
| 687 | |
| 688 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 689 | // FIXME: Canonicalize name. |
| 690 | if (getArchName() != A->getValue(Args, 0)) |
| 691 | continue; |
| 692 | |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 693 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1)); |
| 694 | unsigned Prev = Index; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 695 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 697 | // If the argument parsing failed or more than one argument was |
| 698 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 699 | // extra arguments. Emit an error and ignore. |
| 700 | // |
| 701 | // We also want to disallow any options which would alter the |
| 702 | // driver behavior; that isn't going to work in our model. We |
| 703 | // use isDriverOption() as an approximation, although things |
| 704 | // like -O4 are going to slip through. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | if (!XarchArg || Index > Prev + 1 || |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 706 | XarchArg->getOption().isDriverOption()) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 707 | getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 708 | << A->getAsString(Args); |
| 709 | continue; |
| 710 | } |
| 711 | |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 712 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 713 | A = XarchArg; |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 714 | |
| 715 | DAL->AddSynthesizedArg(A); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 716 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 717 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 718 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 719 | // gcc translates options twice, which means that self-expanding |
| 720 | // options add duplicates. |
Daniel Dunbar | 9e1f982 | 2009-11-19 04:14:53 +0000 | [diff] [blame] | 721 | switch ((options::ID) A->getOption().getID()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 722 | default: |
| 723 | DAL->append(A); |
| 724 | break; |
| 725 | |
| 726 | case options::OPT_mkernel: |
| 727 | case options::OPT_fapple_kext: |
| 728 | DAL->append(A); |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 729 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
| 730 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 731 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 733 | case options::OPT_dependency_file: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 734 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), |
| 735 | A->getValue(Args)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case options::OPT_gfull: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 739 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 740 | DAL->AddFlagArg(A, |
| 741 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 742 | break; |
| 743 | |
| 744 | case options::OPT_gused: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 745 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 746 | DAL->AddFlagArg(A, |
| 747 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case options::OPT_fterminated_vtables: |
| 751 | case options::OPT_findirect_virtual_calls: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 752 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_fapple_kext)); |
| 753 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 754 | break; |
| 755 | |
| 756 | case options::OPT_shared: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 757 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 761 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 762 | break; |
| 763 | |
| 764 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 765 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 769 | DAL->AddFlagArg(A, |
| 770 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 774 | DAL->AddFlagArg(A, |
| 775 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 779 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 780 | break; |
| 781 | |
| 782 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 783 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 784 | break; |
| 785 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 788 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 789 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 790 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 791 | DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 792 | |
| 793 | // Add the arch options based on the particular spelling of -arch, to match |
| 794 | // how the driver driver works. |
| 795 | if (BoundArch) { |
| 796 | llvm::StringRef Name = BoundArch; |
| 797 | const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 798 | const Option *MArch = Opts.getOption(options::OPT_march_EQ); |
| 799 | |
| 800 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 801 | // which defines the list of which architectures we accept. |
| 802 | if (Name == "ppc") |
| 803 | ; |
| 804 | else if (Name == "ppc601") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 805 | DAL->AddJoinedArg(0, MCpu, "601"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 806 | else if (Name == "ppc603") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 807 | DAL->AddJoinedArg(0, MCpu, "603"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 808 | else if (Name == "ppc604") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 809 | DAL->AddJoinedArg(0, MCpu, "604"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 810 | else if (Name == "ppc604e") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 811 | DAL->AddJoinedArg(0, MCpu, "604e"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 812 | else if (Name == "ppc750") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 813 | DAL->AddJoinedArg(0, MCpu, "750"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 814 | else if (Name == "ppc7400") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 815 | DAL->AddJoinedArg(0, MCpu, "7400"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 816 | else if (Name == "ppc7450") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 817 | DAL->AddJoinedArg(0, MCpu, "7450"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 818 | else if (Name == "ppc970") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 819 | DAL->AddJoinedArg(0, MCpu, "970"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 820 | |
| 821 | else if (Name == "ppc64") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 822 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 823 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 824 | else if (Name == "i386") |
| 825 | ; |
| 826 | else if (Name == "i486") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 827 | DAL->AddJoinedArg(0, MArch, "i486"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 828 | else if (Name == "i586") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 829 | DAL->AddJoinedArg(0, MArch, "i586"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 830 | else if (Name == "i686") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 831 | DAL->AddJoinedArg(0, MArch, "i686"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 832 | else if (Name == "pentium") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 833 | DAL->AddJoinedArg(0, MArch, "pentium"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 834 | else if (Name == "pentium2") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 835 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 836 | else if (Name == "pentpro") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 837 | DAL->AddJoinedArg(0, MArch, "pentiumpro"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 838 | else if (Name == "pentIIm3") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 839 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 840 | |
| 841 | else if (Name == "x86_64") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 842 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 843 | |
| 844 | else if (Name == "arm") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 845 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 846 | else if (Name == "armv4t") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 847 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 848 | else if (Name == "armv5") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 849 | DAL->AddJoinedArg(0, MArch, "armv5tej"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 850 | else if (Name == "xscale") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 851 | DAL->AddJoinedArg(0, MArch, "xscale"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 852 | else if (Name == "armv6") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 853 | DAL->AddJoinedArg(0, MArch, "armv6k"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 854 | else if (Name == "armv7") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 855 | DAL->AddJoinedArg(0, MArch, "armv7a"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 856 | |
| 857 | else |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 858 | llvm_unreachable("invalid Darwin arch"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 859 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 860 | |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 861 | // Add an explicit version min argument for the deployment target. We do this |
| 862 | // after argument translation because -Xarch_ arguments may add a version min |
| 863 | // argument. |
| 864 | AddDeploymentTarget(*DAL); |
| 865 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 866 | return DAL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 867 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 868 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 869 | bool Darwin::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 870 | // FIXME: Gross; we should probably have some separate target |
| 871 | // definition, possibly even reusing the one in clang. |
| 872 | return getArchName() == "x86_64"; |
| 873 | } |
| 874 | |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 875 | bool Darwin::UseDwarfDebugFlags() const { |
| 876 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 877 | return S[0] != '\0'; |
| 878 | return false; |
| 879 | } |
| 880 | |
Daniel Dunbar | b2987d1 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 881 | bool Darwin::UseSjLjExceptions() const { |
| 882 | // Darwin uses SjLj exceptions on ARM. |
| 883 | return (getTriple().getArch() == llvm::Triple::arm || |
| 884 | getTriple().getArch() == llvm::Triple::thumb); |
| 885 | } |
| 886 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 887 | const char *Darwin::GetDefaultRelocationModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 888 | return "pic"; |
| 889 | } |
| 890 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 891 | const char *Darwin::GetForcedPicModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 892 | if (getArchName() == "x86_64") |
| 893 | return "pic"; |
| 894 | return 0; |
| 895 | } |
| 896 | |
Daniel Dunbar | 43a9b32 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 897 | bool Darwin::SupportsObjCGC() const { |
| 898 | // Garbage collection is supported everywhere except on iPhone OS. |
| 899 | return !isTargetIPhoneOS(); |
| 900 | } |
| 901 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 902 | std::string |
| 903 | Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const { |
| 904 | return ComputeLLVMTriple(Args); |
| 905 | } |
| 906 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 907 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 908 | /// all subcommands; this relies on gcc translating the majority of |
| 909 | /// command line options. |
| 910 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 911 | Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 912 | : ToolChain(Host, Triple) { |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 913 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 914 | if (getDriver().getInstalledDir() != getDriver().Dir.c_str()) |
| 915 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 918 | Generic_GCC::~Generic_GCC() { |
| 919 | // Free tool implementations. |
| 920 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 921 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 922 | delete it->second; |
| 923 | } |
| 924 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 925 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 926 | 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())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +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) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 936 | case Action::InputClass: |
| 937 | case Action::BindArchClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 938 | assert(0 && "Invalid tool kind."); |
| 939 | case Action::PreprocessJobClass: |
| 940 | T = new tools::gcc::Preprocess(*this); break; |
| 941 | case Action::PrecompileJobClass: |
| 942 | T = new tools::gcc::Precompile(*this); break; |
| 943 | case Action::AnalyzeJobClass: |
| 944 | T = new tools::Clang(*this); break; |
| 945 | case Action::CompileJobClass: |
| 946 | T = new tools::gcc::Compile(*this); break; |
| 947 | case Action::AssembleJobClass: |
| 948 | T = new tools::gcc::Assemble(*this); break; |
| 949 | case Action::LinkJobClass: |
| 950 | T = new tools::gcc::Link(*this); break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 952 | // This is a bit ungeneric, but the only platform using a driver |
| 953 | // driver is Darwin. |
| 954 | case Action::LipoJobClass: |
| 955 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 956 | case Action::DsymutilJobClass: |
| 957 | T = new tools::darwin::Dsymutil(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
| 961 | return *T; |
| 962 | } |
| 963 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 964 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 965 | // FIXME: Gross; we should probably have some separate target |
| 966 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 967 | return getArchName() == "x86_64"; |
| 968 | } |
| 969 | |
| 970 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 971 | return "static"; |
| 972 | } |
| 973 | |
| 974 | const char *Generic_GCC::GetForcedPicModel() const { |
| 975 | return 0; |
| 976 | } |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 977 | |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 978 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 979 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 980 | /// Currently does not support anything else but compilation. |
| 981 | |
| 982 | TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple) |
| 983 | : ToolChain(Host, Triple) { |
| 984 | // Path mangling to find libexec |
| 985 | std::string Path(getDriver().Dir); |
| 986 | |
| 987 | Path += "/../libexec"; |
| 988 | getProgramPaths().push_back(Path); |
| 989 | } |
| 990 | |
| 991 | TCEToolChain::~TCEToolChain() { |
| 992 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 993 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 994 | delete it->second; |
| 995 | } |
| 996 | |
| 997 | bool TCEToolChain::IsMathErrnoDefault() const { |
| 998 | return true; |
| 999 | } |
| 1000 | |
| 1001 | bool TCEToolChain::IsUnwindTablesDefault() const { |
| 1002 | return false; |
| 1003 | } |
| 1004 | |
| 1005 | const char *TCEToolChain::GetDefaultRelocationModel() const { |
| 1006 | return "static"; |
| 1007 | } |
| 1008 | |
| 1009 | const char *TCEToolChain::GetForcedPicModel() const { |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | Tool &TCEToolChain::SelectTool(const Compilation &C, |
| 1014 | const JobAction &JA) const { |
| 1015 | Action::ActionClass Key; |
| 1016 | Key = Action::AnalyzeJobClass; |
| 1017 | |
| 1018 | Tool *&T = Tools[Key]; |
| 1019 | if (!T) { |
| 1020 | switch (Key) { |
| 1021 | case Action::PreprocessJobClass: |
| 1022 | T = new tools::gcc::Preprocess(*this); break; |
| 1023 | case Action::AnalyzeJobClass: |
| 1024 | T = new tools::Clang(*this); break; |
| 1025 | default: |
| 1026 | assert(false && "Unsupported action for TCE target."); |
| 1027 | } |
| 1028 | } |
| 1029 | return *T; |
| 1030 | } |
| 1031 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1032 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 1033 | |
| 1034 | OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 1035 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1036 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1037 | getFilePaths().push_back("/usr/lib"); |
| 1038 | } |
| 1039 | |
| 1040 | Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 1041 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1042 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1043 | Key = Action::AnalyzeJobClass; |
| 1044 | else |
| 1045 | Key = JA.getKind(); |
| 1046 | |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1047 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1048 | options::OPT_no_integrated_as, |
| 1049 | IsIntegratedAssemblerDefault()); |
| 1050 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1051 | Tool *&T = Tools[Key]; |
| 1052 | if (!T) { |
| 1053 | switch (Key) { |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1054 | case Action::AssembleJobClass: { |
| 1055 | if (UseIntegratedAs) |
| 1056 | T = new tools::ClangAs(*this); |
| 1057 | else |
| 1058 | T = new tools::openbsd::Assemble(*this); |
| 1059 | break; |
| 1060 | } |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1061 | case Action::LinkJobClass: |
| 1062 | T = new tools::openbsd::Link(*this); break; |
| 1063 | default: |
| 1064 | T = &Generic_GCC::SelectTool(C, JA); |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | return *T; |
| 1069 | } |
| 1070 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1071 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 1072 | |
Daniel Dunbar | 214afe9 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 1073 | FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 1074 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | 214afe9 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Determine if we are compiling 32-bit code on an x86_64 platform. |
| 1077 | bool Lib32 = false; |
| 1078 | if (Triple.getArch() == llvm::Triple::x86 && |
| 1079 | llvm::Triple(getDriver().DefaultHostTriple).getArch() == |
| 1080 | llvm::Triple::x86_64) |
| 1081 | Lib32 = true; |
| 1082 | |
Daniel Dunbar | 7fb2c25 | 2010-06-15 15:03:31 +0000 | [diff] [blame] | 1083 | getProgramPaths().push_back(getDriver().Dir + "/../libexec"); |
| 1084 | getProgramPaths().push_back("/usr/libexec"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 1085 | if (Lib32) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1086 | getFilePaths().push_back(getDriver().Dir + "/../lib32"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 1087 | getFilePaths().push_back("/usr/lib32"); |
| 1088 | } else { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1089 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | bc53466 | 2009-04-02 18:30:04 +0000 | [diff] [blame] | 1090 | getFilePaths().push_back("/usr/lib"); |
| 1091 | } |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 1095 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1096 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1097 | Key = Action::AnalyzeJobClass; |
| 1098 | else |
| 1099 | Key = JA.getKind(); |
| 1100 | |
Roman Divacky | 67dece7 | 2010-11-08 17:46:39 +0000 | [diff] [blame^] | 1101 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1102 | options::OPT_no_integrated_as, |
| 1103 | IsIntegratedAssemblerDefault()); |
| 1104 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1105 | Tool *&T = Tools[Key]; |
| 1106 | if (!T) { |
| 1107 | switch (Key) { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1108 | case Action::AssembleJobClass: |
Roman Divacky | 67dece7 | 2010-11-08 17:46:39 +0000 | [diff] [blame^] | 1109 | if (UseIntegratedAs) |
| 1110 | T = new tools::ClangAs(*this); |
| 1111 | else |
| 1112 | T = new tools::freebsd::Assemble(*this); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1113 | case Action::LinkJobClass: |
| 1114 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1115 | default: |
| 1116 | T = &Generic_GCC::SelectTool(C, JA); |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | return *T; |
| 1121 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1122 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1123 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 1124 | |
| 1125 | Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple) |
| 1126 | : Generic_GCC(Host, Triple) { |
| 1127 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 1128 | getFilePaths().push_back("/usr/lib"); |
| 1129 | getFilePaths().push_back("/usr/gnu/lib"); |
| 1130 | getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3"); |
| 1131 | } |
| 1132 | |
| 1133 | Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 1134 | Action::ActionClass Key; |
| 1135 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1136 | Key = Action::AnalyzeJobClass; |
| 1137 | else |
| 1138 | Key = JA.getKind(); |
| 1139 | |
| 1140 | Tool *&T = Tools[Key]; |
| 1141 | if (!T) { |
| 1142 | switch (Key) { |
| 1143 | case Action::AssembleJobClass: |
| 1144 | T = new tools::minix::Assemble(*this); break; |
| 1145 | case Action::LinkJobClass: |
| 1146 | T = new tools::minix::Link(*this); break; |
| 1147 | default: |
| 1148 | T = &Generic_GCC::SelectTool(C, JA); |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | return *T; |
| 1153 | } |
| 1154 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1155 | /// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. |
| 1156 | |
| 1157 | AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) |
| 1158 | : Generic_GCC(Host, Triple) { |
| 1159 | |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1160 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 1161 | if (getDriver().getInstalledDir() != getDriver().Dir.c_str()) |
| 1162 | getProgramPaths().push_back(getDriver().Dir); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1163 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1164 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1165 | getFilePaths().push_back("/usr/lib"); |
| 1166 | getFilePaths().push_back("/usr/sfw/lib"); |
| 1167 | getFilePaths().push_back("/opt/gcc4/lib"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 1168 | 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] | 1169 | |
| 1170 | } |
| 1171 | |
| 1172 | Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 1173 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1174 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1175 | Key = Action::AnalyzeJobClass; |
| 1176 | else |
| 1177 | Key = JA.getKind(); |
| 1178 | |
| 1179 | Tool *&T = Tools[Key]; |
| 1180 | if (!T) { |
| 1181 | switch (Key) { |
| 1182 | case Action::AssembleJobClass: |
| 1183 | T = new tools::auroraux::Assemble(*this); break; |
| 1184 | case Action::LinkJobClass: |
| 1185 | T = new tools::auroraux::Link(*this); break; |
| 1186 | default: |
| 1187 | T = &Generic_GCC::SelectTool(C, JA); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | return *T; |
| 1192 | } |
| 1193 | |
| 1194 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1195 | /// Linux toolchain (very bare-bones at the moment). |
| 1196 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1197 | enum LinuxDistro { |
| 1198 | DebianLenny, |
| 1199 | DebianSqueeze, |
| 1200 | Fedora13, |
| 1201 | Fedora14, |
| 1202 | OpenSuse11_3, |
| 1203 | UbuntuLucid, |
| 1204 | UbuntuMaverick, |
| 1205 | UnknownDistro |
| 1206 | }; |
| 1207 | |
| 1208 | static bool IsFedora(enum LinuxDistro Distro) { |
| 1209 | return Distro == Fedora13 || Distro == Fedora14; |
| 1210 | } |
| 1211 | |
| 1212 | static bool IsOpenSuse(enum LinuxDistro Distro) { |
| 1213 | return Distro == OpenSuse11_3; |
| 1214 | } |
| 1215 | |
| 1216 | static bool IsDebian(enum LinuxDistro Distro) { |
| 1217 | return Distro == DebianLenny || Distro == DebianSqueeze; |
| 1218 | } |
| 1219 | |
| 1220 | static bool IsUbuntu(enum LinuxDistro Distro) { |
| 1221 | return Distro == UbuntuLucid || Distro == UbuntuMaverick; |
| 1222 | } |
| 1223 | |
| 1224 | static bool IsDebianBased(enum LinuxDistro Distro) { |
| 1225 | return IsDebian(Distro) || IsUbuntu(Distro); |
| 1226 | } |
| 1227 | |
| 1228 | static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) { |
| 1229 | if (Arch == llvm::Triple::x86_64) |
| 1230 | return true; |
| 1231 | if (Arch == llvm::Triple::x86 && IsDebianBased(Distro)) |
| 1232 | return true; |
| 1233 | return false; |
| 1234 | } |
| 1235 | |
| 1236 | static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) { |
| 1237 | llvm::OwningPtr<const llvm::MemoryBuffer> |
| 1238 | LsbRelease(llvm::MemoryBuffer::getFile("/etc/lsb-release")); |
| 1239 | if (LsbRelease) { |
| 1240 | llvm::StringRef Data = LsbRelease.get()->getBuffer(); |
| 1241 | llvm::SmallVector<llvm::StringRef, 8> Lines; |
| 1242 | Data.split(Lines, "\n"); |
| 1243 | for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) { |
| 1244 | if (Lines[i] == "DISTRIB_CODENAME=maverick") |
| 1245 | return UbuntuMaverick; |
| 1246 | else if (Lines[i] == "DISTRIB_CODENAME=lucid") |
| 1247 | return UbuntuLucid; |
| 1248 | } |
| 1249 | return UnknownDistro; |
| 1250 | } |
| 1251 | |
| 1252 | llvm::OwningPtr<const llvm::MemoryBuffer> |
| 1253 | RHRelease(llvm::MemoryBuffer::getFile("/etc/redhat-release")); |
| 1254 | if (RHRelease) { |
| 1255 | llvm::StringRef Data = RHRelease.get()->getBuffer(); |
| 1256 | if (Data.startswith("Fedora release 14 (Laughlin)")) |
| 1257 | return Fedora14; |
| 1258 | else if (Data.startswith("Fedora release 13 (Goddard)")) |
| 1259 | return Fedora13; |
| 1260 | return UnknownDistro; |
| 1261 | } |
| 1262 | |
| 1263 | llvm::OwningPtr<const llvm::MemoryBuffer> |
| 1264 | DebianVersion(llvm::MemoryBuffer::getFile("/etc/debian_version")); |
| 1265 | if (DebianVersion) { |
| 1266 | llvm::StringRef Data = DebianVersion.get()->getBuffer(); |
| 1267 | if (Data[0] == '5') |
| 1268 | return DebianLenny; |
| 1269 | else if (Data.startswith("squeeze/sid")) |
| 1270 | return DebianSqueeze; |
| 1271 | return UnknownDistro; |
| 1272 | } |
| 1273 | |
| 1274 | llvm::OwningPtr<const llvm::MemoryBuffer> |
| 1275 | SuseRelease(llvm::MemoryBuffer::getFile("/etc/SuSE-release")); |
| 1276 | if (SuseRelease) { |
| 1277 | llvm::StringRef Data = SuseRelease.get()->getBuffer(); |
| 1278 | if (Data.startswith("openSUSE 11.3")) |
| 1279 | return OpenSuse11_3; |
| 1280 | return UnknownDistro; |
| 1281 | } |
| 1282 | |
| 1283 | return UnknownDistro; |
| 1284 | } |
| 1285 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1286 | Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 1287 | : Generic_ELF(Host, Triple) { |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1288 | llvm::Triple::ArchType Arch = |
| 1289 | llvm::Triple(getDriver().DefaultHostTriple).getArch(); |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 1290 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1291 | std::string Suffix32 = ""; |
| 1292 | if (Arch == llvm::Triple::x86_64) |
| 1293 | Suffix32 = "/32"; |
Daniel Dunbar | a9822de | 2009-08-06 01:47:11 +0000 | [diff] [blame] | 1294 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1295 | std::string Suffix64 = ""; |
| 1296 | if (Arch == llvm::Triple::x86) |
| 1297 | Suffix64 = "/64"; |
| 1298 | |
| 1299 | std::string Lib32 = "lib"; |
| 1300 | |
| 1301 | if ( llvm::sys::Path("/lib32").exists()) |
| 1302 | Lib32 = "lib32"; |
| 1303 | |
| 1304 | std::string Lib64 = "lib"; |
| 1305 | llvm::sys::Path Lib64Path("/lib64"); |
| 1306 | if (Lib64Path.exists() && !Lib64Path.isSymLink()) |
| 1307 | Lib64 = "lib64"; |
| 1308 | |
| 1309 | std::string GccTriple = ""; |
| 1310 | if (Arch == llvm::Triple::arm) { |
| 1311 | if (llvm::sys::Path("/usr/lib/gcc/arm-linux-gnueabi").exists()) |
| 1312 | GccTriple = "arm-linux-gnueabi"; |
| 1313 | } else if (Arch == llvm::Triple::x86_64) { |
| 1314 | if (llvm::sys::Path("/usr/lib/gcc/x86_64-linux-gnu").exists()) |
| 1315 | GccTriple = "x86_64-linux-gnu"; |
| 1316 | else if (llvm::sys::Path("/usr/lib/gcc/x86_64-redhat-linux").exists()) |
| 1317 | GccTriple = "x86_64-redhat-linux"; |
| 1318 | else if (llvm::sys::Path("/usr/lib64/gcc/x86_64-suse-linux").exists()) |
| 1319 | GccTriple = "x86_64-suse-linux"; |
| 1320 | } else if (Arch == llvm::Triple::x86) { |
| 1321 | if (llvm::sys::Path("/usr/lib/gcc/i686-linux-gnu").exists()) |
| 1322 | GccTriple = "i686-linux-gnu"; |
| 1323 | else if (llvm::sys::Path("/usr/lib/gcc/i486-linux-gnu").exists()) |
| 1324 | GccTriple = "i486-linux-gnu"; |
| 1325 | else if (llvm::sys::Path("/usr/lib/gcc/i686-redhat-linux").exists()) |
| 1326 | GccTriple = "i686-redhat-linux"; |
| 1327 | else if (llvm::sys::Path("/usr/lib/gcc/i586-suse-linux").exists()) |
| 1328 | GccTriple = "i586-suse-linux"; |
| 1329 | } |
| 1330 | |
| 1331 | const char* GccVersions[] = {"4.5.1", "4.5", "4.4.5", "4.4.4", "4.4.3", |
| 1332 | "4.3.2"}; |
| 1333 | std::string Base = ""; |
| 1334 | for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) { |
| 1335 | std::string Suffix = GccTriple + "/" + GccVersions[i]; |
| 1336 | std::string t1 = "/usr/lib/gcc/" + Suffix; |
| 1337 | if (llvm::sys::Path(t1 + "/crtbegin.o").exists()) { |
| 1338 | Base = t1; |
| 1339 | break; |
| 1340 | } |
| 1341 | std::string t2 = "/usr/lib64/gcc/" + Suffix; |
| 1342 | if (llvm::sys::Path(t2 + "/crtbegin.o").exists()) { |
| 1343 | Base = t2; |
| 1344 | break; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | path_list &Paths = getFilePaths(); |
| 1349 | bool Is32Bits = getArch() == llvm::Triple::x86; |
| 1350 | |
| 1351 | std::string Suffix; |
| 1352 | std::string Lib; |
| 1353 | |
| 1354 | if (Is32Bits) { |
| 1355 | Suffix = Suffix32; |
| 1356 | Lib = Lib32; |
| 1357 | } else { |
| 1358 | Suffix = Suffix64; |
| 1359 | Lib = Lib64; |
| 1360 | } |
| 1361 | |
| 1362 | llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld"); |
| 1363 | if (LinkerPath.exists()) |
| 1364 | Linker = LinkerPath.str(); |
| 1365 | else |
| 1366 | Linker = GetProgramPath("ld"); |
| 1367 | |
| 1368 | LinuxDistro Distro = DetectLinuxDistro(Arch); |
| 1369 | |
Rafael Espindola | 94c8022 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 1370 | if (IsUbuntu(Distro)) { |
| 1371 | ExtraOpts.push_back("-z"); |
| 1372 | ExtraOpts.push_back("relro"); |
| 1373 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1374 | |
| 1375 | if (Arch == llvm::Triple::arm) |
| 1376 | ExtraOpts.push_back("-X"); |
| 1377 | |
| 1378 | if (IsFedora(Distro) || Distro == UbuntuMaverick) |
| 1379 | ExtraOpts.push_back("--hash-style=gnu"); |
| 1380 | |
| 1381 | if (IsDebian(Distro) || Distro == UbuntuLucid) |
| 1382 | ExtraOpts.push_back("--hash-style=both"); |
| 1383 | |
| 1384 | if (IsFedora(Distro)) |
| 1385 | ExtraOpts.push_back("--no-add-needed"); |
| 1386 | |
| 1387 | if (Distro == DebianSqueeze || IsUbuntu(Distro) || IsOpenSuse(Distro) || |
| 1388 | IsFedora(Distro)) |
| 1389 | ExtraOpts.push_back("--build-id"); |
| 1390 | |
| 1391 | Paths.push_back(Base + Suffix); |
| 1392 | if (HasMultilib(Arch, Distro)) { |
| 1393 | if (IsOpenSuse(Distro) && Is32Bits) |
| 1394 | Paths.push_back(Base + "/../../../../" + GccTriple + "/lib/../lib"); |
| 1395 | Paths.push_back(Base + "/../../../../" + Lib); |
| 1396 | Paths.push_back("/lib/../" + Lib); |
| 1397 | Paths.push_back("/usr/lib/../" + Lib); |
| 1398 | } |
| 1399 | if (!Suffix.empty()) |
| 1400 | Paths.push_back(Base); |
| 1401 | if (IsOpenSuse(Distro)) |
| 1402 | Paths.push_back(Base + "/../../../../" + GccTriple + "/lib"); |
| 1403 | Paths.push_back(Base + "/../../.."); |
| 1404 | if (Arch == getArch() && IsUbuntu(Distro)) |
| 1405 | Paths.push_back("/usr/lib/" + GccTriple); |
| 1406 | } |
| 1407 | |
| 1408 | bool Linux::HasNativeLLVMSupport() const { |
| 1409 | return true; |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1412 | Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 1413 | Action::ActionClass Key; |
| 1414 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1415 | Key = Action::AnalyzeJobClass; |
| 1416 | else |
| 1417 | Key = JA.getKind(); |
| 1418 | |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1419 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1420 | options::OPT_no_integrated_as, |
| 1421 | IsIntegratedAssemblerDefault()); |
| 1422 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1423 | Tool *&T = Tools[Key]; |
| 1424 | if (!T) { |
| 1425 | switch (Key) { |
| 1426 | case Action::AssembleJobClass: |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1427 | if (UseIntegratedAs) |
| 1428 | T = new tools::ClangAs(*this); |
| 1429 | else |
| 1430 | T = new tools::linuxtools::Assemble(*this); |
| 1431 | break; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1432 | case Action::LinkJobClass: |
| 1433 | T = new tools::linuxtools::Link(*this); break; |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 1434 | default: |
| 1435 | T = &Generic_GCC::SelectTool(C, JA); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | return *T; |
| 1440 | } |
| 1441 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1442 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 1443 | |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 1444 | DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) |
Rafael Espindola | e43cfa1 | 2010-10-29 20:14:02 +0000 | [diff] [blame] | 1445 | : Generic_ELF(Host, Triple) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1446 | |
| 1447 | // Path mangling to find libexec |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1448 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 1449 | if (getDriver().getInstalledDir() != getDriver().Dir.c_str()) |
| 1450 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1451 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1452 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1453 | getFilePaths().push_back("/usr/lib"); |
| 1454 | getFilePaths().push_back("/usr/lib/gcc41"); |
| 1455 | } |
| 1456 | |
| 1457 | Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 1458 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1459 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1460 | Key = Action::AnalyzeJobClass; |
| 1461 | else |
| 1462 | Key = JA.getKind(); |
| 1463 | |
| 1464 | Tool *&T = Tools[Key]; |
| 1465 | if (!T) { |
| 1466 | switch (Key) { |
| 1467 | case Action::AssembleJobClass: |
| 1468 | T = new tools::dragonfly::Assemble(*this); break; |
| 1469 | case Action::LinkJobClass: |
| 1470 | T = new tools::dragonfly::Link(*this); break; |
| 1471 | default: |
| 1472 | T = &Generic_GCC::SelectTool(C, JA); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | return *T; |
| 1477 | } |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 1478 | |
| 1479 | Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple) |
| 1480 | : ToolChain(Host, Triple) { |
| 1481 | } |
| 1482 | |
| 1483 | Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA) const { |
| 1484 | Action::ActionClass Key; |
| 1485 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1486 | Key = Action::AnalyzeJobClass; |
| 1487 | else |
| 1488 | Key = JA.getKind(); |
| 1489 | |
| 1490 | Tool *&T = Tools[Key]; |
| 1491 | if (!T) { |
| 1492 | switch (Key) { |
| 1493 | case Action::InputClass: |
| 1494 | case Action::BindArchClass: |
Chandler Carruth | e97673f | 2010-08-22 06:56:37 +0000 | [diff] [blame] | 1495 | case Action::LipoJobClass: |
| 1496 | case Action::DsymutilJobClass: |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 1497 | assert(0 && "Invalid tool kind."); |
| 1498 | case Action::PreprocessJobClass: |
| 1499 | case Action::PrecompileJobClass: |
| 1500 | case Action::AnalyzeJobClass: |
| 1501 | case Action::CompileJobClass: |
| 1502 | T = new tools::Clang(*this); break; |
| 1503 | case Action::AssembleJobClass: |
| 1504 | T = new tools::ClangAs(*this); break; |
| 1505 | case Action::LinkJobClass: |
| 1506 | T = new tools::visualstudio::Link(*this); break; |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | return *T; |
| 1511 | } |
| 1512 | |
| 1513 | bool Windows::IsIntegratedAssemblerDefault() const { |
| 1514 | return true; |
| 1515 | } |
| 1516 | |
| 1517 | bool Windows::IsUnwindTablesDefault() const { |
| 1518 | // FIXME: Gross; we should probably have some separate target |
| 1519 | // definition, possibly even reusing the one in clang. |
| 1520 | return getArchName() == "x86_64"; |
| 1521 | } |
| 1522 | |
| 1523 | const char *Windows::GetDefaultRelocationModel() const { |
| 1524 | return "static"; |
| 1525 | } |
| 1526 | |
| 1527 | const char *Windows::GetForcedPicModel() const { |
| 1528 | if (getArchName() == "x86_64") |
| 1529 | return "pic"; |
| 1530 | return 0; |
| 1531 | } |