| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 1 | //===--- ToolChains.cpp - ToolChain Implementations -------------*- C++ -*-===// |
| 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" |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 11 | #include "clang/Basic/Cuda.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 12 | #include "clang/Basic/ObjCRuntime.h" |
| 13 | #include "clang/Basic/Version.h" |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 14 | #include "clang/Basic/VirtualFileSystem.h" |
| Alp Toker | 1d257e1 | 2014-06-04 03:28:55 +0000 | [diff] [blame] | 15 | #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX |
| Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Compilation.h" |
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Driver.h" |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 18 | #include "clang/Driver/DriverDiagnostic.h" |
| Daniel Dunbar | da13faf | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Options.h" |
| Alexey Samsonov | 609213f9 | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 20 | #include "clang/Driver/SanitizerArgs.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/STLExtras.h" |
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallString.h" |
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringExtras.h" |
| Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringSwitch.h" |
| Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 25 | #include "llvm/Option/Arg.h" |
| 26 | #include "llvm/Option/ArgList.h" |
| 27 | #include "llvm/Option/OptTable.h" |
| 28 | #include "llvm/Option/Option.h" |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 29 | #include "llvm/ProfileData/InstrProf.h" |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
| Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 31 | #include "llvm/Support/FileSystem.h" |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 32 | #include "llvm/Support/MemoryBuffer.h" |
| Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Path.h" |
| Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Program.h" |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 35 | #include "llvm/Support/TargetParser.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 36 | #include "llvm/Support/raw_ostream.h" |
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 37 | #include <cstdlib> // ::getenv |
| Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 38 | #include <system_error> |
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 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 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 45 | MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 46 | : ToolChain(D, Triple, Args) { |
| Tim Northover | 15ff71d | 2014-05-22 13:12:14 +0000 | [diff] [blame] | 47 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
| 48 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 49 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 50 | getProgramPaths().push_back(getDriver().Dir); |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 51 | } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 52 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 53 | /// Darwin - Darwin tool chain for i386 and x86_64. |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 54 | Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 55 | : MachO(D, Triple, Args), TargetInitialized(false) {} |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 56 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 57 | types::ID MachO::LookupTypeForExtension(const char *Ext) const { |
| Daniel Dunbar | cc7df6c | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 58 | types::ID Ty = types::lookupTypeForExtension(Ext); |
| 59 | |
| 60 | // Darwin always preprocesses assembly files (unless -x is used explicitly). |
| 61 | if (Ty == types::TY_PP_Asm) |
| 62 | return types::TY_Asm; |
| 63 | |
| 64 | return Ty; |
| 65 | } |
| 66 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 67 | bool MachO::HasNativeLLVMSupport() const { return true; } |
| Daniel Dunbar | 62123a1 | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 68 | |
| Jonas Hahnfeld | aae8374 | 2016-02-12 07:48:37 +0000 | [diff] [blame] | 69 | ToolChain::CXXStdlibType Darwin::GetDefaultCXXStdlibType() const { |
| 70 | // Default to use libc++ on OS X 10.9+ and iOS 7+. |
| 71 | if ((isTargetMacOS() && !isMacosxVersionLT(10, 9)) || |
| 72 | (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) || |
| 73 | isTargetWatchOSBased()) |
| 74 | return ToolChain::CST_Libcxx; |
| 75 | |
| 76 | return ToolChain::CST_Libstdcxx; |
| 77 | } |
| 78 | |
| John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 79 | /// 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] | 80 | ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 81 | if (isTargetWatchOSBased()) |
| Tim Northover | 756447a | 2015-10-30 16:30:36 +0000 | [diff] [blame] | 82 | return ObjCRuntime(ObjCRuntime::WatchOS, TargetVersion); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 83 | if (isTargetIOSBased()) |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 84 | return ObjCRuntime(ObjCRuntime::iOS, TargetVersion); |
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 85 | if (isNonFragile) |
| 86 | return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion); |
| 87 | return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion); |
| John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 90 | /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. |
| 91 | bool Darwin::hasBlocksRuntime() const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 92 | if (isTargetWatchOSBased()) |
| 93 | return true; |
| 94 | else if (isTargetIOSBased()) |
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 95 | return !isIPhoneOSVersionLT(3, 2); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 96 | else { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 97 | assert(isTargetMacOS() && "unexpected darwin target"); |
| 98 | return !isMacosxVersionLT(10, 6); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 99 | } |
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 102 | // This is just a MachO name translation routine and there's no |
| 103 | // way to join this into ARMTargetParser without breaking all |
| 104 | // other assumptions. Maybe MachO should consider standardising |
| 105 | // their nomenclature. |
| 106 | static const char *ArmMachOArchName(StringRef Arch) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 107 | return llvm::StringSwitch<const char *>(Arch) |
| 108 | .Case("armv6k", "armv6") |
| 109 | .Case("armv6m", "armv6m") |
| 110 | .Case("armv5tej", "armv5") |
| 111 | .Case("xscale", "xscale") |
| 112 | .Case("armv4t", "armv4t") |
| 113 | .Case("armv7", "armv7") |
| 114 | .Cases("armv7a", "armv7-a", "armv7") |
| 115 | .Cases("armv7r", "armv7-r", "armv7") |
| 116 | .Cases("armv7em", "armv7e-m", "armv7em") |
| 117 | .Cases("armv7k", "armv7-k", "armv7k") |
| 118 | .Cases("armv7m", "armv7-m", "armv7m") |
| 119 | .Cases("armv7s", "armv7-s", "armv7s") |
| 120 | .Default(nullptr); |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 123 | static const char *ArmMachOArchNameCPU(StringRef CPU) { |
| Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 124 | unsigned ArchKind = llvm::ARM::parseCPUArch(CPU); |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 125 | if (ArchKind == llvm::ARM::AK_INVALID) |
| 126 | return nullptr; |
| Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 127 | StringRef Arch = llvm::ARM::getArchName(ArchKind); |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 128 | |
| 129 | // FIXME: Make sure this MachO triple mangling is really necessary. |
| 130 | // ARMv5* normalises to ARMv5. |
| 131 | if (Arch.startswith("armv5")) |
| 132 | Arch = Arch.substr(0, 5); |
| 133 | // ARMv6*, except ARMv6M, normalises to ARMv6. |
| 134 | else if (Arch.startswith("armv6") && !Arch.endswith("6m")) |
| 135 | Arch = Arch.substr(0, 5); |
| 136 | // ARMv7A normalises to ARMv7. |
| 137 | else if (Arch.endswith("v7a")) |
| 138 | Arch = Arch.substr(0, 5); |
| 139 | return Arch.data(); |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 142 | static bool isSoftFloatABI(const ArgList &Args) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 143 | Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 144 | options::OPT_mfloat_abi_EQ); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 145 | if (!A) |
| 146 | return false; |
| Rafael Auler | 3f7abf7 | 2014-09-29 21:50:34 +0000 | [diff] [blame] | 147 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 148 | return A->getOption().matches(options::OPT_msoft_float) || |
| 149 | (A->getOption().matches(options::OPT_mfloat_abi_EQ) && |
| 150 | A->getValue() == StringRef("soft")); |
| 151 | } |
| 152 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 153 | StringRef MachO::getMachOArchName(const ArgList &Args) const { |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 154 | switch (getTriple().getArch()) { |
| 155 | default: |
| Rafael Espindola | ed1233e | 2014-08-28 21:23:05 +0000 | [diff] [blame] | 156 | return getDefaultUniversalArchName(); |
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 157 | |
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 158 | case llvm::Triple::aarch64: |
| 159 | return "arm64"; |
| 160 | |
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 161 | case llvm::Triple::thumb: |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 162 | case llvm::Triple::arm: |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 163 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 164 | if (const char *Arch = ArmMachOArchName(A->getValue())) |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 165 | return Arch; |
| 166 | |
| 167 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 168 | if (const char *Arch = ArmMachOArchNameCPU(A->getValue())) |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 169 | return Arch; |
| 170 | |
| 171 | return "arm"; |
| 172 | } |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 175 | Darwin::~Darwin() {} |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 176 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 177 | MachO::~MachO() {} |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 178 | |
| Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 179 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, |
| 180 | types::ID InputType) const { |
| 181 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 182 | |
| 183 | // If the target isn't initialized (e.g., an unknown Darwin platform, return |
| 184 | // the default triple). |
| 185 | if (!isTargetInitialized()) |
| 186 | return Triple.getTriple(); |
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 187 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 188 | SmallString<16> Str; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 189 | if (isTargetWatchOSBased()) |
| 190 | Str += "watchos"; |
| 191 | else if (isTargetTvOSBased()) |
| 192 | Str += "tvos"; |
| 193 | else if (isTargetIOSBased()) |
| 194 | Str += "ios"; |
| 195 | else |
| 196 | Str += "macosx"; |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 197 | Str += getTargetVersion().getAsString(); |
| 198 | Triple.setOSName(Str); |
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 199 | |
| 200 | return Triple.getTriple(); |
| 201 | } |
| 202 | |
| David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 203 | void Generic_ELF::anchor() {} |
| 204 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 205 | Tool *MachO::getTool(Action::ActionClass AC) const { |
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 206 | switch (AC) { |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 207 | case Action::LipoJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 208 | if (!Lipo) |
| 209 | Lipo.reset(new tools::darwin::Lipo(*this)); |
| 210 | return Lipo.get(); |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 211 | case Action::DsymutilJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 212 | if (!Dsymutil) |
| 213 | Dsymutil.reset(new tools::darwin::Dsymutil(*this)); |
| 214 | return Dsymutil.get(); |
| Ben Langmuir | 9b9a8d3 | 2014-02-06 18:53:25 +0000 | [diff] [blame] | 215 | case Action::VerifyDebugInfoJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 216 | if (!VerifyDebug) |
| 217 | VerifyDebug.reset(new tools::darwin::VerifyDebug(*this)); |
| 218 | return VerifyDebug.get(); |
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 219 | default: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 220 | return ToolChain::getTool(AC); |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 221 | } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 224 | Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); } |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 225 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 226 | Tool *MachO::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 227 | return new tools::darwin::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 228 | } |
| Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 229 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 230 | DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 231 | const ArgList &Args) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 232 | : Darwin(D, Triple, Args) {} |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 233 | |
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 234 | void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 235 | // For modern targets, promote certain warnings to errors. |
| 236 | if (isTargetWatchOSBased() || getTriple().isArch64Bit()) { |
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 237 | // Always enable -Wdeprecated-objc-isa-usage and promote it |
| 238 | // to an error. |
| 239 | CC1Args.push_back("-Wdeprecated-objc-isa-usage"); |
| 240 | CC1Args.push_back("-Werror=deprecated-objc-isa-usage"); |
| 241 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 242 | // For iOS and watchOS, also error about implicit function declarations, |
| 243 | // as that can impact calling conventions. |
| 244 | if (!isTargetMacOS()) |
| 245 | CC1Args.push_back("-Werror=implicit-function-declaration"); |
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 249 | /// \brief Determine whether Objective-C automated reference counting is |
| 250 | /// enabled. |
| 251 | static bool isObjCAutoRefCount(const ArgList &Args) { |
| 252 | return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); |
| 253 | } |
| 254 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 255 | void DarwinClang::AddLinkARCArgs(const ArgList &Args, |
| 256 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 257 | // Avoid linking compatibility stubs on i386 mac. |
| 258 | if (isTargetMacOS() && getArch() == llvm::Triple::x86) |
| 259 | return; |
| 260 | |
| 261 | ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true); |
| 262 | |
| 263 | if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) && |
| 264 | runtime.hasSubscripting()) |
| 265 | return; |
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 266 | |
| 267 | CmdArgs.push_back("-force_load"); |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 268 | SmallString<128> P(getDriver().ClangExecutable); |
| 269 | llvm::sys::path::remove_filename(P); // 'clang' |
| 270 | llvm::sys::path::remove_filename(P); // 'bin' |
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 271 | llvm::sys::path::append(P, "lib", "arc", "libarclite_"); |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 272 | // Mash in the platform. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 273 | if (isTargetWatchOSSimulator()) |
| 274 | P += "watchsimulator"; |
| 275 | else if (isTargetWatchOS()) |
| 276 | P += "watchos"; |
| 277 | else if (isTargetTvOSSimulator()) |
| 278 | P += "appletvsimulator"; |
| 279 | else if (isTargetTvOS()) |
| 280 | P += "appletvos"; |
| 281 | else if (isTargetIOSSimulator()) |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 282 | P += "iphonesimulator"; |
| Argyrios Kyrtzidis | 058b451 | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 283 | else if (isTargetIPhoneOS()) |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 284 | P += "iphoneos"; |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 285 | else |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 286 | P += "macosx"; |
| 287 | P += ".a"; |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 288 | |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 289 | CmdArgs.push_back(Args.MakeArgString(P)); |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 292 | void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, |
| Kuba Brecka | 2735a025 | 2014-10-31 00:08:57 +0000 | [diff] [blame] | 293 | StringRef DarwinLibName, bool AlwaysLink, |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 294 | bool IsEmbedded, bool AddRPath) const { |
| 295 | SmallString<128> Dir(getDriver().ResourceDir); |
| 296 | llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin"); |
| 297 | |
| 298 | SmallString<128> P(Dir); |
| 299 | llvm::sys::path::append(P, DarwinLibName); |
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 300 | |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 301 | // For now, allow missing resource libraries to support developers who may |
| Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 302 | // not have compiler-rt checked out or integrated into their build (unless |
| 303 | // we explicitly force linking with this library). |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 304 | if (AlwaysLink || getVFS().exists(P)) |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 305 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 306 | |
| 307 | // Adding the rpaths might negatively interact when other rpaths are involved, |
| 308 | // so we should make sure we add the rpaths last, after all user-specified |
| 309 | // rpaths. This is currently true from this place, but we need to be |
| 310 | // careful if this function is ever called before user's rpaths are emitted. |
| 311 | if (AddRPath) { |
| 312 | assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library"); |
| 313 | |
| 314 | // Add @executable_path to rpath to support having the dylib copied with |
| 315 | // the executable. |
| 316 | CmdArgs.push_back("-rpath"); |
| 317 | CmdArgs.push_back("@executable_path"); |
| 318 | |
| 319 | // Add the path to the resource dir to rpath to support using the dylib |
| 320 | // from the default location without copying. |
| 321 | CmdArgs.push_back("-rpath"); |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 322 | CmdArgs.push_back(Args.MakeArgString(Dir)); |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 323 | } |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 326 | StringRef Darwin::getPlatformFamily() const { |
| 327 | switch (TargetPlatform) { |
| 328 | case DarwinPlatformKind::MacOS: |
| 329 | return "MacOSX"; |
| 330 | case DarwinPlatformKind::IPhoneOS: |
| 331 | case DarwinPlatformKind::IPhoneOSSimulator: |
| 332 | return "iPhone"; |
| 333 | case DarwinPlatformKind::TvOS: |
| 334 | case DarwinPlatformKind::TvOSSimulator: |
| 335 | return "AppleTV"; |
| 336 | case DarwinPlatformKind::WatchOS: |
| 337 | case DarwinPlatformKind::WatchOSSimulator: |
| 338 | return "Watch"; |
| 339 | } |
| 340 | llvm_unreachable("Unsupported platform"); |
| 341 | } |
| 342 | |
| 343 | StringRef Darwin::getSDKName(StringRef isysroot) { |
| 344 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk |
| 345 | llvm::sys::path::const_iterator SDKDir; |
| 346 | auto BeginSDK = llvm::sys::path::begin(isysroot); |
| 347 | auto EndSDK = llvm::sys::path::end(isysroot); |
| 348 | for (auto IT = BeginSDK; IT != EndSDK; ++IT) { |
| 349 | StringRef SDK = *IT; |
| 350 | if (SDK.endswith(".sdk")) |
| 351 | return SDK.slice(0, SDK.size() - 4); |
| 352 | } |
| 353 | return ""; |
| 354 | } |
| 355 | |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 356 | StringRef Darwin::getOSLibraryNameSuffix() const { |
| 357 | switch(TargetPlatform) { |
| 358 | case DarwinPlatformKind::MacOS: |
| 359 | return "osx"; |
| 360 | case DarwinPlatformKind::IPhoneOS: |
| 361 | return "ios"; |
| 362 | case DarwinPlatformKind::IPhoneOSSimulator: |
| 363 | return "iossim"; |
| 364 | case DarwinPlatformKind::TvOS: |
| 365 | return "tvos"; |
| 366 | case DarwinPlatformKind::TvOSSimulator: |
| 367 | return "tvossim"; |
| 368 | case DarwinPlatformKind::WatchOS: |
| 369 | return "watchos"; |
| 370 | case DarwinPlatformKind::WatchOSSimulator: |
| 371 | return "watchossim"; |
| 372 | } |
| 373 | llvm_unreachable("Unsupported platform"); |
| 374 | } |
| 375 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 376 | void Darwin::addProfileRTLibs(const ArgList &Args, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 377 | ArgStringList &CmdArgs) const { |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 378 | if (!needsProfileRT(Args)) return; |
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 379 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 380 | AddLinkRuntimeLib(Args, CmdArgs, (Twine("libclang_rt.profile_") + |
| 381 | getOSLibraryNameSuffix() + ".a").str(), |
| 382 | /*AlwaysLink*/ true); |
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 385 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, |
| 386 | ArgStringList &CmdArgs, |
| 387 | StringRef Sanitizer) const { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 388 | AddLinkRuntimeLib( |
| 389 | Args, CmdArgs, |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 390 | (Twine("libclang_rt.") + Sanitizer + "_" + |
| 391 | getOSLibraryNameSuffix() + "_dynamic.dylib").str(), |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 392 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, |
| 393 | /*AddRPath*/ true); |
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| Jonas Hahnfeld | d196fa5 | 2016-07-27 08:15:54 +0000 | [diff] [blame] | 396 | ToolChain::RuntimeLibType DarwinClang::GetRuntimeLibType( |
| 397 | const ArgList &Args) const { |
| 398 | if (Arg* A = Args.getLastArg(options::OPT_rtlib_EQ)) { |
| 399 | StringRef Value = A->getValue(); |
| 400 | if (Value != "compiler-rt") |
| 401 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) |
| 402 | << Value << "darwin"; |
| 403 | } |
| 404 | |
| 405 | return ToolChain::RLT_CompilerRT; |
| 406 | } |
| 407 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 408 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 409 | ArgStringList &CmdArgs) const { |
| Jonas Hahnfeld | d196fa5 | 2016-07-27 08:15:54 +0000 | [diff] [blame] | 410 | // Call once to ensure diagnostic is printed if wrong value was specified |
| 411 | GetRuntimeLibType(Args); |
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 412 | |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 413 | // Darwin doesn't support real static executables, don't link any runtime |
| 414 | // libraries with -static. |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 415 | if (Args.hasArg(options::OPT_static) || |
| 416 | Args.hasArg(options::OPT_fapple_kext) || |
| 417 | Args.hasArg(options::OPT_mkernel)) |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 418 | return; |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 419 | |
| 420 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 421 | // cares. This is useful in situations where someone wants to statically link |
| 422 | // something like libstdc++, and needs its runtime support routines. |
| 423 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 424 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 425 | return; |
| 426 | } |
| 427 | |
| Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 428 | const SanitizerArgs &Sanitize = getSanitizerArgs(); |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 429 | if (Sanitize.needsAsanRt()) |
| 430 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); |
| 431 | if (Sanitize.needsUbsanRt()) |
| 432 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); |
| Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 433 | if (Sanitize.needsTsanRt()) |
| 434 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); |
| Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 435 | if (Sanitize.needsStatsRt()) { |
| 436 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; |
| 437 | AddLinkRuntimeLib(Args, CmdArgs, |
| 438 | (Twine("libclang_rt.stats_client_") + OS + ".a").str(), |
| 439 | /*AlwaysLink=*/true); |
| 440 | AddLinkSanitizerLibArgs(Args, CmdArgs, "stats"); |
| 441 | } |
| Derek Bruening | 256c2e1 | 2016-04-21 21:32:04 +0000 | [diff] [blame] | 442 | if (Sanitize.needsEsanRt()) |
| 443 | AddLinkSanitizerLibArgs(Args, CmdArgs, "esan"); |
| Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 444 | |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 445 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 446 | // target specific static runtime library. |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 447 | CmdArgs.push_back("-lSystem"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 448 | |
| 449 | // Select the dynamic runtime library and the target specific static library. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 450 | if (isTargetWatchOSBased()) { |
| 451 | // We currently always need a static runtime library for watchOS. |
| 452 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); |
| 453 | } else if (isTargetTvOSBased()) { |
| 454 | // We currently always need a static runtime library for tvOS. |
| 455 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); |
| 456 | } else if (isTargetIOSBased()) { |
| Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 457 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, |
| 458 | // it never went into the SDK. |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 459 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 460 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && |
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 461 | getTriple().getArch() != llvm::Triple::aarch64) |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 462 | CmdArgs.push_back("-lgcc_s.1"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 463 | |
| Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 464 | // We currently always need a static runtime library for iOS. |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 465 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 466 | } else { |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 467 | assert(isTargetMacOS() && "unexpected non MacOS platform"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 468 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 469 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 470 | if (isMacosxVersionLT(10, 5)) |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 471 | CmdArgs.push_back("-lgcc_s.10.4"); |
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 472 | else if (isMacosxVersionLT(10, 6)) |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 473 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 474 | |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 475 | // 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] | 476 | // targeting 10.4, to provide versions of the static functions which were |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 477 | // omitted from 10.4.dylib. |
| 478 | // |
| 479 | // Unfortunately, that turned out to not be true, because Darwin system |
| 480 | // headers can still use eprintf on i386, and it is not exported from |
| 481 | // libSystem. Therefore, we still must provide a runtime library just for |
| 482 | // the tiny tiny handful of projects that *might* use that symbol. |
| 483 | if (isMacosxVersionLT(10, 5)) { |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 484 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 485 | } else { |
| 486 | if (getTriple().getArch() == llvm::Triple::x86) |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 487 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); |
| 488 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 489 | } |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 490 | } |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 493 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 494 | const OptTable &Opts = getDriver().getOpts(); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 495 | |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 496 | // Support allowing the SDKROOT environment variable used by xcrun and other |
| 497 | // Xcode tools to define the default sysroot, by making it the default for |
| 498 | // isysroot. |
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 499 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 500 | // Warn if the path does not exist. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 501 | if (!getVFS().exists(A->getValue())) |
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 502 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); |
| 503 | } else { |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 504 | if (char *env = ::getenv("SDKROOT")) { |
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 505 | // We only use this value as the default if it is an absolute path, |
| 506 | // exists, and it is not the root path. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 507 | if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) && |
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 508 | StringRef(env) != "/") { |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 509 | Args.append(Args.MakeSeparateArg( |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 510 | nullptr, Opts.getOption(options::OPT_isysroot), env)); |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 515 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 516 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 517 | Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ); |
| 518 | Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ); |
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 519 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 520 | if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 521 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 522 | << OSXVersion->getAsString(Args) |
| 523 | << (iOSVersion ? iOSVersion : |
| 524 | TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 525 | iOSVersion = TvOSVersion = WatchOSVersion = nullptr; |
| 526 | } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) { |
| 527 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 528 | << iOSVersion->getAsString(Args) |
| 529 | << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 530 | TvOSVersion = WatchOSVersion = nullptr; |
| 531 | } else if (TvOSVersion && WatchOSVersion) { |
| 532 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 533 | << TvOSVersion->getAsString(Args) |
| 534 | << WatchOSVersion->getAsString(Args); |
| 535 | WatchOSVersion = nullptr; |
| 536 | } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) { |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 537 | // If no deployment target was specified on the command line, check for |
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 538 | // environment defines. |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 539 | std::string OSXTarget; |
| 540 | std::string iOSTarget; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 541 | std::string TvOSTarget; |
| 542 | std::string WatchOSTarget; |
| 543 | |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 544 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) |
| 545 | OSXTarget = env; |
| 546 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) |
| 547 | iOSTarget = env; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 548 | if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET")) |
| 549 | TvOSTarget = env; |
| 550 | if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET")) |
| 551 | WatchOSTarget = env; |
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 552 | |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 553 | // If there is no command-line argument to specify the Target version and |
| 554 | // no environment variable defined, see if we can set the default based |
| 555 | // on -isysroot. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 556 | if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() && |
| Frederic Riss | 3ad83bd | 2016-01-12 23:47:59 +0000 | [diff] [blame] | 557 | TvOSTarget.empty() && Args.hasArg(options::OPT_isysroot)) { |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 558 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 559 | StringRef isysroot = A->getValue(); |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 560 | StringRef SDK = getSDKName(isysroot); |
| 561 | if (SDK.size() > 0) { |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 562 | // Slice the version number out. |
| 563 | // Version number is between the first and the last number. |
| 564 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 565 | size_t EndVer = SDK.find_last_of("0123456789"); |
| 566 | if (StartVer != StringRef::npos && EndVer > StartVer) { |
| 567 | StringRef Version = SDK.slice(StartVer, EndVer + 1); |
| 568 | if (SDK.startswith("iPhoneOS") || |
| 569 | SDK.startswith("iPhoneSimulator")) |
| 570 | iOSTarget = Version; |
| 571 | else if (SDK.startswith("MacOSX")) |
| 572 | OSXTarget = Version; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 573 | else if (SDK.startswith("WatchOS") || |
| 574 | SDK.startswith("WatchSimulator")) |
| 575 | WatchOSTarget = Version; |
| 576 | else if (SDK.startswith("AppleTVOS") || |
| 577 | SDK.startswith("AppleTVSimulator")) |
| 578 | TvOSTarget = Version; |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 579 | } |
| 580 | } |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 581 | } |
| 582 | } |
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 583 | |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 584 | // If no OSX or iOS target has been specified, try to guess platform |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 585 | // from arch name and compute the version from the triple. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 586 | if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() && |
| 587 | WatchOSTarget.empty()) { |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 588 | StringRef MachOArchName = getMachOArchName(Args); |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 589 | unsigned Major, Minor, Micro; |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 590 | if (MachOArchName == "armv7" || MachOArchName == "armv7s" || |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 591 | MachOArchName == "arm64") { |
| 592 | getTriple().getiOSVersion(Major, Minor, Micro); |
| 593 | llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' |
| 594 | << Micro; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 595 | } else if (MachOArchName == "armv7k") { |
| 596 | getTriple().getWatchOSVersion(Major, Minor, Micro); |
| 597 | llvm::raw_string_ostream(WatchOSTarget) << Major << '.' << Minor << '.' |
| 598 | << Micro; |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 599 | } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && |
| 600 | MachOArchName != "armv7em") { |
| 601 | if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { |
| 602 | getDriver().Diag(diag::err_drv_invalid_darwin_version) |
| 603 | << getTriple().getOSName(); |
| 604 | } |
| 605 | llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' |
| 606 | << Micro; |
| 607 | } |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 608 | } |
| Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 609 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 610 | // Do not allow conflicts with the watchOS target. |
| 611 | if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) { |
| 612 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 613 | << "WATCHOS_DEPLOYMENT_TARGET" |
| 614 | << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" : |
| 615 | "TVOS_DEPLOYMENT_TARGET"); |
| 616 | } |
| 617 | |
| 618 | // Do not allow conflicts with the tvOS target. |
| 619 | if (!TvOSTarget.empty() && !iOSTarget.empty()) { |
| 620 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 621 | << "TVOS_DEPLOYMENT_TARGET" |
| 622 | << "IPHONEOS_DEPLOYMENT_TARGET"; |
| 623 | } |
| 624 | |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 625 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 626 | // default platform. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 627 | if (!OSXTarget.empty() && (!iOSTarget.empty() || |
| 628 | !WatchOSTarget.empty() || |
| 629 | !TvOSTarget.empty())) { |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 630 | if (getTriple().getArch() == llvm::Triple::arm || |
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 631 | getTriple().getArch() == llvm::Triple::aarch64 || |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 632 | getTriple().getArch() == llvm::Triple::thumb) |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 633 | OSXTarget = ""; |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 634 | else |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 635 | iOSTarget = WatchOSTarget = TvOSTarget = ""; |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 636 | } |
| Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 637 | |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 638 | if (!OSXTarget.empty()) { |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 639 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 640 | OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 641 | Args.append(OSXVersion); |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 642 | } else if (!iOSTarget.empty()) { |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 643 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 644 | iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 645 | Args.append(iOSVersion); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 646 | } else if (!TvOSTarget.empty()) { |
| 647 | const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ); |
| 648 | TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget); |
| 649 | Args.append(TvOSVersion); |
| 650 | } else if (!WatchOSTarget.empty()) { |
| 651 | const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ); |
| 652 | WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget); |
| 653 | Args.append(WatchOSVersion); |
| Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 654 | } |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 655 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 657 | DarwinPlatformKind Platform; |
| 658 | if (OSXVersion) |
| 659 | Platform = MacOS; |
| 660 | else if (iOSVersion) |
| 661 | Platform = IPhoneOS; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 662 | else if (TvOSVersion) |
| 663 | Platform = TvOS; |
| 664 | else if (WatchOSVersion) |
| 665 | Platform = WatchOS; |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 666 | else |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 667 | llvm_unreachable("Unable to infer Darwin variant"); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 668 | |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 669 | // Set the tool chain target information. |
| 670 | unsigned Major, Minor, Micro; |
| 671 | bool HadExtra; |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 672 | if (Platform == MacOS) { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 673 | assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && |
| 674 | "Unknown target platform!"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 675 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, |
| 676 | HadExtra) || |
| 677 | HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 678 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 679 | << OSXVersion->getAsString(Args); |
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 680 | } else if (Platform == IPhoneOS) { |
| 681 | assert(iOSVersion && "Unknown target platform!"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 682 | if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, |
| 683 | HadExtra) || |
| Bob Wilson | 4cf27c4 | 2016-07-18 20:29:14 +0000 | [diff] [blame] | 684 | HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100) |
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 685 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 686 | << iOSVersion->getAsString(Args); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 687 | } else if (Platform == TvOS) { |
| 688 | if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, |
| 689 | Micro, HadExtra) || HadExtra || |
| Bob Wilson | 4cf27c4 | 2016-07-18 20:29:14 +0000 | [diff] [blame] | 690 | Major >= 100 || Minor >= 100 || Micro >= 100) |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 691 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 692 | << TvOSVersion->getAsString(Args); |
| 693 | } else if (Platform == WatchOS) { |
| 694 | if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor, |
| 695 | Micro, HadExtra) || HadExtra || |
| 696 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 697 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 698 | << WatchOSVersion->getAsString(Args); |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 699 | } else |
| 700 | llvm_unreachable("unknown kind of Darwin platform"); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 701 | |
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 702 | // Recognize iOS targets with an x86 architecture as the iOS simulator. |
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 703 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 704 | getTriple().getArch() == llvm::Triple::x86_64)) |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 705 | Platform = IPhoneOSSimulator; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 706 | if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 707 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 708 | Platform = TvOSSimulator; |
| 709 | if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 710 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 711 | Platform = WatchOSSimulator; |
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 712 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 713 | setTarget(Platform, Major, Minor, Micro); |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 714 | |
| 715 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 716 | StringRef SDK = getSDKName(A->getValue()); |
| 717 | if (SDK.size() > 0) { |
| 718 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 719 | StringRef SDKName = SDK.slice(0, StartVer); |
| 720 | if (!SDKName.startswith(getPlatformFamily())) |
| 721 | getDriver().Diag(diag::warn_incompatible_sysroot) |
| 722 | << SDKName << getPlatformFamily(); |
| 723 | } |
| 724 | } |
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 727 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 728 | ArgStringList &CmdArgs) const { |
| 729 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 730 | |
| 731 | switch (Type) { |
| 732 | case ToolChain::CST_Libcxx: |
| 733 | CmdArgs.push_back("-lc++"); |
| 734 | break; |
| 735 | |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 736 | case ToolChain::CST_Libstdcxx: |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 737 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 738 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 739 | // platforms we care about it was -lstdc++.6, so we search for that |
| 740 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 741 | |
| 742 | // Check in the sysroot first. |
| 743 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 744 | SmallString<128> P(A->getValue()); |
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 745 | llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 746 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 747 | if (!getVFS().exists(P)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 748 | llvm::sys::path::remove_filename(P); |
| 749 | llvm::sys::path::append(P, "libstdc++.6.dylib"); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 750 | if (getVFS().exists(P)) { |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 751 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 752 | return; |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | // Otherwise, look in the root. |
| Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 758 | // FIXME: This should be removed someday when we don't have to care about |
| 759 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 760 | if (!getVFS().exists("/usr/lib/libstdc++.dylib") && |
| 761 | getVFS().exists("/usr/lib/libstdc++.6.dylib")) { |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 762 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | // Otherwise, let the linker search. |
| 767 | CmdArgs.push_back("-lstdc++"); |
| 768 | break; |
| 769 | } |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 772 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 773 | ArgStringList &CmdArgs) const { |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 774 | // For Darwin platforms, use the compiler-rt-based support library |
| 775 | // instead of the gcc-provided one (which is also incidentally |
| 776 | // only present in the gcc lib dir, which makes it hard to find). |
| 777 | |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 778 | SmallString<128> P(getDriver().ResourceDir); |
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 779 | llvm::sys::path::append(P, "lib", "darwin"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 780 | |
| 781 | // Use the newer cc_kext for iOS ARM after 6.0. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 782 | if (isTargetWatchOS()) { |
| 783 | llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a"); |
| 784 | } else if (isTargetTvOS()) { |
| 785 | llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a"); |
| 786 | } else if (isTargetIPhoneOS()) { |
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 787 | llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 788 | } else { |
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 789 | llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 790 | } |
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 791 | |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 792 | // For now, allow missing resource libraries to support developers who may |
| 793 | // not have compiler-rt checked out or integrated into their build. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 794 | if (getVFS().exists(P)) |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 795 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 798 | DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, |
| 799 | const char *BoundArch) const { |
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 800 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 801 | const OptTable &Opts = getDriver().getOpts(); |
| 802 | |
| 803 | // FIXME: We really want to get out of the tool chain level argument |
| 804 | // translation business, as it makes the driver functionality much |
| 805 | // more opaque. For now, we follow gcc closely solely for the |
| 806 | // purpose of easily achieving feature parity & testability. Once we |
| 807 | // have something that works, we should reevaluate each translation |
| 808 | // and try to push it down into tool specific logic. |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 809 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 810 | for (Arg *A : Args) { |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 811 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 812 | // Skip this argument unless the architecture matches either the toolchain |
| 813 | // triple arch, or the arch being bound. |
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 814 | llvm::Triple::ArchType XarchArch = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 815 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); |
| 816 | if (!(XarchArch == getArch() || |
| 817 | (BoundArch && |
| 818 | XarchArch == |
| 819 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 820 | continue; |
| 821 | |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 822 | Arg *OriginalArg = A; |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 823 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 824 | unsigned Prev = Index; |
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 825 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 827 | // If the argument parsing failed or more than one argument was |
| 828 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 829 | // extra arguments. Emit an error and ignore. |
| 830 | // |
| 831 | // We also want to disallow any options which would alter the |
| 832 | // driver behavior; that isn't going to work in our model. We |
| 833 | // use isDriverOption() as an approximation, although things |
| 834 | // like -O4 are going to slip through. |
| Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 835 | if (!XarchArg || Index > Prev + 1) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 836 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 837 | << A->getAsString(Args); |
| Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 838 | continue; |
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 839 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 840 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 841 | << A->getAsString(Args); |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 842 | continue; |
| 843 | } |
| 844 | |
| Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 845 | XarchArg->setBaseArg(A); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 846 | |
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 847 | A = XarchArg.release(); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 848 | DAL->AddSynthesizedArg(A); |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 849 | |
| 850 | // Linker input arguments require custom handling. The problem is that we |
| 851 | // have already constructed the phase actions, so we can not treat them as |
| 852 | // "input arguments". |
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 853 | if (A->getOption().hasFlag(options::LinkerInput)) { |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 854 | // Convert the argument into individual Zlinker_input_args. |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 855 | for (const char *Value : A->getValues()) { |
| 856 | DAL->AddSeparateArg( |
| 857 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 858 | } |
| 859 | continue; |
| 860 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 861 | } |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 862 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 863 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 864 | // gcc translates options twice, which means that self-expanding |
| 865 | // options add duplicates. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 866 | switch ((options::ID)A->getOption().getID()) { |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 867 | default: |
| 868 | DAL->append(A); |
| 869 | break; |
| 870 | |
| 871 | case options::OPT_mkernel: |
| 872 | case options::OPT_fapple_kext: |
| 873 | DAL->append(A); |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 874 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 875 | break; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 876 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 877 | case options::OPT_dependency_file: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 878 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 879 | break; |
| 880 | |
| 881 | case options::OPT_gfull: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 882 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 883 | DAL->AddFlagArg( |
| 884 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | case options::OPT_gused: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 888 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 889 | DAL->AddFlagArg( |
| 890 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 891 | break; |
| 892 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 893 | case options::OPT_shared: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 894 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 895 | break; |
| 896 | |
| 897 | case options::OPT_fconstant_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 898 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 899 | break; |
| 900 | |
| 901 | case options::OPT_fno_constant_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 902 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case options::OPT_Wnonportable_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 906 | DAL->AddFlagArg(A, |
| 907 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 908 | break; |
| 909 | |
| 910 | case options::OPT_Wno_nonportable_cfstrings: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 911 | DAL->AddFlagArg( |
| 912 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 913 | break; |
| 914 | |
| 915 | case options::OPT_fpascal_strings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 916 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case options::OPT_fno_pascal_strings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 920 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 921 | break; |
| 922 | } |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 925 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 926 | getTriple().getArch() == llvm::Triple::x86_64) |
| Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 927 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 928 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), |
| 929 | "core2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 930 | |
| 931 | // 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] | 932 | // how the driver driver works. |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 933 | if (BoundArch) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 934 | StringRef Name = BoundArch; |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 935 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 936 | const Option MArch = Opts.getOption(options::OPT_march_EQ); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 937 | |
| 938 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 939 | // which defines the list of which architectures we accept. |
| 940 | if (Name == "ppc") |
| 941 | ; |
| 942 | else if (Name == "ppc601") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 943 | DAL->AddJoinedArg(nullptr, MCpu, "601"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 944 | else if (Name == "ppc603") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 945 | DAL->AddJoinedArg(nullptr, MCpu, "603"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 946 | else if (Name == "ppc604") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 947 | DAL->AddJoinedArg(nullptr, MCpu, "604"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 948 | else if (Name == "ppc604e") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 949 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 950 | else if (Name == "ppc750") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 951 | DAL->AddJoinedArg(nullptr, MCpu, "750"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 952 | else if (Name == "ppc7400") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 953 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 954 | else if (Name == "ppc7450") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 955 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 956 | else if (Name == "ppc970") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 957 | DAL->AddJoinedArg(nullptr, MCpu, "970"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 958 | |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 959 | else if (Name == "ppc64" || Name == "ppc64le") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 960 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 961 | |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 962 | else if (Name == "i386") |
| 963 | ; |
| 964 | else if (Name == "i486") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 965 | DAL->AddJoinedArg(nullptr, MArch, "i486"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 966 | else if (Name == "i586") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 967 | DAL->AddJoinedArg(nullptr, MArch, "i586"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 968 | else if (Name == "i686") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 969 | DAL->AddJoinedArg(nullptr, MArch, "i686"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 970 | else if (Name == "pentium") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 971 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 972 | else if (Name == "pentium2") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 973 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 974 | else if (Name == "pentpro") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 975 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 976 | else if (Name == "pentIIm3") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 977 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 978 | |
| 979 | else if (Name == "x86_64") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 980 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 981 | else if (Name == "x86_64h") { |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 982 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| 983 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); |
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 984 | } |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 985 | |
| 986 | else if (Name == "arm") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 987 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 988 | else if (Name == "armv4t") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 989 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 990 | else if (Name == "armv5") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 991 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 992 | else if (Name == "xscale") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 993 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 994 | else if (Name == "armv6") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 995 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 996 | else if (Name == "armv6m") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 997 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 998 | else if (Name == "armv7") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 999 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1000 | else if (Name == "armv7em") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1001 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); |
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1002 | else if (Name == "armv7k") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1003 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1004 | else if (Name == "armv7m") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1005 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); |
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1006 | else if (Name == "armv7s") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1007 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1008 | } |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 1009 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1010 | return DAL; |
| 1011 | } |
| 1012 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 1013 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1014 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1015 | // Embedded targets are simple at the moment, not supporting sanitizers and |
| 1016 | // with different libraries for each member of the product { static, PIC } x |
| 1017 | // { hard-float, soft-float } |
| 1018 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 1019 | CompilerRT += |
| 1020 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) |
| 1021 | ? "hard" |
| 1022 | : "soft"; |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1023 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; |
| 1024 | |
| 1025 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); |
| 1026 | } |
| 1027 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1028 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 1029 | const char *BoundArch) const { |
| 1030 | // First get the generic Apple args, before moving onto Darwin-specific ones. |
| 1031 | DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1032 | const OptTable &Opts = getDriver().getOpts(); |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1033 | |
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1034 | // If no architecture is bound, none of the translations here are relevant. |
| 1035 | if (!BoundArch) |
| 1036 | return DAL; |
| 1037 | |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1038 | // Add an explicit version min argument for the deployment target. We do this |
| 1039 | // after argument translation because -Xarch_ arguments may add a version min |
| 1040 | // argument. |
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1041 | AddDeploymentTarget(*DAL); |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1042 | |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1043 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. |
| 1044 | // FIXME: It would be far better to avoid inserting those -static arguments, |
| 1045 | // but we can't check the deployment target in the translation code until |
| 1046 | // it is set here. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1047 | if (isTargetWatchOSBased() || |
| 1048 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { |
| 1049 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1050 | Arg *A = *it; |
| 1051 | ++it; |
| 1052 | if (A->getOption().getID() != options::OPT_mkernel && |
| 1053 | A->getOption().getID() != options::OPT_fapple_kext) |
| 1054 | continue; |
| 1055 | assert(it != ie && "unexpected argument translation"); |
| 1056 | A = *it; |
| 1057 | assert(A->getOption().getID() == options::OPT_static && |
| 1058 | "missing expected -static argument"); |
| 1059 | it = DAL->getArgs().erase(it); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1063 | if (!Args.getLastArg(options::OPT_stdlib_EQ) && |
| Tim Northover | 3a098c1 | 2016-02-15 16:38:10 +0000 | [diff] [blame] | 1064 | GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1065 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), |
| 1066 | "libc++"); |
| 1067 | |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1068 | // Validate the C++ standard library choice. |
| 1069 | CXXStdlibType Type = GetCXXStdlibType(*DAL); |
| 1070 | if (Type == ToolChain::CST_Libcxx) { |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1071 | // Check whether the target provides libc++. |
| 1072 | StringRef where; |
| 1073 | |
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1074 | // Complain about targeting iOS < 5.0 in any way. |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1075 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) |
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1076 | where = "iOS 5.0"; |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1077 | |
| 1078 | if (where != StringRef()) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1079 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1083 | return DAL; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1085 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1086 | bool MachO::IsUnwindTablesDefault() const { |
| Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1087 | return getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1090 | bool MachO::UseDwarfDebugFlags() const { |
| Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1091 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 1092 | return S[0] != '\0'; |
| 1093 | return false; |
| 1094 | } |
| 1095 | |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1096 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { |
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1097 | // Darwin uses SjLj exceptions on ARM. |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1098 | if (getTriple().getArch() != llvm::Triple::arm && |
| 1099 | getTriple().getArch() != llvm::Triple::thumb) |
| 1100 | return false; |
| 1101 | |
| Tim Northover | c741b04 | 2015-11-17 18:27:27 +0000 | [diff] [blame] | 1102 | // Only watchOS uses the new DWARF/Compact unwinding method. |
| Tim Northover | d88ecb3 | 2016-01-27 19:32:40 +0000 | [diff] [blame] | 1103 | llvm::Triple Triple(ComputeLLVMTriple(Args)); |
| Tim Northover | 4c9ac7d | 2016-01-27 22:14:02 +0000 | [diff] [blame] | 1104 | return !Triple.isWatchABI(); |
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| Steven Wu | 574b0f2 | 2016-03-01 01:07:58 +0000 | [diff] [blame] | 1107 | bool Darwin::SupportsEmbeddedBitcode() const { |
| 1108 | assert(TargetInitialized && "Target not initialized!"); |
| 1109 | if (isTargetIPhoneOS() && isIPhoneOSVersionLT(6, 0)) |
| 1110 | return false; |
| 1111 | return true; |
| 1112 | } |
| 1113 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1114 | bool MachO::isPICDefault() const { return true; } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1115 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1116 | bool MachO::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1117 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1118 | bool MachO::isPICDefaultForced() const { |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1119 | return (getArch() == llvm::Triple::x86_64 || |
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1120 | getArch() == llvm::Triple::aarch64); |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1123 | bool MachO::SupportsProfiling() const { |
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1124 | // Profiling instrumentation is only supported on x86. |
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1125 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1128 | void Darwin::addMinVersionArgs(const ArgList &Args, |
| 1129 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1130 | VersionTuple TargetVersion = getTargetVersion(); |
| 1131 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1132 | if (isTargetWatchOS()) |
| 1133 | CmdArgs.push_back("-watchos_version_min"); |
| 1134 | else if (isTargetWatchOSSimulator()) |
| 1135 | CmdArgs.push_back("-watchos_simulator_version_min"); |
| 1136 | else if (isTargetTvOS()) |
| 1137 | CmdArgs.push_back("-tvos_version_min"); |
| 1138 | else if (isTargetTvOSSimulator()) |
| 1139 | CmdArgs.push_back("-tvos_simulator_version_min"); |
| 1140 | else if (isTargetIOSSimulator()) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1141 | CmdArgs.push_back("-ios_simulator_version_min"); |
| Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1142 | else if (isTargetIOSBased()) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1143 | CmdArgs.push_back("-iphoneos_version_min"); |
| 1144 | else { |
| 1145 | assert(isTargetMacOS() && "unexpected target"); |
| 1146 | CmdArgs.push_back("-macosx_version_min"); |
| 1147 | } |
| 1148 | |
| 1149 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); |
| 1150 | } |
| 1151 | |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1152 | void Darwin::addStartObjectFileArgs(const ArgList &Args, |
| 1153 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1154 | // Derived from startfile spec. |
| 1155 | if (Args.hasArg(options::OPT_dynamiclib)) { |
| 1156 | // Derived from darwin_dylib1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1157 | if (isTargetWatchOSBased()) { |
| 1158 | ; // watchOS does not need dylib1.o. |
| 1159 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1160 | ; // iOS simulator does not need dylib1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1161 | } else if (isTargetIPhoneOS()) { |
| 1162 | if (isIPhoneOSVersionLT(3, 1)) |
| 1163 | CmdArgs.push_back("-ldylib1.o"); |
| 1164 | } else { |
| 1165 | if (isMacosxVersionLT(10, 5)) |
| 1166 | CmdArgs.push_back("-ldylib1.o"); |
| 1167 | else if (isMacosxVersionLT(10, 6)) |
| 1168 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1169 | } |
| 1170 | } else { |
| 1171 | if (Args.hasArg(options::OPT_bundle)) { |
| 1172 | if (!Args.hasArg(options::OPT_static)) { |
| 1173 | // Derived from darwin_bundle1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1174 | if (isTargetWatchOSBased()) { |
| 1175 | ; // watchOS does not need bundle1.o. |
| 1176 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1177 | ; // iOS simulator does not need bundle1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1178 | } else if (isTargetIPhoneOS()) { |
| 1179 | if (isIPhoneOSVersionLT(3, 1)) |
| 1180 | CmdArgs.push_back("-lbundle1.o"); |
| 1181 | } else { |
| 1182 | if (isMacosxVersionLT(10, 6)) |
| 1183 | CmdArgs.push_back("-lbundle1.o"); |
| 1184 | } |
| 1185 | } |
| 1186 | } else { |
| 1187 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { |
| 1188 | if (Args.hasArg(options::OPT_static) || |
| 1189 | Args.hasArg(options::OPT_object) || |
| 1190 | Args.hasArg(options::OPT_preload)) { |
| 1191 | CmdArgs.push_back("-lgcrt0.o"); |
| 1192 | } else { |
| 1193 | CmdArgs.push_back("-lgcrt1.o"); |
| 1194 | |
| 1195 | // darwin_crt2 spec is empty. |
| 1196 | } |
| 1197 | // By default on OS X 10.8 and later, we don't link with a crt1.o |
| 1198 | // file and the linker knows to use _main as the entry point. But, |
| 1199 | // when compiling with -pg, we need to link with the gcrt1.o file, |
| 1200 | // so pass the -no_new_main option to tell the linker to use the |
| 1201 | // "start" symbol as the entry point. |
| 1202 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) |
| 1203 | CmdArgs.push_back("-no_new_main"); |
| 1204 | } else { |
| 1205 | if (Args.hasArg(options::OPT_static) || |
| 1206 | Args.hasArg(options::OPT_object) || |
| 1207 | Args.hasArg(options::OPT_preload)) { |
| 1208 | CmdArgs.push_back("-lcrt0.o"); |
| 1209 | } else { |
| 1210 | // Derived from darwin_crt1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1211 | if (isTargetWatchOSBased()) { |
| 1212 | ; // watchOS does not need crt1.o. |
| 1213 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1214 | ; // iOS simulator does not need crt1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1215 | } else if (isTargetIPhoneOS()) { |
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1216 | if (getArch() == llvm::Triple::aarch64) |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1217 | ; // iOS does not need any crt1 files for arm64 |
| 1218 | else if (isIPhoneOSVersionLT(3, 1)) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1219 | CmdArgs.push_back("-lcrt1.o"); |
| 1220 | else if (isIPhoneOSVersionLT(6, 0)) |
| 1221 | CmdArgs.push_back("-lcrt1.3.1.o"); |
| 1222 | } else { |
| 1223 | if (isMacosxVersionLT(10, 5)) |
| 1224 | CmdArgs.push_back("-lcrt1.o"); |
| 1225 | else if (isMacosxVersionLT(10, 6)) |
| 1226 | CmdArgs.push_back("-lcrt1.10.5.o"); |
| 1227 | else if (isMacosxVersionLT(10, 8)) |
| 1228 | CmdArgs.push_back("-lcrt1.10.6.o"); |
| 1229 | |
| 1230 | // darwin_crt2 spec is empty. |
| 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1238 | !isTargetWatchOS() && |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1239 | isMacosxVersionLT(10, 5)) { |
| 1240 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); |
| 1241 | CmdArgs.push_back(Str); |
| 1242 | } |
| 1243 | } |
| 1244 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1245 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } |
| Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1246 | |
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1247 | void Darwin::CheckObjCARC() const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1248 | if (isTargetIOSBased() || isTargetWatchOSBased() || |
| 1249 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) |
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1250 | return; |
| John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1251 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); |
| Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1254 | SanitizerMask Darwin::getSupportedSanitizers() const { |
| Devin Coughlin | fcfa38c | 2016-03-20 18:24:33 +0000 | [diff] [blame] | 1255 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1256 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 1257 | Res |= SanitizerKind::Address; |
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1258 | if (isTargetMacOS()) { |
| 1259 | if (!isMacosxVersionLT(10, 9)) |
| 1260 | Res |= SanitizerKind::Vptr; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1261 | Res |= SanitizerKind::SafeStack; |
| Devin Coughlin | fcfa38c | 2016-03-20 18:24:33 +0000 | [diff] [blame] | 1262 | if (IsX86_64) |
| 1263 | Res |= SanitizerKind::Thread; |
| 1264 | } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) { |
| 1265 | if (IsX86_64) |
| 1266 | Res |= SanitizerKind::Thread; |
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1267 | } |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1268 | return Res; |
| 1269 | } |
| 1270 | |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1271 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 1272 | /// all subcommands; this relies on gcc translating the majority of |
| 1273 | /// command line options. |
| 1274 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1275 | /// \brief Parse a GCCVersion object out of a string of text. |
| 1276 | /// |
| 1277 | /// This is the primary means of forming GCCVersion objects. |
| 1278 | /*static*/ |
| 1279 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1280 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1281 | std::pair<StringRef, StringRef> First = VersionText.split('.'); |
| 1282 | std::pair<StringRef, StringRef> Second = First.second.split('.'); |
| 1283 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1284 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| 1285 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1286 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1287 | GoodVersion.MajorStr = First.first.str(); |
| Bryan Chan | d346ae6 | 2016-06-17 16:47:14 +0000 | [diff] [blame] | 1288 | if (First.second.empty()) |
| 1289 | return GoodVersion; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1290 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1291 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1292 | GoodVersion.MinorStr = Second.first.str(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1293 | |
| 1294 | // First look for a number prefix and parse that if present. Otherwise just |
| 1295 | // stash the entire patch string in the suffix, and leave the number |
| 1296 | // unspecified. This covers versions strings such as: |
| Bryan Chan | d346ae6 | 2016-06-17 16:47:14 +0000 | [diff] [blame] | 1297 | // 5 (handled above) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1298 | // 4.4 |
| 1299 | // 4.4.0 |
| 1300 | // 4.4.x |
| 1301 | // 4.4.2-rc4 |
| 1302 | // 4.4.x-patched |
| 1303 | // And retains any patch number it finds. |
| 1304 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); |
| 1305 | if (!PatchText.empty()) { |
| Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1306 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1307 | // Try to parse the number and any suffix. |
| 1308 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || |
| 1309 | GoodVersion.Patch < 0) |
| 1310 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1311 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | return GoodVersion; |
| 1316 | } |
| 1317 | |
| 1318 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1319 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, |
| 1320 | int RHSPatch, |
| 1321 | StringRef RHSPatchSuffix) const { |
| 1322 | if (Major != RHSMajor) |
| 1323 | return Major < RHSMajor; |
| 1324 | if (Minor != RHSMinor) |
| 1325 | return Minor < RHSMinor; |
| 1326 | if (Patch != RHSPatch) { |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1327 | // Note that versions without a specified patch sort higher than those with |
| 1328 | // a patch. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1329 | if (RHSPatch == -1) |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1330 | return true; |
| 1331 | if (Patch == -1) |
| 1332 | return false; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1333 | |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1334 | // Otherwise just sort on the patch itself. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1335 | return Patch < RHSPatch; |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1336 | } |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1337 | if (PatchSuffix != RHSPatchSuffix) { |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1338 | // Sort empty suffixes higher. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1339 | if (RHSPatchSuffix.empty()) |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1340 | return true; |
| 1341 | if (PatchSuffix.empty()) |
| Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1342 | return false; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1343 | |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1344 | // Provide a lexicographic sort to make this a total ordering. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1345 | return PatchSuffix < RHSPatchSuffix; |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | // The versions are equal. |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1349 | return false; |
| 1350 | } |
| 1351 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1352 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1353 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); |
| 1354 | if (A) |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1355 | return A->getValue(); |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1356 | return GCC_INSTALL_PREFIX; |
| 1357 | } |
| 1358 | |
| Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1359 | /// \brief Initialize a GCCInstallationDetector from the driver. |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1360 | /// |
| 1361 | /// This performs all of the autodetection and sets up the various paths. |
| Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1362 | /// Once constructed, a GCCInstallationDetector is essentially immutable. |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1363 | /// |
| 1364 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and |
| 1365 | /// should instead pull the target out of the driver. This is currently |
| 1366 | /// necessary because the driver doesn't store the final version of the target |
| 1367 | /// triple. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1368 | void Generic_GCC::GCCInstallationDetector::init( |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1369 | const llvm::Triple &TargetTriple, const ArgList &Args, |
| Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1370 | ArrayRef<std::string> ExtraTripleAliases) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1371 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() |
| 1372 | ? TargetTriple.get64BitArchVariant() |
| 1373 | : TargetTriple.get32BitArchVariant(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1374 | // The library directories which may contain GCC installations. |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1375 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1376 | // The compatible GCC triples for this particular architecture. |
| Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1377 | SmallVector<StringRef, 16> CandidateTripleAliases; |
| 1378 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1379 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, |
| 1380 | CandidateTripleAliases, CandidateBiarchLibDirs, |
| 1381 | CandidateBiarchTripleAliases); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1382 | |
| 1383 | // Compute the set of prefixes for our search. |
| 1384 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), |
| 1385 | D.PrefixDirs.end()); |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1386 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1387 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); |
| 1388 | if (GCCToolchainDir != "") { |
| 1389 | if (GCCToolchainDir.back() == '/') |
| 1390 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1391 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1392 | Prefixes.push_back(GCCToolchainDir); |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1393 | } else { |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1394 | // If we have a SysRoot, try that first. |
| 1395 | if (!D.SysRoot.empty()) { |
| 1396 | Prefixes.push_back(D.SysRoot); |
| 1397 | Prefixes.push_back(D.SysRoot + "/usr"); |
| 1398 | } |
| 1399 | |
| 1400 | // Then look for gcc installed alongside clang. |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1401 | Prefixes.push_back(D.InstalledDir + "/.."); |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1402 | |
| Rafael Espindola | 2edca41 | 2016-05-09 13:03:10 +0000 | [diff] [blame] | 1403 | // Then look for distribution supplied gcc installations. |
| 1404 | if (D.SysRoot.empty()) { |
| 1405 | // Look for RHEL devtoolsets. |
| 1406 | Prefixes.push_back("/opt/rh/devtoolset-4/root/usr"); |
| 1407 | Prefixes.push_back("/opt/rh/devtoolset-3/root/usr"); |
| 1408 | Prefixes.push_back("/opt/rh/devtoolset-2/root/usr"); |
| 1409 | Prefixes.push_back("/opt/rh/devtoolset-1.1/root/usr"); |
| 1410 | Prefixes.push_back("/opt/rh/devtoolset-1.0/root/usr"); |
| 1411 | // And finally in /usr. |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1412 | Prefixes.push_back("/usr"); |
| Rafael Espindola | 2edca41 | 2016-05-09 13:03:10 +0000 | [diff] [blame] | 1413 | } |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1414 | } |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1415 | |
| 1416 | // Loop over the various components which exist and select the best GCC |
| 1417 | // installation available. GCC installs are ranked by version number. |
| 1418 | Version = GCCVersion::Parse("0.0.0"); |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1419 | for (const std::string &Prefix : Prefixes) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1420 | if (!D.getVFS().exists(Prefix)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1421 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1422 | for (StringRef Suffix : CandidateLibDirs) { |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1423 | const std::string LibDir = Prefix + Suffix.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1424 | if (!D.getVFS().exists(LibDir)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1425 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1426 | for (StringRef Candidate : ExtraTripleAliases) // Try these first. |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1427 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1428 | for (StringRef Candidate : CandidateTripleAliases) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1429 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1430 | } |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1431 | for (StringRef Suffix : CandidateBiarchLibDirs) { |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1432 | const std::string LibDir = Prefix + Suffix.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1433 | if (!D.getVFS().exists(LibDir)) |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1434 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1435 | for (StringRef Candidate : CandidateBiarchTripleAliases) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1436 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1437 | /*NeedsBiarchSuffix=*/ true); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1442 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1443 | for (const auto &InstallPath : CandidateGCCInstallPaths) |
| 1444 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1445 | |
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1446 | if (!GCCInstallPath.empty()) |
| 1447 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; |
| 1448 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1449 | for (const auto &Multilib : Multilibs) |
| 1450 | OS << "Candidate multilib: " << Multilib << "\n"; |
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1451 | |
| 1452 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) |
| 1453 | OS << "Selected multilib: " << SelectedMultilib << "\n"; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { |
| 1457 | if (BiarchSibling.hasValue()) { |
| 1458 | M = BiarchSibling.getValue(); |
| 1459 | return true; |
| 1460 | } |
| 1461 | return false; |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1464 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1465 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1466 | SmallVectorImpl<StringRef> &LibDirs, |
| 1467 | SmallVectorImpl<StringRef> &TripleAliases, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1468 | SmallVectorImpl<StringRef> &BiarchLibDirs, |
| 1469 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1470 | // Declare a bunch of static data sets that we'll select between below. These |
| 1471 | // are specifically designed to always refer to string literals to avoid any |
| 1472 | // lifetime or initialization issues. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1473 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; |
| 1474 | static const char *const AArch64Triples[] = { |
| 1475 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", |
| 1476 | "aarch64-redhat-linux"}; |
| 1477 | static const char *const AArch64beLibDirs[] = {"/lib"}; |
| 1478 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", |
| 1479 | "aarch64_be-linux-gnu"}; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1480 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1481 | static const char *const ARMLibDirs[] = {"/lib"}; |
| 1482 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", |
| 1483 | "arm-linux-androideabi"}; |
| 1484 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", |
| 1485 | "armv7hl-redhat-linux-gnueabi"}; |
| 1486 | static const char *const ARMebLibDirs[] = {"/lib"}; |
| 1487 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", |
| 1488 | "armeb-linux-androideabi"}; |
| 1489 | static const char *const ARMebHFTriples[] = { |
| 1490 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1491 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1492 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1493 | static const char *const X86_64Triples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1494 | "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", |
| 1495 | "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E", |
| 1496 | "x86_64-redhat-linux", "x86_64-suse-linux", |
| 1497 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", |
| 1498 | "x86_64-slackware-linux", "x86_64-linux-android", |
| 1499 | "x86_64-unknown-linux"}; |
| 1500 | static const char *const X32LibDirs[] = {"/libx32"}; |
| 1501 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1502 | static const char *const X86Triples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1503 | "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", |
| 1504 | "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux", |
| 1505 | "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux", |
| 1506 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", |
| 1507 | "i586-linux-gnu"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1508 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1509 | static const char *const MIPSLibDirs[] = {"/lib"}; |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1510 | static const char *const MIPSTriples[] = {"mips-linux-gnu", "mips-mti-linux", |
| 1511 | "mips-mti-linux-gnu", |
| 1512 | "mips-img-linux-gnu"}; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1513 | static const char *const MIPSELLibDirs[] = {"/lib"}; |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 1514 | static const char *const MIPSELTriples[] = {"mipsel-linux-gnu", |
| 1515 | "mips-img-linux-gnu"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1516 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1517 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; |
| 1518 | static const char *const MIPS64Triples[] = { |
| 1519 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1520 | "mips64-linux-gnuabi64"}; |
| 1521 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; |
| 1522 | static const char *const MIPS64ELTriples[] = { |
| 1523 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 1524 | "mips64el-linux-gnuabi64"}; |
| 1525 | |
| 1526 | static const char *const MIPSELAndroidLibDirs[] = {"/lib", "/libr2", |
| 1527 | "/libr6"}; |
| 1528 | static const char *const MIPSELAndroidTriples[] = {"mipsel-linux-android"}; |
| 1529 | static const char *const MIPS64ELAndroidLibDirs[] = {"/lib64", "/lib", |
| 1530 | "/libr2", "/libr6"}; |
| 1531 | static const char *const MIPS64ELAndroidTriples[] = { |
| 1532 | "mips64el-linux-android"}; |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1533 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1534 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1535 | static const char *const PPCTriples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1536 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", |
| 1537 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; |
| 1538 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; |
| 1539 | static const char *const PPC64Triples[] = { |
| 1540 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", |
| 1541 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; |
| 1542 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; |
| 1543 | static const char *const PPC64LETriples[] = { |
| 1544 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", |
| 1545 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1546 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1547 | static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; |
| 1548 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", |
| 1549 | "sparcv8-linux-gnu"}; |
| 1550 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; |
| 1551 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", |
| 1552 | "sparcv9-linux-gnu"}; |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1553 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1554 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1555 | static const char *const SystemZTriples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1556 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", |
| 1557 | "s390x-suse-linux", "s390x-redhat-linux"}; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1558 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1559 | // Solaris. |
| 1560 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; |
| 1561 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", |
| 1562 | "i386-pc-solaris2.11"}; |
| 1563 | |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1564 | using std::begin; |
| 1565 | using std::end; |
| 1566 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1567 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 1568 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); |
| 1569 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1570 | return; |
| 1571 | } |
| 1572 | |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1573 | switch (TargetTriple.getArch()) { |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1574 | case llvm::Triple::aarch64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1575 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1576 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| 1577 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1578 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1579 | break; |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1580 | case llvm::Triple::aarch64_be: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1581 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1582 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| 1583 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1584 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1585 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1586 | case llvm::Triple::arm: |
| 1587 | case llvm::Triple::thumb: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1588 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1589 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1590 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1591 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1592 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1593 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1594 | break; |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1595 | case llvm::Triple::armeb: |
| 1596 | case llvm::Triple::thumbeb: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1597 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1598 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1599 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1600 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1601 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1602 | } |
| 1603 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1604 | case llvm::Triple::x86_64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1605 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1606 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| 1607 | // x32 is always available when x86_64 is available, so adding it as |
| 1608 | // secondary arch with x86_64 triples |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1609 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1610 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); |
| 1611 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1612 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1613 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1614 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1615 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1616 | break; |
| 1617 | case llvm::Triple::x86: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1618 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1619 | // MCU toolchain is 32 bit only and its triple alias is TargetTriple |
| 1620 | // itself, which will be appended below. |
| 1621 | if (!TargetTriple.isOSIAMCU()) { |
| 1622 | TripleAliases.append(begin(X86Triples), end(X86Triples)); |
| 1623 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1624 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| 1625 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1626 | break; |
| 1627 | case llvm::Triple::mips: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1628 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1629 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1630 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1631 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1632 | break; |
| 1633 | case llvm::Triple::mipsel: |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 1634 | if (TargetTriple.isAndroid()) { |
| 1635 | LibDirs.append(begin(MIPSELAndroidLibDirs), end(MIPSELAndroidLibDirs)); |
| 1636 | TripleAliases.append(begin(MIPSELAndroidTriples), |
| 1637 | end(MIPSELAndroidTriples)); |
| 1638 | BiarchLibDirs.append(begin(MIPS64ELAndroidLibDirs), |
| 1639 | end(MIPS64ELAndroidLibDirs)); |
| 1640 | BiarchTripleAliases.append(begin(MIPS64ELAndroidTriples), |
| 1641 | end(MIPS64ELAndroidTriples)); |
| 1642 | |
| 1643 | } else { |
| 1644 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1645 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1646 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1647 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1648 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| 1649 | } |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1650 | break; |
| 1651 | case llvm::Triple::mips64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1652 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1653 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| 1654 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1655 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1656 | break; |
| 1657 | case llvm::Triple::mips64el: |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 1658 | if (TargetTriple.isAndroid()) { |
| 1659 | LibDirs.append(begin(MIPS64ELAndroidLibDirs), |
| 1660 | end(MIPS64ELAndroidLibDirs)); |
| 1661 | TripleAliases.append(begin(MIPS64ELAndroidTriples), |
| 1662 | end(MIPS64ELAndroidTriples)); |
| 1663 | BiarchLibDirs.append(begin(MIPSELAndroidLibDirs), |
| 1664 | end(MIPSELAndroidLibDirs)); |
| 1665 | BiarchTripleAliases.append(begin(MIPSELAndroidTriples), |
| 1666 | end(MIPSELAndroidTriples)); |
| 1667 | |
| 1668 | } else { |
| 1669 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1670 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| 1671 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1672 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1673 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1674 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1675 | break; |
| 1676 | case llvm::Triple::ppc: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1677 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1678 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| 1679 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1680 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1681 | break; |
| 1682 | case llvm::Triple::ppc64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1683 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1684 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| 1685 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1686 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1687 | break; |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1688 | case llvm::Triple::ppc64le: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1689 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); |
| 1690 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1691 | break; |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1692 | case llvm::Triple::sparc: |
| Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1693 | case llvm::Triple::sparcel: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1694 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1695 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| 1696 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1697 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1698 | break; |
| 1699 | case llvm::Triple::sparcv9: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1700 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1701 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| 1702 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1703 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1704 | break; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1705 | case llvm::Triple::systemz: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1706 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); |
| 1707 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1708 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1709 | default: |
| 1710 | // By default, just rely on the standard lib directories and the original |
| 1711 | // triple. |
| 1712 | break; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1713 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1714 | |
| 1715 | // Always append the drivers target triple to the end, in case it doesn't |
| 1716 | // match any of our aliases. |
| 1717 | TripleAliases.push_back(TargetTriple.str()); |
| 1718 | |
| 1719 | // Also include the multiarch variant if it's different. |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1720 | if (TargetTriple.str() != BiarchTriple.str()) |
| 1721 | BiarchTripleAliases.push_back(BiarchTriple.str()); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 1724 | // Parses the contents of version.txt in an CUDA installation. It should |
| 1725 | // contain one line of the from e.g. "CUDA Version 7.5.2". |
| 1726 | static CudaVersion ParseCudaVersionFile(llvm::StringRef V) { |
| 1727 | if (!V.startswith("CUDA Version ")) |
| 1728 | return CudaVersion::UNKNOWN; |
| 1729 | V = V.substr(strlen("CUDA Version ")); |
| 1730 | int Major = -1, Minor = -1; |
| 1731 | auto First = V.split('.'); |
| 1732 | auto Second = First.second.split('.'); |
| 1733 | if (!First.first.getAsInteger(10, Major) || |
| 1734 | !Second.first.getAsInteger(10, Minor)) |
| 1735 | return CudaVersion::UNKNOWN; |
| 1736 | |
| 1737 | if (Major == 7 && Minor == 0) { |
| 1738 | // This doesn't appear to ever happen -- version.txt doesn't exist in the |
| 1739 | // CUDA 7 installs I've seen. But no harm in checking. |
| 1740 | return CudaVersion::CUDA_70; |
| 1741 | } |
| 1742 | if (Major == 7 && Minor == 5) |
| 1743 | return CudaVersion::CUDA_75; |
| 1744 | if (Major == 8 && Minor == 0) |
| 1745 | return CudaVersion::CUDA_80; |
| 1746 | return CudaVersion::UNKNOWN; |
| 1747 | } |
| 1748 | |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1749 | // \brief -- try common CUDA installation paths looking for files we need for |
| 1750 | // CUDA compilation. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1751 | void Generic_GCC::CudaInstallationDetector::init( |
| 1752 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { |
| NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1753 | SmallVector<std::string, 4> CudaPathCandidates; |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1754 | |
| 1755 | if (Args.hasArg(options::OPT_cuda_path_EQ)) |
| 1756 | CudaPathCandidates.push_back( |
| 1757 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); |
| 1758 | else { |
| 1759 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); |
| Justin Lebar | ef1aaac | 2016-07-06 21:21:14 +0000 | [diff] [blame] | 1760 | // FIXME: Uncomment this once we can compile the cuda 8 headers. |
| 1761 | // CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-8.0"); |
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 1762 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.5"); |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1763 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); |
| 1764 | } |
| 1765 | |
| Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1766 | for (const auto &CudaPath : CudaPathCandidates) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1767 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1768 | continue; |
| 1769 | |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1770 | InstallPath = CudaPath; |
| 1771 | BinPath = CudaPath + "/bin"; |
| 1772 | IncludePath = InstallPath + "/include"; |
| 1773 | LibDevicePath = InstallPath + "/nvvm/libdevice"; |
| 1774 | LibPath = InstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1775 | |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1776 | auto &FS = D.getVFS(); |
| 1777 | if (!(FS.exists(IncludePath) && FS.exists(BinPath) && FS.exists(LibPath) && |
| 1778 | FS.exists(LibDevicePath))) |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1779 | continue; |
| 1780 | |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1781 | std::error_code EC; |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1782 | for (llvm::sys::fs::directory_iterator LI(LibDevicePath, EC), LE; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1783 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 1784 | StringRef FilePath = LI->path(); |
| 1785 | StringRef FileName = llvm::sys::path::filename(FilePath); |
| 1786 | // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc |
| 1787 | const StringRef LibDeviceName = "libdevice."; |
| 1788 | if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc"))) |
| 1789 | continue; |
| 1790 | StringRef GpuArch = FileName.slice( |
| 1791 | LibDeviceName.size(), FileName.find('.', LibDeviceName.size())); |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1792 | LibDeviceMap[GpuArch] = FilePath.str(); |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1793 | // Insert map entries for specifc devices with this compute capability. |
| 1794 | if (GpuArch == "compute_20") { |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1795 | LibDeviceMap["sm_20"] = FilePath; |
| 1796 | LibDeviceMap["sm_21"] = FilePath; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1797 | } else if (GpuArch == "compute_30") { |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1798 | LibDeviceMap["sm_30"] = FilePath; |
| 1799 | LibDeviceMap["sm_32"] = FilePath; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1800 | } else if (GpuArch == "compute_35") { |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1801 | LibDeviceMap["sm_35"] = FilePath; |
| 1802 | LibDeviceMap["sm_37"] = FilePath; |
| Artem Belevich | ffa5fc5 | 2016-05-19 17:47:47 +0000 | [diff] [blame] | 1803 | } else if (GpuArch == "compute_50") { |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1804 | LibDeviceMap["sm_50"] = FilePath; |
| 1805 | LibDeviceMap["sm_52"] = FilePath; |
| 1806 | LibDeviceMap["sm_53"] = FilePath; |
| 1807 | LibDeviceMap["sm_60"] = FilePath; |
| 1808 | LibDeviceMap["sm_61"] = FilePath; |
| 1809 | LibDeviceMap["sm_62"] = FilePath; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 1813 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile = |
| 1814 | FS.getBufferForFile(InstallPath + "/version.txt"); |
| 1815 | if (!VersionFile) { |
| 1816 | // CUDA 7.0 doesn't have a version.txt, so guess that's our version if |
| 1817 | // version.txt isn't present. |
| 1818 | Version = CudaVersion::CUDA_70; |
| 1819 | } else { |
| 1820 | Version = ParseCudaVersionFile((*VersionFile)->getBuffer()); |
| 1821 | } |
| 1822 | |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1823 | IsValid = true; |
| 1824 | break; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 1828 | void Generic_GCC::CudaInstallationDetector::CheckCudaVersionSupportsArch( |
| 1829 | CudaArch Arch) const { |
| 1830 | if (Arch == CudaArch::UNKNOWN || Version == CudaVersion::UNKNOWN || |
| 1831 | ArchsWithVersionTooLowErrors.count(Arch) > 0) |
| 1832 | return; |
| 1833 | |
| 1834 | auto RequiredVersion = MinVersionForCudaArch(Arch); |
| 1835 | if (Version < RequiredVersion) { |
| 1836 | ArchsWithVersionTooLowErrors.insert(Arch); |
| 1837 | D.Diag(diag::err_drv_cuda_version_too_low) |
| 1838 | << InstallPath << CudaArchToString(Arch) << CudaVersionToString(Version) |
| 1839 | << CudaVersionToString(RequiredVersion); |
| 1840 | } |
| 1841 | } |
| 1842 | |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1843 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { |
| 1844 | if (isValid()) |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 1845 | OS << "Found CUDA installation: " << InstallPath << ", version " |
| 1846 | << CudaVersionToString(Version) << "\n"; |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1849 | namespace { |
| 1850 | // Filter to remove Multilibs that don't exist as a suffix to Path |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1851 | class FilterNonExistent { |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1852 | StringRef Base, File; |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1853 | vfs::FileSystem &VFS; |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1854 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1855 | public: |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1856 | FilterNonExistent(StringRef Base, StringRef File, vfs::FileSystem &VFS) |
| 1857 | : Base(Base), File(File), VFS(VFS) {} |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1858 | bool operator()(const Multilib &M) { |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1859 | return !VFS.exists(Base + M.gccSuffix() + File); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1860 | } |
| 1861 | }; |
| 1862 | } // end anonymous namespace |
| 1863 | |
| 1864 | static void addMultilibFlag(bool Enabled, const char *const Flag, |
| 1865 | std::vector<std::string> &Flags) { |
| 1866 | if (Enabled) |
| 1867 | Flags.push_back(std::string("+") + Flag); |
| 1868 | else |
| 1869 | Flags.push_back(std::string("-") + Flag); |
| 1870 | } |
| 1871 | |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 1872 | static bool isArmOrThumbArch(llvm::Triple::ArchType Arch) { |
| 1873 | return Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb; |
| 1874 | } |
| 1875 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1876 | static bool isMipsArch(llvm::Triple::ArchType Arch) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1877 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || |
| 1878 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1879 | } |
| 1880 | |
| 1881 | static bool isMips32(llvm::Triple::ArchType Arch) { |
| 1882 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; |
| 1883 | } |
| 1884 | |
| 1885 | static bool isMips64(llvm::Triple::ArchType Arch) { |
| 1886 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1887 | } |
| 1888 | |
| 1889 | static bool isMipsEL(llvm::Triple::ArchType Arch) { |
| 1890 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; |
| 1891 | } |
| 1892 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1893 | static bool isMips16(const ArgList &Args) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1894 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1895 | return A && A->getOption().matches(options::OPT_mips16); |
| 1896 | } |
| 1897 | |
| 1898 | static bool isMicroMips(const ArgList &Args) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1899 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1900 | return A && A->getOption().matches(options::OPT_mmicromips); |
| 1901 | } |
| 1902 | |
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1903 | namespace { |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1904 | struct DetectedMultilibs { |
| 1905 | /// The set of multilibs that the detected installation supports. |
| 1906 | MultilibSet Multilibs; |
| 1907 | |
| 1908 | /// The primary multilib appropriate for the given flags. |
| 1909 | Multilib SelectedMultilib; |
| 1910 | |
| 1911 | /// On Biarch systems, this corresponds to the default multilib when |
| 1912 | /// targeting the non-default multilib. Otherwise, it is empty. |
| 1913 | llvm::Optional<Multilib> BiarchSibling; |
| 1914 | }; |
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1915 | } // end anonymous namespace |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1916 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1917 | static Multilib makeMultilib(StringRef commonSuffix) { |
| 1918 | return Multilib(commonSuffix, commonSuffix, commonSuffix); |
| 1919 | } |
| 1920 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 1921 | static bool findMipsCsMultilibs(const Multilib::flags_list &Flags, |
| 1922 | FilterNonExistent &NonExistent, |
| 1923 | DetectedMultilibs &Result) { |
| 1924 | // Check for Code Sourcery toolchain multilibs |
| 1925 | MultilibSet CSMipsMultilibs; |
| 1926 | { |
| 1927 | auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 1928 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 1929 | auto MArchMicroMips = |
| 1930 | makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 1931 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 1932 | auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); |
| 1933 | |
| 1934 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
| 1935 | |
| 1936 | auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); |
| 1937 | |
| 1938 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
| 1939 | |
| 1940 | auto DefaultFloat = |
| 1941 | makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); |
| 1942 | |
| 1943 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
| 1944 | |
| 1945 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
| 1946 | |
| 1947 | // Note that this one's osSuffix is "" |
| 1948 | auto MAbi64 = makeMultilib("") |
| 1949 | .gccSuffix("/64") |
| 1950 | .includeSuffix("/64") |
| 1951 | .flag("+mabi=n64") |
| 1952 | .flag("-mabi=n32") |
| 1953 | .flag("-m32"); |
| 1954 | |
| 1955 | CSMipsMultilibs = |
| 1956 | MultilibSet() |
| 1957 | .Either(MArchMips16, MArchMicroMips, MArchDefault) |
| 1958 | .Maybe(UCLibc) |
| 1959 | .Either(SoftFloat, Nan2008, DefaultFloat) |
| 1960 | .FilterOut("/micromips/nan2008") |
| 1961 | .FilterOut("/mips16/nan2008") |
| 1962 | .Either(BigEndian, LittleEndian) |
| 1963 | .Maybe(MAbi64) |
| 1964 | .FilterOut("/mips16.*/64") |
| 1965 | .FilterOut("/micromips.*/64") |
| 1966 | .FilterOut(NonExistent) |
| 1967 | .setIncludeDirsCallback([](const Multilib &M) { |
| 1968 | std::vector<std::string> Dirs({"/include"}); |
| 1969 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| 1970 | Dirs.push_back( |
| 1971 | "/../../../../mips-linux-gnu/libc/uclibc/usr/include"); |
| 1972 | else |
| 1973 | Dirs.push_back("/../../../../mips-linux-gnu/libc/usr/include"); |
| 1974 | return Dirs; |
| 1975 | }); |
| 1976 | } |
| 1977 | |
| 1978 | MultilibSet DebianMipsMultilibs; |
| 1979 | { |
| 1980 | Multilib MAbiN32 = |
| 1981 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); |
| 1982 | |
| 1983 | Multilib M64 = Multilib() |
| 1984 | .gccSuffix("/64") |
| 1985 | .includeSuffix("/64") |
| 1986 | .flag("+m64") |
| 1987 | .flag("-m32") |
| 1988 | .flag("-mabi=n32"); |
| 1989 | |
| 1990 | Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); |
| 1991 | |
| 1992 | DebianMipsMultilibs = |
| 1993 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); |
| 1994 | } |
| 1995 | |
| 1996 | // Sort candidates. Toolchain that best meets the directories tree goes first. |
| 1997 | // Then select the first toolchains matches command line flags. |
| 1998 | MultilibSet *Candidates[] = {&CSMipsMultilibs, &DebianMipsMultilibs}; |
| 1999 | if (CSMipsMultilibs.size() < DebianMipsMultilibs.size()) |
| 2000 | std::iter_swap(Candidates, Candidates + 1); |
| 2001 | for (const MultilibSet *Candidate : Candidates) { |
| 2002 | if (Candidate->select(Flags, Result.SelectedMultilib)) { |
| 2003 | if (Candidate == &DebianMipsMultilibs) |
| 2004 | Result.BiarchSibling = Multilib(); |
| 2005 | Result.Multilibs = *Candidate; |
| 2006 | return true; |
| 2007 | } |
| 2008 | } |
| 2009 | return false; |
| 2010 | } |
| 2011 | |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 2012 | static bool findMipsAndroidMultilibs(vfs::FileSystem &VFS, StringRef Path, |
| 2013 | const Multilib::flags_list &Flags, |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2014 | FilterNonExistent &NonExistent, |
| 2015 | DetectedMultilibs &Result) { |
| 2016 | |
| 2017 | MultilibSet AndroidMipsMultilibs = |
| 2018 | MultilibSet() |
| 2019 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) |
| 2020 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) |
| 2021 | .FilterOut(NonExistent); |
| 2022 | |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 2023 | MultilibSet AndroidMipselMultilibs = |
| 2024 | MultilibSet() |
| 2025 | .Either(Multilib().flag("+march=mips32"), |
| 2026 | Multilib("/mips-r2", "", "/mips-r2").flag("+march=mips32r2"), |
| 2027 | Multilib("/mips-r6", "", "/mips-r6").flag("+march=mips32r6")) |
| 2028 | .FilterOut(NonExistent); |
| 2029 | |
| 2030 | MultilibSet AndroidMips64elMultilibs = |
| 2031 | MultilibSet() |
| 2032 | .Either( |
| 2033 | Multilib().flag("+march=mips64r6"), |
| 2034 | Multilib("/32/mips-r1", "", "/mips-r1").flag("+march=mips32"), |
| 2035 | Multilib("/32/mips-r2", "", "/mips-r2").flag("+march=mips32r2"), |
| 2036 | Multilib("/32/mips-r6", "", "/mips-r6").flag("+march=mips32r6")) |
| 2037 | .FilterOut(NonExistent); |
| 2038 | |
| 2039 | MultilibSet *MS = &AndroidMipsMultilibs; |
| 2040 | if (VFS.exists(Path + "/mips-r6")) |
| 2041 | MS = &AndroidMipselMultilibs; |
| 2042 | else if (VFS.exists(Path + "/32")) |
| 2043 | MS = &AndroidMips64elMultilibs; |
| 2044 | if (MS->select(Flags, Result.SelectedMultilib)) { |
| 2045 | Result.Multilibs = *MS; |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2046 | return true; |
| 2047 | } |
| 2048 | return false; |
| 2049 | } |
| 2050 | |
| 2051 | static bool findMipsMuslMultilibs(const Multilib::flags_list &Flags, |
| 2052 | FilterNonExistent &NonExistent, |
| 2053 | DetectedMultilibs &Result) { |
| 2054 | // Musl toolchain multilibs |
| 2055 | MultilibSet MuslMipsMultilibs; |
| 2056 | { |
| 2057 | auto MArchMipsR2 = makeMultilib("") |
| 2058 | .osSuffix("/mips-r2-hard-musl") |
| 2059 | .flag("+EB") |
| 2060 | .flag("-EL") |
| 2061 | .flag("+march=mips32r2"); |
| 2062 | |
| 2063 | auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl") |
| 2064 | .flag("-EB") |
| 2065 | .flag("+EL") |
| 2066 | .flag("+march=mips32r2"); |
| 2067 | |
| 2068 | MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2); |
| 2069 | |
| 2070 | // Specify the callback that computes the include directories. |
| 2071 | MuslMipsMultilibs.setIncludeDirsCallback([](const Multilib &M) { |
| 2072 | return std::vector<std::string>( |
| 2073 | {"/../sysroot" + M.osSuffix() + "/usr/include"}); |
| 2074 | }); |
| 2075 | } |
| 2076 | if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 2077 | Result.Multilibs = MuslMipsMultilibs; |
| 2078 | return true; |
| 2079 | } |
| 2080 | return false; |
| 2081 | } |
| 2082 | |
| 2083 | static bool findMipsMtiMultilibs(const Multilib::flags_list &Flags, |
| 2084 | FilterNonExistent &NonExistent, |
| 2085 | DetectedMultilibs &Result) { |
| 2086 | // CodeScape MTI toolchain v1.2 and early. |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2087 | MultilibSet MtiMipsMultilibsV1; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2088 | { |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 2089 | auto MArchMips32 = makeMultilib("/mips32") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2090 | .flag("+m32") |
| 2091 | .flag("-m64") |
| 2092 | .flag("-mmicromips") |
| 2093 | .flag("+march=mips32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2094 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 2095 | auto MArchMicroMips = makeMultilib("/micromips") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2096 | .flag("+m32") |
| 2097 | .flag("-m64") |
| 2098 | .flag("+mmicromips"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2099 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 2100 | auto MArchMips64r2 = makeMultilib("/mips64r2") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2101 | .flag("-m32") |
| 2102 | .flag("+m64") |
| 2103 | .flag("+march=mips64r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2104 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2105 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( |
| 2106 | "-march=mips64r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2107 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 2108 | auto MArchDefault = makeMultilib("") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2109 | .flag("+m32") |
| 2110 | .flag("-m64") |
| 2111 | .flag("-mmicromips") |
| 2112 | .flag("+march=mips32r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2113 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2114 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2115 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2116 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2117 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2118 | auto MAbi64 = |
| 2119 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2120 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2121 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2122 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2123 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2124 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2125 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2126 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2127 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2128 | |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2129 | MtiMipsMultilibsV1 = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2130 | MultilibSet() |
| 2131 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, |
| 2132 | MArchDefault) |
| 2133 | .Maybe(UCLibc) |
| 2134 | .Maybe(Mips16) |
| 2135 | .FilterOut("/mips64/mips16") |
| 2136 | .FilterOut("/mips64r2/mips16") |
| 2137 | .FilterOut("/micromips/mips16") |
| 2138 | .Maybe(MAbi64) |
| 2139 | .FilterOut("/micromips/64") |
| 2140 | .FilterOut("/mips32/64") |
| 2141 | .FilterOut("^/64") |
| 2142 | .FilterOut("/mips16/64") |
| 2143 | .Either(BigEndian, LittleEndian) |
| 2144 | .Maybe(SoftFloat) |
| 2145 | .Maybe(Nan2008) |
| 2146 | .FilterOut(".*sof/nan2008") |
| 2147 | .FilterOut(NonExistent) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2148 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2149 | std::vector<std::string> Dirs({"/include"}); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2150 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2151 | Dirs.push_back("/../../../../sysroot/uclibc/usr/include"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2152 | else |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2153 | Dirs.push_back("/../../../../sysroot/usr/include"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2154 | return Dirs; |
| 2155 | }); |
| Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2158 | // CodeScape IMG toolchain starting from v1.3. |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2159 | MultilibSet MtiMipsMultilibsV2; |
| 2160 | { |
| 2161 | auto BeHard = makeMultilib("/mips-r2-hard") |
| 2162 | .flag("+EB") |
| 2163 | .flag("-msoft-float") |
| 2164 | .flag("-mnan=2008") |
| 2165 | .flag("-muclibc"); |
| 2166 | auto BeSoft = makeMultilib("/mips-r2-soft") |
| 2167 | .flag("+EB") |
| 2168 | .flag("+msoft-float") |
| 2169 | .flag("-mnan=2008"); |
| 2170 | auto ElHard = makeMultilib("/mipsel-r2-hard") |
| 2171 | .flag("+EL") |
| 2172 | .flag("-msoft-float") |
| 2173 | .flag("-mnan=2008") |
| 2174 | .flag("-muclibc"); |
| 2175 | auto ElSoft = makeMultilib("/mipsel-r2-soft") |
| 2176 | .flag("+EL") |
| 2177 | .flag("+msoft-float") |
| 2178 | .flag("-mnan=2008") |
| 2179 | .flag("-mmicromips"); |
| 2180 | auto BeHardNan = makeMultilib("/mips-r2-hard-nan2008") |
| 2181 | .flag("+EB") |
| 2182 | .flag("-msoft-float") |
| 2183 | .flag("+mnan=2008") |
| 2184 | .flag("-muclibc"); |
| 2185 | auto ElHardNan = makeMultilib("/mipsel-r2-hard-nan2008") |
| 2186 | .flag("+EL") |
| 2187 | .flag("-msoft-float") |
| 2188 | .flag("+mnan=2008") |
| 2189 | .flag("-muclibc") |
| 2190 | .flag("-mmicromips"); |
| 2191 | auto BeHardNanUclibc = makeMultilib("/mips-r2-hard-nan2008-uclibc") |
| 2192 | .flag("+EB") |
| 2193 | .flag("-msoft-float") |
| 2194 | .flag("+mnan=2008") |
| 2195 | .flag("+muclibc"); |
| 2196 | auto ElHardNanUclibc = makeMultilib("/mipsel-r2-hard-nan2008-uclibc") |
| 2197 | .flag("+EL") |
| 2198 | .flag("-msoft-float") |
| 2199 | .flag("+mnan=2008") |
| 2200 | .flag("+muclibc"); |
| 2201 | auto BeHardUclibc = makeMultilib("/mips-r2-hard-uclibc") |
| 2202 | .flag("+EB") |
| 2203 | .flag("-msoft-float") |
| 2204 | .flag("-mnan=2008") |
| 2205 | .flag("+muclibc"); |
| 2206 | auto ElHardUclibc = makeMultilib("/mipsel-r2-hard-uclibc") |
| 2207 | .flag("+EL") |
| 2208 | .flag("-msoft-float") |
| 2209 | .flag("-mnan=2008") |
| 2210 | .flag("+muclibc"); |
| 2211 | auto ElMicroHardNan = makeMultilib("/micromipsel-r2-hard-nan2008") |
| 2212 | .flag("+EL") |
| 2213 | .flag("-msoft-float") |
| 2214 | .flag("+mnan=2008") |
| 2215 | .flag("+mmicromips"); |
| 2216 | auto ElMicroSoft = makeMultilib("/micromipsel-r2-soft") |
| 2217 | .flag("+EL") |
| 2218 | .flag("+msoft-float") |
| 2219 | .flag("-mnan=2008") |
| 2220 | .flag("+mmicromips"); |
| 2221 | |
| 2222 | auto O32 = |
| 2223 | makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64"); |
| 2224 | auto N32 = |
| 2225 | makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64"); |
| 2226 | auto N64 = |
| 2227 | makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64"); |
| 2228 | |
| 2229 | MtiMipsMultilibsV2 = |
| 2230 | MultilibSet() |
| 2231 | .Either({BeHard, BeSoft, ElHard, ElSoft, BeHardNan, ElHardNan, |
| 2232 | BeHardNanUclibc, ElHardNanUclibc, BeHardUclibc, |
| 2233 | ElHardUclibc, ElMicroHardNan, ElMicroSoft}) |
| 2234 | .Either(O32, N32, N64) |
| 2235 | .FilterOut(NonExistent) |
| 2236 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2237 | return std::vector<std::string>({"/../../../../sysroot" + |
| 2238 | M.includeSuffix() + |
| 2239 | "/../usr/include"}); |
| 2240 | }) |
| 2241 | .setFilePathsCallback([](const Multilib &M) { |
| 2242 | return std::vector<std::string>( |
| 2243 | {"/../../../../mips-mti-linux-gnu/lib" + M.gccSuffix()}); |
| 2244 | }); |
| 2245 | } |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2246 | for (auto Candidate : {&MtiMipsMultilibsV1, &MtiMipsMultilibsV2}) { |
| 2247 | if (Candidate->select(Flags, Result.SelectedMultilib)) { |
| 2248 | Result.Multilibs = *Candidate; |
| 2249 | return true; |
| 2250 | } |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2251 | } |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2252 | return false; |
| 2253 | } |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2254 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2255 | static bool findMipsImgMultilibs(const Multilib::flags_list &Flags, |
| 2256 | FilterNonExistent &NonExistent, |
| 2257 | DetectedMultilibs &Result) { |
| 2258 | // CodeScape IMG toolchain v1.2 and early. |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2259 | MultilibSet ImgMultilibsV1; |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2260 | { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2261 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2262 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2263 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2264 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2265 | auto MAbi64 = |
| 2266 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2267 | |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2268 | ImgMultilibsV1 = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2269 | MultilibSet() |
| 2270 | .Maybe(Mips64r6) |
| 2271 | .Maybe(MAbi64) |
| 2272 | .Maybe(LittleEndian) |
| 2273 | .FilterOut(NonExistent) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2274 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2275 | return std::vector<std::string>( |
| 2276 | {"/include", "/../../../../sysroot/usr/include"}); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2277 | }); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2280 | // CodeScape IMG toolchain starting from v1.3. |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2281 | MultilibSet ImgMultilibsV2; |
| 2282 | { |
| 2283 | auto BeHard = makeMultilib("/mips-r6-hard") |
| 2284 | .flag("+EB") |
| 2285 | .flag("-msoft-float") |
| 2286 | .flag("-mmicromips"); |
| 2287 | auto BeSoft = makeMultilib("/mips-r6-soft") |
| 2288 | .flag("+EB") |
| 2289 | .flag("+msoft-float") |
| 2290 | .flag("-mmicromips"); |
| 2291 | auto ElHard = makeMultilib("/mipsel-r6-hard") |
| 2292 | .flag("+EL") |
| 2293 | .flag("-msoft-float") |
| 2294 | .flag("-mmicromips"); |
| 2295 | auto ElSoft = makeMultilib("/mipsel-r6-soft") |
| 2296 | .flag("+EL") |
| 2297 | .flag("+msoft-float") |
| 2298 | .flag("-mmicromips"); |
| 2299 | auto BeMicroHard = makeMultilib("/micromips-r6-hard") |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2300 | .flag("+EB") |
| 2301 | .flag("-msoft-float") |
| 2302 | .flag("+mmicromips"); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2303 | auto BeMicroSoft = makeMultilib("/micromips-r6-soft") |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2304 | .flag("+EB") |
| 2305 | .flag("+msoft-float") |
| 2306 | .flag("+mmicromips"); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2307 | auto ElMicroHard = makeMultilib("/micromipsel-r6-hard") |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2308 | .flag("+EL") |
| 2309 | .flag("-msoft-float") |
| 2310 | .flag("+mmicromips"); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2311 | auto ElMicroSoft = makeMultilib("/micromipsel-r6-soft") |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2312 | .flag("+EL") |
| 2313 | .flag("+msoft-float") |
| 2314 | .flag("+mmicromips"); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2315 | |
| 2316 | auto O32 = |
| 2317 | makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64"); |
| 2318 | auto N32 = |
| 2319 | makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64"); |
| 2320 | auto N64 = |
| 2321 | makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64"); |
| 2322 | |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2323 | ImgMultilibsV2 = |
| 2324 | MultilibSet() |
| 2325 | .Either({BeHard, BeSoft, ElHard, ElSoft, BeMicroHard, BeMicroSoft, |
| 2326 | ElMicroHard, ElMicroSoft}) |
| 2327 | .Either(O32, N32, N64) |
| 2328 | .FilterOut(NonExistent) |
| 2329 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2330 | return std::vector<std::string>({"/../../../../sysroot" + |
| 2331 | M.includeSuffix() + |
| 2332 | "/../usr/include"}); |
| 2333 | }) |
| 2334 | .setFilePathsCallback([](const Multilib &M) { |
| 2335 | return std::vector<std::string>( |
| 2336 | {"/../../../../mips-img-linux-gnu/lib" + M.gccSuffix()}); |
| 2337 | }); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2338 | } |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2339 | for (auto Candidate : {&ImgMultilibsV1, &ImgMultilibsV2}) { |
| 2340 | if (Candidate->select(Flags, Result.SelectedMultilib)) { |
| 2341 | Result.Multilibs = *Candidate; |
| 2342 | return true; |
| 2343 | } |
| 2344 | } |
| 2345 | return false; |
| 2346 | } |
| 2347 | |
| 2348 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, |
| 2349 | StringRef Path, const ArgList &Args, |
| 2350 | DetectedMultilibs &Result) { |
| 2351 | FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS()); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2352 | |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2353 | StringRef CPUName; |
| 2354 | StringRef ABIName; |
| 2355 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); |
| 2356 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2357 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| 2358 | |
| 2359 | Multilib::flags_list Flags; |
| 2360 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); |
| 2361 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); |
| 2362 | addMultilibFlag(isMips16(Args), "mips16", Flags); |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2363 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2364 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || |
| Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 2365 | CPUName == "mips32r5" || CPUName == "p5600", |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2366 | "march=mips32r2", Flags); |
| Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 2367 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2368 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2369 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || |
| 2370 | CPUName == "mips64r5" || CPUName == "octeon", |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2371 | "march=mips64r2", Flags); |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 2372 | addMultilibFlag(CPUName == "mips64r6", "march=mips64r6", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2373 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); |
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2374 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); |
| Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 2375 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", |
| 2376 | Flags); |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2377 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); |
| 2378 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2379 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2380 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2381 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2382 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2383 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2384 | if (TargetTriple.isAndroid()) |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 2385 | return findMipsAndroidMultilibs(D.getVFS(), Path, Flags, NonExistent, |
| 2386 | Result); |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2387 | |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2388 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && |
| 2389 | TargetTriple.getOS() == llvm::Triple::Linux && |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2390 | TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) |
| 2391 | return findMipsMuslMultilibs(Flags, NonExistent, Result); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2392 | |
| Simon Atanasyan | 4f3fe5b | 2016-05-22 15:28:34 +0000 | [diff] [blame] | 2393 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && |
| 2394 | TargetTriple.getOS() == llvm::Triple::Linux && |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2395 | TargetTriple.getEnvironment() == llvm::Triple::GNU) |
| 2396 | return findMipsMtiMultilibs(Flags, NonExistent, Result); |
| Simon Atanasyan | 4f3fe5b | 2016-05-22 15:28:34 +0000 | [diff] [blame] | 2397 | |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2398 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && |
| 2399 | TargetTriple.getOS() == llvm::Triple::Linux && |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2400 | TargetTriple.getEnvironment() == llvm::Triple::GNU) |
| 2401 | return findMipsImgMultilibs(Flags, NonExistent, Result); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2402 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2403 | if (findMipsCsMultilibs(Flags, NonExistent, Result)) |
| 2404 | return true; |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2405 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2406 | // Fallback to the regular toolchain-tree structure. |
| 2407 | Multilib Default; |
| 2408 | Result.Multilibs.push_back(Default); |
| 2409 | Result.Multilibs.FilterOut(NonExistent); |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2410 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2411 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { |
| 2412 | Result.BiarchSibling = Multilib(); |
| 2413 | return true; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2416 | return false; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2419 | static void findAndroidArmMultilibs(const Driver &D, |
| 2420 | const llvm::Triple &TargetTriple, |
| 2421 | StringRef Path, const ArgList &Args, |
| 2422 | DetectedMultilibs &Result) { |
| 2423 | // Find multilibs with subdirectories like armv7-a, thumb, armv7-a/thumb. |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 2424 | FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS()); |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2425 | Multilib ArmV7Multilib = makeMultilib("/armv7-a") |
| 2426 | .flag("+armv7") |
| 2427 | .flag("-thumb"); |
| 2428 | Multilib ThumbMultilib = makeMultilib("/thumb") |
| 2429 | .flag("-armv7") |
| 2430 | .flag("+thumb"); |
| 2431 | Multilib ArmV7ThumbMultilib = makeMultilib("/armv7-a/thumb") |
| 2432 | .flag("+armv7") |
| 2433 | .flag("+thumb"); |
| 2434 | Multilib DefaultMultilib = makeMultilib("") |
| 2435 | .flag("-armv7") |
| 2436 | .flag("-thumb"); |
| 2437 | MultilibSet AndroidArmMultilibs = |
| 2438 | MultilibSet() |
| 2439 | .Either(ThumbMultilib, ArmV7Multilib, |
| 2440 | ArmV7ThumbMultilib, DefaultMultilib) |
| 2441 | .FilterOut(NonExistent); |
| 2442 | |
| 2443 | Multilib::flags_list Flags; |
| 2444 | llvm::StringRef Arch = Args.getLastArgValue(options::OPT_march_EQ); |
| 2445 | bool IsArmArch = TargetTriple.getArch() == llvm::Triple::arm; |
| 2446 | bool IsThumbArch = TargetTriple.getArch() == llvm::Triple::thumb; |
| 2447 | bool IsV7SubArch = TargetTriple.getSubArch() == llvm::Triple::ARMSubArch_v7; |
| 2448 | bool IsThumbMode = IsThumbArch || |
| 2449 | Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, false) || |
| 2450 | (IsArmArch && llvm::ARM::parseArchISA(Arch) == llvm::ARM::IK_THUMB); |
| 2451 | bool IsArmV7Mode = (IsArmArch || IsThumbArch) && |
| 2452 | (llvm::ARM::parseArchVersion(Arch) == 7 || |
| 2453 | (IsArmArch && Arch == "" && IsV7SubArch)); |
| 2454 | addMultilibFlag(IsArmV7Mode, "armv7", Flags); |
| 2455 | addMultilibFlag(IsThumbMode, "thumb", Flags); |
| 2456 | |
| 2457 | if (AndroidArmMultilibs.select(Flags, Result.SelectedMultilib)) |
| 2458 | Result.Multilibs = AndroidArmMultilibs; |
| 2459 | } |
| 2460 | |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2461 | static bool findBiarchMultilibs(const Driver &D, |
| 2462 | const llvm::Triple &TargetTriple, |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2463 | StringRef Path, const ArgList &Args, |
| 2464 | bool NeedsBiarchSuffix, |
| 2465 | DetectedMultilibs &Result) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2466 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs |
| 2467 | // in what would normally be GCCInstallPath and put the 64-bit |
| 2468 | // libs in a subdirectory named 64. The simple logic we follow is that |
| 2469 | // *if* there is a subdirectory of the right name with crtbegin.o in it, |
| 2470 | // we use that. If not, and if not a biarch triple alias, we look for |
| 2471 | // crtbegin.o without the subdirectory. |
| 2472 | |
| 2473 | Multilib Default; |
| 2474 | Multilib Alt64 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2475 | .gccSuffix("/64") |
| 2476 | .includeSuffix("/64") |
| 2477 | .flag("-m32") |
| 2478 | .flag("+m64") |
| 2479 | .flag("-mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2480 | Multilib Alt32 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2481 | .gccSuffix("/32") |
| 2482 | .includeSuffix("/32") |
| 2483 | .flag("+m32") |
| 2484 | .flag("-m64") |
| 2485 | .flag("-mx32"); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2486 | Multilib Altx32 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2487 | .gccSuffix("/x32") |
| 2488 | .includeSuffix("/x32") |
| 2489 | .flag("-m32") |
| 2490 | .flag("-m64") |
| 2491 | .flag("+mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2492 | |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 2493 | // GCC toolchain for IAMCU doesn't have crtbegin.o, so look for libgcc.a. |
| 2494 | FilterNonExistent NonExistent( |
| 2495 | Path, TargetTriple.isOSIAMCU() ? "/libgcc.a" : "/crtbegin.o", D.getVFS()); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2496 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2497 | // Determine default multilib from: 32, 64, x32 |
| 2498 | // Also handle cases such as 64 on 32, 32 on 64, etc. |
| 2499 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; |
| David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2500 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; |
| Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2501 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2502 | Want = WANT64; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2503 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2504 | Want = WANT64; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2505 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2506 | Want = WANT32; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2507 | else { |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2508 | if (TargetTriple.isArch32Bit()) |
| 2509 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2510 | else if (IsX32) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2511 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2512 | else |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2513 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; |
| Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2516 | if (Want == WANT32) |
| 2517 | Default.flag("+m32").flag("-m64").flag("-mx32"); |
| 2518 | else if (Want == WANT64) |
| 2519 | Default.flag("-m32").flag("+m64").flag("-mx32"); |
| 2520 | else if (Want == WANTX32) |
| 2521 | Default.flag("-m32").flag("-m64").flag("+mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2522 | else |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2523 | return false; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2524 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2525 | Result.Multilibs.push_back(Default); |
| 2526 | Result.Multilibs.push_back(Alt64); |
| 2527 | Result.Multilibs.push_back(Alt32); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2528 | Result.Multilibs.push_back(Altx32); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2529 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2530 | Result.Multilibs.FilterOut(NonExistent); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2531 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2532 | Multilib::flags_list Flags; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2533 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2534 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2535 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2536 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2537 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2538 | return false; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2539 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2540 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2541 | Result.SelectedMultilib == Altx32) |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2542 | Result.BiarchSibling = Default; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2543 | |
| 2544 | return true; |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2547 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( |
| 2548 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, |
| 2549 | const std::string &LibDir, StringRef CandidateTriple, |
| 2550 | bool NeedsBiarchSuffix) { |
| 2551 | // Solaris is a special case. The GCC installation is under |
| 2552 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we |
| 2553 | // need to iterate twice. |
| 2554 | std::error_code EC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2555 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; |
| 2556 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 2557 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2558 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| 2559 | |
| 2560 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2561 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2562 | continue; // Saw this path before; no need to look at it again. |
| 2563 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| 2564 | continue; |
| 2565 | if (CandidateVersion <= Version) |
| 2566 | continue; |
| 2567 | |
| 2568 | GCCInstallPath = |
| 2569 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2570 | if (!D.getVFS().exists(GCCInstallPath)) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2571 | continue; |
| 2572 | |
| 2573 | // If we make it here there has to be at least one GCC version, let's just |
| 2574 | // use the latest one. |
| 2575 | std::error_code EEC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2576 | for (vfs::directory_iterator |
| 2577 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), |
| 2578 | LLE; |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2579 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { |
| 2580 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2581 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2582 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); |
| 2583 | |
| 2584 | if (CandidateSubVersion > Version) |
| 2585 | Version = CandidateSubVersion; |
| 2586 | } |
| 2587 | |
| 2588 | GCCTriple.setTriple(CandidateTriple); |
| 2589 | |
| 2590 | GCCInstallPath += "/" + Version.Text; |
| 2591 | GCCParentLibPath = GCCInstallPath + "/../../../../"; |
| 2592 | |
| 2593 | IsValid = true; |
| 2594 | } |
| 2595 | } |
| 2596 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2597 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2598 | const llvm::Triple &TargetTriple, const ArgList &Args, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2599 | const std::string &LibDir, StringRef CandidateTriple, |
| 2600 | bool NeedsBiarchSuffix) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2601 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2602 | // There are various different suffixes involving the triple we |
| 2603 | // check for. We also record what is necessary to walk from each back |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2604 | // up to the lib directory. Specifically, the number of "up" steps |
| 2605 | // in the second half of each row is 1 + the number of path separators |
| 2606 | // in the first half. |
| 2607 | const std::string LibAndInstallSuffixes[][2] = { |
| 2608 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, |
| 2609 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2610 | // Debian puts cross-compilers in gcc-cross |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2611 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, |
| 2612 | |
| 2613 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), |
| 2614 | "/../../../.."}, |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2615 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2616 | // The Freescale PPC SDK has the gcc libraries in |
| 2617 | // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2618 | {"/" + CandidateTriple.str(), "/../.."}, |
| Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2619 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2620 | // Ubuntu has a strange mis-matched pair of triples that this happens to |
| 2621 | // match. |
| 2622 | // FIXME: It may be worthwhile to generalize this and look for a second |
| 2623 | // triple. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2624 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; |
| 2625 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2626 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 2627 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, |
| 2628 | NeedsBiarchSuffix); |
| 2629 | return; |
| 2630 | } |
| 2631 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2632 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2633 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - |
| 2634 | (TargetArch != llvm::Triple::x86)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2635 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2636 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; |
| Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2637 | std::error_code EC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2638 | for (vfs::directory_iterator |
| 2639 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), |
| 2640 | LE; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2641 | !EC && LI != LE; LI = LI.increment(EC)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2642 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2643 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2644 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2645 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2646 | continue; // Saw this path before; no need to look at it again. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2647 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2648 | continue; |
| 2649 | if (CandidateVersion <= Version) |
| 2650 | continue; |
| Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2651 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2652 | DetectedMultilibs Detected; |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2653 | |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2654 | // Android standalone toolchain could have multilibs for ARM and Thumb. |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2655 | // Debian mips multilibs behave more like the rest of the biarch ones, |
| 2656 | // so handle them there |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2657 | if (isArmOrThumbArch(TargetArch) && TargetTriple.isAndroid()) { |
| 2658 | // It should also work without multilibs in a simplified toolchain. |
| 2659 | findAndroidArmMultilibs(D, TargetTriple, LI->getName(), Args, Detected); |
| 2660 | } else if (isMipsArch(TargetArch)) { |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2661 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2662 | continue; |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2663 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2664 | NeedsBiarchSuffix, Detected)) { |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2665 | continue; |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2666 | } |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2667 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2668 | Multilibs = Detected.Multilibs; |
| 2669 | SelectedMultilib = Detected.SelectedMultilib; |
| 2670 | BiarchSibling = Detected.BiarchSibling; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2671 | Version = CandidateVersion; |
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2672 | GCCTriple.setTriple(CandidateTriple); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2673 | // FIXME: We hack together the directory name here instead of |
| 2674 | // using LI to ensure stable path separators across Windows and |
| 2675 | // Linux. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2676 | GCCInstallPath = |
| 2677 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); |
| 2678 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2679 | IsValid = true; |
| 2680 | } |
| 2681 | } |
| 2682 | } |
| 2683 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2684 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2685 | const ArgList &Args) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2686 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2687 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2688 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2689 | getProgramPaths().push_back(getDriver().Dir); |
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2690 | } |
| 2691 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2692 | Generic_GCC::~Generic_GCC() {} |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2693 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2694 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { |
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2695 | switch (AC) { |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2696 | case Action::PreprocessJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2697 | if (!Preprocess) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2698 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2699 | return Preprocess.get(); |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2700 | case Action::CompileJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2701 | if (!Compile) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2702 | Compile.reset(new tools::gcc::Compiler(*this)); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2703 | return Compile.get(); |
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2704 | default: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2705 | return ToolChain::getTool(AC); |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2706 | } |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2709 | Tool *Generic_GCC::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2710 | return new tools::gnutools::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2711 | } |
| 2712 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2713 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2714 | |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2715 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { |
| 2716 | // Print the information about how we detected the GCC installation. |
| 2717 | GCCInstallation.print(OS); |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2718 | CudaInstallation.print(OS); |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2721 | bool Generic_GCC::IsUnwindTablesDefault() const { |
| Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2722 | return getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2725 | bool Generic_GCC::isPICDefault() const { |
| 2726 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2727 | } |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2728 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2729 | bool Generic_GCC::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2730 | |
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2731 | bool Generic_GCC::isPICDefaultForced() const { |
| 2732 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2733 | } |
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2734 | |
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2735 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2736 | switch (getTriple().getArch()) { |
| 2737 | case llvm::Triple::x86: |
| 2738 | case llvm::Triple::x86_64: |
| 2739 | case llvm::Triple::aarch64: |
| 2740 | case llvm::Triple::aarch64_be: |
| 2741 | case llvm::Triple::arm: |
| 2742 | case llvm::Triple::armeb: |
| Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2743 | case llvm::Triple::bpfel: |
| 2744 | case llvm::Triple::bpfeb: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2745 | case llvm::Triple::thumb: |
| 2746 | case llvm::Triple::thumbeb: |
| 2747 | case llvm::Triple::ppc: |
| 2748 | case llvm::Triple::ppc64: |
| 2749 | case llvm::Triple::ppc64le: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2750 | case llvm::Triple::systemz: |
| Daniel Sanders | e160f83 | 2016-05-14 12:43:08 +0000 | [diff] [blame] | 2751 | case llvm::Triple::mips: |
| 2752 | case llvm::Triple::mipsel: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2753 | return true; |
| 2754 | default: |
| 2755 | return false; |
| 2756 | } |
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2757 | } |
| 2758 | |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2759 | /// \brief Helper to add the variant paths of a libstdc++ installation. |
| 2760 | bool Generic_GCC::addLibStdCXXIncludePaths( |
| 2761 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, |
| 2762 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, |
| 2763 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2764 | if (!getVFS().exists(Base + Suffix)) |
| 2765 | return false; |
| 2766 | |
| 2767 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); |
| 2768 | |
| 2769 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If |
| 2770 | // that path exists or we have neither a GCC nor target multiarch triple, use |
| 2771 | // this vanilla search path. |
| 2772 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || |
| 2773 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { |
| 2774 | addSystemInclude(DriverArgs, CC1Args, |
| 2775 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); |
| 2776 | } else { |
| 2777 | // Otherwise try to use multiarch naming schemes which have normalized the |
| 2778 | // triples and put the triple before the suffix. |
| 2779 | // |
| 2780 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and |
| 2781 | // the target triple, so we support that here. |
| 2782 | addSystemInclude(DriverArgs, CC1Args, |
| 2783 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); |
| 2784 | addSystemInclude(DriverArgs, CC1Args, |
| 2785 | Base + "/" + TargetMultiarchTriple + Suffix); |
| 2786 | } |
| 2787 | |
| 2788 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); |
| 2789 | return true; |
| 2790 | } |
| 2791 | |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2792 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, |
| 2793 | ArgStringList &CC1Args) const { |
| 2794 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2795 | bool UseInitArrayDefault = |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2796 | getTriple().getArch() == llvm::Triple::aarch64 || |
| Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2797 | getTriple().getArch() == llvm::Triple::aarch64_be || |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2798 | (getTriple().getOS() == llvm::Triple::Linux && |
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2799 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2800 | getTriple().getOS() == llvm::Triple::NaCl || |
| 2801 | (getTriple().getVendor() == llvm::Triple::MipsTechnologies && |
| 2802 | !getTriple().hasEnvironment()); |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2803 | |
| 2804 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2805 | options::OPT_fno_use_init_array, UseInitArrayDefault)) |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2806 | CC1Args.push_back("-fuse-init-array"); |
| 2807 | } |
| 2808 | |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2809 | /// Mips Toolchain |
| 2810 | MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D, |
| 2811 | const llvm::Triple &Triple, |
| 2812 | const ArgList &Args) |
| 2813 | : Linux(D, Triple, Args) { |
| 2814 | // Select the correct multilib according to the given arguments. |
| 2815 | DetectedMultilibs Result; |
| 2816 | findMIPSMultilibs(D, Triple, "", Args, Result); |
| 2817 | Multilibs = Result.Multilibs; |
| 2818 | SelectedMultilib = Result.SelectedMultilib; |
| 2819 | |
| 2820 | // Find out the library suffix based on the ABI. |
| 2821 | LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple); |
| 2822 | getFilePaths().clear(); |
| 2823 | getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix); |
| 2824 | |
| 2825 | // Use LLD by default. |
| Peter Collingbourne | 39719a7 | 2015-11-20 20:49:39 +0000 | [diff] [blame] | 2826 | DefaultLinker = "lld"; |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | void MipsLLVMToolChain::AddClangSystemIncludeArgs( |
| 2830 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2831 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2832 | return; |
| 2833 | |
| 2834 | const Driver &D = getDriver(); |
| 2835 | |
| 2836 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 2837 | SmallString<128> P(D.ResourceDir); |
| 2838 | llvm::sys::path::append(P, "include"); |
| 2839 | addSystemInclude(DriverArgs, CC1Args, P); |
| 2840 | } |
| 2841 | |
| 2842 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2843 | return; |
| 2844 | |
| 2845 | const auto &Callback = Multilibs.includeDirsCallback(); |
| 2846 | if (Callback) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2847 | for (const auto &Path : Callback(SelectedMultilib)) |
| 2848 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, |
| 2849 | D.getInstalledDir() + Path); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | Tool *MipsLLVMToolChain::buildLinker() const { |
| 2854 | return new tools::gnutools::Linker(*this); |
| 2855 | } |
| 2856 | |
| 2857 | std::string MipsLLVMToolChain::computeSysRoot() const { |
| 2858 | if (!getDriver().SysRoot.empty()) |
| 2859 | return getDriver().SysRoot + SelectedMultilib.osSuffix(); |
| 2860 | |
| 2861 | const std::string InstalledDir(getDriver().getInstalledDir()); |
| 2862 | std::string SysRootPath = |
| 2863 | InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix(); |
| 2864 | if (llvm::sys::fs::exists(SysRootPath)) |
| 2865 | return SysRootPath; |
| 2866 | |
| 2867 | return std::string(); |
| 2868 | } |
| 2869 | |
| 2870 | ToolChain::CXXStdlibType |
| 2871 | MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| 2872 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 2873 | if (A) { |
| 2874 | StringRef Value = A->getValue(); |
| 2875 | if (Value != "libc++") |
| 2876 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) |
| 2877 | << A->getAsString(Args); |
| 2878 | } |
| 2879 | |
| 2880 | return ToolChain::CST_Libcxx; |
| 2881 | } |
| 2882 | |
| 2883 | void MipsLLVMToolChain::AddClangCXXStdlibIncludeArgs( |
| 2884 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2885 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2886 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2887 | return; |
| 2888 | |
| 2889 | assert((GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) && |
| 2890 | "Only -lc++ (aka libcxx) is suported in this toolchain."); |
| 2891 | |
| 2892 | const auto &Callback = Multilibs.includeDirsCallback(); |
| 2893 | if (Callback) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2894 | for (std::string Path : Callback(SelectedMultilib)) { |
| 2895 | Path = getDriver().getInstalledDir() + Path + "/c++/v1"; |
| 2896 | if (llvm::sys::fs::exists(Path)) { |
| 2897 | addSystemInclude(DriverArgs, CC1Args, Path); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2898 | break; |
| 2899 | } |
| 2900 | } |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2905 | ArgStringList &CmdArgs) const { |
| 2906 | assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) && |
| 2907 | "Only -lc++ (aka libxx) is suported in this toolchain."); |
| 2908 | |
| 2909 | CmdArgs.push_back("-lc++"); |
| 2910 | CmdArgs.push_back("-lc++abi"); |
| 2911 | CmdArgs.push_back("-lunwind"); |
| 2912 | } |
| 2913 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 2914 | std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, |
| 2915 | StringRef Component, |
| 2916 | bool Shared) const { |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2917 | SmallString<128> Path(getDriver().ResourceDir); |
| 2918 | llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix, |
| 2919 | getOS()); |
| 2920 | llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" + |
| Vasileios Kalintiris | bbc9930 | 2015-11-16 15:41:30 +0000 | [diff] [blame] | 2921 | "mips" + (Shared ? ".so" : ".a"))); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2922 | return Path.str(); |
| 2923 | } |
| 2924 | |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2925 | /// Hexagon Toolchain |
| 2926 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2927 | std::string HexagonToolChain::getHexagonTargetDir( |
| 2928 | const std::string &InstalledDir, |
| 2929 | const SmallVectorImpl<std::string> &PrefixDirs) const { |
| 2930 | std::string InstallRelDir; |
| 2931 | const Driver &D = getDriver(); |
| 2932 | |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2933 | // Locate the rest of the toolchain ... |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2934 | for (auto &I : PrefixDirs) |
| 2935 | if (D.getVFS().exists(I)) |
| 2936 | return I; |
| Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 2937 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2938 | if (getVFS().exists(InstallRelDir = InstalledDir + "/../target")) |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2939 | return InstallRelDir; |
| 2940 | |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2941 | return InstallRelDir; |
| 2942 | } |
| 2943 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2944 | Optional<unsigned> HexagonToolChain::getSmallDataThreshold( |
| 2945 | const ArgList &Args) { |
| 2946 | StringRef Gn = ""; |
| 2947 | if (Arg *A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, |
| 2948 | options::OPT_msmall_data_threshold_EQ)) { |
| 2949 | Gn = A->getValue(); |
| 2950 | } else if (Args.getLastArg(options::OPT_shared, options::OPT_fpic, |
| 2951 | options::OPT_fPIC)) { |
| 2952 | Gn = "0"; |
| 2953 | } |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2954 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2955 | unsigned G; |
| 2956 | if (!Gn.getAsInteger(10, G)) |
| 2957 | return G; |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2958 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2959 | return None; |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2960 | } |
| 2961 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2962 | void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args, |
| 2963 | ToolChain::path_list &LibPaths) const { |
| 2964 | const Driver &D = getDriver(); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2965 | |
| 2966 | //---------------------------------------------------------------------------- |
| 2967 | // -L Args |
| 2968 | //---------------------------------------------------------------------------- |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 2969 | for (Arg *A : Args.filtered(options::OPT_L)) |
| 2970 | for (const char *Value : A->getValues()) |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2971 | LibPaths.push_back(Value); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2972 | |
| 2973 | //---------------------------------------------------------------------------- |
| 2974 | // Other standard paths |
| 2975 | //---------------------------------------------------------------------------- |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2976 | std::vector<std::string> RootDirs; |
| Krzysztof Parzyszek | f4467cd | 2016-01-06 14:13:11 +0000 | [diff] [blame] | 2977 | std::copy(D.PrefixDirs.begin(), D.PrefixDirs.end(), |
| 2978 | std::back_inserter(RootDirs)); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2979 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2980 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 2981 | D.PrefixDirs); |
| 2982 | if (std::find(RootDirs.begin(), RootDirs.end(), TargetDir) == RootDirs.end()) |
| 2983 | RootDirs.push_back(TargetDir); |
| 2984 | |
| 2985 | bool HasPIC = Args.hasArg(options::OPT_fpic, options::OPT_fPIC); |
| 2986 | // Assume G0 with -shared. |
| 2987 | bool HasG0 = Args.hasArg(options::OPT_shared); |
| 2988 | if (auto G = getSmallDataThreshold(Args)) |
| 2989 | HasG0 = G.getValue() == 0; |
| 2990 | |
| 2991 | const std::string CpuVer = GetTargetCPUVersion(Args).str(); |
| 2992 | for (auto &Dir : RootDirs) { |
| 2993 | std::string LibDir = Dir + "/hexagon/lib"; |
| 2994 | std::string LibDirCpu = LibDir + '/' + CpuVer; |
| 2995 | if (HasG0) { |
| 2996 | if (HasPIC) |
| 2997 | LibPaths.push_back(LibDirCpu + "/G0/pic"); |
| 2998 | LibPaths.push_back(LibDirCpu + "/G0"); |
| 2999 | } |
| 3000 | LibPaths.push_back(LibDirCpu); |
| 3001 | LibPaths.push_back(LibDir); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3002 | } |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3005 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3006 | const llvm::opt::ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3007 | : Linux(D, Triple, Args) { |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3008 | const std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 3009 | D.PrefixDirs); |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3010 | |
| 3011 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to |
| 3012 | // program paths |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3013 | const std::string BinDir(TargetDir + "/bin"); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3014 | if (D.getVFS().exists(BinDir)) |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3015 | getProgramPaths().push_back(BinDir); |
| 3016 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3017 | ToolChain::path_list &LibPaths = getFilePaths(); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3018 | |
| 3019 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets |
| 3020 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually |
| 3021 | // support 'linux' we'll need to fix this up |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3022 | LibPaths.clear(); |
| 3023 | getHexagonLibraryPaths(Args, LibPaths); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3024 | } |
| 3025 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 3026 | HexagonToolChain::~HexagonToolChain() {} |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3027 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3028 | Tool *HexagonToolChain::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3029 | return new tools::hexagon::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3030 | } |
| 3031 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3032 | Tool *HexagonToolChain::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3033 | return new tools::hexagon::Linker(*this); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3036 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3037 | ArgStringList &CC1Args) const { |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3038 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 3039 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3040 | return; |
| 3041 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3042 | const Driver &D = getDriver(); |
| 3043 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 3044 | D.PrefixDirs); |
| 3045 | addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include"); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3048 | void HexagonToolChain::AddClangCXXStdlibIncludeArgs( |
| 3049 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3050 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3051 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3052 | return; |
| 3053 | |
| 3054 | const Driver &D = getDriver(); |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3055 | std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs); |
| 3056 | addSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include/c++"); |
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 3057 | } |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 3058 | |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3059 | ToolChain::CXXStdlibType |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3060 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3061 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 3062 | if (!A) |
| 3063 | return ToolChain::CST_Libstdcxx; |
| 3064 | |
| 3065 | StringRef Value = A->getValue(); |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3066 | if (Value != "libstdc++") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3067 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3068 | |
| 3069 | return ToolChain::CST_Libstdcxx; |
| 3070 | } |
| 3071 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3072 | // |
| 3073 | // Returns the default CPU for Hexagon. This is the default compilation target |
| 3074 | // if no Hexagon processor is selected at the command-line. |
| 3075 | // |
| 3076 | const StringRef HexagonToolChain::GetDefaultCPU() { |
| 3077 | return "hexagonv60"; |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3080 | const StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) { |
| 3081 | Arg *CpuArg = nullptr; |
| Krzysztof Parzyszek | 972f72c | 2016-01-06 21:12:03 +0000 | [diff] [blame] | 3082 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ, options::OPT_march_EQ)) |
| 3083 | CpuArg = A; |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3084 | |
| 3085 | StringRef CPU = CpuArg ? CpuArg->getValue() : GetDefaultCPU(); |
| 3086 | if (CPU.startswith("hexagon")) |
| 3087 | return CPU.substr(sizeof("hexagon") - 1); |
| 3088 | return CPU; |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 3089 | } |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3090 | // End Hexagon |
| Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 3091 | |
| Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 3092 | /// AMDGPU Toolchain |
| 3093 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, |
| 3094 | const ArgList &Args) |
| 3095 | : Generic_ELF(D, Triple, Args) { } |
| 3096 | |
| 3097 | Tool *AMDGPUToolChain::buildLinker() const { |
| 3098 | return new tools::amdgpu::Linker(*this); |
| 3099 | } |
| 3100 | // End AMDGPU |
| 3101 | |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3102 | /// NaCl Toolchain |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3103 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, |
| 3104 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3105 | : Generic_ELF(D, Triple, Args) { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3106 | |
| 3107 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the |
| 3108 | // default paths, and must instead only use the paths provided |
| 3109 | // with this toolchain based on architecture. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3110 | path_list &file_paths = getFilePaths(); |
| 3111 | path_list &prog_paths = getProgramPaths(); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3112 | |
| 3113 | file_paths.clear(); |
| 3114 | prog_paths.clear(); |
| 3115 | |
| 3116 | // Path for library files (libc.a, ...) |
| 3117 | std::string FilePath(getDriver().Dir + "/../"); |
| 3118 | |
| 3119 | // Path for tools (clang, ld, etc..) |
| 3120 | std::string ProgPath(getDriver().Dir + "/../"); |
| 3121 | |
| 3122 | // Path for toolchain libraries (libgcc.a, ...) |
| 3123 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); |
| 3124 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3125 | switch (Triple.getArch()) { |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3126 | case llvm::Triple::x86: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3127 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); |
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 3128 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3129 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 3130 | file_paths.push_back(ToolPath + "i686-nacl"); |
| 3131 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3132 | case llvm::Triple::x86_64: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3133 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); |
| 3134 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); |
| 3135 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 3136 | file_paths.push_back(ToolPath + "x86_64-nacl"); |
| 3137 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3138 | case llvm::Triple::arm: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3139 | file_paths.push_back(FilePath + "arm-nacl/lib"); |
| 3140 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); |
| 3141 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); |
| 3142 | file_paths.push_back(ToolPath + "arm-nacl"); |
| 3143 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3144 | case llvm::Triple::mipsel: |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3145 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); |
| 3146 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); |
| 3147 | prog_paths.push_back(ProgPath + "bin"); |
| 3148 | file_paths.push_back(ToolPath + "mipsel-nacl"); |
| 3149 | break; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3150 | default: |
| 3151 | break; |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3154 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); |
| 3155 | } |
| 3156 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3157 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3158 | ArgStringList &CC1Args) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3159 | const Driver &D = getDriver(); |
| 3160 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 3161 | return; |
| 3162 | |
| 3163 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 3164 | SmallString<128> P(D.ResourceDir); |
| 3165 | llvm::sys::path::append(P, "include"); |
| 3166 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3167 | } |
| 3168 | |
| 3169 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3170 | return; |
| 3171 | |
| 3172 | SmallString<128> P(D.Dir + "/../"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3173 | switch (getTriple().getArch()) { |
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 3174 | case llvm::Triple::x86: |
| 3175 | // x86 is special because multilib style uses x86_64-nacl/include for libc |
| 3176 | // headers but the SDK wants i686-nacl/usr/include. The other architectures |
| 3177 | // have the same substring. |
| 3178 | llvm::sys::path::append(P, "i686-nacl/usr/include"); |
| 3179 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3180 | llvm::sys::path::remove_filename(P); |
| 3181 | llvm::sys::path::remove_filename(P); |
| 3182 | llvm::sys::path::remove_filename(P); |
| 3183 | llvm::sys::path::append(P, "x86_64-nacl/include"); |
| 3184 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3185 | return; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3186 | case llvm::Triple::arm: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3187 | llvm::sys::path::append(P, "arm-nacl/usr/include"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3188 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3189 | case llvm::Triple::x86_64: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3190 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3191 | break; |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3192 | case llvm::Triple::mipsel: |
| 3193 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); |
| 3194 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3195 | default: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3196 | return; |
| 3197 | } |
| 3198 | |
| 3199 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3200 | llvm::sys::path::remove_filename(P); |
| 3201 | llvm::sys::path::remove_filename(P); |
| 3202 | llvm::sys::path::append(P, "include"); |
| 3203 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3204 | } |
| 3205 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3206 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3207 | ArgStringList &CmdArgs) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3208 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 3209 | // if the value is libc++, and emits an error for other values. |
| 3210 | GetCXXStdlibType(Args); |
| 3211 | CmdArgs.push_back("-lc++"); |
| 3212 | } |
| 3213 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3214 | void NaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3215 | ArgStringList &CC1Args) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3216 | const Driver &D = getDriver(); |
| 3217 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3218 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3219 | return; |
| 3220 | |
| 3221 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 3222 | // if the value is libc++, and emits an error for other values. |
| 3223 | GetCXXStdlibType(DriverArgs); |
| 3224 | |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3225 | SmallString<128> P(D.Dir + "/../"); |
| 3226 | switch (getTriple().getArch()) { |
| 3227 | case llvm::Triple::arm: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3228 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); |
| 3229 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3230 | break; |
| 3231 | case llvm::Triple::x86: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3232 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 3233 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3234 | break; |
| 3235 | case llvm::Triple::x86_64: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3236 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 3237 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3238 | break; |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3239 | case llvm::Triple::mipsel: |
| 3240 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); |
| 3241 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3242 | break; |
| Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 3243 | default: |
| 3244 | break; |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3245 | } |
| 3246 | } |
| 3247 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3248 | ToolChain::CXXStdlibType |
| 3249 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3250 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 3251 | StringRef Value = A->getValue(); |
| 3252 | if (Value == "libc++") |
| 3253 | return ToolChain::CST_Libcxx; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3254 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | return ToolChain::CST_Libcxx; |
| 3258 | } |
| 3259 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3260 | std::string |
| 3261 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, |
| 3262 | types::ID InputType) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3263 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); |
| 3264 | if (TheTriple.getArch() == llvm::Triple::arm && |
| 3265 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) |
| 3266 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); |
| 3267 | return TheTriple.getTriple(); |
| 3268 | } |
| 3269 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3270 | Tool *NaClToolChain::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3271 | return new tools::nacltools::Linker(*this); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3274 | Tool *NaClToolChain::buildAssembler() const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3275 | if (getTriple().getArch() == llvm::Triple::arm) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3276 | return new tools::nacltools::AssemblerARM(*this); |
| 3277 | return new tools::gnutools::Assembler(*this); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3278 | } |
| 3279 | // End NaCl |
| 3280 | |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3281 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 3282 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 3283 | /// Currently does not support anything else but compilation. |
| 3284 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3285 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 3286 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3287 | : ToolChain(D, Triple, Args) { |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3288 | // Path mangling to find libexec |
| 3289 | std::string Path(getDriver().Dir); |
| 3290 | |
| 3291 | Path += "/../libexec"; |
| 3292 | getProgramPaths().push_back(Path); |
| 3293 | } |
| 3294 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 3295 | TCEToolChain::~TCEToolChain() {} |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3296 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3297 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3298 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3299 | bool TCEToolChain::isPICDefault() const { return false; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3300 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3301 | bool TCEToolChain::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 3302 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3303 | bool TCEToolChain::isPICDefaultForced() const { return false; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3304 | |
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3305 | // CloudABI - CloudABI tool chain which can call ld(1) directly. |
| 3306 | |
| 3307 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, |
| 3308 | const ArgList &Args) |
| 3309 | : Generic_ELF(D, Triple, Args) { |
| 3310 | SmallString<128> P(getDriver().Dir); |
| 3311 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); |
| 3312 | getFilePaths().push_back(P.str()); |
| 3313 | } |
| 3314 | |
| 3315 | void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3316 | ArgStringList &CC1Args) const { |
| 3317 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) && |
| 3318 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3319 | return; |
| 3320 | |
| 3321 | SmallString<128> P(getDriver().Dir); |
| 3322 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); |
| 3323 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3324 | } |
| 3325 | |
| 3326 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3327 | ArgStringList &CmdArgs) const { |
| 3328 | CmdArgs.push_back("-lc++"); |
| 3329 | CmdArgs.push_back("-lc++abi"); |
| 3330 | CmdArgs.push_back("-lunwind"); |
| 3331 | } |
| 3332 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3333 | Tool *CloudABI::buildLinker() const { |
| 3334 | return new tools::cloudabi::Linker(*this); |
| 3335 | } |
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3336 | |
| Ed Schouten | 51bfbe7 | 2016-02-17 18:56:20 +0000 | [diff] [blame] | 3337 | SanitizerMask CloudABI::getSupportedSanitizers() const { |
| 3338 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 3339 | Res |= SanitizerKind::SafeStack; |
| 3340 | return Res; |
| 3341 | } |
| 3342 | |
| Ed Schouten | fc79d2c | 2016-03-29 21:13:53 +0000 | [diff] [blame] | 3343 | SanitizerMask CloudABI::getDefaultSanitizers() const { |
| 3344 | return SanitizerKind::SafeStack; |
| 3345 | } |
| 3346 | |
| Reid Kleckner | 330fb17 | 2016-05-11 16:19:05 +0000 | [diff] [blame] | 3347 | /// Haiku - Haiku tool chain which can call as(1) and ld(1) directly. |
| 3348 | |
| 3349 | Haiku::Haiku(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 3350 | : Generic_ELF(D, Triple, Args) { |
| 3351 | |
| 3352 | } |
| 3353 | |
| 3354 | void Haiku::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3355 | ArgStringList &CC1Args) const { |
| 3356 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3357 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3358 | return; |
| 3359 | |
| 3360 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3361 | case ToolChain::CST_Libcxx: |
| 3362 | addSystemInclude(DriverArgs, CC1Args, |
| 3363 | getDriver().SysRoot + "/system/develop/headers/c++/v1"); |
| 3364 | break; |
| 3365 | case ToolChain::CST_Libstdcxx: |
| 3366 | addSystemInclude(DriverArgs, CC1Args, |
| 3367 | getDriver().SysRoot + "/system/develop/headers/c++"); |
| 3368 | addSystemInclude(DriverArgs, CC1Args, |
| 3369 | getDriver().SysRoot + "/system/develop/headers/c++/backward"); |
| 3370 | |
| 3371 | StringRef Triple = getTriple().str(); |
| 3372 | addSystemInclude(DriverArgs, CC1Args, |
| 3373 | getDriver().SysRoot + "/system/develop/headers/c++/" + |
| 3374 | Triple); |
| 3375 | break; |
| 3376 | } |
| 3377 | } |
| 3378 | |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3379 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 3380 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3381 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, |
| 3382 | const ArgList &Args) |
| 3383 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3384 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3385 | getFilePaths().push_back("/usr/lib"); |
| 3386 | } |
| 3387 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3388 | Tool *OpenBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3389 | return new tools::openbsd::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3390 | } |
| 3391 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3392 | Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3393 | |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3394 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. |
| 3395 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3396 | Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3397 | : Generic_ELF(D, Triple, Args) { |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3398 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3399 | getFilePaths().push_back("/usr/lib"); |
| 3400 | } |
| 3401 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3402 | Tool *Bitrig::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3403 | return new tools::bitrig::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3404 | } |
| 3405 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3406 | Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3407 | |
| Jonas Hahnfeld | aae8374 | 2016-02-12 07:48:37 +0000 | [diff] [blame] | 3408 | ToolChain::CXXStdlibType Bitrig::GetDefaultCXXStdlibType() const { |
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3409 | return ToolChain::CST_Libcxx; |
| 3410 | } |
| 3411 | |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3412 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3413 | ArgStringList &CC1Args) const { |
| 3414 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3415 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3416 | return; |
| 3417 | |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3418 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3419 | case ToolChain::CST_Libcxx: |
| 3420 | addSystemInclude(DriverArgs, CC1Args, |
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3421 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3422 | break; |
| 3423 | case ToolChain::CST_Libstdcxx: |
| 3424 | addSystemInclude(DriverArgs, CC1Args, |
| 3425 | getDriver().SysRoot + "/usr/include/c++/stdc++"); |
| 3426 | addSystemInclude(DriverArgs, CC1Args, |
| 3427 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3428 | |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3429 | StringRef Triple = getTriple().str(); |
| 3430 | if (Triple.startswith("amd64")) |
| 3431 | addSystemInclude(DriverArgs, CC1Args, |
| 3432 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3433 | Triple.substr(5)); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3434 | else |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3435 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + |
| 3436 | "/usr/include/c++/stdc++/" + |
| 3437 | Triple); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3438 | break; |
| 3439 | } |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3443 | ArgStringList &CmdArgs) const { |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3444 | switch (GetCXXStdlibType(Args)) { |
| 3445 | case ToolChain::CST_Libcxx: |
| 3446 | CmdArgs.push_back("-lc++"); |
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3447 | CmdArgs.push_back("-lc++abi"); |
| 3448 | CmdArgs.push_back("-lpthread"); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3449 | break; |
| 3450 | case ToolChain::CST_Libstdcxx: |
| 3451 | CmdArgs.push_back("-lstdc++"); |
| 3452 | break; |
| 3453 | } |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3454 | } |
| 3455 | |
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3456 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 3457 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3458 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, |
| 3459 | const ArgList &Args) |
| 3460 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 3461 | |
| Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 3462 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall |
| 3463 | // back to '/usr/lib' if it doesn't exist. |
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3464 | if ((Triple.getArch() == llvm::Triple::x86 || |
| 3465 | Triple.getArch() == llvm::Triple::ppc) && |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3466 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) |
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3467 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); |
| 3468 | else |
| 3469 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3472 | ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3473 | if (getTriple().getOSMajorVersion() >= 10) |
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3474 | return ToolChain::CST_Libcxx; |
| 3475 | return ToolChain::CST_Libstdcxx; |
| 3476 | } |
| 3477 | |
| 3478 | void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3479 | ArgStringList &CC1Args) const { |
| 3480 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3481 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3482 | return; |
| 3483 | |
| 3484 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3485 | case ToolChain::CST_Libcxx: |
| 3486 | addSystemInclude(DriverArgs, CC1Args, |
| 3487 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| 3488 | break; |
| 3489 | case ToolChain::CST_Libstdcxx: |
| 3490 | addSystemInclude(DriverArgs, CC1Args, |
| 3491 | getDriver().SysRoot + "/usr/include/c++/4.2"); |
| 3492 | addSystemInclude(DriverArgs, CC1Args, |
| 3493 | getDriver().SysRoot + "/usr/include/c++/4.2/backward"); |
| 3494 | break; |
| 3495 | } |
| 3496 | } |
| 3497 | |
| Dimitry Andric | 6090739 | 2016-02-14 16:08:20 +0000 | [diff] [blame] | 3498 | void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3499 | ArgStringList &CmdArgs) const { |
| 3500 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 3501 | bool Profiling = Args.hasArg(options::OPT_pg); |
| 3502 | |
| 3503 | switch (Type) { |
| 3504 | case ToolChain::CST_Libcxx: |
| 3505 | CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++"); |
| 3506 | break; |
| 3507 | |
| 3508 | case ToolChain::CST_Libstdcxx: |
| 3509 | CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++"); |
| 3510 | break; |
| 3511 | } |
| 3512 | } |
| 3513 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3514 | Tool *FreeBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3515 | return new tools::freebsd::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3518 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3519 | |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 3520 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { |
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3521 | // FreeBSD uses SjLj exceptions on ARM oabi. |
| 3522 | switch (getTriple().getEnvironment()) { |
| Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 3523 | case llvm::Triple::GNUEABIHF: |
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3524 | case llvm::Triple::GNUEABI: |
| 3525 | case llvm::Triple::EABI: |
| 3526 | return false; |
| 3527 | |
| 3528 | default: |
| 3529 | return (getTriple().getArch() == llvm::Triple::arm || |
| 3530 | getTriple().getArch() == llvm::Triple::thumb); |
| 3531 | } |
| 3532 | } |
| 3533 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3534 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } |
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3535 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3536 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3537 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3538 | SanitizerMask FreeBSD::getSupportedSanitizers() const { |
| 3539 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 3540 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 3541 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 3542 | getTriple().getArch() == llvm::Triple::mips64el; |
| 3543 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 3544 | Res |= SanitizerKind::Address; |
| 3545 | Res |= SanitizerKind::Vptr; |
| 3546 | if (IsX86_64 || IsMIPS64) { |
| 3547 | Res |= SanitizerKind::Leak; |
| 3548 | Res |= SanitizerKind::Thread; |
| 3549 | } |
| 3550 | if (IsX86 || IsX86_64) { |
| 3551 | Res |= SanitizerKind::SafeStack; |
| 3552 | } |
| 3553 | return Res; |
| 3554 | } |
| 3555 | |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3556 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 3557 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3558 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3559 | : Generic_ELF(D, Triple, Args) { |
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3560 | if (getDriver().UseStdLib) { |
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3561 | // When targeting a 32-bit platform, try the special directory used on |
| 3562 | // 64-bit hosts, and only fall back to the main library directory if that |
| 3563 | // doesn't work. |
| 3564 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure |
| 3565 | // what all logic is needed to emulate the '=' prefix here. |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3566 | switch (Triple.getArch()) { |
| 3567 | case llvm::Triple::x86: |
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3568 | getFilePaths().push_back("=/usr/lib/i386"); |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3569 | break; |
| 3570 | case llvm::Triple::arm: |
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3571 | case llvm::Triple::armeb: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3572 | case llvm::Triple::thumb: |
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3573 | case llvm::Triple::thumbeb: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3574 | switch (Triple.getEnvironment()) { |
| 3575 | case llvm::Triple::EABI: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3576 | case llvm::Triple::GNUEABI: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3577 | getFilePaths().push_back("=/usr/lib/eabi"); |
| 3578 | break; |
| Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3579 | case llvm::Triple::EABIHF: |
| 3580 | case llvm::Triple::GNUEABIHF: |
| 3581 | getFilePaths().push_back("=/usr/lib/eabihf"); |
| 3582 | break; |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3583 | default: |
| 3584 | getFilePaths().push_back("=/usr/lib/oabi"); |
| 3585 | break; |
| 3586 | } |
| 3587 | break; |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3588 | case llvm::Triple::mips64: |
| 3589 | case llvm::Triple::mips64el: |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3590 | if (tools::mips::hasMipsAbiArg(Args, "o32")) |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3591 | getFilePaths().push_back("=/usr/lib/o32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3592 | else if (tools::mips::hasMipsAbiArg(Args, "64")) |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3593 | getFilePaths().push_back("=/usr/lib/64"); |
| 3594 | break; |
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3595 | case llvm::Triple::ppc: |
| 3596 | getFilePaths().push_back("=/usr/lib/powerpc"); |
| 3597 | break; |
| Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3598 | case llvm::Triple::sparc: |
| 3599 | getFilePaths().push_back("=/usr/lib/sparc"); |
| 3600 | break; |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3601 | default: |
| 3602 | break; |
| 3603 | } |
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3604 | |
| 3605 | getFilePaths().push_back("=/usr/lib"); |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3606 | } |
| 3607 | } |
| 3608 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3609 | Tool *NetBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3610 | return new tools::netbsd::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3613 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3614 | |
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3615 | ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const { |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3616 | unsigned Major, Minor, Micro; |
| 3617 | getTriple().getOSVersion(Major, Minor, Micro); |
| Joerg Sonnenberger | 21156e8 | 2016-02-11 23:35:03 +0000 | [diff] [blame] | 3618 | if (Major >= 7 || Major == 0) { |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3619 | switch (getArch()) { |
| Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3620 | case llvm::Triple::aarch64: |
| Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3621 | case llvm::Triple::arm: |
| 3622 | case llvm::Triple::armeb: |
| 3623 | case llvm::Triple::thumb: |
| 3624 | case llvm::Triple::thumbeb: |
| Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3625 | case llvm::Triple::ppc: |
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3626 | case llvm::Triple::ppc64: |
| 3627 | case llvm::Triple::ppc64le: |
| Joerg Sonnenberger | 059613c | 2016-02-11 23:18:36 +0000 | [diff] [blame] | 3628 | case llvm::Triple::sparc: |
| 3629 | case llvm::Triple::sparcv9: |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3630 | case llvm::Triple::x86: |
| 3631 | case llvm::Triple::x86_64: |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3632 | return ToolChain::CST_Libcxx; |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3633 | default: |
| 3634 | break; |
| 3635 | } |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3636 | } |
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3637 | return ToolChain::CST_Libstdcxx; |
| 3638 | } |
| 3639 | |
| 3640 | void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3641 | ArgStringList &CC1Args) const { |
| 3642 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3643 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3644 | return; |
| 3645 | |
| 3646 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3647 | case ToolChain::CST_Libcxx: |
| 3648 | addSystemInclude(DriverArgs, CC1Args, |
| 3649 | getDriver().SysRoot + "/usr/include/c++/"); |
| 3650 | break; |
| 3651 | case ToolChain::CST_Libstdcxx: |
| 3652 | addSystemInclude(DriverArgs, CC1Args, |
| 3653 | getDriver().SysRoot + "/usr/include/g++"); |
| 3654 | addSystemInclude(DriverArgs, CC1Args, |
| 3655 | getDriver().SysRoot + "/usr/include/g++/backward"); |
| 3656 | break; |
| 3657 | } |
| 3658 | } |
| 3659 | |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3660 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 3661 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3662 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3663 | : Generic_ELF(D, Triple, Args) { |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3664 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3665 | getFilePaths().push_back("/usr/lib"); |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3666 | } |
| 3667 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3668 | Tool *Minix::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3669 | return new tools::minix::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3670 | } |
| 3671 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3672 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3673 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3674 | static void addPathIfExists(const Driver &D, const Twine &Path, |
| 3675 | ToolChain::path_list &Paths) { |
| 3676 | if (D.getVFS().exists(Path)) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3677 | Paths.push_back(Path.str()); |
| 3678 | } |
| 3679 | |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3680 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. |
| 3681 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3682 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3683 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3684 | : Generic_GCC(D, Triple, Args) { |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3685 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3686 | GCCInstallation.init(Triple, Args); |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3687 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3688 | path_list &Paths = getFilePaths(); |
| 3689 | if (GCCInstallation.isValid()) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3690 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3691 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3692 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3693 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3694 | addPathIfExists(D, getDriver().Dir, Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3695 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3696 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3697 | |
| 3698 | std::string LibPath = "/usr/lib/"; |
| 3699 | switch (Triple.getArch()) { |
| 3700 | case llvm::Triple::x86: |
| 3701 | case llvm::Triple::sparc: |
| 3702 | break; |
| 3703 | case llvm::Triple::x86_64: |
| 3704 | LibPath += "amd64/"; |
| 3705 | break; |
| 3706 | case llvm::Triple::sparcv9: |
| 3707 | LibPath += "sparcv9/"; |
| 3708 | break; |
| 3709 | default: |
| 3710 | llvm_unreachable("Unsupported architecture"); |
| 3711 | } |
| 3712 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3713 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3714 | } |
| 3715 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3716 | Tool *Solaris::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3717 | return new tools::solaris::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3718 | } |
| 3719 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3720 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } |
| Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3721 | |
| Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3722 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3723 | ArgStringList &CC1Args) const { |
| 3724 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3725 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3726 | return; |
| 3727 | |
| 3728 | // Include the support directory for things like xlocale and fudged system |
| 3729 | // headers. |
| 3730 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); |
| 3731 | |
| 3732 | if (GCCInstallation.isValid()) { |
| 3733 | GCCVersion Version = GCCInstallation.getVersion(); |
| 3734 | addSystemInclude(DriverArgs, CC1Args, |
| 3735 | getDriver().SysRoot + "/usr/gcc/" + |
| 3736 | Version.MajorStr + "." + |
| 3737 | Version.MinorStr + |
| 3738 | "/include/c++/" + Version.Text); |
| 3739 | addSystemInclude(DriverArgs, CC1Args, |
| 3740 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + |
| 3741 | "." + Version.MinorStr + "/include/c++/" + |
| 3742 | Version.Text + "/" + |
| 3743 | GCCInstallation.getTriple().str()); |
| 3744 | } |
| 3745 | } |
| 3746 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3747 | /// Distribution (very bare-bones at the moment). |
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3748 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3749 | enum Distro { |
| Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3750 | // NB: Releases of a particular Linux distro should be kept together |
| 3751 | // in this enum, because some tests are done by integer comparison against |
| 3752 | // the first and last known member in the family, e.g. IsRedHat(). |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3753 | ArchLinux, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3754 | DebianLenny, |
| 3755 | DebianSqueeze, |
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3756 | DebianWheezy, |
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3757 | DebianJessie, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3758 | DebianStretch, |
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3759 | Exherbo, |
| Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3760 | RHEL5, |
| 3761 | RHEL6, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3762 | RHEL7, |
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3763 | Fedora, |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3764 | OpenSUSE, |
| Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3765 | UbuntuHardy, |
| 3766 | UbuntuIntrepid, |
| Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3767 | UbuntuJaunty, |
| Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3768 | UbuntuKarmic, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3769 | UbuntuLucid, |
| 3770 | UbuntuMaverick, |
| Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3771 | UbuntuNatty, |
| Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3772 | UbuntuOneiric, |
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3773 | UbuntuPrecise, |
| Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3774 | UbuntuQuantal, |
| 3775 | UbuntuRaring, |
| Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3776 | UbuntuSaucy, |
| Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3777 | UbuntuTrusty, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3778 | UbuntuUtopic, |
| 3779 | UbuntuVivid, |
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3780 | UbuntuWily, |
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3781 | UbuntuXenial, |
| Sylvestre Ledru | d3078e7 | 2016-07-19 14:00:57 +0000 | [diff] [blame] | 3782 | UbuntuYakkety, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3783 | UnknownDistro |
| 3784 | }; |
| 3785 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3786 | static bool IsRedhat(enum Distro Distro) { |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3787 | return Distro == Fedora || (Distro >= RHEL5 && Distro <= RHEL7); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3790 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3791 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3792 | static bool IsDebian(enum Distro Distro) { |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3793 | return Distro >= DebianLenny && Distro <= DebianStretch; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3794 | } |
| 3795 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3796 | static bool IsUbuntu(enum Distro Distro) { |
| Sylvestre Ledru | d3078e7 | 2016-07-19 14:00:57 +0000 | [diff] [blame] | 3797 | return Distro >= UbuntuHardy && Distro <= UbuntuYakkety; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3800 | static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3801 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = |
| 3802 | llvm::MemoryBuffer::getFile("/etc/lsb-release"); |
| 3803 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3804 | StringRef Data = File.get()->getBuffer(); |
| Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3805 | SmallVector<StringRef, 16> Lines; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3806 | Data.split(Lines, "\n"); |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3807 | Distro Version = UnknownDistro; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3808 | for (StringRef Line : Lines) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3809 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) |
| 3810 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) |
| 3811 | .Case("hardy", UbuntuHardy) |
| 3812 | .Case("intrepid", UbuntuIntrepid) |
| 3813 | .Case("jaunty", UbuntuJaunty) |
| 3814 | .Case("karmic", UbuntuKarmic) |
| 3815 | .Case("lucid", UbuntuLucid) |
| 3816 | .Case("maverick", UbuntuMaverick) |
| 3817 | .Case("natty", UbuntuNatty) |
| 3818 | .Case("oneiric", UbuntuOneiric) |
| 3819 | .Case("precise", UbuntuPrecise) |
| 3820 | .Case("quantal", UbuntuQuantal) |
| 3821 | .Case("raring", UbuntuRaring) |
| 3822 | .Case("saucy", UbuntuSaucy) |
| 3823 | .Case("trusty", UbuntuTrusty) |
| 3824 | .Case("utopic", UbuntuUtopic) |
| 3825 | .Case("vivid", UbuntuVivid) |
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3826 | .Case("wily", UbuntuWily) |
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3827 | .Case("xenial", UbuntuXenial) |
| Sylvestre Ledru | d3078e7 | 2016-07-19 14:00:57 +0000 | [diff] [blame] | 3828 | .Case("yakkety", UbuntuYakkety) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3829 | .Default(UnknownDistro); |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3830 | if (Version != UnknownDistro) |
| 3831 | return Version; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3834 | File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); |
| 3835 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3836 | StringRef Data = File.get()->getBuffer(); |
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3837 | if (Data.startswith("Fedora release")) |
| 3838 | return Fedora; |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3839 | if (Data.startswith("Red Hat Enterprise Linux") || |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3840 | Data.startswith("CentOS") || |
| 3841 | Data.startswith("Scientific Linux")) { |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3842 | if (Data.find("release 7") != StringRef::npos) |
| 3843 | return RHEL7; |
| 3844 | else if (Data.find("release 6") != StringRef::npos) |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3845 | return RHEL6; |
| 3846 | else if (Data.find("release 5") != StringRef::npos) |
| 3847 | return RHEL5; |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3848 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3849 | return UnknownDistro; |
| 3850 | } |
| 3851 | |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3852 | File = llvm::MemoryBuffer::getFile("/etc/debian_version"); |
| 3853 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3854 | StringRef Data = File.get()->getBuffer(); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3855 | if (Data[0] == '5') |
| 3856 | return DebianLenny; |
| Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 3857 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3858 | return DebianSqueeze; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3859 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') |
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3860 | return DebianWheezy; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3861 | else if (Data.startswith("jessie/sid") || Data[0] == '8') |
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3862 | return DebianJessie; |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3863 | else if (Data.startswith("stretch/sid") || Data[0] == '9') |
| 3864 | return DebianStretch; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3865 | return UnknownDistro; |
| 3866 | } |
| 3867 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3868 | if (D.getVFS().exists("/etc/SuSE-release")) |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3869 | return OpenSUSE; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3870 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3871 | if (D.getVFS().exists("/etc/exherbo-release")) |
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3872 | return Exherbo; |
| 3873 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3874 | if (D.getVFS().exists("/etc/arch-release")) |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3875 | return ArchLinux; |
| 3876 | |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3877 | return UnknownDistro; |
| 3878 | } |
| 3879 | |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3880 | /// \brief Get our best guess at the multiarch triple for a target. |
| 3881 | /// |
| 3882 | /// Debian-based systems are starting to use a multiarch setup where they use |
| 3883 | /// a target-triple directory in the library and header search paths. |
| 3884 | /// Unfortunately, this triple does not align with the vanilla target triple, |
| 3885 | /// so we provide a rough mapping here. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3886 | static std::string getMultiarchTriple(const Driver &D, |
| 3887 | const llvm::Triple &TargetTriple, |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3888 | StringRef SysRoot) { |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 3889 | llvm::Triple::EnvironmentType TargetEnvironment = |
| 3890 | TargetTriple.getEnvironment(); |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3891 | |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3892 | // For most architectures, just use whatever we have rather than trying to be |
| 3893 | // clever. |
| 3894 | switch (TargetTriple.getArch()) { |
| 3895 | default: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3896 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3897 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3898 | // We use the existence of '/lib/<triple>' as a directory to detect some |
| 3899 | // common linux triples that don't quite match the Clang triple for both |
| 3900 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
| 3901 | // regardless of what the actual target triple is. |
| Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 3902 | case llvm::Triple::arm: |
| 3903 | case llvm::Triple::thumb: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3904 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3905 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3906 | return "arm-linux-gnueabihf"; |
| 3907 | } else { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3908 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3909 | return "arm-linux-gnueabi"; |
| 3910 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3911 | break; |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3912 | case llvm::Triple::armeb: |
| 3913 | case llvm::Triple::thumbeb: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3914 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3915 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3916 | return "armeb-linux-gnueabihf"; |
| 3917 | } else { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3918 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3919 | return "armeb-linux-gnueabi"; |
| 3920 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3921 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3922 | case llvm::Triple::x86: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3923 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3924 | return "i386-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3925 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3926 | case llvm::Triple::x86_64: |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3927 | // We don't want this for x32, otherwise it will match x86_64 libs |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3928 | if (TargetEnvironment != llvm::Triple::GNUX32 && |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3929 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3930 | return "x86_64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3931 | break; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3932 | case llvm::Triple::aarch64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3933 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3934 | return "aarch64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3935 | break; |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3936 | case llvm::Triple::aarch64_be: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3937 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3938 | return "aarch64_be-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3939 | break; |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3940 | case llvm::Triple::mips: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3941 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3942 | return "mips-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3943 | break; |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3944 | case llvm::Triple::mipsel: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3945 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3946 | return "mipsel-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3947 | break; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3948 | case llvm::Triple::mips64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3949 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3950 | return "mips64-linux-gnu"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3951 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3952 | return "mips64-linux-gnuabi64"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3953 | break; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3954 | case llvm::Triple::mips64el: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3955 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3956 | return "mips64el-linux-gnu"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3957 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3958 | return "mips64el-linux-gnuabi64"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3959 | break; |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3960 | case llvm::Triple::ppc: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3961 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) |
| Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 3962 | return "powerpc-linux-gnuspe"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3963 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3964 | return "powerpc-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3965 | break; |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3966 | case llvm::Triple::ppc64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3967 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3968 | return "powerpc64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3969 | break; |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3970 | case llvm::Triple::ppc64le: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3971 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3972 | return "powerpc64le-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3973 | break; |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3974 | case llvm::Triple::sparc: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3975 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3976 | return "sparc-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3977 | break; |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3978 | case llvm::Triple::sparcv9: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3979 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3980 | return "sparc64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3981 | break; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3982 | case llvm::Triple::systemz: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3983 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3984 | return "s390x-linux-gnu"; |
| 3985 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3986 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3987 | return TargetTriple.str(); |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3988 | } |
| 3989 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3990 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3991 | if (isMipsArch(Triple.getArch())) { |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 3992 | if (Triple.isAndroid()) { |
| 3993 | StringRef CPUName; |
| 3994 | StringRef ABIName; |
| 3995 | tools::mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName); |
| 3996 | if (CPUName == "mips32r6") |
| 3997 | return "libr6"; |
| 3998 | if (CPUName == "mips32r2") |
| 3999 | return "libr2"; |
| 4000 | } |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4001 | // lib32 directory has a special meaning on MIPS targets. |
| 4002 | // It contains N32 ABI binaries. Use this folder if produce |
| 4003 | // code for N32 ABI only. |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4004 | if (tools::mips::hasMipsAbiArg(Args, "n32")) |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4005 | return "lib32"; |
| 4006 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 4007 | } |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 4008 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4009 | // It happens that only x86 and PPC use the 'lib32' variant of oslibdir, and |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4010 | // using that variant while targeting other architectures causes problems |
| 4011 | // because the libraries are laid out in shared system roots that can't cope |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4012 | // with a 'lib32' library search path being considered. So we only enable |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4013 | // them when we know we may need it. |
| 4014 | // |
| 4015 | // FIXME: This is a bit of a hack. We should really unify this code for |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4016 | // reasoning about oslibdir spellings with the lib dir spellings in the |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4017 | // GCCInstallationDetector, but that is a more significant refactoring. |
| 4018 | if (Triple.getArch() == llvm::Triple::x86 || |
| 4019 | Triple.getArch() == llvm::Triple::ppc) |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 4020 | return "lib32"; |
| 4021 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 4022 | if (Triple.getArch() == llvm::Triple::x86_64 && |
| 4023 | Triple.getEnvironment() == llvm::Triple::GNUX32) |
| 4024 | return "libx32"; |
| 4025 | |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 4026 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 4027 | } |
| 4028 | |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 4029 | static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, |
| 4030 | const Multilib &Multilib, |
| 4031 | StringRef InstallPath, |
| 4032 | ToolChain::path_list &Paths) { |
| 4033 | if (const auto &PathsCallback = Multilibs.filePathsCallback()) |
| 4034 | for (const auto &Path : PathsCallback(Multilib)) |
| 4035 | addPathIfExists(D, InstallPath + Path, Paths); |
| 4036 | } |
| 4037 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 4038 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4039 | : Generic_ELF(D, Triple, Args) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4040 | GCCInstallation.init(Triple, Args); |
| 4041 | CudaInstallation.init(Triple, Args); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4042 | Multilibs = GCCInstallation.getMultilibs(); |
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 4043 | llvm::Triple::ArchType Arch = Triple.getArch(); |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 4044 | std::string SysRoot = computeSysRoot(); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4045 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4046 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at |
| Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 4047 | // least) put various tools in a triple-prefixed directory off of the parent |
| 4048 | // of the GCC installation. We use the GCC triple here to ensure that we end |
| 4049 | // up with tools that support the same amount of cross compiling as the |
| 4050 | // detected GCC installation. For example, if we find a GCC installation |
| 4051 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be |
| 4052 | // used to target i386. |
| 4053 | // FIXME: This seems unlikely to be Linux-specific. |
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 4054 | ToolChain::path_list &PPaths = getProgramPaths(); |
| Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 4055 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4056 | GCCInstallation.getTriple().str() + "/bin") |
| 4057 | .str()); |
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 4058 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4059 | Distro Distro = DetectDistro(D, Arch); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4060 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4061 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { |
| Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 4062 | ExtraOpts.push_back("-z"); |
| 4063 | ExtraOpts.push_back("relro"); |
| 4064 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4065 | |
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 4066 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4067 | ExtraOpts.push_back("-X"); |
| 4068 | |
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 4069 | const bool IsAndroid = Triple.isAndroid(); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4070 | const bool IsMips = isMipsArch(Arch); |
| 4071 | |
| 4072 | if (IsMips && !SysRoot.empty()) |
| 4073 | ExtraOpts.push_back("--sysroot=" + SysRoot); |
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 4074 | |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 4075 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
| 4076 | // and the MIPS ABI require .dynsym to be sorted in different ways. |
| 4077 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
| 4078 | // ABI requires a mapping between the GOT and the symbol table. |
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 4079 | // Android loader does not support .gnu.hash. |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4080 | if (!IsMips && !IsAndroid) { |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4081 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || |
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 4082 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 4083 | ExtraOpts.push_back("--hash-style=gnu"); |
| 4084 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4085 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 4086 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) |
| 4087 | ExtraOpts.push_back("--hash-style=both"); |
| 4088 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4089 | |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 4090 | if (IsRedhat(Distro) && Distro != RHEL5 && Distro != RHEL6) |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4091 | ExtraOpts.push_back("--no-add-needed"); |
| 4092 | |
| Rafael Espindola | 5ed89d4 | 2016-06-03 17:26:16 +0000 | [diff] [blame] | 4093 | #ifdef ENABLE_LINKER_BUILD_ID |
| 4094 | ExtraOpts.push_back("--build-id"); |
| 4095 | #endif |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4096 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4097 | if (IsOpenSUSE(Distro)) |
| Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 4098 | ExtraOpts.push_back("--enable-new-dtags"); |
| Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 4099 | |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 4100 | // The selection of paths to try here is designed to match the patterns which |
| 4101 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
| 4102 | // This was determined by running GCC in a fake filesystem, creating all |
| 4103 | // possible permutations of these directories, and seeing which ones it added |
| 4104 | // to the link paths. |
| 4105 | path_list &Paths = getFilePaths(); |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 4106 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4107 | const std::string OSLibDir = getOSLibDir(Triple, Args); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4108 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 4109 | |
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 4110 | // Add the multilib suffixed paths where they are available. |
| 4111 | if (GCCInstallation.isValid()) { |
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 4112 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 4113 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4114 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 4115 | const MultilibSet &Multilibs = GCCInstallation.getMultilibs(); |
| 4116 | |
| 4117 | // Add toolchain / multilib specific file paths. |
| 4118 | addMultilibsFilePaths(D, Multilibs, Multilib, |
| 4119 | GCCInstallation.getInstallPath(), Paths); |
| Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 4120 | |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4121 | // Sourcery CodeBench MIPS toolchain holds some libraries under |
| Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 4122 | // a biarch-like suffix of the GCC installation. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4123 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4124 | Paths); |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4125 | |
| 4126 | // GCC cross compiling toolchains will install target libraries which ship |
| 4127 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as |
| 4128 | // any part of the GCC installation in |
| 4129 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat |
| 4130 | // debatable, but is the reality today. We need to search this tree even |
| 4131 | // when we have a sysroot somewhere else. It is the responsibility of |
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 4132 | // whomever is doing the cross build targeting a sysroot using a GCC |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4133 | // installation that is *not* within the system root to ensure two things: |
| 4134 | // |
| 4135 | // 1) Any DSOs that are linked in from this tree or from the install path |
| Alexander Potapenko | c8e749a | 2014-09-01 12:35:57 +0000 | [diff] [blame] | 4136 | // above must be present on the system root and found via an |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4137 | // appropriate rpath. |
| 4138 | // 2) There must not be libraries installed into |
| 4139 | // <prefix>/<triple>/<libdir> unless they should be preferred over |
| 4140 | // those within the system root. |
| 4141 | // |
| 4142 | // Note that this matches the GCC behavior. See the below comment for where |
| 4143 | // Clang diverges from GCC's behavior. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4144 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + |
| 4145 | OSLibDir + Multilib.osSuffix(), |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4146 | Paths); |
| 4147 | |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4148 | // If the GCC installation we found is inside of the sysroot, we want to |
| 4149 | // prefer libraries installed in the parent prefix of the GCC installation. |
| 4150 | // 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] | 4151 | // outside of the system root as that can pick up unintended libraries. |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4152 | // This usually happens when there is an external cross compiler on the |
| 4153 | // 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] | 4154 | // the cross. Note that GCC does include some of these directories in some |
| 4155 | // configurations but this seems somewhere between questionable and simply |
| 4156 | // a bug. |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4157 | if (StringRef(LibPath).startswith(SysRoot)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4158 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); |
| 4159 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4160 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4161 | } |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4162 | |
| 4163 | // Similar to the logic for GCC above, if we currently running Clang inside |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4164 | // of the requested system root, add its parent library paths to |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4165 | // those searched. |
| 4166 | // FIXME: It's not clear whether we should use the driver's installed |
| 4167 | // directory ('Dir' below) or the ResourceDir. |
| 4168 | if (StringRef(D.Dir).startswith(SysRoot)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4169 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); |
| 4170 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4171 | } |
| 4172 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4173 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); |
| 4174 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); |
| 4175 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); |
| 4176 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); |
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 4177 | |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 4178 | // 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] | 4179 | // installations with strange symlinks. |
| Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 4180 | if (GCCInstallation.isValid()) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4181 | addPathIfExists(D, |
| 4182 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4183 | "/../../" + OSLibDir, |
| 4184 | Paths); |
| Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 4185 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4186 | // Add the 'other' biarch variant path |
| 4187 | Multilib BiarchSibling; |
| 4188 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4189 | addPathIfExists(D, GCCInstallation.getInstallPath() + |
| 4190 | BiarchSibling.gccSuffix(), |
| 4191 | Paths); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4192 | } |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4193 | |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4194 | // See comments above on the multilib variant for details of why this is |
| 4195 | // included even from outside the sysroot. |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4196 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| 4197 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| 4198 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4199 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + |
| 4200 | Multilib.osSuffix(), |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4201 | Paths); |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4202 | |
| 4203 | // See comments above on the multilib variant for details of why this is |
| 4204 | // only included from within the sysroot. |
| 4205 | if (StringRef(LibPath).startswith(SysRoot)) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4206 | addPathIfExists(D, LibPath, Paths); |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 4207 | } |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4208 | |
| 4209 | // Similar to the logic for GCC above, if we are currently running Clang |
| 4210 | // inside of the requested system root, add its parent library path to those |
| 4211 | // searched. |
| 4212 | // FIXME: It's not clear whether we should use the driver's installed |
| 4213 | // directory ('Dir' below) or the ResourceDir. |
| 4214 | if (StringRef(D.Dir).startswith(SysRoot)) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4215 | addPathIfExists(D, D.Dir + "/../lib", Paths); |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4216 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4217 | addPathIfExists(D, SysRoot + "/lib", Paths); |
| 4218 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4221 | bool Linux::HasNativeLLVMSupport() const { return true; } |
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 4222 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4223 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4224 | |
| 4225 | Tool *Linux::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4226 | return new tools::gnutools::Assembler(*this); |
| Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 4229 | std::string Linux::computeSysRoot() const { |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4230 | if (!getDriver().SysRoot.empty()) |
| 4231 | return getDriver().SysRoot; |
| 4232 | |
| 4233 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) |
| 4234 | return std::string(); |
| 4235 | |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4236 | // Standalone MIPS toolchains use different names for sysroot folder |
| 4237 | // and put it into different places. Here we try to check some known |
| 4238 | // variants. |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4239 | |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4240 | const StringRef InstallDir = GCCInstallation.getInstallPath(); |
| 4241 | const StringRef TripleStr = GCCInstallation.getTriple().str(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4242 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4243 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4244 | std::string Path = |
| 4245 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) |
| 4246 | .str(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4247 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4248 | if (getVFS().exists(Path)) |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4249 | return Path; |
| 4250 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4251 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4252 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4253 | if (getVFS().exists(Path)) |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4254 | return Path; |
| 4255 | |
| 4256 | return std::string(); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4257 | } |
| 4258 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4259 | std::string Linux::getDynamicLinker(const ArgList &Args) const { |
| 4260 | const llvm::Triple::ArchType Arch = getArch(); |
| 4261 | const llvm::Triple &Triple = getTriple(); |
| 4262 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4263 | const enum Distro Distro = DetectDistro(getDriver(), Arch); |
| 4264 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4265 | if (Triple.isAndroid()) |
| 4266 | return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; |
| Rafael Espindola | 0fa6680 | 2016-06-24 21:35:06 +0000 | [diff] [blame] | 4267 | else if (Triple.isMusl()) { |
| 4268 | std::string ArchName; |
| 4269 | switch (Arch) { |
| 4270 | case llvm::Triple::thumb: |
| 4271 | ArchName = "arm"; |
| 4272 | break; |
| 4273 | case llvm::Triple::thumbeb: |
| 4274 | ArchName = "armeb"; |
| 4275 | break; |
| 4276 | default: |
| 4277 | ArchName = Triple.getArchName().str(); |
| 4278 | } |
| 4279 | if (Triple.getEnvironment() == llvm::Triple::MuslEABIHF) |
| 4280 | ArchName += "hf"; |
| 4281 | |
| 4282 | return "/lib/ld-musl-" + ArchName + ".so.1"; |
| 4283 | } |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4284 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4285 | std::string LibDir; |
| 4286 | std::string Loader; |
| 4287 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4288 | switch (Arch) { |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4289 | default: |
| 4290 | llvm_unreachable("unsupported architecture"); |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4291 | |
| 4292 | case llvm::Triple::aarch64: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4293 | LibDir = "lib"; |
| 4294 | Loader = "ld-linux-aarch64.so.1"; |
| 4295 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4296 | case llvm::Triple::aarch64_be: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4297 | LibDir = "lib"; |
| 4298 | Loader = "ld-linux-aarch64_be.so.1"; |
| 4299 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4300 | case llvm::Triple::arm: |
| 4301 | case llvm::Triple::thumb: |
| 4302 | case llvm::Triple::armeb: |
| 4303 | case llvm::Triple::thumbeb: { |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 4304 | const bool HF = |
| 4305 | Triple.getEnvironment() == llvm::Triple::GNUEABIHF || |
| 4306 | tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4307 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4308 | LibDir = "lib"; |
| 4309 | Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3"; |
| 4310 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4311 | } |
| 4312 | case llvm::Triple::mips: |
| 4313 | case llvm::Triple::mipsel: |
| 4314 | case llvm::Triple::mips64: |
| 4315 | case llvm::Triple::mips64el: { |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4316 | bool LE = (Triple.getArch() == llvm::Triple::mipsel) || |
| 4317 | (Triple.getArch() == llvm::Triple::mips64el); |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4318 | bool IsNaN2008 = tools::mips::isNaN2008(Args, Triple); |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4319 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4320 | LibDir = "lib" + tools::mips::getMipsABILibSuffix(Args, Triple); |
| 4321 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4322 | if (tools::mips::isUCLibc(Args)) |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4323 | Loader = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0"; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4324 | else if (!Triple.hasEnvironment() && |
| 4325 | Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies) |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4326 | Loader = LE ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1"; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4327 | else |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4328 | Loader = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1"; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4329 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4330 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4331 | } |
| 4332 | case llvm::Triple::ppc: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4333 | LibDir = "lib"; |
| 4334 | Loader = "ld.so.1"; |
| 4335 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4336 | case llvm::Triple::ppc64: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4337 | LibDir = "lib64"; |
| 4338 | Loader = |
| 4339 | (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2" : "ld64.so.1"; |
| 4340 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4341 | case llvm::Triple::ppc64le: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4342 | LibDir = "lib64"; |
| 4343 | Loader = |
| 4344 | (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2"; |
| 4345 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4346 | case llvm::Triple::sparc: |
| 4347 | case llvm::Triple::sparcel: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4348 | LibDir = "lib"; |
| 4349 | Loader = "ld-linux.so.2"; |
| 4350 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4351 | case llvm::Triple::sparcv9: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4352 | LibDir = "lib64"; |
| 4353 | Loader = "ld-linux.so.2"; |
| 4354 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4355 | case llvm::Triple::systemz: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4356 | LibDir = "lib"; |
| 4357 | Loader = "ld64.so.1"; |
| 4358 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4359 | case llvm::Triple::x86: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4360 | LibDir = "lib"; |
| 4361 | Loader = "ld-linux.so.2"; |
| 4362 | break; |
| 4363 | case llvm::Triple::x86_64: { |
| 4364 | bool X32 = Triple.getEnvironment() == llvm::Triple::GNUX32; |
| 4365 | |
| 4366 | LibDir = X32 ? "libx32" : "lib64"; |
| 4367 | Loader = X32 ? "ld-linux-x32.so.2" : "ld-linux-x86-64.so.2"; |
| 4368 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4369 | } |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | if (Distro == Exherbo && (Triple.getVendor() == llvm::Triple::UnknownVendor || |
| 4373 | Triple.getVendor() == llvm::Triple::PC)) |
| 4374 | return "/usr/" + Triple.str() + "/lib/" + Loader; |
| 4375 | return "/" + LibDir + "/" + Loader; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4376 | } |
| 4377 | |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4378 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4379 | ArgStringList &CC1Args) const { |
| 4380 | const Driver &D = getDriver(); |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 4381 | std::string SysRoot = computeSysRoot(); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4382 | |
| 4383 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4384 | return; |
| 4385 | |
| 4386 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4387 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4388 | |
| 4389 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 4390 | SmallString<128> P(D.ResourceDir); |
| 4391 | llvm::sys::path::append(P, "include"); |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4392 | addSystemInclude(DriverArgs, CC1Args, P); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 4396 | return; |
| 4397 | |
| 4398 | // Check for configure-time C include directories. |
| 4399 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 4400 | if (CIncludeDirs != "") { |
| 4401 | SmallVector<StringRef, 5> dirs; |
| 4402 | CIncludeDirs.split(dirs, ":"); |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4403 | for (StringRef dir : dirs) { |
| Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 4404 | StringRef Prefix = |
| 4405 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4406 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4407 | } |
| 4408 | return; |
| 4409 | } |
| 4410 | |
| 4411 | // Lacking those, try to detect the correct set of system includes for the |
| 4412 | // target triple. |
| 4413 | |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4414 | // Add include directories specific to the selected multilib set and multilib. |
| 4415 | if (GCCInstallation.isValid()) { |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 4416 | const auto &Callback = Multilibs.includeDirsCallback(); |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4417 | if (Callback) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 4418 | for (const auto &Path : Callback(GCCInstallation.getMultilib())) |
| 4419 | addExternCSystemIncludeIfExists( |
| 4420 | DriverArgs, CC1Args, GCCInstallation.getInstallPath() + Path); |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4421 | } |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4422 | } |
| 4423 | |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4424 | // Implement generic Debian multiarch support. |
| 4425 | const StringRef X86_64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4426 | "/usr/include/x86_64-linux-gnu", |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4427 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4428 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 4429 | // in use in any released version of Debian, so we should consider |
| 4430 | // removing them. |
| 4431 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4432 | const StringRef X86MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4433 | "/usr/include/i386-linux-gnu", |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4434 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4435 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 4436 | // in use in any released version of Debian, so we should consider |
| 4437 | // removing them. |
| 4438 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", |
| 4439 | "/usr/include/i486-linux-gnu"}; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4440 | const StringRef AArch64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4441 | "/usr/include/aarch64-linux-gnu"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4442 | const StringRef ARMMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4443 | "/usr/include/arm-linux-gnueabi"}; |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4444 | const StringRef ARMHFMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4445 | "/usr/include/arm-linux-gnueabihf"}; |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4446 | const StringRef ARMEBMultiarchIncludeDirs[] = { |
| 4447 | "/usr/include/armeb-linux-gnueabi"}; |
| 4448 | const StringRef ARMEBHFMultiarchIncludeDirs[] = { |
| 4449 | "/usr/include/armeb-linux-gnueabihf"}; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4450 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4451 | const StringRef MIPSELMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4452 | "/usr/include/mipsel-linux-gnu"}; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4453 | const StringRef MIPS64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4454 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4455 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4456 | "/usr/include/mips64el-linux-gnu", |
| 4457 | "/usr/include/mips64el-linux-gnuabi64"}; |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4458 | const StringRef PPCMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4459 | "/usr/include/powerpc-linux-gnu"}; |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4460 | const StringRef PPC64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4461 | "/usr/include/powerpc64-linux-gnu"}; |
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4462 | const StringRef PPC64LEMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4463 | "/usr/include/powerpc64le-linux-gnu"}; |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4464 | const StringRef SparcMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4465 | "/usr/include/sparc-linux-gnu"}; |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4466 | const StringRef Sparc64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4467 | "/usr/include/sparc64-linux-gnu"}; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4468 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { |
| 4469 | "/usr/include/s390x-linux-gnu"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4470 | ArrayRef<StringRef> MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4471 | switch (getTriple().getArch()) { |
| 4472 | case llvm::Triple::x86_64: |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4473 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4474 | break; |
| 4475 | case llvm::Triple::x86: |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4476 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4477 | break; |
| 4478 | case llvm::Triple::aarch64: |
| 4479 | case llvm::Triple::aarch64_be: |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4480 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4481 | break; |
| 4482 | case llvm::Triple::arm: |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4483 | case llvm::Triple::thumb: |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4484 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 4485 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; |
| 4486 | else |
| 4487 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4488 | break; |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4489 | case llvm::Triple::armeb: |
| 4490 | case llvm::Triple::thumbeb: |
| 4491 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 4492 | MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs; |
| 4493 | else |
| 4494 | MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs; |
| 4495 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4496 | case llvm::Triple::mips: |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4497 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4498 | break; |
| 4499 | case llvm::Triple::mipsel: |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4500 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4501 | break; |
| 4502 | case llvm::Triple::mips64: |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4503 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4504 | break; |
| 4505 | case llvm::Triple::mips64el: |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4506 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4507 | break; |
| 4508 | case llvm::Triple::ppc: |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4509 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4510 | break; |
| 4511 | case llvm::Triple::ppc64: |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4512 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4513 | break; |
| 4514 | case llvm::Triple::ppc64le: |
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4515 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4516 | break; |
| 4517 | case llvm::Triple::sparc: |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4518 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4519 | break; |
| 4520 | case llvm::Triple::sparcv9: |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4521 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4522 | break; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4523 | case llvm::Triple::systemz: |
| 4524 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; |
| 4525 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4526 | default: |
| 4527 | break; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4528 | } |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4529 | for (StringRef Dir : MultiarchIncludeDirs) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4530 | if (D.getVFS().exists(SysRoot + Dir)) { |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4531 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4532 | break; |
| 4533 | } |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | if (getTriple().getOS() == llvm::Triple::RTEMS) |
| 4537 | return; |
| 4538 | |
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4539 | // Add an include of '/include' directly. This isn't provided by default by |
| 4540 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 4541 | // 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] | 4542 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); |
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4543 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4544 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4545 | } |
| 4546 | |
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4547 | static std::string DetectLibcxxIncludePath(StringRef base) { |
| 4548 | std::error_code EC; |
| 4549 | int MaxVersion = 0; |
| 4550 | std::string MaxVersionString = ""; |
| 4551 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; |
| 4552 | LI = LI.increment(EC)) { |
| 4553 | StringRef VersionText = llvm::sys::path::filename(LI->path()); |
| 4554 | int Version; |
| 4555 | if (VersionText[0] == 'v' && |
| 4556 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { |
| 4557 | if (Version > MaxVersion) { |
| 4558 | MaxVersion = Version; |
| 4559 | MaxVersionString = VersionText; |
| 4560 | } |
| 4561 | } |
| 4562 | } |
| 4563 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; |
| 4564 | } |
| 4565 | |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4566 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 4567 | ArgStringList &CC1Args) const { |
| 4568 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4569 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4570 | return; |
| 4571 | |
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4572 | // Check if libc++ has been enabled and provide its include paths if so. |
| 4573 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4574 | const std::string LibCXXIncludePathCandidates[] = { |
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4575 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), |
| Yaron Keren | 5439b64 | 2016-05-17 19:01:16 +0000 | [diff] [blame] | 4576 | // If this is a development, non-installed, clang, libcxx will |
| 4577 | // not be found at ../include/c++ but it likely to be found at |
| 4578 | // one of the following two locations: |
| 4579 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/local/include/c++"), |
| 4580 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++") }; |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4581 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { |
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4582 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4583 | continue; |
| 4584 | // Add the first candidate that exists. |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4585 | addSystemInclude(DriverArgs, CC1Args, IncludePath); |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4586 | break; |
| 4587 | } |
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4588 | return; |
| 4589 | } |
| 4590 | |
| Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 4591 | // We need a detected GCC installation on Linux to provide libstdc++'s |
| 4592 | // headers. We handled the libc++ case above. |
| 4593 | if (!GCCInstallation.isValid()) |
| 4594 | return; |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4595 | |
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4596 | // By default, look for the C++ headers in an include directory adjacent to |
| 4597 | // the lib directory of the GCC installation. Note that this is expect to be |
| 4598 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. |
| 4599 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4600 | StringRef InstallDir = GCCInstallation.getInstallPath(); |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4601 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4602 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4603 | const std::string GCCMultiarchTriple = getMultiarchTriple( |
| 4604 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4605 | const std::string TargetMultiarchTriple = |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4606 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 4607 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4608 | |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4609 | // The primary search for libstdc++ supports multiarch variants. |
| Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 4610 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4611 | "/c++/" + Version.Text, TripleStr, |
| 4612 | GCCMultiarchTriple, TargetMultiarchTriple, |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4613 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
| Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4614 | return; |
| 4615 | |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4616 | // Otherwise, fall back on a bunch of options which don't use multiarch |
| 4617 | // layouts for simplicity. |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4618 | const std::string LibStdCXXIncludePathCandidates[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4619 | // Gentoo is weird and places its headers inside the GCC install, |
| 4620 | // so if the first attempt to find the headers fails, try these patterns. |
| Chandler Carruth | 81296fb | 2016-05-08 07:59:56 +0000 | [diff] [blame] | 4621 | InstallDir.str() + "/include/g++-v" + Version.Text, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4622 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + |
| 4623 | Version.MinorStr, |
| 4624 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, |
| 4625 | // Android standalone toolchain has C++ headers in yet another place. |
| 4626 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4627 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, |
| 4628 | // without a subdirectory corresponding to the gcc version. |
| 4629 | LibDir.str() + "/../include/c++", |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4630 | }; |
| 4631 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4632 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4633 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, |
| 4634 | /*GCCMultiarchTriple*/ "", |
| 4635 | /*TargetMultiarchTriple*/ "", |
| 4636 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4637 | break; |
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4638 | } |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4641 | void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, |
| 4642 | ArgStringList &CC1Args) const { |
| 4643 | if (DriverArgs.hasArg(options::OPT_nocudainc)) |
| 4644 | return; |
| 4645 | |
| Justin Lebar | 423019d | 2016-04-16 00:11:11 +0000 | [diff] [blame] | 4646 | if (!CudaInstallation.isValid()) { |
| 4647 | getDriver().Diag(diag::err_drv_no_cuda_installation); |
| 4648 | return; |
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4649 | } |
| Justin Lebar | 423019d | 2016-04-16 00:11:11 +0000 | [diff] [blame] | 4650 | |
| 4651 | addSystemInclude(DriverArgs, CC1Args, CudaInstallation.getIncludePath()); |
| 4652 | CC1Args.push_back("-include"); |
| 4653 | CC1Args.push_back("__clang_cuda_runtime_wrapper.h"); |
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4654 | } |
| 4655 | |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 4656 | void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs, |
| 4657 | ArgStringList &CC1Args) const { |
| 4658 | if (GCCInstallation.isValid()) { |
| 4659 | CC1Args.push_back("-isystem"); |
| 4660 | CC1Args.push_back(DriverArgs.MakeArgString( |
| 4661 | GCCInstallation.getParentLibPath() + "/../" + |
| 4662 | GCCInstallation.getTriple().str() + "/include")); |
| 4663 | } |
| 4664 | } |
| 4665 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4666 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 4667 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4668 | SanitizerMask Linux::getSupportedSanitizers() const { |
| 4669 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 4670 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 4671 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 4672 | getTriple().getArch() == llvm::Triple::mips64el; |
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4673 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || |
| 4674 | getTriple().getArch() == llvm::Triple::ppc64le; |
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4675 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || |
| 4676 | getTriple().getArch() == llvm::Triple::aarch64_be; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4677 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 4678 | Res |= SanitizerKind::Address; |
| 4679 | Res |= SanitizerKind::KernelAddress; |
| 4680 | Res |= SanitizerKind::Vptr; |
| Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 4681 | Res |= SanitizerKind::SafeStack; |
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4682 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4683 | Res |= SanitizerKind::DataFlow; |
| Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 4684 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4685 | Res |= SanitizerKind::Leak; |
| Bill Schmidt | 4b8841a | 2015-12-08 22:48:02 +0000 | [diff] [blame] | 4686 | if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4687 | Res |= SanitizerKind::Thread; |
| Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 4688 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) |
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4689 | Res |= SanitizerKind::Memory; |
| Derek Bruening | 256c2e1 | 2016-04-21 21:32:04 +0000 | [diff] [blame] | 4690 | if (IsX86_64) |
| 4691 | Res |= SanitizerKind::Efficiency; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4692 | if (IsX86 || IsX86_64) { |
| 4693 | Res |= SanitizerKind::Function; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4694 | } |
| 4695 | return Res; |
| 4696 | } |
| 4697 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 4698 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4699 | llvm::opt::ArgStringList &CmdArgs) const { |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 4700 | if (!needsProfileRT(Args)) return; |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4701 | |
| 4702 | // Add linker option -u__llvm_runtime_variable to cause runtime |
| 4703 | // initialization module to be linked in. |
| 4704 | if (!Args.hasArg(options::OPT_coverage)) |
| 4705 | CmdArgs.push_back(Args.MakeArgString( |
| 4706 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 4707 | ToolChain::addProfileRTLibs(Args, CmdArgs); |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4710 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 4711 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4712 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, |
| 4713 | const ArgList &Args) |
| 4714 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4715 | |
| 4716 | // Path mangling to find libexec |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4717 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 4718 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4719 | getProgramPaths().push_back(getDriver().Dir); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4720 | |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4721 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4722 | getFilePaths().push_back("/usr/lib"); |
| Dimitry Andric | f59a2b3 | 2015-12-27 10:01:44 +0000 | [diff] [blame] | 4723 | getFilePaths().push_back("/usr/lib/gcc50"); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4726 | Tool *DragonFly::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4727 | return new tools::dragonfly::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | Tool *DragonFly::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4731 | return new tools::dragonfly::Linker(*this); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4732 | } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4733 | |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4734 | /// CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary, |
| 4735 | /// which isn't properly a linker but nonetheless performs the step of stitching |
| 4736 | /// together object files from the assembler into a single blob. |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4737 | |
| 4738 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4739 | const ArgList &Args) |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4740 | : Linux(D, Triple, Args) { |
| 4741 | if (CudaInstallation.isValid()) |
| 4742 | getProgramPaths().push_back(CudaInstallation.getBinPath()); |
| 4743 | } |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4744 | |
| 4745 | void |
| 4746 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, |
| 4747 | llvm::opt::ArgStringList &CC1Args) const { |
| 4748 | Linux::addClangTargetOptions(DriverArgs, CC1Args); |
| 4749 | CC1Args.push_back("-fcuda-is-device"); |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4750 | |
| Justin Lebar | d3a44f6 | 2016-04-05 18:26:20 +0000 | [diff] [blame] | 4751 | if (DriverArgs.hasFlag(options::OPT_fcuda_flush_denormals_to_zero, |
| 4752 | options::OPT_fno_cuda_flush_denormals_to_zero, false)) |
| 4753 | CC1Args.push_back("-fcuda-flush-denormals-to-zero"); |
| 4754 | |
| Justin Lebar | 91f6f07 | 2016-05-23 20:19:56 +0000 | [diff] [blame] | 4755 | if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals, |
| 4756 | options::OPT_fno_cuda_approx_transcendentals, false)) |
| 4757 | CC1Args.push_back("-fcuda-approx-transcendentals"); |
| 4758 | |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4759 | if (DriverArgs.hasArg(options::OPT_nocudalib)) |
| 4760 | return; |
| 4761 | |
| 4762 | std::string LibDeviceFile = CudaInstallation.getLibDeviceFile( |
| 4763 | DriverArgs.getLastArgValue(options::OPT_march_EQ)); |
| 4764 | if (!LibDeviceFile.empty()) { |
| 4765 | CC1Args.push_back("-mlink-cuda-bitcode"); |
| 4766 | CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile)); |
| 4767 | |
| 4768 | // Libdevice in CUDA-7.0 requires PTX version that's more recent |
| 4769 | // than LLVM defaults to. Use PTX4.2 which is the PTX version that |
| 4770 | // came with CUDA-7.0. |
| 4771 | CC1Args.push_back("-target-feature"); |
| 4772 | CC1Args.push_back("+ptx42"); |
| 4773 | } |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4774 | } |
| 4775 | |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 4776 | void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs, |
| 4777 | ArgStringList &CC1Args) const { |
| 4778 | // Check our CUDA version if we're going to include the CUDA headers. |
| 4779 | if (!DriverArgs.hasArg(options::OPT_nocudainc) && |
| Justin Lebar | f399771 | 2016-07-07 18:24:28 +0000 | [diff] [blame] | 4780 | !DriverArgs.hasArg(options::OPT_no_cuda_version_check)) { |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 4781 | StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ); |
| 4782 | assert(!Arch.empty() && "Must have an explicit GPU arch."); |
| 4783 | CudaInstallation.CheckCudaVersionSupportsArch(StringToCudaArch(Arch)); |
| 4784 | } |
| 4785 | Linux::AddCudaIncludeArgs(DriverArgs, CC1Args); |
| 4786 | } |
| 4787 | |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4788 | llvm::opt::DerivedArgList * |
| 4789 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, |
| 4790 | const char *BoundArch) const { |
| 4791 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 4792 | const OptTable &Opts = getDriver().getOpts(); |
| 4793 | |
| 4794 | for (Arg *A : Args) { |
| 4795 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 4796 | // Skip this argument unless the architecture matches BoundArch |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4797 | if (!BoundArch || A->getValue(0) != StringRef(BoundArch)) |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4798 | continue; |
| 4799 | |
| 4800 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| 4801 | unsigned Prev = Index; |
| 4802 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| 4803 | |
| 4804 | // If the argument parsing failed or more than one argument was |
| 4805 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 4806 | // extra arguments. Emit an error and ignore. |
| 4807 | // |
| 4808 | // We also want to disallow any options which would alter the |
| 4809 | // driver behavior; that isn't going to work in our model. We |
| 4810 | // use isDriverOption() as an approximation, although things |
| 4811 | // like -O4 are going to slip through. |
| 4812 | if (!XarchArg || Index > Prev + 1) { |
| 4813 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| 4814 | << A->getAsString(Args); |
| 4815 | continue; |
| 4816 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| 4817 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| 4818 | << A->getAsString(Args); |
| 4819 | continue; |
| 4820 | } |
| 4821 | XarchArg->setBaseArg(A); |
| 4822 | A = XarchArg.release(); |
| 4823 | DAL->AddSynthesizedArg(A); |
| 4824 | } |
| 4825 | DAL->append(A); |
| 4826 | } |
| 4827 | |
| Justin Lebar | 4db224e | 2016-06-15 23:46:11 +0000 | [diff] [blame] | 4828 | if (BoundArch) { |
| 4829 | DAL->eraseArg(options::OPT_march_EQ); |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4830 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); |
| Justin Lebar | 4db224e | 2016-06-15 23:46:11 +0000 | [diff] [blame] | 4831 | } |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4832 | return DAL; |
| 4833 | } |
| 4834 | |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4835 | Tool *CudaToolChain::buildAssembler() const { |
| 4836 | return new tools::NVPTX::Assembler(*this); |
| 4837 | } |
| 4838 | |
| 4839 | Tool *CudaToolChain::buildLinker() const { |
| 4840 | return new tools::NVPTX::Linker(*this); |
| 4841 | } |
| 4842 | |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4843 | /// XCore tool chain |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4844 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4845 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4846 | : ToolChain(D, Triple, Args) { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4847 | // ProgramPaths are found via 'PATH' environment variable. |
| 4848 | } |
| 4849 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4850 | Tool *XCoreToolChain::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4851 | return new tools::XCore::Assembler(*this); |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4852 | } |
| 4853 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4854 | Tool *XCoreToolChain::buildLinker() const { |
| 4855 | return new tools::XCore::Linker(*this); |
| 4856 | } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4857 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4858 | bool XCoreToolChain::isPICDefault() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4859 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4860 | bool XCoreToolChain::isPIEDefault() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4861 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4862 | bool XCoreToolChain::isPICDefaultForced() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4863 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4864 | bool XCoreToolChain::SupportsProfiling() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4865 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4866 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4867 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4868 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4869 | ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4870 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 4871 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 4872 | return; |
| 4873 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { |
| 4874 | SmallVector<StringRef, 4> Dirs; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4875 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4876 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4877 | ArrayRef<StringRef> DirVec(Dirs); |
| 4878 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4879 | } |
| 4880 | } |
| 4881 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4882 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, |
| 4883 | ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4884 | CC1Args.push_back("-nostdsysteminc"); |
| 4885 | } |
| 4886 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4887 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( |
| 4888 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4889 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 4890 | DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4891 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4892 | return; |
| 4893 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { |
| 4894 | SmallVector<StringRef, 4> Dirs; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4895 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4896 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4897 | ArrayRef<StringRef> DirVec(Dirs); |
| 4898 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4899 | } |
| 4900 | } |
| 4901 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4902 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 4903 | ArgStringList &CmdArgs) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4904 | // We don't output any lib args. This is handled by xcc. |
| 4905 | } |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4906 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4907 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4908 | const ArgList &Args) |
| Douglas Katzman | 5eddc23 | 2016-05-09 19:09:59 +0000 | [diff] [blame] | 4909 | : Generic_ELF(D, Triple, Args) { |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4910 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use |
| 4911 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. |
| 4912 | // This won't work to find gcc. Instead we give the installation detector an |
| 4913 | // extra triple, which is preferable to further hacks of the logic that at |
| 4914 | // present is based solely on getArch(). In particular, it would be wrong to |
| 4915 | // choose the myriad installation when targeting a non-myriad sparc install. |
| 4916 | switch (Triple.getArch()) { |
| 4917 | default: |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4918 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() |
| 4919 | << "myriad"; |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4920 | case llvm::Triple::sparc: |
| 4921 | case llvm::Triple::sparcel: |
| 4922 | case llvm::Triple::shave: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4923 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4924 | } |
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 4925 | |
| 4926 | if (GCCInstallation.isValid()) { |
| 4927 | // The contents of LibDir are independent of the version of gcc. |
| Douglas Katzman | 87da5f4 | 2016-07-25 16:36:02 +0000 | [diff] [blame] | 4928 | // This contains libc, libg, libm, libstdc++, libssp. |
| 4929 | // The 'ma1x00' and 'nofpu' variants are irrelevant. |
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 4930 | SmallString<128> LibDir(GCCInstallation.getParentLibPath()); |
| Douglas Katzman | 87da5f4 | 2016-07-25 16:36:02 +0000 | [diff] [blame] | 4931 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib"); |
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 4932 | addPathIfExists(D, LibDir, getFilePaths()); |
| 4933 | |
| 4934 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. |
| 4935 | // These files are tied to a particular version of gcc. |
| 4936 | SmallString<128> CompilerSupportDir(GCCInstallation.getInstallPath()); |
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 4937 | addPathIfExists(D, CompilerSupportDir, getFilePaths()); |
| 4938 | } |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4939 | } |
| 4940 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4941 | MyriadToolChain::~MyriadToolChain() {} |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4942 | |
| Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 4943 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4944 | ArgStringList &CC1Args) const { |
| 4945 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4946 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 4947 | } |
| 4948 | |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4949 | void MyriadToolChain::AddClangCXXStdlibIncludeArgs( |
| 4950 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4951 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4952 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4953 | return; |
| 4954 | |
| 4955 | // Only libstdc++, for now. |
| 4956 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4957 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| 4958 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| 4959 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| 4960 | |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4961 | addLibStdCXXIncludePaths( |
| 4962 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4963 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4964 | } |
| 4965 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4966 | // MyriadToolChain handles several triples: |
| 4967 | // {shave,sparc{,el}}-myriad-{rtems,unknown}-elf |
| 4968 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { |
| 4969 | // The inherited method works fine if not targeting the SHAVE. |
| 4970 | if (!isShaveCompilation(getTriple())) |
| 4971 | return ToolChain::SelectTool(JA); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4972 | switch (JA.getKind()) { |
| Douglas Katzman | 9dc4c62 | 2015-11-20 04:58:12 +0000 | [diff] [blame] | 4973 | case Action::PreprocessJobClass: |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4974 | case Action::CompileJobClass: |
| 4975 | if (!Compiler) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4976 | Compiler.reset(new tools::SHAVE::Compiler(*this)); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4977 | return Compiler.get(); |
| 4978 | case Action::AssembleJobClass: |
| 4979 | if (!Assembler) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4980 | Assembler.reset(new tools::SHAVE::Assembler(*this)); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4981 | return Assembler.get(); |
| 4982 | default: |
| 4983 | return ToolChain::getTool(JA.getKind()); |
| 4984 | } |
| 4985 | } |
| 4986 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4987 | Tool *MyriadToolChain::buildLinker() const { |
| 4988 | return new tools::Myriad::Linker(*this); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4989 | } |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4990 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4991 | WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple, |
| 4992 | const llvm::opt::ArgList &Args) |
| 4993 | : ToolChain(D, Triple, Args) { |
| Dan Gohman | 57b62c5 | 2016-02-22 19:26:15 +0000 | [diff] [blame] | 4994 | |
| 4995 | assert(Triple.isArch32Bit() != Triple.isArch64Bit()); |
| 4996 | getFilePaths().push_back( |
| 4997 | getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64")); |
| 4998 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4999 | // Use LLD by default. |
| 5000 | DefaultLinker = "lld"; |
| 5001 | } |
| 5002 | |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 5003 | bool WebAssembly::IsMathErrnoDefault() const { return false; } |
| 5004 | |
| 5005 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } |
| 5006 | |
| 5007 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } |
| 5008 | |
| 5009 | bool WebAssembly::isPICDefault() const { return false; } |
| 5010 | |
| 5011 | bool WebAssembly::isPIEDefault() const { return false; } |
| 5012 | |
| 5013 | bool WebAssembly::isPICDefaultForced() const { return false; } |
| 5014 | |
| 5015 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } |
| 5016 | |
| 5017 | // TODO: Support Objective C stuff. |
| 5018 | bool WebAssembly::SupportsObjCGC() const { return false; } |
| 5019 | |
| 5020 | bool WebAssembly::hasBlocksRuntime() const { return false; } |
| 5021 | |
| 5022 | // TODO: Support profiling. |
| 5023 | bool WebAssembly::SupportsProfiling() const { return false; } |
| 5024 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 5025 | bool WebAssembly::HasNativeLLVMSupport() const { return true; } |
| 5026 | |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 5027 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, |
| 5028 | ArgStringList &CC1Args) const { |
| 5029 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 5030 | options::OPT_fno_use_init_array, true)) |
| 5031 | CC1Args.push_back("-fuse-init-array"); |
| 5032 | } |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5033 | |
| Dan Gohman | 6ad8f61 | 2016-01-14 16:00:13 +0000 | [diff] [blame] | 5034 | ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const { |
| 5035 | return ToolChain::RLT_CompilerRT; |
| 5036 | } |
| 5037 | |
| 5038 | ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { |
| 5039 | return ToolChain::CST_Libcxx; |
| 5040 | } |
| 5041 | |
| 5042 | void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 5043 | ArgStringList &CC1Args) const { |
| 5044 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 5045 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 5046 | } |
| 5047 | |
| 5048 | void WebAssembly::AddClangCXXStdlibIncludeArgs( |
| 5049 | const llvm::opt::ArgList &DriverArgs, |
| 5050 | llvm::opt::ArgStringList &CC1Args) const { |
| 5051 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc) && |
| 5052 | !DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 5053 | addSystemInclude(DriverArgs, CC1Args, |
| 5054 | getDriver().SysRoot + "/include/c++/v1"); |
| 5055 | } |
| 5056 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 5057 | Tool *WebAssembly::buildLinker() const { |
| 5058 | return new tools::wasm::Linker(*this); |
| 5059 | } |
| 5060 | |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5061 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 5062 | : Generic_ELF(D, Triple, Args) { |
| 5063 | if (Args.hasArg(options::OPT_static)) |
| 5064 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; |
| 5065 | |
| Paul Robinson | 9d61361 | 2016-05-16 17:22:25 +0000 | [diff] [blame] | 5066 | // Determine where to find the PS4 libraries. We use SCE_ORBIS_SDK_DIR |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5067 | // if it exists; otherwise use the driver's installation path, which |
| 5068 | // should be <SDK_DIR>/host_tools/bin. |
| 5069 | |
| 5070 | SmallString<512> PS4SDKDir; |
| Paul Robinson | 9d61361 | 2016-05-16 17:22:25 +0000 | [diff] [blame] | 5071 | if (const char *EnvValue = getenv("SCE_ORBIS_SDK_DIR")) { |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5072 | if (!llvm::sys::fs::exists(EnvValue)) |
| 5073 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; |
| 5074 | PS4SDKDir = EnvValue; |
| 5075 | } else { |
| 5076 | PS4SDKDir = getDriver().Dir; |
| 5077 | llvm::sys::path::append(PS4SDKDir, "/../../"); |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 5078 | } |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5079 | |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 5080 | // By default, the driver won't report a warning if it can't find |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5081 | // PS4's include or lib directories. This behavior could be changed if |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 5082 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5083 | // If -isysroot was passed, use that as the SDK base path. |
| 5084 | std::string PrefixDir; |
| 5085 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 5086 | PrefixDir = A->getValue(); |
| 5087 | if (!llvm::sys::fs::exists(PrefixDir)) |
| 5088 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; |
| 5089 | } else |
| 5090 | PrefixDir = PS4SDKDir.str(); |
| 5091 | |
| 5092 | SmallString<512> PS4SDKIncludeDir(PrefixDir); |
| 5093 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); |
| 5094 | if (!Args.hasArg(options::OPT_nostdinc) && |
| 5095 | !Args.hasArg(options::OPT_nostdlibinc) && |
| 5096 | !Args.hasArg(options::OPT_isysroot) && |
| 5097 | !Args.hasArg(options::OPT__sysroot_EQ) && |
| 5098 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { |
| 5099 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 5100 | << "PS4 system headers" << PS4SDKIncludeDir; |
| 5101 | } |
| 5102 | |
| 5103 | SmallString<512> PS4SDKLibDir(PS4SDKDir); |
| 5104 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); |
| 5105 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5106 | !Args.hasArg(options::OPT_nodefaultlibs) && |
| 5107 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && |
| 5108 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && |
| 5109 | !Args.hasArg(options::OPT_emit_ast) && |
| 5110 | !llvm::sys::fs::exists(PS4SDKLibDir)) { |
| 5111 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 5112 | << "PS4 system libraries" << PS4SDKLibDir; |
| 5113 | return; |
| 5114 | } |
| 5115 | getFilePaths().push_back(PS4SDKLibDir.str()); |
| 5116 | } |
| 5117 | |
| 5118 | Tool *PS4CPU::buildAssembler() const { |
| 5119 | return new tools::PS4cpu::Assemble(*this); |
| 5120 | } |
| 5121 | |
| 5122 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } |
| 5123 | |
| 5124 | bool PS4CPU::isPICDefault() const { return true; } |
| 5125 | |
| 5126 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } |
| 5127 | |
| 5128 | SanitizerMask PS4CPU::getSupportedSanitizers() const { |
| 5129 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 5130 | Res |= SanitizerKind::Address; |
| 5131 | Res |= SanitizerKind::Vptr; |
| 5132 | return Res; |
| 5133 | } |