Nick Lewycky | 3fdcc6f | 2010-12-31 17:31:54 +0000 | [diff] [blame] | 1 | //===--- ToolChains.cpp - ToolChain Implementations -----------------------===// |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 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" |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 17 | #include "clang/Driver/ObjCRuntime.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" |
Bob Wilson | a59956b | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringSwitch.h" |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 27 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 28 | #include "llvm/Support/FileSystem.h" |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 29 | #include "llvm/Support/MemoryBuffer.h" |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 30 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 32 | #include "llvm/Support/system_error.h" |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 33 | |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 34 | #include <cstdlib> // ::getenv |
| 35 | |
Dylan Noblesmith | cc8a945 | 2012-02-14 15:54:49 +0000 | [diff] [blame] | 36 | #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX |
Dylan Noblesmith | 89bb614 | 2011-06-23 13:50:47 +0000 | [diff] [blame] | 37 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 38 | using namespace clang::driver; |
| 39 | using namespace clang::driver::toolchains; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 40 | using namespace clang; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 41 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 42 | /// Darwin - Darwin tool chain for i386 and x86_64. |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 43 | |
Chandler Carruth | 1d16f0f | 2012-01-31 02:21:20 +0000 | [diff] [blame] | 44 | Darwin::Darwin(const Driver &D, const llvm::Triple& Triple) |
| 45 | : ToolChain(D, Triple), TargetInitialized(false), |
Bob Wilson | 163b151 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 46 | ARCRuntimeForSimulator(ARCSimulator_None), |
| 47 | LibCXXForSimulator(LibCXXSimulator_None) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 48 | { |
Bob Wilson | 1085377 | 2012-01-31 21:30:03 +0000 | [diff] [blame] | 49 | // Compute the initial Darwin version from the triple |
| 50 | unsigned Major, Minor, Micro; |
Bob Wilson | 4c5ffb3 | 2012-01-31 22:43:59 +0000 | [diff] [blame] | 51 | if (!Triple.getMacOSXVersion(Major, Minor, Micro)) |
| 52 | getDriver().Diag(diag::err_drv_invalid_darwin_version) << |
| 53 | Triple.getOSName(); |
| 54 | llvm::raw_string_ostream(MacosxVersionMin) |
| 55 | << Major << '.' << Minor << '.' << Micro; |
| 56 | |
Bob Wilson | 1085377 | 2012-01-31 21:30:03 +0000 | [diff] [blame] | 57 | // FIXME: DarwinVersion is only used to find GCC's libexec directory. |
| 58 | // It should be removed when we stop supporting that. |
| 59 | DarwinVersion[0] = Minor + 4; |
| 60 | DarwinVersion[1] = Micro; |
| 61 | DarwinVersion[2] = 0; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Daniel Dunbar | 4180011 | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 64 | types::ID Darwin::LookupTypeForExtension(const char *Ext) const { |
| 65 | types::ID Ty = types::lookupTypeForExtension(Ext); |
| 66 | |
| 67 | // Darwin always preprocesses assembly files (unless -x is used explicitly). |
| 68 | if (Ty == types::TY_PP_Asm) |
| 69 | return types::TY_Asm; |
| 70 | |
| 71 | return Ty; |
| 72 | } |
| 73 | |
Daniel Dunbar | b993f5d | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 74 | bool Darwin::HasNativeLLVMSupport() const { |
| 75 | return true; |
| 76 | } |
| 77 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 78 | bool Darwin::hasARCRuntime() const { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 79 | // FIXME: Remove this once there is a proper way to detect an ARC runtime |
| 80 | // for the simulator. |
| 81 | switch (ARCRuntimeForSimulator) { |
| 82 | case ARCSimulator_None: |
| 83 | break; |
| 84 | case ARCSimulator_HasARCRuntime: |
| 85 | return true; |
| 86 | case ARCSimulator_NoARCRuntime: |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | if (isTargetIPhoneOS()) |
| 91 | return !isIPhoneOSVersionLT(5); |
| 92 | else |
| 93 | return !isMacosxVersionLT(10, 7); |
| 94 | } |
| 95 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 96 | bool Darwin::hasSubscriptingRuntime() const { |
| 97 | return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 8); |
| 98 | } |
| 99 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 100 | /// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. |
| 101 | void Darwin::configureObjCRuntime(ObjCRuntime &runtime) const { |
| 102 | if (runtime.getKind() != ObjCRuntime::NeXT) |
| 103 | return ToolChain::configureObjCRuntime(runtime); |
| 104 | |
| 105 | runtime.HasARC = runtime.HasWeak = hasARCRuntime(); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 106 | runtime.HasSubscripting = hasSubscriptingRuntime(); |
John McCall | 256a76e | 2011-07-06 01:22:26 +0000 | [diff] [blame] | 107 | |
| 108 | // So far, objc_terminate is only available in iOS 5. |
| 109 | // FIXME: do the simulator logic properly. |
| 110 | if (!ARCRuntimeForSimulator && isTargetIPhoneOS()) |
| 111 | runtime.HasTerminate = !isIPhoneOSVersionLT(5); |
| 112 | else |
| 113 | runtime.HasTerminate = false; |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 114 | } |
| 115 | |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 116 | /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. |
| 117 | bool Darwin::hasBlocksRuntime() const { |
| 118 | if (isTargetIPhoneOS()) |
| 119 | return !isIPhoneOSVersionLT(3, 2); |
| 120 | else |
| 121 | return !isMacosxVersionLT(10, 6); |
| 122 | } |
| 123 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 124 | static const char *GetArmArchForMArch(StringRef Value) { |
Bob Wilson | a59956b | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 125 | return llvm::StringSwitch<const char*>(Value) |
| 126 | .Case("armv6k", "armv6") |
| 127 | .Case("armv5tej", "armv5") |
| 128 | .Case("xscale", "xscale") |
| 129 | .Case("armv4t", "armv4t") |
| 130 | .Case("armv7", "armv7") |
| 131 | .Cases("armv7a", "armv7-a", "armv7") |
| 132 | .Cases("armv7r", "armv7-r", "armv7") |
| 133 | .Cases("armv7m", "armv7-m", "armv7") |
| 134 | .Default(0); |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 137 | static const char *GetArmArchForMCpu(StringRef Value) { |
Bob Wilson | a59956b | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 138 | return llvm::StringSwitch<const char *>(Value) |
| 139 | .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "arm926ej-s","armv5") |
| 140 | .Cases("arm10e", "arm10tdmi", "armv5") |
| 141 | .Cases("arm1020t", "arm1020e", "arm1022e", "arm1026ej-s", "armv5") |
| 142 | .Case("xscale", "xscale") |
| 143 | .Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", |
| 144 | "arm1176jzf-s", "cortex-m0", "armv6") |
| 145 | .Cases("cortex-a8", "cortex-r4", "cortex-m3", "cortex-a9", "armv7") |
| 146 | .Default(0); |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 149 | StringRef Darwin::getDarwinArchName(const ArgList &Args) const { |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 150 | switch (getTriple().getArch()) { |
| 151 | default: |
| 152 | return getArchName(); |
NAKAMURA Takumi | 304ed3f | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 153 | |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 154 | case llvm::Triple::thumb: |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 155 | case llvm::Triple::arm: { |
| 156 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
| 157 | if (const char *Arch = GetArmArchForMArch(A->getValue(Args))) |
| 158 | return Arch; |
| 159 | |
| 160 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
| 161 | if (const char *Arch = GetArmArchForMCpu(A->getValue(Args))) |
| 162 | return Arch; |
| 163 | |
| 164 | return "arm"; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 169 | Darwin::~Darwin() { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 170 | // Free tool implementations. |
| 171 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 172 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 173 | delete it->second; |
| 174 | } |
| 175 | |
Chad Rosier | 61ab80a | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 176 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, |
| 177 | types::ID InputType) const { |
| 178 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 179 | |
| 180 | // If the target isn't initialized (e.g., an unknown Darwin platform, return |
| 181 | // the default triple). |
| 182 | if (!isTargetInitialized()) |
| 183 | return Triple.getTriple(); |
NAKAMURA Takumi | 304ed3f | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 184 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 185 | unsigned Version[3]; |
| 186 | getTargetVersion(Version); |
NAKAMURA Takumi | 304ed3f | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 187 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 188 | SmallString<16> Str; |
Daniel Dunbar | 729f38e | 2011-04-19 21:45:47 +0000 | [diff] [blame] | 189 | llvm::raw_svector_ostream(Str) |
Daniel Dunbar | 659d23a | 2011-04-19 23:34:17 +0000 | [diff] [blame] | 190 | << (isTargetIPhoneOS() ? "ios" : "macosx") |
Daniel Dunbar | 729f38e | 2011-04-19 21:45:47 +0000 | [diff] [blame] | 191 | << Version[0] << "." << Version[1] << "." << Version[2]; |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 192 | Triple.setOSName(Str.str()); |
| 193 | |
| 194 | return Triple.getTriple(); |
| 195 | } |
| 196 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 197 | void Generic_ELF::anchor() {} |
| 198 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 199 | Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA, |
| 200 | const ActionList &Inputs) const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 201 | Action::ActionClass Key; |
Daniel Dunbar | 5ce872f | 2011-03-18 20:14:03 +0000 | [diff] [blame] | 202 | |
| 203 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) { |
| 204 | // Fallback to llvm-gcc for i386 kext compiles, we don't support that ABI. |
| 205 | if (Inputs.size() == 1 && |
| 206 | types::isCXX(Inputs[0]->getType()) && |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 207 | getTriple().isOSDarwin() && |
Daniel Dunbar | 5ce872f | 2011-03-18 20:14:03 +0000 | [diff] [blame] | 208 | getTriple().getArch() == llvm::Triple::x86 && |
Bob Wilson | a544aee | 2011-08-13 23:48:55 +0000 | [diff] [blame] | 209 | (C.getArgs().getLastArg(options::OPT_fapple_kext) || |
| 210 | C.getArgs().getLastArg(options::OPT_mkernel))) |
Daniel Dunbar | 5ce872f | 2011-03-18 20:14:03 +0000 | [diff] [blame] | 211 | Key = JA.getKind(); |
| 212 | else |
| 213 | Key = Action::AnalyzeJobClass; |
| 214 | } else |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 215 | Key = JA.getKind(); |
| 216 | |
Daniel Dunbar | 0f602de | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 217 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 218 | options::OPT_no_integrated_as, |
Bob Wilson | 1a1764b | 2011-10-30 00:20:28 +0000 | [diff] [blame] | 219 | IsIntegratedAssemblerDefault()); |
Daniel Dunbar | 0f602de | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 220 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 221 | Tool *&T = Tools[Key]; |
| 222 | if (!T) { |
| 223 | switch (Key) { |
| 224 | case Action::InputClass: |
| 225 | case Action::BindArchClass: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 226 | llvm_unreachable("Invalid tool kind."); |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 227 | case Action::PreprocessJobClass: |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 228 | T = new tools::darwin::Preprocess(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 229 | case Action::AnalyzeJobClass: |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 230 | case Action::MigrateJobClass: |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 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; |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 248 | case Action::VerifyJobClass: |
| 249 | T = new tools::darwin::VerifyDebug(*this); break; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
| 253 | return *T; |
| 254 | } |
| 255 | |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 256 | |
Chandler Carruth | 1d16f0f | 2012-01-31 02:21:20 +0000 | [diff] [blame] | 257 | DarwinClang::DarwinClang(const Driver &D, const llvm::Triple& Triple) |
| 258 | : Darwin(D, Triple) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 259 | { |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 260 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 261 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 262 | getProgramPaths().push_back(getDriver().Dir); |
| 263 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 264 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 265 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 266 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 267 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 268 | |
| 269 | // For fallback, we need to know how to find the GCC cc1 executables, so we |
Daniel Dunbar | 4702309 | 2011-03-18 19:25:15 +0000 | [diff] [blame] | 270 | // also add the GCC libexec paths. This is legacy code that can be removed |
| 271 | // once fallback is no longer useful. |
Bob Wilson | 8aa76ea | 2011-09-20 22:00:38 +0000 | [diff] [blame] | 272 | AddGCCLibexecPath(DarwinVersion[0]); |
| 273 | AddGCCLibexecPath(DarwinVersion[0] - 2); |
| 274 | AddGCCLibexecPath(DarwinVersion[0] - 1); |
| 275 | AddGCCLibexecPath(DarwinVersion[0] + 1); |
| 276 | AddGCCLibexecPath(DarwinVersion[0] + 2); |
| 277 | } |
| 278 | |
| 279 | void DarwinClang::AddGCCLibexecPath(unsigned darwinVersion) { |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 280 | std::string ToolChainDir = "i686-apple-darwin"; |
Bob Wilson | 8aa76ea | 2011-09-20 22:00:38 +0000 | [diff] [blame] | 281 | ToolChainDir += llvm::utostr(darwinVersion); |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 282 | ToolChainDir += "/4.2.1"; |
| 283 | |
| 284 | std::string Path = getDriver().Dir; |
Bob Wilson | 8aa76ea | 2011-09-20 22:00:38 +0000 | [diff] [blame] | 285 | Path += "/../llvm-gcc-4.2/libexec/gcc/"; |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 286 | Path += ToolChainDir; |
| 287 | getProgramPaths().push_back(Path); |
| 288 | |
Bob Wilson | 8aa76ea | 2011-09-20 22:00:38 +0000 | [diff] [blame] | 289 | Path = "/usr/llvm-gcc-4.2/libexec/gcc/"; |
Daniel Dunbar | 0e50ee4 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 290 | Path += ToolChainDir; |
| 291 | getProgramPaths().push_back(Path); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, |
| 295 | ArgStringList &CmdArgs) const { |
| 296 | // The Clang toolchain uses explicit paths for internal libraries. |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 297 | |
| 298 | // Unfortunately, we still might depend on a few of the libraries that are |
| 299 | // only available in the gcc library directory (in particular |
| 300 | // libstdc++.dylib). For now, hardcode the path to the known install location. |
Bob Wilson | 5a5dcdc | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 301 | // FIXME: This should get ripped out someday. However, when building on |
| 302 | // 10.6 (darwin10), we're still relying on this to find libstdc++.dylib. |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 303 | llvm::sys::Path P(getDriver().Dir); |
| 304 | P.eraseComponent(); // .../usr/bin -> ../usr |
Bob Wilson | 5a5dcdc | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 305 | P.appendComponent("llvm-gcc-4.2"); |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 306 | P.appendComponent("lib"); |
| 307 | P.appendComponent("gcc"); |
| 308 | switch (getTriple().getArch()) { |
| 309 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 310 | llvm_unreachable("Invalid Darwin arch!"); |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 311 | case llvm::Triple::x86: |
| 312 | case llvm::Triple::x86_64: |
| 313 | P.appendComponent("i686-apple-darwin10"); |
| 314 | break; |
| 315 | case llvm::Triple::arm: |
| 316 | case llvm::Triple::thumb: |
| 317 | P.appendComponent("arm-apple-darwin10"); |
| 318 | break; |
| 319 | case llvm::Triple::ppc: |
| 320 | case llvm::Triple::ppc64: |
| 321 | P.appendComponent("powerpc-apple-darwin10"); |
| 322 | break; |
| 323 | } |
| 324 | P.appendComponent("4.2.1"); |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 325 | |
| 326 | // Determine the arch specific GCC subdirectory. |
| 327 | const char *ArchSpecificDir = 0; |
| 328 | switch (getTriple().getArch()) { |
| 329 | default: |
| 330 | break; |
| 331 | case llvm::Triple::arm: |
Daniel Dunbar | 3a0e392 | 2010-08-26 00:55:52 +0000 | [diff] [blame] | 332 | case llvm::Triple::thumb: { |
| 333 | std::string Triple = ComputeLLVMTriple(Args); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 334 | StringRef TripleStr = Triple; |
Daniel Dunbar | 3a0e392 | 2010-08-26 00:55:52 +0000 | [diff] [blame] | 335 | if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5")) |
| 336 | ArchSpecificDir = "v5"; |
| 337 | else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6")) |
| 338 | ArchSpecificDir = "v6"; |
| 339 | else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7")) |
| 340 | ArchSpecificDir = "v7"; |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 341 | break; |
Daniel Dunbar | 3a0e392 | 2010-08-26 00:55:52 +0000 | [diff] [blame] | 342 | } |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 343 | case llvm::Triple::ppc64: |
| 344 | ArchSpecificDir = "ppc64"; |
| 345 | break; |
| 346 | case llvm::Triple::x86_64: |
| 347 | ArchSpecificDir = "x86_64"; |
| 348 | break; |
| 349 | } |
| 350 | |
| 351 | if (ArchSpecificDir) { |
| 352 | P.appendComponent(ArchSpecificDir); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 353 | bool Exists; |
| 354 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Daniel Dunbar | eab3bc4 | 2010-08-23 20:58:52 +0000 | [diff] [blame] | 355 | CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); |
| 356 | P.eraseComponent(); |
| 357 | } |
| 358 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 359 | bool Exists; |
| 360 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Daniel Dunbar | 424b661 | 2010-06-30 23:56:13 +0000 | [diff] [blame] | 361 | CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 362 | } |
| 363 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 364 | void DarwinClang::AddLinkARCArgs(const ArgList &Args, |
| 365 | ArgStringList &CmdArgs) const { |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 366 | |
| 367 | CmdArgs.push_back("-force_load"); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 368 | llvm::sys::Path P(getDriver().ClangExecutable); |
| 369 | P.eraseComponent(); // 'clang' |
| 370 | P.eraseComponent(); // 'bin' |
| 371 | P.appendComponent("lib"); |
| 372 | P.appendComponent("arc"); |
| 373 | P.appendComponent("libarclite_"); |
| 374 | std::string s = P.str(); |
| 375 | // Mash in the platform. |
Argyrios Kyrtzidis | c19981c | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 376 | if (isTargetIOSSimulator()) |
| 377 | s += "iphonesimulator"; |
| 378 | else if (isTargetIPhoneOS()) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 379 | s += "iphoneos"; |
Argyrios Kyrtzidis | c19981c | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 380 | // FIXME: Remove this once we depend fully on -mios-simulator-version-min. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 381 | else if (ARCRuntimeForSimulator != ARCSimulator_None) |
| 382 | s += "iphonesimulator"; |
| 383 | else |
| 384 | s += "macosx"; |
| 385 | s += ".a"; |
| 386 | |
| 387 | CmdArgs.push_back(Args.MakeArgString(s)); |
| 388 | } |
| 389 | |
Eric Christopher | 3404fe7 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 390 | void DarwinClang::AddLinkRuntimeLib(const ArgList &Args, |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 391 | ArgStringList &CmdArgs, |
Eric Christopher | 3404fe7 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 392 | const char *DarwinStaticLib) const { |
| 393 | llvm::sys::Path P(getDriver().ResourceDir); |
| 394 | P.appendComponent("lib"); |
| 395 | P.appendComponent("darwin"); |
| 396 | P.appendComponent(DarwinStaticLib); |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 397 | |
Eric Christopher | 3404fe7 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 398 | // For now, allow missing resource libraries to support developers who may |
| 399 | // not have compiler-rt checked out or integrated into their build. |
| 400 | bool Exists; |
| 401 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
| 402 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 403 | } |
| 404 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 405 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 406 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | c24767c | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 407 | // Darwin only supports the compiler-rt based runtime libraries. |
| 408 | switch (GetRuntimeLibType(Args)) { |
| 409 | case ToolChain::RLT_CompilerRT: |
| 410 | break; |
| 411 | default: |
| 412 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) |
| 413 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue(Args) << "darwin"; |
| 414 | return; |
| 415 | } |
| 416 | |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 417 | // Darwin doesn't support real static executables, don't link any runtime |
| 418 | // libraries with -static. |
| 419 | if (Args.hasArg(options::OPT_static)) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 420 | return; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 421 | |
| 422 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 423 | // cares. This is useful in situations where someone wants to statically link |
| 424 | // something like libstdc++, and needs its runtime support routines. |
| 425 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 426 | getDriver().Diag(diag::err_drv_unsupported_opt) |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 427 | << A->getAsString(Args); |
| 428 | return; |
| 429 | } |
| 430 | |
Daniel Dunbar | f471487 | 2011-11-17 00:36:57 +0000 | [diff] [blame] | 431 | // If we are building profile support, link that library in. |
| 432 | if (Args.hasArg(options::OPT_fprofile_arcs) || |
| 433 | Args.hasArg(options::OPT_fprofile_generate) || |
| 434 | Args.hasArg(options::OPT_fcreate_profile) || |
| 435 | Args.hasArg(options::OPT_coverage)) { |
| 436 | // Select the appropriate runtime library for the target. |
| 437 | if (isTargetIPhoneOS()) { |
| 438 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a"); |
| 439 | } else { |
| 440 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a"); |
| 441 | } |
| 442 | } |
| 443 | |
Kostya Serebryany | 7b5f101 | 2011-12-06 19:18:44 +0000 | [diff] [blame] | 444 | // Add ASAN runtime library, if required. Dynamic libraries and bundles |
| 445 | // should not be linked with the runtime library. |
Daniel Dunbar | 94b54ea | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 446 | if (Args.hasFlag(options::OPT_faddress_sanitizer, |
| 447 | options::OPT_fno_address_sanitizer, false)) { |
Kostya Serebryany | 7b5f101 | 2011-12-06 19:18:44 +0000 | [diff] [blame] | 448 | if (Args.hasArg(options::OPT_dynamiclib) || |
| 449 | Args.hasArg(options::OPT_bundle)) return; |
Daniel Dunbar | 94b54ea | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 450 | if (isTargetIPhoneOS()) { |
| 451 | getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) |
| 452 | << "-faddress-sanitizer"; |
| 453 | } else { |
| 454 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.asan_osx.a"); |
| 455 | |
| 456 | // The ASAN runtime library requires C++ and CoreFoundation. |
| 457 | AddCXXStdlibLibArgs(Args, CmdArgs); |
| 458 | CmdArgs.push_back("-framework"); |
| 459 | CmdArgs.push_back("CoreFoundation"); |
| 460 | } |
| 461 | } |
| 462 | |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 463 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 464 | // target specific static runtime library. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 465 | CmdArgs.push_back("-lSystem"); |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 466 | |
| 467 | // Select the dynamic runtime library and the target specific static library. |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 468 | if (isTargetIPhoneOS()) { |
Daniel Dunbar | 87e945f | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 469 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, |
| 470 | // it never went into the SDK. |
Bob Wilson | 163b151 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 471 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ |
| 472 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator()) |
| 473 | CmdArgs.push_back("-lgcc_s.1"); |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 474 | |
Daniel Dunbar | 3cceec5 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 475 | // We currently always need a static runtime library for iOS. |
Eric Christopher | 3404fe7 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 476 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 477 | } else { |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 478 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 479 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 480 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 481 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 482 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 483 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 484 | |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 485 | // For OS X, we thought we would only need a static runtime library when |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 486 | // targeting 10.4, to provide versions of the static functions which were |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 487 | // omitted from 10.4.dylib. |
| 488 | // |
| 489 | // Unfortunately, that turned out to not be true, because Darwin system |
| 490 | // headers can still use eprintf on i386, and it is not exported from |
| 491 | // libSystem. Therefore, we still must provide a runtime library just for |
| 492 | // the tiny tiny handful of projects that *might* use that symbol. |
| 493 | if (isMacosxVersionLT(10, 5)) { |
Eric Christopher | 3404fe7 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 494 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 495 | } else { |
| 496 | if (getTriple().getArch() == llvm::Triple::x86) |
Eric Christopher | 3404fe7 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 497 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); |
| 498 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 499 | } |
Daniel Dunbar | eec9910 | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 500 | } |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Argyrios Kyrtzidis | dceb11f | 2011-10-18 00:22:49 +0000 | [diff] [blame] | 503 | static inline StringRef SimulatorVersionDefineName() { |
| 504 | return "__IPHONE_OS_VERSION_MIN_REQUIRED"; |
| 505 | } |
| 506 | |
| 507 | /// \brief Parse the simulator version define: |
| 508 | /// __IPHONE_OS_VERSION_MIN_REQUIRED=([0-9])([0-9][0-9])([0-9][0-9]) |
| 509 | // and return the grouped values as integers, e.g: |
| 510 | // __IPHONE_OS_VERSION_MIN_REQUIRED=40201 |
| 511 | // will return Major=4, Minor=2, Micro=1. |
| 512 | static bool GetVersionFromSimulatorDefine(StringRef define, |
| 513 | unsigned &Major, unsigned &Minor, |
| 514 | unsigned &Micro) { |
| 515 | assert(define.startswith(SimulatorVersionDefineName())); |
| 516 | StringRef name, version; |
| 517 | llvm::tie(name, version) = define.split('='); |
| 518 | if (version.empty()) |
| 519 | return false; |
| 520 | std::string verstr = version.str(); |
| 521 | char *end; |
| 522 | unsigned num = (unsigned) strtol(verstr.c_str(), &end, 10); |
| 523 | if (*end != '\0') |
| 524 | return false; |
| 525 | Major = num / 10000; |
| 526 | num = num % 10000; |
| 527 | Minor = num / 100; |
| 528 | Micro = num % 100; |
| 529 | return true; |
| 530 | } |
| 531 | |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 532 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 533 | const OptTable &Opts = getDriver().getOpts(); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 534 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 535 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 536 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
| 537 | Arg *iOSSimVersion = Args.getLastArg( |
| 538 | options::OPT_mios_simulator_version_min_EQ); |
Eli Friedman | 983d835 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 539 | |
Bob Wilson | c01dfc1 | 2012-01-26 03:37:03 +0000 | [diff] [blame] | 540 | // FIXME: HACK! When compiling for the simulator we don't get a |
| 541 | // '-miphoneos-version-min' to help us know whether there is an ARC runtime |
| 542 | // or not; try to parse a __IPHONE_OS_VERSION_MIN_REQUIRED |
| 543 | // define passed in command-line. |
| 544 | if (!iOSVersion && !iOSSimVersion) { |
| 545 | for (arg_iterator it = Args.filtered_begin(options::OPT_D), |
| 546 | ie = Args.filtered_end(); it != ie; ++it) { |
| 547 | StringRef define = (*it)->getValue(Args); |
| 548 | if (define.startswith(SimulatorVersionDefineName())) { |
| 549 | unsigned Major = 0, Minor = 0, Micro = 0; |
| 550 | if (GetVersionFromSimulatorDefine(define, Major, Minor, Micro) && |
| 551 | Major < 10 && Minor < 100 && Micro < 100) { |
| 552 | ARCRuntimeForSimulator = Major < 5 ? ARCSimulator_NoARCRuntime |
| 553 | : ARCSimulator_HasARCRuntime; |
| 554 | LibCXXForSimulator = Major < 5 ? LibCXXSimulator_NotAvailable |
| 555 | : LibCXXSimulator_Available; |
| 556 | } |
| 557 | break; |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 562 | if (OSXVersion && (iOSVersion || iOSSimVersion)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 563 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 564 | << OSXVersion->getAsString(Args) |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 565 | << (iOSVersion ? iOSVersion : iOSSimVersion)->getAsString(Args); |
| 566 | iOSVersion = iOSSimVersion = 0; |
| 567 | } else if (iOSVersion && iOSSimVersion) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 568 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 569 | << iOSVersion->getAsString(Args) |
| 570 | << iOSSimVersion->getAsString(Args); |
| 571 | iOSSimVersion = 0; |
| 572 | } else if (!OSXVersion && !iOSVersion && !iOSSimVersion) { |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 573 | // If no deployment target was specified on the command line, check for |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 574 | // environment defines. |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 575 | StringRef OSXTarget; |
| 576 | StringRef iOSTarget; |
| 577 | StringRef iOSSimTarget; |
| 578 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) |
| 579 | OSXTarget = env; |
| 580 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) |
| 581 | iOSTarget = env; |
| 582 | if (char *env = ::getenv("IOS_SIMULATOR_DEPLOYMENT_TARGET")) |
| 583 | iOSSimTarget = env; |
Daniel Dunbar | f36a06a | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 584 | |
NAKAMURA Takumi | a789ca9 | 2011-10-08 11:31:46 +0000 | [diff] [blame] | 585 | // If no '-miphoneos-version-min' specified on the command line and |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 586 | // IPHONEOS_DEPLOYMENT_TARGET is not defined, see if we can set the default |
| 587 | // based on isysroot. |
| 588 | if (iOSTarget.empty()) { |
| 589 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 590 | StringRef first, second; |
| 591 | StringRef isysroot = A->getValue(Args); |
| 592 | llvm::tie(first, second) = isysroot.split(StringRef("SDKs/iPhoneOS")); |
| 593 | if (second != "") |
| 594 | iOSTarget = second.substr(0,3); |
| 595 | } |
| 596 | } |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 597 | |
Chad Rosier | 4f8de27 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 598 | // If no OSX or iOS target has been specified and we're compiling for armv7, |
| 599 | // go ahead as assume we're targeting iOS. |
| 600 | if (OSXTarget.empty() && iOSTarget.empty()) |
| 601 | if (getDarwinArchName(Args) == "armv7") |
| 602 | iOSTarget = "0.0"; |
| 603 | |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 604 | // Handle conflicting deployment targets |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 605 | // |
| 606 | // FIXME: Don't hardcode default here. |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 607 | |
| 608 | // Do not allow conflicts with the iOS simulator target. |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 609 | if (!iOSSimTarget.empty() && (!OSXTarget.empty() || !iOSTarget.empty())) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 610 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 611 | << "IOS_SIMULATOR_DEPLOYMENT_TARGET" |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 612 | << (!OSXTarget.empty() ? "MACOSX_DEPLOYMENT_TARGET" : |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 613 | "IPHONEOS_DEPLOYMENT_TARGET"); |
| 614 | } |
| 615 | |
| 616 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 617 | // default platform. |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 618 | if (!OSXTarget.empty() && !iOSTarget.empty()) { |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 619 | if (getTriple().getArch() == llvm::Triple::arm || |
| 620 | getTriple().getArch() == llvm::Triple::thumb) |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 621 | OSXTarget = ""; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 622 | else |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 623 | iOSTarget = ""; |
Daniel Dunbar | 3905367 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 624 | } |
Daniel Dunbar | 1a3c1d9 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 625 | |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 626 | if (!OSXTarget.empty()) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 627 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 628 | OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget); |
| 629 | Args.append(OSXVersion); |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 630 | } else if (!iOSTarget.empty()) { |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 631 | const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 632 | iOSVersion = Args.MakeJoinedArg(0, O, iOSTarget); |
| 633 | Args.append(iOSVersion); |
Chad Rosier | a488497 | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 634 | } else if (!iOSSimTarget.empty()) { |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 635 | const Option *O = Opts.getOption( |
| 636 | options::OPT_mios_simulator_version_min_EQ); |
| 637 | iOSSimVersion = Args.MakeJoinedArg(0, O, iOSSimTarget); |
| 638 | Args.append(iOSSimVersion); |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 639 | } else { |
Daniel Dunbar | 2bb38d0 | 2010-07-15 16:18:06 +0000 | [diff] [blame] | 640 | // Otherwise, assume we are targeting OS X. |
| 641 | const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 642 | OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin); |
| 643 | Args.append(OSXVersion); |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 644 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 645 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | |
Daniel Dunbar | 3fd823b | 2011-04-30 04:20:40 +0000 | [diff] [blame] | 647 | // Reject invalid architecture combinations. |
| 648 | if (iOSSimVersion && (getTriple().getArch() != llvm::Triple::x86 && |
| 649 | getTriple().getArch() != llvm::Triple::x86_64)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 650 | getDriver().Diag(diag::err_drv_invalid_arch_for_deployment_target) |
Daniel Dunbar | 3fd823b | 2011-04-30 04:20:40 +0000 | [diff] [blame] | 651 | << getTriple().getArchName() << iOSSimVersion->getAsString(Args); |
| 652 | } |
| 653 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 654 | // Set the tool chain target information. |
| 655 | unsigned Major, Minor, Micro; |
| 656 | bool HadExtra; |
| 657 | if (OSXVersion) { |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 658 | assert((!iOSVersion && !iOSSimVersion) && "Unknown target platform!"); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 659 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor, |
| 660 | Micro, HadExtra) || HadExtra || |
Daniel Dunbar | 8a3a7f3 | 2011-04-21 21:27:33 +0000 | [diff] [blame] | 661 | Major != 10 || Minor >= 100 || Micro >= 100) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 662 | getDriver().Diag(diag::err_drv_invalid_version_number) |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 663 | << OSXVersion->getAsString(Args); |
| 664 | } else { |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 665 | const Arg *Version = iOSVersion ? iOSVersion : iOSSimVersion; |
| 666 | assert(Version && "Unknown target platform!"); |
Eli Friedman | 983d835 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 667 | if (!Driver::GetReleaseVersion(Version->getValue(Args), Major, Minor, |
| 668 | Micro, HadExtra) || HadExtra || |
| 669 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 670 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 671 | << Version->getAsString(Args); |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 672 | } |
Daniel Dunbar | 9d609f2 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 673 | |
Daniel Dunbar | 5f5c37b | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 674 | bool IsIOSSim = bool(iOSSimVersion); |
| 675 | |
| 676 | // In GCC, the simulator historically was treated as being OS X in some |
| 677 | // contexts, like determining the link logic, despite generally being called |
| 678 | // with an iOS deployment target. For compatibility, we detect the |
| 679 | // simulator as iOS + x86, and treat it differently in a few contexts. |
| 680 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 681 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 682 | IsIOSSim = true; |
| 683 | |
| 684 | setTarget(/*IsIPhoneOS=*/ !OSXVersion, Major, Minor, Micro, IsIOSSim); |
Daniel Dunbar | c0e665e | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 687 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 688 | ArgStringList &CmdArgs) const { |
| 689 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 690 | |
| 691 | switch (Type) { |
| 692 | case ToolChain::CST_Libcxx: |
| 693 | CmdArgs.push_back("-lc++"); |
| 694 | break; |
| 695 | |
| 696 | case ToolChain::CST_Libstdcxx: { |
| 697 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 698 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 699 | // platforms we care about it was -lstdc++.6, so we search for that |
| 700 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 701 | |
| 702 | // Check in the sysroot first. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 703 | bool Exists; |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 704 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 705 | llvm::sys::Path P(A->getValue(Args)); |
| 706 | P.appendComponent("usr"); |
| 707 | P.appendComponent("lib"); |
| 708 | P.appendComponent("libstdc++.dylib"); |
| 709 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 710 | if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) { |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 711 | P.eraseComponent(); |
| 712 | P.appendComponent("libstdc++.6.dylib"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 713 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 714 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 715 | return; |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | // Otherwise, look in the root. |
Bob Wilson | 5a5dcdc | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 721 | // FIXME: This should be removed someday when we don't have to care about |
| 722 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 723 | if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&& |
| 724 | (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){ |
Daniel Dunbar | efe91ea | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 725 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 726 | return; |
| 727 | } |
| 728 | |
| 729 | // Otherwise, let the linker search. |
| 730 | CmdArgs.push_back("-lstdc++"); |
| 731 | break; |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 736 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 737 | ArgStringList &CmdArgs) const { |
| 738 | |
| 739 | // For Darwin platforms, use the compiler-rt-based support library |
| 740 | // instead of the gcc-provided one (which is also incidentally |
| 741 | // only present in the gcc lib dir, which makes it hard to find). |
| 742 | |
| 743 | llvm::sys::Path P(getDriver().ResourceDir); |
| 744 | P.appendComponent("lib"); |
| 745 | P.appendComponent("darwin"); |
| 746 | P.appendComponent("libclang_rt.cc_kext.a"); |
NAKAMURA Takumi | 304ed3f | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 747 | |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 748 | // For now, allow missing resource libraries to support developers who may |
| 749 | // not have compiler-rt checked out or integrated into their build. |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 750 | bool Exists; |
| 751 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 752 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 753 | } |
| 754 | |
Daniel Dunbar | c0e665e | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 755 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 756 | const char *BoundArch) const { |
| 757 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 758 | const OptTable &Opts = getDriver().getOpts(); |
| 759 | |
| 760 | // FIXME: We really want to get out of the tool chain level argument |
| 761 | // translation business, as it makes the driver functionality much |
| 762 | // more opaque. For now, we follow gcc closely solely for the |
| 763 | // purpose of easily achieving feature parity & testability. Once we |
| 764 | // have something that works, we should reevaluate each translation |
| 765 | // and try to push it down into tool specific logic. |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 766 | |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 767 | for (ArgList::const_iterator it = Args.begin(), |
| 768 | ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 769 | Arg *A = *it; |
| 770 | |
| 771 | if (A->getOption().matches(options::OPT_Xarch__)) { |
Daniel Dunbar | 2a45fa7 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 772 | // Skip this argument unless the architecture matches either the toolchain |
| 773 | // triple arch, or the arch being bound. |
| 774 | // |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 775 | // FIXME: Canonicalize name. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 776 | StringRef XarchArch = A->getValue(Args, 0); |
Daniel Dunbar | 2a45fa7 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 777 | if (!(XarchArch == getArchName() || |
| 778 | (BoundArch && XarchArch == BoundArch))) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 779 | continue; |
| 780 | |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 781 | Arg *OriginalArg = A; |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 782 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1)); |
| 783 | unsigned Prev = Index; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 784 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 786 | // If the argument parsing failed or more than one argument was |
| 787 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 788 | // extra arguments. Emit an error and ignore. |
| 789 | // |
| 790 | // We also want to disallow any options which would alter the |
| 791 | // driver behavior; that isn't going to work in our model. We |
| 792 | // use isDriverOption() as an approximation, although things |
| 793 | // like -O4 are going to slip through. |
Daniel Dunbar | 0e02f6e | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 794 | if (!XarchArg || Index > Prev + 1) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 795 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
Daniel Dunbar | 7e9293b | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 796 | << A->getAsString(Args); |
| 797 | continue; |
| 798 | } else if (XarchArg->getOption().isDriverOption()) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 799 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 800 | << A->getAsString(Args); |
| 801 | continue; |
| 802 | } |
| 803 | |
Daniel Dunbar | 478edc2 | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 804 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 805 | A = XarchArg; |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 806 | |
| 807 | DAL->AddSynthesizedArg(A); |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 808 | |
| 809 | // Linker input arguments require custom handling. The problem is that we |
| 810 | // have already constructed the phase actions, so we can not treat them as |
| 811 | // "input arguments". |
| 812 | if (A->getOption().isLinkerInput()) { |
| 813 | // Convert the argument into individual Zlinker_input_args. |
| 814 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { |
| 815 | DAL->AddSeparateArg(OriginalArg, |
| 816 | Opts.getOption(options::OPT_Zlinker_input), |
| 817 | A->getValue(Args, i)); |
NAKAMURA Takumi | 304ed3f | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 818 | |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 819 | } |
| 820 | continue; |
| 821 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 822 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 823 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 824 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 825 | // gcc translates options twice, which means that self-expanding |
| 826 | // options add duplicates. |
Daniel Dunbar | 9e1f982 | 2009-11-19 04:14:53 +0000 | [diff] [blame] | 827 | switch ((options::ID) A->getOption().getID()) { |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 828 | default: |
| 829 | DAL->append(A); |
| 830 | break; |
| 831 | |
| 832 | case options::OPT_mkernel: |
| 833 | case options::OPT_fapple_kext: |
| 834 | DAL->append(A); |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 835 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 836 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 838 | case options::OPT_dependency_file: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 839 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), |
| 840 | A->getValue(Args)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 841 | break; |
| 842 | |
| 843 | case options::OPT_gfull: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 844 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 845 | DAL->AddFlagArg(A, |
| 846 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 847 | break; |
| 848 | |
| 849 | case options::OPT_gused: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 850 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 851 | DAL->AddFlagArg(A, |
| 852 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 853 | break; |
| 854 | |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 855 | case options::OPT_shared: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 856 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 857 | break; |
| 858 | |
| 859 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 860 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 861 | break; |
| 862 | |
| 863 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 864 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 865 | break; |
| 866 | |
| 867 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 868 | DAL->AddFlagArg(A, |
| 869 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 870 | break; |
| 871 | |
| 872 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 873 | DAL->AddFlagArg(A, |
| 874 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 878 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 879 | break; |
| 880 | |
| 881 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 882 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 883 | break; |
| 884 | } |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 887 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 888 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 889 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 890 | DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 891 | |
| 892 | // Add the arch options based on the particular spelling of -arch, to match |
| 893 | // how the driver driver works. |
| 894 | if (BoundArch) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 895 | StringRef Name = BoundArch; |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 896 | const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 897 | const Option *MArch = Opts.getOption(options::OPT_march_EQ); |
| 898 | |
| 899 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 900 | // which defines the list of which architectures we accept. |
| 901 | if (Name == "ppc") |
| 902 | ; |
| 903 | else if (Name == "ppc601") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 904 | DAL->AddJoinedArg(0, MCpu, "601"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 905 | else if (Name == "ppc603") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 906 | DAL->AddJoinedArg(0, MCpu, "603"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 907 | else if (Name == "ppc604") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 908 | DAL->AddJoinedArg(0, MCpu, "604"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 909 | else if (Name == "ppc604e") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 910 | DAL->AddJoinedArg(0, MCpu, "604e"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 911 | else if (Name == "ppc750") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 912 | DAL->AddJoinedArg(0, MCpu, "750"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 913 | else if (Name == "ppc7400") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 914 | DAL->AddJoinedArg(0, MCpu, "7400"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 915 | else if (Name == "ppc7450") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 916 | DAL->AddJoinedArg(0, MCpu, "7450"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 917 | else if (Name == "ppc970") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 918 | DAL->AddJoinedArg(0, MCpu, "970"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 919 | |
| 920 | else if (Name == "ppc64") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 921 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 922 | |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 923 | else if (Name == "i386") |
| 924 | ; |
| 925 | else if (Name == "i486") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 926 | DAL->AddJoinedArg(0, MArch, "i486"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 927 | else if (Name == "i586") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 928 | DAL->AddJoinedArg(0, MArch, "i586"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 929 | else if (Name == "i686") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 930 | DAL->AddJoinedArg(0, MArch, "i686"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 931 | else if (Name == "pentium") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 932 | DAL->AddJoinedArg(0, MArch, "pentium"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 933 | else if (Name == "pentium2") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 934 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 935 | else if (Name == "pentpro") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 936 | DAL->AddJoinedArg(0, MArch, "pentiumpro"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 937 | else if (Name == "pentIIm3") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 938 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 939 | |
| 940 | else if (Name == "x86_64") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 941 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 942 | |
| 943 | else if (Name == "arm") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 944 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 945 | else if (Name == "armv4t") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 946 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 947 | else if (Name == "armv5") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 948 | DAL->AddJoinedArg(0, MArch, "armv5tej"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 949 | else if (Name == "xscale") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 950 | DAL->AddJoinedArg(0, MArch, "xscale"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 951 | else if (Name == "armv6") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 952 | DAL->AddJoinedArg(0, MArch, "armv6k"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 953 | else if (Name == "armv7") |
Daniel Dunbar | 9d0863b | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 954 | DAL->AddJoinedArg(0, MArch, "armv7a"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 955 | |
| 956 | else |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 957 | llvm_unreachable("invalid Darwin arch"); |
Daniel Dunbar | 84ec96c | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 958 | } |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 959 | |
Daniel Dunbar | 60baf0f | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 960 | // Add an explicit version min argument for the deployment target. We do this |
| 961 | // after argument translation because -Xarch_ arguments may add a version min |
| 962 | // argument. |
| 963 | AddDeploymentTarget(*DAL); |
| 964 | |
Bob Wilson | 163b151 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 965 | // Validate the C++ standard library choice. |
| 966 | CXXStdlibType Type = GetCXXStdlibType(*DAL); |
| 967 | if (Type == ToolChain::CST_Libcxx) { |
| 968 | switch (LibCXXForSimulator) { |
| 969 | case LibCXXSimulator_None: |
| 970 | // Handle non-simulator cases. |
| 971 | if (isTargetIPhoneOS()) { |
| 972 | if (isIPhoneOSVersionLT(5, 0)) { |
| 973 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) |
| 974 | << "iOS 5.0"; |
| 975 | } |
Bob Wilson | 163b151 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 976 | } |
| 977 | break; |
| 978 | case LibCXXSimulator_NotAvailable: |
| 979 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) |
| 980 | << "iOS 5.0"; |
| 981 | break; |
| 982 | case LibCXXSimulator_Available: |
| 983 | break; |
| 984 | } |
| 985 | } |
| 986 | |
Daniel Dunbar | 4e7e9cf | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 987 | return DAL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 989 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 990 | bool Darwin::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 991 | // FIXME: Gross; we should probably have some separate target |
| 992 | // definition, possibly even reusing the one in clang. |
| 993 | return getArchName() == "x86_64"; |
| 994 | } |
| 995 | |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 996 | bool Darwin::UseDwarfDebugFlags() const { |
| 997 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 998 | return S[0] != '\0'; |
| 999 | return false; |
| 1000 | } |
| 1001 | |
Daniel Dunbar | b2987d1 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1002 | bool Darwin::UseSjLjExceptions() const { |
| 1003 | // Darwin uses SjLj exceptions on ARM. |
| 1004 | return (getTriple().getArch() == llvm::Triple::arm || |
| 1005 | getTriple().getArch() == llvm::Triple::thumb); |
| 1006 | } |
| 1007 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 1008 | const char *Darwin::GetDefaultRelocationModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1009 | return "pic"; |
| 1010 | } |
| 1011 | |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 1012 | const char *Darwin::GetForcedPicModel() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1013 | if (getArchName() == "x86_64") |
| 1014 | return "pic"; |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1018 | bool Darwin::SupportsProfiling() const { |
| 1019 | // Profiling instrumentation is only supported on x86. |
| 1020 | return getArchName() == "i386" || getArchName() == "x86_64"; |
| 1021 | } |
| 1022 | |
Daniel Dunbar | 43a9b32 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1023 | bool Darwin::SupportsObjCGC() const { |
| 1024 | // Garbage collection is supported everywhere except on iPhone OS. |
| 1025 | return !isTargetIPhoneOS(); |
| 1026 | } |
| 1027 | |
Argyrios Kyrtzidis | 5840dd9 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1028 | bool Darwin::SupportsObjCARC() const { |
| 1029 | return isTargetIPhoneOS() || !isMacosxVersionLT(10, 6); |
| 1030 | } |
| 1031 | |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 1032 | std::string |
Chad Rosier | 61ab80a | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 1033 | Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args, |
| 1034 | types::ID InputType) const { |
| 1035 | return ComputeLLVMTriple(Args, InputType); |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1038 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 1039 | /// all subcommands; this relies on gcc translating the majority of |
| 1040 | /// command line options. |
| 1041 | |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1042 | /// \brief Parse a GCCVersion object out of a string of text. |
| 1043 | /// |
| 1044 | /// This is the primary means of forming GCCVersion objects. |
| 1045 | /*static*/ |
| 1046 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { |
| 1047 | const GCCVersion BadVersion = { VersionText.str(), -1, -1, -1, "" }; |
| 1048 | std::pair<StringRef, StringRef> First = VersionText.split('.'); |
| 1049 | std::pair<StringRef, StringRef> Second = First.second.split('.'); |
| 1050 | |
| 1051 | GCCVersion GoodVersion = { VersionText.str(), -1, -1, -1, "" }; |
| 1052 | if (First.first.getAsInteger(10, GoodVersion.Major) || |
| 1053 | GoodVersion.Major < 0) |
| 1054 | return BadVersion; |
| 1055 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || |
| 1056 | GoodVersion.Minor < 0) |
| 1057 | return BadVersion; |
| 1058 | |
| 1059 | // First look for a number prefix and parse that if present. Otherwise just |
| 1060 | // stash the entire patch string in the suffix, and leave the number |
| 1061 | // unspecified. This covers versions strings such as: |
| 1062 | // 4.4 |
| 1063 | // 4.4.0 |
| 1064 | // 4.4.x |
| 1065 | // 4.4.2-rc4 |
| 1066 | // 4.4.x-patched |
| 1067 | // And retains any patch number it finds. |
| 1068 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); |
| 1069 | if (!PatchText.empty()) { |
| 1070 | if (unsigned EndNumber = PatchText.find_first_not_of("0123456789")) { |
| 1071 | // Try to parse the number and any suffix. |
| 1072 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || |
| 1073 | GoodVersion.Patch < 0) |
| 1074 | return BadVersion; |
| 1075 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber).str(); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | return GoodVersion; |
| 1080 | } |
| 1081 | |
| 1082 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. |
| 1083 | bool Generic_GCC::GCCVersion::operator<(const GCCVersion &RHS) const { |
| 1084 | if (Major < RHS.Major) return true; if (Major > RHS.Major) return false; |
| 1085 | if (Minor < RHS.Minor) return true; if (Minor > RHS.Minor) return false; |
| 1086 | |
| 1087 | // Note that we rank versions with *no* patch specified is better than ones |
| 1088 | // hard-coding a patch version. Thus if the RHS has no patch, it always |
| 1089 | // wins, and the LHS only wins if it has no patch and the RHS does have |
| 1090 | // a patch. |
| 1091 | if (RHS.Patch == -1) return true; if (Patch == -1) return false; |
| 1092 | if (Patch < RHS.Patch) return true; if (Patch > RHS.Patch) return false; |
| 1093 | |
| 1094 | // Finally, between completely tied version numbers, the version with the |
| 1095 | // suffix loses as we prefer full releases. |
| 1096 | if (RHS.PatchSuffix.empty()) return true; |
| 1097 | return false; |
| 1098 | } |
| 1099 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1100 | static StringRef getGCCToolchainDir(const ArgList &Args) { |
| 1101 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); |
| 1102 | if (A) |
| 1103 | return A->getValue(Args); |
| 1104 | return GCC_INSTALL_PREFIX; |
| 1105 | } |
| 1106 | |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1107 | /// \brief Construct a GCCInstallationDetector from the driver. |
| 1108 | /// |
| 1109 | /// This performs all of the autodetection and sets up the various paths. |
| 1110 | /// Once constructed, a GCCInstallation is esentially immutable. |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1111 | /// |
| 1112 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and |
| 1113 | /// should instead pull the target out of the driver. This is currently |
| 1114 | /// necessary because the driver doesn't store the final version of the target |
| 1115 | /// triple. |
| 1116 | Generic_GCC::GCCInstallationDetector::GCCInstallationDetector( |
| 1117 | const Driver &D, |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1118 | const llvm::Triple &TargetTriple, |
| 1119 | const ArgList &Args) |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1120 | : IsValid(false) { |
Chandler Carruth | 9b338a7 | 2012-02-13 02:02:09 +0000 | [diff] [blame] | 1121 | llvm::Triple MultiarchTriple |
| 1122 | = TargetTriple.isArch32Bit() ? TargetTriple.get64BitArchVariant() |
| 1123 | : TargetTriple.get32BitArchVariant(); |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1124 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1125 | // The library directories which may contain GCC installations. |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1126 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateMultiarchLibDirs; |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1127 | // The compatible GCC triples for this particular architecture. |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1128 | SmallVector<StringRef, 10> CandidateTripleAliases; |
| 1129 | SmallVector<StringRef, 10> CandidateMultiarchTripleAliases; |
| 1130 | CollectLibDirsAndTriples(TargetTriple, MultiarchTriple, CandidateLibDirs, |
| 1131 | CandidateTripleAliases, |
| 1132 | CandidateMultiarchLibDirs, |
| 1133 | CandidateMultiarchTripleAliases); |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1134 | |
| 1135 | // Compute the set of prefixes for our search. |
| 1136 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), |
| 1137 | D.PrefixDirs.end()); |
Rafael Espindola | 353300c | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1138 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1139 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); |
| 1140 | if (GCCToolchainDir != "") { |
| 1141 | if (GCCToolchainDir.back() == '/') |
| 1142 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / |
Rafael Espindola | 353300c | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1143 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1144 | Prefixes.push_back(GCCToolchainDir); |
Rafael Espindola | 353300c | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1145 | } else { |
| 1146 | Prefixes.push_back(D.SysRoot); |
| 1147 | Prefixes.push_back(D.SysRoot + "/usr"); |
| 1148 | Prefixes.push_back(D.InstalledDir + "/.."); |
| 1149 | } |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1150 | |
| 1151 | // Loop over the various components which exist and select the best GCC |
| 1152 | // installation available. GCC installs are ranked by version number. |
| 1153 | Version = GCCVersion::Parse("0.0.0"); |
| 1154 | for (unsigned i = 0, ie = Prefixes.size(); i < ie; ++i) { |
| 1155 | if (!llvm::sys::fs::exists(Prefixes[i])) |
| 1156 | continue; |
| 1157 | for (unsigned j = 0, je = CandidateLibDirs.size(); j < je; ++j) { |
| 1158 | const std::string LibDir = Prefixes[i] + CandidateLibDirs[j].str(); |
| 1159 | if (!llvm::sys::fs::exists(LibDir)) |
| 1160 | continue; |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1161 | for (unsigned k = 0, ke = CandidateTripleAliases.size(); k < ke; ++k) |
| 1162 | ScanLibDirForGCCTriple(TargetArch, LibDir, CandidateTripleAliases[k]); |
| 1163 | } |
| 1164 | for (unsigned j = 0, je = CandidateMultiarchLibDirs.size(); j < je; ++j) { |
| 1165 | const std::string LibDir |
| 1166 | = Prefixes[i] + CandidateMultiarchLibDirs[j].str(); |
| 1167 | if (!llvm::sys::fs::exists(LibDir)) |
| 1168 | continue; |
| 1169 | for (unsigned k = 0, ke = CandidateMultiarchTripleAliases.size(); k < ke; |
| 1170 | ++k) |
| 1171 | ScanLibDirForGCCTriple(TargetArch, LibDir, |
| 1172 | CandidateMultiarchTripleAliases[k], |
| 1173 | /*NeedsMultiarchSuffix=*/true); |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1179 | const llvm::Triple &TargetTriple, |
| 1180 | const llvm::Triple &MultiarchTriple, |
| 1181 | SmallVectorImpl<StringRef> &LibDirs, |
| 1182 | SmallVectorImpl<StringRef> &TripleAliases, |
| 1183 | SmallVectorImpl<StringRef> &MultiarchLibDirs, |
| 1184 | SmallVectorImpl<StringRef> &MultiarchTripleAliases) { |
| 1185 | // Declare a bunch of static data sets that we'll select between below. These |
| 1186 | // are specifically designed to always refer to string literals to avoid any |
| 1187 | // lifetime or initialization issues. |
| 1188 | static const char *const ARMLibDirs[] = { "/lib" }; |
| 1189 | static const char *const ARMTriples[] = { |
| 1190 | "arm-linux-gnueabi", |
| 1191 | "arm-linux-androideabi" |
| 1192 | }; |
| 1193 | |
| 1194 | static const char *const X86_64LibDirs[] = { "/lib64", "/lib" }; |
| 1195 | static const char *const X86_64Triples[] = { |
| 1196 | "x86_64-linux-gnu", |
| 1197 | "x86_64-unknown-linux-gnu", |
| 1198 | "x86_64-pc-linux-gnu", |
| 1199 | "x86_64-redhat-linux6E", |
| 1200 | "x86_64-redhat-linux", |
| 1201 | "x86_64-suse-linux", |
| 1202 | "x86_64-manbo-linux-gnu", |
| 1203 | "x86_64-linux-gnu", |
| 1204 | "x86_64-slackware-linux" |
| 1205 | }; |
| 1206 | static const char *const X86LibDirs[] = { "/lib32", "/lib" }; |
| 1207 | static const char *const X86Triples[] = { |
| 1208 | "i686-linux-gnu", |
| 1209 | "i686-pc-linux-gnu", |
| 1210 | "i486-linux-gnu", |
| 1211 | "i386-linux-gnu", |
| 1212 | "i686-redhat-linux", |
| 1213 | "i586-redhat-linux", |
| 1214 | "i386-redhat-linux", |
| 1215 | "i586-suse-linux", |
| 1216 | "i486-slackware-linux" |
| 1217 | }; |
| 1218 | |
| 1219 | static const char *const MIPSLibDirs[] = { "/lib" }; |
| 1220 | static const char *const MIPSTriples[] = { "mips-linux-gnu" }; |
| 1221 | static const char *const MIPSELLibDirs[] = { "/lib" }; |
| 1222 | static const char *const MIPSELTriples[] = { "mipsel-linux-gnu" }; |
| 1223 | |
| 1224 | static const char *const PPCLibDirs[] = { "/lib32", "/lib" }; |
| 1225 | static const char *const PPCTriples[] = { |
| 1226 | "powerpc-linux-gnu", |
| 1227 | "powerpc-unknown-linux-gnu", |
| 1228 | "powerpc-suse-linux" |
| 1229 | }; |
| 1230 | static const char *const PPC64LibDirs[] = { "/lib64", "/lib" }; |
| 1231 | static const char *const PPC64Triples[] = { |
Chandler Carruth | 155c54c | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 1232 | "powerpc64-linux-gnu", |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1233 | "powerpc64-unknown-linux-gnu", |
| 1234 | "powerpc64-suse-linux", |
| 1235 | "ppc64-redhat-linux" |
| 1236 | }; |
| 1237 | |
| 1238 | switch (TargetTriple.getArch()) { |
| 1239 | case llvm::Triple::arm: |
| 1240 | case llvm::Triple::thumb: |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1241 | LibDirs.append(ARMLibDirs, ARMLibDirs + llvm::array_lengthof(ARMLibDirs)); |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1242 | TripleAliases.append( |
| 1243 | ARMTriples, ARMTriples + llvm::array_lengthof(ARMTriples)); |
| 1244 | break; |
| 1245 | case llvm::Triple::x86_64: |
| 1246 | LibDirs.append( |
| 1247 | X86_64LibDirs, X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs)); |
| 1248 | TripleAliases.append( |
| 1249 | X86_64Triples, X86_64Triples + llvm::array_lengthof(X86_64Triples)); |
| 1250 | MultiarchLibDirs.append( |
| 1251 | X86LibDirs, X86LibDirs + llvm::array_lengthof(X86LibDirs)); |
| 1252 | MultiarchTripleAliases.append( |
| 1253 | X86Triples, X86Triples + llvm::array_lengthof(X86Triples)); |
| 1254 | break; |
| 1255 | case llvm::Triple::x86: |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1256 | LibDirs.append(X86LibDirs, X86LibDirs + llvm::array_lengthof(X86LibDirs)); |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1257 | TripleAliases.append( |
| 1258 | X86Triples, X86Triples + llvm::array_lengthof(X86Triples)); |
| 1259 | MultiarchLibDirs.append( |
| 1260 | X86_64LibDirs, X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs)); |
| 1261 | MultiarchTripleAliases.append( |
| 1262 | X86_64Triples, X86_64Triples + llvm::array_lengthof(X86_64Triples)); |
| 1263 | break; |
| 1264 | case llvm::Triple::mips: |
| 1265 | LibDirs.append( |
| 1266 | MIPSLibDirs, MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs)); |
| 1267 | TripleAliases.append( |
| 1268 | MIPSTriples, MIPSTriples + llvm::array_lengthof(MIPSTriples)); |
| 1269 | break; |
| 1270 | case llvm::Triple::mipsel: |
| 1271 | LibDirs.append( |
| 1272 | MIPSELLibDirs, MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs)); |
| 1273 | TripleAliases.append( |
| 1274 | MIPSELTriples, MIPSELTriples + llvm::array_lengthof(MIPSELTriples)); |
| 1275 | break; |
| 1276 | case llvm::Triple::ppc: |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1277 | LibDirs.append(PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs)); |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1278 | TripleAliases.append( |
| 1279 | PPCTriples, PPCTriples + llvm::array_lengthof(PPCTriples)); |
| 1280 | MultiarchLibDirs.append( |
| 1281 | PPC64LibDirs, PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs)); |
| 1282 | MultiarchTripleAliases.append( |
| 1283 | PPC64Triples, PPC64Triples + llvm::array_lengthof(PPC64Triples)); |
| 1284 | break; |
| 1285 | case llvm::Triple::ppc64: |
| 1286 | LibDirs.append( |
| 1287 | PPC64LibDirs, PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs)); |
| 1288 | TripleAliases.append( |
| 1289 | PPC64Triples, PPC64Triples + llvm::array_lengthof(PPC64Triples)); |
| 1290 | MultiarchLibDirs.append( |
| 1291 | PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs)); |
| 1292 | MultiarchTripleAliases.append( |
| 1293 | PPCTriples, PPCTriples + llvm::array_lengthof(PPCTriples)); |
| 1294 | break; |
| 1295 | |
| 1296 | default: |
| 1297 | // By default, just rely on the standard lib directories and the original |
| 1298 | // triple. |
| 1299 | break; |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1300 | } |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1301 | |
| 1302 | // Always append the drivers target triple to the end, in case it doesn't |
| 1303 | // match any of our aliases. |
| 1304 | TripleAliases.push_back(TargetTriple.str()); |
| 1305 | |
| 1306 | // Also include the multiarch variant if it's different. |
| 1307 | if (TargetTriple.str() != MultiarchTriple.str()) |
| 1308 | MultiarchTripleAliases.push_back(MultiarchTriple.str()); |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1312 | llvm::Triple::ArchType TargetArch, const std::string &LibDir, |
| 1313 | StringRef CandidateTriple, bool NeedsMultiarchSuffix) { |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1314 | // There are various different suffixes involving the triple we |
| 1315 | // check for. We also record what is necessary to walk from each back |
| 1316 | // up to the lib directory. |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1317 | const std::string LibSuffixes[] = { |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1318 | "/gcc/" + CandidateTriple.str(), |
| 1319 | "/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), |
| 1320 | |
| 1321 | // Ubuntu has a strange mis-matched pair of triples that this happens to |
| 1322 | // match. |
| 1323 | // FIXME: It may be worthwhile to generalize this and look for a second |
| 1324 | // triple. |
Chandler Carruth | d936d9d | 2011-11-09 03:46:20 +0000 | [diff] [blame] | 1325 | "/i386-linux-gnu/gcc/" + CandidateTriple.str() |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1326 | }; |
| 1327 | const std::string InstallSuffixes[] = { |
| 1328 | "/../../..", |
| 1329 | "/../../../..", |
| 1330 | "/../../../.." |
| 1331 | }; |
| 1332 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1333 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibSuffixes) - |
| 1334 | (TargetArch != llvm::Triple::x86)); |
| 1335 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { |
| 1336 | StringRef LibSuffix = LibSuffixes[i]; |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1337 | llvm::error_code EC; |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1338 | for (llvm::sys::fs::directory_iterator LI(LibDir + LibSuffix, EC), LE; |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1339 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 1340 | StringRef VersionText = llvm::sys::path::filename(LI->path()); |
| 1341 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| 1342 | static const GCCVersion MinVersion = { "4.1.1", 4, 1, 1, "" }; |
| 1343 | if (CandidateVersion < MinVersion) |
| 1344 | continue; |
| 1345 | if (CandidateVersion <= Version) |
| 1346 | continue; |
Hal Finkel | 2e55df4 | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 1347 | |
| 1348 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs |
Chandler Carruth | 5d84bb4 | 2012-01-24 19:21:42 +0000 | [diff] [blame] | 1349 | // in what would normally be GCCInstallPath and put the 64-bit |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1350 | // libs in a subdirectory named 64. The simple logic we follow is that |
| 1351 | // *if* there is a subdirectory of the right name with crtbegin.o in it, |
| 1352 | // we use that. If not, and if not a multiarch triple, we look for |
| 1353 | // crtbegin.o without the subdirectory. |
| 1354 | StringRef MultiarchSuffix |
| 1355 | = (TargetArch == llvm::Triple::x86_64 || |
| 1356 | TargetArch == llvm::Triple::ppc64) ? "/64" : "/32"; |
| 1357 | if (llvm::sys::fs::exists(LI->path() + MultiarchSuffix + "/crtbegin.o")) { |
| 1358 | GCCMultiarchSuffix = MultiarchSuffix.str(); |
| 1359 | } else { |
| 1360 | if (NeedsMultiarchSuffix || |
| 1361 | !llvm::sys::fs::exists(LI->path() + "/crtbegin.o")) |
| 1362 | continue; |
| 1363 | GCCMultiarchSuffix.clear(); |
| 1364 | } |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1365 | |
| 1366 | Version = CandidateVersion; |
Chandler Carruth | fa5be91 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 1367 | GCCTriple.setTriple(CandidateTriple); |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1368 | // FIXME: We hack together the directory name here instead of |
| 1369 | // using LI to ensure stable path separators across Windows and |
| 1370 | // Linux. |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1371 | GCCInstallPath = LibDir + LibSuffixes[i] + "/" + VersionText.str(); |
Chandler Carruth | 5d84bb4 | 2012-01-24 19:21:42 +0000 | [diff] [blame] | 1372 | GCCParentLibPath = GCCInstallPath + InstallSuffixes[i]; |
Chandler Carruth | 19347ed | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1373 | IsValid = true; |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1378 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple& Triple, |
| 1379 | const ArgList &Args) |
| 1380 | : ToolChain(D, Triple), GCCInstallation(getDriver(), Triple, Args) { |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1381 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 1382 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1383 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1386 | Generic_GCC::~Generic_GCC() { |
| 1387 | // Free tool implementations. |
| 1388 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 1389 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 1390 | delete it->second; |
| 1391 | } |
| 1392 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1394 | const JobAction &JA, |
| 1395 | const ActionList &Inputs) const { |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1396 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1397 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1398 | Key = Action::AnalyzeJobClass; |
| 1399 | else |
| 1400 | Key = JA.getKind(); |
| 1401 | |
| 1402 | Tool *&T = Tools[Key]; |
| 1403 | if (!T) { |
| 1404 | switch (Key) { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1405 | case Action::InputClass: |
| 1406 | case Action::BindArchClass: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1407 | llvm_unreachable("Invalid tool kind."); |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1408 | case Action::PreprocessJobClass: |
| 1409 | T = new tools::gcc::Preprocess(*this); break; |
| 1410 | case Action::PrecompileJobClass: |
| 1411 | T = new tools::gcc::Precompile(*this); break; |
| 1412 | case Action::AnalyzeJobClass: |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1413 | case Action::MigrateJobClass: |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1414 | T = new tools::Clang(*this); break; |
| 1415 | case Action::CompileJobClass: |
| 1416 | T = new tools::gcc::Compile(*this); break; |
| 1417 | case Action::AssembleJobClass: |
| 1418 | T = new tools::gcc::Assemble(*this); break; |
| 1419 | case Action::LinkJobClass: |
| 1420 | T = new tools::gcc::Link(*this); break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1421 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1422 | // This is a bit ungeneric, but the only platform using a driver |
| 1423 | // driver is Darwin. |
| 1424 | case Action::LipoJobClass: |
| 1425 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 1426 | case Action::DsymutilJobClass: |
| 1427 | T = new tools::darwin::Dsymutil(*this); break; |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 1428 | case Action::VerifyJobClass: |
| 1429 | T = new tools::darwin::VerifyDebug(*this); break; |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | return *T; |
| 1434 | } |
| 1435 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1436 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1437 | // FIXME: Gross; we should probably have some separate target |
| 1438 | // definition, possibly even reusing the one in clang. |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1439 | return getArchName() == "x86_64"; |
| 1440 | } |
| 1441 | |
| 1442 | const char *Generic_GCC::GetDefaultRelocationModel() const { |
| 1443 | return "static"; |
| 1444 | } |
| 1445 | |
| 1446 | const char *Generic_GCC::GetForcedPicModel() const { |
| 1447 | return 0; |
| 1448 | } |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1449 | /// Hexagon Toolchain |
| 1450 | |
Chandler Carruth | 1d16f0f | 2012-01-31 02:21:20 +0000 | [diff] [blame] | 1451 | Hexagon_TC::Hexagon_TC(const Driver &D, const llvm::Triple& Triple) |
| 1452 | : ToolChain(D, Triple) { |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1453 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 1454 | if (getDriver().getInstalledDir() != getDriver().Dir.c_str()) |
| 1455 | getProgramPaths().push_back(getDriver().Dir); |
| 1456 | } |
| 1457 | |
| 1458 | Hexagon_TC::~Hexagon_TC() { |
| 1459 | // Free tool implementations. |
| 1460 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 1461 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 1462 | delete it->second; |
| 1463 | } |
| 1464 | |
| 1465 | Tool &Hexagon_TC::SelectTool(const Compilation &C, |
| 1466 | const JobAction &JA, |
| 1467 | const ActionList &Inputs) const { |
| 1468 | Action::ActionClass Key; |
| 1469 | // if (JA.getKind () == Action::CompileJobClass) |
| 1470 | // Key = JA.getKind (); |
| 1471 | // else |
| 1472 | |
| 1473 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1474 | Key = Action::AnalyzeJobClass; |
| 1475 | else |
| 1476 | Key = JA.getKind(); |
| 1477 | // if ((JA.getKind () == Action::CompileJobClass) |
| 1478 | // && (JA.getType () != types::TY_LTO_BC)) { |
| 1479 | // Key = JA.getKind (); |
| 1480 | // } |
| 1481 | |
| 1482 | Tool *&T = Tools[Key]; |
| 1483 | if (!T) { |
| 1484 | switch (Key) { |
| 1485 | case Action::InputClass: |
| 1486 | case Action::BindArchClass: |
| 1487 | assert(0 && "Invalid tool kind."); |
| 1488 | case Action::AnalyzeJobClass: |
| 1489 | T = new tools::Clang(*this); break; |
| 1490 | case Action::AssembleJobClass: |
| 1491 | T = new tools::hexagon::Assemble(*this); break; |
| 1492 | case Action::LinkJobClass: |
| 1493 | T = new tools::hexagon::Link(*this); break; |
| 1494 | default: |
| 1495 | assert(false && "Unsupported action for Hexagon target."); |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | return *T; |
| 1500 | } |
| 1501 | |
| 1502 | bool Hexagon_TC::IsUnwindTablesDefault() const { |
| 1503 | // FIXME: Gross; we should probably have some separate target |
| 1504 | // definition, possibly even reusing the one in clang. |
| 1505 | return getArchName() == "x86_64"; |
| 1506 | } |
| 1507 | |
| 1508 | const char *Hexagon_TC::GetDefaultRelocationModel() const { |
| 1509 | return "static"; |
| 1510 | } |
| 1511 | |
| 1512 | const char *Hexagon_TC::GetForcedPicModel() const { |
| 1513 | return 0; |
| 1514 | } // End Hexagon |
| 1515 | |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 1516 | |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1517 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 1518 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 1519 | /// Currently does not support anything else but compilation. |
| 1520 | |
Chandler Carruth | 1d16f0f | 2012-01-31 02:21:20 +0000 | [diff] [blame] | 1521 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple& Triple) |
| 1522 | : ToolChain(D, Triple) { |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1523 | // Path mangling to find libexec |
| 1524 | std::string Path(getDriver().Dir); |
| 1525 | |
| 1526 | Path += "/../libexec"; |
| 1527 | getProgramPaths().push_back(Path); |
| 1528 | } |
| 1529 | |
| 1530 | TCEToolChain::~TCEToolChain() { |
| 1531 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 1532 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 1533 | delete it->second; |
| 1534 | } |
| 1535 | |
NAKAMURA Takumi | 304ed3f | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 1536 | bool TCEToolChain::IsMathErrnoDefault() const { |
| 1537 | return true; |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | bool TCEToolChain::IsUnwindTablesDefault() const { |
| 1541 | return false; |
| 1542 | } |
| 1543 | |
| 1544 | const char *TCEToolChain::GetDefaultRelocationModel() const { |
| 1545 | return "static"; |
| 1546 | } |
| 1547 | |
| 1548 | const char *TCEToolChain::GetForcedPicModel() const { |
| 1549 | return 0; |
| 1550 | } |
| 1551 | |
NAKAMURA Takumi | 304ed3f | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 1552 | Tool &TCEToolChain::SelectTool(const Compilation &C, |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1553 | const JobAction &JA, |
| 1554 | const ActionList &Inputs) const { |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1555 | Action::ActionClass Key; |
| 1556 | Key = Action::AnalyzeJobClass; |
| 1557 | |
| 1558 | Tool *&T = Tools[Key]; |
| 1559 | if (!T) { |
| 1560 | switch (Key) { |
| 1561 | case Action::PreprocessJobClass: |
| 1562 | T = new tools::gcc::Preprocess(*this); break; |
| 1563 | case Action::AnalyzeJobClass: |
| 1564 | T = new tools::Clang(*this); break; |
| 1565 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1566 | llvm_unreachable("Unsupported action for TCE target."); |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | return *T; |
| 1570 | } |
| 1571 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1572 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 1573 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1574 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1575 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1576 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1577 | getFilePaths().push_back("/usr/lib"); |
| 1578 | } |
| 1579 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1580 | Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 1581 | const ActionList &Inputs) const { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1582 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1583 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1584 | Key = Action::AnalyzeJobClass; |
| 1585 | else |
| 1586 | Key = JA.getKind(); |
| 1587 | |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1588 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1589 | options::OPT_no_integrated_as, |
| 1590 | IsIntegratedAssemblerDefault()); |
| 1591 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1592 | Tool *&T = Tools[Key]; |
| 1593 | if (!T) { |
| 1594 | switch (Key) { |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1595 | case Action::AssembleJobClass: { |
| 1596 | if (UseIntegratedAs) |
| 1597 | T = new tools::ClangAs(*this); |
| 1598 | else |
| 1599 | T = new tools::openbsd::Assemble(*this); |
| 1600 | break; |
| 1601 | } |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1602 | case Action::LinkJobClass: |
| 1603 | T = new tools::openbsd::Link(*this); break; |
| 1604 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1605 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | return *T; |
| 1610 | } |
| 1611 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1612 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 1613 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1614 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1615 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | 214afe9 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 1616 | |
Chandler Carruth | 24248e3 | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 1617 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall |
| 1618 | // back to '/usr/lib' if it doesn't exist. |
Chandler Carruth | 00646ba | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 1619 | if ((Triple.getArch() == llvm::Triple::x86 || |
| 1620 | Triple.getArch() == llvm::Triple::ppc) && |
Chandler Carruth | 24248e3 | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 1621 | llvm::sys::fs::exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) |
Chandler Carruth | 00646ba | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 1622 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); |
| 1623 | else |
| 1624 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1627 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 1628 | const ActionList &Inputs) const { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1629 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1630 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1631 | Key = Action::AnalyzeJobClass; |
| 1632 | else |
| 1633 | Key = JA.getKind(); |
| 1634 | |
Roman Divacky | 67dece7 | 2010-11-08 17:46:39 +0000 | [diff] [blame] | 1635 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1636 | options::OPT_no_integrated_as, |
| 1637 | IsIntegratedAssemblerDefault()); |
| 1638 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1639 | Tool *&T = Tools[Key]; |
| 1640 | if (!T) { |
| 1641 | switch (Key) { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1642 | case Action::AssembleJobClass: |
Roman Divacky | 67dece7 | 2010-11-08 17:46:39 +0000 | [diff] [blame] | 1643 | if (UseIntegratedAs) |
| 1644 | T = new tools::ClangAs(*this); |
| 1645 | else |
| 1646 | T = new tools::freebsd::Assemble(*this); |
Roman Divacky | fe3a7ea | 2010-11-08 19:39:10 +0000 | [diff] [blame] | 1647 | break; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1648 | case Action::LinkJobClass: |
| 1649 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1650 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1651 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | return *T; |
| 1656 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1657 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1658 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 1659 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1660 | NetBSD::NetBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1661 | : Generic_ELF(D, Triple, Args) { |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1662 | |
Joerg Sonnenberger | 05e5930 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 1663 | if (getDriver().UseStdLib) { |
Chandler Carruth | 32f88be | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 1664 | // When targeting a 32-bit platform, try the special directory used on |
| 1665 | // 64-bit hosts, and only fall back to the main library directory if that |
| 1666 | // doesn't work. |
| 1667 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure |
| 1668 | // what all logic is needed to emulate the '=' prefix here. |
Joerg Sonnenberger | 66de97f | 2012-01-26 21:58:37 +0000 | [diff] [blame] | 1669 | if (Triple.getArch() == llvm::Triple::x86) |
Joerg Sonnenberger | 05e5930 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 1670 | getFilePaths().push_back("=/usr/lib/i386"); |
Chandler Carruth | 32f88be | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 1671 | |
| 1672 | getFilePaths().push_back("=/usr/lib"); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1673 | } |
| 1674 | } |
| 1675 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1676 | Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA, |
| 1677 | const ActionList &Inputs) const { |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1678 | Action::ActionClass Key; |
| 1679 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1680 | Key = Action::AnalyzeJobClass; |
| 1681 | else |
| 1682 | Key = JA.getKind(); |
| 1683 | |
| 1684 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1685 | options::OPT_no_integrated_as, |
| 1686 | IsIntegratedAssemblerDefault()); |
| 1687 | |
| 1688 | Tool *&T = Tools[Key]; |
| 1689 | if (!T) { |
| 1690 | switch (Key) { |
| 1691 | case Action::AssembleJobClass: |
| 1692 | if (UseIntegratedAs) |
| 1693 | T = new tools::ClangAs(*this); |
| 1694 | else |
Joerg Sonnenberger | 1bd9137 | 2012-01-26 22:27:52 +0000 | [diff] [blame] | 1695 | T = new tools::netbsd::Assemble(*this); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1696 | break; |
| 1697 | case Action::LinkJobClass: |
Joerg Sonnenberger | 1bd9137 | 2012-01-26 22:27:52 +0000 | [diff] [blame] | 1698 | T = new tools::netbsd::Link(*this); |
Joerg Sonnenberger | 182564c | 2011-05-16 13:35:02 +0000 | [diff] [blame] | 1699 | break; |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1700 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1701 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | return *T; |
| 1706 | } |
| 1707 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1708 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 1709 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1710 | Minix::Minix(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1711 | : Generic_ELF(D, Triple, Args) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1712 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 1713 | getFilePaths().push_back("/usr/lib"); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1716 | Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA, |
| 1717 | const ActionList &Inputs) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1718 | Action::ActionClass Key; |
| 1719 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1720 | Key = Action::AnalyzeJobClass; |
| 1721 | else |
| 1722 | Key = JA.getKind(); |
| 1723 | |
| 1724 | Tool *&T = Tools[Key]; |
| 1725 | if (!T) { |
| 1726 | switch (Key) { |
| 1727 | case Action::AssembleJobClass: |
| 1728 | T = new tools::minix::Assemble(*this); break; |
| 1729 | case Action::LinkJobClass: |
| 1730 | T = new tools::minix::Link(*this); break; |
| 1731 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1732 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | return *T; |
| 1737 | } |
| 1738 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1739 | /// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. |
| 1740 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1741 | AuroraUX::AuroraUX(const Driver &D, const llvm::Triple& Triple, |
| 1742 | const ArgList &Args) |
| 1743 | : Generic_GCC(D, Triple, Args) { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1744 | |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1745 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 1746 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1747 | getProgramPaths().push_back(getDriver().Dir); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1748 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1749 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1750 | getFilePaths().push_back("/usr/lib"); |
| 1751 | getFilePaths().push_back("/usr/sfw/lib"); |
| 1752 | getFilePaths().push_back("/opt/gcc4/lib"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 1753 | 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] | 1754 | |
| 1755 | } |
| 1756 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1757 | Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA, |
| 1758 | const ActionList &Inputs) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1759 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1760 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1761 | Key = Action::AnalyzeJobClass; |
| 1762 | else |
| 1763 | Key = JA.getKind(); |
| 1764 | |
| 1765 | Tool *&T = Tools[Key]; |
| 1766 | if (!T) { |
| 1767 | switch (Key) { |
| 1768 | case Action::AssembleJobClass: |
| 1769 | T = new tools::auroraux::Assemble(*this); break; |
| 1770 | case Action::LinkJobClass: |
| 1771 | T = new tools::auroraux::Link(*this); break; |
| 1772 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 1773 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | return *T; |
| 1778 | } |
| 1779 | |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 1780 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. |
| 1781 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1782 | Solaris::Solaris(const Driver &D, const llvm::Triple& Triple, |
| 1783 | const ArgList &Args) |
| 1784 | : Generic_GCC(D, Triple, Args) { |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 1785 | |
| 1786 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 1787 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 1788 | getProgramPaths().push_back(getDriver().Dir); |
| 1789 | |
| 1790 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 1791 | getFilePaths().push_back("/usr/lib"); |
| 1792 | } |
| 1793 | |
| 1794 | Tool &Solaris::SelectTool(const Compilation &C, const JobAction &JA, |
| 1795 | const ActionList &Inputs) const { |
| 1796 | Action::ActionClass Key; |
| 1797 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 1798 | Key = Action::AnalyzeJobClass; |
| 1799 | else |
| 1800 | Key = JA.getKind(); |
| 1801 | |
| 1802 | Tool *&T = Tools[Key]; |
| 1803 | if (!T) { |
| 1804 | switch (Key) { |
| 1805 | case Action::AssembleJobClass: |
| 1806 | T = new tools::solaris::Assemble(*this); break; |
| 1807 | case Action::LinkJobClass: |
| 1808 | T = new tools::solaris::Link(*this); break; |
| 1809 | default: |
| 1810 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | return *T; |
| 1815 | } |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1816 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 1817 | /// Linux toolchain (very bare-bones at the moment). |
| 1818 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1819 | enum LinuxDistro { |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1820 | ArchLinux, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1821 | DebianLenny, |
| 1822 | DebianSqueeze, |
Eli Friedman | 0b200f6 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 1823 | DebianWheezy, |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1824 | Exherbo, |
Chris Lattner | d753b56 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 1825 | RHEL4, |
| 1826 | RHEL5, |
| 1827 | RHEL6, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1828 | Fedora13, |
| 1829 | Fedora14, |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1830 | Fedora15, |
Benjamin Kramer | afe55fb | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 1831 | Fedora16, |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1832 | FedoraRawhide, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1833 | OpenSuse11_3, |
David Chisnall | de5c048 | 2011-05-19 13:26:33 +0000 | [diff] [blame] | 1834 | OpenSuse11_4, |
| 1835 | OpenSuse12_1, |
Douglas Gregor | 814638e | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 1836 | UbuntuHardy, |
| 1837 | UbuntuIntrepid, |
Rafael Espindola | 021aaa4 | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 1838 | UbuntuJaunty, |
Zhongxing Xu | 5ede807 | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 1839 | UbuntuKarmic, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1840 | UbuntuLucid, |
| 1841 | UbuntuMaverick, |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 1842 | UbuntuNatty, |
Benjamin Kramer | 25a857b | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 1843 | UbuntuOneiric, |
Benjamin Kramer | 668ecd9 | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 1844 | UbuntuPrecise, |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1845 | UnknownDistro |
| 1846 | }; |
| 1847 | |
Chris Lattner | d753b56 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 1848 | static bool IsRedhat(enum LinuxDistro Distro) { |
Benjamin Kramer | afe55fb | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 1849 | return (Distro >= Fedora13 && Distro <= FedoraRawhide) || |
| 1850 | (Distro >= RHEL4 && Distro <= RHEL6); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | static bool IsOpenSuse(enum LinuxDistro Distro) { |
Benjamin Kramer | afe55fb | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 1854 | return Distro >= OpenSuse11_3 && Distro <= OpenSuse12_1; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static bool IsDebian(enum LinuxDistro Distro) { |
Benjamin Kramer | afe55fb | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 1858 | return Distro >= DebianLenny && Distro <= DebianWheezy; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | static bool IsUbuntu(enum LinuxDistro Distro) { |
Benjamin Kramer | 668ecd9 | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 1862 | return Distro >= UbuntuHardy && Distro <= UbuntuPrecise; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1865 | static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) { |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 1866 | OwningPtr<llvm::MemoryBuffer> File; |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1867 | if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1868 | StringRef Data = File.get()->getBuffer(); |
| 1869 | SmallVector<StringRef, 8> Lines; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1870 | Data.split(Lines, "\n"); |
Benjamin Kramer | 668ecd9 | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 1871 | LinuxDistro Version = UnknownDistro; |
| 1872 | for (unsigned i = 0, s = Lines.size(); i != s; ++i) |
| 1873 | if (Version == UnknownDistro && Lines[i].startswith("DISTRIB_CODENAME=")) |
| 1874 | Version = llvm::StringSwitch<LinuxDistro>(Lines[i].substr(17)) |
| 1875 | .Case("hardy", UbuntuHardy) |
| 1876 | .Case("intrepid", UbuntuIntrepid) |
| 1877 | .Case("jaunty", UbuntuJaunty) |
| 1878 | .Case("karmic", UbuntuKarmic) |
| 1879 | .Case("lucid", UbuntuLucid) |
| 1880 | .Case("maverick", UbuntuMaverick) |
| 1881 | .Case("natty", UbuntuNatty) |
| 1882 | .Case("oneiric", UbuntuOneiric) |
| 1883 | .Case("precise", UbuntuPrecise) |
| 1884 | .Default(UnknownDistro); |
| 1885 | return Version; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1888 | if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1889 | StringRef Data = File.get()->getBuffer(); |
Benjamin Kramer | afe55fb | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 1890 | if (Data.startswith("Fedora release 16")) |
| 1891 | return Fedora16; |
| 1892 | else if (Data.startswith("Fedora release 15")) |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1893 | return Fedora15; |
| 1894 | else if (Data.startswith("Fedora release 14")) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1895 | return Fedora14; |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1896 | else if (Data.startswith("Fedora release 13")) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1897 | return Fedora13; |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1898 | else if (Data.startswith("Fedora release") && |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1899 | Data.find("Rawhide") != StringRef::npos) |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 1900 | return FedoraRawhide; |
Chris Lattner | d753b56 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 1901 | else if (Data.startswith("Red Hat Enterprise Linux") && |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1902 | Data.find("release 6") != StringRef::npos) |
Chris Lattner | d753b56 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 1903 | return RHEL6; |
Rafael Espindola | 5a640ef | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 1904 | else if ((Data.startswith("Red Hat Enterprise Linux") || |
| 1905 | Data.startswith("CentOS")) && |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1906 | Data.find("release 5") != StringRef::npos) |
Chris Lattner | d753b56 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 1907 | return RHEL5; |
Rafael Espindola | 5a640ef | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 1908 | else if ((Data.startswith("Red Hat Enterprise Linux") || |
| 1909 | Data.startswith("CentOS")) && |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1910 | Data.find("release 4") != StringRef::npos) |
Chris Lattner | d753b56 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 1911 | return RHEL4; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1912 | return UnknownDistro; |
| 1913 | } |
| 1914 | |
Michael J. Spencer | 4eeebc4 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 1915 | if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1916 | StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1917 | if (Data[0] == '5') |
| 1918 | return DebianLenny; |
Rafael Espindola | 0e743b1 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 1919 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1920 | return DebianSqueeze; |
Rafael Espindola | 0e743b1 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 1921 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') |
Eli Friedman | 0b200f6 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 1922 | return DebianWheezy; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1923 | return UnknownDistro; |
| 1924 | } |
| 1925 | |
Benjamin Kramer | afe55fb | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 1926 | if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) |
| 1927 | return llvm::StringSwitch<LinuxDistro>(File.get()->getBuffer()) |
| 1928 | .StartsWith("openSUSE 11.3", OpenSuse11_3) |
| 1929 | .StartsWith("openSUSE 11.4", OpenSuse11_4) |
| 1930 | .StartsWith("openSUSE 12.1", OpenSuse12_1) |
| 1931 | .Default(UnknownDistro); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1932 | |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 1933 | bool Exists; |
| 1934 | if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists) |
Rafael Espindola | 0a84aee | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 1935 | return Exherbo; |
| 1936 | |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 1937 | if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists) |
| 1938 | return ArchLinux; |
| 1939 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1940 | return UnknownDistro; |
| 1941 | } |
| 1942 | |
Chandler Carruth | deb73f8 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 1943 | /// \brief Get our best guess at the multiarch triple for a target. |
| 1944 | /// |
| 1945 | /// Debian-based systems are starting to use a multiarch setup where they use |
| 1946 | /// a target-triple directory in the library and header search paths. |
| 1947 | /// Unfortunately, this triple does not align with the vanilla target triple, |
| 1948 | /// so we provide a rough mapping here. |
| 1949 | static std::string getMultiarchTriple(const llvm::Triple TargetTriple, |
| 1950 | StringRef SysRoot) { |
| 1951 | // For most architectures, just use whatever we have rather than trying to be |
| 1952 | // clever. |
| 1953 | switch (TargetTriple.getArch()) { |
| 1954 | default: |
| 1955 | return TargetTriple.str(); |
| 1956 | |
| 1957 | // We use the existence of '/lib/<triple>' as a directory to detect some |
| 1958 | // common linux triples that don't quite match the Clang triple for both |
Chandler Carruth | 236e0b6 | 2011-10-31 09:06:40 +0000 | [diff] [blame] | 1959 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
| 1960 | // regardless of what the actual target triple is. |
Chandler Carruth | deb73f8 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 1961 | case llvm::Triple::x86: |
Chandler Carruth | deb73f8 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 1962 | if (llvm::sys::fs::exists(SysRoot + "/lib/i386-linux-gnu")) |
| 1963 | return "i386-linux-gnu"; |
| 1964 | return TargetTriple.str(); |
| 1965 | case llvm::Triple::x86_64: |
| 1966 | if (llvm::sys::fs::exists(SysRoot + "/lib/x86_64-linux-gnu")) |
| 1967 | return "x86_64-linux-gnu"; |
Chandler Carruth | deb73f8 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 1968 | return TargetTriple.str(); |
Eli Friedman | 5bea4f6 | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 1969 | case llvm::Triple::mips: |
| 1970 | if (llvm::sys::fs::exists(SysRoot + "/lib/mips-linux-gnu")) |
| 1971 | return "mips-linux-gnu"; |
| 1972 | return TargetTriple.str(); |
| 1973 | case llvm::Triple::mipsel: |
| 1974 | if (llvm::sys::fs::exists(SysRoot + "/lib/mipsel-linux-gnu")) |
| 1975 | return "mipsel-linux-gnu"; |
| 1976 | return TargetTriple.str(); |
Chandler Carruth | 155c54c | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 1977 | case llvm::Triple::ppc: |
| 1978 | if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc-linux-gnu")) |
| 1979 | return "powerpc-linux-gnu"; |
| 1980 | return TargetTriple.str(); |
| 1981 | case llvm::Triple::ppc64: |
| 1982 | if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc64-linux-gnu")) |
| 1983 | return "powerpc64-linux-gnu"; |
| 1984 | return TargetTriple.str(); |
Chandler Carruth | deb73f8 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 1985 | } |
| 1986 | } |
| 1987 | |
Chandler Carruth | 00646ba | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 1988 | static void addPathIfExists(Twine Path, ToolChain::path_list &Paths) { |
| 1989 | if (llvm::sys::fs::exists(Path)) Paths.push_back(Path.str()); |
| 1990 | } |
| 1991 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1992 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 1993 | : Generic_ELF(D, Triple, Args) { |
Chandler Carruth | 8908879 | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 1994 | llvm::Triple::ArchType Arch = Triple.getArch(); |
Chandler Carruth | fde8d14 | 2011-10-03 06:41:08 +0000 | [diff] [blame] | 1995 | const std::string &SysRoot = getDriver().SysRoot; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 1996 | |
Rafael Espindola | ab78408 | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 1997 | // OpenSuse stores the linker with the compiler, add that to the search |
| 1998 | // path. |
| 1999 | ToolChain::path_list &PPaths = getProgramPaths(); |
Chandler Carruth | fa13459 | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 2000 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + |
Chandler Carruth | fa5be91 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2001 | GCCInstallation.getTriple().str() + "/bin").str()); |
Rafael Espindola | ab78408 | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 2002 | |
| 2003 | Linker = GetProgramPath("ld"); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2004 | |
| 2005 | LinuxDistro Distro = DetectLinuxDistro(Arch); |
| 2006 | |
Chris Lattner | 64a8917 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 2007 | if (IsOpenSuse(Distro) || IsUbuntu(Distro)) { |
Rafael Espindola | 94c8022 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 2008 | ExtraOpts.push_back("-z"); |
| 2009 | ExtraOpts.push_back("relro"); |
| 2010 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2011 | |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 2012 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2013 | ExtraOpts.push_back("-X"); |
| 2014 | |
Chandler Carruth | d4e6e7e | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 2015 | const bool IsMips = Arch == llvm::Triple::mips || |
| 2016 | Arch == llvm::Triple::mipsel || |
| 2017 | Arch == llvm::Triple::mips64 || |
| 2018 | Arch == llvm::Triple::mips64el; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2019 | |
Evgeniy Stepanov | 704e732 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 2020 | const bool IsAndroid = Triple.getEnvironment() == llvm::Triple::ANDROIDEABI; |
| 2021 | |
Chandler Carruth | d4e6e7e | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 2022 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
| 2023 | // and the MIPS ABI require .dynsym to be sorted in different ways. |
| 2024 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
| 2025 | // ABI requires a mapping between the GOT and the symbol table. |
Evgeniy Stepanov | 704e732 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 2026 | // Android loader does not support .gnu.hash. |
| 2027 | if (!IsMips && !IsAndroid) { |
Benjamin Kramer | 668ecd9 | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 2028 | if (IsRedhat(Distro) || IsOpenSuse(Distro) || |
| 2029 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) |
Chandler Carruth | d4e6e7e | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 2030 | ExtraOpts.push_back("--hash-style=gnu"); |
| 2031 | |
| 2032 | if (IsDebian(Distro) || IsOpenSuse(Distro) || Distro == UbuntuLucid || |
| 2033 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) |
| 2034 | ExtraOpts.push_back("--hash-style=both"); |
| 2035 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2036 | |
Chris Lattner | d753b56 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 2037 | if (IsRedhat(Distro)) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2038 | ExtraOpts.push_back("--no-add-needed"); |
| 2039 | |
Eli Friedman | 0b200f6 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 2040 | if (Distro == DebianSqueeze || Distro == DebianWheezy || |
Rafael Espindola | 5a640ef | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 2041 | IsOpenSuse(Distro) || |
| 2042 | (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || |
Benjamin Kramer | 668ecd9 | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 2043 | (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2044 | ExtraOpts.push_back("--build-id"); |
| 2045 | |
Chris Lattner | 64a8917 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 2046 | if (IsOpenSuse(Distro)) |
Chandler Carruth | f0b60ec | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 2047 | ExtraOpts.push_back("--enable-new-dtags"); |
Chris Lattner | 64a8917 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 2048 | |
Chandler Carruth | d2deee1 | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 2049 | // The selection of paths to try here is designed to match the patterns which |
| 2050 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
| 2051 | // This was determined by running GCC in a fake filesystem, creating all |
| 2052 | // possible permutations of these directories, and seeing which ones it added |
| 2053 | // to the link paths. |
| 2054 | path_list &Paths = getFilePaths(); |
Chandler Carruth | 3fd345a | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 2055 | |
Chandler Carruth | d747efa | 2012-02-11 03:31:12 +0000 | [diff] [blame] | 2056 | const std::string Multilib = Triple.isArch32Bit() ? "lib32" : "lib64"; |
Chandler Carruth | deb73f8 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 2057 | const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot); |
Chandler Carruth | d2deee1 | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 2058 | |
Chandler Carruth | d1f7306 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 2059 | // Add the multilib suffixed paths where they are available. |
| 2060 | if (GCCInstallation.isValid()) { |
Chandler Carruth | fa5be91 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2061 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
Chandler Carruth | 8908879 | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 2062 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2063 | addPathIfExists((GCCInstallation.getInstallPath() + |
| 2064 | GCCInstallation.getMultiarchSuffix()), |
| 2065 | Paths); |
Chandler Carruth | fa5be91 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2066 | addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib/../" + Multilib, |
Chandler Carruth | d1f7306 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 2067 | Paths); |
| 2068 | addPathIfExists(LibPath + "/" + MultiarchTriple, Paths); |
| 2069 | addPathIfExists(LibPath + "/../" + Multilib, Paths); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2070 | } |
Chandler Carruth | d1f7306 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 2071 | addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths); |
| 2072 | addPathIfExists(SysRoot + "/lib/../" + Multilib, Paths); |
| 2073 | addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths); |
| 2074 | addPathIfExists(SysRoot + "/usr/lib/../" + Multilib, Paths); |
| 2075 | |
| 2076 | // Try walking via the GCC triple path in case of multiarch GCC |
| 2077 | // installations with strange symlinks. |
| 2078 | if (GCCInstallation.isValid()) |
Chandler Carruth | fa5be91 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2079 | addPathIfExists(SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + |
Chandler Carruth | d1f7306 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 2080 | "/../../" + Multilib, Paths); |
Rafael Espindola | c7409a0 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 2081 | |
Chandler Carruth | 7a09d01 | 2011-10-16 10:54:30 +0000 | [diff] [blame] | 2082 | // Add the non-multilib suffixed paths (if potentially different). |
Chandler Carruth | 048e649 | 2011-10-03 18:16:54 +0000 | [diff] [blame] | 2083 | if (GCCInstallation.isValid()) { |
| 2084 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
Chandler Carruth | fa5be91 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2085 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
Chandler Carruth | 1c6f04a | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2086 | if (!GCCInstallation.getMultiarchSuffix().empty()) |
Chandler Carruth | 048e649 | 2011-10-03 18:16:54 +0000 | [diff] [blame] | 2087 | addPathIfExists(GCCInstallation.getInstallPath(), Paths); |
Chandler Carruth | fa5be91 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2088 | addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib", Paths); |
Chandler Carruth | 048e649 | 2011-10-03 18:16:54 +0000 | [diff] [blame] | 2089 | addPathIfExists(LibPath, Paths); |
Chandler Carruth | d2deee1 | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 2090 | } |
Chandler Carruth | fde8d14 | 2011-10-03 06:41:08 +0000 | [diff] [blame] | 2091 | addPathIfExists(SysRoot + "/lib", Paths); |
| 2092 | addPathIfExists(SysRoot + "/usr/lib", Paths); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | bool Linux::HasNativeLLVMSupport() const { |
| 2096 | return true; |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 2099 | Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA, |
| 2100 | const ActionList &Inputs) const { |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 2101 | Action::ActionClass Key; |
| 2102 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
| 2103 | Key = Action::AnalyzeJobClass; |
| 2104 | else |
| 2105 | Key = JA.getKind(); |
| 2106 | |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 2107 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 2108 | options::OPT_no_integrated_as, |
| 2109 | IsIntegratedAssemblerDefault()); |
| 2110 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 2111 | Tool *&T = Tools[Key]; |
| 2112 | if (!T) { |
| 2113 | switch (Key) { |
| 2114 | case Action::AssembleJobClass: |
Rafael Espindola | dda5b92 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 2115 | if (UseIntegratedAs) |
| 2116 | T = new tools::ClangAs(*this); |
| 2117 | else |
| 2118 | T = new tools::linuxtools::Assemble(*this); |
| 2119 | break; |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2120 | case Action::LinkJobClass: |
| 2121 | T = new tools::linuxtools::Link(*this); break; |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 2122 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 2123 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | return *T; |
| 2128 | } |
| 2129 | |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2130 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2131 | ArgStringList &CC1Args) const { |
| 2132 | const Driver &D = getDriver(); |
| 2133 | |
| 2134 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2135 | return; |
| 2136 | |
| 2137 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2138 | addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/local/include"); |
| 2139 | |
| 2140 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2141 | llvm::sys::Path P(D.ResourceDir); |
| 2142 | P.appendComponent("include"); |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 2143 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2147 | return; |
| 2148 | |
| 2149 | // Check for configure-time C include directories. |
| 2150 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 2151 | if (CIncludeDirs != "") { |
| 2152 | SmallVector<StringRef, 5> dirs; |
| 2153 | CIncludeDirs.split(dirs, ":"); |
| 2154 | for (SmallVectorImpl<StringRef>::iterator I = dirs.begin(), E = dirs.end(); |
| 2155 | I != E; ++I) { |
| 2156 | StringRef Prefix = llvm::sys::path::is_absolute(*I) ? D.SysRoot : ""; |
| 2157 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + *I); |
| 2158 | } |
| 2159 | return; |
| 2160 | } |
| 2161 | |
| 2162 | // Lacking those, try to detect the correct set of system includes for the |
| 2163 | // target triple. |
| 2164 | |
Chandler Carruth | a463089 | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2165 | // Implement generic Debian multiarch support. |
| 2166 | const StringRef X86_64MultiarchIncludeDirs[] = { |
| 2167 | "/usr/include/x86_64-linux-gnu", |
| 2168 | |
| 2169 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 2170 | // in use in any released version of Debian, so we should consider |
| 2171 | // removing them. |
| 2172 | "/usr/include/i686-linux-gnu/64", |
| 2173 | "/usr/include/i486-linux-gnu/64" |
| 2174 | }; |
| 2175 | const StringRef X86MultiarchIncludeDirs[] = { |
| 2176 | "/usr/include/i386-linux-gnu", |
| 2177 | |
| 2178 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 2179 | // in use in any released version of Debian, so we should consider |
| 2180 | // removing them. |
| 2181 | "/usr/include/x86_64-linux-gnu/32", |
| 2182 | "/usr/include/i686-linux-gnu", |
| 2183 | "/usr/include/i486-linux-gnu" |
| 2184 | }; |
| 2185 | const StringRef ARMMultiarchIncludeDirs[] = { |
| 2186 | "/usr/include/arm-linux-gnueabi" |
| 2187 | }; |
Eli Friedman | d7df785 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 2188 | const StringRef MIPSMultiarchIncludeDirs[] = { |
| 2189 | "/usr/include/mips-linux-gnu" |
| 2190 | }; |
| 2191 | const StringRef MIPSELMultiarchIncludeDirs[] = { |
| 2192 | "/usr/include/mipsel-linux-gnu" |
| 2193 | }; |
Chandler Carruth | 079d2bb | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 2194 | const StringRef PPCMultiarchIncludeDirs[] = { |
| 2195 | "/usr/include/powerpc-linux-gnu" |
| 2196 | }; |
| 2197 | const StringRef PPC64MultiarchIncludeDirs[] = { |
| 2198 | "/usr/include/powerpc64-linux-gnu" |
| 2199 | }; |
Chandler Carruth | a463089 | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2200 | ArrayRef<StringRef> MultiarchIncludeDirs; |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2201 | if (getTriple().getArch() == llvm::Triple::x86_64) { |
Chandler Carruth | a463089 | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2202 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2203 | } else if (getTriple().getArch() == llvm::Triple::x86) { |
Chandler Carruth | a463089 | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2204 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2205 | } else if (getTriple().getArch() == llvm::Triple::arm) { |
Chandler Carruth | a463089 | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2206 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; |
Eli Friedman | d7df785 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 2207 | } else if (getTriple().getArch() == llvm::Triple::mips) { |
| 2208 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; |
| 2209 | } else if (getTriple().getArch() == llvm::Triple::mipsel) { |
| 2210 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; |
Chandler Carruth | 079d2bb | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 2211 | } else if (getTriple().getArch() == llvm::Triple::ppc) { |
| 2212 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; |
| 2213 | } else if (getTriple().getArch() == llvm::Triple::ppc64) { |
| 2214 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; |
Chandler Carruth | a463089 | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2215 | } |
| 2216 | for (ArrayRef<StringRef>::iterator I = MultiarchIncludeDirs.begin(), |
| 2217 | E = MultiarchIncludeDirs.end(); |
| 2218 | I != E; ++I) { |
Chandler Carruth | d936d9d | 2011-11-09 03:46:20 +0000 | [diff] [blame] | 2219 | if (llvm::sys::fs::exists(D.SysRoot + *I)) { |
Chandler Carruth | a463089 | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2220 | addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + *I); |
| 2221 | break; |
| 2222 | } |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | if (getTriple().getOS() == llvm::Triple::RTEMS) |
| 2226 | return; |
| 2227 | |
Chandler Carruth | c44bc2d | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 2228 | // Add an include of '/include' directly. This isn't provided by default by |
| 2229 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 2230 | // add even when Clang is acting as-if it were a system compiler. |
| 2231 | addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include"); |
| 2232 | |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2233 | addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include"); |
| 2234 | } |
| 2235 | |
Chandler Carruth | 79cbbdc | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 2236 | /// \brief Helper to add the thre variant paths for a libstdc++ installation. |
| 2237 | /*static*/ bool Linux::addLibStdCXXIncludePaths(Twine Base, Twine TargetArchDir, |
| 2238 | const ArgList &DriverArgs, |
| 2239 | ArgStringList &CC1Args) { |
Chandler Carruth | abaa1d7 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2240 | if (!llvm::sys::fs::exists(Base)) |
| 2241 | return false; |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2242 | addSystemInclude(DriverArgs, CC1Args, Base); |
Chandler Carruth | abaa1d7 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2243 | addSystemInclude(DriverArgs, CC1Args, Base + "/" + TargetArchDir); |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2244 | addSystemInclude(DriverArgs, CC1Args, Base + "/backward"); |
Chandler Carruth | abaa1d7 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2245 | return true; |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2249 | ArgStringList &CC1Args) const { |
| 2250 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2251 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2252 | return; |
| 2253 | |
Chandler Carruth | eb35ffc | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 2254 | // Check if libc++ has been enabled and provide its include paths if so. |
| 2255 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { |
| 2256 | // libc++ is always installed at a fixed path on Linux currently. |
| 2257 | addSystemInclude(DriverArgs, CC1Args, |
| 2258 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| 2259 | return; |
| 2260 | } |
| 2261 | |
Chandler Carruth | fc52f75 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 2262 | // We need a detected GCC installation on Linux to provide libstdc++'s |
| 2263 | // headers. We handled the libc++ case above. |
| 2264 | if (!GCCInstallation.isValid()) |
| 2265 | return; |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2266 | |
Chandler Carruth | abaa1d7 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2267 | // By default, look for the C++ headers in an include directory adjacent to |
| 2268 | // the lib directory of the GCC installation. Note that this is expect to be |
| 2269 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. |
| 2270 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 2271 | StringRef InstallDir = GCCInstallation.getInstallPath(); |
| 2272 | StringRef Version = GCCInstallation.getVersion(); |
| 2273 | if (!addLibStdCXXIncludePaths(LibDir + "/../include/c++/" + Version, |
Chandler Carruth | fc52f75 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 2274 | (GCCInstallation.getTriple().str() + |
| 2275 | GCCInstallation.getMultiarchSuffix()), |
Chandler Carruth | abaa1d7 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2276 | DriverArgs, CC1Args)) { |
| 2277 | // Gentoo is weird and places its headers inside the GCC install, so if the |
| 2278 | // first attempt to find the headers fails, try this pattern. |
| 2279 | addLibStdCXXIncludePaths(InstallDir + "/include/g++-v4", |
Chandler Carruth | fc52f75 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 2280 | (GCCInstallation.getTriple().str() + |
| 2281 | GCCInstallation.getMultiarchSuffix()), |
Chandler Carruth | abaa1d7 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2282 | DriverArgs, CC1Args); |
| 2283 | } |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2286 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 2287 | |
Rafael Espindola | 0e65959 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2288 | DragonFly::DragonFly(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 2289 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2290 | |
| 2291 | // Path mangling to find libexec |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2292 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 86643b8 | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2293 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2294 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2295 | |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2296 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2297 | getFilePaths().push_back("/usr/lib"); |
| 2298 | getFilePaths().push_back("/usr/lib/gcc41"); |
| 2299 | } |
| 2300 | |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 2301 | Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA, |
| 2302 | const ActionList &Inputs) const { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2303 | Action::ActionClass Key; |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2304 | if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2305 | Key = Action::AnalyzeJobClass; |
| 2306 | else |
| 2307 | Key = JA.getKind(); |
| 2308 | |
| 2309 | Tool *&T = Tools[Key]; |
| 2310 | if (!T) { |
| 2311 | switch (Key) { |
| 2312 | case Action::AssembleJobClass: |
| 2313 | T = new tools::dragonfly::Assemble(*this); break; |
| 2314 | case Action::LinkJobClass: |
| 2315 | T = new tools::dragonfly::Link(*this); break; |
| 2316 | default: |
Daniel Dunbar | ac0659a | 2011-03-18 20:14:00 +0000 | [diff] [blame] | 2317 | T = &Generic_GCC::SelectTool(C, JA, Inputs); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | return *T; |
| 2322 | } |