| 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 |  | 
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 332 | StringRef Darwin::getOSLibraryNameSuffix() const { | 
|  | 333 | switch(TargetPlatform) { | 
|  | 334 | case DarwinPlatformKind::MacOS: | 
|  | 335 | return "osx"; | 
|  | 336 | case DarwinPlatformKind::IPhoneOS: | 
|  | 337 | return "ios"; | 
|  | 338 | case DarwinPlatformKind::IPhoneOSSimulator: | 
|  | 339 | return "iossim"; | 
|  | 340 | case DarwinPlatformKind::TvOS: | 
|  | 341 | return "tvos"; | 
|  | 342 | case DarwinPlatformKind::TvOSSimulator: | 
|  | 343 | return "tvossim"; | 
|  | 344 | case DarwinPlatformKind::WatchOS: | 
|  | 345 | return "watchos"; | 
|  | 346 | case DarwinPlatformKind::WatchOSSimulator: | 
|  | 347 | return "watchossim"; | 
|  | 348 | } | 
|  | 349 | llvm_unreachable("Unsupported platform"); | 
|  | 350 | } | 
|  | 351 |  | 
| Justin Bogner | 2fd95f6 | 2015-05-12 06:30:48 +0000 | [diff] [blame] | 352 | void Darwin::addProfileRTLibs(const ArgList &Args, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 353 | ArgStringList &CmdArgs) const { | 
| Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 354 | if (!needsProfileRT(Args)) return; | 
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 355 |  | 
| Chris Bieneman | 586d24b | 2015-11-20 00:19:21 +0000 | [diff] [blame] | 356 | // TODO: Clean this up once autoconf is gone | 
|  | 357 | SmallString<128> P(getDriver().ResourceDir); | 
|  | 358 | llvm::sys::path::append(P, "lib", "darwin"); | 
|  | 359 | const char *Library = "libclang_rt.profile_osx.a"; | 
|  | 360 |  | 
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 361 | // Select the appropriate runtime library for the target. | 
| Chris Bieneman | 586d24b | 2015-11-20 00:19:21 +0000 | [diff] [blame] | 362 | if (isTargetWatchOS()) { | 
|  | 363 | Library = "libclang_rt.profile_watchos.a"; | 
|  | 364 | } else if (isTargetWatchOSSimulator()) { | 
|  | 365 | llvm::sys::path::append(P, "libclang_rt.profile_watchossim.a"); | 
|  | 366 | Library = getVFS().exists(P) ? "libclang_rt.profile_watchossim.a" | 
|  | 367 | : "libclang_rt.profile_watchos.a"; | 
|  | 368 | } else if (isTargetTvOS()) { | 
|  | 369 | Library = "libclang_rt.profile_tvos.a"; | 
|  | 370 | } else if (isTargetTvOSSimulator()) { | 
|  | 371 | llvm::sys::path::append(P, "libclang_rt.profile_tvossim.a"); | 
|  | 372 | Library = getVFS().exists(P) ? "libclang_rt.profile_tvossim.a" | 
|  | 373 | : "libclang_rt.profile_tvos.a"; | 
|  | 374 | } else if (isTargetIPhoneOS()) { | 
|  | 375 | Library = "libclang_rt.profile_ios.a"; | 
|  | 376 | } else if (isTargetIOSSimulator()) { | 
|  | 377 | llvm::sys::path::append(P, "libclang_rt.profile_iossim.a"); | 
|  | 378 | Library = getVFS().exists(P) ? "libclang_rt.profile_iossim.a" | 
|  | 379 | : "libclang_rt.profile_ios.a"; | 
| Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame] | 380 | } else { | 
|  | 381 | assert(isTargetMacOS() && "unexpected non MacOS platform"); | 
| Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame] | 382 | } | 
| Chris Bieneman | 586d24b | 2015-11-20 00:19:21 +0000 | [diff] [blame] | 383 | AddLinkRuntimeLib(Args, CmdArgs, Library, | 
|  | 384 | /*AlwaysLink*/ true); | 
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 385 | } | 
|  | 386 |  | 
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 387 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, | 
|  | 388 | ArgStringList &CmdArgs, | 
|  | 389 | StringRef Sanitizer) const { | 
|  | 390 | if (!Args.hasArg(options::OPT_dynamiclib) && | 
|  | 391 | !Args.hasArg(options::OPT_bundle)) { | 
|  | 392 | // Sanitizer runtime libraries requires C++. | 
|  | 393 | AddCXXStdlibLibArgs(Args, CmdArgs); | 
|  | 394 | } | 
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 395 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 396 | AddLinkRuntimeLib( | 
|  | 397 | Args, CmdArgs, | 
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 398 | (Twine("libclang_rt.") + Sanitizer + "_" + | 
|  | 399 | getOSLibraryNameSuffix() + "_dynamic.dylib").str(), | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 400 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, | 
|  | 401 | /*AddRPath*/ true); | 
| Hans Wennborg | 10821e5 | 2015-04-09 18:47:01 +0000 | [diff] [blame] | 402 |  | 
|  | 403 | if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { | 
|  | 404 | // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export | 
|  | 405 | // all RTTI-related symbols that UBSan uses. | 
|  | 406 | CmdArgs.push_back("-lc++abi"); | 
|  | 407 | } | 
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 408 | } | 
|  | 409 |  | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 410 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, | 
|  | 411 | ArgStringList &CmdArgs) const { | 
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 412 | // Darwin only supports the compiler-rt based runtime libraries. | 
|  | 413 | switch (GetRuntimeLibType(Args)) { | 
|  | 414 | case ToolChain::RLT_CompilerRT: | 
|  | 415 | break; | 
|  | 416 | default: | 
|  | 417 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 418 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; | 
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 419 | return; | 
|  | 420 | } | 
|  | 421 |  | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 422 | // Darwin doesn't support real static executables, don't link any runtime | 
|  | 423 | // libraries with -static. | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 424 | if (Args.hasArg(options::OPT_static) || | 
|  | 425 | Args.hasArg(options::OPT_fapple_kext) || | 
|  | 426 | Args.hasArg(options::OPT_mkernel)) | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 427 | return; | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 428 |  | 
|  | 429 | // Reject -static-libgcc for now, we can deal with this when and if someone | 
|  | 430 | // cares. This is useful in situations where someone wants to statically link | 
|  | 431 | // something like libstdc++, and needs its runtime support routines. | 
|  | 432 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 433 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 434 | return; | 
|  | 435 | } | 
|  | 436 |  | 
| Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 437 | const SanitizerArgs &Sanitize = getSanitizerArgs(); | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 438 | if (Sanitize.needsAsanRt()) | 
|  | 439 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); | 
|  | 440 | if (Sanitize.needsUbsanRt()) | 
|  | 441 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); | 
| Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 442 | if (Sanitize.needsTsanRt()) | 
|  | 443 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); | 
| Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 444 | if (Sanitize.needsStatsRt()) { | 
|  | 445 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; | 
|  | 446 | AddLinkRuntimeLib(Args, CmdArgs, | 
|  | 447 | (Twine("libclang_rt.stats_client_") + OS + ".a").str(), | 
|  | 448 | /*AlwaysLink=*/true); | 
|  | 449 | AddLinkSanitizerLibArgs(Args, CmdArgs, "stats"); | 
|  | 450 | } | 
| Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 451 |  | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 452 | // Otherwise link libSystem, then the dynamic runtime library, and finally any | 
|  | 453 | // target specific static runtime library. | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 454 | CmdArgs.push_back("-lSystem"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 455 |  | 
|  | 456 | // Select the dynamic runtime library and the target specific static library. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 457 | if (isTargetWatchOSBased()) { | 
|  | 458 | // We currently always need a static runtime library for watchOS. | 
|  | 459 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); | 
|  | 460 | } else if (isTargetTvOSBased()) { | 
|  | 461 | // We currently always need a static runtime library for tvOS. | 
|  | 462 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); | 
|  | 463 | } else if (isTargetIOSBased()) { | 
| Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 464 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, | 
|  | 465 | // it never went into the SDK. | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 466 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 467 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && | 
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 468 | getTriple().getArch() != llvm::Triple::aarch64) | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 469 | CmdArgs.push_back("-lgcc_s.1"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 470 |  | 
| Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 471 | // We currently always need a static runtime library for iOS. | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 472 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 473 | } else { | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 474 | assert(isTargetMacOS() && "unexpected non MacOS platform"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 475 | // The dynamic runtime library was merged with libSystem for 10.6 and | 
|  | 476 | // beyond; only 10.4 and 10.5 need an additional runtime library. | 
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 477 | if (isMacosxVersionLT(10, 5)) | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 478 | CmdArgs.push_back("-lgcc_s.10.4"); | 
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 479 | else if (isMacosxVersionLT(10, 6)) | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 480 | CmdArgs.push_back("-lgcc_s.10.5"); | 
|  | 481 |  | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 482 | // 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] | 483 | // targeting 10.4, to provide versions of the static functions which were | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 484 | // omitted from 10.4.dylib. | 
|  | 485 | // | 
|  | 486 | // Unfortunately, that turned out to not be true, because Darwin system | 
|  | 487 | // headers can still use eprintf on i386, and it is not exported from | 
|  | 488 | // libSystem. Therefore, we still must provide a runtime library just for | 
|  | 489 | // the tiny tiny handful of projects that *might* use that symbol. | 
|  | 490 | if (isMacosxVersionLT(10, 5)) { | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 491 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 492 | } else { | 
|  | 493 | if (getTriple().getArch() == llvm::Triple::x86) | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 494 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); | 
|  | 495 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 496 | } | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 497 | } | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 498 | } | 
|  | 499 |  | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 500 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { | 
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 501 | const OptTable &Opts = getDriver().getOpts(); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 502 |  | 
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 503 | // Support allowing the SDKROOT environment variable used by xcrun and other | 
|  | 504 | // Xcode tools to define the default sysroot, by making it the default for | 
|  | 505 | // isysroot. | 
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 506 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
|  | 507 | // Warn if the path does not exist. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 508 | if (!getVFS().exists(A->getValue())) | 
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 509 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); | 
|  | 510 | } else { | 
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 511 | if (char *env = ::getenv("SDKROOT")) { | 
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 512 | // We only use this value as the default if it is an absolute path, | 
|  | 513 | // exists, and it is not the root path. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 514 | if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) && | 
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 515 | StringRef(env) != "/") { | 
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 516 | Args.append(Args.MakeSeparateArg( | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 517 | nullptr, Opts.getOption(options::OPT_isysroot), env)); | 
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 518 | } | 
|  | 519 | } | 
|  | 520 | } | 
|  | 521 |  | 
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 522 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); | 
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 523 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 524 | Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ); | 
|  | 525 | Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ); | 
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 526 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 527 | if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 528 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 529 | << OSXVersion->getAsString(Args) | 
|  | 530 | << (iOSVersion ? iOSVersion : | 
|  | 531 | TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); | 
|  | 532 | iOSVersion = TvOSVersion = WatchOSVersion = nullptr; | 
|  | 533 | } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) { | 
|  | 534 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) | 
|  | 535 | << iOSVersion->getAsString(Args) | 
|  | 536 | << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); | 
|  | 537 | TvOSVersion = WatchOSVersion = nullptr; | 
|  | 538 | } else if (TvOSVersion && WatchOSVersion) { | 
|  | 539 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) | 
|  | 540 | << TvOSVersion->getAsString(Args) | 
|  | 541 | << WatchOSVersion->getAsString(Args); | 
|  | 542 | WatchOSVersion = nullptr; | 
|  | 543 | } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) { | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 544 | // If no deployment target was specified on the command line, check for | 
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 545 | // environment defines. | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 546 | std::string OSXTarget; | 
|  | 547 | std::string iOSTarget; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 548 | std::string TvOSTarget; | 
|  | 549 | std::string WatchOSTarget; | 
|  | 550 |  | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 551 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) | 
|  | 552 | OSXTarget = env; | 
|  | 553 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) | 
|  | 554 | iOSTarget = env; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 555 | if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET")) | 
|  | 556 | TvOSTarget = env; | 
|  | 557 | if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET")) | 
|  | 558 | WatchOSTarget = env; | 
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 559 |  | 
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 560 | // If there is no command-line argument to specify the Target version and | 
|  | 561 | // no environment variable defined, see if we can set the default based | 
|  | 562 | // on -isysroot. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 563 | if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() && | 
| Frederic Riss | 3ad83bd | 2016-01-12 23:47:59 +0000 | [diff] [blame] | 564 | TvOSTarget.empty() && Args.hasArg(options::OPT_isysroot)) { | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 565 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 566 | StringRef isysroot = A->getValue(); | 
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 567 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk | 
|  | 568 | size_t BeginSDK = isysroot.rfind("SDKs/"); | 
|  | 569 | size_t EndSDK = isysroot.rfind(".sdk"); | 
|  | 570 | if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { | 
|  | 571 | StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); | 
|  | 572 | // Slice the version number out. | 
|  | 573 | // Version number is between the first and the last number. | 
|  | 574 | size_t StartVer = SDK.find_first_of("0123456789"); | 
|  | 575 | size_t EndVer = SDK.find_last_of("0123456789"); | 
|  | 576 | if (StartVer != StringRef::npos && EndVer > StartVer) { | 
|  | 577 | StringRef Version = SDK.slice(StartVer, EndVer + 1); | 
|  | 578 | if (SDK.startswith("iPhoneOS") || | 
|  | 579 | SDK.startswith("iPhoneSimulator")) | 
|  | 580 | iOSTarget = Version; | 
|  | 581 | else if (SDK.startswith("MacOSX")) | 
|  | 582 | OSXTarget = Version; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 583 | else if (SDK.startswith("WatchOS") || | 
|  | 584 | SDK.startswith("WatchSimulator")) | 
|  | 585 | WatchOSTarget = Version; | 
|  | 586 | else if (SDK.startswith("AppleTVOS") || | 
|  | 587 | SDK.startswith("AppleTVSimulator")) | 
|  | 588 | TvOSTarget = Version; | 
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 589 | } | 
|  | 590 | } | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 591 | } | 
|  | 592 | } | 
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 593 |  | 
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 594 | // 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] | 595 | // from arch name and compute the version from the triple. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 596 | if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() && | 
|  | 597 | WatchOSTarget.empty()) { | 
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 598 | StringRef MachOArchName = getMachOArchName(Args); | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 599 | unsigned Major, Minor, Micro; | 
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 600 | if (MachOArchName == "armv7" || MachOArchName == "armv7s" || | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 601 | MachOArchName == "arm64") { | 
|  | 602 | getTriple().getiOSVersion(Major, Minor, Micro); | 
|  | 603 | llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' | 
|  | 604 | << Micro; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 605 | } else if (MachOArchName == "armv7k") { | 
|  | 606 | getTriple().getWatchOSVersion(Major, Minor, Micro); | 
|  | 607 | llvm::raw_string_ostream(WatchOSTarget) << Major << '.' << Minor << '.' | 
|  | 608 | << Micro; | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 609 | } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && | 
|  | 610 | MachOArchName != "armv7em") { | 
|  | 611 | if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { | 
|  | 612 | getDriver().Diag(diag::err_drv_invalid_darwin_version) | 
|  | 613 | << getTriple().getOSName(); | 
|  | 614 | } | 
|  | 615 | llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' | 
|  | 616 | << Micro; | 
|  | 617 | } | 
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 618 | } | 
| Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 619 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 620 | // Do not allow conflicts with the watchOS target. | 
|  | 621 | if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) { | 
|  | 622 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) | 
|  | 623 | << "WATCHOS_DEPLOYMENT_TARGET" | 
|  | 624 | << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" : | 
|  | 625 | "TVOS_DEPLOYMENT_TARGET"); | 
|  | 626 | } | 
|  | 627 |  | 
|  | 628 | // Do not allow conflicts with the tvOS target. | 
|  | 629 | if (!TvOSTarget.empty() && !iOSTarget.empty()) { | 
|  | 630 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) | 
|  | 631 | << "TVOS_DEPLOYMENT_TARGET" | 
|  | 632 | << "IPHONEOS_DEPLOYMENT_TARGET"; | 
|  | 633 | } | 
|  | 634 |  | 
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 635 | // Allow conflicts among OSX and iOS for historical reasons, but choose the | 
|  | 636 | // default platform. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 637 | if (!OSXTarget.empty() && (!iOSTarget.empty() || | 
|  | 638 | !WatchOSTarget.empty() || | 
|  | 639 | !TvOSTarget.empty())) { | 
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 640 | if (getTriple().getArch() == llvm::Triple::arm || | 
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 641 | getTriple().getArch() == llvm::Triple::aarch64 || | 
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 642 | getTriple().getArch() == llvm::Triple::thumb) | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 643 | OSXTarget = ""; | 
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 644 | else | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 645 | iOSTarget = WatchOSTarget = TvOSTarget = ""; | 
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 646 | } | 
| Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 647 |  | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 648 | if (!OSXTarget.empty()) { | 
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 649 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 650 | OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 651 | Args.append(OSXVersion); | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 652 | } else if (!iOSTarget.empty()) { | 
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 653 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 654 | iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); | 
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 655 | Args.append(iOSVersion); | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 656 | } else if (!TvOSTarget.empty()) { | 
|  | 657 | const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ); | 
|  | 658 | TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget); | 
|  | 659 | Args.append(TvOSVersion); | 
|  | 660 | } else if (!WatchOSTarget.empty()) { | 
|  | 661 | const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ); | 
|  | 662 | WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget); | 
|  | 663 | Args.append(WatchOSVersion); | 
| Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 664 | } | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 665 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 |  | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 667 | DarwinPlatformKind Platform; | 
|  | 668 | if (OSXVersion) | 
|  | 669 | Platform = MacOS; | 
|  | 670 | else if (iOSVersion) | 
|  | 671 | Platform = IPhoneOS; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 672 | else if (TvOSVersion) | 
|  | 673 | Platform = TvOS; | 
|  | 674 | else if (WatchOSVersion) | 
|  | 675 | Platform = WatchOS; | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 676 | else | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 677 | llvm_unreachable("Unable to infer Darwin variant"); | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 678 |  | 
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 679 | // Set the tool chain target information. | 
|  | 680 | unsigned Major, Minor, Micro; | 
|  | 681 | bool HadExtra; | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 682 | if (Platform == MacOS) { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 683 | assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && | 
|  | 684 | "Unknown target platform!"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 685 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, | 
|  | 686 | HadExtra) || | 
|  | 687 | HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 688 | getDriver().Diag(diag::err_drv_invalid_version_number) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 689 | << OSXVersion->getAsString(Args); | 
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 690 | } else if (Platform == IPhoneOS) { | 
|  | 691 | assert(iOSVersion && "Unknown target platform!"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 692 | if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, | 
|  | 693 | HadExtra) || | 
|  | 694 | HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100) | 
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 695 | getDriver().Diag(diag::err_drv_invalid_version_number) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 696 | << iOSVersion->getAsString(Args); | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 697 | } else if (Platform == TvOS) { | 
|  | 698 | if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, | 
|  | 699 | Micro, HadExtra) || HadExtra || | 
|  | 700 | Major >= 10 || Minor >= 100 || Micro >= 100) | 
|  | 701 | getDriver().Diag(diag::err_drv_invalid_version_number) | 
|  | 702 | << TvOSVersion->getAsString(Args); | 
|  | 703 | } else if (Platform == WatchOS) { | 
|  | 704 | if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor, | 
|  | 705 | Micro, HadExtra) || HadExtra || | 
|  | 706 | Major >= 10 || Minor >= 100 || Micro >= 100) | 
|  | 707 | getDriver().Diag(diag::err_drv_invalid_version_number) | 
|  | 708 | << WatchOSVersion->getAsString(Args); | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 709 | } else | 
|  | 710 | llvm_unreachable("unknown kind of Darwin platform"); | 
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 711 |  | 
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 712 | // Recognize iOS targets with an x86 architecture as the iOS simulator. | 
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 713 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 714 | getTriple().getArch() == llvm::Triple::x86_64)) | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 715 | Platform = IPhoneOSSimulator; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 716 | if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 717 | getTriple().getArch() == llvm::Triple::x86_64)) | 
|  | 718 | Platform = TvOSSimulator; | 
|  | 719 | if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 720 | getTriple().getArch() == llvm::Triple::x86_64)) | 
|  | 721 | Platform = WatchOSSimulator; | 
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 722 |  | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 723 | setTarget(Platform, Major, Minor, Micro); | 
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 724 | } | 
|  | 725 |  | 
| Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 726 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 727 | ArgStringList &CmdArgs) const { | 
|  | 728 | CXXStdlibType Type = GetCXXStdlibType(Args); | 
|  | 729 |  | 
|  | 730 | switch (Type) { | 
|  | 731 | case ToolChain::CST_Libcxx: | 
|  | 732 | CmdArgs.push_back("-lc++"); | 
|  | 733 | break; | 
|  | 734 |  | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 735 | case ToolChain::CST_Libstdcxx: | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 736 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; | 
|  | 737 | // it was previously found in the gcc lib dir. However, for all the Darwin | 
|  | 738 | // platforms we care about it was -lstdc++.6, so we search for that | 
|  | 739 | // explicitly if we can't see an obvious -lstdc++ candidate. | 
|  | 740 |  | 
|  | 741 | // Check in the sysroot first. | 
|  | 742 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 743 | SmallString<128> P(A->getValue()); | 
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 744 | llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 745 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 746 | if (!getVFS().exists(P)) { | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 747 | llvm::sys::path::remove_filename(P); | 
|  | 748 | llvm::sys::path::append(P, "libstdc++.6.dylib"); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 749 | if (getVFS().exists(P)) { | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 750 | CmdArgs.push_back(Args.MakeArgString(P)); | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 751 | return; | 
|  | 752 | } | 
|  | 753 | } | 
|  | 754 | } | 
|  | 755 |  | 
|  | 756 | // Otherwise, look in the root. | 
| Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 757 | // FIXME: This should be removed someday when we don't have to care about | 
|  | 758 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 759 | if (!getVFS().exists("/usr/lib/libstdc++.dylib") && | 
|  | 760 | getVFS().exists("/usr/lib/libstdc++.6.dylib")) { | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 761 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); | 
|  | 762 | return; | 
|  | 763 | } | 
|  | 764 |  | 
|  | 765 | // Otherwise, let the linker search. | 
|  | 766 | CmdArgs.push_back("-lstdc++"); | 
|  | 767 | break; | 
|  | 768 | } | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 769 | } | 
|  | 770 |  | 
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 771 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, | 
|  | 772 | ArgStringList &CmdArgs) const { | 
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 773 | // For Darwin platforms, use the compiler-rt-based support library | 
|  | 774 | // instead of the gcc-provided one (which is also incidentally | 
|  | 775 | // only present in the gcc lib dir, which makes it hard to find). | 
|  | 776 |  | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 777 | SmallString<128> P(getDriver().ResourceDir); | 
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 778 | llvm::sys::path::append(P, "lib", "darwin"); | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 779 |  | 
|  | 780 | // Use the newer cc_kext for iOS ARM after 6.0. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 781 | if (isTargetWatchOS()) { | 
|  | 782 | llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a"); | 
|  | 783 | } else if (isTargetTvOS()) { | 
|  | 784 | llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a"); | 
|  | 785 | } else if (isTargetIPhoneOS()) { | 
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 786 | llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a"); | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 787 | } else { | 
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 788 | llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 789 | } | 
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 790 |  | 
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 791 | // For now, allow missing resource libraries to support developers who may | 
|  | 792 | // not have compiler-rt checked out or integrated into their build. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 793 | if (getVFS().exists(P)) | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 794 | CmdArgs.push_back(Args.MakeArgString(P)); | 
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 795 | } | 
|  | 796 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 797 | DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, | 
|  | 798 | const char *BoundArch) const { | 
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 799 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); | 
|  | 800 | const OptTable &Opts = getDriver().getOpts(); | 
|  | 801 |  | 
|  | 802 | // FIXME: We really want to get out of the tool chain level argument | 
|  | 803 | // translation business, as it makes the driver functionality much | 
|  | 804 | // more opaque. For now, we follow gcc closely solely for the | 
|  | 805 | // purpose of easily achieving feature parity & testability. Once we | 
|  | 806 | // have something that works, we should reevaluate each translation | 
|  | 807 | // and try to push it down into tool specific logic. | 
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 808 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 809 | for (Arg *A : Args) { | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 810 | if (A->getOption().matches(options::OPT_Xarch__)) { | 
| Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 811 | // Skip this argument unless the architecture matches either the toolchain | 
|  | 812 | // triple arch, or the arch being bound. | 
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 813 | llvm::Triple::ArchType XarchArch = | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 814 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); | 
|  | 815 | if (!(XarchArch == getArch() || | 
|  | 816 | (BoundArch && | 
|  | 817 | XarchArch == | 
|  | 818 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 819 | continue; | 
|  | 820 |  | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 821 | Arg *OriginalArg = A; | 
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 822 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 823 | unsigned Prev = Index; | 
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 824 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 |  | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 826 | // If the argument parsing failed or more than one argument was | 
|  | 827 | // consumed, the -Xarch_ argument's parameter tried to consume | 
|  | 828 | // extra arguments. Emit an error and ignore. | 
|  | 829 | // | 
|  | 830 | // We also want to disallow any options which would alter the | 
|  | 831 | // driver behavior; that isn't going to work in our model. We | 
|  | 832 | // use isDriverOption() as an approximation, although things | 
|  | 833 | // like -O4 are going to slip through. | 
| Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 834 | if (!XarchArg || Index > Prev + 1) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 835 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 836 | << A->getAsString(Args); | 
| Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 837 | continue; | 
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 838 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 839 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 840 | << A->getAsString(Args); | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 841 | continue; | 
|  | 842 | } | 
|  | 843 |  | 
| Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 844 | XarchArg->setBaseArg(A); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 845 |  | 
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 846 | A = XarchArg.release(); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 847 | DAL->AddSynthesizedArg(A); | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 848 |  | 
|  | 849 | // Linker input arguments require custom handling. The problem is that we | 
|  | 850 | // have already constructed the phase actions, so we can not treat them as | 
|  | 851 | // "input arguments". | 
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 852 | if (A->getOption().hasFlag(options::LinkerInput)) { | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 853 | // Convert the argument into individual Zlinker_input_args. | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 854 | for (const char *Value : A->getValues()) { | 
|  | 855 | DAL->AddSeparateArg( | 
|  | 856 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 857 | } | 
|  | 858 | continue; | 
|  | 859 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | } | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 861 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 862 | // Sob. These is strictly gcc compatible for the time being. Apple | 
|  | 863 | // gcc translates options twice, which means that self-expanding | 
|  | 864 | // options add duplicates. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 865 | switch ((options::ID)A->getOption().getID()) { | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 866 | default: | 
|  | 867 | DAL->append(A); | 
|  | 868 | break; | 
|  | 869 |  | 
|  | 870 | case options::OPT_mkernel: | 
|  | 871 | case options::OPT_fapple_kext: | 
|  | 872 | DAL->append(A); | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 873 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 874 | break; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 875 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 876 | case options::OPT_dependency_file: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 877 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 878 | break; | 
|  | 879 |  | 
|  | 880 | case options::OPT_gfull: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 881 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 882 | DAL->AddFlagArg( | 
|  | 883 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 884 | break; | 
|  | 885 |  | 
|  | 886 | case options::OPT_gused: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 887 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 888 | DAL->AddFlagArg( | 
|  | 889 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 890 | break; | 
|  | 891 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 892 | case options::OPT_shared: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 893 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 894 | break; | 
|  | 895 |  | 
|  | 896 | case options::OPT_fconstant_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 897 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 898 | break; | 
|  | 899 |  | 
|  | 900 | case options::OPT_fno_constant_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 901 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 902 | break; | 
|  | 903 |  | 
|  | 904 | case options::OPT_Wnonportable_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 905 | DAL->AddFlagArg(A, | 
|  | 906 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 907 | break; | 
|  | 908 |  | 
|  | 909 | case options::OPT_Wno_nonportable_cfstrings: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 910 | DAL->AddFlagArg( | 
|  | 911 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 912 | break; | 
|  | 913 |  | 
|  | 914 | case options::OPT_fpascal_strings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 915 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 916 | break; | 
|  | 917 |  | 
|  | 918 | case options::OPT_fno_pascal_strings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 919 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 920 | break; | 
|  | 921 | } | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 922 | } | 
|  | 923 |  | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 924 | if (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 925 | getTriple().getArch() == llvm::Triple::x86_64) | 
| Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 926 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 927 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), | 
|  | 928 | "core2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 929 |  | 
|  | 930 | // 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] | 931 | // how the driver driver works. | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 932 | if (BoundArch) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 933 | StringRef Name = BoundArch; | 
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 934 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); | 
|  | 935 | const Option MArch = Opts.getOption(options::OPT_march_EQ); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 936 |  | 
|  | 937 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, | 
|  | 938 | // which defines the list of which architectures we accept. | 
|  | 939 | if (Name == "ppc") | 
|  | 940 | ; | 
|  | 941 | else if (Name == "ppc601") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 942 | DAL->AddJoinedArg(nullptr, MCpu, "601"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 943 | else if (Name == "ppc603") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 944 | DAL->AddJoinedArg(nullptr, MCpu, "603"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 945 | else if (Name == "ppc604") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 946 | DAL->AddJoinedArg(nullptr, MCpu, "604"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 947 | else if (Name == "ppc604e") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 948 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 949 | else if (Name == "ppc750") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 950 | DAL->AddJoinedArg(nullptr, MCpu, "750"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 951 | else if (Name == "ppc7400") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 952 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 953 | else if (Name == "ppc7450") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 954 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 955 | else if (Name == "ppc970") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 956 | DAL->AddJoinedArg(nullptr, MCpu, "970"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 957 |  | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 958 | else if (Name == "ppc64" || Name == "ppc64le") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 959 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 960 |  | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 961 | else if (Name == "i386") | 
|  | 962 | ; | 
|  | 963 | else if (Name == "i486") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 964 | DAL->AddJoinedArg(nullptr, MArch, "i486"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 965 | else if (Name == "i586") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 966 | DAL->AddJoinedArg(nullptr, MArch, "i586"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 967 | else if (Name == "i686") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 968 | DAL->AddJoinedArg(nullptr, MArch, "i686"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 969 | else if (Name == "pentium") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 970 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 971 | else if (Name == "pentium2") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 972 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 973 | else if (Name == "pentpro") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 974 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 975 | else if (Name == "pentIIm3") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 976 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 977 |  | 
|  | 978 | else if (Name == "x86_64") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 979 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 980 | else if (Name == "x86_64h") { | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 981 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
|  | 982 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); | 
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 983 | } | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 984 |  | 
|  | 985 | else if (Name == "arm") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 986 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 987 | else if (Name == "armv4t") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 988 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 989 | else if (Name == "armv5") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 990 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 991 | else if (Name == "xscale") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 992 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 993 | else if (Name == "armv6") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 994 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 995 | else if (Name == "armv6m") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 996 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 997 | else if (Name == "armv7") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 998 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 999 | else if (Name == "armv7em") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1000 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); | 
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1001 | else if (Name == "armv7k") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1002 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1003 | else if (Name == "armv7m") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1004 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); | 
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1005 | else if (Name == "armv7s") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1006 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1007 | } | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 1008 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1009 | return DAL; | 
|  | 1010 | } | 
|  | 1011 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1012 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, | 
|  | 1013 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1014 | // Embedded targets are simple at the moment, not supporting sanitizers and | 
|  | 1015 | // with different libraries for each member of the product { static, PIC } x | 
|  | 1016 | // { hard-float, soft-float } | 
|  | 1017 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); | 
| Saleem Abdulrasool | 06f6f99 | 2015-09-19 20:40:16 +0000 | [diff] [blame] | 1018 | CompilerRT += | 
|  | 1019 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) | 
|  | 1020 | ? "hard" | 
|  | 1021 | : "soft"; | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1022 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; | 
|  | 1023 |  | 
|  | 1024 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); | 
|  | 1025 | } | 
|  | 1026 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1027 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, | 
|  | 1028 | const char *BoundArch) const { | 
|  | 1029 | // First get the generic Apple args, before moving onto Darwin-specific ones. | 
|  | 1030 | DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); | 
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1031 | const OptTable &Opts = getDriver().getOpts(); | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1032 |  | 
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1033 | // If no architecture is bound, none of the translations here are relevant. | 
|  | 1034 | if (!BoundArch) | 
|  | 1035 | return DAL; | 
|  | 1036 |  | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1037 | // Add an explicit version min argument for the deployment target. We do this | 
|  | 1038 | // after argument translation because -Xarch_ arguments may add a version min | 
|  | 1039 | // argument. | 
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1040 | AddDeploymentTarget(*DAL); | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1041 |  | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1042 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. | 
|  | 1043 | // FIXME: It would be far better to avoid inserting those -static arguments, | 
|  | 1044 | // but we can't check the deployment target in the translation code until | 
|  | 1045 | // it is set here. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1046 | if (isTargetWatchOSBased() || | 
|  | 1047 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { | 
|  | 1048 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1049 | Arg *A = *it; | 
|  | 1050 | ++it; | 
|  | 1051 | if (A->getOption().getID() != options::OPT_mkernel && | 
|  | 1052 | A->getOption().getID() != options::OPT_fapple_kext) | 
|  | 1053 | continue; | 
|  | 1054 | assert(it != ie && "unexpected argument translation"); | 
|  | 1055 | A = *it; | 
|  | 1056 | assert(A->getOption().getID() == options::OPT_static && | 
|  | 1057 | "missing expected -static argument"); | 
|  | 1058 | it = DAL->getArgs().erase(it); | 
|  | 1059 | } | 
|  | 1060 | } | 
|  | 1061 |  | 
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1062 | if (!Args.getLastArg(options::OPT_stdlib_EQ) && | 
| Tim Northover | 3a098c1 | 2016-02-15 16:38:10 +0000 | [diff] [blame] | 1063 | GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) | 
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1064 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), | 
|  | 1065 | "libc++"); | 
|  | 1066 |  | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1067 | // Validate the C++ standard library choice. | 
|  | 1068 | CXXStdlibType Type = GetCXXStdlibType(*DAL); | 
|  | 1069 | if (Type == ToolChain::CST_Libcxx) { | 
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1070 | // Check whether the target provides libc++. | 
|  | 1071 | StringRef where; | 
|  | 1072 |  | 
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1073 | // Complain about targeting iOS < 5.0 in any way. | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1074 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) | 
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1075 | where = "iOS 5.0"; | 
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1076 |  | 
|  | 1077 | if (where != StringRef()) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1078 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1079 | } | 
|  | 1080 | } | 
|  | 1081 |  | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1082 | return DAL; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1084 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1085 | bool MachO::IsUnwindTablesDefault() const { | 
| Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1086 | return getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1087 | } | 
|  | 1088 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1089 | bool MachO::UseDwarfDebugFlags() const { | 
| Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1090 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) | 
|  | 1091 | return S[0] != '\0'; | 
|  | 1092 | return false; | 
|  | 1093 | } | 
|  | 1094 |  | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1095 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { | 
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1096 | // Darwin uses SjLj exceptions on ARM. | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1097 | if (getTriple().getArch() != llvm::Triple::arm && | 
|  | 1098 | getTriple().getArch() != llvm::Triple::thumb) | 
|  | 1099 | return false; | 
|  | 1100 |  | 
| Tim Northover | c741b04 | 2015-11-17 18:27:27 +0000 | [diff] [blame] | 1101 | // Only watchOS uses the new DWARF/Compact unwinding method. | 
| Tim Northover | d88ecb3 | 2016-01-27 19:32:40 +0000 | [diff] [blame] | 1102 | llvm::Triple Triple(ComputeLLVMTriple(Args)); | 
| Tim Northover | 4c9ac7d | 2016-01-27 22:14:02 +0000 | [diff] [blame] | 1103 | return !Triple.isWatchABI(); | 
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1104 | } | 
|  | 1105 |  | 
| Steven Wu | 574b0f2 | 2016-03-01 01:07:58 +0000 | [diff] [blame] | 1106 | bool Darwin::SupportsEmbeddedBitcode() const { | 
|  | 1107 | assert(TargetInitialized && "Target not initialized!"); | 
|  | 1108 | if (isTargetIPhoneOS() && isIPhoneOSVersionLT(6, 0)) | 
|  | 1109 | return false; | 
|  | 1110 | return true; | 
|  | 1111 | } | 
|  | 1112 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1113 | bool MachO::isPICDefault() const { return true; } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1114 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1115 | bool MachO::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1116 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1117 | bool MachO::isPICDefaultForced() const { | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1118 | return (getArch() == llvm::Triple::x86_64 || | 
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1119 | getArch() == llvm::Triple::aarch64); | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1120 | } | 
|  | 1121 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1122 | bool MachO::SupportsProfiling() const { | 
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1123 | // Profiling instrumentation is only supported on x86. | 
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1124 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1125 | } | 
|  | 1126 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1127 | void Darwin::addMinVersionArgs(const ArgList &Args, | 
|  | 1128 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1129 | VersionTuple TargetVersion = getTargetVersion(); | 
|  | 1130 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1131 | if (isTargetWatchOS()) | 
|  | 1132 | CmdArgs.push_back("-watchos_version_min"); | 
|  | 1133 | else if (isTargetWatchOSSimulator()) | 
|  | 1134 | CmdArgs.push_back("-watchos_simulator_version_min"); | 
|  | 1135 | else if (isTargetTvOS()) | 
|  | 1136 | CmdArgs.push_back("-tvos_version_min"); | 
|  | 1137 | else if (isTargetTvOSSimulator()) | 
|  | 1138 | CmdArgs.push_back("-tvos_simulator_version_min"); | 
|  | 1139 | else if (isTargetIOSSimulator()) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1140 | CmdArgs.push_back("-ios_simulator_version_min"); | 
| Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1141 | else if (isTargetIOSBased()) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1142 | CmdArgs.push_back("-iphoneos_version_min"); | 
|  | 1143 | else { | 
|  | 1144 | assert(isTargetMacOS() && "unexpected target"); | 
|  | 1145 | CmdArgs.push_back("-macosx_version_min"); | 
|  | 1146 | } | 
|  | 1147 |  | 
|  | 1148 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); | 
|  | 1149 | } | 
|  | 1150 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1151 | void Darwin::addStartObjectFileArgs(const ArgList &Args, | 
|  | 1152 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1153 | // Derived from startfile spec. | 
|  | 1154 | if (Args.hasArg(options::OPT_dynamiclib)) { | 
|  | 1155 | // Derived from darwin_dylib1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1156 | if (isTargetWatchOSBased()) { | 
|  | 1157 | ; // watchOS does not need dylib1.o. | 
|  | 1158 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1159 | ; // iOS simulator does not need dylib1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1160 | } else if (isTargetIPhoneOS()) { | 
|  | 1161 | if (isIPhoneOSVersionLT(3, 1)) | 
|  | 1162 | CmdArgs.push_back("-ldylib1.o"); | 
|  | 1163 | } else { | 
|  | 1164 | if (isMacosxVersionLT(10, 5)) | 
|  | 1165 | CmdArgs.push_back("-ldylib1.o"); | 
|  | 1166 | else if (isMacosxVersionLT(10, 6)) | 
|  | 1167 | CmdArgs.push_back("-ldylib1.10.5.o"); | 
|  | 1168 | } | 
|  | 1169 | } else { | 
|  | 1170 | if (Args.hasArg(options::OPT_bundle)) { | 
|  | 1171 | if (!Args.hasArg(options::OPT_static)) { | 
|  | 1172 | // Derived from darwin_bundle1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1173 | if (isTargetWatchOSBased()) { | 
|  | 1174 | ; // watchOS does not need bundle1.o. | 
|  | 1175 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1176 | ; // iOS simulator does not need bundle1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1177 | } else if (isTargetIPhoneOS()) { | 
|  | 1178 | if (isIPhoneOSVersionLT(3, 1)) | 
|  | 1179 | CmdArgs.push_back("-lbundle1.o"); | 
|  | 1180 | } else { | 
|  | 1181 | if (isMacosxVersionLT(10, 6)) | 
|  | 1182 | CmdArgs.push_back("-lbundle1.o"); | 
|  | 1183 | } | 
|  | 1184 | } | 
|  | 1185 | } else { | 
|  | 1186 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { | 
|  | 1187 | if (Args.hasArg(options::OPT_static) || | 
|  | 1188 | Args.hasArg(options::OPT_object) || | 
|  | 1189 | Args.hasArg(options::OPT_preload)) { | 
|  | 1190 | CmdArgs.push_back("-lgcrt0.o"); | 
|  | 1191 | } else { | 
|  | 1192 | CmdArgs.push_back("-lgcrt1.o"); | 
|  | 1193 |  | 
|  | 1194 | // darwin_crt2 spec is empty. | 
|  | 1195 | } | 
|  | 1196 | // By default on OS X 10.8 and later, we don't link with a crt1.o | 
|  | 1197 | // file and the linker knows to use _main as the entry point.  But, | 
|  | 1198 | // when compiling with -pg, we need to link with the gcrt1.o file, | 
|  | 1199 | // so pass the -no_new_main option to tell the linker to use the | 
|  | 1200 | // "start" symbol as the entry point. | 
|  | 1201 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) | 
|  | 1202 | CmdArgs.push_back("-no_new_main"); | 
|  | 1203 | } else { | 
|  | 1204 | if (Args.hasArg(options::OPT_static) || | 
|  | 1205 | Args.hasArg(options::OPT_object) || | 
|  | 1206 | Args.hasArg(options::OPT_preload)) { | 
|  | 1207 | CmdArgs.push_back("-lcrt0.o"); | 
|  | 1208 | } else { | 
|  | 1209 | // Derived from darwin_crt1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1210 | if (isTargetWatchOSBased()) { | 
|  | 1211 | ; // watchOS does not need crt1.o. | 
|  | 1212 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1213 | ; // iOS simulator does not need crt1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1214 | } else if (isTargetIPhoneOS()) { | 
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1215 | if (getArch() == llvm::Triple::aarch64) | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1216 | ; // iOS does not need any crt1 files for arm64 | 
|  | 1217 | else if (isIPhoneOSVersionLT(3, 1)) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1218 | CmdArgs.push_back("-lcrt1.o"); | 
|  | 1219 | else if (isIPhoneOSVersionLT(6, 0)) | 
|  | 1220 | CmdArgs.push_back("-lcrt1.3.1.o"); | 
|  | 1221 | } else { | 
|  | 1222 | if (isMacosxVersionLT(10, 5)) | 
|  | 1223 | CmdArgs.push_back("-lcrt1.o"); | 
|  | 1224 | else if (isMacosxVersionLT(10, 6)) | 
|  | 1225 | CmdArgs.push_back("-lcrt1.10.5.o"); | 
|  | 1226 | else if (isMacosxVersionLT(10, 8)) | 
|  | 1227 | CmdArgs.push_back("-lcrt1.10.6.o"); | 
|  | 1228 |  | 
|  | 1229 | // darwin_crt2 spec is empty. | 
|  | 1230 | } | 
|  | 1231 | } | 
|  | 1232 | } | 
|  | 1233 | } | 
|  | 1234 | } | 
|  | 1235 |  | 
|  | 1236 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1237 | !isTargetWatchOS() && | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1238 | isMacosxVersionLT(10, 5)) { | 
|  | 1239 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); | 
|  | 1240 | CmdArgs.push_back(Str); | 
|  | 1241 | } | 
|  | 1242 | } | 
|  | 1243 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1244 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } | 
| Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1245 |  | 
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1246 | void Darwin::CheckObjCARC() const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1247 | if (isTargetIOSBased() || isTargetWatchOSBased() || | 
|  | 1248 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) | 
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1249 | return; | 
| John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1250 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); | 
| Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1251 | } | 
|  | 1252 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1253 | SanitizerMask Darwin::getSupportedSanitizers() const { | 
|  | 1254 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 1255 | Res |= SanitizerKind::Address; | 
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1256 | if (isTargetMacOS()) { | 
|  | 1257 | if (!isMacosxVersionLT(10, 9)) | 
|  | 1258 | Res |= SanitizerKind::Vptr; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1259 | Res |= SanitizerKind::SafeStack; | 
| Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 1260 | Res |= SanitizerKind::Thread; | 
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1261 | } | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1262 | return Res; | 
|  | 1263 | } | 
|  | 1264 |  | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1265 | /// Generic_GCC - A tool chain using the 'gcc' command to perform | 
|  | 1266 | /// all subcommands; this relies on gcc translating the majority of | 
|  | 1267 | /// command line options. | 
|  | 1268 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1269 | /// \brief Parse a GCCVersion object out of a string of text. | 
|  | 1270 | /// | 
|  | 1271 | /// This is the primary means of forming GCCVersion objects. | 
|  | 1272 | /*static*/ | 
|  | 1273 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1274 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1275 | std::pair<StringRef, StringRef> First = VersionText.split('.'); | 
|  | 1276 | std::pair<StringRef, StringRef> Second = First.second.split('.'); | 
|  | 1277 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1278 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; | 
|  | 1279 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1280 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1281 | GoodVersion.MajorStr = First.first.str(); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1282 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1283 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1284 | GoodVersion.MinorStr = Second.first.str(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1285 |  | 
|  | 1286 | // First look for a number prefix and parse that if present. Otherwise just | 
|  | 1287 | // stash the entire patch string in the suffix, and leave the number | 
|  | 1288 | // unspecified. This covers versions strings such as: | 
|  | 1289 | //   4.4 | 
|  | 1290 | //   4.4.0 | 
|  | 1291 | //   4.4.x | 
|  | 1292 | //   4.4.2-rc4 | 
|  | 1293 | //   4.4.x-patched | 
|  | 1294 | // And retains any patch number it finds. | 
|  | 1295 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); | 
|  | 1296 | if (!PatchText.empty()) { | 
| Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1297 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1298 | // Try to parse the number and any suffix. | 
|  | 1299 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || | 
|  | 1300 | GoodVersion.Patch < 0) | 
|  | 1301 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1302 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1303 | } | 
|  | 1304 | } | 
|  | 1305 |  | 
|  | 1306 | return GoodVersion; | 
|  | 1307 | } | 
|  | 1308 |  | 
|  | 1309 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1310 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, | 
|  | 1311 | int RHSPatch, | 
|  | 1312 | StringRef RHSPatchSuffix) const { | 
|  | 1313 | if (Major != RHSMajor) | 
|  | 1314 | return Major < RHSMajor; | 
|  | 1315 | if (Minor != RHSMinor) | 
|  | 1316 | return Minor < RHSMinor; | 
|  | 1317 | if (Patch != RHSPatch) { | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1318 | // Note that versions without a specified patch sort higher than those with | 
|  | 1319 | // a patch. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1320 | if (RHSPatch == -1) | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1321 | return true; | 
|  | 1322 | if (Patch == -1) | 
|  | 1323 | return false; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1324 |  | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1325 | // Otherwise just sort on the patch itself. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1326 | return Patch < RHSPatch; | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1327 | } | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1328 | if (PatchSuffix != RHSPatchSuffix) { | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1329 | // Sort empty suffixes higher. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1330 | if (RHSPatchSuffix.empty()) | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1331 | return true; | 
|  | 1332 | if (PatchSuffix.empty()) | 
| Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1333 | return false; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1334 |  | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1335 | // Provide a lexicographic sort to make this a total ordering. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1336 | return PatchSuffix < RHSPatchSuffix; | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1337 | } | 
|  | 1338 |  | 
|  | 1339 | // The versions are equal. | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1340 | return false; | 
|  | 1341 | } | 
|  | 1342 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1343 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1344 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); | 
|  | 1345 | if (A) | 
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1346 | return A->getValue(); | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1347 | return GCC_INSTALL_PREFIX; | 
|  | 1348 | } | 
|  | 1349 |  | 
| Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1350 | /// \brief Initialize a GCCInstallationDetector from the driver. | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1351 | /// | 
|  | 1352 | /// This performs all of the autodetection and sets up the various paths. | 
| Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1353 | /// Once constructed, a GCCInstallationDetector is essentially immutable. | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1354 | /// | 
|  | 1355 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and | 
|  | 1356 | /// should instead pull the target out of the driver. This is currently | 
|  | 1357 | /// necessary because the driver doesn't store the final version of the target | 
|  | 1358 | /// triple. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1359 | void Generic_GCC::GCCInstallationDetector::init( | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1360 | const llvm::Triple &TargetTriple, const ArgList &Args, | 
| Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1361 | ArrayRef<std::string> ExtraTripleAliases) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1362 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() | 
|  | 1363 | ? TargetTriple.get64BitArchVariant() | 
|  | 1364 | : TargetTriple.get32BitArchVariant(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1365 | // The library directories which may contain GCC installations. | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1366 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1367 | // The compatible GCC triples for this particular architecture. | 
| Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1368 | SmallVector<StringRef, 16> CandidateTripleAliases; | 
|  | 1369 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1370 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, | 
|  | 1371 | CandidateTripleAliases, CandidateBiarchLibDirs, | 
|  | 1372 | CandidateBiarchTripleAliases); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1373 |  | 
|  | 1374 | // Compute the set of prefixes for our search. | 
|  | 1375 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), | 
|  | 1376 | D.PrefixDirs.end()); | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1377 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1378 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); | 
|  | 1379 | if (GCCToolchainDir != "") { | 
|  | 1380 | if (GCCToolchainDir.back() == '/') | 
|  | 1381 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1382 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1383 | Prefixes.push_back(GCCToolchainDir); | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1384 | } else { | 
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1385 | // If we have a SysRoot, try that first. | 
|  | 1386 | if (!D.SysRoot.empty()) { | 
|  | 1387 | Prefixes.push_back(D.SysRoot); | 
|  | 1388 | Prefixes.push_back(D.SysRoot + "/usr"); | 
|  | 1389 | } | 
|  | 1390 |  | 
|  | 1391 | // Then look for gcc installed alongside clang. | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1392 | Prefixes.push_back(D.InstalledDir + "/.."); | 
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1393 |  | 
|  | 1394 | // And finally in /usr. | 
|  | 1395 | if (D.SysRoot.empty()) | 
|  | 1396 | Prefixes.push_back("/usr"); | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1397 | } | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1398 |  | 
|  | 1399 | // Loop over the various components which exist and select the best GCC | 
|  | 1400 | // installation available. GCC installs are ranked by version number. | 
|  | 1401 | Version = GCCVersion::Parse("0.0.0"); | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1402 | for (const std::string &Prefix : Prefixes) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1403 | if (!D.getVFS().exists(Prefix)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1404 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1405 | for (StringRef Suffix : CandidateLibDirs) { | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1406 | const std::string LibDir = Prefix + Suffix.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1407 | if (!D.getVFS().exists(LibDir)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1408 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1409 | for (StringRef Candidate : ExtraTripleAliases) // Try these first. | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1410 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1411 | for (StringRef Candidate : CandidateTripleAliases) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1412 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1413 | } | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1414 | for (StringRef Suffix : CandidateBiarchLibDirs) { | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1415 | const std::string LibDir = Prefix + Suffix.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1416 | if (!D.getVFS().exists(LibDir)) | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1417 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1418 | for (StringRef Candidate : CandidateBiarchTripleAliases) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1419 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1420 | /*NeedsBiarchSuffix=*/ true); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1421 | } | 
|  | 1422 | } | 
|  | 1423 | } | 
|  | 1424 |  | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1425 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1426 | for (const auto &InstallPath : CandidateGCCInstallPaths) | 
|  | 1427 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1428 |  | 
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1429 | if (!GCCInstallPath.empty()) | 
|  | 1430 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; | 
|  | 1431 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1432 | for (const auto &Multilib : Multilibs) | 
|  | 1433 | OS << "Candidate multilib: " << Multilib << "\n"; | 
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1434 |  | 
|  | 1435 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) | 
|  | 1436 | OS << "Selected multilib: " << SelectedMultilib << "\n"; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1437 | } | 
|  | 1438 |  | 
|  | 1439 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { | 
|  | 1440 | if (BiarchSibling.hasValue()) { | 
|  | 1441 | M = BiarchSibling.getValue(); | 
|  | 1442 | return true; | 
|  | 1443 | } | 
|  | 1444 | return false; | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1445 | } | 
|  | 1446 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1447 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1448 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1449 | SmallVectorImpl<StringRef> &LibDirs, | 
|  | 1450 | SmallVectorImpl<StringRef> &TripleAliases, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1451 | SmallVectorImpl<StringRef> &BiarchLibDirs, | 
|  | 1452 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1453 | // Declare a bunch of static data sets that we'll select between below. These | 
|  | 1454 | // are specifically designed to always refer to string literals to avoid any | 
|  | 1455 | // lifetime or initialization issues. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1456 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1457 | static const char *const AArch64Triples[] = { | 
|  | 1458 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", | 
|  | 1459 | "aarch64-redhat-linux"}; | 
|  | 1460 | static const char *const AArch64beLibDirs[] = {"/lib"}; | 
|  | 1461 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", | 
|  | 1462 | "aarch64_be-linux-gnu"}; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1463 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1464 | static const char *const ARMLibDirs[] = {"/lib"}; | 
|  | 1465 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", | 
|  | 1466 | "arm-linux-androideabi"}; | 
|  | 1467 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", | 
|  | 1468 | "armv7hl-redhat-linux-gnueabi"}; | 
|  | 1469 | static const char *const ARMebLibDirs[] = {"/lib"}; | 
|  | 1470 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", | 
|  | 1471 | "armeb-linux-androideabi"}; | 
|  | 1472 | static const char *const ARMebHFTriples[] = { | 
|  | 1473 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1474 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1475 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1476 | static const char *const X86_64Triples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1477 | "x86_64-linux-gnu",       "x86_64-unknown-linux-gnu", | 
|  | 1478 | "x86_64-pc-linux-gnu",    "x86_64-redhat-linux6E", | 
|  | 1479 | "x86_64-redhat-linux",    "x86_64-suse-linux", | 
|  | 1480 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", | 
|  | 1481 | "x86_64-slackware-linux", "x86_64-linux-android", | 
|  | 1482 | "x86_64-unknown-linux"}; | 
|  | 1483 | static const char *const X32LibDirs[] = {"/libx32"}; | 
|  | 1484 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1485 | static const char *const X86Triples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1486 | "i686-linux-gnu",       "i686-pc-linux-gnu",     "i486-linux-gnu", | 
|  | 1487 | "i386-linux-gnu",       "i386-redhat-linux6E",   "i686-redhat-linux", | 
|  | 1488 | "i586-redhat-linux",    "i386-redhat-linux",     "i586-suse-linux", | 
|  | 1489 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", | 
|  | 1490 | "i586-linux-gnu"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1491 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1492 | static const char *const MIPSLibDirs[] = {"/lib"}; | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1493 | static const char *const MIPSTriples[] = {"mips-linux-gnu", "mips-mti-linux", | 
|  | 1494 | "mips-mti-linux-gnu", | 
|  | 1495 | "mips-img-linux-gnu"}; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1496 | static const char *const MIPSELLibDirs[] = {"/lib"}; | 
|  | 1497 | static const char *const MIPSELTriples[] = { | 
|  | 1498 | "mipsel-linux-gnu", "mipsel-linux-android", "mips-img-linux-gnu"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1499 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1500 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1501 | static const char *const MIPS64Triples[] = { | 
|  | 1502 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", | 
|  | 1503 | "mips64-linux-gnuabi64"}; | 
|  | 1504 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; | 
|  | 1505 | static const char *const MIPS64ELTriples[] = { | 
|  | 1506 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", | 
|  | 1507 | "mips64el-linux-android", "mips64el-linux-gnuabi64"}; | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1508 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1509 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1510 | static const char *const PPCTriples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1511 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", | 
|  | 1512 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; | 
|  | 1513 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1514 | static const char *const PPC64Triples[] = { | 
|  | 1515 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", | 
|  | 1516 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; | 
|  | 1517 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; | 
|  | 1518 | static const char *const PPC64LETriples[] = { | 
|  | 1519 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", | 
|  | 1520 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; | 
| 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 SPARCv8LibDirs[] = {"/lib32", "/lib"}; | 
|  | 1523 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", | 
|  | 1524 | "sparcv8-linux-gnu"}; | 
|  | 1525 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1526 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", | 
|  | 1527 | "sparcv9-linux-gnu"}; | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1528 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1529 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1530 | static const char *const SystemZTriples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1531 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", | 
|  | 1532 | "s390x-suse-linux", "s390x-redhat-linux"}; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1533 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1534 | // Solaris. | 
|  | 1535 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; | 
|  | 1536 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", | 
|  | 1537 | "i386-pc-solaris2.11"}; | 
|  | 1538 |  | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1539 | using std::begin; | 
|  | 1540 | using std::end; | 
|  | 1541 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1542 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { | 
|  | 1543 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); | 
|  | 1544 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1545 | return; | 
|  | 1546 | } | 
|  | 1547 |  | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1548 | switch (TargetTriple.getArch()) { | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1549 | case llvm::Triple::aarch64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1550 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); | 
|  | 1551 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); | 
|  | 1552 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); | 
|  | 1553 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1554 | break; | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1555 | case llvm::Triple::aarch64_be: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1556 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); | 
|  | 1557 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); | 
|  | 1558 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); | 
|  | 1559 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1560 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1561 | case llvm::Triple::arm: | 
|  | 1562 | case llvm::Triple::thumb: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1563 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1564 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1565 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1566 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1567 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1568 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1569 | break; | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1570 | case llvm::Triple::armeb: | 
|  | 1571 | case llvm::Triple::thumbeb: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1572 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1573 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1574 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1575 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1576 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1577 | } | 
|  | 1578 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1579 | case llvm::Triple::x86_64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1580 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); | 
|  | 1581 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
|  | 1582 | // x32 is always available when x86_64 is available, so adding it as | 
|  | 1583 | // secondary arch with x86_64 triples | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1584 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1585 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); | 
|  | 1586 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1587 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1588 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); | 
|  | 1589 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1590 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1591 | break; | 
|  | 1592 | case llvm::Triple::x86: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1593 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); | 
|  | 1594 | TripleAliases.append(begin(X86Triples), end(X86Triples)); | 
|  | 1595 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); | 
|  | 1596 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1597 | break; | 
|  | 1598 | case llvm::Triple::mips: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1599 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); | 
|  | 1600 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
|  | 1601 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); | 
|  | 1602 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1603 | break; | 
|  | 1604 | case llvm::Triple::mipsel: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1605 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); | 
|  | 1606 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); | 
|  | 1607 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
|  | 1608 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); | 
|  | 1609 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1610 | break; | 
|  | 1611 | case llvm::Triple::mips64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1612 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); | 
|  | 1613 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); | 
|  | 1614 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); | 
|  | 1615 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1616 | break; | 
|  | 1617 | case llvm::Triple::mips64el: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1618 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); | 
|  | 1619 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); | 
|  | 1620 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); | 
|  | 1621 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); | 
|  | 1622 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1623 | break; | 
|  | 1624 | case llvm::Triple::ppc: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1625 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); | 
|  | 1626 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); | 
|  | 1627 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); | 
|  | 1628 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1629 | break; | 
|  | 1630 | case llvm::Triple::ppc64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1631 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); | 
|  | 1632 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); | 
|  | 1633 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); | 
|  | 1634 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1635 | break; | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1636 | case llvm::Triple::ppc64le: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1637 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); | 
|  | 1638 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1639 | break; | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1640 | case llvm::Triple::sparc: | 
| Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1641 | case llvm::Triple::sparcel: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1642 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); | 
|  | 1643 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); | 
|  | 1644 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); | 
|  | 1645 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1646 | break; | 
|  | 1647 | case llvm::Triple::sparcv9: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1648 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); | 
|  | 1649 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); | 
|  | 1650 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); | 
|  | 1651 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1652 | break; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1653 | case llvm::Triple::systemz: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1654 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); | 
|  | 1655 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1656 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1657 | default: | 
|  | 1658 | // By default, just rely on the standard lib directories and the original | 
|  | 1659 | // triple. | 
|  | 1660 | break; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1661 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1662 |  | 
|  | 1663 | // Always append the drivers target triple to the end, in case it doesn't | 
|  | 1664 | // match any of our aliases. | 
|  | 1665 | TripleAliases.push_back(TargetTriple.str()); | 
|  | 1666 |  | 
|  | 1667 | // Also include the multiarch variant if it's different. | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1668 | if (TargetTriple.str() != BiarchTriple.str()) | 
|  | 1669 | BiarchTripleAliases.push_back(BiarchTriple.str()); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1670 | } | 
|  | 1671 |  | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1672 | // \brief -- try common CUDA installation paths looking for files we need for | 
|  | 1673 | // CUDA compilation. | 
|  | 1674 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1675 | void Generic_GCC::CudaInstallationDetector::init( | 
|  | 1676 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { | 
| NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1677 | SmallVector<std::string, 4> CudaPathCandidates; | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1678 |  | 
|  | 1679 | if (Args.hasArg(options::OPT_cuda_path_EQ)) | 
|  | 1680 | CudaPathCandidates.push_back( | 
|  | 1681 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); | 
|  | 1682 | else { | 
|  | 1683 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 1684 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.5"); | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1685 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); | 
|  | 1686 | } | 
|  | 1687 |  | 
| Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1688 | for (const auto &CudaPath : CudaPathCandidates) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1689 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1690 | continue; | 
|  | 1691 |  | 
|  | 1692 | CudaInstallPath = CudaPath; | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 1693 | CudaBinPath = CudaPath + "/bin"; | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1694 | CudaIncludePath = CudaInstallPath + "/include"; | 
|  | 1695 | CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice"; | 
|  | 1696 | CudaLibPath = | 
|  | 1697 | CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); | 
|  | 1698 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1699 | if (!(D.getVFS().exists(CudaIncludePath) && | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 1700 | D.getVFS().exists(CudaBinPath) && D.getVFS().exists(CudaLibPath) && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1701 | D.getVFS().exists(CudaLibDevicePath))) | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1702 | continue; | 
|  | 1703 |  | 
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1704 | std::error_code EC; | 
|  | 1705 | for (llvm::sys::fs::directory_iterator LI(CudaLibDevicePath, EC), LE; | 
|  | 1706 | !EC && LI != LE; LI = LI.increment(EC)) { | 
|  | 1707 | StringRef FilePath = LI->path(); | 
|  | 1708 | StringRef FileName = llvm::sys::path::filename(FilePath); | 
|  | 1709 | // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc | 
|  | 1710 | const StringRef LibDeviceName = "libdevice."; | 
|  | 1711 | if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc"))) | 
|  | 1712 | continue; | 
|  | 1713 | StringRef GpuArch = FileName.slice( | 
|  | 1714 | LibDeviceName.size(), FileName.find('.', LibDeviceName.size())); | 
|  | 1715 | CudaLibDeviceMap[GpuArch] = FilePath.str(); | 
|  | 1716 | // Insert map entries for specifc devices with this compute capability. | 
|  | 1717 | if (GpuArch == "compute_20") { | 
|  | 1718 | CudaLibDeviceMap["sm_20"] = FilePath; | 
|  | 1719 | CudaLibDeviceMap["sm_21"] = FilePath; | 
|  | 1720 | } else if (GpuArch == "compute_30") { | 
|  | 1721 | CudaLibDeviceMap["sm_30"] = FilePath; | 
|  | 1722 | CudaLibDeviceMap["sm_32"] = FilePath; | 
|  | 1723 | } else if (GpuArch == "compute_35") { | 
|  | 1724 | CudaLibDeviceMap["sm_35"] = FilePath; | 
|  | 1725 | CudaLibDeviceMap["sm_37"] = FilePath; | 
|  | 1726 | } | 
|  | 1727 | } | 
|  | 1728 |  | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1729 | IsValid = true; | 
|  | 1730 | break; | 
|  | 1731 | } | 
|  | 1732 | } | 
|  | 1733 |  | 
|  | 1734 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { | 
|  | 1735 | if (isValid()) | 
|  | 1736 | OS << "Found CUDA installation: " << CudaInstallPath << "\n"; | 
|  | 1737 | } | 
|  | 1738 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1739 | namespace { | 
|  | 1740 | // 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] | 1741 | class FilterNonExistent { | 
|  | 1742 | StringRef Base; | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1743 | vfs::FileSystem &VFS; | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1744 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1745 | public: | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1746 | FilterNonExistent(StringRef Base, vfs::FileSystem &VFS) | 
|  | 1747 | : Base(Base), VFS(VFS) {} | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1748 | bool operator()(const Multilib &M) { | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1749 | return !VFS.exists(Base + M.gccSuffix() + "/crtbegin.o"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1750 | } | 
|  | 1751 | }; | 
|  | 1752 | } // end anonymous namespace | 
|  | 1753 |  | 
|  | 1754 | static void addMultilibFlag(bool Enabled, const char *const Flag, | 
|  | 1755 | std::vector<std::string> &Flags) { | 
|  | 1756 | if (Enabled) | 
|  | 1757 | Flags.push_back(std::string("+") + Flag); | 
|  | 1758 | else | 
|  | 1759 | Flags.push_back(std::string("-") + Flag); | 
|  | 1760 | } | 
|  | 1761 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1762 | static bool isMipsArch(llvm::Triple::ArchType Arch) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1763 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || | 
|  | 1764 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; | 
|  | 1765 | } | 
|  | 1766 |  | 
|  | 1767 | static bool isMips32(llvm::Triple::ArchType Arch) { | 
|  | 1768 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; | 
|  | 1769 | } | 
|  | 1770 |  | 
|  | 1771 | static bool isMips64(llvm::Triple::ArchType Arch) { | 
|  | 1772 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; | 
|  | 1773 | } | 
|  | 1774 |  | 
|  | 1775 | static bool isMipsEL(llvm::Triple::ArchType Arch) { | 
|  | 1776 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; | 
|  | 1777 | } | 
|  | 1778 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1779 | static bool isMips16(const ArgList &Args) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1780 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1781 | return A && A->getOption().matches(options::OPT_mips16); | 
|  | 1782 | } | 
|  | 1783 |  | 
|  | 1784 | static bool isMicroMips(const ArgList &Args) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1785 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1786 | return A && A->getOption().matches(options::OPT_mmicromips); | 
|  | 1787 | } | 
|  | 1788 |  | 
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1789 | namespace { | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1790 | struct DetectedMultilibs { | 
|  | 1791 | /// The set of multilibs that the detected installation supports. | 
|  | 1792 | MultilibSet Multilibs; | 
|  | 1793 |  | 
|  | 1794 | /// The primary multilib appropriate for the given flags. | 
|  | 1795 | Multilib SelectedMultilib; | 
|  | 1796 |  | 
|  | 1797 | /// On Biarch systems, this corresponds to the default multilib when | 
|  | 1798 | /// targeting the non-default multilib. Otherwise, it is empty. | 
|  | 1799 | llvm::Optional<Multilib> BiarchSibling; | 
|  | 1800 | }; | 
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1801 | } // end anonymous namespace | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1802 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1803 | static Multilib makeMultilib(StringRef commonSuffix) { | 
|  | 1804 | return Multilib(commonSuffix, commonSuffix, commonSuffix); | 
|  | 1805 | } | 
|  | 1806 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1807 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, | 
|  | 1808 | StringRef Path, const ArgList &Args, | 
|  | 1809 | DetectedMultilibs &Result) { | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 1810 | // Some MIPS toolchains put libraries and object files compiled | 
|  | 1811 | // using different options in to the sub-directoris which names | 
|  | 1812 | // reflects the flags used for compilation. For example sysroot | 
|  | 1813 | // directory might looks like the following examples: | 
|  | 1814 | // | 
|  | 1815 | // /usr | 
|  | 1816 | //   /lib      <= crt*.o files compiled with '-mips32' | 
|  | 1817 | // /mips16 | 
|  | 1818 | //   /usr | 
|  | 1819 | //     /lib    <= crt*.o files compiled with '-mips16' | 
|  | 1820 | //   /el | 
|  | 1821 | //     /usr | 
|  | 1822 | //       /lib  <= crt*.o files compiled with '-mips16 -EL' | 
|  | 1823 | // | 
|  | 1824 | // or | 
|  | 1825 | // | 
|  | 1826 | // /usr | 
|  | 1827 | //   /lib      <= crt*.o files compiled with '-mips32r2' | 
|  | 1828 | // /mips16 | 
|  | 1829 | //   /usr | 
|  | 1830 | //     /lib    <= crt*.o files compiled with '-mips32r2 -mips16' | 
|  | 1831 | // /mips32 | 
|  | 1832 | //     /usr | 
|  | 1833 | //       /lib  <= crt*.o files compiled with '-mips32' | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 1834 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1835 | FilterNonExistent NonExistent(Path, D.getVFS()); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 1836 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1837 | // Check for FSF toolchain multilibs | 
|  | 1838 | MultilibSet FSFMipsMultilibs; | 
|  | 1839 | { | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1840 | auto MArchMips32 = makeMultilib("/mips32") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1841 | .flag("+m32") | 
|  | 1842 | .flag("-m64") | 
|  | 1843 | .flag("-mmicromips") | 
|  | 1844 | .flag("+march=mips32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1845 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1846 | auto MArchMicroMips = makeMultilib("/micromips") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1847 | .flag("+m32") | 
|  | 1848 | .flag("-m64") | 
|  | 1849 | .flag("+mmicromips"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1850 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1851 | auto MArchMips64r2 = makeMultilib("/mips64r2") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1852 | .flag("-m32") | 
|  | 1853 | .flag("+m64") | 
|  | 1854 | .flag("+march=mips64r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1855 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1856 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( | 
|  | 1857 | "-march=mips64r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1858 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1859 | auto MArchDefault = makeMultilib("") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1860 | .flag("+m32") | 
|  | 1861 | .flag("-m64") | 
|  | 1862 | .flag("-mmicromips") | 
|  | 1863 | .flag("+march=mips32r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1864 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1865 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1866 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1867 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); | 
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1868 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1869 | auto MAbi64 = | 
|  | 1870 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1871 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1872 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1873 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1874 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1875 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1876 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1877 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1878 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1879 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1880 | FSFMipsMultilibs = | 
|  | 1881 | MultilibSet() | 
|  | 1882 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, | 
|  | 1883 | MArchDefault) | 
|  | 1884 | .Maybe(UCLibc) | 
|  | 1885 | .Maybe(Mips16) | 
|  | 1886 | .FilterOut("/mips64/mips16") | 
|  | 1887 | .FilterOut("/mips64r2/mips16") | 
|  | 1888 | .FilterOut("/micromips/mips16") | 
|  | 1889 | .Maybe(MAbi64) | 
|  | 1890 | .FilterOut("/micromips/64") | 
|  | 1891 | .FilterOut("/mips32/64") | 
|  | 1892 | .FilterOut("^/64") | 
|  | 1893 | .FilterOut("/mips16/64") | 
|  | 1894 | .Either(BigEndian, LittleEndian) | 
|  | 1895 | .Maybe(SoftFloat) | 
|  | 1896 | .Maybe(Nan2008) | 
|  | 1897 | .FilterOut(".*sof/nan2008") | 
|  | 1898 | .FilterOut(NonExistent) | 
|  | 1899 | .setIncludeDirsCallback([](StringRef InstallDir, | 
|  | 1900 | StringRef TripleStr, const Multilib &M) { | 
|  | 1901 | std::vector<std::string> Dirs; | 
|  | 1902 | Dirs.push_back((InstallDir + "/include").str()); | 
|  | 1903 | std::string SysRootInc = | 
|  | 1904 | InstallDir.str() + "/../../../../sysroot"; | 
|  | 1905 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) | 
|  | 1906 | Dirs.push_back(SysRootInc + "/uclibc/usr/include"); | 
|  | 1907 | else | 
|  | 1908 | Dirs.push_back(SysRootInc + "/usr/include"); | 
|  | 1909 | return Dirs; | 
|  | 1910 | }); | 
| Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1911 | } | 
|  | 1912 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1913 | // Check for Musl toolchain multilibs | 
|  | 1914 | MultilibSet MuslMipsMultilibs; | 
|  | 1915 | { | 
|  | 1916 | auto MArchMipsR2 = makeMultilib("") | 
|  | 1917 | .osSuffix("/mips-r2-hard-musl") | 
|  | 1918 | .flag("+EB") | 
|  | 1919 | .flag("-EL") | 
|  | 1920 | .flag("+march=mips32r2"); | 
|  | 1921 |  | 
|  | 1922 | auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl") | 
|  | 1923 | .flag("-EB") | 
|  | 1924 | .flag("+EL") | 
|  | 1925 | .flag("+march=mips32r2"); | 
|  | 1926 |  | 
|  | 1927 | MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2); | 
|  | 1928 |  | 
|  | 1929 | // Specify the callback that computes the include directories. | 
|  | 1930 | MuslMipsMultilibs.setIncludeDirsCallback([]( | 
|  | 1931 | StringRef InstallDir, StringRef TripleStr, const Multilib &M) { | 
|  | 1932 | std::vector<std::string> Dirs; | 
|  | 1933 | Dirs.push_back( | 
|  | 1934 | (InstallDir + "/../sysroot" + M.osSuffix() + "/usr/include").str()); | 
|  | 1935 | return Dirs; | 
|  | 1936 | }); | 
|  | 1937 | } | 
|  | 1938 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1939 | // Check for Code Sourcery toolchain multilibs | 
|  | 1940 | MultilibSet CSMipsMultilibs; | 
|  | 1941 | { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1942 | auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); | 
| Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1943 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1944 | auto MArchMicroMips = | 
|  | 1945 | makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1946 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1947 | auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1948 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1949 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); | 
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1950 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1951 | auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1952 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1953 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1954 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1955 | auto DefaultFloat = | 
|  | 1956 | makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1957 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1958 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1959 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1960 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1961 |  | 
|  | 1962 | // Note that this one's osSuffix is "" | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1963 | auto MAbi64 = makeMultilib("") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1964 | .gccSuffix("/64") | 
|  | 1965 | .includeSuffix("/64") | 
|  | 1966 | .flag("+mabi=n64") | 
|  | 1967 | .flag("-mabi=n32") | 
|  | 1968 | .flag("-m32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1969 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1970 | CSMipsMultilibs = | 
|  | 1971 | MultilibSet() | 
|  | 1972 | .Either(MArchMips16, MArchMicroMips, MArchDefault) | 
|  | 1973 | .Maybe(UCLibc) | 
|  | 1974 | .Either(SoftFloat, Nan2008, DefaultFloat) | 
|  | 1975 | .FilterOut("/micromips/nan2008") | 
|  | 1976 | .FilterOut("/mips16/nan2008") | 
|  | 1977 | .Either(BigEndian, LittleEndian) | 
|  | 1978 | .Maybe(MAbi64) | 
|  | 1979 | .FilterOut("/mips16.*/64") | 
|  | 1980 | .FilterOut("/micromips.*/64") | 
|  | 1981 | .FilterOut(NonExistent) | 
|  | 1982 | .setIncludeDirsCallback([](StringRef InstallDir, | 
|  | 1983 | StringRef TripleStr, const Multilib &M) { | 
|  | 1984 | std::vector<std::string> Dirs; | 
|  | 1985 | Dirs.push_back((InstallDir + "/include").str()); | 
|  | 1986 | std::string SysRootInc = | 
|  | 1987 | InstallDir.str() + "/../../../../" + TripleStr.str(); | 
|  | 1988 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) | 
|  | 1989 | Dirs.push_back(SysRootInc + "/libc/uclibc/usr/include"); | 
|  | 1990 | else | 
|  | 1991 | Dirs.push_back(SysRootInc + "/libc/usr/include"); | 
|  | 1992 | return Dirs; | 
|  | 1993 | }); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1994 | } | 
|  | 1995 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1996 | MultilibSet AndroidMipsMultilibs = | 
|  | 1997 | MultilibSet() | 
|  | 1998 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) | 
|  | 1999 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) | 
|  | 2000 | .FilterOut(NonExistent); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2001 |  | 
|  | 2002 | MultilibSet DebianMipsMultilibs; | 
|  | 2003 | { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2004 | Multilib MAbiN32 = | 
|  | 2005 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2006 |  | 
|  | 2007 | Multilib M64 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2008 | .gccSuffix("/64") | 
|  | 2009 | .includeSuffix("/64") | 
|  | 2010 | .flag("+m64") | 
|  | 2011 | .flag("-m32") | 
|  | 2012 | .flag("-mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2013 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2014 | Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2015 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2016 | DebianMipsMultilibs = | 
|  | 2017 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2018 | } | 
|  | 2019 |  | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2020 | MultilibSet ImgMultilibs; | 
|  | 2021 | { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2022 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2023 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2024 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2025 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2026 | auto MAbi64 = | 
|  | 2027 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2028 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2029 | ImgMultilibs = | 
|  | 2030 | MultilibSet() | 
|  | 2031 | .Maybe(Mips64r6) | 
|  | 2032 | .Maybe(MAbi64) | 
|  | 2033 | .Maybe(LittleEndian) | 
|  | 2034 | .FilterOut(NonExistent) | 
|  | 2035 | .setIncludeDirsCallback([](StringRef InstallDir, | 
|  | 2036 | StringRef TripleStr, const Multilib &M) { | 
|  | 2037 | std::vector<std::string> Dirs; | 
|  | 2038 | Dirs.push_back((InstallDir + "/include").str()); | 
|  | 2039 | Dirs.push_back( | 
|  | 2040 | (InstallDir + "/../../../../sysroot/usr/include").str()); | 
|  | 2041 | return Dirs; | 
|  | 2042 | }); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2043 | } | 
|  | 2044 |  | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2045 | StringRef CPUName; | 
|  | 2046 | StringRef ABIName; | 
|  | 2047 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); | 
|  | 2048 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2049 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); | 
|  | 2050 |  | 
|  | 2051 | Multilib::flags_list Flags; | 
|  | 2052 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); | 
|  | 2053 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); | 
|  | 2054 | addMultilibFlag(isMips16(Args), "mips16", Flags); | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2055 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2056 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || | 
| Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 2057 | CPUName == "mips32r5" || CPUName == "p5600", | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2058 | "march=mips32r2", Flags); | 
| Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 2059 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2060 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2061 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || | 
|  | 2062 | CPUName == "mips64r5" || CPUName == "octeon", | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2063 | "march=mips64r2", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2064 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); | 
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2065 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); | 
| Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 2066 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", | 
|  | 2067 | Flags); | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2068 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); | 
|  | 2069 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2070 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2071 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2072 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2073 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2074 |  | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2075 | if (TargetTriple.isAndroid()) { | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2076 | // Select Android toolchain. It's the only choice in that case. | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2077 | if (AndroidMipsMultilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2078 | Result.Multilibs = AndroidMipsMultilibs; | 
|  | 2079 | return true; | 
|  | 2080 | } | 
|  | 2081 | return false; | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2082 | } | 
|  | 2083 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2084 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && | 
|  | 2085 | TargetTriple.getOS() == llvm::Triple::Linux && | 
|  | 2086 | TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) { | 
|  | 2087 | if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2088 | Result.Multilibs = MuslMipsMultilibs; | 
|  | 2089 | return true; | 
|  | 2090 | } | 
|  | 2091 | return false; | 
|  | 2092 | } | 
|  | 2093 |  | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2094 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && | 
|  | 2095 | TargetTriple.getOS() == llvm::Triple::Linux && | 
|  | 2096 | TargetTriple.getEnvironment() == llvm::Triple::GNU) { | 
|  | 2097 | // Select mips-img-linux-gnu toolchain. | 
|  | 2098 | if (ImgMultilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2099 | Result.Multilibs = ImgMultilibs; | 
|  | 2100 | return true; | 
|  | 2101 | } | 
|  | 2102 | return false; | 
|  | 2103 | } | 
|  | 2104 |  | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2105 | // Sort candidates. Toolchain that best meets the directories goes first. | 
|  | 2106 | // Then select the first toolchains matches command line flags. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2107 | MultilibSet *candidates[] = {&DebianMipsMultilibs, &FSFMipsMultilibs, | 
|  | 2108 | &CSMipsMultilibs}; | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2109 | std::sort( | 
|  | 2110 | std::begin(candidates), std::end(candidates), | 
|  | 2111 | [](MultilibSet *a, MultilibSet *b) { return a->size() > b->size(); }); | 
|  | 2112 | for (const auto &candidate : candidates) { | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2113 | if (candidate->select(Flags, Result.SelectedMultilib)) { | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2114 | if (candidate == &DebianMipsMultilibs) | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2115 | Result.BiarchSibling = Multilib(); | 
|  | 2116 | Result.Multilibs = *candidate; | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2117 | return true; | 
|  | 2118 | } | 
|  | 2119 | } | 
|  | 2120 |  | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2121 | { | 
|  | 2122 | // Fallback to the regular toolchain-tree structure. | 
|  | 2123 | Multilib Default; | 
|  | 2124 | Result.Multilibs.push_back(Default); | 
|  | 2125 | Result.Multilibs.FilterOut(NonExistent); | 
|  | 2126 |  | 
|  | 2127 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2128 | Result.BiarchSibling = Multilib(); | 
|  | 2129 | return true; | 
|  | 2130 | } | 
|  | 2131 | } | 
|  | 2132 |  | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2133 | return false; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2134 | } | 
|  | 2135 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2136 | static bool findBiarchMultilibs(const Driver &D, | 
|  | 2137 | const llvm::Triple &TargetTriple, | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2138 | StringRef Path, const ArgList &Args, | 
|  | 2139 | bool NeedsBiarchSuffix, | 
|  | 2140 | DetectedMultilibs &Result) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2141 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs | 
|  | 2142 | // in what would normally be GCCInstallPath and put the 64-bit | 
|  | 2143 | // libs in a subdirectory named 64. The simple logic we follow is that | 
|  | 2144 | // *if* there is a subdirectory of the right name with crtbegin.o in it, | 
|  | 2145 | // we use that. If not, and if not a biarch triple alias, we look for | 
|  | 2146 | // crtbegin.o without the subdirectory. | 
|  | 2147 |  | 
|  | 2148 | Multilib Default; | 
|  | 2149 | Multilib Alt64 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2150 | .gccSuffix("/64") | 
|  | 2151 | .includeSuffix("/64") | 
|  | 2152 | .flag("-m32") | 
|  | 2153 | .flag("+m64") | 
|  | 2154 | .flag("-mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2155 | Multilib Alt32 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2156 | .gccSuffix("/32") | 
|  | 2157 | .includeSuffix("/32") | 
|  | 2158 | .flag("+m32") | 
|  | 2159 | .flag("-m64") | 
|  | 2160 | .flag("-mx32"); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2161 | Multilib Altx32 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2162 | .gccSuffix("/x32") | 
|  | 2163 | .includeSuffix("/x32") | 
|  | 2164 | .flag("-m32") | 
|  | 2165 | .flag("-m64") | 
|  | 2166 | .flag("+mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2167 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2168 | FilterNonExistent NonExistent(Path, D.getVFS()); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2169 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2170 | // Determine default multilib from: 32, 64, x32 | 
|  | 2171 | // Also handle cases such as 64 on 32, 32 on 64, etc. | 
|  | 2172 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; | 
| David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2173 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; | 
| Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2174 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2175 | Want = WANT64; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2176 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2177 | Want = WANT64; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2178 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2179 | Want = WANT32; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2180 | else { | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2181 | if (TargetTriple.isArch32Bit()) | 
|  | 2182 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2183 | else if (IsX32) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2184 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2185 | else | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2186 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; | 
| Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2187 | } | 
|  | 2188 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2189 | if (Want == WANT32) | 
|  | 2190 | Default.flag("+m32").flag("-m64").flag("-mx32"); | 
|  | 2191 | else if (Want == WANT64) | 
|  | 2192 | Default.flag("-m32").flag("+m64").flag("-mx32"); | 
|  | 2193 | else if (Want == WANTX32) | 
|  | 2194 | Default.flag("-m32").flag("-m64").flag("+mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2195 | else | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2196 | return false; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2197 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2198 | Result.Multilibs.push_back(Default); | 
|  | 2199 | Result.Multilibs.push_back(Alt64); | 
|  | 2200 | Result.Multilibs.push_back(Alt32); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2201 | Result.Multilibs.push_back(Altx32); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2202 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2203 | Result.Multilibs.FilterOut(NonExistent); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2204 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2205 | Multilib::flags_list Flags; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2206 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2207 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2208 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2209 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2210 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2211 | return false; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2212 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2213 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2214 | Result.SelectedMultilib == Altx32) | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2215 | Result.BiarchSibling = Default; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2216 |  | 
|  | 2217 | return true; | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2218 | } | 
|  | 2219 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2220 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( | 
|  | 2221 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, | 
|  | 2222 | const std::string &LibDir, StringRef CandidateTriple, | 
|  | 2223 | bool NeedsBiarchSuffix) { | 
|  | 2224 | // Solaris is a special case. The GCC installation is under | 
|  | 2225 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we | 
|  | 2226 | // need to iterate twice. | 
|  | 2227 | std::error_code EC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2228 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; | 
|  | 2229 | !EC && LI != LE; LI = LI.increment(EC)) { | 
|  | 2230 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2231 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); | 
|  | 2232 |  | 
|  | 2233 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2234 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2235 | continue; // Saw this path before; no need to look at it again. | 
|  | 2236 | if (CandidateVersion.isOlderThan(4, 1, 1)) | 
|  | 2237 | continue; | 
|  | 2238 | if (CandidateVersion <= Version) | 
|  | 2239 | continue; | 
|  | 2240 |  | 
|  | 2241 | GCCInstallPath = | 
|  | 2242 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2243 | if (!D.getVFS().exists(GCCInstallPath)) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2244 | continue; | 
|  | 2245 |  | 
|  | 2246 | // If we make it here there has to be at least one GCC version, let's just | 
|  | 2247 | // use the latest one. | 
|  | 2248 | std::error_code EEC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2249 | for (vfs::directory_iterator | 
|  | 2250 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), | 
|  | 2251 | LLE; | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2252 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { | 
|  | 2253 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2254 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2255 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); | 
|  | 2256 |  | 
|  | 2257 | if (CandidateSubVersion > Version) | 
|  | 2258 | Version = CandidateSubVersion; | 
|  | 2259 | } | 
|  | 2260 |  | 
|  | 2261 | GCCTriple.setTriple(CandidateTriple); | 
|  | 2262 |  | 
|  | 2263 | GCCInstallPath += "/" + Version.Text; | 
|  | 2264 | GCCParentLibPath = GCCInstallPath + "/../../../../"; | 
|  | 2265 |  | 
|  | 2266 | IsValid = true; | 
|  | 2267 | } | 
|  | 2268 | } | 
|  | 2269 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2270 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2271 | const llvm::Triple &TargetTriple, const ArgList &Args, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2272 | const std::string &LibDir, StringRef CandidateTriple, | 
|  | 2273 | bool NeedsBiarchSuffix) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2274 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2275 | // There are various different suffixes involving the triple we | 
|  | 2276 | // 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] | 2277 | // up to the lib directory. Specifically, the number of "up" steps | 
|  | 2278 | // in the second half of each row is 1 + the number of path separators | 
|  | 2279 | // in the first half. | 
|  | 2280 | const std::string LibAndInstallSuffixes[][2] = { | 
|  | 2281 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, | 
|  | 2282 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2283 | // Debian puts cross-compilers in gcc-cross | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2284 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, | 
|  | 2285 |  | 
|  | 2286 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), | 
|  | 2287 | "/../../../.."}, | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2288 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2289 | // The Freescale PPC SDK has the gcc libraries in | 
|  | 2290 | // <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] | 2291 | {"/" + CandidateTriple.str(), "/../.."}, | 
| Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2292 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2293 | // Ubuntu has a strange mis-matched pair of triples that this happens to | 
|  | 2294 | // match. | 
|  | 2295 | // FIXME: It may be worthwhile to generalize this and look for a second | 
|  | 2296 | // triple. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2297 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; | 
|  | 2298 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2299 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { | 
|  | 2300 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, | 
|  | 2301 | NeedsBiarchSuffix); | 
|  | 2302 | return; | 
|  | 2303 | } | 
|  | 2304 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2305 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2306 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - | 
|  | 2307 | (TargetArch != llvm::Triple::x86)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2308 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2309 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; | 
| Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2310 | std::error_code EC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2311 | for (vfs::directory_iterator | 
|  | 2312 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), | 
|  | 2313 | LE; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2314 | !EC && LI != LE; LI = LI.increment(EC)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2315 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2316 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); | 
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2317 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2318 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) | 
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2319 | continue; // Saw this path before; no need to look at it again. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2320 | if (CandidateVersion.isOlderThan(4, 1, 1)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2321 | continue; | 
|  | 2322 | if (CandidateVersion <= Version) | 
|  | 2323 | continue; | 
| Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2324 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2325 | DetectedMultilibs Detected; | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2326 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2327 | // Debian mips multilibs behave more like the rest of the biarch ones, | 
|  | 2328 | // so handle them there | 
|  | 2329 | if (isMipsArch(TargetArch)) { | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2330 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2331 | continue; | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2332 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2333 | NeedsBiarchSuffix, Detected)) { | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2334 | continue; | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2335 | } | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2336 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2337 | Multilibs = Detected.Multilibs; | 
|  | 2338 | SelectedMultilib = Detected.SelectedMultilib; | 
|  | 2339 | BiarchSibling = Detected.BiarchSibling; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2340 | Version = CandidateVersion; | 
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2341 | GCCTriple.setTriple(CandidateTriple); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2342 | // FIXME: We hack together the directory name here instead of | 
|  | 2343 | // using LI to ensure stable path separators across Windows and | 
|  | 2344 | // Linux. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2345 | GCCInstallPath = | 
|  | 2346 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); | 
|  | 2347 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2348 | IsValid = true; | 
|  | 2349 | } | 
|  | 2350 | } | 
|  | 2351 | } | 
|  | 2352 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2353 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2354 | const ArgList &Args) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2355 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2356 | getProgramPaths().push_back(getDriver().getInstalledDir()); | 
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2357 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2358 | getProgramPaths().push_back(getDriver().Dir); | 
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2359 | } | 
|  | 2360 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2361 | Generic_GCC::~Generic_GCC() {} | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2362 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2363 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { | 
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2364 | switch (AC) { | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2365 | case Action::PreprocessJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2366 | if (!Preprocess) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2367 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2368 | return Preprocess.get(); | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2369 | case Action::CompileJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2370 | if (!Compile) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2371 | Compile.reset(new tools::gcc::Compiler(*this)); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2372 | return Compile.get(); | 
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2373 | default: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2374 | return ToolChain::getTool(AC); | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2375 | } | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2376 | } | 
|  | 2377 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2378 | Tool *Generic_GCC::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2379 | return new tools::gnutools::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2380 | } | 
|  | 2381 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2382 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2383 |  | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2384 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { | 
|  | 2385 | // Print the information about how we detected the GCC installation. | 
|  | 2386 | GCCInstallation.print(OS); | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2387 | CudaInstallation.print(OS); | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2388 | } | 
|  | 2389 |  | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2390 | bool Generic_GCC::IsUnwindTablesDefault() const { | 
| Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2391 | return getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2392 | } | 
|  | 2393 |  | 
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2394 | bool Generic_GCC::isPICDefault() const { | 
|  | 2395 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); | 
|  | 2396 | } | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2397 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2398 | bool Generic_GCC::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2399 |  | 
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2400 | bool Generic_GCC::isPICDefaultForced() const { | 
|  | 2401 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); | 
|  | 2402 | } | 
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2403 |  | 
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2404 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2405 | switch (getTriple().getArch()) { | 
|  | 2406 | case llvm::Triple::x86: | 
|  | 2407 | case llvm::Triple::x86_64: | 
|  | 2408 | case llvm::Triple::aarch64: | 
|  | 2409 | case llvm::Triple::aarch64_be: | 
|  | 2410 | case llvm::Triple::arm: | 
|  | 2411 | case llvm::Triple::armeb: | 
| Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2412 | case llvm::Triple::bpfel: | 
|  | 2413 | case llvm::Triple::bpfeb: | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2414 | case llvm::Triple::thumb: | 
|  | 2415 | case llvm::Triple::thumbeb: | 
|  | 2416 | case llvm::Triple::ppc: | 
|  | 2417 | case llvm::Triple::ppc64: | 
|  | 2418 | case llvm::Triple::ppc64le: | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2419 | case llvm::Triple::systemz: | 
|  | 2420 | return true; | 
|  | 2421 | default: | 
|  | 2422 | return false; | 
|  | 2423 | } | 
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2424 | } | 
|  | 2425 |  | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2426 | /// \brief Helper to add the variant paths of a libstdc++ installation. | 
|  | 2427 | bool Generic_GCC::addLibStdCXXIncludePaths( | 
|  | 2428 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, | 
|  | 2429 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, | 
|  | 2430 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2431 | if (!getVFS().exists(Base + Suffix)) | 
|  | 2432 | return false; | 
|  | 2433 |  | 
|  | 2434 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); | 
|  | 2435 |  | 
|  | 2436 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If | 
|  | 2437 | // that path exists or we have neither a GCC nor target multiarch triple, use | 
|  | 2438 | // this vanilla search path. | 
|  | 2439 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || | 
|  | 2440 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { | 
|  | 2441 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2442 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); | 
|  | 2443 | } else { | 
|  | 2444 | // Otherwise try to use multiarch naming schemes which have normalized the | 
|  | 2445 | // triples and put the triple before the suffix. | 
|  | 2446 | // | 
|  | 2447 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and | 
|  | 2448 | // the target triple, so we support that here. | 
|  | 2449 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2450 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); | 
|  | 2451 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2452 | Base + "/" + TargetMultiarchTriple + Suffix); | 
|  | 2453 | } | 
|  | 2454 |  | 
|  | 2455 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); | 
|  | 2456 | return true; | 
|  | 2457 | } | 
|  | 2458 |  | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2459 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 2460 | ArgStringList &CC1Args) const { | 
|  | 2461 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2462 | bool UseInitArrayDefault = | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2463 | getTriple().getArch() == llvm::Triple::aarch64 || | 
| Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2464 | getTriple().getArch() == llvm::Triple::aarch64_be || | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2465 | (getTriple().getOS() == llvm::Triple::Linux && | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2466 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2467 | getTriple().getOS() == llvm::Triple::NaCl || | 
|  | 2468 | (getTriple().getVendor() == llvm::Triple::MipsTechnologies && | 
|  | 2469 | !getTriple().hasEnvironment()); | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2470 |  | 
|  | 2471 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2472 | options::OPT_fno_use_init_array, UseInitArrayDefault)) | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2473 | CC1Args.push_back("-fuse-init-array"); | 
|  | 2474 | } | 
|  | 2475 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2476 | /// Mips Toolchain | 
|  | 2477 | MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D, | 
|  | 2478 | const llvm::Triple &Triple, | 
|  | 2479 | const ArgList &Args) | 
|  | 2480 | : Linux(D, Triple, Args) { | 
|  | 2481 | // Select the correct multilib according to the given arguments. | 
|  | 2482 | DetectedMultilibs Result; | 
|  | 2483 | findMIPSMultilibs(D, Triple, "", Args, Result); | 
|  | 2484 | Multilibs = Result.Multilibs; | 
|  | 2485 | SelectedMultilib = Result.SelectedMultilib; | 
|  | 2486 |  | 
|  | 2487 | // Find out the library suffix based on the ABI. | 
|  | 2488 | LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple); | 
|  | 2489 | getFilePaths().clear(); | 
|  | 2490 | getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix); | 
|  | 2491 |  | 
|  | 2492 | // Use LLD by default. | 
| Peter Collingbourne | 39719a7 | 2015-11-20 20:49:39 +0000 | [diff] [blame] | 2493 | DefaultLinker = "lld"; | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2494 | } | 
|  | 2495 |  | 
|  | 2496 | void MipsLLVMToolChain::AddClangSystemIncludeArgs( | 
|  | 2497 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2498 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 2499 | return; | 
|  | 2500 |  | 
|  | 2501 | const Driver &D = getDriver(); | 
|  | 2502 |  | 
|  | 2503 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
|  | 2504 | SmallString<128> P(D.ResourceDir); | 
|  | 2505 | llvm::sys::path::append(P, "include"); | 
|  | 2506 | addSystemInclude(DriverArgs, CC1Args, P); | 
|  | 2507 | } | 
|  | 2508 |  | 
|  | 2509 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 2510 | return; | 
|  | 2511 |  | 
|  | 2512 | const auto &Callback = Multilibs.includeDirsCallback(); | 
|  | 2513 | if (Callback) { | 
|  | 2514 | const auto IncludePaths = | 
|  | 2515 | Callback(D.getInstalledDir(), getTripleString(), SelectedMultilib); | 
|  | 2516 | for (const auto &Path : IncludePaths) | 
|  | 2517 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); | 
|  | 2518 | } | 
|  | 2519 | } | 
|  | 2520 |  | 
|  | 2521 | Tool *MipsLLVMToolChain::buildLinker() const { | 
|  | 2522 | return new tools::gnutools::Linker(*this); | 
|  | 2523 | } | 
|  | 2524 |  | 
|  | 2525 | std::string MipsLLVMToolChain::computeSysRoot() const { | 
|  | 2526 | if (!getDriver().SysRoot.empty()) | 
|  | 2527 | return getDriver().SysRoot + SelectedMultilib.osSuffix(); | 
|  | 2528 |  | 
|  | 2529 | const std::string InstalledDir(getDriver().getInstalledDir()); | 
|  | 2530 | std::string SysRootPath = | 
|  | 2531 | InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix(); | 
|  | 2532 | if (llvm::sys::fs::exists(SysRootPath)) | 
|  | 2533 | return SysRootPath; | 
|  | 2534 |  | 
|  | 2535 | return std::string(); | 
|  | 2536 | } | 
|  | 2537 |  | 
|  | 2538 | ToolChain::CXXStdlibType | 
|  | 2539 | MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
|  | 2540 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); | 
|  | 2541 | if (A) { | 
|  | 2542 | StringRef Value = A->getValue(); | 
|  | 2543 | if (Value != "libc++") | 
|  | 2544 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) | 
|  | 2545 | << A->getAsString(Args); | 
|  | 2546 | } | 
|  | 2547 |  | 
|  | 2548 | return ToolChain::CST_Libcxx; | 
|  | 2549 | } | 
|  | 2550 |  | 
|  | 2551 | void MipsLLVMToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 2552 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2553 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 2554 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2555 | return; | 
|  | 2556 |  | 
|  | 2557 | assert((GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) && | 
|  | 2558 | "Only -lc++ (aka libcxx) is suported in this toolchain."); | 
|  | 2559 |  | 
|  | 2560 | const auto &Callback = Multilibs.includeDirsCallback(); | 
|  | 2561 | if (Callback) { | 
|  | 2562 | const auto IncludePaths = Callback(getDriver().getInstalledDir(), | 
|  | 2563 | getTripleString(), SelectedMultilib); | 
|  | 2564 | for (const auto &Path : IncludePaths) { | 
|  | 2565 | if (llvm::sys::fs::exists(Path + "/c++/v1")) { | 
|  | 2566 | addSystemInclude(DriverArgs, CC1Args, Path + "/c++/v1"); | 
|  | 2567 | break; | 
|  | 2568 | } | 
|  | 2569 | } | 
|  | 2570 | } | 
|  | 2571 | } | 
|  | 2572 |  | 
|  | 2573 | void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 2574 | ArgStringList &CmdArgs) const { | 
|  | 2575 | assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) && | 
|  | 2576 | "Only -lc++ (aka libxx) is suported in this toolchain."); | 
|  | 2577 |  | 
|  | 2578 | CmdArgs.push_back("-lc++"); | 
|  | 2579 | CmdArgs.push_back("-lc++abi"); | 
|  | 2580 | CmdArgs.push_back("-lunwind"); | 
|  | 2581 | } | 
|  | 2582 |  | 
|  | 2583 | std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, | 
|  | 2584 | StringRef Component, | 
|  | 2585 | bool Shared) const { | 
|  | 2586 | SmallString<128> Path(getDriver().ResourceDir); | 
|  | 2587 | llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix, | 
|  | 2588 | getOS()); | 
|  | 2589 | llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" + | 
| Vasileios Kalintiris | bbc9930 | 2015-11-16 15:41:30 +0000 | [diff] [blame] | 2590 | "mips" + (Shared ? ".so" : ".a"))); | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2591 | return Path.str(); | 
|  | 2592 | } | 
|  | 2593 |  | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2594 | /// Hexagon Toolchain | 
|  | 2595 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2596 | std::string HexagonToolChain::getHexagonTargetDir( | 
|  | 2597 | const std::string &InstalledDir, | 
|  | 2598 | const SmallVectorImpl<std::string> &PrefixDirs) const { | 
|  | 2599 | std::string InstallRelDir; | 
|  | 2600 | const Driver &D = getDriver(); | 
|  | 2601 |  | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2602 | // Locate the rest of the toolchain ... | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2603 | for (auto &I : PrefixDirs) | 
|  | 2604 | if (D.getVFS().exists(I)) | 
|  | 2605 | return I; | 
| Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 2606 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2607 | if (getVFS().exists(InstallRelDir = InstalledDir + "/../target")) | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2608 | return InstallRelDir; | 
|  | 2609 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2610 | std::string PrefixRelDir = std::string(LLVM_PREFIX) + "/target"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2611 | if (getVFS().exists(PrefixRelDir)) | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2612 | return PrefixRelDir; | 
|  | 2613 |  | 
|  | 2614 | return InstallRelDir; | 
|  | 2615 | } | 
|  | 2616 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2617 | Optional<unsigned> HexagonToolChain::getSmallDataThreshold( | 
|  | 2618 | const ArgList &Args) { | 
|  | 2619 | StringRef Gn = ""; | 
|  | 2620 | if (Arg *A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, | 
|  | 2621 | options::OPT_msmall_data_threshold_EQ)) { | 
|  | 2622 | Gn = A->getValue(); | 
|  | 2623 | } else if (Args.getLastArg(options::OPT_shared, options::OPT_fpic, | 
|  | 2624 | options::OPT_fPIC)) { | 
|  | 2625 | Gn = "0"; | 
|  | 2626 | } | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2627 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2628 | unsigned G; | 
|  | 2629 | if (!Gn.getAsInteger(10, G)) | 
|  | 2630 | return G; | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2631 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2632 | return None; | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2633 | } | 
|  | 2634 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2635 | void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args, | 
|  | 2636 | ToolChain::path_list &LibPaths) const { | 
|  | 2637 | const Driver &D = getDriver(); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2638 |  | 
|  | 2639 | //---------------------------------------------------------------------------- | 
|  | 2640 | // -L Args | 
|  | 2641 | //---------------------------------------------------------------------------- | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 2642 | for (Arg *A : Args.filtered(options::OPT_L)) | 
|  | 2643 | for (const char *Value : A->getValues()) | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2644 | LibPaths.push_back(Value); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2645 |  | 
|  | 2646 | //---------------------------------------------------------------------------- | 
|  | 2647 | // Other standard paths | 
|  | 2648 | //---------------------------------------------------------------------------- | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2649 | std::vector<std::string> RootDirs; | 
| Krzysztof Parzyszek | f4467cd | 2016-01-06 14:13:11 +0000 | [diff] [blame] | 2650 | std::copy(D.PrefixDirs.begin(), D.PrefixDirs.end(), | 
|  | 2651 | std::back_inserter(RootDirs)); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2652 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2653 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2654 | D.PrefixDirs); | 
|  | 2655 | if (std::find(RootDirs.begin(), RootDirs.end(), TargetDir) == RootDirs.end()) | 
|  | 2656 | RootDirs.push_back(TargetDir); | 
|  | 2657 |  | 
|  | 2658 | bool HasPIC = Args.hasArg(options::OPT_fpic, options::OPT_fPIC); | 
|  | 2659 | // Assume G0 with -shared. | 
|  | 2660 | bool HasG0 = Args.hasArg(options::OPT_shared); | 
|  | 2661 | if (auto G = getSmallDataThreshold(Args)) | 
|  | 2662 | HasG0 = G.getValue() == 0; | 
|  | 2663 |  | 
|  | 2664 | const std::string CpuVer = GetTargetCPUVersion(Args).str(); | 
|  | 2665 | for (auto &Dir : RootDirs) { | 
|  | 2666 | std::string LibDir = Dir + "/hexagon/lib"; | 
|  | 2667 | std::string LibDirCpu = LibDir + '/' + CpuVer; | 
|  | 2668 | if (HasG0) { | 
|  | 2669 | if (HasPIC) | 
|  | 2670 | LibPaths.push_back(LibDirCpu + "/G0/pic"); | 
|  | 2671 | LibPaths.push_back(LibDirCpu + "/G0"); | 
|  | 2672 | } | 
|  | 2673 | LibPaths.push_back(LibDirCpu); | 
|  | 2674 | LibPaths.push_back(LibDir); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2675 | } | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2676 | } | 
|  | 2677 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2678 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2679 | const llvm::opt::ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2680 | : Linux(D, Triple, Args) { | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2681 | const std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2682 | D.PrefixDirs); | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2683 |  | 
|  | 2684 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to | 
|  | 2685 | // program paths | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2686 | const std::string BinDir(TargetDir + "/bin"); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2687 | if (D.getVFS().exists(BinDir)) | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2688 | getProgramPaths().push_back(BinDir); | 
|  | 2689 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2690 | ToolChain::path_list &LibPaths = getFilePaths(); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2691 |  | 
|  | 2692 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets | 
|  | 2693 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually | 
|  | 2694 | // support 'linux' we'll need to fix this up | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2695 | LibPaths.clear(); | 
|  | 2696 | getHexagonLibraryPaths(Args, LibPaths); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2697 | } | 
|  | 2698 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2699 | HexagonToolChain::~HexagonToolChain() {} | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2700 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2701 | Tool *HexagonToolChain::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2702 | return new tools::hexagon::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2703 | } | 
|  | 2704 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2705 | Tool *HexagonToolChain::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2706 | return new tools::hexagon::Linker(*this); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2707 | } | 
|  | 2708 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2709 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 2710 | ArgStringList &CC1Args) const { | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2711 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
|  | 2712 | DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 2713 | return; | 
|  | 2714 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2715 | const Driver &D = getDriver(); | 
|  | 2716 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2717 | D.PrefixDirs); | 
|  | 2718 | addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include"); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2719 | } | 
|  | 2720 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2721 | void HexagonToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 2722 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2723 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 2724 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2725 | return; | 
|  | 2726 |  | 
|  | 2727 | const Driver &D = getDriver(); | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2728 | std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs); | 
|  | 2729 | addSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include/c++"); | 
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2730 | } | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2731 |  | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2732 | ToolChain::CXXStdlibType | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2733 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2734 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); | 
|  | 2735 | if (!A) | 
|  | 2736 | return ToolChain::CST_Libstdcxx; | 
|  | 2737 |  | 
|  | 2738 | StringRef Value = A->getValue(); | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2739 | if (Value != "libstdc++") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2740 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2741 |  | 
|  | 2742 | return ToolChain::CST_Libstdcxx; | 
|  | 2743 | } | 
|  | 2744 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2745 | // | 
|  | 2746 | // Returns the default CPU for Hexagon. This is the default compilation target | 
|  | 2747 | // if no Hexagon processor is selected at the command-line. | 
|  | 2748 | // | 
|  | 2749 | const StringRef HexagonToolChain::GetDefaultCPU() { | 
|  | 2750 | return "hexagonv60"; | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2751 | } | 
|  | 2752 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2753 | const StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) { | 
|  | 2754 | Arg *CpuArg = nullptr; | 
| Krzysztof Parzyszek | 972f72c | 2016-01-06 21:12:03 +0000 | [diff] [blame] | 2755 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ, options::OPT_march_EQ)) | 
|  | 2756 | CpuArg = A; | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2757 |  | 
|  | 2758 | StringRef CPU = CpuArg ? CpuArg->getValue() : GetDefaultCPU(); | 
|  | 2759 | if (CPU.startswith("hexagon")) | 
|  | 2760 | return CPU.substr(sizeof("hexagon") - 1); | 
|  | 2761 | return CPU; | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2762 | } | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2763 | // End Hexagon | 
| Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 2764 |  | 
| Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 2765 | /// AMDGPU Toolchain | 
|  | 2766 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 2767 | const ArgList &Args) | 
|  | 2768 | : Generic_ELF(D, Triple, Args) { } | 
|  | 2769 |  | 
|  | 2770 | Tool *AMDGPUToolChain::buildLinker() const { | 
|  | 2771 | return new tools::amdgpu::Linker(*this); | 
|  | 2772 | } | 
|  | 2773 | // End AMDGPU | 
|  | 2774 |  | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2775 | /// NaCl Toolchain | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2776 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 2777 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2778 | : Generic_ELF(D, Triple, Args) { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2779 |  | 
|  | 2780 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the | 
|  | 2781 | // default paths, and must instead only use the paths provided | 
|  | 2782 | // with this toolchain based on architecture. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2783 | path_list &file_paths = getFilePaths(); | 
|  | 2784 | path_list &prog_paths = getProgramPaths(); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2785 |  | 
|  | 2786 | file_paths.clear(); | 
|  | 2787 | prog_paths.clear(); | 
|  | 2788 |  | 
|  | 2789 | // Path for library files (libc.a, ...) | 
|  | 2790 | std::string FilePath(getDriver().Dir + "/../"); | 
|  | 2791 |  | 
|  | 2792 | // Path for tools (clang, ld, etc..) | 
|  | 2793 | std::string ProgPath(getDriver().Dir + "/../"); | 
|  | 2794 |  | 
|  | 2795 | // Path for toolchain libraries (libgcc.a, ...) | 
|  | 2796 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); | 
|  | 2797 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2798 | switch (Triple.getArch()) { | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2799 | case llvm::Triple::x86: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2800 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); | 
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2801 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2802 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); | 
|  | 2803 | file_paths.push_back(ToolPath + "i686-nacl"); | 
|  | 2804 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2805 | case llvm::Triple::x86_64: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2806 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); | 
|  | 2807 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); | 
|  | 2808 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); | 
|  | 2809 | file_paths.push_back(ToolPath + "x86_64-nacl"); | 
|  | 2810 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2811 | case llvm::Triple::arm: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2812 | file_paths.push_back(FilePath + "arm-nacl/lib"); | 
|  | 2813 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); | 
|  | 2814 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); | 
|  | 2815 | file_paths.push_back(ToolPath + "arm-nacl"); | 
|  | 2816 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2817 | case llvm::Triple::mipsel: | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2818 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); | 
|  | 2819 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); | 
|  | 2820 | prog_paths.push_back(ProgPath + "bin"); | 
|  | 2821 | file_paths.push_back(ToolPath + "mipsel-nacl"); | 
|  | 2822 | break; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2823 | default: | 
|  | 2824 | break; | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2825 | } | 
|  | 2826 |  | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2827 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); | 
|  | 2828 | } | 
|  | 2829 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2830 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 2831 | ArgStringList &CC1Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2832 | const Driver &D = getDriver(); | 
|  | 2833 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 2834 | return; | 
|  | 2835 |  | 
|  | 2836 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
|  | 2837 | SmallString<128> P(D.ResourceDir); | 
|  | 2838 | llvm::sys::path::append(P, "include"); | 
|  | 2839 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2840 | } | 
|  | 2841 |  | 
|  | 2842 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 2843 | return; | 
|  | 2844 |  | 
|  | 2845 | SmallString<128> P(D.Dir + "/../"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2846 | switch (getTriple().getArch()) { | 
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2847 | case llvm::Triple::x86: | 
|  | 2848 | // x86 is special because multilib style uses x86_64-nacl/include for libc | 
|  | 2849 | // headers but the SDK wants i686-nacl/usr/include. The other architectures | 
|  | 2850 | // have the same substring. | 
|  | 2851 | llvm::sys::path::append(P, "i686-nacl/usr/include"); | 
|  | 2852 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2853 | llvm::sys::path::remove_filename(P); | 
|  | 2854 | llvm::sys::path::remove_filename(P); | 
|  | 2855 | llvm::sys::path::remove_filename(P); | 
|  | 2856 | llvm::sys::path::append(P, "x86_64-nacl/include"); | 
|  | 2857 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2858 | return; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2859 | case llvm::Triple::arm: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2860 | llvm::sys::path::append(P, "arm-nacl/usr/include"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2861 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2862 | case llvm::Triple::x86_64: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2863 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2864 | break; | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2865 | case llvm::Triple::mipsel: | 
|  | 2866 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); | 
|  | 2867 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2868 | default: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2869 | return; | 
|  | 2870 | } | 
|  | 2871 |  | 
|  | 2872 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2873 | llvm::sys::path::remove_filename(P); | 
|  | 2874 | llvm::sys::path::remove_filename(P); | 
|  | 2875 | llvm::sys::path::append(P, "include"); | 
|  | 2876 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2877 | } | 
|  | 2878 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2879 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 2880 | ArgStringList &CmdArgs) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2881 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg | 
|  | 2882 | // if the value is libc++, and emits an error for other values. | 
|  | 2883 | GetCXXStdlibType(Args); | 
|  | 2884 | CmdArgs.push_back("-lc++"); | 
|  | 2885 | } | 
|  | 2886 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2887 | void NaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 2888 | ArgStringList &CC1Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2889 | const Driver &D = getDriver(); | 
|  | 2890 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 2891 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2892 | return; | 
|  | 2893 |  | 
|  | 2894 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg | 
|  | 2895 | // if the value is libc++, and emits an error for other values. | 
|  | 2896 | GetCXXStdlibType(DriverArgs); | 
|  | 2897 |  | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2898 | SmallString<128> P(D.Dir + "/../"); | 
|  | 2899 | switch (getTriple().getArch()) { | 
|  | 2900 | case llvm::Triple::arm: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2901 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); | 
|  | 2902 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2903 | break; | 
|  | 2904 | case llvm::Triple::x86: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2905 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); | 
|  | 2906 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2907 | break; | 
|  | 2908 | case llvm::Triple::x86_64: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2909 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); | 
|  | 2910 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2911 | break; | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2912 | case llvm::Triple::mipsel: | 
|  | 2913 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); | 
|  | 2914 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2915 | break; | 
| Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 2916 | default: | 
|  | 2917 | break; | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2918 | } | 
|  | 2919 | } | 
|  | 2920 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2921 | ToolChain::CXXStdlibType | 
|  | 2922 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2923 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { | 
|  | 2924 | StringRef Value = A->getValue(); | 
|  | 2925 | if (Value == "libc++") | 
|  | 2926 | return ToolChain::CST_Libcxx; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2927 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2928 | } | 
|  | 2929 |  | 
|  | 2930 | return ToolChain::CST_Libcxx; | 
|  | 2931 | } | 
|  | 2932 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2933 | std::string | 
|  | 2934 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, | 
|  | 2935 | types::ID InputType) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2936 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); | 
|  | 2937 | if (TheTriple.getArch() == llvm::Triple::arm && | 
|  | 2938 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) | 
|  | 2939 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); | 
|  | 2940 | return TheTriple.getTriple(); | 
|  | 2941 | } | 
|  | 2942 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2943 | Tool *NaClToolChain::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2944 | return new tools::nacltools::Linker(*this); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2945 | } | 
|  | 2946 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2947 | Tool *NaClToolChain::buildAssembler() const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2948 | if (getTriple().getArch() == llvm::Triple::arm) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2949 | return new tools::nacltools::AssemblerARM(*this); | 
|  | 2950 | return new tools::gnutools::Assembler(*this); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2951 | } | 
|  | 2952 | // End NaCl | 
|  | 2953 |  | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2954 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform | 
|  | 2955 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. | 
|  | 2956 | /// Currently does not support anything else but compilation. | 
|  | 2957 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2958 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 2959 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2960 | : ToolChain(D, Triple, Args) { | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2961 | // Path mangling to find libexec | 
|  | 2962 | std::string Path(getDriver().Dir); | 
|  | 2963 |  | 
|  | 2964 | Path += "/../libexec"; | 
|  | 2965 | getProgramPaths().push_back(Path); | 
|  | 2966 | } | 
|  | 2967 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2968 | TCEToolChain::~TCEToolChain() {} | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2969 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2970 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2971 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2972 | bool TCEToolChain::isPICDefault() const { return false; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2973 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2974 | bool TCEToolChain::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2975 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2976 | bool TCEToolChain::isPICDefaultForced() const { return false; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2977 |  | 
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2978 | // CloudABI - CloudABI tool chain which can call ld(1) directly. | 
|  | 2979 |  | 
|  | 2980 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, | 
|  | 2981 | const ArgList &Args) | 
|  | 2982 | : Generic_ELF(D, Triple, Args) { | 
|  | 2983 | SmallString<128> P(getDriver().Dir); | 
|  | 2984 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); | 
|  | 2985 | getFilePaths().push_back(P.str()); | 
|  | 2986 | } | 
|  | 2987 |  | 
|  | 2988 | void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 2989 | ArgStringList &CC1Args) const { | 
|  | 2990 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) && | 
|  | 2991 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2992 | return; | 
|  | 2993 |  | 
|  | 2994 | SmallString<128> P(getDriver().Dir); | 
|  | 2995 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); | 
|  | 2996 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2997 | } | 
|  | 2998 |  | 
|  | 2999 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 3000 | ArgStringList &CmdArgs) const { | 
|  | 3001 | CmdArgs.push_back("-lc++"); | 
|  | 3002 | CmdArgs.push_back("-lc++abi"); | 
|  | 3003 | CmdArgs.push_back("-lunwind"); | 
|  | 3004 | } | 
|  | 3005 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3006 | Tool *CloudABI::buildLinker() const { | 
|  | 3007 | return new tools::cloudabi::Linker(*this); | 
|  | 3008 | } | 
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 3009 |  | 
| Ed Schouten | 51bfbe7 | 2016-02-17 18:56:20 +0000 | [diff] [blame] | 3010 | SanitizerMask CloudABI::getSupportedSanitizers() const { | 
|  | 3011 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 3012 | Res |= SanitizerKind::SafeStack; | 
|  | 3013 | return Res; | 
|  | 3014 | } | 
|  | 3015 |  | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3016 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 3017 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3018 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, | 
|  | 3019 | const ArgList &Args) | 
|  | 3020 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3021 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3022 | getFilePaths().push_back("/usr/lib"); | 
|  | 3023 | } | 
|  | 3024 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3025 | Tool *OpenBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3026 | return new tools::openbsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3027 | } | 
|  | 3028 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3029 | Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3030 |  | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3031 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. | 
|  | 3032 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3033 | Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3034 | : Generic_ELF(D, Triple, Args) { | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3035 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
|  | 3036 | getFilePaths().push_back("/usr/lib"); | 
|  | 3037 | } | 
|  | 3038 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3039 | Tool *Bitrig::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3040 | return new tools::bitrig::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3041 | } | 
|  | 3042 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3043 | Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3044 |  | 
| Jonas Hahnfeld | aae8374 | 2016-02-12 07:48:37 +0000 | [diff] [blame] | 3045 | ToolChain::CXXStdlibType Bitrig::GetDefaultCXXStdlibType() const { | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3046 | return ToolChain::CST_Libcxx; | 
|  | 3047 | } | 
|  | 3048 |  | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3049 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3050 | ArgStringList &CC1Args) const { | 
|  | 3051 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3052 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3053 | return; | 
|  | 3054 |  | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3055 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3056 | case ToolChain::CST_Libcxx: | 
|  | 3057 | addSystemInclude(DriverArgs, CC1Args, | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3058 | getDriver().SysRoot + "/usr/include/c++/v1"); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3059 | break; | 
|  | 3060 | case ToolChain::CST_Libstdcxx: | 
|  | 3061 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3062 | getDriver().SysRoot + "/usr/include/c++/stdc++"); | 
|  | 3063 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3064 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3065 |  | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3066 | StringRef Triple = getTriple().str(); | 
|  | 3067 | if (Triple.startswith("amd64")) | 
|  | 3068 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3069 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3070 | Triple.substr(5)); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3071 | else | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3072 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + | 
|  | 3073 | "/usr/include/c++/stdc++/" + | 
|  | 3074 | Triple); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3075 | break; | 
|  | 3076 | } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3077 | } | 
|  | 3078 |  | 
|  | 3079 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 3080 | ArgStringList &CmdArgs) const { | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3081 | switch (GetCXXStdlibType(Args)) { | 
|  | 3082 | case ToolChain::CST_Libcxx: | 
|  | 3083 | CmdArgs.push_back("-lc++"); | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3084 | CmdArgs.push_back("-lc++abi"); | 
|  | 3085 | CmdArgs.push_back("-lpthread"); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3086 | break; | 
|  | 3087 | case ToolChain::CST_Libstdcxx: | 
|  | 3088 | CmdArgs.push_back("-lstdc++"); | 
|  | 3089 | break; | 
|  | 3090 | } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3091 | } | 
|  | 3092 |  | 
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3093 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 3094 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3095 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, | 
|  | 3096 | const ArgList &Args) | 
|  | 3097 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 3098 |  | 
| Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 3099 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall | 
|  | 3100 | // back to '/usr/lib' if it doesn't exist. | 
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3101 | if ((Triple.getArch() == llvm::Triple::x86 || | 
|  | 3102 | Triple.getArch() == llvm::Triple::ppc) && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3103 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) | 
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3104 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); | 
|  | 3105 | else | 
|  | 3106 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); | 
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3107 | } | 
|  | 3108 |  | 
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3109 | ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3110 | if (getTriple().getOSMajorVersion() >= 10) | 
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3111 | return ToolChain::CST_Libcxx; | 
|  | 3112 | return ToolChain::CST_Libstdcxx; | 
|  | 3113 | } | 
|  | 3114 |  | 
|  | 3115 | void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3116 | ArgStringList &CC1Args) const { | 
|  | 3117 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3118 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3119 | return; | 
|  | 3120 |  | 
|  | 3121 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3122 | case ToolChain::CST_Libcxx: | 
|  | 3123 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3124 | getDriver().SysRoot + "/usr/include/c++/v1"); | 
|  | 3125 | break; | 
|  | 3126 | case ToolChain::CST_Libstdcxx: | 
|  | 3127 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3128 | getDriver().SysRoot + "/usr/include/c++/4.2"); | 
|  | 3129 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3130 | getDriver().SysRoot + "/usr/include/c++/4.2/backward"); | 
|  | 3131 | break; | 
|  | 3132 | } | 
|  | 3133 | } | 
|  | 3134 |  | 
| Dimitry Andric | 6090739 | 2016-02-14 16:08:20 +0000 | [diff] [blame] | 3135 | void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 3136 | ArgStringList &CmdArgs) const { | 
|  | 3137 | CXXStdlibType Type = GetCXXStdlibType(Args); | 
|  | 3138 | bool Profiling = Args.hasArg(options::OPT_pg); | 
|  | 3139 |  | 
|  | 3140 | switch (Type) { | 
|  | 3141 | case ToolChain::CST_Libcxx: | 
|  | 3142 | CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++"); | 
|  | 3143 | break; | 
|  | 3144 |  | 
|  | 3145 | case ToolChain::CST_Libstdcxx: | 
|  | 3146 | CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++"); | 
|  | 3147 | break; | 
|  | 3148 | } | 
|  | 3149 | } | 
|  | 3150 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3151 | Tool *FreeBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3152 | return new tools::freebsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3153 | } | 
|  | 3154 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3155 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3156 |  | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 3157 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { | 
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3158 | // FreeBSD uses SjLj exceptions on ARM oabi. | 
|  | 3159 | switch (getTriple().getEnvironment()) { | 
| Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 3160 | case llvm::Triple::GNUEABIHF: | 
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3161 | case llvm::Triple::GNUEABI: | 
|  | 3162 | case llvm::Triple::EABI: | 
|  | 3163 | return false; | 
|  | 3164 |  | 
|  | 3165 | default: | 
|  | 3166 | return (getTriple().getArch() == llvm::Triple::arm || | 
|  | 3167 | getTriple().getArch() == llvm::Triple::thumb); | 
|  | 3168 | } | 
|  | 3169 | } | 
|  | 3170 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3171 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } | 
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3172 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3173 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } | 
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3174 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3175 | SanitizerMask FreeBSD::getSupportedSanitizers() const { | 
|  | 3176 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; | 
|  | 3177 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; | 
|  | 3178 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || | 
|  | 3179 | getTriple().getArch() == llvm::Triple::mips64el; | 
|  | 3180 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 3181 | Res |= SanitizerKind::Address; | 
|  | 3182 | Res |= SanitizerKind::Vptr; | 
|  | 3183 | if (IsX86_64 || IsMIPS64) { | 
|  | 3184 | Res |= SanitizerKind::Leak; | 
|  | 3185 | Res |= SanitizerKind::Thread; | 
|  | 3186 | } | 
|  | 3187 | if (IsX86 || IsX86_64) { | 
|  | 3188 | Res |= SanitizerKind::SafeStack; | 
|  | 3189 | } | 
|  | 3190 | return Res; | 
|  | 3191 | } | 
|  | 3192 |  | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3193 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 3194 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3195 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3196 | : Generic_ELF(D, Triple, Args) { | 
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3197 | if (getDriver().UseStdLib) { | 
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3198 | // When targeting a 32-bit platform, try the special directory used on | 
|  | 3199 | // 64-bit hosts, and only fall back to the main library directory if that | 
|  | 3200 | // doesn't work. | 
|  | 3201 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure | 
|  | 3202 | // what all logic is needed to emulate the '=' prefix here. | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3203 | switch (Triple.getArch()) { | 
|  | 3204 | case llvm::Triple::x86: | 
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3205 | getFilePaths().push_back("=/usr/lib/i386"); | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3206 | break; | 
|  | 3207 | case llvm::Triple::arm: | 
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3208 | case llvm::Triple::armeb: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3209 | case llvm::Triple::thumb: | 
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3210 | case llvm::Triple::thumbeb: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3211 | switch (Triple.getEnvironment()) { | 
|  | 3212 | case llvm::Triple::EABI: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3213 | case llvm::Triple::GNUEABI: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3214 | getFilePaths().push_back("=/usr/lib/eabi"); | 
|  | 3215 | break; | 
| Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3216 | case llvm::Triple::EABIHF: | 
|  | 3217 | case llvm::Triple::GNUEABIHF: | 
|  | 3218 | getFilePaths().push_back("=/usr/lib/eabihf"); | 
|  | 3219 | break; | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3220 | default: | 
|  | 3221 | getFilePaths().push_back("=/usr/lib/oabi"); | 
|  | 3222 | break; | 
|  | 3223 | } | 
|  | 3224 | break; | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3225 | case llvm::Triple::mips64: | 
|  | 3226 | case llvm::Triple::mips64el: | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3227 | if (tools::mips::hasMipsAbiArg(Args, "o32")) | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3228 | getFilePaths().push_back("=/usr/lib/o32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3229 | else if (tools::mips::hasMipsAbiArg(Args, "64")) | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3230 | getFilePaths().push_back("=/usr/lib/64"); | 
|  | 3231 | break; | 
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3232 | case llvm::Triple::ppc: | 
|  | 3233 | getFilePaths().push_back("=/usr/lib/powerpc"); | 
|  | 3234 | break; | 
| Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3235 | case llvm::Triple::sparc: | 
|  | 3236 | getFilePaths().push_back("=/usr/lib/sparc"); | 
|  | 3237 | break; | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3238 | default: | 
|  | 3239 | break; | 
|  | 3240 | } | 
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3241 |  | 
|  | 3242 | getFilePaths().push_back("=/usr/lib"); | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3243 | } | 
|  | 3244 | } | 
|  | 3245 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3246 | Tool *NetBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3247 | return new tools::netbsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3248 | } | 
|  | 3249 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3250 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3251 |  | 
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3252 | ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const { | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3253 | unsigned Major, Minor, Micro; | 
|  | 3254 | getTriple().getOSVersion(Major, Minor, Micro); | 
| Joerg Sonnenberger | 21156e8 | 2016-02-11 23:35:03 +0000 | [diff] [blame] | 3255 | if (Major >= 7 || Major == 0) { | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3256 | switch (getArch()) { | 
| Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3257 | case llvm::Triple::aarch64: | 
| Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3258 | case llvm::Triple::arm: | 
|  | 3259 | case llvm::Triple::armeb: | 
|  | 3260 | case llvm::Triple::thumb: | 
|  | 3261 | case llvm::Triple::thumbeb: | 
| Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3262 | case llvm::Triple::ppc: | 
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3263 | case llvm::Triple::ppc64: | 
|  | 3264 | case llvm::Triple::ppc64le: | 
| Joerg Sonnenberger | 059613c | 2016-02-11 23:18:36 +0000 | [diff] [blame] | 3265 | case llvm::Triple::sparc: | 
|  | 3266 | case llvm::Triple::sparcv9: | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3267 | case llvm::Triple::x86: | 
|  | 3268 | case llvm::Triple::x86_64: | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3269 | return ToolChain::CST_Libcxx; | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3270 | default: | 
|  | 3271 | break; | 
|  | 3272 | } | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3273 | } | 
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3274 | return ToolChain::CST_Libstdcxx; | 
|  | 3275 | } | 
|  | 3276 |  | 
|  | 3277 | void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3278 | ArgStringList &CC1Args) const { | 
|  | 3279 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3280 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3281 | return; | 
|  | 3282 |  | 
|  | 3283 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3284 | case ToolChain::CST_Libcxx: | 
|  | 3285 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3286 | getDriver().SysRoot + "/usr/include/c++/"); | 
|  | 3287 | break; | 
|  | 3288 | case ToolChain::CST_Libstdcxx: | 
|  | 3289 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3290 | getDriver().SysRoot + "/usr/include/g++"); | 
|  | 3291 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3292 | getDriver().SysRoot + "/usr/include/g++/backward"); | 
|  | 3293 | break; | 
|  | 3294 | } | 
|  | 3295 | } | 
|  | 3296 |  | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3297 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. | 
|  | 3298 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3299 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3300 | : Generic_ELF(D, Triple, Args) { | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3301 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
|  | 3302 | getFilePaths().push_back("/usr/lib"); | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3303 | } | 
|  | 3304 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3305 | Tool *Minix::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3306 | return new tools::minix::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3307 | } | 
|  | 3308 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3309 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3310 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3311 | static void addPathIfExists(const Driver &D, const Twine &Path, | 
|  | 3312 | ToolChain::path_list &Paths) { | 
|  | 3313 | if (D.getVFS().exists(Path)) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3314 | Paths.push_back(Path.str()); | 
|  | 3315 | } | 
|  | 3316 |  | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3317 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. | 
|  | 3318 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3319 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3320 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3321 | : Generic_GCC(D, Triple, Args) { | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3322 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3323 | GCCInstallation.init(Triple, Args); | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3324 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3325 | path_list &Paths = getFilePaths(); | 
|  | 3326 | if (GCCInstallation.isValid()) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3327 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3328 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3329 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3330 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3331 | addPathIfExists(D, getDriver().Dir, Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3332 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3333 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3334 |  | 
|  | 3335 | std::string LibPath = "/usr/lib/"; | 
|  | 3336 | switch (Triple.getArch()) { | 
|  | 3337 | case llvm::Triple::x86: | 
|  | 3338 | case llvm::Triple::sparc: | 
|  | 3339 | break; | 
|  | 3340 | case llvm::Triple::x86_64: | 
|  | 3341 | LibPath += "amd64/"; | 
|  | 3342 | break; | 
|  | 3343 | case llvm::Triple::sparcv9: | 
|  | 3344 | LibPath += "sparcv9/"; | 
|  | 3345 | break; | 
|  | 3346 | default: | 
|  | 3347 | llvm_unreachable("Unsupported architecture"); | 
|  | 3348 | } | 
|  | 3349 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3350 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3351 | } | 
|  | 3352 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3353 | Tool *Solaris::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3354 | return new tools::solaris::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3355 | } | 
|  | 3356 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3357 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } | 
| Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3358 |  | 
| Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3359 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3360 | ArgStringList &CC1Args) const { | 
|  | 3361 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3362 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3363 | return; | 
|  | 3364 |  | 
|  | 3365 | // Include the support directory for things like xlocale and fudged system | 
|  | 3366 | // headers. | 
|  | 3367 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); | 
|  | 3368 |  | 
|  | 3369 | if (GCCInstallation.isValid()) { | 
|  | 3370 | GCCVersion Version = GCCInstallation.getVersion(); | 
|  | 3371 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3372 | getDriver().SysRoot + "/usr/gcc/" + | 
|  | 3373 | Version.MajorStr + "." + | 
|  | 3374 | Version.MinorStr + | 
|  | 3375 | "/include/c++/" + Version.Text); | 
|  | 3376 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3377 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + | 
|  | 3378 | "." + Version.MinorStr + "/include/c++/" + | 
|  | 3379 | Version.Text + "/" + | 
|  | 3380 | GCCInstallation.getTriple().str()); | 
|  | 3381 | } | 
|  | 3382 | } | 
|  | 3383 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3384 | /// Distribution (very bare-bones at the moment). | 
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3385 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3386 | enum Distro { | 
| Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3387 | // NB: Releases of a particular Linux distro should be kept together | 
|  | 3388 | // in this enum, because some tests are done by integer comparison against | 
|  | 3389 | // the first and last known member in the family, e.g. IsRedHat(). | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3390 | ArchLinux, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3391 | DebianLenny, | 
|  | 3392 | DebianSqueeze, | 
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3393 | DebianWheezy, | 
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3394 | DebianJessie, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3395 | DebianStretch, | 
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3396 | Exherbo, | 
| Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3397 | RHEL4, | 
|  | 3398 | RHEL5, | 
|  | 3399 | RHEL6, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3400 | RHEL7, | 
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3401 | Fedora, | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3402 | OpenSUSE, | 
| Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3403 | UbuntuHardy, | 
|  | 3404 | UbuntuIntrepid, | 
| Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3405 | UbuntuJaunty, | 
| Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3406 | UbuntuKarmic, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3407 | UbuntuLucid, | 
|  | 3408 | UbuntuMaverick, | 
| Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3409 | UbuntuNatty, | 
| Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3410 | UbuntuOneiric, | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3411 | UbuntuPrecise, | 
| Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3412 | UbuntuQuantal, | 
|  | 3413 | UbuntuRaring, | 
| Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3414 | UbuntuSaucy, | 
| Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3415 | UbuntuTrusty, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3416 | UbuntuUtopic, | 
|  | 3417 | UbuntuVivid, | 
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3418 | UbuntuWily, | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3419 | UbuntuXenial, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3420 | UnknownDistro | 
|  | 3421 | }; | 
|  | 3422 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3423 | static bool IsRedhat(enum Distro Distro) { | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3424 | return Distro == Fedora || (Distro >= RHEL4 && Distro <= RHEL7); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3425 | } | 
|  | 3426 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3427 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3428 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3429 | static bool IsDebian(enum Distro Distro) { | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3430 | return Distro >= DebianLenny && Distro <= DebianStretch; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3431 | } | 
|  | 3432 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3433 | static bool IsUbuntu(enum Distro Distro) { | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3434 | return Distro >= UbuntuHardy && Distro <= UbuntuXenial; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3435 | } | 
|  | 3436 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3437 | static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3438 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = | 
|  | 3439 | llvm::MemoryBuffer::getFile("/etc/lsb-release"); | 
|  | 3440 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3441 | StringRef Data = File.get()->getBuffer(); | 
| Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3442 | SmallVector<StringRef, 16> Lines; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3443 | Data.split(Lines, "\n"); | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3444 | Distro Version = UnknownDistro; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3445 | for (StringRef Line : Lines) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3446 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) | 
|  | 3447 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) | 
|  | 3448 | .Case("hardy", UbuntuHardy) | 
|  | 3449 | .Case("intrepid", UbuntuIntrepid) | 
|  | 3450 | .Case("jaunty", UbuntuJaunty) | 
|  | 3451 | .Case("karmic", UbuntuKarmic) | 
|  | 3452 | .Case("lucid", UbuntuLucid) | 
|  | 3453 | .Case("maverick", UbuntuMaverick) | 
|  | 3454 | .Case("natty", UbuntuNatty) | 
|  | 3455 | .Case("oneiric", UbuntuOneiric) | 
|  | 3456 | .Case("precise", UbuntuPrecise) | 
|  | 3457 | .Case("quantal", UbuntuQuantal) | 
|  | 3458 | .Case("raring", UbuntuRaring) | 
|  | 3459 | .Case("saucy", UbuntuSaucy) | 
|  | 3460 | .Case("trusty", UbuntuTrusty) | 
|  | 3461 | .Case("utopic", UbuntuUtopic) | 
|  | 3462 | .Case("vivid", UbuntuVivid) | 
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3463 | .Case("wily", UbuntuWily) | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3464 | .Case("xenial", UbuntuXenial) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3465 | .Default(UnknownDistro); | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3466 | return Version; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3467 | } | 
|  | 3468 |  | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3469 | File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); | 
|  | 3470 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3471 | StringRef Data = File.get()->getBuffer(); | 
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3472 | if (Data.startswith("Fedora release")) | 
|  | 3473 | return Fedora; | 
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3474 | if (Data.startswith("Red Hat Enterprise Linux") || | 
|  | 3475 | Data.startswith("CentOS")) { | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3476 | if (Data.find("release 7") != StringRef::npos) | 
|  | 3477 | return RHEL7; | 
|  | 3478 | else if (Data.find("release 6") != StringRef::npos) | 
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3479 | return RHEL6; | 
|  | 3480 | else if (Data.find("release 5") != StringRef::npos) | 
|  | 3481 | return RHEL5; | 
|  | 3482 | else if (Data.find("release 4") != StringRef::npos) | 
|  | 3483 | return RHEL4; | 
|  | 3484 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3485 | return UnknownDistro; | 
|  | 3486 | } | 
|  | 3487 |  | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3488 | File = llvm::MemoryBuffer::getFile("/etc/debian_version"); | 
|  | 3489 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3490 | StringRef Data = File.get()->getBuffer(); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3491 | if (Data[0] == '5') | 
|  | 3492 | return DebianLenny; | 
| Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 3493 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3494 | return DebianSqueeze; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3495 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') | 
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3496 | return DebianWheezy; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3497 | else if (Data.startswith("jessie/sid") || Data[0] == '8') | 
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3498 | return DebianJessie; | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3499 | else if (Data.startswith("stretch/sid") || Data[0] == '9') | 
|  | 3500 | return DebianStretch; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3501 | return UnknownDistro; | 
|  | 3502 | } | 
|  | 3503 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3504 | if (D.getVFS().exists("/etc/SuSE-release")) | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3505 | return OpenSUSE; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3506 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3507 | if (D.getVFS().exists("/etc/exherbo-release")) | 
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3508 | return Exherbo; | 
|  | 3509 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3510 | if (D.getVFS().exists("/etc/arch-release")) | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3511 | return ArchLinux; | 
|  | 3512 |  | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3513 | return UnknownDistro; | 
|  | 3514 | } | 
|  | 3515 |  | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3516 | /// \brief Get our best guess at the multiarch triple for a target. | 
|  | 3517 | /// | 
|  | 3518 | /// Debian-based systems are starting to use a multiarch setup where they use | 
|  | 3519 | /// a target-triple directory in the library and header search paths. | 
|  | 3520 | /// Unfortunately, this triple does not align with the vanilla target triple, | 
|  | 3521 | /// so we provide a rough mapping here. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3522 | static std::string getMultiarchTriple(const Driver &D, | 
|  | 3523 | const llvm::Triple &TargetTriple, | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3524 | StringRef SysRoot) { | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 3525 | llvm::Triple::EnvironmentType TargetEnvironment = | 
|  | 3526 | TargetTriple.getEnvironment(); | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3527 |  | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3528 | // For most architectures, just use whatever we have rather than trying to be | 
|  | 3529 | // clever. | 
|  | 3530 | switch (TargetTriple.getArch()) { | 
|  | 3531 | default: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3532 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3533 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3534 | // We use the existence of '/lib/<triple>' as a directory to detect some | 
|  | 3535 | // common linux triples that don't quite match the Clang triple for both | 
|  | 3536 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these | 
|  | 3537 | // regardless of what the actual target triple is. | 
| Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 3538 | case llvm::Triple::arm: | 
|  | 3539 | case llvm::Triple::thumb: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3540 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3541 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3542 | return "arm-linux-gnueabihf"; | 
|  | 3543 | } else { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3544 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3545 | return "arm-linux-gnueabi"; | 
|  | 3546 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3547 | break; | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3548 | case llvm::Triple::armeb: | 
|  | 3549 | case llvm::Triple::thumbeb: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3550 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3551 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3552 | return "armeb-linux-gnueabihf"; | 
|  | 3553 | } else { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3554 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3555 | return "armeb-linux-gnueabi"; | 
|  | 3556 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3557 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3558 | case llvm::Triple::x86: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3559 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3560 | return "i386-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3561 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3562 | case llvm::Triple::x86_64: | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3563 | // 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] | 3564 | if (TargetEnvironment != llvm::Triple::GNUX32 && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3565 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3566 | return "x86_64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3567 | break; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3568 | case llvm::Triple::aarch64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3569 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3570 | return "aarch64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3571 | break; | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3572 | case llvm::Triple::aarch64_be: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3573 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3574 | return "aarch64_be-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3575 | break; | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3576 | case llvm::Triple::mips: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3577 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3578 | return "mips-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3579 | break; | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3580 | case llvm::Triple::mipsel: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3581 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3582 | return "mipsel-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3583 | break; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3584 | case llvm::Triple::mips64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3585 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3586 | return "mips64-linux-gnu"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3587 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3588 | return "mips64-linux-gnuabi64"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3589 | break; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3590 | case llvm::Triple::mips64el: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3591 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3592 | return "mips64el-linux-gnu"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3593 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3594 | return "mips64el-linux-gnuabi64"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3595 | break; | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3596 | case llvm::Triple::ppc: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3597 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) | 
| Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 3598 | return "powerpc-linux-gnuspe"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3599 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3600 | return "powerpc-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3601 | break; | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3602 | case llvm::Triple::ppc64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3603 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3604 | return "powerpc64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3605 | break; | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3606 | case llvm::Triple::ppc64le: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3607 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3608 | return "powerpc64le-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3609 | break; | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3610 | case llvm::Triple::sparc: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3611 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3612 | return "sparc-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3613 | break; | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3614 | case llvm::Triple::sparcv9: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3615 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3616 | return "sparc64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3617 | break; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3618 | case llvm::Triple::systemz: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3619 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3620 | return "s390x-linux-gnu"; | 
|  | 3621 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3622 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3623 | return TargetTriple.str(); | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3624 | } | 
|  | 3625 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3626 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3627 | if (isMipsArch(Triple.getArch())) { | 
|  | 3628 | // lib32 directory has a special meaning on MIPS targets. | 
|  | 3629 | // It contains N32 ABI binaries. Use this folder if produce | 
|  | 3630 | // code for N32 ABI only. | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3631 | if (tools::mips::hasMipsAbiArg(Args, "n32")) | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3632 | return "lib32"; | 
|  | 3633 | return Triple.isArch32Bit() ? "lib" : "lib64"; | 
|  | 3634 | } | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3635 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3636 | // 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] | 3637 | // using that variant while targeting other architectures causes problems | 
|  | 3638 | // 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] | 3639 | // with a 'lib32' library search path being considered. So we only enable | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3640 | // them when we know we may need it. | 
|  | 3641 | // | 
|  | 3642 | // 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] | 3643 | // reasoning about oslibdir spellings with the lib dir spellings in the | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3644 | // GCCInstallationDetector, but that is a more significant refactoring. | 
|  | 3645 | if (Triple.getArch() == llvm::Triple::x86 || | 
|  | 3646 | Triple.getArch() == llvm::Triple::ppc) | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3647 | return "lib32"; | 
|  | 3648 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3649 | if (Triple.getArch() == llvm::Triple::x86_64 && | 
|  | 3650 | Triple.getEnvironment() == llvm::Triple::GNUX32) | 
|  | 3651 | return "libx32"; | 
|  | 3652 |  | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3653 | return Triple.isArch32Bit() ? "lib" : "lib64"; | 
|  | 3654 | } | 
|  | 3655 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3656 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3657 | : Generic_ELF(D, Triple, Args) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3658 | GCCInstallation.init(Triple, Args); | 
|  | 3659 | CudaInstallation.init(Triple, Args); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3660 | Multilibs = GCCInstallation.getMultilibs(); | 
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3661 | llvm::Triple::ArchType Arch = Triple.getArch(); | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3662 | std::string SysRoot = computeSysRoot(); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3663 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3664 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at | 
| Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 3665 | // least) put various tools in a triple-prefixed directory off of the parent | 
|  | 3666 | // of the GCC installation. We use the GCC triple here to ensure that we end | 
|  | 3667 | // up with tools that support the same amount of cross compiling as the | 
|  | 3668 | // detected GCC installation. For example, if we find a GCC installation | 
|  | 3669 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be | 
|  | 3670 | // used to target i386. | 
|  | 3671 | // FIXME: This seems unlikely to be Linux-specific. | 
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3672 | ToolChain::path_list &PPaths = getProgramPaths(); | 
| Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 3673 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3674 | GCCInstallation.getTriple().str() + "/bin") | 
|  | 3675 | .str()); | 
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3676 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3677 | Distro Distro = DetectDistro(D, Arch); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3678 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3679 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { | 
| Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 3680 | ExtraOpts.push_back("-z"); | 
|  | 3681 | ExtraOpts.push_back("relro"); | 
|  | 3682 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3683 |  | 
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3684 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3685 | ExtraOpts.push_back("-X"); | 
|  | 3686 |  | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 3687 | const bool IsAndroid = Triple.isAndroid(); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3688 | const bool IsMips = isMipsArch(Arch); | 
|  | 3689 |  | 
|  | 3690 | if (IsMips && !SysRoot.empty()) | 
|  | 3691 | ExtraOpts.push_back("--sysroot=" + SysRoot); | 
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3692 |  | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3693 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash | 
|  | 3694 | // and the MIPS ABI require .dynsym to be sorted in different ways. | 
|  | 3695 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS | 
|  | 3696 | // ABI requires a mapping between the GOT and the symbol table. | 
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3697 | // Android loader does not support .gnu.hash. | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3698 | if (!IsMips && !IsAndroid) { | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3699 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3700 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3701 | ExtraOpts.push_back("--hash-style=gnu"); | 
|  | 3702 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3703 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3704 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) | 
|  | 3705 | ExtraOpts.push_back("--hash-style=both"); | 
|  | 3706 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3707 |  | 
| Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3708 | if (IsRedhat(Distro)) | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3709 | ExtraOpts.push_back("--no-add-needed"); | 
|  | 3710 |  | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3711 | if ((IsDebian(Distro) && Distro >= DebianSqueeze) || IsOpenSUSE(Distro) || | 
| Rafael Espindola | d8f92c8 | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 3712 | (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3713 | (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3714 | ExtraOpts.push_back("--build-id"); | 
|  | 3715 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3716 | if (IsOpenSUSE(Distro)) | 
| Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 3717 | ExtraOpts.push_back("--enable-new-dtags"); | 
| Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 3718 |  | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3719 | // The selection of paths to try here is designed to match the patterns which | 
|  | 3720 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. | 
|  | 3721 | // This was determined by running GCC in a fake filesystem, creating all | 
|  | 3722 | // possible permutations of these directories, and seeing which ones it added | 
|  | 3723 | // to the link paths. | 
|  | 3724 | path_list &Paths = getFilePaths(); | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3725 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3726 | const std::string OSLibDir = getOSLibDir(Triple, Args); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3727 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3728 |  | 
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3729 | // Add the multilib suffixed paths where they are available. | 
|  | 3730 | if (GCCInstallation.isValid()) { | 
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 3731 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); | 
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3732 | const std::string &LibPath = GCCInstallation.getParentLibPath(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3733 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 3734 |  | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3735 | // Sourcery CodeBench MIPS toolchain holds some libraries under | 
| Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 3736 | // a biarch-like suffix of the GCC installation. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3737 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3738 | Paths); | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3739 |  | 
|  | 3740 | // GCC cross compiling toolchains will install target libraries which ship | 
|  | 3741 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as | 
|  | 3742 | // any part of the GCC installation in | 
|  | 3743 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat | 
|  | 3744 | // debatable, but is the reality today. We need to search this tree even | 
|  | 3745 | // when we have a sysroot somewhere else. It is the responsibility of | 
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 3746 | // whomever is doing the cross build targeting a sysroot using a GCC | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3747 | // installation that is *not* within the system root to ensure two things: | 
|  | 3748 | // | 
|  | 3749 | //  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] | 3750 | //     above must be present on the system root and found via an | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3751 | //     appropriate rpath. | 
|  | 3752 | //  2) There must not be libraries installed into | 
|  | 3753 | //     <prefix>/<triple>/<libdir> unless they should be preferred over | 
|  | 3754 | //     those within the system root. | 
|  | 3755 | // | 
|  | 3756 | // Note that this matches the GCC behavior. See the below comment for where | 
|  | 3757 | // Clang diverges from GCC's behavior. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3758 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + | 
|  | 3759 | OSLibDir + Multilib.osSuffix(), | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3760 | Paths); | 
|  | 3761 |  | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3762 | // If the GCC installation we found is inside of the sysroot, we want to | 
|  | 3763 | // prefer libraries installed in the parent prefix of the GCC installation. | 
|  | 3764 | // 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] | 3765 | // outside of the system root as that can pick up unintended libraries. | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3766 | // This usually happens when there is an external cross compiler on the | 
|  | 3767 | // 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] | 3768 | // the cross. Note that GCC does include some of these directories in some | 
|  | 3769 | // configurations but this seems somewhere between questionable and simply | 
|  | 3770 | // a bug. | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3771 | if (StringRef(LibPath).startswith(SysRoot)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3772 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); | 
|  | 3773 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3774 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3775 | } | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3776 |  | 
|  | 3777 | // 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] | 3778 | // of the requested system root, add its parent library paths to | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3779 | // those searched. | 
|  | 3780 | // FIXME: It's not clear whether we should use the driver's installed | 
|  | 3781 | // directory ('Dir' below) or the ResourceDir. | 
|  | 3782 | if (StringRef(D.Dir).startswith(SysRoot)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3783 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); | 
|  | 3784 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3785 | } | 
|  | 3786 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3787 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); | 
|  | 3788 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); | 
|  | 3789 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); | 
|  | 3790 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); | 
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3791 |  | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 3792 | // 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] | 3793 | // installations with strange symlinks. | 
| Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 3794 | if (GCCInstallation.isValid()) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3795 | addPathIfExists(D, | 
|  | 3796 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3797 | "/../../" + OSLibDir, | 
|  | 3798 | Paths); | 
| Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 3799 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3800 | // Add the 'other' biarch variant path | 
|  | 3801 | Multilib BiarchSibling; | 
|  | 3802 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3803 | addPathIfExists(D, GCCInstallation.getInstallPath() + | 
|  | 3804 | BiarchSibling.gccSuffix(), | 
|  | 3805 | Paths); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3806 | } | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3807 |  | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3808 | // See comments above on the multilib variant for details of why this is | 
|  | 3809 | // included even from outside the sysroot. | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3810 | const std::string &LibPath = GCCInstallation.getParentLibPath(); | 
|  | 3811 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); | 
|  | 3812 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3813 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + | 
|  | 3814 | Multilib.osSuffix(), | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3815 | Paths); | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3816 |  | 
|  | 3817 | // See comments above on the multilib variant for details of why this is | 
|  | 3818 | // only included from within the sysroot. | 
|  | 3819 | if (StringRef(LibPath).startswith(SysRoot)) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3820 | addPathIfExists(D, LibPath, Paths); | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3821 | } | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3822 |  | 
|  | 3823 | // Similar to the logic for GCC above, if we are currently running Clang | 
|  | 3824 | // inside of the requested system root, add its parent library path to those | 
|  | 3825 | // searched. | 
|  | 3826 | // FIXME: It's not clear whether we should use the driver's installed | 
|  | 3827 | // directory ('Dir' below) or the ResourceDir. | 
|  | 3828 | if (StringRef(D.Dir).startswith(SysRoot)) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3829 | addPathIfExists(D, D.Dir + "/../lib", Paths); | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3830 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3831 | addPathIfExists(D, SysRoot + "/lib", Paths); | 
|  | 3832 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3833 | } | 
|  | 3834 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3835 | bool Linux::HasNativeLLVMSupport() const { return true; } | 
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3836 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3837 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3838 |  | 
|  | 3839 | Tool *Linux::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3840 | return new tools::gnutools::Assembler(*this); | 
| Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 3841 | } | 
|  | 3842 |  | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3843 | std::string Linux::computeSysRoot() const { | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3844 | if (!getDriver().SysRoot.empty()) | 
|  | 3845 | return getDriver().SysRoot; | 
|  | 3846 |  | 
|  | 3847 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) | 
|  | 3848 | return std::string(); | 
|  | 3849 |  | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3850 | // Standalone MIPS toolchains use different names for sysroot folder | 
|  | 3851 | // and put it into different places. Here we try to check some known | 
|  | 3852 | // variants. | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3853 |  | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3854 | const StringRef InstallDir = GCCInstallation.getInstallPath(); | 
|  | 3855 | const StringRef TripleStr = GCCInstallation.getTriple().str(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3856 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3857 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3858 | std::string Path = | 
|  | 3859 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) | 
|  | 3860 | .str(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3861 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3862 | if (getVFS().exists(Path)) | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3863 | return Path; | 
|  | 3864 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3865 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3866 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3867 | if (getVFS().exists(Path)) | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3868 | return Path; | 
|  | 3869 |  | 
|  | 3870 | return std::string(); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3871 | } | 
|  | 3872 |  | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3873 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 3874 | ArgStringList &CC1Args) const { | 
|  | 3875 | const Driver &D = getDriver(); | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3876 | std::string SysRoot = computeSysRoot(); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3877 |  | 
|  | 3878 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 3879 | return; | 
|  | 3880 |  | 
|  | 3881 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3882 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3883 |  | 
|  | 3884 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 3885 | SmallString<128> P(D.ResourceDir); | 
|  | 3886 | llvm::sys::path::append(P, "include"); | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3887 | addSystemInclude(DriverArgs, CC1Args, P); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3888 | } | 
|  | 3889 |  | 
|  | 3890 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 3891 | return; | 
|  | 3892 |  | 
|  | 3893 | // Check for configure-time C include directories. | 
|  | 3894 | StringRef CIncludeDirs(C_INCLUDE_DIRS); | 
|  | 3895 | if (CIncludeDirs != "") { | 
|  | 3896 | SmallVector<StringRef, 5> dirs; | 
|  | 3897 | CIncludeDirs.split(dirs, ":"); | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3898 | for (StringRef dir : dirs) { | 
| Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 3899 | StringRef Prefix = | 
|  | 3900 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3901 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3902 | } | 
|  | 3903 | return; | 
|  | 3904 | } | 
|  | 3905 |  | 
|  | 3906 | // Lacking those, try to detect the correct set of system includes for the | 
|  | 3907 | // target triple. | 
|  | 3908 |  | 
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3909 | // Add include directories specific to the selected multilib set and multilib. | 
|  | 3910 | if (GCCInstallation.isValid()) { | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 3911 | const auto &Callback = Multilibs.includeDirsCallback(); | 
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3912 | if (Callback) { | 
|  | 3913 | const auto IncludePaths = Callback(GCCInstallation.getInstallPath(), | 
|  | 3914 | GCCInstallation.getTriple().str(), | 
|  | 3915 | GCCInstallation.getMultilib()); | 
|  | 3916 | for (const auto &Path : IncludePaths) | 
|  | 3917 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); | 
|  | 3918 | } | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3919 | } | 
|  | 3920 |  | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3921 | // Implement generic Debian multiarch support. | 
|  | 3922 | const StringRef X86_64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3923 | "/usr/include/x86_64-linux-gnu", | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3924 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3925 | // FIXME: These are older forms of multiarch. It's not clear that they're | 
|  | 3926 | // in use in any released version of Debian, so we should consider | 
|  | 3927 | // removing them. | 
|  | 3928 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3929 | const StringRef X86MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3930 | "/usr/include/i386-linux-gnu", | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3931 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3932 | // FIXME: These are older forms of multiarch. It's not clear that they're | 
|  | 3933 | // in use in any released version of Debian, so we should consider | 
|  | 3934 | // removing them. | 
|  | 3935 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", | 
|  | 3936 | "/usr/include/i486-linux-gnu"}; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3937 | const StringRef AArch64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3938 | "/usr/include/aarch64-linux-gnu"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3939 | const StringRef ARMMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3940 | "/usr/include/arm-linux-gnueabi"}; | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3941 | const StringRef ARMHFMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3942 | "/usr/include/arm-linux-gnueabihf"}; | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 3943 | const StringRef ARMEBMultiarchIncludeDirs[] = { | 
|  | 3944 | "/usr/include/armeb-linux-gnueabi"}; | 
|  | 3945 | const StringRef ARMEBHFMultiarchIncludeDirs[] = { | 
|  | 3946 | "/usr/include/armeb-linux-gnueabihf"}; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3947 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3948 | const StringRef MIPSELMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3949 | "/usr/include/mipsel-linux-gnu"}; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3950 | const StringRef MIPS64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3951 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3952 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3953 | "/usr/include/mips64el-linux-gnu", | 
|  | 3954 | "/usr/include/mips64el-linux-gnuabi64"}; | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3955 | const StringRef PPCMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3956 | "/usr/include/powerpc-linux-gnu"}; | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3957 | const StringRef PPC64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3958 | "/usr/include/powerpc64-linux-gnu"}; | 
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 3959 | const StringRef PPC64LEMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3960 | "/usr/include/powerpc64le-linux-gnu"}; | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3961 | const StringRef SparcMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3962 | "/usr/include/sparc-linux-gnu"}; | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3963 | const StringRef Sparc64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3964 | "/usr/include/sparc64-linux-gnu"}; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3965 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { | 
|  | 3966 | "/usr/include/s390x-linux-gnu"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3967 | ArrayRef<StringRef> MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3968 | switch (getTriple().getArch()) { | 
|  | 3969 | case llvm::Triple::x86_64: | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3970 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3971 | break; | 
|  | 3972 | case llvm::Triple::x86: | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3973 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3974 | break; | 
|  | 3975 | case llvm::Triple::aarch64: | 
|  | 3976 | case llvm::Triple::aarch64_be: | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3977 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3978 | break; | 
|  | 3979 | case llvm::Triple::arm: | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 3980 | case llvm::Triple::thumb: | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3981 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) | 
|  | 3982 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; | 
|  | 3983 | else | 
|  | 3984 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3985 | break; | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 3986 | case llvm::Triple::armeb: | 
|  | 3987 | case llvm::Triple::thumbeb: | 
|  | 3988 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) | 
|  | 3989 | MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs; | 
|  | 3990 | else | 
|  | 3991 | MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs; | 
|  | 3992 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3993 | case llvm::Triple::mips: | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3994 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3995 | break; | 
|  | 3996 | case llvm::Triple::mipsel: | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3997 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3998 | break; | 
|  | 3999 | case llvm::Triple::mips64: | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4000 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4001 | break; | 
|  | 4002 | case llvm::Triple::mips64el: | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4003 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4004 | break; | 
|  | 4005 | case llvm::Triple::ppc: | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4006 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4007 | break; | 
|  | 4008 | case llvm::Triple::ppc64: | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4009 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4010 | break; | 
|  | 4011 | case llvm::Triple::ppc64le: | 
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4012 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4013 | break; | 
|  | 4014 | case llvm::Triple::sparc: | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4015 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4016 | break; | 
|  | 4017 | case llvm::Triple::sparcv9: | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4018 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4019 | break; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4020 | case llvm::Triple::systemz: | 
|  | 4021 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; | 
|  | 4022 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4023 | default: | 
|  | 4024 | break; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4025 | } | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4026 | for (StringRef Dir : MultiarchIncludeDirs) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4027 | if (D.getVFS().exists(SysRoot + Dir)) { | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4028 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4029 | break; | 
|  | 4030 | } | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4031 | } | 
|  | 4032 |  | 
|  | 4033 | if (getTriple().getOS() == llvm::Triple::RTEMS) | 
|  | 4034 | return; | 
|  | 4035 |  | 
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4036 | // Add an include of '/include' directly. This isn't provided by default by | 
|  | 4037 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to | 
|  | 4038 | // 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] | 4039 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); | 
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4040 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4041 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4042 | } | 
|  | 4043 |  | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4044 | static std::string DetectLibcxxIncludePath(StringRef base) { | 
|  | 4045 | std::error_code EC; | 
|  | 4046 | int MaxVersion = 0; | 
|  | 4047 | std::string MaxVersionString = ""; | 
|  | 4048 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; | 
|  | 4049 | LI = LI.increment(EC)) { | 
|  | 4050 | StringRef VersionText = llvm::sys::path::filename(LI->path()); | 
|  | 4051 | int Version; | 
|  | 4052 | if (VersionText[0] == 'v' && | 
|  | 4053 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { | 
|  | 4054 | if (Version > MaxVersion) { | 
|  | 4055 | MaxVersion = Version; | 
|  | 4056 | MaxVersionString = VersionText; | 
|  | 4057 | } | 
|  | 4058 | } | 
|  | 4059 | } | 
|  | 4060 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; | 
|  | 4061 | } | 
|  | 4062 |  | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4063 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 4064 | ArgStringList &CC1Args) const { | 
|  | 4065 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4066 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4067 | return; | 
|  | 4068 |  | 
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4069 | // Check if libc++ has been enabled and provide its include paths if so. | 
|  | 4070 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4071 | const std::string LibCXXIncludePathCandidates[] = { | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4072 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4073 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4074 | // We also check the system as for a long time this is the only place | 
|  | 4075 | // Clang looked. | 
|  | 4076 | // FIXME: We should really remove this. It doesn't make any sense. | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4077 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++")}; | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4078 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4079 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4080 | continue; | 
|  | 4081 | // Add the first candidate that exists. | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4082 | addSystemInclude(DriverArgs, CC1Args, IncludePath); | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4083 | break; | 
|  | 4084 | } | 
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4085 | return; | 
|  | 4086 | } | 
|  | 4087 |  | 
| Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 4088 | // We need a detected GCC installation on Linux to provide libstdc++'s | 
|  | 4089 | // headers. We handled the libc++ case above. | 
|  | 4090 | if (!GCCInstallation.isValid()) | 
|  | 4091 | return; | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4092 |  | 
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4093 | // By default, look for the C++ headers in an include directory adjacent to | 
|  | 4094 | // the lib directory of the GCC installation. Note that this is expect to be | 
|  | 4095 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. | 
|  | 4096 | StringRef LibDir = GCCInstallation.getParentLibPath(); | 
|  | 4097 | StringRef InstallDir = GCCInstallation.getInstallPath(); | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4098 | StringRef TripleStr = GCCInstallation.getTriple().str(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4099 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4100 | const std::string GCCMultiarchTriple = getMultiarchTriple( | 
|  | 4101 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4102 | const std::string TargetMultiarchTriple = | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4103 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 4104 | const GCCVersion &Version = GCCInstallation.getVersion(); | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4105 |  | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4106 | // The primary search for libstdc++ supports multiarch variants. | 
| Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 4107 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4108 | "/c++/" + Version.Text, TripleStr, | 
|  | 4109 | GCCMultiarchTriple, TargetMultiarchTriple, | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4110 | Multilib.includeSuffix(), DriverArgs, CC1Args)) | 
| Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4111 | return; | 
|  | 4112 |  | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4113 | // Otherwise, fall back on a bunch of options which don't use multiarch | 
|  | 4114 | // layouts for simplicity. | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4115 | const std::string LibStdCXXIncludePathCandidates[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4116 | // Gentoo is weird and places its headers inside the GCC install, | 
|  | 4117 | // so if the first attempt to find the headers fails, try these patterns. | 
|  | 4118 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + | 
|  | 4119 | Version.MinorStr, | 
|  | 4120 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, | 
|  | 4121 | // Android standalone toolchain has C++ headers in yet another place. | 
|  | 4122 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, | 
|  | 4123 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, | 
|  | 4124 | // without a subdirectory corresponding to the gcc version. | 
|  | 4125 | LibDir.str() + "/../include/c++", | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4126 | }; | 
|  | 4127 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4128 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4129 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, | 
|  | 4130 | /*GCCMultiarchTriple*/ "", | 
|  | 4131 | /*TargetMultiarchTriple*/ "", | 
|  | 4132 | Multilib.includeSuffix(), DriverArgs, CC1Args)) | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4133 | break; | 
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4134 | } | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4135 | } | 
|  | 4136 |  | 
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4137 | void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, | 
|  | 4138 | ArgStringList &CC1Args) const { | 
|  | 4139 | if (DriverArgs.hasArg(options::OPT_nocudainc)) | 
|  | 4140 | return; | 
|  | 4141 |  | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4142 | if (CudaInstallation.isValid()) { | 
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4143 | addSystemInclude(DriverArgs, CC1Args, CudaInstallation.getIncludePath()); | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4144 | CC1Args.push_back("-include"); | 
| Artem Belevich | 7fda3c9 | 2015-12-16 18:51:59 +0000 | [diff] [blame] | 4145 | CC1Args.push_back("__clang_cuda_runtime_wrapper.h"); | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4146 | } | 
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4147 | } | 
|  | 4148 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4149 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 4150 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4151 | SanitizerMask Linux::getSupportedSanitizers() const { | 
|  | 4152 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; | 
|  | 4153 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; | 
|  | 4154 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || | 
|  | 4155 | getTriple().getArch() == llvm::Triple::mips64el; | 
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4156 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || | 
|  | 4157 | getTriple().getArch() == llvm::Triple::ppc64le; | 
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4158 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || | 
|  | 4159 | getTriple().getArch() == llvm::Triple::aarch64_be; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4160 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 4161 | Res |= SanitizerKind::Address; | 
|  | 4162 | Res |= SanitizerKind::KernelAddress; | 
|  | 4163 | Res |= SanitizerKind::Vptr; | 
| Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 4164 | Res |= SanitizerKind::SafeStack; | 
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4165 | if (IsX86_64 || IsMIPS64 || IsAArch64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4166 | Res |= SanitizerKind::DataFlow; | 
| Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 4167 | if (IsX86_64 || IsMIPS64 || IsAArch64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4168 | Res |= SanitizerKind::Leak; | 
| Bill Schmidt | 4b8841a | 2015-12-08 22:48:02 +0000 | [diff] [blame] | 4169 | if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4170 | Res |= SanitizerKind::Thread; | 
| Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 4171 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) | 
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4172 | Res |= SanitizerKind::Memory; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4173 | if (IsX86 || IsX86_64) { | 
|  | 4174 | Res |= SanitizerKind::Function; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4175 | } | 
|  | 4176 | return Res; | 
|  | 4177 | } | 
|  | 4178 |  | 
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4179 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, | 
|  | 4180 | llvm::opt::ArgStringList &CmdArgs) const { | 
|  | 4181 | if (!needsProfileRT(Args)) return; | 
|  | 4182 |  | 
|  | 4183 | // Add linker option -u__llvm_runtime_variable to cause runtime | 
|  | 4184 | // initialization module to be linked in. | 
|  | 4185 | if (!Args.hasArg(options::OPT_coverage)) | 
|  | 4186 | CmdArgs.push_back(Args.MakeArgString( | 
|  | 4187 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); | 
|  | 4188 | ToolChain::addProfileRTLibs(Args, CmdArgs); | 
|  | 4189 | } | 
|  | 4190 |  | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4191 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. | 
|  | 4192 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4193 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, | 
|  | 4194 | const ArgList &Args) | 
|  | 4195 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4196 |  | 
|  | 4197 | // Path mangling to find libexec | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4198 | getProgramPaths().push_back(getDriver().getInstalledDir()); | 
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 4199 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4200 | getProgramPaths().push_back(getDriver().Dir); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4201 |  | 
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4202 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4203 | getFilePaths().push_back("/usr/lib"); | 
| Dimitry Andric | f59a2b3 | 2015-12-27 10:01:44 +0000 | [diff] [blame] | 4204 | getFilePaths().push_back("/usr/lib/gcc50"); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4205 | } | 
|  | 4206 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4207 | Tool *DragonFly::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4208 | return new tools::dragonfly::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4209 | } | 
|  | 4210 |  | 
|  | 4211 | Tool *DragonFly::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4212 | return new tools::dragonfly::Linker(*this); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4213 | } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4214 |  | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4215 | /// CUDA toolchain.  Our assembler is ptxas, and our "linker" is fatbinary, | 
|  | 4216 | /// which isn't properly a linker but nonetheless performs the step of stitching | 
|  | 4217 | /// together object files from the assembler into a single blob. | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4218 |  | 
|  | 4219 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4220 | const ArgList &Args) | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4221 | : Linux(D, Triple, Args) { | 
|  | 4222 | if (CudaInstallation.isValid()) | 
|  | 4223 | getProgramPaths().push_back(CudaInstallation.getBinPath()); | 
|  | 4224 | } | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4225 |  | 
|  | 4226 | void | 
|  | 4227 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, | 
|  | 4228 | llvm::opt::ArgStringList &CC1Args) const { | 
|  | 4229 | Linux::addClangTargetOptions(DriverArgs, CC1Args); | 
|  | 4230 | CC1Args.push_back("-fcuda-is-device"); | 
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4231 |  | 
|  | 4232 | if (DriverArgs.hasArg(options::OPT_nocudalib)) | 
|  | 4233 | return; | 
|  | 4234 |  | 
|  | 4235 | std::string LibDeviceFile = CudaInstallation.getLibDeviceFile( | 
|  | 4236 | DriverArgs.getLastArgValue(options::OPT_march_EQ)); | 
|  | 4237 | if (!LibDeviceFile.empty()) { | 
|  | 4238 | CC1Args.push_back("-mlink-cuda-bitcode"); | 
|  | 4239 | CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile)); | 
|  | 4240 |  | 
|  | 4241 | // Libdevice in CUDA-7.0 requires PTX version that's more recent | 
|  | 4242 | // than LLVM defaults to. Use PTX4.2 which is the PTX version that | 
|  | 4243 | // came with CUDA-7.0. | 
|  | 4244 | CC1Args.push_back("-target-feature"); | 
|  | 4245 | CC1Args.push_back("+ptx42"); | 
|  | 4246 | } | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4247 | } | 
|  | 4248 |  | 
|  | 4249 | llvm::opt::DerivedArgList * | 
|  | 4250 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, | 
|  | 4251 | const char *BoundArch) const { | 
|  | 4252 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); | 
|  | 4253 | const OptTable &Opts = getDriver().getOpts(); | 
|  | 4254 |  | 
|  | 4255 | for (Arg *A : Args) { | 
|  | 4256 | if (A->getOption().matches(options::OPT_Xarch__)) { | 
|  | 4257 | // Skip this argument unless the architecture matches BoundArch | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4258 | if (!BoundArch || A->getValue(0) != StringRef(BoundArch)) | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4259 | continue; | 
|  | 4260 |  | 
|  | 4261 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); | 
|  | 4262 | unsigned Prev = Index; | 
|  | 4263 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); | 
|  | 4264 |  | 
|  | 4265 | // If the argument parsing failed or more than one argument was | 
|  | 4266 | // consumed, the -Xarch_ argument's parameter tried to consume | 
|  | 4267 | // extra arguments. Emit an error and ignore. | 
|  | 4268 | // | 
|  | 4269 | // We also want to disallow any options which would alter the | 
|  | 4270 | // driver behavior; that isn't going to work in our model. We | 
|  | 4271 | // use isDriverOption() as an approximation, although things | 
|  | 4272 | // like -O4 are going to slip through. | 
|  | 4273 | if (!XarchArg || Index > Prev + 1) { | 
|  | 4274 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) | 
|  | 4275 | << A->getAsString(Args); | 
|  | 4276 | continue; | 
|  | 4277 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { | 
|  | 4278 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) | 
|  | 4279 | << A->getAsString(Args); | 
|  | 4280 | continue; | 
|  | 4281 | } | 
|  | 4282 | XarchArg->setBaseArg(A); | 
|  | 4283 | A = XarchArg.release(); | 
|  | 4284 | DAL->AddSynthesizedArg(A); | 
|  | 4285 | } | 
|  | 4286 | DAL->append(A); | 
|  | 4287 | } | 
|  | 4288 |  | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4289 | if (BoundArch) | 
|  | 4290 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4291 | return DAL; | 
|  | 4292 | } | 
|  | 4293 |  | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4294 | Tool *CudaToolChain::buildAssembler() const { | 
|  | 4295 | return new tools::NVPTX::Assembler(*this); | 
|  | 4296 | } | 
|  | 4297 |  | 
|  | 4298 | Tool *CudaToolChain::buildLinker() const { | 
|  | 4299 | return new tools::NVPTX::Linker(*this); | 
|  | 4300 | } | 
|  | 4301 |  | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4302 | /// XCore tool chain | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4303 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4304 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4305 | : ToolChain(D, Triple, Args) { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4306 | // ProgramPaths are found via 'PATH' environment variable. | 
|  | 4307 | } | 
|  | 4308 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4309 | Tool *XCoreToolChain::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4310 | return new tools::XCore::Assembler(*this); | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4311 | } | 
|  | 4312 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4313 | Tool *XCoreToolChain::buildLinker() const { | 
|  | 4314 | return new tools::XCore::Linker(*this); | 
|  | 4315 | } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4316 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4317 | bool XCoreToolChain::isPICDefault() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4318 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4319 | bool XCoreToolChain::isPIEDefault() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4320 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4321 | bool XCoreToolChain::isPICDefaultForced() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4322 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4323 | bool XCoreToolChain::SupportsProfiling() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4324 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4325 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4326 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4327 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4328 | ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4329 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
|  | 4330 | DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 4331 | return; | 
|  | 4332 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { | 
|  | 4333 | SmallVector<StringRef, 4> Dirs; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4334 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4335 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); | 
|  | 4336 | ArrayRef<StringRef> DirVec(Dirs); | 
|  | 4337 | addSystemIncludes(DriverArgs, CC1Args, DirVec); | 
|  | 4338 | } | 
|  | 4339 | } | 
|  | 4340 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4341 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 4342 | ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4343 | CC1Args.push_back("-nostdsysteminc"); | 
|  | 4344 | } | 
|  | 4345 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4346 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 4347 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4348 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
| Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 4349 | DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4350 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4351 | return; | 
|  | 4352 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { | 
|  | 4353 | SmallVector<StringRef, 4> Dirs; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4354 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4355 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); | 
|  | 4356 | ArrayRef<StringRef> DirVec(Dirs); | 
|  | 4357 | addSystemIncludes(DriverArgs, CC1Args, DirVec); | 
|  | 4358 | } | 
|  | 4359 | } | 
|  | 4360 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4361 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 4362 | ArgStringList &CmdArgs) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4363 | // We don't output any lib args. This is handled by xcc. | 
|  | 4364 | } | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4365 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4366 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4367 | const ArgList &Args) | 
|  | 4368 | : Generic_GCC(D, Triple, Args) { | 
|  | 4369 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use | 
|  | 4370 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. | 
|  | 4371 | // This won't work to find gcc. Instead we give the installation detector an | 
|  | 4372 | // extra triple, which is preferable to further hacks of the logic that at | 
|  | 4373 | // present is based solely on getArch(). In particular, it would be wrong to | 
|  | 4374 | // choose the myriad installation when targeting a non-myriad sparc install. | 
|  | 4375 | switch (Triple.getArch()) { | 
|  | 4376 | default: | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4377 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() | 
|  | 4378 | << "myriad"; | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4379 | case llvm::Triple::sparc: | 
|  | 4380 | case llvm::Triple::sparcel: | 
|  | 4381 | case llvm::Triple::shave: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4382 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4383 | } | 
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 4384 |  | 
|  | 4385 | if (GCCInstallation.isValid()) { | 
|  | 4386 | // The contents of LibDir are independent of the version of gcc. | 
|  | 4387 | // This contains libc, libg (a superset of libc), libm, libstdc++, libssp. | 
|  | 4388 | SmallString<128> LibDir(GCCInstallation.getParentLibPath()); | 
|  | 4389 | if (Triple.getArch() == llvm::Triple::sparcel) | 
|  | 4390 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib/le"); | 
|  | 4391 | else | 
|  | 4392 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib"); | 
|  | 4393 | addPathIfExists(D, LibDir, getFilePaths()); | 
|  | 4394 |  | 
|  | 4395 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. | 
|  | 4396 | // These files are tied to a particular version of gcc. | 
|  | 4397 | SmallString<128> CompilerSupportDir(GCCInstallation.getInstallPath()); | 
|  | 4398 | // There are actually 4 choices: {le,be} x {fpu,nofpu} | 
|  | 4399 | // but as this toolchain is for LEON sparc, it can assume FPU. | 
|  | 4400 | if (Triple.getArch() == llvm::Triple::sparcel) | 
|  | 4401 | llvm::sys::path::append(CompilerSupportDir, "le"); | 
|  | 4402 | addPathIfExists(D, CompilerSupportDir, getFilePaths()); | 
|  | 4403 | } | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4404 | } | 
|  | 4405 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4406 | MyriadToolChain::~MyriadToolChain() {} | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4407 |  | 
| Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 4408 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4409 | ArgStringList &CC1Args) const { | 
|  | 4410 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 4411 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); | 
|  | 4412 | } | 
|  | 4413 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4414 | void MyriadToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 4415 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4416 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4417 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4418 | return; | 
|  | 4419 |  | 
|  | 4420 | // Only libstdc++, for now. | 
|  | 4421 | StringRef LibDir = GCCInstallation.getParentLibPath(); | 
|  | 4422 | const GCCVersion &Version = GCCInstallation.getVersion(); | 
|  | 4423 | StringRef TripleStr = GCCInstallation.getTriple().str(); | 
|  | 4424 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
|  | 4425 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4426 | addLibStdCXXIncludePaths( | 
|  | 4427 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, | 
|  | 4428 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4429 | } | 
|  | 4430 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4431 | // MyriadToolChain handles several triples: | 
|  | 4432 | //  {shave,sparc{,el}}-myriad-{rtems,unknown}-elf | 
|  | 4433 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { | 
|  | 4434 | // The inherited method works fine if not targeting the SHAVE. | 
|  | 4435 | if (!isShaveCompilation(getTriple())) | 
|  | 4436 | return ToolChain::SelectTool(JA); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4437 | switch (JA.getKind()) { | 
| Douglas Katzman | 9dc4c62 | 2015-11-20 04:58:12 +0000 | [diff] [blame] | 4438 | case Action::PreprocessJobClass: | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4439 | case Action::CompileJobClass: | 
|  | 4440 | if (!Compiler) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4441 | Compiler.reset(new tools::SHAVE::Compiler(*this)); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4442 | return Compiler.get(); | 
|  | 4443 | case Action::AssembleJobClass: | 
|  | 4444 | if (!Assembler) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4445 | Assembler.reset(new tools::SHAVE::Assembler(*this)); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4446 | return Assembler.get(); | 
|  | 4447 | default: | 
|  | 4448 | return ToolChain::getTool(JA.getKind()); | 
|  | 4449 | } | 
|  | 4450 | } | 
|  | 4451 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4452 | Tool *MyriadToolChain::buildLinker() const { | 
|  | 4453 | return new tools::Myriad::Linker(*this); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4454 | } | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4455 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4456 | WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple, | 
|  | 4457 | const llvm::opt::ArgList &Args) | 
|  | 4458 | : ToolChain(D, Triple, Args) { | 
| Dan Gohman | 57b62c5 | 2016-02-22 19:26:15 +0000 | [diff] [blame] | 4459 |  | 
|  | 4460 | assert(Triple.isArch32Bit() != Triple.isArch64Bit()); | 
|  | 4461 | getFilePaths().push_back( | 
|  | 4462 | getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64")); | 
|  | 4463 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4464 | // Use LLD by default. | 
|  | 4465 | DefaultLinker = "lld"; | 
|  | 4466 | } | 
|  | 4467 |  | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4468 | bool WebAssembly::IsMathErrnoDefault() const { return false; } | 
|  | 4469 |  | 
|  | 4470 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } | 
|  | 4471 |  | 
|  | 4472 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } | 
|  | 4473 |  | 
|  | 4474 | bool WebAssembly::isPICDefault() const { return false; } | 
|  | 4475 |  | 
|  | 4476 | bool WebAssembly::isPIEDefault() const { return false; } | 
|  | 4477 |  | 
|  | 4478 | bool WebAssembly::isPICDefaultForced() const { return false; } | 
|  | 4479 |  | 
|  | 4480 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } | 
|  | 4481 |  | 
|  | 4482 | // TODO: Support Objective C stuff. | 
|  | 4483 | bool WebAssembly::SupportsObjCGC() const { return false; } | 
|  | 4484 |  | 
|  | 4485 | bool WebAssembly::hasBlocksRuntime() const { return false; } | 
|  | 4486 |  | 
|  | 4487 | // TODO: Support profiling. | 
|  | 4488 | bool WebAssembly::SupportsProfiling() const { return false; } | 
|  | 4489 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4490 | bool WebAssembly::HasNativeLLVMSupport() const { return true; } | 
|  | 4491 |  | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4492 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 4493 | ArgStringList &CC1Args) const { | 
|  | 4494 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, | 
|  | 4495 | options::OPT_fno_use_init_array, true)) | 
|  | 4496 | CC1Args.push_back("-fuse-init-array"); | 
|  | 4497 | } | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4498 |  | 
| Dan Gohman | 6ad8f61 | 2016-01-14 16:00:13 +0000 | [diff] [blame] | 4499 | ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const { | 
|  | 4500 | return ToolChain::RLT_CompilerRT; | 
|  | 4501 | } | 
|  | 4502 |  | 
|  | 4503 | ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { | 
|  | 4504 | return ToolChain::CST_Libcxx; | 
|  | 4505 | } | 
|  | 4506 |  | 
|  | 4507 | void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4508 | ArgStringList &CC1Args) const { | 
|  | 4509 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 4510 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); | 
|  | 4511 | } | 
|  | 4512 |  | 
|  | 4513 | void WebAssembly::AddClangCXXStdlibIncludeArgs( | 
|  | 4514 | const llvm::opt::ArgList &DriverArgs, | 
|  | 4515 | llvm::opt::ArgStringList &CC1Args) const { | 
|  | 4516 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc) && | 
|  | 4517 | !DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4518 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 4519 | getDriver().SysRoot + "/include/c++/v1"); | 
|  | 4520 | } | 
|  | 4521 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4522 | Tool *WebAssembly::buildLinker() const { | 
|  | 4523 | return new tools::wasm::Linker(*this); | 
|  | 4524 | } | 
|  | 4525 |  | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4526 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 4527 | : Generic_ELF(D, Triple, Args) { | 
|  | 4528 | if (Args.hasArg(options::OPT_static)) | 
|  | 4529 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; | 
|  | 4530 |  | 
|  | 4531 | // Determine where to find the PS4 libraries. We use SCE_PS4_SDK_DIR | 
|  | 4532 | // if it exists; otherwise use the driver's installation path, which | 
|  | 4533 | // should be <SDK_DIR>/host_tools/bin. | 
|  | 4534 |  | 
|  | 4535 | SmallString<512> PS4SDKDir; | 
|  | 4536 | if (const char *EnvValue = getenv("SCE_PS4_SDK_DIR")) { | 
|  | 4537 | if (!llvm::sys::fs::exists(EnvValue)) | 
|  | 4538 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; | 
|  | 4539 | PS4SDKDir = EnvValue; | 
|  | 4540 | } else { | 
|  | 4541 | PS4SDKDir = getDriver().Dir; | 
|  | 4542 | llvm::sys::path::append(PS4SDKDir, "/../../"); | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4543 | } | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4544 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4545 | // 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] | 4546 | // PS4's include or lib directories. This behavior could be changed if | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4547 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4548 | // If -isysroot was passed, use that as the SDK base path. | 
|  | 4549 | std::string PrefixDir; | 
|  | 4550 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
|  | 4551 | PrefixDir = A->getValue(); | 
|  | 4552 | if (!llvm::sys::fs::exists(PrefixDir)) | 
|  | 4553 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; | 
|  | 4554 | } else | 
|  | 4555 | PrefixDir = PS4SDKDir.str(); | 
|  | 4556 |  | 
|  | 4557 | SmallString<512> PS4SDKIncludeDir(PrefixDir); | 
|  | 4558 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); | 
|  | 4559 | if (!Args.hasArg(options::OPT_nostdinc) && | 
|  | 4560 | !Args.hasArg(options::OPT_nostdlibinc) && | 
|  | 4561 | !Args.hasArg(options::OPT_isysroot) && | 
|  | 4562 | !Args.hasArg(options::OPT__sysroot_EQ) && | 
|  | 4563 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { | 
|  | 4564 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) | 
|  | 4565 | << "PS4 system headers" << PS4SDKIncludeDir; | 
|  | 4566 | } | 
|  | 4567 |  | 
|  | 4568 | SmallString<512> PS4SDKLibDir(PS4SDKDir); | 
|  | 4569 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); | 
|  | 4570 | if (!Args.hasArg(options::OPT_nostdlib) && | 
|  | 4571 | !Args.hasArg(options::OPT_nodefaultlibs) && | 
|  | 4572 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && | 
|  | 4573 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && | 
|  | 4574 | !Args.hasArg(options::OPT_emit_ast) && | 
|  | 4575 | !llvm::sys::fs::exists(PS4SDKLibDir)) { | 
|  | 4576 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) | 
|  | 4577 | << "PS4 system libraries" << PS4SDKLibDir; | 
|  | 4578 | return; | 
|  | 4579 | } | 
|  | 4580 | getFilePaths().push_back(PS4SDKLibDir.str()); | 
|  | 4581 | } | 
|  | 4582 |  | 
|  | 4583 | Tool *PS4CPU::buildAssembler() const { | 
|  | 4584 | return new tools::PS4cpu::Assemble(*this); | 
|  | 4585 | } | 
|  | 4586 |  | 
|  | 4587 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } | 
|  | 4588 |  | 
|  | 4589 | bool PS4CPU::isPICDefault() const { return true; } | 
|  | 4590 |  | 
|  | 4591 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } | 
|  | 4592 |  | 
|  | 4593 | SanitizerMask PS4CPU::getSupportedSanitizers() const { | 
|  | 4594 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 4595 | Res |= SanitizerKind::Address; | 
|  | 4596 | Res |= SanitizerKind::Vptr; | 
|  | 4597 | return Res; | 
|  | 4598 | } |