Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 1 | //===--- ToolChains.cpp - ToolChain Implementations -------------*- C++ -*-===// |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "ToolChains.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 11 | #include "clang/Basic/ObjCRuntime.h" |
| 12 | #include "clang/Basic/Version.h" |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 13 | #include "clang/Basic/VirtualFileSystem.h" |
Alp Toker | 1d257e1 | 2014-06-04 03:28:55 +0000 | [diff] [blame] | 14 | #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX |
Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Compilation.h" |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 17 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | da13faf | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 18 | #include "clang/Driver/Options.h" |
Alexey Samsonov | 609213f9 | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 19 | #include "clang/Driver/SanitizerArgs.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallString.h" |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringExtras.h" |
Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringSwitch.h" |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 24 | #include "llvm/Option/Arg.h" |
| 25 | #include "llvm/Option/ArgList.h" |
| 26 | #include "llvm/Option/OptTable.h" |
| 27 | #include "llvm/Option/Option.h" |
Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 28 | #include "llvm/ProfileData/InstrProf.h" |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 30 | #include "llvm/Support/FileSystem.h" |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 31 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Path.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Program.h" |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/TargetParser.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 36 | #include <cstdlib> // ::getenv |
Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 37 | #include <system_error> |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 38 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 39 | using namespace clang::driver; |
| 40 | using namespace clang::driver::toolchains; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 41 | using namespace clang; |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 42 | using namespace llvm::opt; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 43 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 44 | MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 45 | : ToolChain(D, Triple, Args) { |
Tim Northover | 15ff71d | 2014-05-22 13:12:14 +0000 | [diff] [blame] | 46 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
| 47 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 48 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 49 | getProgramPaths().push_back(getDriver().Dir); |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 50 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 51 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 52 | /// Darwin - Darwin tool chain for i386 and x86_64. |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 53 | Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 54 | : MachO(D, Triple, Args), TargetInitialized(false) {} |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 55 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 56 | types::ID MachO::LookupTypeForExtension(const char *Ext) const { |
Daniel Dunbar | cc7df6c | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 57 | types::ID Ty = types::lookupTypeForExtension(Ext); |
| 58 | |
| 59 | // Darwin always preprocesses assembly files (unless -x is used explicitly). |
| 60 | if (Ty == types::TY_PP_Asm) |
| 61 | return types::TY_Asm; |
| 62 | |
| 63 | return Ty; |
| 64 | } |
| 65 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 66 | bool MachO::HasNativeLLVMSupport() const { return true; } |
Daniel Dunbar | 62123a1 | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 67 | |
John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 68 | /// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 69 | ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 70 | if (isTargetWatchOSBased()) |
Tim Northover | 756447a | 2015-10-30 16:30:36 +0000 | [diff] [blame] | 71 | return ObjCRuntime(ObjCRuntime::WatchOS, TargetVersion); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 72 | if (isTargetIOSBased()) |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 73 | return ObjCRuntime(ObjCRuntime::iOS, TargetVersion); |
Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 74 | if (isNonFragile) |
| 75 | return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion); |
| 76 | return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion); |
John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 77 | } |
| 78 | |
John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 79 | /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. |
| 80 | bool Darwin::hasBlocksRuntime() const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 81 | if (isTargetWatchOSBased()) |
| 82 | return true; |
| 83 | else if (isTargetIOSBased()) |
John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 84 | return !isIPhoneOSVersionLT(3, 2); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 85 | else { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 86 | assert(isTargetMacOS() && "unexpected darwin target"); |
| 87 | return !isMacosxVersionLT(10, 6); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 88 | } |
John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 91 | // This is just a MachO name translation routine and there's no |
| 92 | // way to join this into ARMTargetParser without breaking all |
| 93 | // other assumptions. Maybe MachO should consider standardising |
| 94 | // their nomenclature. |
| 95 | static const char *ArmMachOArchName(StringRef Arch) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 96 | return llvm::StringSwitch<const char *>(Arch) |
| 97 | .Case("armv6k", "armv6") |
| 98 | .Case("armv6m", "armv6m") |
| 99 | .Case("armv5tej", "armv5") |
| 100 | .Case("xscale", "xscale") |
| 101 | .Case("armv4t", "armv4t") |
| 102 | .Case("armv7", "armv7") |
| 103 | .Cases("armv7a", "armv7-a", "armv7") |
| 104 | .Cases("armv7r", "armv7-r", "armv7") |
| 105 | .Cases("armv7em", "armv7e-m", "armv7em") |
| 106 | .Cases("armv7k", "armv7-k", "armv7k") |
| 107 | .Cases("armv7m", "armv7-m", "armv7m") |
| 108 | .Cases("armv7s", "armv7-s", "armv7s") |
| 109 | .Default(nullptr); |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 112 | static const char *ArmMachOArchNameCPU(StringRef CPU) { |
Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 113 | unsigned ArchKind = llvm::ARM::parseCPUArch(CPU); |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 114 | if (ArchKind == llvm::ARM::AK_INVALID) |
| 115 | return nullptr; |
Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 116 | StringRef Arch = llvm::ARM::getArchName(ArchKind); |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 117 | |
| 118 | // FIXME: Make sure this MachO triple mangling is really necessary. |
| 119 | // ARMv5* normalises to ARMv5. |
| 120 | if (Arch.startswith("armv5")) |
| 121 | Arch = Arch.substr(0, 5); |
| 122 | // ARMv6*, except ARMv6M, normalises to ARMv6. |
| 123 | else if (Arch.startswith("armv6") && !Arch.endswith("6m")) |
| 124 | Arch = Arch.substr(0, 5); |
| 125 | // ARMv7A normalises to ARMv7. |
| 126 | else if (Arch.endswith("v7a")) |
| 127 | Arch = Arch.substr(0, 5); |
| 128 | return Arch.data(); |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 131 | static bool isSoftFloatABI(const ArgList &Args) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 132 | Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 133 | options::OPT_mfloat_abi_EQ); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 134 | if (!A) |
| 135 | return false; |
Rafael Auler | 3f7abf7 | 2014-09-29 21:50:34 +0000 | [diff] [blame] | 136 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 137 | return A->getOption().matches(options::OPT_msoft_float) || |
| 138 | (A->getOption().matches(options::OPT_mfloat_abi_EQ) && |
| 139 | A->getValue() == StringRef("soft")); |
| 140 | } |
| 141 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 142 | StringRef MachO::getMachOArchName(const ArgList &Args) const { |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 143 | switch (getTriple().getArch()) { |
| 144 | default: |
Rafael Espindola | ed1233e | 2014-08-28 21:23:05 +0000 | [diff] [blame] | 145 | return getDefaultUniversalArchName(); |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 146 | |
Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 147 | case llvm::Triple::aarch64: |
| 148 | return "arm64"; |
| 149 | |
Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 150 | case llvm::Triple::thumb: |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 151 | case llvm::Triple::arm: |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 152 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 153 | if (const char *Arch = ArmMachOArchName(A->getValue())) |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 154 | return Arch; |
| 155 | |
| 156 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 157 | if (const char *Arch = ArmMachOArchNameCPU(A->getValue())) |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 158 | return Arch; |
| 159 | |
| 160 | return "arm"; |
| 161 | } |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 164 | Darwin::~Darwin() {} |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 165 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 166 | MachO::~MachO() {} |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 167 | |
| 168 | std::string MachO::ComputeEffectiveClangTriple(const ArgList &Args, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 169 | types::ID InputType) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 170 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
| 171 | |
| 172 | return Triple.getTriple(); |
| 173 | } |
| 174 | |
Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 175 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, |
| 176 | types::ID InputType) const { |
| 177 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 178 | |
| 179 | // If the target isn't initialized (e.g., an unknown Darwin platform, return |
| 180 | // the default triple). |
| 181 | if (!isTargetInitialized()) |
| 182 | return Triple.getTriple(); |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 183 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 184 | SmallString<16> Str; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 185 | if (isTargetWatchOSBased()) |
| 186 | Str += "watchos"; |
| 187 | else if (isTargetTvOSBased()) |
| 188 | Str += "tvos"; |
| 189 | else if (isTargetIOSBased()) |
| 190 | Str += "ios"; |
| 191 | else |
| 192 | Str += "macosx"; |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 193 | Str += getTargetVersion().getAsString(); |
| 194 | Triple.setOSName(Str); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 195 | |
| 196 | return Triple.getTriple(); |
| 197 | } |
| 198 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 199 | void Generic_ELF::anchor() {} |
| 200 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 201 | Tool *MachO::getTool(Action::ActionClass AC) const { |
Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 202 | switch (AC) { |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 203 | case Action::LipoJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 204 | if (!Lipo) |
| 205 | Lipo.reset(new tools::darwin::Lipo(*this)); |
| 206 | return Lipo.get(); |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 207 | case Action::DsymutilJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 208 | if (!Dsymutil) |
| 209 | Dsymutil.reset(new tools::darwin::Dsymutil(*this)); |
| 210 | return Dsymutil.get(); |
Ben Langmuir | 9b9a8d3 | 2014-02-06 18:53:25 +0000 | [diff] [blame] | 211 | case Action::VerifyDebugInfoJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 212 | if (!VerifyDebug) |
| 213 | VerifyDebug.reset(new tools::darwin::VerifyDebug(*this)); |
| 214 | return VerifyDebug.get(); |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 215 | default: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 216 | return ToolChain::getTool(AC); |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 217 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 220 | Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); } |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 221 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 222 | Tool *MachO::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 223 | return new tools::darwin::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 224 | } |
Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 225 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 226 | DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 227 | const ArgList &Args) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 228 | : Darwin(D, Triple, Args) {} |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 229 | |
Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 230 | void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 231 | // For modern targets, promote certain warnings to errors. |
| 232 | if (isTargetWatchOSBased() || getTriple().isArch64Bit()) { |
Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 233 | // Always enable -Wdeprecated-objc-isa-usage and promote it |
| 234 | // to an error. |
| 235 | CC1Args.push_back("-Wdeprecated-objc-isa-usage"); |
| 236 | CC1Args.push_back("-Werror=deprecated-objc-isa-usage"); |
| 237 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 238 | // For iOS and watchOS, also error about implicit function declarations, |
| 239 | // as that can impact calling conventions. |
| 240 | if (!isTargetMacOS()) |
| 241 | CC1Args.push_back("-Werror=implicit-function-declaration"); |
Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 245 | /// \brief Determine whether Objective-C automated reference counting is |
| 246 | /// enabled. |
| 247 | static bool isObjCAutoRefCount(const ArgList &Args) { |
| 248 | return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); |
| 249 | } |
| 250 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 251 | void DarwinClang::AddLinkARCArgs(const ArgList &Args, |
| 252 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 253 | // Avoid linking compatibility stubs on i386 mac. |
| 254 | if (isTargetMacOS() && getArch() == llvm::Triple::x86) |
| 255 | return; |
| 256 | |
| 257 | ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true); |
| 258 | |
| 259 | if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) && |
| 260 | runtime.hasSubscripting()) |
| 261 | return; |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 262 | |
| 263 | CmdArgs.push_back("-force_load"); |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 264 | SmallString<128> P(getDriver().ClangExecutable); |
| 265 | llvm::sys::path::remove_filename(P); // 'clang' |
| 266 | llvm::sys::path::remove_filename(P); // 'bin' |
Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 267 | llvm::sys::path::append(P, "lib", "arc", "libarclite_"); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 268 | // Mash in the platform. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 269 | if (isTargetWatchOSSimulator()) |
| 270 | P += "watchsimulator"; |
| 271 | else if (isTargetWatchOS()) |
| 272 | P += "watchos"; |
| 273 | else if (isTargetTvOSSimulator()) |
| 274 | P += "appletvsimulator"; |
| 275 | else if (isTargetTvOS()) |
| 276 | P += "appletvos"; |
| 277 | else if (isTargetIOSSimulator()) |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 278 | P += "iphonesimulator"; |
Argyrios Kyrtzidis | 058b451 | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 279 | else if (isTargetIPhoneOS()) |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 280 | P += "iphoneos"; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 281 | else |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 282 | P += "macosx"; |
| 283 | P += ".a"; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 284 | |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 285 | CmdArgs.push_back(Args.MakeArgString(P)); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 288 | void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, |
Kuba Brecka | 2735a025 | 2014-10-31 00:08:57 +0000 | [diff] [blame] | 289 | StringRef DarwinLibName, bool AlwaysLink, |
Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 290 | bool IsEmbedded, bool AddRPath) const { |
| 291 | SmallString<128> Dir(getDriver().ResourceDir); |
| 292 | llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin"); |
| 293 | |
| 294 | SmallString<128> P(Dir); |
| 295 | llvm::sys::path::append(P, DarwinLibName); |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 296 | |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 297 | // For now, allow missing resource libraries to support developers who may |
Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 298 | // not have compiler-rt checked out or integrated into their build (unless |
| 299 | // we explicitly force linking with this library). |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 300 | if (AlwaysLink || getVFS().exists(P)) |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 301 | CmdArgs.push_back(Args.MakeArgString(P)); |
Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 302 | |
| 303 | // Adding the rpaths might negatively interact when other rpaths are involved, |
| 304 | // so we should make sure we add the rpaths last, after all user-specified |
| 305 | // rpaths. This is currently true from this place, but we need to be |
| 306 | // careful if this function is ever called before user's rpaths are emitted. |
| 307 | if (AddRPath) { |
| 308 | assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library"); |
| 309 | |
| 310 | // Add @executable_path to rpath to support having the dylib copied with |
| 311 | // the executable. |
| 312 | CmdArgs.push_back("-rpath"); |
| 313 | CmdArgs.push_back("@executable_path"); |
| 314 | |
| 315 | // Add the path to the resource dir to rpath to support using the dylib |
| 316 | // from the default location without copying. |
| 317 | CmdArgs.push_back("-rpath"); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 318 | CmdArgs.push_back(Args.MakeArgString(Dir)); |
Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 319 | } |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Justin Bogner | 2fd95f6 | 2015-05-12 06:30:48 +0000 | [diff] [blame] | 322 | void Darwin::addProfileRTLibs(const ArgList &Args, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 323 | ArgStringList &CmdArgs) const { |
Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 324 | if (!needsProfileRT(Args)) return; |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 325 | |
| 326 | // Select the appropriate runtime library for the target. |
Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame] | 327 | if (isTargetWatchOSBased()) { |
| 328 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_watchos.a", |
| 329 | /*AlwaysLink*/ true); |
| 330 | } else if (isTargetTvOSBased()) { |
| 331 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_tvos.a", |
| 332 | /*AlwaysLink*/ true); |
| 333 | } else if (isTargetIOSBased()) { |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 334 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a", |
| 335 | /*AlwaysLink*/ true); |
Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame] | 336 | } else { |
| 337 | assert(isTargetMacOS() && "unexpected non MacOS platform"); |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 338 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a", |
| 339 | /*AlwaysLink*/ true); |
Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame] | 340 | } |
Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 341 | return; |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 344 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, |
| 345 | ArgStringList &CmdArgs, |
| 346 | StringRef Sanitizer) const { |
| 347 | if (!Args.hasArg(options::OPT_dynamiclib) && |
| 348 | !Args.hasArg(options::OPT_bundle)) { |
| 349 | // Sanitizer runtime libraries requires C++. |
| 350 | AddCXXStdlibLibArgs(Args, CmdArgs); |
| 351 | } |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 352 | // ASan is not supported on watchOS. |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 353 | assert(isTargetMacOS() || isTargetIOSSimulator()); |
| 354 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 355 | AddLinkRuntimeLib( |
| 356 | Args, CmdArgs, |
| 357 | (Twine("libclang_rt.") + Sanitizer + "_" + OS + "_dynamic.dylib").str(), |
| 358 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, |
| 359 | /*AddRPath*/ true); |
Hans Wennborg | 10821e5 | 2015-04-09 18:47:01 +0000 | [diff] [blame] | 360 | |
| 361 | if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { |
| 362 | // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export |
| 363 | // all RTTI-related symbols that UBSan uses. |
| 364 | CmdArgs.push_back("-lc++abi"); |
| 365 | } |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 368 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 369 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 370 | // Darwin only supports the compiler-rt based runtime libraries. |
| 371 | switch (GetRuntimeLibType(Args)) { |
| 372 | case ToolChain::RLT_CompilerRT: |
| 373 | break; |
| 374 | default: |
| 375 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 376 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 377 | return; |
| 378 | } |
| 379 | |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 380 | // Darwin doesn't support real static executables, don't link any runtime |
| 381 | // libraries with -static. |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 382 | if (Args.hasArg(options::OPT_static) || |
| 383 | Args.hasArg(options::OPT_fapple_kext) || |
| 384 | Args.hasArg(options::OPT_mkernel)) |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 385 | return; |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 386 | |
| 387 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 388 | // cares. This is useful in situations where someone wants to statically link |
| 389 | // something like libstdc++, and needs its runtime support routines. |
| 390 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 391 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 392 | return; |
| 393 | } |
| 394 | |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 395 | const SanitizerArgs &Sanitize = getSanitizerArgs(); |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 396 | if (Sanitize.needsAsanRt()) |
| 397 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); |
| 398 | if (Sanitize.needsUbsanRt()) |
| 399 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); |
Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 400 | if (Sanitize.needsTsanRt()) |
| 401 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); |
Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 402 | |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 403 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 404 | // target specific static runtime library. |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 405 | CmdArgs.push_back("-lSystem"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 406 | |
| 407 | // Select the dynamic runtime library and the target specific static library. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 408 | if (isTargetWatchOSBased()) { |
| 409 | // We currently always need a static runtime library for watchOS. |
| 410 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); |
| 411 | } else if (isTargetTvOSBased()) { |
| 412 | // We currently always need a static runtime library for tvOS. |
| 413 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); |
| 414 | } else if (isTargetIOSBased()) { |
Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 415 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, |
| 416 | // it never went into the SDK. |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 417 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 418 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && |
Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 419 | getTriple().getArch() != llvm::Triple::aarch64) |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 420 | CmdArgs.push_back("-lgcc_s.1"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 421 | |
Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 422 | // We currently always need a static runtime library for iOS. |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 423 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 424 | } else { |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 425 | assert(isTargetMacOS() && "unexpected non MacOS platform"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 426 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 427 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 428 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 429 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 430 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 431 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 432 | |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 433 | // 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] | 434 | // targeting 10.4, to provide versions of the static functions which were |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 435 | // omitted from 10.4.dylib. |
| 436 | // |
| 437 | // Unfortunately, that turned out to not be true, because Darwin system |
| 438 | // headers can still use eprintf on i386, and it is not exported from |
| 439 | // libSystem. Therefore, we still must provide a runtime library just for |
| 440 | // the tiny tiny handful of projects that *might* use that symbol. |
| 441 | if (isMacosxVersionLT(10, 5)) { |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 442 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 443 | } else { |
| 444 | if (getTriple().getArch() == llvm::Triple::x86) |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 445 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); |
| 446 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 447 | } |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 448 | } |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 451 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 452 | const OptTable &Opts = getDriver().getOpts(); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 453 | |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 454 | // Support allowing the SDKROOT environment variable used by xcrun and other |
| 455 | // Xcode tools to define the default sysroot, by making it the default for |
| 456 | // isysroot. |
Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 457 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 458 | // Warn if the path does not exist. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 459 | if (!getVFS().exists(A->getValue())) |
Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 460 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); |
| 461 | } else { |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 462 | if (char *env = ::getenv("SDKROOT")) { |
Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 463 | // We only use this value as the default if it is an absolute path, |
| 464 | // exists, and it is not the root path. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 465 | if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) && |
Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 466 | StringRef(env) != "/") { |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 467 | Args.append(Args.MakeSeparateArg( |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 468 | nullptr, Opts.getOption(options::OPT_isysroot), env)); |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 473 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 474 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 475 | Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ); |
| 476 | Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ); |
Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 477 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 478 | if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 479 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 480 | << OSXVersion->getAsString(Args) |
| 481 | << (iOSVersion ? iOSVersion : |
| 482 | TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 483 | iOSVersion = TvOSVersion = WatchOSVersion = nullptr; |
| 484 | } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) { |
| 485 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 486 | << iOSVersion->getAsString(Args) |
| 487 | << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 488 | TvOSVersion = WatchOSVersion = nullptr; |
| 489 | } else if (TvOSVersion && WatchOSVersion) { |
| 490 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 491 | << TvOSVersion->getAsString(Args) |
| 492 | << WatchOSVersion->getAsString(Args); |
| 493 | WatchOSVersion = nullptr; |
| 494 | } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) { |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 495 | // If no deployment target was specified on the command line, check for |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 496 | // environment defines. |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 497 | std::string OSXTarget; |
| 498 | std::string iOSTarget; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 499 | std::string TvOSTarget; |
| 500 | std::string WatchOSTarget; |
| 501 | |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 502 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) |
| 503 | OSXTarget = env; |
| 504 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) |
| 505 | iOSTarget = env; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 506 | if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET")) |
| 507 | TvOSTarget = env; |
| 508 | if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET")) |
| 509 | WatchOSTarget = env; |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 510 | |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 511 | // If there is no command-line argument to specify the Target version and |
| 512 | // no environment variable defined, see if we can set the default based |
| 513 | // on -isysroot. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 514 | if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() && |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 515 | Args.hasArg(options::OPT_isysroot)) { |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 516 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 517 | StringRef isysroot = A->getValue(); |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 518 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk |
| 519 | size_t BeginSDK = isysroot.rfind("SDKs/"); |
| 520 | size_t EndSDK = isysroot.rfind(".sdk"); |
| 521 | if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { |
| 522 | StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); |
| 523 | // Slice the version number out. |
| 524 | // Version number is between the first and the last number. |
| 525 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 526 | size_t EndVer = SDK.find_last_of("0123456789"); |
| 527 | if (StartVer != StringRef::npos && EndVer > StartVer) { |
| 528 | StringRef Version = SDK.slice(StartVer, EndVer + 1); |
| 529 | if (SDK.startswith("iPhoneOS") || |
| 530 | SDK.startswith("iPhoneSimulator")) |
| 531 | iOSTarget = Version; |
| 532 | else if (SDK.startswith("MacOSX")) |
| 533 | OSXTarget = Version; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 534 | else if (SDK.startswith("WatchOS") || |
| 535 | SDK.startswith("WatchSimulator")) |
| 536 | WatchOSTarget = Version; |
| 537 | else if (SDK.startswith("AppleTVOS") || |
| 538 | SDK.startswith("AppleTVSimulator")) |
| 539 | TvOSTarget = Version; |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 540 | } |
| 541 | } |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 542 | } |
| 543 | } |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 544 | |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 545 | // 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] | 546 | // from arch name and compute the version from the triple. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 547 | if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() && |
| 548 | WatchOSTarget.empty()) { |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 549 | StringRef MachOArchName = getMachOArchName(Args); |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 550 | unsigned Major, Minor, Micro; |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 551 | if (MachOArchName == "armv7" || MachOArchName == "armv7s" || |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 552 | MachOArchName == "arm64") { |
| 553 | getTriple().getiOSVersion(Major, Minor, Micro); |
| 554 | llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' |
| 555 | << Micro; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 556 | } else if (MachOArchName == "armv7k") { |
| 557 | getTriple().getWatchOSVersion(Major, Minor, Micro); |
| 558 | llvm::raw_string_ostream(WatchOSTarget) << Major << '.' << Minor << '.' |
| 559 | << Micro; |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 560 | } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && |
| 561 | MachOArchName != "armv7em") { |
| 562 | if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { |
| 563 | getDriver().Diag(diag::err_drv_invalid_darwin_version) |
| 564 | << getTriple().getOSName(); |
| 565 | } |
| 566 | llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' |
| 567 | << Micro; |
| 568 | } |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 569 | } |
Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 570 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 571 | // Do not allow conflicts with the watchOS target. |
| 572 | if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) { |
| 573 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 574 | << "WATCHOS_DEPLOYMENT_TARGET" |
| 575 | << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" : |
| 576 | "TVOS_DEPLOYMENT_TARGET"); |
| 577 | } |
| 578 | |
| 579 | // Do not allow conflicts with the tvOS target. |
| 580 | if (!TvOSTarget.empty() && !iOSTarget.empty()) { |
| 581 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 582 | << "TVOS_DEPLOYMENT_TARGET" |
| 583 | << "IPHONEOS_DEPLOYMENT_TARGET"; |
| 584 | } |
| 585 | |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 586 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 587 | // default platform. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 588 | if (!OSXTarget.empty() && (!iOSTarget.empty() || |
| 589 | !WatchOSTarget.empty() || |
| 590 | !TvOSTarget.empty())) { |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 591 | if (getTriple().getArch() == llvm::Triple::arm || |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 592 | getTriple().getArch() == llvm::Triple::aarch64 || |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 593 | getTriple().getArch() == llvm::Triple::thumb) |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 594 | OSXTarget = ""; |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 595 | else |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 596 | iOSTarget = WatchOSTarget = TvOSTarget = ""; |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 597 | } |
Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 598 | |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 599 | if (!OSXTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 600 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 601 | OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 602 | Args.append(OSXVersion); |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 603 | } else if (!iOSTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 604 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 605 | iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 606 | Args.append(iOSVersion); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 607 | } else if (!TvOSTarget.empty()) { |
| 608 | const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ); |
| 609 | TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget); |
| 610 | Args.append(TvOSVersion); |
| 611 | } else if (!WatchOSTarget.empty()) { |
| 612 | const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ); |
| 613 | WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget); |
| 614 | Args.append(WatchOSVersion); |
Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 615 | } |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 616 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 617 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 618 | DarwinPlatformKind Platform; |
| 619 | if (OSXVersion) |
| 620 | Platform = MacOS; |
| 621 | else if (iOSVersion) |
| 622 | Platform = IPhoneOS; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 623 | else if (TvOSVersion) |
| 624 | Platform = TvOS; |
| 625 | else if (WatchOSVersion) |
| 626 | Platform = WatchOS; |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 627 | else |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 628 | llvm_unreachable("Unable to infer Darwin variant"); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 629 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 630 | // Set the tool chain target information. |
| 631 | unsigned Major, Minor, Micro; |
| 632 | bool HadExtra; |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 633 | if (Platform == MacOS) { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 634 | assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && |
| 635 | "Unknown target platform!"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 636 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, |
| 637 | HadExtra) || |
| 638 | HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 639 | getDriver().Diag(diag::err_drv_invalid_version_number) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 640 | << OSXVersion->getAsString(Args); |
Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 641 | } else if (Platform == IPhoneOS) { |
| 642 | assert(iOSVersion && "Unknown target platform!"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 643 | if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, |
| 644 | HadExtra) || |
| 645 | HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100) |
Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 646 | getDriver().Diag(diag::err_drv_invalid_version_number) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 647 | << iOSVersion->getAsString(Args); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 648 | } else if (Platform == TvOS) { |
| 649 | if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, |
| 650 | Micro, HadExtra) || HadExtra || |
| 651 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 652 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 653 | << TvOSVersion->getAsString(Args); |
| 654 | } else if (Platform == WatchOS) { |
| 655 | if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor, |
| 656 | Micro, HadExtra) || HadExtra || |
| 657 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 658 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 659 | << WatchOSVersion->getAsString(Args); |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 660 | } else |
| 661 | llvm_unreachable("unknown kind of Darwin platform"); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 662 | |
Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 663 | // Recognize iOS targets with an x86 architecture as the iOS simulator. |
Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 664 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 665 | getTriple().getArch() == llvm::Triple::x86_64)) |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 666 | Platform = IPhoneOSSimulator; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 667 | if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 668 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 669 | Platform = TvOSSimulator; |
| 670 | if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 671 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 672 | Platform = WatchOSSimulator; |
Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 673 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 674 | setTarget(Platform, Major, Minor, Micro); |
Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 677 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 678 | ArgStringList &CmdArgs) const { |
| 679 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 680 | |
| 681 | switch (Type) { |
| 682 | case ToolChain::CST_Libcxx: |
| 683 | CmdArgs.push_back("-lc++"); |
| 684 | break; |
| 685 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 686 | case ToolChain::CST_Libstdcxx: |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 687 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 688 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 689 | // platforms we care about it was -lstdc++.6, so we search for that |
| 690 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 691 | |
| 692 | // Check in the sysroot first. |
| 693 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 694 | SmallString<128> P(A->getValue()); |
Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 695 | llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 696 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 697 | if (!getVFS().exists(P)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 698 | llvm::sys::path::remove_filename(P); |
| 699 | llvm::sys::path::append(P, "libstdc++.6.dylib"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 700 | if (getVFS().exists(P)) { |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 701 | CmdArgs.push_back(Args.MakeArgString(P)); |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 702 | return; |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | // Otherwise, look in the root. |
Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 708 | // FIXME: This should be removed someday when we don't have to care about |
| 709 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 710 | if (!getVFS().exists("/usr/lib/libstdc++.dylib") && |
| 711 | getVFS().exists("/usr/lib/libstdc++.6.dylib")) { |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 712 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 713 | return; |
| 714 | } |
| 715 | |
| 716 | // Otherwise, let the linker search. |
| 717 | CmdArgs.push_back("-lstdc++"); |
| 718 | break; |
| 719 | } |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 722 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 723 | ArgStringList &CmdArgs) const { |
| 724 | |
| 725 | // For Darwin platforms, use the compiler-rt-based support library |
| 726 | // instead of the gcc-provided one (which is also incidentally |
| 727 | // only present in the gcc lib dir, which makes it hard to find). |
| 728 | |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 729 | SmallString<128> P(getDriver().ResourceDir); |
Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 730 | llvm::sys::path::append(P, "lib", "darwin"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 731 | |
| 732 | // Use the newer cc_kext for iOS ARM after 6.0. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 733 | if (isTargetWatchOS()) { |
| 734 | llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a"); |
| 735 | } else if (isTargetTvOS()) { |
| 736 | llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a"); |
| 737 | } else if (isTargetIPhoneOS()) { |
Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 738 | llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 739 | } else { |
Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 740 | llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 741 | } |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 742 | |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 743 | // For now, allow missing resource libraries to support developers who may |
| 744 | // not have compiler-rt checked out or integrated into their build. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 745 | if (getVFS().exists(P)) |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 746 | CmdArgs.push_back(Args.MakeArgString(P)); |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 749 | DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, |
| 750 | const char *BoundArch) const { |
Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 751 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 752 | const OptTable &Opts = getDriver().getOpts(); |
| 753 | |
| 754 | // FIXME: We really want to get out of the tool chain level argument |
| 755 | // translation business, as it makes the driver functionality much |
| 756 | // more opaque. For now, we follow gcc closely solely for the |
| 757 | // purpose of easily achieving feature parity & testability. Once we |
| 758 | // have something that works, we should reevaluate each translation |
| 759 | // and try to push it down into tool specific logic. |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 760 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 761 | for (Arg *A : Args) { |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 762 | if (A->getOption().matches(options::OPT_Xarch__)) { |
Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 763 | // Skip this argument unless the architecture matches either the toolchain |
| 764 | // triple arch, or the arch being bound. |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 765 | llvm::Triple::ArchType XarchArch = |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 766 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); |
| 767 | if (!(XarchArch == getArch() || |
| 768 | (BoundArch && |
| 769 | XarchArch == |
| 770 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 771 | continue; |
| 772 | |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 773 | Arg *OriginalArg = A; |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 774 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 775 | unsigned Prev = Index; |
Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 776 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 778 | // If the argument parsing failed or more than one argument was |
| 779 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 780 | // extra arguments. Emit an error and ignore. |
| 781 | // |
| 782 | // We also want to disallow any options which would alter the |
| 783 | // driver behavior; that isn't going to work in our model. We |
| 784 | // use isDriverOption() as an approximation, although things |
| 785 | // like -O4 are going to slip through. |
Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 786 | if (!XarchArg || Index > Prev + 1) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 787 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 788 | << A->getAsString(Args); |
Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 789 | continue; |
Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 790 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 791 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 792 | << A->getAsString(Args); |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 793 | continue; |
| 794 | } |
| 795 | |
Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 796 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 797 | |
Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 798 | A = XarchArg.release(); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 799 | DAL->AddSynthesizedArg(A); |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 800 | |
| 801 | // Linker input arguments require custom handling. The problem is that we |
| 802 | // have already constructed the phase actions, so we can not treat them as |
| 803 | // "input arguments". |
Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 804 | if (A->getOption().hasFlag(options::LinkerInput)) { |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 805 | // Convert the argument into individual Zlinker_input_args. |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 806 | for (const char *Value : A->getValues()) { |
| 807 | DAL->AddSeparateArg( |
| 808 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 809 | } |
| 810 | continue; |
| 811 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | } |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 813 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 814 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 815 | // gcc translates options twice, which means that self-expanding |
| 816 | // options add duplicates. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 817 | switch ((options::ID)A->getOption().getID()) { |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 818 | default: |
| 819 | DAL->append(A); |
| 820 | break; |
| 821 | |
| 822 | case options::OPT_mkernel: |
| 823 | case options::OPT_fapple_kext: |
| 824 | DAL->append(A); |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 825 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 826 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 828 | case options::OPT_dependency_file: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 829 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 830 | break; |
| 831 | |
| 832 | case options::OPT_gfull: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 833 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 834 | DAL->AddFlagArg( |
| 835 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | case options::OPT_gused: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 839 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 840 | DAL->AddFlagArg( |
| 841 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 842 | break; |
| 843 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 844 | case options::OPT_shared: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 845 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 846 | break; |
| 847 | |
| 848 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 849 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 853 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 854 | break; |
| 855 | |
| 856 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 857 | DAL->AddFlagArg(A, |
| 858 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 859 | break; |
| 860 | |
| 861 | case options::OPT_Wno_nonportable_cfstrings: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 862 | DAL->AddFlagArg( |
| 863 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 867 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 871 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 872 | break; |
| 873 | } |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 876 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 877 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 878 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 879 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), |
| 880 | "core2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 881 | |
| 882 | // 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] | 883 | // how the driver driver works. |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 884 | if (BoundArch) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 885 | StringRef Name = BoundArch; |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 886 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 887 | const Option MArch = Opts.getOption(options::OPT_march_EQ); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 888 | |
| 889 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 890 | // which defines the list of which architectures we accept. |
| 891 | if (Name == "ppc") |
| 892 | ; |
| 893 | else if (Name == "ppc601") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 894 | DAL->AddJoinedArg(nullptr, MCpu, "601"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 895 | else if (Name == "ppc603") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 896 | DAL->AddJoinedArg(nullptr, MCpu, "603"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 897 | else if (Name == "ppc604") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 898 | DAL->AddJoinedArg(nullptr, MCpu, "604"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 899 | else if (Name == "ppc604e") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 900 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 901 | else if (Name == "ppc750") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 902 | DAL->AddJoinedArg(nullptr, MCpu, "750"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 903 | else if (Name == "ppc7400") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 904 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 905 | else if (Name == "ppc7450") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 906 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 907 | else if (Name == "ppc970") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 908 | DAL->AddJoinedArg(nullptr, MCpu, "970"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 909 | |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 910 | else if (Name == "ppc64" || Name == "ppc64le") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 911 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 912 | |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 913 | else if (Name == "i386") |
| 914 | ; |
| 915 | else if (Name == "i486") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 916 | DAL->AddJoinedArg(nullptr, MArch, "i486"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 917 | else if (Name == "i586") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 918 | DAL->AddJoinedArg(nullptr, MArch, "i586"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 919 | else if (Name == "i686") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 920 | DAL->AddJoinedArg(nullptr, MArch, "i686"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 921 | else if (Name == "pentium") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 922 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 923 | else if (Name == "pentium2") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 924 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 925 | else if (Name == "pentpro") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 926 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 927 | else if (Name == "pentIIm3") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 928 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 929 | |
| 930 | else if (Name == "x86_64") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 931 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 932 | else if (Name == "x86_64h") { |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 933 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| 934 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); |
Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 935 | } |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 936 | |
| 937 | else if (Name == "arm") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 938 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 939 | else if (Name == "armv4t") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 940 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 941 | else if (Name == "armv5") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 942 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 943 | else if (Name == "xscale") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 944 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 945 | else if (Name == "armv6") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 946 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 947 | else if (Name == "armv6m") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 948 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 949 | else if (Name == "armv7") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 950 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 951 | else if (Name == "armv7em") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 952 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 953 | else if (Name == "armv7k") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 954 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 955 | else if (Name == "armv7m") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 956 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 957 | else if (Name == "armv7s") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 958 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 959 | } |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 960 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 961 | return DAL; |
| 962 | } |
| 963 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 964 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 965 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 966 | // Embedded targets are simple at the moment, not supporting sanitizers and |
| 967 | // with different libraries for each member of the product { static, PIC } x |
| 968 | // { hard-float, soft-float } |
| 969 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); |
Saleem Abdulrasool | 06f6f99 | 2015-09-19 20:40:16 +0000 | [diff] [blame] | 970 | CompilerRT += |
| 971 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) |
| 972 | ? "hard" |
| 973 | : "soft"; |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 974 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; |
| 975 | |
| 976 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); |
| 977 | } |
| 978 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 979 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 980 | const char *BoundArch) const { |
| 981 | // First get the generic Apple args, before moving onto Darwin-specific ones. |
| 982 | DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); |
| 983 | const OptTable &Opts = getDriver().getOpts(); |
| 984 | |
Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 985 | // If no architecture is bound, none of the translations here are relevant. |
| 986 | if (!BoundArch) |
| 987 | return DAL; |
| 988 | |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 989 | // Add an explicit version min argument for the deployment target. We do this |
| 990 | // after argument translation because -Xarch_ arguments may add a version min |
| 991 | // argument. |
Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 992 | AddDeploymentTarget(*DAL); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 993 | |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 994 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. |
| 995 | // FIXME: It would be far better to avoid inserting those -static arguments, |
| 996 | // but we can't check the deployment target in the translation code until |
| 997 | // it is set here. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 998 | if (isTargetWatchOSBased() || |
| 999 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { |
| 1000 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1001 | Arg *A = *it; |
| 1002 | ++it; |
| 1003 | if (A->getOption().getID() != options::OPT_mkernel && |
| 1004 | A->getOption().getID() != options::OPT_fapple_kext) |
| 1005 | continue; |
| 1006 | assert(it != ie && "unexpected argument translation"); |
| 1007 | A = *it; |
| 1008 | assert(A->getOption().getID() == options::OPT_static && |
| 1009 | "missing expected -static argument"); |
| 1010 | it = DAL->getArgs().erase(it); |
| 1011 | } |
| 1012 | } |
| 1013 | |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1014 | // Default to use libc++ on OS X 10.9+ and iOS 7+. |
| 1015 | if (((isTargetMacOS() && !isMacosxVersionLT(10, 9)) || |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1016 | (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) || |
| 1017 | isTargetWatchOSBased()) && |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1018 | !Args.getLastArg(options::OPT_stdlib_EQ)) |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1019 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), |
| 1020 | "libc++"); |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1021 | |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1022 | // Validate the C++ standard library choice. |
| 1023 | CXXStdlibType Type = GetCXXStdlibType(*DAL); |
| 1024 | if (Type == ToolChain::CST_Libcxx) { |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1025 | // Check whether the target provides libc++. |
| 1026 | StringRef where; |
| 1027 | |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1028 | // Complain about targeting iOS < 5.0 in any way. |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1029 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) |
Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1030 | where = "iOS 5.0"; |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1031 | |
| 1032 | if (where != StringRef()) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1033 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1037 | return DAL; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1039 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1040 | bool MachO::IsUnwindTablesDefault() const { |
Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1041 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1044 | bool MachO::UseDwarfDebugFlags() const { |
Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1045 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 1046 | return S[0] != '\0'; |
| 1047 | return false; |
| 1048 | } |
| 1049 | |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1050 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { |
Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1051 | // Darwin uses SjLj exceptions on ARM. |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1052 | if (getTriple().getArch() != llvm::Triple::arm && |
| 1053 | getTriple().getArch() != llvm::Triple::thumb) |
| 1054 | return false; |
| 1055 | |
Tim Northover | c741b04 | 2015-11-17 18:27:27 +0000 | [diff] [blame] | 1056 | // Only watchOS uses the new DWARF/Compact unwinding method. |
| 1057 | return !isTargetWatchOS(); |
Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1060 | bool MachO::isPICDefault() const { return true; } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1061 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1062 | bool MachO::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1063 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1064 | bool MachO::isPICDefaultForced() const { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1065 | return (getArch() == llvm::Triple::x86_64 || |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1066 | getArch() == llvm::Triple::aarch64); |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1069 | bool MachO::SupportsProfiling() const { |
Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1070 | // Profiling instrumentation is only supported on x86. |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1071 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1074 | void Darwin::addMinVersionArgs(const ArgList &Args, |
| 1075 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1076 | VersionTuple TargetVersion = getTargetVersion(); |
| 1077 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1078 | if (isTargetWatchOS()) |
| 1079 | CmdArgs.push_back("-watchos_version_min"); |
| 1080 | else if (isTargetWatchOSSimulator()) |
| 1081 | CmdArgs.push_back("-watchos_simulator_version_min"); |
| 1082 | else if (isTargetTvOS()) |
| 1083 | CmdArgs.push_back("-tvos_version_min"); |
| 1084 | else if (isTargetTvOSSimulator()) |
| 1085 | CmdArgs.push_back("-tvos_simulator_version_min"); |
| 1086 | else if (isTargetIOSSimulator()) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1087 | CmdArgs.push_back("-ios_simulator_version_min"); |
Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1088 | else if (isTargetIOSBased()) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1089 | CmdArgs.push_back("-iphoneos_version_min"); |
| 1090 | else { |
| 1091 | assert(isTargetMacOS() && "unexpected target"); |
| 1092 | CmdArgs.push_back("-macosx_version_min"); |
| 1093 | } |
| 1094 | |
| 1095 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); |
| 1096 | } |
| 1097 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1098 | void Darwin::addStartObjectFileArgs(const ArgList &Args, |
| 1099 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1100 | // Derived from startfile spec. |
| 1101 | if (Args.hasArg(options::OPT_dynamiclib)) { |
| 1102 | // Derived from darwin_dylib1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1103 | if (isTargetWatchOSBased()) { |
| 1104 | ; // watchOS does not need dylib1.o. |
| 1105 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1106 | ; // iOS simulator does not need dylib1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1107 | } else if (isTargetIPhoneOS()) { |
| 1108 | if (isIPhoneOSVersionLT(3, 1)) |
| 1109 | CmdArgs.push_back("-ldylib1.o"); |
| 1110 | } else { |
| 1111 | if (isMacosxVersionLT(10, 5)) |
| 1112 | CmdArgs.push_back("-ldylib1.o"); |
| 1113 | else if (isMacosxVersionLT(10, 6)) |
| 1114 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1115 | } |
| 1116 | } else { |
| 1117 | if (Args.hasArg(options::OPT_bundle)) { |
| 1118 | if (!Args.hasArg(options::OPT_static)) { |
| 1119 | // Derived from darwin_bundle1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1120 | if (isTargetWatchOSBased()) { |
| 1121 | ; // watchOS does not need bundle1.o. |
| 1122 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1123 | ; // iOS simulator does not need bundle1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1124 | } else if (isTargetIPhoneOS()) { |
| 1125 | if (isIPhoneOSVersionLT(3, 1)) |
| 1126 | CmdArgs.push_back("-lbundle1.o"); |
| 1127 | } else { |
| 1128 | if (isMacosxVersionLT(10, 6)) |
| 1129 | CmdArgs.push_back("-lbundle1.o"); |
| 1130 | } |
| 1131 | } |
| 1132 | } else { |
| 1133 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { |
| 1134 | if (Args.hasArg(options::OPT_static) || |
| 1135 | Args.hasArg(options::OPT_object) || |
| 1136 | Args.hasArg(options::OPT_preload)) { |
| 1137 | CmdArgs.push_back("-lgcrt0.o"); |
| 1138 | } else { |
| 1139 | CmdArgs.push_back("-lgcrt1.o"); |
| 1140 | |
| 1141 | // darwin_crt2 spec is empty. |
| 1142 | } |
| 1143 | // By default on OS X 10.8 and later, we don't link with a crt1.o |
| 1144 | // file and the linker knows to use _main as the entry point. But, |
| 1145 | // when compiling with -pg, we need to link with the gcrt1.o file, |
| 1146 | // so pass the -no_new_main option to tell the linker to use the |
| 1147 | // "start" symbol as the entry point. |
| 1148 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) |
| 1149 | CmdArgs.push_back("-no_new_main"); |
| 1150 | } else { |
| 1151 | if (Args.hasArg(options::OPT_static) || |
| 1152 | Args.hasArg(options::OPT_object) || |
| 1153 | Args.hasArg(options::OPT_preload)) { |
| 1154 | CmdArgs.push_back("-lcrt0.o"); |
| 1155 | } else { |
| 1156 | // Derived from darwin_crt1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1157 | if (isTargetWatchOSBased()) { |
| 1158 | ; // watchOS does not need crt1.o. |
| 1159 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1160 | ; // iOS simulator does not need crt1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1161 | } else if (isTargetIPhoneOS()) { |
Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1162 | if (getArch() == llvm::Triple::aarch64) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1163 | ; // iOS does not need any crt1 files for arm64 |
| 1164 | else if (isIPhoneOSVersionLT(3, 1)) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1165 | CmdArgs.push_back("-lcrt1.o"); |
| 1166 | else if (isIPhoneOSVersionLT(6, 0)) |
| 1167 | CmdArgs.push_back("-lcrt1.3.1.o"); |
| 1168 | } else { |
| 1169 | if (isMacosxVersionLT(10, 5)) |
| 1170 | CmdArgs.push_back("-lcrt1.o"); |
| 1171 | else if (isMacosxVersionLT(10, 6)) |
| 1172 | CmdArgs.push_back("-lcrt1.10.5.o"); |
| 1173 | else if (isMacosxVersionLT(10, 8)) |
| 1174 | CmdArgs.push_back("-lcrt1.10.6.o"); |
| 1175 | |
| 1176 | // darwin_crt2 spec is empty. |
| 1177 | } |
| 1178 | } |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1184 | !isTargetWatchOS() && |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1185 | isMacosxVersionLT(10, 5)) { |
| 1186 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); |
| 1187 | CmdArgs.push_back(Str); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1191 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } |
Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1192 | |
John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1193 | void Darwin::CheckObjCARC() const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1194 | if (isTargetIOSBased() || isTargetWatchOSBased() || |
| 1195 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) |
John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1196 | return; |
John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1197 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); |
Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1200 | SanitizerMask Darwin::getSupportedSanitizers() const { |
| 1201 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1202 | if (isTargetMacOS() || isTargetIOSSimulator()) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1203 | Res |= SanitizerKind::Address; |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1204 | if (isTargetMacOS()) { |
| 1205 | if (!isMacosxVersionLT(10, 9)) |
| 1206 | Res |= SanitizerKind::Vptr; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1207 | Res |= SanitizerKind::SafeStack; |
Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 1208 | Res |= SanitizerKind::Thread; |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1209 | } |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1210 | return Res; |
| 1211 | } |
| 1212 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1213 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 1214 | /// all subcommands; this relies on gcc translating the majority of |
| 1215 | /// command line options. |
| 1216 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1217 | /// \brief Parse a GCCVersion object out of a string of text. |
| 1218 | /// |
| 1219 | /// This is the primary means of forming GCCVersion objects. |
| 1220 | /*static*/ |
| 1221 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1222 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1223 | std::pair<StringRef, StringRef> First = VersionText.split('.'); |
| 1224 | std::pair<StringRef, StringRef> Second = First.second.split('.'); |
| 1225 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1226 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| 1227 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1228 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1229 | GoodVersion.MajorStr = First.first.str(); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1230 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1231 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1232 | GoodVersion.MinorStr = Second.first.str(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1233 | |
| 1234 | // First look for a number prefix and parse that if present. Otherwise just |
| 1235 | // stash the entire patch string in the suffix, and leave the number |
| 1236 | // unspecified. This covers versions strings such as: |
| 1237 | // 4.4 |
| 1238 | // 4.4.0 |
| 1239 | // 4.4.x |
| 1240 | // 4.4.2-rc4 |
| 1241 | // 4.4.x-patched |
| 1242 | // And retains any patch number it finds. |
| 1243 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); |
| 1244 | if (!PatchText.empty()) { |
Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1245 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1246 | // Try to parse the number and any suffix. |
| 1247 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || |
| 1248 | GoodVersion.Patch < 0) |
| 1249 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1250 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | return GoodVersion; |
| 1255 | } |
| 1256 | |
| 1257 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1258 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, |
| 1259 | int RHSPatch, |
| 1260 | StringRef RHSPatchSuffix) const { |
| 1261 | if (Major != RHSMajor) |
| 1262 | return Major < RHSMajor; |
| 1263 | if (Minor != RHSMinor) |
| 1264 | return Minor < RHSMinor; |
| 1265 | if (Patch != RHSPatch) { |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1266 | // Note that versions without a specified patch sort higher than those with |
| 1267 | // a patch. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1268 | if (RHSPatch == -1) |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1269 | return true; |
| 1270 | if (Patch == -1) |
| 1271 | return false; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1272 | |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1273 | // Otherwise just sort on the patch itself. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1274 | return Patch < RHSPatch; |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1275 | } |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1276 | if (PatchSuffix != RHSPatchSuffix) { |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1277 | // Sort empty suffixes higher. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1278 | if (RHSPatchSuffix.empty()) |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1279 | return true; |
| 1280 | if (PatchSuffix.empty()) |
Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1281 | return false; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1282 | |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1283 | // Provide a lexicographic sort to make this a total ordering. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1284 | return PatchSuffix < RHSPatchSuffix; |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | // The versions are equal. |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1288 | return false; |
| 1289 | } |
| 1290 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1291 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1292 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); |
| 1293 | if (A) |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1294 | return A->getValue(); |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1295 | return GCC_INSTALL_PREFIX; |
| 1296 | } |
| 1297 | |
Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1298 | /// \brief Initialize a GCCInstallationDetector from the driver. |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1299 | /// |
| 1300 | /// This performs all of the autodetection and sets up the various paths. |
Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1301 | /// Once constructed, a GCCInstallationDetector is essentially immutable. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1302 | /// |
| 1303 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and |
| 1304 | /// should instead pull the target out of the driver. This is currently |
| 1305 | /// necessary because the driver doesn't store the final version of the target |
| 1306 | /// triple. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1307 | void Generic_GCC::GCCInstallationDetector::init( |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1308 | const llvm::Triple &TargetTriple, const ArgList &Args, |
Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1309 | ArrayRef<std::string> ExtraTripleAliases) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1310 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() |
| 1311 | ? TargetTriple.get64BitArchVariant() |
| 1312 | : TargetTriple.get32BitArchVariant(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1313 | // The library directories which may contain GCC installations. |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1314 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1315 | // The compatible GCC triples for this particular architecture. |
Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1316 | SmallVector<StringRef, 16> CandidateTripleAliases; |
| 1317 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1318 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, |
| 1319 | CandidateTripleAliases, CandidateBiarchLibDirs, |
| 1320 | CandidateBiarchTripleAliases); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1321 | |
| 1322 | // Compute the set of prefixes for our search. |
| 1323 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), |
| 1324 | D.PrefixDirs.end()); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1325 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1326 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); |
| 1327 | if (GCCToolchainDir != "") { |
| 1328 | if (GCCToolchainDir.back() == '/') |
| 1329 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1330 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1331 | Prefixes.push_back(GCCToolchainDir); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1332 | } else { |
Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1333 | // If we have a SysRoot, try that first. |
| 1334 | if (!D.SysRoot.empty()) { |
| 1335 | Prefixes.push_back(D.SysRoot); |
| 1336 | Prefixes.push_back(D.SysRoot + "/usr"); |
| 1337 | } |
| 1338 | |
| 1339 | // Then look for gcc installed alongside clang. |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1340 | Prefixes.push_back(D.InstalledDir + "/.."); |
Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1341 | |
| 1342 | // And finally in /usr. |
| 1343 | if (D.SysRoot.empty()) |
| 1344 | Prefixes.push_back("/usr"); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1345 | } |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1346 | |
| 1347 | // Loop over the various components which exist and select the best GCC |
| 1348 | // installation available. GCC installs are ranked by version number. |
| 1349 | Version = GCCVersion::Parse("0.0.0"); |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1350 | for (const std::string &Prefix : Prefixes) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1351 | if (!D.getVFS().exists(Prefix)) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1352 | continue; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1353 | for (StringRef Suffix : CandidateLibDirs) { |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1354 | const std::string LibDir = Prefix + Suffix.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1355 | if (!D.getVFS().exists(LibDir)) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1356 | continue; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1357 | for (StringRef Candidate : ExtraTripleAliases) // Try these first. |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1358 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1359 | for (StringRef Candidate : CandidateTripleAliases) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1360 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1361 | } |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1362 | for (StringRef Suffix : CandidateBiarchLibDirs) { |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1363 | const std::string LibDir = Prefix + Suffix.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1364 | if (!D.getVFS().exists(LibDir)) |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1365 | continue; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1366 | for (StringRef Candidate : CandidateBiarchTripleAliases) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1367 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1368 | /*NeedsBiarchSuffix=*/ true); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1373 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1374 | for (const auto &InstallPath : CandidateGCCInstallPaths) |
| 1375 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1376 | |
Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1377 | if (!GCCInstallPath.empty()) |
| 1378 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; |
| 1379 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1380 | for (const auto &Multilib : Multilibs) |
| 1381 | OS << "Candidate multilib: " << Multilib << "\n"; |
Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1382 | |
| 1383 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) |
| 1384 | OS << "Selected multilib: " << SelectedMultilib << "\n"; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { |
| 1388 | if (BiarchSibling.hasValue()) { |
| 1389 | M = BiarchSibling.getValue(); |
| 1390 | return true; |
| 1391 | } |
| 1392 | return false; |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1395 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1396 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1397 | SmallVectorImpl<StringRef> &LibDirs, |
| 1398 | SmallVectorImpl<StringRef> &TripleAliases, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1399 | SmallVectorImpl<StringRef> &BiarchLibDirs, |
| 1400 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1401 | // Declare a bunch of static data sets that we'll select between below. These |
| 1402 | // are specifically designed to always refer to string literals to avoid any |
| 1403 | // lifetime or initialization issues. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1404 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; |
| 1405 | static const char *const AArch64Triples[] = { |
| 1406 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", |
| 1407 | "aarch64-redhat-linux"}; |
| 1408 | static const char *const AArch64beLibDirs[] = {"/lib"}; |
| 1409 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", |
| 1410 | "aarch64_be-linux-gnu"}; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1411 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1412 | static const char *const ARMLibDirs[] = {"/lib"}; |
| 1413 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", |
| 1414 | "arm-linux-androideabi"}; |
| 1415 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", |
| 1416 | "armv7hl-redhat-linux-gnueabi"}; |
| 1417 | static const char *const ARMebLibDirs[] = {"/lib"}; |
| 1418 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", |
| 1419 | "armeb-linux-androideabi"}; |
| 1420 | static const char *const ARMebHFTriples[] = { |
| 1421 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1422 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1423 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1424 | static const char *const X86_64Triples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1425 | "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", |
| 1426 | "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E", |
| 1427 | "x86_64-redhat-linux", "x86_64-suse-linux", |
| 1428 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", |
| 1429 | "x86_64-slackware-linux", "x86_64-linux-android", |
| 1430 | "x86_64-unknown-linux"}; |
| 1431 | static const char *const X32LibDirs[] = {"/libx32"}; |
| 1432 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1433 | static const char *const X86Triples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1434 | "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", |
| 1435 | "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux", |
| 1436 | "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux", |
| 1437 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", |
| 1438 | "i586-linux-gnu"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1439 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1440 | static const char *const MIPSLibDirs[] = {"/lib"}; |
Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1441 | static const char *const MIPSTriples[] = {"mips-linux-gnu", "mips-mti-linux", |
| 1442 | "mips-mti-linux-gnu", |
| 1443 | "mips-img-linux-gnu"}; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1444 | static const char *const MIPSELLibDirs[] = {"/lib"}; |
| 1445 | static const char *const MIPSELTriples[] = { |
| 1446 | "mipsel-linux-gnu", "mipsel-linux-android", "mips-img-linux-gnu"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1447 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1448 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; |
| 1449 | static const char *const MIPS64Triples[] = { |
| 1450 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1451 | "mips64-linux-gnuabi64"}; |
| 1452 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; |
| 1453 | static const char *const MIPS64ELTriples[] = { |
| 1454 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1455 | "mips64el-linux-android", "mips64el-linux-gnuabi64"}; |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1456 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1457 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1458 | static const char *const PPCTriples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1459 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", |
| 1460 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; |
| 1461 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; |
| 1462 | static const char *const PPC64Triples[] = { |
| 1463 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", |
| 1464 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; |
| 1465 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; |
| 1466 | static const char *const PPC64LETriples[] = { |
| 1467 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", |
| 1468 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1469 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1470 | static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; |
| 1471 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", |
| 1472 | "sparcv8-linux-gnu"}; |
| 1473 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; |
| 1474 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", |
| 1475 | "sparcv9-linux-gnu"}; |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1476 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1477 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1478 | static const char *const SystemZTriples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1479 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", |
| 1480 | "s390x-suse-linux", "s390x-redhat-linux"}; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1481 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1482 | // Solaris. |
| 1483 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; |
| 1484 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", |
| 1485 | "i386-pc-solaris2.11"}; |
| 1486 | |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1487 | using std::begin; |
| 1488 | using std::end; |
| 1489 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1490 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 1491 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); |
| 1492 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1493 | return; |
| 1494 | } |
| 1495 | |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1496 | switch (TargetTriple.getArch()) { |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1497 | case llvm::Triple::aarch64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1498 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1499 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| 1500 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1501 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1502 | break; |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1503 | case llvm::Triple::aarch64_be: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1504 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1505 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| 1506 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1507 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1508 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1509 | case llvm::Triple::arm: |
| 1510 | case llvm::Triple::thumb: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1511 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1512 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1513 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1514 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1515 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1516 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1517 | break; |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1518 | case llvm::Triple::armeb: |
| 1519 | case llvm::Triple::thumbeb: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1520 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1521 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1522 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1523 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1524 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1525 | } |
| 1526 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1527 | case llvm::Triple::x86_64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1528 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1529 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| 1530 | // x32 is always available when x86_64 is available, so adding it as |
| 1531 | // secondary arch with x86_64 triples |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1532 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1533 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); |
| 1534 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1535 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1536 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1537 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1538 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1539 | break; |
| 1540 | case llvm::Triple::x86: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1541 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1542 | TripleAliases.append(begin(X86Triples), end(X86Triples)); |
| 1543 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1544 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1545 | break; |
| 1546 | case llvm::Triple::mips: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1547 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1548 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1549 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1550 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1551 | break; |
| 1552 | case llvm::Triple::mipsel: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1553 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1554 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1555 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1556 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1557 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1558 | break; |
| 1559 | case llvm::Triple::mips64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1560 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1561 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| 1562 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1563 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1564 | break; |
| 1565 | case llvm::Triple::mips64el: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1566 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1567 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| 1568 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1569 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1570 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1571 | break; |
| 1572 | case llvm::Triple::ppc: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1573 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1574 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| 1575 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1576 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1577 | break; |
| 1578 | case llvm::Triple::ppc64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1579 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1580 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| 1581 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1582 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1583 | break; |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1584 | case llvm::Triple::ppc64le: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1585 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); |
| 1586 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1587 | break; |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1588 | case llvm::Triple::sparc: |
Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1589 | case llvm::Triple::sparcel: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1590 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1591 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| 1592 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1593 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1594 | break; |
| 1595 | case llvm::Triple::sparcv9: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1596 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1597 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| 1598 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1599 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1600 | break; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1601 | case llvm::Triple::systemz: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1602 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); |
| 1603 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1604 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1605 | default: |
| 1606 | // By default, just rely on the standard lib directories and the original |
| 1607 | // triple. |
| 1608 | break; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1609 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1610 | |
| 1611 | // Always append the drivers target triple to the end, in case it doesn't |
| 1612 | // match any of our aliases. |
| 1613 | TripleAliases.push_back(TargetTriple.str()); |
| 1614 | |
| 1615 | // Also include the multiarch variant if it's different. |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1616 | if (TargetTriple.str() != BiarchTriple.str()) |
| 1617 | BiarchTripleAliases.push_back(BiarchTriple.str()); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1620 | // \brief -- try common CUDA installation paths looking for files we need for |
| 1621 | // CUDA compilation. |
| 1622 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1623 | void Generic_GCC::CudaInstallationDetector::init( |
| 1624 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { |
NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1625 | SmallVector<std::string, 4> CudaPathCandidates; |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1626 | |
| 1627 | if (Args.hasArg(options::OPT_cuda_path_EQ)) |
| 1628 | CudaPathCandidates.push_back( |
| 1629 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); |
| 1630 | else { |
| 1631 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); |
Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 1632 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.5"); |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1633 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); |
| 1634 | } |
| 1635 | |
Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1636 | for (const auto &CudaPath : CudaPathCandidates) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1637 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1638 | continue; |
| 1639 | |
| 1640 | CudaInstallPath = CudaPath; |
| 1641 | CudaIncludePath = CudaInstallPath + "/include"; |
| 1642 | CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice"; |
| 1643 | CudaLibPath = |
| 1644 | CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); |
| 1645 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1646 | if (!(D.getVFS().exists(CudaIncludePath) && |
| 1647 | D.getVFS().exists(CudaLibPath) && |
| 1648 | D.getVFS().exists(CudaLibDevicePath))) |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1649 | continue; |
| 1650 | |
Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 1651 | std::error_code EC; |
| 1652 | for (llvm::sys::fs::directory_iterator LI(CudaLibDevicePath, EC), LE; |
| 1653 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 1654 | StringRef FilePath = LI->path(); |
| 1655 | StringRef FileName = llvm::sys::path::filename(FilePath); |
| 1656 | // Process all bitcode filenames that look like libdevice.compute_XX.YY.bc |
| 1657 | const StringRef LibDeviceName = "libdevice."; |
| 1658 | if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc"))) |
| 1659 | continue; |
| 1660 | StringRef GpuArch = FileName.slice( |
| 1661 | LibDeviceName.size(), FileName.find('.', LibDeviceName.size())); |
| 1662 | CudaLibDeviceMap[GpuArch] = FilePath.str(); |
| 1663 | // Insert map entries for specifc devices with this compute capability. |
| 1664 | if (GpuArch == "compute_20") { |
| 1665 | CudaLibDeviceMap["sm_20"] = FilePath; |
| 1666 | CudaLibDeviceMap["sm_21"] = FilePath; |
| 1667 | } else if (GpuArch == "compute_30") { |
| 1668 | CudaLibDeviceMap["sm_30"] = FilePath; |
| 1669 | CudaLibDeviceMap["sm_32"] = FilePath; |
| 1670 | } else if (GpuArch == "compute_35") { |
| 1671 | CudaLibDeviceMap["sm_35"] = FilePath; |
| 1672 | CudaLibDeviceMap["sm_37"] = FilePath; |
| 1673 | } |
| 1674 | } |
| 1675 | |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1676 | IsValid = true; |
| 1677 | break; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { |
| 1682 | if (isValid()) |
| 1683 | OS << "Found CUDA installation: " << CudaInstallPath << "\n"; |
| 1684 | } |
| 1685 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1686 | namespace { |
| 1687 | // 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] | 1688 | class FilterNonExistent { |
| 1689 | StringRef Base; |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1690 | vfs::FileSystem &VFS; |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1691 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1692 | public: |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1693 | FilterNonExistent(StringRef Base, vfs::FileSystem &VFS) |
| 1694 | : Base(Base), VFS(VFS) {} |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1695 | bool operator()(const Multilib &M) { |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1696 | return !VFS.exists(Base + M.gccSuffix() + "/crtbegin.o"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1697 | } |
| 1698 | }; |
| 1699 | } // end anonymous namespace |
| 1700 | |
| 1701 | static void addMultilibFlag(bool Enabled, const char *const Flag, |
| 1702 | std::vector<std::string> &Flags) { |
| 1703 | if (Enabled) |
| 1704 | Flags.push_back(std::string("+") + Flag); |
| 1705 | else |
| 1706 | Flags.push_back(std::string("-") + Flag); |
| 1707 | } |
| 1708 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1709 | static bool isMipsArch(llvm::Triple::ArchType Arch) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1710 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || |
| 1711 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1712 | } |
| 1713 | |
| 1714 | static bool isMips32(llvm::Triple::ArchType Arch) { |
| 1715 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; |
| 1716 | } |
| 1717 | |
| 1718 | static bool isMips64(llvm::Triple::ArchType Arch) { |
| 1719 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1720 | } |
| 1721 | |
| 1722 | static bool isMipsEL(llvm::Triple::ArchType Arch) { |
| 1723 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; |
| 1724 | } |
| 1725 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1726 | static bool isMips16(const ArgList &Args) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1727 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1728 | return A && A->getOption().matches(options::OPT_mips16); |
| 1729 | } |
| 1730 | |
| 1731 | static bool isMicroMips(const ArgList &Args) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1732 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1733 | return A && A->getOption().matches(options::OPT_mmicromips); |
| 1734 | } |
| 1735 | |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1736 | namespace { |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1737 | struct DetectedMultilibs { |
| 1738 | /// The set of multilibs that the detected installation supports. |
| 1739 | MultilibSet Multilibs; |
| 1740 | |
| 1741 | /// The primary multilib appropriate for the given flags. |
| 1742 | Multilib SelectedMultilib; |
| 1743 | |
| 1744 | /// On Biarch systems, this corresponds to the default multilib when |
| 1745 | /// targeting the non-default multilib. Otherwise, it is empty. |
| 1746 | llvm::Optional<Multilib> BiarchSibling; |
| 1747 | }; |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1748 | } // end anonymous namespace |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1749 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1750 | static Multilib makeMultilib(StringRef commonSuffix) { |
| 1751 | return Multilib(commonSuffix, commonSuffix, commonSuffix); |
| 1752 | } |
| 1753 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1754 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, |
| 1755 | StringRef Path, const ArgList &Args, |
| 1756 | DetectedMultilibs &Result) { |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 1757 | // Some MIPS toolchains put libraries and object files compiled |
| 1758 | // using different options in to the sub-directoris which names |
| 1759 | // reflects the flags used for compilation. For example sysroot |
| 1760 | // directory might looks like the following examples: |
| 1761 | // |
| 1762 | // /usr |
| 1763 | // /lib <= crt*.o files compiled with '-mips32' |
| 1764 | // /mips16 |
| 1765 | // /usr |
| 1766 | // /lib <= crt*.o files compiled with '-mips16' |
| 1767 | // /el |
| 1768 | // /usr |
| 1769 | // /lib <= crt*.o files compiled with '-mips16 -EL' |
| 1770 | // |
| 1771 | // or |
| 1772 | // |
| 1773 | // /usr |
| 1774 | // /lib <= crt*.o files compiled with '-mips32r2' |
| 1775 | // /mips16 |
| 1776 | // /usr |
| 1777 | // /lib <= crt*.o files compiled with '-mips32r2 -mips16' |
| 1778 | // /mips32 |
| 1779 | // /usr |
| 1780 | // /lib <= crt*.o files compiled with '-mips32' |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 1781 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1782 | FilterNonExistent NonExistent(Path, D.getVFS()); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 1783 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1784 | // Check for FSF toolchain multilibs |
| 1785 | MultilibSet FSFMipsMultilibs; |
| 1786 | { |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1787 | auto MArchMips32 = makeMultilib("/mips32") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1788 | .flag("+m32") |
| 1789 | .flag("-m64") |
| 1790 | .flag("-mmicromips") |
| 1791 | .flag("+march=mips32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1792 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1793 | auto MArchMicroMips = makeMultilib("/micromips") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1794 | .flag("+m32") |
| 1795 | .flag("-m64") |
| 1796 | .flag("+mmicromips"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1797 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1798 | auto MArchMips64r2 = makeMultilib("/mips64r2") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1799 | .flag("-m32") |
| 1800 | .flag("+m64") |
| 1801 | .flag("+march=mips64r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1802 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1803 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( |
| 1804 | "-march=mips64r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1805 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1806 | auto MArchDefault = makeMultilib("") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1807 | .flag("+m32") |
| 1808 | .flag("-m64") |
| 1809 | .flag("-mmicromips") |
| 1810 | .flag("+march=mips32r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1811 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1812 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1813 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1814 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1815 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1816 | auto MAbi64 = |
| 1817 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1818 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1819 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1820 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1821 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1822 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1823 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1824 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1825 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1826 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1827 | FSFMipsMultilibs = |
| 1828 | MultilibSet() |
| 1829 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, |
| 1830 | MArchDefault) |
| 1831 | .Maybe(UCLibc) |
| 1832 | .Maybe(Mips16) |
| 1833 | .FilterOut("/mips64/mips16") |
| 1834 | .FilterOut("/mips64r2/mips16") |
| 1835 | .FilterOut("/micromips/mips16") |
| 1836 | .Maybe(MAbi64) |
| 1837 | .FilterOut("/micromips/64") |
| 1838 | .FilterOut("/mips32/64") |
| 1839 | .FilterOut("^/64") |
| 1840 | .FilterOut("/mips16/64") |
| 1841 | .Either(BigEndian, LittleEndian) |
| 1842 | .Maybe(SoftFloat) |
| 1843 | .Maybe(Nan2008) |
| 1844 | .FilterOut(".*sof/nan2008") |
| 1845 | .FilterOut(NonExistent) |
| 1846 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1847 | StringRef TripleStr, const Multilib &M) { |
| 1848 | std::vector<std::string> Dirs; |
| 1849 | Dirs.push_back((InstallDir + "/include").str()); |
| 1850 | std::string SysRootInc = |
| 1851 | InstallDir.str() + "/../../../../sysroot"; |
| 1852 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| 1853 | Dirs.push_back(SysRootInc + "/uclibc/usr/include"); |
| 1854 | else |
| 1855 | Dirs.push_back(SysRootInc + "/usr/include"); |
| 1856 | return Dirs; |
| 1857 | }); |
Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 1860 | // Check for Musl toolchain multilibs |
| 1861 | MultilibSet MuslMipsMultilibs; |
| 1862 | { |
| 1863 | auto MArchMipsR2 = makeMultilib("") |
| 1864 | .osSuffix("/mips-r2-hard-musl") |
| 1865 | .flag("+EB") |
| 1866 | .flag("-EL") |
| 1867 | .flag("+march=mips32r2"); |
| 1868 | |
| 1869 | auto MArchMipselR2 = makeMultilib("/mipsel-r2-hard-musl") |
| 1870 | .flag("-EB") |
| 1871 | .flag("+EL") |
| 1872 | .flag("+march=mips32r2"); |
| 1873 | |
| 1874 | MuslMipsMultilibs = MultilibSet().Either(MArchMipsR2, MArchMipselR2); |
| 1875 | |
| 1876 | // Specify the callback that computes the include directories. |
| 1877 | MuslMipsMultilibs.setIncludeDirsCallback([]( |
| 1878 | StringRef InstallDir, StringRef TripleStr, const Multilib &M) { |
| 1879 | std::vector<std::string> Dirs; |
| 1880 | Dirs.push_back( |
| 1881 | (InstallDir + "/../sysroot" + M.osSuffix() + "/usr/include").str()); |
| 1882 | return Dirs; |
| 1883 | }); |
| 1884 | } |
| 1885 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1886 | // Check for Code Sourcery toolchain multilibs |
| 1887 | MultilibSet CSMipsMultilibs; |
| 1888 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1889 | auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); |
Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1890 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1891 | auto MArchMicroMips = |
| 1892 | makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1893 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1894 | auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); |
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 UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1897 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1898 | auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1899 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1900 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1901 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1902 | auto DefaultFloat = |
| 1903 | makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1904 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1905 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1906 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1907 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1908 | |
| 1909 | // Note that this one's osSuffix is "" |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1910 | auto MAbi64 = makeMultilib("") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1911 | .gccSuffix("/64") |
| 1912 | .includeSuffix("/64") |
| 1913 | .flag("+mabi=n64") |
| 1914 | .flag("-mabi=n32") |
| 1915 | .flag("-m32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1916 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1917 | CSMipsMultilibs = |
| 1918 | MultilibSet() |
| 1919 | .Either(MArchMips16, MArchMicroMips, MArchDefault) |
| 1920 | .Maybe(UCLibc) |
| 1921 | .Either(SoftFloat, Nan2008, DefaultFloat) |
| 1922 | .FilterOut("/micromips/nan2008") |
| 1923 | .FilterOut("/mips16/nan2008") |
| 1924 | .Either(BigEndian, LittleEndian) |
| 1925 | .Maybe(MAbi64) |
| 1926 | .FilterOut("/mips16.*/64") |
| 1927 | .FilterOut("/micromips.*/64") |
| 1928 | .FilterOut(NonExistent) |
| 1929 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1930 | StringRef TripleStr, const Multilib &M) { |
| 1931 | std::vector<std::string> Dirs; |
| 1932 | Dirs.push_back((InstallDir + "/include").str()); |
| 1933 | std::string SysRootInc = |
| 1934 | InstallDir.str() + "/../../../../" + TripleStr.str(); |
| 1935 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| 1936 | Dirs.push_back(SysRootInc + "/libc/uclibc/usr/include"); |
| 1937 | else |
| 1938 | Dirs.push_back(SysRootInc + "/libc/usr/include"); |
| 1939 | return Dirs; |
| 1940 | }); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1943 | MultilibSet AndroidMipsMultilibs = |
| 1944 | MultilibSet() |
| 1945 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) |
| 1946 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) |
| 1947 | .FilterOut(NonExistent); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1948 | |
| 1949 | MultilibSet DebianMipsMultilibs; |
| 1950 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1951 | Multilib MAbiN32 = |
| 1952 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1953 | |
| 1954 | Multilib M64 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1955 | .gccSuffix("/64") |
| 1956 | .includeSuffix("/64") |
| 1957 | .flag("+m64") |
| 1958 | .flag("-m32") |
| 1959 | .flag("-mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1960 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1961 | Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1962 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1963 | DebianMipsMultilibs = |
| 1964 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1965 | } |
| 1966 | |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1967 | MultilibSet ImgMultilibs; |
| 1968 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1969 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1970 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1971 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1972 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1973 | auto MAbi64 = |
| 1974 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1975 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1976 | ImgMultilibs = |
| 1977 | MultilibSet() |
| 1978 | .Maybe(Mips64r6) |
| 1979 | .Maybe(MAbi64) |
| 1980 | .Maybe(LittleEndian) |
| 1981 | .FilterOut(NonExistent) |
| 1982 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1983 | StringRef TripleStr, const Multilib &M) { |
| 1984 | std::vector<std::string> Dirs; |
| 1985 | Dirs.push_back((InstallDir + "/include").str()); |
| 1986 | Dirs.push_back( |
| 1987 | (InstallDir + "/../../../../sysroot/usr/include").str()); |
| 1988 | return Dirs; |
| 1989 | }); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1990 | } |
| 1991 | |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 1992 | StringRef CPUName; |
| 1993 | StringRef ABIName; |
| 1994 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); |
| 1995 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1996 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| 1997 | |
| 1998 | Multilib::flags_list Flags; |
| 1999 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); |
| 2000 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); |
| 2001 | addMultilibFlag(isMips16(Args), "mips16", Flags); |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2002 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2003 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || |
Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 2004 | CPUName == "mips32r5" || CPUName == "p5600", |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2005 | "march=mips32r2", Flags); |
Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 2006 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2007 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 2008 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || |
| 2009 | CPUName == "mips64r5" || CPUName == "octeon", |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 2010 | "march=mips64r2", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2011 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 2012 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); |
Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 2013 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", |
| 2014 | Flags); |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2015 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); |
| 2016 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2017 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2018 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2019 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 2020 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2021 | |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2022 | if (TargetTriple.isAndroid()) { |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2023 | // Select Android toolchain. It's the only choice in that case. |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2024 | if (AndroidMipsMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 2025 | Result.Multilibs = AndroidMipsMultilibs; |
| 2026 | return true; |
| 2027 | } |
| 2028 | return false; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2031 | if (TargetTriple.getVendor() == llvm::Triple::MipsTechnologies && |
| 2032 | TargetTriple.getOS() == llvm::Triple::Linux && |
| 2033 | TargetTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) { |
| 2034 | if (MuslMipsMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 2035 | Result.Multilibs = MuslMipsMultilibs; |
| 2036 | return true; |
| 2037 | } |
| 2038 | return false; |
| 2039 | } |
| 2040 | |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 2041 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && |
| 2042 | TargetTriple.getOS() == llvm::Triple::Linux && |
| 2043 | TargetTriple.getEnvironment() == llvm::Triple::GNU) { |
| 2044 | // Select mips-img-linux-gnu toolchain. |
| 2045 | if (ImgMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 2046 | Result.Multilibs = ImgMultilibs; |
| 2047 | return true; |
| 2048 | } |
| 2049 | return false; |
| 2050 | } |
| 2051 | |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2052 | // Sort candidates. Toolchain that best meets the directories goes first. |
| 2053 | // Then select the first toolchains matches command line flags. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2054 | MultilibSet *candidates[] = {&DebianMipsMultilibs, &FSFMipsMultilibs, |
| 2055 | &CSMipsMultilibs}; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2056 | std::sort( |
| 2057 | std::begin(candidates), std::end(candidates), |
| 2058 | [](MultilibSet *a, MultilibSet *b) { return a->size() > b->size(); }); |
| 2059 | for (const auto &candidate : candidates) { |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2060 | if (candidate->select(Flags, Result.SelectedMultilib)) { |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2061 | if (candidate == &DebianMipsMultilibs) |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2062 | Result.BiarchSibling = Multilib(); |
| 2063 | Result.Multilibs = *candidate; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2064 | return true; |
| 2065 | } |
| 2066 | } |
| 2067 | |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2068 | { |
| 2069 | // Fallback to the regular toolchain-tree structure. |
| 2070 | Multilib Default; |
| 2071 | Result.Multilibs.push_back(Default); |
| 2072 | Result.Multilibs.FilterOut(NonExistent); |
| 2073 | |
| 2074 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { |
| 2075 | Result.BiarchSibling = Multilib(); |
| 2076 | return true; |
| 2077 | } |
| 2078 | } |
| 2079 | |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2080 | return false; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2083 | static bool findBiarchMultilibs(const Driver &D, |
| 2084 | const llvm::Triple &TargetTriple, |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2085 | StringRef Path, const ArgList &Args, |
| 2086 | bool NeedsBiarchSuffix, |
| 2087 | DetectedMultilibs &Result) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2088 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs |
| 2089 | // in what would normally be GCCInstallPath and put the 64-bit |
| 2090 | // libs in a subdirectory named 64. The simple logic we follow is that |
| 2091 | // *if* there is a subdirectory of the right name with crtbegin.o in it, |
| 2092 | // we use that. If not, and if not a biarch triple alias, we look for |
| 2093 | // crtbegin.o without the subdirectory. |
| 2094 | |
| 2095 | Multilib Default; |
| 2096 | Multilib Alt64 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2097 | .gccSuffix("/64") |
| 2098 | .includeSuffix("/64") |
| 2099 | .flag("-m32") |
| 2100 | .flag("+m64") |
| 2101 | .flag("-mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2102 | Multilib Alt32 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2103 | .gccSuffix("/32") |
| 2104 | .includeSuffix("/32") |
| 2105 | .flag("+m32") |
| 2106 | .flag("-m64") |
| 2107 | .flag("-mx32"); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2108 | Multilib Altx32 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2109 | .gccSuffix("/x32") |
| 2110 | .includeSuffix("/x32") |
| 2111 | .flag("-m32") |
| 2112 | .flag("-m64") |
| 2113 | .flag("+mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2114 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2115 | FilterNonExistent NonExistent(Path, D.getVFS()); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2116 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2117 | // Determine default multilib from: 32, 64, x32 |
| 2118 | // Also handle cases such as 64 on 32, 32 on 64, etc. |
| 2119 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; |
David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2120 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; |
Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2121 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2122 | Want = WANT64; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2123 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2124 | Want = WANT64; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2125 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2126 | Want = WANT32; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2127 | else { |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2128 | if (TargetTriple.isArch32Bit()) |
| 2129 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2130 | else if (IsX32) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2131 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2132 | else |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2133 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; |
Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2136 | if (Want == WANT32) |
| 2137 | Default.flag("+m32").flag("-m64").flag("-mx32"); |
| 2138 | else if (Want == WANT64) |
| 2139 | Default.flag("-m32").flag("+m64").flag("-mx32"); |
| 2140 | else if (Want == WANTX32) |
| 2141 | Default.flag("-m32").flag("-m64").flag("+mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2142 | else |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2143 | return false; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2144 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2145 | Result.Multilibs.push_back(Default); |
| 2146 | Result.Multilibs.push_back(Alt64); |
| 2147 | Result.Multilibs.push_back(Alt32); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2148 | Result.Multilibs.push_back(Altx32); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2149 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2150 | Result.Multilibs.FilterOut(NonExistent); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2151 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2152 | Multilib::flags_list Flags; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2153 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2154 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2155 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2156 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2157 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2158 | return false; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2159 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2160 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2161 | Result.SelectedMultilib == Altx32) |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2162 | Result.BiarchSibling = Default; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2163 | |
| 2164 | return true; |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2167 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( |
| 2168 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, |
| 2169 | const std::string &LibDir, StringRef CandidateTriple, |
| 2170 | bool NeedsBiarchSuffix) { |
| 2171 | // Solaris is a special case. The GCC installation is under |
| 2172 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we |
| 2173 | // need to iterate twice. |
| 2174 | std::error_code EC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2175 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; |
| 2176 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 2177 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2178 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| 2179 | |
| 2180 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2181 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2182 | continue; // Saw this path before; no need to look at it again. |
| 2183 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| 2184 | continue; |
| 2185 | if (CandidateVersion <= Version) |
| 2186 | continue; |
| 2187 | |
| 2188 | GCCInstallPath = |
| 2189 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2190 | if (!D.getVFS().exists(GCCInstallPath)) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2191 | continue; |
| 2192 | |
| 2193 | // If we make it here there has to be at least one GCC version, let's just |
| 2194 | // use the latest one. |
| 2195 | std::error_code EEC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2196 | for (vfs::directory_iterator |
| 2197 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), |
| 2198 | LLE; |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2199 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { |
| 2200 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2201 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2202 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); |
| 2203 | |
| 2204 | if (CandidateSubVersion > Version) |
| 2205 | Version = CandidateSubVersion; |
| 2206 | } |
| 2207 | |
| 2208 | GCCTriple.setTriple(CandidateTriple); |
| 2209 | |
| 2210 | GCCInstallPath += "/" + Version.Text; |
| 2211 | GCCParentLibPath = GCCInstallPath + "/../../../../"; |
| 2212 | |
| 2213 | IsValid = true; |
| 2214 | } |
| 2215 | } |
| 2216 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2217 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2218 | const llvm::Triple &TargetTriple, const ArgList &Args, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2219 | const std::string &LibDir, StringRef CandidateTriple, |
| 2220 | bool NeedsBiarchSuffix) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2221 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2222 | // There are various different suffixes involving the triple we |
| 2223 | // 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] | 2224 | // up to the lib directory. Specifically, the number of "up" steps |
| 2225 | // in the second half of each row is 1 + the number of path separators |
| 2226 | // in the first half. |
| 2227 | const std::string LibAndInstallSuffixes[][2] = { |
| 2228 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, |
| 2229 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2230 | // Debian puts cross-compilers in gcc-cross |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2231 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, |
| 2232 | |
| 2233 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), |
| 2234 | "/../../../.."}, |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2235 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2236 | // The Freescale PPC SDK has the gcc libraries in |
| 2237 | // <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] | 2238 | {"/" + CandidateTriple.str(), "/../.."}, |
Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2239 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2240 | // Ubuntu has a strange mis-matched pair of triples that this happens to |
| 2241 | // match. |
| 2242 | // FIXME: It may be worthwhile to generalize this and look for a second |
| 2243 | // triple. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2244 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; |
| 2245 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2246 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 2247 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, |
| 2248 | NeedsBiarchSuffix); |
| 2249 | return; |
| 2250 | } |
| 2251 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2252 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2253 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - |
| 2254 | (TargetArch != llvm::Triple::x86)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2255 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2256 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; |
Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2257 | std::error_code EC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2258 | for (vfs::directory_iterator |
| 2259 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), |
| 2260 | LE; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2261 | !EC && LI != LE; LI = LI.increment(EC)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2262 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2263 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2264 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2265 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2266 | continue; // Saw this path before; no need to look at it again. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2267 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2268 | continue; |
| 2269 | if (CandidateVersion <= Version) |
| 2270 | continue; |
Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2271 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2272 | DetectedMultilibs Detected; |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2273 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2274 | // Debian mips multilibs behave more like the rest of the biarch ones, |
| 2275 | // so handle them there |
| 2276 | if (isMipsArch(TargetArch)) { |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2277 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2278 | continue; |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2279 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2280 | NeedsBiarchSuffix, Detected)) { |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2281 | continue; |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2282 | } |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2283 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2284 | Multilibs = Detected.Multilibs; |
| 2285 | SelectedMultilib = Detected.SelectedMultilib; |
| 2286 | BiarchSibling = Detected.BiarchSibling; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2287 | Version = CandidateVersion; |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2288 | GCCTriple.setTriple(CandidateTriple); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2289 | // FIXME: We hack together the directory name here instead of |
| 2290 | // using LI to ensure stable path separators across Windows and |
| 2291 | // Linux. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2292 | GCCInstallPath = |
| 2293 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); |
| 2294 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2295 | IsValid = true; |
| 2296 | } |
| 2297 | } |
| 2298 | } |
| 2299 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2300 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2301 | const ArgList &Args) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2302 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2303 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2304 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2305 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2308 | Generic_GCC::~Generic_GCC() {} |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2309 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2310 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { |
Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2311 | switch (AC) { |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2312 | case Action::PreprocessJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2313 | if (!Preprocess) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2314 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2315 | return Preprocess.get(); |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2316 | case Action::CompileJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2317 | if (!Compile) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2318 | Compile.reset(new tools::gcc::Compiler(*this)); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2319 | return Compile.get(); |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2320 | default: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2321 | return ToolChain::getTool(AC); |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2322 | } |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2325 | Tool *Generic_GCC::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2326 | return new tools::gnutools::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2329 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2330 | |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2331 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { |
| 2332 | // Print the information about how we detected the GCC installation. |
| 2333 | GCCInstallation.print(OS); |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2334 | CudaInstallation.print(OS); |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2337 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2338 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2341 | bool Generic_GCC::isPICDefault() const { |
| 2342 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2343 | } |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2344 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2345 | bool Generic_GCC::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2346 | |
David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2347 | bool Generic_GCC::isPICDefaultForced() const { |
| 2348 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2349 | } |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2350 | |
Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2351 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { |
Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2352 | switch (getTriple().getArch()) { |
| 2353 | case llvm::Triple::x86: |
| 2354 | case llvm::Triple::x86_64: |
| 2355 | case llvm::Triple::aarch64: |
| 2356 | case llvm::Triple::aarch64_be: |
| 2357 | case llvm::Triple::arm: |
| 2358 | case llvm::Triple::armeb: |
Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2359 | case llvm::Triple::bpfel: |
| 2360 | case llvm::Triple::bpfeb: |
Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2361 | case llvm::Triple::thumb: |
| 2362 | case llvm::Triple::thumbeb: |
| 2363 | case llvm::Triple::ppc: |
| 2364 | case llvm::Triple::ppc64: |
| 2365 | case llvm::Triple::ppc64le: |
| 2366 | case llvm::Triple::sparc: |
| 2367 | case llvm::Triple::sparcel: |
| 2368 | case llvm::Triple::sparcv9: |
| 2369 | case llvm::Triple::systemz: |
| 2370 | return true; |
| 2371 | default: |
| 2372 | return false; |
| 2373 | } |
Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2376 | /// \brief Helper to add the variant paths of a libstdc++ installation. |
| 2377 | bool Generic_GCC::addLibStdCXXIncludePaths( |
| 2378 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, |
| 2379 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, |
| 2380 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2381 | if (!getVFS().exists(Base + Suffix)) |
| 2382 | return false; |
| 2383 | |
| 2384 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); |
| 2385 | |
| 2386 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If |
| 2387 | // that path exists or we have neither a GCC nor target multiarch triple, use |
| 2388 | // this vanilla search path. |
| 2389 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || |
| 2390 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { |
| 2391 | addSystemInclude(DriverArgs, CC1Args, |
| 2392 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); |
| 2393 | } else { |
| 2394 | // Otherwise try to use multiarch naming schemes which have normalized the |
| 2395 | // triples and put the triple before the suffix. |
| 2396 | // |
| 2397 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and |
| 2398 | // the target triple, so we support that here. |
| 2399 | addSystemInclude(DriverArgs, CC1Args, |
| 2400 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); |
| 2401 | addSystemInclude(DriverArgs, CC1Args, |
| 2402 | Base + "/" + TargetMultiarchTriple + Suffix); |
| 2403 | } |
| 2404 | |
| 2405 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); |
| 2406 | return true; |
| 2407 | } |
| 2408 | |
| 2409 | |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2410 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, |
| 2411 | ArgStringList &CC1Args) const { |
| 2412 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2413 | bool UseInitArrayDefault = |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2414 | getTriple().getArch() == llvm::Triple::aarch64 || |
Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2415 | getTriple().getArch() == llvm::Triple::aarch64_be || |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2416 | (getTriple().getOS() == llvm::Triple::Linux && |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2417 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || |
Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2418 | getTriple().getOS() == llvm::Triple::NaCl || |
| 2419 | (getTriple().getVendor() == llvm::Triple::MipsTechnologies && |
| 2420 | !getTriple().hasEnvironment()); |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2421 | |
| 2422 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2423 | options::OPT_fno_use_init_array, UseInitArrayDefault)) |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2424 | CC1Args.push_back("-fuse-init-array"); |
| 2425 | } |
| 2426 | |
Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2427 | /// Mips Toolchain |
| 2428 | MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D, |
| 2429 | const llvm::Triple &Triple, |
| 2430 | const ArgList &Args) |
| 2431 | : Linux(D, Triple, Args) { |
| 2432 | // Select the correct multilib according to the given arguments. |
| 2433 | DetectedMultilibs Result; |
| 2434 | findMIPSMultilibs(D, Triple, "", Args, Result); |
| 2435 | Multilibs = Result.Multilibs; |
| 2436 | SelectedMultilib = Result.SelectedMultilib; |
| 2437 | |
| 2438 | // Find out the library suffix based on the ABI. |
| 2439 | LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple); |
| 2440 | getFilePaths().clear(); |
| 2441 | getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix); |
| 2442 | |
| 2443 | // Use LLD by default. |
| 2444 | if (!Args.getLastArg(options::OPT_fuse_ld_EQ)) |
| 2445 | Linker = GetProgramPath("lld"); |
| 2446 | } |
| 2447 | |
| 2448 | void MipsLLVMToolChain::AddClangSystemIncludeArgs( |
| 2449 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2450 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2451 | return; |
| 2452 | |
| 2453 | const Driver &D = getDriver(); |
| 2454 | |
| 2455 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 2456 | SmallString<128> P(D.ResourceDir); |
| 2457 | llvm::sys::path::append(P, "include"); |
| 2458 | addSystemInclude(DriverArgs, CC1Args, P); |
| 2459 | } |
| 2460 | |
| 2461 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2462 | return; |
| 2463 | |
| 2464 | const auto &Callback = Multilibs.includeDirsCallback(); |
| 2465 | if (Callback) { |
| 2466 | const auto IncludePaths = |
| 2467 | Callback(D.getInstalledDir(), getTripleString(), SelectedMultilib); |
| 2468 | for (const auto &Path : IncludePaths) |
| 2469 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | Tool *MipsLLVMToolChain::buildLinker() const { |
| 2474 | return new tools::gnutools::Linker(*this); |
| 2475 | } |
| 2476 | |
| 2477 | std::string MipsLLVMToolChain::computeSysRoot() const { |
| 2478 | if (!getDriver().SysRoot.empty()) |
| 2479 | return getDriver().SysRoot + SelectedMultilib.osSuffix(); |
| 2480 | |
| 2481 | const std::string InstalledDir(getDriver().getInstalledDir()); |
| 2482 | std::string SysRootPath = |
| 2483 | InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix(); |
| 2484 | if (llvm::sys::fs::exists(SysRootPath)) |
| 2485 | return SysRootPath; |
| 2486 | |
| 2487 | return std::string(); |
| 2488 | } |
| 2489 | |
| 2490 | ToolChain::CXXStdlibType |
| 2491 | MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const { |
| 2492 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 2493 | if (A) { |
| 2494 | StringRef Value = A->getValue(); |
| 2495 | if (Value != "libc++") |
| 2496 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) |
| 2497 | << A->getAsString(Args); |
| 2498 | } |
| 2499 | |
| 2500 | return ToolChain::CST_Libcxx; |
| 2501 | } |
| 2502 | |
| 2503 | void MipsLLVMToolChain::AddClangCXXStdlibIncludeArgs( |
| 2504 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2505 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2506 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2507 | return; |
| 2508 | |
| 2509 | assert((GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) && |
| 2510 | "Only -lc++ (aka libcxx) is suported in this toolchain."); |
| 2511 | |
| 2512 | const auto &Callback = Multilibs.includeDirsCallback(); |
| 2513 | if (Callback) { |
| 2514 | const auto IncludePaths = Callback(getDriver().getInstalledDir(), |
| 2515 | getTripleString(), SelectedMultilib); |
| 2516 | for (const auto &Path : IncludePaths) { |
| 2517 | if (llvm::sys::fs::exists(Path + "/c++/v1")) { |
| 2518 | addSystemInclude(DriverArgs, CC1Args, Path + "/c++/v1"); |
| 2519 | break; |
| 2520 | } |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2526 | ArgStringList &CmdArgs) const { |
| 2527 | assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) && |
| 2528 | "Only -lc++ (aka libxx) is suported in this toolchain."); |
| 2529 | |
| 2530 | CmdArgs.push_back("-lc++"); |
| 2531 | CmdArgs.push_back("-lc++abi"); |
| 2532 | CmdArgs.push_back("-lunwind"); |
| 2533 | } |
| 2534 | |
| 2535 | std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, |
| 2536 | StringRef Component, |
| 2537 | bool Shared) const { |
| 2538 | SmallString<128> Path(getDriver().ResourceDir); |
| 2539 | llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix, |
| 2540 | getOS()); |
| 2541 | llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" + |
Vasileios Kalintiris | bbc9930 | 2015-11-16 15:41:30 +0000 | [diff] [blame] | 2542 | "mips" + (Shared ? ".so" : ".a"))); |
Vasileios Kalintiris | c744e12 | 2015-11-12 15:26:54 +0000 | [diff] [blame] | 2543 | return Path.str(); |
| 2544 | } |
| 2545 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2546 | /// Hexagon Toolchain |
| 2547 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2548 | std::string HexagonToolChain::GetGnuDir(const std::string &InstalledDir, |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2549 | const ArgList &Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2550 | // Locate the rest of the toolchain ... |
Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 2551 | std::string GccToolchain = getGCCToolchainDir(Args); |
| 2552 | |
| 2553 | if (!GccToolchain.empty()) |
| 2554 | return GccToolchain; |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2555 | |
| 2556 | std::string InstallRelDir = InstalledDir + "/../../gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2557 | if (getVFS().exists(InstallRelDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2558 | return InstallRelDir; |
| 2559 | |
| 2560 | std::string PrefixRelDir = std::string(LLVM_PREFIX) + "/../gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2561 | if (getVFS().exists(PrefixRelDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2562 | return PrefixRelDir; |
| 2563 | |
| 2564 | return InstallRelDir; |
| 2565 | } |
| 2566 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2567 | const char *HexagonToolChain::GetSmallDataThreshold(const ArgList &Args) { |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2568 | Arg *A; |
| 2569 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2570 | A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2571 | options::OPT_msmall_data_threshold_EQ); |
| 2572 | if (A) |
| 2573 | return A->getValue(); |
| 2574 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2575 | A = Args.getLastArg(options::OPT_shared, options::OPT_fpic, |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2576 | options::OPT_fPIC); |
| 2577 | if (A) |
| 2578 | return "0"; |
| 2579 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2580 | return nullptr; |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2583 | bool HexagonToolChain::UsesG0(const char *smallDataThreshold) { |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2584 | return smallDataThreshold && smallDataThreshold[0] == '0'; |
| 2585 | } |
| 2586 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2587 | static void GetHexagonLibraryPaths(const HexagonToolChain &TC, |
| 2588 | const ArgList &Args, const std::string &Ver, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2589 | const std::string &MarchString, |
| 2590 | const std::string &InstalledDir, |
| 2591 | ToolChain::path_list *LibPaths) { |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2592 | bool buildingLib = Args.hasArg(options::OPT_shared); |
| 2593 | |
| 2594 | //---------------------------------------------------------------------------- |
| 2595 | // -L Args |
| 2596 | //---------------------------------------------------------------------------- |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 2597 | for (Arg *A : Args.filtered(options::OPT_L)) |
| 2598 | for (const char *Value : A->getValues()) |
| 2599 | LibPaths->push_back(Value); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2600 | |
| 2601 | //---------------------------------------------------------------------------- |
| 2602 | // Other standard paths |
| 2603 | //---------------------------------------------------------------------------- |
| 2604 | const std::string MarchSuffix = "/" + MarchString; |
| 2605 | const std::string G0Suffix = "/G0"; |
| 2606 | const std::string MarchG0Suffix = MarchSuffix + G0Suffix; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2607 | const std::string RootDir = TC.GetGnuDir(InstalledDir, Args) + "/"; |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2608 | |
| 2609 | // lib/gcc/hexagon/... |
| 2610 | std::string LibGCCHexagonDir = RootDir + "lib/gcc/hexagon/"; |
| 2611 | if (buildingLib) { |
| 2612 | LibPaths->push_back(LibGCCHexagonDir + Ver + MarchG0Suffix); |
| 2613 | LibPaths->push_back(LibGCCHexagonDir + Ver + G0Suffix); |
| 2614 | } |
| 2615 | LibPaths->push_back(LibGCCHexagonDir + Ver + MarchSuffix); |
| 2616 | LibPaths->push_back(LibGCCHexagonDir + Ver); |
| 2617 | |
| 2618 | // lib/gcc/... |
| 2619 | LibPaths->push_back(RootDir + "lib/gcc"); |
| 2620 | |
| 2621 | // hexagon/lib/... |
| 2622 | std::string HexagonLibDir = RootDir + "hexagon/lib"; |
| 2623 | if (buildingLib) { |
| 2624 | LibPaths->push_back(HexagonLibDir + MarchG0Suffix); |
| 2625 | LibPaths->push_back(HexagonLibDir + G0Suffix); |
| 2626 | } |
| 2627 | LibPaths->push_back(HexagonLibDir + MarchSuffix); |
| 2628 | LibPaths->push_back(HexagonLibDir); |
| 2629 | } |
| 2630 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2631 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2632 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2633 | : Linux(D, Triple, Args) { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2634 | const std::string InstalledDir(getDriver().getInstalledDir()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2635 | const std::string GnuDir = GetGnuDir(InstalledDir, Args); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2636 | |
| 2637 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to |
| 2638 | // program paths |
| 2639 | const std::string BinDir(GnuDir + "/bin"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2640 | if (D.getVFS().exists(BinDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2641 | getProgramPaths().push_back(BinDir); |
| 2642 | |
| 2643 | // Determine version of GCC libraries and headers to use. |
| 2644 | const std::string HexagonDir(GnuDir + "/lib/gcc/hexagon"); |
Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2645 | std::error_code ec; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2646 | GCCVersion MaxVersion = GCCVersion::Parse("0.0.0"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2647 | for (vfs::directory_iterator di = D.getVFS().dir_begin(HexagonDir, ec), de; |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2648 | !ec && di != de; di = di.increment(ec)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2649 | GCCVersion cv = GCCVersion::Parse(llvm::sys::path::filename(di->getName())); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2650 | if (MaxVersion < cv) |
| 2651 | MaxVersion = cv; |
| 2652 | } |
| 2653 | GCCLibAndIncVersion = MaxVersion; |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2654 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2655 | ToolChain::path_list *LibPaths = &getFilePaths(); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2656 | |
| 2657 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets |
| 2658 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually |
| 2659 | // support 'linux' we'll need to fix this up |
| 2660 | LibPaths->clear(); |
| 2661 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2662 | GetHexagonLibraryPaths(*this, Args, GetGCCLibAndIncVersion(), |
| 2663 | GetTargetCPU(Args), InstalledDir, LibPaths); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2666 | HexagonToolChain::~HexagonToolChain() {} |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2667 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2668 | Tool *HexagonToolChain::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2669 | return new tools::hexagon::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2670 | } |
| 2671 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2672 | Tool *HexagonToolChain::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2673 | return new tools::hexagon::Linker(*this); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2676 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2677 | ArgStringList &CC1Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2678 | const Driver &D = getDriver(); |
| 2679 | |
| 2680 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 2681 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2682 | return; |
| 2683 | |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2684 | std::string Ver(GetGCCLibAndIncVersion()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2685 | std::string GnuDir = GetGnuDir(D.InstalledDir, DriverArgs); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2686 | std::string HexagonDir(GnuDir + "/lib/gcc/hexagon/" + Ver); |
| 2687 | addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include"); |
| 2688 | addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include-fixed"); |
| 2689 | addExternCSystemInclude(DriverArgs, CC1Args, GnuDir + "/hexagon/include"); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2690 | } |
| 2691 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2692 | void HexagonToolChain::AddClangCXXStdlibIncludeArgs( |
| 2693 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2694 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2695 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2696 | return; |
| 2697 | |
| 2698 | const Driver &D = getDriver(); |
| 2699 | std::string Ver(GetGCCLibAndIncVersion()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2700 | SmallString<128> IncludeDir(GetGnuDir(D.InstalledDir, DriverArgs)); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2701 | |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 2702 | llvm::sys::path::append(IncludeDir, "hexagon/include/c++/"); |
| 2703 | llvm::sys::path::append(IncludeDir, Ver); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 2704 | addSystemInclude(DriverArgs, CC1Args, IncludeDir); |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2705 | } |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2706 | |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2707 | ToolChain::CXXStdlibType |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2708 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2709 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 2710 | if (!A) |
| 2711 | return ToolChain::CST_Libstdcxx; |
| 2712 | |
| 2713 | StringRef Value = A->getValue(); |
| 2714 | if (Value != "libstdc++") { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2715 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | return ToolChain::CST_Libstdcxx; |
| 2719 | } |
| 2720 | |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2721 | static int getHexagonVersion(const ArgList &Args) { |
| 2722 | Arg *A = Args.getLastArg(options::OPT_march_EQ, options::OPT_mcpu_EQ); |
| 2723 | // Select the default CPU (v4) if none was given. |
| 2724 | if (!A) |
| 2725 | return 4; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2726 | |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2727 | // FIXME: produce errors if we cannot parse the version. |
| 2728 | StringRef WhichHexagon = A->getValue(); |
| 2729 | if (WhichHexagon.startswith("hexagonv")) { |
| 2730 | int Val; |
| 2731 | if (!WhichHexagon.substr(sizeof("hexagonv") - 1).getAsInteger(10, Val)) |
| 2732 | return Val; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2733 | } |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2734 | if (WhichHexagon.startswith("v")) { |
| 2735 | int Val; |
| 2736 | if (!WhichHexagon.substr(1).getAsInteger(10, Val)) |
| 2737 | return Val; |
| 2738 | } |
| 2739 | |
| 2740 | // FIXME: should probably be an error. |
| 2741 | return 4; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2744 | StringRef HexagonToolChain::GetTargetCPU(const ArgList &Args) { |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2745 | int V = getHexagonVersion(Args); |
| 2746 | // FIXME: We don't support versions < 4. We should error on them. |
| 2747 | switch (V) { |
| 2748 | default: |
| 2749 | llvm_unreachable("Unexpected version"); |
| 2750 | case 5: |
| 2751 | return "v5"; |
| 2752 | case 4: |
| 2753 | return "v4"; |
| 2754 | case 3: |
| 2755 | return "v3"; |
| 2756 | case 2: |
| 2757 | return "v2"; |
| 2758 | case 1: |
| 2759 | return "v1"; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2760 | } |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2761 | } |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2762 | // End Hexagon |
Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 2763 | |
Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 2764 | /// AMDGPU Toolchain |
| 2765 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2766 | const ArgList &Args) |
| 2767 | : Generic_ELF(D, Triple, Args) { } |
| 2768 | |
| 2769 | Tool *AMDGPUToolChain::buildLinker() const { |
| 2770 | return new tools::amdgpu::Linker(*this); |
| 2771 | } |
| 2772 | // End AMDGPU |
| 2773 | |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2774 | /// NaCl Toolchain |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2775 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2776 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2777 | : Generic_ELF(D, Triple, Args) { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2778 | |
| 2779 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the |
| 2780 | // default paths, and must instead only use the paths provided |
| 2781 | // with this toolchain based on architecture. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2782 | path_list &file_paths = getFilePaths(); |
| 2783 | path_list &prog_paths = getProgramPaths(); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2784 | |
| 2785 | file_paths.clear(); |
| 2786 | prog_paths.clear(); |
| 2787 | |
| 2788 | // Path for library files (libc.a, ...) |
| 2789 | std::string FilePath(getDriver().Dir + "/../"); |
| 2790 | |
| 2791 | // Path for tools (clang, ld, etc..) |
| 2792 | std::string ProgPath(getDriver().Dir + "/../"); |
| 2793 | |
| 2794 | // Path for toolchain libraries (libgcc.a, ...) |
| 2795 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); |
| 2796 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2797 | switch (Triple.getArch()) { |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2798 | case llvm::Triple::x86: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2799 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); |
Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2800 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2801 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 2802 | file_paths.push_back(ToolPath + "i686-nacl"); |
| 2803 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2804 | case llvm::Triple::x86_64: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2805 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); |
| 2806 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); |
| 2807 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 2808 | file_paths.push_back(ToolPath + "x86_64-nacl"); |
| 2809 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2810 | case llvm::Triple::arm: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2811 | file_paths.push_back(FilePath + "arm-nacl/lib"); |
| 2812 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); |
| 2813 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); |
| 2814 | file_paths.push_back(ToolPath + "arm-nacl"); |
| 2815 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2816 | case llvm::Triple::mipsel: |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2817 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); |
| 2818 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); |
| 2819 | prog_paths.push_back(ProgPath + "bin"); |
| 2820 | file_paths.push_back(ToolPath + "mipsel-nacl"); |
| 2821 | break; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2822 | default: |
| 2823 | break; |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | // Use provided linker, not system linker |
Derek Schuff | ef465d7 | 2015-08-24 23:53:25 +0000 | [diff] [blame] | 2827 | Linker = GetLinkerPath(); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2828 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); |
| 2829 | } |
| 2830 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2831 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2832 | ArgStringList &CC1Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2833 | const Driver &D = getDriver(); |
| 2834 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2835 | return; |
| 2836 | |
| 2837 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 2838 | SmallString<128> P(D.ResourceDir); |
| 2839 | llvm::sys::path::append(P, "include"); |
| 2840 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2841 | } |
| 2842 | |
| 2843 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2844 | return; |
| 2845 | |
| 2846 | SmallString<128> P(D.Dir + "/../"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2847 | switch (getTriple().getArch()) { |
Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2848 | case llvm::Triple::x86: |
| 2849 | // x86 is special because multilib style uses x86_64-nacl/include for libc |
| 2850 | // headers but the SDK wants i686-nacl/usr/include. The other architectures |
| 2851 | // have the same substring. |
| 2852 | llvm::sys::path::append(P, "i686-nacl/usr/include"); |
| 2853 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2854 | llvm::sys::path::remove_filename(P); |
| 2855 | llvm::sys::path::remove_filename(P); |
| 2856 | llvm::sys::path::remove_filename(P); |
| 2857 | llvm::sys::path::append(P, "x86_64-nacl/include"); |
| 2858 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2859 | return; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2860 | case llvm::Triple::arm: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2861 | llvm::sys::path::append(P, "arm-nacl/usr/include"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2862 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2863 | case llvm::Triple::x86_64: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2864 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2865 | break; |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2866 | case llvm::Triple::mipsel: |
| 2867 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); |
| 2868 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2869 | default: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2870 | return; |
| 2871 | } |
| 2872 | |
| 2873 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2874 | llvm::sys::path::remove_filename(P); |
| 2875 | llvm::sys::path::remove_filename(P); |
| 2876 | llvm::sys::path::append(P, "include"); |
| 2877 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2878 | } |
| 2879 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2880 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2881 | ArgStringList &CmdArgs) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2882 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 2883 | // if the value is libc++, and emits an error for other values. |
| 2884 | GetCXXStdlibType(Args); |
| 2885 | CmdArgs.push_back("-lc++"); |
| 2886 | } |
| 2887 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2888 | void NaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2889 | ArgStringList &CC1Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2890 | const Driver &D = getDriver(); |
| 2891 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2892 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2893 | return; |
| 2894 | |
| 2895 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 2896 | // if the value is libc++, and emits an error for other values. |
| 2897 | GetCXXStdlibType(DriverArgs); |
| 2898 | |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2899 | SmallString<128> P(D.Dir + "/../"); |
| 2900 | switch (getTriple().getArch()) { |
| 2901 | case llvm::Triple::arm: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2902 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); |
| 2903 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2904 | break; |
| 2905 | case llvm::Triple::x86: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2906 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 2907 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2908 | break; |
| 2909 | case llvm::Triple::x86_64: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2910 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 2911 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2912 | break; |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2913 | case llvm::Triple::mipsel: |
| 2914 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); |
| 2915 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2916 | break; |
Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 2917 | default: |
| 2918 | break; |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2919 | } |
| 2920 | } |
| 2921 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2922 | ToolChain::CXXStdlibType |
| 2923 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2924 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 2925 | StringRef Value = A->getValue(); |
| 2926 | if (Value == "libc++") |
| 2927 | return ToolChain::CST_Libcxx; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2928 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | return ToolChain::CST_Libcxx; |
| 2932 | } |
| 2933 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2934 | std::string |
| 2935 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, |
| 2936 | types::ID InputType) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2937 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); |
| 2938 | if (TheTriple.getArch() == llvm::Triple::arm && |
| 2939 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) |
| 2940 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); |
| 2941 | return TheTriple.getTriple(); |
| 2942 | } |
| 2943 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2944 | Tool *NaClToolChain::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2945 | return new tools::nacltools::Linker(*this); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2948 | Tool *NaClToolChain::buildAssembler() const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2949 | if (getTriple().getArch() == llvm::Triple::arm) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2950 | return new tools::nacltools::AssemblerARM(*this); |
| 2951 | return new tools::gnutools::Assembler(*this); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2952 | } |
| 2953 | // End NaCl |
| 2954 | |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2955 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 2956 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 2957 | /// Currently does not support anything else but compilation. |
| 2958 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2959 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 2960 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2961 | : ToolChain(D, Triple, Args) { |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2962 | // Path mangling to find libexec |
| 2963 | std::string Path(getDriver().Dir); |
| 2964 | |
| 2965 | Path += "/../libexec"; |
| 2966 | getProgramPaths().push_back(Path); |
| 2967 | } |
| 2968 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2969 | TCEToolChain::~TCEToolChain() {} |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2970 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2971 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2972 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2973 | bool TCEToolChain::isPICDefault() const { return false; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2974 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2975 | bool TCEToolChain::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2976 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2977 | bool TCEToolChain::isPICDefaultForced() const { return false; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2978 | |
Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2979 | // CloudABI - CloudABI tool chain which can call ld(1) directly. |
| 2980 | |
| 2981 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, |
| 2982 | const ArgList &Args) |
| 2983 | : Generic_ELF(D, Triple, Args) { |
| 2984 | SmallString<128> P(getDriver().Dir); |
| 2985 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); |
| 2986 | getFilePaths().push_back(P.str()); |
| 2987 | } |
| 2988 | |
| 2989 | void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2990 | ArgStringList &CC1Args) const { |
| 2991 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) && |
| 2992 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2993 | return; |
| 2994 | |
| 2995 | SmallString<128> P(getDriver().Dir); |
| 2996 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); |
| 2997 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2998 | } |
| 2999 | |
| 3000 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3001 | ArgStringList &CmdArgs) const { |
| 3002 | CmdArgs.push_back("-lc++"); |
| 3003 | CmdArgs.push_back("-lc++abi"); |
| 3004 | CmdArgs.push_back("-lunwind"); |
| 3005 | } |
| 3006 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3007 | Tool *CloudABI::buildLinker() const { |
| 3008 | return new tools::cloudabi::Linker(*this); |
| 3009 | } |
Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 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 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3040 | ToolChain::CXXStdlibType Bitrig::GetCXXStdlibType(const ArgList &Args) const { |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3041 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 3042 | StringRef Value = A->getValue(); |
| 3043 | if (Value == "libstdc++") |
| 3044 | return ToolChain::CST_Libstdcxx; |
| 3045 | if (Value == "libc++") |
| 3046 | return ToolChain::CST_Libcxx; |
| 3047 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3048 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3049 | } |
| 3050 | return ToolChain::CST_Libcxx; |
| 3051 | } |
| 3052 | |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3053 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3054 | ArgStringList &CC1Args) const { |
| 3055 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3056 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3057 | return; |
| 3058 | |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3059 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3060 | case ToolChain::CST_Libcxx: |
| 3061 | addSystemInclude(DriverArgs, CC1Args, |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3062 | getDriver().SysRoot + "/usr/include/c++/v1"); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3063 | break; |
| 3064 | case ToolChain::CST_Libstdcxx: |
| 3065 | addSystemInclude(DriverArgs, CC1Args, |
| 3066 | getDriver().SysRoot + "/usr/include/c++/stdc++"); |
| 3067 | addSystemInclude(DriverArgs, CC1Args, |
| 3068 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3069 | |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3070 | StringRef Triple = getTriple().str(); |
| 3071 | if (Triple.startswith("amd64")) |
| 3072 | addSystemInclude(DriverArgs, CC1Args, |
| 3073 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3074 | Triple.substr(5)); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3075 | else |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3076 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + |
| 3077 | "/usr/include/c++/stdc++/" + |
| 3078 | Triple); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3079 | break; |
| 3080 | } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3084 | ArgStringList &CmdArgs) const { |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3085 | switch (GetCXXStdlibType(Args)) { |
| 3086 | case ToolChain::CST_Libcxx: |
| 3087 | CmdArgs.push_back("-lc++"); |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 3088 | CmdArgs.push_back("-lc++abi"); |
| 3089 | CmdArgs.push_back("-lpthread"); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 3090 | break; |
| 3091 | case ToolChain::CST_Libstdcxx: |
| 3092 | CmdArgs.push_back("-lstdc++"); |
| 3093 | break; |
| 3094 | } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 3095 | } |
| 3096 | |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3097 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 3098 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3099 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, |
| 3100 | const ArgList &Args) |
| 3101 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 3102 | |
Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 3103 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall |
| 3104 | // back to '/usr/lib' if it doesn't exist. |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3105 | if ((Triple.getArch() == llvm::Triple::x86 || |
| 3106 | Triple.getArch() == llvm::Triple::ppc) && |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3107 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 3108 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); |
| 3109 | else |
| 3110 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3113 | ToolChain::CXXStdlibType FreeBSD::GetCXXStdlibType(const ArgList &Args) const { |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3114 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 3115 | StringRef Value = A->getValue(); |
| 3116 | if (Value == "libstdc++") |
| 3117 | return ToolChain::CST_Libstdcxx; |
| 3118 | if (Value == "libc++") |
| 3119 | return ToolChain::CST_Libcxx; |
| 3120 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3121 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3122 | } |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3123 | if (getTriple().getOSMajorVersion() >= 10) |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 3124 | return ToolChain::CST_Libcxx; |
| 3125 | return ToolChain::CST_Libstdcxx; |
| 3126 | } |
| 3127 | |
| 3128 | void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3129 | ArgStringList &CC1Args) const { |
| 3130 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3131 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3132 | return; |
| 3133 | |
| 3134 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3135 | case ToolChain::CST_Libcxx: |
| 3136 | addSystemInclude(DriverArgs, CC1Args, |
| 3137 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| 3138 | break; |
| 3139 | case ToolChain::CST_Libstdcxx: |
| 3140 | addSystemInclude(DriverArgs, CC1Args, |
| 3141 | getDriver().SysRoot + "/usr/include/c++/4.2"); |
| 3142 | addSystemInclude(DriverArgs, CC1Args, |
| 3143 | getDriver().SysRoot + "/usr/include/c++/4.2/backward"); |
| 3144 | break; |
| 3145 | } |
| 3146 | } |
| 3147 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3148 | Tool *FreeBSD::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3149 | return new tools::freebsd::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3152 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3153 | |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 3154 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { |
Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3155 | // FreeBSD uses SjLj exceptions on ARM oabi. |
| 3156 | switch (getTriple().getEnvironment()) { |
Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 3157 | case llvm::Triple::GNUEABIHF: |
Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 3158 | case llvm::Triple::GNUEABI: |
| 3159 | case llvm::Triple::EABI: |
| 3160 | return false; |
| 3161 | |
| 3162 | default: |
| 3163 | return (getTriple().getArch() == llvm::Triple::arm || |
| 3164 | getTriple().getArch() == llvm::Triple::thumb); |
| 3165 | } |
| 3166 | } |
| 3167 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3168 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } |
Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3169 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3170 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 3171 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3172 | SanitizerMask FreeBSD::getSupportedSanitizers() const { |
| 3173 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 3174 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 3175 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 3176 | getTriple().getArch() == llvm::Triple::mips64el; |
| 3177 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 3178 | Res |= SanitizerKind::Address; |
| 3179 | Res |= SanitizerKind::Vptr; |
| 3180 | if (IsX86_64 || IsMIPS64) { |
| 3181 | Res |= SanitizerKind::Leak; |
| 3182 | Res |= SanitizerKind::Thread; |
| 3183 | } |
| 3184 | if (IsX86 || IsX86_64) { |
| 3185 | Res |= SanitizerKind::SafeStack; |
| 3186 | } |
| 3187 | return Res; |
| 3188 | } |
| 3189 | |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3190 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 3191 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3192 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3193 | : Generic_ELF(D, Triple, Args) { |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3194 | |
Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3195 | if (getDriver().UseStdLib) { |
Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3196 | // When targeting a 32-bit platform, try the special directory used on |
| 3197 | // 64-bit hosts, and only fall back to the main library directory if that |
| 3198 | // doesn't work. |
| 3199 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure |
| 3200 | // what all logic is needed to emulate the '=' prefix here. |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3201 | switch (Triple.getArch()) { |
| 3202 | case llvm::Triple::x86: |
Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3203 | getFilePaths().push_back("=/usr/lib/i386"); |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3204 | break; |
| 3205 | case llvm::Triple::arm: |
Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3206 | case llvm::Triple::armeb: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3207 | case llvm::Triple::thumb: |
Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3208 | case llvm::Triple::thumbeb: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3209 | switch (Triple.getEnvironment()) { |
| 3210 | case llvm::Triple::EABI: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3211 | case llvm::Triple::GNUEABI: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3212 | getFilePaths().push_back("=/usr/lib/eabi"); |
| 3213 | break; |
Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3214 | case llvm::Triple::EABIHF: |
| 3215 | case llvm::Triple::GNUEABIHF: |
| 3216 | getFilePaths().push_back("=/usr/lib/eabihf"); |
| 3217 | break; |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3218 | default: |
| 3219 | getFilePaths().push_back("=/usr/lib/oabi"); |
| 3220 | break; |
| 3221 | } |
| 3222 | break; |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3223 | case llvm::Triple::mips64: |
| 3224 | case llvm::Triple::mips64el: |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3225 | if (tools::mips::hasMipsAbiArg(Args, "o32")) |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3226 | getFilePaths().push_back("=/usr/lib/o32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3227 | else if (tools::mips::hasMipsAbiArg(Args, "64")) |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3228 | getFilePaths().push_back("=/usr/lib/64"); |
| 3229 | break; |
Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3230 | case llvm::Triple::ppc: |
| 3231 | getFilePaths().push_back("=/usr/lib/powerpc"); |
| 3232 | break; |
Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3233 | case llvm::Triple::sparc: |
| 3234 | getFilePaths().push_back("=/usr/lib/sparc"); |
| 3235 | break; |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3236 | default: |
| 3237 | break; |
| 3238 | } |
Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3239 | |
| 3240 | getFilePaths().push_back("=/usr/lib"); |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3241 | } |
| 3242 | } |
| 3243 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3244 | Tool *NetBSD::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3245 | return new tools::netbsd::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3248 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3249 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3250 | ToolChain::CXXStdlibType NetBSD::GetCXXStdlibType(const ArgList &Args) const { |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3251 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 3252 | StringRef Value = A->getValue(); |
| 3253 | if (Value == "libstdc++") |
| 3254 | return ToolChain::CST_Libstdcxx; |
| 3255 | if (Value == "libc++") |
| 3256 | return ToolChain::CST_Libcxx; |
| 3257 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3258 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3259 | } |
| 3260 | |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3261 | unsigned Major, Minor, Micro; |
| 3262 | getTriple().getOSVersion(Major, Minor, Micro); |
Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3263 | if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 49) || Major == 0) { |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3264 | switch (getArch()) { |
Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3265 | case llvm::Triple::aarch64: |
Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3266 | case llvm::Triple::arm: |
| 3267 | case llvm::Triple::armeb: |
| 3268 | case llvm::Triple::thumb: |
| 3269 | case llvm::Triple::thumbeb: |
Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3270 | case llvm::Triple::ppc: |
Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3271 | case llvm::Triple::ppc64: |
| 3272 | case llvm::Triple::ppc64le: |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3273 | case llvm::Triple::x86: |
| 3274 | case llvm::Triple::x86_64: |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3275 | return ToolChain::CST_Libcxx; |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3276 | default: |
| 3277 | break; |
| 3278 | } |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3279 | } |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3280 | return ToolChain::CST_Libstdcxx; |
| 3281 | } |
| 3282 | |
| 3283 | void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3284 | ArgStringList &CC1Args) const { |
| 3285 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3286 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3287 | return; |
| 3288 | |
| 3289 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3290 | case ToolChain::CST_Libcxx: |
| 3291 | addSystemInclude(DriverArgs, CC1Args, |
| 3292 | getDriver().SysRoot + "/usr/include/c++/"); |
| 3293 | break; |
| 3294 | case ToolChain::CST_Libstdcxx: |
| 3295 | addSystemInclude(DriverArgs, CC1Args, |
| 3296 | getDriver().SysRoot + "/usr/include/g++"); |
| 3297 | addSystemInclude(DriverArgs, CC1Args, |
| 3298 | getDriver().SysRoot + "/usr/include/g++/backward"); |
| 3299 | break; |
| 3300 | } |
| 3301 | } |
| 3302 | |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3303 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 3304 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3305 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3306 | : Generic_ELF(D, Triple, Args) { |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3307 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3308 | getFilePaths().push_back("/usr/lib"); |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3311 | Tool *Minix::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3312 | return new tools::minix::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3313 | } |
| 3314 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3315 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3316 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3317 | static void addPathIfExists(const Driver &D, const Twine &Path, |
| 3318 | ToolChain::path_list &Paths) { |
| 3319 | if (D.getVFS().exists(Path)) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3320 | Paths.push_back(Path.str()); |
| 3321 | } |
| 3322 | |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3323 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. |
| 3324 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3325 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3326 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3327 | : Generic_GCC(D, Triple, Args) { |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3328 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3329 | GCCInstallation.init(Triple, Args); |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3330 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3331 | path_list &Paths = getFilePaths(); |
| 3332 | if (GCCInstallation.isValid()) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3333 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3334 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3335 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3336 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3337 | addPathIfExists(D, getDriver().Dir, Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3338 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3339 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3340 | |
| 3341 | std::string LibPath = "/usr/lib/"; |
| 3342 | switch (Triple.getArch()) { |
| 3343 | case llvm::Triple::x86: |
| 3344 | case llvm::Triple::sparc: |
| 3345 | break; |
| 3346 | case llvm::Triple::x86_64: |
| 3347 | LibPath += "amd64/"; |
| 3348 | break; |
| 3349 | case llvm::Triple::sparcv9: |
| 3350 | LibPath += "sparcv9/"; |
| 3351 | break; |
| 3352 | default: |
| 3353 | llvm_unreachable("Unsupported architecture"); |
| 3354 | } |
| 3355 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3356 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3359 | Tool *Solaris::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3360 | return new tools::solaris::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3363 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3364 | |
Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3365 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3366 | ArgStringList &CC1Args) const { |
| 3367 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3368 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3369 | return; |
| 3370 | |
| 3371 | // Include the support directory for things like xlocale and fudged system |
| 3372 | // headers. |
| 3373 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); |
| 3374 | |
| 3375 | if (GCCInstallation.isValid()) { |
| 3376 | GCCVersion Version = GCCInstallation.getVersion(); |
| 3377 | addSystemInclude(DriverArgs, CC1Args, |
| 3378 | getDriver().SysRoot + "/usr/gcc/" + |
| 3379 | Version.MajorStr + "." + |
| 3380 | Version.MinorStr + |
| 3381 | "/include/c++/" + Version.Text); |
| 3382 | addSystemInclude(DriverArgs, CC1Args, |
| 3383 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + |
| 3384 | "." + Version.MinorStr + "/include/c++/" + |
| 3385 | Version.Text + "/" + |
| 3386 | GCCInstallation.getTriple().str()); |
| 3387 | } |
| 3388 | } |
| 3389 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3390 | /// Distribution (very bare-bones at the moment). |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3391 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3392 | enum Distro { |
Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3393 | // NB: Releases of a particular Linux distro should be kept together |
| 3394 | // in this enum, because some tests are done by integer comparison against |
| 3395 | // the first and last known member in the family, e.g. IsRedHat(). |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3396 | ArchLinux, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3397 | DebianLenny, |
| 3398 | DebianSqueeze, |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3399 | DebianWheezy, |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3400 | DebianJessie, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3401 | DebianStretch, |
Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3402 | Exherbo, |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3403 | RHEL4, |
| 3404 | RHEL5, |
| 3405 | RHEL6, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3406 | RHEL7, |
Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3407 | Fedora, |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3408 | OpenSUSE, |
Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3409 | UbuntuHardy, |
| 3410 | UbuntuIntrepid, |
Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3411 | UbuntuJaunty, |
Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3412 | UbuntuKarmic, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3413 | UbuntuLucid, |
| 3414 | UbuntuMaverick, |
Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3415 | UbuntuNatty, |
Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3416 | UbuntuOneiric, |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3417 | UbuntuPrecise, |
Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3418 | UbuntuQuantal, |
| 3419 | UbuntuRaring, |
Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3420 | UbuntuSaucy, |
Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3421 | UbuntuTrusty, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3422 | UbuntuUtopic, |
| 3423 | UbuntuVivid, |
Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3424 | UbuntuWily, |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3425 | UbuntuXenial, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3426 | UnknownDistro |
| 3427 | }; |
| 3428 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3429 | static bool IsRedhat(enum Distro Distro) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3430 | return Distro == Fedora || (Distro >= RHEL4 && Distro <= RHEL7); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3433 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3434 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3435 | static bool IsDebian(enum Distro Distro) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3436 | return Distro >= DebianLenny && Distro <= DebianStretch; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3437 | } |
| 3438 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3439 | static bool IsUbuntu(enum Distro Distro) { |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3440 | return Distro >= UbuntuHardy && Distro <= UbuntuXenial; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3441 | } |
| 3442 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3443 | static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3444 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = |
| 3445 | llvm::MemoryBuffer::getFile("/etc/lsb-release"); |
| 3446 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3447 | StringRef Data = File.get()->getBuffer(); |
Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3448 | SmallVector<StringRef, 16> Lines; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3449 | Data.split(Lines, "\n"); |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3450 | Distro Version = UnknownDistro; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3451 | for (StringRef Line : Lines) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3452 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) |
| 3453 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) |
| 3454 | .Case("hardy", UbuntuHardy) |
| 3455 | .Case("intrepid", UbuntuIntrepid) |
| 3456 | .Case("jaunty", UbuntuJaunty) |
| 3457 | .Case("karmic", UbuntuKarmic) |
| 3458 | .Case("lucid", UbuntuLucid) |
| 3459 | .Case("maverick", UbuntuMaverick) |
| 3460 | .Case("natty", UbuntuNatty) |
| 3461 | .Case("oneiric", UbuntuOneiric) |
| 3462 | .Case("precise", UbuntuPrecise) |
| 3463 | .Case("quantal", UbuntuQuantal) |
| 3464 | .Case("raring", UbuntuRaring) |
| 3465 | .Case("saucy", UbuntuSaucy) |
| 3466 | .Case("trusty", UbuntuTrusty) |
| 3467 | .Case("utopic", UbuntuUtopic) |
| 3468 | .Case("vivid", UbuntuVivid) |
Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3469 | .Case("wily", UbuntuWily) |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3470 | .Case("xenial", UbuntuXenial) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3471 | .Default(UnknownDistro); |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3472 | return Version; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3473 | } |
| 3474 | |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3475 | File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); |
| 3476 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3477 | StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3478 | if (Data.startswith("Fedora release")) |
| 3479 | return Fedora; |
Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3480 | if (Data.startswith("Red Hat Enterprise Linux") || |
| 3481 | Data.startswith("CentOS")) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3482 | if (Data.find("release 7") != StringRef::npos) |
| 3483 | return RHEL7; |
| 3484 | else if (Data.find("release 6") != StringRef::npos) |
Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3485 | return RHEL6; |
| 3486 | else if (Data.find("release 5") != StringRef::npos) |
| 3487 | return RHEL5; |
| 3488 | else if (Data.find("release 4") != StringRef::npos) |
| 3489 | return RHEL4; |
| 3490 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3491 | return UnknownDistro; |
| 3492 | } |
| 3493 | |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3494 | File = llvm::MemoryBuffer::getFile("/etc/debian_version"); |
| 3495 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3496 | StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3497 | if (Data[0] == '5') |
| 3498 | return DebianLenny; |
Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 3499 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3500 | return DebianSqueeze; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3501 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3502 | return DebianWheezy; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3503 | else if (Data.startswith("jessie/sid") || Data[0] == '8') |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3504 | return DebianJessie; |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3505 | else if (Data.startswith("stretch/sid") || Data[0] == '9') |
| 3506 | return DebianStretch; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3507 | return UnknownDistro; |
| 3508 | } |
| 3509 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3510 | if (D.getVFS().exists("/etc/SuSE-release")) |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3511 | return OpenSUSE; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3512 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3513 | if (D.getVFS().exists("/etc/exherbo-release")) |
Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3514 | return Exherbo; |
| 3515 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3516 | if (D.getVFS().exists("/etc/arch-release")) |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3517 | return ArchLinux; |
| 3518 | |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3519 | return UnknownDistro; |
| 3520 | } |
| 3521 | |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3522 | /// \brief Get our best guess at the multiarch triple for a target. |
| 3523 | /// |
| 3524 | /// Debian-based systems are starting to use a multiarch setup where they use |
| 3525 | /// a target-triple directory in the library and header search paths. |
| 3526 | /// Unfortunately, this triple does not align with the vanilla target triple, |
| 3527 | /// so we provide a rough mapping here. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3528 | static std::string getMultiarchTriple(const Driver &D, |
| 3529 | const llvm::Triple &TargetTriple, |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3530 | StringRef SysRoot) { |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3531 | llvm::Triple::EnvironmentType TargetEnvironment = TargetTriple.getEnvironment(); |
| 3532 | |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3533 | // For most architectures, just use whatever we have rather than trying to be |
| 3534 | // clever. |
| 3535 | switch (TargetTriple.getArch()) { |
| 3536 | default: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3537 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3538 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3539 | // We use the existence of '/lib/<triple>' as a directory to detect some |
| 3540 | // common linux triples that don't quite match the Clang triple for both |
| 3541 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
| 3542 | // regardless of what the actual target triple is. |
Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 3543 | case llvm::Triple::arm: |
| 3544 | case llvm::Triple::thumb: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3545 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3546 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3547 | return "arm-linux-gnueabihf"; |
| 3548 | } else { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3549 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3550 | return "arm-linux-gnueabi"; |
| 3551 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3552 | break; |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3553 | case llvm::Triple::armeb: |
| 3554 | case llvm::Triple::thumbeb: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3555 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3556 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3557 | return "armeb-linux-gnueabihf"; |
| 3558 | } else { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3559 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3560 | return "armeb-linux-gnueabi"; |
| 3561 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3562 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3563 | case llvm::Triple::x86: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3564 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3565 | return "i386-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3566 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3567 | case llvm::Triple::x86_64: |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3568 | // 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] | 3569 | if (TargetEnvironment != llvm::Triple::GNUX32 && |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3570 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3571 | return "x86_64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3572 | break; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3573 | case llvm::Triple::aarch64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3574 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3575 | return "aarch64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3576 | break; |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3577 | case llvm::Triple::aarch64_be: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3578 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3579 | return "aarch64_be-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3580 | break; |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3581 | case llvm::Triple::mips: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3582 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3583 | return "mips-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3584 | break; |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3585 | case llvm::Triple::mipsel: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3586 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3587 | return "mipsel-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3588 | break; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3589 | case llvm::Triple::mips64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3590 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3591 | return "mips64-linux-gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3592 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3593 | return "mips64-linux-gnuabi64"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3594 | break; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3595 | case llvm::Triple::mips64el: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3596 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3597 | return "mips64el-linux-gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3598 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3599 | return "mips64el-linux-gnuabi64"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3600 | break; |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3601 | case llvm::Triple::ppc: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3602 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) |
Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 3603 | return "powerpc-linux-gnuspe"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3604 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3605 | return "powerpc-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3606 | break; |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3607 | case llvm::Triple::ppc64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3608 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3609 | return "powerpc64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3610 | break; |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3611 | case llvm::Triple::ppc64le: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3612 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3613 | return "powerpc64le-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3614 | break; |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3615 | case llvm::Triple::sparc: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3616 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3617 | return "sparc-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3618 | break; |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3619 | case llvm::Triple::sparcv9: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3620 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3621 | return "sparc64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3622 | break; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3623 | case llvm::Triple::systemz: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3624 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3625 | return "s390x-linux-gnu"; |
| 3626 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3627 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3628 | return TargetTriple.str(); |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3629 | } |
| 3630 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3631 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3632 | if (isMipsArch(Triple.getArch())) { |
| 3633 | // lib32 directory has a special meaning on MIPS targets. |
| 3634 | // It contains N32 ABI binaries. Use this folder if produce |
| 3635 | // code for N32 ABI only. |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3636 | if (tools::mips::hasMipsAbiArg(Args, "n32")) |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3637 | return "lib32"; |
| 3638 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 3639 | } |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3640 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3641 | // 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] | 3642 | // using that variant while targeting other architectures causes problems |
| 3643 | // 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] | 3644 | // with a 'lib32' library search path being considered. So we only enable |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3645 | // them when we know we may need it. |
| 3646 | // |
| 3647 | // 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] | 3648 | // reasoning about oslibdir spellings with the lib dir spellings in the |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3649 | // GCCInstallationDetector, but that is a more significant refactoring. |
| 3650 | if (Triple.getArch() == llvm::Triple::x86 || |
| 3651 | Triple.getArch() == llvm::Triple::ppc) |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3652 | return "lib32"; |
| 3653 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3654 | if (Triple.getArch() == llvm::Triple::x86_64 && |
| 3655 | Triple.getEnvironment() == llvm::Triple::GNUX32) |
| 3656 | return "libx32"; |
| 3657 | |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3658 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 3659 | } |
| 3660 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3661 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3662 | : Generic_ELF(D, Triple, Args) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3663 | GCCInstallation.init(Triple, Args); |
| 3664 | CudaInstallation.init(Triple, Args); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3665 | Multilibs = GCCInstallation.getMultilibs(); |
Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3666 | llvm::Triple::ArchType Arch = Triple.getArch(); |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3667 | std::string SysRoot = computeSysRoot(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3668 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3669 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at |
Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 3670 | // least) put various tools in a triple-prefixed directory off of the parent |
| 3671 | // of the GCC installation. We use the GCC triple here to ensure that we end |
| 3672 | // up with tools that support the same amount of cross compiling as the |
| 3673 | // detected GCC installation. For example, if we find a GCC installation |
| 3674 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be |
| 3675 | // used to target i386. |
| 3676 | // FIXME: This seems unlikely to be Linux-specific. |
Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3677 | ToolChain::path_list &PPaths = getProgramPaths(); |
Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 3678 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3679 | GCCInstallation.getTriple().str() + "/bin") |
| 3680 | .str()); |
Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3681 | |
Logan Chien | eb9162f | 2014-06-26 14:23:45 +0000 | [diff] [blame] | 3682 | Linker = GetLinkerPath(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3683 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3684 | Distro Distro = DetectDistro(D, Arch); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3685 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3686 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { |
Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 3687 | ExtraOpts.push_back("-z"); |
| 3688 | ExtraOpts.push_back("relro"); |
| 3689 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3691 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3692 | ExtraOpts.push_back("-X"); |
| 3693 | |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 3694 | const bool IsAndroid = Triple.isAndroid(); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3695 | const bool IsMips = isMipsArch(Arch); |
| 3696 | |
| 3697 | if (IsMips && !SysRoot.empty()) |
| 3698 | ExtraOpts.push_back("--sysroot=" + SysRoot); |
Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3699 | |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3700 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
| 3701 | // and the MIPS ABI require .dynsym to be sorted in different ways. |
| 3702 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
| 3703 | // ABI requires a mapping between the GOT and the symbol table. |
Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3704 | // Android loader does not support .gnu.hash. |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3705 | if (!IsMips && !IsAndroid) { |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3706 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3707 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3708 | ExtraOpts.push_back("--hash-style=gnu"); |
| 3709 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3710 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3711 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) |
| 3712 | ExtraOpts.push_back("--hash-style=both"); |
| 3713 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3714 | |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3715 | if (IsRedhat(Distro)) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3716 | ExtraOpts.push_back("--no-add-needed"); |
| 3717 | |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3718 | if ((IsDebian(Distro) && Distro >= DebianSqueeze) || IsOpenSUSE(Distro) || |
Rafael Espindola | d8f92c8 | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 3719 | (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3720 | (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3721 | ExtraOpts.push_back("--build-id"); |
| 3722 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3723 | if (IsOpenSUSE(Distro)) |
Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 3724 | ExtraOpts.push_back("--enable-new-dtags"); |
Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 3725 | |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3726 | // The selection of paths to try here is designed to match the patterns which |
| 3727 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
| 3728 | // This was determined by running GCC in a fake filesystem, creating all |
| 3729 | // possible permutations of these directories, and seeing which ones it added |
| 3730 | // to the link paths. |
| 3731 | path_list &Paths = getFilePaths(); |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3732 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3733 | const std::string OSLibDir = getOSLibDir(Triple, Args); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3734 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3735 | |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3736 | // Add the multilib suffixed paths where they are available. |
| 3737 | if (GCCInstallation.isValid()) { |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 3738 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3739 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3740 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 3741 | |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3742 | // Sourcery CodeBench MIPS toolchain holds some libraries under |
Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 3743 | // a biarch-like suffix of the GCC installation. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3744 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3745 | Paths); |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3746 | |
| 3747 | // GCC cross compiling toolchains will install target libraries which ship |
| 3748 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as |
| 3749 | // any part of the GCC installation in |
| 3750 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat |
| 3751 | // debatable, but is the reality today. We need to search this tree even |
| 3752 | // when we have a sysroot somewhere else. It is the responsibility of |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 3753 | // whomever is doing the cross build targeting a sysroot using a GCC |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3754 | // installation that is *not* within the system root to ensure two things: |
| 3755 | // |
| 3756 | // 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] | 3757 | // above must be present on the system root and found via an |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3758 | // appropriate rpath. |
| 3759 | // 2) There must not be libraries installed into |
| 3760 | // <prefix>/<triple>/<libdir> unless they should be preferred over |
| 3761 | // those within the system root. |
| 3762 | // |
| 3763 | // Note that this matches the GCC behavior. See the below comment for where |
| 3764 | // Clang diverges from GCC's behavior. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3765 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + |
| 3766 | OSLibDir + Multilib.osSuffix(), |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3767 | Paths); |
| 3768 | |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3769 | // If the GCC installation we found is inside of the sysroot, we want to |
| 3770 | // prefer libraries installed in the parent prefix of the GCC installation. |
| 3771 | // 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] | 3772 | // outside of the system root as that can pick up unintended libraries. |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3773 | // This usually happens when there is an external cross compiler on the |
| 3774 | // 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] | 3775 | // the cross. Note that GCC does include some of these directories in some |
| 3776 | // configurations but this seems somewhere between questionable and simply |
| 3777 | // a bug. |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3778 | if (StringRef(LibPath).startswith(SysRoot)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3779 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); |
| 3780 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3781 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3782 | } |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3783 | |
| 3784 | // 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] | 3785 | // of the requested system root, add its parent library paths to |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3786 | // those searched. |
| 3787 | // FIXME: It's not clear whether we should use the driver's installed |
| 3788 | // directory ('Dir' below) or the ResourceDir. |
| 3789 | if (StringRef(D.Dir).startswith(SysRoot)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3790 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); |
| 3791 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3792 | } |
| 3793 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3794 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); |
| 3795 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); |
| 3796 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); |
| 3797 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3798 | |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 3799 | // 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] | 3800 | // installations with strange symlinks. |
Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 3801 | if (GCCInstallation.isValid()) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3802 | addPathIfExists(D, |
| 3803 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3804 | "/../../" + OSLibDir, |
| 3805 | Paths); |
Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 3806 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3807 | // Add the 'other' biarch variant path |
| 3808 | Multilib BiarchSibling; |
| 3809 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3810 | addPathIfExists(D, GCCInstallation.getInstallPath() + |
| 3811 | BiarchSibling.gccSuffix(), |
| 3812 | Paths); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3813 | } |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3814 | |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3815 | // See comments above on the multilib variant for details of why this is |
| 3816 | // included even from outside the sysroot. |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3817 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| 3818 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| 3819 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3820 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + |
| 3821 | Multilib.osSuffix(), |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3822 | Paths); |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3823 | |
| 3824 | // See comments above on the multilib variant for details of why this is |
| 3825 | // only included from within the sysroot. |
| 3826 | if (StringRef(LibPath).startswith(SysRoot)) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3827 | addPathIfExists(D, LibPath, Paths); |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3828 | } |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3829 | |
| 3830 | // Similar to the logic for GCC above, if we are currently running Clang |
| 3831 | // inside of the requested system root, add its parent library path to those |
| 3832 | // searched. |
| 3833 | // FIXME: It's not clear whether we should use the driver's installed |
| 3834 | // directory ('Dir' below) or the ResourceDir. |
| 3835 | if (StringRef(D.Dir).startswith(SysRoot)) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3836 | addPathIfExists(D, D.Dir + "/../lib", Paths); |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3837 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3838 | addPathIfExists(D, SysRoot + "/lib", Paths); |
| 3839 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3840 | } |
| 3841 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3842 | bool Linux::HasNativeLLVMSupport() const { return true; } |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3843 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3844 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3845 | |
| 3846 | Tool *Linux::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3847 | return new tools::gnutools::Assembler(*this); |
Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 3848 | } |
| 3849 | |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3850 | std::string Linux::computeSysRoot() const { |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3851 | if (!getDriver().SysRoot.empty()) |
| 3852 | return getDriver().SysRoot; |
| 3853 | |
| 3854 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) |
| 3855 | return std::string(); |
| 3856 | |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3857 | // Standalone MIPS toolchains use different names for sysroot folder |
| 3858 | // and put it into different places. Here we try to check some known |
| 3859 | // variants. |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3860 | |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3861 | const StringRef InstallDir = GCCInstallation.getInstallPath(); |
| 3862 | const StringRef TripleStr = GCCInstallation.getTriple().str(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3863 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3864 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3865 | std::string Path = |
| 3866 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) |
| 3867 | .str(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3868 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3869 | if (getVFS().exists(Path)) |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3870 | return Path; |
| 3871 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3872 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3873 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3874 | if (getVFS().exists(Path)) |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3875 | return Path; |
| 3876 | |
| 3877 | return std::string(); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3878 | } |
| 3879 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3880 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3881 | ArgStringList &CC1Args) const { |
| 3882 | const Driver &D = getDriver(); |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3883 | std::string SysRoot = computeSysRoot(); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3884 | |
| 3885 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 3886 | return; |
| 3887 | |
| 3888 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3889 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3890 | |
| 3891 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 3892 | SmallString<128> P(D.ResourceDir); |
| 3893 | llvm::sys::path::append(P, "include"); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3894 | addSystemInclude(DriverArgs, CC1Args, P); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3898 | return; |
| 3899 | |
| 3900 | // Check for configure-time C include directories. |
| 3901 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 3902 | if (CIncludeDirs != "") { |
| 3903 | SmallVector<StringRef, 5> dirs; |
| 3904 | CIncludeDirs.split(dirs, ":"); |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3905 | for (StringRef dir : dirs) { |
Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 3906 | StringRef Prefix = |
| 3907 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3908 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3909 | } |
| 3910 | return; |
| 3911 | } |
| 3912 | |
| 3913 | // Lacking those, try to detect the correct set of system includes for the |
| 3914 | // target triple. |
| 3915 | |
Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3916 | // Add include directories specific to the selected multilib set and multilib. |
| 3917 | if (GCCInstallation.isValid()) { |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 3918 | const auto &Callback = Multilibs.includeDirsCallback(); |
Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3919 | if (Callback) { |
| 3920 | const auto IncludePaths = Callback(GCCInstallation.getInstallPath(), |
| 3921 | GCCInstallation.getTriple().str(), |
| 3922 | GCCInstallation.getMultilib()); |
| 3923 | for (const auto &Path : IncludePaths) |
| 3924 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); |
| 3925 | } |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3928 | // Implement generic Debian multiarch support. |
| 3929 | const StringRef X86_64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3930 | "/usr/include/x86_64-linux-gnu", |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3931 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3932 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 3933 | // in use in any released version of Debian, so we should consider |
| 3934 | // removing them. |
| 3935 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3936 | const StringRef X86MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3937 | "/usr/include/i386-linux-gnu", |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3938 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3939 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 3940 | // in use in any released version of Debian, so we should consider |
| 3941 | // removing them. |
| 3942 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", |
| 3943 | "/usr/include/i486-linux-gnu"}; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3944 | const StringRef AArch64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3945 | "/usr/include/aarch64-linux-gnu"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3946 | const StringRef ARMMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3947 | "/usr/include/arm-linux-gnueabi"}; |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3948 | const StringRef ARMHFMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3949 | "/usr/include/arm-linux-gnueabihf"}; |
| 3950 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3951 | const StringRef MIPSELMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3952 | "/usr/include/mipsel-linux-gnu"}; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3953 | const StringRef MIPS64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3954 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3955 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3956 | "/usr/include/mips64el-linux-gnu", |
| 3957 | "/usr/include/mips64el-linux-gnuabi64"}; |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3958 | const StringRef PPCMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3959 | "/usr/include/powerpc-linux-gnu"}; |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3960 | const StringRef PPC64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3961 | "/usr/include/powerpc64-linux-gnu"}; |
Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 3962 | const StringRef PPC64LEMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3963 | "/usr/include/powerpc64le-linux-gnu"}; |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3964 | const StringRef SparcMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3965 | "/usr/include/sparc-linux-gnu"}; |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3966 | const StringRef Sparc64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3967 | "/usr/include/sparc64-linux-gnu"}; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3968 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { |
| 3969 | "/usr/include/s390x-linux-gnu"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3970 | ArrayRef<StringRef> MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3971 | switch (getTriple().getArch()) { |
| 3972 | case llvm::Triple::x86_64: |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3973 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3974 | break; |
| 3975 | case llvm::Triple::x86: |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3976 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3977 | break; |
| 3978 | case llvm::Triple::aarch64: |
| 3979 | case llvm::Triple::aarch64_be: |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3980 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3981 | break; |
| 3982 | case llvm::Triple::arm: |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3983 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 3984 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; |
| 3985 | else |
| 3986 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3987 | break; |
| 3988 | case llvm::Triple::mips: |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3989 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3990 | break; |
| 3991 | case llvm::Triple::mipsel: |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3992 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3993 | break; |
| 3994 | case llvm::Triple::mips64: |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3995 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3996 | break; |
| 3997 | case llvm::Triple::mips64el: |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3998 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3999 | break; |
| 4000 | case llvm::Triple::ppc: |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4001 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4002 | break; |
| 4003 | case llvm::Triple::ppc64: |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 4004 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4005 | break; |
| 4006 | case llvm::Triple::ppc64le: |
Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 4007 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4008 | break; |
| 4009 | case llvm::Triple::sparc: |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4010 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4011 | break; |
| 4012 | case llvm::Triple::sparcv9: |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 4013 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4014 | break; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 4015 | case llvm::Triple::systemz: |
| 4016 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; |
| 4017 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 4018 | default: |
| 4019 | break; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4020 | } |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4021 | for (StringRef Dir : MultiarchIncludeDirs) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4022 | if (D.getVFS().exists(SysRoot + Dir)) { |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4023 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 4024 | break; |
| 4025 | } |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | if (getTriple().getOS() == llvm::Triple::RTEMS) |
| 4029 | return; |
| 4030 | |
Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4031 | // Add an include of '/include' directly. This isn't provided by default by |
| 4032 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 4033 | // 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] | 4034 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); |
Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 4035 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 4036 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4037 | } |
| 4038 | |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4039 | |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4040 | static std::string DetectLibcxxIncludePath(StringRef base) { |
| 4041 | std::error_code EC; |
| 4042 | int MaxVersion = 0; |
| 4043 | std::string MaxVersionString = ""; |
| 4044 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; |
| 4045 | LI = LI.increment(EC)) { |
| 4046 | StringRef VersionText = llvm::sys::path::filename(LI->path()); |
| 4047 | int Version; |
| 4048 | if (VersionText[0] == 'v' && |
| 4049 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { |
| 4050 | if (Version > MaxVersion) { |
| 4051 | MaxVersion = Version; |
| 4052 | MaxVersionString = VersionText; |
| 4053 | } |
| 4054 | } |
| 4055 | } |
| 4056 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; |
| 4057 | } |
| 4058 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4059 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 4060 | ArgStringList &CC1Args) const { |
| 4061 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4062 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4063 | return; |
| 4064 | |
Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4065 | // Check if libc++ has been enabled and provide its include paths if so. |
| 4066 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4067 | const std::string LibCXXIncludePathCandidates[] = { |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4068 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4069 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4070 | // We also check the system as for a long time this is the only place |
| 4071 | // Clang looked. |
| 4072 | // FIXME: We should really remove this. It doesn't make any sense. |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4073 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++")}; |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4074 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 4075 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4076 | continue; |
| 4077 | // Add the first candidate that exists. |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4078 | addSystemInclude(DriverArgs, CC1Args, IncludePath); |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4079 | break; |
| 4080 | } |
Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 4081 | return; |
| 4082 | } |
| 4083 | |
Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 4084 | // We need a detected GCC installation on Linux to provide libstdc++'s |
| 4085 | // headers. We handled the libc++ case above. |
| 4086 | if (!GCCInstallation.isValid()) |
| 4087 | return; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4088 | |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4089 | // By default, look for the C++ headers in an include directory adjacent to |
| 4090 | // the lib directory of the GCC installation. Note that this is expect to be |
| 4091 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. |
| 4092 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4093 | StringRef InstallDir = GCCInstallation.getInstallPath(); |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4094 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4095 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4096 | const std::string GCCMultiarchTriple = getMultiarchTriple( |
| 4097 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4098 | const std::string TargetMultiarchTriple = |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4099 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 4100 | const GCCVersion &Version = GCCInstallation.getVersion(); |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4101 | |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4102 | // The primary search for libstdc++ supports multiarch variants. |
Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 4103 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4104 | "/c++/" + Version.Text, TripleStr, |
| 4105 | GCCMultiarchTriple, TargetMultiarchTriple, |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 4106 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 4107 | return; |
| 4108 | |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4109 | // Otherwise, fall back on a bunch of options which don't use multiarch |
| 4110 | // layouts for simplicity. |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 4111 | const std::string LibStdCXXIncludePathCandidates[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4112 | // Gentoo is weird and places its headers inside the GCC install, |
| 4113 | // so if the first attempt to find the headers fails, try these patterns. |
| 4114 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + |
| 4115 | Version.MinorStr, |
| 4116 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, |
| 4117 | // Android standalone toolchain has C++ headers in yet another place. |
| 4118 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4119 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, |
| 4120 | // without a subdirectory corresponding to the gcc version. |
| 4121 | LibDir.str() + "/../include/c++", |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4122 | }; |
| 4123 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 4124 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 4125 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, |
| 4126 | /*GCCMultiarchTriple*/ "", |
| 4127 | /*TargetMultiarchTriple*/ "", |
| 4128 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 4129 | break; |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 4130 | } |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4133 | void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs, |
| 4134 | ArgStringList &CC1Args) const { |
| 4135 | if (DriverArgs.hasArg(options::OPT_nocudainc)) |
| 4136 | return; |
| 4137 | |
Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4138 | if (CudaInstallation.isValid()) { |
Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4139 | addSystemInclude(DriverArgs, CC1Args, CudaInstallation.getIncludePath()); |
Artem Belevich | 8601733 | 2015-11-17 22:28:55 +0000 | [diff] [blame] | 4140 | CC1Args.push_back("-include"); |
| 4141 | CC1Args.push_back("cuda_runtime.h"); |
| 4142 | } |
Artem Belevich | fa11ab5 | 2015-11-17 22:28:46 +0000 | [diff] [blame] | 4143 | } |
| 4144 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4145 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 4146 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4147 | SanitizerMask Linux::getSupportedSanitizers() const { |
| 4148 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 4149 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 4150 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 4151 | getTriple().getArch() == llvm::Triple::mips64el; |
Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4152 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || |
| 4153 | getTriple().getArch() == llvm::Triple::ppc64le; |
Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4154 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || |
| 4155 | getTriple().getArch() == llvm::Triple::aarch64_be; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4156 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 4157 | Res |= SanitizerKind::Address; |
| 4158 | Res |= SanitizerKind::KernelAddress; |
| 4159 | Res |= SanitizerKind::Vptr; |
Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 4160 | Res |= SanitizerKind::SafeStack; |
Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 4161 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4162 | Res |= SanitizerKind::DataFlow; |
Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 4163 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4164 | Res |= SanitizerKind::Leak; |
Renato Golin | d45c2df | 2015-08-05 18:42:41 +0000 | [diff] [blame] | 4165 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4166 | Res |= SanitizerKind::Thread; |
Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 4167 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) |
Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 4168 | Res |= SanitizerKind::Memory; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4169 | if (IsX86 || IsX86_64) { |
| 4170 | Res |= SanitizerKind::Function; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 4171 | } |
| 4172 | return Res; |
| 4173 | } |
| 4174 | |
Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 4175 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, |
| 4176 | llvm::opt::ArgStringList &CmdArgs) const { |
| 4177 | if (!needsProfileRT(Args)) return; |
| 4178 | |
| 4179 | // Add linker option -u__llvm_runtime_variable to cause runtime |
| 4180 | // initialization module to be linked in. |
| 4181 | if (!Args.hasArg(options::OPT_coverage)) |
| 4182 | CmdArgs.push_back(Args.MakeArgString( |
| 4183 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); |
| 4184 | ToolChain::addProfileRTLibs(Args, CmdArgs); |
| 4185 | } |
| 4186 | |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4187 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 4188 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4189 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, |
| 4190 | const ArgList &Args) |
| 4191 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4192 | |
| 4193 | // Path mangling to find libexec |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4194 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 4195 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4196 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4197 | |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4198 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4199 | getFilePaths().push_back("/usr/lib"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4200 | if (D.getVFS().exists("/usr/lib/gcc47")) |
John McCall | 65b8da0 | 2013-04-11 22:55:55 +0000 | [diff] [blame] | 4201 | getFilePaths().push_back("/usr/lib/gcc47"); |
| 4202 | else |
| 4203 | getFilePaths().push_back("/usr/lib/gcc44"); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4204 | } |
| 4205 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4206 | Tool *DragonFly::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4207 | return new tools::dragonfly::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | Tool *DragonFly::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4211 | return new tools::dragonfly::Linker(*this); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4212 | } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4213 | |
Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4214 | /// Stub for CUDA toolchain. At the moment we don't have assembler or |
| 4215 | /// linker and need toolchain mainly to propagate device-side options |
| 4216 | /// to CC1. |
| 4217 | |
| 4218 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4219 | const ArgList &Args) |
| 4220 | : Linux(D, Triple, Args) {} |
| 4221 | |
| 4222 | void |
| 4223 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, |
| 4224 | llvm::opt::ArgStringList &CC1Args) const { |
| 4225 | Linux::addClangTargetOptions(DriverArgs, CC1Args); |
| 4226 | CC1Args.push_back("-fcuda-is-device"); |
Artem Belevich | 34f481a | 2015-11-17 22:28:50 +0000 | [diff] [blame] | 4227 | |
| 4228 | if (DriverArgs.hasArg(options::OPT_nocudalib)) |
| 4229 | return; |
| 4230 | |
| 4231 | std::string LibDeviceFile = CudaInstallation.getLibDeviceFile( |
| 4232 | DriverArgs.getLastArgValue(options::OPT_march_EQ)); |
| 4233 | if (!LibDeviceFile.empty()) { |
| 4234 | CC1Args.push_back("-mlink-cuda-bitcode"); |
| 4235 | CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile)); |
| 4236 | |
| 4237 | // Libdevice in CUDA-7.0 requires PTX version that's more recent |
| 4238 | // than LLVM defaults to. Use PTX4.2 which is the PTX version that |
| 4239 | // came with CUDA-7.0. |
| 4240 | CC1Args.push_back("-target-feature"); |
| 4241 | CC1Args.push_back("+ptx42"); |
| 4242 | } |
Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4243 | } |
| 4244 | |
| 4245 | llvm::opt::DerivedArgList * |
| 4246 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, |
| 4247 | const char *BoundArch) const { |
| 4248 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 4249 | const OptTable &Opts = getDriver().getOpts(); |
| 4250 | |
| 4251 | for (Arg *A : Args) { |
| 4252 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 4253 | // Skip this argument unless the architecture matches BoundArch |
| 4254 | if (A->getValue(0) != StringRef(BoundArch)) |
| 4255 | continue; |
| 4256 | |
| 4257 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| 4258 | unsigned Prev = Index; |
| 4259 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| 4260 | |
| 4261 | // If the argument parsing failed or more than one argument was |
| 4262 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 4263 | // extra arguments. Emit an error and ignore. |
| 4264 | // |
| 4265 | // We also want to disallow any options which would alter the |
| 4266 | // driver behavior; that isn't going to work in our model. We |
| 4267 | // use isDriverOption() as an approximation, although things |
| 4268 | // like -O4 are going to slip through. |
| 4269 | if (!XarchArg || Index > Prev + 1) { |
| 4270 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| 4271 | << A->getAsString(Args); |
| 4272 | continue; |
| 4273 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| 4274 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| 4275 | << A->getAsString(Args); |
| 4276 | continue; |
| 4277 | } |
| 4278 | XarchArg->setBaseArg(A); |
| 4279 | A = XarchArg.release(); |
| 4280 | DAL->AddSynthesizedArg(A); |
| 4281 | } |
| 4282 | DAL->append(A); |
| 4283 | } |
| 4284 | |
| 4285 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); |
| 4286 | return DAL; |
| 4287 | } |
| 4288 | |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4289 | /// XCore tool chain |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4290 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4291 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4292 | : ToolChain(D, Triple, Args) { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4293 | // ProgramPaths are found via 'PATH' environment variable. |
| 4294 | } |
| 4295 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4296 | Tool *XCoreToolChain::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4297 | return new tools::XCore::Assembler(*this); |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4298 | } |
| 4299 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4300 | Tool *XCoreToolChain::buildLinker() const { |
| 4301 | return new tools::XCore::Linker(*this); |
| 4302 | } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4303 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4304 | bool XCoreToolChain::isPICDefault() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4305 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4306 | bool XCoreToolChain::isPIEDefault() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4307 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4308 | bool XCoreToolChain::isPICDefaultForced() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4309 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4310 | bool XCoreToolChain::SupportsProfiling() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4311 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4312 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4313 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4314 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4315 | ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4316 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 4317 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 4318 | return; |
| 4319 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { |
| 4320 | SmallVector<StringRef, 4> Dirs; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4321 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4322 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4323 | ArrayRef<StringRef> DirVec(Dirs); |
| 4324 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4325 | } |
| 4326 | } |
| 4327 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4328 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, |
| 4329 | ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4330 | CC1Args.push_back("-nostdsysteminc"); |
| 4331 | } |
| 4332 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4333 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( |
| 4334 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4335 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 4336 | DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4337 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4338 | return; |
| 4339 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { |
| 4340 | SmallVector<StringRef, 4> Dirs; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4341 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4342 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4343 | ArrayRef<StringRef> DirVec(Dirs); |
| 4344 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4345 | } |
| 4346 | } |
| 4347 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4348 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 4349 | ArgStringList &CmdArgs) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4350 | // We don't output any lib args. This is handled by xcc. |
| 4351 | } |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4352 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4353 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4354 | const ArgList &Args) |
| 4355 | : Generic_GCC(D, Triple, Args) { |
| 4356 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use |
| 4357 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. |
| 4358 | // This won't work to find gcc. Instead we give the installation detector an |
| 4359 | // extra triple, which is preferable to further hacks of the logic that at |
| 4360 | // present is based solely on getArch(). In particular, it would be wrong to |
| 4361 | // choose the myriad installation when targeting a non-myriad sparc install. |
| 4362 | switch (Triple.getArch()) { |
| 4363 | default: |
| 4364 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() << "myriad"; |
| 4365 | case llvm::Triple::sparc: |
| 4366 | case llvm::Triple::sparcel: |
| 4367 | case llvm::Triple::shave: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4368 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4369 | } |
Douglas Katzman | 674a312 | 2015-11-18 16:24:46 +0000 | [diff] [blame^] | 4370 | |
| 4371 | if (GCCInstallation.isValid()) { |
| 4372 | // The contents of LibDir are independent of the version of gcc. |
| 4373 | // This contains libc, libg (a superset of libc), libm, libstdc++, libssp. |
| 4374 | SmallString<128> LibDir(GCCInstallation.getParentLibPath()); |
| 4375 | if (Triple.getArch() == llvm::Triple::sparcel) |
| 4376 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib/le"); |
| 4377 | else |
| 4378 | llvm::sys::path::append(LibDir, "../sparc-myriad-elf/lib"); |
| 4379 | addPathIfExists(D, LibDir, getFilePaths()); |
| 4380 | |
| 4381 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. |
| 4382 | // These files are tied to a particular version of gcc. |
| 4383 | SmallString<128> CompilerSupportDir(GCCInstallation.getInstallPath()); |
| 4384 | // There are actually 4 choices: {le,be} x {fpu,nofpu} |
| 4385 | // but as this toolchain is for LEON sparc, it can assume FPU. |
| 4386 | if (Triple.getArch() == llvm::Triple::sparcel) |
| 4387 | llvm::sys::path::append(CompilerSupportDir, "le"); |
| 4388 | addPathIfExists(D, CompilerSupportDir, getFilePaths()); |
| 4389 | } |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4390 | } |
| 4391 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4392 | MyriadToolChain::~MyriadToolChain() {} |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4393 | |
Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 4394 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4395 | ArgStringList &CC1Args) const { |
| 4396 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4397 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 4398 | } |
| 4399 | |
James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4400 | void MyriadToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 4401 | ArgStringList &CC1Args) const { |
| 4402 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4403 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4404 | return; |
| 4405 | |
| 4406 | // Only libstdc++, for now. |
| 4407 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4408 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| 4409 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| 4410 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| 4411 | |
| 4412 | addLibStdCXXIncludePaths(LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4413 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); |
| 4414 | } |
| 4415 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4416 | // MyriadToolChain handles several triples: |
| 4417 | // {shave,sparc{,el}}-myriad-{rtems,unknown}-elf |
| 4418 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { |
| 4419 | // The inherited method works fine if not targeting the SHAVE. |
| 4420 | if (!isShaveCompilation(getTriple())) |
| 4421 | return ToolChain::SelectTool(JA); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4422 | switch (JA.getKind()) { |
| 4423 | case Action::CompileJobClass: |
| 4424 | if (!Compiler) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4425 | Compiler.reset(new tools::SHAVE::Compiler(*this)); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4426 | return Compiler.get(); |
| 4427 | case Action::AssembleJobClass: |
| 4428 | if (!Assembler) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4429 | Assembler.reset(new tools::SHAVE::Assembler(*this)); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4430 | return Assembler.get(); |
| 4431 | default: |
| 4432 | return ToolChain::getTool(JA.getKind()); |
| 4433 | } |
| 4434 | } |
| 4435 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4436 | Tool *MyriadToolChain::buildLinker() const { |
| 4437 | return new tools::Myriad::Linker(*this); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4438 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4439 | |
| 4440 | bool WebAssembly::IsMathErrnoDefault() const { return false; } |
| 4441 | |
| 4442 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } |
| 4443 | |
| 4444 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } |
| 4445 | |
| 4446 | bool WebAssembly::isPICDefault() const { return false; } |
| 4447 | |
| 4448 | bool WebAssembly::isPIEDefault() const { return false; } |
| 4449 | |
| 4450 | bool WebAssembly::isPICDefaultForced() const { return false; } |
| 4451 | |
| 4452 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } |
| 4453 | |
| 4454 | // TODO: Support Objective C stuff. |
| 4455 | bool WebAssembly::SupportsObjCGC() const { return false; } |
| 4456 | |
| 4457 | bool WebAssembly::hasBlocksRuntime() const { return false; } |
| 4458 | |
| 4459 | // TODO: Support profiling. |
| 4460 | bool WebAssembly::SupportsProfiling() const { return false; } |
| 4461 | |
| 4462 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, |
| 4463 | ArgStringList &CC1Args) const { |
| 4464 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 4465 | options::OPT_fno_use_init_array, true)) |
| 4466 | CC1Args.push_back("-fuse-init-array"); |
| 4467 | } |
Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4468 | |
| 4469 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 4470 | : Generic_ELF(D, Triple, Args) { |
| 4471 | if (Args.hasArg(options::OPT_static)) |
| 4472 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; |
| 4473 | |
| 4474 | // Determine where to find the PS4 libraries. We use SCE_PS4_SDK_DIR |
| 4475 | // if it exists; otherwise use the driver's installation path, which |
| 4476 | // should be <SDK_DIR>/host_tools/bin. |
| 4477 | |
| 4478 | SmallString<512> PS4SDKDir; |
| 4479 | if (const char *EnvValue = getenv("SCE_PS4_SDK_DIR")) { |
| 4480 | if (!llvm::sys::fs::exists(EnvValue)) |
| 4481 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; |
| 4482 | PS4SDKDir = EnvValue; |
| 4483 | } else { |
| 4484 | PS4SDKDir = getDriver().Dir; |
| 4485 | llvm::sys::path::append(PS4SDKDir, "/../../"); |
| 4486 | } |
| 4487 | |
| 4488 | // By default, the driver won't report a warning if it can't find |
| 4489 | // PS4's include or lib directories. This behavior could be changed if |
| 4490 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. |
| 4491 | // If -isysroot was passed, use that as the SDK base path. |
| 4492 | std::string PrefixDir; |
| 4493 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 4494 | PrefixDir = A->getValue(); |
| 4495 | if (!llvm::sys::fs::exists(PrefixDir)) |
| 4496 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; |
| 4497 | } else |
| 4498 | PrefixDir = PS4SDKDir.str(); |
| 4499 | |
| 4500 | SmallString<512> PS4SDKIncludeDir(PrefixDir); |
| 4501 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); |
| 4502 | if (!Args.hasArg(options::OPT_nostdinc) && |
| 4503 | !Args.hasArg(options::OPT_nostdlibinc) && |
| 4504 | !Args.hasArg(options::OPT_isysroot) && |
| 4505 | !Args.hasArg(options::OPT__sysroot_EQ) && |
| 4506 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { |
| 4507 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 4508 | << "PS4 system headers" << PS4SDKIncludeDir; |
| 4509 | } |
| 4510 | |
| 4511 | SmallString<512> PS4SDKLibDir(PS4SDKDir); |
| 4512 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); |
| 4513 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4514 | !Args.hasArg(options::OPT_nodefaultlibs) && |
| 4515 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && |
| 4516 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && |
| 4517 | !Args.hasArg(options::OPT_emit_ast) && |
| 4518 | !llvm::sys::fs::exists(PS4SDKLibDir)) { |
| 4519 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 4520 | << "PS4 system libraries" << PS4SDKLibDir; |
| 4521 | return; |
| 4522 | } |
| 4523 | getFilePaths().push_back(PS4SDKLibDir.str()); |
| 4524 | } |
| 4525 | |
| 4526 | Tool *PS4CPU::buildAssembler() const { |
| 4527 | return new tools::PS4cpu::Assemble(*this); |
| 4528 | } |
| 4529 | |
| 4530 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } |
| 4531 | |
| 4532 | bool PS4CPU::isPICDefault() const { return true; } |
| 4533 | |
| 4534 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } |
| 4535 | |
| 4536 | SanitizerMask PS4CPU::getSupportedSanitizers() const { |
| 4537 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 4538 | Res |= SanitizerKind::Address; |
| 4539 | Res |= SanitizerKind::Vptr; |
| 4540 | return Res; |
| 4541 | } |