| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 1 | //===--- ToolChains.cpp - ToolChain Implementations -------------*- C++ -*-===// |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "ToolChains.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 11 | #include "clang/Basic/ObjCRuntime.h" |
| 12 | #include "clang/Basic/Version.h" |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 13 | #include "clang/Basic/VirtualFileSystem.h" |
| Alp Toker | 1d257e1 | 2014-06-04 03:28:55 +0000 | [diff] [blame] | 14 | #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX |
| Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Compilation.h" |
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Driver.h" |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 17 | #include "clang/Driver/DriverDiagnostic.h" |
| Daniel Dunbar | da13faf | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 18 | #include "clang/Driver/Options.h" |
| Alexey Samsonov | 609213f9 | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 19 | #include "clang/Driver/SanitizerArgs.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallString.h" |
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringExtras.h" |
| Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringSwitch.h" |
| Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 24 | #include "llvm/Option/Arg.h" |
| 25 | #include "llvm/Option/ArgList.h" |
| 26 | #include "llvm/Option/OptTable.h" |
| 27 | #include "llvm/Option/Option.h" |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 28 | #include "llvm/ProfileData/InstrProf.h" |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
| Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 30 | #include "llvm/Support/FileSystem.h" |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 31 | #include "llvm/Support/MemoryBuffer.h" |
| Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Path.h" |
| Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Program.h" |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/TargetParser.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 36 | #include <cstdlib> // ::getenv |
| Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 37 | #include <system_error> |
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 38 | |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 39 | using namespace clang::driver; |
| 40 | using namespace clang::driver::toolchains; |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 41 | using namespace clang; |
| Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 42 | using namespace llvm::opt; |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 43 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 44 | MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 45 | : ToolChain(D, Triple, Args) { |
| Tim Northover | 15ff71d | 2014-05-22 13:12:14 +0000 | [diff] [blame] | 46 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
| 47 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 48 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 49 | getProgramPaths().push_back(getDriver().Dir); |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 50 | } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 51 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 52 | /// Darwin - Darwin tool chain for i386 and x86_64. |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 53 | Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 54 | : MachO(D, Triple, Args), TargetInitialized(false) {} |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 55 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 56 | types::ID MachO::LookupTypeForExtension(const char *Ext) const { |
| Daniel Dunbar | cc7df6c | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 57 | types::ID Ty = types::lookupTypeForExtension(Ext); |
| 58 | |
| 59 | // Darwin always preprocesses assembly files (unless -x is used explicitly). |
| 60 | if (Ty == types::TY_PP_Asm) |
| 61 | return types::TY_Asm; |
| 62 | |
| 63 | return Ty; |
| 64 | } |
| 65 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 66 | bool MachO::HasNativeLLVMSupport() const { return true; } |
| Daniel Dunbar | 62123a1 | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 67 | |
| Jonas Hahnfeld | aae8374 | 2016-02-12 07:48:37 +0000 | [diff] [blame] | 68 | ToolChain::CXXStdlibType Darwin::GetDefaultCXXStdlibType() const { |
| 69 | // Default to use libc++ on OS X 10.9+ and iOS 7+. |
| 70 | if ((isTargetMacOS() && !isMacosxVersionLT(10, 9)) || |
| 71 | (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) || |
| 72 | isTargetWatchOSBased()) |
| 73 | return ToolChain::CST_Libcxx; |
| 74 | |
| 75 | return ToolChain::CST_Libstdcxx; |
| 76 | } |
| 77 | |
| John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 78 | /// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 79 | ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 80 | if (isTargetWatchOSBased()) |
| Tim Northover | 756447a | 2015-10-30 16:30:36 +0000 | [diff] [blame] | 81 | return ObjCRuntime(ObjCRuntime::WatchOS, TargetVersion); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 82 | if (isTargetIOSBased()) |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 83 | return ObjCRuntime(ObjCRuntime::iOS, TargetVersion); |
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 84 | if (isNonFragile) |
| 85 | return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion); |
| 86 | return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion); |
| John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 89 | /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. |
| 90 | bool Darwin::hasBlocksRuntime() const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 91 | if (isTargetWatchOSBased()) |
| 92 | return true; |
| 93 | else if (isTargetIOSBased()) |
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 94 | return !isIPhoneOSVersionLT(3, 2); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 95 | else { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 96 | assert(isTargetMacOS() && "unexpected darwin target"); |
| 97 | return !isMacosxVersionLT(10, 6); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 98 | } |
| John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 101 | // This is just a MachO name translation routine and there's no |
| 102 | // way to join this into ARMTargetParser without breaking all |
| 103 | // other assumptions. Maybe MachO should consider standardising |
| 104 | // their nomenclature. |
| 105 | static const char *ArmMachOArchName(StringRef Arch) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 106 | return llvm::StringSwitch<const char *>(Arch) |
| 107 | .Case("armv6k", "armv6") |
| 108 | .Case("armv6m", "armv6m") |
| 109 | .Case("armv5tej", "armv5") |
| 110 | .Case("xscale", "xscale") |
| 111 | .Case("armv4t", "armv4t") |
| 112 | .Case("armv7", "armv7") |
| 113 | .Cases("armv7a", "armv7-a", "armv7") |
| 114 | .Cases("armv7r", "armv7-r", "armv7") |
| 115 | .Cases("armv7em", "armv7e-m", "armv7em") |
| 116 | .Cases("armv7k", "armv7-k", "armv7k") |
| 117 | .Cases("armv7m", "armv7-m", "armv7m") |
| 118 | .Cases("armv7s", "armv7-s", "armv7s") |
| 119 | .Default(nullptr); |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 122 | static const char *ArmMachOArchNameCPU(StringRef CPU) { |
| Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 123 | unsigned ArchKind = llvm::ARM::parseCPUArch(CPU); |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 124 | if (ArchKind == llvm::ARM::AK_INVALID) |
| 125 | return nullptr; |
| Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 126 | StringRef Arch = llvm::ARM::getArchName(ArchKind); |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 127 | |
| 128 | // FIXME: Make sure this MachO triple mangling is really necessary. |
| 129 | // ARMv5* normalises to ARMv5. |
| 130 | if (Arch.startswith("armv5")) |
| 131 | Arch = Arch.substr(0, 5); |
| 132 | // ARMv6*, except ARMv6M, normalises to ARMv6. |
| 133 | else if (Arch.startswith("armv6") && !Arch.endswith("6m")) |
| 134 | Arch = Arch.substr(0, 5); |
| 135 | // ARMv7A normalises to ARMv7. |
| 136 | else if (Arch.endswith("v7a")) |
| 137 | Arch = Arch.substr(0, 5); |
| 138 | return Arch.data(); |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 141 | static bool isSoftFloatABI(const ArgList &Args) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 142 | Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 143 | options::OPT_mfloat_abi_EQ); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 144 | if (!A) |
| 145 | return false; |
| Rafael Auler | 3f7abf7 | 2014-09-29 21:50:34 +0000 | [diff] [blame] | 146 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 147 | return A->getOption().matches(options::OPT_msoft_float) || |
| 148 | (A->getOption().matches(options::OPT_mfloat_abi_EQ) && |
| 149 | A->getValue() == StringRef("soft")); |
| 150 | } |
| 151 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 152 | StringRef MachO::getMachOArchName(const ArgList &Args) const { |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 153 | switch (getTriple().getArch()) { |
| 154 | default: |
| Rafael Espindola | ed1233e | 2014-08-28 21:23:05 +0000 | [diff] [blame] | 155 | return getDefaultUniversalArchName(); |
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 156 | |
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 157 | case llvm::Triple::aarch64: |
| 158 | return "arm64"; |
| 159 | |
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 160 | case llvm::Triple::thumb: |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 161 | case llvm::Triple::arm: |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 162 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 163 | if (const char *Arch = ArmMachOArchName(A->getValue())) |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 164 | return Arch; |
| 165 | |
| 166 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
| Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 167 | if (const char *Arch = ArmMachOArchNameCPU(A->getValue())) |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 168 | return Arch; |
| 169 | |
| 170 | return "arm"; |
| 171 | } |
| Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 174 | Darwin::~Darwin() {} |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 175 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 176 | MachO::~MachO() {} |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 177 | |
| 178 | std::string MachO::ComputeEffectiveClangTriple(const ArgList &Args, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 179 | types::ID InputType) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 180 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
| 181 | |
| 182 | return Triple.getTriple(); |
| 183 | } |
| 184 | |
| Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 185 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, |
| 186 | types::ID InputType) const { |
| 187 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 188 | |
| 189 | // If the target isn't initialized (e.g., an unknown Darwin platform, return |
| 190 | // the default triple). |
| 191 | if (!isTargetInitialized()) |
| 192 | return Triple.getTriple(); |
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 193 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 194 | SmallString<16> Str; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 195 | if (isTargetWatchOSBased()) |
| 196 | Str += "watchos"; |
| 197 | else if (isTargetTvOSBased()) |
| 198 | Str += "tvos"; |
| 199 | else if (isTargetIOSBased()) |
| 200 | Str += "ios"; |
| 201 | else |
| 202 | Str += "macosx"; |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 203 | Str += getTargetVersion().getAsString(); |
| 204 | Triple.setOSName(Str); |
| Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 205 | |
| 206 | return Triple.getTriple(); |
| 207 | } |
| 208 | |
| David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 209 | void Generic_ELF::anchor() {} |
| 210 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 211 | Tool *MachO::getTool(Action::ActionClass AC) const { |
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 212 | switch (AC) { |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 213 | case Action::LipoJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 214 | if (!Lipo) |
| 215 | Lipo.reset(new tools::darwin::Lipo(*this)); |
| 216 | return Lipo.get(); |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 217 | case Action::DsymutilJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 218 | if (!Dsymutil) |
| 219 | Dsymutil.reset(new tools::darwin::Dsymutil(*this)); |
| 220 | return Dsymutil.get(); |
| Ben Langmuir | 9b9a8d3 | 2014-02-06 18:53:25 +0000 | [diff] [blame] | 221 | case Action::VerifyDebugInfoJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 222 | if (!VerifyDebug) |
| 223 | VerifyDebug.reset(new tools::darwin::VerifyDebug(*this)); |
| 224 | return VerifyDebug.get(); |
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 225 | default: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 226 | return ToolChain::getTool(AC); |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 227 | } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 230 | Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); } |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 231 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 232 | Tool *MachO::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 233 | return new tools::darwin::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 234 | } |
| Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 235 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 236 | DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 237 | const ArgList &Args) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 238 | : Darwin(D, Triple, Args) {} |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 239 | |
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 240 | void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 241 | // For modern targets, promote certain warnings to errors. |
| 242 | if (isTargetWatchOSBased() || getTriple().isArch64Bit()) { |
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 243 | // Always enable -Wdeprecated-objc-isa-usage and promote it |
| 244 | // to an error. |
| 245 | CC1Args.push_back("-Wdeprecated-objc-isa-usage"); |
| 246 | CC1Args.push_back("-Werror=deprecated-objc-isa-usage"); |
| 247 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 248 | // For iOS and watchOS, also error about implicit function declarations, |
| 249 | // as that can impact calling conventions. |
| 250 | if (!isTargetMacOS()) |
| 251 | CC1Args.push_back("-Werror=implicit-function-declaration"); |
| Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 255 | /// \brief Determine whether Objective-C automated reference counting is |
| 256 | /// enabled. |
| 257 | static bool isObjCAutoRefCount(const ArgList &Args) { |
| 258 | return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); |
| 259 | } |
| 260 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 261 | void DarwinClang::AddLinkARCArgs(const ArgList &Args, |
| 262 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 263 | // Avoid linking compatibility stubs on i386 mac. |
| 264 | if (isTargetMacOS() && getArch() == llvm::Triple::x86) |
| 265 | return; |
| 266 | |
| 267 | ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true); |
| 268 | |
| 269 | if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) && |
| 270 | runtime.hasSubscripting()) |
| 271 | return; |
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 272 | |
| 273 | CmdArgs.push_back("-force_load"); |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 274 | SmallString<128> P(getDriver().ClangExecutable); |
| 275 | llvm::sys::path::remove_filename(P); // 'clang' |
| 276 | llvm::sys::path::remove_filename(P); // 'bin' |
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 277 | llvm::sys::path::append(P, "lib", "arc", "libarclite_"); |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 278 | // Mash in the platform. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 279 | if (isTargetWatchOSSimulator()) |
| 280 | P += "watchsimulator"; |
| 281 | else if (isTargetWatchOS()) |
| 282 | P += "watchos"; |
| 283 | else if (isTargetTvOSSimulator()) |
| 284 | P += "appletvsimulator"; |
| 285 | else if (isTargetTvOS()) |
| 286 | P += "appletvos"; |
| 287 | else if (isTargetIOSSimulator()) |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 288 | P += "iphonesimulator"; |
| Argyrios Kyrtzidis | 058b451 | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 289 | else if (isTargetIPhoneOS()) |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 290 | P += "iphoneos"; |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 291 | else |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 292 | P += "macosx"; |
| 293 | P += ".a"; |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 294 | |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 295 | CmdArgs.push_back(Args.MakeArgString(P)); |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 298 | void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, |
| Kuba Brecka | 2735a025 | 2014-10-31 00:08:57 +0000 | [diff] [blame] | 299 | StringRef DarwinLibName, bool AlwaysLink, |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 300 | bool IsEmbedded, bool AddRPath) const { |
| 301 | SmallString<128> Dir(getDriver().ResourceDir); |
| 302 | llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin"); |
| 303 | |
| 304 | SmallString<128> P(Dir); |
| 305 | llvm::sys::path::append(P, DarwinLibName); |
| Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 306 | |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 307 | // For now, allow missing resource libraries to support developers who may |
| Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 308 | // not have compiler-rt checked out or integrated into their build (unless |
| 309 | // we explicitly force linking with this library). |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 310 | if (AlwaysLink || getVFS().exists(P)) |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 311 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 312 | |
| 313 | // Adding the rpaths might negatively interact when other rpaths are involved, |
| 314 | // so we should make sure we add the rpaths last, after all user-specified |
| 315 | // rpaths. This is currently true from this place, but we need to be |
| 316 | // careful if this function is ever called before user's rpaths are emitted. |
| 317 | if (AddRPath) { |
| 318 | assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library"); |
| 319 | |
| 320 | // Add @executable_path to rpath to support having the dylib copied with |
| 321 | // the executable. |
| 322 | CmdArgs.push_back("-rpath"); |
| 323 | CmdArgs.push_back("@executable_path"); |
| 324 | |
| 325 | // Add the path to the resource dir to rpath to support using the dylib |
| 326 | // from the default location without copying. |
| 327 | CmdArgs.push_back("-rpath"); |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 328 | CmdArgs.push_back(Args.MakeArgString(Dir)); |
| Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 329 | } |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 332 | StringRef Darwin::getPlatformFamily() const { |
| 333 | switch (TargetPlatform) { |
| 334 | case DarwinPlatformKind::MacOS: |
| 335 | return "MacOSX"; |
| 336 | case DarwinPlatformKind::IPhoneOS: |
| 337 | case DarwinPlatformKind::IPhoneOSSimulator: |
| 338 | return "iPhone"; |
| 339 | case DarwinPlatformKind::TvOS: |
| 340 | case DarwinPlatformKind::TvOSSimulator: |
| 341 | return "AppleTV"; |
| 342 | case DarwinPlatformKind::WatchOS: |
| 343 | case DarwinPlatformKind::WatchOSSimulator: |
| 344 | return "Watch"; |
| 345 | } |
| 346 | llvm_unreachable("Unsupported platform"); |
| 347 | } |
| 348 | |
| 349 | StringRef Darwin::getSDKName(StringRef isysroot) { |
| 350 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk |
| 351 | llvm::sys::path::const_iterator SDKDir; |
| 352 | auto BeginSDK = llvm::sys::path::begin(isysroot); |
| 353 | auto EndSDK = llvm::sys::path::end(isysroot); |
| 354 | for (auto IT = BeginSDK; IT != EndSDK; ++IT) { |
| 355 | StringRef SDK = *IT; |
| 356 | if (SDK.endswith(".sdk")) |
| 357 | return SDK.slice(0, SDK.size() - 4); |
| 358 | } |
| 359 | return ""; |
| 360 | } |
| 361 | |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 362 | StringRef Darwin::getOSLibraryNameSuffix() const { |
| 363 | switch(TargetPlatform) { |
| 364 | case DarwinPlatformKind::MacOS: |
| 365 | return "osx"; |
| 366 | case DarwinPlatformKind::IPhoneOS: |
| 367 | return "ios"; |
| 368 | case DarwinPlatformKind::IPhoneOSSimulator: |
| 369 | return "iossim"; |
| 370 | case DarwinPlatformKind::TvOS: |
| 371 | return "tvos"; |
| 372 | case DarwinPlatformKind::TvOSSimulator: |
| 373 | return "tvossim"; |
| 374 | case DarwinPlatformKind::WatchOS: |
| 375 | return "watchos"; |
| 376 | case DarwinPlatformKind::WatchOSSimulator: |
| 377 | return "watchossim"; |
| 378 | } |
| 379 | llvm_unreachable("Unsupported platform"); |
| 380 | } |
| 381 | |
| Justin Bogner | 2fd95f6 | 2015-05-12 06:30:48 +0000 | [diff] [blame] | 382 | void Darwin::addProfileRTLibs(const ArgList &Args, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 383 | ArgStringList &CmdArgs) const { |
| Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 384 | if (!needsProfileRT(Args)) return; |
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 385 | |
| Chris Bieneman | 7f2844f | 2016-03-15 18:08:20 +0000 | [diff] [blame] | 386 | AddLinkRuntimeLib(Args, CmdArgs, (Twine("libclang_rt.profile_") + |
| 387 | getOSLibraryNameSuffix() + ".a").str(), |
| Chris Bieneman | 586d24b | 2015-11-20 00:19:21 +0000 | [diff] [blame] | 388 | /*AlwaysLink*/ true); |
| Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 391 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, |
| 392 | ArgStringList &CmdArgs, |
| 393 | StringRef Sanitizer) const { |
| 394 | if (!Args.hasArg(options::OPT_dynamiclib) && |
| 395 | !Args.hasArg(options::OPT_bundle)) { |
| 396 | // Sanitizer runtime libraries requires C++. |
| 397 | AddCXXStdlibLibArgs(Args, CmdArgs); |
| 398 | } |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 399 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 400 | AddLinkRuntimeLib( |
| 401 | Args, CmdArgs, |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 402 | (Twine("libclang_rt.") + Sanitizer + "_" + |
| 403 | getOSLibraryNameSuffix() + "_dynamic.dylib").str(), |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 404 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, |
| 405 | /*AddRPath*/ true); |
| Hans Wennborg | 10821e5 | 2015-04-09 18:47:01 +0000 | [diff] [blame] | 406 | |
| 407 | if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { |
| 408 | // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export |
| 409 | // all RTTI-related symbols that UBSan uses. |
| 410 | CmdArgs.push_back("-lc++abi"); |
| 411 | } |
| Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 414 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 415 | ArgStringList &CmdArgs) const { |
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 416 | // Darwin only supports the compiler-rt based runtime libraries. |
| 417 | switch (GetRuntimeLibType(Args)) { |
| 418 | case ToolChain::RLT_CompilerRT: |
| 419 | break; |
| 420 | default: |
| 421 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 422 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; |
| Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 423 | return; |
| 424 | } |
| 425 | |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 426 | // Darwin doesn't support real static executables, don't link any runtime |
| 427 | // libraries with -static. |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 428 | if (Args.hasArg(options::OPT_static) || |
| 429 | Args.hasArg(options::OPT_fapple_kext) || |
| 430 | Args.hasArg(options::OPT_mkernel)) |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 431 | return; |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 432 | |
| 433 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 434 | // cares. This is useful in situations where someone wants to statically link |
| 435 | // something like libstdc++, and needs its runtime support routines. |
| 436 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 437 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 438 | return; |
| 439 | } |
| 440 | |
| Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 441 | const SanitizerArgs &Sanitize = getSanitizerArgs(); |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 442 | if (Sanitize.needsAsanRt()) |
| 443 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); |
| 444 | if (Sanitize.needsUbsanRt()) |
| 445 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); |
| Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 446 | if (Sanitize.needsTsanRt()) |
| 447 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); |
| Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 448 | if (Sanitize.needsStatsRt()) { |
| 449 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; |
| 450 | AddLinkRuntimeLib(Args, CmdArgs, |
| 451 | (Twine("libclang_rt.stats_client_") + OS + ".a").str(), |
| 452 | /*AlwaysLink=*/true); |
| 453 | AddLinkSanitizerLibArgs(Args, CmdArgs, "stats"); |
| 454 | } |
| Derek Bruening | 256c2e1 | 2016-04-21 21:32:04 +0000 | [diff] [blame] | 455 | if (Sanitize.needsEsanRt()) |
| 456 | AddLinkSanitizerLibArgs(Args, CmdArgs, "esan"); |
| Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 457 | |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 458 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 459 | // target specific static runtime library. |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 460 | CmdArgs.push_back("-lSystem"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 461 | |
| 462 | // Select the dynamic runtime library and the target specific static library. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 463 | if (isTargetWatchOSBased()) { |
| 464 | // We currently always need a static runtime library for watchOS. |
| 465 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); |
| 466 | } else if (isTargetTvOSBased()) { |
| 467 | // We currently always need a static runtime library for tvOS. |
| 468 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); |
| 469 | } else if (isTargetIOSBased()) { |
| Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 470 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, |
| 471 | // it never went into the SDK. |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 472 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 473 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && |
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 474 | getTriple().getArch() != llvm::Triple::aarch64) |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 475 | CmdArgs.push_back("-lgcc_s.1"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 476 | |
| Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 477 | // We currently always need a static runtime library for iOS. |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 478 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 479 | } else { |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 480 | assert(isTargetMacOS() && "unexpected non MacOS platform"); |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 481 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 482 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 483 | if (isMacosxVersionLT(10, 5)) |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 484 | CmdArgs.push_back("-lgcc_s.10.4"); |
| Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 485 | else if (isMacosxVersionLT(10, 6)) |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 486 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 487 | |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 488 | // For OS X, we thought we would only need a static runtime library when |
| Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 489 | // targeting 10.4, to provide versions of the static functions which were |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 490 | // omitted from 10.4.dylib. |
| 491 | // |
| 492 | // Unfortunately, that turned out to not be true, because Darwin system |
| 493 | // headers can still use eprintf on i386, and it is not exported from |
| 494 | // libSystem. Therefore, we still must provide a runtime library just for |
| 495 | // the tiny tiny handful of projects that *might* use that symbol. |
| 496 | if (isMacosxVersionLT(10, 5)) { |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 497 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 498 | } else { |
| 499 | if (getTriple().getArch() == llvm::Triple::x86) |
| Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 500 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); |
| 501 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); |
| Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 502 | } |
| Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 503 | } |
| Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 506 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 507 | const OptTable &Opts = getDriver().getOpts(); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 508 | |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 509 | // Support allowing the SDKROOT environment variable used by xcrun and other |
| 510 | // Xcode tools to define the default sysroot, by making it the default for |
| 511 | // isysroot. |
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 512 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 513 | // Warn if the path does not exist. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 514 | if (!getVFS().exists(A->getValue())) |
| Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 515 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); |
| 516 | } else { |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 517 | if (char *env = ::getenv("SDKROOT")) { |
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 518 | // We only use this value as the default if it is an absolute path, |
| 519 | // exists, and it is not the root path. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 520 | if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) && |
| Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 521 | StringRef(env) != "/") { |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 522 | Args.append(Args.MakeSeparateArg( |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 523 | nullptr, Opts.getOption(options::OPT_isysroot), env)); |
| Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 528 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 529 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 530 | Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ); |
| 531 | Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ); |
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 532 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 533 | if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 534 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 535 | << OSXVersion->getAsString(Args) |
| 536 | << (iOSVersion ? iOSVersion : |
| 537 | TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 538 | iOSVersion = TvOSVersion = WatchOSVersion = nullptr; |
| 539 | } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) { |
| 540 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 541 | << iOSVersion->getAsString(Args) |
| 542 | << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 543 | TvOSVersion = WatchOSVersion = nullptr; |
| 544 | } else if (TvOSVersion && WatchOSVersion) { |
| 545 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 546 | << TvOSVersion->getAsString(Args) |
| 547 | << WatchOSVersion->getAsString(Args); |
| 548 | WatchOSVersion = nullptr; |
| 549 | } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) { |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 550 | // If no deployment target was specified on the command line, check for |
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 551 | // environment defines. |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 552 | std::string OSXTarget; |
| 553 | std::string iOSTarget; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 554 | std::string TvOSTarget; |
| 555 | std::string WatchOSTarget; |
| 556 | |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 557 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) |
| 558 | OSXTarget = env; |
| 559 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) |
| 560 | iOSTarget = env; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 561 | if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET")) |
| 562 | TvOSTarget = env; |
| 563 | if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET")) |
| 564 | WatchOSTarget = env; |
| Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 565 | |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 566 | // If there is no command-line argument to specify the Target version and |
| 567 | // no environment variable defined, see if we can set the default based |
| 568 | // on -isysroot. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 569 | if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() && |
| Frederic Riss | 3ad83bd | 2016-01-12 23:47:59 +0000 | [diff] [blame] | 570 | TvOSTarget.empty() && Args.hasArg(options::OPT_isysroot)) { |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 571 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 572 | StringRef isysroot = A->getValue(); |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 573 | StringRef SDK = getSDKName(isysroot); |
| 574 | if (SDK.size() > 0) { |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 575 | // Slice the version number out. |
| 576 | // Version number is between the first and the last number. |
| 577 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 578 | size_t EndVer = SDK.find_last_of("0123456789"); |
| 579 | if (StartVer != StringRef::npos && EndVer > StartVer) { |
| 580 | StringRef Version = SDK.slice(StartVer, EndVer + 1); |
| 581 | if (SDK.startswith("iPhoneOS") || |
| 582 | SDK.startswith("iPhoneSimulator")) |
| 583 | iOSTarget = Version; |
| 584 | else if (SDK.startswith("MacOSX")) |
| 585 | OSXTarget = Version; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 586 | else if (SDK.startswith("WatchOS") || |
| 587 | SDK.startswith("WatchSimulator")) |
| 588 | WatchOSTarget = Version; |
| 589 | else if (SDK.startswith("AppleTVOS") || |
| 590 | SDK.startswith("AppleTVSimulator")) |
| 591 | TvOSTarget = Version; |
| Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 592 | } |
| 593 | } |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 594 | } |
| 595 | } |
| Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 596 | |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 597 | // If no OSX or iOS target has been specified, try to guess platform |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 598 | // from arch name and compute the version from the triple. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 599 | if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() && |
| 600 | WatchOSTarget.empty()) { |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 601 | StringRef MachOArchName = getMachOArchName(Args); |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 602 | unsigned Major, Minor, Micro; |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 603 | if (MachOArchName == "armv7" || MachOArchName == "armv7s" || |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 604 | MachOArchName == "arm64") { |
| 605 | getTriple().getiOSVersion(Major, Minor, Micro); |
| 606 | llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' |
| 607 | << Micro; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 608 | } else if (MachOArchName == "armv7k") { |
| 609 | getTriple().getWatchOSVersion(Major, Minor, Micro); |
| 610 | llvm::raw_string_ostream(WatchOSTarget) << Major << '.' << Minor << '.' |
| 611 | << Micro; |
| Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 612 | } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && |
| 613 | MachOArchName != "armv7em") { |
| 614 | if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { |
| 615 | getDriver().Diag(diag::err_drv_invalid_darwin_version) |
| 616 | << getTriple().getOSName(); |
| 617 | } |
| 618 | llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' |
| 619 | << Micro; |
| 620 | } |
| Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 621 | } |
| Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 622 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 623 | // Do not allow conflicts with the watchOS target. |
| 624 | if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) { |
| 625 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 626 | << "WATCHOS_DEPLOYMENT_TARGET" |
| 627 | << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" : |
| 628 | "TVOS_DEPLOYMENT_TARGET"); |
| 629 | } |
| 630 | |
| 631 | // Do not allow conflicts with the tvOS target. |
| 632 | if (!TvOSTarget.empty() && !iOSTarget.empty()) { |
| 633 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 634 | << "TVOS_DEPLOYMENT_TARGET" |
| 635 | << "IPHONEOS_DEPLOYMENT_TARGET"; |
| 636 | } |
| 637 | |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 638 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 639 | // default platform. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 640 | if (!OSXTarget.empty() && (!iOSTarget.empty() || |
| 641 | !WatchOSTarget.empty() || |
| 642 | !TvOSTarget.empty())) { |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 643 | if (getTriple().getArch() == llvm::Triple::arm || |
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 644 | getTriple().getArch() == llvm::Triple::aarch64 || |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 645 | getTriple().getArch() == llvm::Triple::thumb) |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 646 | OSXTarget = ""; |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 647 | else |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 648 | iOSTarget = WatchOSTarget = TvOSTarget = ""; |
| Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 649 | } |
| Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 650 | |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 651 | if (!OSXTarget.empty()) { |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 652 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 653 | OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 654 | Args.append(OSXVersion); |
| Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 655 | } else if (!iOSTarget.empty()) { |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 656 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 657 | iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 658 | Args.append(iOSVersion); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 659 | } else if (!TvOSTarget.empty()) { |
| 660 | const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ); |
| 661 | TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget); |
| 662 | Args.append(TvOSVersion); |
| 663 | } else if (!WatchOSTarget.empty()) { |
| 664 | const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ); |
| 665 | WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget); |
| 666 | Args.append(WatchOSVersion); |
| Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 667 | } |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 668 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 670 | DarwinPlatformKind Platform; |
| 671 | if (OSXVersion) |
| 672 | Platform = MacOS; |
| 673 | else if (iOSVersion) |
| 674 | Platform = IPhoneOS; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 675 | else if (TvOSVersion) |
| 676 | Platform = TvOS; |
| 677 | else if (WatchOSVersion) |
| 678 | Platform = WatchOS; |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 679 | else |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 680 | llvm_unreachable("Unable to infer Darwin variant"); |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 681 | |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 682 | // Set the tool chain target information. |
| 683 | unsigned Major, Minor, Micro; |
| 684 | bool HadExtra; |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 685 | if (Platform == MacOS) { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 686 | assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && |
| 687 | "Unknown target platform!"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 688 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, |
| 689 | HadExtra) || |
| 690 | HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 691 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 692 | << OSXVersion->getAsString(Args); |
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 693 | } else if (Platform == IPhoneOS) { |
| 694 | assert(iOSVersion && "Unknown target platform!"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 695 | if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, |
| 696 | HadExtra) || |
| 697 | HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100) |
| Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 698 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 699 | << iOSVersion->getAsString(Args); |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 700 | } else if (Platform == TvOS) { |
| 701 | if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, |
| 702 | Micro, HadExtra) || HadExtra || |
| 703 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 704 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 705 | << TvOSVersion->getAsString(Args); |
| 706 | } else if (Platform == WatchOS) { |
| 707 | if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor, |
| 708 | Micro, HadExtra) || HadExtra || |
| 709 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 710 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 711 | << WatchOSVersion->getAsString(Args); |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 712 | } else |
| 713 | llvm_unreachable("unknown kind of Darwin platform"); |
| Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 714 | |
| Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 715 | // Recognize iOS targets with an x86 architecture as the iOS simulator. |
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 716 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 717 | getTriple().getArch() == llvm::Triple::x86_64)) |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 718 | Platform = IPhoneOSSimulator; |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 719 | if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 720 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 721 | Platform = TvOSSimulator; |
| 722 | if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 723 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 724 | Platform = WatchOSSimulator; |
| Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 725 | |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 726 | setTarget(Platform, Major, Minor, Micro); |
| Chris Bieneman | e60e7c2 | 2016-04-29 22:28:34 +0000 | [diff] [blame] | 727 | |
| 728 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 729 | StringRef SDK = getSDKName(A->getValue()); |
| 730 | if (SDK.size() > 0) { |
| 731 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 732 | StringRef SDKName = SDK.slice(0, StartVer); |
| 733 | if (!SDKName.startswith(getPlatformFamily())) |
| 734 | getDriver().Diag(diag::warn_incompatible_sysroot) |
| 735 | << SDKName << getPlatformFamily(); |
| 736 | } |
| 737 | } |
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 740 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 741 | ArgStringList &CmdArgs) const { |
| 742 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 743 | |
| 744 | switch (Type) { |
| 745 | case ToolChain::CST_Libcxx: |
| 746 | CmdArgs.push_back("-lc++"); |
| 747 | break; |
| 748 | |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 749 | case ToolChain::CST_Libstdcxx: |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 750 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 751 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 752 | // platforms we care about it was -lstdc++.6, so we search for that |
| 753 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 754 | |
| 755 | // Check in the sysroot first. |
| 756 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 757 | SmallString<128> P(A->getValue()); |
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 758 | llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 759 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 760 | if (!getVFS().exists(P)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 761 | llvm::sys::path::remove_filename(P); |
| 762 | llvm::sys::path::append(P, "libstdc++.6.dylib"); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 763 | if (getVFS().exists(P)) { |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 764 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 765 | return; |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | // Otherwise, look in the root. |
| Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 771 | // FIXME: This should be removed someday when we don't have to care about |
| 772 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 773 | if (!getVFS().exists("/usr/lib/libstdc++.dylib") && |
| 774 | getVFS().exists("/usr/lib/libstdc++.6.dylib")) { |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 775 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 776 | return; |
| 777 | } |
| 778 | |
| 779 | // Otherwise, let the linker search. |
| 780 | CmdArgs.push_back("-lstdc++"); |
| 781 | break; |
| 782 | } |
| Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 785 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 786 | ArgStringList &CmdArgs) const { |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 787 | // For Darwin platforms, use the compiler-rt-based support library |
| 788 | // instead of the gcc-provided one (which is also incidentally |
| 789 | // only present in the gcc lib dir, which makes it hard to find). |
| 790 | |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 791 | SmallString<128> P(getDriver().ResourceDir); |
| Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 792 | llvm::sys::path::append(P, "lib", "darwin"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 793 | |
| 794 | // Use the newer cc_kext for iOS ARM after 6.0. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 795 | if (isTargetWatchOS()) { |
| 796 | llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a"); |
| 797 | } else if (isTargetTvOS()) { |
| 798 | llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a"); |
| 799 | } else if (isTargetIPhoneOS()) { |
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 800 | llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 801 | } else { |
| Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 802 | llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 803 | } |
| NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 804 | |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 805 | // For now, allow missing resource libraries to support developers who may |
| 806 | // not have compiler-rt checked out or integrated into their build. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 807 | if (getVFS().exists(P)) |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 808 | CmdArgs.push_back(Args.MakeArgString(P)); |
| Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 811 | DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, |
| 812 | const char *BoundArch) const { |
| Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 813 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 814 | const OptTable &Opts = getDriver().getOpts(); |
| 815 | |
| 816 | // FIXME: We really want to get out of the tool chain level argument |
| 817 | // translation business, as it makes the driver functionality much |
| 818 | // more opaque. For now, we follow gcc closely solely for the |
| 819 | // purpose of easily achieving feature parity & testability. Once we |
| 820 | // have something that works, we should reevaluate each translation |
| 821 | // and try to push it down into tool specific logic. |
| Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 822 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 823 | for (Arg *A : Args) { |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 824 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 825 | // Skip this argument unless the architecture matches either the toolchain |
| 826 | // triple arch, or the arch being bound. |
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 827 | llvm::Triple::ArchType XarchArch = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 828 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); |
| 829 | if (!(XarchArch == getArch() || |
| 830 | (BoundArch && |
| 831 | XarchArch == |
| 832 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 833 | continue; |
| 834 | |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 835 | Arg *OriginalArg = A; |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 836 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 837 | unsigned Prev = Index; |
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 838 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 840 | // If the argument parsing failed or more than one argument was |
| 841 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 842 | // extra arguments. Emit an error and ignore. |
| 843 | // |
| 844 | // We also want to disallow any options which would alter the |
| 845 | // driver behavior; that isn't going to work in our model. We |
| 846 | // use isDriverOption() as an approximation, although things |
| 847 | // like -O4 are going to slip through. |
| Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 848 | if (!XarchArg || Index > Prev + 1) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 849 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 850 | << A->getAsString(Args); |
| Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 851 | continue; |
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 852 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 853 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 854 | << A->getAsString(Args); |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 855 | continue; |
| 856 | } |
| 857 | |
| Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 858 | XarchArg->setBaseArg(A); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 859 | |
| Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 860 | A = XarchArg.release(); |
| Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 861 | DAL->AddSynthesizedArg(A); |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 862 | |
| 863 | // Linker input arguments require custom handling. The problem is that we |
| 864 | // have already constructed the phase actions, so we can not treat them as |
| 865 | // "input arguments". |
| Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 866 | if (A->getOption().hasFlag(options::LinkerInput)) { |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 867 | // Convert the argument into individual Zlinker_input_args. |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 868 | for (const char *Value : A->getValues()) { |
| 869 | DAL->AddSeparateArg( |
| 870 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); |
| Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 871 | } |
| 872 | continue; |
| 873 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 874 | } |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 875 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 876 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 877 | // gcc translates options twice, which means that self-expanding |
| 878 | // options add duplicates. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 879 | switch ((options::ID)A->getOption().getID()) { |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 880 | default: |
| 881 | DAL->append(A); |
| 882 | break; |
| 883 | |
| 884 | case options::OPT_mkernel: |
| 885 | case options::OPT_fapple_kext: |
| 886 | DAL->append(A); |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 887 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 888 | break; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 889 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 890 | case options::OPT_dependency_file: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 891 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 892 | break; |
| 893 | |
| 894 | case options::OPT_gfull: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 895 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 896 | DAL->AddFlagArg( |
| 897 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 898 | break; |
| 899 | |
| 900 | case options::OPT_gused: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 901 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 902 | DAL->AddFlagArg( |
| 903 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 904 | break; |
| 905 | |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 906 | case options::OPT_shared: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 907 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 908 | break; |
| 909 | |
| 910 | case options::OPT_fconstant_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 911 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case options::OPT_fno_constant_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 915 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case options::OPT_Wnonportable_cfstrings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 919 | DAL->AddFlagArg(A, |
| 920 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 921 | break; |
| 922 | |
| 923 | case options::OPT_Wno_nonportable_cfstrings: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 924 | DAL->AddFlagArg( |
| 925 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case options::OPT_fpascal_strings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 929 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 930 | break; |
| 931 | |
| 932 | case options::OPT_fno_pascal_strings: |
| Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 933 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 934 | break; |
| 935 | } |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 936 | } |
| 937 | |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 938 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 939 | getTriple().getArch() == llvm::Triple::x86_64) |
| Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 940 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 941 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), |
| 942 | "core2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 943 | |
| 944 | // Add the arch options based on the particular spelling of -arch, to match |
| Chad Rosier | 7c5d908 | 2012-04-27 14:58:16 +0000 | [diff] [blame] | 945 | // how the driver driver works. |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 946 | if (BoundArch) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 947 | StringRef Name = BoundArch; |
| Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 948 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 949 | const Option MArch = Opts.getOption(options::OPT_march_EQ); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 950 | |
| 951 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 952 | // which defines the list of which architectures we accept. |
| 953 | if (Name == "ppc") |
| 954 | ; |
| 955 | else if (Name == "ppc601") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 956 | DAL->AddJoinedArg(nullptr, MCpu, "601"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 957 | else if (Name == "ppc603") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 958 | DAL->AddJoinedArg(nullptr, MCpu, "603"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 959 | else if (Name == "ppc604") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 960 | DAL->AddJoinedArg(nullptr, MCpu, "604"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 961 | else if (Name == "ppc604e") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 962 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 963 | else if (Name == "ppc750") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 964 | DAL->AddJoinedArg(nullptr, MCpu, "750"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 965 | else if (Name == "ppc7400") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 966 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 967 | else if (Name == "ppc7450") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 968 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 969 | else if (Name == "ppc970") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 970 | DAL->AddJoinedArg(nullptr, MCpu, "970"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 971 | |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 972 | else if (Name == "ppc64" || Name == "ppc64le") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 973 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 974 | |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 975 | else if (Name == "i386") |
| 976 | ; |
| 977 | else if (Name == "i486") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 978 | DAL->AddJoinedArg(nullptr, MArch, "i486"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 979 | else if (Name == "i586") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 980 | DAL->AddJoinedArg(nullptr, MArch, "i586"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 981 | else if (Name == "i686") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 982 | DAL->AddJoinedArg(nullptr, MArch, "i686"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 983 | else if (Name == "pentium") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 984 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 985 | else if (Name == "pentium2") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 986 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 987 | else if (Name == "pentpro") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 988 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 989 | else if (Name == "pentIIm3") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 990 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 991 | |
| 992 | else if (Name == "x86_64") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 993 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 994 | else if (Name == "x86_64h") { |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 995 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| 996 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); |
| Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 997 | } |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 998 | |
| 999 | else if (Name == "arm") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1000 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1001 | else if (Name == "armv4t") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1002 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1003 | else if (Name == "armv5") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1004 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1005 | else if (Name == "xscale") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1006 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1007 | else if (Name == "armv6") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1008 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1009 | else if (Name == "armv6m") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1010 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1011 | else if (Name == "armv7") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1012 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1013 | else if (Name == "armv7em") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1014 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); |
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1015 | else if (Name == "armv7k") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1016 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); |
| Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 1017 | else if (Name == "armv7m") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1018 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); |
| Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 1019 | else if (Name == "armv7s") |
| Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1020 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); |
| Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 1021 | } |
| Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 1022 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1023 | return DAL; |
| 1024 | } |
| 1025 | |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1026 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 1027 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1028 | // Embedded targets are simple at the moment, not supporting sanitizers and |
| 1029 | // with different libraries for each member of the product { static, PIC } x |
| 1030 | // { hard-float, soft-float } |
| 1031 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); |
| Saleem Abdulrasool | 06f6f99 | 2015-09-19 20:40:16 +0000 | [diff] [blame] | 1032 | CompilerRT += |
| 1033 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) |
| 1034 | ? "hard" |
| 1035 | : "soft"; |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1036 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; |
| 1037 | |
| 1038 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); |
| 1039 | } |
| 1040 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1041 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 1042 | const char *BoundArch) const { |
| 1043 | // First get the generic Apple args, before moving onto Darwin-specific ones. |
| 1044 | DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1045 | const OptTable &Opts = getDriver().getOpts(); |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1046 | |
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1047 | // If no architecture is bound, none of the translations here are relevant. |
| 1048 | if (!BoundArch) |
| 1049 | return DAL; |
| 1050 | |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1051 | // Add an explicit version min argument for the deployment target. We do this |
| 1052 | // after argument translation because -Xarch_ arguments may add a version min |
| 1053 | // argument. |
| Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 1054 | AddDeploymentTarget(*DAL); |
| Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 1055 | |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1056 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. |
| 1057 | // FIXME: It would be far better to avoid inserting those -static arguments, |
| 1058 | // but we can't check the deployment target in the translation code until |
| 1059 | // it is set here. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1060 | if (isTargetWatchOSBased() || |
| 1061 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { |
| 1062 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { |
| Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1063 | Arg *A = *it; |
| 1064 | ++it; |
| 1065 | if (A->getOption().getID() != options::OPT_mkernel && |
| 1066 | A->getOption().getID() != options::OPT_fapple_kext) |
| 1067 | continue; |
| 1068 | assert(it != ie && "unexpected argument translation"); |
| 1069 | A = *it; |
| 1070 | assert(A->getOption().getID() == options::OPT_static && |
| 1071 | "missing expected -static argument"); |
| 1072 | it = DAL->getArgs().erase(it); |
| 1073 | } |
| 1074 | } |
| 1075 | |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1076 | if (!Args.getLastArg(options::OPT_stdlib_EQ) && |
| Tim Northover | 3a098c1 | 2016-02-15 16:38:10 +0000 | [diff] [blame] | 1077 | GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) |
| Tim Northover | b534ce4 | 2016-02-12 22:30:42 +0000 | [diff] [blame] | 1078 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), |
| 1079 | "libc++"); |
| 1080 | |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1081 | // Validate the C++ standard library choice. |
| 1082 | CXXStdlibType Type = GetCXXStdlibType(*DAL); |
| 1083 | if (Type == ToolChain::CST_Libcxx) { |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1084 | // Check whether the target provides libc++. |
| 1085 | StringRef where; |
| 1086 | |
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1087 | // Complain about targeting iOS < 5.0 in any way. |
| Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1088 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) |
| Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1089 | where = "iOS 5.0"; |
| John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1090 | |
| 1091 | if (where != StringRef()) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1092 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; |
| Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | |
| Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1096 | return DAL; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1098 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1099 | bool MachO::IsUnwindTablesDefault() const { |
| Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1100 | return getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1103 | bool MachO::UseDwarfDebugFlags() const { |
| Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1104 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 1105 | return S[0] != '\0'; |
| 1106 | return false; |
| 1107 | } |
| 1108 | |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1109 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { |
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1110 | // Darwin uses SjLj exceptions on ARM. |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1111 | if (getTriple().getArch() != llvm::Triple::arm && |
| 1112 | getTriple().getArch() != llvm::Triple::thumb) |
| 1113 | return false; |
| 1114 | |
| Tim Northover | c741b04 | 2015-11-17 18:27:27 +0000 | [diff] [blame] | 1115 | // Only watchOS uses the new DWARF/Compact unwinding method. |
| Tim Northover | d88ecb3 | 2016-01-27 19:32:40 +0000 | [diff] [blame] | 1116 | llvm::Triple Triple(ComputeLLVMTriple(Args)); |
| Tim Northover | 4c9ac7d | 2016-01-27 22:14:02 +0000 | [diff] [blame] | 1117 | return !Triple.isWatchABI(); |
| Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| Steven Wu | 574b0f2 | 2016-03-01 01:07:58 +0000 | [diff] [blame] | 1120 | bool Darwin::SupportsEmbeddedBitcode() const { |
| 1121 | assert(TargetInitialized && "Target not initialized!"); |
| 1122 | if (isTargetIPhoneOS() && isIPhoneOSVersionLT(6, 0)) |
| 1123 | return false; |
| 1124 | return true; |
| 1125 | } |
| 1126 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1127 | bool MachO::isPICDefault() const { return true; } |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1128 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1129 | bool MachO::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1130 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1131 | bool MachO::isPICDefaultForced() const { |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1132 | return (getArch() == llvm::Triple::x86_64 || |
| Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1133 | getArch() == llvm::Triple::aarch64); |
| Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1136 | bool MachO::SupportsProfiling() const { |
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1137 | // Profiling instrumentation is only supported on x86. |
| Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1138 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1141 | void Darwin::addMinVersionArgs(const ArgList &Args, |
| 1142 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1143 | VersionTuple TargetVersion = getTargetVersion(); |
| 1144 | |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1145 | if (isTargetWatchOS()) |
| 1146 | CmdArgs.push_back("-watchos_version_min"); |
| 1147 | else if (isTargetWatchOSSimulator()) |
| 1148 | CmdArgs.push_back("-watchos_simulator_version_min"); |
| 1149 | else if (isTargetTvOS()) |
| 1150 | CmdArgs.push_back("-tvos_version_min"); |
| 1151 | else if (isTargetTvOSSimulator()) |
| 1152 | CmdArgs.push_back("-tvos_simulator_version_min"); |
| 1153 | else if (isTargetIOSSimulator()) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1154 | CmdArgs.push_back("-ios_simulator_version_min"); |
| Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1155 | else if (isTargetIOSBased()) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1156 | CmdArgs.push_back("-iphoneos_version_min"); |
| 1157 | else { |
| 1158 | assert(isTargetMacOS() && "unexpected target"); |
| 1159 | CmdArgs.push_back("-macosx_version_min"); |
| 1160 | } |
| 1161 | |
| 1162 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); |
| 1163 | } |
| 1164 | |
| Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1165 | void Darwin::addStartObjectFileArgs(const ArgList &Args, |
| 1166 | ArgStringList &CmdArgs) const { |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1167 | // Derived from startfile spec. |
| 1168 | if (Args.hasArg(options::OPT_dynamiclib)) { |
| 1169 | // Derived from darwin_dylib1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1170 | if (isTargetWatchOSBased()) { |
| 1171 | ; // watchOS does not need dylib1.o. |
| 1172 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1173 | ; // iOS simulator does not need dylib1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1174 | } else if (isTargetIPhoneOS()) { |
| 1175 | if (isIPhoneOSVersionLT(3, 1)) |
| 1176 | CmdArgs.push_back("-ldylib1.o"); |
| 1177 | } else { |
| 1178 | if (isMacosxVersionLT(10, 5)) |
| 1179 | CmdArgs.push_back("-ldylib1.o"); |
| 1180 | else if (isMacosxVersionLT(10, 6)) |
| 1181 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1182 | } |
| 1183 | } else { |
| 1184 | if (Args.hasArg(options::OPT_bundle)) { |
| 1185 | if (!Args.hasArg(options::OPT_static)) { |
| 1186 | // Derived from darwin_bundle1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1187 | if (isTargetWatchOSBased()) { |
| 1188 | ; // watchOS does not need bundle1.o. |
| 1189 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1190 | ; // iOS simulator does not need bundle1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1191 | } else if (isTargetIPhoneOS()) { |
| 1192 | if (isIPhoneOSVersionLT(3, 1)) |
| 1193 | CmdArgs.push_back("-lbundle1.o"); |
| 1194 | } else { |
| 1195 | if (isMacosxVersionLT(10, 6)) |
| 1196 | CmdArgs.push_back("-lbundle1.o"); |
| 1197 | } |
| 1198 | } |
| 1199 | } else { |
| 1200 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { |
| 1201 | if (Args.hasArg(options::OPT_static) || |
| 1202 | Args.hasArg(options::OPT_object) || |
| 1203 | Args.hasArg(options::OPT_preload)) { |
| 1204 | CmdArgs.push_back("-lgcrt0.o"); |
| 1205 | } else { |
| 1206 | CmdArgs.push_back("-lgcrt1.o"); |
| 1207 | |
| 1208 | // darwin_crt2 spec is empty. |
| 1209 | } |
| 1210 | // By default on OS X 10.8 and later, we don't link with a crt1.o |
| 1211 | // file and the linker knows to use _main as the entry point. But, |
| 1212 | // when compiling with -pg, we need to link with the gcrt1.o file, |
| 1213 | // so pass the -no_new_main option to tell the linker to use the |
| 1214 | // "start" symbol as the entry point. |
| 1215 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) |
| 1216 | CmdArgs.push_back("-no_new_main"); |
| 1217 | } else { |
| 1218 | if (Args.hasArg(options::OPT_static) || |
| 1219 | Args.hasArg(options::OPT_object) || |
| 1220 | Args.hasArg(options::OPT_preload)) { |
| 1221 | CmdArgs.push_back("-lcrt0.o"); |
| 1222 | } else { |
| 1223 | // Derived from darwin_crt1 spec. |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1224 | if (isTargetWatchOSBased()) { |
| 1225 | ; // watchOS does not need crt1.o. |
| 1226 | } else if (isTargetIOSSimulator()) { |
| Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1227 | ; // iOS simulator does not need crt1.o. |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1228 | } else if (isTargetIPhoneOS()) { |
| Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1229 | if (getArch() == llvm::Triple::aarch64) |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1230 | ; // iOS does not need any crt1 files for arm64 |
| 1231 | else if (isIPhoneOSVersionLT(3, 1)) |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1232 | CmdArgs.push_back("-lcrt1.o"); |
| 1233 | else if (isIPhoneOSVersionLT(6, 0)) |
| 1234 | CmdArgs.push_back("-lcrt1.3.1.o"); |
| 1235 | } else { |
| 1236 | if (isMacosxVersionLT(10, 5)) |
| 1237 | CmdArgs.push_back("-lcrt1.o"); |
| 1238 | else if (isMacosxVersionLT(10, 6)) |
| 1239 | CmdArgs.push_back("-lcrt1.10.5.o"); |
| 1240 | else if (isMacosxVersionLT(10, 8)) |
| 1241 | CmdArgs.push_back("-lcrt1.10.6.o"); |
| 1242 | |
| 1243 | // darwin_crt2 spec is empty. |
| 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1251 | !isTargetWatchOS() && |
| Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1252 | isMacosxVersionLT(10, 5)) { |
| 1253 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); |
| 1254 | CmdArgs.push_back(Str); |
| 1255 | } |
| 1256 | } |
| 1257 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1258 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } |
| Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1259 | |
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1260 | void Darwin::CheckObjCARC() const { |
| Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1261 | if (isTargetIOSBased() || isTargetWatchOSBased() || |
| 1262 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) |
| John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1263 | return; |
| John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1264 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); |
| Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1267 | SanitizerMask Darwin::getSupportedSanitizers() const { |
| Devin Coughlin | fcfa38c | 2016-03-20 18:24:33 +0000 | [diff] [blame] | 1268 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1269 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| Anna Zaks | e67b402 | 2016-02-02 02:04:48 +0000 | [diff] [blame] | 1270 | Res |= SanitizerKind::Address; |
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1271 | if (isTargetMacOS()) { |
| 1272 | if (!isMacosxVersionLT(10, 9)) |
| 1273 | Res |= SanitizerKind::Vptr; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1274 | Res |= SanitizerKind::SafeStack; |
| Devin Coughlin | fcfa38c | 2016-03-20 18:24:33 +0000 | [diff] [blame] | 1275 | if (IsX86_64) |
| 1276 | Res |= SanitizerKind::Thread; |
| 1277 | } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) { |
| 1278 | if (IsX86_64) |
| 1279 | Res |= SanitizerKind::Thread; |
| Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1280 | } |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1281 | return Res; |
| 1282 | } |
| 1283 | |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1284 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 1285 | /// all subcommands; this relies on gcc translating the majority of |
| 1286 | /// command line options. |
| 1287 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1288 | /// \brief Parse a GCCVersion object out of a string of text. |
| 1289 | /// |
| 1290 | /// This is the primary means of forming GCCVersion objects. |
| 1291 | /*static*/ |
| 1292 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1293 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1294 | std::pair<StringRef, StringRef> First = VersionText.split('.'); |
| 1295 | std::pair<StringRef, StringRef> Second = First.second.split('.'); |
| 1296 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1297 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| 1298 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1299 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1300 | GoodVersion.MajorStr = First.first.str(); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1301 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1302 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1303 | GoodVersion.MinorStr = Second.first.str(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1304 | |
| 1305 | // First look for a number prefix and parse that if present. Otherwise just |
| 1306 | // stash the entire patch string in the suffix, and leave the number |
| 1307 | // unspecified. This covers versions strings such as: |
| 1308 | // 4.4 |
| 1309 | // 4.4.0 |
| 1310 | // 4.4.x |
| 1311 | // 4.4.2-rc4 |
| 1312 | // 4.4.x-patched |
| 1313 | // And retains any patch number it finds. |
| 1314 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); |
| 1315 | if (!PatchText.empty()) { |
| Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1316 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1317 | // Try to parse the number and any suffix. |
| 1318 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || |
| 1319 | GoodVersion.Patch < 0) |
| 1320 | return BadVersion; |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1321 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | return GoodVersion; |
| 1326 | } |
| 1327 | |
| 1328 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1329 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, |
| 1330 | int RHSPatch, |
| 1331 | StringRef RHSPatchSuffix) const { |
| 1332 | if (Major != RHSMajor) |
| 1333 | return Major < RHSMajor; |
| 1334 | if (Minor != RHSMinor) |
| 1335 | return Minor < RHSMinor; |
| 1336 | if (Patch != RHSPatch) { |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1337 | // Note that versions without a specified patch sort higher than those with |
| 1338 | // a patch. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1339 | if (RHSPatch == -1) |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1340 | return true; |
| 1341 | if (Patch == -1) |
| 1342 | return false; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1343 | |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1344 | // Otherwise just sort on the patch itself. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1345 | return Patch < RHSPatch; |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1346 | } |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1347 | if (PatchSuffix != RHSPatchSuffix) { |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1348 | // Sort empty suffixes higher. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1349 | if (RHSPatchSuffix.empty()) |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1350 | return true; |
| 1351 | if (PatchSuffix.empty()) |
| Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1352 | return false; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1353 | |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1354 | // Provide a lexicographic sort to make this a total ordering. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1355 | return PatchSuffix < RHSPatchSuffix; |
| Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | // The versions are equal. |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1359 | return false; |
| 1360 | } |
| 1361 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1362 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1363 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); |
| 1364 | if (A) |
| Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1365 | return A->getValue(); |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1366 | return GCC_INSTALL_PREFIX; |
| 1367 | } |
| 1368 | |
| Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1369 | /// \brief Initialize a GCCInstallationDetector from the driver. |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1370 | /// |
| 1371 | /// This performs all of the autodetection and sets up the various paths. |
| Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1372 | /// Once constructed, a GCCInstallationDetector is essentially immutable. |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1373 | /// |
| 1374 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and |
| 1375 | /// should instead pull the target out of the driver. This is currently |
| 1376 | /// necessary because the driver doesn't store the final version of the target |
| 1377 | /// triple. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1378 | void Generic_GCC::GCCInstallationDetector::init( |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1379 | const llvm::Triple &TargetTriple, const ArgList &Args, |
| Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1380 | ArrayRef<std::string> ExtraTripleAliases) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1381 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() |
| 1382 | ? TargetTriple.get64BitArchVariant() |
| 1383 | : TargetTriple.get32BitArchVariant(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1384 | // The library directories which may contain GCC installations. |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1385 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1386 | // The compatible GCC triples for this particular architecture. |
| Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1387 | SmallVector<StringRef, 16> CandidateTripleAliases; |
| 1388 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1389 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, |
| 1390 | CandidateTripleAliases, CandidateBiarchLibDirs, |
| 1391 | CandidateBiarchTripleAliases); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1392 | |
| 1393 | // Compute the set of prefixes for our search. |
| 1394 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), |
| 1395 | D.PrefixDirs.end()); |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1396 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1397 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); |
| 1398 | if (GCCToolchainDir != "") { |
| 1399 | if (GCCToolchainDir.back() == '/') |
| 1400 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1401 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1402 | Prefixes.push_back(GCCToolchainDir); |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1403 | } else { |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1404 | // If we have a SysRoot, try that first. |
| 1405 | if (!D.SysRoot.empty()) { |
| 1406 | Prefixes.push_back(D.SysRoot); |
| 1407 | Prefixes.push_back(D.SysRoot + "/usr"); |
| 1408 | } |
| 1409 | |
| 1410 | // Then look for gcc installed alongside clang. |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1411 | Prefixes.push_back(D.InstalledDir + "/.."); |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1412 | |
| Rafael Espindola | 2edca41 | 2016-05-09 13:03:10 +0000 | [diff] [blame] | 1413 | // Then look for distribution supplied gcc installations. |
| 1414 | if (D.SysRoot.empty()) { |
| 1415 | // Look for RHEL devtoolsets. |
| 1416 | Prefixes.push_back("/opt/rh/devtoolset-4/root/usr"); |
| 1417 | Prefixes.push_back("/opt/rh/devtoolset-3/root/usr"); |
| 1418 | Prefixes.push_back("/opt/rh/devtoolset-2/root/usr"); |
| 1419 | Prefixes.push_back("/opt/rh/devtoolset-1.1/root/usr"); |
| 1420 | Prefixes.push_back("/opt/rh/devtoolset-1.0/root/usr"); |
| 1421 | // And finally in /usr. |
| Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1422 | Prefixes.push_back("/usr"); |
| Rafael Espindola | 2edca41 | 2016-05-09 13:03:10 +0000 | [diff] [blame] | 1423 | } |
| Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1424 | } |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1425 | |
| 1426 | // Loop over the various components which exist and select the best GCC |
| 1427 | // installation available. GCC installs are ranked by version number. |
| 1428 | Version = GCCVersion::Parse("0.0.0"); |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1429 | for (const std::string &Prefix : Prefixes) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1430 | if (!D.getVFS().exists(Prefix)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1431 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1432 | for (StringRef Suffix : CandidateLibDirs) { |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1433 | const std::string LibDir = Prefix + Suffix.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1434 | if (!D.getVFS().exists(LibDir)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1435 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1436 | for (StringRef Candidate : ExtraTripleAliases) // Try these first. |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1437 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1438 | for (StringRef Candidate : CandidateTripleAliases) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1439 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1440 | } |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1441 | for (StringRef Suffix : CandidateBiarchLibDirs) { |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1442 | const std::string LibDir = Prefix + Suffix.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1443 | if (!D.getVFS().exists(LibDir)) |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1444 | continue; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1445 | for (StringRef Candidate : CandidateBiarchTripleAliases) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1446 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1447 | /*NeedsBiarchSuffix=*/ true); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1452 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1453 | for (const auto &InstallPath : CandidateGCCInstallPaths) |
| 1454 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1455 | |
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1456 | if (!GCCInstallPath.empty()) |
| 1457 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; |
| 1458 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1459 | for (const auto &Multilib : Multilibs) |
| 1460 | OS << "Candidate multilib: " << Multilib << "\n"; |
| Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1461 | |
| 1462 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) |
| 1463 | OS << "Selected multilib: " << SelectedMultilib << "\n"; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { |
| 1467 | if (BiarchSibling.hasValue()) { |
| 1468 | M = BiarchSibling.getValue(); |
| 1469 | return true; |
| 1470 | } |
| 1471 | return false; |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1474 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1475 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1476 | SmallVectorImpl<StringRef> &LibDirs, |
| 1477 | SmallVectorImpl<StringRef> &TripleAliases, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1478 | SmallVectorImpl<StringRef> &BiarchLibDirs, |
| 1479 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1480 | // Declare a bunch of static data sets that we'll select between below. These |
| 1481 | // are specifically designed to always refer to string literals to avoid any |
| 1482 | // lifetime or initialization issues. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1483 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; |
| 1484 | static const char *const AArch64Triples[] = { |
| 1485 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", |
| 1486 | "aarch64-redhat-linux"}; |
| 1487 | static const char *const AArch64beLibDirs[] = {"/lib"}; |
| 1488 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", |
| 1489 | "aarch64_be-linux-gnu"}; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1490 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1491 | static const char *const ARMLibDirs[] = {"/lib"}; |
| 1492 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", |
| 1493 | "arm-linux-androideabi"}; |
| 1494 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", |
| 1495 | "armv7hl-redhat-linux-gnueabi"}; |
| 1496 | static const char *const ARMebLibDirs[] = {"/lib"}; |
| 1497 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", |
| 1498 | "armeb-linux-androideabi"}; |
| 1499 | static const char *const ARMebHFTriples[] = { |
| 1500 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1501 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1502 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1503 | static const char *const X86_64Triples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1504 | "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", |
| 1505 | "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E", |
| 1506 | "x86_64-redhat-linux", "x86_64-suse-linux", |
| 1507 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", |
| 1508 | "x86_64-slackware-linux", "x86_64-linux-android", |
| 1509 | "x86_64-unknown-linux"}; |
| 1510 | static const char *const X32LibDirs[] = {"/libx32"}; |
| 1511 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1512 | static const char *const X86Triples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1513 | "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", |
| 1514 | "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux", |
| 1515 | "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux", |
| 1516 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", |
| 1517 | "i586-linux-gnu"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1518 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1519 | static const char *const MIPSLibDirs[] = {"/lib"}; |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1520 | static const char *const MIPSTriples[] = {"mips-linux-gnu", "mips-mti-linux", |
| 1521 | "mips-mti-linux-gnu", |
| 1522 | "mips-img-linux-gnu"}; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1523 | static const char *const MIPSELLibDirs[] = {"/lib"}; |
| 1524 | static const char *const MIPSELTriples[] = { |
| 1525 | "mipsel-linux-gnu", "mipsel-linux-android", "mips-img-linux-gnu"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1526 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1527 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; |
| 1528 | static const char *const MIPS64Triples[] = { |
| 1529 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1530 | "mips64-linux-gnuabi64"}; |
| 1531 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; |
| 1532 | static const char *const MIPS64ELTriples[] = { |
| 1533 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1534 | "mips64el-linux-android", "mips64el-linux-gnuabi64"}; |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1535 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1536 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1537 | static const char *const PPCTriples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1538 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", |
| 1539 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; |
| 1540 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; |
| 1541 | static const char *const PPC64Triples[] = { |
| 1542 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", |
| 1543 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; |
| 1544 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; |
| 1545 | static const char *const PPC64LETriples[] = { |
| 1546 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", |
| 1547 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1548 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1549 | static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; |
| 1550 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", |
| 1551 | "sparcv8-linux-gnu"}; |
| 1552 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; |
| 1553 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", |
| 1554 | "sparcv9-linux-gnu"}; |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1555 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1556 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1557 | static const char *const SystemZTriples[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1558 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", |
| 1559 | "s390x-suse-linux", "s390x-redhat-linux"}; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1560 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1561 | // Solaris. |
| 1562 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; |
| 1563 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", |
| 1564 | "i386-pc-solaris2.11"}; |
| 1565 | |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1566 | using std::begin; |
| 1567 | using std::end; |
| 1568 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1569 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 1570 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); |
| 1571 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1572 | return; |
| 1573 | } |
| 1574 | |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1575 | switch (TargetTriple.getArch()) { |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1576 | case llvm::Triple::aarch64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1577 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1578 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| 1579 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1580 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1581 | break; |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1582 | case llvm::Triple::aarch64_be: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1583 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1584 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| 1585 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1586 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1587 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1588 | case llvm::Triple::arm: |
| 1589 | case llvm::Triple::thumb: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1590 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1591 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1592 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1593 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1594 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1595 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1596 | break; |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1597 | case llvm::Triple::armeb: |
| 1598 | case llvm::Triple::thumbeb: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1599 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1600 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1601 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1602 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1603 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1604 | } |
| 1605 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1606 | case llvm::Triple::x86_64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1607 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1608 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| 1609 | // x32 is always available when x86_64 is available, so adding it as |
| 1610 | // secondary arch with x86_64 triples |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1611 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1612 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); |
| 1613 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1614 | } else { |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1615 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1616 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1617 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1618 | break; |
| 1619 | case llvm::Triple::x86: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1620 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1621 | TripleAliases.append(begin(X86Triples), end(X86Triples)); |
| 1622 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1623 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1624 | break; |
| 1625 | case llvm::Triple::mips: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1626 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1627 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1628 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1629 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1630 | break; |
| 1631 | case llvm::Triple::mipsel: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1632 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1633 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1634 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1635 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1636 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1637 | break; |
| 1638 | case llvm::Triple::mips64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1639 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1640 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| 1641 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1642 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1643 | break; |
| 1644 | case llvm::Triple::mips64el: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1645 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1646 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| 1647 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1648 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1649 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1650 | break; |
| 1651 | case llvm::Triple::ppc: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1652 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1653 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| 1654 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1655 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1656 | break; |
| 1657 | case llvm::Triple::ppc64: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1658 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1659 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| 1660 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1661 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1662 | break; |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1663 | case llvm::Triple::ppc64le: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1664 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); |
| 1665 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1666 | break; |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1667 | case llvm::Triple::sparc: |
| Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1668 | case llvm::Triple::sparcel: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1669 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1670 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| 1671 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1672 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1673 | break; |
| 1674 | case llvm::Triple::sparcv9: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1675 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1676 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| 1677 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1678 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1679 | break; |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1680 | case llvm::Triple::systemz: |
| Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1681 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); |
| 1682 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); |
| Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1683 | break; |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1684 | default: |
| 1685 | // By default, just rely on the standard lib directories and the original |
| 1686 | // triple. |
| 1687 | break; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1688 | } |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1689 | |
| 1690 | // Always append the drivers target triple to the end, in case it doesn't |
| 1691 | // match any of our aliases. |
| 1692 | TripleAliases.push_back(TargetTriple.str()); |
| 1693 | |
| 1694 | // Also include the multiarch variant if it's different. |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1695 | if (TargetTriple.str() != BiarchTriple.str()) |
| 1696 | BiarchTripleAliases.push_back(BiarchTriple.str()); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1699 | // \brief -- try common CUDA installation paths looking for files we need for |
| 1700 | // CUDA compilation. |
| 1701 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1702 | void Generic_GCC::CudaInstallationDetector::init( |
| 1703 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { |
| NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1704 | SmallVector<std::string, 4> CudaPathCandidates; |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1705 | |
| 1706 | if (Args.hasArg(options::OPT_cuda_path_EQ)) |
| 1707 | CudaPathCandidates.push_back( |
| 1708 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); |
| 1709 | else { |
| 1710 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); |
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 1711 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.5"); |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1712 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); |
| 1713 | } |
| 1714 | |
| Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1715 | for (const auto &CudaPath : CudaPathCandidates) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1716 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1717 | continue; |
| 1718 | |
| 1719 | CudaInstallPath = CudaPath; |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 1720 | CudaBinPath = CudaPath + "/bin"; |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1721 | CudaIncludePath = CudaInstallPath + "/include"; |
| 1722 | CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice"; |
| 1723 | CudaLibPath = |
| 1724 | CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); |
| 1725 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1726 | if (!(D.getVFS().exists(CudaIncludePath) && |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 1727 | D.getVFS().exists(CudaBinPath) && D.getVFS().exists(CudaLibPath) && |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1728 | D.getVFS().exists(CudaLibDevicePath))) |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1729 | continue; |
| 1730 | |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1731 | std::error_code EC; |
| 1732 | for (llvm::sys::fs::directory_iterator LI(CudaLibDevicePath, EC), LE; |
| 1733 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 1734 | StringRef FilePath = LI->path(); |
| 1735 | StringRef FileName = llvm::sys::path::filename(FilePath); |
| 1736 | // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc |
| 1737 | const StringRef LibDeviceName = "libdevice."; |
| 1738 | if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc"))) |
| 1739 | continue; |
| 1740 | StringRef GpuArch = FileName.slice( |
| 1741 | LibDeviceName.size(), FileName.find('.', LibDeviceName.size())); |
| 1742 | CudaLibDeviceMap[GpuArch] = FilePath.str(); |
| 1743 | // Insert map entries for specifc devices with this compute capability. |
| 1744 | if (GpuArch == "compute_20") { |
| 1745 | CudaLibDeviceMap["sm_20"] = FilePath; |
| 1746 | CudaLibDeviceMap["sm_21"] = FilePath; |
| 1747 | } else if (GpuArch == "compute_30") { |
| 1748 | CudaLibDeviceMap["sm_30"] = FilePath; |
| 1749 | CudaLibDeviceMap["sm_32"] = FilePath; |
| 1750 | } else if (GpuArch == "compute_35") { |
| 1751 | CudaLibDeviceMap["sm_35"] = FilePath; |
| 1752 | CudaLibDeviceMap["sm_37"] = FilePath; |
| Artem Belevich | ffa5fc5 | 2016-05-19 17:47:47 +0000 | [diff] [blame] | 1753 | } else if (GpuArch == "compute_50") { |
| 1754 | CudaLibDeviceMap["sm_50"] = FilePath; |
| 1755 | CudaLibDeviceMap["sm_52"] = FilePath; |
| 1756 | CudaLibDeviceMap["sm_53"] = FilePath; |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1757 | } |
| 1758 | } |
| 1759 | |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1760 | IsValid = true; |
| 1761 | break; |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { |
| 1766 | if (isValid()) |
| 1767 | OS << "Found CUDA installation: " << CudaInstallPath << "\n"; |
| 1768 | } |
| 1769 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1770 | namespace { |
| 1771 | // 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] | 1772 | class FilterNonExistent { |
| 1773 | StringRef Base; |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1774 | vfs::FileSystem &VFS; |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1775 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1776 | public: |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1777 | FilterNonExistent(StringRef Base, vfs::FileSystem &VFS) |
| 1778 | : Base(Base), VFS(VFS) {} |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1779 | bool operator()(const Multilib &M) { |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1780 | return !VFS.exists(Base + M.gccSuffix() + "/crtbegin.o"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1781 | } |
| 1782 | }; |
| 1783 | } // end anonymous namespace |
| 1784 | |
| 1785 | static void addMultilibFlag(bool Enabled, const char *const Flag, |
| 1786 | std::vector<std::string> &Flags) { |
| 1787 | if (Enabled) |
| 1788 | Flags.push_back(std::string("+") + Flag); |
| 1789 | else |
| 1790 | Flags.push_back(std::string("-") + Flag); |
| 1791 | } |
| 1792 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1793 | static bool isMipsArch(llvm::Triple::ArchType Arch) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1794 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || |
| 1795 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1796 | } |
| 1797 | |
| 1798 | static bool isMips32(llvm::Triple::ArchType Arch) { |
| 1799 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; |
| 1800 | } |
| 1801 | |
| 1802 | static bool isMips64(llvm::Triple::ArchType Arch) { |
| 1803 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1804 | } |
| 1805 | |
| 1806 | static bool isMipsEL(llvm::Triple::ArchType Arch) { |
| 1807 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; |
| 1808 | } |
| 1809 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1810 | static bool isMips16(const ArgList &Args) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1811 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1812 | return A && A->getOption().matches(options::OPT_mips16); |
| 1813 | } |
| 1814 | |
| 1815 | static bool isMicroMips(const ArgList &Args) { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1816 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1817 | return A && A->getOption().matches(options::OPT_mmicromips); |
| 1818 | } |
| 1819 | |
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1820 | namespace { |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1821 | struct DetectedMultilibs { |
| 1822 | /// The set of multilibs that the detected installation supports. |
| 1823 | MultilibSet Multilibs; |
| 1824 | |
| 1825 | /// The primary multilib appropriate for the given flags. |
| 1826 | Multilib SelectedMultilib; |
| 1827 | |
| 1828 | /// On Biarch systems, this corresponds to the default multilib when |
| 1829 | /// targeting the non-default multilib. Otherwise, it is empty. |
| 1830 | llvm::Optional<Multilib> BiarchSibling; |
| 1831 | }; |
| Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1832 | } // end anonymous namespace |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1833 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1834 | static Multilib makeMultilib(StringRef commonSuffix) { |
| 1835 | return Multilib(commonSuffix, commonSuffix, commonSuffix); |
| 1836 | } |
| 1837 | |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1838 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, |
| 1839 | StringRef Path, const ArgList &Args, |
| 1840 | DetectedMultilibs &Result) { |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 1841 | // Some MIPS toolchains put libraries and object files compiled |
| 1842 | // using different options in to the sub-directoris which names |
| 1843 | // reflects the flags used for compilation. For example sysroot |
| 1844 | // directory might looks like the following examples: |
| 1845 | // |
| 1846 | // /usr |
| 1847 | // /lib <= crt*.o files compiled with '-mips32' |
| 1848 | // /mips16 |
| 1849 | // /usr |
| 1850 | // /lib <= crt*.o files compiled with '-mips16' |
| 1851 | // /el |
| 1852 | // /usr |
| 1853 | // /lib <= crt*.o files compiled with '-mips16 -EL' |
| 1854 | // |
| 1855 | // or |
| 1856 | // |
| 1857 | // /usr |
| 1858 | // /lib <= crt*.o files compiled with '-mips32r2' |
| 1859 | // /mips16 |
| 1860 | // /usr |
| 1861 | // /lib <= crt*.o files compiled with '-mips32r2 -mips16' |
| 1862 | // /mips32 |
| 1863 | // /usr |
| 1864 | // /lib <= crt*.o files compiled with '-mips32' |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 1865 | |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1866 | FilterNonExistent NonExistent(Path, D.getVFS()); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 1867 | |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame^] | 1868 | // Check for CodeScape MTI toolchain v1.2 and early. |
| 1869 | MultilibSet MtiMipsMultilibsV1; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1870 | { |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1871 | auto MArchMips32 = makeMultilib("/mips32") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1872 | .flag("+m32") |
| 1873 | .flag("-m64") |
| 1874 | .flag("-mmicromips") |
| 1875 | .flag("+march=mips32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1876 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1877 | auto MArchMicroMips = makeMultilib("/micromips") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1878 | .flag("+m32") |
| 1879 | .flag("-m64") |
| 1880 | .flag("+mmicromips"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1881 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1882 | auto MArchMips64r2 = makeMultilib("/mips64r2") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1883 | .flag("-m32") |
| 1884 | .flag("+m64") |
| 1885 | .flag("+march=mips64r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1886 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1887 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( |
| 1888 | "-march=mips64r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1889 | |
| Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1890 | auto MArchDefault = makeMultilib("") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1891 | .flag("+m32") |
| 1892 | .flag("-m64") |
| 1893 | .flag("-mmicromips") |
| 1894 | .flag("+march=mips32r2"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1895 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1896 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1897 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1898 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1899 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1900 | auto MAbi64 = |
| 1901 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1902 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1903 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1904 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1905 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1906 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1907 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1908 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1909 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1910 | |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame^] | 1911 | MtiMipsMultilibsV1 = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1912 | MultilibSet() |
| 1913 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, |
| 1914 | MArchDefault) |
| 1915 | .Maybe(UCLibc) |
| 1916 | .Maybe(Mips16) |
| 1917 | .FilterOut("/mips64/mips16") |
| 1918 | .FilterOut("/mips64r2/mips16") |
| 1919 | .FilterOut("/micromips/mips16") |
| 1920 | .Maybe(MAbi64) |
| 1921 | .FilterOut("/micromips/64") |
| 1922 | .FilterOut("/mips32/64") |
| 1923 | .FilterOut("^/64") |
| 1924 | .FilterOut("/mips16/64") |
| 1925 | .Either(BigEndian, LittleEndian) |
| 1926 | .Maybe(SoftFloat) |
| 1927 | .Maybe(Nan2008) |
| 1928 | .FilterOut(".*sof/nan2008") |
| 1929 | .FilterOut(NonExistent) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 1930 | .setIncludeDirsCallback([](const Multilib &M) { |
| 1931 | std::vector<std::string> Dirs({"/include"}); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1932 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 1933 | Dirs.push_back("/../../../../sysroot/uclibc/usr/include"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1934 | else |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 1935 | Dirs.push_back("/../../../../sysroot/usr/include"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1936 | return Dirs; |
| 1937 | }); |
| Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1940 | // Check for Musl toolchain multilibs |
| 1941 | MultilibSet MuslMipsMultilibs; |
| 1942 | { |
| 1943 | auto MArchMipsR2 = makeMultilib("") |
| 1944 | .osSuffix("/mips-r2-hard-musl") |
| 1945 | .flag("+EB") |
| 1946 | .flag("-EL") |
| 1947 | .flag("+march=mips32r2"); |
| 1948 | |
| 1949 | auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl") |
| 1950 | .flag("-EB") |
| 1951 | .flag("+EL") |
| 1952 | .flag("+march=mips32r2"); |
| 1953 | |
| 1954 | MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2); |
| 1955 | |
| 1956 | // Specify the callback that computes the include directories. |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 1957 | MuslMipsMultilibs.setIncludeDirsCallback([](const Multilib &M) { |
| 1958 | return std::vector<std::string>( |
| 1959 | {"/../sysroot" + M.osSuffix() + "/usr/include"}); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1960 | }); |
| 1961 | } |
| 1962 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1963 | MultilibSet AndroidMipsMultilibs = |
| 1964 | MultilibSet() |
| 1965 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) |
| 1966 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) |
| 1967 | .FilterOut(NonExistent); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1968 | |
| 1969 | MultilibSet DebianMipsMultilibs; |
| 1970 | { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1971 | Multilib MAbiN32 = |
| 1972 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1973 | |
| 1974 | Multilib M64 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1975 | .gccSuffix("/64") |
| 1976 | .includeSuffix("/64") |
| 1977 | .flag("+m64") |
| 1978 | .flag("-m32") |
| 1979 | .flag("-mabi=n32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1980 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1981 | Multilib M32 = Multilib().flag("-m64").flag("+m32").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 | DebianMipsMultilibs = |
| 1984 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame^] | 1987 | // Check for CodeScape IMG toolchain v1.2 and early. |
| 1988 | MultilibSet ImgMultilibsV1; |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1989 | { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1990 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1991 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1992 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1993 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1994 | auto MAbi64 = |
| 1995 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1996 | |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame^] | 1997 | ImgMultilibsV1 = |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1998 | MultilibSet() |
| 1999 | .Maybe(Mips64r6) |
| 2000 | .Maybe(MAbi64) |
| 2001 | .Maybe(LittleEndian) |
| 2002 | .FilterOut(NonExistent) |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2003 | .setIncludeDirsCallback([](const Multilib &M) { |
| 2004 | return std::vector<std::string>( |
| 2005 | {"/include", "/../../../../sysroot/usr/include"}); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2006 | }); |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2009 | StringRef CPUName; |
| 2010 | StringRef ABIName; |
| 2011 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); |
| 2012 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2013 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| 2014 | |
| 2015 | Multilib::flags_list Flags; |
| 2016 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); |
| 2017 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); |
| 2018 | addMultilibFlag(isMips16(Args), "mips16", Flags); |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2019 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2020 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || |
| Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 2021 | CPUName == "mips32r5" || CPUName == "p5600", |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2022 | "march=mips32r2", Flags); |
| Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 2023 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2024 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); |
| Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2025 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || |
| 2026 | CPUName == "mips64r5" || CPUName == "octeon", |
| Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2027 | "march=mips64r2", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2028 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); |
| Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2029 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); |
| Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 2030 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", |
| 2031 | Flags); |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2032 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); |
| 2033 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2034 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2035 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2036 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); |
| Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2037 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2038 | |
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2039 | if (TargetTriple.isAndroid()) { |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2040 | // Select Android toolchain. It's the only choice in that case. |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2041 | if (AndroidMipsMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 2042 | Result.Multilibs = AndroidMipsMultilibs; |
| 2043 | return true; |
| 2044 | } |
| 2045 | return false; |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2048 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && |
| 2049 | TargetTriple.getOS() == llvm::Triple::Linux && |
| 2050 | TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) { |
| 2051 | if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 2052 | Result.Multilibs = MuslMipsMultilibs; |
| 2053 | return true; |
| 2054 | } |
| 2055 | return false; |
| 2056 | } |
| 2057 | |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2058 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && |
| 2059 | TargetTriple.getOS() == llvm::Triple::Linux && |
| 2060 | TargetTriple.getEnvironment() == llvm::Triple::GNU) { |
| 2061 | // Select mips-img-linux-gnu toolchain. |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame^] | 2062 | if (ImgMultilibsV1.select(Flags, Result.SelectedMultilib)) { |
| 2063 | Result.Multilibs = ImgMultilibsV1; |
| Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2064 | return true; |
| 2065 | } |
| 2066 | return false; |
| 2067 | } |
| 2068 | |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2069 | // Sort candidates. Toolchain that best meets the directories goes first. |
| 2070 | // Then select the first toolchains matches command line flags. |
| Simon Atanasyan | cf7ac67 | 2016-05-22 15:27:58 +0000 | [diff] [blame^] | 2071 | MultilibSet *candidates[] = {&DebianMipsMultilibs, &MtiMipsMultilibsV1}; |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2072 | std::sort( |
| 2073 | std::begin(candidates), std::end(candidates), |
| 2074 | [](MultilibSet *a, MultilibSet *b) { return a->size() > b->size(); }); |
| 2075 | for (const auto &candidate : candidates) { |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2076 | if (candidate->select(Flags, Result.SelectedMultilib)) { |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2077 | if (candidate == &DebianMipsMultilibs) |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2078 | Result.BiarchSibling = Multilib(); |
| 2079 | Result.Multilibs = *candidate; |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2080 | return true; |
| 2081 | } |
| 2082 | } |
| 2083 | |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2084 | { |
| 2085 | // Fallback to the regular toolchain-tree structure. |
| 2086 | Multilib Default; |
| 2087 | Result.Multilibs.push_back(Default); |
| 2088 | Result.Multilibs.FilterOut(NonExistent); |
| 2089 | |
| 2090 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { |
| 2091 | Result.BiarchSibling = Multilib(); |
| 2092 | return true; |
| 2093 | } |
| 2094 | } |
| 2095 | |
| Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2096 | return false; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2099 | static bool findBiarchMultilibs(const Driver &D, |
| 2100 | const llvm::Triple &TargetTriple, |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2101 | StringRef Path, const ArgList &Args, |
| 2102 | bool NeedsBiarchSuffix, |
| 2103 | DetectedMultilibs &Result) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2104 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs |
| 2105 | // in what would normally be GCCInstallPath and put the 64-bit |
| 2106 | // libs in a subdirectory named 64. The simple logic we follow is that |
| 2107 | // *if* there is a subdirectory of the right name with crtbegin.o in it, |
| 2108 | // we use that. If not, and if not a biarch triple alias, we look for |
| 2109 | // crtbegin.o without the subdirectory. |
| 2110 | |
| 2111 | Multilib Default; |
| 2112 | Multilib Alt64 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2113 | .gccSuffix("/64") |
| 2114 | .includeSuffix("/64") |
| 2115 | .flag("-m32") |
| 2116 | .flag("+m64") |
| 2117 | .flag("-mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2118 | Multilib Alt32 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2119 | .gccSuffix("/32") |
| 2120 | .includeSuffix("/32") |
| 2121 | .flag("+m32") |
| 2122 | .flag("-m64") |
| 2123 | .flag("-mx32"); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2124 | Multilib Altx32 = Multilib() |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2125 | .gccSuffix("/x32") |
| 2126 | .includeSuffix("/x32") |
| 2127 | .flag("-m32") |
| 2128 | .flag("-m64") |
| 2129 | .flag("+mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2130 | |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2131 | FilterNonExistent NonExistent(Path, D.getVFS()); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2132 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2133 | // Determine default multilib from: 32, 64, x32 |
| 2134 | // Also handle cases such as 64 on 32, 32 on 64, etc. |
| 2135 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; |
| David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2136 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; |
| Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2137 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2138 | Want = WANT64; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2139 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2140 | Want = WANT64; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2141 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2142 | Want = WANT32; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2143 | else { |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2144 | if (TargetTriple.isArch32Bit()) |
| 2145 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2146 | else if (IsX32) |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2147 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2148 | else |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2149 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; |
| Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2152 | if (Want == WANT32) |
| 2153 | Default.flag("+m32").flag("-m64").flag("-mx32"); |
| 2154 | else if (Want == WANT64) |
| 2155 | Default.flag("-m32").flag("+m64").flag("-mx32"); |
| 2156 | else if (Want == WANTX32) |
| 2157 | Default.flag("-m32").flag("-m64").flag("+mx32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2158 | else |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2159 | return false; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2160 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2161 | Result.Multilibs.push_back(Default); |
| 2162 | Result.Multilibs.push_back(Alt64); |
| 2163 | Result.Multilibs.push_back(Alt32); |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2164 | Result.Multilibs.push_back(Altx32); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2165 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2166 | Result.Multilibs.FilterOut(NonExistent); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2167 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2168 | Multilib::flags_list Flags; |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2169 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2170 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); |
| Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2171 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2172 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2173 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2174 | return false; |
| Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2175 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2176 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2177 | Result.SelectedMultilib == Altx32) |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2178 | Result.BiarchSibling = Default; |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2179 | |
| 2180 | return true; |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2183 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( |
| 2184 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, |
| 2185 | const std::string &LibDir, StringRef CandidateTriple, |
| 2186 | bool NeedsBiarchSuffix) { |
| 2187 | // Solaris is a special case. The GCC installation is under |
| 2188 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we |
| 2189 | // need to iterate twice. |
| 2190 | std::error_code EC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2191 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; |
| 2192 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 2193 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2194 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| 2195 | |
| 2196 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2197 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2198 | continue; // Saw this path before; no need to look at it again. |
| 2199 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| 2200 | continue; |
| 2201 | if (CandidateVersion <= Version) |
| 2202 | continue; |
| 2203 | |
| 2204 | GCCInstallPath = |
| 2205 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2206 | if (!D.getVFS().exists(GCCInstallPath)) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2207 | continue; |
| 2208 | |
| 2209 | // If we make it here there has to be at least one GCC version, let's just |
| 2210 | // use the latest one. |
| 2211 | std::error_code EEC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2212 | for (vfs::directory_iterator |
| 2213 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), |
| 2214 | LLE; |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2215 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { |
| 2216 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2217 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2218 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); |
| 2219 | |
| 2220 | if (CandidateSubVersion > Version) |
| 2221 | Version = CandidateSubVersion; |
| 2222 | } |
| 2223 | |
| 2224 | GCCTriple.setTriple(CandidateTriple); |
| 2225 | |
| 2226 | GCCInstallPath += "/" + Version.Text; |
| 2227 | GCCParentLibPath = GCCInstallPath + "/../../../../"; |
| 2228 | |
| 2229 | IsValid = true; |
| 2230 | } |
| 2231 | } |
| 2232 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2233 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2234 | const llvm::Triple &TargetTriple, const ArgList &Args, |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2235 | const std::string &LibDir, StringRef CandidateTriple, |
| 2236 | bool NeedsBiarchSuffix) { |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2237 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2238 | // There are various different suffixes involving the triple we |
| 2239 | // 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] | 2240 | // up to the lib directory. Specifically, the number of "up" steps |
| 2241 | // in the second half of each row is 1 + the number of path separators |
| 2242 | // in the first half. |
| 2243 | const std::string LibAndInstallSuffixes[][2] = { |
| 2244 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, |
| 2245 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2246 | // Debian puts cross-compilers in gcc-cross |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2247 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, |
| 2248 | |
| 2249 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), |
| 2250 | "/../../../.."}, |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2251 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2252 | // The Freescale PPC SDK has the gcc libraries in |
| 2253 | // <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] | 2254 | {"/" + CandidateTriple.str(), "/../.."}, |
| Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2255 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2256 | // Ubuntu has a strange mis-matched pair of triples that this happens to |
| 2257 | // match. |
| 2258 | // FIXME: It may be worthwhile to generalize this and look for a second |
| 2259 | // triple. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2260 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; |
| 2261 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2262 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 2263 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, |
| 2264 | NeedsBiarchSuffix); |
| 2265 | return; |
| 2266 | } |
| 2267 | |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2268 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2269 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - |
| 2270 | (TargetArch != llvm::Triple::x86)); |
| Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2271 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2272 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; |
| Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2273 | std::error_code EC; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2274 | for (vfs::directory_iterator |
| 2275 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), |
| 2276 | LE; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2277 | !EC && LI != LE; LI = LI.increment(EC)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2278 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2279 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2280 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2281 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
| Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2282 | continue; // Saw this path before; no need to look at it again. |
| Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2283 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2284 | continue; |
| 2285 | if (CandidateVersion <= Version) |
| 2286 | continue; |
| Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2287 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2288 | DetectedMultilibs Detected; |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2289 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2290 | // Debian mips multilibs behave more like the rest of the biarch ones, |
| 2291 | // so handle them there |
| 2292 | if (isMipsArch(TargetArch)) { |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2293 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2294 | continue; |
| Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2295 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2296 | NeedsBiarchSuffix, Detected)) { |
| Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2297 | continue; |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2298 | } |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2299 | |
| Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2300 | Multilibs = Detected.Multilibs; |
| 2301 | SelectedMultilib = Detected.SelectedMultilib; |
| 2302 | BiarchSibling = Detected.BiarchSibling; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2303 | Version = CandidateVersion; |
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2304 | GCCTriple.setTriple(CandidateTriple); |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2305 | // FIXME: We hack together the directory name here instead of |
| 2306 | // using LI to ensure stable path separators across Windows and |
| 2307 | // Linux. |
| Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2308 | GCCInstallPath = |
| 2309 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); |
| 2310 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; |
| Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2311 | IsValid = true; |
| 2312 | } |
| 2313 | } |
| 2314 | } |
| 2315 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2316 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2317 | const ArgList &Args) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2318 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2319 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2320 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2321 | getProgramPaths().push_back(getDriver().Dir); |
| Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2324 | Generic_GCC::~Generic_GCC() {} |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2325 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2326 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { |
| Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2327 | switch (AC) { |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2328 | case Action::PreprocessJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2329 | if (!Preprocess) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2330 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2331 | return Preprocess.get(); |
| Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2332 | case Action::CompileJobClass: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2333 | if (!Compile) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2334 | Compile.reset(new tools::gcc::Compiler(*this)); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2335 | return Compile.get(); |
| Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2336 | default: |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2337 | return ToolChain::getTool(AC); |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2338 | } |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2341 | Tool *Generic_GCC::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2342 | return new tools::gnutools::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2345 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2346 | |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2347 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { |
| 2348 | // Print the information about how we detected the GCC installation. |
| 2349 | GCCInstallation.print(OS); |
| Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2350 | CudaInstallation.print(OS); |
| Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2353 | bool Generic_GCC::IsUnwindTablesDefault() const { |
| Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2354 | return getArch() == llvm::Triple::x86_64; |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2357 | bool Generic_GCC::isPICDefault() const { |
| 2358 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2359 | } |
| Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2360 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2361 | bool Generic_GCC::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2362 | |
| David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2363 | bool Generic_GCC::isPICDefaultForced() const { |
| 2364 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2365 | } |
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2366 | |
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2367 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2368 | switch (getTriple().getArch()) { |
| 2369 | case llvm::Triple::x86: |
| 2370 | case llvm::Triple::x86_64: |
| 2371 | case llvm::Triple::aarch64: |
| 2372 | case llvm::Triple::aarch64_be: |
| 2373 | case llvm::Triple::arm: |
| 2374 | case llvm::Triple::armeb: |
| Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2375 | case llvm::Triple::bpfel: |
| 2376 | case llvm::Triple::bpfeb: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2377 | case llvm::Triple::thumb: |
| 2378 | case llvm::Triple::thumbeb: |
| 2379 | case llvm::Triple::ppc: |
| 2380 | case llvm::Triple::ppc64: |
| 2381 | case llvm::Triple::ppc64le: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2382 | case llvm::Triple::systemz: |
| Daniel Sanders | e160f83 | 2016-05-14 12:43:08 +0000 | [diff] [blame] | 2383 | case llvm::Triple::mips: |
| 2384 | case llvm::Triple::mipsel: |
| Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2385 | return true; |
| 2386 | default: |
| 2387 | return false; |
| 2388 | } |
| Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2391 | /// \brief Helper to add the variant paths of a libstdc++ installation. |
| 2392 | bool Generic_GCC::addLibStdCXXIncludePaths( |
| 2393 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, |
| 2394 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, |
| 2395 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2396 | if (!getVFS().exists(Base + Suffix)) |
| 2397 | return false; |
| 2398 | |
| 2399 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); |
| 2400 | |
| 2401 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If |
| 2402 | // that path exists or we have neither a GCC nor target multiarch triple, use |
| 2403 | // this vanilla search path. |
| 2404 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || |
| 2405 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { |
| 2406 | addSystemInclude(DriverArgs, CC1Args, |
| 2407 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); |
| 2408 | } else { |
| 2409 | // Otherwise try to use multiarch naming schemes which have normalized the |
| 2410 | // triples and put the triple before the suffix. |
| 2411 | // |
| 2412 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and |
| 2413 | // the target triple, so we support that here. |
| 2414 | addSystemInclude(DriverArgs, CC1Args, |
| 2415 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); |
| 2416 | addSystemInclude(DriverArgs, CC1Args, |
| 2417 | Base + "/" + TargetMultiarchTriple + Suffix); |
| 2418 | } |
| 2419 | |
| 2420 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); |
| 2421 | return true; |
| 2422 | } |
| 2423 | |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2424 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, |
| 2425 | ArgStringList &CC1Args) const { |
| 2426 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2427 | bool UseInitArrayDefault = |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2428 | getTriple().getArch() == llvm::Triple::aarch64 || |
| Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2429 | getTriple().getArch() == llvm::Triple::aarch64_be || |
| Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2430 | (getTriple().getOS() == llvm::Triple::Linux && |
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2431 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2432 | getTriple().getOS() == llvm::Triple::NaCl || |
| 2433 | (getTriple().getVendor() == llvm::Triple::MipsTechnologies && |
| 2434 | !getTriple().hasEnvironment()); |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2435 | |
| 2436 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2437 | options::OPT_fno_use_init_array, UseInitArrayDefault)) |
| Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2438 | CC1Args.push_back("-fuse-init-array"); |
| 2439 | } |
| 2440 | |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2441 | /// Mips Toolchain |
| 2442 | MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D, |
| 2443 | const llvm::Triple &Triple, |
| 2444 | const ArgList &Args) |
| 2445 | : Linux(D, Triple, Args) { |
| 2446 | // Select the correct multilib according to the given arguments. |
| 2447 | DetectedMultilibs Result; |
| 2448 | findMIPSMultilibs(D, Triple, "", Args, Result); |
| 2449 | Multilibs = Result.Multilibs; |
| 2450 | SelectedMultilib = Result.SelectedMultilib; |
| 2451 | |
| 2452 | // Find out the library suffix based on the ABI. |
| 2453 | LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple); |
| 2454 | getFilePaths().clear(); |
| 2455 | getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix); |
| 2456 | |
| 2457 | // Use LLD by default. |
| Peter Collingbourne | 39719a7 | 2015-11-20 20:49:39 +0000 | [diff] [blame] | 2458 | DefaultLinker = "lld"; |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | void MipsLLVMToolChain::AddClangSystemIncludeArgs( |
| 2462 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2463 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2464 | return; |
| 2465 | |
| 2466 | const Driver &D = getDriver(); |
| 2467 | |
| 2468 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 2469 | SmallString<128> P(D.ResourceDir); |
| 2470 | llvm::sys::path::append(P, "include"); |
| 2471 | addSystemInclude(DriverArgs, CC1Args, P); |
| 2472 | } |
| 2473 | |
| 2474 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2475 | return; |
| 2476 | |
| 2477 | const auto &Callback = Multilibs.includeDirsCallback(); |
| 2478 | if (Callback) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2479 | for (const auto &Path : Callback(SelectedMultilib)) |
| 2480 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, |
| 2481 | D.getInstalledDir() + Path); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | Tool *MipsLLVMToolChain::buildLinker() const { |
| 2486 | return new tools::gnutools::Linker(*this); |
| 2487 | } |
| 2488 | |
| 2489 | std::string MipsLLVMToolChain::computeSysRoot() const { |
| 2490 | if (!getDriver().SysRoot.empty()) |
| 2491 | return getDriver().SysRoot + SelectedMultilib.osSuffix(); |
| 2492 | |
| 2493 | const std::string InstalledDir(getDriver().getInstalledDir()); |
| 2494 | std::string SysRootPath = |
| 2495 | InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix(); |
| 2496 | if (llvm::sys::fs::exists(SysRootPath)) |
| 2497 | return SysRootPath; |
| 2498 | |
| 2499 | return std::string(); |
| 2500 | } |
| 2501 | |
| 2502 | ToolChain::CXXStdlibType |
| 2503 | MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| 2504 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 2505 | if (A) { |
| 2506 | StringRef Value = A->getValue(); |
| 2507 | if (Value != "libc++") |
| 2508 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) |
| 2509 | << A->getAsString(Args); |
| 2510 | } |
| 2511 | |
| 2512 | return ToolChain::CST_Libcxx; |
| 2513 | } |
| 2514 | |
| 2515 | void MipsLLVMToolChain::AddClangCXXStdlibIncludeArgs( |
| 2516 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2517 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2518 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2519 | return; |
| 2520 | |
| 2521 | assert((GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) && |
| 2522 | "Only -lc++ (aka libcxx) is suported in this toolchain."); |
| 2523 | |
| 2524 | const auto &Callback = Multilibs.includeDirsCallback(); |
| 2525 | if (Callback) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 2526 | for (std::string Path : Callback(SelectedMultilib)) { |
| 2527 | Path = getDriver().getInstalledDir() + Path + "/c++/v1"; |
| 2528 | if (llvm::sys::fs::exists(Path)) { |
| 2529 | addSystemInclude(DriverArgs, CC1Args, Path); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2530 | break; |
| 2531 | } |
| 2532 | } |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2537 | ArgStringList &CmdArgs) const { |
| 2538 | assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) && |
| 2539 | "Only -lc++ (aka libxx) is suported in this toolchain."); |
| 2540 | |
| 2541 | CmdArgs.push_back("-lc++"); |
| 2542 | CmdArgs.push_back("-lc++abi"); |
| 2543 | CmdArgs.push_back("-lunwind"); |
| 2544 | } |
| 2545 | |
| 2546 | std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, |
| 2547 | StringRef Component, |
| 2548 | bool Shared) const { |
| 2549 | SmallString<128> Path(getDriver().ResourceDir); |
| 2550 | llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix, |
| 2551 | getOS()); |
| 2552 | llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" + |
| Vasileios Kalintiris | bbc9930 | 2015-11-16 15:41:30 +0000 | [diff] [blame] | 2553 | "mips" + (Shared ? ".so" : ".a"))); |
| Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2554 | return Path.str(); |
| 2555 | } |
| 2556 | |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2557 | /// Hexagon Toolchain |
| 2558 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2559 | std::string HexagonToolChain::getHexagonTargetDir( |
| 2560 | const std::string &InstalledDir, |
| 2561 | const SmallVectorImpl<std::string> &PrefixDirs) const { |
| 2562 | std::string InstallRelDir; |
| 2563 | const Driver &D = getDriver(); |
| 2564 | |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2565 | // Locate the rest of the toolchain ... |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2566 | for (auto &I : PrefixDirs) |
| 2567 | if (D.getVFS().exists(I)) |
| 2568 | return I; |
| Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 2569 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2570 | if (getVFS().exists(InstallRelDir = InstalledDir + "/../target")) |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2571 | return InstallRelDir; |
| 2572 | |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2573 | return InstallRelDir; |
| 2574 | } |
| 2575 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2576 | Optional<unsigned> HexagonToolChain::getSmallDataThreshold( |
| 2577 | const ArgList &Args) { |
| 2578 | StringRef Gn = ""; |
| 2579 | if (Arg *A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, |
| 2580 | options::OPT_msmall_data_threshold_EQ)) { |
| 2581 | Gn = A->getValue(); |
| 2582 | } else if (Args.getLastArg(options::OPT_shared, options::OPT_fpic, |
| 2583 | options::OPT_fPIC)) { |
| 2584 | Gn = "0"; |
| 2585 | } |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2586 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2587 | unsigned G; |
| 2588 | if (!Gn.getAsInteger(10, G)) |
| 2589 | return G; |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2590 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2591 | return None; |
| Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2594 | void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args, |
| 2595 | ToolChain::path_list &LibPaths) const { |
| 2596 | const Driver &D = getDriver(); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2597 | |
| 2598 | //---------------------------------------------------------------------------- |
| 2599 | // -L Args |
| 2600 | //---------------------------------------------------------------------------- |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 2601 | for (Arg *A : Args.filtered(options::OPT_L)) |
| 2602 | for (const char *Value : A->getValues()) |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2603 | LibPaths.push_back(Value); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2604 | |
| 2605 | //---------------------------------------------------------------------------- |
| 2606 | // Other standard paths |
| 2607 | //---------------------------------------------------------------------------- |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2608 | std::vector<std::string> RootDirs; |
| Krzysztof Parzyszek | f4467cd | 2016-01-06 14:13:11 +0000 | [diff] [blame] | 2609 | std::copy(D.PrefixDirs.begin(), D.PrefixDirs.end(), |
| 2610 | std::back_inserter(RootDirs)); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2611 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2612 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 2613 | D.PrefixDirs); |
| 2614 | if (std::find(RootDirs.begin(), RootDirs.end(), TargetDir) == RootDirs.end()) |
| 2615 | RootDirs.push_back(TargetDir); |
| 2616 | |
| 2617 | bool HasPIC = Args.hasArg(options::OPT_fpic, options::OPT_fPIC); |
| 2618 | // Assume G0 with -shared. |
| 2619 | bool HasG0 = Args.hasArg(options::OPT_shared); |
| 2620 | if (auto G = getSmallDataThreshold(Args)) |
| 2621 | HasG0 = G.getValue() == 0; |
| 2622 | |
| 2623 | const std::string CpuVer = GetTargetCPUVersion(Args).str(); |
| 2624 | for (auto &Dir : RootDirs) { |
| 2625 | std::string LibDir = Dir + "/hexagon/lib"; |
| 2626 | std::string LibDirCpu = LibDir + '/' + CpuVer; |
| 2627 | if (HasG0) { |
| 2628 | if (HasPIC) |
| 2629 | LibPaths.push_back(LibDirCpu + "/G0/pic"); |
| 2630 | LibPaths.push_back(LibDirCpu + "/G0"); |
| 2631 | } |
| 2632 | LibPaths.push_back(LibDirCpu); |
| 2633 | LibPaths.push_back(LibDir); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2634 | } |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2637 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2638 | const llvm::opt::ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2639 | : Linux(D, Triple, Args) { |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2640 | const std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 2641 | D.PrefixDirs); |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2642 | |
| 2643 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to |
| 2644 | // program paths |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2645 | const std::string BinDir(TargetDir + "/bin"); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2646 | if (D.getVFS().exists(BinDir)) |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2647 | getProgramPaths().push_back(BinDir); |
| 2648 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2649 | ToolChain::path_list &LibPaths = getFilePaths(); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2650 | |
| 2651 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets |
| 2652 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually |
| 2653 | // support 'linux' we'll need to fix this up |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2654 | LibPaths.clear(); |
| 2655 | getHexagonLibraryPaths(Args, LibPaths); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2658 | HexagonToolChain::~HexagonToolChain() {} |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2659 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2660 | Tool *HexagonToolChain::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2661 | return new tools::hexagon::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2664 | Tool *HexagonToolChain::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2665 | return new tools::hexagon::Linker(*this); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2666 | } |
| 2667 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2668 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2669 | ArgStringList &CC1Args) const { |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2670 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 2671 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2672 | return; |
| 2673 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2674 | const Driver &D = getDriver(); |
| 2675 | std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(), |
| 2676 | D.PrefixDirs); |
| 2677 | addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include"); |
| Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2680 | void HexagonToolChain::AddClangCXXStdlibIncludeArgs( |
| 2681 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2682 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2683 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2684 | return; |
| 2685 | |
| 2686 | const Driver &D = getDriver(); |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2687 | std::string TargetDir = getHexagonTargetDir(D.InstalledDir, D.PrefixDirs); |
| 2688 | addSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include/c++"); |
| Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2689 | } |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2690 | |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2691 | ToolChain::CXXStdlibType |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2692 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2693 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 2694 | if (!A) |
| 2695 | return ToolChain::CST_Libstdcxx; |
| 2696 | |
| 2697 | StringRef Value = A->getValue(); |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2698 | if (Value != "libstdc++") |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2699 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
| Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2700 | |
| 2701 | return ToolChain::CST_Libstdcxx; |
| 2702 | } |
| 2703 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2704 | // |
| 2705 | // Returns the default CPU for Hexagon. This is the default compilation target |
| 2706 | // if no Hexagon processor is selected at the command-line. |
| 2707 | // |
| 2708 | const StringRef HexagonToolChain::GetDefaultCPU() { |
| 2709 | return "hexagonv60"; |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2710 | } |
| 2711 | |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2712 | const StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) { |
| 2713 | Arg *CpuArg = nullptr; |
| Krzysztof Parzyszek | 972f72c | 2016-01-06 21:12:03 +0000 | [diff] [blame] | 2714 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ, options::OPT_march_EQ)) |
| 2715 | CpuArg = A; |
| Krzysztof Parzyszek | 1e6e3c6 | 2015-12-14 15:03:57 +0000 | [diff] [blame] | 2716 | |
| 2717 | StringRef CPU = CpuArg ? CpuArg->getValue() : GetDefaultCPU(); |
| 2718 | if (CPU.startswith("hexagon")) |
| 2719 | return CPU.substr(sizeof("hexagon") - 1); |
| 2720 | return CPU; |
| Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2721 | } |
| Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2722 | // End Hexagon |
| Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 2723 | |
| Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 2724 | /// AMDGPU Toolchain |
| 2725 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2726 | const ArgList &Args) |
| 2727 | : Generic_ELF(D, Triple, Args) { } |
| 2728 | |
| 2729 | Tool *AMDGPUToolChain::buildLinker() const { |
| 2730 | return new tools::amdgpu::Linker(*this); |
| 2731 | } |
| 2732 | // End AMDGPU |
| 2733 | |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2734 | /// NaCl Toolchain |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2735 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2736 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2737 | : Generic_ELF(D, Triple, Args) { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2738 | |
| 2739 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the |
| 2740 | // default paths, and must instead only use the paths provided |
| 2741 | // with this toolchain based on architecture. |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2742 | path_list &file_paths = getFilePaths(); |
| 2743 | path_list &prog_paths = getProgramPaths(); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2744 | |
| 2745 | file_paths.clear(); |
| 2746 | prog_paths.clear(); |
| 2747 | |
| 2748 | // Path for library files (libc.a, ...) |
| 2749 | std::string FilePath(getDriver().Dir + "/../"); |
| 2750 | |
| 2751 | // Path for tools (clang, ld, etc..) |
| 2752 | std::string ProgPath(getDriver().Dir + "/../"); |
| 2753 | |
| 2754 | // Path for toolchain libraries (libgcc.a, ...) |
| 2755 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); |
| 2756 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2757 | switch (Triple.getArch()) { |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2758 | case llvm::Triple::x86: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2759 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); |
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2760 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2761 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 2762 | file_paths.push_back(ToolPath + "i686-nacl"); |
| 2763 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2764 | case llvm::Triple::x86_64: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2765 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); |
| 2766 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); |
| 2767 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 2768 | file_paths.push_back(ToolPath + "x86_64-nacl"); |
| 2769 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2770 | case llvm::Triple::arm: |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2771 | file_paths.push_back(FilePath + "arm-nacl/lib"); |
| 2772 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); |
| 2773 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); |
| 2774 | file_paths.push_back(ToolPath + "arm-nacl"); |
| 2775 | break; |
| Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2776 | case llvm::Triple::mipsel: |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2777 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); |
| 2778 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); |
| 2779 | prog_paths.push_back(ProgPath + "bin"); |
| 2780 | file_paths.push_back(ToolPath + "mipsel-nacl"); |
| 2781 | break; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2782 | default: |
| 2783 | break; |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2786 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); |
| 2787 | } |
| 2788 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2789 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2790 | ArgStringList &CC1Args) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2791 | const Driver &D = getDriver(); |
| 2792 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2793 | return; |
| 2794 | |
| 2795 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 2796 | SmallString<128> P(D.ResourceDir); |
| 2797 | llvm::sys::path::append(P, "include"); |
| 2798 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2799 | } |
| 2800 | |
| 2801 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2802 | return; |
| 2803 | |
| 2804 | SmallString<128> P(D.Dir + "/../"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2805 | switch (getTriple().getArch()) { |
| Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2806 | case llvm::Triple::x86: |
| 2807 | // x86 is special because multilib style uses x86_64-nacl/include for libc |
| 2808 | // headers but the SDK wants i686-nacl/usr/include. The other architectures |
| 2809 | // have the same substring. |
| 2810 | llvm::sys::path::append(P, "i686-nacl/usr/include"); |
| 2811 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2812 | llvm::sys::path::remove_filename(P); |
| 2813 | llvm::sys::path::remove_filename(P); |
| 2814 | llvm::sys::path::remove_filename(P); |
| 2815 | llvm::sys::path::append(P, "x86_64-nacl/include"); |
| 2816 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2817 | return; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2818 | case llvm::Triple::arm: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2819 | llvm::sys::path::append(P, "arm-nacl/usr/include"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2820 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2821 | case llvm::Triple::x86_64: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2822 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2823 | break; |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2824 | case llvm::Triple::mipsel: |
| 2825 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); |
| 2826 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2827 | default: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2828 | return; |
| 2829 | } |
| 2830 | |
| 2831 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2832 | llvm::sys::path::remove_filename(P); |
| 2833 | llvm::sys::path::remove_filename(P); |
| 2834 | llvm::sys::path::append(P, "include"); |
| 2835 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2836 | } |
| 2837 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2838 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2839 | ArgStringList &CmdArgs) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2840 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 2841 | // if the value is libc++, and emits an error for other values. |
| 2842 | GetCXXStdlibType(Args); |
| 2843 | CmdArgs.push_back("-lc++"); |
| 2844 | } |
| 2845 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2846 | void NaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2847 | ArgStringList &CC1Args) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2848 | const Driver &D = getDriver(); |
| 2849 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2850 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2851 | return; |
| 2852 | |
| 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(DriverArgs); |
| 2856 | |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2857 | SmallString<128> P(D.Dir + "/../"); |
| 2858 | switch (getTriple().getArch()) { |
| 2859 | case llvm::Triple::arm: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2860 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); |
| 2861 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2862 | break; |
| 2863 | case llvm::Triple::x86: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2864 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 2865 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2866 | break; |
| 2867 | case llvm::Triple::x86_64: |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2868 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 2869 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2870 | break; |
| Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2871 | case llvm::Triple::mipsel: |
| 2872 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); |
| 2873 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2874 | break; |
| Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 2875 | default: |
| 2876 | break; |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2877 | } |
| 2878 | } |
| 2879 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2880 | ToolChain::CXXStdlibType |
| 2881 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2882 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 2883 | StringRef Value = A->getValue(); |
| 2884 | if (Value == "libc++") |
| 2885 | return ToolChain::CST_Libcxx; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2886 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | return ToolChain::CST_Libcxx; |
| 2890 | } |
| 2891 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2892 | std::string |
| 2893 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, |
| 2894 | types::ID InputType) const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2895 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); |
| 2896 | if (TheTriple.getArch() == llvm::Triple::arm && |
| 2897 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) |
| 2898 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); |
| 2899 | return TheTriple.getTriple(); |
| 2900 | } |
| 2901 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2902 | Tool *NaClToolChain::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2903 | return new tools::nacltools::Linker(*this); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2904 | } |
| 2905 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2906 | Tool *NaClToolChain::buildAssembler() const { |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2907 | if (getTriple().getArch() == llvm::Triple::arm) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2908 | return new tools::nacltools::AssemblerARM(*this); |
| 2909 | return new tools::gnutools::Assembler(*this); |
| Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2910 | } |
| 2911 | // End NaCl |
| 2912 | |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2913 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 2914 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 2915 | /// Currently does not support anything else but compilation. |
| 2916 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2917 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 2918 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2919 | : ToolChain(D, Triple, Args) { |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2920 | // Path mangling to find libexec |
| 2921 | std::string Path(getDriver().Dir); |
| 2922 | |
| 2923 | Path += "/../libexec"; |
| 2924 | getProgramPaths().push_back(Path); |
| 2925 | } |
| 2926 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2927 | TCEToolChain::~TCEToolChain() {} |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2928 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2929 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2930 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2931 | bool TCEToolChain::isPICDefault() const { return false; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2932 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2933 | bool TCEToolChain::isPIEDefault() const { return false; } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2934 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2935 | bool TCEToolChain::isPICDefaultForced() const { return false; } |
| Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2936 | |
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2937 | // CloudABI - CloudABI tool chain which can call ld(1) directly. |
| 2938 | |
| 2939 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, |
| 2940 | const ArgList &Args) |
| 2941 | : Generic_ELF(D, Triple, Args) { |
| 2942 | SmallString<128> P(getDriver().Dir); |
| 2943 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); |
| 2944 | getFilePaths().push_back(P.str()); |
| 2945 | } |
| 2946 | |
| 2947 | void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2948 | ArgStringList &CC1Args) const { |
| 2949 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) && |
| 2950 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2951 | return; |
| 2952 | |
| 2953 | SmallString<128> P(getDriver().Dir); |
| 2954 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); |
| 2955 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2956 | } |
| 2957 | |
| 2958 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2959 | ArgStringList &CmdArgs) const { |
| 2960 | CmdArgs.push_back("-lc++"); |
| 2961 | CmdArgs.push_back("-lc++abi"); |
| 2962 | CmdArgs.push_back("-lunwind"); |
| 2963 | } |
| 2964 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2965 | Tool *CloudABI::buildLinker() const { |
| 2966 | return new tools::cloudabi::Linker(*this); |
| 2967 | } |
| Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2968 | |
| Ed Schouten | 51bfbe7 | 2016-02-17 18:56:20 +0000 | [diff] [blame] | 2969 | SanitizerMask CloudABI::getSupportedSanitizers() const { |
| 2970 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 2971 | Res |= SanitizerKind::SafeStack; |
| 2972 | return Res; |
| 2973 | } |
| 2974 | |
| Ed Schouten | fc79d2c | 2016-03-29 21:13:53 +0000 | [diff] [blame] | 2975 | SanitizerMask CloudABI::getDefaultSanitizers() const { |
| 2976 | return SanitizerKind::SafeStack; |
| 2977 | } |
| 2978 | |
| Reid Kleckner | 330fb17 | 2016-05-11 16:19:05 +0000 | [diff] [blame] | 2979 | /// Haiku - Haiku tool chain which can call as(1) and ld(1) directly. |
| 2980 | |
| 2981 | Haiku::Haiku(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
| 2982 | : Generic_ELF(D, Triple, Args) { |
| 2983 | |
| 2984 | } |
| 2985 | |
| 2986 | void Haiku::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2987 | ArgStringList &CC1Args) const { |
| 2988 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2989 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2990 | return; |
| 2991 | |
| 2992 | switch (GetCXXStdlibType(DriverArgs)) { |
| 2993 | case ToolChain::CST_Libcxx: |
| 2994 | addSystemInclude(DriverArgs, CC1Args, |
| 2995 | getDriver().SysRoot + "/system/develop/headers/c++/v1"); |
| 2996 | break; |
| 2997 | case ToolChain::CST_Libstdcxx: |
| 2998 | addSystemInclude(DriverArgs, CC1Args, |
| 2999 | getDriver().SysRoot + "/system/develop/headers/c++"); |
| 3000 | addSystemInclude(DriverArgs, CC1Args, |
| 3001 | getDriver().SysRoot + "/system/develop/headers/c++/backward"); |
| 3002 | |
| 3003 | StringRef Triple = getTriple().str(); |
| 3004 | addSystemInclude(DriverArgs, CC1Args, |
| 3005 | getDriver().SysRoot + "/system/develop/headers/c++/" + |
| 3006 | Triple); |
| 3007 | break; |
| 3008 | } |
| 3009 | } |
| 3010 | |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3011 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 3012 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3013 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, |
| 3014 | const ArgList &Args) |
| 3015 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3016 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3017 | getFilePaths().push_back("/usr/lib"); |
| 3018 | } |
| 3019 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3020 | Tool *OpenBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3021 | return new tools::openbsd::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3024 | Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } |
| Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3025 | |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3026 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. |
| 3027 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3028 | Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3029 | : Generic_ELF(D, Triple, Args) { |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3030 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3031 | getFilePaths().push_back("/usr/lib"); |
| 3032 | } |
| 3033 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3034 | Tool *Bitrig::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3035 | return new tools::bitrig::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3038 | Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3039 | |
| Jonas Hahnfeld | aae8374 | 2016-02-12 07:48:37 +0000 | [diff] [blame] | 3040 | ToolChain::CXXStdlibType Bitrig::GetDefaultCXXStdlibType() const { |
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3041 | return ToolChain::CST_Libcxx; |
| 3042 | } |
| 3043 | |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3044 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3045 | ArgStringList &CC1Args) const { |
| 3046 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3047 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3048 | return; |
| 3049 | |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3050 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3051 | case ToolChain::CST_Libcxx: |
| 3052 | addSystemInclude(DriverArgs, CC1Args, |
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3053 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3054 | break; |
| 3055 | case ToolChain::CST_Libstdcxx: |
| 3056 | addSystemInclude(DriverArgs, CC1Args, |
| 3057 | getDriver().SysRoot + "/usr/include/c++/stdc++"); |
| 3058 | addSystemInclude(DriverArgs, CC1Args, |
| 3059 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3060 | |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3061 | StringRef Triple = getTriple().str(); |
| 3062 | if (Triple.startswith("amd64")) |
| 3063 | addSystemInclude(DriverArgs, CC1Args, |
| 3064 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3065 | Triple.substr(5)); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3066 | else |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3067 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + |
| 3068 | "/usr/include/c++/stdc++/" + |
| 3069 | Triple); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3070 | break; |
| 3071 | } |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3075 | ArgStringList &CmdArgs) const { |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3076 | switch (GetCXXStdlibType(Args)) { |
| 3077 | case ToolChain::CST_Libcxx: |
| 3078 | CmdArgs.push_back("-lc++"); |
| Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3079 | CmdArgs.push_back("-lc++abi"); |
| 3080 | CmdArgs.push_back("-lpthread"); |
| Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3081 | break; |
| 3082 | case ToolChain::CST_Libstdcxx: |
| 3083 | CmdArgs.push_back("-lstdc++"); |
| 3084 | break; |
| 3085 | } |
| Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3086 | } |
| 3087 | |
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3088 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 3089 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3090 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, |
| 3091 | const ArgList &Args) |
| 3092 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 3093 | |
| Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 3094 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall |
| 3095 | // back to '/usr/lib' if it doesn't exist. |
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3096 | if ((Triple.getArch() == llvm::Triple::x86 || |
| 3097 | Triple.getArch() == llvm::Triple::ppc) && |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3098 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) |
| Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3099 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); |
| 3100 | else |
| 3101 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
| Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3104 | ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3105 | if (getTriple().getOSMajorVersion() >= 10) |
| David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3106 | return ToolChain::CST_Libcxx; |
| 3107 | return ToolChain::CST_Libstdcxx; |
| 3108 | } |
| 3109 | |
| 3110 | void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3111 | ArgStringList &CC1Args) const { |
| 3112 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3113 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3114 | return; |
| 3115 | |
| 3116 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3117 | case ToolChain::CST_Libcxx: |
| 3118 | addSystemInclude(DriverArgs, CC1Args, |
| 3119 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| 3120 | break; |
| 3121 | case ToolChain::CST_Libstdcxx: |
| 3122 | addSystemInclude(DriverArgs, CC1Args, |
| 3123 | getDriver().SysRoot + "/usr/include/c++/4.2"); |
| 3124 | addSystemInclude(DriverArgs, CC1Args, |
| 3125 | getDriver().SysRoot + "/usr/include/c++/4.2/backward"); |
| 3126 | break; |
| 3127 | } |
| 3128 | } |
| 3129 | |
| Dimitry Andric | 6090739 | 2016-02-14 16:08:20 +0000 | [diff] [blame] | 3130 | void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3131 | ArgStringList &CmdArgs) const { |
| 3132 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 3133 | bool Profiling = Args.hasArg(options::OPT_pg); |
| 3134 | |
| 3135 | switch (Type) { |
| 3136 | case ToolChain::CST_Libcxx: |
| 3137 | CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++"); |
| 3138 | break; |
| 3139 | |
| 3140 | case ToolChain::CST_Libstdcxx: |
| 3141 | CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++"); |
| 3142 | break; |
| 3143 | } |
| 3144 | } |
| 3145 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3146 | Tool *FreeBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3147 | return new tools::freebsd::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3148 | } |
| 3149 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3150 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3151 | |
| Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 3152 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { |
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3153 | // FreeBSD uses SjLj exceptions on ARM oabi. |
| 3154 | switch (getTriple().getEnvironment()) { |
| Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 3155 | case llvm::Triple::GNUEABIHF: |
| Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3156 | case llvm::Triple::GNUEABI: |
| 3157 | case llvm::Triple::EABI: |
| 3158 | return false; |
| 3159 | |
| 3160 | default: |
| 3161 | return (getTriple().getArch() == llvm::Triple::arm || |
| 3162 | getTriple().getArch() == llvm::Triple::thumb); |
| 3163 | } |
| 3164 | } |
| 3165 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3166 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } |
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3167 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3168 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
| Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3169 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3170 | SanitizerMask FreeBSD::getSupportedSanitizers() const { |
| 3171 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 3172 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 3173 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 3174 | getTriple().getArch() == llvm::Triple::mips64el; |
| 3175 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 3176 | Res |= SanitizerKind::Address; |
| 3177 | Res |= SanitizerKind::Vptr; |
| 3178 | if (IsX86_64 || IsMIPS64) { |
| 3179 | Res |= SanitizerKind::Leak; |
| 3180 | Res |= SanitizerKind::Thread; |
| 3181 | } |
| 3182 | if (IsX86 || IsX86_64) { |
| 3183 | Res |= SanitizerKind::SafeStack; |
| 3184 | } |
| 3185 | return Res; |
| 3186 | } |
| 3187 | |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3188 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 3189 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3190 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3191 | : Generic_ELF(D, Triple, Args) { |
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3192 | if (getDriver().UseStdLib) { |
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3193 | // When targeting a 32-bit platform, try the special directory used on |
| 3194 | // 64-bit hosts, and only fall back to the main library directory if that |
| 3195 | // doesn't work. |
| 3196 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure |
| 3197 | // what all logic is needed to emulate the '=' prefix here. |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3198 | switch (Triple.getArch()) { |
| 3199 | case llvm::Triple::x86: |
| Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3200 | getFilePaths().push_back("=/usr/lib/i386"); |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3201 | break; |
| 3202 | case llvm::Triple::arm: |
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3203 | case llvm::Triple::armeb: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3204 | case llvm::Triple::thumb: |
| Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3205 | case llvm::Triple::thumbeb: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3206 | switch (Triple.getEnvironment()) { |
| 3207 | case llvm::Triple::EABI: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3208 | case llvm::Triple::GNUEABI: |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3209 | getFilePaths().push_back("=/usr/lib/eabi"); |
| 3210 | break; |
| Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3211 | case llvm::Triple::EABIHF: |
| 3212 | case llvm::Triple::GNUEABIHF: |
| 3213 | getFilePaths().push_back("=/usr/lib/eabihf"); |
| 3214 | break; |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3215 | default: |
| 3216 | getFilePaths().push_back("=/usr/lib/oabi"); |
| 3217 | break; |
| 3218 | } |
| 3219 | break; |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3220 | case llvm::Triple::mips64: |
| 3221 | case llvm::Triple::mips64el: |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3222 | if (tools::mips::hasMipsAbiArg(Args, "o32")) |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3223 | getFilePaths().push_back("=/usr/lib/o32"); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3224 | else if (tools::mips::hasMipsAbiArg(Args, "64")) |
| Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3225 | getFilePaths().push_back("=/usr/lib/64"); |
| 3226 | break; |
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3227 | case llvm::Triple::ppc: |
| 3228 | getFilePaths().push_back("=/usr/lib/powerpc"); |
| 3229 | break; |
| Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3230 | case llvm::Triple::sparc: |
| 3231 | getFilePaths().push_back("=/usr/lib/sparc"); |
| 3232 | break; |
| Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3233 | default: |
| 3234 | break; |
| 3235 | } |
| Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3236 | |
| 3237 | getFilePaths().push_back("=/usr/lib"); |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3241 | Tool *NetBSD::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3242 | return new tools::netbsd::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3245 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } |
| Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3246 | |
| Jonas Hahnfeld | 0995419 | 2016-03-14 14:34:04 +0000 | [diff] [blame] | 3247 | ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const { |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3248 | unsigned Major, Minor, Micro; |
| 3249 | getTriple().getOSVersion(Major, Minor, Micro); |
| Joerg Sonnenberger | 21156e8 | 2016-02-11 23:35:03 +0000 | [diff] [blame] | 3250 | if (Major >= 7 || Major == 0) { |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3251 | switch (getArch()) { |
| Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3252 | case llvm::Triple::aarch64: |
| Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3253 | case llvm::Triple::arm: |
| 3254 | case llvm::Triple::armeb: |
| 3255 | case llvm::Triple::thumb: |
| 3256 | case llvm::Triple::thumbeb: |
| Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3257 | case llvm::Triple::ppc: |
| Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3258 | case llvm::Triple::ppc64: |
| 3259 | case llvm::Triple::ppc64le: |
| Joerg Sonnenberger | 059613c | 2016-02-11 23:18:36 +0000 | [diff] [blame] | 3260 | case llvm::Triple::sparc: |
| 3261 | case llvm::Triple::sparcv9: |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3262 | case llvm::Triple::x86: |
| 3263 | case llvm::Triple::x86_64: |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3264 | return ToolChain::CST_Libcxx; |
| Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3265 | default: |
| 3266 | break; |
| 3267 | } |
| Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3268 | } |
| Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3269 | return ToolChain::CST_Libstdcxx; |
| 3270 | } |
| 3271 | |
| 3272 | void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3273 | ArgStringList &CC1Args) const { |
| 3274 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3275 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3276 | return; |
| 3277 | |
| 3278 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3279 | case ToolChain::CST_Libcxx: |
| 3280 | addSystemInclude(DriverArgs, CC1Args, |
| 3281 | getDriver().SysRoot + "/usr/include/c++/"); |
| 3282 | break; |
| 3283 | case ToolChain::CST_Libstdcxx: |
| 3284 | addSystemInclude(DriverArgs, CC1Args, |
| 3285 | getDriver().SysRoot + "/usr/include/g++"); |
| 3286 | addSystemInclude(DriverArgs, CC1Args, |
| 3287 | getDriver().SysRoot + "/usr/include/g++/backward"); |
| 3288 | break; |
| 3289 | } |
| 3290 | } |
| 3291 | |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3292 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 3293 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3294 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3295 | : Generic_ELF(D, Triple, Args) { |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3296 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3297 | getFilePaths().push_back("/usr/lib"); |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3298 | } |
| 3299 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3300 | Tool *Minix::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3301 | return new tools::minix::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3304 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } |
| Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3305 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3306 | static void addPathIfExists(const Driver &D, const Twine &Path, |
| 3307 | ToolChain::path_list &Paths) { |
| 3308 | if (D.getVFS().exists(Path)) |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3309 | Paths.push_back(Path.str()); |
| 3310 | } |
| 3311 | |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3312 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. |
| 3313 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3314 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3315 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3316 | : Generic_GCC(D, Triple, Args) { |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3317 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3318 | GCCInstallation.init(Triple, Args); |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3319 | |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3320 | path_list &Paths = getFilePaths(); |
| 3321 | if (GCCInstallation.isValid()) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3322 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3323 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3324 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3325 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3326 | addPathIfExists(D, getDriver().Dir, Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3327 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3328 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); |
| Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3329 | |
| 3330 | std::string LibPath = "/usr/lib/"; |
| 3331 | switch (Triple.getArch()) { |
| 3332 | case llvm::Triple::x86: |
| 3333 | case llvm::Triple::sparc: |
| 3334 | break; |
| 3335 | case llvm::Triple::x86_64: |
| 3336 | LibPath += "amd64/"; |
| 3337 | break; |
| 3338 | case llvm::Triple::sparcv9: |
| 3339 | LibPath += "sparcv9/"; |
| 3340 | break; |
| 3341 | default: |
| 3342 | llvm_unreachable("Unsupported architecture"); |
| 3343 | } |
| 3344 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3345 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); |
| David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3348 | Tool *Solaris::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3349 | return new tools::solaris::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3350 | } |
| 3351 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3352 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } |
| Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3353 | |
| Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3354 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3355 | ArgStringList &CC1Args) const { |
| 3356 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3357 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3358 | return; |
| 3359 | |
| 3360 | // Include the support directory for things like xlocale and fudged system |
| 3361 | // headers. |
| 3362 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); |
| 3363 | |
| 3364 | if (GCCInstallation.isValid()) { |
| 3365 | GCCVersion Version = GCCInstallation.getVersion(); |
| 3366 | addSystemInclude(DriverArgs, CC1Args, |
| 3367 | getDriver().SysRoot + "/usr/gcc/" + |
| 3368 | Version.MajorStr + "." + |
| 3369 | Version.MinorStr + |
| 3370 | "/include/c++/" + Version.Text); |
| 3371 | addSystemInclude(DriverArgs, CC1Args, |
| 3372 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + |
| 3373 | "." + Version.MinorStr + "/include/c++/" + |
| 3374 | Version.Text + "/" + |
| 3375 | GCCInstallation.getTriple().str()); |
| 3376 | } |
| 3377 | } |
| 3378 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3379 | /// Distribution (very bare-bones at the moment). |
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3380 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3381 | enum Distro { |
| Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3382 | // NB: Releases of a particular Linux distro should be kept together |
| 3383 | // in this enum, because some tests are done by integer comparison against |
| 3384 | // the first and last known member in the family, e.g. IsRedHat(). |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3385 | ArchLinux, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3386 | DebianLenny, |
| 3387 | DebianSqueeze, |
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3388 | DebianWheezy, |
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3389 | DebianJessie, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3390 | DebianStretch, |
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3391 | Exherbo, |
| Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3392 | RHEL5, |
| 3393 | RHEL6, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3394 | RHEL7, |
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3395 | Fedora, |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3396 | OpenSUSE, |
| Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3397 | UbuntuHardy, |
| 3398 | UbuntuIntrepid, |
| Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3399 | UbuntuJaunty, |
| Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3400 | UbuntuKarmic, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3401 | UbuntuLucid, |
| 3402 | UbuntuMaverick, |
| Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3403 | UbuntuNatty, |
| Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3404 | UbuntuOneiric, |
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3405 | UbuntuPrecise, |
| Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3406 | UbuntuQuantal, |
| 3407 | UbuntuRaring, |
| Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3408 | UbuntuSaucy, |
| Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3409 | UbuntuTrusty, |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3410 | UbuntuUtopic, |
| 3411 | UbuntuVivid, |
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3412 | UbuntuWily, |
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3413 | UbuntuXenial, |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3414 | UnknownDistro |
| 3415 | }; |
| 3416 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3417 | static bool IsRedhat(enum Distro Distro) { |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3418 | return Distro == Fedora || (Distro >= RHEL5 && Distro <= RHEL7); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3419 | } |
| 3420 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3421 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3422 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3423 | static bool IsDebian(enum Distro Distro) { |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3424 | return Distro >= DebianLenny && Distro <= DebianStretch; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3425 | } |
| 3426 | |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3427 | static bool IsUbuntu(enum Distro Distro) { |
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3428 | return Distro >= UbuntuHardy && Distro <= UbuntuXenial; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3431 | static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3432 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = |
| 3433 | llvm::MemoryBuffer::getFile("/etc/lsb-release"); |
| 3434 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3435 | StringRef Data = File.get()->getBuffer(); |
| Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3436 | SmallVector<StringRef, 16> Lines; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3437 | Data.split(Lines, "\n"); |
| Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3438 | Distro Version = UnknownDistro; |
| Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3439 | for (StringRef Line : Lines) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3440 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) |
| 3441 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) |
| 3442 | .Case("hardy", UbuntuHardy) |
| 3443 | .Case("intrepid", UbuntuIntrepid) |
| 3444 | .Case("jaunty", UbuntuJaunty) |
| 3445 | .Case("karmic", UbuntuKarmic) |
| 3446 | .Case("lucid", UbuntuLucid) |
| 3447 | .Case("maverick", UbuntuMaverick) |
| 3448 | .Case("natty", UbuntuNatty) |
| 3449 | .Case("oneiric", UbuntuOneiric) |
| 3450 | .Case("precise", UbuntuPrecise) |
| 3451 | .Case("quantal", UbuntuQuantal) |
| 3452 | .Case("raring", UbuntuRaring) |
| 3453 | .Case("saucy", UbuntuSaucy) |
| 3454 | .Case("trusty", UbuntuTrusty) |
| 3455 | .Case("utopic", UbuntuUtopic) |
| 3456 | .Case("vivid", UbuntuVivid) |
| Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3457 | .Case("wily", UbuntuWily) |
| Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3458 | .Case("xenial", UbuntuXenial) |
| Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3459 | .Default(UnknownDistro); |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3460 | if (Version != UnknownDistro) |
| 3461 | return Version; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3464 | File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); |
| 3465 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3466 | StringRef Data = File.get()->getBuffer(); |
| Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3467 | if (Data.startswith("Fedora release")) |
| 3468 | return Fedora; |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3469 | if (Data.startswith("Red Hat Enterprise Linux") || |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3470 | Data.startswith("CentOS") || |
| 3471 | Data.startswith("Scientific Linux")) { |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3472 | if (Data.find("release 7") != StringRef::npos) |
| 3473 | return RHEL7; |
| 3474 | else if (Data.find("release 6") != StringRef::npos) |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3475 | return RHEL6; |
| 3476 | else if (Data.find("release 5") != StringRef::npos) |
| 3477 | return RHEL5; |
| Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3478 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3479 | return UnknownDistro; |
| 3480 | } |
| 3481 | |
| Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3482 | File = llvm::MemoryBuffer::getFile("/etc/debian_version"); |
| 3483 | if (File) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3484 | StringRef Data = File.get()->getBuffer(); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3485 | if (Data[0] == '5') |
| 3486 | return DebianLenny; |
| Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 3487 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3488 | return DebianSqueeze; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3489 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') |
| Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3490 | return DebianWheezy; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3491 | else if (Data.startswith("jessie/sid") || Data[0] == '8') |
| Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3492 | return DebianJessie; |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3493 | else if (Data.startswith("stretch/sid") || Data[0] == '9') |
| 3494 | return DebianStretch; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3495 | return UnknownDistro; |
| 3496 | } |
| 3497 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3498 | if (D.getVFS().exists("/etc/SuSE-release")) |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3499 | return OpenSUSE; |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3500 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3501 | if (D.getVFS().exists("/etc/exherbo-release")) |
| Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3502 | return Exherbo; |
| 3503 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3504 | if (D.getVFS().exists("/etc/arch-release")) |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3505 | return ArchLinux; |
| 3506 | |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3507 | return UnknownDistro; |
| 3508 | } |
| 3509 | |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3510 | /// \brief Get our best guess at the multiarch triple for a target. |
| 3511 | /// |
| 3512 | /// Debian-based systems are starting to use a multiarch setup where they use |
| 3513 | /// a target-triple directory in the library and header search paths. |
| 3514 | /// Unfortunately, this triple does not align with the vanilla target triple, |
| 3515 | /// so we provide a rough mapping here. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3516 | static std::string getMultiarchTriple(const Driver &D, |
| 3517 | const llvm::Triple &TargetTriple, |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3518 | StringRef SysRoot) { |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 3519 | llvm::Triple::EnvironmentType TargetEnvironment = |
| 3520 | TargetTriple.getEnvironment(); |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3521 | |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3522 | // For most architectures, just use whatever we have rather than trying to be |
| 3523 | // clever. |
| 3524 | switch (TargetTriple.getArch()) { |
| 3525 | default: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3526 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3527 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3528 | // We use the existence of '/lib/<triple>' as a directory to detect some |
| 3529 | // common linux triples that don't quite match the Clang triple for both |
| 3530 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
| 3531 | // regardless of what the actual target triple is. |
| Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 3532 | case llvm::Triple::arm: |
| 3533 | case llvm::Triple::thumb: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3534 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3535 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3536 | return "arm-linux-gnueabihf"; |
| 3537 | } else { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3538 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3539 | return "arm-linux-gnueabi"; |
| 3540 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3541 | break; |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3542 | case llvm::Triple::armeb: |
| 3543 | case llvm::Triple::thumbeb: |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3544 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3545 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3546 | return "armeb-linux-gnueabihf"; |
| 3547 | } else { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3548 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) |
| Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3549 | return "armeb-linux-gnueabi"; |
| 3550 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3551 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3552 | case llvm::Triple::x86: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3553 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3554 | return "i386-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3555 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3556 | case llvm::Triple::x86_64: |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3557 | // 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] | 3558 | if (TargetEnvironment != llvm::Triple::GNUX32 && |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3559 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3560 | return "x86_64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3561 | break; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3562 | case llvm::Triple::aarch64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3563 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3564 | return "aarch64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3565 | break; |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3566 | case llvm::Triple::aarch64_be: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3567 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) |
| Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3568 | return "aarch64_be-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3569 | break; |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3570 | case llvm::Triple::mips: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3571 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3572 | return "mips-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3573 | break; |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3574 | case llvm::Triple::mipsel: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3575 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) |
| Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3576 | return "mipsel-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3577 | break; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3578 | case llvm::Triple::mips64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3579 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3580 | return "mips64-linux-gnu"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3581 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3582 | return "mips64-linux-gnuabi64"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3583 | break; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3584 | case llvm::Triple::mips64el: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3585 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3586 | return "mips64el-linux-gnu"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3587 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3588 | return "mips64el-linux-gnuabi64"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3589 | break; |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3590 | case llvm::Triple::ppc: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3591 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) |
| Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 3592 | return "powerpc-linux-gnuspe"; |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3593 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3594 | return "powerpc-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3595 | break; |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3596 | case llvm::Triple::ppc64: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3597 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) |
| Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3598 | return "powerpc64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3599 | break; |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3600 | case llvm::Triple::ppc64le: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3601 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) |
| Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3602 | return "powerpc64le-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3603 | break; |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3604 | case llvm::Triple::sparc: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3605 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3606 | return "sparc-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3607 | break; |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3608 | case llvm::Triple::sparcv9: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3609 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) |
| James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3610 | return "sparc64-linux-gnu"; |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3611 | break; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3612 | case llvm::Triple::systemz: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3613 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3614 | return "s390x-linux-gnu"; |
| 3615 | break; |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3616 | } |
| Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3617 | return TargetTriple.str(); |
| Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3620 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3621 | if (isMipsArch(Triple.getArch())) { |
| 3622 | // lib32 directory has a special meaning on MIPS targets. |
| 3623 | // It contains N32 ABI binaries. Use this folder if produce |
| 3624 | // code for N32 ABI only. |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3625 | if (tools::mips::hasMipsAbiArg(Args, "n32")) |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3626 | return "lib32"; |
| 3627 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 3628 | } |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3629 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3630 | // 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] | 3631 | // using that variant while targeting other architectures causes problems |
| 3632 | // 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] | 3633 | // with a 'lib32' library search path being considered. So we only enable |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3634 | // them when we know we may need it. |
| 3635 | // |
| 3636 | // 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] | 3637 | // reasoning about oslibdir spellings with the lib dir spellings in the |
| Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3638 | // GCCInstallationDetector, but that is a more significant refactoring. |
| 3639 | if (Triple.getArch() == llvm::Triple::x86 || |
| 3640 | Triple.getArch() == llvm::Triple::ppc) |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3641 | return "lib32"; |
| 3642 | |
| Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3643 | if (Triple.getArch() == llvm::Triple::x86_64 && |
| 3644 | Triple.getEnvironment() == llvm::Triple::GNUX32) |
| 3645 | return "libx32"; |
| 3646 | |
| Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3647 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 3648 | } |
| 3649 | |
| Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3650 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3651 | : Generic_ELF(D, Triple, Args) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3652 | GCCInstallation.init(Triple, Args); |
| 3653 | CudaInstallation.init(Triple, Args); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3654 | Multilibs = GCCInstallation.getMultilibs(); |
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3655 | llvm::Triple::ArchType Arch = Triple.getArch(); |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3656 | std::string SysRoot = computeSysRoot(); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3657 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3658 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at |
| Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 3659 | // least) put various tools in a triple-prefixed directory off of the parent |
| 3660 | // of the GCC installation. We use the GCC triple here to ensure that we end |
| 3661 | // up with tools that support the same amount of cross compiling as the |
| 3662 | // detected GCC installation. For example, if we find a GCC installation |
| 3663 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be |
| 3664 | // used to target i386. |
| 3665 | // FIXME: This seems unlikely to be Linux-specific. |
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3666 | ToolChain::path_list &PPaths = getProgramPaths(); |
| Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 3667 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3668 | GCCInstallation.getTriple().str() + "/bin") |
| 3669 | .str()); |
| Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3670 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3671 | Distro Distro = DetectDistro(D, Arch); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3672 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3673 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { |
| Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 3674 | ExtraOpts.push_back("-z"); |
| 3675 | ExtraOpts.push_back("relro"); |
| 3676 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3677 | |
| Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3678 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3679 | ExtraOpts.push_back("-X"); |
| 3680 | |
| Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 3681 | const bool IsAndroid = Triple.isAndroid(); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3682 | const bool IsMips = isMipsArch(Arch); |
| 3683 | |
| 3684 | if (IsMips && !SysRoot.empty()) |
| 3685 | ExtraOpts.push_back("--sysroot=" + SysRoot); |
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3686 | |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3687 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
| 3688 | // and the MIPS ABI require .dynsym to be sorted in different ways. |
| 3689 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
| 3690 | // ABI requires a mapping between the GOT and the symbol table. |
| Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3691 | // Android loader does not support .gnu.hash. |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3692 | if (!IsMips && !IsAndroid) { |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3693 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || |
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3694 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3695 | ExtraOpts.push_back("--hash-style=gnu"); |
| 3696 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3697 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || |
| Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3698 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) |
| 3699 | ExtraOpts.push_back("--hash-style=both"); |
| 3700 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3701 | |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3702 | if (IsRedhat(Distro) && Distro != RHEL5 && Distro != RHEL6) |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3703 | ExtraOpts.push_back("--no-add-needed"); |
| 3704 | |
| Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3705 | if ((IsDebian(Distro) && Distro >= DebianSqueeze) || IsOpenSUSE(Distro) || |
| Rafael Espindola | 52fe896 | 2016-05-09 13:13:50 +0000 | [diff] [blame] | 3706 | (IsRedhat(Distro) && Distro != RHEL5) || |
| Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3707 | (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3708 | ExtraOpts.push_back("--build-id"); |
| 3709 | |
| Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3710 | if (IsOpenSUSE(Distro)) |
| Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 3711 | ExtraOpts.push_back("--enable-new-dtags"); |
| Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 3712 | |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3713 | // The selection of paths to try here is designed to match the patterns which |
| 3714 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
| 3715 | // This was determined by running GCC in a fake filesystem, creating all |
| 3716 | // possible permutations of these directories, and seeing which ones it added |
| 3717 | // to the link paths. |
| 3718 | path_list &Paths = getFilePaths(); |
| Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3719 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3720 | const std::string OSLibDir = getOSLibDir(Triple, Args); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3721 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3722 | |
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3723 | // Add the multilib suffixed paths where they are available. |
| 3724 | if (GCCInstallation.isValid()) { |
| Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 3725 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3726 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3727 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 3728 | |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3729 | // Sourcery CodeBench MIPS toolchain holds some libraries under |
| Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 3730 | // a biarch-like suffix of the GCC installation. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3731 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3732 | Paths); |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3733 | |
| 3734 | // GCC cross compiling toolchains will install target libraries which ship |
| 3735 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as |
| 3736 | // any part of the GCC installation in |
| 3737 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat |
| 3738 | // debatable, but is the reality today. We need to search this tree even |
| 3739 | // when we have a sysroot somewhere else. It is the responsibility of |
| Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 3740 | // whomever is doing the cross build targeting a sysroot using a GCC |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3741 | // installation that is *not* within the system root to ensure two things: |
| 3742 | // |
| 3743 | // 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] | 3744 | // above must be present on the system root and found via an |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3745 | // appropriate rpath. |
| 3746 | // 2) There must not be libraries installed into |
| 3747 | // <prefix>/<triple>/<libdir> unless they should be preferred over |
| 3748 | // those within the system root. |
| 3749 | // |
| 3750 | // Note that this matches the GCC behavior. See the below comment for where |
| 3751 | // Clang diverges from GCC's behavior. |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3752 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + |
| 3753 | OSLibDir + Multilib.osSuffix(), |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3754 | Paths); |
| 3755 | |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3756 | // If the GCC installation we found is inside of the sysroot, we want to |
| 3757 | // prefer libraries installed in the parent prefix of the GCC installation. |
| 3758 | // 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] | 3759 | // outside of the system root as that can pick up unintended libraries. |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3760 | // This usually happens when there is an external cross compiler on the |
| 3761 | // 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] | 3762 | // the cross. Note that GCC does include some of these directories in some |
| 3763 | // configurations but this seems somewhere between questionable and simply |
| 3764 | // a bug. |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3765 | if (StringRef(LibPath).startswith(SysRoot)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3766 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); |
| 3767 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3768 | } |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3769 | } |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3770 | |
| 3771 | // 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] | 3772 | // of the requested system root, add its parent library paths to |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3773 | // those searched. |
| 3774 | // FIXME: It's not clear whether we should use the driver's installed |
| 3775 | // directory ('Dir' below) or the ResourceDir. |
| 3776 | if (StringRef(D.Dir).startswith(SysRoot)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3777 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); |
| 3778 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3779 | } |
| 3780 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3781 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); |
| 3782 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); |
| 3783 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); |
| 3784 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); |
| Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3785 | |
| Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 3786 | // 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] | 3787 | // installations with strange symlinks. |
| Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 3788 | if (GCCInstallation.isValid()) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3789 | addPathIfExists(D, |
| 3790 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3791 | "/../../" + OSLibDir, |
| 3792 | Paths); |
| Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 3793 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3794 | // Add the 'other' biarch variant path |
| 3795 | Multilib BiarchSibling; |
| 3796 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3797 | addPathIfExists(D, GCCInstallation.getInstallPath() + |
| 3798 | BiarchSibling.gccSuffix(), |
| 3799 | Paths); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3800 | } |
| Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3801 | |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3802 | // See comments above on the multilib variant for details of why this is |
| 3803 | // included even from outside the sysroot. |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3804 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| 3805 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| 3806 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3807 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + |
| 3808 | Multilib.osSuffix(), |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3809 | Paths); |
| Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3810 | |
| 3811 | // See comments above on the multilib variant for details of why this is |
| 3812 | // only included from within the sysroot. |
| 3813 | if (StringRef(LibPath).startswith(SysRoot)) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3814 | addPathIfExists(D, LibPath, Paths); |
| Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3815 | } |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3816 | |
| 3817 | // Similar to the logic for GCC above, if we are currently running Clang |
| 3818 | // inside of the requested system root, add its parent library path to those |
| 3819 | // searched. |
| 3820 | // FIXME: It's not clear whether we should use the driver's installed |
| 3821 | // directory ('Dir' below) or the ResourceDir. |
| 3822 | if (StringRef(D.Dir).startswith(SysRoot)) |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3823 | addPathIfExists(D, D.Dir + "/../lib", Paths); |
| Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3824 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3825 | addPathIfExists(D, SysRoot + "/lib", Paths); |
| 3826 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); |
| Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3827 | } |
| 3828 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3829 | bool Linux::HasNativeLLVMSupport() const { return true; } |
| Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3830 | |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3831 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3832 | |
| 3833 | Tool *Linux::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3834 | return new tools::gnutools::Assembler(*this); |
| Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3837 | std::string Linux::computeSysRoot() const { |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3838 | if (!getDriver().SysRoot.empty()) |
| 3839 | return getDriver().SysRoot; |
| 3840 | |
| 3841 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) |
| 3842 | return std::string(); |
| 3843 | |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3844 | // Standalone MIPS toolchains use different names for sysroot folder |
| 3845 | // and put it into different places. Here we try to check some known |
| 3846 | // variants. |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3847 | |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3848 | const StringRef InstallDir = GCCInstallation.getInstallPath(); |
| 3849 | const StringRef TripleStr = GCCInstallation.getTriple().str(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3850 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3851 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3852 | std::string Path = |
| 3853 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) |
| 3854 | .str(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3855 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3856 | if (getVFS().exists(Path)) |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3857 | return Path; |
| 3858 | |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3859 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3860 | |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3861 | if (getVFS().exists(Path)) |
| Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3862 | return Path; |
| 3863 | |
| 3864 | return std::string(); |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| Saleem Abdulrasool | 783fc63 | 2016-05-22 03:12:19 +0000 | [diff] [blame] | 3867 | std::string Linux::getDynamicLinker(const ArgList &Args) const { |
| 3868 | const llvm::Triple::ArchType Arch = getArch(); |
| 3869 | const llvm::Triple &Triple = getTriple(); |
| 3870 | |
| 3871 | if (Triple.isAndroid()) |
| 3872 | return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; |
| 3873 | |
| 3874 | switch (Arch) { |
| 3875 | default: llvm_unreachable("unsupported architecture"); |
| 3876 | |
| 3877 | case llvm::Triple::aarch64: |
| 3878 | return "/lib/ld-linux-aarch64.so.1"; |
| 3879 | case llvm::Triple::aarch64_be: |
| 3880 | return "/lib/ld-linux-aarch64_be.so.1"; |
| 3881 | case llvm::Triple::arm: |
| 3882 | case llvm::Triple::thumb: |
| 3883 | case llvm::Triple::armeb: |
| 3884 | case llvm::Triple::thumbeb: { |
| 3885 | const bool IsHardFloat = |
| 3886 | Triple.getEnvironment() == llvm::Triple::GNUEABIHF || |
| 3887 | tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard; |
| 3888 | |
| 3889 | return IsHardFloat ? "/lib/ld-linux-armhf.so.3" : "/lib/ld-linux.so.3"; |
| 3890 | } |
| 3891 | case llvm::Triple::mips: |
| 3892 | case llvm::Triple::mipsel: |
| 3893 | case llvm::Triple::mips64: |
| 3894 | case llvm::Triple::mips64el: { |
| 3895 | bool IsNaN2008 = tools::mips::isNaN2008(Args, Triple); |
| 3896 | bool LE = (Triple.getArch() == llvm::Triple::mipsel) || |
| 3897 | (Triple.getArch() == llvm::Triple::mips64el); |
| 3898 | |
| 3899 | std::string LibDir = |
| 3900 | "/lib" + tools::mips::getMipsABILibSuffix(Args, Triple); |
| 3901 | StringRef LibName; |
| 3902 | if (tools::mips::isUCLibc(Args)) |
| 3903 | LibName = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0"; |
| 3904 | else if (!Triple.hasEnvironment() && |
| 3905 | Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies) |
| 3906 | LibName = LE ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1"; |
| 3907 | else |
| 3908 | LibName = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1"; |
| 3909 | |
| 3910 | return (LibDir + "/" + LibName).str(); |
| 3911 | } |
| 3912 | case llvm::Triple::ppc: |
| 3913 | return "/lib/ld.so.1"; |
| 3914 | case llvm::Triple::ppc64: |
| 3915 | return (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "/lib64/ld64.so.2" |
| 3916 | : "/lib64/ld64.so.1"; |
| 3917 | case llvm::Triple::ppc64le: |
| 3918 | return (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "/lib64/ld64.so.1" |
| 3919 | : "/lib64/ld64.so.2"; |
| 3920 | case llvm::Triple::sparc: |
| 3921 | case llvm::Triple::sparcel: |
| 3922 | return "/lib/ld-linux.so.2"; |
| 3923 | case llvm::Triple::sparcv9: |
| 3924 | return "/lib64/ld-linux.so.2"; |
| 3925 | case llvm::Triple::systemz: |
| 3926 | return "/lib/ld64.so.1"; |
| 3927 | case llvm::Triple::x86: |
| 3928 | return "/lib/ld-linux.so.2"; |
| 3929 | case llvm::Triple::x86_64: |
| 3930 | return (Triple.getEnvironment() == llvm::Triple::GNUX32) |
| 3931 | ? "/libx32/ld-linux-x32.so.2" |
| 3932 | : "/lib64/ld-linux-x86-64.so.2"; |
| 3933 | } |
| 3934 | } |
| 3935 | |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3936 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3937 | ArgStringList &CC1Args) const { |
| 3938 | const Driver &D = getDriver(); |
| Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3939 | std::string SysRoot = computeSysRoot(); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3940 | |
| 3941 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 3942 | return; |
| 3943 | |
| 3944 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3945 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3946 | |
| 3947 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 3948 | SmallString<128> P(D.ResourceDir); |
| 3949 | llvm::sys::path::append(P, "include"); |
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3950 | addSystemInclude(DriverArgs, CC1Args, P); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3954 | return; |
| 3955 | |
| 3956 | // Check for configure-time C include directories. |
| 3957 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 3958 | if (CIncludeDirs != "") { |
| 3959 | SmallVector<StringRef, 5> dirs; |
| 3960 | CIncludeDirs.split(dirs, ":"); |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3961 | for (StringRef dir : dirs) { |
| Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 3962 | StringRef Prefix = |
| 3963 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3964 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3965 | } |
| 3966 | return; |
| 3967 | } |
| 3968 | |
| 3969 | // Lacking those, try to detect the correct set of system includes for the |
| 3970 | // target triple. |
| 3971 | |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3972 | // Add include directories specific to the selected multilib set and multilib. |
| 3973 | if (GCCInstallation.isValid()) { |
| Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 3974 | const auto &Callback = Multilibs.includeDirsCallback(); |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3975 | if (Callback) { |
| Simon Atanasyan | a45502d | 2016-05-19 15:07:21 +0000 | [diff] [blame] | 3976 | for (const auto &Path : Callback(GCCInstallation.getMultilib())) |
| 3977 | addExternCSystemIncludeIfExists( |
| 3978 | DriverArgs, CC1Args, GCCInstallation.getInstallPath() + Path); |
| Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3979 | } |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3980 | } |
| 3981 | |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3982 | // Implement generic Debian multiarch support. |
| 3983 | const StringRef X86_64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3984 | "/usr/include/x86_64-linux-gnu", |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3985 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3986 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 3987 | // in use in any released version of Debian, so we should consider |
| 3988 | // removing them. |
| 3989 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3990 | const StringRef X86MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3991 | "/usr/include/i386-linux-gnu", |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3992 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3993 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 3994 | // in use in any released version of Debian, so we should consider |
| 3995 | // removing them. |
| 3996 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", |
| 3997 | "/usr/include/i486-linux-gnu"}; |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3998 | const StringRef AArch64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3999 | "/usr/include/aarch64-linux-gnu"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4000 | const StringRef ARMMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4001 | "/usr/include/arm-linux-gnueabi"}; |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4002 | const StringRef ARMHFMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4003 | "/usr/include/arm-linux-gnueabihf"}; |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4004 | const StringRef ARMEBMultiarchIncludeDirs[] = { |
| 4005 | "/usr/include/armeb-linux-gnueabi"}; |
| 4006 | const StringRef ARMEBHFMultiarchIncludeDirs[] = { |
| 4007 | "/usr/include/armeb-linux-gnueabihf"}; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4008 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4009 | const StringRef MIPSELMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4010 | "/usr/include/mipsel-linux-gnu"}; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4011 | const StringRef MIPS64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4012 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4013 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4014 | "/usr/include/mips64el-linux-gnu", |
| 4015 | "/usr/include/mips64el-linux-gnuabi64"}; |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4016 | const StringRef PPCMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4017 | "/usr/include/powerpc-linux-gnu"}; |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4018 | const StringRef PPC64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4019 | "/usr/include/powerpc64-linux-gnu"}; |
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4020 | const StringRef PPC64LEMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4021 | "/usr/include/powerpc64le-linux-gnu"}; |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4022 | const StringRef SparcMultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4023 | "/usr/include/sparc-linux-gnu"}; |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4024 | const StringRef Sparc64MultiarchIncludeDirs[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4025 | "/usr/include/sparc64-linux-gnu"}; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4026 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { |
| 4027 | "/usr/include/s390x-linux-gnu"}; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4028 | ArrayRef<StringRef> MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4029 | switch (getTriple().getArch()) { |
| 4030 | case llvm::Triple::x86_64: |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4031 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4032 | break; |
| 4033 | case llvm::Triple::x86: |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4034 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4035 | break; |
| 4036 | case llvm::Triple::aarch64: |
| 4037 | case llvm::Triple::aarch64_be: |
| Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 4038 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4039 | break; |
| 4040 | case llvm::Triple::arm: |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4041 | case llvm::Triple::thumb: |
| Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 4042 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 4043 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; |
| 4044 | else |
| 4045 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4046 | break; |
| Saleem Abdulrasool | 20f733a | 2015-12-11 06:20:59 +0000 | [diff] [blame] | 4047 | case llvm::Triple::armeb: |
| 4048 | case llvm::Triple::thumbeb: |
| 4049 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 4050 | MultiarchIncludeDirs = ARMEBHFMultiarchIncludeDirs; |
| 4051 | else |
| 4052 | MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs; |
| 4053 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4054 | case llvm::Triple::mips: |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4055 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4056 | break; |
| 4057 | case llvm::Triple::mipsel: |
| Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 4058 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4059 | break; |
| 4060 | case llvm::Triple::mips64: |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4061 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4062 | break; |
| 4063 | case llvm::Triple::mips64el: |
| Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 4064 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4065 | break; |
| 4066 | case llvm::Triple::ppc: |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4067 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4068 | break; |
| 4069 | case llvm::Triple::ppc64: |
| Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4070 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4071 | break; |
| 4072 | case llvm::Triple::ppc64le: |
| Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4073 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4074 | break; |
| 4075 | case llvm::Triple::sparc: |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4076 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4077 | break; |
| 4078 | case llvm::Triple::sparcv9: |
| James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4079 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4080 | break; |
| Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4081 | case llvm::Triple::systemz: |
| 4082 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; |
| 4083 | break; |
| Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4084 | default: |
| 4085 | break; |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4086 | } |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4087 | for (StringRef Dir : MultiarchIncludeDirs) { |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4088 | if (D.getVFS().exists(SysRoot + Dir)) { |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4089 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); |
| Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4090 | break; |
| 4091 | } |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | if (getTriple().getOS() == llvm::Triple::RTEMS) |
| 4095 | return; |
| 4096 | |
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4097 | // Add an include of '/include' directly. This isn't provided by default by |
| 4098 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 4099 | // 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] | 4100 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); |
| Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4101 | |
| Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4102 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4103 | } |
| 4104 | |
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4105 | static std::string DetectLibcxxIncludePath(StringRef base) { |
| 4106 | std::error_code EC; |
| 4107 | int MaxVersion = 0; |
| 4108 | std::string MaxVersionString = ""; |
| 4109 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; |
| 4110 | LI = LI.increment(EC)) { |
| 4111 | StringRef VersionText = llvm::sys::path::filename(LI->path()); |
| 4112 | int Version; |
| 4113 | if (VersionText[0] == 'v' && |
| 4114 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { |
| 4115 | if (Version > MaxVersion) { |
| 4116 | MaxVersion = Version; |
| 4117 | MaxVersionString = VersionText; |
| 4118 | } |
| 4119 | } |
| 4120 | } |
| 4121 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; |
| 4122 | } |
| 4123 | |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4124 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 4125 | ArgStringList &CC1Args) const { |
| 4126 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4127 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4128 | return; |
| 4129 | |
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4130 | // Check if libc++ has been enabled and provide its include paths if so. |
| 4131 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4132 | const std::string LibCXXIncludePathCandidates[] = { |
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4133 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), |
| Yaron Keren | 5439b64 | 2016-05-17 19:01:16 +0000 | [diff] [blame] | 4134 | // If this is a development, non-installed, clang, libcxx will |
| 4135 | // not be found at ../include/c++ but it likely to be found at |
| 4136 | // one of the following two locations: |
| 4137 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/local/include/c++"), |
| 4138 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++") }; |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4139 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { |
| Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4140 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4141 | continue; |
| 4142 | // Add the first candidate that exists. |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4143 | addSystemInclude(DriverArgs, CC1Args, IncludePath); |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4144 | break; |
| 4145 | } |
| Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4146 | return; |
| 4147 | } |
| 4148 | |
| Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 4149 | // We need a detected GCC installation on Linux to provide libstdc++'s |
| 4150 | // headers. We handled the libc++ case above. |
| 4151 | if (!GCCInstallation.isValid()) |
| 4152 | return; |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4153 | |
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4154 | // By default, look for the C++ headers in an include directory adjacent to |
| 4155 | // the lib directory of the GCC installation. Note that this is expect to be |
| 4156 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. |
| 4157 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4158 | StringRef InstallDir = GCCInstallation.getInstallPath(); |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4159 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4160 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4161 | const std::string GCCMultiarchTriple = getMultiarchTriple( |
| 4162 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4163 | const std::string TargetMultiarchTriple = |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4164 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); |
| Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 4165 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4166 | |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4167 | // The primary search for libstdc++ supports multiarch variants. |
| Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 4168 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4169 | "/c++/" + Version.Text, TripleStr, |
| 4170 | GCCMultiarchTriple, TargetMultiarchTriple, |
| Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4171 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
| Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4172 | return; |
| 4173 | |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4174 | // Otherwise, fall back on a bunch of options which don't use multiarch |
| 4175 | // layouts for simplicity. |
| Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4176 | const std::string LibStdCXXIncludePathCandidates[] = { |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4177 | // Gentoo is weird and places its headers inside the GCC install, |
| 4178 | // so if the first attempt to find the headers fails, try these patterns. |
| Chandler Carruth | 81296fb | 2016-05-08 07:59:56 +0000 | [diff] [blame] | 4179 | InstallDir.str() + "/include/g++-v" + Version.Text, |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4180 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + |
| 4181 | Version.MinorStr, |
| 4182 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, |
| 4183 | // Android standalone toolchain has C++ headers in yet another place. |
| 4184 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4185 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, |
| 4186 | // without a subdirectory corresponding to the gcc version. |
| 4187 | LibDir.str() + "/../include/c++", |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4188 | }; |
| 4189 | |
| Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4190 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { |
| Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4191 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, |
| 4192 | /*GCCMultiarchTriple*/ "", |
| 4193 | /*TargetMultiarchTriple*/ "", |
| 4194 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
| Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4195 | break; |
| Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4196 | } |
| Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4197 | } |
| 4198 | |
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4199 | void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, |
| 4200 | ArgStringList &CC1Args) const { |
| 4201 | if (DriverArgs.hasArg(options::OPT_nocudainc)) |
| 4202 | return; |
| 4203 | |
| Justin Lebar | 423019d | 2016-04-16 00:11:11 +0000 | [diff] [blame] | 4204 | if (!CudaInstallation.isValid()) { |
| 4205 | getDriver().Diag(diag::err_drv_no_cuda_installation); |
| 4206 | return; |
| Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4207 | } |
| Justin Lebar | 423019d | 2016-04-16 00:11:11 +0000 | [diff] [blame] | 4208 | |
| 4209 | addSystemInclude(DriverArgs, CC1Args, CudaInstallation.getIncludePath()); |
| 4210 | CC1Args.push_back("-include"); |
| 4211 | CC1Args.push_back("__clang_cuda_runtime_wrapper.h"); |
| Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4212 | } |
| 4213 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4214 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
| Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 4215 | |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4216 | SanitizerMask Linux::getSupportedSanitizers() const { |
| 4217 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 4218 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 4219 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 4220 | getTriple().getArch() == llvm::Triple::mips64el; |
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4221 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || |
| 4222 | getTriple().getArch() == llvm::Triple::ppc64le; |
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4223 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || |
| 4224 | getTriple().getArch() == llvm::Triple::aarch64_be; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4225 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 4226 | Res |= SanitizerKind::Address; |
| 4227 | Res |= SanitizerKind::KernelAddress; |
| 4228 | Res |= SanitizerKind::Vptr; |
| Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 4229 | Res |= SanitizerKind::SafeStack; |
| Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4230 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4231 | Res |= SanitizerKind::DataFlow; |
| Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 4232 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4233 | Res |= SanitizerKind::Leak; |
| Bill Schmidt | 4b8841a | 2015-12-08 22:48:02 +0000 | [diff] [blame] | 4234 | if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64) |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4235 | Res |= SanitizerKind::Thread; |
| Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 4236 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) |
| Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4237 | Res |= SanitizerKind::Memory; |
| Derek Bruening | 256c2e1 | 2016-04-21 21:32:04 +0000 | [diff] [blame] | 4238 | if (IsX86_64) |
| 4239 | Res |= SanitizerKind::Efficiency; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4240 | if (IsX86 || IsX86_64) { |
| 4241 | Res |= SanitizerKind::Function; |
| Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4242 | } |
| 4243 | return Res; |
| 4244 | } |
| 4245 | |
| Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4246 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, |
| 4247 | llvm::opt::ArgStringList &CmdArgs) const { |
| 4248 | if (!needsProfileRT(Args)) return; |
| 4249 | |
| 4250 | // Add linker option -u__llvm_runtime_variable to cause runtime |
| 4251 | // initialization module to be linked in. |
| 4252 | if (!Args.hasArg(options::OPT_coverage)) |
| 4253 | CmdArgs.push_back(Args.MakeArgString( |
| 4254 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); |
| 4255 | ToolChain::addProfileRTLibs(Args, CmdArgs); |
| 4256 | } |
| 4257 | |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4258 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 4259 | |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4260 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, |
| 4261 | const ArgList &Args) |
| 4262 | : Generic_ELF(D, Triple, Args) { |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4263 | |
| 4264 | // Path mangling to find libexec |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4265 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 4266 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4267 | getProgramPaths().push_back(getDriver().Dir); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4268 | |
| Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4269 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4270 | getFilePaths().push_back("/usr/lib"); |
| Dimitry Andric | f59a2b3 | 2015-12-27 10:01:44 +0000 | [diff] [blame] | 4271 | getFilePaths().push_back("/usr/lib/gcc50"); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4274 | Tool *DragonFly::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4275 | return new tools::dragonfly::Assembler(*this); |
| Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | Tool *DragonFly::buildLinker() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4279 | return new tools::dragonfly::Linker(*this); |
| Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4280 | } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4281 | |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4282 | /// CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary, |
| 4283 | /// which isn't properly a linker but nonetheless performs the step of stitching |
| 4284 | /// together object files from the assembler into a single blob. |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4285 | |
| 4286 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4287 | const ArgList &Args) |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4288 | : Linux(D, Triple, Args) { |
| 4289 | if (CudaInstallation.isValid()) |
| 4290 | getProgramPaths().push_back(CudaInstallation.getBinPath()); |
| 4291 | } |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4292 | |
| 4293 | void |
| 4294 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, |
| 4295 | llvm::opt::ArgStringList &CC1Args) const { |
| 4296 | Linux::addClangTargetOptions(DriverArgs, CC1Args); |
| 4297 | CC1Args.push_back("-fcuda-is-device"); |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4298 | |
| Justin Lebar | d3a44f6 | 2016-04-05 18:26:20 +0000 | [diff] [blame] | 4299 | if (DriverArgs.hasFlag(options::OPT_fcuda_flush_denormals_to_zero, |
| 4300 | options::OPT_fno_cuda_flush_denormals_to_zero, false)) |
| 4301 | CC1Args.push_back("-fcuda-flush-denormals-to-zero"); |
| 4302 | |
| Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4303 | if (DriverArgs.hasArg(options::OPT_nocudalib)) |
| 4304 | return; |
| 4305 | |
| 4306 | std::string LibDeviceFile = CudaInstallation.getLibDeviceFile( |
| 4307 | DriverArgs.getLastArgValue(options::OPT_march_EQ)); |
| 4308 | if (!LibDeviceFile.empty()) { |
| 4309 | CC1Args.push_back("-mlink-cuda-bitcode"); |
| 4310 | CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile)); |
| 4311 | |
| 4312 | // Libdevice in CUDA-7.0 requires PTX version that's more recent |
| 4313 | // than LLVM defaults to. Use PTX4.2 which is the PTX version that |
| 4314 | // came with CUDA-7.0. |
| 4315 | CC1Args.push_back("-target-feature"); |
| 4316 | CC1Args.push_back("+ptx42"); |
| 4317 | } |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | llvm::opt::DerivedArgList * |
| 4321 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, |
| 4322 | const char *BoundArch) const { |
| 4323 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 4324 | const OptTable &Opts = getDriver().getOpts(); |
| 4325 | |
| 4326 | for (Arg *A : Args) { |
| 4327 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 4328 | // Skip this argument unless the architecture matches BoundArch |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4329 | if (!BoundArch || A->getValue(0) != StringRef(BoundArch)) |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4330 | continue; |
| 4331 | |
| 4332 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| 4333 | unsigned Prev = Index; |
| 4334 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| 4335 | |
| 4336 | // If the argument parsing failed or more than one argument was |
| 4337 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 4338 | // extra arguments. Emit an error and ignore. |
| 4339 | // |
| 4340 | // We also want to disallow any options which would alter the |
| 4341 | // driver behavior; that isn't going to work in our model. We |
| 4342 | // use isDriverOption() as an approximation, although things |
| 4343 | // like -O4 are going to slip through. |
| 4344 | if (!XarchArg || Index > Prev + 1) { |
| 4345 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| 4346 | << A->getAsString(Args); |
| 4347 | continue; |
| 4348 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| 4349 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| 4350 | << A->getAsString(Args); |
| 4351 | continue; |
| 4352 | } |
| 4353 | XarchArg->setBaseArg(A); |
| 4354 | A = XarchArg.release(); |
| 4355 | DAL->AddSynthesizedArg(A); |
| 4356 | } |
| 4357 | DAL->append(A); |
| 4358 | } |
| 4359 | |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4360 | if (BoundArch) |
| 4361 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); |
| Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4362 | return DAL; |
| 4363 | } |
| 4364 | |
| Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 4365 | Tool *CudaToolChain::buildAssembler() const { |
| 4366 | return new tools::NVPTX::Assembler(*this); |
| 4367 | } |
| 4368 | |
| 4369 | Tool *CudaToolChain::buildLinker() const { |
| 4370 | return new tools::NVPTX::Linker(*this); |
| 4371 | } |
| 4372 | |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4373 | /// XCore tool chain |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4374 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4375 | const ArgList &Args) |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4376 | : ToolChain(D, Triple, Args) { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4377 | // ProgramPaths are found via 'PATH' environment variable. |
| 4378 | } |
| 4379 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4380 | Tool *XCoreToolChain::buildAssembler() const { |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4381 | return new tools::XCore::Assembler(*this); |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4384 | Tool *XCoreToolChain::buildLinker() const { |
| 4385 | return new tools::XCore::Linker(*this); |
| 4386 | } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4387 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4388 | bool XCoreToolChain::isPICDefault() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4389 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4390 | bool XCoreToolChain::isPIEDefault() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4391 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4392 | bool XCoreToolChain::isPICDefaultForced() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4393 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4394 | bool XCoreToolChain::SupportsProfiling() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4395 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4396 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4397 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4398 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4399 | ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4400 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 4401 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 4402 | return; |
| 4403 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { |
| 4404 | SmallVector<StringRef, 4> Dirs; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4405 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4406 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4407 | ArrayRef<StringRef> DirVec(Dirs); |
| 4408 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4409 | } |
| 4410 | } |
| 4411 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4412 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, |
| 4413 | ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4414 | CC1Args.push_back("-nostdsysteminc"); |
| 4415 | } |
| 4416 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4417 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( |
| 4418 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4419 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 4420 | DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4421 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4422 | return; |
| 4423 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { |
| 4424 | SmallVector<StringRef, 4> Dirs; |
| Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4425 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4426 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4427 | ArrayRef<StringRef> DirVec(Dirs); |
| 4428 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4429 | } |
| 4430 | } |
| 4431 | |
| Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4432 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 4433 | ArgStringList &CmdArgs) const { |
| Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4434 | // We don't output any lib args. This is handled by xcc. |
| 4435 | } |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4436 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4437 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4438 | const ArgList &Args) |
| Douglas Katzman | 5eddc23 | 2016-05-09 19:09:59 +0000 | [diff] [blame] | 4439 | : Generic_ELF(D, Triple, Args) { |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4440 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use |
| 4441 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. |
| 4442 | // This won't work to find gcc. Instead we give the installation detector an |
| 4443 | // extra triple, which is preferable to further hacks of the logic that at |
| 4444 | // present is based solely on getArch(). In particular, it would be wrong to |
| 4445 | // choose the myriad installation when targeting a non-myriad sparc install. |
| 4446 | switch (Triple.getArch()) { |
| 4447 | default: |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4448 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() |
| 4449 | << "myriad"; |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4450 | case llvm::Triple::sparc: |
| 4451 | case llvm::Triple::sparcel: |
| 4452 | case llvm::Triple::shave: |
| Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4453 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4454 | } |
| Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame] | 4455 | |
| 4456 | if (GCCInstallation.isValid()) { |
| 4457 | // The contents of LibDir are independent of the version of gcc. |
| 4458 | // This contains libc, libg (a superset of libc), libm, libstdc++, libssp. |
| 4459 | SmallString<128> LibDir(GCCInstallation.getParentLibPath()); |
| 4460 | if (Triple.getArch() == llvm::Triple::sparcel) |
| 4461 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib/le"); |
| 4462 | else |
| 4463 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib"); |
| 4464 | addPathIfExists(D, LibDir, getFilePaths()); |
| 4465 | |
| 4466 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. |
| 4467 | // These files are tied to a particular version of gcc. |
| 4468 | SmallString<128> CompilerSupportDir(GCCInstallation.getInstallPath()); |
| 4469 | // There are actually 4 choices: {le,be} x {fpu,nofpu} |
| 4470 | // but as this toolchain is for LEON sparc, it can assume FPU. |
| 4471 | if (Triple.getArch() == llvm::Triple::sparcel) |
| 4472 | llvm::sys::path::append(CompilerSupportDir, "le"); |
| 4473 | addPathIfExists(D, CompilerSupportDir, getFilePaths()); |
| 4474 | } |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4477 | MyriadToolChain::~MyriadToolChain() {} |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4478 | |
| Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 4479 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4480 | ArgStringList &CC1Args) const { |
| 4481 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4482 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 4483 | } |
| 4484 | |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4485 | void MyriadToolChain::AddClangCXXStdlibIncludeArgs( |
| 4486 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4487 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4488 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4489 | return; |
| 4490 | |
| 4491 | // Only libstdc++, for now. |
| 4492 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4493 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| 4494 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| 4495 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| 4496 | |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4497 | addLibStdCXXIncludePaths( |
| 4498 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4499 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); |
| James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4500 | } |
| 4501 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4502 | // MyriadToolChain handles several triples: |
| 4503 | // {shave,sparc{,el}}-myriad-{rtems,unknown}-elf |
| 4504 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { |
| 4505 | // The inherited method works fine if not targeting the SHAVE. |
| 4506 | if (!isShaveCompilation(getTriple())) |
| 4507 | return ToolChain::SelectTool(JA); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4508 | switch (JA.getKind()) { |
| Douglas Katzman | 9dc4c62 | 2015-11-20 04:58:12 +0000 | [diff] [blame] | 4509 | case Action::PreprocessJobClass: |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4510 | case Action::CompileJobClass: |
| 4511 | if (!Compiler) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4512 | Compiler.reset(new tools::SHAVE::Compiler(*this)); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4513 | return Compiler.get(); |
| 4514 | case Action::AssembleJobClass: |
| 4515 | if (!Assembler) |
| Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4516 | Assembler.reset(new tools::SHAVE::Assembler(*this)); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4517 | return Assembler.get(); |
| 4518 | default: |
| 4519 | return ToolChain::getTool(JA.getKind()); |
| 4520 | } |
| 4521 | } |
| 4522 | |
| Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4523 | Tool *MyriadToolChain::buildLinker() const { |
| 4524 | return new tools::Myriad::Linker(*this); |
| Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4525 | } |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4526 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4527 | WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple, |
| 4528 | const llvm::opt::ArgList &Args) |
| 4529 | : ToolChain(D, Triple, Args) { |
| Dan Gohman | 57b62c5 | 2016-02-22 19:26:15 +0000 | [diff] [blame] | 4530 | |
| 4531 | assert(Triple.isArch32Bit() != Triple.isArch64Bit()); |
| 4532 | getFilePaths().push_back( |
| 4533 | getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64")); |
| 4534 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4535 | // Use LLD by default. |
| 4536 | DefaultLinker = "lld"; |
| 4537 | } |
| 4538 | |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4539 | bool WebAssembly::IsMathErrnoDefault() const { return false; } |
| 4540 | |
| 4541 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } |
| 4542 | |
| 4543 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } |
| 4544 | |
| 4545 | bool WebAssembly::isPICDefault() const { return false; } |
| 4546 | |
| 4547 | bool WebAssembly::isPIEDefault() const { return false; } |
| 4548 | |
| 4549 | bool WebAssembly::isPICDefaultForced() const { return false; } |
| 4550 | |
| 4551 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } |
| 4552 | |
| 4553 | // TODO: Support Objective C stuff. |
| 4554 | bool WebAssembly::SupportsObjCGC() const { return false; } |
| 4555 | |
| 4556 | bool WebAssembly::hasBlocksRuntime() const { return false; } |
| 4557 | |
| 4558 | // TODO: Support profiling. |
| 4559 | bool WebAssembly::SupportsProfiling() const { return false; } |
| 4560 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4561 | bool WebAssembly::HasNativeLLVMSupport() const { return true; } |
| 4562 | |
| Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4563 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, |
| 4564 | ArgStringList &CC1Args) const { |
| 4565 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 4566 | options::OPT_fno_use_init_array, true)) |
| 4567 | CC1Args.push_back("-fuse-init-array"); |
| 4568 | } |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4569 | |
| Dan Gohman | 6ad8f61 | 2016-01-14 16:00:13 +0000 | [diff] [blame] | 4570 | ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const { |
| 4571 | return ToolChain::RLT_CompilerRT; |
| 4572 | } |
| 4573 | |
| 4574 | ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList &Args) const { |
| 4575 | return ToolChain::CST_Libcxx; |
| 4576 | } |
| 4577 | |
| 4578 | void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4579 | ArgStringList &CC1Args) const { |
| 4580 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4581 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 4582 | } |
| 4583 | |
| 4584 | void WebAssembly::AddClangCXXStdlibIncludeArgs( |
| 4585 | const llvm::opt::ArgList &DriverArgs, |
| 4586 | llvm::opt::ArgStringList &CC1Args) const { |
| 4587 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc) && |
| 4588 | !DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4589 | addSystemInclude(DriverArgs, CC1Args, |
| 4590 | getDriver().SysRoot + "/include/c++/v1"); |
| 4591 | } |
| 4592 | |
| Dan Gohman | 5281686 | 2015-12-16 23:30:41 +0000 | [diff] [blame] | 4593 | Tool *WebAssembly::buildLinker() const { |
| 4594 | return new tools::wasm::Linker(*this); |
| 4595 | } |
| 4596 | |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4597 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 4598 | : Generic_ELF(D, Triple, Args) { |
| 4599 | if (Args.hasArg(options::OPT_static)) |
| 4600 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; |
| 4601 | |
| Paul Robinson | 9d61361 | 2016-05-16 17:22:25 +0000 | [diff] [blame] | 4602 | // Determine where to find the PS4 libraries. We use SCE_ORBIS_SDK_DIR |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4603 | // if it exists; otherwise use the driver's installation path, which |
| 4604 | // should be <SDK_DIR>/host_tools/bin. |
| 4605 | |
| 4606 | SmallString<512> PS4SDKDir; |
| Paul Robinson | 9d61361 | 2016-05-16 17:22:25 +0000 | [diff] [blame] | 4607 | if (const char *EnvValue = getenv("SCE_ORBIS_SDK_DIR")) { |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4608 | if (!llvm::sys::fs::exists(EnvValue)) |
| 4609 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; |
| 4610 | PS4SDKDir = EnvValue; |
| 4611 | } else { |
| 4612 | PS4SDKDir = getDriver().Dir; |
| 4613 | llvm::sys::path::append(PS4SDKDir, "/../../"); |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4614 | } |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4615 | |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4616 | // 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] | 4617 | // PS4's include or lib directories. This behavior could be changed if |
| Eric Christopher | efef8ef | 2015-12-07 22:43:05 +0000 | [diff] [blame] | 4618 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. |
| Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4619 | // If -isysroot was passed, use that as the SDK base path. |
| 4620 | std::string PrefixDir; |
| 4621 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 4622 | PrefixDir = A->getValue(); |
| 4623 | if (!llvm::sys::fs::exists(PrefixDir)) |
| 4624 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; |
| 4625 | } else |
| 4626 | PrefixDir = PS4SDKDir.str(); |
| 4627 | |
| 4628 | SmallString<512> PS4SDKIncludeDir(PrefixDir); |
| 4629 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); |
| 4630 | if (!Args.hasArg(options::OPT_nostdinc) && |
| 4631 | !Args.hasArg(options::OPT_nostdlibinc) && |
| 4632 | !Args.hasArg(options::OPT_isysroot) && |
| 4633 | !Args.hasArg(options::OPT__sysroot_EQ) && |
| 4634 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { |
| 4635 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 4636 | << "PS4 system headers" << PS4SDKIncludeDir; |
| 4637 | } |
| 4638 | |
| 4639 | SmallString<512> PS4SDKLibDir(PS4SDKDir); |
| 4640 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); |
| 4641 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4642 | !Args.hasArg(options::OPT_nodefaultlibs) && |
| 4643 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && |
| 4644 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && |
| 4645 | !Args.hasArg(options::OPT_emit_ast) && |
| 4646 | !llvm::sys::fs::exists(PS4SDKLibDir)) { |
| 4647 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 4648 | << "PS4 system libraries" << PS4SDKLibDir; |
| 4649 | return; |
| 4650 | } |
| 4651 | getFilePaths().push_back(PS4SDKLibDir.str()); |
| 4652 | } |
| 4653 | |
| 4654 | Tool *PS4CPU::buildAssembler() const { |
| 4655 | return new tools::PS4cpu::Assemble(*this); |
| 4656 | } |
| 4657 | |
| 4658 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } |
| 4659 | |
| 4660 | bool PS4CPU::isPICDefault() const { return true; } |
| 4661 | |
| 4662 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } |
| 4663 | |
| 4664 | SanitizerMask PS4CPU::getSupportedSanitizers() const { |
| 4665 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 4666 | Res |= SanitizerKind::Address; |
| 4667 | Res |= SanitizerKind::Vptr; |
| 4668 | return Res; |
| 4669 | } |