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