| 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 |  | 
| John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 68 | /// 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] | 69 | ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 70 | if (isTargetWatchOSBased()) | 
| Tim Northover | 756447a | 2015-10-30 16:30:36 +0000 | [diff] [blame] | 71 | return ObjCRuntime(ObjCRuntime::WatchOS, TargetVersion); | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 72 | if (isTargetIOSBased()) | 
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 73 | return ObjCRuntime(ObjCRuntime::iOS, TargetVersion); | 
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 74 | if (isNonFragile) | 
|  | 75 | return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion); | 
|  | 76 | return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion); | 
| John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 77 | } | 
|  | 78 |  | 
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 79 | /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. | 
|  | 80 | bool Darwin::hasBlocksRuntime() const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 81 | if (isTargetWatchOSBased()) | 
|  | 82 | return true; | 
|  | 83 | else if (isTargetIOSBased()) | 
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 84 | return !isIPhoneOSVersionLT(3, 2); | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 85 | else { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 86 | assert(isTargetMacOS() && "unexpected darwin target"); | 
|  | 87 | return !isMacosxVersionLT(10, 6); | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 88 | } | 
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 89 | } | 
|  | 90 |  | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 91 | // This is just a MachO name translation routine and there's no | 
|  | 92 | // way to join this into ARMTargetParser without breaking all | 
|  | 93 | // other assumptions. Maybe MachO should consider standardising | 
|  | 94 | // their nomenclature. | 
|  | 95 | static const char *ArmMachOArchName(StringRef Arch) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 96 | return llvm::StringSwitch<const char *>(Arch) | 
|  | 97 | .Case("armv6k", "armv6") | 
|  | 98 | .Case("armv6m", "armv6m") | 
|  | 99 | .Case("armv5tej", "armv5") | 
|  | 100 | .Case("xscale", "xscale") | 
|  | 101 | .Case("armv4t", "armv4t") | 
|  | 102 | .Case("armv7", "armv7") | 
|  | 103 | .Cases("armv7a", "armv7-a", "armv7") | 
|  | 104 | .Cases("armv7r", "armv7-r", "armv7") | 
|  | 105 | .Cases("armv7em", "armv7e-m", "armv7em") | 
|  | 106 | .Cases("armv7k", "armv7-k", "armv7k") | 
|  | 107 | .Cases("armv7m", "armv7-m", "armv7m") | 
|  | 108 | .Cases("armv7s", "armv7-s", "armv7s") | 
|  | 109 | .Default(nullptr); | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 110 | } | 
|  | 111 |  | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 112 | static const char *ArmMachOArchNameCPU(StringRef CPU) { | 
| Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 113 | unsigned ArchKind = llvm::ARM::parseCPUArch(CPU); | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 114 | if (ArchKind == llvm::ARM::AK_INVALID) | 
|  | 115 | return nullptr; | 
| Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 116 | StringRef Arch = llvm::ARM::getArchName(ArchKind); | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 117 |  | 
|  | 118 | // FIXME: Make sure this MachO triple mangling is really necessary. | 
|  | 119 | // ARMv5* normalises to ARMv5. | 
|  | 120 | if (Arch.startswith("armv5")) | 
|  | 121 | Arch = Arch.substr(0, 5); | 
|  | 122 | // ARMv6*, except ARMv6M, normalises to ARMv6. | 
|  | 123 | else if (Arch.startswith("armv6") && !Arch.endswith("6m")) | 
|  | 124 | Arch = Arch.substr(0, 5); | 
|  | 125 | // ARMv7A normalises to ARMv7. | 
|  | 126 | else if (Arch.endswith("v7a")) | 
|  | 127 | Arch = Arch.substr(0, 5); | 
|  | 128 | return Arch.data(); | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 129 | } | 
|  | 130 |  | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 131 | static bool isSoftFloatABI(const ArgList &Args) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 132 | Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 133 | options::OPT_mfloat_abi_EQ); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 134 | if (!A) | 
|  | 135 | return false; | 
| Rafael Auler | 3f7abf7 | 2014-09-29 21:50:34 +0000 | [diff] [blame] | 136 |  | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 137 | return A->getOption().matches(options::OPT_msoft_float) || | 
|  | 138 | (A->getOption().matches(options::OPT_mfloat_abi_EQ) && | 
|  | 139 | A->getValue() == StringRef("soft")); | 
|  | 140 | } | 
|  | 141 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 142 | StringRef MachO::getMachOArchName(const ArgList &Args) const { | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 143 | switch (getTriple().getArch()) { | 
|  | 144 | default: | 
| Rafael Espindola | ed1233e | 2014-08-28 21:23:05 +0000 | [diff] [blame] | 145 | return getDefaultUniversalArchName(); | 
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 146 |  | 
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 147 | case llvm::Triple::aarch64: | 
|  | 148 | return "arm64"; | 
|  | 149 |  | 
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 150 | case llvm::Triple::thumb: | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 151 | case llvm::Triple::arm: | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 152 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 153 | if (const char *Arch = ArmMachOArchName(A->getValue())) | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 154 | return Arch; | 
|  | 155 |  | 
|  | 156 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) | 
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 157 | if (const char *Arch = ArmMachOArchNameCPU(A->getValue())) | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 158 | return Arch; | 
|  | 159 |  | 
|  | 160 | return "arm"; | 
|  | 161 | } | 
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 162 | } | 
|  | 163 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 164 | Darwin::~Darwin() {} | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 165 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 166 | MachO::~MachO() {} | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 167 |  | 
|  | 168 | std::string MachO::ComputeEffectiveClangTriple(const ArgList &Args, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 169 | types::ID InputType) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 170 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); | 
|  | 171 |  | 
|  | 172 | return Triple.getTriple(); | 
|  | 173 | } | 
|  | 174 |  | 
| Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 175 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, | 
|  | 176 | types::ID InputType) const { | 
|  | 177 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); | 
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 178 |  | 
|  | 179 | // If the target isn't initialized (e.g., an unknown Darwin platform, return | 
|  | 180 | // the default triple). | 
|  | 181 | if (!isTargetInitialized()) | 
|  | 182 | return Triple.getTriple(); | 
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 183 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 184 | SmallString<16> Str; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 185 | if (isTargetWatchOSBased()) | 
|  | 186 | Str += "watchos"; | 
|  | 187 | else if (isTargetTvOSBased()) | 
|  | 188 | Str += "tvos"; | 
|  | 189 | else if (isTargetIOSBased()) | 
|  | 190 | Str += "ios"; | 
|  | 191 | else | 
|  | 192 | Str += "macosx"; | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 193 | Str += getTargetVersion().getAsString(); | 
|  | 194 | Triple.setOSName(Str); | 
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 195 |  | 
|  | 196 | return Triple.getTriple(); | 
|  | 197 | } | 
|  | 198 |  | 
| David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 199 | void Generic_ELF::anchor() {} | 
|  | 200 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 201 | Tool *MachO::getTool(Action::ActionClass AC) const { | 
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 202 | switch (AC) { | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 203 | case Action::LipoJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 204 | if (!Lipo) | 
|  | 205 | Lipo.reset(new tools::darwin::Lipo(*this)); | 
|  | 206 | return Lipo.get(); | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 207 | case Action::DsymutilJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 208 | if (!Dsymutil) | 
|  | 209 | Dsymutil.reset(new tools::darwin::Dsymutil(*this)); | 
|  | 210 | return Dsymutil.get(); | 
| Ben Langmuir | 9b9a8d3 | 2014-02-06 18:53:25 +0000 | [diff] [blame] | 211 | case Action::VerifyDebugInfoJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 212 | if (!VerifyDebug) | 
|  | 213 | VerifyDebug.reset(new tools::darwin::VerifyDebug(*this)); | 
|  | 214 | return VerifyDebug.get(); | 
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 215 | default: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 216 | return ToolChain::getTool(AC); | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 217 | } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 218 | } | 
|  | 219 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 220 | Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); } | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 221 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 222 | Tool *MachO::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 223 | return new tools::darwin::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 224 | } | 
| Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 225 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 226 | DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 227 | const ArgList &Args) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 228 | : Darwin(D, Triple, Args) {} | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 229 |  | 
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 230 | void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 231 | // For modern targets, promote certain warnings to errors. | 
|  | 232 | if (isTargetWatchOSBased() || getTriple().isArch64Bit()) { | 
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 233 | // Always enable -Wdeprecated-objc-isa-usage and promote it | 
|  | 234 | // to an error. | 
|  | 235 | CC1Args.push_back("-Wdeprecated-objc-isa-usage"); | 
|  | 236 | CC1Args.push_back("-Werror=deprecated-objc-isa-usage"); | 
|  | 237 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 238 | // For iOS and watchOS, also error about implicit function declarations, | 
|  | 239 | // as that can impact calling conventions. | 
|  | 240 | if (!isTargetMacOS()) | 
|  | 241 | CC1Args.push_back("-Werror=implicit-function-declaration"); | 
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 242 | } | 
|  | 243 | } | 
|  | 244 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 245 | /// \brief Determine whether Objective-C automated reference counting is | 
|  | 246 | /// enabled. | 
|  | 247 | static bool isObjCAutoRefCount(const ArgList &Args) { | 
|  | 248 | return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); | 
|  | 249 | } | 
|  | 250 |  | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 251 | void DarwinClang::AddLinkARCArgs(const ArgList &Args, | 
|  | 252 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 253 | // Avoid linking compatibility stubs on i386 mac. | 
|  | 254 | if (isTargetMacOS() && getArch() == llvm::Triple::x86) | 
|  | 255 | return; | 
|  | 256 |  | 
|  | 257 | ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true); | 
|  | 258 |  | 
|  | 259 | if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) && | 
|  | 260 | runtime.hasSubscripting()) | 
|  | 261 | return; | 
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 262 |  | 
|  | 263 | CmdArgs.push_back("-force_load"); | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 264 | SmallString<128> P(getDriver().ClangExecutable); | 
|  | 265 | llvm::sys::path::remove_filename(P); // 'clang' | 
|  | 266 | llvm::sys::path::remove_filename(P); // 'bin' | 
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 267 | llvm::sys::path::append(P, "lib", "arc", "libarclite_"); | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 268 | // Mash in the platform. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 269 | if (isTargetWatchOSSimulator()) | 
|  | 270 | P += "watchsimulator"; | 
|  | 271 | else if (isTargetWatchOS()) | 
|  | 272 | P += "watchos"; | 
|  | 273 | else if (isTargetTvOSSimulator()) | 
|  | 274 | P += "appletvsimulator"; | 
|  | 275 | else if (isTargetTvOS()) | 
|  | 276 | P += "appletvos"; | 
|  | 277 | else if (isTargetIOSSimulator()) | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 278 | P += "iphonesimulator"; | 
| Argyrios Kyrtzidis | 058b451 | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 279 | else if (isTargetIPhoneOS()) | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 280 | P += "iphoneos"; | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 281 | else | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 282 | P += "macosx"; | 
|  | 283 | P += ".a"; | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 284 |  | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 285 | CmdArgs.push_back(Args.MakeArgString(P)); | 
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 286 | } | 
|  | 287 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 288 | void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, | 
| Kuba Brecka | 2735a025 | 2014-10-31 00:08:57 +0000 | [diff] [blame] | 289 | StringRef DarwinLibName, bool AlwaysLink, | 
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 290 | bool IsEmbedded, bool AddRPath) const { | 
|  | 291 | SmallString<128> Dir(getDriver().ResourceDir); | 
|  | 292 | llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin"); | 
|  | 293 |  | 
|  | 294 | SmallString<128> P(Dir); | 
|  | 295 | llvm::sys::path::append(P, DarwinLibName); | 
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 296 |  | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 297 | // For now, allow missing resource libraries to support developers who may | 
| Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 298 | // not have compiler-rt checked out or integrated into their build (unless | 
|  | 299 | // we explicitly force linking with this library). | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 300 | if (AlwaysLink || getVFS().exists(P)) | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 301 | CmdArgs.push_back(Args.MakeArgString(P)); | 
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 302 |  | 
|  | 303 | // Adding the rpaths might negatively interact when other rpaths are involved, | 
|  | 304 | // so we should make sure we add the rpaths last, after all user-specified | 
|  | 305 | // rpaths. This is currently true from this place, but we need to be | 
|  | 306 | // careful if this function is ever called before user's rpaths are emitted. | 
|  | 307 | if (AddRPath) { | 
|  | 308 | assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library"); | 
|  | 309 |  | 
|  | 310 | // Add @executable_path to rpath to support having the dylib copied with | 
|  | 311 | // the executable. | 
|  | 312 | CmdArgs.push_back("-rpath"); | 
|  | 313 | CmdArgs.push_back("@executable_path"); | 
|  | 314 |  | 
|  | 315 | // Add the path to the resource dir to rpath to support using the dylib | 
|  | 316 | // from the default location without copying. | 
|  | 317 | CmdArgs.push_back("-rpath"); | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 318 | CmdArgs.push_back(Args.MakeArgString(Dir)); | 
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 319 | } | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 320 | } | 
|  | 321 |  | 
| Justin Bogner | 2fd95f6 | 2015-05-12 06:30:48 +0000 | [diff] [blame] | 322 | void Darwin::addProfileRTLibs(const ArgList &Args, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 323 | ArgStringList &CmdArgs) const { | 
| Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 324 | if (!needsProfileRT(Args)) return; | 
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 325 |  | 
| Chris Bieneman | 586d24b | 2015-11-20 00:19:21 +0000 | [diff] [blame] | 326 | // TODO: Clean this up once autoconf is gone | 
|  | 327 | SmallString<128> P(getDriver().ResourceDir); | 
|  | 328 | llvm::sys::path::append(P, "lib", "darwin"); | 
|  | 329 | const char *Library = "libclang_rt.profile_osx.a"; | 
|  | 330 |  | 
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 331 | // Select the appropriate runtime library for the target. | 
| Chris Bieneman | 586d24b | 2015-11-20 00:19:21 +0000 | [diff] [blame] | 332 | if (isTargetWatchOS()) { | 
|  | 333 | Library = "libclang_rt.profile_watchos.a"; | 
|  | 334 | } else if (isTargetWatchOSSimulator()) { | 
|  | 335 | llvm::sys::path::append(P, "libclang_rt.profile_watchossim.a"); | 
|  | 336 | Library = getVFS().exists(P) ? "libclang_rt.profile_watchossim.a" | 
|  | 337 | : "libclang_rt.profile_watchos.a"; | 
|  | 338 | } else if (isTargetTvOS()) { | 
|  | 339 | Library = "libclang_rt.profile_tvos.a"; | 
|  | 340 | } else if (isTargetTvOSSimulator()) { | 
|  | 341 | llvm::sys::path::append(P, "libclang_rt.profile_tvossim.a"); | 
|  | 342 | Library = getVFS().exists(P) ? "libclang_rt.profile_tvossim.a" | 
|  | 343 | : "libclang_rt.profile_tvos.a"; | 
|  | 344 | } else if (isTargetIPhoneOS()) { | 
|  | 345 | Library = "libclang_rt.profile_ios.a"; | 
|  | 346 | } else if (isTargetIOSSimulator()) { | 
|  | 347 | llvm::sys::path::append(P, "libclang_rt.profile_iossim.a"); | 
|  | 348 | Library = getVFS().exists(P) ? "libclang_rt.profile_iossim.a" | 
|  | 349 | : "libclang_rt.profile_ios.a"; | 
| Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame] | 350 | } else { | 
|  | 351 | assert(isTargetMacOS() && "unexpected non MacOS platform"); | 
| Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame] | 352 | } | 
| Chris Bieneman | 586d24b | 2015-11-20 00:19:21 +0000 | [diff] [blame] | 353 | AddLinkRuntimeLib(Args, CmdArgs, Library, | 
|  | 354 | /*AlwaysLink*/ true); | 
| Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 355 | return; | 
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 356 | } | 
|  | 357 |  | 
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 358 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, | 
|  | 359 | ArgStringList &CmdArgs, | 
|  | 360 | StringRef Sanitizer) const { | 
|  | 361 | if (!Args.hasArg(options::OPT_dynamiclib) && | 
|  | 362 | !Args.hasArg(options::OPT_bundle)) { | 
|  | 363 | // Sanitizer runtime libraries requires C++. | 
|  | 364 | AddCXXStdlibLibArgs(Args, CmdArgs); | 
|  | 365 | } | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 366 | // ASan is not supported on watchOS. | 
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 367 | assert(isTargetMacOS() || isTargetIOSSimulator()); | 
|  | 368 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 369 | AddLinkRuntimeLib( | 
|  | 370 | Args, CmdArgs, | 
|  | 371 | (Twine("libclang_rt.") + Sanitizer + "_" + OS + "_dynamic.dylib").str(), | 
|  | 372 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, | 
|  | 373 | /*AddRPath*/ true); | 
| Hans Wennborg | 10821e5 | 2015-04-09 18:47:01 +0000 | [diff] [blame] | 374 |  | 
|  | 375 | if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { | 
|  | 376 | // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export | 
|  | 377 | // all RTTI-related symbols that UBSan uses. | 
|  | 378 | CmdArgs.push_back("-lc++abi"); | 
|  | 379 | } | 
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 380 | } | 
|  | 381 |  | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 382 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, | 
|  | 383 | ArgStringList &CmdArgs) const { | 
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 384 | // Darwin only supports the compiler-rt based runtime libraries. | 
|  | 385 | switch (GetRuntimeLibType(Args)) { | 
|  | 386 | case ToolChain::RLT_CompilerRT: | 
|  | 387 | break; | 
|  | 388 | default: | 
|  | 389 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 390 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; | 
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 391 | return; | 
|  | 392 | } | 
|  | 393 |  | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 394 | // Darwin doesn't support real static executables, don't link any runtime | 
|  | 395 | // libraries with -static. | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 396 | if (Args.hasArg(options::OPT_static) || | 
|  | 397 | Args.hasArg(options::OPT_fapple_kext) || | 
|  | 398 | Args.hasArg(options::OPT_mkernel)) | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 399 | return; | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 400 |  | 
|  | 401 | // Reject -static-libgcc for now, we can deal with this when and if someone | 
|  | 402 | // cares. This is useful in situations where someone wants to statically link | 
|  | 403 | // something like libstdc++, and needs its runtime support routines. | 
|  | 404 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 405 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 406 | return; | 
|  | 407 | } | 
|  | 408 |  | 
| Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 409 | const SanitizerArgs &Sanitize = getSanitizerArgs(); | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 410 | if (Sanitize.needsAsanRt()) | 
|  | 411 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); | 
|  | 412 | if (Sanitize.needsUbsanRt()) | 
|  | 413 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); | 
| Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 414 | if (Sanitize.needsTsanRt()) | 
|  | 415 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); | 
| Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 416 | if (Sanitize.needsStatsRt()) { | 
|  | 417 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; | 
|  | 418 | AddLinkRuntimeLib(Args, CmdArgs, | 
|  | 419 | (Twine("libclang_rt.stats_client_") + OS + ".a").str(), | 
|  | 420 | /*AlwaysLink=*/true); | 
|  | 421 | AddLinkSanitizerLibArgs(Args, CmdArgs, "stats"); | 
|  | 422 | } | 
| Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 423 |  | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 424 | // Otherwise link libSystem, then the dynamic runtime library, and finally any | 
|  | 425 | // target specific static runtime library. | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 426 | CmdArgs.push_back("-lSystem"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 427 |  | 
|  | 428 | // Select the dynamic runtime library and the target specific static library. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 429 | if (isTargetWatchOSBased()) { | 
|  | 430 | // We currently always need a static runtime library for watchOS. | 
|  | 431 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); | 
|  | 432 | } else if (isTargetTvOSBased()) { | 
|  | 433 | // We currently always need a static runtime library for tvOS. | 
|  | 434 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); | 
|  | 435 | } else if (isTargetIOSBased()) { | 
| Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 436 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, | 
|  | 437 | // it never went into the SDK. | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 438 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 439 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && | 
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 440 | getTriple().getArch() != llvm::Triple::aarch64) | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 441 | CmdArgs.push_back("-lgcc_s.1"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 442 |  | 
| Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 443 | // We currently always need a static runtime library for iOS. | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 444 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 445 | } else { | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 446 | assert(isTargetMacOS() && "unexpected non MacOS platform"); | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 447 | // The dynamic runtime library was merged with libSystem for 10.6 and | 
|  | 448 | // beyond; only 10.4 and 10.5 need an additional runtime library. | 
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 449 | if (isMacosxVersionLT(10, 5)) | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 450 | CmdArgs.push_back("-lgcc_s.10.4"); | 
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 451 | else if (isMacosxVersionLT(10, 6)) | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 452 | CmdArgs.push_back("-lgcc_s.10.5"); | 
|  | 453 |  | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 454 | // 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] | 455 | // targeting 10.4, to provide versions of the static functions which were | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 456 | // omitted from 10.4.dylib. | 
|  | 457 | // | 
|  | 458 | // Unfortunately, that turned out to not be true, because Darwin system | 
|  | 459 | // headers can still use eprintf on i386, and it is not exported from | 
|  | 460 | // libSystem. Therefore, we still must provide a runtime library just for | 
|  | 461 | // the tiny tiny handful of projects that *might* use that symbol. | 
|  | 462 | if (isMacosxVersionLT(10, 5)) { | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 463 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 464 | } else { | 
|  | 465 | if (getTriple().getArch() == llvm::Triple::x86) | 
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 466 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); | 
|  | 467 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); | 
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 468 | } | 
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 469 | } | 
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 470 | } | 
|  | 471 |  | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 472 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { | 
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 473 | const OptTable &Opts = getDriver().getOpts(); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 474 |  | 
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 475 | // Support allowing the SDKROOT environment variable used by xcrun and other | 
|  | 476 | // Xcode tools to define the default sysroot, by making it the default for | 
|  | 477 | // isysroot. | 
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 478 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
|  | 479 | // Warn if the path does not exist. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 480 | if (!getVFS().exists(A->getValue())) | 
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 481 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); | 
|  | 482 | } else { | 
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 483 | if (char *env = ::getenv("SDKROOT")) { | 
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 484 | // We only use this value as the default if it is an absolute path, | 
|  | 485 | // exists, and it is not the root path. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 486 | if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) && | 
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 487 | StringRef(env) != "/") { | 
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 488 | Args.append(Args.MakeSeparateArg( | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 489 | nullptr, Opts.getOption(options::OPT_isysroot), env)); | 
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 490 | } | 
|  | 491 | } | 
|  | 492 | } | 
|  | 493 |  | 
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 494 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); | 
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 495 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 496 | Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ); | 
|  | 497 | Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ); | 
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 498 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 499 | if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 500 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 501 | << OSXVersion->getAsString(Args) | 
|  | 502 | << (iOSVersion ? iOSVersion : | 
|  | 503 | TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); | 
|  | 504 | iOSVersion = TvOSVersion = WatchOSVersion = nullptr; | 
|  | 505 | } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) { | 
|  | 506 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) | 
|  | 507 | << iOSVersion->getAsString(Args) | 
|  | 508 | << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); | 
|  | 509 | TvOSVersion = WatchOSVersion = nullptr; | 
|  | 510 | } else if (TvOSVersion && WatchOSVersion) { | 
|  | 511 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) | 
|  | 512 | << TvOSVersion->getAsString(Args) | 
|  | 513 | << WatchOSVersion->getAsString(Args); | 
|  | 514 | WatchOSVersion = nullptr; | 
|  | 515 | } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) { | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 516 | // If no deployment target was specified on the command line, check for | 
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 517 | // environment defines. | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 518 | std::string OSXTarget; | 
|  | 519 | std::string iOSTarget; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 520 | std::string TvOSTarget; | 
|  | 521 | std::string WatchOSTarget; | 
|  | 522 |  | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 523 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) | 
|  | 524 | OSXTarget = env; | 
|  | 525 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) | 
|  | 526 | iOSTarget = env; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 527 | if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET")) | 
|  | 528 | TvOSTarget = env; | 
|  | 529 | if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET")) | 
|  | 530 | WatchOSTarget = env; | 
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 531 |  | 
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 532 | // If there is no command-line argument to specify the Target version and | 
|  | 533 | // no environment variable defined, see if we can set the default based | 
|  | 534 | // on -isysroot. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 535 | if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() && | 
| Frederic Riss | 3ad83bd | 2016-01-12 23:47:59 +0000 | [diff] [blame] | 536 | TvOSTarget.empty() && Args.hasArg(options::OPT_isysroot)) { | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 537 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 538 | StringRef isysroot = A->getValue(); | 
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 539 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk | 
|  | 540 | size_t BeginSDK = isysroot.rfind("SDKs/"); | 
|  | 541 | size_t EndSDK = isysroot.rfind(".sdk"); | 
|  | 542 | if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { | 
|  | 543 | StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); | 
|  | 544 | // Slice the version number out. | 
|  | 545 | // Version number is between the first and the last number. | 
|  | 546 | size_t StartVer = SDK.find_first_of("0123456789"); | 
|  | 547 | size_t EndVer = SDK.find_last_of("0123456789"); | 
|  | 548 | if (StartVer != StringRef::npos && EndVer > StartVer) { | 
|  | 549 | StringRef Version = SDK.slice(StartVer, EndVer + 1); | 
|  | 550 | if (SDK.startswith("iPhoneOS") || | 
|  | 551 | SDK.startswith("iPhoneSimulator")) | 
|  | 552 | iOSTarget = Version; | 
|  | 553 | else if (SDK.startswith("MacOSX")) | 
|  | 554 | OSXTarget = Version; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 555 | else if (SDK.startswith("WatchOS") || | 
|  | 556 | SDK.startswith("WatchSimulator")) | 
|  | 557 | WatchOSTarget = Version; | 
|  | 558 | else if (SDK.startswith("AppleTVOS") || | 
|  | 559 | SDK.startswith("AppleTVSimulator")) | 
|  | 560 | TvOSTarget = Version; | 
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 561 | } | 
|  | 562 | } | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 563 | } | 
|  | 564 | } | 
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 565 |  | 
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 566 | // 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] | 567 | // from arch name and compute the version from the triple. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 568 | if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() && | 
|  | 569 | WatchOSTarget.empty()) { | 
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 570 | StringRef MachOArchName = getMachOArchName(Args); | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 571 | unsigned Major, Minor, Micro; | 
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 572 | if (MachOArchName == "armv7" || MachOArchName == "armv7s" || | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 573 | MachOArchName == "arm64") { | 
|  | 574 | getTriple().getiOSVersion(Major, Minor, Micro); | 
|  | 575 | llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' | 
|  | 576 | << Micro; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 577 | } else if (MachOArchName == "armv7k") { | 
|  | 578 | getTriple().getWatchOSVersion(Major, Minor, Micro); | 
|  | 579 | llvm::raw_string_ostream(WatchOSTarget) << Major << '.' << Minor << '.' | 
|  | 580 | << Micro; | 
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 581 | } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && | 
|  | 582 | MachOArchName != "armv7em") { | 
|  | 583 | if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { | 
|  | 584 | getDriver().Diag(diag::err_drv_invalid_darwin_version) | 
|  | 585 | << getTriple().getOSName(); | 
|  | 586 | } | 
|  | 587 | llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' | 
|  | 588 | << Micro; | 
|  | 589 | } | 
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 590 | } | 
| Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 591 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 592 | // Do not allow conflicts with the watchOS target. | 
|  | 593 | if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) { | 
|  | 594 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) | 
|  | 595 | << "WATCHOS_DEPLOYMENT_TARGET" | 
|  | 596 | << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" : | 
|  | 597 | "TVOS_DEPLOYMENT_TARGET"); | 
|  | 598 | } | 
|  | 599 |  | 
|  | 600 | // Do not allow conflicts with the tvOS target. | 
|  | 601 | if (!TvOSTarget.empty() && !iOSTarget.empty()) { | 
|  | 602 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) | 
|  | 603 | << "TVOS_DEPLOYMENT_TARGET" | 
|  | 604 | << "IPHONEOS_DEPLOYMENT_TARGET"; | 
|  | 605 | } | 
|  | 606 |  | 
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 607 | // Allow conflicts among OSX and iOS for historical reasons, but choose the | 
|  | 608 | // default platform. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 609 | if (!OSXTarget.empty() && (!iOSTarget.empty() || | 
|  | 610 | !WatchOSTarget.empty() || | 
|  | 611 | !TvOSTarget.empty())) { | 
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 612 | if (getTriple().getArch() == llvm::Triple::arm || | 
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 613 | getTriple().getArch() == llvm::Triple::aarch64 || | 
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 614 | getTriple().getArch() == llvm::Triple::thumb) | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 615 | OSXTarget = ""; | 
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 616 | else | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 617 | iOSTarget = WatchOSTarget = TvOSTarget = ""; | 
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 618 | } | 
| Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 619 |  | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 620 | if (!OSXTarget.empty()) { | 
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 621 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 622 | OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 623 | Args.append(OSXVersion); | 
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 624 | } else if (!iOSTarget.empty()) { | 
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 625 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 626 | iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); | 
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 627 | Args.append(iOSVersion); | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 628 | } else if (!TvOSTarget.empty()) { | 
|  | 629 | const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ); | 
|  | 630 | TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget); | 
|  | 631 | Args.append(TvOSVersion); | 
|  | 632 | } else if (!WatchOSTarget.empty()) { | 
|  | 633 | const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ); | 
|  | 634 | WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget); | 
|  | 635 | Args.append(WatchOSVersion); | 
| Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 636 | } | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 637 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 |  | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 639 | DarwinPlatformKind Platform; | 
|  | 640 | if (OSXVersion) | 
|  | 641 | Platform = MacOS; | 
|  | 642 | else if (iOSVersion) | 
|  | 643 | Platform = IPhoneOS; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 644 | else if (TvOSVersion) | 
|  | 645 | Platform = TvOS; | 
|  | 646 | else if (WatchOSVersion) | 
|  | 647 | Platform = WatchOS; | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 648 | else | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 649 | llvm_unreachable("Unable to infer Darwin variant"); | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 650 |  | 
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 651 | // Set the tool chain target information. | 
|  | 652 | unsigned Major, Minor, Micro; | 
|  | 653 | bool HadExtra; | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 654 | if (Platform == MacOS) { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 655 | assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && | 
|  | 656 | "Unknown target platform!"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 657 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, | 
|  | 658 | HadExtra) || | 
|  | 659 | HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 660 | getDriver().Diag(diag::err_drv_invalid_version_number) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 661 | << OSXVersion->getAsString(Args); | 
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 662 | } else if (Platform == IPhoneOS) { | 
|  | 663 | assert(iOSVersion && "Unknown target platform!"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 664 | if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, | 
|  | 665 | HadExtra) || | 
|  | 666 | HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100) | 
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 667 | getDriver().Diag(diag::err_drv_invalid_version_number) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 668 | << iOSVersion->getAsString(Args); | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 669 | } else if (Platform == TvOS) { | 
|  | 670 | if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, | 
|  | 671 | Micro, HadExtra) || HadExtra || | 
|  | 672 | Major >= 10 || Minor >= 100 || Micro >= 100) | 
|  | 673 | getDriver().Diag(diag::err_drv_invalid_version_number) | 
|  | 674 | << TvOSVersion->getAsString(Args); | 
|  | 675 | } else if (Platform == WatchOS) { | 
|  | 676 | if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor, | 
|  | 677 | Micro, HadExtra) || HadExtra || | 
|  | 678 | Major >= 10 || Minor >= 100 || Micro >= 100) | 
|  | 679 | getDriver().Diag(diag::err_drv_invalid_version_number) | 
|  | 680 | << WatchOSVersion->getAsString(Args); | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 681 | } else | 
|  | 682 | llvm_unreachable("unknown kind of Darwin platform"); | 
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 683 |  | 
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 684 | // Recognize iOS targets with an x86 architecture as the iOS simulator. | 
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 685 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 686 | getTriple().getArch() == llvm::Triple::x86_64)) | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 687 | Platform = IPhoneOSSimulator; | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 688 | if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 689 | getTriple().getArch() == llvm::Triple::x86_64)) | 
|  | 690 | Platform = TvOSSimulator; | 
|  | 691 | if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 692 | getTriple().getArch() == llvm::Triple::x86_64)) | 
|  | 693 | Platform = WatchOSSimulator; | 
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 694 |  | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 695 | setTarget(Platform, Major, Minor, Micro); | 
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 696 | } | 
|  | 697 |  | 
| Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 698 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 699 | ArgStringList &CmdArgs) const { | 
|  | 700 | CXXStdlibType Type = GetCXXStdlibType(Args); | 
|  | 701 |  | 
|  | 702 | switch (Type) { | 
|  | 703 | case ToolChain::CST_Libcxx: | 
|  | 704 | CmdArgs.push_back("-lc++"); | 
|  | 705 | break; | 
|  | 706 |  | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 707 | case ToolChain::CST_Libstdcxx: | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 708 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; | 
|  | 709 | // it was previously found in the gcc lib dir. However, for all the Darwin | 
|  | 710 | // platforms we care about it was -lstdc++.6, so we search for that | 
|  | 711 | // explicitly if we can't see an obvious -lstdc++ candidate. | 
|  | 712 |  | 
|  | 713 | // Check in the sysroot first. | 
|  | 714 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 715 | SmallString<128> P(A->getValue()); | 
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 716 | llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 717 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 718 | if (!getVFS().exists(P)) { | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 719 | llvm::sys::path::remove_filename(P); | 
|  | 720 | llvm::sys::path::append(P, "libstdc++.6.dylib"); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 721 | if (getVFS().exists(P)) { | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 722 | CmdArgs.push_back(Args.MakeArgString(P)); | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 723 | return; | 
|  | 724 | } | 
|  | 725 | } | 
|  | 726 | } | 
|  | 727 |  | 
|  | 728 | // Otherwise, look in the root. | 
| Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 729 | // FIXME: This should be removed someday when we don't have to care about | 
|  | 730 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 731 | if (!getVFS().exists("/usr/lib/libstdc++.dylib") && | 
|  | 732 | getVFS().exists("/usr/lib/libstdc++.6.dylib")) { | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 733 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); | 
|  | 734 | return; | 
|  | 735 | } | 
|  | 736 |  | 
|  | 737 | // Otherwise, let the linker search. | 
|  | 738 | CmdArgs.push_back("-lstdc++"); | 
|  | 739 | break; | 
|  | 740 | } | 
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 741 | } | 
|  | 742 |  | 
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 743 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, | 
|  | 744 | ArgStringList &CmdArgs) const { | 
|  | 745 |  | 
|  | 746 | // For Darwin platforms, use the compiler-rt-based support library | 
|  | 747 | // instead of the gcc-provided one (which is also incidentally | 
|  | 748 | // only present in the gcc lib dir, which makes it hard to find). | 
|  | 749 |  | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 750 | SmallString<128> P(getDriver().ResourceDir); | 
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 751 | llvm::sys::path::append(P, "lib", "darwin"); | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 752 |  | 
|  | 753 | // Use the newer cc_kext for iOS ARM after 6.0. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 754 | if (isTargetWatchOS()) { | 
|  | 755 | llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a"); | 
|  | 756 | } else if (isTargetTvOS()) { | 
|  | 757 | llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a"); | 
|  | 758 | } else if (isTargetIPhoneOS()) { | 
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 759 | llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a"); | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 760 | } else { | 
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 761 | llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 762 | } | 
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 763 |  | 
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 764 | // For now, allow missing resource libraries to support developers who may | 
|  | 765 | // not have compiler-rt checked out or integrated into their build. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 766 | if (getVFS().exists(P)) | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 767 | CmdArgs.push_back(Args.MakeArgString(P)); | 
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 768 | } | 
|  | 769 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 770 | DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, | 
|  | 771 | const char *BoundArch) const { | 
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 772 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); | 
|  | 773 | const OptTable &Opts = getDriver().getOpts(); | 
|  | 774 |  | 
|  | 775 | // FIXME: We really want to get out of the tool chain level argument | 
|  | 776 | // translation business, as it makes the driver functionality much | 
|  | 777 | // more opaque. For now, we follow gcc closely solely for the | 
|  | 778 | // purpose of easily achieving feature parity & testability. Once we | 
|  | 779 | // have something that works, we should reevaluate each translation | 
|  | 780 | // and try to push it down into tool specific logic. | 
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 781 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 782 | for (Arg *A : Args) { | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 783 | if (A->getOption().matches(options::OPT_Xarch__)) { | 
| Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 784 | // Skip this argument unless the architecture matches either the toolchain | 
|  | 785 | // triple arch, or the arch being bound. | 
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 786 | llvm::Triple::ArchType XarchArch = | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 787 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); | 
|  | 788 | if (!(XarchArch == getArch() || | 
|  | 789 | (BoundArch && | 
|  | 790 | XarchArch == | 
|  | 791 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 792 | continue; | 
|  | 793 |  | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 794 | Arg *OriginalArg = A; | 
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 795 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 796 | unsigned Prev = Index; | 
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 797 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 |  | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 799 | // If the argument parsing failed or more than one argument was | 
|  | 800 | // consumed, the -Xarch_ argument's parameter tried to consume | 
|  | 801 | // extra arguments. Emit an error and ignore. | 
|  | 802 | // | 
|  | 803 | // We also want to disallow any options which would alter the | 
|  | 804 | // driver behavior; that isn't going to work in our model. We | 
|  | 805 | // use isDriverOption() as an approximation, although things | 
|  | 806 | // like -O4 are going to slip through. | 
| Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 807 | if (!XarchArg || Index > Prev + 1) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 808 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 809 | << A->getAsString(Args); | 
| Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 810 | continue; | 
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 811 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 812 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 813 | << A->getAsString(Args); | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 814 | continue; | 
|  | 815 | } | 
|  | 816 |  | 
| Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 817 | XarchArg->setBaseArg(A); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 818 |  | 
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 819 | A = XarchArg.release(); | 
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 820 | DAL->AddSynthesizedArg(A); | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 821 |  | 
|  | 822 | // Linker input arguments require custom handling. The problem is that we | 
|  | 823 | // have already constructed the phase actions, so we can not treat them as | 
|  | 824 | // "input arguments". | 
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 825 | if (A->getOption().hasFlag(options::LinkerInput)) { | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 826 | // Convert the argument into individual Zlinker_input_args. | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 827 | for (const char *Value : A->getValues()) { | 
|  | 828 | DAL->AddSeparateArg( | 
|  | 829 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); | 
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 830 | } | 
|  | 831 | continue; | 
|  | 832 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | } | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 834 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 835 | // Sob. These is strictly gcc compatible for the time being. Apple | 
|  | 836 | // gcc translates options twice, which means that self-expanding | 
|  | 837 | // options add duplicates. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 838 | switch ((options::ID)A->getOption().getID()) { | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 839 | default: | 
|  | 840 | DAL->append(A); | 
|  | 841 | break; | 
|  | 842 |  | 
|  | 843 | case options::OPT_mkernel: | 
|  | 844 | case options::OPT_fapple_kext: | 
|  | 845 | DAL->append(A); | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 846 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 847 | break; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 848 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 849 | case options::OPT_dependency_file: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 850 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 851 | break; | 
|  | 852 |  | 
|  | 853 | case options::OPT_gfull: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 854 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 855 | DAL->AddFlagArg( | 
|  | 856 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 857 | break; | 
|  | 858 |  | 
|  | 859 | case options::OPT_gused: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 860 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 861 | DAL->AddFlagArg( | 
|  | 862 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 863 | break; | 
|  | 864 |  | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 865 | case options::OPT_shared: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 866 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 867 | break; | 
|  | 868 |  | 
|  | 869 | case options::OPT_fconstant_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 870 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 871 | break; | 
|  | 872 |  | 
|  | 873 | case options::OPT_fno_constant_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 874 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 875 | break; | 
|  | 876 |  | 
|  | 877 | case options::OPT_Wnonportable_cfstrings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 878 | DAL->AddFlagArg(A, | 
|  | 879 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 880 | break; | 
|  | 881 |  | 
|  | 882 | case options::OPT_Wno_nonportable_cfstrings: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 883 | DAL->AddFlagArg( | 
|  | 884 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 885 | break; | 
|  | 886 |  | 
|  | 887 | case options::OPT_fpascal_strings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 888 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 889 | break; | 
|  | 890 |  | 
|  | 891 | case options::OPT_fno_pascal_strings: | 
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 892 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 893 | break; | 
|  | 894 | } | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 895 | } | 
|  | 896 |  | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 897 | if (getTriple().getArch() == llvm::Triple::x86 || | 
|  | 898 | getTriple().getArch() == llvm::Triple::x86_64) | 
| Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 899 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 900 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), | 
|  | 901 | "core2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 902 |  | 
|  | 903 | // 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] | 904 | // how the driver driver works. | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 905 | if (BoundArch) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 906 | StringRef Name = BoundArch; | 
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 907 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); | 
|  | 908 | const Option MArch = Opts.getOption(options::OPT_march_EQ); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 909 |  | 
|  | 910 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, | 
|  | 911 | // which defines the list of which architectures we accept. | 
|  | 912 | if (Name == "ppc") | 
|  | 913 | ; | 
|  | 914 | else if (Name == "ppc601") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 915 | DAL->AddJoinedArg(nullptr, MCpu, "601"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 916 | else if (Name == "ppc603") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 917 | DAL->AddJoinedArg(nullptr, MCpu, "603"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 918 | else if (Name == "ppc604") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 919 | DAL->AddJoinedArg(nullptr, MCpu, "604"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 920 | else if (Name == "ppc604e") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 921 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 922 | else if (Name == "ppc750") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 923 | DAL->AddJoinedArg(nullptr, MCpu, "750"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 924 | else if (Name == "ppc7400") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 925 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 926 | else if (Name == "ppc7450") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 927 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 928 | else if (Name == "ppc970") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 929 | DAL->AddJoinedArg(nullptr, MCpu, "970"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 930 |  | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 931 | else if (Name == "ppc64" || Name == "ppc64le") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 932 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 933 |  | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 934 | else if (Name == "i386") | 
|  | 935 | ; | 
|  | 936 | else if (Name == "i486") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 937 | DAL->AddJoinedArg(nullptr, MArch, "i486"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 938 | else if (Name == "i586") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 939 | DAL->AddJoinedArg(nullptr, MArch, "i586"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 940 | else if (Name == "i686") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 941 | DAL->AddJoinedArg(nullptr, MArch, "i686"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 942 | else if (Name == "pentium") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 943 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 944 | else if (Name == "pentium2") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 945 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 946 | else if (Name == "pentpro") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 947 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 948 | else if (Name == "pentIIm3") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 949 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 950 |  | 
|  | 951 | else if (Name == "x86_64") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 952 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 953 | else if (Name == "x86_64h") { | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 954 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); | 
|  | 955 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); | 
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 956 | } | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 957 |  | 
|  | 958 | else if (Name == "arm") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 959 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 960 | else if (Name == "armv4t") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 961 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 962 | else if (Name == "armv5") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 963 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 964 | else if (Name == "xscale") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 965 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 966 | else if (Name == "armv6") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 967 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 968 | else if (Name == "armv6m") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 969 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 970 | else if (Name == "armv7") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 971 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 972 | else if (Name == "armv7em") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 973 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); | 
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 974 | else if (Name == "armv7k") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 975 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); | 
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 976 | else if (Name == "armv7m") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 977 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); | 
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 978 | else if (Name == "armv7s") | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 979 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); | 
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 980 | } | 
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 981 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 982 | return DAL; | 
|  | 983 | } | 
|  | 984 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 985 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, | 
|  | 986 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 987 | // Embedded targets are simple at the moment, not supporting sanitizers and | 
|  | 988 | // with different libraries for each member of the product { static, PIC } x | 
|  | 989 | // { hard-float, soft-float } | 
|  | 990 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); | 
| Saleem Abdulrasool | 06f6f99 | 2015-09-19 20:40:16 +0000 | [diff] [blame] | 991 | CompilerRT += | 
|  | 992 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) | 
|  | 993 | ? "hard" | 
|  | 994 | : "soft"; | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 995 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; | 
|  | 996 |  | 
|  | 997 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); | 
|  | 998 | } | 
|  | 999 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1000 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, | 
|  | 1001 | const char *BoundArch) const { | 
|  | 1002 | // First get the generic Apple args, before moving onto Darwin-specific ones. | 
|  | 1003 | DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); | 
|  | 1004 | const OptTable &Opts = getDriver().getOpts(); | 
|  | 1005 |  | 
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1006 | // If no architecture is bound, none of the translations here are relevant. | 
|  | 1007 | if (!BoundArch) | 
|  | 1008 | return DAL; | 
|  | 1009 |  | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1010 | // Add an explicit version min argument for the deployment target. We do this | 
|  | 1011 | // after argument translation because -Xarch_ arguments may add a version min | 
|  | 1012 | // argument. | 
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1013 | AddDeploymentTarget(*DAL); | 
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1014 |  | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1015 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. | 
|  | 1016 | // FIXME: It would be far better to avoid inserting those -static arguments, | 
|  | 1017 | // but we can't check the deployment target in the translation code until | 
|  | 1018 | // it is set here. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1019 | if (isTargetWatchOSBased() || | 
|  | 1020 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { | 
|  | 1021 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { | 
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1022 | Arg *A = *it; | 
|  | 1023 | ++it; | 
|  | 1024 | if (A->getOption().getID() != options::OPT_mkernel && | 
|  | 1025 | A->getOption().getID() != options::OPT_fapple_kext) | 
|  | 1026 | continue; | 
|  | 1027 | assert(it != ie && "unexpected argument translation"); | 
|  | 1028 | A = *it; | 
|  | 1029 | assert(A->getOption().getID() == options::OPT_static && | 
|  | 1030 | "missing expected -static argument"); | 
|  | 1031 | it = DAL->getArgs().erase(it); | 
|  | 1032 | } | 
|  | 1033 | } | 
|  | 1034 |  | 
| Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1035 | // Default to use libc++ on OS X 10.9+ and iOS 7+. | 
|  | 1036 | if (((isTargetMacOS() && !isMacosxVersionLT(10, 9)) || | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1037 | (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) || | 
|  | 1038 | isTargetWatchOSBased()) && | 
| Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1039 | !Args.getLastArg(options::OPT_stdlib_EQ)) | 
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1040 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), | 
|  | 1041 | "libc++"); | 
| Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1042 |  | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1043 | // Validate the C++ standard library choice. | 
|  | 1044 | CXXStdlibType Type = GetCXXStdlibType(*DAL); | 
|  | 1045 | if (Type == ToolChain::CST_Libcxx) { | 
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1046 | // Check whether the target provides libc++. | 
|  | 1047 | StringRef where; | 
|  | 1048 |  | 
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1049 | // Complain about targeting iOS < 5.0 in any way. | 
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1050 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) | 
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1051 | where = "iOS 5.0"; | 
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1052 |  | 
|  | 1053 | if (where != StringRef()) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1054 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; | 
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1055 | } | 
|  | 1056 | } | 
|  | 1057 |  | 
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1058 | return DAL; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1060 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1061 | bool MachO::IsUnwindTablesDefault() const { | 
| Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1062 | return getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1063 | } | 
|  | 1064 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1065 | bool MachO::UseDwarfDebugFlags() const { | 
| Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1066 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) | 
|  | 1067 | return S[0] != '\0'; | 
|  | 1068 | return false; | 
|  | 1069 | } | 
|  | 1070 |  | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1071 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { | 
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1072 | // Darwin uses SjLj exceptions on ARM. | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1073 | if (getTriple().getArch() != llvm::Triple::arm && | 
|  | 1074 | getTriple().getArch() != llvm::Triple::thumb) | 
|  | 1075 | return false; | 
|  | 1076 |  | 
| Tim Northover | c741b04 | 2015-11-17 18:27:27 +0000 | [diff] [blame] | 1077 | // Only watchOS uses the new DWARF/Compact unwinding method. | 
|  | 1078 | return !isTargetWatchOS(); | 
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1079 | } | 
|  | 1080 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1081 | bool MachO::isPICDefault() const { return true; } | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1082 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1083 | bool MachO::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1084 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1085 | bool MachO::isPICDefaultForced() const { | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1086 | return (getArch() == llvm::Triple::x86_64 || | 
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1087 | getArch() == llvm::Triple::aarch64); | 
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1088 | } | 
|  | 1089 |  | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1090 | bool MachO::SupportsProfiling() const { | 
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1091 | // Profiling instrumentation is only supported on x86. | 
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1092 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1093 | } | 
|  | 1094 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1095 | void Darwin::addMinVersionArgs(const ArgList &Args, | 
|  | 1096 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1097 | VersionTuple TargetVersion = getTargetVersion(); | 
|  | 1098 |  | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1099 | if (isTargetWatchOS()) | 
|  | 1100 | CmdArgs.push_back("-watchos_version_min"); | 
|  | 1101 | else if (isTargetWatchOSSimulator()) | 
|  | 1102 | CmdArgs.push_back("-watchos_simulator_version_min"); | 
|  | 1103 | else if (isTargetTvOS()) | 
|  | 1104 | CmdArgs.push_back("-tvos_version_min"); | 
|  | 1105 | else if (isTargetTvOSSimulator()) | 
|  | 1106 | CmdArgs.push_back("-tvos_simulator_version_min"); | 
|  | 1107 | else if (isTargetIOSSimulator()) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1108 | CmdArgs.push_back("-ios_simulator_version_min"); | 
| Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1109 | else if (isTargetIOSBased()) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1110 | CmdArgs.push_back("-iphoneos_version_min"); | 
|  | 1111 | else { | 
|  | 1112 | assert(isTargetMacOS() && "unexpected target"); | 
|  | 1113 | CmdArgs.push_back("-macosx_version_min"); | 
|  | 1114 | } | 
|  | 1115 |  | 
|  | 1116 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); | 
|  | 1117 | } | 
|  | 1118 |  | 
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1119 | void Darwin::addStartObjectFileArgs(const ArgList &Args, | 
|  | 1120 | ArgStringList &CmdArgs) const { | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1121 | // Derived from startfile spec. | 
|  | 1122 | if (Args.hasArg(options::OPT_dynamiclib)) { | 
|  | 1123 | // Derived from darwin_dylib1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1124 | if (isTargetWatchOSBased()) { | 
|  | 1125 | ; // watchOS does not need dylib1.o. | 
|  | 1126 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1127 | ; // iOS simulator does not need dylib1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1128 | } else if (isTargetIPhoneOS()) { | 
|  | 1129 | if (isIPhoneOSVersionLT(3, 1)) | 
|  | 1130 | CmdArgs.push_back("-ldylib1.o"); | 
|  | 1131 | } else { | 
|  | 1132 | if (isMacosxVersionLT(10, 5)) | 
|  | 1133 | CmdArgs.push_back("-ldylib1.o"); | 
|  | 1134 | else if (isMacosxVersionLT(10, 6)) | 
|  | 1135 | CmdArgs.push_back("-ldylib1.10.5.o"); | 
|  | 1136 | } | 
|  | 1137 | } else { | 
|  | 1138 | if (Args.hasArg(options::OPT_bundle)) { | 
|  | 1139 | if (!Args.hasArg(options::OPT_static)) { | 
|  | 1140 | // Derived from darwin_bundle1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1141 | if (isTargetWatchOSBased()) { | 
|  | 1142 | ; // watchOS does not need bundle1.o. | 
|  | 1143 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1144 | ; // iOS simulator does not need bundle1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1145 | } else if (isTargetIPhoneOS()) { | 
|  | 1146 | if (isIPhoneOSVersionLT(3, 1)) | 
|  | 1147 | CmdArgs.push_back("-lbundle1.o"); | 
|  | 1148 | } else { | 
|  | 1149 | if (isMacosxVersionLT(10, 6)) | 
|  | 1150 | CmdArgs.push_back("-lbundle1.o"); | 
|  | 1151 | } | 
|  | 1152 | } | 
|  | 1153 | } else { | 
|  | 1154 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { | 
|  | 1155 | if (Args.hasArg(options::OPT_static) || | 
|  | 1156 | Args.hasArg(options::OPT_object) || | 
|  | 1157 | Args.hasArg(options::OPT_preload)) { | 
|  | 1158 | CmdArgs.push_back("-lgcrt0.o"); | 
|  | 1159 | } else { | 
|  | 1160 | CmdArgs.push_back("-lgcrt1.o"); | 
|  | 1161 |  | 
|  | 1162 | // darwin_crt2 spec is empty. | 
|  | 1163 | } | 
|  | 1164 | // By default on OS X 10.8 and later, we don't link with a crt1.o | 
|  | 1165 | // file and the linker knows to use _main as the entry point.  But, | 
|  | 1166 | // when compiling with -pg, we need to link with the gcrt1.o file, | 
|  | 1167 | // so pass the -no_new_main option to tell the linker to use the | 
|  | 1168 | // "start" symbol as the entry point. | 
|  | 1169 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) | 
|  | 1170 | CmdArgs.push_back("-no_new_main"); | 
|  | 1171 | } else { | 
|  | 1172 | if (Args.hasArg(options::OPT_static) || | 
|  | 1173 | Args.hasArg(options::OPT_object) || | 
|  | 1174 | Args.hasArg(options::OPT_preload)) { | 
|  | 1175 | CmdArgs.push_back("-lcrt0.o"); | 
|  | 1176 | } else { | 
|  | 1177 | // Derived from darwin_crt1 spec. | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1178 | if (isTargetWatchOSBased()) { | 
|  | 1179 | ; // watchOS does not need crt1.o. | 
|  | 1180 | } else if (isTargetIOSSimulator()) { | 
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1181 | ; // iOS simulator does not need crt1.o. | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1182 | } else if (isTargetIPhoneOS()) { | 
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1183 | if (getArch() == llvm::Triple::aarch64) | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1184 | ; // iOS does not need any crt1 files for arm64 | 
|  | 1185 | else if (isIPhoneOSVersionLT(3, 1)) | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1186 | CmdArgs.push_back("-lcrt1.o"); | 
|  | 1187 | else if (isIPhoneOSVersionLT(6, 0)) | 
|  | 1188 | CmdArgs.push_back("-lcrt1.3.1.o"); | 
|  | 1189 | } else { | 
|  | 1190 | if (isMacosxVersionLT(10, 5)) | 
|  | 1191 | CmdArgs.push_back("-lcrt1.o"); | 
|  | 1192 | else if (isMacosxVersionLT(10, 6)) | 
|  | 1193 | CmdArgs.push_back("-lcrt1.10.5.o"); | 
|  | 1194 | else if (isMacosxVersionLT(10, 8)) | 
|  | 1195 | CmdArgs.push_back("-lcrt1.10.6.o"); | 
|  | 1196 |  | 
|  | 1197 | // darwin_crt2 spec is empty. | 
|  | 1198 | } | 
|  | 1199 | } | 
|  | 1200 | } | 
|  | 1201 | } | 
|  | 1202 | } | 
|  | 1203 |  | 
|  | 1204 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1205 | !isTargetWatchOS() && | 
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1206 | isMacosxVersionLT(10, 5)) { | 
|  | 1207 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); | 
|  | 1208 | CmdArgs.push_back(Str); | 
|  | 1209 | } | 
|  | 1210 | } | 
|  | 1211 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1212 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } | 
| Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1213 |  | 
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1214 | void Darwin::CheckObjCARC() const { | 
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1215 | if (isTargetIOSBased() || isTargetWatchOSBased() || | 
|  | 1216 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) | 
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1217 | return; | 
| John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1218 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); | 
| Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1219 | } | 
|  | 1220 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1221 | SanitizerMask Darwin::getSupportedSanitizers() const { | 
|  | 1222 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1223 | if (isTargetMacOS() || isTargetIOSSimulator()) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1224 | Res |= SanitizerKind::Address; | 
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1225 | if (isTargetMacOS()) { | 
|  | 1226 | if (!isMacosxVersionLT(10, 9)) | 
|  | 1227 | Res |= SanitizerKind::Vptr; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1228 | Res |= SanitizerKind::SafeStack; | 
| Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 1229 | Res |= SanitizerKind::Thread; | 
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1230 | } | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1231 | return Res; | 
|  | 1232 | } | 
|  | 1233 |  | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1234 | /// Generic_GCC - A tool chain using the 'gcc' command to perform | 
|  | 1235 | /// all subcommands; this relies on gcc translating the majority of | 
|  | 1236 | /// command line options. | 
|  | 1237 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1238 | /// \brief Parse a GCCVersion object out of a string of text. | 
|  | 1239 | /// | 
|  | 1240 | /// This is the primary means of forming GCCVersion objects. | 
|  | 1241 | /*static*/ | 
|  | 1242 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1243 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1244 | std::pair<StringRef, StringRef> First = VersionText.split('.'); | 
|  | 1245 | std::pair<StringRef, StringRef> Second = First.second.split('.'); | 
|  | 1246 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1247 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; | 
|  | 1248 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1249 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1250 | GoodVersion.MajorStr = First.first.str(); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1251 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1252 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1253 | GoodVersion.MinorStr = Second.first.str(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1254 |  | 
|  | 1255 | // First look for a number prefix and parse that if present. Otherwise just | 
|  | 1256 | // stash the entire patch string in the suffix, and leave the number | 
|  | 1257 | // unspecified. This covers versions strings such as: | 
|  | 1258 | //   4.4 | 
|  | 1259 | //   4.4.0 | 
|  | 1260 | //   4.4.x | 
|  | 1261 | //   4.4.2-rc4 | 
|  | 1262 | //   4.4.x-patched | 
|  | 1263 | // And retains any patch number it finds. | 
|  | 1264 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); | 
|  | 1265 | if (!PatchText.empty()) { | 
| Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1266 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1267 | // Try to parse the number and any suffix. | 
|  | 1268 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || | 
|  | 1269 | GoodVersion.Patch < 0) | 
|  | 1270 | return BadVersion; | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1271 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1272 | } | 
|  | 1273 | } | 
|  | 1274 |  | 
|  | 1275 | return GoodVersion; | 
|  | 1276 | } | 
|  | 1277 |  | 
|  | 1278 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1279 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, | 
|  | 1280 | int RHSPatch, | 
|  | 1281 | StringRef RHSPatchSuffix) const { | 
|  | 1282 | if (Major != RHSMajor) | 
|  | 1283 | return Major < RHSMajor; | 
|  | 1284 | if (Minor != RHSMinor) | 
|  | 1285 | return Minor < RHSMinor; | 
|  | 1286 | if (Patch != RHSPatch) { | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1287 | // Note that versions without a specified patch sort higher than those with | 
|  | 1288 | // a patch. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1289 | if (RHSPatch == -1) | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1290 | return true; | 
|  | 1291 | if (Patch == -1) | 
|  | 1292 | return false; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1293 |  | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1294 | // Otherwise just sort on the patch itself. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1295 | return Patch < RHSPatch; | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1296 | } | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1297 | if (PatchSuffix != RHSPatchSuffix) { | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1298 | // Sort empty suffixes higher. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1299 | if (RHSPatchSuffix.empty()) | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1300 | return true; | 
|  | 1301 | if (PatchSuffix.empty()) | 
| Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1302 | return false; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1303 |  | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1304 | // Provide a lexicographic sort to make this a total ordering. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1305 | return PatchSuffix < RHSPatchSuffix; | 
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1306 | } | 
|  | 1307 |  | 
|  | 1308 | // The versions are equal. | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1309 | return false; | 
|  | 1310 | } | 
|  | 1311 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1312 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1313 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); | 
|  | 1314 | if (A) | 
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1315 | return A->getValue(); | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1316 | return GCC_INSTALL_PREFIX; | 
|  | 1317 | } | 
|  | 1318 |  | 
| Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1319 | /// \brief Initialize a GCCInstallationDetector from the driver. | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1320 | /// | 
|  | 1321 | /// This performs all of the autodetection and sets up the various paths. | 
| Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1322 | /// Once constructed, a GCCInstallationDetector is essentially immutable. | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1323 | /// | 
|  | 1324 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and | 
|  | 1325 | /// should instead pull the target out of the driver. This is currently | 
|  | 1326 | /// necessary because the driver doesn't store the final version of the target | 
|  | 1327 | /// triple. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1328 | void Generic_GCC::GCCInstallationDetector::init( | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1329 | const llvm::Triple &TargetTriple, const ArgList &Args, | 
| Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1330 | ArrayRef<std::string> ExtraTripleAliases) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1331 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() | 
|  | 1332 | ? TargetTriple.get64BitArchVariant() | 
|  | 1333 | : TargetTriple.get32BitArchVariant(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1334 | // The library directories which may contain GCC installations. | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1335 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1336 | // The compatible GCC triples for this particular architecture. | 
| Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1337 | SmallVector<StringRef, 16> CandidateTripleAliases; | 
|  | 1338 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1339 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, | 
|  | 1340 | CandidateTripleAliases, CandidateBiarchLibDirs, | 
|  | 1341 | CandidateBiarchTripleAliases); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1342 |  | 
|  | 1343 | // Compute the set of prefixes for our search. | 
|  | 1344 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), | 
|  | 1345 | D.PrefixDirs.end()); | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1346 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1347 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); | 
|  | 1348 | if (GCCToolchainDir != "") { | 
|  | 1349 | if (GCCToolchainDir.back() == '/') | 
|  | 1350 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1351 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1352 | Prefixes.push_back(GCCToolchainDir); | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1353 | } else { | 
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1354 | // If we have a SysRoot, try that first. | 
|  | 1355 | if (!D.SysRoot.empty()) { | 
|  | 1356 | Prefixes.push_back(D.SysRoot); | 
|  | 1357 | Prefixes.push_back(D.SysRoot + "/usr"); | 
|  | 1358 | } | 
|  | 1359 |  | 
|  | 1360 | // Then look for gcc installed alongside clang. | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1361 | Prefixes.push_back(D.InstalledDir + "/.."); | 
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1362 |  | 
|  | 1363 | // And finally in /usr. | 
|  | 1364 | if (D.SysRoot.empty()) | 
|  | 1365 | Prefixes.push_back("/usr"); | 
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1366 | } | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1367 |  | 
|  | 1368 | // Loop over the various components which exist and select the best GCC | 
|  | 1369 | // installation available. GCC installs are ranked by version number. | 
|  | 1370 | Version = GCCVersion::Parse("0.0.0"); | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1371 | for (const std::string &Prefix : Prefixes) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1372 | if (!D.getVFS().exists(Prefix)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1373 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1374 | for (StringRef Suffix : CandidateLibDirs) { | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1375 | const std::string LibDir = Prefix + Suffix.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1376 | if (!D.getVFS().exists(LibDir)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1377 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1378 | for (StringRef Candidate : ExtraTripleAliases) // Try these first. | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1379 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1380 | for (StringRef Candidate : CandidateTripleAliases) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1381 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1382 | } | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1383 | for (StringRef Suffix : CandidateBiarchLibDirs) { | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1384 | const std::string LibDir = Prefix + Suffix.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1385 | if (!D.getVFS().exists(LibDir)) | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1386 | continue; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1387 | for (StringRef Candidate : CandidateBiarchTripleAliases) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1388 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1389 | /*NeedsBiarchSuffix=*/ true); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1390 | } | 
|  | 1391 | } | 
|  | 1392 | } | 
|  | 1393 |  | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1394 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1395 | for (const auto &InstallPath : CandidateGCCInstallPaths) | 
|  | 1396 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1397 |  | 
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1398 | if (!GCCInstallPath.empty()) | 
|  | 1399 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; | 
|  | 1400 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1401 | for (const auto &Multilib : Multilibs) | 
|  | 1402 | OS << "Candidate multilib: " << Multilib << "\n"; | 
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1403 |  | 
|  | 1404 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) | 
|  | 1405 | OS << "Selected multilib: " << SelectedMultilib << "\n"; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1406 | } | 
|  | 1407 |  | 
|  | 1408 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { | 
|  | 1409 | if (BiarchSibling.hasValue()) { | 
|  | 1410 | M = BiarchSibling.getValue(); | 
|  | 1411 | return true; | 
|  | 1412 | } | 
|  | 1413 | return false; | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1414 | } | 
|  | 1415 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1416 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1417 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1418 | SmallVectorImpl<StringRef> &LibDirs, | 
|  | 1419 | SmallVectorImpl<StringRef> &TripleAliases, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1420 | SmallVectorImpl<StringRef> &BiarchLibDirs, | 
|  | 1421 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1422 | // Declare a bunch of static data sets that we'll select between below. These | 
|  | 1423 | // are specifically designed to always refer to string literals to avoid any | 
|  | 1424 | // lifetime or initialization issues. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1425 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1426 | static const char *const AArch64Triples[] = { | 
|  | 1427 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", | 
|  | 1428 | "aarch64-redhat-linux"}; | 
|  | 1429 | static const char *const AArch64beLibDirs[] = {"/lib"}; | 
|  | 1430 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", | 
|  | 1431 | "aarch64_be-linux-gnu"}; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1432 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1433 | static const char *const ARMLibDirs[] = {"/lib"}; | 
|  | 1434 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", | 
|  | 1435 | "arm-linux-androideabi"}; | 
|  | 1436 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", | 
|  | 1437 | "armv7hl-redhat-linux-gnueabi"}; | 
|  | 1438 | static const char *const ARMebLibDirs[] = {"/lib"}; | 
|  | 1439 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", | 
|  | 1440 | "armeb-linux-androideabi"}; | 
|  | 1441 | static const char *const ARMebHFTriples[] = { | 
|  | 1442 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1443 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1444 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1445 | static const char *const X86_64Triples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1446 | "x86_64-linux-gnu",       "x86_64-unknown-linux-gnu", | 
|  | 1447 | "x86_64-pc-linux-gnu",    "x86_64-redhat-linux6E", | 
|  | 1448 | "x86_64-redhat-linux",    "x86_64-suse-linux", | 
|  | 1449 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", | 
|  | 1450 | "x86_64-slackware-linux", "x86_64-linux-android", | 
|  | 1451 | "x86_64-unknown-linux"}; | 
|  | 1452 | static const char *const X32LibDirs[] = {"/libx32"}; | 
|  | 1453 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1454 | static const char *const X86Triples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1455 | "i686-linux-gnu",       "i686-pc-linux-gnu",     "i486-linux-gnu", | 
|  | 1456 | "i386-linux-gnu",       "i386-redhat-linux6E",   "i686-redhat-linux", | 
|  | 1457 | "i586-redhat-linux",    "i386-redhat-linux",     "i586-suse-linux", | 
|  | 1458 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", | 
|  | 1459 | "i586-linux-gnu"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1460 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1461 | static const char *const MIPSLibDirs[] = {"/lib"}; | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1462 | static const char *const MIPSTriples[] = {"mips-linux-gnu", "mips-mti-linux", | 
|  | 1463 | "mips-mti-linux-gnu", | 
|  | 1464 | "mips-img-linux-gnu"}; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1465 | static const char *const MIPSELLibDirs[] = {"/lib"}; | 
|  | 1466 | static const char *const MIPSELTriples[] = { | 
|  | 1467 | "mipsel-linux-gnu", "mipsel-linux-android", "mips-img-linux-gnu"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1468 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1469 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1470 | static const char *const MIPS64Triples[] = { | 
|  | 1471 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", | 
|  | 1472 | "mips64-linux-gnuabi64"}; | 
|  | 1473 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; | 
|  | 1474 | static const char *const MIPS64ELTriples[] = { | 
|  | 1475 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", | 
|  | 1476 | "mips64el-linux-android", "mips64el-linux-gnuabi64"}; | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1477 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1478 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1479 | static const char *const PPCTriples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1480 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", | 
|  | 1481 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; | 
|  | 1482 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1483 | static const char *const PPC64Triples[] = { | 
|  | 1484 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", | 
|  | 1485 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; | 
|  | 1486 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; | 
|  | 1487 | static const char *const PPC64LETriples[] = { | 
|  | 1488 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", | 
|  | 1489 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1490 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1491 | static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; | 
|  | 1492 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", | 
|  | 1493 | "sparcv8-linux-gnu"}; | 
|  | 1494 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; | 
|  | 1495 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", | 
|  | 1496 | "sparcv9-linux-gnu"}; | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1497 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1498 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1499 | static const char *const SystemZTriples[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1500 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", | 
|  | 1501 | "s390x-suse-linux", "s390x-redhat-linux"}; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1502 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1503 | // Solaris. | 
|  | 1504 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; | 
|  | 1505 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", | 
|  | 1506 | "i386-pc-solaris2.11"}; | 
|  | 1507 |  | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1508 | using std::begin; | 
|  | 1509 | using std::end; | 
|  | 1510 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1511 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { | 
|  | 1512 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); | 
|  | 1513 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1514 | return; | 
|  | 1515 | } | 
|  | 1516 |  | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1517 | switch (TargetTriple.getArch()) { | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1518 | case llvm::Triple::aarch64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1519 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); | 
|  | 1520 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); | 
|  | 1521 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); | 
|  | 1522 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1523 | break; | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1524 | case llvm::Triple::aarch64_be: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1525 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); | 
|  | 1526 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); | 
|  | 1527 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); | 
|  | 1528 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1529 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1530 | case llvm::Triple::arm: | 
|  | 1531 | case llvm::Triple::thumb: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1532 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1533 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1534 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1535 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1536 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1537 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1538 | break; | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1539 | case llvm::Triple::armeb: | 
|  | 1540 | case llvm::Triple::thumbeb: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1541 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1542 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1543 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1544 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1545 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1546 | } | 
|  | 1547 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1548 | case llvm::Triple::x86_64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1549 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); | 
|  | 1550 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
|  | 1551 | // x32 is always available when x86_64 is available, so adding it as | 
|  | 1552 | // secondary arch with x86_64 triples | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1553 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1554 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); | 
|  | 1555 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1556 | } else { | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1557 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); | 
|  | 1558 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1559 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1560 | break; | 
|  | 1561 | case llvm::Triple::x86: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1562 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); | 
|  | 1563 | TripleAliases.append(begin(X86Triples), end(X86Triples)); | 
|  | 1564 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); | 
|  | 1565 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1566 | break; | 
|  | 1567 | case llvm::Triple::mips: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1568 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); | 
|  | 1569 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
|  | 1570 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); | 
|  | 1571 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1572 | break; | 
|  | 1573 | case llvm::Triple::mipsel: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1574 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); | 
|  | 1575 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); | 
|  | 1576 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
|  | 1577 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); | 
|  | 1578 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1579 | break; | 
|  | 1580 | case llvm::Triple::mips64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1581 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); | 
|  | 1582 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); | 
|  | 1583 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); | 
|  | 1584 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1585 | break; | 
|  | 1586 | case llvm::Triple::mips64el: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1587 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); | 
|  | 1588 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); | 
|  | 1589 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); | 
|  | 1590 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); | 
|  | 1591 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1592 | break; | 
|  | 1593 | case llvm::Triple::ppc: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1594 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); | 
|  | 1595 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); | 
|  | 1596 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); | 
|  | 1597 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1598 | break; | 
|  | 1599 | case llvm::Triple::ppc64: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1600 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); | 
|  | 1601 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); | 
|  | 1602 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); | 
|  | 1603 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1604 | break; | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1605 | case llvm::Triple::ppc64le: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1606 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); | 
|  | 1607 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1608 | break; | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1609 | case llvm::Triple::sparc: | 
| Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1610 | case llvm::Triple::sparcel: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1611 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); | 
|  | 1612 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); | 
|  | 1613 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); | 
|  | 1614 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1615 | break; | 
|  | 1616 | case llvm::Triple::sparcv9: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1617 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); | 
|  | 1618 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); | 
|  | 1619 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); | 
|  | 1620 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); | 
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1621 | break; | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1622 | case llvm::Triple::systemz: | 
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1623 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); | 
|  | 1624 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); | 
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1625 | break; | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1626 | default: | 
|  | 1627 | // By default, just rely on the standard lib directories and the original | 
|  | 1628 | // triple. | 
|  | 1629 | break; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1630 | } | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1631 |  | 
|  | 1632 | // Always append the drivers target triple to the end, in case it doesn't | 
|  | 1633 | // match any of our aliases. | 
|  | 1634 | TripleAliases.push_back(TargetTriple.str()); | 
|  | 1635 |  | 
|  | 1636 | // Also include the multiarch variant if it's different. | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1637 | if (TargetTriple.str() != BiarchTriple.str()) | 
|  | 1638 | BiarchTripleAliases.push_back(BiarchTriple.str()); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1639 | } | 
|  | 1640 |  | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1641 | // \brief -- try common CUDA installation paths looking for files we need for | 
|  | 1642 | // CUDA compilation. | 
|  | 1643 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1644 | void Generic_GCC::CudaInstallationDetector::init( | 
|  | 1645 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { | 
| NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1646 | SmallVector<std::string, 4> CudaPathCandidates; | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1647 |  | 
|  | 1648 | if (Args.hasArg(options::OPT_cuda_path_EQ)) | 
|  | 1649 | CudaPathCandidates.push_back( | 
|  | 1650 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); | 
|  | 1651 | else { | 
|  | 1652 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 1653 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.5"); | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1654 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); | 
|  | 1655 | } | 
|  | 1656 |  | 
| Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1657 | for (const auto &CudaPath : CudaPathCandidates) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1658 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1659 | continue; | 
|  | 1660 |  | 
|  | 1661 | CudaInstallPath = CudaPath; | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 1662 | CudaBinPath = CudaPath + "/bin"; | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1663 | CudaIncludePath = CudaInstallPath + "/include"; | 
|  | 1664 | CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice"; | 
|  | 1665 | CudaLibPath = | 
|  | 1666 | CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); | 
|  | 1667 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1668 | if (!(D.getVFS().exists(CudaIncludePath) && | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 1669 | D.getVFS().exists(CudaBinPath) && D.getVFS().exists(CudaLibPath) && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1670 | D.getVFS().exists(CudaLibDevicePath))) | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1671 | continue; | 
|  | 1672 |  | 
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1673 | std::error_code EC; | 
|  | 1674 | for (llvm::sys::fs::directory_iterator LI(CudaLibDevicePath, EC), LE; | 
|  | 1675 | !EC && LI != LE; LI = LI.increment(EC)) { | 
|  | 1676 | StringRef FilePath = LI->path(); | 
|  | 1677 | StringRef FileName = llvm::sys::path::filename(FilePath); | 
|  | 1678 | // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc | 
|  | 1679 | const StringRef LibDeviceName = "libdevice."; | 
|  | 1680 | if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc"))) | 
|  | 1681 | continue; | 
|  | 1682 | StringRef GpuArch = FileName.slice( | 
|  | 1683 | LibDeviceName.size(), FileName.find('.', LibDeviceName.size())); | 
|  | 1684 | CudaLibDeviceMap[GpuArch] = FilePath.str(); | 
|  | 1685 | // Insert map entries for specifc devices with this compute capability. | 
|  | 1686 | if (GpuArch == "compute_20") { | 
|  | 1687 | CudaLibDeviceMap["sm_20"] = FilePath; | 
|  | 1688 | CudaLibDeviceMap["sm_21"] = FilePath; | 
|  | 1689 | } else if (GpuArch == "compute_30") { | 
|  | 1690 | CudaLibDeviceMap["sm_30"] = FilePath; | 
|  | 1691 | CudaLibDeviceMap["sm_32"] = FilePath; | 
|  | 1692 | } else if (GpuArch == "compute_35") { | 
|  | 1693 | CudaLibDeviceMap["sm_35"] = FilePath; | 
|  | 1694 | CudaLibDeviceMap["sm_37"] = FilePath; | 
|  | 1695 | } | 
|  | 1696 | } | 
|  | 1697 |  | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1698 | IsValid = true; | 
|  | 1699 | break; | 
|  | 1700 | } | 
|  | 1701 | } | 
|  | 1702 |  | 
|  | 1703 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { | 
|  | 1704 | if (isValid()) | 
|  | 1705 | OS << "Found CUDA installation: " << CudaInstallPath << "\n"; | 
|  | 1706 | } | 
|  | 1707 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1708 | namespace { | 
|  | 1709 | // 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] | 1710 | class FilterNonExistent { | 
|  | 1711 | StringRef Base; | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1712 | vfs::FileSystem &VFS; | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1713 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1714 | public: | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1715 | FilterNonExistent(StringRef Base, vfs::FileSystem &VFS) | 
|  | 1716 | : Base(Base), VFS(VFS) {} | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1717 | bool operator()(const Multilib &M) { | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1718 | return !VFS.exists(Base + M.gccSuffix() + "/crtbegin.o"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1719 | } | 
|  | 1720 | }; | 
|  | 1721 | } // end anonymous namespace | 
|  | 1722 |  | 
|  | 1723 | static void addMultilibFlag(bool Enabled, const char *const Flag, | 
|  | 1724 | std::vector<std::string> &Flags) { | 
|  | 1725 | if (Enabled) | 
|  | 1726 | Flags.push_back(std::string("+") + Flag); | 
|  | 1727 | else | 
|  | 1728 | Flags.push_back(std::string("-") + Flag); | 
|  | 1729 | } | 
|  | 1730 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1731 | static bool isMipsArch(llvm::Triple::ArchType Arch) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1732 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || | 
|  | 1733 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; | 
|  | 1734 | } | 
|  | 1735 |  | 
|  | 1736 | static bool isMips32(llvm::Triple::ArchType Arch) { | 
|  | 1737 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; | 
|  | 1738 | } | 
|  | 1739 |  | 
|  | 1740 | static bool isMips64(llvm::Triple::ArchType Arch) { | 
|  | 1741 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; | 
|  | 1742 | } | 
|  | 1743 |  | 
|  | 1744 | static bool isMipsEL(llvm::Triple::ArchType Arch) { | 
|  | 1745 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; | 
|  | 1746 | } | 
|  | 1747 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1748 | static bool isMips16(const ArgList &Args) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1749 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1750 | return A && A->getOption().matches(options::OPT_mips16); | 
|  | 1751 | } | 
|  | 1752 |  | 
|  | 1753 | static bool isMicroMips(const ArgList &Args) { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1754 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1755 | return A && A->getOption().matches(options::OPT_mmicromips); | 
|  | 1756 | } | 
|  | 1757 |  | 
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1758 | namespace { | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1759 | struct DetectedMultilibs { | 
|  | 1760 | /// The set of multilibs that the detected installation supports. | 
|  | 1761 | MultilibSet Multilibs; | 
|  | 1762 |  | 
|  | 1763 | /// The primary multilib appropriate for the given flags. | 
|  | 1764 | Multilib SelectedMultilib; | 
|  | 1765 |  | 
|  | 1766 | /// On Biarch systems, this corresponds to the default multilib when | 
|  | 1767 | /// targeting the non-default multilib. Otherwise, it is empty. | 
|  | 1768 | llvm::Optional<Multilib> BiarchSibling; | 
|  | 1769 | }; | 
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1770 | } // end anonymous namespace | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1771 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1772 | static Multilib makeMultilib(StringRef commonSuffix) { | 
|  | 1773 | return Multilib(commonSuffix, commonSuffix, commonSuffix); | 
|  | 1774 | } | 
|  | 1775 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1776 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, | 
|  | 1777 | StringRef Path, const ArgList &Args, | 
|  | 1778 | DetectedMultilibs &Result) { | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 1779 | // Some MIPS toolchains put libraries and object files compiled | 
|  | 1780 | // using different options in to the sub-directoris which names | 
|  | 1781 | // reflects the flags used for compilation. For example sysroot | 
|  | 1782 | // directory might looks like the following examples: | 
|  | 1783 | // | 
|  | 1784 | // /usr | 
|  | 1785 | //   /lib      <= crt*.o files compiled with '-mips32' | 
|  | 1786 | // /mips16 | 
|  | 1787 | //   /usr | 
|  | 1788 | //     /lib    <= crt*.o files compiled with '-mips16' | 
|  | 1789 | //   /el | 
|  | 1790 | //     /usr | 
|  | 1791 | //       /lib  <= crt*.o files compiled with '-mips16 -EL' | 
|  | 1792 | // | 
|  | 1793 | // or | 
|  | 1794 | // | 
|  | 1795 | // /usr | 
|  | 1796 | //   /lib      <= crt*.o files compiled with '-mips32r2' | 
|  | 1797 | // /mips16 | 
|  | 1798 | //   /usr | 
|  | 1799 | //     /lib    <= crt*.o files compiled with '-mips32r2 -mips16' | 
|  | 1800 | // /mips32 | 
|  | 1801 | //     /usr | 
|  | 1802 | //       /lib  <= crt*.o files compiled with '-mips32' | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 1803 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1804 | FilterNonExistent NonExistent(Path, D.getVFS()); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 1805 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1806 | // Check for FSF toolchain multilibs | 
|  | 1807 | MultilibSet FSFMipsMultilibs; | 
|  | 1808 | { | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1809 | auto MArchMips32 = makeMultilib("/mips32") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1810 | .flag("+m32") | 
|  | 1811 | .flag("-m64") | 
|  | 1812 | .flag("-mmicromips") | 
|  | 1813 | .flag("+march=mips32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1814 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1815 | auto MArchMicroMips = makeMultilib("/micromips") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1816 | .flag("+m32") | 
|  | 1817 | .flag("-m64") | 
|  | 1818 | .flag("+mmicromips"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1819 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1820 | auto MArchMips64r2 = makeMultilib("/mips64r2") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1821 | .flag("-m32") | 
|  | 1822 | .flag("+m64") | 
|  | 1823 | .flag("+march=mips64r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1824 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1825 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( | 
|  | 1826 | "-march=mips64r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1827 |  | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1828 | auto MArchDefault = makeMultilib("") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1829 | .flag("+m32") | 
|  | 1830 | .flag("-m64") | 
|  | 1831 | .flag("-mmicromips") | 
|  | 1832 | .flag("+march=mips32r2"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1833 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1834 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1835 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1836 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); | 
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1837 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1838 | auto MAbi64 = | 
|  | 1839 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1840 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1841 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1842 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1843 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1844 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1845 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1846 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1847 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1848 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1849 | FSFMipsMultilibs = | 
|  | 1850 | MultilibSet() | 
|  | 1851 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, | 
|  | 1852 | MArchDefault) | 
|  | 1853 | .Maybe(UCLibc) | 
|  | 1854 | .Maybe(Mips16) | 
|  | 1855 | .FilterOut("/mips64/mips16") | 
|  | 1856 | .FilterOut("/mips64r2/mips16") | 
|  | 1857 | .FilterOut("/micromips/mips16") | 
|  | 1858 | .Maybe(MAbi64) | 
|  | 1859 | .FilterOut("/micromips/64") | 
|  | 1860 | .FilterOut("/mips32/64") | 
|  | 1861 | .FilterOut("^/64") | 
|  | 1862 | .FilterOut("/mips16/64") | 
|  | 1863 | .Either(BigEndian, LittleEndian) | 
|  | 1864 | .Maybe(SoftFloat) | 
|  | 1865 | .Maybe(Nan2008) | 
|  | 1866 | .FilterOut(".*sof/nan2008") | 
|  | 1867 | .FilterOut(NonExistent) | 
|  | 1868 | .setIncludeDirsCallback([](StringRef InstallDir, | 
|  | 1869 | StringRef TripleStr, const Multilib &M) { | 
|  | 1870 | std::vector<std::string> Dirs; | 
|  | 1871 | Dirs.push_back((InstallDir + "/include").str()); | 
|  | 1872 | std::string SysRootInc = | 
|  | 1873 | InstallDir.str() + "/../../../../sysroot"; | 
|  | 1874 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) | 
|  | 1875 | Dirs.push_back(SysRootInc + "/uclibc/usr/include"); | 
|  | 1876 | else | 
|  | 1877 | Dirs.push_back(SysRootInc + "/usr/include"); | 
|  | 1878 | return Dirs; | 
|  | 1879 | }); | 
| Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1880 | } | 
|  | 1881 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1882 | // Check for Musl toolchain multilibs | 
|  | 1883 | MultilibSet MuslMipsMultilibs; | 
|  | 1884 | { | 
|  | 1885 | auto MArchMipsR2 = makeMultilib("") | 
|  | 1886 | .osSuffix("/mips-r2-hard-musl") | 
|  | 1887 | .flag("+EB") | 
|  | 1888 | .flag("-EL") | 
|  | 1889 | .flag("+march=mips32r2"); | 
|  | 1890 |  | 
|  | 1891 | auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl") | 
|  | 1892 | .flag("-EB") | 
|  | 1893 | .flag("+EL") | 
|  | 1894 | .flag("+march=mips32r2"); | 
|  | 1895 |  | 
|  | 1896 | MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2); | 
|  | 1897 |  | 
|  | 1898 | // Specify the callback that computes the include directories. | 
|  | 1899 | MuslMipsMultilibs.setIncludeDirsCallback([]( | 
|  | 1900 | StringRef InstallDir, StringRef TripleStr, const Multilib &M) { | 
|  | 1901 | std::vector<std::string> Dirs; | 
|  | 1902 | Dirs.push_back( | 
|  | 1903 | (InstallDir + "/../sysroot" + M.osSuffix() + "/usr/include").str()); | 
|  | 1904 | return Dirs; | 
|  | 1905 | }); | 
|  | 1906 | } | 
|  | 1907 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1908 | // Check for Code Sourcery toolchain multilibs | 
|  | 1909 | MultilibSet CSMipsMultilibs; | 
|  | 1910 | { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1911 | auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); | 
| Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1912 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1913 | auto MArchMicroMips = | 
|  | 1914 | makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1915 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1916 | auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1917 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1918 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); | 
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1919 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1920 | auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1921 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1922 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1923 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1924 | auto DefaultFloat = | 
|  | 1925 | makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1926 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1927 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1928 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1929 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1930 |  | 
|  | 1931 | // Note that this one's osSuffix is "" | 
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1932 | auto MAbi64 = makeMultilib("") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1933 | .gccSuffix("/64") | 
|  | 1934 | .includeSuffix("/64") | 
|  | 1935 | .flag("+mabi=n64") | 
|  | 1936 | .flag("-mabi=n32") | 
|  | 1937 | .flag("-m32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1938 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1939 | CSMipsMultilibs = | 
|  | 1940 | MultilibSet() | 
|  | 1941 | .Either(MArchMips16, MArchMicroMips, MArchDefault) | 
|  | 1942 | .Maybe(UCLibc) | 
|  | 1943 | .Either(SoftFloat, Nan2008, DefaultFloat) | 
|  | 1944 | .FilterOut("/micromips/nan2008") | 
|  | 1945 | .FilterOut("/mips16/nan2008") | 
|  | 1946 | .Either(BigEndian, LittleEndian) | 
|  | 1947 | .Maybe(MAbi64) | 
|  | 1948 | .FilterOut("/mips16.*/64") | 
|  | 1949 | .FilterOut("/micromips.*/64") | 
|  | 1950 | .FilterOut(NonExistent) | 
|  | 1951 | .setIncludeDirsCallback([](StringRef InstallDir, | 
|  | 1952 | StringRef TripleStr, const Multilib &M) { | 
|  | 1953 | std::vector<std::string> Dirs; | 
|  | 1954 | Dirs.push_back((InstallDir + "/include").str()); | 
|  | 1955 | std::string SysRootInc = | 
|  | 1956 | InstallDir.str() + "/../../../../" + TripleStr.str(); | 
|  | 1957 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) | 
|  | 1958 | Dirs.push_back(SysRootInc + "/libc/uclibc/usr/include"); | 
|  | 1959 | else | 
|  | 1960 | Dirs.push_back(SysRootInc + "/libc/usr/include"); | 
|  | 1961 | return Dirs; | 
|  | 1962 | }); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1963 | } | 
|  | 1964 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1965 | MultilibSet AndroidMipsMultilibs = | 
|  | 1966 | MultilibSet() | 
|  | 1967 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) | 
|  | 1968 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) | 
|  | 1969 | .FilterOut(NonExistent); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1970 |  | 
|  | 1971 | MultilibSet DebianMipsMultilibs; | 
|  | 1972 | { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1973 | Multilib MAbiN32 = | 
|  | 1974 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1975 |  | 
|  | 1976 | Multilib M64 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1977 | .gccSuffix("/64") | 
|  | 1978 | .includeSuffix("/64") | 
|  | 1979 | .flag("+m64") | 
|  | 1980 | .flag("-m32") | 
|  | 1981 | .flag("-mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1982 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1983 | Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1984 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1985 | DebianMipsMultilibs = | 
|  | 1986 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1987 | } | 
|  | 1988 |  | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1989 | MultilibSet ImgMultilibs; | 
|  | 1990 | { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1991 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1992 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1993 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1994 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1995 | auto MAbi64 = | 
|  | 1996 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1997 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1998 | ImgMultilibs = | 
|  | 1999 | MultilibSet() | 
|  | 2000 | .Maybe(Mips64r6) | 
|  | 2001 | .Maybe(MAbi64) | 
|  | 2002 | .Maybe(LittleEndian) | 
|  | 2003 | .FilterOut(NonExistent) | 
|  | 2004 | .setIncludeDirsCallback([](StringRef InstallDir, | 
|  | 2005 | StringRef TripleStr, const Multilib &M) { | 
|  | 2006 | std::vector<std::string> Dirs; | 
|  | 2007 | Dirs.push_back((InstallDir + "/include").str()); | 
|  | 2008 | Dirs.push_back( | 
|  | 2009 | (InstallDir + "/../../../../sysroot/usr/include").str()); | 
|  | 2010 | return Dirs; | 
|  | 2011 | }); | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2012 | } | 
|  | 2013 |  | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2014 | StringRef CPUName; | 
|  | 2015 | StringRef ABIName; | 
|  | 2016 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); | 
|  | 2017 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2018 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); | 
|  | 2019 |  | 
|  | 2020 | Multilib::flags_list Flags; | 
|  | 2021 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); | 
|  | 2022 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); | 
|  | 2023 | addMultilibFlag(isMips16(Args), "mips16", Flags); | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2024 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2025 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || | 
| Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 2026 | CPUName == "mips32r5" || CPUName == "p5600", | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2027 | "march=mips32r2", Flags); | 
| Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 2028 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2029 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); | 
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2030 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || | 
|  | 2031 | CPUName == "mips64r5" || CPUName == "octeon", | 
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2032 | "march=mips64r2", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2033 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); | 
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2034 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); | 
| Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 2035 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", | 
|  | 2036 | Flags); | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2037 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); | 
|  | 2038 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2039 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2040 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2041 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); | 
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2042 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2043 |  | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2044 | if (TargetTriple.isAndroid()) { | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2045 | // Select Android toolchain. It's the only choice in that case. | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2046 | if (AndroidMipsMultilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2047 | Result.Multilibs = AndroidMipsMultilibs; | 
|  | 2048 | return true; | 
|  | 2049 | } | 
|  | 2050 | return false; | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2051 | } | 
|  | 2052 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2053 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && | 
|  | 2054 | TargetTriple.getOS() == llvm::Triple::Linux && | 
|  | 2055 | TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) { | 
|  | 2056 | if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2057 | Result.Multilibs = MuslMipsMultilibs; | 
|  | 2058 | return true; | 
|  | 2059 | } | 
|  | 2060 | return false; | 
|  | 2061 | } | 
|  | 2062 |  | 
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2063 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && | 
|  | 2064 | TargetTriple.getOS() == llvm::Triple::Linux && | 
|  | 2065 | TargetTriple.getEnvironment() == llvm::Triple::GNU) { | 
|  | 2066 | // Select mips-img-linux-gnu toolchain. | 
|  | 2067 | if (ImgMultilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2068 | Result.Multilibs = ImgMultilibs; | 
|  | 2069 | return true; | 
|  | 2070 | } | 
|  | 2071 | return false; | 
|  | 2072 | } | 
|  | 2073 |  | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2074 | // Sort candidates. Toolchain that best meets the directories goes first. | 
|  | 2075 | // Then select the first toolchains matches command line flags. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2076 | MultilibSet *candidates[] = {&DebianMipsMultilibs, &FSFMipsMultilibs, | 
|  | 2077 | &CSMipsMultilibs}; | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2078 | std::sort( | 
|  | 2079 | std::begin(candidates), std::end(candidates), | 
|  | 2080 | [](MultilibSet *a, MultilibSet *b) { return a->size() > b->size(); }); | 
|  | 2081 | for (const auto &candidate : candidates) { | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2082 | if (candidate->select(Flags, Result.SelectedMultilib)) { | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2083 | if (candidate == &DebianMipsMultilibs) | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2084 | Result.BiarchSibling = Multilib(); | 
|  | 2085 | Result.Multilibs = *candidate; | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2086 | return true; | 
|  | 2087 | } | 
|  | 2088 | } | 
|  | 2089 |  | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2090 | { | 
|  | 2091 | // Fallback to the regular toolchain-tree structure. | 
|  | 2092 | Multilib Default; | 
|  | 2093 | Result.Multilibs.push_back(Default); | 
|  | 2094 | Result.Multilibs.FilterOut(NonExistent); | 
|  | 2095 |  | 
|  | 2096 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { | 
|  | 2097 | Result.BiarchSibling = Multilib(); | 
|  | 2098 | return true; | 
|  | 2099 | } | 
|  | 2100 | } | 
|  | 2101 |  | 
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2102 | return false; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2103 | } | 
|  | 2104 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2105 | static bool findBiarchMultilibs(const Driver &D, | 
|  | 2106 | const llvm::Triple &TargetTriple, | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2107 | StringRef Path, const ArgList &Args, | 
|  | 2108 | bool NeedsBiarchSuffix, | 
|  | 2109 | DetectedMultilibs &Result) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2110 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs | 
|  | 2111 | // in what would normally be GCCInstallPath and put the 64-bit | 
|  | 2112 | // libs in a subdirectory named 64. The simple logic we follow is that | 
|  | 2113 | // *if* there is a subdirectory of the right name with crtbegin.o in it, | 
|  | 2114 | // we use that. If not, and if not a biarch triple alias, we look for | 
|  | 2115 | // crtbegin.o without the subdirectory. | 
|  | 2116 |  | 
|  | 2117 | Multilib Default; | 
|  | 2118 | Multilib Alt64 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2119 | .gccSuffix("/64") | 
|  | 2120 | .includeSuffix("/64") | 
|  | 2121 | .flag("-m32") | 
|  | 2122 | .flag("+m64") | 
|  | 2123 | .flag("-mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2124 | Multilib Alt32 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2125 | .gccSuffix("/32") | 
|  | 2126 | .includeSuffix("/32") | 
|  | 2127 | .flag("+m32") | 
|  | 2128 | .flag("-m64") | 
|  | 2129 | .flag("-mx32"); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2130 | Multilib Altx32 = Multilib() | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2131 | .gccSuffix("/x32") | 
|  | 2132 | .includeSuffix("/x32") | 
|  | 2133 | .flag("-m32") | 
|  | 2134 | .flag("-m64") | 
|  | 2135 | .flag("+mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2136 |  | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2137 | FilterNonExistent NonExistent(Path, D.getVFS()); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2138 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2139 | // Determine default multilib from: 32, 64, x32 | 
|  | 2140 | // Also handle cases such as 64 on 32, 32 on 64, etc. | 
|  | 2141 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; | 
| David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2142 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; | 
| Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2143 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2144 | Want = WANT64; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2145 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2146 | Want = WANT64; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2147 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2148 | Want = WANT32; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2149 | else { | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2150 | if (TargetTriple.isArch32Bit()) | 
|  | 2151 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2152 | else if (IsX32) | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2153 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2154 | else | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2155 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; | 
| Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2156 | } | 
|  | 2157 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2158 | if (Want == WANT32) | 
|  | 2159 | Default.flag("+m32").flag("-m64").flag("-mx32"); | 
|  | 2160 | else if (Want == WANT64) | 
|  | 2161 | Default.flag("-m32").flag("+m64").flag("-mx32"); | 
|  | 2162 | else if (Want == WANTX32) | 
|  | 2163 | Default.flag("-m32").flag("-m64").flag("+mx32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2164 | else | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2165 | return false; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2166 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2167 | Result.Multilibs.push_back(Default); | 
|  | 2168 | Result.Multilibs.push_back(Alt64); | 
|  | 2169 | Result.Multilibs.push_back(Alt32); | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2170 | Result.Multilibs.push_back(Altx32); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2171 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2172 | Result.Multilibs.FilterOut(NonExistent); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2173 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2174 | Multilib::flags_list Flags; | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2175 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2176 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); | 
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2177 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2178 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2179 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2180 | return false; | 
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2181 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2182 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2183 | Result.SelectedMultilib == Altx32) | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2184 | Result.BiarchSibling = Default; | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2185 |  | 
|  | 2186 | return true; | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2187 | } | 
|  | 2188 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2189 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( | 
|  | 2190 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, | 
|  | 2191 | const std::string &LibDir, StringRef CandidateTriple, | 
|  | 2192 | bool NeedsBiarchSuffix) { | 
|  | 2193 | // Solaris is a special case. The GCC installation is under | 
|  | 2194 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we | 
|  | 2195 | // need to iterate twice. | 
|  | 2196 | std::error_code EC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2197 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; | 
|  | 2198 | !EC && LI != LE; LI = LI.increment(EC)) { | 
|  | 2199 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2200 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); | 
|  | 2201 |  | 
|  | 2202 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2203 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2204 | continue; // Saw this path before; no need to look at it again. | 
|  | 2205 | if (CandidateVersion.isOlderThan(4, 1, 1)) | 
|  | 2206 | continue; | 
|  | 2207 | if (CandidateVersion <= Version) | 
|  | 2208 | continue; | 
|  | 2209 |  | 
|  | 2210 | GCCInstallPath = | 
|  | 2211 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2212 | if (!D.getVFS().exists(GCCInstallPath)) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2213 | continue; | 
|  | 2214 |  | 
|  | 2215 | // If we make it here there has to be at least one GCC version, let's just | 
|  | 2216 | // use the latest one. | 
|  | 2217 | std::error_code EEC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2218 | for (vfs::directory_iterator | 
|  | 2219 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), | 
|  | 2220 | LLE; | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2221 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { | 
|  | 2222 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2223 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2224 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); | 
|  | 2225 |  | 
|  | 2226 | if (CandidateSubVersion > Version) | 
|  | 2227 | Version = CandidateSubVersion; | 
|  | 2228 | } | 
|  | 2229 |  | 
|  | 2230 | GCCTriple.setTriple(CandidateTriple); | 
|  | 2231 |  | 
|  | 2232 | GCCInstallPath += "/" + Version.Text; | 
|  | 2233 | GCCParentLibPath = GCCInstallPath + "/../../../../"; | 
|  | 2234 |  | 
|  | 2235 | IsValid = true; | 
|  | 2236 | } | 
|  | 2237 | } | 
|  | 2238 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2239 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2240 | const llvm::Triple &TargetTriple, const ArgList &Args, | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2241 | const std::string &LibDir, StringRef CandidateTriple, | 
|  | 2242 | bool NeedsBiarchSuffix) { | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2243 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2244 | // There are various different suffixes involving the triple we | 
|  | 2245 | // 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] | 2246 | // up to the lib directory. Specifically, the number of "up" steps | 
|  | 2247 | // in the second half of each row is 1 + the number of path separators | 
|  | 2248 | // in the first half. | 
|  | 2249 | const std::string LibAndInstallSuffixes[][2] = { | 
|  | 2250 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, | 
|  | 2251 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2252 | // Debian puts cross-compilers in gcc-cross | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2253 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, | 
|  | 2254 |  | 
|  | 2255 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), | 
|  | 2256 | "/../../../.."}, | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2257 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2258 | // The Freescale PPC SDK has the gcc libraries in | 
|  | 2259 | // <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] | 2260 | {"/" + CandidateTriple.str(), "/../.."}, | 
| Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2261 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2262 | // Ubuntu has a strange mis-matched pair of triples that this happens to | 
|  | 2263 | // match. | 
|  | 2264 | // FIXME: It may be worthwhile to generalize this and look for a second | 
|  | 2265 | // triple. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2266 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; | 
|  | 2267 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2268 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { | 
|  | 2269 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, | 
|  | 2270 | NeedsBiarchSuffix); | 
|  | 2271 | return; | 
|  | 2272 | } | 
|  | 2273 |  | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2274 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2275 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - | 
|  | 2276 | (TargetArch != llvm::Triple::x86)); | 
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2277 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2278 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; | 
| Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2279 | std::error_code EC; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2280 | for (vfs::directory_iterator | 
|  | 2281 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), | 
|  | 2282 | LE; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2283 | !EC && LI != LE; LI = LI.increment(EC)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2284 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2285 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); | 
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2286 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2287 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) | 
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2288 | continue; // Saw this path before; no need to look at it again. | 
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2289 | if (CandidateVersion.isOlderThan(4, 1, 1)) | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2290 | continue; | 
|  | 2291 | if (CandidateVersion <= Version) | 
|  | 2292 | continue; | 
| Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2293 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2294 | DetectedMultilibs Detected; | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2295 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2296 | // Debian mips multilibs behave more like the rest of the biarch ones, | 
|  | 2297 | // so handle them there | 
|  | 2298 | if (isMipsArch(TargetArch)) { | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2299 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2300 | continue; | 
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2301 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2302 | NeedsBiarchSuffix, Detected)) { | 
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2303 | continue; | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2304 | } | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2305 |  | 
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2306 | Multilibs = Detected.Multilibs; | 
|  | 2307 | SelectedMultilib = Detected.SelectedMultilib; | 
|  | 2308 | BiarchSibling = Detected.BiarchSibling; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2309 | Version = CandidateVersion; | 
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2310 | GCCTriple.setTriple(CandidateTriple); | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2311 | // FIXME: We hack together the directory name here instead of | 
|  | 2312 | // using LI to ensure stable path separators across Windows and | 
|  | 2313 | // Linux. | 
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2314 | GCCInstallPath = | 
|  | 2315 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); | 
|  | 2316 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; | 
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2317 | IsValid = true; | 
|  | 2318 | } | 
|  | 2319 | } | 
|  | 2320 | } | 
|  | 2321 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2322 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2323 | const ArgList &Args) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2324 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2325 | getProgramPaths().push_back(getDriver().getInstalledDir()); | 
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2326 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2327 | getProgramPaths().push_back(getDriver().Dir); | 
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2328 | } | 
|  | 2329 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2330 | Generic_GCC::~Generic_GCC() {} | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2331 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2332 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { | 
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2333 | switch (AC) { | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2334 | case Action::PreprocessJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2335 | if (!Preprocess) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2336 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2337 | return Preprocess.get(); | 
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2338 | case Action::CompileJobClass: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2339 | if (!Compile) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2340 | Compile.reset(new tools::gcc::Compiler(*this)); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2341 | return Compile.get(); | 
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2342 | default: | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2343 | return ToolChain::getTool(AC); | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2344 | } | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2345 | } | 
|  | 2346 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2347 | Tool *Generic_GCC::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2348 | return new tools::gnutools::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2349 | } | 
|  | 2350 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2351 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2352 |  | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2353 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { | 
|  | 2354 | // Print the information about how we detected the GCC installation. | 
|  | 2355 | GCCInstallation.print(OS); | 
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2356 | CudaInstallation.print(OS); | 
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2357 | } | 
|  | 2358 |  | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2359 | bool Generic_GCC::IsUnwindTablesDefault() const { | 
| Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2360 | return getArch() == llvm::Triple::x86_64; | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2361 | } | 
|  | 2362 |  | 
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2363 | bool Generic_GCC::isPICDefault() const { | 
|  | 2364 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); | 
|  | 2365 | } | 
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2366 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2367 | bool Generic_GCC::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2368 |  | 
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2369 | bool Generic_GCC::isPICDefaultForced() const { | 
|  | 2370 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); | 
|  | 2371 | } | 
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2372 |  | 
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2373 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2374 | switch (getTriple().getArch()) { | 
|  | 2375 | case llvm::Triple::x86: | 
|  | 2376 | case llvm::Triple::x86_64: | 
|  | 2377 | case llvm::Triple::aarch64: | 
|  | 2378 | case llvm::Triple::aarch64_be: | 
|  | 2379 | case llvm::Triple::arm: | 
|  | 2380 | case llvm::Triple::armeb: | 
| Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2381 | case llvm::Triple::bpfel: | 
|  | 2382 | case llvm::Triple::bpfeb: | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2383 | case llvm::Triple::thumb: | 
|  | 2384 | case llvm::Triple::thumbeb: | 
|  | 2385 | case llvm::Triple::ppc: | 
|  | 2386 | case llvm::Triple::ppc64: | 
|  | 2387 | case llvm::Triple::ppc64le: | 
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2388 | case llvm::Triple::systemz: | 
|  | 2389 | return true; | 
|  | 2390 | default: | 
|  | 2391 | return false; | 
|  | 2392 | } | 
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2393 | } | 
|  | 2394 |  | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2395 | /// \brief Helper to add the variant paths of a libstdc++ installation. | 
|  | 2396 | bool Generic_GCC::addLibStdCXXIncludePaths( | 
|  | 2397 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, | 
|  | 2398 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, | 
|  | 2399 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2400 | if (!getVFS().exists(Base + Suffix)) | 
|  | 2401 | return false; | 
|  | 2402 |  | 
|  | 2403 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); | 
|  | 2404 |  | 
|  | 2405 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If | 
|  | 2406 | // that path exists or we have neither a GCC nor target multiarch triple, use | 
|  | 2407 | // this vanilla search path. | 
|  | 2408 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || | 
|  | 2409 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { | 
|  | 2410 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2411 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); | 
|  | 2412 | } else { | 
|  | 2413 | // Otherwise try to use multiarch naming schemes which have normalized the | 
|  | 2414 | // triples and put the triple before the suffix. | 
|  | 2415 | // | 
|  | 2416 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and | 
|  | 2417 | // the target triple, so we support that here. | 
|  | 2418 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2419 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); | 
|  | 2420 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 2421 | Base + "/" + TargetMultiarchTriple + Suffix); | 
|  | 2422 | } | 
|  | 2423 |  | 
|  | 2424 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); | 
|  | 2425 | return true; | 
|  | 2426 | } | 
|  | 2427 |  | 
|  | 2428 |  | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2429 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 2430 | ArgStringList &CC1Args) const { | 
|  | 2431 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2432 | bool UseInitArrayDefault = | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2433 | getTriple().getArch() == llvm::Triple::aarch64 || | 
| Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2434 | getTriple().getArch() == llvm::Triple::aarch64_be || | 
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2435 | (getTriple().getOS() == llvm::Triple::Linux && | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2436 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2437 | getTriple().getOS() == llvm::Triple::NaCl || | 
|  | 2438 | (getTriple().getVendor() == llvm::Triple::MipsTechnologies && | 
|  | 2439 | !getTriple().hasEnvironment()); | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2440 |  | 
|  | 2441 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2442 | options::OPT_fno_use_init_array, UseInitArrayDefault)) | 
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2443 | CC1Args.push_back("-fuse-init-array"); | 
|  | 2444 | } | 
|  | 2445 |  | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2446 | /// Mips Toolchain | 
|  | 2447 | MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D, | 
|  | 2448 | const llvm::Triple &Triple, | 
|  | 2449 | const ArgList &Args) | 
|  | 2450 | : Linux(D, Triple, Args) { | 
|  | 2451 | // Select the correct multilib according to the given arguments. | 
|  | 2452 | DetectedMultilibs Result; | 
|  | 2453 | findMIPSMultilibs(D, Triple, "", Args, Result); | 
|  | 2454 | Multilibs = Result.Multilibs; | 
|  | 2455 | SelectedMultilib = Result.SelectedMultilib; | 
|  | 2456 |  | 
|  | 2457 | // Find out the library suffix based on the ABI. | 
|  | 2458 | LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple); | 
|  | 2459 | getFilePaths().clear(); | 
|  | 2460 | getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix); | 
|  | 2461 |  | 
|  | 2462 | // Use LLD by default. | 
| Peter Collingbourne | 39719a7 | 2015-11-20 20:49:39 +0000 | [diff] [blame] | 2463 | DefaultLinker = "lld"; | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2464 | } | 
|  | 2465 |  | 
|  | 2466 | void MipsLLVMToolChain::AddClangSystemIncludeArgs( | 
|  | 2467 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2468 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 2469 | return; | 
|  | 2470 |  | 
|  | 2471 | const Driver &D = getDriver(); | 
|  | 2472 |  | 
|  | 2473 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
|  | 2474 | SmallString<128> P(D.ResourceDir); | 
|  | 2475 | llvm::sys::path::append(P, "include"); | 
|  | 2476 | addSystemInclude(DriverArgs, CC1Args, P); | 
|  | 2477 | } | 
|  | 2478 |  | 
|  | 2479 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 2480 | return; | 
|  | 2481 |  | 
|  | 2482 | const auto &Callback = Multilibs.includeDirsCallback(); | 
|  | 2483 | if (Callback) { | 
|  | 2484 | const auto IncludePaths = | 
|  | 2485 | Callback(D.getInstalledDir(), getTripleString(), SelectedMultilib); | 
|  | 2486 | for (const auto &Path : IncludePaths) | 
|  | 2487 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); | 
|  | 2488 | } | 
|  | 2489 | } | 
|  | 2490 |  | 
|  | 2491 | Tool *MipsLLVMToolChain::buildLinker() const { | 
|  | 2492 | return new tools::gnutools::Linker(*this); | 
|  | 2493 | } | 
|  | 2494 |  | 
|  | 2495 | std::string MipsLLVMToolChain::computeSysRoot() const { | 
|  | 2496 | if (!getDriver().SysRoot.empty()) | 
|  | 2497 | return getDriver().SysRoot + SelectedMultilib.osSuffix(); | 
|  | 2498 |  | 
|  | 2499 | const std::string InstalledDir(getDriver().getInstalledDir()); | 
|  | 2500 | std::string SysRootPath = | 
|  | 2501 | InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix(); | 
|  | 2502 | if (llvm::sys::fs::exists(SysRootPath)) | 
|  | 2503 | return SysRootPath; | 
|  | 2504 |  | 
|  | 2505 | return std::string(); | 
|  | 2506 | } | 
|  | 2507 |  | 
|  | 2508 | ToolChain::CXXStdlibType | 
|  | 2509 | MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
|  | 2510 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); | 
|  | 2511 | if (A) { | 
|  | 2512 | StringRef Value = A->getValue(); | 
|  | 2513 | if (Value != "libc++") | 
|  | 2514 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) | 
|  | 2515 | << A->getAsString(Args); | 
|  | 2516 | } | 
|  | 2517 |  | 
|  | 2518 | return ToolChain::CST_Libcxx; | 
|  | 2519 | } | 
|  | 2520 |  | 
|  | 2521 | void MipsLLVMToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 2522 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
|  | 2523 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 2524 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2525 | return; | 
|  | 2526 |  | 
|  | 2527 | assert((GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) && | 
|  | 2528 | "Only -lc++ (aka libcxx) is suported in this toolchain."); | 
|  | 2529 |  | 
|  | 2530 | const auto &Callback = Multilibs.includeDirsCallback(); | 
|  | 2531 | if (Callback) { | 
|  | 2532 | const auto IncludePaths = Callback(getDriver().getInstalledDir(), | 
|  | 2533 | getTripleString(), SelectedMultilib); | 
|  | 2534 | for (const auto &Path : IncludePaths) { | 
|  | 2535 | if (llvm::sys::fs::exists(Path + "/c++/v1")) { | 
|  | 2536 | addSystemInclude(DriverArgs, CC1Args, Path + "/c++/v1"); | 
|  | 2537 | break; | 
|  | 2538 | } | 
|  | 2539 | } | 
|  | 2540 | } | 
|  | 2541 | } | 
|  | 2542 |  | 
|  | 2543 | void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 2544 | ArgStringList &CmdArgs) const { | 
|  | 2545 | assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) && | 
|  | 2546 | "Only -lc++ (aka libxx) is suported in this toolchain."); | 
|  | 2547 |  | 
|  | 2548 | CmdArgs.push_back("-lc++"); | 
|  | 2549 | CmdArgs.push_back("-lc++abi"); | 
|  | 2550 | CmdArgs.push_back("-lunwind"); | 
|  | 2551 | } | 
|  | 2552 |  | 
|  | 2553 | std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, | 
|  | 2554 | StringRef Component, | 
|  | 2555 | bool Shared) const { | 
|  | 2556 | SmallString<128> Path(getDriver().ResourceDir); | 
|  | 2557 | llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix, | 
|  | 2558 | getOS()); | 
|  | 2559 | llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" + | 
| Vasileios Kalintiris | bbc9930 | 2015-11-16 15:41:30 +0000 | [diff] [blame] | 2560 | "mips" + (Shared ? ".so" : ".a"))); | 
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2561 | return Path.str(); | 
|  | 2562 | } | 
|  | 2563 |  | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2564 | /// Hexagon Toolchain | 
|  | 2565 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2566 | std::string HexagonToolChain::getHexagonTargetDir( | 
|  | 2567 | const std::string &InstalledDir, | 
|  | 2568 | const SmallVectorImpl<std::string> &PrefixDirs) const { | 
|  | 2569 | std::string InstallRelDir; | 
|  | 2570 | const Driver &D = getDriver(); | 
|  | 2571 |  | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2572 | // Locate the rest of the toolchain ... | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2573 | for (auto &I : PrefixDirs) | 
|  | 2574 | if (D.getVFS().exists(I)) | 
|  | 2575 | return I; | 
| Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 2576 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2577 | if (getVFS().exists(InstallRelDir = InstalledDir + "/../target")) | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2578 | return InstallRelDir; | 
|  | 2579 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2580 | std::string PrefixRelDir = std::string(LLVM_PREFIX) + "/target"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2581 | if (getVFS().exists(PrefixRelDir)) | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2582 | return PrefixRelDir; | 
|  | 2583 |  | 
|  | 2584 | return InstallRelDir; | 
|  | 2585 | } | 
|  | 2586 |  | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2587 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2588 | Optional<unsigned> HexagonToolChain::getSmallDataThreshold( | 
|  | 2589 | const ArgList &Args) { | 
|  | 2590 | StringRef Gn = ""; | 
|  | 2591 | if (Arg *A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, | 
|  | 2592 | options::OPT_msmall_data_threshold_EQ)) { | 
|  | 2593 | Gn = A->getValue(); | 
|  | 2594 | } else if (Args.getLastArg(options::OPT_shared, options::OPT_fpic, | 
|  | 2595 | options::OPT_fPIC)) { | 
|  | 2596 | Gn = "0"; | 
|  | 2597 | } | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2598 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2599 | unsigned G; | 
|  | 2600 | if (!Gn.getAsInteger(10, G)) | 
|  | 2601 | return G; | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2602 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2603 | return None; | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2604 | } | 
|  | 2605 |  | 
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2606 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2607 | void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args, | 
|  | 2608 | ToolChain::path_list &LibPaths) const { | 
|  | 2609 | const Driver &D = getDriver(); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2610 |  | 
|  | 2611 | //---------------------------------------------------------------------------- | 
|  | 2612 | // -L Args | 
|  | 2613 | //---------------------------------------------------------------------------- | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 2614 | for (Arg *A : Args.filtered(options::OPT_L)) | 
|  | 2615 | for (const char *Value : A->getValues()) | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2616 | LibPaths.push_back(Value); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2617 |  | 
|  | 2618 | //---------------------------------------------------------------------------- | 
|  | 2619 | // Other standard paths | 
|  | 2620 | //---------------------------------------------------------------------------- | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2621 | std::vector<std::string> RootDirs; | 
| Krzysztof Parzyszek | f4467cd | 2016-01-06 14:13:11 +0000 | [diff] [blame] | 2622 | std::copy(D.PrefixDirs.begin(), D.PrefixDirs.end(), | 
|  | 2623 | std::back_inserter(RootDirs)); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2624 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2625 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2626 | D.PrefixDirs); | 
|  | 2627 | if (std::find(RootDirs.begin(), RootDirs.end(), TargetDir) == RootDirs.end()) | 
|  | 2628 | RootDirs.push_back(TargetDir); | 
|  | 2629 |  | 
|  | 2630 | bool HasPIC = Args.hasArg(options::OPT_fpic, options::OPT_fPIC); | 
|  | 2631 | // Assume G0 with -shared. | 
|  | 2632 | bool HasG0 = Args.hasArg(options::OPT_shared); | 
|  | 2633 | if (auto G = getSmallDataThreshold(Args)) | 
|  | 2634 | HasG0 = G.getValue() == 0; | 
|  | 2635 |  | 
|  | 2636 | const std::string CpuVer = GetTargetCPUVersion(Args).str(); | 
|  | 2637 | for (auto &Dir : RootDirs) { | 
|  | 2638 | std::string LibDir = Dir + "/hexagon/lib"; | 
|  | 2639 | std::string LibDirCpu = LibDir + '/' + CpuVer; | 
|  | 2640 | if (HasG0) { | 
|  | 2641 | if (HasPIC) | 
|  | 2642 | LibPaths.push_back(LibDirCpu + "/G0/pic"); | 
|  | 2643 | LibPaths.push_back(LibDirCpu + "/G0"); | 
|  | 2644 | } | 
|  | 2645 | LibPaths.push_back(LibDirCpu); | 
|  | 2646 | LibPaths.push_back(LibDir); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2647 | } | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2648 | } | 
|  | 2649 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2650 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2651 | const llvm::opt::ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2652 | : Linux(D, Triple, Args) { | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2653 | const std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2654 | D.PrefixDirs); | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2655 |  | 
|  | 2656 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to | 
|  | 2657 | // program paths | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2658 | const std::string BinDir(TargetDir + "/bin"); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2659 | if (D.getVFS().exists(BinDir)) | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2660 | getProgramPaths().push_back(BinDir); | 
|  | 2661 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2662 | ToolChain::path_list &LibPaths = getFilePaths(); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2663 |  | 
|  | 2664 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets | 
|  | 2665 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually | 
|  | 2666 | // support 'linux' we'll need to fix this up | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2667 | LibPaths.clear(); | 
|  | 2668 | getHexagonLibraryPaths(Args, LibPaths); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2669 | } | 
|  | 2670 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2671 | HexagonToolChain::~HexagonToolChain() {} | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2672 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2673 | Tool *HexagonToolChain::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2674 | return new tools::hexagon::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2675 | } | 
|  | 2676 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2677 | Tool *HexagonToolChain::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2678 | return new tools::hexagon::Linker(*this); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2679 | } | 
|  | 2680 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2681 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 2682 | ArgStringList &CC1Args) const { | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2683 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
|  | 2684 | DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 2685 | return; | 
|  | 2686 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2687 | const Driver &D = getDriver(); | 
|  | 2688 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), | 
|  | 2689 | D.PrefixDirs); | 
|  | 2690 | addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include"); | 
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2691 | } | 
|  | 2692 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2693 | void HexagonToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 2694 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2695 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 2696 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2697 | return; | 
|  | 2698 |  | 
|  | 2699 | const Driver &D = getDriver(); | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2700 | std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs); | 
|  | 2701 | addSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include/c++"); | 
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2702 | } | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2703 |  | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2704 | ToolChain::CXXStdlibType | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2705 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2706 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); | 
|  | 2707 | if (!A) | 
|  | 2708 | return ToolChain::CST_Libstdcxx; | 
|  | 2709 |  | 
|  | 2710 | StringRef Value = A->getValue(); | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2711 | if (Value != "libstdc++") | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2712 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2713 |  | 
|  | 2714 | return ToolChain::CST_Libstdcxx; | 
|  | 2715 | } | 
|  | 2716 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2717 | // | 
|  | 2718 | // Returns the default CPU for Hexagon. This is the default compilation target | 
|  | 2719 | // if no Hexagon processor is selected at the command-line. | 
|  | 2720 | // | 
|  | 2721 | const StringRef HexagonToolChain::GetDefaultCPU() { | 
|  | 2722 | return "hexagonv60"; | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2723 | } | 
|  | 2724 |  | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2725 | const StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) { | 
|  | 2726 | Arg *CpuArg = nullptr; | 
| Krzysztof Parzyszek | 972f72c | 2016-01-06 21:12:03 +0000 | [diff] [blame] | 2727 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ, options::OPT_march_EQ)) | 
|  | 2728 | CpuArg = A; | 
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2729 |  | 
|  | 2730 | StringRef CPU = CpuArg ? CpuArg->getValue() : GetDefaultCPU(); | 
|  | 2731 | if (CPU.startswith("hexagon")) | 
|  | 2732 | return CPU.substr(sizeof("hexagon") - 1); | 
|  | 2733 | return CPU; | 
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2734 | } | 
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2735 | // End Hexagon | 
| Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 2736 |  | 
| Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 2737 | /// AMDGPU Toolchain | 
|  | 2738 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 2739 | const ArgList &Args) | 
|  | 2740 | : Generic_ELF(D, Triple, Args) { } | 
|  | 2741 |  | 
|  | 2742 | Tool *AMDGPUToolChain::buildLinker() const { | 
|  | 2743 | return new tools::amdgpu::Linker(*this); | 
|  | 2744 | } | 
|  | 2745 | // End AMDGPU | 
|  | 2746 |  | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2747 | /// NaCl Toolchain | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2748 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 2749 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2750 | : Generic_ELF(D, Triple, Args) { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2751 |  | 
|  | 2752 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the | 
|  | 2753 | // default paths, and must instead only use the paths provided | 
|  | 2754 | // with this toolchain based on architecture. | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2755 | path_list &file_paths = getFilePaths(); | 
|  | 2756 | path_list &prog_paths = getProgramPaths(); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2757 |  | 
|  | 2758 | file_paths.clear(); | 
|  | 2759 | prog_paths.clear(); | 
|  | 2760 |  | 
|  | 2761 | // Path for library files (libc.a, ...) | 
|  | 2762 | std::string FilePath(getDriver().Dir + "/../"); | 
|  | 2763 |  | 
|  | 2764 | // Path for tools (clang, ld, etc..) | 
|  | 2765 | std::string ProgPath(getDriver().Dir + "/../"); | 
|  | 2766 |  | 
|  | 2767 | // Path for toolchain libraries (libgcc.a, ...) | 
|  | 2768 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); | 
|  | 2769 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2770 | switch (Triple.getArch()) { | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2771 | case llvm::Triple::x86: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2772 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); | 
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2773 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2774 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); | 
|  | 2775 | file_paths.push_back(ToolPath + "i686-nacl"); | 
|  | 2776 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2777 | case llvm::Triple::x86_64: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2778 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); | 
|  | 2779 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); | 
|  | 2780 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); | 
|  | 2781 | file_paths.push_back(ToolPath + "x86_64-nacl"); | 
|  | 2782 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2783 | case llvm::Triple::arm: | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2784 | file_paths.push_back(FilePath + "arm-nacl/lib"); | 
|  | 2785 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); | 
|  | 2786 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); | 
|  | 2787 | file_paths.push_back(ToolPath + "arm-nacl"); | 
|  | 2788 | break; | 
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2789 | case llvm::Triple::mipsel: | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2790 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); | 
|  | 2791 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); | 
|  | 2792 | prog_paths.push_back(ProgPath + "bin"); | 
|  | 2793 | file_paths.push_back(ToolPath + "mipsel-nacl"); | 
|  | 2794 | break; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2795 | default: | 
|  | 2796 | break; | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2797 | } | 
|  | 2798 |  | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2799 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); | 
|  | 2800 | } | 
|  | 2801 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2802 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 2803 | ArgStringList &CC1Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2804 | const Driver &D = getDriver(); | 
|  | 2805 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 2806 | return; | 
|  | 2807 |  | 
|  | 2808 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
|  | 2809 | SmallString<128> P(D.ResourceDir); | 
|  | 2810 | llvm::sys::path::append(P, "include"); | 
|  | 2811 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2812 | } | 
|  | 2813 |  | 
|  | 2814 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 2815 | return; | 
|  | 2816 |  | 
|  | 2817 | SmallString<128> P(D.Dir + "/../"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2818 | switch (getTriple().getArch()) { | 
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2819 | case llvm::Triple::x86: | 
|  | 2820 | // x86 is special because multilib style uses x86_64-nacl/include for libc | 
|  | 2821 | // headers but the SDK wants i686-nacl/usr/include. The other architectures | 
|  | 2822 | // have the same substring. | 
|  | 2823 | llvm::sys::path::append(P, "i686-nacl/usr/include"); | 
|  | 2824 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2825 | llvm::sys::path::remove_filename(P); | 
|  | 2826 | llvm::sys::path::remove_filename(P); | 
|  | 2827 | llvm::sys::path::remove_filename(P); | 
|  | 2828 | llvm::sys::path::append(P, "x86_64-nacl/include"); | 
|  | 2829 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2830 | return; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2831 | case llvm::Triple::arm: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2832 | llvm::sys::path::append(P, "arm-nacl/usr/include"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2833 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2834 | case llvm::Triple::x86_64: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2835 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2836 | break; | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2837 | case llvm::Triple::mipsel: | 
|  | 2838 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); | 
|  | 2839 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2840 | default: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2841 | return; | 
|  | 2842 | } | 
|  | 2843 |  | 
|  | 2844 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2845 | llvm::sys::path::remove_filename(P); | 
|  | 2846 | llvm::sys::path::remove_filename(P); | 
|  | 2847 | llvm::sys::path::append(P, "include"); | 
|  | 2848 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2849 | } | 
|  | 2850 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2851 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 2852 | ArgStringList &CmdArgs) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2853 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg | 
|  | 2854 | // if the value is libc++, and emits an error for other values. | 
|  | 2855 | GetCXXStdlibType(Args); | 
|  | 2856 | CmdArgs.push_back("-lc++"); | 
|  | 2857 | } | 
|  | 2858 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2859 | void NaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 2860 | ArgStringList &CC1Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2861 | const Driver &D = getDriver(); | 
|  | 2862 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 2863 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2864 | return; | 
|  | 2865 |  | 
|  | 2866 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg | 
|  | 2867 | // if the value is libc++, and emits an error for other values. | 
|  | 2868 | GetCXXStdlibType(DriverArgs); | 
|  | 2869 |  | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2870 | SmallString<128> P(D.Dir + "/../"); | 
|  | 2871 | switch (getTriple().getArch()) { | 
|  | 2872 | case llvm::Triple::arm: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2873 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); | 
|  | 2874 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2875 | break; | 
|  | 2876 | case llvm::Triple::x86: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2877 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); | 
|  | 2878 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2879 | break; | 
|  | 2880 | case llvm::Triple::x86_64: | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2881 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); | 
|  | 2882 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2883 | break; | 
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2884 | case llvm::Triple::mipsel: | 
|  | 2885 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); | 
|  | 2886 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2887 | break; | 
| Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 2888 | default: | 
|  | 2889 | break; | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2890 | } | 
|  | 2891 | } | 
|  | 2892 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2893 | ToolChain::CXXStdlibType | 
|  | 2894 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2895 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { | 
|  | 2896 | StringRef Value = A->getValue(); | 
|  | 2897 | if (Value == "libc++") | 
|  | 2898 | return ToolChain::CST_Libcxx; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2899 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2900 | } | 
|  | 2901 |  | 
|  | 2902 | return ToolChain::CST_Libcxx; | 
|  | 2903 | } | 
|  | 2904 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2905 | std::string | 
|  | 2906 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, | 
|  | 2907 | types::ID InputType) const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2908 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); | 
|  | 2909 | if (TheTriple.getArch() == llvm::Triple::arm && | 
|  | 2910 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) | 
|  | 2911 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); | 
|  | 2912 | return TheTriple.getTriple(); | 
|  | 2913 | } | 
|  | 2914 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2915 | Tool *NaClToolChain::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2916 | return new tools::nacltools::Linker(*this); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2917 | } | 
|  | 2918 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2919 | Tool *NaClToolChain::buildAssembler() const { | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2920 | if (getTriple().getArch() == llvm::Triple::arm) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2921 | return new tools::nacltools::AssemblerARM(*this); | 
|  | 2922 | return new tools::gnutools::Assembler(*this); | 
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2923 | } | 
|  | 2924 | // End NaCl | 
|  | 2925 |  | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2926 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform | 
|  | 2927 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. | 
|  | 2928 | /// Currently does not support anything else but compilation. | 
|  | 2929 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2930 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 2931 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2932 | : ToolChain(D, Triple, Args) { | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2933 | // Path mangling to find libexec | 
|  | 2934 | std::string Path(getDriver().Dir); | 
|  | 2935 |  | 
|  | 2936 | Path += "/../libexec"; | 
|  | 2937 | getProgramPaths().push_back(Path); | 
|  | 2938 | } | 
|  | 2939 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2940 | TCEToolChain::~TCEToolChain() {} | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2941 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2942 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2943 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2944 | bool TCEToolChain::isPICDefault() const { return false; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2945 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2946 | bool TCEToolChain::isPIEDefault() const { return false; } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2947 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2948 | bool TCEToolChain::isPICDefaultForced() const { return false; } | 
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2949 |  | 
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2950 | // CloudABI - CloudABI tool chain which can call ld(1) directly. | 
|  | 2951 |  | 
|  | 2952 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, | 
|  | 2953 | const ArgList &Args) | 
|  | 2954 | : Generic_ELF(D, Triple, Args) { | 
|  | 2955 | SmallString<128> P(getDriver().Dir); | 
|  | 2956 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); | 
|  | 2957 | getFilePaths().push_back(P.str()); | 
|  | 2958 | } | 
|  | 2959 |  | 
|  | 2960 | void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 2961 | ArgStringList &CC1Args) const { | 
|  | 2962 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) && | 
|  | 2963 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 2964 | return; | 
|  | 2965 |  | 
|  | 2966 | SmallString<128> P(getDriver().Dir); | 
|  | 2967 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); | 
|  | 2968 | addSystemInclude(DriverArgs, CC1Args, P.str()); | 
|  | 2969 | } | 
|  | 2970 |  | 
|  | 2971 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 2972 | ArgStringList &CmdArgs) const { | 
|  | 2973 | CmdArgs.push_back("-lc++"); | 
|  | 2974 | CmdArgs.push_back("-lc++abi"); | 
|  | 2975 | CmdArgs.push_back("-lunwind"); | 
|  | 2976 | } | 
|  | 2977 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2978 | Tool *CloudABI::buildLinker() const { | 
|  | 2979 | return new tools::cloudabi::Linker(*this); | 
|  | 2980 | } | 
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2981 |  | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2982 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 2983 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2984 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, | 
|  | 2985 | const ArgList &Args) | 
|  | 2986 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2987 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2988 | getFilePaths().push_back("/usr/lib"); | 
|  | 2989 | } | 
|  | 2990 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2991 | Tool *OpenBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2992 | return new tools::openbsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2993 | } | 
|  | 2994 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2995 | Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } | 
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2996 |  | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2997 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. | 
|  | 2998 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2999 | Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3000 | : Generic_ELF(D, Triple, Args) { | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3001 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
|  | 3002 | getFilePaths().push_back("/usr/lib"); | 
|  | 3003 | } | 
|  | 3004 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3005 | Tool *Bitrig::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3006 | return new tools::bitrig::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3007 | } | 
|  | 3008 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3009 | Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3010 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3011 | ToolChain::CXXStdlibType Bitrig::GetCXXStdlibType(const ArgList &Args) const { | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3012 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { | 
|  | 3013 | StringRef Value = A->getValue(); | 
|  | 3014 | if (Value == "libstdc++") | 
|  | 3015 | return ToolChain::CST_Libstdcxx; | 
|  | 3016 | if (Value == "libc++") | 
|  | 3017 | return ToolChain::CST_Libcxx; | 
|  | 3018 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3019 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3020 | } | 
|  | 3021 | return ToolChain::CST_Libcxx; | 
|  | 3022 | } | 
|  | 3023 |  | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3024 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3025 | ArgStringList &CC1Args) const { | 
|  | 3026 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3027 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3028 | return; | 
|  | 3029 |  | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3030 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3031 | case ToolChain::CST_Libcxx: | 
|  | 3032 | addSystemInclude(DriverArgs, CC1Args, | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3033 | getDriver().SysRoot + "/usr/include/c++/v1"); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3034 | break; | 
|  | 3035 | case ToolChain::CST_Libstdcxx: | 
|  | 3036 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3037 | getDriver().SysRoot + "/usr/include/c++/stdc++"); | 
|  | 3038 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3039 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3040 |  | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3041 | StringRef Triple = getTriple().str(); | 
|  | 3042 | if (Triple.startswith("amd64")) | 
|  | 3043 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3044 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3045 | Triple.substr(5)); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3046 | else | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3047 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + | 
|  | 3048 | "/usr/include/c++/stdc++/" + | 
|  | 3049 | Triple); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3050 | break; | 
|  | 3051 | } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3052 | } | 
|  | 3053 |  | 
|  | 3054 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 3055 | ArgStringList &CmdArgs) const { | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3056 | switch (GetCXXStdlibType(Args)) { | 
|  | 3057 | case ToolChain::CST_Libcxx: | 
|  | 3058 | CmdArgs.push_back("-lc++"); | 
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3059 | CmdArgs.push_back("-lc++abi"); | 
|  | 3060 | CmdArgs.push_back("-lpthread"); | 
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3061 | break; | 
|  | 3062 | case ToolChain::CST_Libstdcxx: | 
|  | 3063 | CmdArgs.push_back("-lstdc++"); | 
|  | 3064 | break; | 
|  | 3065 | } | 
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3066 | } | 
|  | 3067 |  | 
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3068 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 3069 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3070 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, | 
|  | 3071 | const ArgList &Args) | 
|  | 3072 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 3073 |  | 
| Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 3074 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall | 
|  | 3075 | // back to '/usr/lib' if it doesn't exist. | 
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3076 | if ((Triple.getArch() == llvm::Triple::x86 || | 
|  | 3077 | Triple.getArch() == llvm::Triple::ppc) && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3078 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) | 
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3079 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); | 
|  | 3080 | else | 
|  | 3081 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); | 
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3082 | } | 
|  | 3083 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3084 | ToolChain::CXXStdlibType FreeBSD::GetCXXStdlibType(const ArgList &Args) const { | 
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3085 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { | 
|  | 3086 | StringRef Value = A->getValue(); | 
|  | 3087 | if (Value == "libstdc++") | 
|  | 3088 | return ToolChain::CST_Libstdcxx; | 
|  | 3089 | if (Value == "libc++") | 
|  | 3090 | return ToolChain::CST_Libcxx; | 
|  | 3091 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3092 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3093 | } | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3094 | if (getTriple().getOSMajorVersion() >= 10) | 
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3095 | return ToolChain::CST_Libcxx; | 
|  | 3096 | return ToolChain::CST_Libstdcxx; | 
|  | 3097 | } | 
|  | 3098 |  | 
|  | 3099 | void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3100 | ArgStringList &CC1Args) const { | 
|  | 3101 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3102 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3103 | return; | 
|  | 3104 |  | 
|  | 3105 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3106 | case ToolChain::CST_Libcxx: | 
|  | 3107 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3108 | getDriver().SysRoot + "/usr/include/c++/v1"); | 
|  | 3109 | break; | 
|  | 3110 | case ToolChain::CST_Libstdcxx: | 
|  | 3111 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3112 | getDriver().SysRoot + "/usr/include/c++/4.2"); | 
|  | 3113 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3114 | getDriver().SysRoot + "/usr/include/c++/4.2/backward"); | 
|  | 3115 | break; | 
|  | 3116 | } | 
|  | 3117 | } | 
|  | 3118 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3119 | Tool *FreeBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3120 | return new tools::freebsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3121 | } | 
|  | 3122 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3123 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3124 |  | 
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 3125 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { | 
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3126 | // FreeBSD uses SjLj exceptions on ARM oabi. | 
|  | 3127 | switch (getTriple().getEnvironment()) { | 
| Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 3128 | case llvm::Triple::GNUEABIHF: | 
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3129 | case llvm::Triple::GNUEABI: | 
|  | 3130 | case llvm::Triple::EABI: | 
|  | 3131 | return false; | 
|  | 3132 |  | 
|  | 3133 | default: | 
|  | 3134 | return (getTriple().getArch() == llvm::Triple::arm || | 
|  | 3135 | getTriple().getArch() == llvm::Triple::thumb); | 
|  | 3136 | } | 
|  | 3137 | } | 
|  | 3138 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3139 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } | 
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3140 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3141 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } | 
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3142 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3143 | SanitizerMask FreeBSD::getSupportedSanitizers() const { | 
|  | 3144 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; | 
|  | 3145 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; | 
|  | 3146 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || | 
|  | 3147 | getTriple().getArch() == llvm::Triple::mips64el; | 
|  | 3148 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 3149 | Res |= SanitizerKind::Address; | 
|  | 3150 | Res |= SanitizerKind::Vptr; | 
|  | 3151 | if (IsX86_64 || IsMIPS64) { | 
|  | 3152 | Res |= SanitizerKind::Leak; | 
|  | 3153 | Res |= SanitizerKind::Thread; | 
|  | 3154 | } | 
|  | 3155 | if (IsX86 || IsX86_64) { | 
|  | 3156 | Res |= SanitizerKind::SafeStack; | 
|  | 3157 | } | 
|  | 3158 | return Res; | 
|  | 3159 | } | 
|  | 3160 |  | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3161 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. | 
|  | 3162 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3163 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3164 | : Generic_ELF(D, Triple, Args) { | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3165 |  | 
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3166 | if (getDriver().UseStdLib) { | 
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3167 | // When targeting a 32-bit platform, try the special directory used on | 
|  | 3168 | // 64-bit hosts, and only fall back to the main library directory if that | 
|  | 3169 | // doesn't work. | 
|  | 3170 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure | 
|  | 3171 | // what all logic is needed to emulate the '=' prefix here. | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3172 | switch (Triple.getArch()) { | 
|  | 3173 | case llvm::Triple::x86: | 
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3174 | getFilePaths().push_back("=/usr/lib/i386"); | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3175 | break; | 
|  | 3176 | case llvm::Triple::arm: | 
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3177 | case llvm::Triple::armeb: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3178 | case llvm::Triple::thumb: | 
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3179 | case llvm::Triple::thumbeb: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3180 | switch (Triple.getEnvironment()) { | 
|  | 3181 | case llvm::Triple::EABI: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3182 | case llvm::Triple::GNUEABI: | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3183 | getFilePaths().push_back("=/usr/lib/eabi"); | 
|  | 3184 | break; | 
| Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3185 | case llvm::Triple::EABIHF: | 
|  | 3186 | case llvm::Triple::GNUEABIHF: | 
|  | 3187 | getFilePaths().push_back("=/usr/lib/eabihf"); | 
|  | 3188 | break; | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3189 | default: | 
|  | 3190 | getFilePaths().push_back("=/usr/lib/oabi"); | 
|  | 3191 | break; | 
|  | 3192 | } | 
|  | 3193 | break; | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3194 | case llvm::Triple::mips64: | 
|  | 3195 | case llvm::Triple::mips64el: | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3196 | if (tools::mips::hasMipsAbiArg(Args, "o32")) | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3197 | getFilePaths().push_back("=/usr/lib/o32"); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3198 | else if (tools::mips::hasMipsAbiArg(Args, "64")) | 
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3199 | getFilePaths().push_back("=/usr/lib/64"); | 
|  | 3200 | break; | 
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3201 | case llvm::Triple::ppc: | 
|  | 3202 | getFilePaths().push_back("=/usr/lib/powerpc"); | 
|  | 3203 | break; | 
| Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3204 | case llvm::Triple::sparc: | 
|  | 3205 | getFilePaths().push_back("=/usr/lib/sparc"); | 
|  | 3206 | break; | 
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3207 | default: | 
|  | 3208 | break; | 
|  | 3209 | } | 
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3210 |  | 
|  | 3211 | getFilePaths().push_back("=/usr/lib"); | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3212 | } | 
|  | 3213 | } | 
|  | 3214 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3215 | Tool *NetBSD::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3216 | return new tools::netbsd::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3217 | } | 
|  | 3218 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3219 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } | 
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3220 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3221 | ToolChain::CXXStdlibType NetBSD::GetCXXStdlibType(const ArgList &Args) const { | 
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3222 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { | 
|  | 3223 | StringRef Value = A->getValue(); | 
|  | 3224 | if (Value == "libstdc++") | 
|  | 3225 | return ToolChain::CST_Libstdcxx; | 
|  | 3226 | if (Value == "libc++") | 
|  | 3227 | return ToolChain::CST_Libcxx; | 
|  | 3228 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3229 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); | 
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3230 | } | 
|  | 3231 |  | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3232 | unsigned Major, Minor, Micro; | 
|  | 3233 | getTriple().getOSVersion(Major, Minor, Micro); | 
| Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3234 | if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 49) || Major == 0) { | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3235 | switch (getArch()) { | 
| Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3236 | case llvm::Triple::aarch64: | 
| Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3237 | case llvm::Triple::arm: | 
|  | 3238 | case llvm::Triple::armeb: | 
|  | 3239 | case llvm::Triple::thumb: | 
|  | 3240 | case llvm::Triple::thumbeb: | 
| Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3241 | case llvm::Triple::ppc: | 
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3242 | case llvm::Triple::ppc64: | 
|  | 3243 | case llvm::Triple::ppc64le: | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3244 | case llvm::Triple::x86: | 
|  | 3245 | case llvm::Triple::x86_64: | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3246 | return ToolChain::CST_Libcxx; | 
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3247 | default: | 
|  | 3248 | break; | 
|  | 3249 | } | 
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3250 | } | 
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3251 | return ToolChain::CST_Libstdcxx; | 
|  | 3252 | } | 
|  | 3253 |  | 
|  | 3254 | void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3255 | ArgStringList &CC1Args) const { | 
|  | 3256 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3257 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3258 | return; | 
|  | 3259 |  | 
|  | 3260 | switch (GetCXXStdlibType(DriverArgs)) { | 
|  | 3261 | case ToolChain::CST_Libcxx: | 
|  | 3262 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3263 | getDriver().SysRoot + "/usr/include/c++/"); | 
|  | 3264 | break; | 
|  | 3265 | case ToolChain::CST_Libstdcxx: | 
|  | 3266 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3267 | getDriver().SysRoot + "/usr/include/g++"); | 
|  | 3268 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3269 | getDriver().SysRoot + "/usr/include/g++/backward"); | 
|  | 3270 | break; | 
|  | 3271 | } | 
|  | 3272 | } | 
|  | 3273 |  | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3274 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. | 
|  | 3275 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3276 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 3277 | : Generic_ELF(D, Triple, Args) { | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3278 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
|  | 3279 | getFilePaths().push_back("/usr/lib"); | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3280 | } | 
|  | 3281 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3282 | Tool *Minix::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3283 | return new tools::minix::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3284 | } | 
|  | 3285 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3286 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } | 
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3287 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3288 | static void addPathIfExists(const Driver &D, const Twine &Path, | 
|  | 3289 | ToolChain::path_list &Paths) { | 
|  | 3290 | if (D.getVFS().exists(Path)) | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3291 | Paths.push_back(Path.str()); | 
|  | 3292 | } | 
|  | 3293 |  | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3294 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. | 
|  | 3295 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3296 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3297 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3298 | : Generic_GCC(D, Triple, Args) { | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3299 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3300 | GCCInstallation.init(Triple, Args); | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3301 |  | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3302 | path_list &Paths = getFilePaths(); | 
|  | 3303 | if (GCCInstallation.isValid()) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3304 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3305 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3306 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3307 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3308 | addPathIfExists(D, getDriver().Dir, Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3309 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3310 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); | 
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3311 |  | 
|  | 3312 | std::string LibPath = "/usr/lib/"; | 
|  | 3313 | switch (Triple.getArch()) { | 
|  | 3314 | case llvm::Triple::x86: | 
|  | 3315 | case llvm::Triple::sparc: | 
|  | 3316 | break; | 
|  | 3317 | case llvm::Triple::x86_64: | 
|  | 3318 | LibPath += "amd64/"; | 
|  | 3319 | break; | 
|  | 3320 | case llvm::Triple::sparcv9: | 
|  | 3321 | LibPath += "sparcv9/"; | 
|  | 3322 | break; | 
|  | 3323 | default: | 
|  | 3324 | llvm_unreachable("Unsupported architecture"); | 
|  | 3325 | } | 
|  | 3326 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3327 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); | 
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3328 | } | 
|  | 3329 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3330 | Tool *Solaris::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3331 | return new tools::solaris::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3332 | } | 
|  | 3333 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3334 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } | 
| Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3335 |  | 
| Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3336 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 3337 | ArgStringList &CC1Args) const { | 
|  | 3338 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 3339 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 3340 | return; | 
|  | 3341 |  | 
|  | 3342 | // Include the support directory for things like xlocale and fudged system | 
|  | 3343 | // headers. | 
|  | 3344 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); | 
|  | 3345 |  | 
|  | 3346 | if (GCCInstallation.isValid()) { | 
|  | 3347 | GCCVersion Version = GCCInstallation.getVersion(); | 
|  | 3348 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3349 | getDriver().SysRoot + "/usr/gcc/" + | 
|  | 3350 | Version.MajorStr + "." + | 
|  | 3351 | Version.MinorStr + | 
|  | 3352 | "/include/c++/" + Version.Text); | 
|  | 3353 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 3354 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + | 
|  | 3355 | "." + Version.MinorStr + "/include/c++/" + | 
|  | 3356 | Version.Text + "/" + | 
|  | 3357 | GCCInstallation.getTriple().str()); | 
|  | 3358 | } | 
|  | 3359 | } | 
|  | 3360 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3361 | /// Distribution (very bare-bones at the moment). | 
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3362 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3363 | enum Distro { | 
| Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3364 | // NB: Releases of a particular Linux distro should be kept together | 
|  | 3365 | // in this enum, because some tests are done by integer comparison against | 
|  | 3366 | // the first and last known member in the family, e.g. IsRedHat(). | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3367 | ArchLinux, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3368 | DebianLenny, | 
|  | 3369 | DebianSqueeze, | 
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3370 | DebianWheezy, | 
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3371 | DebianJessie, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3372 | DebianStretch, | 
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3373 | Exherbo, | 
| Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3374 | RHEL4, | 
|  | 3375 | RHEL5, | 
|  | 3376 | RHEL6, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3377 | RHEL7, | 
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3378 | Fedora, | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3379 | OpenSUSE, | 
| Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3380 | UbuntuHardy, | 
|  | 3381 | UbuntuIntrepid, | 
| Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3382 | UbuntuJaunty, | 
| Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3383 | UbuntuKarmic, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3384 | UbuntuLucid, | 
|  | 3385 | UbuntuMaverick, | 
| Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3386 | UbuntuNatty, | 
| Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3387 | UbuntuOneiric, | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3388 | UbuntuPrecise, | 
| Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3389 | UbuntuQuantal, | 
|  | 3390 | UbuntuRaring, | 
| Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3391 | UbuntuSaucy, | 
| Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3392 | UbuntuTrusty, | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3393 | UbuntuUtopic, | 
|  | 3394 | UbuntuVivid, | 
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3395 | UbuntuWily, | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3396 | UbuntuXenial, | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3397 | UnknownDistro | 
|  | 3398 | }; | 
|  | 3399 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3400 | static bool IsRedhat(enum Distro Distro) { | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3401 | return Distro == Fedora || (Distro >= RHEL4 && Distro <= RHEL7); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3402 | } | 
|  | 3403 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3404 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3405 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3406 | static bool IsDebian(enum Distro Distro) { | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3407 | return Distro >= DebianLenny && Distro <= DebianStretch; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3408 | } | 
|  | 3409 |  | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3410 | static bool IsUbuntu(enum Distro Distro) { | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3411 | return Distro >= UbuntuHardy && Distro <= UbuntuXenial; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3412 | } | 
|  | 3413 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3414 | static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3415 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = | 
|  | 3416 | llvm::MemoryBuffer::getFile("/etc/lsb-release"); | 
|  | 3417 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3418 | StringRef Data = File.get()->getBuffer(); | 
| Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3419 | SmallVector<StringRef, 16> Lines; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3420 | Data.split(Lines, "\n"); | 
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3421 | Distro Version = UnknownDistro; | 
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3422 | for (StringRef Line : Lines) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3423 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) | 
|  | 3424 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) | 
|  | 3425 | .Case("hardy", UbuntuHardy) | 
|  | 3426 | .Case("intrepid", UbuntuIntrepid) | 
|  | 3427 | .Case("jaunty", UbuntuJaunty) | 
|  | 3428 | .Case("karmic", UbuntuKarmic) | 
|  | 3429 | .Case("lucid", UbuntuLucid) | 
|  | 3430 | .Case("maverick", UbuntuMaverick) | 
|  | 3431 | .Case("natty", UbuntuNatty) | 
|  | 3432 | .Case("oneiric", UbuntuOneiric) | 
|  | 3433 | .Case("precise", UbuntuPrecise) | 
|  | 3434 | .Case("quantal", UbuntuQuantal) | 
|  | 3435 | .Case("raring", UbuntuRaring) | 
|  | 3436 | .Case("saucy", UbuntuSaucy) | 
|  | 3437 | .Case("trusty", UbuntuTrusty) | 
|  | 3438 | .Case("utopic", UbuntuUtopic) | 
|  | 3439 | .Case("vivid", UbuntuVivid) | 
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3440 | .Case("wily", UbuntuWily) | 
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3441 | .Case("xenial", UbuntuXenial) | 
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3442 | .Default(UnknownDistro); | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3443 | return Version; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3444 | } | 
|  | 3445 |  | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3446 | File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); | 
|  | 3447 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3448 | StringRef Data = File.get()->getBuffer(); | 
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3449 | if (Data.startswith("Fedora release")) | 
|  | 3450 | return Fedora; | 
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3451 | if (Data.startswith("Red Hat Enterprise Linux") || | 
|  | 3452 | Data.startswith("CentOS")) { | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3453 | if (Data.find("release 7") != StringRef::npos) | 
|  | 3454 | return RHEL7; | 
|  | 3455 | else if (Data.find("release 6") != StringRef::npos) | 
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3456 | return RHEL6; | 
|  | 3457 | else if (Data.find("release 5") != StringRef::npos) | 
|  | 3458 | return RHEL5; | 
|  | 3459 | else if (Data.find("release 4") != StringRef::npos) | 
|  | 3460 | return RHEL4; | 
|  | 3461 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3462 | return UnknownDistro; | 
|  | 3463 | } | 
|  | 3464 |  | 
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3465 | File = llvm::MemoryBuffer::getFile("/etc/debian_version"); | 
|  | 3466 | if (File) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3467 | StringRef Data = File.get()->getBuffer(); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3468 | if (Data[0] == '5') | 
|  | 3469 | return DebianLenny; | 
| Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 3470 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3471 | return DebianSqueeze; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3472 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') | 
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3473 | return DebianWheezy; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3474 | else if (Data.startswith("jessie/sid") || Data[0] == '8') | 
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3475 | return DebianJessie; | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3476 | else if (Data.startswith("stretch/sid") || Data[0] == '9') | 
|  | 3477 | return DebianStretch; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3478 | return UnknownDistro; | 
|  | 3479 | } | 
|  | 3480 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3481 | if (D.getVFS().exists("/etc/SuSE-release")) | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3482 | return OpenSUSE; | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3483 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3484 | if (D.getVFS().exists("/etc/exherbo-release")) | 
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3485 | return Exherbo; | 
|  | 3486 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3487 | if (D.getVFS().exists("/etc/arch-release")) | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3488 | return ArchLinux; | 
|  | 3489 |  | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3490 | return UnknownDistro; | 
|  | 3491 | } | 
|  | 3492 |  | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3493 | /// \brief Get our best guess at the multiarch triple for a target. | 
|  | 3494 | /// | 
|  | 3495 | /// Debian-based systems are starting to use a multiarch setup where they use | 
|  | 3496 | /// a target-triple directory in the library and header search paths. | 
|  | 3497 | /// Unfortunately, this triple does not align with the vanilla target triple, | 
|  | 3498 | /// so we provide a rough mapping here. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3499 | static std::string getMultiarchTriple(const Driver &D, | 
|  | 3500 | const llvm::Triple &TargetTriple, | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3501 | StringRef SysRoot) { | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 3502 | llvm::Triple::EnvironmentType TargetEnvironment = | 
|  | 3503 | TargetTriple.getEnvironment(); | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3504 |  | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3505 | // For most architectures, just use whatever we have rather than trying to be | 
|  | 3506 | // clever. | 
|  | 3507 | switch (TargetTriple.getArch()) { | 
|  | 3508 | default: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3509 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3510 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3511 | // We use the existence of '/lib/<triple>' as a directory to detect some | 
|  | 3512 | // common linux triples that don't quite match the Clang triple for both | 
|  | 3513 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these | 
|  | 3514 | // regardless of what the actual target triple is. | 
| Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 3515 | case llvm::Triple::arm: | 
|  | 3516 | case llvm::Triple::thumb: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3517 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3518 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3519 | return "arm-linux-gnueabihf"; | 
|  | 3520 | } else { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3521 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3522 | return "arm-linux-gnueabi"; | 
|  | 3523 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3524 | break; | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3525 | case llvm::Triple::armeb: | 
|  | 3526 | case llvm::Triple::thumbeb: | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3527 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3528 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3529 | return "armeb-linux-gnueabihf"; | 
|  | 3530 | } else { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3531 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) | 
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3532 | return "armeb-linux-gnueabi"; | 
|  | 3533 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3534 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3535 | case llvm::Triple::x86: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3536 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3537 | return "i386-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3538 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3539 | case llvm::Triple::x86_64: | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3540 | // 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] | 3541 | if (TargetEnvironment != llvm::Triple::GNUX32 && | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3542 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3543 | return "x86_64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3544 | break; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3545 | case llvm::Triple::aarch64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3546 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3547 | return "aarch64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3548 | break; | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3549 | case llvm::Triple::aarch64_be: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3550 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) | 
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3551 | return "aarch64_be-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3552 | break; | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3553 | case llvm::Triple::mips: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3554 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3555 | return "mips-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3556 | break; | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3557 | case llvm::Triple::mipsel: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3558 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) | 
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3559 | return "mipsel-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3560 | break; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3561 | case llvm::Triple::mips64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3562 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3563 | return "mips64-linux-gnu"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3564 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3565 | return "mips64-linux-gnuabi64"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3566 | break; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3567 | case llvm::Triple::mips64el: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3568 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3569 | return "mips64el-linux-gnu"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3570 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3571 | return "mips64el-linux-gnuabi64"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3572 | break; | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3573 | case llvm::Triple::ppc: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3574 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) | 
| Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 3575 | return "powerpc-linux-gnuspe"; | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3576 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3577 | return "powerpc-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3578 | break; | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3579 | case llvm::Triple::ppc64: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3580 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) | 
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3581 | return "powerpc64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3582 | break; | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3583 | case llvm::Triple::ppc64le: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3584 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) | 
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3585 | return "powerpc64le-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3586 | break; | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3587 | case llvm::Triple::sparc: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3588 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3589 | return "sparc-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3590 | break; | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3591 | case llvm::Triple::sparcv9: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3592 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) | 
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3593 | return "sparc64-linux-gnu"; | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3594 | break; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3595 | case llvm::Triple::systemz: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3596 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3597 | return "s390x-linux-gnu"; | 
|  | 3598 | break; | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3599 | } | 
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3600 | return TargetTriple.str(); | 
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3601 | } | 
|  | 3602 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3603 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3604 | if (isMipsArch(Triple.getArch())) { | 
|  | 3605 | // lib32 directory has a special meaning on MIPS targets. | 
|  | 3606 | // It contains N32 ABI binaries. Use this folder if produce | 
|  | 3607 | // code for N32 ABI only. | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3608 | if (tools::mips::hasMipsAbiArg(Args, "n32")) | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3609 | return "lib32"; | 
|  | 3610 | return Triple.isArch32Bit() ? "lib" : "lib64"; | 
|  | 3611 | } | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3612 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3613 | // 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] | 3614 | // using that variant while targeting other architectures causes problems | 
|  | 3615 | // 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] | 3616 | // with a 'lib32' library search path being considered. So we only enable | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3617 | // them when we know we may need it. | 
|  | 3618 | // | 
|  | 3619 | // 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] | 3620 | // reasoning about oslibdir spellings with the lib dir spellings in the | 
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3621 | // GCCInstallationDetector, but that is a more significant refactoring. | 
|  | 3622 | if (Triple.getArch() == llvm::Triple::x86 || | 
|  | 3623 | Triple.getArch() == llvm::Triple::ppc) | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3624 | return "lib32"; | 
|  | 3625 |  | 
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3626 | if (Triple.getArch() == llvm::Triple::x86_64 && | 
|  | 3627 | Triple.getEnvironment() == llvm::Triple::GNUX32) | 
|  | 3628 | return "libx32"; | 
|  | 3629 |  | 
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3630 | return Triple.isArch32Bit() ? "lib" : "lib64"; | 
|  | 3631 | } | 
|  | 3632 |  | 
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3633 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3634 | : Generic_ELF(D, Triple, Args) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3635 | GCCInstallation.init(Triple, Args); | 
|  | 3636 | CudaInstallation.init(Triple, Args); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3637 | Multilibs = GCCInstallation.getMultilibs(); | 
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3638 | llvm::Triple::ArchType Arch = Triple.getArch(); | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3639 | std::string SysRoot = computeSysRoot(); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3640 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3641 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at | 
| Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 3642 | // least) put various tools in a triple-prefixed directory off of the parent | 
|  | 3643 | // of the GCC installation. We use the GCC triple here to ensure that we end | 
|  | 3644 | // up with tools that support the same amount of cross compiling as the | 
|  | 3645 | // detected GCC installation. For example, if we find a GCC installation | 
|  | 3646 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be | 
|  | 3647 | // used to target i386. | 
|  | 3648 | // FIXME: This seems unlikely to be Linux-specific. | 
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3649 | ToolChain::path_list &PPaths = getProgramPaths(); | 
| Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 3650 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3651 | GCCInstallation.getTriple().str() + "/bin") | 
|  | 3652 | .str()); | 
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3653 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3654 | Distro Distro = DetectDistro(D, Arch); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3655 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3656 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { | 
| Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 3657 | ExtraOpts.push_back("-z"); | 
|  | 3658 | ExtraOpts.push_back("relro"); | 
|  | 3659 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3660 |  | 
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3661 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3662 | ExtraOpts.push_back("-X"); | 
|  | 3663 |  | 
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 3664 | const bool IsAndroid = Triple.isAndroid(); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3665 | const bool IsMips = isMipsArch(Arch); | 
|  | 3666 |  | 
|  | 3667 | if (IsMips && !SysRoot.empty()) | 
|  | 3668 | ExtraOpts.push_back("--sysroot=" + SysRoot); | 
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3669 |  | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3670 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash | 
|  | 3671 | // and the MIPS ABI require .dynsym to be sorted in different ways. | 
|  | 3672 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS | 
|  | 3673 | // ABI requires a mapping between the GOT and the symbol table. | 
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3674 | // Android loader does not support .gnu.hash. | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3675 | if (!IsMips && !IsAndroid) { | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3676 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3677 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3678 | ExtraOpts.push_back("--hash-style=gnu"); | 
|  | 3679 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3680 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || | 
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3681 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) | 
|  | 3682 | ExtraOpts.push_back("--hash-style=both"); | 
|  | 3683 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3684 |  | 
| Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3685 | if (IsRedhat(Distro)) | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3686 | ExtraOpts.push_back("--no-add-needed"); | 
|  | 3687 |  | 
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3688 | if ((IsDebian(Distro) && Distro >= DebianSqueeze) || IsOpenSUSE(Distro) || | 
| Rafael Espindola | d8f92c8 | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 3689 | (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || | 
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3690 | (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3691 | ExtraOpts.push_back("--build-id"); | 
|  | 3692 |  | 
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3693 | if (IsOpenSUSE(Distro)) | 
| Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 3694 | ExtraOpts.push_back("--enable-new-dtags"); | 
| Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 3695 |  | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3696 | // The selection of paths to try here is designed to match the patterns which | 
|  | 3697 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. | 
|  | 3698 | // This was determined by running GCC in a fake filesystem, creating all | 
|  | 3699 | // possible permutations of these directories, and seeing which ones it added | 
|  | 3700 | // to the link paths. | 
|  | 3701 | path_list &Paths = getFilePaths(); | 
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3702 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3703 | const std::string OSLibDir = getOSLibDir(Triple, Args); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3704 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3705 |  | 
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3706 | // Add the multilib suffixed paths where they are available. | 
|  | 3707 | if (GCCInstallation.isValid()) { | 
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 3708 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); | 
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3709 | const std::string &LibPath = GCCInstallation.getParentLibPath(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3710 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 3711 |  | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3712 | // Sourcery CodeBench MIPS toolchain holds some libraries under | 
| Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 3713 | // a biarch-like suffix of the GCC installation. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3714 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3715 | Paths); | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3716 |  | 
|  | 3717 | // GCC cross compiling toolchains will install target libraries which ship | 
|  | 3718 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as | 
|  | 3719 | // any part of the GCC installation in | 
|  | 3720 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat | 
|  | 3721 | // debatable, but is the reality today. We need to search this tree even | 
|  | 3722 | // when we have a sysroot somewhere else. It is the responsibility of | 
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 3723 | // whomever is doing the cross build targeting a sysroot using a GCC | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3724 | // installation that is *not* within the system root to ensure two things: | 
|  | 3725 | // | 
|  | 3726 | //  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] | 3727 | //     above must be present on the system root and found via an | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3728 | //     appropriate rpath. | 
|  | 3729 | //  2) There must not be libraries installed into | 
|  | 3730 | //     <prefix>/<triple>/<libdir> unless they should be preferred over | 
|  | 3731 | //     those within the system root. | 
|  | 3732 | // | 
|  | 3733 | // Note that this matches the GCC behavior. See the below comment for where | 
|  | 3734 | // Clang diverges from GCC's behavior. | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3735 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + | 
|  | 3736 | OSLibDir + Multilib.osSuffix(), | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3737 | Paths); | 
|  | 3738 |  | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3739 | // If the GCC installation we found is inside of the sysroot, we want to | 
|  | 3740 | // prefer libraries installed in the parent prefix of the GCC installation. | 
|  | 3741 | // 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] | 3742 | // outside of the system root as that can pick up unintended libraries. | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3743 | // This usually happens when there is an external cross compiler on the | 
|  | 3744 | // 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] | 3745 | // the cross. Note that GCC does include some of these directories in some | 
|  | 3746 | // configurations but this seems somewhere between questionable and simply | 
|  | 3747 | // a bug. | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3748 | if (StringRef(LibPath).startswith(SysRoot)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3749 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); | 
|  | 3750 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3751 | } | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3752 | } | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3753 |  | 
|  | 3754 | // 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] | 3755 | // of the requested system root, add its parent library paths to | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3756 | // those searched. | 
|  | 3757 | // FIXME: It's not clear whether we should use the driver's installed | 
|  | 3758 | // directory ('Dir' below) or the ResourceDir. | 
|  | 3759 | if (StringRef(D.Dir).startswith(SysRoot)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3760 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); | 
|  | 3761 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3762 | } | 
|  | 3763 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3764 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); | 
|  | 3765 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); | 
|  | 3766 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); | 
|  | 3767 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); | 
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3768 |  | 
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 3769 | // 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] | 3770 | // installations with strange symlinks. | 
| Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 3771 | if (GCCInstallation.isValid()) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3772 | addPathIfExists(D, | 
|  | 3773 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3774 | "/../../" + OSLibDir, | 
|  | 3775 | Paths); | 
| Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 3776 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3777 | // Add the 'other' biarch variant path | 
|  | 3778 | Multilib BiarchSibling; | 
|  | 3779 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3780 | addPathIfExists(D, GCCInstallation.getInstallPath() + | 
|  | 3781 | BiarchSibling.gccSuffix(), | 
|  | 3782 | Paths); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3783 | } | 
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3784 |  | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3785 | // See comments above on the multilib variant for details of why this is | 
|  | 3786 | // included even from outside the sysroot. | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3787 | const std::string &LibPath = GCCInstallation.getParentLibPath(); | 
|  | 3788 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); | 
|  | 3789 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3790 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + | 
|  | 3791 | Multilib.osSuffix(), | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3792 | Paths); | 
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3793 |  | 
|  | 3794 | // See comments above on the multilib variant for details of why this is | 
|  | 3795 | // only included from within the sysroot. | 
|  | 3796 | if (StringRef(LibPath).startswith(SysRoot)) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3797 | addPathIfExists(D, LibPath, Paths); | 
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3798 | } | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3799 |  | 
|  | 3800 | // Similar to the logic for GCC above, if we are currently running Clang | 
|  | 3801 | // inside of the requested system root, add its parent library path to those | 
|  | 3802 | // searched. | 
|  | 3803 | // FIXME: It's not clear whether we should use the driver's installed | 
|  | 3804 | // directory ('Dir' below) or the ResourceDir. | 
|  | 3805 | if (StringRef(D.Dir).startswith(SysRoot)) | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3806 | addPathIfExists(D, D.Dir + "/../lib", Paths); | 
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3807 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3808 | addPathIfExists(D, SysRoot + "/lib", Paths); | 
|  | 3809 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); | 
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3810 | } | 
|  | 3811 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3812 | bool Linux::HasNativeLLVMSupport() const { return true; } | 
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3813 |  | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3814 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3815 |  | 
|  | 3816 | Tool *Linux::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3817 | return new tools::gnutools::Assembler(*this); | 
| Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 3818 | } | 
|  | 3819 |  | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3820 | std::string Linux::computeSysRoot() const { | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3821 | if (!getDriver().SysRoot.empty()) | 
|  | 3822 | return getDriver().SysRoot; | 
|  | 3823 |  | 
|  | 3824 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) | 
|  | 3825 | return std::string(); | 
|  | 3826 |  | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3827 | // Standalone MIPS toolchains use different names for sysroot folder | 
|  | 3828 | // and put it into different places. Here we try to check some known | 
|  | 3829 | // variants. | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3830 |  | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3831 | const StringRef InstallDir = GCCInstallation.getInstallPath(); | 
|  | 3832 | const StringRef TripleStr = GCCInstallation.getTriple().str(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3833 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3834 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3835 | std::string Path = | 
|  | 3836 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) | 
|  | 3837 | .str(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3838 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3839 | if (getVFS().exists(Path)) | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3840 | return Path; | 
|  | 3841 |  | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3842 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3843 |  | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3844 | if (getVFS().exists(Path)) | 
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3845 | return Path; | 
|  | 3846 |  | 
|  | 3847 | return std::string(); | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3848 | } | 
|  | 3849 |  | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3850 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 3851 | ArgStringList &CC1Args) const { | 
|  | 3852 | const Driver &D = getDriver(); | 
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3853 | std::string SysRoot = computeSysRoot(); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3854 |  | 
|  | 3855 | if (DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 3856 | return; | 
|  | 3857 |  | 
|  | 3858 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3859 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3860 |  | 
|  | 3861 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | 
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 3862 | SmallString<128> P(D.ResourceDir); | 
|  | 3863 | llvm::sys::path::append(P, "include"); | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3864 | addSystemInclude(DriverArgs, CC1Args, P); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3865 | } | 
|  | 3866 |  | 
|  | 3867 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 3868 | return; | 
|  | 3869 |  | 
|  | 3870 | // Check for configure-time C include directories. | 
|  | 3871 | StringRef CIncludeDirs(C_INCLUDE_DIRS); | 
|  | 3872 | if (CIncludeDirs != "") { | 
|  | 3873 | SmallVector<StringRef, 5> dirs; | 
|  | 3874 | CIncludeDirs.split(dirs, ":"); | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3875 | for (StringRef dir : dirs) { | 
| Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 3876 | StringRef Prefix = | 
|  | 3877 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3878 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3879 | } | 
|  | 3880 | return; | 
|  | 3881 | } | 
|  | 3882 |  | 
|  | 3883 | // Lacking those, try to detect the correct set of system includes for the | 
|  | 3884 | // target triple. | 
|  | 3885 |  | 
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3886 | // Add include directories specific to the selected multilib set and multilib. | 
|  | 3887 | if (GCCInstallation.isValid()) { | 
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 3888 | const auto &Callback = Multilibs.includeDirsCallback(); | 
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3889 | if (Callback) { | 
|  | 3890 | const auto IncludePaths = Callback(GCCInstallation.getInstallPath(), | 
|  | 3891 | GCCInstallation.getTriple().str(), | 
|  | 3892 | GCCInstallation.getMultilib()); | 
|  | 3893 | for (const auto &Path : IncludePaths) | 
|  | 3894 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); | 
|  | 3895 | } | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3896 | } | 
|  | 3897 |  | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3898 | // Implement generic Debian multiarch support. | 
|  | 3899 | const StringRef X86_64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3900 | "/usr/include/x86_64-linux-gnu", | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3901 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3902 | // FIXME: These are older forms of multiarch. It's not clear that they're | 
|  | 3903 | // in use in any released version of Debian, so we should consider | 
|  | 3904 | // removing them. | 
|  | 3905 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3906 | const StringRef X86MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3907 | "/usr/include/i386-linux-gnu", | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3908 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3909 | // FIXME: These are older forms of multiarch. It's not clear that they're | 
|  | 3910 | // in use in any released version of Debian, so we should consider | 
|  | 3911 | // removing them. | 
|  | 3912 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", | 
|  | 3913 | "/usr/include/i486-linux-gnu"}; | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3914 | const StringRef AArch64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3915 | "/usr/include/aarch64-linux-gnu"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3916 | const StringRef ARMMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3917 | "/usr/include/arm-linux-gnueabi"}; | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3918 | const StringRef ARMHFMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3919 | "/usr/include/arm-linux-gnueabihf"}; | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 3920 | const StringRef ARMEBMultiarchIncludeDirs[] = { | 
|  | 3921 | "/usr/include/armeb-linux-gnueabi"}; | 
|  | 3922 | const StringRef ARMEBHFMultiarchIncludeDirs[] = { | 
|  | 3923 | "/usr/include/armeb-linux-gnueabihf"}; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3924 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3925 | const StringRef MIPSELMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3926 | "/usr/include/mipsel-linux-gnu"}; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3927 | const StringRef MIPS64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3928 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3929 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3930 | "/usr/include/mips64el-linux-gnu", | 
|  | 3931 | "/usr/include/mips64el-linux-gnuabi64"}; | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3932 | const StringRef PPCMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3933 | "/usr/include/powerpc-linux-gnu"}; | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3934 | const StringRef PPC64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3935 | "/usr/include/powerpc64-linux-gnu"}; | 
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 3936 | const StringRef PPC64LEMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3937 | "/usr/include/powerpc64le-linux-gnu"}; | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3938 | const StringRef SparcMultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3939 | "/usr/include/sparc-linux-gnu"}; | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3940 | const StringRef Sparc64MultiarchIncludeDirs[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3941 | "/usr/include/sparc64-linux-gnu"}; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3942 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { | 
|  | 3943 | "/usr/include/s390x-linux-gnu"}; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3944 | ArrayRef<StringRef> MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3945 | switch (getTriple().getArch()) { | 
|  | 3946 | case llvm::Triple::x86_64: | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3947 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3948 | break; | 
|  | 3949 | case llvm::Triple::x86: | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3950 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3951 | break; | 
|  | 3952 | case llvm::Triple::aarch64: | 
|  | 3953 | case llvm::Triple::aarch64_be: | 
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3954 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3955 | break; | 
|  | 3956 | case llvm::Triple::arm: | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 3957 | case llvm::Triple::thumb: | 
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3958 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) | 
|  | 3959 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; | 
|  | 3960 | else | 
|  | 3961 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3962 | break; | 
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 3963 | case llvm::Triple::armeb: | 
|  | 3964 | case llvm::Triple::thumbeb: | 
|  | 3965 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) | 
|  | 3966 | MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs; | 
|  | 3967 | else | 
|  | 3968 | MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs; | 
|  | 3969 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3970 | case llvm::Triple::mips: | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3971 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3972 | break; | 
|  | 3973 | case llvm::Triple::mipsel: | 
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3974 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3975 | break; | 
|  | 3976 | case llvm::Triple::mips64: | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3977 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3978 | break; | 
|  | 3979 | case llvm::Triple::mips64el: | 
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3980 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3981 | break; | 
|  | 3982 | case llvm::Triple::ppc: | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3983 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3984 | break; | 
|  | 3985 | case llvm::Triple::ppc64: | 
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3986 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3987 | break; | 
|  | 3988 | case llvm::Triple::ppc64le: | 
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 3989 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3990 | break; | 
|  | 3991 | case llvm::Triple::sparc: | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3992 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3993 | break; | 
|  | 3994 | case llvm::Triple::sparcv9: | 
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3995 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3996 | break; | 
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3997 | case llvm::Triple::systemz: | 
|  | 3998 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; | 
|  | 3999 | break; | 
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4000 | default: | 
|  | 4001 | break; | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4002 | } | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4003 | for (StringRef Dir : MultiarchIncludeDirs) { | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4004 | if (D.getVFS().exists(SysRoot + Dir)) { | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4005 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); | 
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4006 | break; | 
|  | 4007 | } | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4008 | } | 
|  | 4009 |  | 
|  | 4010 | if (getTriple().getOS() == llvm::Triple::RTEMS) | 
|  | 4011 | return; | 
|  | 4012 |  | 
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4013 | // Add an include of '/include' directly. This isn't provided by default by | 
|  | 4014 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to | 
|  | 4015 | // 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] | 4016 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); | 
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4017 |  | 
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4018 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4019 | } | 
|  | 4020 |  | 
| Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4021 |  | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4022 | static std::string DetectLibcxxIncludePath(StringRef base) { | 
|  | 4023 | std::error_code EC; | 
|  | 4024 | int MaxVersion = 0; | 
|  | 4025 | std::string MaxVersionString = ""; | 
|  | 4026 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; | 
|  | 4027 | LI = LI.increment(EC)) { | 
|  | 4028 | StringRef VersionText = llvm::sys::path::filename(LI->path()); | 
|  | 4029 | int Version; | 
|  | 4030 | if (VersionText[0] == 'v' && | 
|  | 4031 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { | 
|  | 4032 | if (Version > MaxVersion) { | 
|  | 4033 | MaxVersion = Version; | 
|  | 4034 | MaxVersionString = VersionText; | 
|  | 4035 | } | 
|  | 4036 | } | 
|  | 4037 | } | 
|  | 4038 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; | 
|  | 4039 | } | 
|  | 4040 |  | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4041 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, | 
|  | 4042 | ArgStringList &CC1Args) const { | 
|  | 4043 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4044 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4045 | return; | 
|  | 4046 |  | 
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4047 | // Check if libc++ has been enabled and provide its include paths if so. | 
|  | 4048 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4049 | const std::string LibCXXIncludePathCandidates[] = { | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4050 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4051 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4052 | // We also check the system as for a long time this is the only place | 
|  | 4053 | // Clang looked. | 
|  | 4054 | // FIXME: We should really remove this. It doesn't make any sense. | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4055 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++")}; | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4056 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { | 
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4057 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4058 | continue; | 
|  | 4059 | // Add the first candidate that exists. | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4060 | addSystemInclude(DriverArgs, CC1Args, IncludePath); | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4061 | break; | 
|  | 4062 | } | 
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4063 | return; | 
|  | 4064 | } | 
|  | 4065 |  | 
| Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 4066 | // We need a detected GCC installation on Linux to provide libstdc++'s | 
|  | 4067 | // headers. We handled the libc++ case above. | 
|  | 4068 | if (!GCCInstallation.isValid()) | 
|  | 4069 | return; | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4070 |  | 
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4071 | // By default, look for the C++ headers in an include directory adjacent to | 
|  | 4072 | // the lib directory of the GCC installation. Note that this is expect to be | 
|  | 4073 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. | 
|  | 4074 | StringRef LibDir = GCCInstallation.getParentLibPath(); | 
|  | 4075 | StringRef InstallDir = GCCInstallation.getInstallPath(); | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4076 | StringRef TripleStr = GCCInstallation.getTriple().str(); | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4077 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4078 | const std::string GCCMultiarchTriple = getMultiarchTriple( | 
|  | 4079 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4080 | const std::string TargetMultiarchTriple = | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4081 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); | 
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 4082 | const GCCVersion &Version = GCCInstallation.getVersion(); | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4083 |  | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4084 | // The primary search for libstdc++ supports multiarch variants. | 
| Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 4085 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4086 | "/c++/" + Version.Text, TripleStr, | 
|  | 4087 | GCCMultiarchTriple, TargetMultiarchTriple, | 
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4088 | Multilib.includeSuffix(), DriverArgs, CC1Args)) | 
| Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4089 | return; | 
|  | 4090 |  | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4091 | // Otherwise, fall back on a bunch of options which don't use multiarch | 
|  | 4092 | // layouts for simplicity. | 
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4093 | const std::string LibStdCXXIncludePathCandidates[] = { | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4094 | // Gentoo is weird and places its headers inside the GCC install, | 
|  | 4095 | // so if the first attempt to find the headers fails, try these patterns. | 
|  | 4096 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + | 
|  | 4097 | Version.MinorStr, | 
|  | 4098 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, | 
|  | 4099 | // Android standalone toolchain has C++ headers in yet another place. | 
|  | 4100 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, | 
|  | 4101 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, | 
|  | 4102 | // without a subdirectory corresponding to the gcc version. | 
|  | 4103 | LibDir.str() + "/../include/c++", | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4104 | }; | 
|  | 4105 |  | 
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4106 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { | 
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4107 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, | 
|  | 4108 | /*GCCMultiarchTriple*/ "", | 
|  | 4109 | /*TargetMultiarchTriple*/ "", | 
|  | 4110 | Multilib.includeSuffix(), DriverArgs, CC1Args)) | 
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4111 | break; | 
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4112 | } | 
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4113 | } | 
|  | 4114 |  | 
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4115 | void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, | 
|  | 4116 | ArgStringList &CC1Args) const { | 
|  | 4117 | if (DriverArgs.hasArg(options::OPT_nocudainc)) | 
|  | 4118 | return; | 
|  | 4119 |  | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4120 | if (CudaInstallation.isValid()) { | 
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4121 | addSystemInclude(DriverArgs, CC1Args, CudaInstallation.getIncludePath()); | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4122 | CC1Args.push_back("-include"); | 
| Artem Belevich | 7fda3c9 | 2015-12-16 18:51:59 +0000 | [diff] [blame] | 4123 | CC1Args.push_back("__clang_cuda_runtime_wrapper.h"); | 
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4124 | } | 
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4125 | } | 
|  | 4126 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4127 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } | 
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 4128 |  | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4129 | SanitizerMask Linux::getSupportedSanitizers() const { | 
|  | 4130 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; | 
|  | 4131 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; | 
|  | 4132 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || | 
|  | 4133 | getTriple().getArch() == llvm::Triple::mips64el; | 
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4134 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || | 
|  | 4135 | getTriple().getArch() == llvm::Triple::ppc64le; | 
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4136 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || | 
|  | 4137 | getTriple().getArch() == llvm::Triple::aarch64_be; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4138 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 4139 | Res |= SanitizerKind::Address; | 
|  | 4140 | Res |= SanitizerKind::KernelAddress; | 
|  | 4141 | Res |= SanitizerKind::Vptr; | 
| Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 4142 | Res |= SanitizerKind::SafeStack; | 
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4143 | if (IsX86_64 || IsMIPS64 || IsAArch64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4144 | Res |= SanitizerKind::DataFlow; | 
| Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 4145 | if (IsX86_64 || IsMIPS64 || IsAArch64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4146 | Res |= SanitizerKind::Leak; | 
| Bill Schmidt | 4b8841a | 2015-12-08 22:48:02 +0000 | [diff] [blame] | 4147 | if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64) | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4148 | Res |= SanitizerKind::Thread; | 
| Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 4149 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) | 
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4150 | Res |= SanitizerKind::Memory; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4151 | if (IsX86 || IsX86_64) { | 
|  | 4152 | Res |= SanitizerKind::Function; | 
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4153 | } | 
|  | 4154 | return Res; | 
|  | 4155 | } | 
|  | 4156 |  | 
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4157 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, | 
|  | 4158 | llvm::opt::ArgStringList &CmdArgs) const { | 
|  | 4159 | if (!needsProfileRT(Args)) return; | 
|  | 4160 |  | 
|  | 4161 | // Add linker option -u__llvm_runtime_variable to cause runtime | 
|  | 4162 | // initialization module to be linked in. | 
|  | 4163 | if (!Args.hasArg(options::OPT_coverage)) | 
|  | 4164 | CmdArgs.push_back(Args.MakeArgString( | 
|  | 4165 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); | 
|  | 4166 | ToolChain::addProfileRTLibs(Args, CmdArgs); | 
|  | 4167 | } | 
|  | 4168 |  | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4169 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. | 
|  | 4170 |  | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4171 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, | 
|  | 4172 | const ArgList &Args) | 
|  | 4173 | : Generic_ELF(D, Triple, Args) { | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4174 |  | 
|  | 4175 | // Path mangling to find libexec | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4176 | getProgramPaths().push_back(getDriver().getInstalledDir()); | 
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 4177 | if (getDriver().getInstalledDir() != getDriver().Dir) | 
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4178 | getProgramPaths().push_back(getDriver().Dir); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4179 |  | 
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4180 | getFilePaths().push_back(getDriver().Dir + "/../lib"); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4181 | getFilePaths().push_back("/usr/lib"); | 
| Dimitry Andric | f59a2b3 | 2015-12-27 10:01:44 +0000 | [diff] [blame] | 4182 | getFilePaths().push_back("/usr/lib/gcc50"); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4183 | } | 
|  | 4184 |  | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4185 | Tool *DragonFly::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4186 | return new tools::dragonfly::Assembler(*this); | 
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4187 | } | 
|  | 4188 |  | 
|  | 4189 | Tool *DragonFly::buildLinker() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4190 | return new tools::dragonfly::Linker(*this); | 
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4191 | } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4192 |  | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4193 | /// CUDA toolchain.  Our assembler is ptxas, and our "linker" is fatbinary, | 
|  | 4194 | /// which isn't properly a linker but nonetheless performs the step of stitching | 
|  | 4195 | /// together object files from the assembler into a single blob. | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4196 |  | 
|  | 4197 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4198 | const ArgList &Args) | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4199 | : Linux(D, Triple, Args) { | 
|  | 4200 | if (CudaInstallation.isValid()) | 
|  | 4201 | getProgramPaths().push_back(CudaInstallation.getBinPath()); | 
|  | 4202 | } | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4203 |  | 
|  | 4204 | void | 
|  | 4205 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, | 
|  | 4206 | llvm::opt::ArgStringList &CC1Args) const { | 
|  | 4207 | Linux::addClangTargetOptions(DriverArgs, CC1Args); | 
|  | 4208 | CC1Args.push_back("-fcuda-is-device"); | 
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4209 |  | 
|  | 4210 | if (DriverArgs.hasArg(options::OPT_nocudalib)) | 
|  | 4211 | return; | 
|  | 4212 |  | 
|  | 4213 | std::string LibDeviceFile = CudaInstallation.getLibDeviceFile( | 
|  | 4214 | DriverArgs.getLastArgValue(options::OPT_march_EQ)); | 
|  | 4215 | if (!LibDeviceFile.empty()) { | 
|  | 4216 | CC1Args.push_back("-mlink-cuda-bitcode"); | 
|  | 4217 | CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile)); | 
|  | 4218 |  | 
|  | 4219 | // Libdevice in CUDA-7.0 requires PTX version that's more recent | 
|  | 4220 | // than LLVM defaults to. Use PTX4.2 which is the PTX version that | 
|  | 4221 | // came with CUDA-7.0. | 
|  | 4222 | CC1Args.push_back("-target-feature"); | 
|  | 4223 | CC1Args.push_back("+ptx42"); | 
|  | 4224 | } | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4225 | } | 
|  | 4226 |  | 
|  | 4227 | llvm::opt::DerivedArgList * | 
|  | 4228 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, | 
|  | 4229 | const char *BoundArch) const { | 
|  | 4230 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); | 
|  | 4231 | const OptTable &Opts = getDriver().getOpts(); | 
|  | 4232 |  | 
|  | 4233 | for (Arg *A : Args) { | 
|  | 4234 | if (A->getOption().matches(options::OPT_Xarch__)) { | 
|  | 4235 | // Skip this argument unless the architecture matches BoundArch | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4236 | if (!BoundArch || A->getValue(0) != StringRef(BoundArch)) | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4237 | continue; | 
|  | 4238 |  | 
|  | 4239 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); | 
|  | 4240 | unsigned Prev = Index; | 
|  | 4241 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); | 
|  | 4242 |  | 
|  | 4243 | // If the argument parsing failed or more than one argument was | 
|  | 4244 | // consumed, the -Xarch_ argument's parameter tried to consume | 
|  | 4245 | // extra arguments. Emit an error and ignore. | 
|  | 4246 | // | 
|  | 4247 | // We also want to disallow any options which would alter the | 
|  | 4248 | // driver behavior; that isn't going to work in our model. We | 
|  | 4249 | // use isDriverOption() as an approximation, although things | 
|  | 4250 | // like -O4 are going to slip through. | 
|  | 4251 | if (!XarchArg || Index > Prev + 1) { | 
|  | 4252 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) | 
|  | 4253 | << A->getAsString(Args); | 
|  | 4254 | continue; | 
|  | 4255 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { | 
|  | 4256 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) | 
|  | 4257 | << A->getAsString(Args); | 
|  | 4258 | continue; | 
|  | 4259 | } | 
|  | 4260 | XarchArg->setBaseArg(A); | 
|  | 4261 | A = XarchArg.release(); | 
|  | 4262 | DAL->AddSynthesizedArg(A); | 
|  | 4263 | } | 
|  | 4264 | DAL->append(A); | 
|  | 4265 | } | 
|  | 4266 |  | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4267 | if (BoundArch) | 
|  | 4268 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); | 
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4269 | return DAL; | 
|  | 4270 | } | 
|  | 4271 |  | 
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4272 | Tool *CudaToolChain::buildAssembler() const { | 
|  | 4273 | return new tools::NVPTX::Assembler(*this); | 
|  | 4274 | } | 
|  | 4275 |  | 
|  | 4276 | Tool *CudaToolChain::buildLinker() const { | 
|  | 4277 | return new tools::NVPTX::Linker(*this); | 
|  | 4278 | } | 
|  | 4279 |  | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4280 | /// XCore tool chain | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4281 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4282 | const ArgList &Args) | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4283 | : ToolChain(D, Triple, Args) { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4284 | // ProgramPaths are found via 'PATH' environment variable. | 
|  | 4285 | } | 
|  | 4286 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4287 | Tool *XCoreToolChain::buildAssembler() const { | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4288 | return new tools::XCore::Assembler(*this); | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4289 | } | 
|  | 4290 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4291 | Tool *XCoreToolChain::buildLinker() const { | 
|  | 4292 | return new tools::XCore::Linker(*this); | 
|  | 4293 | } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4294 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4295 | bool XCoreToolChain::isPICDefault() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4296 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4297 | bool XCoreToolChain::isPIEDefault() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4298 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4299 | bool XCoreToolChain::isPICDefaultForced() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4300 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4301 | bool XCoreToolChain::SupportsProfiling() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4302 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4303 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4304 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4305 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4306 | ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4307 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
|  | 4308 | DriverArgs.hasArg(options::OPT_nostdlibinc)) | 
|  | 4309 | return; | 
|  | 4310 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { | 
|  | 4311 | SmallVector<StringRef, 4> Dirs; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4312 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4313 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); | 
|  | 4314 | ArrayRef<StringRef> DirVec(Dirs); | 
|  | 4315 | addSystemIncludes(DriverArgs, CC1Args, DirVec); | 
|  | 4316 | } | 
|  | 4317 | } | 
|  | 4318 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4319 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 4320 | ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4321 | CC1Args.push_back("-nostdsysteminc"); | 
|  | 4322 | } | 
|  | 4323 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4324 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 4325 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4326 | if (DriverArgs.hasArg(options::OPT_nostdinc) || | 
| Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 4327 | DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4328 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4329 | return; | 
|  | 4330 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { | 
|  | 4331 | SmallVector<StringRef, 4> Dirs; | 
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4332 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4333 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); | 
|  | 4334 | ArrayRef<StringRef> DirVec(Dirs); | 
|  | 4335 | addSystemIncludes(DriverArgs, CC1Args, DirVec); | 
|  | 4336 | } | 
|  | 4337 | } | 
|  | 4338 |  | 
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4339 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, | 
|  | 4340 | ArgStringList &CmdArgs) const { | 
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4341 | // We don't output any lib args. This is handled by xcc. | 
|  | 4342 | } | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4343 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4344 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, | 
|  | 4345 | const ArgList &Args) | 
|  | 4346 | : Generic_GCC(D, Triple, Args) { | 
|  | 4347 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use | 
|  | 4348 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. | 
|  | 4349 | // This won't work to find gcc. Instead we give the installation detector an | 
|  | 4350 | // extra triple, which is preferable to further hacks of the logic that at | 
|  | 4351 | // present is based solely on getArch(). In particular, it would be wrong to | 
|  | 4352 | // choose the myriad installation when targeting a non-myriad sparc install. | 
|  | 4353 | switch (Triple.getArch()) { | 
|  | 4354 | default: | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4355 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() | 
|  | 4356 | << "myriad"; | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4357 | case llvm::Triple::sparc: | 
|  | 4358 | case llvm::Triple::sparcel: | 
|  | 4359 | case llvm::Triple::shave: | 
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4360 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4361 | } | 
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 4362 |  | 
|  | 4363 | if (GCCInstallation.isValid()) { | 
|  | 4364 | // The contents of LibDir are independent of the version of gcc. | 
|  | 4365 | // This contains libc, libg (a superset of libc), libm, libstdc++, libssp. | 
|  | 4366 | SmallString<128> LibDir(GCCInstallation.getParentLibPath()); | 
|  | 4367 | if (Triple.getArch() == llvm::Triple::sparcel) | 
|  | 4368 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib/le"); | 
|  | 4369 | else | 
|  | 4370 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib"); | 
|  | 4371 | addPathIfExists(D, LibDir, getFilePaths()); | 
|  | 4372 |  | 
|  | 4373 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. | 
|  | 4374 | // These files are tied to a particular version of gcc. | 
|  | 4375 | SmallString<128> CompilerSupportDir(GCCInstallation.getInstallPath()); | 
|  | 4376 | // There are actually 4 choices: {le,be} x {fpu,nofpu} | 
|  | 4377 | // but as this toolchain is for LEON sparc, it can assume FPU. | 
|  | 4378 | if (Triple.getArch() == llvm::Triple::sparcel) | 
|  | 4379 | llvm::sys::path::append(CompilerSupportDir, "le"); | 
|  | 4380 | addPathIfExists(D, CompilerSupportDir, getFilePaths()); | 
|  | 4381 | } | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4382 | } | 
|  | 4383 |  | 
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4384 | MyriadToolChain::~MyriadToolChain() {} | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4385 |  | 
| Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 4386 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4387 | ArgStringList &CC1Args) const { | 
|  | 4388 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 4389 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); | 
|  | 4390 | } | 
|  | 4391 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4392 | void MyriadToolChain::AddClangCXXStdlibIncludeArgs( | 
|  | 4393 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4394 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || | 
|  | 4395 | DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4396 | return; | 
|  | 4397 |  | 
|  | 4398 | // Only libstdc++, for now. | 
|  | 4399 | StringRef LibDir = GCCInstallation.getParentLibPath(); | 
|  | 4400 | const GCCVersion &Version = GCCInstallation.getVersion(); | 
|  | 4401 | StringRef TripleStr = GCCInstallation.getTriple().str(); | 
|  | 4402 | const Multilib &Multilib = GCCInstallation.getMultilib(); | 
|  | 4403 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4404 | addLibStdCXXIncludePaths( | 
|  | 4405 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, | 
|  | 4406 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); | 
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4407 | } | 
|  | 4408 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4409 | // MyriadToolChain handles several triples: | 
|  | 4410 | //  {shave,sparc{,el}}-myriad-{rtems,unknown}-elf | 
|  | 4411 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { | 
|  | 4412 | // The inherited method works fine if not targeting the SHAVE. | 
|  | 4413 | if (!isShaveCompilation(getTriple())) | 
|  | 4414 | return ToolChain::SelectTool(JA); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4415 | switch (JA.getKind()) { | 
| Douglas Katzman | 9dc4c62 | 2015-11-20 04:58:12 +0000 | [diff] [blame] | 4416 | case Action::PreprocessJobClass: | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4417 | case Action::CompileJobClass: | 
|  | 4418 | if (!Compiler) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4419 | Compiler.reset(new tools::SHAVE::Compiler(*this)); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4420 | return Compiler.get(); | 
|  | 4421 | case Action::AssembleJobClass: | 
|  | 4422 | if (!Assembler) | 
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4423 | Assembler.reset(new tools::SHAVE::Assembler(*this)); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4424 | return Assembler.get(); | 
|  | 4425 | default: | 
|  | 4426 | return ToolChain::getTool(JA.getKind()); | 
|  | 4427 | } | 
|  | 4428 | } | 
|  | 4429 |  | 
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4430 | Tool *MyriadToolChain::buildLinker() const { | 
|  | 4431 | return new tools::Myriad::Linker(*this); | 
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4432 | } | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4433 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4434 | WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple, | 
|  | 4435 | const llvm::opt::ArgList &Args) | 
|  | 4436 | : ToolChain(D, Triple, Args) { | 
|  | 4437 | // Use LLD by default. | 
|  | 4438 | DefaultLinker = "lld"; | 
|  | 4439 | } | 
|  | 4440 |  | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4441 | bool WebAssembly::IsMathErrnoDefault() const { return false; } | 
|  | 4442 |  | 
|  | 4443 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } | 
|  | 4444 |  | 
|  | 4445 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } | 
|  | 4446 |  | 
|  | 4447 | bool WebAssembly::isPICDefault() const { return false; } | 
|  | 4448 |  | 
|  | 4449 | bool WebAssembly::isPIEDefault() const { return false; } | 
|  | 4450 |  | 
|  | 4451 | bool WebAssembly::isPICDefaultForced() const { return false; } | 
|  | 4452 |  | 
|  | 4453 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } | 
|  | 4454 |  | 
|  | 4455 | // TODO: Support Objective C stuff. | 
|  | 4456 | bool WebAssembly::SupportsObjCGC() const { return false; } | 
|  | 4457 |  | 
|  | 4458 | bool WebAssembly::hasBlocksRuntime() const { return false; } | 
|  | 4459 |  | 
|  | 4460 | // TODO: Support profiling. | 
|  | 4461 | bool WebAssembly::SupportsProfiling() const { return false; } | 
|  | 4462 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4463 | bool WebAssembly::HasNativeLLVMSupport() const { return true; } | 
|  | 4464 |  | 
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4465 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, | 
|  | 4466 | ArgStringList &CC1Args) const { | 
|  | 4467 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, | 
|  | 4468 | options::OPT_fno_use_init_array, true)) | 
|  | 4469 | CC1Args.push_back("-fuse-init-array"); | 
|  | 4470 | } | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4471 |  | 
| Dan Gohman | 6ad8f61 | 2016-01-14 16:00:13 +0000 | [diff] [blame] | 4472 | ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const { | 
|  | 4473 | return ToolChain::RLT_CompilerRT; | 
|  | 4474 | } | 
|  | 4475 |  | 
|  | 4476 | ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { | 
|  | 4477 | return ToolChain::CST_Libcxx; | 
|  | 4478 | } | 
|  | 4479 |  | 
|  | 4480 | void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs, | 
|  | 4481 | ArgStringList &CC1Args) const { | 
|  | 4482 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) | 
|  | 4483 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); | 
|  | 4484 | } | 
|  | 4485 |  | 
|  | 4486 | void WebAssembly::AddClangCXXStdlibIncludeArgs( | 
|  | 4487 | const llvm::opt::ArgList &DriverArgs, | 
|  | 4488 | llvm::opt::ArgStringList &CC1Args) const { | 
|  | 4489 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc) && | 
|  | 4490 | !DriverArgs.hasArg(options::OPT_nostdincxx)) | 
|  | 4491 | addSystemInclude(DriverArgs, CC1Args, | 
|  | 4492 | getDriver().SysRoot + "/include/c++/v1"); | 
|  | 4493 | } | 
|  | 4494 |  | 
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4495 | Tool *WebAssembly::buildLinker() const { | 
|  | 4496 | return new tools::wasm::Linker(*this); | 
|  | 4497 | } | 
|  | 4498 |  | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4499 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | 
|  | 4500 | : Generic_ELF(D, Triple, Args) { | 
|  | 4501 | if (Args.hasArg(options::OPT_static)) | 
|  | 4502 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; | 
|  | 4503 |  | 
|  | 4504 | // Determine where to find the PS4 libraries. We use SCE_PS4_SDK_DIR | 
|  | 4505 | // if it exists; otherwise use the driver's installation path, which | 
|  | 4506 | // should be <SDK_DIR>/host_tools/bin. | 
|  | 4507 |  | 
|  | 4508 | SmallString<512> PS4SDKDir; | 
|  | 4509 | if (const char *EnvValue = getenv("SCE_PS4_SDK_DIR")) { | 
|  | 4510 | if (!llvm::sys::fs::exists(EnvValue)) | 
|  | 4511 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; | 
|  | 4512 | PS4SDKDir = EnvValue; | 
|  | 4513 | } else { | 
|  | 4514 | PS4SDKDir = getDriver().Dir; | 
|  | 4515 | llvm::sys::path::append(PS4SDKDir, "/../../"); | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4516 | } | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4517 |  | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4518 | // 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] | 4519 | // PS4's include or lib directories. This behavior could be changed if | 
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4520 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. | 
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4521 | // If -isysroot was passed, use that as the SDK base path. | 
|  | 4522 | std::string PrefixDir; | 
|  | 4523 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { | 
|  | 4524 | PrefixDir = A->getValue(); | 
|  | 4525 | if (!llvm::sys::fs::exists(PrefixDir)) | 
|  | 4526 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; | 
|  | 4527 | } else | 
|  | 4528 | PrefixDir = PS4SDKDir.str(); | 
|  | 4529 |  | 
|  | 4530 | SmallString<512> PS4SDKIncludeDir(PrefixDir); | 
|  | 4531 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); | 
|  | 4532 | if (!Args.hasArg(options::OPT_nostdinc) && | 
|  | 4533 | !Args.hasArg(options::OPT_nostdlibinc) && | 
|  | 4534 | !Args.hasArg(options::OPT_isysroot) && | 
|  | 4535 | !Args.hasArg(options::OPT__sysroot_EQ) && | 
|  | 4536 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { | 
|  | 4537 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) | 
|  | 4538 | << "PS4 system headers" << PS4SDKIncludeDir; | 
|  | 4539 | } | 
|  | 4540 |  | 
|  | 4541 | SmallString<512> PS4SDKLibDir(PS4SDKDir); | 
|  | 4542 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); | 
|  | 4543 | if (!Args.hasArg(options::OPT_nostdlib) && | 
|  | 4544 | !Args.hasArg(options::OPT_nodefaultlibs) && | 
|  | 4545 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && | 
|  | 4546 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && | 
|  | 4547 | !Args.hasArg(options::OPT_emit_ast) && | 
|  | 4548 | !llvm::sys::fs::exists(PS4SDKLibDir)) { | 
|  | 4549 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) | 
|  | 4550 | << "PS4 system libraries" << PS4SDKLibDir; | 
|  | 4551 | return; | 
|  | 4552 | } | 
|  | 4553 | getFilePaths().push_back(PS4SDKLibDir.str()); | 
|  | 4554 | } | 
|  | 4555 |  | 
|  | 4556 | Tool *PS4CPU::buildAssembler() const { | 
|  | 4557 | return new tools::PS4cpu::Assemble(*this); | 
|  | 4558 | } | 
|  | 4559 |  | 
|  | 4560 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } | 
|  | 4561 |  | 
|  | 4562 | bool PS4CPU::isPICDefault() const { return true; } | 
|  | 4563 |  | 
|  | 4564 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } | 
|  | 4565 |  | 
|  | 4566 | SanitizerMask PS4CPU::getSupportedSanitizers() const { | 
|  | 4567 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); | 
|  | 4568 | Res |= SanitizerKind::Address; | 
|  | 4569 | Res |= SanitizerKind::Vptr; | 
|  | 4570 | return Res; | 
|  | 4571 | } |