Nick Lewycky | 6da9077 | 2010-12-31 17:31:54 +0000 | [diff] [blame] | 1 | //===--- ToolChains.cpp - ToolChain Implementations -----------------------===// |
Daniel Dunbar | 59e5e88 | 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" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 11 | #include "SanitizerArgs.h" |
| 12 | #include "clang/Basic/ObjCRuntime.h" |
| 13 | #include "clang/Basic/Version.h" |
Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Arg.h" |
| 15 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Compilation.h" |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 18 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | aa76737 | 2009-11-19 00:15:11 +0000 | [diff] [blame] | 19 | #include "clang/Driver/OptTable.h" |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 20 | #include "clang/Driver/Option.h" |
Daniel Dunbar | da13faf | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 21 | #include "clang/Driver/Options.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallString.h" |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringExtras.h" |
Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringSwitch.h" |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 27 | #include "llvm/Support/FileSystem.h" |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 28 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Path.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 30 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | f25faaa | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 31 | #include "llvm/Support/system_error.h" |
NAKAMURA Takumi | 067fcb5 | 2012-12-04 14:31:59 +0000 | [diff] [blame] | 32 | |
| 33 | // FIXME: This needs to be listed last until we fix the broken include guards |
| 34 | // in these files and the LLVM config.h files. |
| 35 | #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX |
| 36 | |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 37 | #include <cstdlib> // ::getenv |
| 38 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 39 | using namespace clang::driver; |
| 40 | using namespace clang::driver::toolchains; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 41 | using namespace clang; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 42 | |
Daniel Dunbar | f0a5b9b | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 43 | /// Darwin - Darwin tool chain for i386 and x86_64. |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 44 | |
Chandler Carruth | d7fa2e0 | 2012-01-31 02:21:20 +0000 | [diff] [blame] | 45 | Darwin::Darwin(const Driver &D, const llvm::Triple& Triple) |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 46 | : ToolChain(D, Triple), TargetInitialized(false) |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 47 | { |
Bob Wilson | 9d3f7af | 2012-01-31 21:30:03 +0000 | [diff] [blame] | 48 | // Compute the initial Darwin version from the triple |
| 49 | unsigned Major, Minor, Micro; |
Bob Wilson | a223401 | 2012-01-31 22:43:59 +0000 | [diff] [blame] | 50 | if (!Triple.getMacOSXVersion(Major, Minor, Micro)) |
| 51 | getDriver().Diag(diag::err_drv_invalid_darwin_version) << |
| 52 | Triple.getOSName(); |
| 53 | llvm::raw_string_ostream(MacosxVersionMin) |
| 54 | << Major << '.' << Minor << '.' << Micro; |
| 55 | |
Bob Wilson | 9d3f7af | 2012-01-31 21:30:03 +0000 | [diff] [blame] | 56 | // FIXME: DarwinVersion is only used to find GCC's libexec directory. |
| 57 | // It should be removed when we stop supporting that. |
| 58 | DarwinVersion[0] = Minor + 4; |
| 59 | DarwinVersion[1] = Micro; |
| 60 | DarwinVersion[2] = 0; |
Chad Rosier | 266c620 | 2012-05-09 18:46:30 +0000 | [diff] [blame] | 61 | |
| 62 | // Compute the initial iOS version from the triple |
Chad Rosier | bf8628e | 2012-05-09 18:51:13 +0000 | [diff] [blame] | 63 | Triple.getiOSVersion(Major, Minor, Micro); |
Chad Rosier | 266c620 | 2012-05-09 18:46:30 +0000 | [diff] [blame] | 64 | llvm::raw_string_ostream(iOSVersionMin) |
| 65 | << Major << '.' << Minor << '.' << Micro; |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Daniel Dunbar | cc7df6c | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 68 | types::ID Darwin::LookupTypeForExtension(const char *Ext) const { |
| 69 | types::ID Ty = types::lookupTypeForExtension(Ext); |
| 70 | |
| 71 | // Darwin always preprocesses assembly files (unless -x is used explicitly). |
| 72 | if (Ty == types::TY_PP_Asm) |
| 73 | return types::TY_Asm; |
| 74 | |
| 75 | return Ty; |
| 76 | } |
| 77 | |
Daniel Dunbar | 62123a1 | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 78 | bool Darwin::HasNativeLLVMSupport() const { |
| 79 | return true; |
| 80 | } |
| 81 | |
John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 82 | /// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 83 | ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const { |
Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 84 | if (isTargetIPhoneOS()) |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 85 | return ObjCRuntime(ObjCRuntime::iOS, TargetVersion); |
Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 86 | if (isNonFragile) |
| 87 | return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion); |
| 88 | return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion); |
John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 89 | } |
| 90 | |
John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 91 | /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. |
| 92 | bool Darwin::hasBlocksRuntime() const { |
| 93 | if (isTargetIPhoneOS()) |
| 94 | return !isIPhoneOSVersionLT(3, 2); |
| 95 | else |
| 96 | return !isMacosxVersionLT(10, 6); |
| 97 | } |
| 98 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 99 | static const char *GetArmArchForMArch(StringRef Value) { |
Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 100 | return llvm::StringSwitch<const char*>(Value) |
| 101 | .Case("armv6k", "armv6") |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 102 | .Case("armv6m", "armv6m") |
Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 103 | .Case("armv5tej", "armv5") |
| 104 | .Case("xscale", "xscale") |
| 105 | .Case("armv4t", "armv4t") |
| 106 | .Case("armv7", "armv7") |
| 107 | .Cases("armv7a", "armv7-a", "armv7") |
| 108 | .Cases("armv7r", "armv7-r", "armv7") |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 109 | .Cases("armv7em", "armv7e-m", "armv7em") |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 110 | .Cases("armv7f", "armv7-f", "armv7f") |
| 111 | .Cases("armv7k", "armv7-k", "armv7k") |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 112 | .Cases("armv7m", "armv7-m", "armv7m") |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 113 | .Cases("armv7s", "armv7-s", "armv7s") |
Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 114 | .Default(0); |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 117 | static const char *GetArmArchForMCpu(StringRef Value) { |
Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 118 | return llvm::StringSwitch<const char *>(Value) |
| 119 | .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "arm926ej-s","armv5") |
| 120 | .Cases("arm10e", "arm10tdmi", "armv5") |
| 121 | .Cases("arm1020t", "arm1020e", "arm1022e", "arm1026ej-s", "armv5") |
| 122 | .Case("xscale", "xscale") |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 123 | .Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "arm1176jzf-s", "armv6") |
| 124 | .Case("cortex-m0", "armv6m") |
| 125 | .Cases("cortex-a8", "cortex-r4", "cortex-a9", "cortex-a15", "armv7") |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 126 | .Case("cortex-a9-mp", "armv7f") |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 127 | .Case("cortex-m3", "armv7m") |
| 128 | .Case("cortex-m4", "armv7em") |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 129 | .Case("swift", "armv7s") |
Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 130 | .Default(0); |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 133 | StringRef Darwin::getDarwinArchName(const ArgList &Args) const { |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 134 | switch (getTriple().getArch()) { |
| 135 | default: |
| 136 | return getArchName(); |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 137 | |
Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 138 | case llvm::Triple::thumb: |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 139 | case llvm::Triple::arm: { |
| 140 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 141 | if (const char *Arch = GetArmArchForMArch(A->getValue())) |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 142 | return Arch; |
| 143 | |
| 144 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 145 | if (const char *Arch = GetArmArchForMCpu(A->getValue())) |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 146 | return Arch; |
| 147 | |
| 148 | return "arm"; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
Daniel Dunbar | f0a5b9b | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 153 | Darwin::~Darwin() { |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 154 | // Free tool implementations. |
| 155 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 156 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 157 | delete it->second; |
| 158 | } |
| 159 | |
Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 160 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, |
| 161 | types::ID InputType) const { |
| 162 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 163 | |
| 164 | // If the target isn't initialized (e.g., an unknown Darwin platform, return |
| 165 | // the default triple). |
| 166 | if (!isTargetInitialized()) |
| 167 | return Triple.getTriple(); |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 168 | |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 169 | SmallString<16> Str; |
Benjamin Kramer | ddefa6d | 2012-03-10 20:55:36 +0000 | [diff] [blame] | 170 | Str += isTargetIPhoneOS() ? "ios" : "macosx"; |
| 171 | Str += getTargetVersion().getAsString(); |
| 172 | Triple.setOSName(Str); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 173 | |
| 174 | return Triple.getTriple(); |
| 175 | } |
| 176 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 177 | void Generic_ELF::anchor() {} |
| 178 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 179 | Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { |
Argyrios Kyrtzidis | 3169e80 | 2012-05-21 20:11:54 +0000 | [diff] [blame] | 180 | Action::ActionClass Key = JA.getKind(); |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 181 | |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 182 | if (getDriver().ShouldUseClangCompiler(JA)) { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 183 | // FIXME: This seems like a hacky way to choose clang frontend. |
| 184 | Key = Action::AnalyzeJobClass; |
| 185 | } |
| 186 | |
Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 187 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 188 | options::OPT_no_integrated_as, |
Bob Wilson | d32fba2 | 2011-10-30 00:20:28 +0000 | [diff] [blame] | 189 | IsIntegratedAssemblerDefault()); |
Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 190 | |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 191 | Tool *&T = Tools[Key]; |
| 192 | if (!T) { |
| 193 | switch (Key) { |
| 194 | case Action::InputClass: |
| 195 | case Action::BindArchClass: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 196 | llvm_unreachable("Invalid tool kind."); |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 197 | case Action::PreprocessJobClass: |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 198 | case Action::AnalyzeJobClass: |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 199 | case Action::MigrateJobClass: |
Daniel Dunbar | f64f530 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 200 | case Action::PrecompileJobClass: |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 201 | case Action::CompileJobClass: |
Bob Wilson | decc03e | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 202 | T = new tools::Clang(*this); break; |
Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 203 | case Action::AssembleJobClass: { |
| 204 | if (UseIntegratedAs) |
| 205 | T = new tools::ClangAs(*this); |
| 206 | else |
| 207 | T = new tools::darwin::Assemble(*this); |
| 208 | break; |
| 209 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 210 | case Action::LinkJobClass: |
Daniel Dunbar | 5095b29 | 2009-09-04 17:39:02 +0000 | [diff] [blame] | 211 | T = new tools::darwin::Link(*this); break; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 212 | case Action::LipoJobClass: |
| 213 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 8829962 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 214 | case Action::DsymutilJobClass: |
| 215 | T = new tools::darwin::Dsymutil(*this); break; |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 216 | case Action::VerifyJobClass: |
| 217 | T = new tools::darwin::VerifyDebug(*this); break; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
| 221 | return *T; |
| 222 | } |
| 223 | |
Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 224 | |
Chandler Carruth | d7fa2e0 | 2012-01-31 02:21:20 +0000 | [diff] [blame] | 225 | DarwinClang::DarwinClang(const Driver &D, const llvm::Triple& Triple) |
| 226 | : Darwin(D, Triple) |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 227 | { |
Daniel Dunbar | 00aff04 | 2010-09-17 08:22:12 +0000 | [diff] [blame] | 228 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 229 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 230 | getProgramPaths().push_back(getDriver().Dir); |
| 231 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 232 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 233 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 234 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 235 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 236 | } |
| 237 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 238 | void DarwinClang::AddLinkARCArgs(const ArgList &Args, |
| 239 | ArgStringList &CmdArgs) const { |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 240 | |
| 241 | CmdArgs.push_back("-force_load"); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 242 | llvm::sys::Path P(getDriver().ClangExecutable); |
| 243 | P.eraseComponent(); // 'clang' |
| 244 | P.eraseComponent(); // 'bin' |
| 245 | P.appendComponent("lib"); |
| 246 | P.appendComponent("arc"); |
| 247 | P.appendComponent("libarclite_"); |
| 248 | std::string s = P.str(); |
| 249 | // Mash in the platform. |
Argyrios Kyrtzidis | 058b451 | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 250 | if (isTargetIOSSimulator()) |
| 251 | s += "iphonesimulator"; |
| 252 | else if (isTargetIPhoneOS()) |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 253 | s += "iphoneos"; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 254 | else |
| 255 | s += "macosx"; |
| 256 | s += ".a"; |
| 257 | |
| 258 | CmdArgs.push_back(Args.MakeArgString(s)); |
| 259 | } |
| 260 | |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 261 | void DarwinClang::AddLinkRuntimeLib(const ArgList &Args, |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 262 | ArgStringList &CmdArgs, |
Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 263 | const char *DarwinStaticLib, |
| 264 | bool AlwaysLink) const { |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 265 | llvm::sys::Path P(getDriver().ResourceDir); |
| 266 | P.appendComponent("lib"); |
| 267 | P.appendComponent("darwin"); |
| 268 | P.appendComponent(DarwinStaticLib); |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 269 | |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 270 | // For now, allow missing resource libraries to support developers who may |
Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 271 | // not have compiler-rt checked out or integrated into their build (unless |
| 272 | // we explicitly force linking with this library). |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 273 | bool Exists; |
Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 274 | if (AlwaysLink || (!llvm::sys::fs::exists(P.str(), Exists) && Exists)) |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 275 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 276 | } |
| 277 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 278 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 279 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 280 | // Darwin only supports the compiler-rt based runtime libraries. |
| 281 | switch (GetRuntimeLibType(Args)) { |
| 282 | case ToolChain::RLT_CompilerRT: |
| 283 | break; |
| 284 | default: |
| 285 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 286 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 287 | return; |
| 288 | } |
| 289 | |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 290 | // Darwin doesn't support real static executables, don't link any runtime |
| 291 | // libraries with -static. |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 292 | if (Args.hasArg(options::OPT_static) || |
| 293 | Args.hasArg(options::OPT_fapple_kext) || |
| 294 | Args.hasArg(options::OPT_mkernel)) |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 295 | return; |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 296 | |
| 297 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 298 | // cares. This is useful in situations where someone wants to statically link |
| 299 | // something like libstdc++, and needs its runtime support routines. |
| 300 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 301 | getDriver().Diag(diag::err_drv_unsupported_opt) |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 302 | << A->getAsString(Args); |
| 303 | return; |
| 304 | } |
| 305 | |
Daniel Dunbar | 4f41440c | 2011-11-17 00:36:57 +0000 | [diff] [blame] | 306 | // If we are building profile support, link that library in. |
| 307 | if (Args.hasArg(options::OPT_fprofile_arcs) || |
| 308 | Args.hasArg(options::OPT_fprofile_generate) || |
| 309 | Args.hasArg(options::OPT_fcreate_profile) || |
| 310 | Args.hasArg(options::OPT_coverage)) { |
| 311 | // Select the appropriate runtime library for the target. |
| 312 | if (isTargetIPhoneOS()) { |
| 313 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a"); |
| 314 | } else { |
| 315 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a"); |
| 316 | } |
| 317 | } |
| 318 | |
Alexey Samsonov | 627b10f | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 319 | SanitizerArgs Sanitize(getDriver(), Args); |
| 320 | |
Alexey Samsonov | cc42980 | 2012-11-16 12:53:14 +0000 | [diff] [blame] | 321 | // Add Ubsan runtime library, if required. |
| 322 | if (Sanitize.needsUbsanRt()) { |
Alexey Samsonov | 969be24 | 2013-01-21 08:45:02 +0000 | [diff] [blame] | 323 | if (isTargetIPhoneOS()) { |
Alexey Samsonov | cc42980 | 2012-11-16 12:53:14 +0000 | [diff] [blame] | 324 | getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) |
| 325 | << "-fsanitize=undefined"; |
| 326 | } else { |
Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 327 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a", true); |
Alexey Samsonov | cc42980 | 2012-11-16 12:53:14 +0000 | [diff] [blame] | 328 | |
| 329 | // The Ubsan runtime library requires C++. |
| 330 | AddCXXStdlibLibArgs(Args, CmdArgs); |
| 331 | } |
| 332 | } |
| 333 | |
Kostya Serebryany | 0b692ce | 2011-12-06 19:18:44 +0000 | [diff] [blame] | 334 | // Add ASAN runtime library, if required. Dynamic libraries and bundles |
| 335 | // should not be linked with the runtime library. |
Alexey Samsonov | 627b10f | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 336 | if (Sanitize.needsAsanRt()) { |
Kostya Serebryany | 0b692ce | 2011-12-06 19:18:44 +0000 | [diff] [blame] | 337 | if (Args.hasArg(options::OPT_dynamiclib) || |
Alexey Samsonov | cc42980 | 2012-11-16 12:53:14 +0000 | [diff] [blame] | 338 | Args.hasArg(options::OPT_bundle)) { |
| 339 | // Assume the binary will provide the ASan runtime. |
| 340 | } else if (isTargetIPhoneOS()) { |
Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 341 | getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) |
Alexey Samsonov | 627b10f | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 342 | << "-fsanitize=address"; |
Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 343 | } else { |
Alexander Potapenko | f6b5697 | 2013-01-22 09:16:03 +0000 | [diff] [blame] | 344 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.asan_osx_dynamic.dylib", true); |
Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 345 | |
Alexander Potapenko | f6b5697 | 2013-01-22 09:16:03 +0000 | [diff] [blame] | 346 | // The ASAN runtime library requires C++. |
Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 347 | AddCXXStdlibLibArgs(Args, CmdArgs); |
Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 351 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 352 | // target specific static runtime library. |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 353 | CmdArgs.push_back("-lSystem"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 354 | |
| 355 | // Select the dynamic runtime library and the target specific static library. |
Daniel Dunbar | 15c8942 | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 356 | if (isTargetIPhoneOS()) { |
Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 357 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, |
| 358 | // it never went into the SDK. |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 359 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ |
| 360 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator()) |
| 361 | CmdArgs.push_back("-lgcc_s.1"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 362 | |
Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 363 | // We currently always need a static runtime library for iOS. |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 364 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 365 | } else { |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 366 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 367 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 368 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 369 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 370 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 371 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 372 | |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 373 | // For OS X, we thought we would only need a static runtime library when |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 374 | // targeting 10.4, to provide versions of the static functions which were |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 375 | // omitted from 10.4.dylib. |
| 376 | // |
| 377 | // Unfortunately, that turned out to not be true, because Darwin system |
| 378 | // headers can still use eprintf on i386, and it is not exported from |
| 379 | // libSystem. Therefore, we still must provide a runtime library just for |
| 380 | // the tiny tiny handful of projects that *might* use that symbol. |
| 381 | if (isMacosxVersionLT(10, 5)) { |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 382 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 383 | } else { |
| 384 | if (getTriple().getArch() == llvm::Triple::x86) |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 385 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); |
| 386 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 387 | } |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 388 | } |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 391 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 392 | const OptTable &Opts = getDriver().getOpts(); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 393 | |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 394 | // Support allowing the SDKROOT environment variable used by xcrun and other |
| 395 | // Xcode tools to define the default sysroot, by making it the default for |
| 396 | // isysroot. |
Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 397 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 398 | // Warn if the path does not exist. |
| 399 | bool Exists; |
| 400 | if (llvm::sys::fs::exists(A->getValue(), Exists) || !Exists) |
| 401 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); |
| 402 | } else { |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 403 | if (char *env = ::getenv("SDKROOT")) { |
Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 404 | // We only use this value as the default if it is an absolute path, |
| 405 | // exists, and it is not the root path. |
| 406 | if (llvm::sys::path::is_absolute(env) && llvm::sys::fs::exists(env) && |
| 407 | StringRef(env) != "/") { |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 408 | Args.append(Args.MakeSeparateArg( |
| 409 | 0, Opts.getOption(options::OPT_isysroot), env)); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 414 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 415 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
| 416 | Arg *iOSSimVersion = Args.getLastArg( |
| 417 | options::OPT_mios_simulator_version_min_EQ); |
Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 418 | |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 419 | if (OSXVersion && (iOSVersion || iOSSimVersion)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 420 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | c8b7af8 | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 421 | << OSXVersion->getAsString(Args) |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 422 | << (iOSVersion ? iOSVersion : iOSSimVersion)->getAsString(Args); |
| 423 | iOSVersion = iOSSimVersion = 0; |
| 424 | } else if (iOSVersion && iOSSimVersion) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 425 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 426 | << iOSVersion->getAsString(Args) |
| 427 | << iOSSimVersion->getAsString(Args); |
| 428 | iOSSimVersion = 0; |
| 429 | } else if (!OSXVersion && !iOSVersion && !iOSSimVersion) { |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 430 | // If no deployment target was specified on the command line, check for |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 431 | // environment defines. |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 432 | StringRef OSXTarget; |
| 433 | StringRef iOSTarget; |
| 434 | StringRef iOSSimTarget; |
| 435 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) |
| 436 | OSXTarget = env; |
| 437 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) |
| 438 | iOSTarget = env; |
| 439 | if (char *env = ::getenv("IOS_SIMULATOR_DEPLOYMENT_TARGET")) |
| 440 | iOSSimTarget = env; |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 441 | |
NAKAMURA Takumi | 82a3511 | 2011-10-08 11:31:46 +0000 | [diff] [blame] | 442 | // If no '-miphoneos-version-min' specified on the command line and |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 443 | // IPHONEOS_DEPLOYMENT_TARGET is not defined, see if we can set the default |
Gabor Greif | 5d3231c | 2012-04-18 10:59:08 +0000 | [diff] [blame] | 444 | // based on -isysroot. |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 445 | if (iOSTarget.empty()) { |
| 446 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 447 | StringRef first, second; |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 448 | StringRef isysroot = A->getValue(); |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 449 | llvm::tie(first, second) = isysroot.split(StringRef("SDKs/iPhoneOS")); |
| 450 | if (second != "") |
| 451 | iOSTarget = second.substr(0,3); |
| 452 | } |
| 453 | } |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 454 | |
Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 455 | // If no OSX or iOS target has been specified and we're compiling for armv7, |
| 456 | // go ahead as assume we're targeting iOS. |
Chad Rosier | 7b1fee1 | 2012-05-09 18:55:57 +0000 | [diff] [blame] | 457 | if (OSXTarget.empty() && iOSTarget.empty() && |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 458 | (getDarwinArchName(Args) == "armv7" || |
| 459 | getDarwinArchName(Args) == "armv7s")) |
Chad Rosier | f761fe9 | 2012-05-09 18:09:58 +0000 | [diff] [blame] | 460 | iOSTarget = iOSVersionMin; |
Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 461 | |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 462 | // Handle conflicting deployment targets |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 463 | // |
| 464 | // FIXME: Don't hardcode default here. |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 465 | |
| 466 | // Do not allow conflicts with the iOS simulator target. |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 467 | if (!iOSSimTarget.empty() && (!OSXTarget.empty() || !iOSTarget.empty())) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 468 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 469 | << "IOS_SIMULATOR_DEPLOYMENT_TARGET" |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 470 | << (!OSXTarget.empty() ? "MACOSX_DEPLOYMENT_TARGET" : |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 471 | "IPHONEOS_DEPLOYMENT_TARGET"); |
| 472 | } |
| 473 | |
| 474 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 475 | // default platform. |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 476 | if (!OSXTarget.empty() && !iOSTarget.empty()) { |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 477 | if (getTriple().getArch() == llvm::Triple::arm || |
| 478 | getTriple().getArch() == llvm::Triple::thumb) |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 479 | OSXTarget = ""; |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 480 | else |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 481 | iOSTarget = ""; |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 482 | } |
Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 483 | |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 484 | if (!OSXTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 485 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 486 | OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget); |
| 487 | Args.append(OSXVersion); |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 488 | } else if (!iOSTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 489 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 490 | iOSVersion = Args.MakeJoinedArg(0, O, iOSTarget); |
| 491 | Args.append(iOSVersion); |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 492 | } else if (!iOSSimTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 493 | const Option O = Opts.getOption( |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 494 | options::OPT_mios_simulator_version_min_EQ); |
| 495 | iOSSimVersion = Args.MakeJoinedArg(0, O, iOSSimTarget); |
| 496 | Args.append(iOSSimVersion); |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 497 | } else { |
Daniel Dunbar | b244715 | 2010-07-15 16:18:06 +0000 | [diff] [blame] | 498 | // Otherwise, assume we are targeting OS X. |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 499 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 500 | OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin); |
| 501 | Args.append(OSXVersion); |
Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 502 | } |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 503 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Daniel Dunbar | a9cbb6b9 | 2011-04-30 04:20:40 +0000 | [diff] [blame] | 505 | // Reject invalid architecture combinations. |
| 506 | if (iOSSimVersion && (getTriple().getArch() != llvm::Triple::x86 && |
| 507 | getTriple().getArch() != llvm::Triple::x86_64)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 508 | getDriver().Diag(diag::err_drv_invalid_arch_for_deployment_target) |
Daniel Dunbar | a9cbb6b9 | 2011-04-30 04:20:40 +0000 | [diff] [blame] | 509 | << getTriple().getArchName() << iOSSimVersion->getAsString(Args); |
| 510 | } |
| 511 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 512 | // Set the tool chain target information. |
| 513 | unsigned Major, Minor, Micro; |
| 514 | bool HadExtra; |
| 515 | if (OSXVersion) { |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 516 | assert((!iOSVersion && !iOSSimVersion) && "Unknown target platform!"); |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 517 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 518 | Micro, HadExtra) || HadExtra || |
Daniel Dunbar | bbd4822 | 2011-04-21 21:27:33 +0000 | [diff] [blame] | 519 | Major != 10 || Minor >= 100 || Micro >= 100) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 520 | getDriver().Diag(diag::err_drv_invalid_version_number) |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 521 | << OSXVersion->getAsString(Args); |
| 522 | } else { |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 523 | const Arg *Version = iOSVersion ? iOSVersion : iOSSimVersion; |
| 524 | assert(Version && "Unknown target platform!"); |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 525 | if (!Driver::GetReleaseVersion(Version->getValue(), Major, Minor, |
Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 526 | Micro, HadExtra) || HadExtra || |
| 527 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 528 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 529 | << Version->getAsString(Args); |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 530 | } |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 531 | |
Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 532 | bool IsIOSSim = bool(iOSSimVersion); |
| 533 | |
| 534 | // In GCC, the simulator historically was treated as being OS X in some |
| 535 | // contexts, like determining the link logic, despite generally being called |
| 536 | // with an iOS deployment target. For compatibility, we detect the |
| 537 | // simulator as iOS + x86, and treat it differently in a few contexts. |
| 538 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 539 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 540 | IsIOSSim = true; |
| 541 | |
| 542 | setTarget(/*IsIPhoneOS=*/ !OSXVersion, Major, Minor, Micro, IsIOSSim); |
Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 545 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 546 | ArgStringList &CmdArgs) const { |
| 547 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 548 | |
| 549 | switch (Type) { |
| 550 | case ToolChain::CST_Libcxx: |
| 551 | CmdArgs.push_back("-lc++"); |
| 552 | break; |
| 553 | |
| 554 | case ToolChain::CST_Libstdcxx: { |
| 555 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 556 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 557 | // platforms we care about it was -lstdc++.6, so we search for that |
| 558 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 559 | |
| 560 | // Check in the sysroot first. |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 561 | bool Exists; |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 562 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 563 | llvm::sys::Path P(A->getValue()); |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 564 | P.appendComponent("usr"); |
| 565 | P.appendComponent("lib"); |
| 566 | P.appendComponent("libstdc++.dylib"); |
| 567 | |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 568 | if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) { |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 569 | P.eraseComponent(); |
| 570 | P.appendComponent("libstdc++.6.dylib"); |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 571 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 572 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 573 | return; |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | // Otherwise, look in the root. |
Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 579 | // FIXME: This should be removed someday when we don't have to care about |
| 580 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 581 | if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&& |
| 582 | (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){ |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 583 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | // Otherwise, let the linker search. |
| 588 | CmdArgs.push_back("-lstdc++"); |
| 589 | break; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 594 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 595 | ArgStringList &CmdArgs) const { |
| 596 | |
| 597 | // For Darwin platforms, use the compiler-rt-based support library |
| 598 | // instead of the gcc-provided one (which is also incidentally |
| 599 | // only present in the gcc lib dir, which makes it hard to find). |
| 600 | |
| 601 | llvm::sys::Path P(getDriver().ResourceDir); |
| 602 | P.appendComponent("lib"); |
| 603 | P.appendComponent("darwin"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 604 | |
| 605 | // Use the newer cc_kext for iOS ARM after 6.0. |
| 606 | if (!isTargetIPhoneOS() || isTargetIOSSimulator() || |
| 607 | !isIPhoneOSVersionLT(6, 0)) { |
| 608 | P.appendComponent("libclang_rt.cc_kext.a"); |
| 609 | } else { |
| 610 | P.appendComponent("libclang_rt.cc_kext_ios5.a"); |
| 611 | } |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 612 | |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 613 | // For now, allow missing resource libraries to support developers who may |
| 614 | // not have compiler-rt checked out or integrated into their build. |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 615 | bool Exists; |
| 616 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 617 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 618 | } |
| 619 | |
Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 620 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 621 | const char *BoundArch) const { |
| 622 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 623 | const OptTable &Opts = getDriver().getOpts(); |
| 624 | |
| 625 | // FIXME: We really want to get out of the tool chain level argument |
| 626 | // translation business, as it makes the driver functionality much |
| 627 | // more opaque. For now, we follow gcc closely solely for the |
| 628 | // purpose of easily achieving feature parity & testability. Once we |
| 629 | // have something that works, we should reevaluate each translation |
| 630 | // and try to push it down into tool specific logic. |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 631 | |
Daniel Dunbar | 775d406 | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 632 | for (ArgList::const_iterator it = Args.begin(), |
| 633 | ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 634 | Arg *A = *it; |
| 635 | |
| 636 | if (A->getOption().matches(options::OPT_Xarch__)) { |
Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 637 | // Skip this argument unless the architecture matches either the toolchain |
| 638 | // triple arch, or the arch being bound. |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 639 | llvm::Triple::ArchType XarchArch = |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 640 | tools::darwin::getArchTypeForDarwinArchName(A->getValue(0)); |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 641 | if (!(XarchArch == getArch() || |
| 642 | (BoundArch && XarchArch == |
Rafael Espindola | dcbf698 | 2012-10-31 18:51:07 +0000 | [diff] [blame] | 643 | tools::darwin::getArchTypeForDarwinArchName(BoundArch)))) |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 644 | continue; |
| 645 | |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 646 | Arg *OriginalArg = A; |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 647 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 648 | unsigned Prev = Index; |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 649 | Arg *XarchArg = Opts.ParseOneArg(Args, Index); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 651 | // If the argument parsing failed or more than one argument was |
| 652 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 653 | // extra arguments. Emit an error and ignore. |
| 654 | // |
| 655 | // We also want to disallow any options which would alter the |
| 656 | // driver behavior; that isn't going to work in our model. We |
| 657 | // use isDriverOption() as an approximation, although things |
| 658 | // like -O4 are going to slip through. |
Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 659 | if (!XarchArg || Index > Prev + 1) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 660 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 661 | << A->getAsString(Args); |
| 662 | continue; |
Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 663 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 664 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 665 | << A->getAsString(Args); |
| 666 | continue; |
| 667 | } |
| 668 | |
Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 669 | XarchArg->setBaseArg(A); |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 670 | A = XarchArg; |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 671 | |
| 672 | DAL->AddSynthesizedArg(A); |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 673 | |
| 674 | // Linker input arguments require custom handling. The problem is that we |
| 675 | // have already constructed the phase actions, so we can not treat them as |
| 676 | // "input arguments". |
Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 677 | if (A->getOption().hasFlag(options::LinkerInput)) { |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 678 | // Convert the argument into individual Zlinker_input_args. |
| 679 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { |
| 680 | DAL->AddSeparateArg(OriginalArg, |
| 681 | Opts.getOption(options::OPT_Zlinker_input), |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 682 | A->getValue(i)); |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 683 | |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 684 | } |
| 685 | continue; |
| 686 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | } |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 688 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 689 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 690 | // gcc translates options twice, which means that self-expanding |
| 691 | // options add duplicates. |
Daniel Dunbar | 8c00957 | 2009-11-19 04:14:53 +0000 | [diff] [blame] | 692 | switch ((options::ID) A->getOption().getID()) { |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 693 | default: |
| 694 | DAL->append(A); |
| 695 | break; |
| 696 | |
| 697 | case options::OPT_mkernel: |
| 698 | case options::OPT_fapple_kext: |
| 699 | DAL->append(A); |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 700 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 701 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 702 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 703 | case options::OPT_dependency_file: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 704 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 705 | A->getValue()); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 706 | break; |
| 707 | |
| 708 | case options::OPT_gfull: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 709 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 710 | DAL->AddFlagArg(A, |
| 711 | Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 712 | break; |
| 713 | |
| 714 | case options::OPT_gused: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 715 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| 716 | DAL->AddFlagArg(A, |
| 717 | Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 718 | break; |
| 719 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 720 | case options::OPT_shared: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 721 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 722 | break; |
| 723 | |
| 724 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 725 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 729 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 733 | DAL->AddFlagArg(A, |
| 734 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case options::OPT_Wno_nonportable_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 738 | DAL->AddFlagArg(A, |
| 739 | Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 740 | break; |
| 741 | |
| 742 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 743 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 747 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 748 | break; |
| 749 | } |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 752 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 753 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 754 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 755 | DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 756 | |
| 757 | // Add the arch options based on the particular spelling of -arch, to match |
Chad Rosier | 7c5d908 | 2012-04-27 14:58:16 +0000 | [diff] [blame] | 758 | // how the driver driver works. |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 759 | if (BoundArch) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 760 | StringRef Name = BoundArch; |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 761 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 762 | const Option MArch = Opts.getOption(options::OPT_march_EQ); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 763 | |
| 764 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 765 | // which defines the list of which architectures we accept. |
| 766 | if (Name == "ppc") |
| 767 | ; |
| 768 | else if (Name == "ppc601") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 769 | DAL->AddJoinedArg(0, MCpu, "601"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 770 | else if (Name == "ppc603") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 771 | DAL->AddJoinedArg(0, MCpu, "603"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 772 | else if (Name == "ppc604") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 773 | DAL->AddJoinedArg(0, MCpu, "604"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 774 | else if (Name == "ppc604e") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 775 | DAL->AddJoinedArg(0, MCpu, "604e"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 776 | else if (Name == "ppc750") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 777 | DAL->AddJoinedArg(0, MCpu, "750"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 778 | else if (Name == "ppc7400") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 779 | DAL->AddJoinedArg(0, MCpu, "7400"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 780 | else if (Name == "ppc7450") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 781 | DAL->AddJoinedArg(0, MCpu, "7450"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 782 | else if (Name == "ppc970") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 783 | DAL->AddJoinedArg(0, MCpu, "970"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 784 | |
| 785 | else if (Name == "ppc64") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 786 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 787 | |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 788 | else if (Name == "i386") |
| 789 | ; |
| 790 | else if (Name == "i486") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 791 | DAL->AddJoinedArg(0, MArch, "i486"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 792 | else if (Name == "i586") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 793 | DAL->AddJoinedArg(0, MArch, "i586"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 794 | else if (Name == "i686") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 795 | DAL->AddJoinedArg(0, MArch, "i686"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 796 | else if (Name == "pentium") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 797 | DAL->AddJoinedArg(0, MArch, "pentium"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 798 | else if (Name == "pentium2") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 799 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 800 | else if (Name == "pentpro") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 801 | DAL->AddJoinedArg(0, MArch, "pentiumpro"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 802 | else if (Name == "pentIIm3") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 803 | DAL->AddJoinedArg(0, MArch, "pentium2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 804 | |
| 805 | else if (Name == "x86_64") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 806 | DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 807 | |
| 808 | else if (Name == "arm") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 809 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 810 | else if (Name == "armv4t") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 811 | DAL->AddJoinedArg(0, MArch, "armv4t"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 812 | else if (Name == "armv5") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 813 | DAL->AddJoinedArg(0, MArch, "armv5tej"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 814 | else if (Name == "xscale") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 815 | DAL->AddJoinedArg(0, MArch, "xscale"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 816 | else if (Name == "armv6") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 817 | DAL->AddJoinedArg(0, MArch, "armv6k"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 818 | else if (Name == "armv6m") |
| 819 | DAL->AddJoinedArg(0, MArch, "armv6m"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 820 | else if (Name == "armv7") |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 821 | DAL->AddJoinedArg(0, MArch, "armv7a"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 822 | else if (Name == "armv7em") |
| 823 | DAL->AddJoinedArg(0, MArch, "armv7em"); |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 824 | else if (Name == "armv7f") |
| 825 | DAL->AddJoinedArg(0, MArch, "armv7f"); |
| 826 | else if (Name == "armv7k") |
| 827 | DAL->AddJoinedArg(0, MArch, "armv7k"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 828 | else if (Name == "armv7m") |
| 829 | DAL->AddJoinedArg(0, MArch, "armv7m"); |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 830 | else if (Name == "armv7s") |
| 831 | DAL->AddJoinedArg(0, MArch, "armv7s"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 832 | |
| 833 | else |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 834 | llvm_unreachable("invalid Darwin arch"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 835 | } |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 836 | |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 837 | // Add an explicit version min argument for the deployment target. We do this |
| 838 | // after argument translation because -Xarch_ arguments may add a version min |
| 839 | // argument. |
Chad Rosier | 98ab91c | 2012-04-27 19:51:11 +0000 | [diff] [blame] | 840 | if (BoundArch) |
| 841 | AddDeploymentTarget(*DAL); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 842 | |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 843 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. |
| 844 | // FIXME: It would be far better to avoid inserting those -static arguments, |
| 845 | // but we can't check the deployment target in the translation code until |
| 846 | // it is set here. |
| 847 | if (isTargetIPhoneOS() && !isIPhoneOSVersionLT(6, 0)) { |
| 848 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { |
| 849 | Arg *A = *it; |
| 850 | ++it; |
| 851 | if (A->getOption().getID() != options::OPT_mkernel && |
| 852 | A->getOption().getID() != options::OPT_fapple_kext) |
| 853 | continue; |
| 854 | assert(it != ie && "unexpected argument translation"); |
| 855 | A = *it; |
| 856 | assert(A->getOption().getID() == options::OPT_static && |
| 857 | "missing expected -static argument"); |
| 858 | it = DAL->getArgs().erase(it); |
| 859 | } |
| 860 | } |
| 861 | |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 862 | // Validate the C++ standard library choice. |
| 863 | CXXStdlibType Type = GetCXXStdlibType(*DAL); |
| 864 | if (Type == ToolChain::CST_Libcxx) { |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 865 | // Check whether the target provides libc++. |
| 866 | StringRef where; |
| 867 | |
| 868 | // Complain about targetting iOS < 5.0 in any way. |
Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 869 | if (isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)) |
| 870 | where = "iOS 5.0"; |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 871 | |
| 872 | if (where != StringRef()) { |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 873 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 874 | << where; |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 878 | return DAL; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 880 | |
Daniel Dunbar | f0a5b9b | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 881 | bool Darwin::IsUnwindTablesDefault() const { |
Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 882 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 885 | bool Darwin::UseDwarfDebugFlags() const { |
| 886 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 887 | return S[0] != '\0'; |
| 888 | return false; |
| 889 | } |
| 890 | |
Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 891 | bool Darwin::UseSjLjExceptions() const { |
| 892 | // Darwin uses SjLj exceptions on ARM. |
| 893 | return (getTriple().getArch() == llvm::Triple::arm || |
| 894 | getTriple().getArch() == llvm::Triple::thumb); |
| 895 | } |
| 896 | |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 897 | bool Darwin::isPICDefault() const { |
| 898 | return true; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 901 | bool Darwin::isPICDefaultForced() const { |
| 902 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 905 | bool Darwin::SupportsProfiling() const { |
| 906 | // Profiling instrumentation is only supported on x86. |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 907 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 908 | } |
| 909 | |
Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 910 | bool Darwin::SupportsObjCGC() const { |
| 911 | // Garbage collection is supported everywhere except on iPhone OS. |
| 912 | return !isTargetIPhoneOS(); |
| 913 | } |
| 914 | |
John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 915 | void Darwin::CheckObjCARC() const { |
| 916 | if (isTargetIPhoneOS() || !isMacosxVersionLT(10, 6)) |
| 917 | return; |
John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 918 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); |
Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 921 | std::string |
Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 922 | Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args, |
| 923 | types::ID InputType) const { |
| 924 | return ComputeLLVMTriple(Args, InputType); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 927 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 928 | /// all subcommands; this relies on gcc translating the majority of |
| 929 | /// command line options. |
| 930 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 931 | /// \brief Parse a GCCVersion object out of a string of text. |
| 932 | /// |
| 933 | /// This is the primary means of forming GCCVersion objects. |
| 934 | /*static*/ |
| 935 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { |
| 936 | const GCCVersion BadVersion = { VersionText.str(), -1, -1, -1, "" }; |
| 937 | std::pair<StringRef, StringRef> First = VersionText.split('.'); |
| 938 | std::pair<StringRef, StringRef> Second = First.second.split('.'); |
| 939 | |
| 940 | GCCVersion GoodVersion = { VersionText.str(), -1, -1, -1, "" }; |
| 941 | if (First.first.getAsInteger(10, GoodVersion.Major) || |
| 942 | GoodVersion.Major < 0) |
| 943 | return BadVersion; |
| 944 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || |
| 945 | GoodVersion.Minor < 0) |
| 946 | return BadVersion; |
| 947 | |
| 948 | // First look for a number prefix and parse that if present. Otherwise just |
| 949 | // stash the entire patch string in the suffix, and leave the number |
| 950 | // unspecified. This covers versions strings such as: |
| 951 | // 4.4 |
| 952 | // 4.4.0 |
| 953 | // 4.4.x |
| 954 | // 4.4.2-rc4 |
| 955 | // 4.4.x-patched |
| 956 | // And retains any patch number it finds. |
| 957 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); |
| 958 | if (!PatchText.empty()) { |
Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 959 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 960 | // Try to parse the number and any suffix. |
| 961 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || |
| 962 | GoodVersion.Patch < 0) |
| 963 | return BadVersion; |
| 964 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber).str(); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | return GoodVersion; |
| 969 | } |
| 970 | |
| 971 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. |
| 972 | bool Generic_GCC::GCCVersion::operator<(const GCCVersion &RHS) const { |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 973 | if (Major != RHS.Major) |
| 974 | return Major < RHS.Major; |
| 975 | if (Minor != RHS.Minor) |
| 976 | return Minor < RHS.Minor; |
| 977 | if (Patch != RHS.Patch) { |
| 978 | // Note that versions without a specified patch sort higher than those with |
| 979 | // a patch. |
| 980 | if (RHS.Patch == -1) |
| 981 | return true; |
| 982 | if (Patch == -1) |
| 983 | return false; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 984 | |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 985 | // Otherwise just sort on the patch itself. |
| 986 | return Patch < RHS.Patch; |
| 987 | } |
| 988 | if (PatchSuffix != RHS.PatchSuffix) { |
| 989 | // Sort empty suffixes higher. |
| 990 | if (RHS.PatchSuffix.empty()) |
| 991 | return true; |
| 992 | if (PatchSuffix.empty()) |
Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 993 | return false; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 994 | |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 995 | // Provide a lexicographic sort to make this a total ordering. |
| 996 | return PatchSuffix < RHS.PatchSuffix; |
| 997 | } |
| 998 | |
| 999 | // The versions are equal. |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1000 | return false; |
| 1001 | } |
| 1002 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1003 | static StringRef getGCCToolchainDir(const ArgList &Args) { |
| 1004 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); |
| 1005 | if (A) |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1006 | return A->getValue(); |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1007 | return GCC_INSTALL_PREFIX; |
| 1008 | } |
| 1009 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1010 | /// \brief Construct a GCCInstallationDetector from the driver. |
| 1011 | /// |
| 1012 | /// This performs all of the autodetection and sets up the various paths. |
Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1013 | /// Once constructed, a GCCInstallationDetector is essentially immutable. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1014 | /// |
| 1015 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and |
| 1016 | /// should instead pull the target out of the driver. This is currently |
| 1017 | /// necessary because the driver doesn't store the final version of the target |
| 1018 | /// triple. |
| 1019 | Generic_GCC::GCCInstallationDetector::GCCInstallationDetector( |
| 1020 | const Driver &D, |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1021 | const llvm::Triple &TargetTriple, |
| 1022 | const ArgList &Args) |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1023 | : IsValid(false) { |
Chandler Carruth | 779579b | 2012-02-13 02:02:09 +0000 | [diff] [blame] | 1024 | llvm::Triple MultiarchTriple |
| 1025 | = TargetTriple.isArch32Bit() ? TargetTriple.get64BitArchVariant() |
| 1026 | : TargetTriple.get32BitArchVariant(); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1027 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1028 | // The library directories which may contain GCC installations. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1029 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateMultiarchLibDirs; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1030 | // The compatible GCC triples for this particular architecture. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1031 | SmallVector<StringRef, 10> CandidateTripleAliases; |
| 1032 | SmallVector<StringRef, 10> CandidateMultiarchTripleAliases; |
| 1033 | CollectLibDirsAndTriples(TargetTriple, MultiarchTriple, CandidateLibDirs, |
| 1034 | CandidateTripleAliases, |
| 1035 | CandidateMultiarchLibDirs, |
| 1036 | CandidateMultiarchTripleAliases); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1037 | |
| 1038 | // Compute the set of prefixes for our search. |
| 1039 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), |
| 1040 | D.PrefixDirs.end()); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1041 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1042 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); |
| 1043 | if (GCCToolchainDir != "") { |
| 1044 | if (GCCToolchainDir.back() == '/') |
| 1045 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1046 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1047 | Prefixes.push_back(GCCToolchainDir); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1048 | } else { |
| 1049 | Prefixes.push_back(D.SysRoot); |
| 1050 | Prefixes.push_back(D.SysRoot + "/usr"); |
| 1051 | Prefixes.push_back(D.InstalledDir + "/.."); |
| 1052 | } |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1053 | |
| 1054 | // Loop over the various components which exist and select the best GCC |
| 1055 | // installation available. GCC installs are ranked by version number. |
| 1056 | Version = GCCVersion::Parse("0.0.0"); |
| 1057 | for (unsigned i = 0, ie = Prefixes.size(); i < ie; ++i) { |
| 1058 | if (!llvm::sys::fs::exists(Prefixes[i])) |
| 1059 | continue; |
| 1060 | for (unsigned j = 0, je = CandidateLibDirs.size(); j < je; ++j) { |
| 1061 | const std::string LibDir = Prefixes[i] + CandidateLibDirs[j].str(); |
| 1062 | if (!llvm::sys::fs::exists(LibDir)) |
| 1063 | continue; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1064 | for (unsigned k = 0, ke = CandidateTripleAliases.size(); k < ke; ++k) |
Simon Atanasyan | 2d1b1ad | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 1065 | ScanLibDirForGCCTriple(TargetArch, Args, LibDir, |
| 1066 | CandidateTripleAliases[k]); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1067 | } |
| 1068 | for (unsigned j = 0, je = CandidateMultiarchLibDirs.size(); j < je; ++j) { |
| 1069 | const std::string LibDir |
| 1070 | = Prefixes[i] + CandidateMultiarchLibDirs[j].str(); |
| 1071 | if (!llvm::sys::fs::exists(LibDir)) |
| 1072 | continue; |
| 1073 | for (unsigned k = 0, ke = CandidateMultiarchTripleAliases.size(); k < ke; |
| 1074 | ++k) |
Simon Atanasyan | 2d1b1ad | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 1075 | ScanLibDirForGCCTriple(TargetArch, Args, LibDir, |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1076 | CandidateMultiarchTripleAliases[k], |
| 1077 | /*NeedsMultiarchSuffix=*/true); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1083 | const llvm::Triple &TargetTriple, |
| 1084 | const llvm::Triple &MultiarchTriple, |
| 1085 | SmallVectorImpl<StringRef> &LibDirs, |
| 1086 | SmallVectorImpl<StringRef> &TripleAliases, |
| 1087 | SmallVectorImpl<StringRef> &MultiarchLibDirs, |
| 1088 | SmallVectorImpl<StringRef> &MultiarchTripleAliases) { |
| 1089 | // Declare a bunch of static data sets that we'll select between below. These |
| 1090 | // are specifically designed to always refer to string literals to avoid any |
| 1091 | // lifetime or initialization issues. |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1092 | static const char *const AArch64LibDirs[] = { "/lib" }; |
| 1093 | static const char *const AArch64Triples[] = { |
| 1094 | "aarch64-none-linux-gnu", |
| 1095 | "aarch64-linux-gnu" |
| 1096 | }; |
| 1097 | |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1098 | static const char *const ARMLibDirs[] = { "/lib" }; |
| 1099 | static const char *const ARMTriples[] = { |
| 1100 | "arm-linux-gnueabi", |
| 1101 | "arm-linux-androideabi" |
| 1102 | }; |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1103 | static const char *const ARMHFTriples[] = { |
| 1104 | "arm-linux-gnueabihf", |
| 1105 | }; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1106 | |
| 1107 | static const char *const X86_64LibDirs[] = { "/lib64", "/lib" }; |
| 1108 | static const char *const X86_64Triples[] = { |
| 1109 | "x86_64-linux-gnu", |
| 1110 | "x86_64-unknown-linux-gnu", |
| 1111 | "x86_64-pc-linux-gnu", |
| 1112 | "x86_64-redhat-linux6E", |
| 1113 | "x86_64-redhat-linux", |
| 1114 | "x86_64-suse-linux", |
| 1115 | "x86_64-manbo-linux-gnu", |
| 1116 | "x86_64-linux-gnu", |
| 1117 | "x86_64-slackware-linux" |
| 1118 | }; |
| 1119 | static const char *const X86LibDirs[] = { "/lib32", "/lib" }; |
| 1120 | static const char *const X86Triples[] = { |
| 1121 | "i686-linux-gnu", |
| 1122 | "i686-pc-linux-gnu", |
| 1123 | "i486-linux-gnu", |
| 1124 | "i386-linux-gnu", |
NAKAMURA Takumi | 55c1289 | 2012-12-07 17:13:18 +0000 | [diff] [blame] | 1125 | "i386-redhat-linux6E", |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1126 | "i686-redhat-linux", |
| 1127 | "i586-redhat-linux", |
| 1128 | "i386-redhat-linux", |
| 1129 | "i586-suse-linux", |
Gabor Greif | 9304763 | 2012-05-15 11:21:03 +0000 | [diff] [blame] | 1130 | "i486-slackware-linux", |
| 1131 | "i686-montavista-linux" |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1132 | }; |
| 1133 | |
| 1134 | static const char *const MIPSLibDirs[] = { "/lib" }; |
| 1135 | static const char *const MIPSTriples[] = { "mips-linux-gnu" }; |
| 1136 | static const char *const MIPSELLibDirs[] = { "/lib" }; |
Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 1137 | static const char *const MIPSELTriples[] = { |
| 1138 | "mipsel-linux-gnu", |
| 1139 | "mipsel-linux-android" |
| 1140 | }; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1141 | |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1142 | static const char *const MIPS64LibDirs[] = { "/lib64", "/lib" }; |
| 1143 | static const char *const MIPS64Triples[] = { "mips64-linux-gnu" }; |
| 1144 | static const char *const MIPS64ELLibDirs[] = { "/lib64", "/lib" }; |
| 1145 | static const char *const MIPS64ELTriples[] = { "mips64el-linux-gnu" }; |
| 1146 | |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1147 | static const char *const PPCLibDirs[] = { "/lib32", "/lib" }; |
| 1148 | static const char *const PPCTriples[] = { |
| 1149 | "powerpc-linux-gnu", |
| 1150 | "powerpc-unknown-linux-gnu", |
Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 1151 | "powerpc-linux-gnuspe", |
Gabor Greif | 9304763 | 2012-05-15 11:21:03 +0000 | [diff] [blame] | 1152 | "powerpc-suse-linux", |
| 1153 | "powerpc-montavista-linuxspe" |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1154 | }; |
| 1155 | static const char *const PPC64LibDirs[] = { "/lib64", "/lib" }; |
| 1156 | static const char *const PPC64Triples[] = { |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 1157 | "powerpc64-linux-gnu", |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1158 | "powerpc64-unknown-linux-gnu", |
| 1159 | "powerpc64-suse-linux", |
| 1160 | "ppc64-redhat-linux" |
| 1161 | }; |
| 1162 | |
| 1163 | switch (TargetTriple.getArch()) { |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1164 | case llvm::Triple::aarch64: |
Eric Christopher | c4b0be9 | 2013-02-05 07:29:49 +0000 | [diff] [blame] | 1165 | LibDirs.append(AArch64LibDirs, AArch64LibDirs |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1166 | + llvm::array_lengthof(AArch64LibDirs)); |
| 1167 | TripleAliases.append( |
| 1168 | AArch64Triples, AArch64Triples + llvm::array_lengthof(AArch64Triples)); |
| 1169 | MultiarchLibDirs.append( |
| 1170 | AArch64LibDirs, AArch64LibDirs + llvm::array_lengthof(AArch64LibDirs)); |
| 1171 | MultiarchTripleAliases.append( |
| 1172 | AArch64Triples, AArch64Triples + llvm::array_lengthof(AArch64Triples)); |
| 1173 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1174 | case llvm::Triple::arm: |
| 1175 | case llvm::Triple::thumb: |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1176 | LibDirs.append(ARMLibDirs, ARMLibDirs + llvm::array_lengthof(ARMLibDirs)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1177 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
| 1178 | TripleAliases.append( |
| 1179 | ARMHFTriples, ARMHFTriples + llvm::array_lengthof(ARMHFTriples)); |
| 1180 | } else { |
| 1181 | TripleAliases.append( |
| 1182 | ARMTriples, ARMTriples + llvm::array_lengthof(ARMTriples)); |
| 1183 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1184 | break; |
| 1185 | case llvm::Triple::x86_64: |
| 1186 | LibDirs.append( |
| 1187 | X86_64LibDirs, X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs)); |
| 1188 | TripleAliases.append( |
| 1189 | X86_64Triples, X86_64Triples + llvm::array_lengthof(X86_64Triples)); |
| 1190 | MultiarchLibDirs.append( |
| 1191 | X86LibDirs, X86LibDirs + llvm::array_lengthof(X86LibDirs)); |
| 1192 | MultiarchTripleAliases.append( |
| 1193 | X86Triples, X86Triples + llvm::array_lengthof(X86Triples)); |
| 1194 | break; |
| 1195 | case llvm::Triple::x86: |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1196 | LibDirs.append(X86LibDirs, X86LibDirs + llvm::array_lengthof(X86LibDirs)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1197 | TripleAliases.append( |
| 1198 | X86Triples, X86Triples + llvm::array_lengthof(X86Triples)); |
| 1199 | MultiarchLibDirs.append( |
| 1200 | X86_64LibDirs, X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs)); |
| 1201 | MultiarchTripleAliases.append( |
| 1202 | X86_64Triples, X86_64Triples + llvm::array_lengthof(X86_64Triples)); |
| 1203 | break; |
| 1204 | case llvm::Triple::mips: |
| 1205 | LibDirs.append( |
| 1206 | MIPSLibDirs, MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs)); |
| 1207 | TripleAliases.append( |
| 1208 | MIPSTriples, MIPSTriples + llvm::array_lengthof(MIPSTriples)); |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1209 | MultiarchLibDirs.append( |
| 1210 | MIPS64LibDirs, MIPS64LibDirs + llvm::array_lengthof(MIPS64LibDirs)); |
| 1211 | MultiarchTripleAliases.append( |
| 1212 | MIPS64Triples, MIPS64Triples + llvm::array_lengthof(MIPS64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1213 | break; |
| 1214 | case llvm::Triple::mipsel: |
| 1215 | LibDirs.append( |
| 1216 | MIPSELLibDirs, MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs)); |
| 1217 | TripleAliases.append( |
| 1218 | MIPSELTriples, MIPSELTriples + llvm::array_lengthof(MIPSELTriples)); |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1219 | MultiarchLibDirs.append( |
| 1220 | MIPS64ELLibDirs, MIPS64ELLibDirs + llvm::array_lengthof(MIPS64ELLibDirs)); |
| 1221 | MultiarchTripleAliases.append( |
| 1222 | MIPS64ELTriples, MIPS64ELTriples + llvm::array_lengthof(MIPS64ELTriples)); |
| 1223 | break; |
| 1224 | case llvm::Triple::mips64: |
| 1225 | LibDirs.append( |
| 1226 | MIPS64LibDirs, MIPS64LibDirs + llvm::array_lengthof(MIPS64LibDirs)); |
| 1227 | TripleAliases.append( |
| 1228 | MIPS64Triples, MIPS64Triples + llvm::array_lengthof(MIPS64Triples)); |
| 1229 | MultiarchLibDirs.append( |
| 1230 | MIPSLibDirs, MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs)); |
| 1231 | MultiarchTripleAliases.append( |
| 1232 | MIPSTriples, MIPSTriples + llvm::array_lengthof(MIPSTriples)); |
| 1233 | break; |
| 1234 | case llvm::Triple::mips64el: |
| 1235 | LibDirs.append( |
| 1236 | MIPS64ELLibDirs, MIPS64ELLibDirs + llvm::array_lengthof(MIPS64ELLibDirs)); |
| 1237 | TripleAliases.append( |
| 1238 | MIPS64ELTriples, MIPS64ELTriples + llvm::array_lengthof(MIPS64ELTriples)); |
| 1239 | MultiarchLibDirs.append( |
| 1240 | MIPSELLibDirs, MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs)); |
| 1241 | MultiarchTripleAliases.append( |
| 1242 | MIPSELTriples, MIPSELTriples + llvm::array_lengthof(MIPSELTriples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1243 | break; |
| 1244 | case llvm::Triple::ppc: |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1245 | LibDirs.append(PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1246 | TripleAliases.append( |
| 1247 | PPCTriples, PPCTriples + llvm::array_lengthof(PPCTriples)); |
| 1248 | MultiarchLibDirs.append( |
| 1249 | PPC64LibDirs, PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs)); |
| 1250 | MultiarchTripleAliases.append( |
| 1251 | PPC64Triples, PPC64Triples + llvm::array_lengthof(PPC64Triples)); |
| 1252 | break; |
| 1253 | case llvm::Triple::ppc64: |
| 1254 | LibDirs.append( |
| 1255 | PPC64LibDirs, PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs)); |
| 1256 | TripleAliases.append( |
| 1257 | PPC64Triples, PPC64Triples + llvm::array_lengthof(PPC64Triples)); |
| 1258 | MultiarchLibDirs.append( |
| 1259 | PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs)); |
| 1260 | MultiarchTripleAliases.append( |
| 1261 | PPCTriples, PPCTriples + llvm::array_lengthof(PPCTriples)); |
| 1262 | break; |
| 1263 | |
| 1264 | default: |
| 1265 | // By default, just rely on the standard lib directories and the original |
| 1266 | // triple. |
| 1267 | break; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1268 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1269 | |
| 1270 | // Always append the drivers target triple to the end, in case it doesn't |
| 1271 | // match any of our aliases. |
| 1272 | TripleAliases.push_back(TargetTriple.str()); |
| 1273 | |
| 1274 | // Also include the multiarch variant if it's different. |
| 1275 | if (TargetTriple.str() != MultiarchTriple.str()) |
| 1276 | MultiarchTripleAliases.push_back(MultiarchTriple.str()); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
Simon Atanasyan | 2d1b1ad | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 1279 | // FIXME: There is the same routine in the Tools.cpp. |
| 1280 | static bool hasMipsN32ABIArg(const ArgList &Args) { |
| 1281 | Arg *A = Args.getLastArg(options::OPT_mabi_EQ); |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1282 | return A && (A->getValue() == StringRef("n32")); |
Simon Atanasyan | 2d1b1ad | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | static StringRef getTargetMultiarchSuffix(llvm::Triple::ArchType TargetArch, |
| 1286 | const ArgList &Args) { |
| 1287 | if (TargetArch == llvm::Triple::x86_64 || |
| 1288 | TargetArch == llvm::Triple::ppc64) |
| 1289 | return "/64"; |
| 1290 | |
| 1291 | if (TargetArch == llvm::Triple::mips64 || |
| 1292 | TargetArch == llvm::Triple::mips64el) { |
| 1293 | if (hasMipsN32ABIArg(Args)) |
| 1294 | return "/n32"; |
| 1295 | else |
| 1296 | return "/64"; |
| 1297 | } |
| 1298 | |
| 1299 | return "/32"; |
| 1300 | } |
| 1301 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1302 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( |
Simon Atanasyan | 2d1b1ad | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 1303 | llvm::Triple::ArchType TargetArch, const ArgList &Args, |
| 1304 | const std::string &LibDir, |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1305 | StringRef CandidateTriple, bool NeedsMultiarchSuffix) { |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1306 | // There are various different suffixes involving the triple we |
| 1307 | // check for. We also record what is necessary to walk from each back |
| 1308 | // up to the lib directory. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1309 | const std::string LibSuffixes[] = { |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1310 | "/gcc/" + CandidateTriple.str(), |
| 1311 | "/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), |
| 1312 | |
Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 1313 | // The Freescale PPC SDK has the gcc libraries in |
| 1314 | // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. |
| 1315 | "/" + CandidateTriple.str(), |
| 1316 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1317 | // Ubuntu has a strange mis-matched pair of triples that this happens to |
| 1318 | // match. |
| 1319 | // FIXME: It may be worthwhile to generalize this and look for a second |
| 1320 | // triple. |
Chandler Carruth | 6e46ca2 | 2011-11-09 03:46:20 +0000 | [diff] [blame] | 1321 | "/i386-linux-gnu/gcc/" + CandidateTriple.str() |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1322 | }; |
| 1323 | const std::string InstallSuffixes[] = { |
| 1324 | "/../../..", |
| 1325 | "/../../../..", |
Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 1326 | "/../..", |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1327 | "/../../../.." |
| 1328 | }; |
| 1329 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1330 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibSuffixes) - |
| 1331 | (TargetArch != llvm::Triple::x86)); |
| 1332 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { |
| 1333 | StringRef LibSuffix = LibSuffixes[i]; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1334 | llvm::error_code EC; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1335 | for (llvm::sys::fs::directory_iterator LI(LibDir + LibSuffix, EC), LE; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1336 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 1337 | StringRef VersionText = llvm::sys::path::filename(LI->path()); |
| 1338 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| 1339 | static const GCCVersion MinVersion = { "4.1.1", 4, 1, 1, "" }; |
| 1340 | if (CandidateVersion < MinVersion) |
| 1341 | continue; |
| 1342 | if (CandidateVersion <= Version) |
| 1343 | continue; |
Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 1344 | |
| 1345 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs |
Chandler Carruth | 64cee06 | 2012-01-24 19:21:42 +0000 | [diff] [blame] | 1346 | // in what would normally be GCCInstallPath and put the 64-bit |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1347 | // libs in a subdirectory named 64. The simple logic we follow is that |
| 1348 | // *if* there is a subdirectory of the right name with crtbegin.o in it, |
| 1349 | // we use that. If not, and if not a multiarch triple, we look for |
| 1350 | // crtbegin.o without the subdirectory. |
Simon Atanasyan | 2d1b1ad | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 1351 | StringRef MultiarchSuffix = getTargetMultiarchSuffix(TargetArch, Args); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1352 | if (llvm::sys::fs::exists(LI->path() + MultiarchSuffix + "/crtbegin.o")) { |
| 1353 | GCCMultiarchSuffix = MultiarchSuffix.str(); |
| 1354 | } else { |
| 1355 | if (NeedsMultiarchSuffix || |
| 1356 | !llvm::sys::fs::exists(LI->path() + "/crtbegin.o")) |
| 1357 | continue; |
| 1358 | GCCMultiarchSuffix.clear(); |
| 1359 | } |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1360 | |
| 1361 | Version = CandidateVersion; |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 1362 | GCCTriple.setTriple(CandidateTriple); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1363 | // FIXME: We hack together the directory name here instead of |
| 1364 | // using LI to ensure stable path separators across Windows and |
| 1365 | // Linux. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1366 | GCCInstallPath = LibDir + LibSuffixes[i] + "/" + VersionText.str(); |
Chandler Carruth | 64cee06 | 2012-01-24 19:21:42 +0000 | [diff] [blame] | 1367 | GCCParentLibPath = GCCInstallPath + InstallSuffixes[i]; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1368 | IsValid = true; |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1373 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple& Triple, |
| 1374 | const ArgList &Args) |
| 1375 | : ToolChain(D, Triple), GCCInstallation(getDriver(), Triple, Args) { |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1376 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 1377 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1378 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1381 | Generic_GCC::~Generic_GCC() { |
| 1382 | // Free tool implementations. |
| 1383 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 1384 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 1385 | delete it->second; |
| 1386 | } |
| 1387 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1388 | Tool &Generic_GCC::SelectTool(const Compilation &C, |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1389 | const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1390 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 1391 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1392 | Key = Action::AnalyzeJobClass; |
| 1393 | else |
| 1394 | Key = JA.getKind(); |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1395 | |
| 1396 | Tool *&T = Tools[Key]; |
| 1397 | if (!T) { |
| 1398 | switch (Key) { |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1399 | case Action::InputClass: |
| 1400 | case Action::BindArchClass: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1401 | llvm_unreachable("Invalid tool kind."); |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1402 | case Action::PreprocessJobClass: |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1403 | T = new tools::gcc::Preprocess(*this); break; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1404 | case Action::PrecompileJobClass: |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1405 | T = new tools::gcc::Precompile(*this); break; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1406 | case Action::AnalyzeJobClass: |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1407 | case Action::MigrateJobClass: |
Bob Wilson | 0c79f3c | 2012-11-08 01:03:34 +0000 | [diff] [blame] | 1408 | T = new tools::Clang(*this); break; |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1409 | case Action::CompileJobClass: |
| 1410 | T = new tools::gcc::Compile(*this); break; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1411 | case Action::AssembleJobClass: |
| 1412 | T = new tools::gcc::Assemble(*this); break; |
| 1413 | case Action::LinkJobClass: |
| 1414 | T = new tools::gcc::Link(*this); break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1415 | |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1416 | // This is a bit ungeneric, but the only platform using a driver |
| 1417 | // driver is Darwin. |
| 1418 | case Action::LipoJobClass: |
| 1419 | T = new tools::darwin::Lipo(*this); break; |
Daniel Dunbar | 8829962 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 1420 | case Action::DsymutilJobClass: |
| 1421 | T = new tools::darwin::Dsymutil(*this); break; |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 1422 | case Action::VerifyJobClass: |
| 1423 | T = new tools::darwin::VerifyDebug(*this); break; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | return *T; |
| 1428 | } |
| 1429 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1430 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 1431 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1434 | bool Generic_GCC::isPICDefault() const { |
| 1435 | return false; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1438 | bool Generic_GCC::isPICDefaultForced() const { |
| 1439 | return false; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1440 | } |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1441 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1442 | /// Hexagon Toolchain |
| 1443 | |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 1444 | std::string Hexagon_TC::GetGnuDir(const std::string &InstalledDir) { |
| 1445 | |
| 1446 | // Locate the rest of the toolchain ... |
| 1447 | if (strlen(GCC_INSTALL_PREFIX)) |
| 1448 | return std::string(GCC_INSTALL_PREFIX); |
| 1449 | |
| 1450 | std::string InstallRelDir = InstalledDir + "/../../gnu"; |
| 1451 | if (llvm::sys::fs::exists(InstallRelDir)) |
| 1452 | return InstallRelDir; |
| 1453 | |
| 1454 | std::string PrefixRelDir = std::string(LLVM_PREFIX) + "/../gnu"; |
| 1455 | if (llvm::sys::fs::exists(PrefixRelDir)) |
| 1456 | return PrefixRelDir; |
| 1457 | |
| 1458 | return InstallRelDir; |
| 1459 | } |
| 1460 | |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 1461 | static void GetHexagonLibraryPaths( |
| 1462 | const ArgList &Args, |
| 1463 | const std::string Ver, |
| 1464 | const std::string MarchString, |
| 1465 | const std::string &InstalledDir, |
| 1466 | ToolChain::path_list *LibPaths) |
| 1467 | { |
| 1468 | bool buildingLib = Args.hasArg(options::OPT_shared); |
| 1469 | |
| 1470 | //---------------------------------------------------------------------------- |
| 1471 | // -L Args |
| 1472 | //---------------------------------------------------------------------------- |
| 1473 | for (arg_iterator |
| 1474 | it = Args.filtered_begin(options::OPT_L), |
| 1475 | ie = Args.filtered_end(); |
| 1476 | it != ie; |
| 1477 | ++it) { |
| 1478 | for (unsigned i = 0, e = (*it)->getNumValues(); i != e; ++i) |
| 1479 | LibPaths->push_back((*it)->getValue(i)); |
| 1480 | } |
| 1481 | |
| 1482 | //---------------------------------------------------------------------------- |
| 1483 | // Other standard paths |
| 1484 | //---------------------------------------------------------------------------- |
| 1485 | const std::string MarchSuffix = "/" + MarchString; |
| 1486 | const std::string G0Suffix = "/G0"; |
| 1487 | const std::string MarchG0Suffix = MarchSuffix + G0Suffix; |
| 1488 | const std::string RootDir = Hexagon_TC::GetGnuDir(InstalledDir) + "/"; |
| 1489 | |
| 1490 | // lib/gcc/hexagon/... |
| 1491 | std::string LibGCCHexagonDir = RootDir + "lib/gcc/hexagon/"; |
| 1492 | if (buildingLib) { |
| 1493 | LibPaths->push_back(LibGCCHexagonDir + Ver + MarchG0Suffix); |
| 1494 | LibPaths->push_back(LibGCCHexagonDir + Ver + G0Suffix); |
| 1495 | } |
| 1496 | LibPaths->push_back(LibGCCHexagonDir + Ver + MarchSuffix); |
| 1497 | LibPaths->push_back(LibGCCHexagonDir + Ver); |
| 1498 | |
| 1499 | // lib/gcc/... |
| 1500 | LibPaths->push_back(RootDir + "lib/gcc"); |
| 1501 | |
| 1502 | // hexagon/lib/... |
| 1503 | std::string HexagonLibDir = RootDir + "hexagon/lib"; |
| 1504 | if (buildingLib) { |
| 1505 | LibPaths->push_back(HexagonLibDir + MarchG0Suffix); |
| 1506 | LibPaths->push_back(HexagonLibDir + G0Suffix); |
| 1507 | } |
| 1508 | LibPaths->push_back(HexagonLibDir + MarchSuffix); |
| 1509 | LibPaths->push_back(HexagonLibDir); |
| 1510 | } |
| 1511 | |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 1512 | Hexagon_TC::Hexagon_TC(const Driver &D, const llvm::Triple &Triple, |
| 1513 | const ArgList &Args) |
| 1514 | : Linux(D, Triple, Args) { |
| 1515 | const std::string InstalledDir(getDriver().getInstalledDir()); |
| 1516 | const std::string GnuDir = Hexagon_TC::GetGnuDir(InstalledDir); |
| 1517 | |
| 1518 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to |
| 1519 | // program paths |
| 1520 | const std::string BinDir(GnuDir + "/bin"); |
| 1521 | if (llvm::sys::fs::exists(BinDir)) |
| 1522 | getProgramPaths().push_back(BinDir); |
| 1523 | |
| 1524 | // Determine version of GCC libraries and headers to use. |
| 1525 | const std::string HexagonDir(GnuDir + "/lib/gcc/hexagon"); |
| 1526 | llvm::error_code ec; |
| 1527 | GCCVersion MaxVersion= GCCVersion::Parse("0.0.0"); |
| 1528 | for (llvm::sys::fs::directory_iterator di(HexagonDir, ec), de; |
| 1529 | !ec && di != de; di = di.increment(ec)) { |
| 1530 | GCCVersion cv = GCCVersion::Parse(llvm::sys::path::filename(di->path())); |
| 1531 | if (MaxVersion < cv) |
| 1532 | MaxVersion = cv; |
| 1533 | } |
| 1534 | GCCLibAndIncVersion = MaxVersion; |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 1535 | |
| 1536 | ToolChain::path_list *LibPaths= &getFilePaths(); |
| 1537 | |
| 1538 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets |
| 1539 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually |
| 1540 | // support 'linux' we'll need to fix this up |
| 1541 | LibPaths->clear(); |
| 1542 | |
| 1543 | GetHexagonLibraryPaths( |
| 1544 | Args, |
| 1545 | GetGCCLibAndIncVersion(), |
| 1546 | GetTargetCPU(Args), |
| 1547 | InstalledDir, |
| 1548 | LibPaths); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | Hexagon_TC::~Hexagon_TC() { |
| 1552 | // Free tool implementations. |
| 1553 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 1554 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 1555 | delete it->second; |
| 1556 | } |
| 1557 | |
| 1558 | Tool &Hexagon_TC::SelectTool(const Compilation &C, |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1559 | const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1560 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 1561 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1562 | Key = Action::AnalyzeJobClass; |
| 1563 | else |
| 1564 | Key = JA.getKind(); |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1565 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1566 | Tool *&T = Tools[Key]; |
| 1567 | if (!T) { |
| 1568 | switch (Key) { |
| 1569 | case Action::InputClass: |
| 1570 | case Action::BindArchClass: |
| 1571 | assert(0 && "Invalid tool kind."); |
| 1572 | case Action::AnalyzeJobClass: |
| 1573 | T = new tools::Clang(*this); break; |
| 1574 | case Action::AssembleJobClass: |
| 1575 | T = new tools::hexagon::Assemble(*this); break; |
| 1576 | case Action::LinkJobClass: |
| 1577 | T = new tools::hexagon::Link(*this); break; |
| 1578 | default: |
| 1579 | assert(false && "Unsupported action for Hexagon target."); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | return *T; |
| 1584 | } |
| 1585 | |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 1586 | void Hexagon_TC::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 1587 | ArgStringList &CC1Args) const { |
| 1588 | const Driver &D = getDriver(); |
| 1589 | |
| 1590 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 1591 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 1592 | return; |
| 1593 | |
| 1594 | llvm::sys::Path InstallDir(D.InstalledDir); |
| 1595 | std::string Ver(GetGCCLibAndIncVersion()); |
| 1596 | std::string GnuDir = Hexagon_TC::GetGnuDir(D.InstalledDir); |
| 1597 | std::string HexagonDir(GnuDir + "/lib/gcc/hexagon/" + Ver); |
| 1598 | addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include"); |
| 1599 | addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include-fixed"); |
| 1600 | addExternCSystemInclude(DriverArgs, CC1Args, GnuDir + "/hexagon/include"); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 1603 | void Hexagon_TC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 1604 | ArgStringList &CC1Args) const { |
| 1605 | |
| 1606 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 1607 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 1608 | return; |
| 1609 | |
| 1610 | const Driver &D = getDriver(); |
| 1611 | std::string Ver(GetGCCLibAndIncVersion()); |
| 1612 | llvm::sys::Path IncludeDir(Hexagon_TC::GetGnuDir(D.InstalledDir)); |
| 1613 | |
| 1614 | IncludeDir.appendComponent("hexagon/include/c++/"); |
| 1615 | IncludeDir.appendComponent(Ver); |
| 1616 | addSystemInclude(DriverArgs, CC1Args, IncludeDir.str()); |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1617 | } |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 1618 | |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 1619 | ToolChain::CXXStdlibType |
| 1620 | Hexagon_TC::GetCXXStdlibType(const ArgList &Args) const { |
| 1621 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 1622 | if (!A) |
| 1623 | return ToolChain::CST_Libstdcxx; |
| 1624 | |
| 1625 | StringRef Value = A->getValue(); |
| 1626 | if (Value != "libstdc++") { |
| 1627 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) |
| 1628 | << A->getAsString(Args); |
| 1629 | } |
| 1630 | |
| 1631 | return ToolChain::CST_Libstdcxx; |
| 1632 | } |
| 1633 | |
| 1634 | static Arg *GetLastHexagonArchArg(const ArgList &Args) |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 1635 | { |
| 1636 | Arg *A = NULL; |
| 1637 | |
| 1638 | for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); |
| 1639 | it != ie; ++it) { |
| 1640 | if ((*it)->getOption().matches(options::OPT_march_EQ) || |
| 1641 | (*it)->getOption().matches(options::OPT_mcpu_EQ)) { |
| 1642 | A = *it; |
| 1643 | A->claim(); |
| 1644 | } else if ((*it)->getOption().matches(options::OPT_m_Joined)) { |
| 1645 | StringRef Value = (*it)->getValue(0); |
| 1646 | if (Value.startswith("v")) { |
| 1647 | A = *it; |
| 1648 | A->claim(); |
| 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | return A; |
| 1653 | } |
| 1654 | |
| 1655 | StringRef Hexagon_TC::GetTargetCPU(const ArgList &Args) |
| 1656 | { |
| 1657 | // Select the default CPU (v4) if none was given or detection failed. |
| 1658 | Arg *A = GetLastHexagonArchArg (Args); |
| 1659 | if (A) { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1660 | StringRef WhichHexagon = A->getValue(); |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 1661 | if (WhichHexagon.startswith("hexagon")) |
| 1662 | return WhichHexagon.substr(sizeof("hexagon") - 1); |
| 1663 | if (WhichHexagon != "") |
| 1664 | return WhichHexagon; |
| 1665 | } |
| 1666 | |
| 1667 | return "v4"; |
| 1668 | } |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 1669 | // End Hexagon |
Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 1670 | |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1671 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 1672 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 1673 | /// Currently does not support anything else but compilation. |
| 1674 | |
Chandler Carruth | d7fa2e0 | 2012-01-31 02:21:20 +0000 | [diff] [blame] | 1675 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple& Triple) |
| 1676 | : ToolChain(D, Triple) { |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1677 | // Path mangling to find libexec |
| 1678 | std::string Path(getDriver().Dir); |
| 1679 | |
| 1680 | Path += "/../libexec"; |
| 1681 | getProgramPaths().push_back(Path); |
| 1682 | } |
| 1683 | |
| 1684 | TCEToolChain::~TCEToolChain() { |
| 1685 | for (llvm::DenseMap<unsigned, Tool*>::iterator |
| 1686 | it = Tools.begin(), ie = Tools.end(); it != ie; ++it) |
| 1687 | delete it->second; |
| 1688 | } |
| 1689 | |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 1690 | bool TCEToolChain::IsMathErrnoDefault() const { |
| 1691 | return true; |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1694 | bool TCEToolChain::isPICDefault() const { |
| 1695 | return false; |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1698 | bool TCEToolChain::isPICDefaultForced() const { |
| 1699 | return false; |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 1702 | Tool &TCEToolChain::SelectTool(const Compilation &C, |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1703 | const JobAction &JA) const { |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1704 | Action::ActionClass Key; |
| 1705 | Key = Action::AnalyzeJobClass; |
| 1706 | |
| 1707 | Tool *&T = Tools[Key]; |
| 1708 | if (!T) { |
| 1709 | switch (Key) { |
| 1710 | case Action::PreprocessJobClass: |
| 1711 | T = new tools::gcc::Preprocess(*this); break; |
| 1712 | case Action::AnalyzeJobClass: |
| 1713 | T = new tools::Clang(*this); break; |
| 1714 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1715 | llvm_unreachable("Unsupported action for TCE target."); |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | return *T; |
| 1719 | } |
| 1720 | |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1721 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 1722 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1723 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1724 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1725 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1726 | getFilePaths().push_back("/usr/lib"); |
| 1727 | } |
| 1728 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1729 | Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1730 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 1731 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1732 | Key = Action::AnalyzeJobClass; |
| 1733 | else |
| 1734 | Key = JA.getKind(); |
| 1735 | |
Rafael Espindola | 96aef79 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1736 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1737 | options::OPT_no_integrated_as, |
| 1738 | IsIntegratedAssemblerDefault()); |
| 1739 | |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1740 | Tool *&T = Tools[Key]; |
| 1741 | if (!T) { |
| 1742 | switch (Key) { |
Rafael Espindola | 96aef79 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 1743 | case Action::AssembleJobClass: { |
| 1744 | if (UseIntegratedAs) |
| 1745 | T = new tools::ClangAs(*this); |
| 1746 | else |
| 1747 | T = new tools::openbsd::Assemble(*this); |
| 1748 | break; |
| 1749 | } |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1750 | case Action::LinkJobClass: |
| 1751 | T = new tools::openbsd::Link(*this); break; |
| 1752 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1753 | T = &Generic_GCC::SelectTool(C, JA); |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | return *T; |
| 1758 | } |
| 1759 | |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 1760 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. |
| 1761 | |
| 1762 | Bitrig::Bitrig(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1763 | : Generic_ELF(D, Triple, Args) { |
| 1764 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 1765 | getFilePaths().push_back("/usr/lib"); |
| 1766 | } |
| 1767 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1768 | Tool &Bitrig::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1769 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 1770 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1771 | Key = Action::AnalyzeJobClass; |
| 1772 | else |
| 1773 | Key = JA.getKind(); |
| 1774 | |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 1775 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1776 | options::OPT_no_integrated_as, |
| 1777 | IsIntegratedAssemblerDefault()); |
| 1778 | |
| 1779 | Tool *&T = Tools[Key]; |
| 1780 | if (!T) { |
| 1781 | switch (Key) { |
| 1782 | case Action::AssembleJobClass: { |
| 1783 | if (UseIntegratedAs) |
| 1784 | T = new tools::ClangAs(*this); |
| 1785 | else |
| 1786 | T = new tools::bitrig::Assemble(*this); |
| 1787 | break; |
| 1788 | } |
| 1789 | case Action::LinkJobClass: |
| 1790 | T = new tools::bitrig::Link(*this); break; |
| 1791 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1792 | T = &Generic_GCC::SelectTool(C, JA); |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | return *T; |
| 1797 | } |
| 1798 | |
| 1799 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 1800 | ArgStringList &CC1Args) const { |
| 1801 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 1802 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 1803 | return; |
| 1804 | |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 1805 | switch (GetCXXStdlibType(DriverArgs)) { |
| 1806 | case ToolChain::CST_Libcxx: |
| 1807 | addSystemInclude(DriverArgs, CC1Args, |
| 1808 | getDriver().SysRoot + "/usr/include/c++/"); |
| 1809 | break; |
| 1810 | case ToolChain::CST_Libstdcxx: |
| 1811 | addSystemInclude(DriverArgs, CC1Args, |
| 1812 | getDriver().SysRoot + "/usr/include/c++/stdc++"); |
| 1813 | addSystemInclude(DriverArgs, CC1Args, |
| 1814 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 1815 | |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 1816 | StringRef Triple = getTriple().str(); |
| 1817 | if (Triple.startswith("amd64")) |
| 1818 | addSystemInclude(DriverArgs, CC1Args, |
| 1819 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + |
| 1820 | Triple.substr(5)); |
| 1821 | else |
| 1822 | addSystemInclude(DriverArgs, CC1Args, |
| 1823 | getDriver().SysRoot + "/usr/include/c++/stdc++/" + |
| 1824 | Triple); |
| 1825 | break; |
| 1826 | } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, |
| 1830 | ArgStringList &CmdArgs) const { |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 1831 | switch (GetCXXStdlibType(Args)) { |
| 1832 | case ToolChain::CST_Libcxx: |
| 1833 | CmdArgs.push_back("-lc++"); |
| 1834 | CmdArgs.push_back("-lcxxrt"); |
| 1835 | // Include supc++ to provide Unwind until provided by libcxx. |
| 1836 | CmdArgs.push_back("-lgcc"); |
| 1837 | break; |
| 1838 | case ToolChain::CST_Libstdcxx: |
| 1839 | CmdArgs.push_back("-lstdc++"); |
| 1840 | break; |
| 1841 | } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1844 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 1845 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1846 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1847 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 1848 | |
Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 1849 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall |
| 1850 | // back to '/usr/lib' if it doesn't exist. |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 1851 | if ((Triple.getArch() == llvm::Triple::x86 || |
| 1852 | Triple.getArch() == llvm::Triple::ppc) && |
Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 1853 | llvm::sys::fs::exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 1854 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); |
| 1855 | else |
| 1856 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1859 | Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1860 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 1861 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1862 | Key = Action::AnalyzeJobClass; |
| 1863 | else |
| 1864 | Key = JA.getKind(); |
| 1865 | |
Roman Divacky | 137426a | 2010-11-08 17:46:39 +0000 | [diff] [blame] | 1866 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1867 | options::OPT_no_integrated_as, |
| 1868 | IsIntegratedAssemblerDefault()); |
| 1869 | |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1870 | Tool *&T = Tools[Key]; |
| 1871 | if (!T) { |
| 1872 | switch (Key) { |
Daniel Dunbar | 8eb473c | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1873 | case Action::AssembleJobClass: |
Roman Divacky | 137426a | 2010-11-08 17:46:39 +0000 | [diff] [blame] | 1874 | if (UseIntegratedAs) |
| 1875 | T = new tools::ClangAs(*this); |
| 1876 | else |
| 1877 | T = new tools::freebsd::Assemble(*this); |
Roman Divacky | b45d267 | 2010-11-08 19:39:10 +0000 | [diff] [blame] | 1878 | break; |
Daniel Dunbar | d854c8d | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1879 | case Action::LinkJobClass: |
| 1880 | T = new tools::freebsd::Link(*this); break; |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1881 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1882 | T = &Generic_GCC::SelectTool(C, JA); |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | return *T; |
| 1887 | } |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 1888 | |
Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 1889 | bool FreeBSD::UseSjLjExceptions() const { |
| 1890 | // FreeBSD uses SjLj exceptions on ARM oabi. |
| 1891 | switch (getTriple().getEnvironment()) { |
| 1892 | case llvm::Triple::GNUEABI: |
| 1893 | case llvm::Triple::EABI: |
| 1894 | return false; |
| 1895 | |
| 1896 | default: |
| 1897 | return (getTriple().getArch() == llvm::Triple::arm || |
| 1898 | getTriple().getArch() == llvm::Triple::thumb); |
| 1899 | } |
| 1900 | } |
| 1901 | |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1902 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 1903 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1904 | NetBSD::NetBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1905 | : Generic_ELF(D, Triple, Args) { |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1906 | |
Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 1907 | if (getDriver().UseStdLib) { |
Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 1908 | // When targeting a 32-bit platform, try the special directory used on |
| 1909 | // 64-bit hosts, and only fall back to the main library directory if that |
| 1910 | // doesn't work. |
| 1911 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure |
| 1912 | // what all logic is needed to emulate the '=' prefix here. |
Joerg Sonnenberger | f8ce857 | 2012-01-26 21:58:37 +0000 | [diff] [blame] | 1913 | if (Triple.getArch() == llvm::Triple::x86) |
Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 1914 | getFilePaths().push_back("=/usr/lib/i386"); |
Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 1915 | |
| 1916 | getFilePaths().push_back("=/usr/lib"); |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1920 | Tool &NetBSD::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1921 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 1922 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1923 | Key = Action::AnalyzeJobClass; |
| 1924 | else |
| 1925 | Key = JA.getKind(); |
| 1926 | |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1927 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 1928 | options::OPT_no_integrated_as, |
| 1929 | IsIntegratedAssemblerDefault()); |
| 1930 | |
| 1931 | Tool *&T = Tools[Key]; |
| 1932 | if (!T) { |
| 1933 | switch (Key) { |
| 1934 | case Action::AssembleJobClass: |
| 1935 | if (UseIntegratedAs) |
| 1936 | T = new tools::ClangAs(*this); |
| 1937 | else |
Joerg Sonnenberger | d64c60e | 2012-01-26 22:27:52 +0000 | [diff] [blame] | 1938 | T = new tools::netbsd::Assemble(*this); |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1939 | break; |
| 1940 | case Action::LinkJobClass: |
Joerg Sonnenberger | d64c60e | 2012-01-26 22:27:52 +0000 | [diff] [blame] | 1941 | T = new tools::netbsd::Link(*this); |
Joerg Sonnenberger | 637603a | 2011-05-16 13:35:02 +0000 | [diff] [blame] | 1942 | break; |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1943 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1944 | T = &Generic_GCC::SelectTool(C, JA); |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | return *T; |
| 1949 | } |
| 1950 | |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1951 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 1952 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1953 | Minix::Minix(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 1954 | : Generic_ELF(D, Triple, Args) { |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1955 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 1956 | getFilePaths().push_back("/usr/lib"); |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1959 | Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1960 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 1961 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 1962 | Key = Action::AnalyzeJobClass; |
| 1963 | else |
| 1964 | Key = JA.getKind(); |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1965 | |
| 1966 | Tool *&T = Tools[Key]; |
| 1967 | if (!T) { |
| 1968 | switch (Key) { |
| 1969 | case Action::AssembleJobClass: |
| 1970 | T = new tools::minix::Assemble(*this); break; |
| 1971 | case Action::LinkJobClass: |
| 1972 | T = new tools::minix::Link(*this); break; |
| 1973 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1974 | T = &Generic_GCC::SelectTool(C, JA); |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 1975 | } |
| 1976 | } |
| 1977 | |
| 1978 | return *T; |
| 1979 | } |
| 1980 | |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1981 | /// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. |
| 1982 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1983 | AuroraUX::AuroraUX(const Driver &D, const llvm::Triple& Triple, |
| 1984 | const ArgList &Args) |
| 1985 | : Generic_GCC(D, Triple, Args) { |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1986 | |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1987 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 1988 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 1989 | getProgramPaths().push_back(getDriver().Dir); |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1990 | |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1991 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1992 | getFilePaths().push_back("/usr/lib"); |
| 1993 | getFilePaths().push_back("/usr/sfw/lib"); |
| 1994 | getFilePaths().push_back("/opt/gcc4/lib"); |
Edward O'Callaghan | d8712d9 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 1995 | getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4"); |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1996 | |
| 1997 | } |
| 1998 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 1999 | Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 2000 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 2001 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 2002 | Key = Action::AnalyzeJobClass; |
| 2003 | else |
| 2004 | Key = JA.getKind(); |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 2005 | |
| 2006 | Tool *&T = Tools[Key]; |
| 2007 | if (!T) { |
| 2008 | switch (Key) { |
| 2009 | case Action::AssembleJobClass: |
| 2010 | T = new tools::auroraux::Assemble(*this); break; |
| 2011 | case Action::LinkJobClass: |
| 2012 | T = new tools::auroraux::Link(*this); break; |
| 2013 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 2014 | T = &Generic_GCC::SelectTool(C, JA); |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | return *T; |
| 2019 | } |
| 2020 | |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 2021 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. |
| 2022 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2023 | Solaris::Solaris(const Driver &D, const llvm::Triple& Triple, |
| 2024 | const ArgList &Args) |
| 2025 | : Generic_GCC(D, Triple, Args) { |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 2026 | |
| 2027 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 2028 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 2029 | getProgramPaths().push_back(getDriver().Dir); |
| 2030 | |
| 2031 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 2032 | getFilePaths().push_back("/usr/lib"); |
| 2033 | } |
| 2034 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 2035 | Tool &Solaris::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 2036 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 2037 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 2038 | Key = Action::AnalyzeJobClass; |
| 2039 | else |
| 2040 | Key = JA.getKind(); |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 2041 | |
| 2042 | Tool *&T = Tools[Key]; |
| 2043 | if (!T) { |
| 2044 | switch (Key) { |
| 2045 | case Action::AssembleJobClass: |
| 2046 | T = new tools::solaris::Assemble(*this); break; |
| 2047 | case Action::LinkJobClass: |
| 2048 | T = new tools::solaris::Link(*this); break; |
| 2049 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 2050 | T = &Generic_GCC::SelectTool(C, JA); |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | return *T; |
| 2055 | } |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 2056 | |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 2057 | /// Linux toolchain (very bare-bones at the moment). |
| 2058 | |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2059 | enum LinuxDistro { |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 2060 | ArchLinux, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2061 | DebianLenny, |
| 2062 | DebianSqueeze, |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 2063 | DebianWheezy, |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 2064 | DebianJessie, |
Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 2065 | Exherbo, |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 2066 | RHEL4, |
| 2067 | RHEL5, |
| 2068 | RHEL6, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2069 | Fedora13, |
| 2070 | Fedora14, |
Eric Christopher | 534b6a0 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 2071 | Fedora15, |
Benjamin Kramer | 3bb42f3 | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 2072 | Fedora16, |
Eric Christopher | 534b6a0 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 2073 | FedoraRawhide, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2074 | OpenSuse11_3, |
David Chisnall | b8f65e2 | 2011-05-19 13:26:33 +0000 | [diff] [blame] | 2075 | OpenSuse11_4, |
| 2076 | OpenSuse12_1, |
Douglas Gregor | f7b8841 | 2012-04-30 23:42:57 +0000 | [diff] [blame] | 2077 | OpenSuse12_2, |
Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 2078 | UbuntuHardy, |
| 2079 | UbuntuIntrepid, |
Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 2080 | UbuntuJaunty, |
Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 2081 | UbuntuKarmic, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2082 | UbuntuLucid, |
| 2083 | UbuntuMaverick, |
Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 2084 | UbuntuNatty, |
Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 2085 | UbuntuOneiric, |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 2086 | UbuntuPrecise, |
Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 2087 | UbuntuQuantal, |
| 2088 | UbuntuRaring, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2089 | UnknownDistro |
| 2090 | }; |
| 2091 | |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 2092 | static bool IsRedhat(enum LinuxDistro Distro) { |
Benjamin Kramer | 3bb42f3 | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 2093 | return (Distro >= Fedora13 && Distro <= FedoraRawhide) || |
| 2094 | (Distro >= RHEL4 && Distro <= RHEL6); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | static bool IsOpenSuse(enum LinuxDistro Distro) { |
Douglas Gregor | f7b8841 | 2012-04-30 23:42:57 +0000 | [diff] [blame] | 2098 | return Distro >= OpenSuse11_3 && Distro <= OpenSuse12_2; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | static bool IsDebian(enum LinuxDistro Distro) { |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 2102 | return Distro >= DebianLenny && Distro <= DebianJessie; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | static bool IsUbuntu(enum LinuxDistro Distro) { |
Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 2106 | return Distro >= UbuntuHardy && Distro <= UbuntuRaring; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2109 | static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) { |
Dylan Noblesmith | e277899 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 2110 | OwningPtr<llvm::MemoryBuffer> File; |
Michael J. Spencer | d9da7a1 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 2111 | if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2112 | StringRef Data = File.get()->getBuffer(); |
| 2113 | SmallVector<StringRef, 8> Lines; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2114 | Data.split(Lines, "\n"); |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 2115 | LinuxDistro Version = UnknownDistro; |
| 2116 | for (unsigned i = 0, s = Lines.size(); i != s; ++i) |
| 2117 | if (Version == UnknownDistro && Lines[i].startswith("DISTRIB_CODENAME=")) |
| 2118 | Version = llvm::StringSwitch<LinuxDistro>(Lines[i].substr(17)) |
| 2119 | .Case("hardy", UbuntuHardy) |
| 2120 | .Case("intrepid", UbuntuIntrepid) |
| 2121 | .Case("jaunty", UbuntuJaunty) |
| 2122 | .Case("karmic", UbuntuKarmic) |
| 2123 | .Case("lucid", UbuntuLucid) |
| 2124 | .Case("maverick", UbuntuMaverick) |
| 2125 | .Case("natty", UbuntuNatty) |
| 2126 | .Case("oneiric", UbuntuOneiric) |
| 2127 | .Case("precise", UbuntuPrecise) |
Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 2128 | .Case("quantal", UbuntuQuantal) |
| 2129 | .Case("raring", UbuntuRaring) |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 2130 | .Default(UnknownDistro); |
| 2131 | return Version; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
Michael J. Spencer | d9da7a1 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 2134 | if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2135 | StringRef Data = File.get()->getBuffer(); |
Benjamin Kramer | 3bb42f3 | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 2136 | if (Data.startswith("Fedora release 16")) |
| 2137 | return Fedora16; |
| 2138 | else if (Data.startswith("Fedora release 15")) |
Eric Christopher | 534b6a0 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 2139 | return Fedora15; |
| 2140 | else if (Data.startswith("Fedora release 14")) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2141 | return Fedora14; |
Eric Christopher | 534b6a0 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 2142 | else if (Data.startswith("Fedora release 13")) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2143 | return Fedora13; |
Eric Christopher | 534b6a0 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 2144 | else if (Data.startswith("Fedora release") && |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2145 | Data.find("Rawhide") != StringRef::npos) |
Eric Christopher | 534b6a0 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 2146 | return FedoraRawhide; |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 2147 | else if (Data.startswith("Red Hat Enterprise Linux") && |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2148 | Data.find("release 6") != StringRef::npos) |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 2149 | return RHEL6; |
Rafael Espindola | d8f92c8 | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 2150 | else if ((Data.startswith("Red Hat Enterprise Linux") || |
Eric Christopher | c4b0be9 | 2013-02-05 07:29:49 +0000 | [diff] [blame] | 2151 | Data.startswith("CentOS")) && |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2152 | Data.find("release 5") != StringRef::npos) |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 2153 | return RHEL5; |
Rafael Espindola | d8f92c8 | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 2154 | else if ((Data.startswith("Red Hat Enterprise Linux") || |
Eric Christopher | c4b0be9 | 2013-02-05 07:29:49 +0000 | [diff] [blame] | 2155 | Data.startswith("CentOS")) && |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2156 | Data.find("release 4") != StringRef::npos) |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 2157 | return RHEL4; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2158 | return UnknownDistro; |
| 2159 | } |
| 2160 | |
Michael J. Spencer | d9da7a1 | 2010-12-16 03:28:14 +0000 | [diff] [blame] | 2161 | if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2162 | StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2163 | if (Data[0] == '5') |
| 2164 | return DebianLenny; |
Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 2165 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2166 | return DebianSqueeze; |
Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 2167 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 2168 | return DebianWheezy; |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 2169 | else if (Data.startswith("jessie/sid") || Data[0] == '8') |
| 2170 | return DebianJessie; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2171 | return UnknownDistro; |
| 2172 | } |
| 2173 | |
Benjamin Kramer | 3bb42f3 | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 2174 | if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) |
| 2175 | return llvm::StringSwitch<LinuxDistro>(File.get()->getBuffer()) |
| 2176 | .StartsWith("openSUSE 11.3", OpenSuse11_3) |
| 2177 | .StartsWith("openSUSE 11.4", OpenSuse11_4) |
| 2178 | .StartsWith("openSUSE 12.1", OpenSuse12_1) |
Douglas Gregor | f7b8841 | 2012-04-30 23:42:57 +0000 | [diff] [blame] | 2179 | .StartsWith("openSUSE 12.2", OpenSuse12_2) |
Benjamin Kramer | 3bb42f3 | 2012-02-06 15:33:06 +0000 | [diff] [blame] | 2180 | .Default(UnknownDistro); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2181 | |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 2182 | bool Exists; |
| 2183 | if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists) |
Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 2184 | return Exherbo; |
| 2185 | |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 2186 | if (!llvm::sys::fs::exists("/etc/arch-release", Exists) && Exists) |
| 2187 | return ArchLinux; |
| 2188 | |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2189 | return UnknownDistro; |
| 2190 | } |
| 2191 | |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 2192 | /// \brief Get our best guess at the multiarch triple for a target. |
| 2193 | /// |
| 2194 | /// Debian-based systems are starting to use a multiarch setup where they use |
| 2195 | /// a target-triple directory in the library and header search paths. |
| 2196 | /// Unfortunately, this triple does not align with the vanilla target triple, |
| 2197 | /// so we provide a rough mapping here. |
| 2198 | static std::string getMultiarchTriple(const llvm::Triple TargetTriple, |
| 2199 | StringRef SysRoot) { |
| 2200 | // For most architectures, just use whatever we have rather than trying to be |
| 2201 | // clever. |
| 2202 | switch (TargetTriple.getArch()) { |
| 2203 | default: |
| 2204 | return TargetTriple.str(); |
| 2205 | |
| 2206 | // We use the existence of '/lib/<triple>' as a directory to detect some |
| 2207 | // common linux triples that don't quite match the Clang triple for both |
Chandler Carruth | 4c042fe | 2011-10-31 09:06:40 +0000 | [diff] [blame] | 2208 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
| 2209 | // regardless of what the actual target triple is. |
Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 2210 | case llvm::Triple::arm: |
| 2211 | case llvm::Triple::thumb: |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 2212 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
| 2213 | if (llvm::sys::fs::exists(SysRoot + "/lib/arm-linux-gnueabihf")) |
| 2214 | return "arm-linux-gnueabihf"; |
| 2215 | } else { |
| 2216 | if (llvm::sys::fs::exists(SysRoot + "/lib/arm-linux-gnueabi")) |
| 2217 | return "arm-linux-gnueabi"; |
| 2218 | } |
Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 2219 | return TargetTriple.str(); |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 2220 | case llvm::Triple::x86: |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 2221 | if (llvm::sys::fs::exists(SysRoot + "/lib/i386-linux-gnu")) |
| 2222 | return "i386-linux-gnu"; |
| 2223 | return TargetTriple.str(); |
| 2224 | case llvm::Triple::x86_64: |
| 2225 | if (llvm::sys::fs::exists(SysRoot + "/lib/x86_64-linux-gnu")) |
| 2226 | return "x86_64-linux-gnu"; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 2227 | return TargetTriple.str(); |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 2228 | case llvm::Triple::aarch64: |
| 2229 | if (llvm::sys::fs::exists(SysRoot + "/lib/aarch64-linux-gnu")) |
| 2230 | return "aarch64-linux-gnu"; |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 2231 | case llvm::Triple::mips: |
| 2232 | if (llvm::sys::fs::exists(SysRoot + "/lib/mips-linux-gnu")) |
| 2233 | return "mips-linux-gnu"; |
| 2234 | return TargetTriple.str(); |
| 2235 | case llvm::Triple::mipsel: |
| 2236 | if (llvm::sys::fs::exists(SysRoot + "/lib/mipsel-linux-gnu")) |
| 2237 | return "mipsel-linux-gnu"; |
| 2238 | return TargetTriple.str(); |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 2239 | case llvm::Triple::ppc: |
Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 2240 | if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc-linux-gnuspe")) |
| 2241 | return "powerpc-linux-gnuspe"; |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 2242 | if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc-linux-gnu")) |
| 2243 | return "powerpc-linux-gnu"; |
| 2244 | return TargetTriple.str(); |
| 2245 | case llvm::Triple::ppc64: |
| 2246 | if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc64-linux-gnu")) |
| 2247 | return "powerpc64-linux-gnu"; |
| 2248 | return TargetTriple.str(); |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 2252 | static void addPathIfExists(Twine Path, ToolChain::path_list &Paths) { |
| 2253 | if (llvm::sys::fs::exists(Path)) Paths.push_back(Path.str()); |
| 2254 | } |
| 2255 | |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 2256 | static bool isMipsArch(llvm::Triple::ArchType Arch) { |
| 2257 | return Arch == llvm::Triple::mips || |
| 2258 | Arch == llvm::Triple::mipsel || |
| 2259 | Arch == llvm::Triple::mips64 || |
| 2260 | Arch == llvm::Triple::mips64el; |
| 2261 | } |
| 2262 | |
Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 2263 | static bool isMipsR2Arch(llvm::Triple::ArchType Arch, |
| 2264 | const ArgList &Args) { |
| 2265 | if (Arch != llvm::Triple::mips && |
| 2266 | Arch != llvm::Triple::mipsel) |
| 2267 | return false; |
| 2268 | |
| 2269 | Arg *A = Args.getLastArg(options::OPT_march_EQ, |
| 2270 | options::OPT_mcpu_EQ, |
| 2271 | options::OPT_mips_CPUs_Group); |
| 2272 | |
| 2273 | if (!A) |
| 2274 | return false; |
| 2275 | |
| 2276 | if (A->getOption().matches(options::OPT_mips_CPUs_Group)) |
| 2277 | return A->getOption().matches(options::OPT_mips32r2); |
| 2278 | |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2279 | return A->getValue() == StringRef("mips32r2"); |
Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 2282 | static StringRef getMultilibDir(const llvm::Triple &Triple, |
| 2283 | const ArgList &Args) { |
| 2284 | if (!isMipsArch(Triple.getArch())) |
| 2285 | return Triple.isArch32Bit() ? "lib32" : "lib64"; |
| 2286 | |
| 2287 | // lib32 directory has a special meaning on MIPS targets. |
| 2288 | // It contains N32 ABI binaries. Use this folder if produce |
| 2289 | // code for N32 ABI only. |
Simon Atanasyan | 2d1b1ad | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 2290 | if (hasMipsN32ABIArg(Args)) |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 2291 | return "lib32"; |
| 2292 | |
| 2293 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 2294 | } |
| 2295 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2296 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 2297 | : Generic_ELF(D, Triple, Args) { |
Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 2298 | llvm::Triple::ArchType Arch = Triple.getArch(); |
Chandler Carruth | 2a649c7 | 2011-10-03 06:41:08 +0000 | [diff] [blame] | 2299 | const std::string &SysRoot = getDriver().SysRoot; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2300 | |
Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 2301 | // OpenSuse stores the linker with the compiler, add that to the search |
| 2302 | // path. |
| 2303 | ToolChain::path_list &PPaths = getProgramPaths(); |
Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 2304 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2305 | GCCInstallation.getTriple().str() + "/bin").str()); |
Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 2306 | |
| 2307 | Linker = GetProgramPath("ld"); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2308 | |
| 2309 | LinuxDistro Distro = DetectLinuxDistro(Arch); |
| 2310 | |
Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 2311 | if (IsOpenSuse(Distro) || IsUbuntu(Distro)) { |
Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 2312 | ExtraOpts.push_back("-z"); |
| 2313 | ExtraOpts.push_back("relro"); |
| 2314 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2315 | |
Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 2316 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2317 | ExtraOpts.push_back("-X"); |
| 2318 | |
Logan Chien | c6fd820 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 2319 | const bool IsAndroid = Triple.getEnvironment() == llvm::Triple::Android; |
Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 2320 | |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 2321 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
| 2322 | // and the MIPS ABI require .dynsym to be sorted in different ways. |
| 2323 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
| 2324 | // ABI requires a mapping between the GOT and the symbol table. |
Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 2325 | // Android loader does not support .gnu.hash. |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 2326 | if (!isMipsArch(Arch) && !IsAndroid) { |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 2327 | if (IsRedhat(Distro) || IsOpenSuse(Distro) || |
| 2328 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 2329 | ExtraOpts.push_back("--hash-style=gnu"); |
| 2330 | |
| 2331 | if (IsDebian(Distro) || IsOpenSuse(Distro) || Distro == UbuntuLucid || |
| 2332 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) |
| 2333 | ExtraOpts.push_back("--hash-style=both"); |
| 2334 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2335 | |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 2336 | if (IsRedhat(Distro)) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2337 | ExtraOpts.push_back("--no-add-needed"); |
| 2338 | |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 2339 | if (Distro == DebianSqueeze || Distro == DebianWheezy || |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 2340 | Distro == DebianJessie || IsOpenSuse(Distro) || |
Rafael Espindola | d8f92c8 | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 2341 | (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 2342 | (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2343 | ExtraOpts.push_back("--build-id"); |
| 2344 | |
Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 2345 | if (IsOpenSuse(Distro)) |
Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 2346 | ExtraOpts.push_back("--enable-new-dtags"); |
Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 2347 | |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 2348 | // The selection of paths to try here is designed to match the patterns which |
| 2349 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
| 2350 | // This was determined by running GCC in a fake filesystem, creating all |
| 2351 | // possible permutations of these directories, and seeing which ones it added |
| 2352 | // to the link paths. |
| 2353 | path_list &Paths = getFilePaths(); |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 2354 | |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 2355 | const std::string Multilib = getMultilibDir(Triple, Args); |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 2356 | const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot); |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 2357 | |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 2358 | // Add the multilib suffixed paths where they are available. |
| 2359 | if (GCCInstallation.isValid()) { |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2360 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 2361 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 2362 | |
| 2363 | if (IsAndroid && isMipsR2Arch(Triple.getArch(), Args)) |
| 2364 | addPathIfExists(GCCInstallation.getInstallPath() + |
| 2365 | GCCInstallation.getMultiarchSuffix() + |
| 2366 | "/mips-r2", |
| 2367 | Paths); |
| 2368 | else |
| 2369 | addPathIfExists((GCCInstallation.getInstallPath() + |
| 2370 | GCCInstallation.getMultiarchSuffix()), |
| 2371 | Paths); |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 2372 | |
| 2373 | // If the GCC installation we found is inside of the sysroot, we want to |
| 2374 | // prefer libraries installed in the parent prefix of the GCC installation. |
| 2375 | // It is important to *not* use these paths when the GCC installation is |
Gabor Greif | 5d3231c | 2012-04-18 10:59:08 +0000 | [diff] [blame] | 2376 | // outside of the system root as that can pick up unintended libraries. |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 2377 | // This usually happens when there is an external cross compiler on the |
| 2378 | // host system, and a more minimal sysroot available that is the target of |
| 2379 | // the cross. |
| 2380 | if (StringRef(LibPath).startswith(SysRoot)) { |
| 2381 | addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib/../" + Multilib, |
| 2382 | Paths); |
| 2383 | addPathIfExists(LibPath + "/" + MultiarchTriple, Paths); |
| 2384 | addPathIfExists(LibPath + "/../" + Multilib, Paths); |
| 2385 | } |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 2386 | // On Android, libraries in the parent prefix of the GCC installation are |
| 2387 | // preferred to the ones under sysroot. |
| 2388 | if (IsAndroid) { |
| 2389 | addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib", Paths); |
| 2390 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2391 | } |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 2392 | addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths); |
| 2393 | addPathIfExists(SysRoot + "/lib/../" + Multilib, Paths); |
| 2394 | addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths); |
| 2395 | addPathIfExists(SysRoot + "/usr/lib/../" + Multilib, Paths); |
| 2396 | |
| 2397 | // Try walking via the GCC triple path in case of multiarch GCC |
| 2398 | // installations with strange symlinks. |
| 2399 | if (GCCInstallation.isValid()) |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2400 | addPathIfExists(SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 2401 | "/../../" + Multilib, Paths); |
Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 2402 | |
Chandler Carruth | a7b4414 | 2011-10-16 10:54:30 +0000 | [diff] [blame] | 2403 | // Add the non-multilib suffixed paths (if potentially different). |
Chandler Carruth | 3f0c8f7 | 2011-10-03 18:16:54 +0000 | [diff] [blame] | 2404 | if (GCCInstallation.isValid()) { |
| 2405 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2406 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2407 | if (!GCCInstallation.getMultiarchSuffix().empty()) |
Chandler Carruth | 3f0c8f7 | 2011-10-03 18:16:54 +0000 | [diff] [blame] | 2408 | addPathIfExists(GCCInstallation.getInstallPath(), Paths); |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 2409 | |
| 2410 | if (StringRef(LibPath).startswith(SysRoot)) { |
| 2411 | addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib", Paths); |
| 2412 | addPathIfExists(LibPath, Paths); |
| 2413 | } |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 2414 | } |
Chandler Carruth | 2a649c7 | 2011-10-03 06:41:08 +0000 | [diff] [blame] | 2415 | addPathIfExists(SysRoot + "/lib", Paths); |
| 2416 | addPathIfExists(SysRoot + "/usr/lib", Paths); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | bool Linux::HasNativeLLVMSupport() const { |
| 2420 | return true; |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 2423 | Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 2424 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 2425 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 2426 | Key = Action::AnalyzeJobClass; |
| 2427 | else |
| 2428 | Key = JA.getKind(); |
| 2429 | |
Rafael Espindola | 96aef79 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 2430 | bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, |
| 2431 | options::OPT_no_integrated_as, |
| 2432 | IsIntegratedAssemblerDefault()); |
| 2433 | |
Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 2434 | Tool *&T = Tools[Key]; |
| 2435 | if (!T) { |
| 2436 | switch (Key) { |
| 2437 | case Action::AssembleJobClass: |
Rafael Espindola | 96aef79 | 2010-11-07 23:13:01 +0000 | [diff] [blame] | 2438 | if (UseIntegratedAs) |
| 2439 | T = new tools::ClangAs(*this); |
| 2440 | else |
| 2441 | T = new tools::linuxtools::Assemble(*this); |
| 2442 | break; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 2443 | case Action::LinkJobClass: |
| 2444 | T = new tools::linuxtools::Link(*this); break; |
Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 2445 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 2446 | T = &Generic_GCC::SelectTool(C, JA); |
Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | return *T; |
| 2451 | } |
| 2452 | |
Chandler Carruth | 05fb585 | 2012-11-21 23:40:23 +0000 | [diff] [blame] | 2453 | void Linux::addClangTargetOptions(const ArgList &DriverArgs, |
| 2454 | ArgStringList &CC1Args) const { |
Rafael Espindola | 66aa045 | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 2455 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); |
Chandler Carruth | 05fb585 | 2012-11-21 23:40:23 +0000 | [diff] [blame] | 2456 | bool UseInitArrayDefault |
| 2457 | = V >= Generic_GCC::GCCVersion::Parse("4.7.0") || |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 2458 | getTriple().getArch() == llvm::Triple::aarch64 || |
Chandler Carruth | 05fb585 | 2012-11-21 23:40:23 +0000 | [diff] [blame] | 2459 | getTriple().getEnvironment() == llvm::Triple::Android; |
| 2460 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 2461 | options::OPT_fno_use_init_array, |
| 2462 | UseInitArrayDefault)) |
Rafael Espindola | 66aa045 | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 2463 | CC1Args.push_back("-fuse-init-array"); |
| 2464 | } |
| 2465 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2466 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2467 | ArgStringList &CC1Args) const { |
| 2468 | const Driver &D = getDriver(); |
| 2469 | |
| 2470 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2471 | return; |
| 2472 | |
| 2473 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2474 | addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/local/include"); |
| 2475 | |
| 2476 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2477 | llvm::sys::Path P(D.ResourceDir); |
| 2478 | P.appendComponent("include"); |
Chandler Carruth | a62ba81 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 2479 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2483 | return; |
| 2484 | |
| 2485 | // Check for configure-time C include directories. |
| 2486 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 2487 | if (CIncludeDirs != "") { |
| 2488 | SmallVector<StringRef, 5> dirs; |
| 2489 | CIncludeDirs.split(dirs, ":"); |
| 2490 | for (SmallVectorImpl<StringRef>::iterator I = dirs.begin(), E = dirs.end(); |
| 2491 | I != E; ++I) { |
| 2492 | StringRef Prefix = llvm::sys::path::is_absolute(*I) ? D.SysRoot : ""; |
| 2493 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + *I); |
| 2494 | } |
| 2495 | return; |
| 2496 | } |
| 2497 | |
| 2498 | // Lacking those, try to detect the correct set of system includes for the |
| 2499 | // target triple. |
| 2500 | |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2501 | // Implement generic Debian multiarch support. |
| 2502 | const StringRef X86_64MultiarchIncludeDirs[] = { |
| 2503 | "/usr/include/x86_64-linux-gnu", |
| 2504 | |
| 2505 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 2506 | // in use in any released version of Debian, so we should consider |
| 2507 | // removing them. |
| 2508 | "/usr/include/i686-linux-gnu/64", |
| 2509 | "/usr/include/i486-linux-gnu/64" |
| 2510 | }; |
| 2511 | const StringRef X86MultiarchIncludeDirs[] = { |
| 2512 | "/usr/include/i386-linux-gnu", |
| 2513 | |
| 2514 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 2515 | // in use in any released version of Debian, so we should consider |
| 2516 | // removing them. |
| 2517 | "/usr/include/x86_64-linux-gnu/32", |
| 2518 | "/usr/include/i686-linux-gnu", |
| 2519 | "/usr/include/i486-linux-gnu" |
| 2520 | }; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 2521 | const StringRef AArch64MultiarchIncludeDirs[] = { |
| 2522 | "/usr/include/aarch64-linux-gnu" |
| 2523 | }; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2524 | const StringRef ARMMultiarchIncludeDirs[] = { |
| 2525 | "/usr/include/arm-linux-gnueabi" |
| 2526 | }; |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 2527 | const StringRef ARMHFMultiarchIncludeDirs[] = { |
| 2528 | "/usr/include/arm-linux-gnueabihf" |
| 2529 | }; |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 2530 | const StringRef MIPSMultiarchIncludeDirs[] = { |
| 2531 | "/usr/include/mips-linux-gnu" |
| 2532 | }; |
| 2533 | const StringRef MIPSELMultiarchIncludeDirs[] = { |
| 2534 | "/usr/include/mipsel-linux-gnu" |
| 2535 | }; |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 2536 | const StringRef PPCMultiarchIncludeDirs[] = { |
| 2537 | "/usr/include/powerpc-linux-gnu" |
| 2538 | }; |
| 2539 | const StringRef PPC64MultiarchIncludeDirs[] = { |
| 2540 | "/usr/include/powerpc64-linux-gnu" |
| 2541 | }; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2542 | ArrayRef<StringRef> MultiarchIncludeDirs; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2543 | if (getTriple().getArch() == llvm::Triple::x86_64) { |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2544 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2545 | } else if (getTriple().getArch() == llvm::Triple::x86) { |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2546 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 2547 | } else if (getTriple().getArch() == llvm::Triple::aarch64) { |
| 2548 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2549 | } else if (getTriple().getArch() == llvm::Triple::arm) { |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 2550 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 2551 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; |
| 2552 | else |
| 2553 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 2554 | } else if (getTriple().getArch() == llvm::Triple::mips) { |
| 2555 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; |
| 2556 | } else if (getTriple().getArch() == llvm::Triple::mipsel) { |
| 2557 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 2558 | } else if (getTriple().getArch() == llvm::Triple::ppc) { |
| 2559 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; |
| 2560 | } else if (getTriple().getArch() == llvm::Triple::ppc64) { |
| 2561 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2562 | } |
| 2563 | for (ArrayRef<StringRef>::iterator I = MultiarchIncludeDirs.begin(), |
| 2564 | E = MultiarchIncludeDirs.end(); |
| 2565 | I != E; ++I) { |
Chandler Carruth | 6e46ca2 | 2011-11-09 03:46:20 +0000 | [diff] [blame] | 2566 | if (llvm::sys::fs::exists(D.SysRoot + *I)) { |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 2567 | addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + *I); |
| 2568 | break; |
| 2569 | } |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | if (getTriple().getOS() == llvm::Triple::RTEMS) |
| 2573 | return; |
| 2574 | |
Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 2575 | // Add an include of '/include' directly. This isn't provided by default by |
| 2576 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 2577 | // add even when Clang is acting as-if it were a system compiler. |
| 2578 | addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include"); |
| 2579 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2580 | addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include"); |
| 2581 | } |
| 2582 | |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 2583 | /// \brief Helper to add the three variant paths for a libstdc++ installation. |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 2584 | /*static*/ bool Linux::addLibStdCXXIncludePaths(Twine Base, Twine TargetArchDir, |
| 2585 | const ArgList &DriverArgs, |
| 2586 | ArgStringList &CC1Args) { |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2587 | if (!llvm::sys::fs::exists(Base)) |
| 2588 | return false; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2589 | addSystemInclude(DriverArgs, CC1Args, Base); |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2590 | addSystemInclude(DriverArgs, CC1Args, Base + "/" + TargetArchDir); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2591 | addSystemInclude(DriverArgs, CC1Args, Base + "/backward"); |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2592 | return true; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 2595 | /// \brief Helper to add an extra variant path for an (Ubuntu) multilib |
| 2596 | /// libstdc++ installation. |
| 2597 | /*static*/ bool Linux::addLibStdCXXIncludePaths(Twine Base, Twine Suffix, |
| 2598 | Twine TargetArchDir, |
| 2599 | Twine MultiLibSuffix, |
| 2600 | const ArgList &DriverArgs, |
| 2601 | ArgStringList &CC1Args) { |
| 2602 | if (!addLibStdCXXIncludePaths(Base+Suffix, TargetArchDir + MultiLibSuffix, |
| 2603 | DriverArgs, CC1Args)) |
| 2604 | return false; |
| 2605 | |
| 2606 | addSystemInclude(DriverArgs, CC1Args, Base + "/" + TargetArchDir + Suffix |
| 2607 | + MultiLibSuffix); |
| 2608 | return true; |
| 2609 | } |
| 2610 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2611 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2612 | ArgStringList &CC1Args) const { |
| 2613 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2614 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2615 | return; |
| 2616 | |
Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 2617 | // Check if libc++ has been enabled and provide its include paths if so. |
| 2618 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { |
| 2619 | // libc++ is always installed at a fixed path on Linux currently. |
| 2620 | addSystemInclude(DriverArgs, CC1Args, |
| 2621 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| 2622 | return; |
| 2623 | } |
| 2624 | |
Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 2625 | // We need a detected GCC installation on Linux to provide libstdc++'s |
| 2626 | // headers. We handled the libc++ case above. |
| 2627 | if (!GCCInstallation.isValid()) |
| 2628 | return; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2629 | |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2630 | // By default, look for the C++ headers in an include directory adjacent to |
| 2631 | // the lib directory of the GCC installation. Note that this is expect to be |
| 2632 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. |
| 2633 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 2634 | StringRef InstallDir = GCCInstallation.getInstallPath(); |
Rafael Espindola | 66aa045 | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 2635 | StringRef Version = GCCInstallation.getVersion().Text; |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 2636 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| 2637 | |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 2638 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", |
| 2639 | "/c++/" + Version.str(), |
| 2640 | TripleStr, |
| 2641 | GCCInstallation.getMultiarchSuffix(), |
| 2642 | DriverArgs, CC1Args)) |
| 2643 | return; |
| 2644 | |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 2645 | const std::string IncludePathCandidates[] = { |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2646 | // Gentoo is weird and places its headers inside the GCC install, so if the |
| 2647 | // first attempt to find the headers fails, try this pattern. |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 2648 | InstallDir.str() + "/include/g++-v4", |
| 2649 | // Android standalone toolchain has C++ headers in yet another place. |
| 2650 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.str(), |
Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2651 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, |
| 2652 | // without a subdirectory corresponding to the gcc version. |
| 2653 | LibDir.str() + "/../include/c++", |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 2654 | }; |
| 2655 | |
| 2656 | for (unsigned i = 0; i < llvm::array_lengthof(IncludePathCandidates); ++i) { |
| 2657 | if (addLibStdCXXIncludePaths(IncludePathCandidates[i], (TripleStr + |
| 2658 | GCCInstallation.getMultiarchSuffix()), |
| 2659 | DriverArgs, CC1Args)) |
| 2660 | break; |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 2661 | } |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2664 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 2665 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2666 | DragonFly::DragonFly(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 2667 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2668 | |
| 2669 | // Path mangling to find libexec |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2670 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2671 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2672 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2673 | |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2674 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2675 | getFilePaths().push_back("/usr/lib"); |
| 2676 | getFilePaths().push_back("/usr/lib/gcc41"); |
| 2677 | } |
| 2678 | |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 2679 | Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 2680 | Action::ActionClass Key; |
Rafael Espindola | 2f69d40 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 2681 | if (getDriver().ShouldUseClangCompiler(JA)) |
Nick Lewycky | 5cc9ebb | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 2682 | Key = Action::AnalyzeJobClass; |
| 2683 | else |
| 2684 | Key = JA.getKind(); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2685 | |
| 2686 | Tool *&T = Tools[Key]; |
| 2687 | if (!T) { |
| 2688 | switch (Key) { |
| 2689 | case Action::AssembleJobClass: |
| 2690 | T = new tools::dragonfly::Assemble(*this); break; |
| 2691 | case Action::LinkJobClass: |
| 2692 | T = new tools::dragonfly::Link(*this); break; |
| 2693 | default: |
Rafael Espindola | 88b55ea | 2013-03-18 17:25:58 +0000 | [diff] [blame^] | 2694 | T = &Generic_GCC::SelectTool(C, JA); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2695 | } |
| 2696 | } |
| 2697 | |
| 2698 | return *T; |
| 2699 | } |