| 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" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 11 | #include "clang/Basic/ObjCRuntime.h" | 
|  | 12 | #include "clang/Basic/Version.h" | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 13 | #include "clang/Basic/VirtualFileSystem.h" | 
| Alp Toker | 1d257e1 | 2014-06-04 03:28:55 +0000 | [diff] [blame] | 14 | #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX | 
| Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Compilation.h" | 
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Driver.h" | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 17 | #include "clang/Driver/DriverDiagnostic.h" | 
| Daniel Dunbar | da13faf | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 18 | #include "clang/Driver/Options.h" | 
| Alexey Samsonov | 609213f9 | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 19 | #include "clang/Driver/SanitizerArgs.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" | 
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallString.h" | 
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringExtras.h" | 
| Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringSwitch.h" | 
| Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 24 | #include "llvm/Option/Arg.h" | 
|  | 25 | #include "llvm/Option/ArgList.h" | 
|  | 26 | #include "llvm/Option/OptTable.h" | 
|  | 27 | #include "llvm/Option/Option.h" | 
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 28 | #include "llvm/ProfileData/InstrProf.h" | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" | 
| Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 30 | #include "llvm/Support/FileSystem.h" | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 31 | #include "llvm/Support/MemoryBuffer.h" | 
| Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Path.h" | 
| Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Program.h" | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/TargetParser.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" | 
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 36 | #include <cstdlib> // ::getenv | 
| Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 37 | #include <system_error> | 
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 38 |  | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 39 | using namespace clang::driver; | 
|  | 40 | using namespace clang::driver::toolchains; | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 41 | using namespace clang; | 
| Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 42 | using namespace llvm::opt; | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 43 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 44 | MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 45 | : ToolChain(D, Triple, Args) { | 
| Tim Northover | 15ff71d | 2014-05-22 13:12:14 +0000 | [diff] [blame] | 46 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. | 
|  | 47 | getProgramPaths().push_back(getDriver().getInstalledDir()); | 
|  | 48 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
|  | 49 | getProgramPaths().push_back(getDriver().Dir); | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 50 | } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 51 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 52 | /// Darwin - Darwin tool chain for i386 and x86_64. | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 53 | Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 54 | : MachO(D, Triple, Args), TargetInitialized(false) {} | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 55 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 56 | types::ID MachO::LookupTypeForExtension(const char *Ext) const { | 
| Daniel Dunbar | cc7df6c | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 57 | types::ID Ty = types::lookupTypeForExtension(Ext); | 
|  | 58 |  | 
|  | 59 | // Darwin always preprocesses assembly files (unless -x is used explicitly). | 
|  | 60 | if (Ty == types::TY_PP_Asm) | 
|  | 61 | return types::TY_Asm; | 
|  | 62 |  | 
|  | 63 | return Ty; | 
|  | 64 | } | 
|  | 65 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 66 | bool MachO::HasNativeLLVMSupport() const { return true; } | 
| Daniel Dunbar | 62123a1 | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 67 |  | 
| Jonas Hahnfeld | aae8374 | 2016-02-12 07:48:37 +0000 | [diff] [blame] | 68 | ToolChain::CXXStdlibType Darwin::GetDefaultCXXStdlibType() const { | 
|  | 69 | // Default to use libc++ on OS X 10.9+ and iOS 7+. | 
|  | 70 | if ((isTargetMacOS() && !isMacosxVersionLT(10, 9)) || | 
|  | 71 | (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) || | 
|  | 72 | isTargetWatchOSBased()) | 
|  | 73 | return ToolChain::CST_Libcxx; | 
|  | 74 |  | 
|  | 75 | return ToolChain::CST_Libstdcxx; | 
|  | 76 | } | 
|  | 77 |  | 
| John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 78 | /// 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] | 79 | ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 80 | if (isTargetWatchOSBased()) | 
| Tim Northover | 756447a | 2015-10-30 16:30:36 +0000 | [diff] [blame] | 81 | return ObjCRuntime(ObjCRuntime::WatchOS, TargetVersion); | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 82 | if (isTargetIOSBased()) | 
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 83 | return ObjCRuntime(ObjCRuntime::iOS, TargetVersion); | 
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 84 | if (isNonFragile) | 
|  | 85 | return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion); | 
|  | 86 | return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion); | 
| John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 87 | } | 
|  | 88 |  | 
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 89 | /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. | 
|  | 90 | bool Darwin::hasBlocksRuntime() const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 91 | if (isTargetWatchOSBased()) | 
|  | 92 | return true; | 
|  | 93 | else if (isTargetIOSBased()) | 
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 94 | return !isIPhoneOSVersionLT(3, 2); | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 95 | else { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 96 | assert(isTargetMacOS() && "unexpected darwin target"); | 
|  | 97 | return !isMacosxVersionLT(10, 6); | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 98 | } | 
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 101 | // This is just a MachO name translation routine and there's no | 
|  | 102 | // way to join this into ARMTargetParser without breaking all | 
|  | 103 | // other assumptions. Maybe MachO should consider standardising | 
|  | 104 | // their nomenclature. | 
|  | 105 | static const char *ArmMachOArchName(StringRef Arch) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 106 | return llvm::StringSwitch<const char *>(Arch) | 
|  | 107 | .Case("armv6k", "armv6") | 
|  | 108 | .Case("armv6m", "armv6m") | 
|  | 109 | .Case("armv5tej", "armv5") | 
|  | 110 | .Case("xscale", "xscale") | 
|  | 111 | .Case("armv4t", "armv4t") | 
|  | 112 | .Case("armv7", "armv7") | 
|  | 113 | .Cases("armv7a", "armv7-a", "armv7") | 
|  | 114 | .Cases("armv7r", "armv7-r", "armv7") | 
|  | 115 | .Cases("armv7em", "armv7e-m", "armv7em") | 
|  | 116 | .Cases("armv7k", "armv7-k", "armv7k") | 
|  | 117 | .Cases("armv7m", "armv7-m", "armv7m") | 
|  | 118 | .Cases("armv7s", "armv7-s", "armv7s") | 
|  | 119 | .Default(nullptr); | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 120 | } | 
|  | 121 |  | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 122 | static const char *ArmMachOArchNameCPU(StringRef CPU) { | 
| Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 123 | unsigned ArchKind = llvm::ARM::parseCPUArch(CPU); | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 124 | if (ArchKind == llvm::ARM::AK_INVALID) | 
|  | 125 | return nullptr; | 
| Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 126 | StringRef Arch = llvm::ARM::getArchName(ArchKind); | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 127 |  | 
|  | 128 | // FIXME: Make sure this MachO triple mangling is really necessary. | 
|  | 129 | // ARMv5* normalises to ARMv5. | 
|  | 130 | if (Arch.startswith("armv5")) | 
|  | 131 | Arch = Arch.substr(0, 5); | 
|  | 132 | // ARMv6*, except ARMv6M, normalises to ARMv6. | 
|  | 133 | else if (Arch.startswith("armv6") && !Arch.endswith("6m")) | 
|  | 134 | Arch = Arch.substr(0, 5); | 
|  | 135 | // ARMv7A normalises to ARMv7. | 
|  | 136 | else if (Arch.endswith("v7a")) | 
|  | 137 | Arch = Arch.substr(0, 5); | 
|  | 138 | return Arch.data(); | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 139 | } | 
|  | 140 |  | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 141 | static bool isSoftFloatABI(const ArgList &Args) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 142 | Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 143 | options::OPT_mfloat_abi_EQ); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 144 | if (!A) | 
|  | 145 | return false; | 
| Rafael Auler | 3f7abf7 | 2014-09-29 21:50:34 +0000 | [diff] [blame] | 146 |  | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 147 | return A->getOption().matches(options::OPT_msoft_float) || | 
|  | 148 | (A->getOption().matches(options::OPT_mfloat_abi_EQ) && | 
|  | 149 | A->getValue() == StringRef("soft")); | 
|  | 150 | } | 
|  | 151 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 152 | StringRef MachO::getMachOArchName(const ArgList &Args) const { | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 153 | switch (getTriple().getArch()) { | 
|  | 154 | default: | 
| Rafael Espindola | ed1233e | 2014-08-28 21:23:05 +0000 | [diff] [blame] | 155 | return getDefaultUniversalArchName(); | 
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 156 |  | 
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 157 | case llvm::Triple::aarch64: | 
|  | 158 | return "arm64"; | 
|  | 159 |  | 
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 160 | case llvm::Triple::thumb: | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 161 | case llvm::Triple::arm: | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 162 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 163 | if (const char *Arch = ArmMachOArchName(A->getValue())) | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 164 | return Arch; | 
|  | 165 |  | 
|  | 166 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 167 | if (const char *Arch = ArmMachOArchNameCPU(A->getValue())) | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 168 | return Arch; | 
|  | 169 |  | 
|  | 170 | return "arm"; | 
|  | 171 | } | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 174 | Darwin::~Darwin() {} | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 175 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 176 | MachO::~MachO() {} | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 177 |  | 
|  | 178 | std::string MachO::ComputeEffectiveClangTriple(const ArgList &Args, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 179 | types::ID InputType) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 180 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); | 
|  | 181 |  | 
|  | 182 | return Triple.getTriple(); | 
|  | 183 | } | 
|  | 184 |  | 
| Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 185 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, | 
|  | 186 | types::ID InputType) const { | 
|  | 187 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); | 
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 188 |  | 
|  | 189 | // If the target isn't initialized (e.g., an unknown Darwin platform, return | 
|  | 190 | // the default triple). | 
|  | 191 | if (!isTargetInitialized()) | 
|  | 192 | return Triple.getTriple(); | 
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 193 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 194 | SmallString<16> Str; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 195 | if (isTargetWatchOSBased()) | 
|  | 196 | Str += "watchos"; | 
|  | 197 | else if (isTargetTvOSBased()) | 
|  | 198 | Str += "tvos"; | 
|  | 199 | else if (isTargetIOSBased()) | 
|  | 200 | Str += "ios"; | 
|  | 201 | else | 
|  | 202 | Str += "macosx"; | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 203 | Str += getTargetVersion().getAsString(); | 
|  | 204 | Triple.setOSName(Str); | 
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 205 |  | 
|  | 206 | return Triple.getTriple(); | 
|  | 207 | } | 
|  | 208 |  | 
| David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 209 | void Generic_ELF::anchor() {} | 
|  | 210 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 211 | Tool *MachO::getTool(Action::ActionClass AC) const { | 
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 212 | switch (AC) { | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 213 | case Action::LipoJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 214 | if (!Lipo) | 
|  | 215 | Lipo.reset(new tools::darwin::Lipo(*this)); | 
|  | 216 | return Lipo.get(); | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 217 | case Action::DsymutilJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 218 | if (!Dsymutil) | 
|  | 219 | Dsymutil.reset(new tools::darwin::Dsymutil(*this)); | 
|  | 220 | return Dsymutil.get(); | 
| Ben Langmuir | 9b9a8d3 | 2014-02-06 18:53:25 +0000 | [diff] [blame] | 221 | case Action::VerifyDebugInfoJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 222 | if (!VerifyDebug) | 
|  | 223 | VerifyDebug.reset(new tools::darwin::VerifyDebug(*this)); | 
|  | 224 | return VerifyDebug.get(); | 
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 225 | default: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 226 | return ToolChain::getTool(AC); | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 227 | } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 228 | } | 
|  | 229 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 230 | Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); } | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 231 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 232 | Tool *MachO::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 233 | return new tools::darwin::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 234 | } | 
| Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 235 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 236 | DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 237 | const ArgList &Args) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 238 | : Darwin(D, Triple, Args) {} | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 239 |  | 
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 240 | void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 241 | // For modern targets, promote certain warnings to errors. | 
|  | 242 | if (isTargetWatchOSBased() || getTriple().isArch64Bit()) { | 
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 243 | // Always enable -Wdeprecated-objc-isa-usage and promote it | 
|  | 244 | // to an error. | 
|  | 245 | CC1Args.push_back("-Wdeprecated-objc-isa-usage"); | 
|  | 246 | CC1Args.push_back("-Werror=deprecated-objc-isa-usage"); | 
|  | 247 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 248 | // For iOS and watchOS, also error about implicit function declarations, | 
|  | 249 | // as that can impact calling conventions. | 
|  | 250 | if (!isTargetMacOS()) | 
|  | 251 | CC1Args.push_back("-Werror=implicit-function-declaration"); | 
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 252 | } | 
|  | 253 | } | 
|  | 254 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 255 | /// \brief Determine whether Objective-C automated reference counting is | 
|  | 256 | /// enabled. | 
|  | 257 | static bool isObjCAutoRefCount(const ArgList &Args) { | 
|  | 258 | return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); | 
|  | 259 | } | 
|  | 260 |  | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 261 | void DarwinClang::AddLinkARCArgs(const ArgList &Args, | 
|  | 262 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 263 | // Avoid linking compatibility stubs on i386 mac. | 
|  | 264 | if (isTargetMacOS() && getArch() == llvm::Triple::x86) | 
|  | 265 | return; | 
|  | 266 |  | 
|  | 267 | ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true); | 
|  | 268 |  | 
|  | 269 | if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) && | 
|  | 270 | runtime.hasSubscripting()) | 
|  | 271 | return; | 
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 272 |  | 
|  | 273 | CmdArgs.push_back("-force_load"); | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 274 | SmallString<128> P(getDriver().ClangExecutable); | 
|  | 275 | llvm::sys::path::remove_filename(P); // 'clang' | 
|  | 276 | llvm::sys::path::remove_filename(P); // 'bin' | 
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 277 | llvm::sys::path::append(P, "lib", "arc", "libarclite_"); | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 278 | // Mash in the platform. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 279 | if (isTargetWatchOSSimulator()) | 
|  | 280 | P += "watchsimulator"; | 
|  | 281 | else if (isTargetWatchOS()) | 
|  | 282 | P += "watchos"; | 
|  | 283 | else if (isTargetTvOSSimulator()) | 
|  | 284 | P += "appletvsimulator"; | 
|  | 285 | else if (isTargetTvOS()) | 
|  | 286 | P += "appletvos"; | 
|  | 287 | else if (isTargetIOSSimulator()) | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 288 | P += "iphonesimulator"; | 
| Argyrios Kyrtzidis | 058b451 | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 289 | else if (isTargetIPhoneOS()) | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 290 | P += "iphoneos"; | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 291 | else | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 292 | P += "macosx"; | 
|  | 293 | P += ".a"; | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 294 |  | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 295 | CmdArgs.push_back(Args.MakeArgString(P)); | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 296 | } | 
|  | 297 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 298 | void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, | 
| Kuba Brecka | 2735a025 | 2014-10-31 00:08:57 +0000 | [diff] [blame] | 299 | StringRef DarwinLibName, bool AlwaysLink, | 
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 300 | bool IsEmbedded, bool AddRPath) const { | 
|  | 301 | SmallString<128> Dir(getDriver().ResourceDir); | 
|  | 302 | llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin"); | 
|  | 303 |  | 
|  | 304 | SmallString<128> P(Dir); | 
|  | 305 | llvm::sys::path::append(P, DarwinLibName); | 
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 306 |  | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 307 | // For now, allow missing resource libraries to support developers who may | 
| Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 308 | // not have compiler-rt checked out or integrated into their build (unless | 
|  | 309 | // we explicitly force linking with this library). | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 310 | if (AlwaysLink || getVFS().exists(P)) | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 311 | CmdArgs.push_back(Args.MakeArgString(P)); | 
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 312 |  | 
|  | 313 | // Adding the rpaths might negatively interact when other rpaths are involved, | 
|  | 314 | // so we should make sure we add the rpaths last, after all user-specified | 
|  | 315 | // rpaths. This is currently true from this place, but we need to be | 
|  | 316 | // careful if this function is ever called before user's rpaths are emitted. | 
|  | 317 | if (AddRPath) { | 
|  | 318 | assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library"); | 
|  | 319 |  | 
|  | 320 | // Add @executable_path to rpath to support having the dylib copied with | 
|  | 321 | // the executable. | 
|  | 322 | CmdArgs.push_back("-rpath"); | 
|  | 323 | CmdArgs.push_back("@executable_path"); | 
|  | 324 |  | 
|  | 325 | // Add the path to the resource dir to rpath to support using the dylib | 
|  | 326 | // from the default location without copying. | 
|  | 327 | CmdArgs.push_back("-rpath"); | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 328 | CmdArgs.push_back(Args.MakeArgString(Dir)); | 
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 329 | } | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 330 | } | 
|  | 331 |  | 
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 332 | StringRef Darwin::getPlatformFamily() const { | 
|  | 333 | switch (TargetPlatform) { | 
|  | 334 | case DarwinPlatformKind::MacOS: | 
|  | 335 | return "MacOSX"; | 
|  | 336 | case DarwinPlatformKind::IPhoneOS: | 
|  | 337 | case DarwinPlatformKind::IPhoneOSSimulator: | 
|  | 338 | return "iPhone"; | 
|  | 339 | case DarwinPlatformKind::TvOS: | 
|  | 340 | case DarwinPlatformKind::TvOSSimulator: | 
|  | 341 | return "AppleTV"; | 
|  | 342 | case DarwinPlatformKind::WatchOS: | 
|  | 343 | case DarwinPlatformKind::WatchOSSimulator: | 
|  | 344 | return "Watch"; | 
|  | 345 | } | 
|  | 346 | llvm_unreachable("Unsupported platform"); | 
|  | 347 | } | 
|  | 348 |  | 
|  | 349 | StringRef Darwin::getSDKName(StringRef isysroot) { | 
|  | 350 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk | 
|  | 351 | llvm::sys::path::const_iterator SDKDir; | 
|  | 352 | auto BeginSDK = llvm::sys::path::begin(isysroot); | 
|  | 353 | auto EndSDK = llvm::sys::path::end(isysroot); | 
|  | 354 | for (auto IT = BeginSDK; IT != EndSDK; ++IT) { | 
|  | 355 | StringRef SDK = *IT; | 
|  | 356 | if (SDK.endswith(".sdk")) | 
|  | 357 | return SDK.slice(0, SDK.size() - 4); | 
|  | 358 | } | 
|  | 359 | return ""; | 
|  | 360 | } | 
|  | 361 |  | 
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 362 | StringRef Darwin::getOSLibraryNameSuffix() const { | 
|  | 363 | switch(TargetPlatform) { | 
|  | 364 | case DarwinPlatformKind::MacOS: | 
|  | 365 | return "osx"; | 
|  | 366 | case DarwinPlatformKind::IPhoneOS: | 
|  | 367 | return "ios"; | 
|  | 368 | case DarwinPlatformKind::IPhoneOSSimulator: | 
|  | 369 | return "iossim"; | 
|  | 370 | case DarwinPlatformKind::TvOS: | 
|  | 371 | return "tvos"; | 
|  | 372 | case DarwinPlatformKind::TvOSSimulator: | 
|  | 373 | return "tvossim"; | 
|  | 374 | case DarwinPlatformKind::WatchOS: | 
|  | 375 | return "watchos"; | 
|  | 376 | case DarwinPlatformKind::WatchOSSimulator: | 
|  | 377 | return "watchossim"; | 
|  | 378 | } | 
|  | 379 | llvm_unreachable("Unsupported platform"); | 
|  | 380 | } | 
|  | 381 |  | 
| Justin Bogner | 2fd95f6 | 2015-05-12 06:30:48 +0000 | [diff] [blame] | 382 | void Darwin::addProfileRTLibs(const ArgList &Args, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 383 | ArgStringList &CmdArgs) const { | 
| Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 384 | if (!needsProfileRT(Args)) return; | 
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 385 |  | 
| Chris Bieneman | 7f2844f | 2016-03-15 18:08:20 +0000 | [diff] [blame] | 386 | AddLinkRuntimeLib(Args, CmdArgs, (Twine("libclang_rt.profile_") + | 
|  | 387 | getOSLibraryNameSuffix() + ".a").str(), | 
| Chris Bieneman | 586d24b | 2015-11-20 00:19:21 +0000 | [diff] [blame] | 388 | /*AlwaysLink*/ true); | 
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 389 | } | 
|  | 390 |  | 
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 391 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, | 
|  | 392 | ArgStringList &CmdArgs, | 
|  | 393 | StringRef Sanitizer) const { | 
|  | 394 | if (!Args.hasArg(options::OPT_dynamiclib) && | 
|  | 395 | !Args.hasArg(options::OPT_bundle)) { | 
|  | 396 | // Sanitizer runtime libraries requires C++. | 
|  | 397 | AddCXXStdlibLibArgs(Args, CmdArgs); | 
|  | 398 | } | 
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 399 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 400 | AddLinkRuntimeLib( | 
|  | 401 | Args, CmdArgs, | 
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 402 | (Twine("libclang_rt.") + Sanitizer + "_" + | 
|  | 403 | getOSLibraryNameSuffix() + "_dynamic.dylib").str(), | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 404 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, | 
|  | 405 | /*AddRPath*/ true); | 
| Hans Wennborg | 10821e5 | 2015-04-09 18:47:01 +0000 | [diff] [blame] | 406 |  | 
|  | 407 | if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { | 
|  | 408 | // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export | 
|  | 409 | // all RTTI-related symbols that UBSan uses. | 
|  | 410 | CmdArgs.push_back("-lc++abi"); | 
|  | 411 | } | 
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 412 | } | 
|  | 413 |  | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 414 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, | 
|  | 415 | ArgStringList &CmdArgs) const { | 
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 416 | // Darwin only supports the compiler-rt based runtime libraries. | 
|  | 417 | switch (GetRuntimeLibType(Args)) { | 
|  | 418 | case ToolChain::RLT_CompilerRT: | 
|  | 419 | break; | 
|  | 420 | default: | 
|  | 421 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 422 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; | 
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 423 | return; | 
|  | 424 | } | 
|  | 425 |  | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 426 | // Darwin doesn't support real static executables, don't link any runtime | 
|  | 427 | // libraries with -static. | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 428 | if (Args.hasArg(options::OPT_static) || | 
|  | 429 | Args.hasArg(options::OPT_fapple_kext) || | 
|  | 430 | Args.hasArg(options::OPT_mkernel)) | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 431 | return; | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 432 |  | 
|  | 433 | // Reject -static-libgcc for now, we can deal with this when and if someone | 
|  | 434 | // cares. This is useful in situations where someone wants to statically link | 
|  | 435 | // something like libstdc++, and needs its runtime support routines. | 
|  | 436 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 437 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 438 | return; | 
|  | 439 | } | 
|  | 440 |  | 
| Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 441 | const SanitizerArgs &Sanitize = getSanitizerArgs(); | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 442 | if (Sanitize.needsAsanRt()) | 
|  | 443 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); | 
|  | 444 | if (Sanitize.needsUbsanRt()) | 
|  | 445 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); | 
| Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 446 | if (Sanitize.needsTsanRt()) | 
|  | 447 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); | 
| Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 448 | if (Sanitize.needsStatsRt()) { | 
|  | 449 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; | 
|  | 450 | AddLinkRuntimeLib(Args, CmdArgs, | 
|  | 451 | (Twine("libclang_rt.stats_client_") + OS + ".a").str(), | 
|  | 452 | /*AlwaysLink=*/true); | 
|  | 453 | AddLinkSanitizerLibArgs(Args, CmdArgs, "stats"); | 
|  | 454 | } | 
| Derek Bruening | 256c2e1 | 2016-04-21 21:32:04 +0000 | [diff] [blame] | 455 | if (Sanitize.needsEsanRt()) | 
|  | 456 | AddLinkSanitizerLibArgs(Args, CmdArgs, "esan"); | 
| Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 457 |  | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 458 | // Otherwise link libSystem, then the dynamic runtime library, and finally any | 
|  | 459 | // target specific static runtime library. | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 460 | CmdArgs.push_back("-lSystem"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 461 |  | 
|  | 462 | // Select the dynamic runtime library and the target specific static library. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 463 | if (isTargetWatchOSBased()) { | 
|  | 464 | // We currently always need a static runtime library for watchOS. | 
|  | 465 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); | 
|  | 466 | } else if (isTargetTvOSBased()) { | 
|  | 467 | // We currently always need a static runtime library for tvOS. | 
|  | 468 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); | 
|  | 469 | } else if (isTargetIOSBased()) { | 
| Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 470 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, | 
|  | 471 | // it never went into the SDK. | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 472 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 473 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && | 
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 474 | getTriple().getArch() != llvm::Triple::aarch64) | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 475 | CmdArgs.push_back("-lgcc_s.1"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 476 |  | 
| Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 477 | // We currently always need a static runtime library for iOS. | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 478 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 479 | } else { | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 480 | assert(isTargetMacOS() && "unexpected non MacOS platform"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 481 | // The dynamic runtime library was merged with libSystem for 10.6 and | 
|  | 482 | // beyond; only 10.4 and 10.5 need an additional runtime library. | 
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 483 | if (isMacosxVersionLT(10, 5)) | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 484 | CmdArgs.push_back("-lgcc_s.10.4"); | 
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 485 | else if (isMacosxVersionLT(10, 6)) | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 486 | CmdArgs.push_back("-lgcc_s.10.5"); | 
|  | 487 |  | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 488 | // For OS X, we thought we would only need a static runtime library when | 
| Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 489 | // targeting 10.4, to provide versions of the static functions which were | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 490 | // omitted from 10.4.dylib. | 
|  | 491 | // | 
|  | 492 | // Unfortunately, that turned out to not be true, because Darwin system | 
|  | 493 | // headers can still use eprintf on i386, and it is not exported from | 
|  | 494 | // libSystem. Therefore, we still must provide a runtime library just for | 
|  | 495 | // the tiny tiny handful of projects that *might* use that symbol. | 
|  | 496 | if (isMacosxVersionLT(10, 5)) { | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 497 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 498 | } else { | 
|  | 499 | if (getTriple().getArch() == llvm::Triple::x86) | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 500 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); | 
|  | 501 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 502 | } | 
| 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) || | 
|  | 697 | HadExtra || Major >= 10 || 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 || | 
|  | 703 | Major >= 10 || Minor >= 100 || Micro >= 100) | 
|  | 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, | 
|  | 812 | const char *BoundArch) const { | 
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 813 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); | 
|  | 814 | const OptTable &Opts = getDriver().getOpts(); | 
|  | 815 |  | 
|  | 816 | // FIXME: We really want to get out of the tool chain level argument | 
|  | 817 | // translation business, as it makes the driver functionality much | 
|  | 818 | // more opaque. For now, we follow gcc closely solely for the | 
|  | 819 | // purpose of easily achieving feature parity & testability. Once we | 
|  | 820 | // have something that works, we should reevaluate each translation | 
|  | 821 | // and try to push it down into tool specific logic. | 
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 822 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 823 | for (Arg *A : Args) { | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 824 | if (A->getOption().matches(options::OPT_Xarch__)) { | 
| Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 825 | // Skip this argument unless the architecture matches either the toolchain | 
|  | 826 | // triple arch, or the arch being bound. | 
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 827 | llvm::Triple::ArchType XarchArch = | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 828 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); | 
|  | 829 | if (!(XarchArch == getArch() || | 
|  | 830 | (BoundArch && | 
|  | 831 | XarchArch == | 
|  | 832 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 833 | continue; | 
|  | 834 |  | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 835 | Arg *OriginalArg = A; | 
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 836 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 837 | unsigned Prev = Index; | 
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 838 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 |  | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 840 | // If the argument parsing failed or more than one argument was | 
|  | 841 | // consumed, the -Xarch_ argument's parameter tried to consume | 
|  | 842 | // extra arguments. Emit an error and ignore. | 
|  | 843 | // | 
|  | 844 | // We also want to disallow any options which would alter the | 
|  | 845 | // driver behavior; that isn't going to work in our model. We | 
|  | 846 | // use isDriverOption() as an approximation, although things | 
|  | 847 | // like -O4 are going to slip through. | 
| Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 848 | if (!XarchArg || Index > Prev + 1) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 849 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 850 | << A->getAsString(Args); | 
| Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 851 | continue; | 
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 852 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 853 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 854 | << A->getAsString(Args); | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 855 | continue; | 
|  | 856 | } | 
|  | 857 |  | 
| Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 858 | XarchArg->setBaseArg(A); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 859 |  | 
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 860 | A = XarchArg.release(); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 861 | DAL->AddSynthesizedArg(A); | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 862 |  | 
|  | 863 | // Linker input arguments require custom handling. The problem is that we | 
|  | 864 | // have already constructed the phase actions, so we can not treat them as | 
|  | 865 | // "input arguments". | 
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 866 | if (A->getOption().hasFlag(options::LinkerInput)) { | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 867 | // Convert the argument into individual Zlinker_input_args. | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 868 | for (const char *Value : A->getValues()) { | 
|  | 869 | DAL->AddSeparateArg( | 
|  | 870 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 871 | } | 
|  | 872 | continue; | 
|  | 873 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 874 | } | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 875 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 876 | // Sob. These is strictly gcc compatible for the time being. Apple | 
|  | 877 | // gcc translates options twice, which means that self-expanding | 
|  | 878 | // options add duplicates. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 879 | switch ((options::ID)A->getOption().getID()) { | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 880 | default: | 
|  | 881 | DAL->append(A); | 
|  | 882 | break; | 
|  | 883 |  | 
|  | 884 | case options::OPT_mkernel: | 
|  | 885 | case options::OPT_fapple_kext: | 
|  | 886 | DAL->append(A); | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 887 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 888 | break; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 889 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 890 | case options::OPT_dependency_file: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 891 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 892 | break; | 
|  | 893 |  | 
|  | 894 | case options::OPT_gfull: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 895 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 896 | DAL->AddFlagArg( | 
|  | 897 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 898 | break; | 
|  | 899 |  | 
|  | 900 | case options::OPT_gused: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 901 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 902 | DAL->AddFlagArg( | 
|  | 903 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 904 | break; | 
|  | 905 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 906 | case options::OPT_shared: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 907 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 908 | break; | 
|  | 909 |  | 
|  | 910 | case options::OPT_fconstant_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 911 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 912 | break; | 
|  | 913 |  | 
|  | 914 | case options::OPT_fno_constant_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 915 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 916 | break; | 
|  | 917 |  | 
|  | 918 | case options::OPT_Wnonportable_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 919 | DAL->AddFlagArg(A, | 
|  | 920 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 921 | break; | 
|  | 922 |  | 
|  | 923 | case options::OPT_Wno_nonportable_cfstrings: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 924 | DAL->AddFlagArg( | 
|  | 925 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 926 | break; | 
|  | 927 |  | 
|  | 928 | case options::OPT_fpascal_strings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 929 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 930 | break; | 
|  | 931 |  | 
|  | 932 | case options::OPT_fno_pascal_strings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 933 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 934 | break; | 
|  | 935 | } | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 936 | } | 
|  | 937 |  | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 938 | if (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 939 | getTriple().getArch() == llvm::Triple::x86_64) | 
| Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 940 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 941 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), | 
|  | 942 | "core2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 943 |  | 
|  | 944 | // 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] | 945 | // how the driver driver works. | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 946 | if (BoundArch) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 947 | StringRef Name = BoundArch; | 
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 948 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); | 
|  | 949 | const Option MArch = Opts.getOption(options::OPT_march_EQ); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 950 |  | 
|  | 951 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, | 
|  | 952 | // which defines the list of which architectures we accept. | 
|  | 953 | if (Name == "ppc") | 
|  | 954 | ; | 
|  | 955 | else if (Name == "ppc601") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 956 | DAL->AddJoinedArg(nullptr, MCpu, "601"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 957 | else if (Name == "ppc603") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 958 | DAL->AddJoinedArg(nullptr, MCpu, "603"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 959 | else if (Name == "ppc604") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 960 | DAL->AddJoinedArg(nullptr, MCpu, "604"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 961 | else if (Name == "ppc604e") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 962 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 963 | else if (Name == "ppc750") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 964 | DAL->AddJoinedArg(nullptr, MCpu, "750"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 965 | else if (Name == "ppc7400") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 966 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 967 | else if (Name == "ppc7450") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 968 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 969 | else if (Name == "ppc970") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 970 | DAL->AddJoinedArg(nullptr, MCpu, "970"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 971 |  | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 972 | else if (Name == "ppc64" || Name == "ppc64le") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 973 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 974 |  | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 975 | else if (Name == "i386") | 
|  | 976 | ; | 
|  | 977 | else if (Name == "i486") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 978 | DAL->AddJoinedArg(nullptr, MArch, "i486"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 979 | else if (Name == "i586") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 980 | DAL->AddJoinedArg(nullptr, MArch, "i586"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 981 | else if (Name == "i686") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 982 | DAL->AddJoinedArg(nullptr, MArch, "i686"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 983 | else if (Name == "pentium") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 984 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 985 | else if (Name == "pentium2") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 986 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 987 | else if (Name == "pentpro") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 988 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 989 | else if (Name == "pentIIm3") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 990 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 991 |  | 
|  | 992 | else if (Name == "x86_64") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 993 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 994 | else if (Name == "x86_64h") { | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 995 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
|  | 996 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); | 
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 997 | } | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 998 |  | 
|  | 999 | else if (Name == "arm") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1000 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1001 | else if (Name == "armv4t") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1002 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1003 | else if (Name == "armv5") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1004 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1005 | else if (Name == "xscale") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1006 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1007 | else if (Name == "armv6") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1008 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1009 | else if (Name == "armv6m") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1010 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1011 | else if (Name == "armv7") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1012 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1013 | else if (Name == "armv7em") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1014 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); | 
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1015 | else if (Name == "armv7k") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1016 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1017 | else if (Name == "armv7m") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1018 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); | 
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1019 | else if (Name == "armv7s") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1020 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1021 | } | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 1022 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1023 | return DAL; | 
|  | 1024 | } | 
|  | 1025 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1026 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, | 
|  | 1027 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1028 | // Embedded targets are simple at the moment, not supporting sanitizers and | 
|  | 1029 | // with different libraries for each member of the product { static, PIC } x | 
|  | 1030 | // { hard-float, soft-float } | 
|  | 1031 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); | 
| Saleem Abdulrasool | 06f6f99 | 2015-09-19 20:40:16 +0000 | [diff] [blame] | 1032 | CompilerRT += | 
|  | 1033 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) | 
|  | 1034 | ? "hard" | 
|  | 1035 | : "soft"; | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1036 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; | 
|  | 1037 |  | 
|  | 1038 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); | 
|  | 1039 | } | 
|  | 1040 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1041 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, | 
|  | 1042 | const char *BoundArch) const { | 
|  | 1043 | // First get the generic Apple args, before moving onto Darwin-specific ones. | 
|  | 1044 | DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); | 
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1045 | const OptTable &Opts = getDriver().getOpts(); | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1046 |  | 
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1047 | // If no architecture is bound, none of the translations here are relevant. | 
|  | 1048 | if (!BoundArch) | 
|  | 1049 | return DAL; | 
|  | 1050 |  | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1051 | // Add an explicit version min argument for the deployment target. We do this | 
|  | 1052 | // after argument translation because -Xarch_ arguments may add a version min | 
|  | 1053 | // argument. | 
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1054 | AddDeploymentTarget(*DAL); | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1055 |  | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1056 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. | 
|  | 1057 | // FIXME: It would be far better to avoid inserting those -static arguments, | 
|  | 1058 | // but we can't check the deployment target in the translation code until | 
|  | 1059 | // it is set here. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1060 | if (isTargetWatchOSBased() || | 
|  | 1061 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { | 
|  | 1062 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1063 | Arg *A = *it; | 
|  | 1064 | ++it; | 
|  | 1065 | if (A->getOption().getID() != options::OPT_mkernel && | 
|  | 1066 | A->getOption().getID() != options::OPT_fapple_kext) | 
|  | 1067 | continue; | 
|  | 1068 | assert(it != ie && "unexpected argument translation"); | 
|  | 1069 | A = *it; | 
|  | 1070 | assert(A->getOption().getID() == options::OPT_static && | 
|  | 1071 | "missing expected -static argument"); | 
|  | 1072 | it = DAL->getArgs().erase(it); | 
|  | 1073 | } | 
|  | 1074 | } | 
|  | 1075 |  | 
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1076 | if (!Args.getLastArg(options::OPT_stdlib_EQ) && | 
| Tim Northover | 3a098c1 | 2016-02-15 16:38:10 +0000 | [diff] [blame] | 1077 | GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) | 
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1078 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), | 
|  | 1079 | "libc++"); | 
|  | 1080 |  | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1081 | // Validate the C++ standard library choice. | 
|  | 1082 | CXXStdlibType Type = GetCXXStdlibType(*DAL); | 
|  | 1083 | if (Type == ToolChain::CST_Libcxx) { | 
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1084 | // Check whether the target provides libc++. | 
|  | 1085 | StringRef where; | 
|  | 1086 |  | 
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1087 | // Complain about targeting iOS < 5.0 in any way. | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1088 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) | 
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1089 | where = "iOS 5.0"; | 
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1090 |  | 
|  | 1091 | if (where != StringRef()) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1092 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1093 | } | 
|  | 1094 | } | 
|  | 1095 |  | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1096 | return DAL; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1098 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1099 | bool MachO::IsUnwindTablesDefault() const { | 
| Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1100 | return getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1101 | } | 
|  | 1102 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1103 | bool MachO::UseDwarfDebugFlags() const { | 
| Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1104 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) | 
|  | 1105 | return S[0] != '\0'; | 
|  | 1106 | return false; | 
|  | 1107 | } | 
|  | 1108 |  | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1109 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { | 
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1110 | // Darwin uses SjLj exceptions on ARM. | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1111 | if (getTriple().getArch() != llvm::Triple::arm && | 
|  | 1112 | getTriple().getArch() != llvm::Triple::thumb) | 
|  | 1113 | return false; | 
|  | 1114 |  | 
| Tim Northover | c741b04 | 2015-11-17 18:27:27 +0000 | [diff] [blame] | 1115 | // Only watchOS uses the new DWARF/Compact unwinding method. | 
| Tim Northover | d88ecb3 | 2016-01-27 19:32:40 +0000 | [diff] [blame] | 1116 | llvm::Triple Triple(ComputeLLVMTriple(Args)); | 
| Tim Northover | 4c9ac7d | 2016-01-27 22:14:02 +0000 | [diff] [blame] | 1117 | return !Triple.isWatchABI(); | 
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1118 | } | 
|  | 1119 |  | 
| Steven Wu | 574b0f2 | 2016-03-01 01:07:58 +0000 | [diff] [blame] | 1120 | bool Darwin::SupportsEmbeddedBitcode() const { | 
|  | 1121 | assert(TargetInitialized && "Target not initialized!"); | 
|  | 1122 | if (isTargetIPhoneOS() && isIPhoneOSVersionLT(6, 0)) | 
|  | 1123 | return false; | 
|  | 1124 | return true; | 
|  | 1125 | } | 
|  | 1126 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1127 | bool MachO::isPICDefault() const { return true; } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1128 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1129 | bool MachO::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1130 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1131 | bool MachO::isPICDefaultForced() const { | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1132 | return (getArch() == llvm::Triple::x86_64 || | 
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1133 | getArch() == llvm::Triple::aarch64); | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1134 | } | 
|  | 1135 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1136 | bool MachO::SupportsProfiling() const { | 
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1137 | // Profiling instrumentation is only supported on x86. | 
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1138 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1139 | } | 
|  | 1140 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1141 | void Darwin::addMinVersionArgs(const ArgList &Args, | 
|  | 1142 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1143 | VersionTuple TargetVersion = getTargetVersion(); | 
|  | 1144 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1145 | if (isTargetWatchOS()) | 
|  | 1146 | CmdArgs.push_back("-watchos_version_min"); | 
|  | 1147 | else if (isTargetWatchOSSimulator()) | 
|  | 1148 | CmdArgs.push_back("-watchos_simulator_version_min"); | 
|  | 1149 | else if (isTargetTvOS()) | 
|  | 1150 | CmdArgs.push_back("-tvos_version_min"); | 
|  | 1151 | else if (isTargetTvOSSimulator()) | 
|  | 1152 | CmdArgs.push_back("-tvos_simulator_version_min"); | 
|  | 1153 | else if (isTargetIOSSimulator()) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1154 | CmdArgs.push_back("-ios_simulator_version_min"); | 
| Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1155 | else if (isTargetIOSBased()) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1156 | CmdArgs.push_back("-iphoneos_version_min"); | 
|  | 1157 | else { | 
|  | 1158 | assert(isTargetMacOS() && "unexpected target"); | 
|  | 1159 | CmdArgs.push_back("-macosx_version_min"); | 
|  | 1160 | } | 
|  | 1161 |  | 
|  | 1162 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); | 
|  | 1163 | } | 
|  | 1164 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1165 | void Darwin::addStartObjectFileArgs(const ArgList &Args, | 
|  | 1166 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1167 | // Derived from startfile spec. | 
|  | 1168 | if (Args.hasArg(options::OPT_dynamiclib)) { | 
|  | 1169 | // Derived from darwin_dylib1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1170 | if (isTargetWatchOSBased()) { | 
|  | 1171 | ; // watchOS does not need dylib1.o. | 
|  | 1172 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1173 | ; // iOS simulator does not need dylib1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1174 | } else if (isTargetIPhoneOS()) { | 
|  | 1175 | if (isIPhoneOSVersionLT(3, 1)) | 
|  | 1176 | CmdArgs.push_back("-ldylib1.o"); | 
|  | 1177 | } else { | 
|  | 1178 | if (isMacosxVersionLT(10, 5)) | 
|  | 1179 | CmdArgs.push_back("-ldylib1.o"); | 
|  | 1180 | else if (isMacosxVersionLT(10, 6)) | 
|  | 1181 | CmdArgs.push_back("-ldylib1.10.5.o"); | 
|  | 1182 | } | 
|  | 1183 | } else { | 
|  | 1184 | if (Args.hasArg(options::OPT_bundle)) { | 
|  | 1185 | if (!Args.hasArg(options::OPT_static)) { | 
|  | 1186 | // Derived from darwin_bundle1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1187 | if (isTargetWatchOSBased()) { | 
|  | 1188 | ; // watchOS does not need bundle1.o. | 
|  | 1189 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1190 | ; // iOS simulator does not need bundle1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1191 | } else if (isTargetIPhoneOS()) { | 
|  | 1192 | if (isIPhoneOSVersionLT(3, 1)) | 
|  | 1193 | CmdArgs.push_back("-lbundle1.o"); | 
|  | 1194 | } else { | 
|  | 1195 | if (isMacosxVersionLT(10, 6)) | 
|  | 1196 | CmdArgs.push_back("-lbundle1.o"); | 
|  | 1197 | } | 
|  | 1198 | } | 
|  | 1199 | } else { | 
|  | 1200 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { | 
|  | 1201 | if (Args.hasArg(options::OPT_static) || | 
|  | 1202 | Args.hasArg(options::OPT_object) || | 
|  | 1203 | Args.hasArg(options::OPT_preload)) { | 
|  | 1204 | CmdArgs.push_back("-lgcrt0.o"); | 
|  | 1205 | } else { | 
|  | 1206 | CmdArgs.push_back("-lgcrt1.o"); | 
|  | 1207 |  | 
|  | 1208 | // darwin_crt2 spec is empty. | 
|  | 1209 | } | 
|  | 1210 | // By default on OS X 10.8 and later, we don't link with a crt1.o | 
|  | 1211 | // file and the linker knows to use _main as the entry point.  But, | 
|  | 1212 | // when compiling with -pg, we need to link with the gcrt1.o file, | 
|  | 1213 | // so pass the -no_new_main option to tell the linker to use the | 
|  | 1214 | // "start" symbol as the entry point. | 
|  | 1215 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) | 
|  | 1216 | CmdArgs.push_back("-no_new_main"); | 
|  | 1217 | } else { | 
|  | 1218 | if (Args.hasArg(options::OPT_static) || | 
|  | 1219 | Args.hasArg(options::OPT_object) || | 
|  | 1220 | Args.hasArg(options::OPT_preload)) { | 
|  | 1221 | CmdArgs.push_back("-lcrt0.o"); | 
|  | 1222 | } else { | 
|  | 1223 | // Derived from darwin_crt1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1224 | if (isTargetWatchOSBased()) { | 
|  | 1225 | ; // watchOS does not need crt1.o. | 
|  | 1226 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1227 | ; // iOS simulator does not need crt1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1228 | } else if (isTargetIPhoneOS()) { | 
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1229 | if (getArch() == llvm::Triple::aarch64) | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1230 | ; // iOS does not need any crt1 files for arm64 | 
|  | 1231 | else if (isIPhoneOSVersionLT(3, 1)) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1232 | CmdArgs.push_back("-lcrt1.o"); | 
|  | 1233 | else if (isIPhoneOSVersionLT(6, 0)) | 
|  | 1234 | CmdArgs.push_back("-lcrt1.3.1.o"); | 
|  | 1235 | } else { | 
|  | 1236 | if (isMacosxVersionLT(10, 5)) | 
|  | 1237 | CmdArgs.push_back("-lcrt1.o"); | 
|  | 1238 | else if (isMacosxVersionLT(10, 6)) | 
|  | 1239 | CmdArgs.push_back("-lcrt1.10.5.o"); | 
|  | 1240 | else if (isMacosxVersionLT(10, 8)) | 
|  | 1241 | CmdArgs.push_back("-lcrt1.10.6.o"); | 
|  | 1242 |  | 
|  | 1243 | // darwin_crt2 spec is empty. | 
|  | 1244 | } | 
|  | 1245 | } | 
|  | 1246 | } | 
|  | 1247 | } | 
|  | 1248 | } | 
|  | 1249 |  | 
|  | 1250 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1251 | !isTargetWatchOS() && | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1252 | isMacosxVersionLT(10, 5)) { | 
|  | 1253 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); | 
|  | 1254 | CmdArgs.push_back(Str); | 
|  | 1255 | } | 
|  | 1256 | } | 
|  | 1257 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1258 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } | 
| Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1259 |  | 
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1260 | void Darwin::CheckObjCARC() const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1261 | if (isTargetIOSBased() || isTargetWatchOSBased() || | 
|  | 1262 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) | 
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1263 | return; | 
| John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1264 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); | 
| Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1265 | } | 
|  | 1266 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1267 | SanitizerMask Darwin::getSupportedSanitizers() const { | 
| Devin Coughlin | fcfa38c | 2016-03-20 18:24:33 +0000 | [diff] [blame] | 1268 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1269 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 1270 | Res |= SanitizerKind::Address; | 
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1271 | if (isTargetMacOS()) { | 
|  | 1272 | if (!isMacosxVersionLT(10, 9)) | 
|  | 1273 | Res |= SanitizerKind::Vptr; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1274 | Res |= SanitizerKind::SafeStack; | 
| Devin Coughlin | fcfa38c | 2016-03-20 18:24:33 +0000 | [diff] [blame] | 1275 | if (IsX86_64) | 
|  | 1276 | Res |= SanitizerKind::Thread; | 
|  | 1277 | } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) { | 
|  | 1278 | if (IsX86_64) | 
|  | 1279 | Res |= SanitizerKind::Thread; | 
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1280 | } | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1281 | return Res; | 
|  | 1282 | } | 
|  | 1283 |  | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1284 | /// Generic_GCC - A tool chain using the 'gcc' command to perform | 
|  | 1285 | /// all subcommands; this relies on gcc translating the majority of | 
|  | 1286 | /// command line options. | 
|  | 1287 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1288 | /// \brief Parse a GCCVersion object out of a string of text. | 
|  | 1289 | /// | 
|  | 1290 | /// This is the primary means of forming GCCVersion objects. | 
|  | 1291 | /*static*/ | 
|  | 1292 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1293 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1294 | std::pair<StringRef, StringRef> First = VersionText.split('.'); | 
|  | 1295 | std::pair<StringRef, StringRef> Second = First.second.split('.'); | 
|  | 1296 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1297 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; | 
|  | 1298 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1299 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1300 | GoodVersion.MajorStr = First.first.str(); | 
| Bryan Chan | d346ae6 | 2016-06-17 16:47:14 +0000 | [diff] [blame^] | 1301 | if (First.second.empty()) | 
|  | 1302 | return GoodVersion; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1303 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1304 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1305 | GoodVersion.MinorStr = Second.first.str(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1306 |  | 
|  | 1307 | // First look for a number prefix and parse that if present. Otherwise just | 
|  | 1308 | // stash the entire patch string in the suffix, and leave the number | 
|  | 1309 | // unspecified. This covers versions strings such as: | 
| Bryan Chan | d346ae6 | 2016-06-17 16:47:14 +0000 | [diff] [blame^] | 1310 | //   5        (handled above) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1311 | //   4.4 | 
|  | 1312 | //   4.4.0 | 
|  | 1313 | //   4.4.x | 
|  | 1314 | //   4.4.2-rc4 | 
|  | 1315 | //   4.4.x-patched | 
|  | 1316 | // And retains any patch number it finds. | 
|  | 1317 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); | 
|  | 1318 | if (!PatchText.empty()) { | 
| Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1319 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1320 | // Try to parse the number and any suffix. | 
|  | 1321 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || | 
|  | 1322 | GoodVersion.Patch < 0) | 
|  | 1323 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1324 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1325 | } | 
|  | 1326 | } | 
|  | 1327 |  | 
|  | 1328 | return GoodVersion; | 
|  | 1329 | } | 
|  | 1330 |  | 
|  | 1331 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1332 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, | 
|  | 1333 | int RHSPatch, | 
|  | 1334 | StringRef RHSPatchSuffix) const { | 
|  | 1335 | if (Major != RHSMajor) | 
|  | 1336 | return Major < RHSMajor; | 
|  | 1337 | if (Minor != RHSMinor) | 
|  | 1338 | return Minor < RHSMinor; | 
|  | 1339 | if (Patch != RHSPatch) { | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1340 | // Note that versions without a specified patch sort higher than those with | 
|  | 1341 | // a patch. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1342 | if (RHSPatch == -1) | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1343 | return true; | 
|  | 1344 | if (Patch == -1) | 
|  | 1345 | return false; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1346 |  | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1347 | // Otherwise just sort on the patch itself. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1348 | return Patch < RHSPatch; | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1349 | } | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1350 | if (PatchSuffix != RHSPatchSuffix) { | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1351 | // Sort empty suffixes higher. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1352 | if (RHSPatchSuffix.empty()) | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1353 | return true; | 
|  | 1354 | if (PatchSuffix.empty()) | 
| Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1355 | return false; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1356 |  | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1357 | // Provide a lexicographic sort to make this a total ordering. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1358 | return PatchSuffix < RHSPatchSuffix; | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1359 | } | 
|  | 1360 |  | 
|  | 1361 | // The versions are equal. | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1362 | return false; | 
|  | 1363 | } | 
|  | 1364 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1365 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1366 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); | 
|  | 1367 | if (A) | 
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1368 | return A->getValue(); | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1369 | return GCC_INSTALL_PREFIX; | 
|  | 1370 | } | 
|  | 1371 |  | 
| Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1372 | /// \brief Initialize a GCCInstallationDetector from the driver. | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1373 | /// | 
|  | 1374 | /// This performs all of the autodetection and sets up the various paths. | 
| Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1375 | /// Once constructed, a GCCInstallationDetector is essentially immutable. | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1376 | /// | 
|  | 1377 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and | 
|  | 1378 | /// should instead pull the target out of the driver. This is currently | 
|  | 1379 | /// necessary because the driver doesn't store the final version of the target | 
|  | 1380 | /// triple. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1381 | void Generic_GCC::GCCInstallationDetector::init( | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1382 | const llvm::Triple &TargetTriple, const ArgList &Args, | 
| Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1383 | ArrayRef<std::string> ExtraTripleAliases) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1384 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() | 
|  | 1385 | ? TargetTriple.get64BitArchVariant() | 
|  | 1386 | : TargetTriple.get32BitArchVariant(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1387 | // The library directories which may contain GCC installations. | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1388 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1389 | // The compatible GCC triples for this particular architecture. | 
| Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1390 | SmallVector<StringRef, 16> CandidateTripleAliases; | 
|  | 1391 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1392 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, | 
|  | 1393 | CandidateTripleAliases, CandidateBiarchLibDirs, | 
|  | 1394 | CandidateBiarchTripleAliases); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1395 |  | 
|  | 1396 | // Compute the set of prefixes for our search. | 
|  | 1397 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), | 
|  | 1398 | D.PrefixDirs.end()); | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1399 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1400 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); | 
|  | 1401 | if (GCCToolchainDir != "") { | 
|  | 1402 | if (GCCToolchainDir.back() == '/') | 
|  | 1403 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1404 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1405 | Prefixes.push_back(GCCToolchainDir); | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1406 | } else { | 
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1407 | // If we have a SysRoot, try that first. | 
|  | 1408 | if (!D.SysRoot.empty()) { | 
|  | 1409 | Prefixes.push_back(D.SysRoot); | 
|  | 1410 | Prefixes.push_back(D.SysRoot + "/usr"); | 
|  | 1411 | } | 
|  | 1412 |  | 
|  | 1413 | // Then look for gcc installed alongside clang. | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1414 | Prefixes.push_back(D.InstalledDir + "/.."); | 
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1415 |  | 
| Rafael Espindola | 2edca41 | 2016-05-09 13:03:10 +0000 | [diff] [blame] | 1416 | // Then look for distribution supplied gcc installations. | 
|  | 1417 | if (D.SysRoot.empty()) { | 
|  | 1418 | // Look for RHEL devtoolsets. | 
|  | 1419 | Prefixes.push_back("/opt/rh/devtoolset-4/root/usr"); | 
|  | 1420 | Prefixes.push_back("/opt/rh/devtoolset-3/root/usr"); | 
|  | 1421 | Prefixes.push_back("/opt/rh/devtoolset-2/root/usr"); | 
|  | 1422 | Prefixes.push_back("/opt/rh/devtoolset-1.1/root/usr"); | 
|  | 1423 | Prefixes.push_back("/opt/rh/devtoolset-1.0/root/usr"); | 
|  | 1424 | // And finally in /usr. | 
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1425 | Prefixes.push_back("/usr"); | 
| Rafael Espindola | 2edca41 | 2016-05-09 13:03:10 +0000 | [diff] [blame] | 1426 | } | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1427 | } | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1428 |  | 
|  | 1429 | // Loop over the various components which exist and select the best GCC | 
|  | 1430 | // installation available. GCC installs are ranked by version number. | 
|  | 1431 | Version = GCCVersion::Parse("0.0.0"); | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1432 | for (const std::string &Prefix : Prefixes) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1433 | if (!D.getVFS().exists(Prefix)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1434 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1435 | for (StringRef Suffix : CandidateLibDirs) { | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1436 | const std::string LibDir = Prefix + Suffix.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1437 | if (!D.getVFS().exists(LibDir)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1438 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1439 | for (StringRef Candidate : ExtraTripleAliases) // Try these first. | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1440 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1441 | for (StringRef Candidate : CandidateTripleAliases) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1442 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1443 | } | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1444 | for (StringRef Suffix : CandidateBiarchLibDirs) { | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1445 | const std::string LibDir = Prefix + Suffix.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1446 | if (!D.getVFS().exists(LibDir)) | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1447 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1448 | for (StringRef Candidate : CandidateBiarchTripleAliases) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1449 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1450 | /*NeedsBiarchSuffix=*/ true); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1451 | } | 
|  | 1452 | } | 
|  | 1453 | } | 
|  | 1454 |  | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1455 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1456 | for (const auto &InstallPath : CandidateGCCInstallPaths) | 
|  | 1457 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1458 |  | 
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1459 | if (!GCCInstallPath.empty()) | 
|  | 1460 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; | 
|  | 1461 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1462 | for (const auto &Multilib : Multilibs) | 
|  | 1463 | OS << "Candidate multilib: " << Multilib << "\n"; | 
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1464 |  | 
|  | 1465 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) | 
|  | 1466 | OS << "Selected multilib: " << SelectedMultilib << "\n"; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1467 | } | 
|  | 1468 |  | 
|  | 1469 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { | 
|  | 1470 | if (BiarchSibling.hasValue()) { | 
|  | 1471 | M = BiarchSibling.getValue(); | 
|  | 1472 | return true; | 
|  | 1473 | } | 
|  | 1474 | return false; | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1475 | } | 
|  | 1476 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1477 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1478 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1479 | SmallVectorImpl<StringRef> &LibDirs, | 
|  | 1480 | SmallVectorImpl<StringRef> &TripleAliases, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1481 | SmallVectorImpl<StringRef> &BiarchLibDirs, | 
|  | 1482 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1483 | // Declare a bunch of static data sets that we'll select between below. These | 
|  | 1484 | // are specifically designed to always refer to string literals to avoid any | 
|  | 1485 | // lifetime or initialization issues. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1486 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1487 | static const char *const AArch64Triples[] = { | 
|  | 1488 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", | 
|  | 1489 | "aarch64-redhat-linux"}; | 
|  | 1490 | static const char *const AArch64beLibDirs[] = {"/lib"}; | 
|  | 1491 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", | 
|  | 1492 | "aarch64_be-linux-gnu"}; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1493 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1494 | static const char *const ARMLibDirs[] = {"/lib"}; | 
|  | 1495 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", | 
|  | 1496 | "arm-linux-androideabi"}; | 
|  | 1497 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", | 
|  | 1498 | "armv7hl-redhat-linux-gnueabi"}; | 
|  | 1499 | static const char *const ARMebLibDirs[] = {"/lib"}; | 
|  | 1500 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", | 
|  | 1501 | "armeb-linux-androideabi"}; | 
|  | 1502 | static const char *const ARMebHFTriples[] = { | 
|  | 1503 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1504 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1505 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1506 | static const char *const X86_64Triples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1507 | "x86_64-linux-gnu",       "x86_64-unknown-linux-gnu", | 
|  | 1508 | "x86_64-pc-linux-gnu",    "x86_64-redhat-linux6E", | 
|  | 1509 | "x86_64-redhat-linux",    "x86_64-suse-linux", | 
|  | 1510 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", | 
|  | 1511 | "x86_64-slackware-linux", "x86_64-linux-android", | 
|  | 1512 | "x86_64-unknown-linux"}; | 
|  | 1513 | static const char *const X32LibDirs[] = {"/libx32"}; | 
|  | 1514 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1515 | static const char *const X86Triples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1516 | "i686-linux-gnu",       "i686-pc-linux-gnu",     "i486-linux-gnu", | 
|  | 1517 | "i386-linux-gnu",       "i386-redhat-linux6E",   "i686-redhat-linux", | 
|  | 1518 | "i586-redhat-linux",    "i386-redhat-linux",     "i586-suse-linux", | 
|  | 1519 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", | 
|  | 1520 | "i586-linux-gnu"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1521 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1522 | static const char *const MIPSLibDirs[] = {"/lib"}; | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1523 | static const char *const MIPSTriples[] = {"mips-linux-gnu", "mips-mti-linux", | 
|  | 1524 | "mips-mti-linux-gnu", | 
|  | 1525 | "mips-img-linux-gnu"}; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1526 | static const char *const MIPSELLibDirs[] = {"/lib"}; | 
|  | 1527 | static const char *const MIPSELTriples[] = { | 
|  | 1528 | "mipsel-linux-gnu", "mipsel-linux-android", "mips-img-linux-gnu"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1529 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1530 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1531 | static const char *const MIPS64Triples[] = { | 
|  | 1532 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", | 
|  | 1533 | "mips64-linux-gnuabi64"}; | 
|  | 1534 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; | 
|  | 1535 | static const char *const MIPS64ELTriples[] = { | 
|  | 1536 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", | 
|  | 1537 | "mips64el-linux-android", "mips64el-linux-gnuabi64"}; | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1538 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1539 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1540 | static const char *const PPCTriples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1541 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", | 
|  | 1542 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; | 
|  | 1543 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1544 | static const char *const PPC64Triples[] = { | 
|  | 1545 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", | 
|  | 1546 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; | 
|  | 1547 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; | 
|  | 1548 | static const char *const PPC64LETriples[] = { | 
|  | 1549 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", | 
|  | 1550 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1551 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1552 | static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; | 
|  | 1553 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", | 
|  | 1554 | "sparcv8-linux-gnu"}; | 
|  | 1555 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1556 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", | 
|  | 1557 | "sparcv9-linux-gnu"}; | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1558 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1559 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1560 | static const char *const SystemZTriples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1561 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", | 
|  | 1562 | "s390x-suse-linux", "s390x-redhat-linux"}; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1563 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1564 | // Solaris. | 
|  | 1565 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; | 
|  | 1566 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", | 
|  | 1567 | "i386-pc-solaris2.11"}; | 
|  | 1568 |  | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1569 | using std::begin; | 
|  | 1570 | using std::end; | 
|  | 1571 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1572 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { | 
|  | 1573 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); | 
|  | 1574 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1575 | return; | 
|  | 1576 | } | 
|  | 1577 |  | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1578 | switch (TargetTriple.getArch()) { | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1579 | case llvm::Triple::aarch64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1580 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); | 
|  | 1581 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); | 
|  | 1582 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); | 
|  | 1583 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1584 | break; | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1585 | case llvm::Triple::aarch64_be: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1586 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); | 
|  | 1587 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); | 
|  | 1588 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); | 
|  | 1589 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1590 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1591 | case llvm::Triple::arm: | 
|  | 1592 | case llvm::Triple::thumb: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1593 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1594 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1595 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1596 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1597 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1598 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1599 | break; | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1600 | case llvm::Triple::armeb: | 
|  | 1601 | case llvm::Triple::thumbeb: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1602 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1603 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1604 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1605 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1606 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1607 | } | 
|  | 1608 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1609 | case llvm::Triple::x86_64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1610 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); | 
|  | 1611 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
|  | 1612 | // x32 is always available when x86_64 is available, so adding it as | 
|  | 1613 | // secondary arch with x86_64 triples | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1614 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1615 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); | 
|  | 1616 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1617 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1618 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); | 
|  | 1619 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1620 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1621 | break; | 
|  | 1622 | case llvm::Triple::x86: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1623 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); | 
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1624 | // MCU toolchain is 32 bit only and its triple alias is TargetTriple | 
|  | 1625 | // itself, which will be appended below. | 
|  | 1626 | if (!TargetTriple.isOSIAMCU()) { | 
|  | 1627 | TripleAliases.append(begin(X86Triples), end(X86Triples)); | 
|  | 1628 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); | 
|  | 1629 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
|  | 1630 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1631 | break; | 
|  | 1632 | case llvm::Triple::mips: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1633 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); | 
|  | 1634 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
|  | 1635 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); | 
|  | 1636 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1637 | break; | 
|  | 1638 | case llvm::Triple::mipsel: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1639 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); | 
|  | 1640 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); | 
|  | 1641 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
|  | 1642 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); | 
|  | 1643 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1644 | break; | 
|  | 1645 | case llvm::Triple::mips64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1646 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); | 
|  | 1647 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); | 
|  | 1648 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); | 
|  | 1649 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1650 | break; | 
|  | 1651 | case llvm::Triple::mips64el: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1652 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); | 
|  | 1653 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); | 
|  | 1654 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); | 
|  | 1655 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); | 
|  | 1656 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1657 | break; | 
|  | 1658 | case llvm::Triple::ppc: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1659 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); | 
|  | 1660 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); | 
|  | 1661 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); | 
|  | 1662 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1663 | break; | 
|  | 1664 | case llvm::Triple::ppc64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1665 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); | 
|  | 1666 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); | 
|  | 1667 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); | 
|  | 1668 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1669 | break; | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1670 | case llvm::Triple::ppc64le: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1671 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); | 
|  | 1672 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1673 | break; | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1674 | case llvm::Triple::sparc: | 
| Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1675 | case llvm::Triple::sparcel: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1676 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); | 
|  | 1677 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); | 
|  | 1678 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); | 
|  | 1679 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1680 | break; | 
|  | 1681 | case llvm::Triple::sparcv9: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1682 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); | 
|  | 1683 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); | 
|  | 1684 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); | 
|  | 1685 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1686 | break; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1687 | case llvm::Triple::systemz: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1688 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); | 
|  | 1689 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1690 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1691 | default: | 
|  | 1692 | // By default, just rely on the standard lib directories and the original | 
|  | 1693 | // triple. | 
|  | 1694 | break; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1695 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1696 |  | 
|  | 1697 | // Always append the drivers target triple to the end, in case it doesn't | 
|  | 1698 | // match any of our aliases. | 
|  | 1699 | TripleAliases.push_back(TargetTriple.str()); | 
|  | 1700 |  | 
|  | 1701 | // Also include the multiarch variant if it's different. | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1702 | if (TargetTriple.str() != BiarchTriple.str()) | 
|  | 1703 | BiarchTripleAliases.push_back(BiarchTriple.str()); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1704 | } | 
|  | 1705 |  | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1706 | // \brief -- try common CUDA installation paths looking for files we need for | 
|  | 1707 | // CUDA compilation. | 
|  | 1708 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1709 | void Generic_GCC::CudaInstallationDetector::init( | 
|  | 1710 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { | 
| NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1711 | SmallVector<std::string, 4> CudaPathCandidates; | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1712 |  | 
|  | 1713 | if (Args.hasArg(options::OPT_cuda_path_EQ)) | 
|  | 1714 | CudaPathCandidates.push_back( | 
|  | 1715 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); | 
|  | 1716 | else { | 
|  | 1717 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 1718 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.5"); | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1719 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); | 
|  | 1720 | } | 
|  | 1721 |  | 
| Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1722 | for (const auto &CudaPath : CudaPathCandidates) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1723 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1724 | continue; | 
|  | 1725 |  | 
|  | 1726 | CudaInstallPath = CudaPath; | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 1727 | CudaBinPath = CudaPath + "/bin"; | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1728 | CudaIncludePath = CudaInstallPath + "/include"; | 
|  | 1729 | CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice"; | 
|  | 1730 | CudaLibPath = | 
|  | 1731 | CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); | 
|  | 1732 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1733 | if (!(D.getVFS().exists(CudaIncludePath) && | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 1734 | D.getVFS().exists(CudaBinPath) && D.getVFS().exists(CudaLibPath) && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1735 | D.getVFS().exists(CudaLibDevicePath))) | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1736 | continue; | 
|  | 1737 |  | 
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1738 | std::error_code EC; | 
|  | 1739 | for (llvm::sys::fs::directory_iterator LI(CudaLibDevicePath, EC), LE; | 
|  | 1740 | !EC && LI != LE; LI = LI.increment(EC)) { | 
|  | 1741 | StringRef FilePath = LI->path(); | 
|  | 1742 | StringRef FileName = llvm::sys::path::filename(FilePath); | 
|  | 1743 | // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc | 
|  | 1744 | const StringRef LibDeviceName = "libdevice."; | 
|  | 1745 | if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc"))) | 
|  | 1746 | continue; | 
|  | 1747 | StringRef GpuArch = FileName.slice( | 
|  | 1748 | LibDeviceName.size(), FileName.find('.', LibDeviceName.size())); | 
|  | 1749 | CudaLibDeviceMap[GpuArch] = FilePath.str(); | 
|  | 1750 | // Insert map entries for specifc devices with this compute capability. | 
|  | 1751 | if (GpuArch == "compute_20") { | 
|  | 1752 | CudaLibDeviceMap["sm_20"] = FilePath; | 
|  | 1753 | CudaLibDeviceMap["sm_21"] = FilePath; | 
|  | 1754 | } else if (GpuArch == "compute_30") { | 
|  | 1755 | CudaLibDeviceMap["sm_30"] = FilePath; | 
|  | 1756 | CudaLibDeviceMap["sm_32"] = FilePath; | 
|  | 1757 | } else if (GpuArch == "compute_35") { | 
|  | 1758 | CudaLibDeviceMap["sm_35"] = FilePath; | 
|  | 1759 | CudaLibDeviceMap["sm_37"] = FilePath; | 
| Artem Belevich | ffa5fc5 | 2016-05-19 17:47:47 +0000 | [diff] [blame] | 1760 | } else if (GpuArch == "compute_50") { | 
|  | 1761 | CudaLibDeviceMap["sm_50"] = FilePath; | 
|  | 1762 | CudaLibDeviceMap["sm_52"] = FilePath; | 
|  | 1763 | CudaLibDeviceMap["sm_53"] = FilePath; | 
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1764 | } | 
|  | 1765 | } | 
|  | 1766 |  | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1767 | IsValid = true; | 
|  | 1768 | break; | 
|  | 1769 | } | 
|  | 1770 | } | 
|  | 1771 |  | 
|  | 1772 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { | 
|  | 1773 | if (isValid()) | 
|  | 1774 | OS << "Found CUDA installation: " << CudaInstallPath << "\n"; | 
|  | 1775 | } | 
|  | 1776 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1777 | namespace { | 
|  | 1778 | // 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] | 1779 | class FilterNonExistent { | 
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1780 | StringRef Base, File; | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1781 | vfs::FileSystem &VFS; | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1782 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1783 | public: | 
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1784 | FilterNonExistent(StringRef Base, StringRef File, vfs::FileSystem &VFS) | 
|  | 1785 | : Base(Base), File(File), VFS(VFS) {} | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1786 | bool operator()(const Multilib &M) { | 
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1787 | return !VFS.exists(Base + M.gccSuffix() + File); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1788 | } | 
|  | 1789 | }; | 
|  | 1790 | } // end anonymous namespace | 
|  | 1791 |  | 
|  | 1792 | static void addMultilibFlag(bool Enabled, const char *const Flag, | 
|  | 1793 | std::vector<std::string> &Flags) { | 
|  | 1794 | if (Enabled) | 
|  | 1795 | Flags.push_back(std::string("+") + Flag); | 
|  | 1796 | else | 
|  | 1797 | Flags.push_back(std::string("-") + Flag); | 
|  | 1798 | } | 
|  | 1799 |  | 
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 1800 | static bool isArmOrThumbArch(llvm::Triple::ArchType Arch) { | 
|  | 1801 | return Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb; | 
|  | 1802 | } | 
|  | 1803 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1804 | static bool isMipsArch(llvm::Triple::ArchType Arch) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1805 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || | 
|  | 1806 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; | 
|  | 1807 | } | 
|  | 1808 |  | 
|  | 1809 | static bool isMips32(llvm::Triple::ArchType Arch) { | 
|  | 1810 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; | 
|  | 1811 | } | 
|  | 1812 |  | 
|  | 1813 | static bool isMips64(llvm::Triple::ArchType Arch) { | 
|  | 1814 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; | 
|  | 1815 | } | 
|  | 1816 |  | 
|  | 1817 | static bool isMipsEL(llvm::Triple::ArchType Arch) { | 
|  | 1818 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; | 
|  | 1819 | } | 
|  | 1820 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1821 | static bool isMips16(const ArgList &Args) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1822 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1823 | return A && A->getOption().matches(options::OPT_mips16); | 
|  | 1824 | } | 
|  | 1825 |  | 
|  | 1826 | static bool isMicroMips(const ArgList &Args) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1827 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1828 | return A && A->getOption().matches(options::OPT_mmicromips); | 
|  | 1829 | } | 
|  | 1830 |  | 
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1831 | namespace { | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1832 | struct DetectedMultilibs { | 
|  | 1833 | /// The set of multilibs that the detected installation supports. | 
|  | 1834 | MultilibSet Multilibs; | 
|  | 1835 |  | 
|  | 1836 | /// The primary multilib appropriate for the given flags. | 
|  | 1837 | Multilib SelectedMultilib; | 
|  | 1838 |  | 
|  | 1839 | /// On Biarch systems, this corresponds to the default multilib when | 
|  | 1840 | /// targeting the non-default multilib. Otherwise, it is empty. | 
|  | 1841 | llvm::Optional<Multilib> BiarchSibling; | 
|  | 1842 | }; | 
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1843 | } // end anonymous namespace | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1844 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1845 | static Multilib makeMultilib(StringRef commonSuffix) { | 
|  | 1846 | return Multilib(commonSuffix, commonSuffix, commonSuffix); | 
|  | 1847 | } | 
|  | 1848 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1849 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, | 
|  | 1850 | StringRef Path, const ArgList &Args, | 
|  | 1851 | DetectedMultilibs &Result) { | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 1852 | // Some MIPS toolchains put libraries and object files compiled | 
|  | 1853 | // using different options in to the sub-directoris which names | 
|  | 1854 | // reflects the flags used for compilation. For example sysroot | 
|  | 1855 | // directory might looks like the following examples: | 
|  | 1856 | // | 
|  | 1857 | // /usr | 
|  | 1858 | //   /lib      <= crt*.o files compiled with '-mips32' | 
|  | 1859 | // /mips16 | 
|  | 1860 | //   /usr | 
|  | 1861 | //     /lib    <= crt*.o files compiled with '-mips16' | 
|  | 1862 | //   /el | 
|  | 1863 | //     /usr | 
|  | 1864 | //       /lib  <= crt*.o files compiled with '-mips16 -EL' | 
|  | 1865 | // | 
|  | 1866 | // or | 
|  | 1867 | // | 
|  | 1868 | // /usr | 
|  | 1869 | //   /lib      <= crt*.o files compiled with '-mips32r2' | 
|  | 1870 | // /mips16 | 
|  | 1871 | //   /usr | 
|  | 1872 | //     /lib    <= crt*.o files compiled with '-mips32r2 -mips16' | 
|  | 1873 | // /mips32 | 
|  | 1874 | //     /usr | 
|  | 1875 | //       /lib  <= crt*.o files compiled with '-mips32' | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 1876 |  | 
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 1877 | FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS()); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 1878 |  | 
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 1879 | // Check for CodeScape MTI toolchain v1.2 and early. | 
|  | 1880 | MultilibSet MtiMipsMultilibsV1; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1881 | { | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1882 | auto MArchMips32 = makeMultilib("/mips32") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1883 | .flag("+m32") | 
|  | 1884 | .flag("-m64") | 
|  | 1885 | .flag("-mmicromips") | 
|  | 1886 | .flag("+march=mips32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1887 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1888 | auto MArchMicroMips = makeMultilib("/micromips") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1889 | .flag("+m32") | 
|  | 1890 | .flag("-m64") | 
|  | 1891 | .flag("+mmicromips"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1892 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1893 | auto MArchMips64r2 = makeMultilib("/mips64r2") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1894 | .flag("-m32") | 
|  | 1895 | .flag("+m64") | 
|  | 1896 | .flag("+march=mips64r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1897 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1898 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( | 
|  | 1899 | "-march=mips64r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1900 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1901 | auto MArchDefault = makeMultilib("") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1902 | .flag("+m32") | 
|  | 1903 | .flag("-m64") | 
|  | 1904 | .flag("-mmicromips") | 
|  | 1905 | .flag("+march=mips32r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1906 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1907 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1908 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1909 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); | 
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1910 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1911 | auto MAbi64 = | 
|  | 1912 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1913 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1914 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1915 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1916 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1917 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1918 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1919 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1920 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1921 |  | 
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 1922 | MtiMipsMultilibsV1 = | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1923 | MultilibSet() | 
|  | 1924 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, | 
|  | 1925 | MArchDefault) | 
|  | 1926 | .Maybe(UCLibc) | 
|  | 1927 | .Maybe(Mips16) | 
|  | 1928 | .FilterOut("/mips64/mips16") | 
|  | 1929 | .FilterOut("/mips64r2/mips16") | 
|  | 1930 | .FilterOut("/micromips/mips16") | 
|  | 1931 | .Maybe(MAbi64) | 
|  | 1932 | .FilterOut("/micromips/64") | 
|  | 1933 | .FilterOut("/mips32/64") | 
|  | 1934 | .FilterOut("^/64") | 
|  | 1935 | .FilterOut("/mips16/64") | 
|  | 1936 | .Either(BigEndian, LittleEndian) | 
|  | 1937 | .Maybe(SoftFloat) | 
|  | 1938 | .Maybe(Nan2008) | 
|  | 1939 | .FilterOut(".*sof/nan2008") | 
|  | 1940 | .FilterOut(NonExistent) | 
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 1941 | .setIncludeDirsCallback([](const Multilib &M) { | 
|  | 1942 | std::vector<std::string> Dirs({"/include"}); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1943 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) | 
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 1944 | Dirs.push_back("/../../../../sysroot/uclibc/usr/include"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1945 | else | 
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 1946 | Dirs.push_back("/../../../../sysroot/usr/include"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1947 | return Dirs; | 
|  | 1948 | }); | 
| Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1949 | } | 
|  | 1950 |  | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 1951 | // Check for CodeScape IMG toolchain starting from v1.3. | 
|  | 1952 | MultilibSet MtiMipsMultilibsV2; | 
|  | 1953 | { | 
|  | 1954 | auto BeHard = makeMultilib("/mips-r2-hard") | 
|  | 1955 | .flag("+EB") | 
|  | 1956 | .flag("-msoft-float") | 
|  | 1957 | .flag("-mnan=2008") | 
|  | 1958 | .flag("-muclibc"); | 
|  | 1959 | auto BeSoft = makeMultilib("/mips-r2-soft") | 
|  | 1960 | .flag("+EB") | 
|  | 1961 | .flag("+msoft-float") | 
|  | 1962 | .flag("-mnan=2008"); | 
|  | 1963 | auto ElHard = makeMultilib("/mipsel-r2-hard") | 
|  | 1964 | .flag("+EL") | 
|  | 1965 | .flag("-msoft-float") | 
|  | 1966 | .flag("-mnan=2008") | 
|  | 1967 | .flag("-muclibc"); | 
|  | 1968 | auto ElSoft = makeMultilib("/mipsel-r2-soft") | 
|  | 1969 | .flag("+EL") | 
|  | 1970 | .flag("+msoft-float") | 
|  | 1971 | .flag("-mnan=2008") | 
|  | 1972 | .flag("-mmicromips"); | 
|  | 1973 | auto BeHardNan = makeMultilib("/mips-r2-hard-nan2008") | 
|  | 1974 | .flag("+EB") | 
|  | 1975 | .flag("-msoft-float") | 
|  | 1976 | .flag("+mnan=2008") | 
|  | 1977 | .flag("-muclibc"); | 
|  | 1978 | auto ElHardNan = makeMultilib("/mipsel-r2-hard-nan2008") | 
|  | 1979 | .flag("+EL") | 
|  | 1980 | .flag("-msoft-float") | 
|  | 1981 | .flag("+mnan=2008") | 
|  | 1982 | .flag("-muclibc") | 
|  | 1983 | .flag("-mmicromips"); | 
|  | 1984 | auto BeHardNanUclibc = makeMultilib("/mips-r2-hard-nan2008-uclibc") | 
|  | 1985 | .flag("+EB") | 
|  | 1986 | .flag("-msoft-float") | 
|  | 1987 | .flag("+mnan=2008") | 
|  | 1988 | .flag("+muclibc"); | 
|  | 1989 | auto ElHardNanUclibc = makeMultilib("/mipsel-r2-hard-nan2008-uclibc") | 
|  | 1990 | .flag("+EL") | 
|  | 1991 | .flag("-msoft-float") | 
|  | 1992 | .flag("+mnan=2008") | 
|  | 1993 | .flag("+muclibc"); | 
|  | 1994 | auto BeHardUclibc = makeMultilib("/mips-r2-hard-uclibc") | 
|  | 1995 | .flag("+EB") | 
|  | 1996 | .flag("-msoft-float") | 
|  | 1997 | .flag("-mnan=2008") | 
|  | 1998 | .flag("+muclibc"); | 
|  | 1999 | auto ElHardUclibc = makeMultilib("/mipsel-r2-hard-uclibc") | 
|  | 2000 | .flag("+EL") | 
|  | 2001 | .flag("-msoft-float") | 
|  | 2002 | .flag("-mnan=2008") | 
|  | 2003 | .flag("+muclibc"); | 
|  | 2004 | auto ElMicroHardNan = makeMultilib("/micromipsel-r2-hard-nan2008") | 
|  | 2005 | .flag("+EL") | 
|  | 2006 | .flag("-msoft-float") | 
|  | 2007 | .flag("+mnan=2008") | 
|  | 2008 | .flag("+mmicromips"); | 
|  | 2009 | auto ElMicroSoft = makeMultilib("/micromipsel-r2-soft") | 
|  | 2010 | .flag("+EL") | 
|  | 2011 | .flag("+msoft-float") | 
|  | 2012 | .flag("-mnan=2008") | 
|  | 2013 | .flag("+mmicromips"); | 
|  | 2014 |  | 
|  | 2015 | auto O32 = | 
|  | 2016 | makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64"); | 
|  | 2017 | auto N32 = | 
|  | 2018 | makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64"); | 
|  | 2019 | auto N64 = | 
|  | 2020 | makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64"); | 
|  | 2021 |  | 
|  | 2022 | MtiMipsMultilibsV2 = | 
|  | 2023 | MultilibSet() | 
|  | 2024 | .Either({BeHard, BeSoft, ElHard, ElSoft, BeHardNan, ElHardNan, | 
|  | 2025 | BeHardNanUclibc, ElHardNanUclibc, BeHardUclibc, | 
|  | 2026 | ElHardUclibc, ElMicroHardNan, ElMicroSoft}) | 
|  | 2027 | .Either(O32, N32, N64) | 
|  | 2028 | .FilterOut(NonExistent) | 
|  | 2029 | .setIncludeDirsCallback([](const Multilib &M) { | 
|  | 2030 | return std::vector<std::string>({"/../../../../sysroot" + | 
|  | 2031 | M.includeSuffix() + | 
|  | 2032 | "/../usr/include"}); | 
|  | 2033 | }) | 
|  | 2034 | .setFilePathsCallback([](const Multilib &M) { | 
|  | 2035 | return std::vector<std::string>( | 
|  | 2036 | {"/../../../../mips-mti-linux-gnu/lib" + M.gccSuffix()}); | 
|  | 2037 | }); | 
|  | 2038 | } | 
|  | 2039 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2040 | // Check for Musl toolchain multilibs | 
|  | 2041 | MultilibSet MuslMipsMultilibs; | 
|  | 2042 | { | 
|  | 2043 | auto MArchMipsR2 = makeMultilib("") | 
|  | 2044 | .osSuffix("/mips-r2-hard-musl") | 
|  | 2045 | .flag("+EB") | 
|  | 2046 | .flag("-EL") | 
|  | 2047 | .flag("+march=mips32r2"); | 
|  | 2048 |  | 
|  | 2049 | auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl") | 
|  | 2050 | .flag("-EB") | 
|  | 2051 | .flag("+EL") | 
|  | 2052 | .flag("+march=mips32r2"); | 
|  | 2053 |  | 
|  | 2054 | MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2); | 
|  | 2055 |  | 
|  | 2056 | // Specify the callback that computes the include directories. | 
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2057 | MuslMipsMultilibs.setIncludeDirsCallback([](const Multilib &M) { | 
|  | 2058 | return std::vector<std::string>( | 
|  | 2059 | {"/../sysroot" + M.osSuffix() + "/usr/include"}); | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2060 | }); | 
|  | 2061 | } | 
|  | 2062 |  | 
| Simon Atanasyan | 4de8e6d | 2016-05-28 09:44:04 +0000 | [diff] [blame] | 2063 | // Check for Code Sourcery toolchain multilibs | 
|  | 2064 | MultilibSet CSMipsMultilibs; | 
|  | 2065 | { | 
|  | 2066 | auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); | 
|  | 2067 |  | 
|  | 2068 | auto MArchMicroMips = | 
|  | 2069 | makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); | 
|  | 2070 |  | 
|  | 2071 | auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); | 
|  | 2072 |  | 
|  | 2073 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); | 
|  | 2074 |  | 
|  | 2075 | auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); | 
|  | 2076 |  | 
|  | 2077 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); | 
|  | 2078 |  | 
|  | 2079 | auto DefaultFloat = | 
|  | 2080 | makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); | 
|  | 2081 |  | 
|  | 2082 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); | 
|  | 2083 |  | 
|  | 2084 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
|  | 2085 |  | 
|  | 2086 | // Note that this one's osSuffix is "" | 
|  | 2087 | auto MAbi64 = makeMultilib("") | 
|  | 2088 | .gccSuffix("/64") | 
|  | 2089 | .includeSuffix("/64") | 
|  | 2090 | .flag("+mabi=n64") | 
|  | 2091 | .flag("-mabi=n32") | 
|  | 2092 | .flag("-m32"); | 
|  | 2093 |  | 
|  | 2094 | CSMipsMultilibs = | 
|  | 2095 | MultilibSet() | 
|  | 2096 | .Either(MArchMips16, MArchMicroMips, MArchDefault) | 
|  | 2097 | .Maybe(UCLibc) | 
|  | 2098 | .Either(SoftFloat, Nan2008, DefaultFloat) | 
|  | 2099 | .FilterOut("/micromips/nan2008") | 
|  | 2100 | .FilterOut("/mips16/nan2008") | 
|  | 2101 | .Either(BigEndian, LittleEndian) | 
|  | 2102 | .Maybe(MAbi64) | 
|  | 2103 | .FilterOut("/mips16.*/64") | 
|  | 2104 | .FilterOut("/micromips.*/64") | 
|  | 2105 | .FilterOut(NonExistent) | 
|  | 2106 | .setIncludeDirsCallback([](const Multilib &M) { | 
|  | 2107 | std::vector<std::string> Dirs({"/include"}); | 
|  | 2108 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) | 
|  | 2109 | Dirs.push_back( | 
|  | 2110 | "/../../../../mips-linux-gnu/libc/uclibc/usr/include"); | 
|  | 2111 | else | 
|  | 2112 | Dirs.push_back("/../../../../mips-linux-gnu/libc/usr/include"); | 
|  | 2113 | return Dirs; | 
|  | 2114 | }); | 
|  | 2115 | } | 
|  | 2116 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2117 | MultilibSet AndroidMipsMultilibs = | 
|  | 2118 | MultilibSet() | 
|  | 2119 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) | 
|  | 2120 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) | 
|  | 2121 | .FilterOut(NonExistent); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2122 |  | 
|  | 2123 | MultilibSet DebianMipsMultilibs; | 
|  | 2124 | { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2125 | Multilib MAbiN32 = | 
|  | 2126 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2127 |  | 
|  | 2128 | Multilib M64 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2129 | .gccSuffix("/64") | 
|  | 2130 | .includeSuffix("/64") | 
|  | 2131 | .flag("+m64") | 
|  | 2132 | .flag("-m32") | 
|  | 2133 | .flag("-mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2134 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2135 | Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2136 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2137 | DebianMipsMultilibs = | 
|  | 2138 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2139 | } | 
|  | 2140 |  | 
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2141 | // Check for CodeScape IMG toolchain v1.2 and early. | 
|  | 2142 | MultilibSet ImgMultilibsV1; | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2143 | { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2144 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2145 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2146 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2147 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2148 | auto MAbi64 = | 
|  | 2149 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2150 |  | 
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame] | 2151 | ImgMultilibsV1 = | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2152 | MultilibSet() | 
|  | 2153 | .Maybe(Mips64r6) | 
|  | 2154 | .Maybe(MAbi64) | 
|  | 2155 | .Maybe(LittleEndian) | 
|  | 2156 | .FilterOut(NonExistent) | 
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2157 | .setIncludeDirsCallback([](const Multilib &M) { | 
|  | 2158 | return std::vector<std::string>( | 
|  | 2159 | {"/include", "/../../../../sysroot/usr/include"}); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2160 | }); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2161 | } | 
|  | 2162 |  | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2163 | // Check for CodeScape IMG toolchain starting from v1.3. | 
|  | 2164 | MultilibSet ImgMultilibsV2; | 
|  | 2165 | { | 
|  | 2166 | auto BeHard = makeMultilib("/mips-r6-hard") | 
|  | 2167 | .flag("+EB") | 
|  | 2168 | .flag("-msoft-float") | 
|  | 2169 | .flag("-mmicromips"); | 
|  | 2170 | auto BeSoft = makeMultilib("/mips-r6-soft") | 
|  | 2171 | .flag("+EB") | 
|  | 2172 | .flag("+msoft-float") | 
|  | 2173 | .flag("-mmicromips"); | 
|  | 2174 | auto ElHard = makeMultilib("/mipsel-r6-hard") | 
|  | 2175 | .flag("+EL") | 
|  | 2176 | .flag("-msoft-float") | 
|  | 2177 | .flag("-mmicromips"); | 
|  | 2178 | auto ElSoft = makeMultilib("/mipsel-r6-soft") | 
|  | 2179 | .flag("+EL") | 
|  | 2180 | .flag("+msoft-float") | 
|  | 2181 | .flag("-mmicromips"); | 
|  | 2182 | auto BeMicroHard = makeMultilib("/micromips-r6-hard") | 
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2183 | .flag("+EB") | 
|  | 2184 | .flag("-msoft-float") | 
|  | 2185 | .flag("+mmicromips"); | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2186 | auto BeMicroSoft = makeMultilib("/micromips-r6-soft") | 
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2187 | .flag("+EB") | 
|  | 2188 | .flag("+msoft-float") | 
|  | 2189 | .flag("+mmicromips"); | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2190 | auto ElMicroHard = makeMultilib("/micromipsel-r6-hard") | 
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2191 | .flag("+EL") | 
|  | 2192 | .flag("-msoft-float") | 
|  | 2193 | .flag("+mmicromips"); | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2194 | auto ElMicroSoft = makeMultilib("/micromipsel-r6-soft") | 
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2195 | .flag("+EL") | 
|  | 2196 | .flag("+msoft-float") | 
|  | 2197 | .flag("+mmicromips"); | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2198 |  | 
|  | 2199 | auto O32 = | 
|  | 2200 | makeMultilib("/lib").osSuffix("").flag("-mabi=n32").flag("-mabi=n64"); | 
|  | 2201 | auto N32 = | 
|  | 2202 | makeMultilib("/lib32").osSuffix("").flag("+mabi=n32").flag("-mabi=n64"); | 
|  | 2203 | auto N64 = | 
|  | 2204 | makeMultilib("/lib64").osSuffix("").flag("-mabi=n32").flag("+mabi=n64"); | 
|  | 2205 |  | 
| Simon Atanasyan | 6c51f5a | 2016-05-22 18:18:41 +0000 | [diff] [blame] | 2206 | ImgMultilibsV2 = | 
|  | 2207 | MultilibSet() | 
|  | 2208 | .Either({BeHard, BeSoft, ElHard, ElSoft, BeMicroHard, BeMicroSoft, | 
|  | 2209 | ElMicroHard, ElMicroSoft}) | 
|  | 2210 | .Either(O32, N32, N64) | 
|  | 2211 | .FilterOut(NonExistent) | 
|  | 2212 | .setIncludeDirsCallback([](const Multilib &M) { | 
|  | 2213 | return std::vector<std::string>({"/../../../../sysroot" + | 
|  | 2214 | M.includeSuffix() + | 
|  | 2215 | "/../usr/include"}); | 
|  | 2216 | }) | 
|  | 2217 | .setFilePathsCallback([](const Multilib &M) { | 
|  | 2218 | return std::vector<std::string>( | 
|  | 2219 | {"/../../../../mips-img-linux-gnu/lib" + M.gccSuffix()}); | 
|  | 2220 | }); | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2221 | } | 
|  | 2222 |  | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2223 | StringRef CPUName; | 
|  | 2224 | StringRef ABIName; | 
|  | 2225 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); | 
|  | 2226 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2227 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); | 
|  | 2228 |  | 
|  | 2229 | Multilib::flags_list Flags; | 
|  | 2230 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); | 
|  | 2231 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); | 
|  | 2232 | addMultilibFlag(isMips16(Args), "mips16", Flags); | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2233 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2234 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || | 
| Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 2235 | CPUName == "mips32r5" || CPUName == "p5600", | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2236 | "march=mips32r2", Flags); | 
| Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 2237 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2238 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2239 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || | 
|  | 2240 | CPUName == "mips64r5" || CPUName == "octeon", | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2241 | "march=mips64r2", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2242 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); | 
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2243 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); | 
| Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 2244 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", | 
|  | 2245 | Flags); | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2246 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); | 
|  | 2247 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2248 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2249 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2250 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2251 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2252 |  | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2253 | if (TargetTriple.isAndroid()) { | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2254 | // Select Android toolchain. It's the only choice in that case. | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2255 | if (AndroidMipsMultilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2256 | Result.Multilibs = AndroidMipsMultilibs; | 
|  | 2257 | return true; | 
|  | 2258 | } | 
|  | 2259 | return false; | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2260 | } | 
|  | 2261 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2262 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && | 
|  | 2263 | TargetTriple.getOS() == llvm::Triple::Linux && | 
|  | 2264 | TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) { | 
|  | 2265 | if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2266 | Result.Multilibs = MuslMipsMultilibs; | 
|  | 2267 | return true; | 
|  | 2268 | } | 
|  | 2269 | return false; | 
|  | 2270 | } | 
|  | 2271 |  | 
| Simon Atanasyan | 4f3fe5b | 2016-05-22 15:28:34 +0000 | [diff] [blame] | 2272 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && | 
|  | 2273 | TargetTriple.getOS() == llvm::Triple::Linux && | 
|  | 2274 | TargetTriple.getEnvironment() == llvm::Triple::GNU) { | 
|  | 2275 | // Select mips-mti-linux-gnu toolchain. | 
| Simon Atanasyan | 96d06c6 | 2016-05-28 09:44:15 +0000 | [diff] [blame] | 2276 | for (auto Candidate : {&MtiMipsMultilibsV1, &MtiMipsMultilibsV2}) { | 
|  | 2277 | if (Candidate->select(Flags, Result.SelectedMultilib)) { | 
|  | 2278 | Result.Multilibs = *Candidate; | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2279 | return true; | 
|  | 2280 | } | 
| Simon Atanasyan | 4f3fe5b | 2016-05-22 15:28:34 +0000 | [diff] [blame] | 2281 | } | 
|  | 2282 | return false; | 
|  | 2283 | } | 
|  | 2284 |  | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2285 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && | 
|  | 2286 | TargetTriple.getOS() == llvm::Triple::Linux && | 
|  | 2287 | TargetTriple.getEnvironment() == llvm::Triple::GNU) { | 
|  | 2288 | // Select mips-img-linux-gnu toolchain. | 
| Simon Atanasyan | 96d06c6 | 2016-05-28 09:44:15 +0000 | [diff] [blame] | 2289 | for (auto Candidate : {&ImgMultilibsV1, &ImgMultilibsV2}) { | 
|  | 2290 | if (Candidate->select(Flags, Result.SelectedMultilib)) { | 
|  | 2291 | Result.Multilibs = *Candidate; | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 2292 | return true; | 
|  | 2293 | } | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2294 | } | 
|  | 2295 | return false; | 
|  | 2296 | } | 
|  | 2297 |  | 
| Simon Atanasyan | 4de8e6d | 2016-05-28 09:44:04 +0000 | [diff] [blame] | 2298 | // Sort candidates. Toolchain that best meets the directories tree goes first. | 
|  | 2299 | // Then select the first toolchains matches command line flags. | 
|  | 2300 | MultilibSet *Candidates[] = {&CSMipsMultilibs, &DebianMipsMultilibs}; | 
|  | 2301 | if (CSMipsMultilibs.size() < DebianMipsMultilibs.size()) | 
|  | 2302 | std::iter_swap(Candidates, Candidates + 1); | 
|  | 2303 | for (const MultilibSet *Candidate : Candidates) { | 
|  | 2304 | if (Candidate->select(Flags, Result.SelectedMultilib)) { | 
|  | 2305 | if (Candidate == &DebianMipsMultilibs) | 
|  | 2306 | Result.BiarchSibling = Multilib(); | 
|  | 2307 | Result.Multilibs = *Candidate; | 
|  | 2308 | return true; | 
|  | 2309 | } | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2310 | } | 
|  | 2311 |  | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2312 | { | 
|  | 2313 | // Fallback to the regular toolchain-tree structure. | 
|  | 2314 | Multilib Default; | 
|  | 2315 | Result.Multilibs.push_back(Default); | 
|  | 2316 | Result.Multilibs.FilterOut(NonExistent); | 
|  | 2317 |  | 
|  | 2318 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2319 | Result.BiarchSibling = Multilib(); | 
|  | 2320 | return true; | 
|  | 2321 | } | 
|  | 2322 | } | 
|  | 2323 |  | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2324 | return false; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2325 | } | 
|  | 2326 |  | 
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2327 | static void findAndroidArmMultilibs(const Driver &D, | 
|  | 2328 | const llvm::Triple &TargetTriple, | 
|  | 2329 | StringRef Path, const ArgList &Args, | 
|  | 2330 | DetectedMultilibs &Result) { | 
|  | 2331 | // Find multilibs with subdirectories like armv7-a, thumb, armv7-a/thumb. | 
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 2332 | FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS()); | 
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2333 | Multilib ArmV7Multilib = makeMultilib("/armv7-a") | 
|  | 2334 | .flag("+armv7") | 
|  | 2335 | .flag("-thumb"); | 
|  | 2336 | Multilib ThumbMultilib = makeMultilib("/thumb") | 
|  | 2337 | .flag("-armv7") | 
|  | 2338 | .flag("+thumb"); | 
|  | 2339 | Multilib ArmV7ThumbMultilib = makeMultilib("/armv7-a/thumb") | 
|  | 2340 | .flag("+armv7") | 
|  | 2341 | .flag("+thumb"); | 
|  | 2342 | Multilib DefaultMultilib = makeMultilib("") | 
|  | 2343 | .flag("-armv7") | 
|  | 2344 | .flag("-thumb"); | 
|  | 2345 | MultilibSet AndroidArmMultilibs = | 
|  | 2346 | MultilibSet() | 
|  | 2347 | .Either(ThumbMultilib, ArmV7Multilib, | 
|  | 2348 | ArmV7ThumbMultilib, DefaultMultilib) | 
|  | 2349 | .FilterOut(NonExistent); | 
|  | 2350 |  | 
|  | 2351 | Multilib::flags_list Flags; | 
|  | 2352 | llvm::StringRef Arch = Args.getLastArgValue(options::OPT_march_EQ); | 
|  | 2353 | bool IsArmArch = TargetTriple.getArch() == llvm::Triple::arm; | 
|  | 2354 | bool IsThumbArch = TargetTriple.getArch() == llvm::Triple::thumb; | 
|  | 2355 | bool IsV7SubArch = TargetTriple.getSubArch() == llvm::Triple::ARMSubArch_v7; | 
|  | 2356 | bool IsThumbMode = IsThumbArch || | 
|  | 2357 | Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, false) || | 
|  | 2358 | (IsArmArch && llvm::ARM::parseArchISA(Arch) == llvm::ARM::IK_THUMB); | 
|  | 2359 | bool IsArmV7Mode = (IsArmArch || IsThumbArch) && | 
|  | 2360 | (llvm::ARM::parseArchVersion(Arch) == 7 || | 
|  | 2361 | (IsArmArch && Arch == "" && IsV7SubArch)); | 
|  | 2362 | addMultilibFlag(IsArmV7Mode, "armv7", Flags); | 
|  | 2363 | addMultilibFlag(IsThumbMode, "thumb", Flags); | 
|  | 2364 |  | 
|  | 2365 | if (AndroidArmMultilibs.select(Flags, Result.SelectedMultilib)) | 
|  | 2366 | Result.Multilibs = AndroidArmMultilibs; | 
|  | 2367 | } | 
|  | 2368 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2369 | static bool findBiarchMultilibs(const Driver &D, | 
|  | 2370 | const llvm::Triple &TargetTriple, | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2371 | StringRef Path, const ArgList &Args, | 
|  | 2372 | bool NeedsBiarchSuffix, | 
|  | 2373 | DetectedMultilibs &Result) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2374 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs | 
|  | 2375 | // in what would normally be GCCInstallPath and put the 64-bit | 
|  | 2376 | // libs in a subdirectory named 64. The simple logic we follow is that | 
|  | 2377 | // *if* there is a subdirectory of the right name with crtbegin.o in it, | 
|  | 2378 | // we use that. If not, and if not a biarch triple alias, we look for | 
|  | 2379 | // crtbegin.o without the subdirectory. | 
|  | 2380 |  | 
|  | 2381 | Multilib Default; | 
|  | 2382 | Multilib Alt64 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2383 | .gccSuffix("/64") | 
|  | 2384 | .includeSuffix("/64") | 
|  | 2385 | .flag("-m32") | 
|  | 2386 | .flag("+m64") | 
|  | 2387 | .flag("-mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2388 | Multilib Alt32 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2389 | .gccSuffix("/32") | 
|  | 2390 | .includeSuffix("/32") | 
|  | 2391 | .flag("+m32") | 
|  | 2392 | .flag("-m64") | 
|  | 2393 | .flag("-mx32"); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2394 | Multilib Altx32 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2395 | .gccSuffix("/x32") | 
|  | 2396 | .includeSuffix("/x32") | 
|  | 2397 | .flag("-m32") | 
|  | 2398 | .flag("-m64") | 
|  | 2399 | .flag("+mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2400 |  | 
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 2401 | // GCC toolchain for IAMCU doesn't have crtbegin.o, so look for libgcc.a. | 
|  | 2402 | FilterNonExistent NonExistent( | 
|  | 2403 | Path, TargetTriple.isOSIAMCU() ? "/libgcc.a" : "/crtbegin.o", D.getVFS()); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2404 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2405 | // Determine default multilib from: 32, 64, x32 | 
|  | 2406 | // Also handle cases such as 64 on 32, 32 on 64, etc. | 
|  | 2407 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; | 
| David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2408 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; | 
| Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2409 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2410 | Want = WANT64; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2411 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2412 | Want = WANT64; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2413 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2414 | Want = WANT32; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2415 | else { | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2416 | if (TargetTriple.isArch32Bit()) | 
|  | 2417 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2418 | else if (IsX32) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2419 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2420 | else | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2421 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; | 
| Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2422 | } | 
|  | 2423 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2424 | if (Want == WANT32) | 
|  | 2425 | Default.flag("+m32").flag("-m64").flag("-mx32"); | 
|  | 2426 | else if (Want == WANT64) | 
|  | 2427 | Default.flag("-m32").flag("+m64").flag("-mx32"); | 
|  | 2428 | else if (Want == WANTX32) | 
|  | 2429 | Default.flag("-m32").flag("-m64").flag("+mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2430 | else | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2431 | return false; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2432 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2433 | Result.Multilibs.push_back(Default); | 
|  | 2434 | Result.Multilibs.push_back(Alt64); | 
|  | 2435 | Result.Multilibs.push_back(Alt32); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2436 | Result.Multilibs.push_back(Altx32); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2437 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2438 | Result.Multilibs.FilterOut(NonExistent); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2439 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2440 | Multilib::flags_list Flags; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2441 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2442 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2443 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2444 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2445 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2446 | return false; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2447 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2448 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2449 | Result.SelectedMultilib == Altx32) | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2450 | Result.BiarchSibling = Default; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2451 |  | 
|  | 2452 | return true; | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2453 | } | 
|  | 2454 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2455 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( | 
|  | 2456 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, | 
|  | 2457 | const std::string &LibDir, StringRef CandidateTriple, | 
|  | 2458 | bool NeedsBiarchSuffix) { | 
|  | 2459 | // Solaris is a special case. The GCC installation is under | 
|  | 2460 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we | 
|  | 2461 | // need to iterate twice. | 
|  | 2462 | std::error_code EC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2463 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; | 
|  | 2464 | !EC && LI != LE; LI = LI.increment(EC)) { | 
|  | 2465 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2466 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); | 
|  | 2467 |  | 
|  | 2468 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2469 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2470 | continue; // Saw this path before; no need to look at it again. | 
|  | 2471 | if (CandidateVersion.isOlderThan(4, 1, 1)) | 
|  | 2472 | continue; | 
|  | 2473 | if (CandidateVersion <= Version) | 
|  | 2474 | continue; | 
|  | 2475 |  | 
|  | 2476 | GCCInstallPath = | 
|  | 2477 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2478 | if (!D.getVFS().exists(GCCInstallPath)) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2479 | continue; | 
|  | 2480 |  | 
|  | 2481 | // If we make it here there has to be at least one GCC version, let's just | 
|  | 2482 | // use the latest one. | 
|  | 2483 | std::error_code EEC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2484 | for (vfs::directory_iterator | 
|  | 2485 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), | 
|  | 2486 | LLE; | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2487 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { | 
|  | 2488 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2489 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2490 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); | 
|  | 2491 |  | 
|  | 2492 | if (CandidateSubVersion > Version) | 
|  | 2493 | Version = CandidateSubVersion; | 
|  | 2494 | } | 
|  | 2495 |  | 
|  | 2496 | GCCTriple.setTriple(CandidateTriple); | 
|  | 2497 |  | 
|  | 2498 | GCCInstallPath += "/" + Version.Text; | 
|  | 2499 | GCCParentLibPath = GCCInstallPath + "/../../../../"; | 
|  | 2500 |  | 
|  | 2501 | IsValid = true; | 
|  | 2502 | } | 
|  | 2503 | } | 
|  | 2504 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2505 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2506 | const llvm::Triple &TargetTriple, const ArgList &Args, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2507 | const std::string &LibDir, StringRef CandidateTriple, | 
|  | 2508 | bool NeedsBiarchSuffix) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2509 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2510 | // There are various different suffixes involving the triple we | 
|  | 2511 | // 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] | 2512 | // up to the lib directory. Specifically, the number of "up" steps | 
|  | 2513 | // in the second half of each row is 1 + the number of path separators | 
|  | 2514 | // in the first half. | 
|  | 2515 | const std::string LibAndInstallSuffixes[][2] = { | 
|  | 2516 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, | 
|  | 2517 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2518 | // Debian puts cross-compilers in gcc-cross | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2519 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, | 
|  | 2520 |  | 
|  | 2521 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), | 
|  | 2522 | "/../../../.."}, | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2523 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2524 | // The Freescale PPC SDK has the gcc libraries in | 
|  | 2525 | // <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] | 2526 | {"/" + CandidateTriple.str(), "/../.."}, | 
| Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2527 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2528 | // Ubuntu has a strange mis-matched pair of triples that this happens to | 
|  | 2529 | // match. | 
|  | 2530 | // FIXME: It may be worthwhile to generalize this and look for a second | 
|  | 2531 | // triple. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2532 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; | 
|  | 2533 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2534 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { | 
|  | 2535 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, | 
|  | 2536 | NeedsBiarchSuffix); | 
|  | 2537 | return; | 
|  | 2538 | } | 
|  | 2539 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2540 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2541 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - | 
|  | 2542 | (TargetArch != llvm::Triple::x86)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2543 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2544 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; | 
| Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2545 | std::error_code EC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2546 | for (vfs::directory_iterator | 
|  | 2547 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), | 
|  | 2548 | LE; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2549 | !EC && LI != LE; LI = LI.increment(EC)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2550 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2551 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); | 
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2552 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2553 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) | 
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2554 | continue; // Saw this path before; no need to look at it again. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2555 | if (CandidateVersion.isOlderThan(4, 1, 1)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2556 | continue; | 
|  | 2557 | if (CandidateVersion <= Version) | 
|  | 2558 | continue; | 
| Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2559 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2560 | DetectedMultilibs Detected; | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2561 |  | 
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2562 | // Android standalone toolchain could have multilibs for ARM and Thumb. | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2563 | // Debian mips multilibs behave more like the rest of the biarch ones, | 
|  | 2564 | // so handle them there | 
| Chih-Hung Hsieh | b4d3bf7 | 2016-06-01 20:48:46 +0000 | [diff] [blame] | 2565 | if (isArmOrThumbArch(TargetArch) && TargetTriple.isAndroid()) { | 
|  | 2566 | // It should also work without multilibs in a simplified toolchain. | 
|  | 2567 | findAndroidArmMultilibs(D, TargetTriple, LI->getName(), Args, Detected); | 
|  | 2568 | } else if (isMipsArch(TargetArch)) { | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2569 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2570 | continue; | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2571 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2572 | NeedsBiarchSuffix, Detected)) { | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2573 | continue; | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2574 | } | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2575 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2576 | Multilibs = Detected.Multilibs; | 
|  | 2577 | SelectedMultilib = Detected.SelectedMultilib; | 
|  | 2578 | BiarchSibling = Detected.BiarchSibling; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2579 | Version = CandidateVersion; | 
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2580 | GCCTriple.setTriple(CandidateTriple); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2581 | // FIXME: We hack together the directory name here instead of | 
|  | 2582 | // using LI to ensure stable path separators across Windows and | 
|  | 2583 | // Linux. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2584 | GCCInstallPath = | 
|  | 2585 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); | 
|  | 2586 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2587 | IsValid = true; | 
|  | 2588 | } | 
|  | 2589 | } | 
|  | 2590 | } | 
|  | 2591 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2592 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2593 | const ArgList &Args) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2594 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2595 | getProgramPaths().push_back(getDriver().getInstalledDir()); | 
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2596 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2597 | getProgramPaths().push_back(getDriver().Dir); | 
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2598 | } | 
|  | 2599 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2600 | Generic_GCC::~Generic_GCC() {} | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2601 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2602 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { | 
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2603 | switch (AC) { | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2604 | case Action::PreprocessJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2605 | if (!Preprocess) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2606 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2607 | return Preprocess.get(); | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2608 | case Action::CompileJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2609 | if (!Compile) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2610 | Compile.reset(new tools::gcc::Compiler(*this)); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2611 | return Compile.get(); | 
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2612 | default: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2613 | return ToolChain::getTool(AC); | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2614 | } | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2615 | } | 
|  | 2616 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2617 | Tool *Generic_GCC::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2618 | return new tools::gnutools::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2619 | } | 
|  | 2620 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2621 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2622 |  | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2623 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { | 
|  | 2624 | // Print the information about how we detected the GCC installation. | 
|  | 2625 | GCCInstallation.print(OS); | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2626 | CudaInstallation.print(OS); | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2627 | } | 
|  | 2628 |  | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2629 | bool Generic_GCC::IsUnwindTablesDefault() const { | 
| Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2630 | return getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2631 | } | 
|  | 2632 |  | 
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2633 | bool Generic_GCC::isPICDefault() const { | 
|  | 2634 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); | 
|  | 2635 | } | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2636 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2637 | bool Generic_GCC::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2638 |  | 
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2639 | bool Generic_GCC::isPICDefaultForced() const { | 
|  | 2640 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); | 
|  | 2641 | } | 
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2642 |  | 
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2643 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2644 | switch (getTriple().getArch()) { | 
|  | 2645 | case llvm::Triple::x86: | 
|  | 2646 | case llvm::Triple::x86_64: | 
|  | 2647 | case llvm::Triple::aarch64: | 
|  | 2648 | case llvm::Triple::aarch64_be: | 
|  | 2649 | case llvm::Triple::arm: | 
|  | 2650 | case llvm::Triple::armeb: | 
| Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2651 | case llvm::Triple::bpfel: | 
|  | 2652 | case llvm::Triple::bpfeb: | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2653 | case llvm::Triple::thumb: | 
|  | 2654 | case llvm::Triple::thumbeb: | 
|  | 2655 | case llvm::Triple::ppc: | 
|  | 2656 | case llvm::Triple::ppc64: | 
|  | 2657 | case llvm::Triple::ppc64le: | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2658 | case llvm::Triple::systemz: | 
| Daniel Sanders | e160f83 | 2016-05-14 12:43:08 +0000 | [diff] [blame] | 2659 | case llvm::Triple::mips: | 
|  | 2660 | case llvm::Triple::mipsel: | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2661 | return true; | 
|  | 2662 | default: | 
|  | 2663 | return false; | 
|  | 2664 | } | 
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2665 | } | 
|  | 2666 |  | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2667 | /// \brief Helper to add the variant paths of a libstdc++ installation. | 
|  | 2668 | bool Generic_GCC::addLibStdCXXIncludePaths( | 
|  | 2669 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, | 
|  | 2670 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, | 
|  | 2671 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2672 | if (!getVFS().exists(Base + Suffix)) | 
|  | 2673 | return false; | 
|  | 2674 |  | 
|  | 2675 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); | 
|  | 2676 |  | 
|  | 2677 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If | 
|  | 2678 | // that path exists or we have neither a GCC nor target multiarch triple, use | 
|  | 2679 | // this vanilla search path. | 
|  | 2680 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || | 
|  | 2681 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { | 
|  | 2682 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2683 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); | 
|  | 2684 | } else { | 
|  | 2685 | // Otherwise try to use multiarch naming schemes which have normalized the | 
|  | 2686 | // triples and put the triple before the suffix. | 
|  | 2687 | // | 
|  | 2688 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and | 
|  | 2689 | // the target triple, so we support that here. | 
|  | 2690 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2691 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); | 
|  | 2692 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2693 | Base + "/" + TargetMultiarchTriple + Suffix); | 
|  | 2694 | } | 
|  | 2695 |  | 
|  | 2696 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); | 
|  | 2697 | return true; | 
|  | 2698 | } | 
|  | 2699 |  | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2700 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 2701 | ArgStringList &CC1Args) const { | 
|  | 2702 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2703 | bool UseInitArrayDefault = | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2704 | getTriple().getArch() == llvm::Triple::aarch64 || | 
| Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2705 | getTriple().getArch() == llvm::Triple::aarch64_be || | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2706 | (getTriple().getOS() == llvm::Triple::Linux && | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2707 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2708 | getTriple().getOS() == llvm::Triple::NaCl || | 
|  | 2709 | (getTriple().getVendor() == llvm::Triple::MipsTechnologies && | 
|  | 2710 | !getTriple().hasEnvironment()); | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2711 |  | 
|  | 2712 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2713 | options::OPT_fno_use_init_array, UseInitArrayDefault)) | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2714 | CC1Args.push_back("-fuse-init-array"); | 
|  | 2715 | } | 
|  | 2716 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2717 | /// Mips Toolchain | 
|  | 2718 | MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D, | 
|  | 2719 | const llvm::Triple &Triple, | 
|  | 2720 | const ArgList &Args) | 
|  | 2721 | : Linux(D, Triple, Args) { | 
|  | 2722 | // Select the correct multilib according to the given arguments. | 
|  | 2723 | DetectedMultilibs Result; | 
|  | 2724 | findMIPSMultilibs(D, Triple, "", Args, Result); | 
|  | 2725 | Multilibs = Result.Multilibs; | 
|  | 2726 | SelectedMultilib = Result.SelectedMultilib; | 
|  | 2727 |  | 
|  | 2728 | // Find out the library suffix based on the ABI. | 
|  | 2729 | LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple); | 
|  | 2730 | getFilePaths().clear(); | 
|  | 2731 | getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix); | 
|  | 2732 |  | 
|  | 2733 | // Use LLD by default. | 
| Peter Collingbourne | 39719a7 | 2015-11-20 20:49:39 +0000 | [diff] [blame] | 2734 | DefaultLinker = "lld"; | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2735 | } | 
|  | 2736 |  | 
|  | 2737 | void MipsLLVMToolChain::AddClangSystemIncludeArgs( | 
|  | 2738 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2739 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 2740 | return; | 
|  | 2741 |  | 
|  | 2742 | const Driver &D = getDriver(); | 
|  | 2743 |  | 
|  | 2744 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
|  | 2745 | SmallString<128> P(D.ResourceDir); | 
|  | 2746 | llvm::sys::path::append(P, "include"); | 
|  | 2747 | addSystemInclude(DriverArgs, CC1Args, P); | 
|  | 2748 | } | 
|  | 2749 |  | 
|  | 2750 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 2751 | return; | 
|  | 2752 |  | 
|  | 2753 | const auto &Callback = Multilibs.includeDirsCallback(); | 
|  | 2754 | if (Callback) { | 
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2755 | for (const auto &Path : Callback(SelectedMultilib)) | 
|  | 2756 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, | 
|  | 2757 | D.getInstalledDir() + Path); | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2758 | } | 
|  | 2759 | } | 
|  | 2760 |  | 
|  | 2761 | Tool *MipsLLVMToolChain::buildLinker() const { | 
|  | 2762 | return new tools::gnutools::Linker(*this); | 
|  | 2763 | } | 
|  | 2764 |  | 
|  | 2765 | std::string MipsLLVMToolChain::computeSysRoot() const { | 
|  | 2766 | if (!getDriver().SysRoot.empty()) | 
|  | 2767 | return getDriver().SysRoot + SelectedMultilib.osSuffix(); | 
|  | 2768 |  | 
|  | 2769 | const std::string InstalledDir(getDriver().getInstalledDir()); | 
|  | 2770 | std::string SysRootPath = | 
|  | 2771 | InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix(); | 
|  | 2772 | if (llvm::sys::fs::exists(SysRootPath)) | 
|  | 2773 | return SysRootPath; | 
|  | 2774 |  | 
|  | 2775 | return std::string(); | 
|  | 2776 | } | 
|  | 2777 |  | 
|  | 2778 | ToolChain::CXXStdlibType | 
|  | 2779 | MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
|  | 2780 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); | 
|  | 2781 | if (A) { | 
|  | 2782 | StringRef Value = A->getValue(); | 
|  | 2783 | if (Value != "libc++") | 
|  | 2784 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) | 
|  | 2785 | << A->getAsString(Args); | 
|  | 2786 | } | 
|  | 2787 |  | 
|  | 2788 | return ToolChain::CST_Libcxx; | 
|  | 2789 | } | 
|  | 2790 |  | 
|  | 2791 | void MipsLLVMToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 2792 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2793 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 2794 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2795 | return; | 
|  | 2796 |  | 
|  | 2797 | assert((GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) && | 
|  | 2798 | "Only -lc++ (aka libcxx) is suported in this toolchain."); | 
|  | 2799 |  | 
|  | 2800 | const auto &Callback = Multilibs.includeDirsCallback(); | 
|  | 2801 | if (Callback) { | 
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2802 | for (std::string Path : Callback(SelectedMultilib)) { | 
|  | 2803 | Path = getDriver().getInstalledDir() + Path + "/c++/v1"; | 
|  | 2804 | if (llvm::sys::fs::exists(Path)) { | 
|  | 2805 | addSystemInclude(DriverArgs, CC1Args, Path); | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2806 | break; | 
|  | 2807 | } | 
|  | 2808 | } | 
|  | 2809 | } | 
|  | 2810 | } | 
|  | 2811 |  | 
|  | 2812 | void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 2813 | ArgStringList &CmdArgs) const { | 
|  | 2814 | assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) && | 
|  | 2815 | "Only -lc++ (aka libxx) is suported in this toolchain."); | 
|  | 2816 |  | 
|  | 2817 | CmdArgs.push_back("-lc++"); | 
|  | 2818 | CmdArgs.push_back("-lc++abi"); | 
|  | 2819 | CmdArgs.push_back("-lunwind"); | 
|  | 2820 | } | 
|  | 2821 |  | 
|  | 2822 | std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, | 
|  | 2823 | StringRef Component, | 
|  | 2824 | bool Shared) const { | 
|  | 2825 | SmallString<128> Path(getDriver().ResourceDir); | 
|  | 2826 | llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix, | 
|  | 2827 | getOS()); | 
|  | 2828 | llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" + | 
| Vasileios Kalintiris | bbc9930 | 2015-11-16 15:41:30 +0000 | [diff] [blame] | 2829 | "mips" + (Shared ? ".so" : ".a"))); | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2830 | return Path.str(); | 
|  | 2831 | } | 
|  | 2832 |  | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2833 | /// Hexagon Toolchain | 
|  | 2834 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2835 | std::string HexagonToolChain::getHexagonTargetDir( | 
|  | 2836 | const std::string &InstalledDir, | 
|  | 2837 | const SmallVectorImpl<std::string> &PrefixDirs) const { | 
|  | 2838 | std::string InstallRelDir; | 
|  | 2839 | const Driver &D = getDriver(); | 
|  | 2840 |  | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2841 | // Locate the rest of the toolchain ... | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2842 | for (auto &I : PrefixDirs) | 
|  | 2843 | if (D.getVFS().exists(I)) | 
|  | 2844 | return I; | 
| Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 2845 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2846 | if (getVFS().exists(InstallRelDir = InstalledDir + "/../target")) | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2847 | return InstallRelDir; | 
|  | 2848 |  | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2849 | return InstallRelDir; | 
|  | 2850 | } | 
|  | 2851 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2852 | Optional<unsigned> HexagonToolChain::getSmallDataThreshold( | 
|  | 2853 | const ArgList &Args) { | 
|  | 2854 | StringRef Gn = ""; | 
|  | 2855 | if (Arg *A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, | 
|  | 2856 | options::OPT_msmall_data_threshold_EQ)) { | 
|  | 2857 | Gn = A->getValue(); | 
|  | 2858 | } else if (Args.getLastArg(options::OPT_shared, options::OPT_fpic, | 
|  | 2859 | options::OPT_fPIC)) { | 
|  | 2860 | Gn = "0"; | 
|  | 2861 | } | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2862 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2863 | unsigned G; | 
|  | 2864 | if (!Gn.getAsInteger(10, G)) | 
|  | 2865 | return G; | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2866 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2867 | return None; | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2868 | } | 
|  | 2869 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2870 | void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args, | 
|  | 2871 | ToolChain::path_list &LibPaths) const { | 
|  | 2872 | const Driver &D = getDriver(); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2873 |  | 
|  | 2874 | //---------------------------------------------------------------------------- | 
|  | 2875 | // -L Args | 
|  | 2876 | //---------------------------------------------------------------------------- | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 2877 | for (Arg *A : Args.filtered(options::OPT_L)) | 
|  | 2878 | for (const char *Value : A->getValues()) | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2879 | LibPaths.push_back(Value); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2880 |  | 
|  | 2881 | //---------------------------------------------------------------------------- | 
|  | 2882 | // Other standard paths | 
|  | 2883 | //---------------------------------------------------------------------------- | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2884 | std::vector<std::string> RootDirs; | 
| Krzysztof Parzyszek | f4467cd | 2016-01-06 14:13:11 +0000 | [diff] [blame] | 2885 | std::copy(D.PrefixDirs.begin(), D.PrefixDirs.end(), | 
|  | 2886 | std::back_inserter(RootDirs)); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2887 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2888 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2889 | D.PrefixDirs); | 
|  | 2890 | if (std::find(RootDirs.begin(), RootDirs.end(), TargetDir) == RootDirs.end()) | 
|  | 2891 | RootDirs.push_back(TargetDir); | 
|  | 2892 |  | 
|  | 2893 | bool HasPIC = Args.hasArg(options::OPT_fpic, options::OPT_fPIC); | 
|  | 2894 | // Assume G0 with -shared. | 
|  | 2895 | bool HasG0 = Args.hasArg(options::OPT_shared); | 
|  | 2896 | if (auto G = getSmallDataThreshold(Args)) | 
|  | 2897 | HasG0 = G.getValue() == 0; | 
|  | 2898 |  | 
|  | 2899 | const std::string CpuVer = GetTargetCPUVersion(Args).str(); | 
|  | 2900 | for (auto &Dir : RootDirs) { | 
|  | 2901 | std::string LibDir = Dir + "/hexagon/lib"; | 
|  | 2902 | std::string LibDirCpu = LibDir + '/' + CpuVer; | 
|  | 2903 | if (HasG0) { | 
|  | 2904 | if (HasPIC) | 
|  | 2905 | LibPaths.push_back(LibDirCpu + "/G0/pic"); | 
|  | 2906 | LibPaths.push_back(LibDirCpu + "/G0"); | 
|  | 2907 | } | 
|  | 2908 | LibPaths.push_back(LibDirCpu); | 
|  | 2909 | LibPaths.push_back(LibDir); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2910 | } | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2911 | } | 
|  | 2912 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2913 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2914 | const llvm::opt::ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2915 | : Linux(D, Triple, Args) { | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2916 | const std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2917 | D.PrefixDirs); | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2918 |  | 
|  | 2919 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to | 
|  | 2920 | // program paths | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2921 | const std::string BinDir(TargetDir + "/bin"); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2922 | if (D.getVFS().exists(BinDir)) | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2923 | getProgramPaths().push_back(BinDir); | 
|  | 2924 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2925 | ToolChain::path_list &LibPaths = getFilePaths(); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2926 |  | 
|  | 2927 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets | 
|  | 2928 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually | 
|  | 2929 | // support 'linux' we'll need to fix this up | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2930 | LibPaths.clear(); | 
|  | 2931 | getHexagonLibraryPaths(Args, LibPaths); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2932 | } | 
|  | 2933 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2934 | HexagonToolChain::~HexagonToolChain() {} | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2935 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2936 | Tool *HexagonToolChain::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2937 | return new tools::hexagon::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2938 | } | 
|  | 2939 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2940 | Tool *HexagonToolChain::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2941 | return new tools::hexagon::Linker(*this); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2942 | } | 
|  | 2943 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2944 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 2945 | ArgStringList &CC1Args) const { | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2946 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
|  | 2947 | DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 2948 | return; | 
|  | 2949 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2950 | const Driver &D = getDriver(); | 
|  | 2951 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2952 | D.PrefixDirs); | 
|  | 2953 | addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include"); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2954 | } | 
|  | 2955 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2956 | void HexagonToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 2957 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2958 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 2959 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2960 | return; | 
|  | 2961 |  | 
|  | 2962 | const Driver &D = getDriver(); | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2963 | std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs); | 
|  | 2964 | addSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include/c++"); | 
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2965 | } | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2966 |  | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2967 | ToolChain::CXXStdlibType | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2968 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2969 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); | 
|  | 2970 | if (!A) | 
|  | 2971 | return ToolChain::CST_Libstdcxx; | 
|  | 2972 |  | 
|  | 2973 | StringRef Value = A->getValue(); | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2974 | if (Value != "libstdc++") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2975 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2976 |  | 
|  | 2977 | return ToolChain::CST_Libstdcxx; | 
|  | 2978 | } | 
|  | 2979 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2980 | // | 
|  | 2981 | // Returns the default CPU for Hexagon. This is the default compilation target | 
|  | 2982 | // if no Hexagon processor is selected at the command-line. | 
|  | 2983 | // | 
|  | 2984 | const StringRef HexagonToolChain::GetDefaultCPU() { | 
|  | 2985 | return "hexagonv60"; | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2986 | } | 
|  | 2987 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2988 | const StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) { | 
|  | 2989 | Arg *CpuArg = nullptr; | 
| Krzysztof Parzyszek | 972f72c | 2016-01-06 21:12:03 +0000 | [diff] [blame] | 2990 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ, options::OPT_march_EQ)) | 
|  | 2991 | CpuArg = A; | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2992 |  | 
|  | 2993 | StringRef CPU = CpuArg ? CpuArg->getValue() : GetDefaultCPU(); | 
|  | 2994 | if (CPU.startswith("hexagon")) | 
|  | 2995 | return CPU.substr(sizeof("hexagon") - 1); | 
|  | 2996 | return CPU; | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2997 | } | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2998 | // End Hexagon | 
| Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 2999 |  | 
| Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 3000 | /// AMDGPU Toolchain | 
|  | 3001 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 3002 | const ArgList &Args) | 
|  | 3003 | : Generic_ELF(D, Triple, Args) { } | 
|  | 3004 |  | 
|  | 3005 | Tool *AMDGPUToolChain::buildLinker() const { | 
|  | 3006 | return new tools::amdgpu::Linker(*this); | 
|  | 3007 | } | 
|  | 3008 | // End AMDGPU | 
|  | 3009 |  | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3010 | /// NaCl Toolchain | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3011 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 3012 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3013 | : Generic_ELF(D, Triple, Args) { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3014 |  | 
|  | 3015 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the | 
|  | 3016 | // default paths, and must instead only use the paths provided | 
|  | 3017 | // with this toolchain based on architecture. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3018 | path_list &file_paths = getFilePaths(); | 
|  | 3019 | path_list &prog_paths = getProgramPaths(); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3020 |  | 
|  | 3021 | file_paths.clear(); | 
|  | 3022 | prog_paths.clear(); | 
|  | 3023 |  | 
|  | 3024 | // Path for library files (libc.a, ...) | 
|  | 3025 | std::string FilePath(getDriver().Dir + "/../"); | 
|  | 3026 |  | 
|  | 3027 | // Path for tools (clang, ld, etc..) | 
|  | 3028 | std::string ProgPath(getDriver().Dir + "/../"); | 
|  | 3029 |  | 
|  | 3030 | // Path for toolchain libraries (libgcc.a, ...) | 
|  | 3031 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); | 
|  | 3032 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3033 | switch (Triple.getArch()) { | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3034 | case llvm::Triple::x86: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3035 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); | 
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 3036 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3037 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); | 
|  | 3038 | file_paths.push_back(ToolPath + "i686-nacl"); | 
|  | 3039 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3040 | case llvm::Triple::x86_64: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3041 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); | 
|  | 3042 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); | 
|  | 3043 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); | 
|  | 3044 | file_paths.push_back(ToolPath + "x86_64-nacl"); | 
|  | 3045 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3046 | case llvm::Triple::arm: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3047 | file_paths.push_back(FilePath + "arm-nacl/lib"); | 
|  | 3048 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); | 
|  | 3049 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); | 
|  | 3050 | file_paths.push_back(ToolPath + "arm-nacl"); | 
|  | 3051 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3052 | case llvm::Triple::mipsel: | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3053 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); | 
|  | 3054 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); | 
|  | 3055 | prog_paths.push_back(ProgPath + "bin"); | 
|  | 3056 | file_paths.push_back(ToolPath + "mipsel-nacl"); | 
|  | 3057 | break; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3058 | default: | 
|  | 3059 | break; | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3060 | } | 
|  | 3061 |  | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3062 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); | 
|  | 3063 | } | 
|  | 3064 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3065 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 3066 | ArgStringList &CC1Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3067 | const Driver &D = getDriver(); | 
|  | 3068 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 3069 | return; | 
|  | 3070 |  | 
|  | 3071 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
|  | 3072 | SmallString<128> P(D.ResourceDir); | 
|  | 3073 | llvm::sys::path::append(P, "include"); | 
|  | 3074 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 3075 | } | 
|  | 3076 |  | 
|  | 3077 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 3078 | return; | 
|  | 3079 |  | 
|  | 3080 | SmallString<128> P(D.Dir + "/../"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3081 | switch (getTriple().getArch()) { | 
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 3082 | case llvm::Triple::x86: | 
|  | 3083 | // x86 is special because multilib style uses x86_64-nacl/include for libc | 
|  | 3084 | // headers but the SDK wants i686-nacl/usr/include. The other architectures | 
|  | 3085 | // have the same substring. | 
|  | 3086 | llvm::sys::path::append(P, "i686-nacl/usr/include"); | 
|  | 3087 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 3088 | llvm::sys::path::remove_filename(P); | 
|  | 3089 | llvm::sys::path::remove_filename(P); | 
|  | 3090 | llvm::sys::path::remove_filename(P); | 
|  | 3091 | llvm::sys::path::append(P, "x86_64-nacl/include"); | 
|  | 3092 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 3093 | return; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3094 | case llvm::Triple::arm: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3095 | llvm::sys::path::append(P, "arm-nacl/usr/include"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3096 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3097 | case llvm::Triple::x86_64: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3098 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3099 | break; | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3100 | case llvm::Triple::mipsel: | 
|  | 3101 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); | 
|  | 3102 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3103 | default: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3104 | return; | 
|  | 3105 | } | 
|  | 3106 |  | 
|  | 3107 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 3108 | llvm::sys::path::remove_filename(P); | 
|  | 3109 | llvm::sys::path::remove_filename(P); | 
|  | 3110 | llvm::sys::path::append(P, "include"); | 
|  | 3111 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 3112 | } | 
|  | 3113 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3114 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 3115 | ArgStringList &CmdArgs) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3116 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg | 
|  | 3117 | // if the value is libc++, and emits an error for other values. | 
|  | 3118 | GetCXXStdlibType(Args); | 
|  | 3119 | CmdArgs.push_back("-lc++"); | 
|  | 3120 | } | 
|  | 3121 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3122 | void NaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3123 | ArgStringList &CC1Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3124 | const Driver &D = getDriver(); | 
|  | 3125 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3126 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3127 | return; | 
|  | 3128 |  | 
|  | 3129 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg | 
|  | 3130 | // if the value is libc++, and emits an error for other values. | 
|  | 3131 | GetCXXStdlibType(DriverArgs); | 
|  | 3132 |  | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3133 | SmallString<128> P(D.Dir + "/../"); | 
|  | 3134 | switch (getTriple().getArch()) { | 
|  | 3135 | case llvm::Triple::arm: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3136 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); | 
|  | 3137 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3138 | break; | 
|  | 3139 | case llvm::Triple::x86: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3140 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); | 
|  | 3141 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3142 | break; | 
|  | 3143 | case llvm::Triple::x86_64: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3144 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); | 
|  | 3145 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3146 | break; | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 3147 | case llvm::Triple::mipsel: | 
|  | 3148 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); | 
|  | 3149 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 3150 | break; | 
| Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 3151 | default: | 
|  | 3152 | break; | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3153 | } | 
|  | 3154 | } | 
|  | 3155 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3156 | ToolChain::CXXStdlibType | 
|  | 3157 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3158 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { | 
|  | 3159 | StringRef Value = A->getValue(); | 
|  | 3160 | if (Value == "libc++") | 
|  | 3161 | return ToolChain::CST_Libcxx; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3162 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3163 | } | 
|  | 3164 |  | 
|  | 3165 | return ToolChain::CST_Libcxx; | 
|  | 3166 | } | 
|  | 3167 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3168 | std::string | 
|  | 3169 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, | 
|  | 3170 | types::ID InputType) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3171 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); | 
|  | 3172 | if (TheTriple.getArch() == llvm::Triple::arm && | 
|  | 3173 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) | 
|  | 3174 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); | 
|  | 3175 | return TheTriple.getTriple(); | 
|  | 3176 | } | 
|  | 3177 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3178 | Tool *NaClToolChain::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3179 | return new tools::nacltools::Linker(*this); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3180 | } | 
|  | 3181 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 3182 | Tool *NaClToolChain::buildAssembler() const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3183 | if (getTriple().getArch() == llvm::Triple::arm) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3184 | return new tools::nacltools::AssemblerARM(*this); | 
|  | 3185 | return new tools::gnutools::Assembler(*this); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 3186 | } | 
|  | 3187 | // End NaCl | 
|  | 3188 |  | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3189 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform | 
|  | 3190 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. | 
|  | 3191 | /// Currently does not support anything else but compilation. | 
|  | 3192 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3193 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 3194 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3195 | : ToolChain(D, Triple, Args) { | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3196 | // Path mangling to find libexec | 
|  | 3197 | std::string Path(getDriver().Dir); | 
|  | 3198 |  | 
|  | 3199 | Path += "/../libexec"; | 
|  | 3200 | getProgramPaths().push_back(Path); | 
|  | 3201 | } | 
|  | 3202 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 3203 | TCEToolChain::~TCEToolChain() {} | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3204 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3205 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3206 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3207 | bool TCEToolChain::isPICDefault() const { return false; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3208 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3209 | bool TCEToolChain::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 3210 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3211 | bool TCEToolChain::isPICDefaultForced() const { return false; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3212 |  | 
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3213 | // CloudABI - CloudABI tool chain which can call ld(1) directly. | 
|  | 3214 |  | 
|  | 3215 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, | 
|  | 3216 | const ArgList &Args) | 
|  | 3217 | : Generic_ELF(D, Triple, Args) { | 
|  | 3218 | SmallString<128> P(getDriver().Dir); | 
|  | 3219 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); | 
|  | 3220 | getFilePaths().push_back(P.str()); | 
|  | 3221 | } | 
|  | 3222 |  | 
|  | 3223 | void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3224 | ArgStringList &CC1Args) const { | 
|  | 3225 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) && | 
|  | 3226 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3227 | return; | 
|  | 3228 |  | 
|  | 3229 | SmallString<128> P(getDriver().Dir); | 
|  | 3230 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); | 
|  | 3231 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 3232 | } | 
|  | 3233 |  | 
|  | 3234 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 3235 | ArgStringList &CmdArgs) const { | 
|  | 3236 | CmdArgs.push_back("-lc++"); | 
|  | 3237 | CmdArgs.push_back("-lc++abi"); | 
|  | 3238 | CmdArgs.push_back("-lunwind"); | 
|  | 3239 | } | 
|  | 3240 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3241 | Tool *CloudABI::buildLinker() const { | 
|  | 3242 | return new tools::cloudabi::Linker(*this); | 
|  | 3243 | } | 
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3244 |  | 
| Ed Schouten | 51bfbe7 | 2016-02-17 18:56:20 +0000 | [diff] [blame] | 3245 | SanitizerMask CloudABI::getSupportedSanitizers() const { | 
|  | 3246 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 3247 | Res |= SanitizerKind::SafeStack; | 
|  | 3248 | return Res; | 
|  | 3249 | } | 
|  | 3250 |  | 
| Ed Schouten | fc79d2c | 2016-03-29 21:13:53 +0000 | [diff] [blame] | 3251 | SanitizerMask CloudABI::getDefaultSanitizers() const { | 
|  | 3252 | return SanitizerKind::SafeStack; | 
|  | 3253 | } | 
|  | 3254 |  | 
| Reid Kleckner | 330fb17 | 2016-05-11 16:19:05 +0000 | [diff] [blame] | 3255 | /// Haiku - Haiku tool chain which can call as(1) and ld(1) directly. | 
|  | 3256 |  | 
|  | 3257 | Haiku::Haiku(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) | 
|  | 3258 | : Generic_ELF(D, Triple, Args) { | 
|  | 3259 |  | 
|  | 3260 | } | 
|  | 3261 |  | 
|  | 3262 | void Haiku::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3263 | ArgStringList &CC1Args) const { | 
|  | 3264 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3265 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3266 | return; | 
|  | 3267 |  | 
|  | 3268 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3269 | case ToolChain::CST_Libcxx: | 
|  | 3270 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3271 | getDriver().SysRoot + "/system/develop/headers/c++/v1"); | 
|  | 3272 | break; | 
|  | 3273 | case ToolChain::CST_Libstdcxx: | 
|  | 3274 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3275 | getDriver().SysRoot + "/system/develop/headers/c++"); | 
|  | 3276 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3277 | getDriver().SysRoot + "/system/develop/headers/c++/backward"); | 
|  | 3278 |  | 
|  | 3279 | StringRef Triple = getTriple().str(); | 
|  | 3280 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3281 | getDriver().SysRoot + "/system/develop/headers/c++/" + | 
|  | 3282 | Triple); | 
|  | 3283 | break; | 
|  | 3284 | } | 
|  | 3285 | } | 
|  | 3286 |  | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3287 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 3288 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3289 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, | 
|  | 3290 | const ArgList &Args) | 
|  | 3291 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3292 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3293 | getFilePaths().push_back("/usr/lib"); | 
|  | 3294 | } | 
|  | 3295 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3296 | Tool *OpenBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3297 | return new tools::openbsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3298 | } | 
|  | 3299 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3300 | Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3301 |  | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3302 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. | 
|  | 3303 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3304 | Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3305 | : Generic_ELF(D, Triple, Args) { | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3306 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
|  | 3307 | getFilePaths().push_back("/usr/lib"); | 
|  | 3308 | } | 
|  | 3309 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3310 | Tool *Bitrig::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3311 | return new tools::bitrig::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3312 | } | 
|  | 3313 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3314 | Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3315 |  | 
| Jonas Hahnfeld | aae8374 | 2016-02-12 07:48:37 +0000 | [diff] [blame] | 3316 | ToolChain::CXXStdlibType Bitrig::GetDefaultCXXStdlibType() const { | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3317 | return ToolChain::CST_Libcxx; | 
|  | 3318 | } | 
|  | 3319 |  | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3320 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3321 | ArgStringList &CC1Args) const { | 
|  | 3322 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3323 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3324 | return; | 
|  | 3325 |  | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3326 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3327 | case ToolChain::CST_Libcxx: | 
|  | 3328 | addSystemInclude(DriverArgs, CC1Args, | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3329 | getDriver().SysRoot + "/usr/include/c++/v1"); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3330 | break; | 
|  | 3331 | case ToolChain::CST_Libstdcxx: | 
|  | 3332 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3333 | getDriver().SysRoot + "/usr/include/c++/stdc++"); | 
|  | 3334 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3335 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3336 |  | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3337 | StringRef Triple = getTriple().str(); | 
|  | 3338 | if (Triple.startswith("amd64")) | 
|  | 3339 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3340 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3341 | Triple.substr(5)); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3342 | else | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3343 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + | 
|  | 3344 | "/usr/include/c++/stdc++/" + | 
|  | 3345 | Triple); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3346 | break; | 
|  | 3347 | } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3348 | } | 
|  | 3349 |  | 
|  | 3350 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 3351 | ArgStringList &CmdArgs) const { | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3352 | switch (GetCXXStdlibType(Args)) { | 
|  | 3353 | case ToolChain::CST_Libcxx: | 
|  | 3354 | CmdArgs.push_back("-lc++"); | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3355 | CmdArgs.push_back("-lc++abi"); | 
|  | 3356 | CmdArgs.push_back("-lpthread"); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3357 | break; | 
|  | 3358 | case ToolChain::CST_Libstdcxx: | 
|  | 3359 | CmdArgs.push_back("-lstdc++"); | 
|  | 3360 | break; | 
|  | 3361 | } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3362 | } | 
|  | 3363 |  | 
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3364 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 3365 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3366 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, | 
|  | 3367 | const ArgList &Args) | 
|  | 3368 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 3369 |  | 
| Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 3370 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall | 
|  | 3371 | // back to '/usr/lib' if it doesn't exist. | 
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3372 | if ((Triple.getArch() == llvm::Triple::x86 || | 
|  | 3373 | Triple.getArch() == llvm::Triple::ppc) && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3374 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) | 
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3375 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); | 
|  | 3376 | else | 
|  | 3377 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); | 
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3378 | } | 
|  | 3379 |  | 
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3380 | ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3381 | if (getTriple().getOSMajorVersion() >= 10) | 
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3382 | return ToolChain::CST_Libcxx; | 
|  | 3383 | return ToolChain::CST_Libstdcxx; | 
|  | 3384 | } | 
|  | 3385 |  | 
|  | 3386 | void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3387 | ArgStringList &CC1Args) const { | 
|  | 3388 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3389 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3390 | return; | 
|  | 3391 |  | 
|  | 3392 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3393 | case ToolChain::CST_Libcxx: | 
|  | 3394 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3395 | getDriver().SysRoot + "/usr/include/c++/v1"); | 
|  | 3396 | break; | 
|  | 3397 | case ToolChain::CST_Libstdcxx: | 
|  | 3398 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3399 | getDriver().SysRoot + "/usr/include/c++/4.2"); | 
|  | 3400 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3401 | getDriver().SysRoot + "/usr/include/c++/4.2/backward"); | 
|  | 3402 | break; | 
|  | 3403 | } | 
|  | 3404 | } | 
|  | 3405 |  | 
| Dimitry Andric | 6090739 | 2016-02-14 16:08:20 +0000 | [diff] [blame] | 3406 | void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 3407 | ArgStringList &CmdArgs) const { | 
|  | 3408 | CXXStdlibType Type = GetCXXStdlibType(Args); | 
|  | 3409 | bool Profiling = Args.hasArg(options::OPT_pg); | 
|  | 3410 |  | 
|  | 3411 | switch (Type) { | 
|  | 3412 | case ToolChain::CST_Libcxx: | 
|  | 3413 | CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++"); | 
|  | 3414 | break; | 
|  | 3415 |  | 
|  | 3416 | case ToolChain::CST_Libstdcxx: | 
|  | 3417 | CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++"); | 
|  | 3418 | break; | 
|  | 3419 | } | 
|  | 3420 | } | 
|  | 3421 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3422 | Tool *FreeBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3423 | return new tools::freebsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3424 | } | 
|  | 3425 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3426 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3427 |  | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 3428 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { | 
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3429 | // FreeBSD uses SjLj exceptions on ARM oabi. | 
|  | 3430 | switch (getTriple().getEnvironment()) { | 
| Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 3431 | case llvm::Triple::GNUEABIHF: | 
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3432 | case llvm::Triple::GNUEABI: | 
|  | 3433 | case llvm::Triple::EABI: | 
|  | 3434 | return false; | 
|  | 3435 |  | 
|  | 3436 | default: | 
|  | 3437 | return (getTriple().getArch() == llvm::Triple::arm || | 
|  | 3438 | getTriple().getArch() == llvm::Triple::thumb); | 
|  | 3439 | } | 
|  | 3440 | } | 
|  | 3441 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3442 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } | 
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3443 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3444 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } | 
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3445 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3446 | SanitizerMask FreeBSD::getSupportedSanitizers() const { | 
|  | 3447 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; | 
|  | 3448 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; | 
|  | 3449 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || | 
|  | 3450 | getTriple().getArch() == llvm::Triple::mips64el; | 
|  | 3451 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 3452 | Res |= SanitizerKind::Address; | 
|  | 3453 | Res |= SanitizerKind::Vptr; | 
|  | 3454 | if (IsX86_64 || IsMIPS64) { | 
|  | 3455 | Res |= SanitizerKind::Leak; | 
|  | 3456 | Res |= SanitizerKind::Thread; | 
|  | 3457 | } | 
|  | 3458 | if (IsX86 || IsX86_64) { | 
|  | 3459 | Res |= SanitizerKind::SafeStack; | 
|  | 3460 | } | 
|  | 3461 | return Res; | 
|  | 3462 | } | 
|  | 3463 |  | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3464 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 3465 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3466 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3467 | : Generic_ELF(D, Triple, Args) { | 
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3468 | if (getDriver().UseStdLib) { | 
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3469 | // When targeting a 32-bit platform, try the special directory used on | 
|  | 3470 | // 64-bit hosts, and only fall back to the main library directory if that | 
|  | 3471 | // doesn't work. | 
|  | 3472 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure | 
|  | 3473 | // what all logic is needed to emulate the '=' prefix here. | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3474 | switch (Triple.getArch()) { | 
|  | 3475 | case llvm::Triple::x86: | 
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3476 | getFilePaths().push_back("=/usr/lib/i386"); | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3477 | break; | 
|  | 3478 | case llvm::Triple::arm: | 
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3479 | case llvm::Triple::armeb: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3480 | case llvm::Triple::thumb: | 
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3481 | case llvm::Triple::thumbeb: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3482 | switch (Triple.getEnvironment()) { | 
|  | 3483 | case llvm::Triple::EABI: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3484 | case llvm::Triple::GNUEABI: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3485 | getFilePaths().push_back("=/usr/lib/eabi"); | 
|  | 3486 | break; | 
| Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3487 | case llvm::Triple::EABIHF: | 
|  | 3488 | case llvm::Triple::GNUEABIHF: | 
|  | 3489 | getFilePaths().push_back("=/usr/lib/eabihf"); | 
|  | 3490 | break; | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3491 | default: | 
|  | 3492 | getFilePaths().push_back("=/usr/lib/oabi"); | 
|  | 3493 | break; | 
|  | 3494 | } | 
|  | 3495 | break; | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3496 | case llvm::Triple::mips64: | 
|  | 3497 | case llvm::Triple::mips64el: | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3498 | if (tools::mips::hasMipsAbiArg(Args, "o32")) | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3499 | getFilePaths().push_back("=/usr/lib/o32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3500 | else if (tools::mips::hasMipsAbiArg(Args, "64")) | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3501 | getFilePaths().push_back("=/usr/lib/64"); | 
|  | 3502 | break; | 
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3503 | case llvm::Triple::ppc: | 
|  | 3504 | getFilePaths().push_back("=/usr/lib/powerpc"); | 
|  | 3505 | break; | 
| Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3506 | case llvm::Triple::sparc: | 
|  | 3507 | getFilePaths().push_back("=/usr/lib/sparc"); | 
|  | 3508 | break; | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3509 | default: | 
|  | 3510 | break; | 
|  | 3511 | } | 
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3512 |  | 
|  | 3513 | getFilePaths().push_back("=/usr/lib"); | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3514 | } | 
|  | 3515 | } | 
|  | 3516 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3517 | Tool *NetBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3518 | return new tools::netbsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3519 | } | 
|  | 3520 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3521 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3522 |  | 
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3523 | ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const { | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3524 | unsigned Major, Minor, Micro; | 
|  | 3525 | getTriple().getOSVersion(Major, Minor, Micro); | 
| Joerg Sonnenberger | 21156e8 | 2016-02-11 23:35:03 +0000 | [diff] [blame] | 3526 | if (Major >= 7 || Major == 0) { | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3527 | switch (getArch()) { | 
| Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3528 | case llvm::Triple::aarch64: | 
| Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3529 | case llvm::Triple::arm: | 
|  | 3530 | case llvm::Triple::armeb: | 
|  | 3531 | case llvm::Triple::thumb: | 
|  | 3532 | case llvm::Triple::thumbeb: | 
| Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3533 | case llvm::Triple::ppc: | 
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3534 | case llvm::Triple::ppc64: | 
|  | 3535 | case llvm::Triple::ppc64le: | 
| Joerg Sonnenberger | 059613c | 2016-02-11 23:18:36 +0000 | [diff] [blame] | 3536 | case llvm::Triple::sparc: | 
|  | 3537 | case llvm::Triple::sparcv9: | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3538 | case llvm::Triple::x86: | 
|  | 3539 | case llvm::Triple::x86_64: | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3540 | return ToolChain::CST_Libcxx; | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3541 | default: | 
|  | 3542 | break; | 
|  | 3543 | } | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3544 | } | 
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3545 | return ToolChain::CST_Libstdcxx; | 
|  | 3546 | } | 
|  | 3547 |  | 
|  | 3548 | void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3549 | ArgStringList &CC1Args) const { | 
|  | 3550 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3551 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3552 | return; | 
|  | 3553 |  | 
|  | 3554 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3555 | case ToolChain::CST_Libcxx: | 
|  | 3556 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3557 | getDriver().SysRoot + "/usr/include/c++/"); | 
|  | 3558 | break; | 
|  | 3559 | case ToolChain::CST_Libstdcxx: | 
|  | 3560 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3561 | getDriver().SysRoot + "/usr/include/g++"); | 
|  | 3562 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3563 | getDriver().SysRoot + "/usr/include/g++/backward"); | 
|  | 3564 | break; | 
|  | 3565 | } | 
|  | 3566 | } | 
|  | 3567 |  | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3568 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. | 
|  | 3569 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3570 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3571 | : Generic_ELF(D, Triple, Args) { | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3572 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
|  | 3573 | getFilePaths().push_back("/usr/lib"); | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3574 | } | 
|  | 3575 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3576 | Tool *Minix::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3577 | return new tools::minix::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3578 | } | 
|  | 3579 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3580 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3581 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3582 | static void addPathIfExists(const Driver &D, const Twine &Path, | 
|  | 3583 | ToolChain::path_list &Paths) { | 
|  | 3584 | if (D.getVFS().exists(Path)) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3585 | Paths.push_back(Path.str()); | 
|  | 3586 | } | 
|  | 3587 |  | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3588 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. | 
|  | 3589 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3590 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3591 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3592 | : Generic_GCC(D, Triple, Args) { | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3593 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3594 | GCCInstallation.init(Triple, Args); | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3595 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3596 | path_list &Paths = getFilePaths(); | 
|  | 3597 | if (GCCInstallation.isValid()) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3598 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3599 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3600 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3601 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3602 | addPathIfExists(D, getDriver().Dir, Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3603 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3604 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3605 |  | 
|  | 3606 | std::string LibPath = "/usr/lib/"; | 
|  | 3607 | switch (Triple.getArch()) { | 
|  | 3608 | case llvm::Triple::x86: | 
|  | 3609 | case llvm::Triple::sparc: | 
|  | 3610 | break; | 
|  | 3611 | case llvm::Triple::x86_64: | 
|  | 3612 | LibPath += "amd64/"; | 
|  | 3613 | break; | 
|  | 3614 | case llvm::Triple::sparcv9: | 
|  | 3615 | LibPath += "sparcv9/"; | 
|  | 3616 | break; | 
|  | 3617 | default: | 
|  | 3618 | llvm_unreachable("Unsupported architecture"); | 
|  | 3619 | } | 
|  | 3620 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3621 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3622 | } | 
|  | 3623 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3624 | Tool *Solaris::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3625 | return new tools::solaris::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3626 | } | 
|  | 3627 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3628 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } | 
| Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3629 |  | 
| Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3630 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3631 | ArgStringList &CC1Args) const { | 
|  | 3632 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3633 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3634 | return; | 
|  | 3635 |  | 
|  | 3636 | // Include the support directory for things like xlocale and fudged system | 
|  | 3637 | // headers. | 
|  | 3638 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); | 
|  | 3639 |  | 
|  | 3640 | if (GCCInstallation.isValid()) { | 
|  | 3641 | GCCVersion Version = GCCInstallation.getVersion(); | 
|  | 3642 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3643 | getDriver().SysRoot + "/usr/gcc/" + | 
|  | 3644 | Version.MajorStr + "." + | 
|  | 3645 | Version.MinorStr + | 
|  | 3646 | "/include/c++/" + Version.Text); | 
|  | 3647 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3648 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + | 
|  | 3649 | "." + Version.MinorStr + "/include/c++/" + | 
|  | 3650 | Version.Text + "/" + | 
|  | 3651 | GCCInstallation.getTriple().str()); | 
|  | 3652 | } | 
|  | 3653 | } | 
|  | 3654 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3655 | /// Distribution (very bare-bones at the moment). | 
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3656 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3657 | enum Distro { | 
| Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3658 | // NB: Releases of a particular Linux distro should be kept together | 
|  | 3659 | // in this enum, because some tests are done by integer comparison against | 
|  | 3660 | // the first and last known member in the family, e.g. IsRedHat(). | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3661 | ArchLinux, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3662 | DebianLenny, | 
|  | 3663 | DebianSqueeze, | 
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3664 | DebianWheezy, | 
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3665 | DebianJessie, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3666 | DebianStretch, | 
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3667 | Exherbo, | 
| Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3668 | RHEL5, | 
|  | 3669 | RHEL6, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3670 | RHEL7, | 
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3671 | Fedora, | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3672 | OpenSUSE, | 
| Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3673 | UbuntuHardy, | 
|  | 3674 | UbuntuIntrepid, | 
| Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3675 | UbuntuJaunty, | 
| Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3676 | UbuntuKarmic, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3677 | UbuntuLucid, | 
|  | 3678 | UbuntuMaverick, | 
| Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3679 | UbuntuNatty, | 
| Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3680 | UbuntuOneiric, | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3681 | UbuntuPrecise, | 
| Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3682 | UbuntuQuantal, | 
|  | 3683 | UbuntuRaring, | 
| Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3684 | UbuntuSaucy, | 
| Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3685 | UbuntuTrusty, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3686 | UbuntuUtopic, | 
|  | 3687 | UbuntuVivid, | 
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3688 | UbuntuWily, | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3689 | UbuntuXenial, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3690 | UnknownDistro | 
|  | 3691 | }; | 
|  | 3692 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3693 | static bool IsRedhat(enum Distro Distro) { | 
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3694 | return Distro == Fedora || (Distro >= RHEL5 && Distro <= RHEL7); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3695 | } | 
|  | 3696 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3697 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3698 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3699 | static bool IsDebian(enum Distro Distro) { | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3700 | return Distro >= DebianLenny && Distro <= DebianStretch; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3701 | } | 
|  | 3702 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3703 | static bool IsUbuntu(enum Distro Distro) { | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3704 | return Distro >= UbuntuHardy && Distro <= UbuntuXenial; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3705 | } | 
|  | 3706 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3707 | static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3708 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = | 
|  | 3709 | llvm::MemoryBuffer::getFile("/etc/lsb-release"); | 
|  | 3710 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3711 | StringRef Data = File.get()->getBuffer(); | 
| Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3712 | SmallVector<StringRef, 16> Lines; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3713 | Data.split(Lines, "\n"); | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3714 | Distro Version = UnknownDistro; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3715 | for (StringRef Line : Lines) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3716 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) | 
|  | 3717 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) | 
|  | 3718 | .Case("hardy", UbuntuHardy) | 
|  | 3719 | .Case("intrepid", UbuntuIntrepid) | 
|  | 3720 | .Case("jaunty", UbuntuJaunty) | 
|  | 3721 | .Case("karmic", UbuntuKarmic) | 
|  | 3722 | .Case("lucid", UbuntuLucid) | 
|  | 3723 | .Case("maverick", UbuntuMaverick) | 
|  | 3724 | .Case("natty", UbuntuNatty) | 
|  | 3725 | .Case("oneiric", UbuntuOneiric) | 
|  | 3726 | .Case("precise", UbuntuPrecise) | 
|  | 3727 | .Case("quantal", UbuntuQuantal) | 
|  | 3728 | .Case("raring", UbuntuRaring) | 
|  | 3729 | .Case("saucy", UbuntuSaucy) | 
|  | 3730 | .Case("trusty", UbuntuTrusty) | 
|  | 3731 | .Case("utopic", UbuntuUtopic) | 
|  | 3732 | .Case("vivid", UbuntuVivid) | 
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3733 | .Case("wily", UbuntuWily) | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3734 | .Case("xenial", UbuntuXenial) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3735 | .Default(UnknownDistro); | 
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3736 | if (Version != UnknownDistro) | 
|  | 3737 | return Version; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3738 | } | 
|  | 3739 |  | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3740 | File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); | 
|  | 3741 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3742 | StringRef Data = File.get()->getBuffer(); | 
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3743 | if (Data.startswith("Fedora release")) | 
|  | 3744 | return Fedora; | 
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3745 | if (Data.startswith("Red Hat Enterprise Linux") || | 
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3746 | Data.startswith("CentOS") || | 
|  | 3747 | Data.startswith("Scientific Linux")) { | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3748 | if (Data.find("release 7") != StringRef::npos) | 
|  | 3749 | return RHEL7; | 
|  | 3750 | else if (Data.find("release 6") != StringRef::npos) | 
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3751 | return RHEL6; | 
|  | 3752 | else if (Data.find("release 5") != StringRef::npos) | 
|  | 3753 | return RHEL5; | 
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3754 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3755 | return UnknownDistro; | 
|  | 3756 | } | 
|  | 3757 |  | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3758 | File = llvm::MemoryBuffer::getFile("/etc/debian_version"); | 
|  | 3759 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3760 | StringRef Data = File.get()->getBuffer(); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3761 | if (Data[0] == '5') | 
|  | 3762 | return DebianLenny; | 
| Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 3763 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3764 | return DebianSqueeze; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3765 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') | 
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3766 | return DebianWheezy; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3767 | else if (Data.startswith("jessie/sid") || Data[0] == '8') | 
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3768 | return DebianJessie; | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3769 | else if (Data.startswith("stretch/sid") || Data[0] == '9') | 
|  | 3770 | return DebianStretch; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3771 | return UnknownDistro; | 
|  | 3772 | } | 
|  | 3773 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3774 | if (D.getVFS().exists("/etc/SuSE-release")) | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3775 | return OpenSUSE; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3776 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3777 | if (D.getVFS().exists("/etc/exherbo-release")) | 
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3778 | return Exherbo; | 
|  | 3779 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3780 | if (D.getVFS().exists("/etc/arch-release")) | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3781 | return ArchLinux; | 
|  | 3782 |  | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3783 | return UnknownDistro; | 
|  | 3784 | } | 
|  | 3785 |  | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3786 | /// \brief Get our best guess at the multiarch triple for a target. | 
|  | 3787 | /// | 
|  | 3788 | /// Debian-based systems are starting to use a multiarch setup where they use | 
|  | 3789 | /// a target-triple directory in the library and header search paths. | 
|  | 3790 | /// Unfortunately, this triple does not align with the vanilla target triple, | 
|  | 3791 | /// so we provide a rough mapping here. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3792 | static std::string getMultiarchTriple(const Driver &D, | 
|  | 3793 | const llvm::Triple &TargetTriple, | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3794 | StringRef SysRoot) { | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 3795 | llvm::Triple::EnvironmentType TargetEnvironment = | 
|  | 3796 | TargetTriple.getEnvironment(); | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3797 |  | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3798 | // For most architectures, just use whatever we have rather than trying to be | 
|  | 3799 | // clever. | 
|  | 3800 | switch (TargetTriple.getArch()) { | 
|  | 3801 | default: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3802 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3803 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3804 | // We use the existence of '/lib/<triple>' as a directory to detect some | 
|  | 3805 | // common linux triples that don't quite match the Clang triple for both | 
|  | 3806 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these | 
|  | 3807 | // regardless of what the actual target triple is. | 
| Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 3808 | case llvm::Triple::arm: | 
|  | 3809 | case llvm::Triple::thumb: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3810 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3811 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3812 | return "arm-linux-gnueabihf"; | 
|  | 3813 | } else { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3814 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3815 | return "arm-linux-gnueabi"; | 
|  | 3816 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3817 | break; | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3818 | case llvm::Triple::armeb: | 
|  | 3819 | case llvm::Triple::thumbeb: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3820 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3821 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3822 | return "armeb-linux-gnueabihf"; | 
|  | 3823 | } else { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3824 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3825 | return "armeb-linux-gnueabi"; | 
|  | 3826 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3827 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3828 | case llvm::Triple::x86: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3829 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3830 | return "i386-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3831 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3832 | case llvm::Triple::x86_64: | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3833 | // 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] | 3834 | if (TargetEnvironment != llvm::Triple::GNUX32 && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3835 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3836 | return "x86_64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3837 | break; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3838 | case llvm::Triple::aarch64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3839 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3840 | return "aarch64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3841 | break; | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3842 | case llvm::Triple::aarch64_be: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3843 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3844 | return "aarch64_be-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3845 | break; | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3846 | case llvm::Triple::mips: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3847 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3848 | return "mips-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3849 | break; | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3850 | case llvm::Triple::mipsel: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3851 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3852 | return "mipsel-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3853 | break; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3854 | case llvm::Triple::mips64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3855 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3856 | return "mips64-linux-gnu"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3857 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3858 | return "mips64-linux-gnuabi64"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3859 | break; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3860 | case llvm::Triple::mips64el: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3861 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3862 | return "mips64el-linux-gnu"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3863 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3864 | return "mips64el-linux-gnuabi64"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3865 | break; | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3866 | case llvm::Triple::ppc: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3867 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) | 
| Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 3868 | return "powerpc-linux-gnuspe"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3869 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3870 | return "powerpc-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3871 | break; | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3872 | case llvm::Triple::ppc64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3873 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3874 | return "powerpc64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3875 | break; | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3876 | case llvm::Triple::ppc64le: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3877 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3878 | return "powerpc64le-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3879 | break; | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3880 | case llvm::Triple::sparc: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3881 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3882 | return "sparc-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3883 | break; | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3884 | case llvm::Triple::sparcv9: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3885 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3886 | return "sparc64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3887 | break; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3888 | case llvm::Triple::systemz: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3889 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3890 | return "s390x-linux-gnu"; | 
|  | 3891 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3892 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3893 | return TargetTriple.str(); | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3894 | } | 
|  | 3895 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3896 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3897 | if (isMipsArch(Triple.getArch())) { | 
|  | 3898 | // lib32 directory has a special meaning on MIPS targets. | 
|  | 3899 | // It contains N32 ABI binaries. Use this folder if produce | 
|  | 3900 | // code for N32 ABI only. | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3901 | if (tools::mips::hasMipsAbiArg(Args, "n32")) | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3902 | return "lib32"; | 
|  | 3903 | return Triple.isArch32Bit() ? "lib" : "lib64"; | 
|  | 3904 | } | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3905 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3906 | // 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] | 3907 | // using that variant while targeting other architectures causes problems | 
|  | 3908 | // 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] | 3909 | // with a 'lib32' library search path being considered. So we only enable | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3910 | // them when we know we may need it. | 
|  | 3911 | // | 
|  | 3912 | // 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] | 3913 | // reasoning about oslibdir spellings with the lib dir spellings in the | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3914 | // GCCInstallationDetector, but that is a more significant refactoring. | 
|  | 3915 | if (Triple.getArch() == llvm::Triple::x86 || | 
|  | 3916 | Triple.getArch() == llvm::Triple::ppc) | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3917 | return "lib32"; | 
|  | 3918 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3919 | if (Triple.getArch() == llvm::Triple::x86_64 && | 
|  | 3920 | Triple.getEnvironment() == llvm::Triple::GNUX32) | 
|  | 3921 | return "libx32"; | 
|  | 3922 |  | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3923 | return Triple.isArch32Bit() ? "lib" : "lib64"; | 
|  | 3924 | } | 
|  | 3925 |  | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 3926 | static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs, | 
|  | 3927 | const Multilib &Multilib, | 
|  | 3928 | StringRef InstallPath, | 
|  | 3929 | ToolChain::path_list &Paths) { | 
|  | 3930 | if (const auto &PathsCallback = Multilibs.filePathsCallback()) | 
|  | 3931 | for (const auto &Path : PathsCallback(Multilib)) | 
|  | 3932 | addPathIfExists(D, InstallPath + Path, Paths); | 
|  | 3933 | } | 
|  | 3934 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3935 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3936 | : Generic_ELF(D, Triple, Args) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3937 | GCCInstallation.init(Triple, Args); | 
|  | 3938 | CudaInstallation.init(Triple, Args); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3939 | Multilibs = GCCInstallation.getMultilibs(); | 
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3940 | llvm::Triple::ArchType Arch = Triple.getArch(); | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3941 | std::string SysRoot = computeSysRoot(); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3942 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3943 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at | 
| Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 3944 | // least) put various tools in a triple-prefixed directory off of the parent | 
|  | 3945 | // of the GCC installation. We use the GCC triple here to ensure that we end | 
|  | 3946 | // up with tools that support the same amount of cross compiling as the | 
|  | 3947 | // detected GCC installation. For example, if we find a GCC installation | 
|  | 3948 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be | 
|  | 3949 | // used to target i386. | 
|  | 3950 | // FIXME: This seems unlikely to be Linux-specific. | 
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3951 | ToolChain::path_list &PPaths = getProgramPaths(); | 
| Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 3952 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3953 | GCCInstallation.getTriple().str() + "/bin") | 
|  | 3954 | .str()); | 
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3955 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3956 | Distro Distro = DetectDistro(D, Arch); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3957 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3958 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { | 
| Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 3959 | ExtraOpts.push_back("-z"); | 
|  | 3960 | ExtraOpts.push_back("relro"); | 
|  | 3961 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3962 |  | 
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3963 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3964 | ExtraOpts.push_back("-X"); | 
|  | 3965 |  | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 3966 | const bool IsAndroid = Triple.isAndroid(); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3967 | const bool IsMips = isMipsArch(Arch); | 
|  | 3968 |  | 
|  | 3969 | if (IsMips && !SysRoot.empty()) | 
|  | 3970 | ExtraOpts.push_back("--sysroot=" + SysRoot); | 
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3971 |  | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3972 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash | 
|  | 3973 | // and the MIPS ABI require .dynsym to be sorted in different ways. | 
|  | 3974 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS | 
|  | 3975 | // ABI requires a mapping between the GOT and the symbol table. | 
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3976 | // Android loader does not support .gnu.hash. | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3977 | if (!IsMips && !IsAndroid) { | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3978 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3979 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3980 | ExtraOpts.push_back("--hash-style=gnu"); | 
|  | 3981 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3982 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3983 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) | 
|  | 3984 | ExtraOpts.push_back("--hash-style=both"); | 
|  | 3985 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3986 |  | 
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3987 | if (IsRedhat(Distro) && Distro != RHEL5 && Distro != RHEL6) | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3988 | ExtraOpts.push_back("--no-add-needed"); | 
|  | 3989 |  | 
| Rafael Espindola | 5ed89d4 | 2016-06-03 17:26:16 +0000 | [diff] [blame] | 3990 | #ifdef ENABLE_LINKER_BUILD_ID | 
|  | 3991 | ExtraOpts.push_back("--build-id"); | 
|  | 3992 | #endif | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3993 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3994 | if (IsOpenSUSE(Distro)) | 
| Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 3995 | ExtraOpts.push_back("--enable-new-dtags"); | 
| Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 3996 |  | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3997 | // The selection of paths to try here is designed to match the patterns which | 
|  | 3998 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. | 
|  | 3999 | // This was determined by running GCC in a fake filesystem, creating all | 
|  | 4000 | // possible permutations of these directories, and seeing which ones it added | 
|  | 4001 | // to the link paths. | 
|  | 4002 | path_list &Paths = getFilePaths(); | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 4003 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4004 | const std::string OSLibDir = getOSLibDir(Triple, Args); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4005 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 4006 |  | 
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 4007 | // Add the multilib suffixed paths where they are available. | 
|  | 4008 | if (GCCInstallation.isValid()) { | 
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 4009 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); | 
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 4010 | const std::string &LibPath = GCCInstallation.getParentLibPath(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4011 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Simon Atanasyan | 2834a22 | 2016-05-22 18:18:07 +0000 | [diff] [blame] | 4012 | const MultilibSet &Multilibs = GCCInstallation.getMultilibs(); | 
|  | 4013 |  | 
|  | 4014 | // Add toolchain / multilib specific file paths. | 
|  | 4015 | addMultilibsFilePaths(D, Multilibs, Multilib, | 
|  | 4016 | GCCInstallation.getInstallPath(), Paths); | 
| Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 4017 |  | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4018 | // Sourcery CodeBench MIPS toolchain holds some libraries under | 
| Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 4019 | // a biarch-like suffix of the GCC installation. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4020 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4021 | Paths); | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4022 |  | 
|  | 4023 | // GCC cross compiling toolchains will install target libraries which ship | 
|  | 4024 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as | 
|  | 4025 | // any part of the GCC installation in | 
|  | 4026 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat | 
|  | 4027 | // debatable, but is the reality today. We need to search this tree even | 
|  | 4028 | // when we have a sysroot somewhere else. It is the responsibility of | 
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 4029 | // whomever is doing the cross build targeting a sysroot using a GCC | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4030 | // installation that is *not* within the system root to ensure two things: | 
|  | 4031 | // | 
|  | 4032 | //  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] | 4033 | //     above must be present on the system root and found via an | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4034 | //     appropriate rpath. | 
|  | 4035 | //  2) There must not be libraries installed into | 
|  | 4036 | //     <prefix>/<triple>/<libdir> unless they should be preferred over | 
|  | 4037 | //     those within the system root. | 
|  | 4038 | // | 
|  | 4039 | // Note that this matches the GCC behavior. See the below comment for where | 
|  | 4040 | // Clang diverges from GCC's behavior. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4041 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + | 
|  | 4042 | OSLibDir + Multilib.osSuffix(), | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4043 | Paths); | 
|  | 4044 |  | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4045 | // If the GCC installation we found is inside of the sysroot, we want to | 
|  | 4046 | // prefer libraries installed in the parent prefix of the GCC installation. | 
|  | 4047 | // 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] | 4048 | // outside of the system root as that can pick up unintended libraries. | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4049 | // This usually happens when there is an external cross compiler on the | 
|  | 4050 | // 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] | 4051 | // the cross. Note that GCC does include some of these directories in some | 
|  | 4052 | // configurations but this seems somewhere between questionable and simply | 
|  | 4053 | // a bug. | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4054 | if (StringRef(LibPath).startswith(SysRoot)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4055 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); | 
|  | 4056 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4057 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4058 | } | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4059 |  | 
|  | 4060 | // 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] | 4061 | // of the requested system root, add its parent library paths to | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4062 | // those searched. | 
|  | 4063 | // FIXME: It's not clear whether we should use the driver's installed | 
|  | 4064 | // directory ('Dir' below) or the ResourceDir. | 
|  | 4065 | if (StringRef(D.Dir).startswith(SysRoot)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4066 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); | 
|  | 4067 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4068 | } | 
|  | 4069 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4070 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); | 
|  | 4071 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); | 
|  | 4072 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); | 
|  | 4073 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); | 
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 4074 |  | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 4075 | // 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] | 4076 | // installations with strange symlinks. | 
| Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 4077 | if (GCCInstallation.isValid()) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4078 | addPathIfExists(D, | 
|  | 4079 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4080 | "/../../" + OSLibDir, | 
|  | 4081 | Paths); | 
| Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 4082 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4083 | // Add the 'other' biarch variant path | 
|  | 4084 | Multilib BiarchSibling; | 
|  | 4085 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4086 | addPathIfExists(D, GCCInstallation.getInstallPath() + | 
|  | 4087 | BiarchSibling.gccSuffix(), | 
|  | 4088 | Paths); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4089 | } | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 4090 |  | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4091 | // See comments above on the multilib variant for details of why this is | 
|  | 4092 | // included even from outside the sysroot. | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4093 | const std::string &LibPath = GCCInstallation.getParentLibPath(); | 
|  | 4094 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); | 
|  | 4095 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4096 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + | 
|  | 4097 | Multilib.osSuffix(), | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4098 | Paths); | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 4099 |  | 
|  | 4100 | // See comments above on the multilib variant for details of why this is | 
|  | 4101 | // only included from within the sysroot. | 
|  | 4102 | if (StringRef(LibPath).startswith(SysRoot)) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4103 | addPathIfExists(D, LibPath, Paths); | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 4104 | } | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4105 |  | 
|  | 4106 | // Similar to the logic for GCC above, if we are currently running Clang | 
|  | 4107 | // inside of the requested system root, add its parent library path to those | 
|  | 4108 | // searched. | 
|  | 4109 | // FIXME: It's not clear whether we should use the driver's installed | 
|  | 4110 | // directory ('Dir' below) or the ResourceDir. | 
|  | 4111 | if (StringRef(D.Dir).startswith(SysRoot)) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4112 | addPathIfExists(D, D.Dir + "/../lib", Paths); | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 4113 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4114 | addPathIfExists(D, SysRoot + "/lib", Paths); | 
|  | 4115 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 4116 | } | 
|  | 4117 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4118 | bool Linux::HasNativeLLVMSupport() const { return true; } | 
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 4119 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4120 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4121 |  | 
|  | 4122 | Tool *Linux::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4123 | return new tools::gnutools::Assembler(*this); | 
| Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 4124 | } | 
|  | 4125 |  | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 4126 | std::string Linux::computeSysRoot() const { | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4127 | if (!getDriver().SysRoot.empty()) | 
|  | 4128 | return getDriver().SysRoot; | 
|  | 4129 |  | 
|  | 4130 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) | 
|  | 4131 | return std::string(); | 
|  | 4132 |  | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4133 | // Standalone MIPS toolchains use different names for sysroot folder | 
|  | 4134 | // and put it into different places. Here we try to check some known | 
|  | 4135 | // variants. | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4136 |  | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4137 | const StringRef InstallDir = GCCInstallation.getInstallPath(); | 
|  | 4138 | const StringRef TripleStr = GCCInstallation.getTriple().str(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4139 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4140 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4141 | std::string Path = | 
|  | 4142 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) | 
|  | 4143 | .str(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4144 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4145 | if (getVFS().exists(Path)) | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4146 | return Path; | 
|  | 4147 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4148 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4149 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4150 | if (getVFS().exists(Path)) | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 4151 | return Path; | 
|  | 4152 |  | 
|  | 4153 | return std::string(); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4154 | } | 
|  | 4155 |  | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4156 | std::string Linux::getDynamicLinker(const ArgList &Args) const { | 
|  | 4157 | const llvm::Triple::ArchType Arch = getArch(); | 
|  | 4158 | const llvm::Triple &Triple = getTriple(); | 
|  | 4159 |  | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4160 | const enum Distro Distro = DetectDistro(getDriver(), Arch); | 
|  | 4161 |  | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4162 | if (Triple.isAndroid()) | 
|  | 4163 | return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; | 
| Rafael Espindola | 164fe34 | 2016-06-14 12:47:24 +0000 | [diff] [blame] | 4164 | else if (Triple.getEnvironment() == llvm::Triple::Musl) | 
|  | 4165 | return "/lib/ld-musl-" + Triple.getArchName().str() + ".so.1"; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4166 |  | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4167 | std::string LibDir; | 
|  | 4168 | std::string Loader; | 
|  | 4169 |  | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4170 | switch (Arch) { | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4171 | default: | 
|  | 4172 | llvm_unreachable("unsupported architecture"); | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4173 |  | 
|  | 4174 | case llvm::Triple::aarch64: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4175 | LibDir = "lib"; | 
|  | 4176 | Loader = "ld-linux-aarch64.so.1"; | 
|  | 4177 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4178 | case llvm::Triple::aarch64_be: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4179 | LibDir = "lib"; | 
|  | 4180 | Loader = "ld-linux-aarch64_be.so.1"; | 
|  | 4181 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4182 | case llvm::Triple::arm: | 
|  | 4183 | case llvm::Triple::thumb: | 
|  | 4184 | case llvm::Triple::armeb: | 
|  | 4185 | case llvm::Triple::thumbeb: { | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4186 | const bool HF = | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4187 | Triple.getEnvironment() == llvm::Triple::GNUEABIHF || | 
|  | 4188 | tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard; | 
|  | 4189 |  | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4190 | LibDir = "lib"; | 
|  | 4191 | Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3"; | 
|  | 4192 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4193 | } | 
|  | 4194 | case llvm::Triple::mips: | 
|  | 4195 | case llvm::Triple::mipsel: | 
|  | 4196 | case llvm::Triple::mips64: | 
|  | 4197 | case llvm::Triple::mips64el: { | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4198 | bool LE = (Triple.getArch() == llvm::Triple::mipsel) || | 
|  | 4199 | (Triple.getArch() == llvm::Triple::mips64el); | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4200 | bool IsNaN2008 = tools::mips::isNaN2008(Args, Triple); | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4201 |  | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4202 | LibDir = "lib" + tools::mips::getMipsABILibSuffix(Args, Triple); | 
|  | 4203 |  | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4204 | if (tools::mips::isUCLibc(Args)) | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4205 | Loader = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0"; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4206 | else if (!Triple.hasEnvironment() && | 
|  | 4207 | Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies) | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4208 | Loader = LE ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1"; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4209 | else | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4210 | Loader = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1"; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4211 |  | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4212 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4213 | } | 
|  | 4214 | case llvm::Triple::ppc: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4215 | LibDir = "lib"; | 
|  | 4216 | Loader = "ld.so.1"; | 
|  | 4217 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4218 | case llvm::Triple::ppc64: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4219 | LibDir = "lib64"; | 
|  | 4220 | Loader = | 
|  | 4221 | (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2" : "ld64.so.1"; | 
|  | 4222 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4223 | case llvm::Triple::ppc64le: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4224 | LibDir = "lib64"; | 
|  | 4225 | Loader = | 
|  | 4226 | (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2"; | 
|  | 4227 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4228 | case llvm::Triple::sparc: | 
|  | 4229 | case llvm::Triple::sparcel: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4230 | LibDir = "lib"; | 
|  | 4231 | Loader = "ld-linux.so.2"; | 
|  | 4232 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4233 | case llvm::Triple::sparcv9: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4234 | LibDir = "lib64"; | 
|  | 4235 | Loader = "ld-linux.so.2"; | 
|  | 4236 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4237 | case llvm::Triple::systemz: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4238 | LibDir = "lib"; | 
|  | 4239 | Loader = "ld64.so.1"; | 
|  | 4240 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4241 | case llvm::Triple::x86: | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4242 | LibDir = "lib"; | 
|  | 4243 | Loader = "ld-linux.so.2"; | 
|  | 4244 | break; | 
|  | 4245 | case llvm::Triple::x86_64: { | 
|  | 4246 | bool X32 = Triple.getEnvironment() == llvm::Triple::GNUX32; | 
|  | 4247 |  | 
|  | 4248 | LibDir = X32 ? "libx32" : "lib64"; | 
|  | 4249 | Loader = X32 ? "ld-linux-x32.so.2" : "ld-linux-x86-64.so.2"; | 
|  | 4250 | break; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4251 | } | 
| Saleem Abdulrasool | 6f8442b | 2016-05-23 02:17:28 +0000 | [diff] [blame] | 4252 | } | 
|  | 4253 |  | 
|  | 4254 | if (Distro == Exherbo && (Triple.getVendor() == llvm::Triple::UnknownVendor || | 
|  | 4255 | Triple.getVendor() == llvm::Triple::PC)) | 
|  | 4256 | return "/usr/" + Triple.str() + "/lib/" + Loader; | 
|  | 4257 | return "/" + LibDir + "/" + Loader; | 
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 4258 | } | 
|  | 4259 |  | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4260 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4261 | ArgStringList &CC1Args) const { | 
|  | 4262 | const Driver &D = getDriver(); | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 4263 | std::string SysRoot = computeSysRoot(); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4264 |  | 
|  | 4265 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 4266 | return; | 
|  | 4267 |  | 
|  | 4268 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4269 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4270 |  | 
|  | 4271 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 4272 | SmallString<128> P(D.ResourceDir); | 
|  | 4273 | llvm::sys::path::append(P, "include"); | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 4274 | addSystemInclude(DriverArgs, CC1Args, P); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4275 | } | 
|  | 4276 |  | 
|  | 4277 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 4278 | return; | 
|  | 4279 |  | 
|  | 4280 | // Check for configure-time C include directories. | 
|  | 4281 | StringRef CIncludeDirs(C_INCLUDE_DIRS); | 
|  | 4282 | if (CIncludeDirs != "") { | 
|  | 4283 | SmallVector<StringRef, 5> dirs; | 
|  | 4284 | CIncludeDirs.split(dirs, ":"); | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4285 | for (StringRef dir : dirs) { | 
| Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 4286 | StringRef Prefix = | 
|  | 4287 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4288 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4289 | } | 
|  | 4290 | return; | 
|  | 4291 | } | 
|  | 4292 |  | 
|  | 4293 | // Lacking those, try to detect the correct set of system includes for the | 
|  | 4294 | // target triple. | 
|  | 4295 |  | 
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4296 | // Add include directories specific to the selected multilib set and multilib. | 
|  | 4297 | if (GCCInstallation.isValid()) { | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 4298 | const auto &Callback = Multilibs.includeDirsCallback(); | 
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4299 | if (Callback) { | 
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 4300 | for (const auto &Path : Callback(GCCInstallation.getMultilib())) | 
|  | 4301 | addExternCSystemIncludeIfExists( | 
|  | 4302 | DriverArgs, CC1Args, GCCInstallation.getInstallPath() + Path); | 
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 4303 | } | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4304 | } | 
|  | 4305 |  | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4306 | // Implement generic Debian multiarch support. | 
|  | 4307 | const StringRef X86_64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4308 | "/usr/include/x86_64-linux-gnu", | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4309 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4310 | // FIXME: These are older forms of multiarch. It's not clear that they're | 
|  | 4311 | // in use in any released version of Debian, so we should consider | 
|  | 4312 | // removing them. | 
|  | 4313 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4314 | const StringRef X86MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4315 | "/usr/include/i386-linux-gnu", | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4316 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4317 | // FIXME: These are older forms of multiarch. It's not clear that they're | 
|  | 4318 | // in use in any released version of Debian, so we should consider | 
|  | 4319 | // removing them. | 
|  | 4320 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", | 
|  | 4321 | "/usr/include/i486-linux-gnu"}; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4322 | const StringRef AArch64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4323 | "/usr/include/aarch64-linux-gnu"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4324 | const StringRef ARMMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4325 | "/usr/include/arm-linux-gnueabi"}; | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4326 | const StringRef ARMHFMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4327 | "/usr/include/arm-linux-gnueabihf"}; | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4328 | const StringRef ARMEBMultiarchIncludeDirs[] = { | 
|  | 4329 | "/usr/include/armeb-linux-gnueabi"}; | 
|  | 4330 | const StringRef ARMEBHFMultiarchIncludeDirs[] = { | 
|  | 4331 | "/usr/include/armeb-linux-gnueabihf"}; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4332 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4333 | const StringRef MIPSELMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4334 | "/usr/include/mipsel-linux-gnu"}; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4335 | const StringRef MIPS64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4336 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4337 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4338 | "/usr/include/mips64el-linux-gnu", | 
|  | 4339 | "/usr/include/mips64el-linux-gnuabi64"}; | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4340 | const StringRef PPCMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4341 | "/usr/include/powerpc-linux-gnu"}; | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4342 | const StringRef PPC64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4343 | "/usr/include/powerpc64-linux-gnu"}; | 
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4344 | const StringRef PPC64LEMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4345 | "/usr/include/powerpc64le-linux-gnu"}; | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4346 | const StringRef SparcMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4347 | "/usr/include/sparc-linux-gnu"}; | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4348 | const StringRef Sparc64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4349 | "/usr/include/sparc64-linux-gnu"}; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4350 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { | 
|  | 4351 | "/usr/include/s390x-linux-gnu"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4352 | ArrayRef<StringRef> MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4353 | switch (getTriple().getArch()) { | 
|  | 4354 | case llvm::Triple::x86_64: | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4355 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4356 | break; | 
|  | 4357 | case llvm::Triple::x86: | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4358 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4359 | break; | 
|  | 4360 | case llvm::Triple::aarch64: | 
|  | 4361 | case llvm::Triple::aarch64_be: | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4362 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4363 | break; | 
|  | 4364 | case llvm::Triple::arm: | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4365 | case llvm::Triple::thumb: | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4366 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) | 
|  | 4367 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; | 
|  | 4368 | else | 
|  | 4369 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4370 | break; | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4371 | case llvm::Triple::armeb: | 
|  | 4372 | case llvm::Triple::thumbeb: | 
|  | 4373 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) | 
|  | 4374 | MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs; | 
|  | 4375 | else | 
|  | 4376 | MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs; | 
|  | 4377 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4378 | case llvm::Triple::mips: | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4379 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4380 | break; | 
|  | 4381 | case llvm::Triple::mipsel: | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4382 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4383 | break; | 
|  | 4384 | case llvm::Triple::mips64: | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4385 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4386 | break; | 
|  | 4387 | case llvm::Triple::mips64el: | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4388 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4389 | break; | 
|  | 4390 | case llvm::Triple::ppc: | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4391 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4392 | break; | 
|  | 4393 | case llvm::Triple::ppc64: | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4394 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4395 | break; | 
|  | 4396 | case llvm::Triple::ppc64le: | 
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4397 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4398 | break; | 
|  | 4399 | case llvm::Triple::sparc: | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4400 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4401 | break; | 
|  | 4402 | case llvm::Triple::sparcv9: | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4403 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4404 | break; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4405 | case llvm::Triple::systemz: | 
|  | 4406 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; | 
|  | 4407 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4408 | default: | 
|  | 4409 | break; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4410 | } | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4411 | for (StringRef Dir : MultiarchIncludeDirs) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4412 | if (D.getVFS().exists(SysRoot + Dir)) { | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4413 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4414 | break; | 
|  | 4415 | } | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4416 | } | 
|  | 4417 |  | 
|  | 4418 | if (getTriple().getOS() == llvm::Triple::RTEMS) | 
|  | 4419 | return; | 
|  | 4420 |  | 
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4421 | // Add an include of '/include' directly. This isn't provided by default by | 
|  | 4422 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to | 
|  | 4423 | // 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] | 4424 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); | 
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4425 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4426 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4427 | } | 
|  | 4428 |  | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4429 | static std::string DetectLibcxxIncludePath(StringRef base) { | 
|  | 4430 | std::error_code EC; | 
|  | 4431 | int MaxVersion = 0; | 
|  | 4432 | std::string MaxVersionString = ""; | 
|  | 4433 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; | 
|  | 4434 | LI = LI.increment(EC)) { | 
|  | 4435 | StringRef VersionText = llvm::sys::path::filename(LI->path()); | 
|  | 4436 | int Version; | 
|  | 4437 | if (VersionText[0] == 'v' && | 
|  | 4438 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { | 
|  | 4439 | if (Version > MaxVersion) { | 
|  | 4440 | MaxVersion = Version; | 
|  | 4441 | MaxVersionString = VersionText; | 
|  | 4442 | } | 
|  | 4443 | } | 
|  | 4444 | } | 
|  | 4445 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; | 
|  | 4446 | } | 
|  | 4447 |  | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4448 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 4449 | ArgStringList &CC1Args) const { | 
|  | 4450 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4451 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4452 | return; | 
|  | 4453 |  | 
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4454 | // Check if libc++ has been enabled and provide its include paths if so. | 
|  | 4455 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4456 | const std::string LibCXXIncludePathCandidates[] = { | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4457 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), | 
| Yaron Keren | 5439b64 | 2016-05-17 19:01:16 +0000 | [diff] [blame] | 4458 | // If this is a development, non-installed, clang, libcxx will | 
|  | 4459 | // not be found at ../include/c++ but it likely to be found at | 
|  | 4460 | // one of the following two locations: | 
|  | 4461 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/local/include/c++"), | 
|  | 4462 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++") }; | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4463 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4464 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4465 | continue; | 
|  | 4466 | // Add the first candidate that exists. | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4467 | addSystemInclude(DriverArgs, CC1Args, IncludePath); | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4468 | break; | 
|  | 4469 | } | 
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4470 | return; | 
|  | 4471 | } | 
|  | 4472 |  | 
| Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 4473 | // We need a detected GCC installation on Linux to provide libstdc++'s | 
|  | 4474 | // headers. We handled the libc++ case above. | 
|  | 4475 | if (!GCCInstallation.isValid()) | 
|  | 4476 | return; | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4477 |  | 
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4478 | // By default, look for the C++ headers in an include directory adjacent to | 
|  | 4479 | // the lib directory of the GCC installation. Note that this is expect to be | 
|  | 4480 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. | 
|  | 4481 | StringRef LibDir = GCCInstallation.getParentLibPath(); | 
|  | 4482 | StringRef InstallDir = GCCInstallation.getInstallPath(); | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4483 | StringRef TripleStr = GCCInstallation.getTriple().str(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4484 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4485 | const std::string GCCMultiarchTriple = getMultiarchTriple( | 
|  | 4486 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4487 | const std::string TargetMultiarchTriple = | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4488 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 4489 | const GCCVersion &Version = GCCInstallation.getVersion(); | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4490 |  | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4491 | // The primary search for libstdc++ supports multiarch variants. | 
| Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 4492 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4493 | "/c++/" + Version.Text, TripleStr, | 
|  | 4494 | GCCMultiarchTriple, TargetMultiarchTriple, | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4495 | Multilib.includeSuffix(), DriverArgs, CC1Args)) | 
| Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4496 | return; | 
|  | 4497 |  | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4498 | // Otherwise, fall back on a bunch of options which don't use multiarch | 
|  | 4499 | // layouts for simplicity. | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4500 | const std::string LibStdCXXIncludePathCandidates[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4501 | // Gentoo is weird and places its headers inside the GCC install, | 
|  | 4502 | // 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] | 4503 | InstallDir.str() + "/include/g++-v" + Version.Text, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4504 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + | 
|  | 4505 | Version.MinorStr, | 
|  | 4506 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, | 
|  | 4507 | // Android standalone toolchain has C++ headers in yet another place. | 
|  | 4508 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, | 
|  | 4509 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, | 
|  | 4510 | // without a subdirectory corresponding to the gcc version. | 
|  | 4511 | LibDir.str() + "/../include/c++", | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4512 | }; | 
|  | 4513 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4514 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4515 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, | 
|  | 4516 | /*GCCMultiarchTriple*/ "", | 
|  | 4517 | /*TargetMultiarchTriple*/ "", | 
|  | 4518 | Multilib.includeSuffix(), DriverArgs, CC1Args)) | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4519 | break; | 
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4520 | } | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4521 | } | 
|  | 4522 |  | 
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4523 | void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, | 
|  | 4524 | ArgStringList &CC1Args) const { | 
|  | 4525 | if (DriverArgs.hasArg(options::OPT_nocudainc)) | 
|  | 4526 | return; | 
|  | 4527 |  | 
| Justin Lebar | 423019d | 2016-04-16 00:11:11 +0000 | [diff] [blame] | 4528 | if (!CudaInstallation.isValid()) { | 
|  | 4529 | getDriver().Diag(diag::err_drv_no_cuda_installation); | 
|  | 4530 | return; | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4531 | } | 
| Justin Lebar | 423019d | 2016-04-16 00:11:11 +0000 | [diff] [blame] | 4532 |  | 
|  | 4533 | addSystemInclude(DriverArgs, CC1Args, CudaInstallation.getIncludePath()); | 
|  | 4534 | CC1Args.push_back("-include"); | 
|  | 4535 | CC1Args.push_back("__clang_cuda_runtime_wrapper.h"); | 
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4536 | } | 
|  | 4537 |  | 
| Andrey Turetskiy | 4798eb6 | 2016-06-16 10:36:09 +0000 | [diff] [blame] | 4538 | void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs, | 
|  | 4539 | ArgStringList &CC1Args) const { | 
|  | 4540 | if (GCCInstallation.isValid()) { | 
|  | 4541 | CC1Args.push_back("-isystem"); | 
|  | 4542 | CC1Args.push_back(DriverArgs.MakeArgString( | 
|  | 4543 | GCCInstallation.getParentLibPath() + "/../" + | 
|  | 4544 | GCCInstallation.getTriple().str() + "/include")); | 
|  | 4545 | } | 
|  | 4546 | } | 
|  | 4547 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4548 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 4549 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4550 | SanitizerMask Linux::getSupportedSanitizers() const { | 
|  | 4551 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; | 
|  | 4552 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; | 
|  | 4553 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || | 
|  | 4554 | getTriple().getArch() == llvm::Triple::mips64el; | 
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4555 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || | 
|  | 4556 | getTriple().getArch() == llvm::Triple::ppc64le; | 
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4557 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || | 
|  | 4558 | getTriple().getArch() == llvm::Triple::aarch64_be; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4559 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 4560 | Res |= SanitizerKind::Address; | 
|  | 4561 | Res |= SanitizerKind::KernelAddress; | 
|  | 4562 | Res |= SanitizerKind::Vptr; | 
| Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 4563 | Res |= SanitizerKind::SafeStack; | 
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4564 | if (IsX86_64 || IsMIPS64 || IsAArch64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4565 | Res |= SanitizerKind::DataFlow; | 
| Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 4566 | if (IsX86_64 || IsMIPS64 || IsAArch64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4567 | Res |= SanitizerKind::Leak; | 
| Bill Schmidt | 4b8841a | 2015-12-08 22:48:02 +0000 | [diff] [blame] | 4568 | if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4569 | Res |= SanitizerKind::Thread; | 
| Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 4570 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) | 
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4571 | Res |= SanitizerKind::Memory; | 
| Derek Bruening | 256c2e1 | 2016-04-21 21:32:04 +0000 | [diff] [blame] | 4572 | if (IsX86_64) | 
|  | 4573 | Res |= SanitizerKind::Efficiency; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4574 | if (IsX86 || IsX86_64) { | 
|  | 4575 | Res |= SanitizerKind::Function; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4576 | } | 
|  | 4577 | return Res; | 
|  | 4578 | } | 
|  | 4579 |  | 
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4580 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, | 
|  | 4581 | llvm::opt::ArgStringList &CmdArgs) const { | 
|  | 4582 | if (!needsProfileRT(Args)) return; | 
|  | 4583 |  | 
|  | 4584 | // Add linker option -u__llvm_runtime_variable to cause runtime | 
|  | 4585 | // initialization module to be linked in. | 
|  | 4586 | if (!Args.hasArg(options::OPT_coverage)) | 
|  | 4587 | CmdArgs.push_back(Args.MakeArgString( | 
|  | 4588 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); | 
|  | 4589 | ToolChain::addProfileRTLibs(Args, CmdArgs); | 
|  | 4590 | } | 
|  | 4591 |  | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4592 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. | 
|  | 4593 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4594 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, | 
|  | 4595 | const ArgList &Args) | 
|  | 4596 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4597 |  | 
|  | 4598 | // Path mangling to find libexec | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4599 | getProgramPaths().push_back(getDriver().getInstalledDir()); | 
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 4600 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4601 | getProgramPaths().push_back(getDriver().Dir); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4602 |  | 
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4603 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4604 | getFilePaths().push_back("/usr/lib"); | 
| Dimitry Andric | f59a2b3 | 2015-12-27 10:01:44 +0000 | [diff] [blame] | 4605 | getFilePaths().push_back("/usr/lib/gcc50"); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4606 | } | 
|  | 4607 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4608 | Tool *DragonFly::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4609 | return new tools::dragonfly::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4610 | } | 
|  | 4611 |  | 
|  | 4612 | Tool *DragonFly::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4613 | return new tools::dragonfly::Linker(*this); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4614 | } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4615 |  | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4616 | /// CUDA toolchain.  Our assembler is ptxas, and our "linker" is fatbinary, | 
|  | 4617 | /// which isn't properly a linker but nonetheless performs the step of stitching | 
|  | 4618 | /// together object files from the assembler into a single blob. | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4619 |  | 
|  | 4620 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4621 | const ArgList &Args) | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4622 | : Linux(D, Triple, Args) { | 
|  | 4623 | if (CudaInstallation.isValid()) | 
|  | 4624 | getProgramPaths().push_back(CudaInstallation.getBinPath()); | 
|  | 4625 | } | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4626 |  | 
|  | 4627 | void | 
|  | 4628 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, | 
|  | 4629 | llvm::opt::ArgStringList &CC1Args) const { | 
|  | 4630 | Linux::addClangTargetOptions(DriverArgs, CC1Args); | 
|  | 4631 | CC1Args.push_back("-fcuda-is-device"); | 
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4632 |  | 
| Justin Lebar | d3a44f6 | 2016-04-05 18:26:20 +0000 | [diff] [blame] | 4633 | if (DriverArgs.hasFlag(options::OPT_fcuda_flush_denormals_to_zero, | 
|  | 4634 | options::OPT_fno_cuda_flush_denormals_to_zero, false)) | 
|  | 4635 | CC1Args.push_back("-fcuda-flush-denormals-to-zero"); | 
|  | 4636 |  | 
| Justin Lebar | 91f6f07 | 2016-05-23 20:19:56 +0000 | [diff] [blame] | 4637 | if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals, | 
|  | 4638 | options::OPT_fno_cuda_approx_transcendentals, false)) | 
|  | 4639 | CC1Args.push_back("-fcuda-approx-transcendentals"); | 
|  | 4640 |  | 
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4641 | if (DriverArgs.hasArg(options::OPT_nocudalib)) | 
|  | 4642 | return; | 
|  | 4643 |  | 
|  | 4644 | std::string LibDeviceFile = CudaInstallation.getLibDeviceFile( | 
|  | 4645 | DriverArgs.getLastArgValue(options::OPT_march_EQ)); | 
|  | 4646 | if (!LibDeviceFile.empty()) { | 
|  | 4647 | CC1Args.push_back("-mlink-cuda-bitcode"); | 
|  | 4648 | CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile)); | 
|  | 4649 |  | 
|  | 4650 | // Libdevice in CUDA-7.0 requires PTX version that's more recent | 
|  | 4651 | // than LLVM defaults to. Use PTX4.2 which is the PTX version that | 
|  | 4652 | // came with CUDA-7.0. | 
|  | 4653 | CC1Args.push_back("-target-feature"); | 
|  | 4654 | CC1Args.push_back("+ptx42"); | 
|  | 4655 | } | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4656 | } | 
|  | 4657 |  | 
|  | 4658 | llvm::opt::DerivedArgList * | 
|  | 4659 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, | 
|  | 4660 | const char *BoundArch) const { | 
|  | 4661 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); | 
|  | 4662 | const OptTable &Opts = getDriver().getOpts(); | 
|  | 4663 |  | 
|  | 4664 | for (Arg *A : Args) { | 
|  | 4665 | if (A->getOption().matches(options::OPT_Xarch__)) { | 
|  | 4666 | // Skip this argument unless the architecture matches BoundArch | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4667 | if (!BoundArch || A->getValue(0) != StringRef(BoundArch)) | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4668 | continue; | 
|  | 4669 |  | 
|  | 4670 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); | 
|  | 4671 | unsigned Prev = Index; | 
|  | 4672 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); | 
|  | 4673 |  | 
|  | 4674 | // If the argument parsing failed or more than one argument was | 
|  | 4675 | // consumed, the -Xarch_ argument's parameter tried to consume | 
|  | 4676 | // extra arguments. Emit an error and ignore. | 
|  | 4677 | // | 
|  | 4678 | // We also want to disallow any options which would alter the | 
|  | 4679 | // driver behavior; that isn't going to work in our model. We | 
|  | 4680 | // use isDriverOption() as an approximation, although things | 
|  | 4681 | // like -O4 are going to slip through. | 
|  | 4682 | if (!XarchArg || Index > Prev + 1) { | 
|  | 4683 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) | 
|  | 4684 | << A->getAsString(Args); | 
|  | 4685 | continue; | 
|  | 4686 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { | 
|  | 4687 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) | 
|  | 4688 | << A->getAsString(Args); | 
|  | 4689 | continue; | 
|  | 4690 | } | 
|  | 4691 | XarchArg->setBaseArg(A); | 
|  | 4692 | A = XarchArg.release(); | 
|  | 4693 | DAL->AddSynthesizedArg(A); | 
|  | 4694 | } | 
|  | 4695 | DAL->append(A); | 
|  | 4696 | } | 
|  | 4697 |  | 
| Justin Lebar | 4db224e | 2016-06-15 23:46:11 +0000 | [diff] [blame] | 4698 | if (BoundArch) { | 
|  | 4699 | DAL->eraseArg(options::OPT_march_EQ); | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4700 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); | 
| Justin Lebar | 4db224e | 2016-06-15 23:46:11 +0000 | [diff] [blame] | 4701 | } | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4702 | return DAL; | 
|  | 4703 | } | 
|  | 4704 |  | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4705 | Tool *CudaToolChain::buildAssembler() const { | 
|  | 4706 | return new tools::NVPTX::Assembler(*this); | 
|  | 4707 | } | 
|  | 4708 |  | 
|  | 4709 | Tool *CudaToolChain::buildLinker() const { | 
|  | 4710 | return new tools::NVPTX::Linker(*this); | 
|  | 4711 | } | 
|  | 4712 |  | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4713 | /// XCore tool chain | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4714 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4715 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4716 | : ToolChain(D, Triple, Args) { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4717 | // ProgramPaths are found via 'PATH' environment variable. | 
|  | 4718 | } | 
|  | 4719 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4720 | Tool *XCoreToolChain::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4721 | return new tools::XCore::Assembler(*this); | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4722 | } | 
|  | 4723 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4724 | Tool *XCoreToolChain::buildLinker() const { | 
|  | 4725 | return new tools::XCore::Linker(*this); | 
|  | 4726 | } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4727 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4728 | bool XCoreToolChain::isPICDefault() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4729 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4730 | bool XCoreToolChain::isPIEDefault() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4731 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4732 | bool XCoreToolChain::isPICDefaultForced() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4733 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4734 | bool XCoreToolChain::SupportsProfiling() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4735 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4736 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4737 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4738 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4739 | ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4740 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
|  | 4741 | DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 4742 | return; | 
|  | 4743 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { | 
|  | 4744 | SmallVector<StringRef, 4> Dirs; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4745 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4746 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); | 
|  | 4747 | ArrayRef<StringRef> DirVec(Dirs); | 
|  | 4748 | addSystemIncludes(DriverArgs, CC1Args, DirVec); | 
|  | 4749 | } | 
|  | 4750 | } | 
|  | 4751 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4752 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 4753 | ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4754 | CC1Args.push_back("-nostdsysteminc"); | 
|  | 4755 | } | 
|  | 4756 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4757 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 4758 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4759 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
| Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 4760 | DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4761 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4762 | return; | 
|  | 4763 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { | 
|  | 4764 | SmallVector<StringRef, 4> Dirs; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4765 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4766 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); | 
|  | 4767 | ArrayRef<StringRef> DirVec(Dirs); | 
|  | 4768 | addSystemIncludes(DriverArgs, CC1Args, DirVec); | 
|  | 4769 | } | 
|  | 4770 | } | 
|  | 4771 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4772 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 4773 | ArgStringList &CmdArgs) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4774 | // We don't output any lib args. This is handled by xcc. | 
|  | 4775 | } | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4776 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4777 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4778 | const ArgList &Args) | 
| Douglas Katzman | 5eddc23 | 2016-05-09 19:09:59 +0000 | [diff] [blame] | 4779 | : Generic_ELF(D, Triple, Args) { | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4780 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use | 
|  | 4781 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. | 
|  | 4782 | // This won't work to find gcc. Instead we give the installation detector an | 
|  | 4783 | // extra triple, which is preferable to further hacks of the logic that at | 
|  | 4784 | // present is based solely on getArch(). In particular, it would be wrong to | 
|  | 4785 | // choose the myriad installation when targeting a non-myriad sparc install. | 
|  | 4786 | switch (Triple.getArch()) { | 
|  | 4787 | default: | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4788 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() | 
|  | 4789 | << "myriad"; | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4790 | case llvm::Triple::sparc: | 
|  | 4791 | case llvm::Triple::sparcel: | 
|  | 4792 | case llvm::Triple::shave: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4793 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4794 | } | 
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 4795 |  | 
|  | 4796 | if (GCCInstallation.isValid()) { | 
|  | 4797 | // The contents of LibDir are independent of the version of gcc. | 
|  | 4798 | // This contains libc, libg (a superset of libc), libm, libstdc++, libssp. | 
|  | 4799 | SmallString<128> LibDir(GCCInstallation.getParentLibPath()); | 
|  | 4800 | if (Triple.getArch() == llvm::Triple::sparcel) | 
|  | 4801 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib/le"); | 
|  | 4802 | else | 
|  | 4803 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib"); | 
|  | 4804 | addPathIfExists(D, LibDir, getFilePaths()); | 
|  | 4805 |  | 
|  | 4806 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. | 
|  | 4807 | // These files are tied to a particular version of gcc. | 
|  | 4808 | SmallString<128> CompilerSupportDir(GCCInstallation.getInstallPath()); | 
|  | 4809 | // There are actually 4 choices: {le,be} x {fpu,nofpu} | 
|  | 4810 | // but as this toolchain is for LEON sparc, it can assume FPU. | 
|  | 4811 | if (Triple.getArch() == llvm::Triple::sparcel) | 
|  | 4812 | llvm::sys::path::append(CompilerSupportDir, "le"); | 
|  | 4813 | addPathIfExists(D, CompilerSupportDir, getFilePaths()); | 
|  | 4814 | } | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4815 | } | 
|  | 4816 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4817 | MyriadToolChain::~MyriadToolChain() {} | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4818 |  | 
| Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 4819 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4820 | ArgStringList &CC1Args) const { | 
|  | 4821 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 4822 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); | 
|  | 4823 | } | 
|  | 4824 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4825 | void MyriadToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 4826 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4827 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4828 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4829 | return; | 
|  | 4830 |  | 
|  | 4831 | // Only libstdc++, for now. | 
|  | 4832 | StringRef LibDir = GCCInstallation.getParentLibPath(); | 
|  | 4833 | const GCCVersion &Version = GCCInstallation.getVersion(); | 
|  | 4834 | StringRef TripleStr = GCCInstallation.getTriple().str(); | 
|  | 4835 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
|  | 4836 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4837 | addLibStdCXXIncludePaths( | 
|  | 4838 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, | 
|  | 4839 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4840 | } | 
|  | 4841 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4842 | // MyriadToolChain handles several triples: | 
|  | 4843 | //  {shave,sparc{,el}}-myriad-{rtems,unknown}-elf | 
|  | 4844 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { | 
|  | 4845 | // The inherited method works fine if not targeting the SHAVE. | 
|  | 4846 | if (!isShaveCompilation(getTriple())) | 
|  | 4847 | return ToolChain::SelectTool(JA); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4848 | switch (JA.getKind()) { | 
| Douglas Katzman | 9dc4c62 | 2015-11-20 04:58:12 +0000 | [diff] [blame] | 4849 | case Action::PreprocessJobClass: | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4850 | case Action::CompileJobClass: | 
|  | 4851 | if (!Compiler) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4852 | Compiler.reset(new tools::SHAVE::Compiler(*this)); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4853 | return Compiler.get(); | 
|  | 4854 | case Action::AssembleJobClass: | 
|  | 4855 | if (!Assembler) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4856 | Assembler.reset(new tools::SHAVE::Assembler(*this)); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4857 | return Assembler.get(); | 
|  | 4858 | default: | 
|  | 4859 | return ToolChain::getTool(JA.getKind()); | 
|  | 4860 | } | 
|  | 4861 | } | 
|  | 4862 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4863 | Tool *MyriadToolChain::buildLinker() const { | 
|  | 4864 | return new tools::Myriad::Linker(*this); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4865 | } | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4866 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4867 | WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple, | 
|  | 4868 | const llvm::opt::ArgList &Args) | 
|  | 4869 | : ToolChain(D, Triple, Args) { | 
| Dan Gohman | 57b62c5 | 2016-02-22 19:26:15 +0000 | [diff] [blame] | 4870 |  | 
|  | 4871 | assert(Triple.isArch32Bit() != Triple.isArch64Bit()); | 
|  | 4872 | getFilePaths().push_back( | 
|  | 4873 | getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64")); | 
|  | 4874 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4875 | // Use LLD by default. | 
|  | 4876 | DefaultLinker = "lld"; | 
|  | 4877 | } | 
|  | 4878 |  | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4879 | bool WebAssembly::IsMathErrnoDefault() const { return false; } | 
|  | 4880 |  | 
|  | 4881 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } | 
|  | 4882 |  | 
|  | 4883 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } | 
|  | 4884 |  | 
|  | 4885 | bool WebAssembly::isPICDefault() const { return false; } | 
|  | 4886 |  | 
|  | 4887 | bool WebAssembly::isPIEDefault() const { return false; } | 
|  | 4888 |  | 
|  | 4889 | bool WebAssembly::isPICDefaultForced() const { return false; } | 
|  | 4890 |  | 
|  | 4891 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } | 
|  | 4892 |  | 
|  | 4893 | // TODO: Support Objective C stuff. | 
|  | 4894 | bool WebAssembly::SupportsObjCGC() const { return false; } | 
|  | 4895 |  | 
|  | 4896 | bool WebAssembly::hasBlocksRuntime() const { return false; } | 
|  | 4897 |  | 
|  | 4898 | // TODO: Support profiling. | 
|  | 4899 | bool WebAssembly::SupportsProfiling() const { return false; } | 
|  | 4900 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4901 | bool WebAssembly::HasNativeLLVMSupport() const { return true; } | 
|  | 4902 |  | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4903 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 4904 | ArgStringList &CC1Args) const { | 
|  | 4905 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, | 
|  | 4906 | options::OPT_fno_use_init_array, true)) | 
|  | 4907 | CC1Args.push_back("-fuse-init-array"); | 
|  | 4908 | } | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4909 |  | 
| Dan Gohman | 6ad8f61 | 2016-01-14 16:00:13 +0000 | [diff] [blame] | 4910 | ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const { | 
|  | 4911 | return ToolChain::RLT_CompilerRT; | 
|  | 4912 | } | 
|  | 4913 |  | 
|  | 4914 | ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { | 
|  | 4915 | return ToolChain::CST_Libcxx; | 
|  | 4916 | } | 
|  | 4917 |  | 
|  | 4918 | void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4919 | ArgStringList &CC1Args) const { | 
|  | 4920 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 4921 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); | 
|  | 4922 | } | 
|  | 4923 |  | 
|  | 4924 | void WebAssembly::AddClangCXXStdlibIncludeArgs( | 
|  | 4925 | const llvm::opt::ArgList &DriverArgs, | 
|  | 4926 | llvm::opt::ArgStringList &CC1Args) const { | 
|  | 4927 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc) && | 
|  | 4928 | !DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4929 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 4930 | getDriver().SysRoot + "/include/c++/v1"); | 
|  | 4931 | } | 
|  | 4932 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4933 | Tool *WebAssembly::buildLinker() const { | 
|  | 4934 | return new tools::wasm::Linker(*this); | 
|  | 4935 | } | 
|  | 4936 |  | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4937 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 4938 | : Generic_ELF(D, Triple, Args) { | 
|  | 4939 | if (Args.hasArg(options::OPT_static)) | 
|  | 4940 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; | 
|  | 4941 |  | 
| Paul Robinson | 9d61361 | 2016-05-16 17:22:25 +0000 | [diff] [blame] | 4942 | // 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] | 4943 | // if it exists; otherwise use the driver's installation path, which | 
|  | 4944 | // should be <SDK_DIR>/host_tools/bin. | 
|  | 4945 |  | 
|  | 4946 | SmallString<512> PS4SDKDir; | 
| Paul Robinson | 9d61361 | 2016-05-16 17:22:25 +0000 | [diff] [blame] | 4947 | if (const char *EnvValue = getenv("SCE_ORBIS_SDK_DIR")) { | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4948 | if (!llvm::sys::fs::exists(EnvValue)) | 
|  | 4949 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; | 
|  | 4950 | PS4SDKDir = EnvValue; | 
|  | 4951 | } else { | 
|  | 4952 | PS4SDKDir = getDriver().Dir; | 
|  | 4953 | llvm::sys::path::append(PS4SDKDir, "/../../"); | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4954 | } | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4955 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4956 | // 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] | 4957 | // PS4's include or lib directories. This behavior could be changed if | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4958 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4959 | // If -isysroot was passed, use that as the SDK base path. | 
|  | 4960 | std::string PrefixDir; | 
|  | 4961 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
|  | 4962 | PrefixDir = A->getValue(); | 
|  | 4963 | if (!llvm::sys::fs::exists(PrefixDir)) | 
|  | 4964 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; | 
|  | 4965 | } else | 
|  | 4966 | PrefixDir = PS4SDKDir.str(); | 
|  | 4967 |  | 
|  | 4968 | SmallString<512> PS4SDKIncludeDir(PrefixDir); | 
|  | 4969 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); | 
|  | 4970 | if (!Args.hasArg(options::OPT_nostdinc) && | 
|  | 4971 | !Args.hasArg(options::OPT_nostdlibinc) && | 
|  | 4972 | !Args.hasArg(options::OPT_isysroot) && | 
|  | 4973 | !Args.hasArg(options::OPT__sysroot_EQ) && | 
|  | 4974 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { | 
|  | 4975 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) | 
|  | 4976 | << "PS4 system headers" << PS4SDKIncludeDir; | 
|  | 4977 | } | 
|  | 4978 |  | 
|  | 4979 | SmallString<512> PS4SDKLibDir(PS4SDKDir); | 
|  | 4980 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); | 
|  | 4981 | if (!Args.hasArg(options::OPT_nostdlib) && | 
|  | 4982 | !Args.hasArg(options::OPT_nodefaultlibs) && | 
|  | 4983 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && | 
|  | 4984 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && | 
|  | 4985 | !Args.hasArg(options::OPT_emit_ast) && | 
|  | 4986 | !llvm::sys::fs::exists(PS4SDKLibDir)) { | 
|  | 4987 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) | 
|  | 4988 | << "PS4 system libraries" << PS4SDKLibDir; | 
|  | 4989 | return; | 
|  | 4990 | } | 
|  | 4991 | getFilePaths().push_back(PS4SDKLibDir.str()); | 
|  | 4992 | } | 
|  | 4993 |  | 
|  | 4994 | Tool *PS4CPU::buildAssembler() const { | 
|  | 4995 | return new tools::PS4cpu::Assemble(*this); | 
|  | 4996 | } | 
|  | 4997 |  | 
|  | 4998 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } | 
|  | 4999 |  | 
|  | 5000 | bool PS4CPU::isPICDefault() const { return true; } | 
|  | 5001 |  | 
|  | 5002 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } | 
|  | 5003 |  | 
|  | 5004 | SanitizerMask PS4CPU::getSupportedSanitizers() const { | 
|  | 5005 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 5006 | Res |= SanitizerKind::Address; | 
|  | 5007 | Res |= SanitizerKind::Vptr; | 
|  | 5008 | return Res; | 
|  | 5009 | } |