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