| 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 | |
| Mehdi Amini | 6fcd4eb | 2016-10-07 21:41:00 +0000 | [diff] [blame] | 57 | types::ID MachO::LookupTypeForExtension(StringRef 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 | |
| Adrian Prantl | d50d56c | 2016-10-17 19:36:18 +0000 | [diff] [blame] | 292 | unsigned DarwinClang::GetDefaultDwarfVersion() const { |
| 293 | // Default to use DWARF 2 on OS X 10.10 / iOS 8 and lower. |
| 294 | if ((isTargetMacOS() && isMacosxVersionLT(10, 11)) || |
| 295 | (isTargetIOSBased() && isIPhoneOSVersionLT(9))) |
| 296 | return 2; |
| 297 | return 4; |
| 298 | } |
| 299 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 300 | void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, |
| Kuba Brecka | 2735a025 | 2014-10-31 00:08:57 +0000 | [diff] [blame] | 301 | StringRef DarwinLibName, bool AlwaysLink, |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 302 | bool IsEmbedded, bool AddRPath) const { |
| 303 | SmallString<128> Dir(getDriver().ResourceDir); |
| 304 | llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin"); |
| 305 | |
| 306 | SmallString<128> P(Dir); |
| 307 | llvm::sys::path::append(P, DarwinLibName); |
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 308 | |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 309 | // For now, allow missing resource libraries to support developers who may |
| Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 310 | // not have compiler-rt checked out or integrated into their build (unless |
| 311 | // we explicitly force linking with this library). |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 312 | if (AlwaysLink || getVFS().exists(P)) |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 313 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 314 | |
| 315 | // Adding the rpaths might negatively interact when other rpaths are involved, |
| 316 | // so we should make sure we add the rpaths last, after all user-specified |
| 317 | // rpaths. This is currently true from this place, but we need to be |
| 318 | // careful if this function is ever called before user's rpaths are emitted. |
| 319 | if (AddRPath) { |
| 320 | assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library"); |
| 321 | |
| 322 | // Add @executable_path to rpath to support having the dylib copied with |
| 323 | // the executable. |
| 324 | CmdArgs.push_back("-rpath"); |
| 325 | CmdArgs.push_back("@executable_path"); |
| 326 | |
| 327 | // Add the path to the resource dir to rpath to support using the dylib |
| 328 | // from the default location without copying. |
| 329 | CmdArgs.push_back("-rpath"); |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 330 | CmdArgs.push_back(Args.MakeArgString(Dir)); |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 331 | } |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 334 | StringRef Darwin::getPlatformFamily() const { |
| 335 | switch (TargetPlatform) { |
| 336 | case DarwinPlatformKind::MacOS: |
| 337 | return "MacOSX"; |
| 338 | case DarwinPlatformKind::IPhoneOS: |
| 339 | case DarwinPlatformKind::IPhoneOSSimulator: |
| 340 | return "iPhone"; |
| 341 | case DarwinPlatformKind::TvOS: |
| 342 | case DarwinPlatformKind::TvOSSimulator: |
| 343 | return "AppleTV"; |
| 344 | case DarwinPlatformKind::WatchOS: |
| 345 | case DarwinPlatformKind::WatchOSSimulator: |
| 346 | return "Watch"; |
| 347 | } |
| 348 | llvm_unreachable("Unsupported platform"); |
| 349 | } |
| 350 | |
| 351 | StringRef Darwin::getSDKName(StringRef isysroot) { |
| 352 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk |
| 353 | llvm::sys::path::const_iterator SDKDir; |
| 354 | auto BeginSDK = llvm::sys::path::begin(isysroot); |
| 355 | auto EndSDK = llvm::sys::path::end(isysroot); |
| 356 | for (auto IT = BeginSDK; IT != EndSDK; ++IT) { |
| 357 | StringRef SDK = *IT; |
| 358 | if (SDK.endswith(".sdk")) |
| 359 | return SDK.slice(0, SDK.size() - 4); |
| 360 | } |
| 361 | return ""; |
| 362 | } |
| 363 | |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 364 | StringRef Darwin::getOSLibraryNameSuffix() const { |
| 365 | switch(TargetPlatform) { |
| 366 | case DarwinPlatformKind::MacOS: |
| 367 | return "osx"; |
| 368 | case DarwinPlatformKind::IPhoneOS: |
| 369 | return "ios"; |
| 370 | case DarwinPlatformKind::IPhoneOSSimulator: |
| 371 | return "iossim"; |
| 372 | case DarwinPlatformKind::TvOS: |
| 373 | return "tvos"; |
| 374 | case DarwinPlatformKind::TvOSSimulator: |
| 375 | return "tvossim"; |
| 376 | case DarwinPlatformKind::WatchOS: |
| 377 | return "watchos"; |
| 378 | case DarwinPlatformKind::WatchOSSimulator: |
| 379 | return "watchossim"; |
| 380 | } |
| 381 | llvm_unreachable("Unsupported platform"); |
| 382 | } |
| 383 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 384 | void Darwin::addProfileRTLibs(const ArgList &Args, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 385 | ArgStringList &CmdArgs) const { |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 386 | if (!needsProfileRT(Args)) return; |
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 387 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 388 | AddLinkRuntimeLib(Args, CmdArgs, (Twine("libclang_rt.profile_") + |
| 389 | getOSLibraryNameSuffix() + ".a").str(), |
| 390 | /*AlwaysLink*/ true); |
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 393 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, |
| 394 | ArgStringList &CmdArgs, |
| 395 | StringRef Sanitizer) const { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 396 | AddLinkRuntimeLib( |
| 397 | Args, CmdArgs, |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 398 | (Twine("libclang_rt.") + Sanitizer + "_" + |
| 399 | getOSLibraryNameSuffix() + "_dynamic.dylib").str(), |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 400 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, |
| 401 | /*AddRPath*/ true); |
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| Jonas Hahnfeld | d196fa5 | 2016-07-27 08:15:54 +0000 | [diff] [blame] | 404 | ToolChain::RuntimeLibType DarwinClang::GetRuntimeLibType( |
| 405 | const ArgList &Args) const { |
| 406 | if (Arg* A = Args.getLastArg(options::OPT_rtlib_EQ)) { |
| 407 | StringRef Value = A->getValue(); |
| 408 | if (Value != "compiler-rt") |
| 409 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) |
| 410 | << Value << "darwin"; |
| 411 | } |
| 412 | |
| 413 | return ToolChain::RLT_CompilerRT; |
| 414 | } |
| 415 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 416 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 417 | ArgStringList &CmdArgs) const { |
| Jonas Hahnfeld | d196fa5 | 2016-07-27 08:15:54 +0000 | [diff] [blame] | 418 | // Call once to ensure diagnostic is printed if wrong value was specified |
| 419 | GetRuntimeLibType(Args); |
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 420 | |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 421 | // Darwin doesn't support real static executables, don't link any runtime |
| 422 | // libraries with -static. |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 423 | if (Args.hasArg(options::OPT_static) || |
| 424 | Args.hasArg(options::OPT_fapple_kext) || |
| 425 | Args.hasArg(options::OPT_mkernel)) |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 426 | return; |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 427 | |
| 428 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 429 | // cares. This is useful in situations where someone wants to statically link |
| 430 | // something like libstdc++, and needs its runtime support routines. |
| 431 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 432 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 433 | return; |
| 434 | } |
| 435 | |
| Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 436 | const SanitizerArgs &Sanitize = getSanitizerArgs(); |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 437 | if (Sanitize.needsAsanRt()) |
| 438 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); |
| 439 | if (Sanitize.needsUbsanRt()) |
| 440 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); |
| Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 441 | if (Sanitize.needsTsanRt()) |
| 442 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); |
| Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 443 | if (Sanitize.needsStatsRt()) { |
| 444 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; |
| 445 | AddLinkRuntimeLib(Args, CmdArgs, |
| 446 | (Twine("libclang_rt.stats_client_") + OS + ".a").str(), |
| 447 | /*AlwaysLink=*/true); |
| 448 | AddLinkSanitizerLibArgs(Args, CmdArgs, "stats"); |
| 449 | } |
| Derek Bruening | 256c2e1 | 2016-04-21 21:32:04 +0000 | [diff] [blame] | 450 | if (Sanitize.needsEsanRt()) |
| 451 | AddLinkSanitizerLibArgs(Args, CmdArgs, "esan"); |
| Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 452 | |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 453 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 454 | // target specific static runtime library. |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 455 | CmdArgs.push_back("-lSystem"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 456 | |
| 457 | // Select the dynamic runtime library and the target specific static library. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 458 | if (isTargetWatchOSBased()) { |
| 459 | // We currently always need a static runtime library for watchOS. |
| 460 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); |
| 461 | } else if (isTargetTvOSBased()) { |
| 462 | // We currently always need a static runtime library for tvOS. |
| 463 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); |
| 464 | } else if (isTargetIOSBased()) { |
| Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 465 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, |
| 466 | // it never went into the SDK. |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 467 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 468 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && |
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 469 | getTriple().getArch() != llvm::Triple::aarch64) |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 470 | CmdArgs.push_back("-lgcc_s.1"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 471 | |
| Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 472 | // We currently always need a static runtime library for iOS. |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 473 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 474 | } else { |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 475 | assert(isTargetMacOS() && "unexpected non MacOS platform"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 476 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 477 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 478 | if (isMacosxVersionLT(10, 5)) |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 479 | CmdArgs.push_back("-lgcc_s.10.4"); |
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 480 | else if (isMacosxVersionLT(10, 6)) |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 481 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 482 | |
| Chris Bieneman | 9074341 | 2016-08-17 21:54:30 +0000 | [diff] [blame] | 483 | // Originally for OS X, we thought we would only need a static runtime |
| 484 | // library when targeting 10.4, to provide versions of the static functions |
| 485 | // which were omitted from 10.4.dylib. This led to the creation of the 10.4 |
| 486 | // builtins library. |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 487 | // |
| 488 | // Unfortunately, that turned out to not be true, because Darwin system |
| 489 | // headers can still use eprintf on i386, and it is not exported from |
| 490 | // libSystem. Therefore, we still must provide a runtime library just for |
| 491 | // the tiny tiny handful of projects that *might* use that symbol. |
| Chris Bieneman | 9074341 | 2016-08-17 21:54:30 +0000 | [diff] [blame] | 492 | // |
| 493 | // Then over time, we figured out it was useful to add more things to the |
| 494 | // runtime so we created libclang_rt.osx.a to provide new functions when |
| 495 | // deploying to old OS builds, and for a long time we had both eprintf and |
| 496 | // osx builtin libraries. Which just seems excessive. So with PR 28855, we |
| 497 | // are removing the eprintf library and expecting eprintf to be provided by |
| 498 | // the OS X builtins library. |
| 499 | if (isMacosxVersionLT(10, 5)) |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 500 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); |
| Chris Bieneman | 9074341 | 2016-08-17 21:54:30 +0000 | [diff] [blame] | 501 | else |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 502 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 503 | } |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 506 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 507 | const OptTable &Opts = getDriver().getOpts(); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 508 | |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 509 | // Support allowing the SDKROOT environment variable used by xcrun and other |
| 510 | // Xcode tools to define the default sysroot, by making it the default for |
| 511 | // isysroot. |
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 512 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 513 | // Warn if the path does not exist. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 514 | if (!getVFS().exists(A->getValue())) |
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 515 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); |
| 516 | } else { |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 517 | if (char *env = ::getenv("SDKROOT")) { |
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 518 | // We only use this value as the default if it is an absolute path, |
| 519 | // exists, and it is not the root path. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 520 | if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) && |
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 521 | StringRef(env) != "/") { |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 522 | Args.append(Args.MakeSeparateArg( |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 523 | nullptr, Opts.getOption(options::OPT_isysroot), env)); |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 528 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 529 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 530 | Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ); |
| 531 | Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ); |
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 532 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 533 | if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 534 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 535 | << OSXVersion->getAsString(Args) |
| 536 | << (iOSVersion ? iOSVersion : |
| 537 | TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 538 | iOSVersion = TvOSVersion = WatchOSVersion = nullptr; |
| 539 | } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) { |
| 540 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 541 | << iOSVersion->getAsString(Args) |
| 542 | << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 543 | TvOSVersion = WatchOSVersion = nullptr; |
| 544 | } else if (TvOSVersion && WatchOSVersion) { |
| 545 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 546 | << TvOSVersion->getAsString(Args) |
| 547 | << WatchOSVersion->getAsString(Args); |
| 548 | WatchOSVersion = nullptr; |
| 549 | } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) { |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 550 | // If no deployment target was specified on the command line, check for |
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 551 | // environment defines. |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 552 | std::string OSXTarget; |
| 553 | std::string iOSTarget; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 554 | std::string TvOSTarget; |
| 555 | std::string WatchOSTarget; |
| 556 | |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 557 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) |
| 558 | OSXTarget = env; |
| 559 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) |
| 560 | iOSTarget = env; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 561 | if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET")) |
| 562 | TvOSTarget = env; |
| 563 | if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET")) |
| 564 | WatchOSTarget = env; |
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 565 | |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 566 | // If there is no command-line argument to specify the Target version and |
| 567 | // no environment variable defined, see if we can set the default based |
| 568 | // on -isysroot. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 569 | if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() && |
| Frederic Riss | 3ad83bd | 2016-01-12 23:47:59 +0000 | [diff] [blame] | 570 | TvOSTarget.empty() && Args.hasArg(options::OPT_isysroot)) { |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 571 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 572 | StringRef isysroot = A->getValue(); |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 573 | StringRef SDK = getSDKName(isysroot); |
| 574 | if (SDK.size() > 0) { |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 575 | // Slice the version number out. |
| 576 | // Version number is between the first and the last number. |
| 577 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 578 | size_t EndVer = SDK.find_last_of("0123456789"); |
| 579 | if (StartVer != StringRef::npos && EndVer > StartVer) { |
| 580 | StringRef Version = SDK.slice(StartVer, EndVer + 1); |
| 581 | if (SDK.startswith("iPhoneOS") || |
| 582 | SDK.startswith("iPhoneSimulator")) |
| 583 | iOSTarget = Version; |
| 584 | else if (SDK.startswith("MacOSX")) |
| 585 | OSXTarget = Version; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 586 | else if (SDK.startswith("WatchOS") || |
| 587 | SDK.startswith("WatchSimulator")) |
| 588 | WatchOSTarget = Version; |
| 589 | else if (SDK.startswith("AppleTVOS") || |
| 590 | SDK.startswith("AppleTVSimulator")) |
| 591 | TvOSTarget = Version; |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 592 | } |
| 593 | } |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 594 | } |
| 595 | } |
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 596 | |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 597 | // 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] | 598 | // from arch name and compute the version from the triple. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 599 | if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() && |
| 600 | WatchOSTarget.empty()) { |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 601 | StringRef MachOArchName = getMachOArchName(Args); |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 602 | unsigned Major, Minor, Micro; |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 603 | if (MachOArchName == "armv7" || MachOArchName == "armv7s" || |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 604 | MachOArchName == "arm64") { |
| 605 | getTriple().getiOSVersion(Major, Minor, Micro); |
| 606 | llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' |
| 607 | << Micro; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 608 | } else if (MachOArchName == "armv7k") { |
| 609 | getTriple().getWatchOSVersion(Major, Minor, Micro); |
| 610 | llvm::raw_string_ostream(WatchOSTarget) << Major << '.' << Minor << '.' |
| 611 | << Micro; |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 612 | } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && |
| 613 | MachOArchName != "armv7em") { |
| 614 | if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { |
| 615 | getDriver().Diag(diag::err_drv_invalid_darwin_version) |
| 616 | << getTriple().getOSName(); |
| 617 | } |
| 618 | llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' |
| 619 | << Micro; |
| 620 | } |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 621 | } |
| Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 622 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 623 | // Do not allow conflicts with the watchOS target. |
| 624 | if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) { |
| 625 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 626 | << "WATCHOS_DEPLOYMENT_TARGET" |
| 627 | << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" : |
| 628 | "TVOS_DEPLOYMENT_TARGET"); |
| 629 | } |
| 630 | |
| 631 | // Do not allow conflicts with the tvOS target. |
| 632 | if (!TvOSTarget.empty() && !iOSTarget.empty()) { |
| 633 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 634 | << "TVOS_DEPLOYMENT_TARGET" |
| 635 | << "IPHONEOS_DEPLOYMENT_TARGET"; |
| 636 | } |
| 637 | |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 638 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 639 | // default platform. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 640 | if (!OSXTarget.empty() && (!iOSTarget.empty() || |
| 641 | !WatchOSTarget.empty() || |
| 642 | !TvOSTarget.empty())) { |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 643 | if (getTriple().getArch() == llvm::Triple::arm || |
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 644 | getTriple().getArch() == llvm::Triple::aarch64 || |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 645 | getTriple().getArch() == llvm::Triple::thumb) |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 646 | OSXTarget = ""; |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 647 | else |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 648 | iOSTarget = WatchOSTarget = TvOSTarget = ""; |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 649 | } |
| Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 650 | |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 651 | if (!OSXTarget.empty()) { |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 652 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 653 | OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 654 | Args.append(OSXVersion); |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 655 | } else if (!iOSTarget.empty()) { |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 656 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 657 | iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 658 | Args.append(iOSVersion); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 659 | } else if (!TvOSTarget.empty()) { |
| 660 | const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ); |
| 661 | TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget); |
| 662 | Args.append(TvOSVersion); |
| 663 | } else if (!WatchOSTarget.empty()) { |
| 664 | const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ); |
| 665 | WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget); |
| 666 | Args.append(WatchOSVersion); |
| Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 667 | } |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 668 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 670 | DarwinPlatformKind Platform; |
| 671 | if (OSXVersion) |
| 672 | Platform = MacOS; |
| 673 | else if (iOSVersion) |
| 674 | Platform = IPhoneOS; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 675 | else if (TvOSVersion) |
| 676 | Platform = TvOS; |
| 677 | else if (WatchOSVersion) |
| 678 | Platform = WatchOS; |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 679 | else |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 680 | llvm_unreachable("Unable to infer Darwin variant"); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 681 | |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 682 | // Set the tool chain target information. |
| 683 | unsigned Major, Minor, Micro; |
| 684 | bool HadExtra; |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 685 | if (Platform == MacOS) { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 686 | assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && |
| 687 | "Unknown target platform!"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 688 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, |
| 689 | HadExtra) || |
| 690 | HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 691 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 692 | << OSXVersion->getAsString(Args); |
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 693 | } else if (Platform == IPhoneOS) { |
| 694 | assert(iOSVersion && "Unknown target platform!"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 695 | if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, |
| 696 | HadExtra) || |
| Bob Wilson | 4cf27c4 | 2016-07-18 20:29:14 +0000 | [diff] [blame] | 697 | HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100) |
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 698 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 699 | << iOSVersion->getAsString(Args); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 700 | } else if (Platform == TvOS) { |
| 701 | if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, |
| 702 | Micro, HadExtra) || HadExtra || |
| Bob Wilson | 4cf27c4 | 2016-07-18 20:29:14 +0000 | [diff] [blame] | 703 | Major >= 100 || Minor >= 100 || Micro >= 100) |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 704 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 705 | << TvOSVersion->getAsString(Args); |
| 706 | } else if (Platform == WatchOS) { |
| 707 | if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor, |
| 708 | Micro, HadExtra) || HadExtra || |
| 709 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 710 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 711 | << WatchOSVersion->getAsString(Args); |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 712 | } else |
| 713 | llvm_unreachable("unknown kind of Darwin platform"); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 714 | |
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 715 | // Recognize iOS targets with an x86 architecture as the iOS simulator. |
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 716 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 717 | getTriple().getArch() == llvm::Triple::x86_64)) |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 718 | Platform = IPhoneOSSimulator; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 719 | if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 720 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 721 | Platform = TvOSSimulator; |
| 722 | if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 723 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 724 | Platform = WatchOSSimulator; |
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 725 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 726 | setTarget(Platform, Major, Minor, Micro); |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 727 | |
| 728 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 729 | StringRef SDK = getSDKName(A->getValue()); |
| 730 | if (SDK.size() > 0) { |
| 731 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 732 | StringRef SDKName = SDK.slice(0, StartVer); |
| 733 | if (!SDKName.startswith(getPlatformFamily())) |
| 734 | getDriver().Diag(diag::warn_incompatible_sysroot) |
| 735 | << SDKName << getPlatformFamily(); |
| 736 | } |
| 737 | } |
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 740 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 741 | ArgStringList &CmdArgs) const { |
| 742 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 743 | |
| 744 | switch (Type) { |
| 745 | case ToolChain::CST_Libcxx: |
| 746 | CmdArgs.push_back("-lc++"); |
| 747 | break; |
| 748 | |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 749 | case ToolChain::CST_Libstdcxx: |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 750 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 751 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 752 | // platforms we care about it was -lstdc++.6, so we search for that |
| 753 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 754 | |
| 755 | // Check in the sysroot first. |
| 756 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 757 | SmallString<128> P(A->getValue()); |
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 758 | llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 759 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 760 | if (!getVFS().exists(P)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 761 | llvm::sys::path::remove_filename(P); |
| 762 | llvm::sys::path::append(P, "libstdc++.6.dylib"); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 763 | if (getVFS().exists(P)) { |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 764 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 765 | return; |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | // Otherwise, look in the root. |
| Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 771 | // FIXME: This should be removed someday when we don't have to care about |
| 772 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 773 | if (!getVFS().exists("/usr/lib/libstdc++.dylib") && |
| 774 | getVFS().exists("/usr/lib/libstdc++.6.dylib")) { |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 775 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 776 | return; |
| 777 | } |
| 778 | |
| 779 | // Otherwise, let the linker search. |
| 780 | CmdArgs.push_back("-lstdc++"); |
| 781 | break; |
| 782 | } |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 785 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 786 | ArgStringList &CmdArgs) const { |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 787 | // For Darwin platforms, use the compiler-rt-based support library |
| 788 | // instead of the gcc-provided one (which is also incidentally |
| 789 | // only present in the gcc lib dir, which makes it hard to find). |
| 790 | |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 791 | SmallString<128> P(getDriver().ResourceDir); |
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 792 | llvm::sys::path::append(P, "lib", "darwin"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 793 | |
| 794 | // Use the newer cc_kext for iOS ARM after 6.0. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 795 | if (isTargetWatchOS()) { |
| 796 | llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a"); |
| 797 | } else if (isTargetTvOS()) { |
| 798 | llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a"); |
| 799 | } else if (isTargetIPhoneOS()) { |
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 800 | llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 801 | } else { |
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 802 | llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 803 | } |
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 804 | |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 805 | // For now, allow missing resource libraries to support developers who may |
| 806 | // not have compiler-rt checked out or integrated into their build. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 807 | if (getVFS().exists(P)) |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 808 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 811 | DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, |
| Samuel Antao | 31fef98 | 2016-10-27 17:39:44 +0000 | [diff] [blame] | 812 | StringRef BoundArch, |
| 813 | Action::OffloadKind) const { |
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 814 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 815 | const OptTable &Opts = getDriver().getOpts(); |
| 816 | |
| 817 | // FIXME: We really want to get out of the tool chain level argument |
| 818 | // translation business, as it makes the driver functionality much |
| 819 | // more opaque. For now, we follow gcc closely solely for the |
| 820 | // purpose of easily achieving feature parity & testability. Once we |
| 821 | // have something that works, we should reevaluate each translation |
| 822 | // and try to push it down into tool specific logic. |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 823 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 824 | for (Arg *A : Args) { |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 825 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 826 | // Skip this argument unless the architecture matches either the toolchain |
| 827 | // triple arch, or the arch being bound. |
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 828 | llvm::Triple::ArchType XarchArch = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 829 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); |
| 830 | if (!(XarchArch == getArch() || |
| Mehdi Amini | c50b1a2 | 2016-10-07 21:27:26 +0000 | [diff] [blame] | 831 | (!BoundArch.empty() && |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 832 | XarchArch == |
| 833 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 834 | continue; |
| 835 | |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 836 | Arg *OriginalArg = A; |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 837 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 838 | unsigned Prev = Index; |
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 839 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 840 | |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 841 | // If the argument parsing failed or more than one argument was |
| 842 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 843 | // extra arguments. Emit an error and ignore. |
| 844 | // |
| 845 | // We also want to disallow any options which would alter the |
| 846 | // driver behavior; that isn't going to work in our model. We |
| 847 | // use isDriverOption() as an approximation, although things |
| 848 | // like -O4 are going to slip through. |
| Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 849 | if (!XarchArg || Index > Prev + 1) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 850 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 851 | << A->getAsString(Args); |
| Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 852 | continue; |
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 853 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 854 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 855 | << A->getAsString(Args); |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 856 | continue; |
| 857 | } |
| 858 | |
| Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 859 | XarchArg->setBaseArg(A); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 860 | |
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 861 | A = XarchArg.release(); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 862 | DAL->AddSynthesizedArg(A); |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 863 | |
| 864 | // Linker input arguments require custom handling. The problem is that we |
| 865 | // have already constructed the phase actions, so we can not treat them as |
| 866 | // "input arguments". |
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 867 | if (A->getOption().hasFlag(options::LinkerInput)) { |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 868 | // Convert the argument into individual Zlinker_input_args. |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 869 | for (const char *Value : A->getValues()) { |
| 870 | DAL->AddSeparateArg( |
| 871 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 872 | } |
| 873 | continue; |
| 874 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 875 | } |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 876 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 877 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 878 | // gcc translates options twice, which means that self-expanding |
| 879 | // options add duplicates. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 880 | switch ((options::ID)A->getOption().getID()) { |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 881 | default: |
| 882 | DAL->append(A); |
| 883 | break; |
| 884 | |
| 885 | case options::OPT_mkernel: |
| 886 | case options::OPT_fapple_kext: |
| 887 | DAL->append(A); |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 888 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 889 | break; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 891 | case options::OPT_dependency_file: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 892 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 893 | break; |
| 894 | |
| 895 | case options::OPT_gfull: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 896 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 897 | DAL->AddFlagArg( |
| 898 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 899 | break; |
| 900 | |
| 901 | case options::OPT_gused: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 902 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 903 | DAL->AddFlagArg( |
| 904 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 905 | break; |
| 906 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 907 | case options::OPT_shared: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 908 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 909 | break; |
| 910 | |
| 911 | case options::OPT_fconstant_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 912 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 913 | break; |
| 914 | |
| 915 | case options::OPT_fno_constant_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 916 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case options::OPT_Wnonportable_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 920 | DAL->AddFlagArg(A, |
| 921 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 922 | break; |
| 923 | |
| 924 | case options::OPT_Wno_nonportable_cfstrings: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 925 | DAL->AddFlagArg( |
| 926 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 927 | break; |
| 928 | |
| 929 | case options::OPT_fpascal_strings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 930 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 931 | break; |
| 932 | |
| 933 | case options::OPT_fno_pascal_strings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 934 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 935 | break; |
| 936 | } |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 939 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 940 | getTriple().getArch() == llvm::Triple::x86_64) |
| Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 941 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 942 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), |
| 943 | "core2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 944 | |
| 945 | // 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] | 946 | // how the driver driver works. |
| Mehdi Amini | c50b1a2 | 2016-10-07 21:27:26 +0000 | [diff] [blame] | 947 | if (!BoundArch.empty()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 948 | StringRef Name = BoundArch; |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 949 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 950 | const Option MArch = Opts.getOption(options::OPT_march_EQ); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 951 | |
| 952 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 953 | // which defines the list of which architectures we accept. |
| 954 | if (Name == "ppc") |
| 955 | ; |
| 956 | else if (Name == "ppc601") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 957 | DAL->AddJoinedArg(nullptr, MCpu, "601"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 958 | else if (Name == "ppc603") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 959 | DAL->AddJoinedArg(nullptr, MCpu, "603"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 960 | else if (Name == "ppc604") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 961 | DAL->AddJoinedArg(nullptr, MCpu, "604"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 962 | else if (Name == "ppc604e") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 963 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 964 | else if (Name == "ppc750") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 965 | DAL->AddJoinedArg(nullptr, MCpu, "750"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 966 | else if (Name == "ppc7400") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 967 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 968 | else if (Name == "ppc7450") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 969 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 970 | else if (Name == "ppc970") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 971 | DAL->AddJoinedArg(nullptr, MCpu, "970"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 972 | |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 973 | else if (Name == "ppc64" || Name == "ppc64le") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 974 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 975 | |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 976 | else if (Name == "i386") |
| 977 | ; |
| 978 | else if (Name == "i486") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 979 | DAL->AddJoinedArg(nullptr, MArch, "i486"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 980 | else if (Name == "i586") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 981 | DAL->AddJoinedArg(nullptr, MArch, "i586"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 982 | else if (Name == "i686") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 983 | DAL->AddJoinedArg(nullptr, MArch, "i686"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 984 | else if (Name == "pentium") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 985 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 986 | else if (Name == "pentium2") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 987 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 988 | else if (Name == "pentpro") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 989 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 990 | else if (Name == "pentIIm3") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 991 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 992 | |
| 993 | else if (Name == "x86_64") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 994 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 995 | else if (Name == "x86_64h") { |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 996 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| 997 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); |
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 998 | } |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 999 | |
| 1000 | else if (Name == "arm") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1001 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1002 | else if (Name == "armv4t") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1003 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1004 | else if (Name == "armv5") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1005 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1006 | else if (Name == "xscale") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1007 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1008 | else if (Name == "armv6") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1009 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1010 | else if (Name == "armv6m") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1011 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1012 | else if (Name == "armv7") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1013 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1014 | else if (Name == "armv7em") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1015 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); |
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1016 | else if (Name == "armv7k") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1017 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1018 | else if (Name == "armv7m") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1019 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); |
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1020 | else if (Name == "armv7s") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1021 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1022 | } |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 1023 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1024 | return DAL; |
| 1025 | } |
| 1026 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 1027 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1028 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1029 | // Embedded targets are simple at the moment, not supporting sanitizers and |
| 1030 | // with different libraries for each member of the product { static, PIC } x |
| 1031 | // { hard-float, soft-float } |
| 1032 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 1033 | CompilerRT += |
| 1034 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) |
| 1035 | ? "hard" |
| 1036 | : "soft"; |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1037 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; |
| 1038 | |
| 1039 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); |
| 1040 | } |
| 1041 | |
| Samuel Antao | 31fef98 | 2016-10-27 17:39:44 +0000 | [diff] [blame] | 1042 | DerivedArgList * |
| 1043 | Darwin::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch, |
| 1044 | Action::OffloadKind DeviceOffloadKind) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1045 | // First get the generic Apple args, before moving onto Darwin-specific ones. |
| Samuel Antao | 31fef98 | 2016-10-27 17:39:44 +0000 | [diff] [blame] | 1046 | DerivedArgList *DAL = |
| 1047 | MachO::TranslateArgs(Args, BoundArch, DeviceOffloadKind); |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1048 | const OptTable &Opts = getDriver().getOpts(); |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1049 | |
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1050 | // If no architecture is bound, none of the translations here are relevant. |
| Mehdi Amini | c50b1a2 | 2016-10-07 21:27:26 +0000 | [diff] [blame] | 1051 | if (BoundArch.empty()) |
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1052 | return DAL; |
| 1053 | |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1054 | // Add an explicit version min argument for the deployment target. We do this |
| 1055 | // after argument translation because -Xarch_ arguments may add a version min |
| 1056 | // argument. |
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1057 | AddDeploymentTarget(*DAL); |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1058 | |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1059 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. |
| 1060 | // FIXME: It would be far better to avoid inserting those -static arguments, |
| 1061 | // but we can't check the deployment target in the translation code until |
| 1062 | // it is set here. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1063 | if (isTargetWatchOSBased() || |
| 1064 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { |
| 1065 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1066 | Arg *A = *it; |
| 1067 | ++it; |
| 1068 | if (A->getOption().getID() != options::OPT_mkernel && |
| 1069 | A->getOption().getID() != options::OPT_fapple_kext) |
| 1070 | continue; |
| 1071 | assert(it != ie && "unexpected argument translation"); |
| 1072 | A = *it; |
| 1073 | assert(A->getOption().getID() == options::OPT_static && |
| 1074 | "missing expected -static argument"); |
| 1075 | it = DAL->getArgs().erase(it); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1079 | if (!Args.getLastArg(options::OPT_stdlib_EQ) && |
| Tim Northover | 3a098c1 | 2016-02-15 16:38:10 +0000 | [diff] [blame] | 1080 | GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1081 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), |
| 1082 | "libc++"); |
| 1083 | |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1084 | // Validate the C++ standard library choice. |
| 1085 | CXXStdlibType Type = GetCXXStdlibType(*DAL); |
| 1086 | if (Type == ToolChain::CST_Libcxx) { |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1087 | // Check whether the target provides libc++. |
| 1088 | StringRef where; |
| 1089 | |
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1090 | // Complain about targeting iOS < 5.0 in any way. |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1091 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) |
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1092 | where = "iOS 5.0"; |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1093 | |
| 1094 | if (where != StringRef()) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1095 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
| Tim Northover | c0f6c9b | 2016-08-23 18:12:58 +0000 | [diff] [blame] | 1099 | auto Arch = tools::darwin::getArchTypeForMachOArchName(BoundArch); |
| 1100 | if ((Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)) { |
| 1101 | if (Args.hasFlag(options::OPT_fomit_frame_pointer, |
| 1102 | options::OPT_fno_omit_frame_pointer, false)) |
| 1103 | getDriver().Diag(clang::diag::warn_drv_unsupported_opt_for_target) |
| 1104 | << "-fomit-frame-pointer" << BoundArch; |
| 1105 | if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer, |
| 1106 | options::OPT_mno_omit_leaf_frame_pointer, false)) |
| 1107 | getDriver().Diag(clang::diag::warn_drv_unsupported_opt_for_target) |
| 1108 | << "-momit-leaf-frame-pointer" << BoundArch; |
| 1109 | } |
| 1110 | |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1111 | return DAL; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1113 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1114 | bool MachO::IsUnwindTablesDefault() const { |
| Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1115 | return getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1118 | bool MachO::UseDwarfDebugFlags() const { |
| Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1119 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 1120 | return S[0] != '\0'; |
| 1121 | return false; |
| 1122 | } |
| 1123 | |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1124 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { |
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1125 | // Darwin uses SjLj exceptions on ARM. |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1126 | if (getTriple().getArch() != llvm::Triple::arm && |
| 1127 | getTriple().getArch() != llvm::Triple::thumb) |
| 1128 | return false; |
| 1129 | |
| Tim Northover | c741b04 | 2015-11-17 18:27:27 +0000 | [diff] [blame] | 1130 | // Only watchOS uses the new DWARF/Compact unwinding method. |
| Tim Northover | d88ecb3 | 2016-01-27 19:32:40 +0000 | [diff] [blame] | 1131 | llvm::Triple Triple(ComputeLLVMTriple(Args)); |
| Tim Northover | 4c9ac7d | 2016-01-27 22:14:02 +0000 | [diff] [blame] | 1132 | return !Triple.isWatchABI(); |
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| Steven Wu | 574b0f2 | 2016-03-01 01:07:58 +0000 | [diff] [blame] | 1135 | bool Darwin::SupportsEmbeddedBitcode() const { |
| 1136 | assert(TargetInitialized && "Target not initialized!"); |
| 1137 | if (isTargetIPhoneOS() && isIPhoneOSVersionLT(6, 0)) |
| 1138 | return false; |
| 1139 | return true; |
| 1140 | } |
| 1141 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1142 | bool MachO::isPICDefault() const { return true; } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1143 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1144 | bool MachO::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1145 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1146 | bool MachO::isPICDefaultForced() const { |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1147 | return (getArch() == llvm::Triple::x86_64 || |
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1148 | getArch() == llvm::Triple::aarch64); |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1151 | bool MachO::SupportsProfiling() const { |
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1152 | // Profiling instrumentation is only supported on x86. |
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1153 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1156 | void Darwin::addMinVersionArgs(const ArgList &Args, |
| 1157 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1158 | VersionTuple TargetVersion = getTargetVersion(); |
| 1159 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1160 | if (isTargetWatchOS()) |
| 1161 | CmdArgs.push_back("-watchos_version_min"); |
| 1162 | else if (isTargetWatchOSSimulator()) |
| 1163 | CmdArgs.push_back("-watchos_simulator_version_min"); |
| 1164 | else if (isTargetTvOS()) |
| 1165 | CmdArgs.push_back("-tvos_version_min"); |
| 1166 | else if (isTargetTvOSSimulator()) |
| 1167 | CmdArgs.push_back("-tvos_simulator_version_min"); |
| 1168 | else if (isTargetIOSSimulator()) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1169 | CmdArgs.push_back("-ios_simulator_version_min"); |
| Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1170 | else if (isTargetIOSBased()) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1171 | CmdArgs.push_back("-iphoneos_version_min"); |
| 1172 | else { |
| 1173 | assert(isTargetMacOS() && "unexpected target"); |
| 1174 | CmdArgs.push_back("-macosx_version_min"); |
| 1175 | } |
| 1176 | |
| 1177 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); |
| 1178 | } |
| 1179 | |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1180 | void Darwin::addStartObjectFileArgs(const ArgList &Args, |
| 1181 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1182 | // Derived from startfile spec. |
| 1183 | if (Args.hasArg(options::OPT_dynamiclib)) { |
| 1184 | // Derived from darwin_dylib1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1185 | if (isTargetWatchOSBased()) { |
| 1186 | ; // watchOS does not need dylib1.o. |
| 1187 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1188 | ; // iOS simulator does not need dylib1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1189 | } else if (isTargetIPhoneOS()) { |
| 1190 | if (isIPhoneOSVersionLT(3, 1)) |
| 1191 | CmdArgs.push_back("-ldylib1.o"); |
| 1192 | } else { |
| 1193 | if (isMacosxVersionLT(10, 5)) |
| 1194 | CmdArgs.push_back("-ldylib1.o"); |
| 1195 | else if (isMacosxVersionLT(10, 6)) |
| 1196 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1197 | } |
| 1198 | } else { |
| 1199 | if (Args.hasArg(options::OPT_bundle)) { |
| 1200 | if (!Args.hasArg(options::OPT_static)) { |
| 1201 | // Derived from darwin_bundle1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1202 | if (isTargetWatchOSBased()) { |
| 1203 | ; // watchOS does not need bundle1.o. |
| 1204 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1205 | ; // iOS simulator does not need bundle1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1206 | } else if (isTargetIPhoneOS()) { |
| 1207 | if (isIPhoneOSVersionLT(3, 1)) |
| 1208 | CmdArgs.push_back("-lbundle1.o"); |
| 1209 | } else { |
| 1210 | if (isMacosxVersionLT(10, 6)) |
| 1211 | CmdArgs.push_back("-lbundle1.o"); |
| 1212 | } |
| 1213 | } |
| 1214 | } else { |
| 1215 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { |
| 1216 | if (Args.hasArg(options::OPT_static) || |
| 1217 | Args.hasArg(options::OPT_object) || |
| 1218 | Args.hasArg(options::OPT_preload)) { |
| 1219 | CmdArgs.push_back("-lgcrt0.o"); |
| 1220 | } else { |
| 1221 | CmdArgs.push_back("-lgcrt1.o"); |
| 1222 | |
| 1223 | // darwin_crt2 spec is empty. |
| 1224 | } |
| 1225 | // By default on OS X 10.8 and later, we don't link with a crt1.o |
| 1226 | // file and the linker knows to use _main as the entry point. But, |
| 1227 | // when compiling with -pg, we need to link with the gcrt1.o file, |
| 1228 | // so pass the -no_new_main option to tell the linker to use the |
| 1229 | // "start" symbol as the entry point. |
| 1230 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) |
| 1231 | CmdArgs.push_back("-no_new_main"); |
| 1232 | } else { |
| 1233 | if (Args.hasArg(options::OPT_static) || |
| 1234 | Args.hasArg(options::OPT_object) || |
| 1235 | Args.hasArg(options::OPT_preload)) { |
| 1236 | CmdArgs.push_back("-lcrt0.o"); |
| 1237 | } else { |
| 1238 | // Derived from darwin_crt1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1239 | if (isTargetWatchOSBased()) { |
| 1240 | ; // watchOS does not need crt1.o. |
| 1241 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1242 | ; // iOS simulator does not need crt1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1243 | } else if (isTargetIPhoneOS()) { |
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1244 | if (getArch() == llvm::Triple::aarch64) |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1245 | ; // iOS does not need any crt1 files for arm64 |
| 1246 | else if (isIPhoneOSVersionLT(3, 1)) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1247 | CmdArgs.push_back("-lcrt1.o"); |
| 1248 | else if (isIPhoneOSVersionLT(6, 0)) |
| 1249 | CmdArgs.push_back("-lcrt1.3.1.o"); |
| 1250 | } else { |
| 1251 | if (isMacosxVersionLT(10, 5)) |
| 1252 | CmdArgs.push_back("-lcrt1.o"); |
| 1253 | else if (isMacosxVersionLT(10, 6)) |
| 1254 | CmdArgs.push_back("-lcrt1.10.5.o"); |
| 1255 | else if (isMacosxVersionLT(10, 8)) |
| 1256 | CmdArgs.push_back("-lcrt1.10.6.o"); |
| 1257 | |
| 1258 | // darwin_crt2 spec is empty. |
| 1259 | } |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1266 | !isTargetWatchOS() && |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1267 | isMacosxVersionLT(10, 5)) { |
| 1268 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); |
| 1269 | CmdArgs.push_back(Str); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1273 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } |
| Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1274 | |
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1275 | void Darwin::CheckObjCARC() const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1276 | if (isTargetIOSBased() || isTargetWatchOSBased() || |
| 1277 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) |
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1278 | return; |
| John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1279 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); |
| Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1282 | SanitizerMask Darwin::getSupportedSanitizers() const { |
| Devin Coughlin | fcfa38c | 2016-03-20 18:24:33 +0000 | [diff] [blame] | 1283 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1284 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 1285 | Res |= SanitizerKind::Address; |
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1286 | if (isTargetMacOS()) { |
| 1287 | if (!isMacosxVersionLT(10, 9)) |
| 1288 | Res |= SanitizerKind::Vptr; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1289 | Res |= SanitizerKind::SafeStack; |
| Devin Coughlin | fcfa38c | 2016-03-20 18:24:33 +0000 | [diff] [blame] | 1290 | if (IsX86_64) |
| 1291 | Res |= SanitizerKind::Thread; |
| 1292 | } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) { |
| 1293 | if (IsX86_64) |
| 1294 | Res |= SanitizerKind::Thread; |
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1295 | } |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1296 | return Res; |
| 1297 | } |
| 1298 | |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1299 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 1300 | /// all subcommands; this relies on gcc translating the majority of |
| 1301 | /// command line options. |
| 1302 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1303 | /// \brief Parse a GCCVersion object out of a string of text. |
| 1304 | /// |
| 1305 | /// This is the primary means of forming GCCVersion objects. |
| 1306 | /*static*/ |
| 1307 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1308 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1309 | std::pair<StringRef, StringRef> First = VersionText.split('.'); |
| 1310 | std::pair<StringRef, StringRef> Second = First.second.split('.'); |
| 1311 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1312 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| 1313 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1314 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1315 | GoodVersion.MajorStr = First.first.str(); |
| Bryan Chan | d346ae6 | 2016-06-17 16:47:14 +0000 | [diff] [blame] | 1316 | if (First.second.empty()) |
| 1317 | return GoodVersion; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1318 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1319 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1320 | GoodVersion.MinorStr = Second.first.str(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1321 | |
| 1322 | // First look for a number prefix and parse that if present. Otherwise just |
| 1323 | // stash the entire patch string in the suffix, and leave the number |
| 1324 | // unspecified. This covers versions strings such as: |
| Bryan Chan | d346ae6 | 2016-06-17 16:47:14 +0000 | [diff] [blame] | 1325 | // 5 (handled above) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1326 | // 4.4 |
| 1327 | // 4.4.0 |
| 1328 | // 4.4.x |
| 1329 | // 4.4.2-rc4 |
| 1330 | // 4.4.x-patched |
| 1331 | // And retains any patch number it finds. |
| 1332 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); |
| 1333 | if (!PatchText.empty()) { |
| Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1334 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1335 | // Try to parse the number and any suffix. |
| 1336 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || |
| 1337 | GoodVersion.Patch < 0) |
| 1338 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1339 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | return GoodVersion; |
| 1344 | } |
| 1345 | |
| 1346 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1347 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, |
| 1348 | int RHSPatch, |
| 1349 | StringRef RHSPatchSuffix) const { |
| 1350 | if (Major != RHSMajor) |
| 1351 | return Major < RHSMajor; |
| 1352 | if (Minor != RHSMinor) |
| 1353 | return Minor < RHSMinor; |
| 1354 | if (Patch != RHSPatch) { |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1355 | // Note that versions without a specified patch sort higher than those with |
| 1356 | // a patch. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1357 | if (RHSPatch == -1) |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1358 | return true; |
| 1359 | if (Patch == -1) |
| 1360 | return false; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1361 | |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1362 | // Otherwise just sort on the patch itself. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1363 | return Patch < RHSPatch; |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1364 | } |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1365 | if (PatchSuffix != RHSPatchSuffix) { |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1366 | // Sort empty suffixes higher. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1367 | if (RHSPatchSuffix.empty()) |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1368 | return true; |
| 1369 | if (PatchSuffix.empty()) |
| Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1370 | return false; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1371 | |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1372 | // Provide a lexicographic sort to make this a total ordering. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1373 | return PatchSuffix < RHSPatchSuffix; |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | // The versions are equal. |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1377 | return false; |
| 1378 | } |
| 1379 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1380 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1381 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); |
| 1382 | if (A) |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1383 | return A->getValue(); |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1384 | return GCC_INSTALL_PREFIX; |
| 1385 | } |
| 1386 | |
| Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1387 | /// \brief Initialize a GCCInstallationDetector from the driver. |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1388 | /// |
| 1389 | /// This performs all of the autodetection and sets up the various paths. |
| Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1390 | /// Once constructed, a GCCInstallationDetector is essentially immutable. |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1391 | /// |
| 1392 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and |
| 1393 | /// should instead pull the target out of the driver. This is currently |
| 1394 | /// necessary because the driver doesn't store the final version of the target |
| 1395 | /// triple. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1396 | void Generic_GCC::GCCInstallationDetector::init( |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1397 | const llvm::Triple &TargetTriple, const ArgList &Args, |
| Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1398 | ArrayRef<std::string> ExtraTripleAliases) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1399 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() |
| 1400 | ? TargetTriple.get64BitArchVariant() |
| 1401 | : TargetTriple.get32BitArchVariant(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1402 | // The library directories which may contain GCC installations. |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1403 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1404 | // The compatible GCC triples for this particular architecture. |
| Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1405 | SmallVector<StringRef, 16> CandidateTripleAliases; |
| 1406 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1407 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, |
| 1408 | CandidateTripleAliases, CandidateBiarchLibDirs, |
| 1409 | CandidateBiarchTripleAliases); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1410 | |
| 1411 | // Compute the set of prefixes for our search. |
| 1412 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), |
| 1413 | D.PrefixDirs.end()); |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1414 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1415 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); |
| 1416 | if (GCCToolchainDir != "") { |
| 1417 | if (GCCToolchainDir.back() == '/') |
| 1418 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1419 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1420 | Prefixes.push_back(GCCToolchainDir); |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1421 | } else { |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1422 | // If we have a SysRoot, try that first. |
| 1423 | if (!D.SysRoot.empty()) { |
| 1424 | Prefixes.push_back(D.SysRoot); |
| 1425 | Prefixes.push_back(D.SysRoot + "/usr"); |
| 1426 | } |
| 1427 | |
| 1428 | // Then look for gcc installed alongside clang. |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1429 | Prefixes.push_back(D.InstalledDir + "/.."); |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1430 | |
| Rafael Espindola | 2edca41 | 2016-05-09 13:03:10 +0000 | [diff] [blame] | 1431 | // Then look for distribution supplied gcc installations. |
| 1432 | if (D.SysRoot.empty()) { |
| 1433 | // Look for RHEL devtoolsets. |
| 1434 | Prefixes.push_back("/opt/rh/devtoolset-4/root/usr"); |
| 1435 | Prefixes.push_back("/opt/rh/devtoolset-3/root/usr"); |
| 1436 | Prefixes.push_back("/opt/rh/devtoolset-2/root/usr"); |
| 1437 | Prefixes.push_back("/opt/rh/devtoolset-1.1/root/usr"); |
| 1438 | Prefixes.push_back("/opt/rh/devtoolset-1.0/root/usr"); |
| 1439 | // And finally in /usr. |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1440 | Prefixes.push_back("/usr"); |
| Rafael Espindola | 2edca41 | 2016-05-09 13:03:10 +0000 | [diff] [blame] | 1441 | } |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1442 | } |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1443 | |
| Michal Gorny | bd449c2 | 2016-10-25 15:07:41 +0000 | [diff] [blame] | 1444 | // Try to respect gcc-config on Gentoo. However, do that only |
| 1445 | // if --gcc-toolchain is not provided or equal to the Gentoo install |
| 1446 | // in /usr. This avoids accidentally enforcing the system GCC version |
| 1447 | // when using a custom toolchain. |
| 1448 | if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") { |
| 1449 | for (StringRef CandidateTriple : CandidateTripleAliases) { |
| 1450 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = |
| 1451 | D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" + |
| 1452 | CandidateTriple.str()); |
| 1453 | if (File) { |
| 1454 | SmallVector<StringRef, 2> Lines; |
| 1455 | File.get()->getBuffer().split(Lines, "\n"); |
| 1456 | for (StringRef Line : Lines) { |
| 1457 | // CURRENT=triple-version |
| 1458 | if (Line.consume_front("CURRENT=")) { |
| 1459 | const std::pair<StringRef, StringRef> ActiveVersion = |
| 1460 | Line.rsplit('-'); |
| 1461 | // Note: Strictly speaking, we should be reading |
| 1462 | // /etc/env.d/gcc/${CURRENT} now. However, the file doesn't |
| 1463 | // contain anything new or especially useful to us. |
| 1464 | const std::string GentooPath = D.SysRoot + "/usr/lib/gcc/" + |
| 1465 | ActiveVersion.first.str() + "/" + |
| 1466 | ActiveVersion.second.str(); |
| 1467 | if (D.getVFS().exists(GentooPath + "/crtbegin.o")) { |
| 1468 | Version = GCCVersion::Parse(ActiveVersion.second); |
| 1469 | GCCInstallPath = GentooPath; |
| 1470 | GCCParentLibPath = GentooPath + "/../../.."; |
| 1471 | GCCTriple.setTriple(ActiveVersion.first); |
| 1472 | IsValid = true; |
| 1473 | return; |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | } |
| 1480 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1481 | // Loop over the various components which exist and select the best GCC |
| 1482 | // installation available. GCC installs are ranked by version number. |
| 1483 | Version = GCCVersion::Parse("0.0.0"); |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1484 | for (const std::string &Prefix : Prefixes) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1485 | if (!D.getVFS().exists(Prefix)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1486 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1487 | for (StringRef Suffix : CandidateLibDirs) { |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1488 | const std::string LibDir = Prefix + Suffix.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1489 | if (!D.getVFS().exists(LibDir)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1490 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1491 | for (StringRef Candidate : ExtraTripleAliases) // Try these first. |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1492 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1493 | for (StringRef Candidate : CandidateTripleAliases) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1494 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1495 | } |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1496 | for (StringRef Suffix : CandidateBiarchLibDirs) { |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1497 | const std::string LibDir = Prefix + Suffix.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1498 | if (!D.getVFS().exists(LibDir)) |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1499 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1500 | for (StringRef Candidate : CandidateBiarchTripleAliases) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1501 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1502 | /*NeedsBiarchSuffix=*/ true); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1503 | } |
| 1504 | } |
| 1505 | } |
| 1506 | |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1507 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1508 | for (const auto &InstallPath : CandidateGCCInstallPaths) |
| 1509 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1510 | |
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1511 | if (!GCCInstallPath.empty()) |
| 1512 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; |
| 1513 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1514 | for (const auto &Multilib : Multilibs) |
| 1515 | OS << "Candidate multilib: " << Multilib << "\n"; |
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1516 | |
| 1517 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) |
| 1518 | OS << "Selected multilib: " << SelectedMultilib << "\n"; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { |
| 1522 | if (BiarchSibling.hasValue()) { |
| 1523 | M = BiarchSibling.getValue(); |
| 1524 | return true; |
| 1525 | } |
| 1526 | return false; |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1529 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1530 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1531 | SmallVectorImpl<StringRef> &LibDirs, |
| 1532 | SmallVectorImpl<StringRef> &TripleAliases, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1533 | SmallVectorImpl<StringRef> &BiarchLibDirs, |
| 1534 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1535 | // Declare a bunch of static data sets that we'll select between below. These |
| 1536 | // are specifically designed to always refer to string literals to avoid any |
| 1537 | // lifetime or initialization issues. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1538 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; |
| 1539 | static const char *const AArch64Triples[] = { |
| 1540 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", |
| 1541 | "aarch64-redhat-linux"}; |
| 1542 | static const char *const AArch64beLibDirs[] = {"/lib"}; |
| 1543 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", |
| 1544 | "aarch64_be-linux-gnu"}; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1545 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1546 | static const char *const ARMLibDirs[] = {"/lib"}; |
| 1547 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", |
| 1548 | "arm-linux-androideabi"}; |
| 1549 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", |
| 1550 | "armv7hl-redhat-linux-gnueabi"}; |
| 1551 | static const char *const ARMebLibDirs[] = {"/lib"}; |
| 1552 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", |
| 1553 | "armeb-linux-androideabi"}; |
| 1554 | static const char *const ARMebHFTriples[] = { |
| 1555 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1556 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1557 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1558 | static const char *const X86_64Triples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1559 | "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", |
| 1560 | "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E", |
| 1561 | "x86_64-redhat-linux", "x86_64-suse-linux", |
| 1562 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", |
| 1563 | "x86_64-slackware-linux", "x86_64-linux-android", |
| 1564 | "x86_64-unknown-linux"}; |
| 1565 | static const char *const X32LibDirs[] = {"/libx32"}; |
| 1566 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1567 | static const char *const X86Triples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1568 | "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", |
| 1569 | "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux", |
| 1570 | "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux", |
| 1571 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", |
| 1572 | "i586-linux-gnu"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1573 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1574 | static const char *const MIPSLibDirs[] = {"/lib"}; |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1575 | static const char *const MIPSTriples[] = {"mips-linux-gnu", "mips-mti-linux", |
| 1576 | "mips-mti-linux-gnu", |
| 1577 | "mips-img-linux-gnu"}; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1578 | static const char *const MIPSELLibDirs[] = {"/lib"}; |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 1579 | static const char *const MIPSELTriples[] = {"mipsel-linux-gnu", |
| 1580 | "mips-img-linux-gnu"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1581 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1582 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; |
| 1583 | static const char *const MIPS64Triples[] = { |
| 1584 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1585 | "mips64-linux-gnuabi64"}; |
| 1586 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; |
| 1587 | static const char *const MIPS64ELTriples[] = { |
| 1588 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 1589 | "mips64el-linux-gnuabi64"}; |
| 1590 | |
| 1591 | static const char *const MIPSELAndroidLibDirs[] = {"/lib", "/libr2", |
| 1592 | "/libr6"}; |
| 1593 | static const char *const MIPSELAndroidTriples[] = {"mipsel-linux-android"}; |
| 1594 | static const char *const MIPS64ELAndroidLibDirs[] = {"/lib64", "/lib", |
| 1595 | "/libr2", "/libr6"}; |
| 1596 | static const char *const MIPS64ELAndroidTriples[] = { |
| 1597 | "mips64el-linux-android"}; |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1598 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1599 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1600 | static const char *const PPCTriples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1601 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", |
| 1602 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; |
| 1603 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; |
| 1604 | static const char *const PPC64Triples[] = { |
| 1605 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", |
| 1606 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; |
| 1607 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; |
| 1608 | static const char *const PPC64LETriples[] = { |
| 1609 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", |
| 1610 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1611 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1612 | static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; |
| 1613 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", |
| 1614 | "sparcv8-linux-gnu"}; |
| 1615 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; |
| 1616 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", |
| 1617 | "sparcv9-linux-gnu"}; |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1618 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1619 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1620 | static const char *const SystemZTriples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1621 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", |
| 1622 | "s390x-suse-linux", "s390x-redhat-linux"}; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1623 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1624 | // Solaris. |
| 1625 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; |
| 1626 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", |
| 1627 | "i386-pc-solaris2.11"}; |
| 1628 | |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1629 | using std::begin; |
| 1630 | using std::end; |
| 1631 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1632 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 1633 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); |
| 1634 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1635 | return; |
| 1636 | } |
| 1637 | |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1638 | switch (TargetTriple.getArch()) { |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1639 | case llvm::Triple::aarch64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1640 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1641 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| 1642 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1643 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1644 | break; |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1645 | case llvm::Triple::aarch64_be: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1646 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1647 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| 1648 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1649 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1650 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1651 | case llvm::Triple::arm: |
| 1652 | case llvm::Triple::thumb: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1653 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1654 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1655 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1656 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1657 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1658 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1659 | break; |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1660 | case llvm::Triple::armeb: |
| 1661 | case llvm::Triple::thumbeb: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1662 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1663 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1664 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1665 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1666 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1667 | } |
| 1668 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1669 | case llvm::Triple::x86_64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1670 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1671 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| 1672 | // x32 is always available when x86_64 is available, so adding it as |
| 1673 | // secondary arch with x86_64 triples |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1674 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1675 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); |
| 1676 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1677 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1678 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1679 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1680 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1681 | break; |
| 1682 | case llvm::Triple::x86: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1683 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1684 | // MCU toolchain is 32 bit only and its triple alias is TargetTriple |
| 1685 | // itself, which will be appended below. |
| 1686 | if (!TargetTriple.isOSIAMCU()) { |
| 1687 | TripleAliases.append(begin(X86Triples), end(X86Triples)); |
| 1688 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1689 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| 1690 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1691 | break; |
| 1692 | case llvm::Triple::mips: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1693 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1694 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1695 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1696 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1697 | break; |
| 1698 | case llvm::Triple::mipsel: |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 1699 | if (TargetTriple.isAndroid()) { |
| 1700 | LibDirs.append(begin(MIPSELAndroidLibDirs), end(MIPSELAndroidLibDirs)); |
| 1701 | TripleAliases.append(begin(MIPSELAndroidTriples), |
| 1702 | end(MIPSELAndroidTriples)); |
| 1703 | BiarchLibDirs.append(begin(MIPS64ELAndroidLibDirs), |
| 1704 | end(MIPS64ELAndroidLibDirs)); |
| 1705 | BiarchTripleAliases.append(begin(MIPS64ELAndroidTriples), |
| 1706 | end(MIPS64ELAndroidTriples)); |
| 1707 | |
| 1708 | } else { |
| 1709 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1710 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1711 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1712 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1713 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| 1714 | } |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1715 | break; |
| 1716 | case llvm::Triple::mips64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1717 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1718 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| 1719 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1720 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1721 | break; |
| 1722 | case llvm::Triple::mips64el: |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 1723 | if (TargetTriple.isAndroid()) { |
| 1724 | LibDirs.append(begin(MIPS64ELAndroidLibDirs), |
| 1725 | end(MIPS64ELAndroidLibDirs)); |
| 1726 | TripleAliases.append(begin(MIPS64ELAndroidTriples), |
| 1727 | end(MIPS64ELAndroidTriples)); |
| 1728 | BiarchLibDirs.append(begin(MIPSELAndroidLibDirs), |
| 1729 | end(MIPSELAndroidLibDirs)); |
| 1730 | BiarchTripleAliases.append(begin(MIPSELAndroidTriples), |
| 1731 | end(MIPSELAndroidTriples)); |
| 1732 | |
| 1733 | } else { |
| 1734 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1735 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| 1736 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1737 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1738 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1739 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1740 | break; |
| 1741 | case llvm::Triple::ppc: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1742 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1743 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| 1744 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1745 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1746 | break; |
| 1747 | case llvm::Triple::ppc64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1748 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1749 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| 1750 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1751 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1752 | break; |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1753 | case llvm::Triple::ppc64le: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1754 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); |
| 1755 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1756 | break; |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1757 | case llvm::Triple::sparc: |
| Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1758 | case llvm::Triple::sparcel: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1759 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1760 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| 1761 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1762 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1763 | break; |
| 1764 | case llvm::Triple::sparcv9: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1765 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1766 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| 1767 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1768 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1769 | break; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1770 | case llvm::Triple::systemz: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1771 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); |
| 1772 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1773 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1774 | default: |
| 1775 | // By default, just rely on the standard lib directories and the original |
| 1776 | // triple. |
| 1777 | break; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1778 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1779 | |
| 1780 | // Always append the drivers target triple to the end, in case it doesn't |
| 1781 | // match any of our aliases. |
| 1782 | TripleAliases.push_back(TargetTriple.str()); |
| 1783 | |
| 1784 | // Also include the multiarch variant if it's different. |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1785 | if (TargetTriple.str() != BiarchTriple.str()) |
| 1786 | BiarchTripleAliases.push_back(BiarchTriple.str()); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 1789 | // Parses the contents of version.txt in an CUDA installation. It should |
| 1790 | // contain one line of the from e.g. "CUDA Version 7.5.2". |
| 1791 | static CudaVersion ParseCudaVersionFile(llvm::StringRef V) { |
| 1792 | if (!V.startswith("CUDA Version ")) |
| 1793 | return CudaVersion::UNKNOWN; |
| 1794 | V = V.substr(strlen("CUDA Version ")); |
| 1795 | int Major = -1, Minor = -1; |
| 1796 | auto First = V.split('.'); |
| 1797 | auto Second = First.second.split('.'); |
| Justin Lebar | a27654a | 2016-08-15 20:38:48 +0000 | [diff] [blame] | 1798 | if (First.first.getAsInteger(10, Major) || |
| 1799 | Second.first.getAsInteger(10, Minor)) |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 1800 | return CudaVersion::UNKNOWN; |
| 1801 | |
| 1802 | if (Major == 7 && Minor == 0) { |
| 1803 | // This doesn't appear to ever happen -- version.txt doesn't exist in the |
| 1804 | // CUDA 7 installs I've seen. But no harm in checking. |
| 1805 | return CudaVersion::CUDA_70; |
| 1806 | } |
| 1807 | if (Major == 7 && Minor == 5) |
| 1808 | return CudaVersion::CUDA_75; |
| 1809 | if (Major == 8 && Minor == 0) |
| 1810 | return CudaVersion::CUDA_80; |
| 1811 | return CudaVersion::UNKNOWN; |
| 1812 | } |
| 1813 | |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1814 | // \brief -- try common CUDA installation paths looking for files we need for |
| 1815 | // CUDA compilation. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1816 | void Generic_GCC::CudaInstallationDetector::init( |
| 1817 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { |
| NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1818 | SmallVector<std::string, 4> CudaPathCandidates; |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1819 | |
| 1820 | if (Args.hasArg(options::OPT_cuda_path_EQ)) |
| 1821 | CudaPathCandidates.push_back( |
| 1822 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); |
| 1823 | else { |
| 1824 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); |
| Artem Belevich | d4d9dc8 | 2016-09-28 17:47:40 +0000 | [diff] [blame] | 1825 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-8.0"); |
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 1826 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.5"); |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1827 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); |
| 1828 | } |
| 1829 | |
| Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1830 | for (const auto &CudaPath : CudaPathCandidates) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1831 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1832 | continue; |
| 1833 | |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1834 | InstallPath = CudaPath; |
| 1835 | BinPath = CudaPath + "/bin"; |
| 1836 | IncludePath = InstallPath + "/include"; |
| 1837 | LibDevicePath = InstallPath + "/nvvm/libdevice"; |
| 1838 | LibPath = InstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1839 | |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1840 | auto &FS = D.getVFS(); |
| 1841 | if (!(FS.exists(IncludePath) && FS.exists(BinPath) && FS.exists(LibPath) && |
| 1842 | FS.exists(LibDevicePath))) |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1843 | continue; |
| 1844 | |
| Artem Belevich | d4d9dc8 | 2016-09-28 17:47:40 +0000 | [diff] [blame] | 1845 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile = |
| 1846 | FS.getBufferForFile(InstallPath + "/version.txt"); |
| 1847 | if (!VersionFile) { |
| 1848 | // CUDA 7.0 doesn't have a version.txt, so guess that's our version if |
| 1849 | // version.txt isn't present. |
| 1850 | Version = CudaVersion::CUDA_70; |
| 1851 | } else { |
| 1852 | Version = ParseCudaVersionFile((*VersionFile)->getBuffer()); |
| 1853 | } |
| 1854 | |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1855 | std::error_code EC; |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1856 | for (llvm::sys::fs::directory_iterator LI(LibDevicePath, EC), LE; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1857 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 1858 | StringRef FilePath = LI->path(); |
| 1859 | StringRef FileName = llvm::sys::path::filename(FilePath); |
| 1860 | // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc |
| 1861 | const StringRef LibDeviceName = "libdevice."; |
| 1862 | if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc"))) |
| 1863 | continue; |
| 1864 | StringRef GpuArch = FileName.slice( |
| 1865 | LibDeviceName.size(), FileName.find('.', LibDeviceName.size())); |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1866 | LibDeviceMap[GpuArch] = FilePath.str(); |
| Artem Belevich | d4d9dc8 | 2016-09-28 17:47:40 +0000 | [diff] [blame] | 1867 | // Insert map entries for specifc devices with this compute |
| 1868 | // capability. NVCC's choice of the libdevice library version is |
| 1869 | // rather peculiar and depends on the CUDA version. |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1870 | if (GpuArch == "compute_20") { |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1871 | LibDeviceMap["sm_20"] = FilePath; |
| 1872 | LibDeviceMap["sm_21"] = FilePath; |
| Artem Belevich | 02a1e97 | 2016-08-02 23:12:51 +0000 | [diff] [blame] | 1873 | LibDeviceMap["sm_32"] = FilePath; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1874 | } else if (GpuArch == "compute_30") { |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1875 | LibDeviceMap["sm_30"] = FilePath; |
| Artem Belevich | d4d9dc8 | 2016-09-28 17:47:40 +0000 | [diff] [blame] | 1876 | if (Version < CudaVersion::CUDA_80) { |
| 1877 | LibDeviceMap["sm_50"] = FilePath; |
| 1878 | LibDeviceMap["sm_52"] = FilePath; |
| 1879 | LibDeviceMap["sm_53"] = FilePath; |
| 1880 | } |
| Artem Belevich | 02a1e97 | 2016-08-02 23:12:51 +0000 | [diff] [blame] | 1881 | LibDeviceMap["sm_60"] = FilePath; |
| 1882 | LibDeviceMap["sm_61"] = FilePath; |
| 1883 | LibDeviceMap["sm_62"] = FilePath; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1884 | } else if (GpuArch == "compute_35") { |
| Justin Lebar | 710c131 | 2016-07-06 21:21:43 +0000 | [diff] [blame] | 1885 | LibDeviceMap["sm_35"] = FilePath; |
| 1886 | LibDeviceMap["sm_37"] = FilePath; |
| Artem Belevich | ffa5fc5 | 2016-05-19 17:47:47 +0000 | [diff] [blame] | 1887 | } else if (GpuArch == "compute_50") { |
| Artem Belevich | d4d9dc8 | 2016-09-28 17:47:40 +0000 | [diff] [blame] | 1888 | if (Version >= CudaVersion::CUDA_80) { |
| 1889 | LibDeviceMap["sm_50"] = FilePath; |
| 1890 | LibDeviceMap["sm_52"] = FilePath; |
| 1891 | LibDeviceMap["sm_53"] = FilePath; |
| 1892 | } |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1893 | } |
| 1894 | } |
| 1895 | |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1896 | IsValid = true; |
| 1897 | break; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 1901 | void Generic_GCC::CudaInstallationDetector::CheckCudaVersionSupportsArch( |
| 1902 | CudaArch Arch) const { |
| 1903 | if (Arch == CudaArch::UNKNOWN || Version == CudaVersion::UNKNOWN || |
| 1904 | ArchsWithVersionTooLowErrors.count(Arch) > 0) |
| 1905 | return; |
| 1906 | |
| 1907 | auto RequiredVersion = MinVersionForCudaArch(Arch); |
| 1908 | if (Version < RequiredVersion) { |
| 1909 | ArchsWithVersionTooLowErrors.insert(Arch); |
| 1910 | D.Diag(diag::err_drv_cuda_version_too_low) |
| 1911 | << InstallPath << CudaArchToString(Arch) << CudaVersionToString(Version) |
| 1912 | << CudaVersionToString(RequiredVersion); |
| 1913 | } |
| 1914 | } |
| 1915 | |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1916 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { |
| 1917 | if (isValid()) |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 1918 | OS << "Found CUDA installation: " << InstallPath << ", version " |
| 1919 | << CudaVersionToString(Version) << "\n"; |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1922 | namespace { |
| 1923 | // 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] | 1924 | class FilterNonExistent { |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1925 | StringRef Base, File; |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1926 | vfs::FileSystem &VFS; |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1927 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1928 | public: |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1929 | FilterNonExistent(StringRef Base, StringRef File, vfs::FileSystem &VFS) |
| 1930 | : Base(Base), File(File), VFS(VFS) {} |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1931 | bool operator()(const Multilib &M) { |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1932 | return !VFS.exists(Base + M.gccSuffix() + File); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1933 | } |
| 1934 | }; |
| 1935 | } // end anonymous namespace |
| 1936 | |
| 1937 | static void addMultilibFlag(bool Enabled, const char *const Flag, |
| 1938 | std::vector<std::string> &Flags) { |
| 1939 | if (Enabled) |
| 1940 | Flags.push_back(std::string("+") + Flag); |
| 1941 | else |
| 1942 | Flags.push_back(std::string("-") + Flag); |
| 1943 | } |
| 1944 | |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 1945 | static bool isArmOrThumbArch(llvm::Triple::ArchType Arch) { |
| 1946 | return Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb; |
| 1947 | } |
| 1948 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1949 | static bool isMipsArch(llvm::Triple::ArchType Arch) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1950 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || |
| 1951 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1952 | } |
| 1953 | |
| 1954 | static bool isMips32(llvm::Triple::ArchType Arch) { |
| 1955 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; |
| 1956 | } |
| 1957 | |
| 1958 | static bool isMips64(llvm::Triple::ArchType Arch) { |
| 1959 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1960 | } |
| 1961 | |
| 1962 | static bool isMipsEL(llvm::Triple::ArchType Arch) { |
| 1963 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; |
| 1964 | } |
| 1965 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1966 | static bool isMips16(const ArgList &Args) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1967 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1968 | return A && A->getOption().matches(options::OPT_mips16); |
| 1969 | } |
| 1970 | |
| 1971 | static bool isMicroMips(const ArgList &Args) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1972 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1973 | return A && A->getOption().matches(options::OPT_mmicromips); |
| 1974 | } |
| 1975 | |
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1976 | namespace { |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1977 | struct DetectedMultilibs { |
| 1978 | /// The set of multilibs that the detected installation supports. |
| 1979 | MultilibSet Multilibs; |
| 1980 | |
| 1981 | /// The primary multilib appropriate for the given flags. |
| 1982 | Multilib SelectedMultilib; |
| 1983 | |
| 1984 | /// On Biarch systems, this corresponds to the default multilib when |
| 1985 | /// targeting the non-default multilib. Otherwise, it is empty. |
| 1986 | llvm::Optional<Multilib> BiarchSibling; |
| 1987 | }; |
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1988 | } // end anonymous namespace |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1989 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1990 | static Multilib makeMultilib(StringRef commonSuffix) { |
| 1991 | return Multilib(commonSuffix, commonSuffix, commonSuffix); |
| 1992 | } |
| 1993 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 1994 | static bool findMipsCsMultilibs(const Multilib::flags_list &Flags, |
| 1995 | FilterNonExistent &NonExistent, |
| 1996 | DetectedMultilibs &Result) { |
| 1997 | // Check for Code Sourcery toolchain multilibs |
| 1998 | MultilibSet CSMipsMultilibs; |
| 1999 | { |
| 2000 | auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2001 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2002 | auto MArchMicroMips = |
| 2003 | makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2004 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2005 | auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); |
| 2006 | |
| 2007 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
| 2008 | |
| 2009 | auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); |
| 2010 | |
| 2011 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
| 2012 | |
| 2013 | auto DefaultFloat = |
| 2014 | makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); |
| 2015 | |
| 2016 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
| 2017 | |
| 2018 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
| 2019 | |
| 2020 | // Note that this one's osSuffix is "" |
| 2021 | auto MAbi64 = makeMultilib("") |
| 2022 | .gccSuffix("/64") |
| 2023 | .includeSuffix("/64") |
| 2024 | .flag("+mabi=n64") |
| 2025 | .flag("-mabi=n32") |
| 2026 | .flag("-m32"); |
| 2027 | |
| 2028 | CSMipsMultilibs = |
| 2029 | MultilibSet() |
| 2030 | .Either(MArchMips16, MArchMicroMips, MArchDefault) |
| 2031 | .Maybe(UCLibc) |
| 2032 | .Either(SoftFloat, Nan2008, DefaultFloat) |
| 2033 | .FilterOut("/micromips/nan2008") |
| 2034 | .FilterOut("/mips16/nan2008") |
| 2035 | .Either(BigEndian, LittleEndian) |
| 2036 | .Maybe(MAbi64) |
| 2037 | .FilterOut("/mips16.*/64") |
| 2038 | .FilterOut("/micromips.*/64") |
| 2039 | .FilterOut(NonExistent) |
| 2040 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2041 | std::vector<std::string> Dirs({"/include"}); |
| 2042 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| 2043 | Dirs.push_back( |
| 2044 | "/../../../../mips-linux-gnu/libc/uclibc/usr/include"); |
| 2045 | else |
| 2046 | Dirs.push_back("/../../../../mips-linux-gnu/libc/usr/include"); |
| 2047 | return Dirs; |
| 2048 | }); |
| 2049 | } |
| 2050 | |
| 2051 | MultilibSet DebianMipsMultilibs; |
| 2052 | { |
| 2053 | Multilib MAbiN32 = |
| 2054 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); |
| 2055 | |
| 2056 | Multilib M64 = Multilib() |
| 2057 | .gccSuffix("/64") |
| 2058 | .includeSuffix("/64") |
| 2059 | .flag("+m64") |
| 2060 | .flag("-m32") |
| 2061 | .flag("-mabi=n32"); |
| 2062 | |
| 2063 | Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); |
| 2064 | |
| 2065 | DebianMipsMultilibs = |
| 2066 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); |
| 2067 | } |
| 2068 | |
| 2069 | // Sort candidates. Toolchain that best meets the directories tree goes first. |
| 2070 | // Then select the first toolchains matches command line flags. |
| 2071 | MultilibSet *Candidates[] = {&CSMipsMultilibs, &DebianMipsMultilibs}; |
| 2072 | if (CSMipsMultilibs.size() < DebianMipsMultilibs.size()) |
| 2073 | std::iter_swap(Candidates, Candidates + 1); |
| 2074 | for (const MultilibSet *Candidate : Candidates) { |
| 2075 | if (Candidate->select(Flags, Result.SelectedMultilib)) { |
| 2076 | if (Candidate == &DebianMipsMultilibs) |
| 2077 | Result.BiarchSibling = Multilib(); |
| 2078 | Result.Multilibs = *Candidate; |
| 2079 | return true; |
| 2080 | } |
| 2081 | } |
| 2082 | return false; |
| 2083 | } |
| 2084 | |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 2085 | static bool findMipsAndroidMultilibs(vfs::FileSystem &VFS, StringRef Path, |
| 2086 | const Multilib::flags_list &Flags, |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2087 | FilterNonExistent &NonExistent, |
| 2088 | DetectedMultilibs &Result) { |
| 2089 | |
| 2090 | MultilibSet AndroidMipsMultilibs = |
| 2091 | MultilibSet() |
| 2092 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) |
| 2093 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) |
| 2094 | .FilterOut(NonExistent); |
| 2095 | |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 2096 | MultilibSet AndroidMipselMultilibs = |
| 2097 | MultilibSet() |
| 2098 | .Either(Multilib().flag("+march=mips32"), |
| 2099 | Multilib("/mips-r2", "", "/mips-r2").flag("+march=mips32r2"), |
| 2100 | Multilib("/mips-r6", "", "/mips-r6").flag("+march=mips32r6")) |
| 2101 | .FilterOut(NonExistent); |
| 2102 | |
| 2103 | MultilibSet AndroidMips64elMultilibs = |
| 2104 | MultilibSet() |
| 2105 | .Either( |
| 2106 | Multilib().flag("+march=mips64r6"), |
| 2107 | Multilib("/32/mips-r1", "", "/mips-r1").flag("+march=mips32"), |
| 2108 | Multilib("/32/mips-r2", "", "/mips-r2").flag("+march=mips32r2"), |
| 2109 | Multilib("/32/mips-r6", "", "/mips-r6").flag("+march=mips32r6")) |
| 2110 | .FilterOut(NonExistent); |
| 2111 | |
| 2112 | MultilibSet *MS = &AndroidMipsMultilibs; |
| 2113 | if (VFS.exists(Path + "/mips-r6")) |
| 2114 | MS = &AndroidMipselMultilibs; |
| 2115 | else if (VFS.exists(Path + "/32")) |
| 2116 | MS = &AndroidMips64elMultilibs; |
| 2117 | if (MS->select(Flags, Result.SelectedMultilib)) { |
| 2118 | Result.Multilibs = *MS; |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2119 | return true; |
| 2120 | } |
| 2121 | return false; |
| 2122 | } |
| 2123 | |
| 2124 | static bool findMipsMuslMultilibs(const Multilib::flags_list &Flags, |
| 2125 | FilterNonExistent &NonExistent, |
| 2126 | DetectedMultilibs &Result) { |
| 2127 | // Musl toolchain multilibs |
| 2128 | MultilibSet MuslMipsMultilibs; |
| 2129 | { |
| 2130 | auto MArchMipsR2 = makeMultilib("") |
| 2131 | .osSuffix("/mips-r2-hard-musl") |
| 2132 | .flag("+EB") |
| 2133 | .flag("-EL") |
| 2134 | .flag("+march=mips32r2"); |
| 2135 | |
| 2136 | auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl") |
| 2137 | .flag("-EB") |
| 2138 | .flag("+EL") |
| 2139 | .flag("+march=mips32r2"); |
| 2140 | |
| 2141 | MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2); |
| 2142 | |
| 2143 | // Specify the callback that computes the include directories. |
| 2144 | MuslMipsMultilibs.setIncludeDirsCallback([](const Multilib &M) { |
| 2145 | return std::vector<std::string>( |
| 2146 | {"/../sysroot" + M.osSuffix() + "/usr/include"}); |
| 2147 | }); |
| 2148 | } |
| 2149 | if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 2150 | Result.Multilibs = MuslMipsMultilibs; |
| 2151 | return true; |
| 2152 | } |
| 2153 | return false; |
| 2154 | } |
| 2155 | |
| 2156 | static bool findMipsMtiMultilibs(const Multilib::flags_list &Flags, |
| 2157 | FilterNonExistent &NonExistent, |
| 2158 | DetectedMultilibs &Result) { |
| 2159 | // CodeScape MTI toolchain v1.2 and early. |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2160 | MultilibSet MtiMipsMultilibsV1; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2161 | { |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 2162 | auto MArchMips32 = makeMultilib("/mips32") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2163 | .flag("+m32") |
| 2164 | .flag("-m64") |
| 2165 | .flag("-mmicromips") |
| 2166 | .flag("+march=mips32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2167 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 2168 | auto MArchMicroMips = makeMultilib("/micromips") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2169 | .flag("+m32") |
| 2170 | .flag("-m64") |
| 2171 | .flag("+mmicromips"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2172 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 2173 | auto MArchMips64r2 = makeMultilib("/mips64r2") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2174 | .flag("-m32") |
| 2175 | .flag("+m64") |
| 2176 | .flag("+march=mips64r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2177 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2178 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( |
| 2179 | "-march=mips64r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2180 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 2181 | auto MArchDefault = makeMultilib("") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2182 | .flag("+m32") |
| 2183 | .flag("-m64") |
| 2184 | .flag("-mmicromips") |
| 2185 | .flag("+march=mips32r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2186 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2187 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2188 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2189 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2190 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2191 | auto MAbi64 = |
| 2192 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2193 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2194 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2195 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2196 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2197 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2198 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2199 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2200 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2201 | |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2202 | MtiMipsMultilibsV1 = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2203 | MultilibSet() |
| 2204 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, |
| 2205 | MArchDefault) |
| 2206 | .Maybe(UCLibc) |
| 2207 | .Maybe(Mips16) |
| 2208 | .FilterOut("/mips64/mips16") |
| 2209 | .FilterOut("/mips64r2/mips16") |
| 2210 | .FilterOut("/micromips/mips16") |
| 2211 | .Maybe(MAbi64) |
| 2212 | .FilterOut("/micromips/64") |
| 2213 | .FilterOut("/mips32/64") |
| 2214 | .FilterOut("^/64") |
| 2215 | .FilterOut("/mips16/64") |
| 2216 | .Either(BigEndian, LittleEndian) |
| 2217 | .Maybe(SoftFloat) |
| 2218 | .Maybe(Nan2008) |
| 2219 | .FilterOut(".*sof/nan2008") |
| 2220 | .FilterOut(NonExistent) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2221 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2222 | std::vector<std::string> Dirs({"/include"}); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2223 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2224 | Dirs.push_back("/../../../../sysroot/uclibc/usr/include"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2225 | else |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2226 | Dirs.push_back("/../../../../sysroot/usr/include"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2227 | return Dirs; |
| 2228 | }); |
| Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2231 | // CodeScape IMG toolchain starting from v1.3. |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2232 | MultilibSet MtiMipsMultilibsV2; |
| 2233 | { |
| 2234 | auto BeHard = makeMultilib("/mips-r2-hard") |
| 2235 | .flag("+EB") |
| 2236 | .flag("-msoft-float") |
| 2237 | .flag("-mnan=2008") |
| 2238 | .flag("-muclibc"); |
| 2239 | auto BeSoft = makeMultilib("/mips-r2-soft") |
| 2240 | .flag("+EB") |
| 2241 | .flag("+msoft-float") |
| 2242 | .flag("-mnan=2008"); |
| 2243 | auto ElHard = makeMultilib("/mipsel-r2-hard") |
| 2244 | .flag("+EL") |
| 2245 | .flag("-msoft-float") |
| 2246 | .flag("-mnan=2008") |
| 2247 | .flag("-muclibc"); |
| 2248 | auto ElSoft = makeMultilib("/mipsel-r2-soft") |
| 2249 | .flag("+EL") |
| 2250 | .flag("+msoft-float") |
| 2251 | .flag("-mnan=2008") |
| 2252 | .flag("-mmicromips"); |
| 2253 | auto BeHardNan = makeMultilib("/mips-r2-hard-nan2008") |
| 2254 | .flag("+EB") |
| 2255 | .flag("-msoft-float") |
| 2256 | .flag("+mnan=2008") |
| 2257 | .flag("-muclibc"); |
| 2258 | auto ElHardNan = makeMultilib("/mipsel-r2-hard-nan2008") |
| 2259 | .flag("+EL") |
| 2260 | .flag("-msoft-float") |
| 2261 | .flag("+mnan=2008") |
| 2262 | .flag("-muclibc") |
| 2263 | .flag("-mmicromips"); |
| 2264 | auto BeHardNanUclibc = makeMultilib("/mips-r2-hard-nan2008-uclibc") |
| 2265 | .flag("+EB") |
| 2266 | .flag("-msoft-float") |
| 2267 | .flag("+mnan=2008") |
| 2268 | .flag("+muclibc"); |
| 2269 | auto ElHardNanUclibc = makeMultilib("/mipsel-r2-hard-nan2008-uclibc") |
| 2270 | .flag("+EL") |
| 2271 | .flag("-msoft-float") |
| 2272 | .flag("+mnan=2008") |
| 2273 | .flag("+muclibc"); |
| 2274 | auto BeHardUclibc = makeMultilib("/mips-r2-hard-uclibc") |
| 2275 | .flag("+EB") |
| 2276 | .flag("-msoft-float") |
| 2277 | .flag("-mnan=2008") |
| 2278 | .flag("+muclibc"); |
| 2279 | auto ElHardUclibc = makeMultilib("/mipsel-r2-hard-uclibc") |
| 2280 | .flag("+EL") |
| 2281 | .flag("-msoft-float") |
| 2282 | .flag("-mnan=2008") |
| 2283 | .flag("+muclibc"); |
| 2284 | auto ElMicroHardNan = makeMultilib("/micromipsel-r2-hard-nan2008") |
| 2285 | .flag("+EL") |
| 2286 | .flag("-msoft-float") |
| 2287 | .flag("+mnan=2008") |
| 2288 | .flag("+mmicromips"); |
| 2289 | auto ElMicroSoft = makeMultilib("/micromipsel-r2-soft") |
| 2290 | .flag("+EL") |
| 2291 | .flag("+msoft-float") |
| 2292 | .flag("-mnan=2008") |
| 2293 | .flag("+mmicromips"); |
| 2294 | |
| 2295 | auto O32 = |
| 2296 | makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64"); |
| 2297 | auto N32 = |
| 2298 | makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64"); |
| 2299 | auto N64 = |
| 2300 | makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64"); |
| 2301 | |
| 2302 | MtiMipsMultilibsV2 = |
| 2303 | MultilibSet() |
| 2304 | .Either({BeHard, BeSoft, ElHard, ElSoft, BeHardNan, ElHardNan, |
| 2305 | BeHardNanUclibc, ElHardNanUclibc, BeHardUclibc, |
| 2306 | ElHardUclibc, ElMicroHardNan, ElMicroSoft}) |
| 2307 | .Either(O32, N32, N64) |
| 2308 | .FilterOut(NonExistent) |
| 2309 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2310 | return std::vector<std::string>({"/../../../../sysroot" + |
| 2311 | M.includeSuffix() + |
| 2312 | "/../usr/include"}); |
| 2313 | }) |
| 2314 | .setFilePathsCallback([](const Multilib &M) { |
| 2315 | return std::vector<std::string>( |
| 2316 | {"/../../../../mips-mti-linux-gnu/lib" + M.gccSuffix()}); |
| 2317 | }); |
| 2318 | } |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2319 | for (auto Candidate : {&MtiMipsMultilibsV1, &MtiMipsMultilibsV2}) { |
| 2320 | if (Candidate->select(Flags, Result.SelectedMultilib)) { |
| 2321 | Result.Multilibs = *Candidate; |
| 2322 | return true; |
| 2323 | } |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2324 | } |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2325 | return false; |
| 2326 | } |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2327 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2328 | static bool findMipsImgMultilibs(const Multilib::flags_list &Flags, |
| 2329 | FilterNonExistent &NonExistent, |
| 2330 | DetectedMultilibs &Result) { |
| 2331 | // CodeScape IMG toolchain v1.2 and early. |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2332 | MultilibSet ImgMultilibsV1; |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2333 | { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2334 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2335 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2336 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2337 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2338 | auto MAbi64 = |
| 2339 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2340 | |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2341 | ImgMultilibsV1 = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2342 | MultilibSet() |
| 2343 | .Maybe(Mips64r6) |
| 2344 | .Maybe(MAbi64) |
| 2345 | .Maybe(LittleEndian) |
| 2346 | .FilterOut(NonExistent) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2347 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2348 | return std::vector<std::string>( |
| 2349 | {"/include", "/../../../../sysroot/usr/include"}); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2350 | }); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2353 | // CodeScape IMG toolchain starting from v1.3. |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2354 | MultilibSet ImgMultilibsV2; |
| 2355 | { |
| 2356 | auto BeHard = makeMultilib("/mips-r6-hard") |
| 2357 | .flag("+EB") |
| 2358 | .flag("-msoft-float") |
| 2359 | .flag("-mmicromips"); |
| 2360 | auto BeSoft = makeMultilib("/mips-r6-soft") |
| 2361 | .flag("+EB") |
| 2362 | .flag("+msoft-float") |
| 2363 | .flag("-mmicromips"); |
| 2364 | auto ElHard = makeMultilib("/mipsel-r6-hard") |
| 2365 | .flag("+EL") |
| 2366 | .flag("-msoft-float") |
| 2367 | .flag("-mmicromips"); |
| 2368 | auto ElSoft = makeMultilib("/mipsel-r6-soft") |
| 2369 | .flag("+EL") |
| 2370 | .flag("+msoft-float") |
| 2371 | .flag("-mmicromips"); |
| 2372 | auto BeMicroHard = makeMultilib("/micromips-r6-hard") |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2373 | .flag("+EB") |
| 2374 | .flag("-msoft-float") |
| 2375 | .flag("+mmicromips"); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2376 | auto BeMicroSoft = makeMultilib("/micromips-r6-soft") |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2377 | .flag("+EB") |
| 2378 | .flag("+msoft-float") |
| 2379 | .flag("+mmicromips"); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2380 | auto ElMicroHard = makeMultilib("/micromipsel-r6-hard") |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2381 | .flag("+EL") |
| 2382 | .flag("-msoft-float") |
| 2383 | .flag("+mmicromips"); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2384 | auto ElMicroSoft = makeMultilib("/micromipsel-r6-soft") |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2385 | .flag("+EL") |
| 2386 | .flag("+msoft-float") |
| 2387 | .flag("+mmicromips"); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2388 | |
| 2389 | auto O32 = |
| 2390 | makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64"); |
| 2391 | auto N32 = |
| 2392 | makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64"); |
| 2393 | auto N64 = |
| 2394 | makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64"); |
| 2395 | |
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2396 | ImgMultilibsV2 = |
| 2397 | MultilibSet() |
| 2398 | .Either({BeHard, BeSoft, ElHard, ElSoft, BeMicroHard, BeMicroSoft, |
| 2399 | ElMicroHard, ElMicroSoft}) |
| 2400 | .Either(O32, N32, N64) |
| 2401 | .FilterOut(NonExistent) |
| 2402 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2403 | return std::vector<std::string>({"/../../../../sysroot" + |
| 2404 | M.includeSuffix() + |
| 2405 | "/../usr/include"}); |
| 2406 | }) |
| 2407 | .setFilePathsCallback([](const Multilib &M) { |
| 2408 | return std::vector<std::string>( |
| 2409 | {"/../../../../mips-img-linux-gnu/lib" + M.gccSuffix()}); |
| 2410 | }); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2411 | } |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2412 | for (auto Candidate : {&ImgMultilibsV1, &ImgMultilibsV2}) { |
| 2413 | if (Candidate->select(Flags, Result.SelectedMultilib)) { |
| 2414 | Result.Multilibs = *Candidate; |
| 2415 | return true; |
| 2416 | } |
| 2417 | } |
| 2418 | return false; |
| 2419 | } |
| 2420 | |
| 2421 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, |
| 2422 | StringRef Path, const ArgList &Args, |
| 2423 | DetectedMultilibs &Result) { |
| 2424 | FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS()); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2425 | |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2426 | StringRef CPUName; |
| 2427 | StringRef ABIName; |
| 2428 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); |
| 2429 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2430 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| 2431 | |
| 2432 | Multilib::flags_list Flags; |
| 2433 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); |
| 2434 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); |
| 2435 | addMultilibFlag(isMips16(Args), "mips16", Flags); |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2436 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2437 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || |
| Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 2438 | CPUName == "mips32r5" || CPUName == "p5600", |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2439 | "march=mips32r2", Flags); |
| Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 2440 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2441 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2442 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || |
| 2443 | CPUName == "mips64r5" || CPUName == "octeon", |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2444 | "march=mips64r2", Flags); |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 2445 | addMultilibFlag(CPUName == "mips64r6", "march=mips64r6", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2446 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); |
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2447 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); |
| Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 2448 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", |
| 2449 | Flags); |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2450 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); |
| 2451 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2452 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2453 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2454 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2455 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2456 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2457 | if (TargetTriple.isAndroid()) |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 2458 | return findMipsAndroidMultilibs(D.getVFS(), Path, Flags, NonExistent, |
| 2459 | Result); |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2460 | |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2461 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && |
| 2462 | TargetTriple.getOS() == llvm::Triple::Linux && |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2463 | TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) |
| 2464 | return findMipsMuslMultilibs(Flags, NonExistent, Result); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2465 | |
| Simon Atanasyan | 4f3fe5b | 2016-05-22 15:28:34 +0000 | [diff] [blame] | 2466 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && |
| 2467 | TargetTriple.getOS() == llvm::Triple::Linux && |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2468 | TargetTriple.getEnvironment() == llvm::Triple::GNU) |
| 2469 | return findMipsMtiMultilibs(Flags, NonExistent, Result); |
| Simon Atanasyan | 4f3fe5b | 2016-05-22 15:28:34 +0000 | [diff] [blame] | 2470 | |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2471 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && |
| 2472 | TargetTriple.getOS() == llvm::Triple::Linux && |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2473 | TargetTriple.getEnvironment() == llvm::Triple::GNU) |
| 2474 | return findMipsImgMultilibs(Flags, NonExistent, Result); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2475 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2476 | if (findMipsCsMultilibs(Flags, NonExistent, Result)) |
| 2477 | return true; |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2478 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2479 | // Fallback to the regular toolchain-tree structure. |
| 2480 | Multilib Default; |
| 2481 | Result.Multilibs.push_back(Default); |
| 2482 | Result.Multilibs.FilterOut(NonExistent); |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2483 | |
| Simon Atanasyan | b4abcc5 | 2016-06-22 20:00:50 +0000 | [diff] [blame] | 2484 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { |
| 2485 | Result.BiarchSibling = Multilib(); |
| 2486 | return true; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2489 | return false; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2492 | static void findAndroidArmMultilibs(const Driver &D, |
| 2493 | const llvm::Triple &TargetTriple, |
| 2494 | StringRef Path, const ArgList &Args, |
| 2495 | DetectedMultilibs &Result) { |
| 2496 | // Find multilibs with subdirectories like armv7-a, thumb, armv7-a/thumb. |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 2497 | FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS()); |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2498 | Multilib ArmV7Multilib = makeMultilib("/armv7-a") |
| 2499 | .flag("+armv7") |
| 2500 | .flag("-thumb"); |
| 2501 | Multilib ThumbMultilib = makeMultilib("/thumb") |
| 2502 | .flag("-armv7") |
| 2503 | .flag("+thumb"); |
| 2504 | Multilib ArmV7ThumbMultilib = makeMultilib("/armv7-a/thumb") |
| 2505 | .flag("+armv7") |
| 2506 | .flag("+thumb"); |
| 2507 | Multilib DefaultMultilib = makeMultilib("") |
| 2508 | .flag("-armv7") |
| 2509 | .flag("-thumb"); |
| 2510 | MultilibSet AndroidArmMultilibs = |
| 2511 | MultilibSet() |
| 2512 | .Either(ThumbMultilib, ArmV7Multilib, |
| 2513 | ArmV7ThumbMultilib, DefaultMultilib) |
| 2514 | .FilterOut(NonExistent); |
| 2515 | |
| 2516 | Multilib::flags_list Flags; |
| 2517 | llvm::StringRef Arch = Args.getLastArgValue(options::OPT_march_EQ); |
| 2518 | bool IsArmArch = TargetTriple.getArch() == llvm::Triple::arm; |
| 2519 | bool IsThumbArch = TargetTriple.getArch() == llvm::Triple::thumb; |
| 2520 | bool IsV7SubArch = TargetTriple.getSubArch() == llvm::Triple::ARMSubArch_v7; |
| 2521 | bool IsThumbMode = IsThumbArch || |
| 2522 | Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, false) || |
| 2523 | (IsArmArch && llvm::ARM::parseArchISA(Arch) == llvm::ARM::IK_THUMB); |
| 2524 | bool IsArmV7Mode = (IsArmArch || IsThumbArch) && |
| 2525 | (llvm::ARM::parseArchVersion(Arch) == 7 || |
| 2526 | (IsArmArch && Arch == "" && IsV7SubArch)); |
| 2527 | addMultilibFlag(IsArmV7Mode, "armv7", Flags); |
| 2528 | addMultilibFlag(IsThumbMode, "thumb", Flags); |
| 2529 | |
| 2530 | if (AndroidArmMultilibs.select(Flags, Result.SelectedMultilib)) |
| 2531 | Result.Multilibs = AndroidArmMultilibs; |
| 2532 | } |
| 2533 | |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2534 | static bool findBiarchMultilibs(const Driver &D, |
| 2535 | const llvm::Triple &TargetTriple, |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2536 | StringRef Path, const ArgList &Args, |
| 2537 | bool NeedsBiarchSuffix, |
| 2538 | DetectedMultilibs &Result) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2539 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs |
| 2540 | // in what would normally be GCCInstallPath and put the 64-bit |
| 2541 | // libs in a subdirectory named 64. The simple logic we follow is that |
| 2542 | // *if* there is a subdirectory of the right name with crtbegin.o in it, |
| 2543 | // we use that. If not, and if not a biarch triple alias, we look for |
| 2544 | // crtbegin.o without the subdirectory. |
| 2545 | |
| 2546 | Multilib Default; |
| 2547 | Multilib Alt64 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2548 | .gccSuffix("/64") |
| 2549 | .includeSuffix("/64") |
| 2550 | .flag("-m32") |
| 2551 | .flag("+m64") |
| 2552 | .flag("-mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2553 | Multilib Alt32 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2554 | .gccSuffix("/32") |
| 2555 | .includeSuffix("/32") |
| 2556 | .flag("+m32") |
| 2557 | .flag("-m64") |
| 2558 | .flag("-mx32"); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2559 | Multilib Altx32 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2560 | .gccSuffix("/x32") |
| 2561 | .includeSuffix("/x32") |
| 2562 | .flag("-m32") |
| 2563 | .flag("-m64") |
| 2564 | .flag("+mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2565 | |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 2566 | // GCC toolchain for IAMCU doesn't have crtbegin.o, so look for libgcc.a. |
| 2567 | FilterNonExistent NonExistent( |
| 2568 | Path, TargetTriple.isOSIAMCU() ? "/libgcc.a" : "/crtbegin.o", D.getVFS()); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2569 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2570 | // Determine default multilib from: 32, 64, x32 |
| 2571 | // Also handle cases such as 64 on 32, 32 on 64, etc. |
| 2572 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; |
| David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2573 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; |
| Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2574 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2575 | Want = WANT64; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2576 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2577 | Want = WANT64; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2578 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2579 | Want = WANT32; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2580 | else { |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2581 | if (TargetTriple.isArch32Bit()) |
| 2582 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2583 | else if (IsX32) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2584 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2585 | else |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2586 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; |
| Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2589 | if (Want == WANT32) |
| 2590 | Default.flag("+m32").flag("-m64").flag("-mx32"); |
| 2591 | else if (Want == WANT64) |
| 2592 | Default.flag("-m32").flag("+m64").flag("-mx32"); |
| 2593 | else if (Want == WANTX32) |
| 2594 | Default.flag("-m32").flag("-m64").flag("+mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2595 | else |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2596 | return false; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2597 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2598 | Result.Multilibs.push_back(Default); |
| 2599 | Result.Multilibs.push_back(Alt64); |
| 2600 | Result.Multilibs.push_back(Alt32); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2601 | Result.Multilibs.push_back(Altx32); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2602 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2603 | Result.Multilibs.FilterOut(NonExistent); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2604 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2605 | Multilib::flags_list Flags; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2606 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2607 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2608 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2609 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2610 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2611 | return false; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2612 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2613 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2614 | Result.SelectedMultilib == Altx32) |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2615 | Result.BiarchSibling = Default; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2616 | |
| 2617 | return true; |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2620 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( |
| 2621 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, |
| 2622 | const std::string &LibDir, StringRef CandidateTriple, |
| 2623 | bool NeedsBiarchSuffix) { |
| 2624 | // Solaris is a special case. The GCC installation is under |
| 2625 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we |
| 2626 | // need to iterate twice. |
| 2627 | std::error_code EC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2628 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; |
| 2629 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 2630 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2631 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| 2632 | |
| 2633 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2634 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2635 | continue; // Saw this path before; no need to look at it again. |
| 2636 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| 2637 | continue; |
| 2638 | if (CandidateVersion <= Version) |
| 2639 | continue; |
| 2640 | |
| 2641 | GCCInstallPath = |
| 2642 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2643 | if (!D.getVFS().exists(GCCInstallPath)) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2644 | continue; |
| 2645 | |
| 2646 | // If we make it here there has to be at least one GCC version, let's just |
| 2647 | // use the latest one. |
| 2648 | std::error_code EEC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2649 | for (vfs::directory_iterator |
| 2650 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), |
| 2651 | LLE; |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2652 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { |
| 2653 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2654 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2655 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); |
| 2656 | |
| 2657 | if (CandidateSubVersion > Version) |
| 2658 | Version = CandidateSubVersion; |
| 2659 | } |
| 2660 | |
| 2661 | GCCTriple.setTriple(CandidateTriple); |
| 2662 | |
| 2663 | GCCInstallPath += "/" + Version.Text; |
| 2664 | GCCParentLibPath = GCCInstallPath + "/../../../../"; |
| 2665 | |
| 2666 | IsValid = true; |
| 2667 | } |
| 2668 | } |
| 2669 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2670 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2671 | const llvm::Triple &TargetTriple, const ArgList &Args, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2672 | const std::string &LibDir, StringRef CandidateTriple, |
| 2673 | bool NeedsBiarchSuffix) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2674 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2675 | // There are various different suffixes involving the triple we |
| 2676 | // 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] | 2677 | // up to the lib directory. Specifically, the number of "up" steps |
| 2678 | // in the second half of each row is 1 + the number of path separators |
| 2679 | // in the first half. |
| 2680 | const std::string LibAndInstallSuffixes[][2] = { |
| 2681 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, |
| 2682 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2683 | // Debian puts cross-compilers in gcc-cross |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2684 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, |
| 2685 | |
| 2686 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), |
| 2687 | "/../../../.."}, |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2688 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2689 | // The Freescale PPC SDK has the gcc libraries in |
| 2690 | // <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] | 2691 | {"/" + CandidateTriple.str(), "/../.."}, |
| Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2692 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2693 | // Ubuntu has a strange mis-matched pair of triples that this happens to |
| 2694 | // match. |
| 2695 | // FIXME: It may be worthwhile to generalize this and look for a second |
| 2696 | // triple. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2697 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; |
| 2698 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2699 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 2700 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, |
| 2701 | NeedsBiarchSuffix); |
| 2702 | return; |
| 2703 | } |
| 2704 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2705 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2706 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - |
| 2707 | (TargetArch != llvm::Triple::x86)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2708 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2709 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; |
| Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2710 | std::error_code EC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2711 | for (vfs::directory_iterator |
| 2712 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), |
| 2713 | LE; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2714 | !EC && LI != LE; LI = LI.increment(EC)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2715 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2716 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2717 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2718 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2719 | continue; // Saw this path before; no need to look at it again. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2720 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2721 | continue; |
| 2722 | if (CandidateVersion <= Version) |
| 2723 | continue; |
| Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2724 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2725 | DetectedMultilibs Detected; |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2726 | |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2727 | // Android standalone toolchain could have multilibs for ARM and Thumb. |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2728 | // Debian mips multilibs behave more like the rest of the biarch ones, |
| 2729 | // so handle them there |
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2730 | if (isArmOrThumbArch(TargetArch) && TargetTriple.isAndroid()) { |
| 2731 | // It should also work without multilibs in a simplified toolchain. |
| 2732 | findAndroidArmMultilibs(D, TargetTriple, LI->getName(), Args, Detected); |
| 2733 | } else if (isMipsArch(TargetArch)) { |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2734 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2735 | continue; |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2736 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2737 | NeedsBiarchSuffix, Detected)) { |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2738 | continue; |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2739 | } |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2740 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2741 | Multilibs = Detected.Multilibs; |
| 2742 | SelectedMultilib = Detected.SelectedMultilib; |
| 2743 | BiarchSibling = Detected.BiarchSibling; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2744 | Version = CandidateVersion; |
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2745 | GCCTriple.setTriple(CandidateTriple); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2746 | // FIXME: We hack together the directory name here instead of |
| 2747 | // using LI to ensure stable path separators across Windows and |
| 2748 | // Linux. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2749 | GCCInstallPath = |
| 2750 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); |
| 2751 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2752 | IsValid = true; |
| 2753 | } |
| 2754 | } |
| 2755 | } |
| 2756 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2757 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2758 | const ArgList &Args) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2759 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2760 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2761 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2762 | getProgramPaths().push_back(getDriver().Dir); |
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2763 | } |
| 2764 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2765 | Generic_GCC::~Generic_GCC() {} |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2766 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2767 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { |
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2768 | switch (AC) { |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2769 | case Action::PreprocessJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2770 | if (!Preprocess) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2771 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2772 | return Preprocess.get(); |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2773 | case Action::CompileJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2774 | if (!Compile) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2775 | Compile.reset(new tools::gcc::Compiler(*this)); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2776 | return Compile.get(); |
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2777 | default: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2778 | return ToolChain::getTool(AC); |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2779 | } |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2780 | } |
| 2781 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2782 | Tool *Generic_GCC::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2783 | return new tools::gnutools::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2786 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2787 | |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2788 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { |
| 2789 | // Print the information about how we detected the GCC installation. |
| 2790 | GCCInstallation.print(OS); |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2791 | CudaInstallation.print(OS); |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2794 | bool Generic_GCC::IsUnwindTablesDefault() const { |
| Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2795 | return getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2798 | bool Generic_GCC::isPICDefault() const { |
| 2799 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2800 | } |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2801 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2802 | bool Generic_GCC::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2803 | |
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2804 | bool Generic_GCC::isPICDefaultForced() const { |
| 2805 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2806 | } |
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2807 | |
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2808 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2809 | switch (getTriple().getArch()) { |
| 2810 | case llvm::Triple::x86: |
| 2811 | case llvm::Triple::x86_64: |
| 2812 | case llvm::Triple::aarch64: |
| 2813 | case llvm::Triple::aarch64_be: |
| 2814 | case llvm::Triple::arm: |
| 2815 | case llvm::Triple::armeb: |
| Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2816 | case llvm::Triple::bpfel: |
| 2817 | case llvm::Triple::bpfeb: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2818 | case llvm::Triple::thumb: |
| 2819 | case llvm::Triple::thumbeb: |
| 2820 | case llvm::Triple::ppc: |
| 2821 | case llvm::Triple::ppc64: |
| 2822 | case llvm::Triple::ppc64le: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2823 | case llvm::Triple::systemz: |
| Daniel Sanders | e160f83 | 2016-05-14 12:43:08 +0000 | [diff] [blame] | 2824 | case llvm::Triple::mips: |
| 2825 | case llvm::Triple::mipsel: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2826 | return true; |
| Simon Dardis | 9edf96e | 2016-09-15 14:01:55 +0000 | [diff] [blame] | 2827 | case llvm::Triple::mips64: |
| 2828 | case llvm::Triple::mips64el: |
| 2829 | // Enabled for Debian mips64/mips64el only. Other targets are unable to |
| 2830 | // distinguish N32 from N64. |
| 2831 | if (getTriple().getEnvironment() == llvm::Triple::GNUABI64) |
| 2832 | return true; |
| 2833 | return false; |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2834 | default: |
| 2835 | return false; |
| 2836 | } |
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 2839 | void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2840 | ArgStringList &CC1Args) const { |
| 2841 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2842 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2843 | return; |
| 2844 | |
| 2845 | switch (GetCXXStdlibType(DriverArgs)) { |
| 2846 | case ToolChain::CST_Libcxx: { |
| 2847 | std::string Path = findLibCxxIncludePath(); |
| 2848 | if (!Path.empty()) |
| 2849 | addSystemInclude(DriverArgs, CC1Args, Path); |
| 2850 | break; |
| 2851 | } |
| 2852 | |
| 2853 | case ToolChain::CST_Libstdcxx: |
| 2854 | addLibStdCxxIncludePaths(DriverArgs, CC1Args); |
| 2855 | break; |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | std::string Generic_GCC::findLibCxxIncludePath() const { |
| 2860 | // FIXME: The Linux behavior would probaby be a better approach here. |
| 2861 | return getDriver().SysRoot + "/usr/include/c++/v1"; |
| 2862 | } |
| 2863 | |
| 2864 | void |
| 2865 | Generic_GCC::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
| 2866 | llvm::opt::ArgStringList &CC1Args) const { |
| 2867 | // By default, we don't assume we know where libstdc++ might be installed. |
| 2868 | // FIXME: If we have a valid GCCInstallation, use it. |
| 2869 | } |
| 2870 | |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2871 | /// \brief Helper to add the variant paths of a libstdc++ installation. |
| 2872 | bool Generic_GCC::addLibStdCXXIncludePaths( |
| 2873 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, |
| 2874 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, |
| 2875 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2876 | if (!getVFS().exists(Base + Suffix)) |
| 2877 | return false; |
| 2878 | |
| 2879 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); |
| 2880 | |
| 2881 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If |
| 2882 | // that path exists or we have neither a GCC nor target multiarch triple, use |
| 2883 | // this vanilla search path. |
| 2884 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || |
| 2885 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { |
| 2886 | addSystemInclude(DriverArgs, CC1Args, |
| 2887 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); |
| 2888 | } else { |
| 2889 | // Otherwise try to use multiarch naming schemes which have normalized the |
| 2890 | // triples and put the triple before the suffix. |
| 2891 | // |
| 2892 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and |
| 2893 | // the target triple, so we support that here. |
| 2894 | addSystemInclude(DriverArgs, CC1Args, |
| 2895 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); |
| 2896 | addSystemInclude(DriverArgs, CC1Args, |
| 2897 | Base + "/" + TargetMultiarchTriple + Suffix); |
| 2898 | } |
| 2899 | |
| 2900 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); |
| 2901 | return true; |
| 2902 | } |
| 2903 | |
| Samuel Antao | 31fef98 | 2016-10-27 17:39:44 +0000 | [diff] [blame] | 2904 | llvm::opt::DerivedArgList * |
| 2905 | Generic_GCC::TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef, |
| 2906 | Action::OffloadKind DeviceOffloadKind) const { |
| 2907 | |
| 2908 | // If this tool chain is used for an OpenMP offloading device we have to make |
| 2909 | // sure we always generate a shared library regardless of the commands the |
| 2910 | // user passed to the host. This is required because the runtime library |
| 2911 | // is required to load the device image dynamically at run time. |
| 2912 | if (DeviceOffloadKind == Action::OFK_OpenMP) { |
| 2913 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 2914 | const OptTable &Opts = getDriver().getOpts(); |
| 2915 | |
| 2916 | // Request the shared library. Given that these options are decided |
| 2917 | // implicitly, they do not refer to any base argument. |
| 2918 | DAL->AddFlagArg(/*BaseArg=*/nullptr, Opts.getOption(options::OPT_shared)); |
| 2919 | DAL->AddFlagArg(/*BaseArg=*/nullptr, Opts.getOption(options::OPT_fPIC)); |
| 2920 | |
| 2921 | // Filter all the arguments we don't care passing to the offloading |
| 2922 | // toolchain as they can mess up with the creation of a shared library. |
| 2923 | for (auto *A : Args) { |
| 2924 | switch ((options::ID)A->getOption().getID()) { |
| 2925 | default: |
| 2926 | DAL->append(A); |
| 2927 | break; |
| 2928 | case options::OPT_shared: |
| 2929 | case options::OPT_dynamic: |
| 2930 | case options::OPT_static: |
| 2931 | case options::OPT_fPIC: |
| 2932 | case options::OPT_fno_PIC: |
| 2933 | case options::OPT_fpic: |
| 2934 | case options::OPT_fno_pic: |
| 2935 | case options::OPT_fPIE: |
| 2936 | case options::OPT_fno_PIE: |
| 2937 | case options::OPT_fpie: |
| 2938 | case options::OPT_fno_pie: |
| 2939 | break; |
| 2940 | } |
| 2941 | } |
| 2942 | return DAL; |
| 2943 | } |
| 2944 | return nullptr; |
| 2945 | } |
| 2946 | |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2947 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, |
| 2948 | ArgStringList &CC1Args) const { |
| 2949 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2950 | bool UseInitArrayDefault = |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2951 | getTriple().getArch() == llvm::Triple::aarch64 || |
| Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2952 | getTriple().getArch() == llvm::Triple::aarch64_be || |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2953 | (getTriple().getOS() == llvm::Triple::Linux && |
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2954 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2955 | getTriple().getOS() == llvm::Triple::NaCl || |
| 2956 | (getTriple().getVendor() == llvm::Triple::MipsTechnologies && |
| 2957 | !getTriple().hasEnvironment()); |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2958 | |
| 2959 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2960 | options::OPT_fno_use_init_array, UseInitArrayDefault)) |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2961 | CC1Args.push_back("-fuse-init-array"); |
| 2962 | } |
| 2963 | |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2964 | /// Mips Toolchain |
| 2965 | MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D, |
| 2966 | const llvm::Triple &Triple, |
| 2967 | const ArgList &Args) |
| 2968 | : Linux(D, Triple, Args) { |
| 2969 | // Select the correct multilib according to the given arguments. |
| 2970 | DetectedMultilibs Result; |
| 2971 | findMIPSMultilibs(D, Triple, "", Args, Result); |
| 2972 | Multilibs = Result.Multilibs; |
| 2973 | SelectedMultilib = Result.SelectedMultilib; |
| 2974 | |
| 2975 | // Find out the library suffix based on the ABI. |
| 2976 | LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple); |
| 2977 | getFilePaths().clear(); |
| 2978 | getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix); |
| 2979 | |
| 2980 | // Use LLD by default. |
| Peter Collingbourne | 39719a7 | 2015-11-20 20:49:39 +0000 | [diff] [blame] | 2981 | DefaultLinker = "lld"; |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | void MipsLLVMToolChain::AddClangSystemIncludeArgs( |
| 2985 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2986 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2987 | return; |
| 2988 | |
| 2989 | const Driver &D = getDriver(); |
| 2990 | |
| 2991 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 2992 | SmallString<128> P(D.ResourceDir); |
| 2993 | llvm::sys::path::append(P, "include"); |
| 2994 | addSystemInclude(DriverArgs, CC1Args, P); |
| 2995 | } |
| 2996 | |
| 2997 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2998 | return; |
| 2999 | |
| 3000 | const auto &Callback = Multilibs.includeDirsCallback(); |
| 3001 | if (Callback) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 3002 | for (const auto &Path : Callback(SelectedMultilib)) |
| 3003 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, |
| 3004 | D.getInstalledDir() + Path); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | Tool *MipsLLVMToolChain::buildLinker() const { |
| 3009 | return new tools::gnutools::Linker(*this); |
| 3010 | } |
| 3011 | |
| 3012 | std::string MipsLLVMToolChain::computeSysRoot() const { |
| 3013 | if (!getDriver().SysRoot.empty()) |
| 3014 | return getDriver().SysRoot + SelectedMultilib.osSuffix(); |
| 3015 | |
| 3016 | const std::string InstalledDir(getDriver().getInstalledDir()); |
| 3017 | std::string SysRootPath = |
| 3018 | InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix(); |
| 3019 | if (llvm::sys::fs::exists(SysRootPath)) |
| 3020 | return SysRootPath; |
| 3021 | |
| 3022 | return std::string(); |
| 3023 | } |
| 3024 | |
| 3025 | ToolChain::CXXStdlibType |
| 3026 | MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| 3027 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 3028 | if (A) { |
| 3029 | StringRef Value = A->getValue(); |
| 3030 | if (Value != "libc++") |
| 3031 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) |
| 3032 | << A->getAsString(Args); |
| 3033 | } |
| 3034 | |
| 3035 | return ToolChain::CST_Libcxx; |
| 3036 | } |
| 3037 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3038 | std::string MipsLLVMToolChain::findLibCxxIncludePath() const { |
| 3039 | if (const auto &Callback = Multilibs.includeDirsCallback()) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 3040 | for (std::string Path : Callback(SelectedMultilib)) { |
| 3041 | Path = getDriver().getInstalledDir() + Path + "/c++/v1"; |
| 3042 | if (llvm::sys::fs::exists(Path)) { |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3043 | return Path; |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 3044 | } |
| 3045 | } |
| 3046 | } |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3047 | return ""; |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3051 | ArgStringList &CmdArgs) const { |
| 3052 | assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) && |
| 3053 | "Only -lc++ (aka libxx) is suported in this toolchain."); |
| 3054 | |
| 3055 | CmdArgs.push_back("-lc++"); |
| 3056 | CmdArgs.push_back("-lc++abi"); |
| 3057 | CmdArgs.push_back("-lunwind"); |
| 3058 | } |
| 3059 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 3060 | std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, |
| 3061 | StringRef Component, |
| 3062 | bool Shared) const { |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 3063 | SmallString<128> Path(getDriver().ResourceDir); |
| 3064 | llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix, |
| 3065 | getOS()); |
| 3066 | llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" + |
| Vasileios Kalintiris | bbc9930 | 2015-11-16 15:41:30 +0000 | [diff] [blame] | 3067 | "mips" + (Shared ? ".so" : ".a"))); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 3068 | return Path.str(); |
| 3069 | } |
| 3070 | |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3071 | /// Hexagon Toolchain |
| 3072 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3073 | std::string HexagonToolChain::getHexagonTargetDir( |
| 3074 | const std::string &InstalledDir, |
| 3075 | const SmallVectorImpl<std::string> &PrefixDirs) const { |
| 3076 | std::string InstallRelDir; |
| 3077 | const Driver &D = getDriver(); |
| 3078 | |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3079 | // Locate the rest of the toolchain ... |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3080 | for (auto &I : PrefixDirs) |
| 3081 | if (D.getVFS().exists(I)) |
| 3082 | return I; |
| Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 3083 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3084 | if (getVFS().exists(InstallRelDir = InstalledDir + "/../target")) |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3085 | return InstallRelDir; |
| 3086 | |
| Krzysztof Parzyszek | 50fd615 | 2016-10-17 15:30:10 +0000 | [diff] [blame] | 3087 | return InstalledDir; |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3088 | } |
| 3089 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3090 | Optional<unsigned> HexagonToolChain::getSmallDataThreshold( |
| 3091 | const ArgList &Args) { |
| 3092 | StringRef Gn = ""; |
| 3093 | if (Arg *A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, |
| 3094 | options::OPT_msmall_data_threshold_EQ)) { |
| 3095 | Gn = A->getValue(); |
| 3096 | } else if (Args.getLastArg(options::OPT_shared, options::OPT_fpic, |
| 3097 | options::OPT_fPIC)) { |
| 3098 | Gn = "0"; |
| 3099 | } |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 3100 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3101 | unsigned G; |
| 3102 | if (!Gn.getAsInteger(10, G)) |
| 3103 | return G; |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 3104 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3105 | return None; |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 3106 | } |
| 3107 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3108 | void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args, |
| 3109 | ToolChain::path_list &LibPaths) const { |
| 3110 | const Driver &D = getDriver(); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3111 | |
| 3112 | //---------------------------------------------------------------------------- |
| 3113 | // -L Args |
| 3114 | //---------------------------------------------------------------------------- |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3115 | for (Arg *A : Args.filtered(options::OPT_L)) |
| 3116 | for (const char *Value : A->getValues()) |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3117 | LibPaths.push_back(Value); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3118 | |
| 3119 | //---------------------------------------------------------------------------- |
| 3120 | // Other standard paths |
| 3121 | //---------------------------------------------------------------------------- |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3122 | std::vector<std::string> RootDirs; |
| Krzysztof Parzyszek | f4467cd | 2016-01-06 14:13:11 +0000 | [diff] [blame] | 3123 | std::copy(D.PrefixDirs.begin(), D.PrefixDirs.end(), |
| 3124 | std::back_inserter(RootDirs)); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3125 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3126 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 3127 | D.PrefixDirs); |
| 3128 | if (std::find(RootDirs.begin(), RootDirs.end(), TargetDir) == RootDirs.end()) |
| 3129 | RootDirs.push_back(TargetDir); |
| 3130 | |
| 3131 | bool HasPIC = Args.hasArg(options::OPT_fpic, options::OPT_fPIC); |
| 3132 | // Assume G0 with -shared. |
| 3133 | bool HasG0 = Args.hasArg(options::OPT_shared); |
| 3134 | if (auto G = getSmallDataThreshold(Args)) |
| 3135 | HasG0 = G.getValue() == 0; |
| 3136 | |
| 3137 | const std::string CpuVer = GetTargetCPUVersion(Args).str(); |
| 3138 | for (auto &Dir : RootDirs) { |
| 3139 | std::string LibDir = Dir + "/hexagon/lib"; |
| 3140 | std::string LibDirCpu = LibDir + '/' + CpuVer; |
| 3141 | if (HasG0) { |
| 3142 | if (HasPIC) |
| 3143 | LibPaths.push_back(LibDirCpu + "/G0/pic"); |
| 3144 | LibPaths.push_back(LibDirCpu + "/G0"); |
| 3145 | } |
| 3146 | LibPaths.push_back(LibDirCpu); |
| 3147 | LibPaths.push_back(LibDir); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3148 | } |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3149 | } |
| 3150 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3151 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3152 | const llvm::opt::ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3153 | : Linux(D, Triple, Args) { |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3154 | const std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 3155 | D.PrefixDirs); |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3156 | |
| 3157 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to |
| 3158 | // program paths |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3159 | const std::string BinDir(TargetDir + "/bin"); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3160 | if (D.getVFS().exists(BinDir)) |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3161 | getProgramPaths().push_back(BinDir); |
| 3162 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3163 | ToolChain::path_list &LibPaths = getFilePaths(); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3164 | |
| 3165 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets |
| 3166 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually |
| 3167 | // support 'linux' we'll need to fix this up |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3168 | LibPaths.clear(); |
| 3169 | getHexagonLibraryPaths(Args, LibPaths); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 3172 | HexagonToolChain::~HexagonToolChain() {} |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3173 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3174 | Tool *HexagonToolChain::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3175 | return new tools::hexagon::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3178 | Tool *HexagonToolChain::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3179 | return new tools::hexagon::Linker(*this); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3180 | } |
| 3181 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3182 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3183 | ArgStringList &CC1Args) const { |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3184 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 3185 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3186 | return; |
| 3187 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3188 | const Driver &D = getDriver(); |
| 3189 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 3190 | D.PrefixDirs); |
| 3191 | addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include"); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3194 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3195 | void HexagonToolChain::addLibStdCxxIncludePaths( |
| 3196 | const llvm::opt::ArgList &DriverArgs, |
| 3197 | llvm::opt::ArgStringList &CC1Args) const { |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3198 | const Driver &D = getDriver(); |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3199 | std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs); |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3200 | addLibStdCXXIncludePaths(TargetDir, "/hexagon/include/c++", "", "", "", "", |
| 3201 | DriverArgs, CC1Args); |
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 3202 | } |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 3203 | |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3204 | ToolChain::CXXStdlibType |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3205 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3206 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 3207 | if (!A) |
| 3208 | return ToolChain::CST_Libstdcxx; |
| 3209 | |
| 3210 | StringRef Value = A->getValue(); |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3211 | if (Value != "libstdc++") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3212 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3213 | |
| 3214 | return ToolChain::CST_Libstdcxx; |
| 3215 | } |
| 3216 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3217 | // |
| 3218 | // Returns the default CPU for Hexagon. This is the default compilation target |
| 3219 | // if no Hexagon processor is selected at the command-line. |
| 3220 | // |
| 3221 | const StringRef HexagonToolChain::GetDefaultCPU() { |
| 3222 | return "hexagonv60"; |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 3223 | } |
| 3224 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3225 | const StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) { |
| 3226 | Arg *CpuArg = nullptr; |
| Krzysztof Parzyszek | 972f72c | 2016-01-06 21:12:03 +0000 | [diff] [blame] | 3227 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ, options::OPT_march_EQ)) |
| 3228 | CpuArg = A; |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 3229 | |
| 3230 | StringRef CPU = CpuArg ? CpuArg->getValue() : GetDefaultCPU(); |
| 3231 | if (CPU.startswith("hexagon")) |
| 3232 | return CPU.substr(sizeof("hexagon") - 1); |
| 3233 | return CPU; |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 3234 | } |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 3235 | // End Hexagon |
| Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 3236 | |
| Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 3237 | /// AMDGPU Toolchain |
| 3238 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, |
| 3239 | const ArgList &Args) |
| 3240 | : Generic_ELF(D, Triple, Args) { } |
| 3241 | |
| 3242 | Tool *AMDGPUToolChain::buildLinker() const { |
| 3243 | return new tools::amdgpu::Linker(*this); |
| 3244 | } |
| 3245 | // End AMDGPU |
| 3246 | |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3247 | /// NaCl Toolchain |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3248 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, |
| 3249 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3250 | : Generic_ELF(D, Triple, Args) { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3251 | |
| 3252 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the |
| 3253 | // default paths, and must instead only use the paths provided |
| 3254 | // with this toolchain based on architecture. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3255 | path_list &file_paths = getFilePaths(); |
| 3256 | path_list &prog_paths = getProgramPaths(); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3257 | |
| 3258 | file_paths.clear(); |
| 3259 | prog_paths.clear(); |
| 3260 | |
| 3261 | // Path for library files (libc.a, ...) |
| 3262 | std::string FilePath(getDriver().Dir + "/../"); |
| 3263 | |
| 3264 | // Path for tools (clang, ld, etc..) |
| 3265 | std::string ProgPath(getDriver().Dir + "/../"); |
| 3266 | |
| 3267 | // Path for toolchain libraries (libgcc.a, ...) |
| 3268 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); |
| 3269 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3270 | switch (Triple.getArch()) { |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3271 | case llvm::Triple::x86: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3272 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); |
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 3273 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3274 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 3275 | file_paths.push_back(ToolPath + "i686-nacl"); |
| 3276 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3277 | case llvm::Triple::x86_64: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3278 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); |
| 3279 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); |
| 3280 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 3281 | file_paths.push_back(ToolPath + "x86_64-nacl"); |
| 3282 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3283 | case llvm::Triple::arm: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3284 | file_paths.push_back(FilePath + "arm-nacl/lib"); |
| 3285 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); |
| 3286 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); |
| 3287 | file_paths.push_back(ToolPath + "arm-nacl"); |
| 3288 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3289 | case llvm::Triple::mipsel: |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3290 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); |
| 3291 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); |
| 3292 | prog_paths.push_back(ProgPath + "bin"); |
| 3293 | file_paths.push_back(ToolPath + "mipsel-nacl"); |
| 3294 | break; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3295 | default: |
| 3296 | break; |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3299 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); |
| 3300 | } |
| 3301 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3302 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3303 | ArgStringList &CC1Args) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3304 | const Driver &D = getDriver(); |
| 3305 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 3306 | return; |
| 3307 | |
| 3308 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 3309 | SmallString<128> P(D.ResourceDir); |
| 3310 | llvm::sys::path::append(P, "include"); |
| 3311 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3312 | } |
| 3313 | |
| 3314 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3315 | return; |
| 3316 | |
| 3317 | SmallString<128> P(D.Dir + "/../"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3318 | switch (getTriple().getArch()) { |
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 3319 | case llvm::Triple::x86: |
| 3320 | // x86 is special because multilib style uses x86_64-nacl/include for libc |
| 3321 | // headers but the SDK wants i686-nacl/usr/include. The other architectures |
| 3322 | // have the same substring. |
| 3323 | llvm::sys::path::append(P, "i686-nacl/usr/include"); |
| 3324 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3325 | llvm::sys::path::remove_filename(P); |
| 3326 | llvm::sys::path::remove_filename(P); |
| 3327 | llvm::sys::path::remove_filename(P); |
| 3328 | llvm::sys::path::append(P, "x86_64-nacl/include"); |
| 3329 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3330 | return; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3331 | case llvm::Triple::arm: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3332 | llvm::sys::path::append(P, "arm-nacl/usr/include"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3333 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3334 | case llvm::Triple::x86_64: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3335 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3336 | break; |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3337 | case llvm::Triple::mipsel: |
| 3338 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); |
| 3339 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3340 | default: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3341 | return; |
| 3342 | } |
| 3343 | |
| 3344 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3345 | llvm::sys::path::remove_filename(P); |
| 3346 | llvm::sys::path::remove_filename(P); |
| 3347 | llvm::sys::path::append(P, "include"); |
| 3348 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3349 | } |
| 3350 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3351 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3352 | ArgStringList &CmdArgs) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3353 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 3354 | // if the value is libc++, and emits an error for other values. |
| 3355 | GetCXXStdlibType(Args); |
| 3356 | CmdArgs.push_back("-lc++"); |
| 3357 | } |
| 3358 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3359 | std::string NaClToolChain::findLibCxxIncludePath() const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3360 | const Driver &D = getDriver(); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3361 | |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3362 | SmallString<128> P(D.Dir + "/../"); |
| 3363 | switch (getTriple().getArch()) { |
| 3364 | case llvm::Triple::arm: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3365 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3366 | return P.str(); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3367 | case llvm::Triple::x86: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3368 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3369 | return P.str(); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3370 | case llvm::Triple::x86_64: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3371 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3372 | return P.str(); |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3373 | case llvm::Triple::mipsel: |
| 3374 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3375 | return P.str(); |
| Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 3376 | default: |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3377 | return ""; |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3378 | } |
| 3379 | } |
| 3380 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3381 | ToolChain::CXXStdlibType |
| 3382 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3383 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 3384 | StringRef Value = A->getValue(); |
| 3385 | if (Value == "libc++") |
| 3386 | return ToolChain::CST_Libcxx; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3387 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | return ToolChain::CST_Libcxx; |
| 3391 | } |
| 3392 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3393 | std::string |
| 3394 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, |
| 3395 | types::ID InputType) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3396 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); |
| 3397 | if (TheTriple.getArch() == llvm::Triple::arm && |
| 3398 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) |
| 3399 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); |
| 3400 | return TheTriple.getTriple(); |
| 3401 | } |
| 3402 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3403 | Tool *NaClToolChain::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3404 | return new tools::nacltools::Linker(*this); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3405 | } |
| 3406 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3407 | Tool *NaClToolChain::buildAssembler() const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3408 | if (getTriple().getArch() == llvm::Triple::arm) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3409 | return new tools::nacltools::AssemblerARM(*this); |
| 3410 | return new tools::gnutools::Assembler(*this); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3411 | } |
| 3412 | // End NaCl |
| 3413 | |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3414 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 3415 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 3416 | /// Currently does not support anything else but compilation. |
| 3417 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3418 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 3419 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3420 | : ToolChain(D, Triple, Args) { |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3421 | // Path mangling to find libexec |
| 3422 | std::string Path(getDriver().Dir); |
| 3423 | |
| 3424 | Path += "/../libexec"; |
| 3425 | getProgramPaths().push_back(Path); |
| 3426 | } |
| 3427 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 3428 | TCEToolChain::~TCEToolChain() {} |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3429 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3430 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3431 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3432 | bool TCEToolChain::isPICDefault() const { return false; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3433 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3434 | bool TCEToolChain::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 3435 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3436 | bool TCEToolChain::isPICDefaultForced() const { return false; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3437 | |
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3438 | // CloudABI - CloudABI tool chain which can call ld(1) directly. |
| 3439 | |
| 3440 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, |
| 3441 | const ArgList &Args) |
| 3442 | : Generic_ELF(D, Triple, Args) { |
| 3443 | SmallString<128> P(getDriver().Dir); |
| 3444 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); |
| 3445 | getFilePaths().push_back(P.str()); |
| 3446 | } |
| 3447 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3448 | std::string CloudABI::findLibCxxIncludePath() const { |
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3449 | SmallString<128> P(getDriver().Dir); |
| 3450 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3451 | return P.str(); |
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3455 | ArgStringList &CmdArgs) const { |
| 3456 | CmdArgs.push_back("-lc++"); |
| 3457 | CmdArgs.push_back("-lc++abi"); |
| 3458 | CmdArgs.push_back("-lunwind"); |
| 3459 | } |
| 3460 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3461 | Tool *CloudABI::buildLinker() const { |
| 3462 | return new tools::cloudabi::Linker(*this); |
| 3463 | } |
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3464 | |
| Ed Schouten | 610adae | 2016-08-11 20:03:22 +0000 | [diff] [blame] | 3465 | bool CloudABI::isPIEDefault() const { |
| 3466 | // Only enable PIE on architectures that support PC-relative |
| 3467 | // addressing. PC-relative addressing is required, as the process |
| 3468 | // startup code must be able to relocate itself. |
| 3469 | switch (getTriple().getArch()) { |
| 3470 | case llvm::Triple::aarch64: |
| 3471 | case llvm::Triple::x86_64: |
| 3472 | return true; |
| 3473 | default: |
| 3474 | return false; |
| 3475 | } |
| 3476 | } |
| 3477 | |
| Ed Schouten | 51bfbe7 | 2016-02-17 18:56:20 +0000 | [diff] [blame] | 3478 | SanitizerMask CloudABI::getSupportedSanitizers() const { |
| 3479 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 3480 | Res |= SanitizerKind::SafeStack; |
| 3481 | return Res; |
| 3482 | } |
| 3483 | |
| Ed Schouten | fc79d2c | 2016-03-29 21:13:53 +0000 | [diff] [blame] | 3484 | SanitizerMask CloudABI::getDefaultSanitizers() const { |
| 3485 | return SanitizerKind::SafeStack; |
| 3486 | } |
| 3487 | |
| Reid Kleckner | 330fb17 | 2016-05-11 16:19:05 +0000 | [diff] [blame] | 3488 | /// Haiku - Haiku tool chain which can call as(1) and ld(1) directly. |
| 3489 | |
| 3490 | Haiku::Haiku(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 3491 | : Generic_ELF(D, Triple, Args) { |
| 3492 | |
| 3493 | } |
| 3494 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3495 | std::string Haiku::findLibCxxIncludePath() const { |
| 3496 | return getDriver().SysRoot + "/system/develop/headers/c++/v1"; |
| 3497 | } |
| Reid Kleckner | 330fb17 | 2016-05-11 16:19:05 +0000 | [diff] [blame] | 3498 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3499 | void Haiku::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
| 3500 | llvm::opt::ArgStringList &CC1Args) const { |
| 3501 | addLibStdCXXIncludePaths(getDriver().SysRoot, "/system/develop/headers/c++", |
| 3502 | getTriple().str(), "", "", "", DriverArgs, CC1Args); |
| Reid Kleckner | 330fb17 | 2016-05-11 16:19:05 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3505 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 3506 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3507 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, |
| 3508 | const ArgList &Args) |
| 3509 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3510 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3511 | getFilePaths().push_back("/usr/lib"); |
| 3512 | } |
| 3513 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3514 | Tool *OpenBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3515 | return new tools::openbsd::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 *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3519 | |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3520 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. |
| 3521 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3522 | Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3523 | : Generic_ELF(D, Triple, Args) { |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3524 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3525 | getFilePaths().push_back("/usr/lib"); |
| 3526 | } |
| 3527 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3528 | Tool *Bitrig::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3529 | return new tools::bitrig::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3530 | } |
| 3531 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3532 | Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3533 | |
| Jonas Hahnfeld | aae8374 | 2016-02-12 07:48:37 +0000 | [diff] [blame] | 3534 | ToolChain::CXXStdlibType Bitrig::GetDefaultCXXStdlibType() const { |
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3535 | return ToolChain::CST_Libcxx; |
| 3536 | } |
| 3537 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3538 | void Bitrig::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
| 3539 | llvm::opt::ArgStringList &CC1Args) const { |
| 3540 | std::string Triple = getTriple().str(); |
| 3541 | if (StringRef(Triple).startswith("amd64")) |
| 3542 | Triple = "x86_64" + Triple.substr(5); |
| 3543 | addLibStdCXXIncludePaths(getDriver().SysRoot, "/usr/include/c++/stdc++", |
| 3544 | Triple, "", "", "", DriverArgs, CC1Args); |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3548 | ArgStringList &CmdArgs) const { |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3549 | switch (GetCXXStdlibType(Args)) { |
| 3550 | case ToolChain::CST_Libcxx: |
| 3551 | CmdArgs.push_back("-lc++"); |
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3552 | CmdArgs.push_back("-lc++abi"); |
| 3553 | CmdArgs.push_back("-lpthread"); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3554 | break; |
| 3555 | case ToolChain::CST_Libstdcxx: |
| 3556 | CmdArgs.push_back("-lstdc++"); |
| 3557 | break; |
| 3558 | } |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3561 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 3562 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3563 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, |
| 3564 | const ArgList &Args) |
| 3565 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 3566 | |
| Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 3567 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall |
| 3568 | // back to '/usr/lib' if it doesn't exist. |
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3569 | if ((Triple.getArch() == llvm::Triple::x86 || |
| 3570 | Triple.getArch() == llvm::Triple::ppc) && |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3571 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) |
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3572 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); |
| 3573 | else |
| 3574 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3575 | } |
| 3576 | |
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3577 | ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3578 | if (getTriple().getOSMajorVersion() >= 10) |
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3579 | return ToolChain::CST_Libcxx; |
| 3580 | return ToolChain::CST_Libstdcxx; |
| 3581 | } |
| 3582 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3583 | void FreeBSD::addLibStdCxxIncludePaths( |
| 3584 | const llvm::opt::ArgList &DriverArgs, |
| 3585 | llvm::opt::ArgStringList &CC1Args) const { |
| 3586 | addLibStdCXXIncludePaths(getDriver().SysRoot, "/usr/include/c++/4.2", "", "", |
| 3587 | "", "", DriverArgs, CC1Args); |
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3588 | } |
| 3589 | |
| Dimitry Andric | 6090739 | 2016-02-14 16:08:20 +0000 | [diff] [blame] | 3590 | void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3591 | ArgStringList &CmdArgs) const { |
| 3592 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 3593 | bool Profiling = Args.hasArg(options::OPT_pg); |
| 3594 | |
| 3595 | switch (Type) { |
| 3596 | case ToolChain::CST_Libcxx: |
| 3597 | CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++"); |
| 3598 | break; |
| 3599 | |
| 3600 | case ToolChain::CST_Libstdcxx: |
| 3601 | CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++"); |
| 3602 | break; |
| 3603 | } |
| 3604 | } |
| 3605 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3606 | Tool *FreeBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3607 | return new tools::freebsd::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3608 | } |
| 3609 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3610 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3611 | |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 3612 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { |
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3613 | // FreeBSD uses SjLj exceptions on ARM oabi. |
| 3614 | switch (getTriple().getEnvironment()) { |
| Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 3615 | case llvm::Triple::GNUEABIHF: |
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3616 | case llvm::Triple::GNUEABI: |
| 3617 | case llvm::Triple::EABI: |
| 3618 | return false; |
| 3619 | |
| 3620 | default: |
| 3621 | return (getTriple().getArch() == llvm::Triple::arm || |
| 3622 | getTriple().getArch() == llvm::Triple::thumb); |
| 3623 | } |
| 3624 | } |
| 3625 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3626 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } |
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3627 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3628 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3629 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3630 | SanitizerMask FreeBSD::getSupportedSanitizers() const { |
| 3631 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 3632 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 3633 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 3634 | getTriple().getArch() == llvm::Triple::mips64el; |
| 3635 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 3636 | Res |= SanitizerKind::Address; |
| 3637 | Res |= SanitizerKind::Vptr; |
| 3638 | if (IsX86_64 || IsMIPS64) { |
| 3639 | Res |= SanitizerKind::Leak; |
| 3640 | Res |= SanitizerKind::Thread; |
| 3641 | } |
| 3642 | if (IsX86 || IsX86_64) { |
| 3643 | Res |= SanitizerKind::SafeStack; |
| 3644 | } |
| 3645 | return Res; |
| 3646 | } |
| 3647 | |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3648 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 3649 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3650 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3651 | : Generic_ELF(D, Triple, Args) { |
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3652 | if (getDriver().UseStdLib) { |
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3653 | // When targeting a 32-bit platform, try the special directory used on |
| 3654 | // 64-bit hosts, and only fall back to the main library directory if that |
| 3655 | // doesn't work. |
| 3656 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure |
| 3657 | // what all logic is needed to emulate the '=' prefix here. |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3658 | switch (Triple.getArch()) { |
| 3659 | case llvm::Triple::x86: |
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3660 | getFilePaths().push_back("=/usr/lib/i386"); |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3661 | break; |
| 3662 | case llvm::Triple::arm: |
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3663 | case llvm::Triple::armeb: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3664 | case llvm::Triple::thumb: |
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3665 | case llvm::Triple::thumbeb: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3666 | switch (Triple.getEnvironment()) { |
| 3667 | case llvm::Triple::EABI: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3668 | case llvm::Triple::GNUEABI: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3669 | getFilePaths().push_back("=/usr/lib/eabi"); |
| 3670 | break; |
| Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3671 | case llvm::Triple::EABIHF: |
| 3672 | case llvm::Triple::GNUEABIHF: |
| 3673 | getFilePaths().push_back("=/usr/lib/eabihf"); |
| 3674 | break; |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3675 | default: |
| 3676 | getFilePaths().push_back("=/usr/lib/oabi"); |
| 3677 | break; |
| 3678 | } |
| 3679 | break; |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3680 | case llvm::Triple::mips64: |
| 3681 | case llvm::Triple::mips64el: |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3682 | if (tools::mips::hasMipsAbiArg(Args, "o32")) |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3683 | getFilePaths().push_back("=/usr/lib/o32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3684 | else if (tools::mips::hasMipsAbiArg(Args, "64")) |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3685 | getFilePaths().push_back("=/usr/lib/64"); |
| 3686 | break; |
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3687 | case llvm::Triple::ppc: |
| 3688 | getFilePaths().push_back("=/usr/lib/powerpc"); |
| 3689 | break; |
| Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3690 | case llvm::Triple::sparc: |
| 3691 | getFilePaths().push_back("=/usr/lib/sparc"); |
| 3692 | break; |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3693 | default: |
| 3694 | break; |
| 3695 | } |
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3696 | |
| 3697 | getFilePaths().push_back("=/usr/lib"); |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3698 | } |
| 3699 | } |
| 3700 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3701 | Tool *NetBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3702 | return new tools::netbsd::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3703 | } |
| 3704 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3705 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3706 | |
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3707 | ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const { |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3708 | unsigned Major, Minor, Micro; |
| 3709 | getTriple().getOSVersion(Major, Minor, Micro); |
| Joerg Sonnenberger | 21156e8 | 2016-02-11 23:35:03 +0000 | [diff] [blame] | 3710 | if (Major >= 7 || Major == 0) { |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3711 | switch (getArch()) { |
| Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3712 | case llvm::Triple::aarch64: |
| Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3713 | case llvm::Triple::arm: |
| 3714 | case llvm::Triple::armeb: |
| 3715 | case llvm::Triple::thumb: |
| 3716 | case llvm::Triple::thumbeb: |
| Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3717 | case llvm::Triple::ppc: |
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3718 | case llvm::Triple::ppc64: |
| 3719 | case llvm::Triple::ppc64le: |
| Joerg Sonnenberger | 059613c | 2016-02-11 23:18:36 +0000 | [diff] [blame] | 3720 | case llvm::Triple::sparc: |
| 3721 | case llvm::Triple::sparcv9: |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3722 | case llvm::Triple::x86: |
| 3723 | case llvm::Triple::x86_64: |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3724 | return ToolChain::CST_Libcxx; |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3725 | default: |
| 3726 | break; |
| 3727 | } |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3728 | } |
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3729 | return ToolChain::CST_Libstdcxx; |
| 3730 | } |
| 3731 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3732 | std::string NetBSD::findLibCxxIncludePath() const { |
| 3733 | return getDriver().SysRoot + "/usr/include/c++/"; |
| 3734 | } |
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3735 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3736 | void NetBSD::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
| 3737 | llvm::opt::ArgStringList &CC1Args) const { |
| 3738 | addLibStdCXXIncludePaths(getDriver().SysRoot, "/usr/include/g++", "", "", "", |
| 3739 | "", DriverArgs, CC1Args); |
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3740 | } |
| 3741 | |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3742 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 3743 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3744 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3745 | : Generic_ELF(D, Triple, Args) { |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3746 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3747 | getFilePaths().push_back("/usr/lib"); |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3748 | } |
| 3749 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3750 | Tool *Minix::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3751 | return new tools::minix::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3752 | } |
| 3753 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3754 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3755 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3756 | static void addPathIfExists(const Driver &D, const Twine &Path, |
| 3757 | ToolChain::path_list &Paths) { |
| 3758 | if (D.getVFS().exists(Path)) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3759 | Paths.push_back(Path.str()); |
| 3760 | } |
| 3761 | |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3762 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. |
| 3763 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3764 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3765 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3766 | : Generic_GCC(D, Triple, Args) { |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3767 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3768 | GCCInstallation.init(Triple, Args); |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3769 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3770 | path_list &Paths = getFilePaths(); |
| 3771 | if (GCCInstallation.isValid()) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3772 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3773 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3774 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3775 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3776 | addPathIfExists(D, getDriver().Dir, Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3777 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3778 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3779 | |
| 3780 | std::string LibPath = "/usr/lib/"; |
| 3781 | switch (Triple.getArch()) { |
| 3782 | case llvm::Triple::x86: |
| 3783 | case llvm::Triple::sparc: |
| 3784 | break; |
| 3785 | case llvm::Triple::x86_64: |
| 3786 | LibPath += "amd64/"; |
| 3787 | break; |
| 3788 | case llvm::Triple::sparcv9: |
| 3789 | LibPath += "sparcv9/"; |
| 3790 | break; |
| 3791 | default: |
| 3792 | llvm_unreachable("Unsupported architecture"); |
| 3793 | } |
| 3794 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3795 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3798 | Tool *Solaris::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3799 | return new tools::solaris::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3802 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } |
| Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3803 | |
| Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3804 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3805 | ArgStringList &CC1Args) const { |
| 3806 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3807 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3808 | return; |
| 3809 | |
| 3810 | // Include the support directory for things like xlocale and fudged system |
| 3811 | // headers. |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 3812 | // FIXME: This is a weird mix of libc++ and libstdc++. We should also be |
| 3813 | // checking the value of -stdlib= here and adding the includes for libc++ |
| 3814 | // rather than libstdc++ if it's requested. |
| Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3815 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); |
| 3816 | |
| 3817 | if (GCCInstallation.isValid()) { |
| 3818 | GCCVersion Version = GCCInstallation.getVersion(); |
| 3819 | addSystemInclude(DriverArgs, CC1Args, |
| 3820 | getDriver().SysRoot + "/usr/gcc/" + |
| 3821 | Version.MajorStr + "." + |
| 3822 | Version.MinorStr + |
| 3823 | "/include/c++/" + Version.Text); |
| 3824 | addSystemInclude(DriverArgs, CC1Args, |
| 3825 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + |
| 3826 | "." + Version.MinorStr + "/include/c++/" + |
| 3827 | Version.Text + "/" + |
| 3828 | GCCInstallation.getTriple().str()); |
| 3829 | } |
| 3830 | } |
| 3831 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3832 | /// Distribution (very bare-bones at the moment). |
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3833 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3834 | enum Distro { |
| Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3835 | // NB: Releases of a particular Linux distro should be kept together |
| 3836 | // in this enum, because some tests are done by integer comparison against |
| 3837 | // the first and last known member in the family, e.g. IsRedHat(). |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3838 | ArchLinux, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3839 | DebianLenny, |
| 3840 | DebianSqueeze, |
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3841 | DebianWheezy, |
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3842 | DebianJessie, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3843 | DebianStretch, |
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3844 | Exherbo, |
| Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3845 | RHEL5, |
| 3846 | RHEL6, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3847 | RHEL7, |
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3848 | Fedora, |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3849 | OpenSUSE, |
| Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3850 | UbuntuHardy, |
| 3851 | UbuntuIntrepid, |
| Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3852 | UbuntuJaunty, |
| Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3853 | UbuntuKarmic, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3854 | UbuntuLucid, |
| 3855 | UbuntuMaverick, |
| Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3856 | UbuntuNatty, |
| Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3857 | UbuntuOneiric, |
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3858 | UbuntuPrecise, |
| Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3859 | UbuntuQuantal, |
| 3860 | UbuntuRaring, |
| Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3861 | UbuntuSaucy, |
| Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3862 | UbuntuTrusty, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3863 | UbuntuUtopic, |
| 3864 | UbuntuVivid, |
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3865 | UbuntuWily, |
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3866 | UbuntuXenial, |
| Sylvestre Ledru | d3078e7 | 2016-07-19 14:00:57 +0000 | [diff] [blame] | 3867 | UbuntuYakkety, |
| Sylvestre Ledru | f017451 | 2016-11-12 09:26:30 +0000 | [diff] [blame] | 3868 | UbuntuZesty, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3869 | UnknownDistro |
| 3870 | }; |
| 3871 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3872 | static bool IsRedhat(enum Distro Distro) { |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3873 | return Distro == Fedora || (Distro >= RHEL5 && Distro <= RHEL7); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3876 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3877 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3878 | static bool IsDebian(enum Distro Distro) { |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3879 | return Distro >= DebianLenny && Distro <= DebianStretch; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3882 | static bool IsUbuntu(enum Distro Distro) { |
| Sylvestre Ledru | f017451 | 2016-11-12 09:26:30 +0000 | [diff] [blame] | 3883 | return Distro >= UbuntuHardy && Distro <= UbuntuZesty; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3884 | } |
| 3885 | |
| Michal Gorny | 16f37c3 | 2016-10-20 20:45:40 +0000 | [diff] [blame] | 3886 | static Distro DetectDistro(vfs::FileSystem &VFS) { |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3887 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = |
| Michal Gorny | 16f37c3 | 2016-10-20 20:45:40 +0000 | [diff] [blame] | 3888 | VFS.getBufferForFile("/etc/lsb-release"); |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3889 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3890 | StringRef Data = File.get()->getBuffer(); |
| Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3891 | SmallVector<StringRef, 16> Lines; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3892 | Data.split(Lines, "\n"); |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3893 | Distro Version = UnknownDistro; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3894 | for (StringRef Line : Lines) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3895 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) |
| 3896 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) |
| 3897 | .Case("hardy", UbuntuHardy) |
| 3898 | .Case("intrepid", UbuntuIntrepid) |
| 3899 | .Case("jaunty", UbuntuJaunty) |
| 3900 | .Case("karmic", UbuntuKarmic) |
| 3901 | .Case("lucid", UbuntuLucid) |
| 3902 | .Case("maverick", UbuntuMaverick) |
| 3903 | .Case("natty", UbuntuNatty) |
| 3904 | .Case("oneiric", UbuntuOneiric) |
| 3905 | .Case("precise", UbuntuPrecise) |
| 3906 | .Case("quantal", UbuntuQuantal) |
| 3907 | .Case("raring", UbuntuRaring) |
| 3908 | .Case("saucy", UbuntuSaucy) |
| 3909 | .Case("trusty", UbuntuTrusty) |
| 3910 | .Case("utopic", UbuntuUtopic) |
| 3911 | .Case("vivid", UbuntuVivid) |
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3912 | .Case("wily", UbuntuWily) |
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3913 | .Case("xenial", UbuntuXenial) |
| Sylvestre Ledru | d3078e7 | 2016-07-19 14:00:57 +0000 | [diff] [blame] | 3914 | .Case("yakkety", UbuntuYakkety) |
| Sylvestre Ledru | f017451 | 2016-11-12 09:26:30 +0000 | [diff] [blame] | 3915 | .Case("zesty", UbuntuZesty) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3916 | .Default(UnknownDistro); |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3917 | if (Version != UnknownDistro) |
| 3918 | return Version; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
| Michal Gorny | 16f37c3 | 2016-10-20 20:45:40 +0000 | [diff] [blame] | 3921 | File = VFS.getBufferForFile("/etc/redhat-release"); |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3922 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3923 | StringRef Data = File.get()->getBuffer(); |
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3924 | if (Data.startswith("Fedora release")) |
| 3925 | return Fedora; |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3926 | if (Data.startswith("Red Hat Enterprise Linux") || |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3927 | Data.startswith("CentOS") || |
| 3928 | Data.startswith("Scientific Linux")) { |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3929 | if (Data.find("release 7") != StringRef::npos) |
| 3930 | return RHEL7; |
| 3931 | else if (Data.find("release 6") != StringRef::npos) |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3932 | return RHEL6; |
| 3933 | else if (Data.find("release 5") != StringRef::npos) |
| 3934 | return RHEL5; |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3935 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3936 | return UnknownDistro; |
| 3937 | } |
| 3938 | |
| Michal Gorny | 16f37c3 | 2016-10-20 20:45:40 +0000 | [diff] [blame] | 3939 | File = VFS.getBufferForFile("/etc/debian_version"); |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3940 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3941 | StringRef Data = File.get()->getBuffer(); |
| Michal Gorny | 0a2cd96 | 2016-10-20 20:13:35 +0000 | [diff] [blame] | 3942 | // Contents: < major.minor > or < codename/sid > |
| 3943 | int MajorVersion; |
| 3944 | if (!Data.split('.').first.getAsInteger(10, MajorVersion)) { |
| 3945 | switch (MajorVersion) { |
| 3946 | case 5: |
| 3947 | return DebianLenny; |
| 3948 | case 6: |
| 3949 | return DebianSqueeze; |
| 3950 | case 7: |
| 3951 | return DebianWheezy; |
| 3952 | case 8: |
| 3953 | return DebianJessie; |
| 3954 | case 9: |
| 3955 | return DebianStretch; |
| 3956 | default: |
| 3957 | return UnknownDistro; |
| 3958 | } |
| 3959 | } |
| 3960 | return llvm::StringSwitch<Distro>(Data.split("\n").first) |
| 3961 | .Case("squeeze/sid", DebianSqueeze) |
| 3962 | .Case("wheezy/sid", DebianWheezy) |
| 3963 | .Case("jessie/sid", DebianJessie) |
| 3964 | .Case("stretch/sid", DebianStretch) |
| 3965 | .Default(UnknownDistro); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3966 | } |
| 3967 | |
| Michal Gorny | 91cc4a6 | 2016-10-25 15:33:32 +0000 | [diff] [blame] | 3968 | File = VFS.getBufferForFile("/etc/SuSE-release"); |
| 3969 | if (File) { |
| 3970 | StringRef Data = File.get()->getBuffer(); |
| 3971 | SmallVector<StringRef, 8> Lines; |
| 3972 | Data.split(Lines, "\n"); |
| 3973 | for (const StringRef& Line : Lines) { |
| 3974 | if (!Line.trim().startswith("VERSION")) |
| 3975 | continue; |
| 3976 | std::pair<StringRef, StringRef> SplitLine = Line.split('='); |
| 3977 | int Version; |
| 3978 | // OpenSUSE/SLES 10 and older are not supported and not compatible |
| 3979 | // with our rules, so just treat them as UnknownDistro. |
| 3980 | if (!SplitLine.second.trim().getAsInteger(10, Version) && |
| 3981 | Version > 10) |
| 3982 | return OpenSUSE; |
| 3983 | return UnknownDistro; |
| 3984 | } |
| 3985 | return UnknownDistro; |
| 3986 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3987 | |
| Michal Gorny | 16f37c3 | 2016-10-20 20:45:40 +0000 | [diff] [blame] | 3988 | if (VFS.exists("/etc/exherbo-release")) |
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3989 | return Exherbo; |
| 3990 | |
| Michal Gorny | 16f37c3 | 2016-10-20 20:45:40 +0000 | [diff] [blame] | 3991 | if (VFS.exists("/etc/arch-release")) |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3992 | return ArchLinux; |
| 3993 | |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3994 | return UnknownDistro; |
| 3995 | } |
| 3996 | |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3997 | /// \brief Get our best guess at the multiarch triple for a target. |
| 3998 | /// |
| 3999 | /// Debian-based systems are starting to use a multiarch setup where they use |
| 4000 | /// a target-triple directory in the library and header search paths. |
| 4001 | /// Unfortunately, this triple does not align with the vanilla target triple, |
| 4002 | /// so we provide a rough mapping here. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4003 | static std::string getMultiarchTriple(const Driver &D, |
| 4004 | const llvm::Triple &TargetTriple, |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4005 | StringRef SysRoot) { |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4006 | llvm::Triple::EnvironmentType TargetEnvironment = |
| 4007 | TargetTriple.getEnvironment(); |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4008 | |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4009 | // For most architectures, just use whatever we have rather than trying to be |
| 4010 | // clever. |
| 4011 | switch (TargetTriple.getArch()) { |
| 4012 | default: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4013 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4014 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4015 | // We use the existence of '/lib/<triple>' as a directory to detect some |
| 4016 | // common linux triples that don't quite match the Clang triple for both |
| 4017 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
| 4018 | // regardless of what the actual target triple is. |
| Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 4019 | case llvm::Triple::arm: |
| 4020 | case llvm::Triple::thumb: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4021 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4022 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4023 | return "arm-linux-gnueabihf"; |
| 4024 | } else { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4025 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4026 | return "arm-linux-gnueabi"; |
| 4027 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4028 | break; |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 4029 | case llvm::Triple::armeb: |
| 4030 | case llvm::Triple::thumbeb: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4031 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4032 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 4033 | return "armeb-linux-gnueabihf"; |
| 4034 | } else { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4035 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 4036 | return "armeb-linux-gnueabi"; |
| 4037 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4038 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4039 | case llvm::Triple::x86: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4040 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4041 | return "i386-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4042 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4043 | case llvm::Triple::x86_64: |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 4044 | // 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] | 4045 | if (TargetEnvironment != llvm::Triple::GNUX32 && |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4046 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4047 | return "x86_64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4048 | break; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4049 | case llvm::Triple::aarch64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4050 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4051 | return "aarch64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4052 | break; |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 4053 | case llvm::Triple::aarch64_be: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4054 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 4055 | return "aarch64_be-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4056 | break; |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 4057 | case llvm::Triple::mips: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4058 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 4059 | return "mips-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4060 | break; |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 4061 | case llvm::Triple::mipsel: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4062 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 4063 | return "mipsel-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4064 | break; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4065 | case llvm::Triple::mips64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4066 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4067 | return "mips64-linux-gnu"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4068 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4069 | return "mips64-linux-gnuabi64"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4070 | break; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4071 | case llvm::Triple::mips64el: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4072 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4073 | return "mips64el-linux-gnu"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4074 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4075 | return "mips64el-linux-gnuabi64"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4076 | break; |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 4077 | case llvm::Triple::ppc: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4078 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) |
| Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 4079 | return "powerpc-linux-gnuspe"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4080 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 4081 | return "powerpc-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4082 | break; |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 4083 | case llvm::Triple::ppc64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4084 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 4085 | return "powerpc64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4086 | break; |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 4087 | case llvm::Triple::ppc64le: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4088 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 4089 | return "powerpc64le-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4090 | break; |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 4091 | case llvm::Triple::sparc: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4092 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 4093 | return "sparc-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4094 | break; |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 4095 | case llvm::Triple::sparcv9: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4096 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 4097 | return "sparc64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4098 | break; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4099 | case llvm::Triple::systemz: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4100 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4101 | return "s390x-linux-gnu"; |
| 4102 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4103 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 4104 | return TargetTriple.str(); |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4107 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4108 | if (isMipsArch(Triple.getArch())) { |
| Simon Atanasyan | 603018a | 2016-07-19 07:09:48 +0000 | [diff] [blame] | 4109 | if (Triple.isAndroid()) { |
| 4110 | StringRef CPUName; |
| 4111 | StringRef ABIName; |
| 4112 | tools::mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName); |
| 4113 | if (CPUName == "mips32r6") |
| 4114 | return "libr6"; |
| 4115 | if (CPUName == "mips32r2") |
| 4116 | return "libr2"; |
| 4117 | } |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4118 | // lib32 directory has a special meaning on MIPS targets. |
| 4119 | // It contains N32 ABI binaries. Use this folder if produce |
| 4120 | // code for N32 ABI only. |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4121 | if (tools::mips::hasMipsAbiArg(Args, "n32")) |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4122 | return "lib32"; |
| 4123 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 4124 | } |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 4125 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4126 | // 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] | 4127 | // using that variant while targeting other architectures causes problems |
| 4128 | // 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] | 4129 | // with a 'lib32' library search path being considered. So we only enable |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4130 | // them when we know we may need it. |
| 4131 | // |
| 4132 | // 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] | 4133 | // reasoning about oslibdir spellings with the lib dir spellings in the |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 4134 | // GCCInstallationDetector, but that is a more significant refactoring. |
| 4135 | if (Triple.getArch() == llvm::Triple::x86 || |
| 4136 | Triple.getArch() == llvm::Triple::ppc) |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 4137 | return "lib32"; |
| 4138 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 4139 | if (Triple.getArch() == llvm::Triple::x86_64 && |
| 4140 | Triple.getEnvironment() == llvm::Triple::GNUX32) |
| 4141 | return "libx32"; |
| 4142 | |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 4143 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 4144 | } |
| 4145 | |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 4146 | static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, |
| 4147 | const Multilib &Multilib, |
| 4148 | StringRef InstallPath, |
| 4149 | ToolChain::path_list &Paths) { |
| 4150 | if (const auto &PathsCallback = Multilibs.filePathsCallback()) |
| 4151 | for (const auto &Path : PathsCallback(Multilib)) |
| 4152 | addPathIfExists(D, InstallPath + Path, Paths); |
| 4153 | } |
| 4154 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 4155 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4156 | : Generic_ELF(D, Triple, Args) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4157 | GCCInstallation.init(Triple, Args); |
| 4158 | CudaInstallation.init(Triple, Args); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4159 | Multilibs = GCCInstallation.getMultilibs(); |
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 4160 | llvm::Triple::ArchType Arch = Triple.getArch(); |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 4161 | std::string SysRoot = computeSysRoot(); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4162 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4163 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at |
| Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 4164 | // least) put various tools in a triple-prefixed directory off of the parent |
| 4165 | // of the GCC installation. We use the GCC triple here to ensure that we end |
| 4166 | // up with tools that support the same amount of cross compiling as the |
| 4167 | // detected GCC installation. For example, if we find a GCC installation |
| 4168 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be |
| 4169 | // used to target i386. |
| 4170 | // FIXME: This seems unlikely to be Linux-specific. |
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 4171 | ToolChain::path_list &PPaths = getProgramPaths(); |
| Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 4172 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4173 | GCCInstallation.getTriple().str() + "/bin") |
| 4174 | .str()); |
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 4175 | |
| Michal Gorny | 16f37c3 | 2016-10-20 20:45:40 +0000 | [diff] [blame] | 4176 | Distro Distro = DetectDistro(D.getVFS()); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4177 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4178 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { |
| Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 4179 | ExtraOpts.push_back("-z"); |
| 4180 | ExtraOpts.push_back("relro"); |
| 4181 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4182 | |
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 4183 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4184 | ExtraOpts.push_back("-X"); |
| 4185 | |
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 4186 | const bool IsAndroid = Triple.isAndroid(); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4187 | const bool IsMips = isMipsArch(Arch); |
| 4188 | |
| 4189 | if (IsMips && !SysRoot.empty()) |
| 4190 | ExtraOpts.push_back("--sysroot=" + SysRoot); |
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 4191 | |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 4192 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
| 4193 | // and the MIPS ABI require .dynsym to be sorted in different ways. |
| 4194 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
| 4195 | // ABI requires a mapping between the GOT and the symbol table. |
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 4196 | // Android loader does not support .gnu.hash. |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4197 | if (!IsMips && !IsAndroid) { |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4198 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || |
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 4199 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 4200 | ExtraOpts.push_back("--hash-style=gnu"); |
| 4201 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4202 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 4203 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) |
| 4204 | ExtraOpts.push_back("--hash-style=both"); |
| 4205 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4206 | |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 4207 | if (IsRedhat(Distro) && Distro != RHEL5 && Distro != RHEL6) |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4208 | ExtraOpts.push_back("--no-add-needed"); |
| 4209 | |
| Rafael Espindola | 5ed89d4 | 2016-06-03 17:26:16 +0000 | [diff] [blame] | 4210 | #ifdef ENABLE_LINKER_BUILD_ID |
| 4211 | ExtraOpts.push_back("--build-id"); |
| 4212 | #endif |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4213 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 4214 | if (IsOpenSUSE(Distro)) |
| Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 4215 | ExtraOpts.push_back("--enable-new-dtags"); |
| Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 4216 | |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 4217 | // The selection of paths to try here is designed to match the patterns which |
| 4218 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
| 4219 | // This was determined by running GCC in a fake filesystem, creating all |
| 4220 | // possible permutations of these directories, and seeing which ones it added |
| 4221 | // to the link paths. |
| 4222 | path_list &Paths = getFilePaths(); |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 4223 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4224 | const std::string OSLibDir = getOSLibDir(Triple, Args); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4225 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 4226 | |
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 4227 | // Add the multilib suffixed paths where they are available. |
| 4228 | if (GCCInstallation.isValid()) { |
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 4229 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 4230 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4231 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 4232 | const MultilibSet &Multilibs = GCCInstallation.getMultilibs(); |
| 4233 | |
| 4234 | // Add toolchain / multilib specific file paths. |
| 4235 | addMultilibsFilePaths(D, Multilibs, Multilib, |
| 4236 | GCCInstallation.getInstallPath(), Paths); |
| Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 4237 | |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4238 | // Sourcery CodeBench MIPS toolchain holds some libraries under |
| Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 4239 | // a biarch-like suffix of the GCC installation. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4240 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4241 | Paths); |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4242 | |
| 4243 | // GCC cross compiling toolchains will install target libraries which ship |
| 4244 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as |
| 4245 | // any part of the GCC installation in |
| 4246 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat |
| 4247 | // debatable, but is the reality today. We need to search this tree even |
| 4248 | // when we have a sysroot somewhere else. It is the responsibility of |
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 4249 | // whomever is doing the cross build targeting a sysroot using a GCC |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4250 | // installation that is *not* within the system root to ensure two things: |
| 4251 | // |
| 4252 | // 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] | 4253 | // above must be present on the system root and found via an |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4254 | // appropriate rpath. |
| 4255 | // 2) There must not be libraries installed into |
| 4256 | // <prefix>/<triple>/<libdir> unless they should be preferred over |
| 4257 | // those within the system root. |
| 4258 | // |
| 4259 | // Note that this matches the GCC behavior. See the below comment for where |
| 4260 | // Clang diverges from GCC's behavior. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4261 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + |
| 4262 | OSLibDir + Multilib.osSuffix(), |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4263 | Paths); |
| 4264 | |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4265 | // If the GCC installation we found is inside of the sysroot, we want to |
| 4266 | // prefer libraries installed in the parent prefix of the GCC installation. |
| 4267 | // 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] | 4268 | // outside of the system root as that can pick up unintended libraries. |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4269 | // This usually happens when there is an external cross compiler on the |
| 4270 | // 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] | 4271 | // the cross. Note that GCC does include some of these directories in some |
| 4272 | // configurations but this seems somewhere between questionable and simply |
| 4273 | // a bug. |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4274 | if (StringRef(LibPath).startswith(SysRoot)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4275 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); |
| 4276 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4277 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4278 | } |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4279 | |
| 4280 | // 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] | 4281 | // of the requested system root, add its parent library paths to |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4282 | // those searched. |
| 4283 | // FIXME: It's not clear whether we should use the driver's installed |
| 4284 | // directory ('Dir' below) or the ResourceDir. |
| 4285 | if (StringRef(D.Dir).startswith(SysRoot)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4286 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); |
| 4287 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4288 | } |
| 4289 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4290 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); |
| 4291 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); |
| 4292 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); |
| 4293 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); |
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 4294 | |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 4295 | // 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] | 4296 | // installations with strange symlinks. |
| Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 4297 | if (GCCInstallation.isValid()) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4298 | addPathIfExists(D, |
| 4299 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4300 | "/../../" + OSLibDir, |
| 4301 | Paths); |
| Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 4302 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4303 | // Add the 'other' biarch variant path |
| 4304 | Multilib BiarchSibling; |
| 4305 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4306 | addPathIfExists(D, GCCInstallation.getInstallPath() + |
| 4307 | BiarchSibling.gccSuffix(), |
| 4308 | Paths); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4309 | } |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4310 | |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4311 | // See comments above on the multilib variant for details of why this is |
| 4312 | // included even from outside the sysroot. |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4313 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| 4314 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| 4315 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4316 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + |
| 4317 | Multilib.osSuffix(), |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4318 | Paths); |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4319 | |
| 4320 | // See comments above on the multilib variant for details of why this is |
| 4321 | // only included from within the sysroot. |
| 4322 | if (StringRef(LibPath).startswith(SysRoot)) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4323 | addPathIfExists(D, LibPath, Paths); |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 4324 | } |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4325 | |
| 4326 | // Similar to the logic for GCC above, if we are currently running Clang |
| 4327 | // inside of the requested system root, add its parent library path to those |
| 4328 | // searched. |
| 4329 | // FIXME: It's not clear whether we should use the driver's installed |
| 4330 | // directory ('Dir' below) or the ResourceDir. |
| 4331 | if (StringRef(D.Dir).startswith(SysRoot)) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4332 | addPathIfExists(D, D.Dir + "/../lib", Paths); |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4333 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4334 | addPathIfExists(D, SysRoot + "/lib", Paths); |
| 4335 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4336 | } |
| 4337 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4338 | bool Linux::HasNativeLLVMSupport() const { return true; } |
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 4339 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4340 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4341 | |
| 4342 | Tool *Linux::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4343 | return new tools::gnutools::Assembler(*this); |
| Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 4344 | } |
| 4345 | |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 4346 | std::string Linux::computeSysRoot() const { |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4347 | if (!getDriver().SysRoot.empty()) |
| 4348 | return getDriver().SysRoot; |
| 4349 | |
| 4350 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) |
| 4351 | return std::string(); |
| 4352 | |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4353 | // Standalone MIPS toolchains use different names for sysroot folder |
| 4354 | // and put it into different places. Here we try to check some known |
| 4355 | // variants. |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4356 | |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4357 | const StringRef InstallDir = GCCInstallation.getInstallPath(); |
| 4358 | const StringRef TripleStr = GCCInstallation.getTriple().str(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4359 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4360 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4361 | std::string Path = |
| 4362 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) |
| 4363 | .str(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4364 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4365 | if (getVFS().exists(Path)) |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4366 | return Path; |
| 4367 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4368 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4369 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4370 | if (getVFS().exists(Path)) |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4371 | return Path; |
| 4372 | |
| 4373 | return std::string(); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4374 | } |
| 4375 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4376 | std::string Linux::getDynamicLinker(const ArgList &Args) const { |
| 4377 | const llvm::Triple::ArchType Arch = getArch(); |
| 4378 | const llvm::Triple &Triple = getTriple(); |
| 4379 | |
| Michal Gorny | 16f37c3 | 2016-10-20 20:45:40 +0000 | [diff] [blame] | 4380 | const enum Distro Distro = DetectDistro(getDriver().getVFS()); |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4381 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4382 | if (Triple.isAndroid()) |
| 4383 | return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; |
| Diana Picus | 86db9e7 | 2016-08-08 08:27:36 +0000 | [diff] [blame] | 4384 | |
| 4385 | if (Triple.isMusl()) { |
| Rafael Espindola | 0fa6680 | 2016-06-24 21:35:06 +0000 | [diff] [blame] | 4386 | std::string ArchName; |
| Diana Picus | 86db9e7 | 2016-08-08 08:27:36 +0000 | [diff] [blame] | 4387 | bool IsArm = false; |
| 4388 | |
| Rafael Espindola | 0fa6680 | 2016-06-24 21:35:06 +0000 | [diff] [blame] | 4389 | switch (Arch) { |
| Diana Picus | 86db9e7 | 2016-08-08 08:27:36 +0000 | [diff] [blame] | 4390 | case llvm::Triple::arm: |
| Rafael Espindola | 0fa6680 | 2016-06-24 21:35:06 +0000 | [diff] [blame] | 4391 | case llvm::Triple::thumb: |
| 4392 | ArchName = "arm"; |
| Diana Picus | 86db9e7 | 2016-08-08 08:27:36 +0000 | [diff] [blame] | 4393 | IsArm = true; |
| Rafael Espindola | 0fa6680 | 2016-06-24 21:35:06 +0000 | [diff] [blame] | 4394 | break; |
| Diana Picus | 86db9e7 | 2016-08-08 08:27:36 +0000 | [diff] [blame] | 4395 | case llvm::Triple::armeb: |
| Rafael Espindola | 0fa6680 | 2016-06-24 21:35:06 +0000 | [diff] [blame] | 4396 | case llvm::Triple::thumbeb: |
| 4397 | ArchName = "armeb"; |
| Diana Picus | 86db9e7 | 2016-08-08 08:27:36 +0000 | [diff] [blame] | 4398 | IsArm = true; |
| Rafael Espindola | 0fa6680 | 2016-06-24 21:35:06 +0000 | [diff] [blame] | 4399 | break; |
| 4400 | default: |
| 4401 | ArchName = Triple.getArchName().str(); |
| 4402 | } |
| Diana Picus | 86db9e7 | 2016-08-08 08:27:36 +0000 | [diff] [blame] | 4403 | if (IsArm && |
| 4404 | (Triple.getEnvironment() == llvm::Triple::MuslEABIHF || |
| 4405 | tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard)) |
| Rafael Espindola | 0fa6680 | 2016-06-24 21:35:06 +0000 | [diff] [blame] | 4406 | ArchName += "hf"; |
| 4407 | |
| 4408 | return "/lib/ld-musl-" + ArchName + ".so.1"; |
| 4409 | } |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4410 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4411 | std::string LibDir; |
| 4412 | std::string Loader; |
| 4413 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4414 | switch (Arch) { |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4415 | default: |
| 4416 | llvm_unreachable("unsupported architecture"); |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4417 | |
| 4418 | case llvm::Triple::aarch64: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4419 | LibDir = "lib"; |
| 4420 | Loader = "ld-linux-aarch64.so.1"; |
| 4421 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4422 | case llvm::Triple::aarch64_be: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4423 | LibDir = "lib"; |
| 4424 | Loader = "ld-linux-aarch64_be.so.1"; |
| 4425 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4426 | case llvm::Triple::arm: |
| 4427 | case llvm::Triple::thumb: |
| 4428 | case llvm::Triple::armeb: |
| 4429 | case llvm::Triple::thumbeb: { |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 4430 | const bool HF = |
| 4431 | Triple.getEnvironment() == llvm::Triple::GNUEABIHF || |
| 4432 | tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4433 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4434 | LibDir = "lib"; |
| 4435 | Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3"; |
| 4436 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4437 | } |
| 4438 | case llvm::Triple::mips: |
| 4439 | case llvm::Triple::mipsel: |
| 4440 | case llvm::Triple::mips64: |
| 4441 | case llvm::Triple::mips64el: { |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4442 | bool LE = (Triple.getArch() == llvm::Triple::mipsel) || |
| 4443 | (Triple.getArch() == llvm::Triple::mips64el); |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4444 | bool IsNaN2008 = tools::mips::isNaN2008(Args, Triple); |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4445 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4446 | LibDir = "lib" + tools::mips::getMipsABILibSuffix(Args, Triple); |
| 4447 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4448 | if (tools::mips::isUCLibc(Args)) |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4449 | Loader = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0"; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4450 | else if (!Triple.hasEnvironment() && |
| 4451 | Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies) |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4452 | Loader = LE ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1"; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4453 | else |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4454 | Loader = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1"; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4455 | |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4456 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4457 | } |
| 4458 | case llvm::Triple::ppc: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4459 | LibDir = "lib"; |
| 4460 | Loader = "ld.so.1"; |
| 4461 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4462 | case llvm::Triple::ppc64: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4463 | LibDir = "lib64"; |
| 4464 | Loader = |
| 4465 | (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2" : "ld64.so.1"; |
| 4466 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4467 | case llvm::Triple::ppc64le: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4468 | LibDir = "lib64"; |
| 4469 | Loader = |
| 4470 | (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2"; |
| 4471 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4472 | case llvm::Triple::sparc: |
| 4473 | case llvm::Triple::sparcel: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4474 | LibDir = "lib"; |
| 4475 | Loader = "ld-linux.so.2"; |
| 4476 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4477 | case llvm::Triple::sparcv9: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4478 | LibDir = "lib64"; |
| 4479 | Loader = "ld-linux.so.2"; |
| 4480 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4481 | case llvm::Triple::systemz: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4482 | LibDir = "lib"; |
| 4483 | Loader = "ld64.so.1"; |
| 4484 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4485 | case llvm::Triple::x86: |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4486 | LibDir = "lib"; |
| 4487 | Loader = "ld-linux.so.2"; |
| 4488 | break; |
| 4489 | case llvm::Triple::x86_64: { |
| 4490 | bool X32 = Triple.getEnvironment() == llvm::Triple::GNUX32; |
| 4491 | |
| 4492 | LibDir = X32 ? "libx32" : "lib64"; |
| 4493 | Loader = X32 ? "ld-linux-x32.so.2" : "ld-linux-x86-64.so.2"; |
| 4494 | break; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4495 | } |
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | if (Distro == Exherbo && (Triple.getVendor() == llvm::Triple::UnknownVendor || |
| 4499 | Triple.getVendor() == llvm::Triple::PC)) |
| 4500 | return "/usr/" + Triple.str() + "/lib/" + Loader; |
| 4501 | return "/" + LibDir + "/" + Loader; |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4504 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4505 | ArgStringList &CC1Args) const { |
| 4506 | const Driver &D = getDriver(); |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 4507 | std::string SysRoot = computeSysRoot(); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4508 | |
| 4509 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4510 | return; |
| 4511 | |
| 4512 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4513 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4514 | |
| 4515 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 4516 | SmallString<128> P(D.ResourceDir); |
| 4517 | llvm::sys::path::append(P, "include"); |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4518 | addSystemInclude(DriverArgs, CC1Args, P); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4519 | } |
| 4520 | |
| 4521 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 4522 | return; |
| 4523 | |
| 4524 | // Check for configure-time C include directories. |
| 4525 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 4526 | if (CIncludeDirs != "") { |
| 4527 | SmallVector<StringRef, 5> dirs; |
| 4528 | CIncludeDirs.split(dirs, ":"); |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4529 | for (StringRef dir : dirs) { |
| Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 4530 | StringRef Prefix = |
| 4531 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4532 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4533 | } |
| 4534 | return; |
| 4535 | } |
| 4536 | |
| 4537 | // Lacking those, try to detect the correct set of system includes for the |
| 4538 | // target triple. |
| 4539 | |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4540 | // Add include directories specific to the selected multilib set and multilib. |
| 4541 | if (GCCInstallation.isValid()) { |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 4542 | const auto &Callback = Multilibs.includeDirsCallback(); |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4543 | if (Callback) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 4544 | for (const auto &Path : Callback(GCCInstallation.getMultilib())) |
| 4545 | addExternCSystemIncludeIfExists( |
| 4546 | DriverArgs, CC1Args, GCCInstallation.getInstallPath() + Path); |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4547 | } |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4548 | } |
| 4549 | |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4550 | // Implement generic Debian multiarch support. |
| 4551 | const StringRef X86_64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4552 | "/usr/include/x86_64-linux-gnu", |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4553 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4554 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 4555 | // in use in any released version of Debian, so we should consider |
| 4556 | // removing them. |
| 4557 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4558 | const StringRef X86MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4559 | "/usr/include/i386-linux-gnu", |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4560 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4561 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 4562 | // in use in any released version of Debian, so we should consider |
| 4563 | // removing them. |
| 4564 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", |
| 4565 | "/usr/include/i486-linux-gnu"}; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4566 | const StringRef AArch64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4567 | "/usr/include/aarch64-linux-gnu"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4568 | const StringRef ARMMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4569 | "/usr/include/arm-linux-gnueabi"}; |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4570 | const StringRef ARMHFMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4571 | "/usr/include/arm-linux-gnueabihf"}; |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4572 | const StringRef ARMEBMultiarchIncludeDirs[] = { |
| 4573 | "/usr/include/armeb-linux-gnueabi"}; |
| 4574 | const StringRef ARMEBHFMultiarchIncludeDirs[] = { |
| 4575 | "/usr/include/armeb-linux-gnueabihf"}; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4576 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4577 | const StringRef MIPSELMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4578 | "/usr/include/mipsel-linux-gnu"}; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4579 | const StringRef MIPS64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4580 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4581 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4582 | "/usr/include/mips64el-linux-gnu", |
| 4583 | "/usr/include/mips64el-linux-gnuabi64"}; |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4584 | const StringRef PPCMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4585 | "/usr/include/powerpc-linux-gnu"}; |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4586 | const StringRef PPC64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4587 | "/usr/include/powerpc64-linux-gnu"}; |
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4588 | const StringRef PPC64LEMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4589 | "/usr/include/powerpc64le-linux-gnu"}; |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4590 | const StringRef SparcMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4591 | "/usr/include/sparc-linux-gnu"}; |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4592 | const StringRef Sparc64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4593 | "/usr/include/sparc64-linux-gnu"}; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4594 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { |
| 4595 | "/usr/include/s390x-linux-gnu"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4596 | ArrayRef<StringRef> MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4597 | switch (getTriple().getArch()) { |
| 4598 | case llvm::Triple::x86_64: |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4599 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4600 | break; |
| 4601 | case llvm::Triple::x86: |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4602 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4603 | break; |
| 4604 | case llvm::Triple::aarch64: |
| 4605 | case llvm::Triple::aarch64_be: |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4606 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4607 | break; |
| 4608 | case llvm::Triple::arm: |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4609 | case llvm::Triple::thumb: |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4610 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 4611 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; |
| 4612 | else |
| 4613 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4614 | break; |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4615 | case llvm::Triple::armeb: |
| 4616 | case llvm::Triple::thumbeb: |
| 4617 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 4618 | MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs; |
| 4619 | else |
| 4620 | MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs; |
| 4621 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4622 | case llvm::Triple::mips: |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4623 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4624 | break; |
| 4625 | case llvm::Triple::mipsel: |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4626 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4627 | break; |
| 4628 | case llvm::Triple::mips64: |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4629 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4630 | break; |
| 4631 | case llvm::Triple::mips64el: |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4632 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4633 | break; |
| 4634 | case llvm::Triple::ppc: |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4635 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4636 | break; |
| 4637 | case llvm::Triple::ppc64: |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4638 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4639 | break; |
| 4640 | case llvm::Triple::ppc64le: |
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4641 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4642 | break; |
| 4643 | case llvm::Triple::sparc: |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4644 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4645 | break; |
| 4646 | case llvm::Triple::sparcv9: |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4647 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4648 | break; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4649 | case llvm::Triple::systemz: |
| 4650 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; |
| 4651 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4652 | default: |
| 4653 | break; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4654 | } |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4655 | for (StringRef Dir : MultiarchIncludeDirs) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4656 | if (D.getVFS().exists(SysRoot + Dir)) { |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4657 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4658 | break; |
| 4659 | } |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | if (getTriple().getOS() == llvm::Triple::RTEMS) |
| 4663 | return; |
| 4664 | |
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4665 | // Add an include of '/include' directly. This isn't provided by default by |
| 4666 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 4667 | // 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] | 4668 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); |
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4669 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4670 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4671 | } |
| 4672 | |
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4673 | static std::string DetectLibcxxIncludePath(StringRef base) { |
| 4674 | std::error_code EC; |
| 4675 | int MaxVersion = 0; |
| 4676 | std::string MaxVersionString = ""; |
| 4677 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; |
| 4678 | LI = LI.increment(EC)) { |
| 4679 | StringRef VersionText = llvm::sys::path::filename(LI->path()); |
| 4680 | int Version; |
| 4681 | if (VersionText[0] == 'v' && |
| 4682 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { |
| 4683 | if (Version > MaxVersion) { |
| 4684 | MaxVersion = Version; |
| 4685 | MaxVersionString = VersionText; |
| 4686 | } |
| 4687 | } |
| 4688 | } |
| 4689 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; |
| 4690 | } |
| 4691 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 4692 | std::string Linux::findLibCxxIncludePath() const { |
| 4693 | const std::string LibCXXIncludePathCandidates[] = { |
| 4694 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), |
| 4695 | // If this is a development, non-installed, clang, libcxx will |
| 4696 | // not be found at ../include/c++ but it likely to be found at |
| 4697 | // one of the following two locations: |
| 4698 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/local/include/c++"), |
| 4699 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++") }; |
| 4700 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { |
| 4701 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) |
| 4702 | continue; |
| 4703 | // Use the first candidate that exists. |
| 4704 | return IncludePath; |
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4705 | } |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 4706 | return ""; |
| 4707 | } |
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4708 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 4709 | void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
| 4710 | llvm::opt::ArgStringList &CC1Args) const { |
| Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 4711 | // We need a detected GCC installation on Linux to provide libstdc++'s |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 4712 | // headers. |
| Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 4713 | if (!GCCInstallation.isValid()) |
| 4714 | return; |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4715 | |
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4716 | // By default, look for the C++ headers in an include directory adjacent to |
| 4717 | // the lib directory of the GCC installation. Note that this is expect to be |
| 4718 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. |
| 4719 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4720 | StringRef InstallDir = GCCInstallation.getInstallPath(); |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4721 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4722 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4723 | const std::string GCCMultiarchTriple = getMultiarchTriple( |
| 4724 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4725 | const std::string TargetMultiarchTriple = |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4726 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 4727 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4728 | |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4729 | // The primary search for libstdc++ supports multiarch variants. |
| Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 4730 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4731 | "/c++/" + Version.Text, TripleStr, |
| 4732 | GCCMultiarchTriple, TargetMultiarchTriple, |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4733 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
| Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4734 | return; |
| 4735 | |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4736 | // Otherwise, fall back on a bunch of options which don't use multiarch |
| 4737 | // layouts for simplicity. |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4738 | const std::string LibStdCXXIncludePathCandidates[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4739 | // Gentoo is weird and places its headers inside the GCC install, |
| 4740 | // 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] | 4741 | InstallDir.str() + "/include/g++-v" + Version.Text, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4742 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + |
| 4743 | Version.MinorStr, |
| 4744 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, |
| 4745 | // Android standalone toolchain has C++ headers in yet another place. |
| 4746 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4747 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, |
| 4748 | // without a subdirectory corresponding to the gcc version. |
| 4749 | LibDir.str() + "/../include/c++", |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4750 | }; |
| 4751 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4752 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4753 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, |
| 4754 | /*GCCMultiarchTriple*/ "", |
| 4755 | /*TargetMultiarchTriple*/ "", |
| 4756 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4757 | break; |
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4758 | } |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4759 | } |
| 4760 | |
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4761 | void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, |
| 4762 | ArgStringList &CC1Args) const { |
| Justin Lebar | 49ec146 | 2016-10-11 17:36:03 +0000 | [diff] [blame] | 4763 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 4764 | // Add cuda_wrappers/* to our system include path. This lets us wrap |
| 4765 | // standard library headers. |
| 4766 | SmallString<128> P(getDriver().ResourceDir); |
| 4767 | llvm::sys::path::append(P, "include"); |
| 4768 | llvm::sys::path::append(P, "cuda_wrappers"); |
| 4769 | addSystemInclude(DriverArgs, CC1Args, P); |
| 4770 | } |
| 4771 | |
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4772 | if (DriverArgs.hasArg(options::OPT_nocudainc)) |
| 4773 | return; |
| 4774 | |
| Justin Lebar | 423019d | 2016-04-16 00:11:11 +0000 | [diff] [blame] | 4775 | if (!CudaInstallation.isValid()) { |
| 4776 | getDriver().Diag(diag::err_drv_no_cuda_installation); |
| 4777 | return; |
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4778 | } |
| Justin Lebar | 423019d | 2016-04-16 00:11:11 +0000 | [diff] [blame] | 4779 | |
| 4780 | addSystemInclude(DriverArgs, CC1Args, CudaInstallation.getIncludePath()); |
| 4781 | CC1Args.push_back("-include"); |
| 4782 | CC1Args.push_back("__clang_cuda_runtime_wrapper.h"); |
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 4785 | void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs, |
| 4786 | ArgStringList &CC1Args) const { |
| 4787 | if (GCCInstallation.isValid()) { |
| 4788 | CC1Args.push_back("-isystem"); |
| 4789 | CC1Args.push_back(DriverArgs.MakeArgString( |
| 4790 | GCCInstallation.getParentLibPath() + "/../" + |
| 4791 | GCCInstallation.getTriple().str() + "/include")); |
| 4792 | } |
| 4793 | } |
| 4794 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4795 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 4796 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4797 | SanitizerMask Linux::getSupportedSanitizers() const { |
| 4798 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 4799 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 4800 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 4801 | getTriple().getArch() == llvm::Triple::mips64el; |
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4802 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || |
| 4803 | getTriple().getArch() == llvm::Triple::ppc64le; |
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4804 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || |
| 4805 | getTriple().getArch() == llvm::Triple::aarch64_be; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4806 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 4807 | Res |= SanitizerKind::Address; |
| 4808 | Res |= SanitizerKind::KernelAddress; |
| 4809 | Res |= SanitizerKind::Vptr; |
| Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 4810 | Res |= SanitizerKind::SafeStack; |
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4811 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4812 | Res |= SanitizerKind::DataFlow; |
| Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 4813 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4814 | Res |= SanitizerKind::Leak; |
| Bill Schmidt | 4b8841a | 2015-12-08 22:48:02 +0000 | [diff] [blame] | 4815 | if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4816 | Res |= SanitizerKind::Thread; |
| Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 4817 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) |
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4818 | Res |= SanitizerKind::Memory; |
| Sagar Thakur | c9113e4 | 2016-09-07 12:23:15 +0000 | [diff] [blame] | 4819 | if (IsX86_64 || IsMIPS64) |
| Derek Bruening | 256c2e1 | 2016-04-21 21:32:04 +0000 | [diff] [blame] | 4820 | Res |= SanitizerKind::Efficiency; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4821 | if (IsX86 || IsX86_64) { |
| 4822 | Res |= SanitizerKind::Function; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4823 | } |
| 4824 | return Res; |
| 4825 | } |
| 4826 | |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 4827 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4828 | llvm::opt::ArgStringList &CmdArgs) const { |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 4829 | if (!needsProfileRT(Args)) return; |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4830 | |
| 4831 | // Add linker option -u__llvm_runtime_variable to cause runtime |
| 4832 | // initialization module to be linked in. |
| 4833 | if (!Args.hasArg(options::OPT_coverage)) |
| 4834 | CmdArgs.push_back(Args.MakeArgString( |
| 4835 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); |
| Vedant Kumar | 5fb00e4 | 2016-07-27 23:01:55 +0000 | [diff] [blame] | 4836 | ToolChain::addProfileRTLibs(Args, CmdArgs); |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
| Petr Hosek | 62e1d23 | 2016-10-06 06:08:09 +0000 | [diff] [blame] | 4839 | /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly. |
| 4840 | |
| 4841 | Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple, |
| 4842 | const ArgList &Args) |
| 4843 | : Generic_ELF(D, Triple, Args) { |
| 4844 | |
| 4845 | getFilePaths().push_back(D.SysRoot + "/lib"); |
| 4846 | getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia"); |
| 4847 | |
| 4848 | // Use LLD by default. |
| 4849 | DefaultLinker = "lld"; |
| 4850 | } |
| 4851 | |
| 4852 | Tool *Fuchsia::buildAssembler() const { |
| 4853 | return new tools::gnutools::Assembler(*this); |
| 4854 | } |
| 4855 | |
| 4856 | Tool *Fuchsia::buildLinker() const { |
| 4857 | return new tools::fuchsia::Linker(*this); |
| 4858 | } |
| 4859 | |
| 4860 | ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType( |
| 4861 | const ArgList &Args) const { |
| 4862 | if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) { |
| 4863 | StringRef Value = A->getValue(); |
| 4864 | if (Value != "compiler-rt") |
| 4865 | getDriver().Diag(diag::err_drv_invalid_rtlib_name) |
| 4866 | << A->getAsString(Args); |
| 4867 | } |
| 4868 | |
| 4869 | return ToolChain::RLT_CompilerRT; |
| 4870 | } |
| 4871 | |
| 4872 | ToolChain::CXXStdlibType |
| 4873 | Fuchsia::GetCXXStdlibType(const ArgList &Args) const { |
| 4874 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 4875 | StringRef Value = A->getValue(); |
| 4876 | if (Value != "libc++") |
| 4877 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) |
| 4878 | << A->getAsString(Args); |
| 4879 | } |
| 4880 | |
| 4881 | return ToolChain::CST_Libcxx; |
| 4882 | } |
| 4883 | |
| 4884 | void Fuchsia::addClangTargetOptions(const ArgList &DriverArgs, |
| 4885 | ArgStringList &CC1Args) const { |
| 4886 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 4887 | options::OPT_fno_use_init_array, true)) |
| 4888 | CC1Args.push_back("-fuse-init-array"); |
| 4889 | } |
| 4890 | |
| 4891 | void Fuchsia::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4892 | ArgStringList &CC1Args) const { |
| 4893 | const Driver &D = getDriver(); |
| 4894 | |
| 4895 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4896 | return; |
| 4897 | |
| 4898 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 4899 | SmallString<128> P(D.ResourceDir); |
| 4900 | llvm::sys::path::append(P, "include"); |
| 4901 | addSystemInclude(DriverArgs, CC1Args, P); |
| 4902 | } |
| 4903 | |
| 4904 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 4905 | return; |
| 4906 | |
| 4907 | // Check for configure-time C include directories. |
| 4908 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 4909 | if (CIncludeDirs != "") { |
| 4910 | SmallVector<StringRef, 5> dirs; |
| 4911 | CIncludeDirs.split(dirs, ":"); |
| 4912 | for (StringRef dir : dirs) { |
| 4913 | StringRef Prefix = |
| 4914 | llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : ""; |
| 4915 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
| 4916 | } |
| 4917 | return; |
| 4918 | } |
| 4919 | |
| 4920 | addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include"); |
| 4921 | } |
| 4922 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 4923 | std::string Fuchsia::findLibCxxIncludePath() const { |
| 4924 | return getDriver().SysRoot + "/include/c++/v1"; |
| Petr Hosek | 62e1d23 | 2016-10-06 06:08:09 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | void Fuchsia::AddCXXStdlibLibArgs(const ArgList &Args, |
| 4928 | ArgStringList &CmdArgs) const { |
| 4929 | (void) GetCXXStdlibType(Args); |
| 4930 | CmdArgs.push_back("-lc++"); |
| 4931 | CmdArgs.push_back("-lc++abi"); |
| 4932 | CmdArgs.push_back("-lunwind"); |
| 4933 | } |
| 4934 | |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4935 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 4936 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4937 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, |
| 4938 | const ArgList &Args) |
| 4939 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4940 | |
| 4941 | // Path mangling to find libexec |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4942 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 4943 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4944 | getProgramPaths().push_back(getDriver().Dir); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4945 | |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4946 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4947 | getFilePaths().push_back("/usr/lib"); |
| Dimitry Andric | f59a2b3 | 2015-12-27 10:01:44 +0000 | [diff] [blame] | 4948 | getFilePaths().push_back("/usr/lib/gcc50"); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4949 | } |
| 4950 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4951 | Tool *DragonFly::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4952 | return new tools::dragonfly::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | Tool *DragonFly::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4956 | return new tools::dragonfly::Linker(*this); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4957 | } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4958 | |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4959 | /// CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary, |
| 4960 | /// which isn't properly a linker but nonetheless performs the step of stitching |
| 4961 | /// together object files from the assembler into a single blob. |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4962 | |
| 4963 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4964 | const ArgList &Args) |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4965 | : Linux(D, Triple, Args) { |
| 4966 | if (CudaInstallation.isValid()) |
| 4967 | getProgramPaths().push_back(CudaInstallation.getBinPath()); |
| 4968 | } |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4969 | |
| 4970 | void |
| 4971 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, |
| 4972 | llvm::opt::ArgStringList &CC1Args) const { |
| 4973 | Linux::addClangTargetOptions(DriverArgs, CC1Args); |
| 4974 | CC1Args.push_back("-fcuda-is-device"); |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4975 | |
| Justin Lebar | d3a44f6 | 2016-04-05 18:26:20 +0000 | [diff] [blame] | 4976 | if (DriverArgs.hasFlag(options::OPT_fcuda_flush_denormals_to_zero, |
| 4977 | options::OPT_fno_cuda_flush_denormals_to_zero, false)) |
| 4978 | CC1Args.push_back("-fcuda-flush-denormals-to-zero"); |
| 4979 | |
| Justin Lebar | 91f6f07 | 2016-05-23 20:19:56 +0000 | [diff] [blame] | 4980 | if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals, |
| 4981 | options::OPT_fno_cuda_approx_transcendentals, false)) |
| 4982 | CC1Args.push_back("-fcuda-approx-transcendentals"); |
| 4983 | |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4984 | if (DriverArgs.hasArg(options::OPT_nocudalib)) |
| 4985 | return; |
| 4986 | |
| Artem Belevich | 02a1e97 | 2016-08-02 23:12:51 +0000 | [diff] [blame] | 4987 | StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ); |
| 4988 | assert(!GpuArch.empty() && "Must have an explicit GPU arch."); |
| 4989 | std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch); |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4990 | |
| Artem Belevich | 02a1e97 | 2016-08-02 23:12:51 +0000 | [diff] [blame] | 4991 | if (LibDeviceFile.empty()) { |
| 4992 | getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch; |
| 4993 | return; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4994 | } |
| Artem Belevich | 02a1e97 | 2016-08-02 23:12:51 +0000 | [diff] [blame] | 4995 | |
| 4996 | CC1Args.push_back("-mlink-cuda-bitcode"); |
| 4997 | CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile)); |
| 4998 | |
| 4999 | // Libdevice in CUDA-7.0 requires PTX version that's more recent |
| 5000 | // than LLVM defaults to. Use PTX4.2 which is the PTX version that |
| 5001 | // came with CUDA-7.0. |
| 5002 | CC1Args.push_back("-target-feature"); |
| 5003 | CC1Args.push_back("+ptx42"); |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 5004 | } |
| 5005 | |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 5006 | void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs, |
| 5007 | ArgStringList &CC1Args) const { |
| 5008 | // Check our CUDA version if we're going to include the CUDA headers. |
| 5009 | if (!DriverArgs.hasArg(options::OPT_nocudainc) && |
| Justin Lebar | f399771 | 2016-07-07 18:24:28 +0000 | [diff] [blame] | 5010 | !DriverArgs.hasArg(options::OPT_no_cuda_version_check)) { |
| Justin Lebar | c43ad9e | 2016-07-07 18:17:52 +0000 | [diff] [blame] | 5011 | StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ); |
| 5012 | assert(!Arch.empty() && "Must have an explicit GPU arch."); |
| 5013 | CudaInstallation.CheckCudaVersionSupportsArch(StringToCudaArch(Arch)); |
| 5014 | } |
| 5015 | Linux::AddCudaIncludeArgs(DriverArgs, CC1Args); |
| 5016 | } |
| 5017 | |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 5018 | llvm::opt::DerivedArgList * |
| 5019 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, |
| Samuel Antao | 31fef98 | 2016-10-27 17:39:44 +0000 | [diff] [blame] | 5020 | StringRef BoundArch, Action::OffloadKind) const { |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 5021 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 5022 | const OptTable &Opts = getDriver().getOpts(); |
| 5023 | |
| 5024 | for (Arg *A : Args) { |
| 5025 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 5026 | // Skip this argument unless the architecture matches BoundArch |
| Mehdi Amini | c50b1a2 | 2016-10-07 21:27:26 +0000 | [diff] [blame] | 5027 | if (BoundArch.empty() || A->getValue(0) != BoundArch) |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 5028 | continue; |
| 5029 | |
| 5030 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| 5031 | unsigned Prev = Index; |
| 5032 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| 5033 | |
| 5034 | // If the argument parsing failed or more than one argument was |
| 5035 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 5036 | // extra arguments. Emit an error and ignore. |
| 5037 | // |
| 5038 | // We also want to disallow any options which would alter the |
| 5039 | // driver behavior; that isn't going to work in our model. We |
| 5040 | // use isDriverOption() as an approximation, although things |
| 5041 | // like -O4 are going to slip through. |
| 5042 | if (!XarchArg || Index > Prev + 1) { |
| 5043 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| 5044 | << A->getAsString(Args); |
| 5045 | continue; |
| 5046 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| 5047 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| 5048 | << A->getAsString(Args); |
| 5049 | continue; |
| 5050 | } |
| 5051 | XarchArg->setBaseArg(A); |
| 5052 | A = XarchArg.release(); |
| 5053 | DAL->AddSynthesizedArg(A); |
| 5054 | } |
| 5055 | DAL->append(A); |
| 5056 | } |
| 5057 | |
| Mehdi Amini | c50b1a2 | 2016-10-07 21:27:26 +0000 | [diff] [blame] | 5058 | if (!BoundArch.empty()) { |
| Justin Lebar | 4db224e | 2016-06-15 23:46:11 +0000 | [diff] [blame] | 5059 | DAL->eraseArg(options::OPT_march_EQ); |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 5060 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); |
| Justin Lebar | 4db224e | 2016-06-15 23:46:11 +0000 | [diff] [blame] | 5061 | } |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 5062 | return DAL; |
| 5063 | } |
| 5064 | |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 5065 | Tool *CudaToolChain::buildAssembler() const { |
| 5066 | return new tools::NVPTX::Assembler(*this); |
| 5067 | } |
| 5068 | |
| 5069 | Tool *CudaToolChain::buildLinker() const { |
| 5070 | return new tools::NVPTX::Linker(*this); |
| 5071 | } |
| 5072 | |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5073 | /// XCore tool chain |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5074 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, |
| 5075 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 5076 | : ToolChain(D, Triple, Args) { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5077 | // ProgramPaths are found via 'PATH' environment variable. |
| 5078 | } |
| 5079 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5080 | Tool *XCoreToolChain::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 5081 | return new tools::XCore::Assembler(*this); |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5082 | } |
| 5083 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5084 | Tool *XCoreToolChain::buildLinker() const { |
| 5085 | return new tools::XCore::Linker(*this); |
| 5086 | } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5087 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5088 | bool XCoreToolChain::isPICDefault() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5089 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5090 | bool XCoreToolChain::isPIEDefault() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5091 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5092 | bool XCoreToolChain::isPICDefaultForced() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5093 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5094 | bool XCoreToolChain::SupportsProfiling() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5095 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5096 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5097 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5098 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 5099 | ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5100 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 5101 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 5102 | return; |
| 5103 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { |
| 5104 | SmallVector<StringRef, 4> Dirs; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 5105 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5106 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 5107 | ArrayRef<StringRef> DirVec(Dirs); |
| 5108 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 5109 | } |
| 5110 | } |
| 5111 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5112 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, |
| 5113 | ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5114 | CC1Args.push_back("-nostdsysteminc"); |
| 5115 | } |
| 5116 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5117 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( |
| 5118 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5119 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 5120 | DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 5121 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5122 | return; |
| 5123 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { |
| 5124 | SmallVector<StringRef, 4> Dirs; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 5125 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5126 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 5127 | ArrayRef<StringRef> DirVec(Dirs); |
| 5128 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 5129 | } |
| 5130 | } |
| 5131 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 5132 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 5133 | ArgStringList &CmdArgs) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 5134 | // We don't output any lib args. This is handled by xcc. |
| 5135 | } |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 5136 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 5137 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, |
| 5138 | const ArgList &Args) |
| Douglas Katzman | 5eddc23 | 2016-05-09 19:09:59 +0000 | [diff] [blame] | 5139 | : Generic_ELF(D, Triple, Args) { |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 5140 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use |
| 5141 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. |
| 5142 | // This won't work to find gcc. Instead we give the installation detector an |
| 5143 | // extra triple, which is preferable to further hacks of the logic that at |
| 5144 | // present is based solely on getArch(). In particular, it would be wrong to |
| 5145 | // choose the myriad installation when targeting a non-myriad sparc install. |
| 5146 | switch (Triple.getArch()) { |
| 5147 | default: |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 5148 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() |
| 5149 | << "myriad"; |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 5150 | case llvm::Triple::sparc: |
| 5151 | case llvm::Triple::sparcel: |
| 5152 | case llvm::Triple::shave: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 5153 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 5154 | } |
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 5155 | |
| 5156 | if (GCCInstallation.isValid()) { |
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 5157 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. |
| 5158 | // These files are tied to a particular version of gcc. |
| 5159 | SmallString<128> CompilerSupportDir(GCCInstallation.getInstallPath()); |
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 5160 | addPathIfExists(D, CompilerSupportDir, getFilePaths()); |
| 5161 | } |
| Douglas Katzman | 1e04e46 | 2016-10-25 23:02:30 +0000 | [diff] [blame] | 5162 | // libstd++ and libc++ must both be found in this one place. |
| 5163 | addPathIfExists(D, D.Dir + "/../sparc-myriad-elf/lib", getFilePaths()); |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 5166 | MyriadToolChain::~MyriadToolChain() {} |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 5167 | |
| Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 5168 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 5169 | ArgStringList &CC1Args) const { |
| 5170 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 5171 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 5172 | } |
| 5173 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 5174 | std::string MyriadToolChain::findLibCxxIncludePath() const { |
| 5175 | std::string Path(getDriver().getInstalledDir()); |
| 5176 | return Path + "/../include/c++/v1"; |
| 5177 | } |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 5178 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 5179 | void MyriadToolChain::addLibStdCxxIncludePaths( |
| 5180 | const llvm::opt::ArgList &DriverArgs, |
| 5181 | llvm::opt::ArgStringList &CC1Args) const { |
| 5182 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 5183 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| 5184 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| 5185 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| 5186 | addLibStdCXXIncludePaths( |
| 5187 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 5188 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 5191 | // MyriadToolChain handles several triples: |
| 5192 | // {shave,sparc{,el}}-myriad-{rtems,unknown}-elf |
| 5193 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { |
| 5194 | // The inherited method works fine if not targeting the SHAVE. |
| 5195 | if (!isShaveCompilation(getTriple())) |
| 5196 | return ToolChain::SelectTool(JA); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 5197 | switch (JA.getKind()) { |
| Douglas Katzman | 9dc4c62 | 2015-11-20 04:58:12 +0000 | [diff] [blame] | 5198 | case Action::PreprocessJobClass: |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 5199 | case Action::CompileJobClass: |
| 5200 | if (!Compiler) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 5201 | Compiler.reset(new tools::SHAVE::Compiler(*this)); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 5202 | return Compiler.get(); |
| 5203 | case Action::AssembleJobClass: |
| 5204 | if (!Assembler) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 5205 | Assembler.reset(new tools::SHAVE::Assembler(*this)); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 5206 | return Assembler.get(); |
| 5207 | default: |
| 5208 | return ToolChain::getTool(JA.getKind()); |
| 5209 | } |
| 5210 | } |
| 5211 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 5212 | Tool *MyriadToolChain::buildLinker() const { |
| 5213 | return new tools::Myriad::Linker(*this); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 5214 | } |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 5215 | |
| Douglas Katzman | 3972f9e | 2016-09-09 18:20:49 +0000 | [diff] [blame] | 5216 | SanitizerMask MyriadToolChain::getSupportedSanitizers() const { |
| 5217 | return SanitizerKind::Address; |
| 5218 | } |
| 5219 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 5220 | WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple, |
| 5221 | const llvm::opt::ArgList &Args) |
| 5222 | : ToolChain(D, Triple, Args) { |
| Dan Gohman | 57b62c5 | 2016-02-22 19:26:15 +0000 | [diff] [blame] | 5223 | |
| 5224 | assert(Triple.isArch32Bit() != Triple.isArch64Bit()); |
| 5225 | getFilePaths().push_back( |
| 5226 | getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64")); |
| 5227 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 5228 | // Use LLD by default. |
| 5229 | DefaultLinker = "lld"; |
| 5230 | } |
| 5231 | |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 5232 | bool WebAssembly::IsMathErrnoDefault() const { return false; } |
| 5233 | |
| 5234 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } |
| 5235 | |
| 5236 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } |
| 5237 | |
| 5238 | bool WebAssembly::isPICDefault() const { return false; } |
| 5239 | |
| 5240 | bool WebAssembly::isPIEDefault() const { return false; } |
| 5241 | |
| 5242 | bool WebAssembly::isPICDefaultForced() const { return false; } |
| 5243 | |
| 5244 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } |
| 5245 | |
| 5246 | // TODO: Support Objective C stuff. |
| 5247 | bool WebAssembly::SupportsObjCGC() const { return false; } |
| 5248 | |
| 5249 | bool WebAssembly::hasBlocksRuntime() const { return false; } |
| 5250 | |
| 5251 | // TODO: Support profiling. |
| 5252 | bool WebAssembly::SupportsProfiling() const { return false; } |
| 5253 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 5254 | bool WebAssembly::HasNativeLLVMSupport() const { return true; } |
| 5255 | |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 5256 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, |
| 5257 | ArgStringList &CC1Args) const { |
| 5258 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 5259 | options::OPT_fno_use_init_array, true)) |
| 5260 | CC1Args.push_back("-fuse-init-array"); |
| 5261 | } |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5262 | |
| Dan Gohman | 6ad8f61 | 2016-01-14 16:00:13 +0000 | [diff] [blame] | 5263 | ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const { |
| 5264 | return ToolChain::RLT_CompilerRT; |
| 5265 | } |
| 5266 | |
| 5267 | ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { |
| 5268 | return ToolChain::CST_Libcxx; |
| 5269 | } |
| 5270 | |
| 5271 | void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 5272 | ArgStringList &CC1Args) const { |
| 5273 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 5274 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 5275 | } |
| 5276 | |
| Richard Smith | 2680bc9 | 2016-10-29 17:28:48 +0000 | [diff] [blame] | 5277 | void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 5278 | ArgStringList &CC1Args) const { |
| Dan Gohman | 6ad8f61 | 2016-01-14 16:00:13 +0000 | [diff] [blame] | 5279 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc) && |
| 5280 | !DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 5281 | addSystemInclude(DriverArgs, CC1Args, |
| 5282 | getDriver().SysRoot + "/include/c++/v1"); |
| 5283 | } |
| 5284 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 5285 | Tool *WebAssembly::buildLinker() const { |
| 5286 | return new tools::wasm::Linker(*this); |
| 5287 | } |
| 5288 | |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5289 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 5290 | : Generic_ELF(D, Triple, Args) { |
| 5291 | if (Args.hasArg(options::OPT_static)) |
| 5292 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; |
| 5293 | |
| Paul Robinson | 9d61361 | 2016-05-16 17:22:25 +0000 | [diff] [blame] | 5294 | // 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] | 5295 | // if it exists; otherwise use the driver's installation path, which |
| 5296 | // should be <SDK_DIR>/host_tools/bin. |
| 5297 | |
| 5298 | SmallString<512> PS4SDKDir; |
| Paul Robinson | 9d61361 | 2016-05-16 17:22:25 +0000 | [diff] [blame] | 5299 | if (const char *EnvValue = getenv("SCE_ORBIS_SDK_DIR")) { |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5300 | if (!llvm::sys::fs::exists(EnvValue)) |
| 5301 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; |
| 5302 | PS4SDKDir = EnvValue; |
| 5303 | } else { |
| 5304 | PS4SDKDir = getDriver().Dir; |
| 5305 | llvm::sys::path::append(PS4SDKDir, "/../../"); |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 5306 | } |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5307 | |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 5308 | // 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] | 5309 | // PS4's include or lib directories. This behavior could be changed if |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 5310 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 5311 | // If -isysroot was passed, use that as the SDK base path. |
| 5312 | std::string PrefixDir; |
| 5313 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 5314 | PrefixDir = A->getValue(); |
| 5315 | if (!llvm::sys::fs::exists(PrefixDir)) |
| 5316 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; |
| 5317 | } else |
| 5318 | PrefixDir = PS4SDKDir.str(); |
| 5319 | |
| 5320 | SmallString<512> PS4SDKIncludeDir(PrefixDir); |
| 5321 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); |
| 5322 | if (!Args.hasArg(options::OPT_nostdinc) && |
| 5323 | !Args.hasArg(options::OPT_nostdlibinc) && |
| 5324 | !Args.hasArg(options::OPT_isysroot) && |
| 5325 | !Args.hasArg(options::OPT__sysroot_EQ) && |
| 5326 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { |
| 5327 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 5328 | << "PS4 system headers" << PS4SDKIncludeDir; |
| 5329 | } |
| 5330 | |
| 5331 | SmallString<512> PS4SDKLibDir(PS4SDKDir); |
| 5332 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); |
| 5333 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5334 | !Args.hasArg(options::OPT_nodefaultlibs) && |
| 5335 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && |
| 5336 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && |
| 5337 | !Args.hasArg(options::OPT_emit_ast) && |
| 5338 | !llvm::sys::fs::exists(PS4SDKLibDir)) { |
| 5339 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 5340 | << "PS4 system libraries" << PS4SDKLibDir; |
| 5341 | return; |
| 5342 | } |
| 5343 | getFilePaths().push_back(PS4SDKLibDir.str()); |
| 5344 | } |
| 5345 | |
| 5346 | Tool *PS4CPU::buildAssembler() const { |
| 5347 | return new tools::PS4cpu::Assemble(*this); |
| 5348 | } |
| 5349 | |
| 5350 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } |
| 5351 | |
| 5352 | bool PS4CPU::isPICDefault() const { return true; } |
| 5353 | |
| 5354 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } |
| 5355 | |
| 5356 | SanitizerMask PS4CPU::getSupportedSanitizers() const { |
| 5357 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 5358 | Res |= SanitizerKind::Address; |
| 5359 | Res |= SanitizerKind::Vptr; |
| 5360 | return Res; |
| 5361 | } |
| David L Kreitzer | d397ea4 | 2016-10-14 20:44:33 +0000 | [diff] [blame] | 5362 | |
| 5363 | Contiki::Contiki(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 5364 | : Generic_ELF(D, Triple, Args) {} |
| 5365 | |
| 5366 | SanitizerMask Contiki::getSupportedSanitizers() const { |
| 5367 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 5368 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 5369 | if (IsX86) |
| 5370 | Res |= SanitizerKind::SafeStack; |
| 5371 | return Res; |
| 5372 | } |