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. |
| 327 | if (isTargetIOSBased()) |
| 328 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a", |
| 329 | /*AlwaysLink*/ true); |
| 330 | else |
| 331 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a", |
| 332 | /*AlwaysLink*/ true); |
Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 333 | return; |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 336 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, |
| 337 | ArgStringList &CmdArgs, |
| 338 | StringRef Sanitizer) const { |
| 339 | if (!Args.hasArg(options::OPT_dynamiclib) && |
| 340 | !Args.hasArg(options::OPT_bundle)) { |
| 341 | // Sanitizer runtime libraries requires C++. |
| 342 | AddCXXStdlibLibArgs(Args, CmdArgs); |
| 343 | } |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 344 | // ASan is not supported on watchOS. |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 345 | assert(isTargetMacOS() || isTargetIOSSimulator()); |
| 346 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 347 | AddLinkRuntimeLib( |
| 348 | Args, CmdArgs, |
| 349 | (Twine("libclang_rt.") + Sanitizer + "_" + OS + "_dynamic.dylib").str(), |
| 350 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, |
| 351 | /*AddRPath*/ true); |
Hans Wennborg | 10821e5 | 2015-04-09 18:47:01 +0000 | [diff] [blame] | 352 | |
| 353 | if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { |
| 354 | // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export |
| 355 | // all RTTI-related symbols that UBSan uses. |
| 356 | CmdArgs.push_back("-lc++abi"); |
| 357 | } |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 360 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 361 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 362 | // Darwin only supports the compiler-rt based runtime libraries. |
| 363 | switch (GetRuntimeLibType(Args)) { |
| 364 | case ToolChain::RLT_CompilerRT: |
| 365 | break; |
| 366 | default: |
| 367 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 368 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 369 | return; |
| 370 | } |
| 371 | |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 372 | // Darwin doesn't support real static executables, don't link any runtime |
| 373 | // libraries with -static. |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 374 | if (Args.hasArg(options::OPT_static) || |
| 375 | Args.hasArg(options::OPT_fapple_kext) || |
| 376 | Args.hasArg(options::OPT_mkernel)) |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 377 | return; |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 378 | |
| 379 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 380 | // cares. This is useful in situations where someone wants to statically link |
| 381 | // something like libstdc++, and needs its runtime support routines. |
| 382 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 383 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 384 | return; |
| 385 | } |
| 386 | |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 387 | const SanitizerArgs &Sanitize = getSanitizerArgs(); |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 388 | if (Sanitize.needsAsanRt()) |
| 389 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); |
| 390 | if (Sanitize.needsUbsanRt()) |
| 391 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); |
Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 392 | if (Sanitize.needsTsanRt()) |
| 393 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); |
Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 394 | |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 395 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 396 | // target specific static runtime library. |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 397 | CmdArgs.push_back("-lSystem"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 398 | |
| 399 | // Select the dynamic runtime library and the target specific static library. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 400 | if (isTargetWatchOSBased()) { |
| 401 | // We currently always need a static runtime library for watchOS. |
| 402 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); |
| 403 | } else if (isTargetTvOSBased()) { |
| 404 | // We currently always need a static runtime library for tvOS. |
| 405 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); |
| 406 | } else if (isTargetIOSBased()) { |
Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 407 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, |
| 408 | // it never went into the SDK. |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 409 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 410 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && |
Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 411 | getTriple().getArch() != llvm::Triple::aarch64) |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 412 | CmdArgs.push_back("-lgcc_s.1"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 413 | |
Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 414 | // We currently always need a static runtime library for iOS. |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 415 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 416 | } else { |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 417 | assert(isTargetMacOS() && "unexpected non MacOS platform"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 418 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 419 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 420 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 421 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 422 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 423 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 424 | |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 425 | // 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] | 426 | // targeting 10.4, to provide versions of the static functions which were |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 427 | // omitted from 10.4.dylib. |
| 428 | // |
| 429 | // Unfortunately, that turned out to not be true, because Darwin system |
| 430 | // headers can still use eprintf on i386, and it is not exported from |
| 431 | // libSystem. Therefore, we still must provide a runtime library just for |
| 432 | // the tiny tiny handful of projects that *might* use that symbol. |
| 433 | if (isMacosxVersionLT(10, 5)) { |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 434 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 435 | } else { |
| 436 | if (getTriple().getArch() == llvm::Triple::x86) |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 437 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); |
| 438 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 439 | } |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 440 | } |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 443 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 444 | const OptTable &Opts = getDriver().getOpts(); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 445 | |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 446 | // Support allowing the SDKROOT environment variable used by xcrun and other |
| 447 | // Xcode tools to define the default sysroot, by making it the default for |
| 448 | // isysroot. |
Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 449 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 450 | // Warn if the path does not exist. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 451 | if (!getVFS().exists(A->getValue())) |
Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 452 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); |
| 453 | } else { |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 454 | if (char *env = ::getenv("SDKROOT")) { |
Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 455 | // We only use this value as the default if it is an absolute path, |
| 456 | // exists, and it is not the root path. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 457 | if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) && |
Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 458 | StringRef(env) != "/") { |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 459 | Args.append(Args.MakeSeparateArg( |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 460 | nullptr, Opts.getOption(options::OPT_isysroot), env)); |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 465 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 466 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 467 | Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ); |
| 468 | Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ); |
Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 469 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 470 | if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 471 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 472 | << OSXVersion->getAsString(Args) |
| 473 | << (iOSVersion ? iOSVersion : |
| 474 | TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 475 | iOSVersion = TvOSVersion = WatchOSVersion = nullptr; |
| 476 | } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) { |
| 477 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 478 | << iOSVersion->getAsString(Args) |
| 479 | << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 480 | TvOSVersion = WatchOSVersion = nullptr; |
| 481 | } else if (TvOSVersion && WatchOSVersion) { |
| 482 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 483 | << TvOSVersion->getAsString(Args) |
| 484 | << WatchOSVersion->getAsString(Args); |
| 485 | WatchOSVersion = nullptr; |
| 486 | } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) { |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 487 | // If no deployment target was specified on the command line, check for |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 488 | // environment defines. |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 489 | std::string OSXTarget; |
| 490 | std::string iOSTarget; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 491 | std::string TvOSTarget; |
| 492 | std::string WatchOSTarget; |
| 493 | |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 494 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) |
| 495 | OSXTarget = env; |
| 496 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) |
| 497 | iOSTarget = env; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 498 | if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET")) |
| 499 | TvOSTarget = env; |
| 500 | if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET")) |
| 501 | WatchOSTarget = env; |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 502 | |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 503 | // If there is no command-line argument to specify the Target version and |
| 504 | // no environment variable defined, see if we can set the default based |
| 505 | // on -isysroot. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 506 | if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() && |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 507 | Args.hasArg(options::OPT_isysroot)) { |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 508 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 509 | StringRef isysroot = A->getValue(); |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 510 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk |
| 511 | size_t BeginSDK = isysroot.rfind("SDKs/"); |
| 512 | size_t EndSDK = isysroot.rfind(".sdk"); |
| 513 | if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { |
| 514 | StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); |
| 515 | // Slice the version number out. |
| 516 | // Version number is between the first and the last number. |
| 517 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 518 | size_t EndVer = SDK.find_last_of("0123456789"); |
| 519 | if (StartVer != StringRef::npos && EndVer > StartVer) { |
| 520 | StringRef Version = SDK.slice(StartVer, EndVer + 1); |
| 521 | if (SDK.startswith("iPhoneOS") || |
| 522 | SDK.startswith("iPhoneSimulator")) |
| 523 | iOSTarget = Version; |
| 524 | else if (SDK.startswith("MacOSX")) |
| 525 | OSXTarget = Version; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 526 | else if (SDK.startswith("WatchOS") || |
| 527 | SDK.startswith("WatchSimulator")) |
| 528 | WatchOSTarget = Version; |
| 529 | else if (SDK.startswith("AppleTVOS") || |
| 530 | SDK.startswith("AppleTVSimulator")) |
| 531 | TvOSTarget = Version; |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 532 | } |
| 533 | } |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 534 | } |
| 535 | } |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 536 | |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 537 | // 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] | 538 | // from arch name and compute the version from the triple. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 539 | if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() && |
| 540 | WatchOSTarget.empty()) { |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 541 | StringRef MachOArchName = getMachOArchName(Args); |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 542 | unsigned Major, Minor, Micro; |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 543 | if (MachOArchName == "armv7" || MachOArchName == "armv7s" || |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 544 | MachOArchName == "arm64") { |
| 545 | getTriple().getiOSVersion(Major, Minor, Micro); |
| 546 | llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' |
| 547 | << Micro; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 548 | } else if (MachOArchName == "armv7k") { |
| 549 | getTriple().getWatchOSVersion(Major, Minor, Micro); |
| 550 | llvm::raw_string_ostream(WatchOSTarget) << Major << '.' << Minor << '.' |
| 551 | << Micro; |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 552 | } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && |
| 553 | MachOArchName != "armv7em") { |
| 554 | if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { |
| 555 | getDriver().Diag(diag::err_drv_invalid_darwin_version) |
| 556 | << getTriple().getOSName(); |
| 557 | } |
| 558 | llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' |
| 559 | << Micro; |
| 560 | } |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 561 | } |
Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 562 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 563 | // Do not allow conflicts with the watchOS target. |
| 564 | if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) { |
| 565 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 566 | << "WATCHOS_DEPLOYMENT_TARGET" |
| 567 | << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" : |
| 568 | "TVOS_DEPLOYMENT_TARGET"); |
| 569 | } |
| 570 | |
| 571 | // Do not allow conflicts with the tvOS target. |
| 572 | if (!TvOSTarget.empty() && !iOSTarget.empty()) { |
| 573 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 574 | << "TVOS_DEPLOYMENT_TARGET" |
| 575 | << "IPHONEOS_DEPLOYMENT_TARGET"; |
| 576 | } |
| 577 | |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 578 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 579 | // default platform. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 580 | if (!OSXTarget.empty() && (!iOSTarget.empty() || |
| 581 | !WatchOSTarget.empty() || |
| 582 | !TvOSTarget.empty())) { |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 583 | if (getTriple().getArch() == llvm::Triple::arm || |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 584 | getTriple().getArch() == llvm::Triple::aarch64 || |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 585 | getTriple().getArch() == llvm::Triple::thumb) |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 586 | OSXTarget = ""; |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 587 | else |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 588 | iOSTarget = WatchOSTarget = TvOSTarget = ""; |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 589 | } |
Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 590 | |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 591 | if (!OSXTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 592 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 593 | OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 594 | Args.append(OSXVersion); |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 595 | } else if (!iOSTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 596 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 597 | iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 598 | Args.append(iOSVersion); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 599 | } else if (!TvOSTarget.empty()) { |
| 600 | const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ); |
| 601 | TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget); |
| 602 | Args.append(TvOSVersion); |
| 603 | } else if (!WatchOSTarget.empty()) { |
| 604 | const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ); |
| 605 | WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget); |
| 606 | Args.append(WatchOSVersion); |
Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 607 | } |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 608 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 609 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 610 | DarwinPlatformKind Platform; |
| 611 | if (OSXVersion) |
| 612 | Platform = MacOS; |
| 613 | else if (iOSVersion) |
| 614 | Platform = IPhoneOS; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 615 | else if (TvOSVersion) |
| 616 | Platform = TvOS; |
| 617 | else if (WatchOSVersion) |
| 618 | Platform = WatchOS; |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 619 | else |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 620 | llvm_unreachable("Unable to infer Darwin variant"); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 621 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 622 | // Set the tool chain target information. |
| 623 | unsigned Major, Minor, Micro; |
| 624 | bool HadExtra; |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 625 | if (Platform == MacOS) { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 626 | assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && |
| 627 | "Unknown target platform!"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 628 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, |
| 629 | HadExtra) || |
| 630 | HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 631 | getDriver().Diag(diag::err_drv_invalid_version_number) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 632 | << OSXVersion->getAsString(Args); |
Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 633 | } else if (Platform == IPhoneOS) { |
| 634 | assert(iOSVersion && "Unknown target platform!"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 635 | if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, |
| 636 | HadExtra) || |
| 637 | HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100) |
Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 638 | getDriver().Diag(diag::err_drv_invalid_version_number) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 639 | << iOSVersion->getAsString(Args); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 640 | } else if (Platform == TvOS) { |
| 641 | if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, |
| 642 | Micro, HadExtra) || HadExtra || |
| 643 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 644 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 645 | << TvOSVersion->getAsString(Args); |
| 646 | } else if (Platform == WatchOS) { |
| 647 | if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor, |
| 648 | Micro, HadExtra) || HadExtra || |
| 649 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 650 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 651 | << WatchOSVersion->getAsString(Args); |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 652 | } else |
| 653 | llvm_unreachable("unknown kind of Darwin platform"); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 654 | |
Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 655 | // Recognize iOS targets with an x86 architecture as the iOS simulator. |
Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 656 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 657 | getTriple().getArch() == llvm::Triple::x86_64)) |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 658 | Platform = IPhoneOSSimulator; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 659 | if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 660 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 661 | Platform = TvOSSimulator; |
| 662 | if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 663 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 664 | Platform = WatchOSSimulator; |
Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 665 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 666 | setTarget(Platform, Major, Minor, Micro); |
Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 669 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 670 | ArgStringList &CmdArgs) const { |
| 671 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 672 | |
| 673 | switch (Type) { |
| 674 | case ToolChain::CST_Libcxx: |
| 675 | CmdArgs.push_back("-lc++"); |
| 676 | break; |
| 677 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 678 | case ToolChain::CST_Libstdcxx: |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 679 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 680 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 681 | // platforms we care about it was -lstdc++.6, so we search for that |
| 682 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 683 | |
| 684 | // Check in the sysroot first. |
| 685 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 686 | SmallString<128> P(A->getValue()); |
Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 687 | llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 688 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 689 | if (!getVFS().exists(P)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 690 | llvm::sys::path::remove_filename(P); |
| 691 | llvm::sys::path::append(P, "libstdc++.6.dylib"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 692 | if (getVFS().exists(P)) { |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 693 | CmdArgs.push_back(Args.MakeArgString(P)); |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 694 | return; |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | // Otherwise, look in the root. |
Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 700 | // FIXME: This should be removed someday when we don't have to care about |
| 701 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 702 | if (!getVFS().exists("/usr/lib/libstdc++.dylib") && |
| 703 | getVFS().exists("/usr/lib/libstdc++.6.dylib")) { |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 704 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 705 | return; |
| 706 | } |
| 707 | |
| 708 | // Otherwise, let the linker search. |
| 709 | CmdArgs.push_back("-lstdc++"); |
| 710 | break; |
| 711 | } |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 714 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 715 | ArgStringList &CmdArgs) const { |
| 716 | |
| 717 | // For Darwin platforms, use the compiler-rt-based support library |
| 718 | // instead of the gcc-provided one (which is also incidentally |
| 719 | // only present in the gcc lib dir, which makes it hard to find). |
| 720 | |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 721 | SmallString<128> P(getDriver().ResourceDir); |
Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 722 | llvm::sys::path::append(P, "lib", "darwin"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 723 | |
| 724 | // Use the newer cc_kext for iOS ARM after 6.0. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 725 | if (isTargetWatchOS()) { |
| 726 | llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a"); |
| 727 | } else if (isTargetTvOS()) { |
| 728 | llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a"); |
| 729 | } else if (isTargetIPhoneOS()) { |
Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 730 | llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 731 | } else { |
Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 732 | llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 733 | } |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 734 | |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 735 | // For now, allow missing resource libraries to support developers who may |
| 736 | // not have compiler-rt checked out or integrated into their build. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 737 | if (getVFS().exists(P)) |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 738 | CmdArgs.push_back(Args.MakeArgString(P)); |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 741 | DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, |
| 742 | const char *BoundArch) const { |
Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 743 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 744 | const OptTable &Opts = getDriver().getOpts(); |
| 745 | |
| 746 | // FIXME: We really want to get out of the tool chain level argument |
| 747 | // translation business, as it makes the driver functionality much |
| 748 | // more opaque. For now, we follow gcc closely solely for the |
| 749 | // purpose of easily achieving feature parity & testability. Once we |
| 750 | // have something that works, we should reevaluate each translation |
| 751 | // and try to push it down into tool specific logic. |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 752 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 753 | for (Arg *A : Args) { |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 754 | if (A->getOption().matches(options::OPT_Xarch__)) { |
Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 755 | // Skip this argument unless the architecture matches either the toolchain |
| 756 | // triple arch, or the arch being bound. |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 757 | llvm::Triple::ArchType XarchArch = |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 758 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); |
| 759 | if (!(XarchArch == getArch() || |
| 760 | (BoundArch && |
| 761 | XarchArch == |
| 762 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 763 | continue; |
| 764 | |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 765 | Arg *OriginalArg = A; |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 766 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 767 | unsigned Prev = Index; |
Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 768 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 770 | // If the argument parsing failed or more than one argument was |
| 771 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 772 | // extra arguments. Emit an error and ignore. |
| 773 | // |
| 774 | // We also want to disallow any options which would alter the |
| 775 | // driver behavior; that isn't going to work in our model. We |
| 776 | // use isDriverOption() as an approximation, although things |
| 777 | // like -O4 are going to slip through. |
Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 778 | if (!XarchArg || Index > Prev + 1) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 779 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 780 | << A->getAsString(Args); |
Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 781 | continue; |
Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 782 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 783 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 784 | << A->getAsString(Args); |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 785 | continue; |
| 786 | } |
| 787 | |
Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 788 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 789 | |
Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 790 | A = XarchArg.release(); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 791 | DAL->AddSynthesizedArg(A); |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 792 | |
| 793 | // Linker input arguments require custom handling. The problem is that we |
| 794 | // have already constructed the phase actions, so we can not treat them as |
| 795 | // "input arguments". |
Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 796 | if (A->getOption().hasFlag(options::LinkerInput)) { |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 797 | // Convert the argument into individual Zlinker_input_args. |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 798 | for (const char *Value : A->getValues()) { |
| 799 | DAL->AddSeparateArg( |
| 800 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 801 | } |
| 802 | continue; |
| 803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | } |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 805 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 806 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 807 | // gcc translates options twice, which means that self-expanding |
| 808 | // options add duplicates. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 809 | switch ((options::ID)A->getOption().getID()) { |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 810 | default: |
| 811 | DAL->append(A); |
| 812 | break; |
| 813 | |
| 814 | case options::OPT_mkernel: |
| 815 | case options::OPT_fapple_kext: |
| 816 | DAL->append(A); |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 817 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 818 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 819 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 820 | case options::OPT_dependency_file: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 821 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 822 | break; |
| 823 | |
| 824 | case options::OPT_gfull: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 825 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 826 | DAL->AddFlagArg( |
| 827 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | case options::OPT_gused: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 831 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 832 | DAL->AddFlagArg( |
| 833 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 834 | break; |
| 835 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 836 | case options::OPT_shared: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 837 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 838 | break; |
| 839 | |
| 840 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 841 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 842 | break; |
| 843 | |
| 844 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 845 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 846 | break; |
| 847 | |
| 848 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 849 | DAL->AddFlagArg(A, |
| 850 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 851 | break; |
| 852 | |
| 853 | case options::OPT_Wno_nonportable_cfstrings: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 854 | DAL->AddFlagArg( |
| 855 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 856 | break; |
| 857 | |
| 858 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 859 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 860 | break; |
| 861 | |
| 862 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 863 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 864 | break; |
| 865 | } |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 866 | } |
| 867 | |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 868 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 869 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 870 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 871 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), |
| 872 | "core2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 873 | |
| 874 | // 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] | 875 | // how the driver driver works. |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 876 | if (BoundArch) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 877 | StringRef Name = BoundArch; |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 878 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 879 | const Option MArch = Opts.getOption(options::OPT_march_EQ); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 880 | |
| 881 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 882 | // which defines the list of which architectures we accept. |
| 883 | if (Name == "ppc") |
| 884 | ; |
| 885 | else if (Name == "ppc601") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 886 | DAL->AddJoinedArg(nullptr, MCpu, "601"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 887 | else if (Name == "ppc603") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 888 | DAL->AddJoinedArg(nullptr, MCpu, "603"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 889 | else if (Name == "ppc604") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 890 | DAL->AddJoinedArg(nullptr, MCpu, "604"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 891 | else if (Name == "ppc604e") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 892 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 893 | else if (Name == "ppc750") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 894 | DAL->AddJoinedArg(nullptr, MCpu, "750"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 895 | else if (Name == "ppc7400") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 896 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 897 | else if (Name == "ppc7450") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 898 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 899 | else if (Name == "ppc970") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 900 | DAL->AddJoinedArg(nullptr, MCpu, "970"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 901 | |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 902 | else if (Name == "ppc64" || Name == "ppc64le") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 903 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 904 | |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 905 | else if (Name == "i386") |
| 906 | ; |
| 907 | else if (Name == "i486") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 908 | DAL->AddJoinedArg(nullptr, MArch, "i486"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 909 | else if (Name == "i586") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 910 | DAL->AddJoinedArg(nullptr, MArch, "i586"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 911 | else if (Name == "i686") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 912 | DAL->AddJoinedArg(nullptr, MArch, "i686"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 913 | else if (Name == "pentium") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 914 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 915 | else if (Name == "pentium2") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 916 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 917 | else if (Name == "pentpro") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 918 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 919 | else if (Name == "pentIIm3") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 920 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 921 | |
| 922 | else if (Name == "x86_64") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 923 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 924 | else if (Name == "x86_64h") { |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 925 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| 926 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); |
Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 927 | } |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 928 | |
| 929 | else if (Name == "arm") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 930 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 931 | else if (Name == "armv4t") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 932 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 933 | else if (Name == "armv5") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 934 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 935 | else if (Name == "xscale") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 936 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 937 | else if (Name == "armv6") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 938 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 939 | else if (Name == "armv6m") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 940 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 941 | else if (Name == "armv7") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 942 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 943 | else if (Name == "armv7em") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 944 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 945 | else if (Name == "armv7k") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 946 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 947 | else if (Name == "armv7m") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 948 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 949 | else if (Name == "armv7s") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 950 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 951 | } |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 952 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 953 | return DAL; |
| 954 | } |
| 955 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 956 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 957 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 958 | // Embedded targets are simple at the moment, not supporting sanitizers and |
| 959 | // with different libraries for each member of the product { static, PIC } x |
| 960 | // { hard-float, soft-float } |
| 961 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); |
Saleem Abdulrasool | 06f6f99 | 2015-09-19 20:40:16 +0000 | [diff] [blame] | 962 | CompilerRT += |
| 963 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) |
| 964 | ? "hard" |
| 965 | : "soft"; |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 966 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; |
| 967 | |
| 968 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); |
| 969 | } |
| 970 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 971 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 972 | const char *BoundArch) const { |
| 973 | // First get the generic Apple args, before moving onto Darwin-specific ones. |
| 974 | DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); |
| 975 | const OptTable &Opts = getDriver().getOpts(); |
| 976 | |
Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 977 | // If no architecture is bound, none of the translations here are relevant. |
| 978 | if (!BoundArch) |
| 979 | return DAL; |
| 980 | |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 981 | // Add an explicit version min argument for the deployment target. We do this |
| 982 | // after argument translation because -Xarch_ arguments may add a version min |
| 983 | // argument. |
Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 984 | AddDeploymentTarget(*DAL); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 985 | |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 986 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. |
| 987 | // FIXME: It would be far better to avoid inserting those -static arguments, |
| 988 | // but we can't check the deployment target in the translation code until |
| 989 | // it is set here. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 990 | if (isTargetWatchOSBased() || |
| 991 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { |
| 992 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 993 | Arg *A = *it; |
| 994 | ++it; |
| 995 | if (A->getOption().getID() != options::OPT_mkernel && |
| 996 | A->getOption().getID() != options::OPT_fapple_kext) |
| 997 | continue; |
| 998 | assert(it != ie && "unexpected argument translation"); |
| 999 | A = *it; |
| 1000 | assert(A->getOption().getID() == options::OPT_static && |
| 1001 | "missing expected -static argument"); |
| 1002 | it = DAL->getArgs().erase(it); |
| 1003 | } |
| 1004 | } |
| 1005 | |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1006 | // Default to use libc++ on OS X 10.9+ and iOS 7+. |
| 1007 | if (((isTargetMacOS() && !isMacosxVersionLT(10, 9)) || |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1008 | (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) || |
| 1009 | isTargetWatchOSBased()) && |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1010 | !Args.getLastArg(options::OPT_stdlib_EQ)) |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1011 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), |
| 1012 | "libc++"); |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1013 | |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1014 | // Validate the C++ standard library choice. |
| 1015 | CXXStdlibType Type = GetCXXStdlibType(*DAL); |
| 1016 | if (Type == ToolChain::CST_Libcxx) { |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1017 | // Check whether the target provides libc++. |
| 1018 | StringRef where; |
| 1019 | |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1020 | // Complain about targeting iOS < 5.0 in any way. |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1021 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) |
Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1022 | where = "iOS 5.0"; |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1023 | |
| 1024 | if (where != StringRef()) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1025 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1029 | return DAL; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1031 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1032 | bool MachO::IsUnwindTablesDefault() const { |
Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1033 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1036 | bool MachO::UseDwarfDebugFlags() const { |
Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1037 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 1038 | return S[0] != '\0'; |
| 1039 | return false; |
| 1040 | } |
| 1041 | |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1042 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { |
Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1043 | // Darwin uses SjLj exceptions on ARM. |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1044 | if (getTriple().getArch() != llvm::Triple::arm && |
| 1045 | getTriple().getArch() != llvm::Triple::thumb) |
| 1046 | return false; |
| 1047 | |
| 1048 | // We can't check directly for watchOS here. ComputeLLVMTriple only |
| 1049 | // fills in the ArchName correctly. |
| 1050 | llvm::Triple Triple(ComputeLLVMTriple(Args)); |
| 1051 | return !(Triple.getArchName() == "armv7k" || |
| 1052 | Triple.getArchName() == "thumbv7k"); |
| 1053 | |
Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1056 | bool MachO::isPICDefault() const { return true; } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1057 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1058 | bool MachO::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1059 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1060 | bool MachO::isPICDefaultForced() const { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1061 | return (getArch() == llvm::Triple::x86_64 || |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1062 | getArch() == llvm::Triple::aarch64); |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1065 | bool MachO::SupportsProfiling() const { |
Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1066 | // Profiling instrumentation is only supported on x86. |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1067 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1070 | void Darwin::addMinVersionArgs(const ArgList &Args, |
| 1071 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1072 | VersionTuple TargetVersion = getTargetVersion(); |
| 1073 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1074 | if (isTargetWatchOS()) |
| 1075 | CmdArgs.push_back("-watchos_version_min"); |
| 1076 | else if (isTargetWatchOSSimulator()) |
| 1077 | CmdArgs.push_back("-watchos_simulator_version_min"); |
| 1078 | else if (isTargetTvOS()) |
| 1079 | CmdArgs.push_back("-tvos_version_min"); |
| 1080 | else if (isTargetTvOSSimulator()) |
| 1081 | CmdArgs.push_back("-tvos_simulator_version_min"); |
| 1082 | else if (isTargetIOSSimulator()) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1083 | CmdArgs.push_back("-ios_simulator_version_min"); |
Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1084 | else if (isTargetIOSBased()) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1085 | CmdArgs.push_back("-iphoneos_version_min"); |
| 1086 | else { |
| 1087 | assert(isTargetMacOS() && "unexpected target"); |
| 1088 | CmdArgs.push_back("-macosx_version_min"); |
| 1089 | } |
| 1090 | |
| 1091 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); |
| 1092 | } |
| 1093 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1094 | void Darwin::addStartObjectFileArgs(const ArgList &Args, |
| 1095 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1096 | // Derived from startfile spec. |
| 1097 | if (Args.hasArg(options::OPT_dynamiclib)) { |
| 1098 | // Derived from darwin_dylib1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1099 | if (isTargetWatchOSBased()) { |
| 1100 | ; // watchOS does not need dylib1.o. |
| 1101 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1102 | ; // iOS simulator does not need dylib1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1103 | } else if (isTargetIPhoneOS()) { |
| 1104 | if (isIPhoneOSVersionLT(3, 1)) |
| 1105 | CmdArgs.push_back("-ldylib1.o"); |
| 1106 | } else { |
| 1107 | if (isMacosxVersionLT(10, 5)) |
| 1108 | CmdArgs.push_back("-ldylib1.o"); |
| 1109 | else if (isMacosxVersionLT(10, 6)) |
| 1110 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1111 | } |
| 1112 | } else { |
| 1113 | if (Args.hasArg(options::OPT_bundle)) { |
| 1114 | if (!Args.hasArg(options::OPT_static)) { |
| 1115 | // Derived from darwin_bundle1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1116 | if (isTargetWatchOSBased()) { |
| 1117 | ; // watchOS does not need bundle1.o. |
| 1118 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1119 | ; // iOS simulator does not need bundle1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1120 | } else if (isTargetIPhoneOS()) { |
| 1121 | if (isIPhoneOSVersionLT(3, 1)) |
| 1122 | CmdArgs.push_back("-lbundle1.o"); |
| 1123 | } else { |
| 1124 | if (isMacosxVersionLT(10, 6)) |
| 1125 | CmdArgs.push_back("-lbundle1.o"); |
| 1126 | } |
| 1127 | } |
| 1128 | } else { |
| 1129 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { |
| 1130 | if (Args.hasArg(options::OPT_static) || |
| 1131 | Args.hasArg(options::OPT_object) || |
| 1132 | Args.hasArg(options::OPT_preload)) { |
| 1133 | CmdArgs.push_back("-lgcrt0.o"); |
| 1134 | } else { |
| 1135 | CmdArgs.push_back("-lgcrt1.o"); |
| 1136 | |
| 1137 | // darwin_crt2 spec is empty. |
| 1138 | } |
| 1139 | // By default on OS X 10.8 and later, we don't link with a crt1.o |
| 1140 | // file and the linker knows to use _main as the entry point. But, |
| 1141 | // when compiling with -pg, we need to link with the gcrt1.o file, |
| 1142 | // so pass the -no_new_main option to tell the linker to use the |
| 1143 | // "start" symbol as the entry point. |
| 1144 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) |
| 1145 | CmdArgs.push_back("-no_new_main"); |
| 1146 | } else { |
| 1147 | if (Args.hasArg(options::OPT_static) || |
| 1148 | Args.hasArg(options::OPT_object) || |
| 1149 | Args.hasArg(options::OPT_preload)) { |
| 1150 | CmdArgs.push_back("-lcrt0.o"); |
| 1151 | } else { |
| 1152 | // Derived from darwin_crt1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1153 | if (isTargetWatchOSBased()) { |
| 1154 | ; // watchOS does not need crt1.o. |
| 1155 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1156 | ; // iOS simulator does not need crt1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1157 | } else if (isTargetIPhoneOS()) { |
Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1158 | if (getArch() == llvm::Triple::aarch64) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1159 | ; // iOS does not need any crt1 files for arm64 |
| 1160 | else if (isIPhoneOSVersionLT(3, 1)) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1161 | CmdArgs.push_back("-lcrt1.o"); |
| 1162 | else if (isIPhoneOSVersionLT(6, 0)) |
| 1163 | CmdArgs.push_back("-lcrt1.3.1.o"); |
| 1164 | } else { |
| 1165 | if (isMacosxVersionLT(10, 5)) |
| 1166 | CmdArgs.push_back("-lcrt1.o"); |
| 1167 | else if (isMacosxVersionLT(10, 6)) |
| 1168 | CmdArgs.push_back("-lcrt1.10.5.o"); |
| 1169 | else if (isMacosxVersionLT(10, 8)) |
| 1170 | CmdArgs.push_back("-lcrt1.10.6.o"); |
| 1171 | |
| 1172 | // darwin_crt2 spec is empty. |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1180 | !isTargetWatchOS() && |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1181 | isMacosxVersionLT(10, 5)) { |
| 1182 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); |
| 1183 | CmdArgs.push_back(Str); |
| 1184 | } |
| 1185 | } |
| 1186 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1187 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } |
Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1188 | |
John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1189 | void Darwin::CheckObjCARC() const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1190 | if (isTargetIOSBased() || isTargetWatchOSBased() || |
| 1191 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) |
John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1192 | return; |
John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1193 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); |
Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1196 | SanitizerMask Darwin::getSupportedSanitizers() const { |
| 1197 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1198 | if (isTargetMacOS() || isTargetIOSSimulator()) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1199 | Res |= SanitizerKind::Address; |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1200 | if (isTargetMacOS()) { |
| 1201 | if (!isMacosxVersionLT(10, 9)) |
| 1202 | Res |= SanitizerKind::Vptr; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1203 | Res |= SanitizerKind::SafeStack; |
Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 1204 | Res |= SanitizerKind::Thread; |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1205 | } |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1206 | return Res; |
| 1207 | } |
| 1208 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1209 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 1210 | /// all subcommands; this relies on gcc translating the majority of |
| 1211 | /// command line options. |
| 1212 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1213 | /// \brief Parse a GCCVersion object out of a string of text. |
| 1214 | /// |
| 1215 | /// This is the primary means of forming GCCVersion objects. |
| 1216 | /*static*/ |
| 1217 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1218 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1219 | std::pair<StringRef, StringRef> First = VersionText.split('.'); |
| 1220 | std::pair<StringRef, StringRef> Second = First.second.split('.'); |
| 1221 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1222 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| 1223 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1224 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1225 | GoodVersion.MajorStr = First.first.str(); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1226 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1227 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1228 | GoodVersion.MinorStr = Second.first.str(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1229 | |
| 1230 | // First look for a number prefix and parse that if present. Otherwise just |
| 1231 | // stash the entire patch string in the suffix, and leave the number |
| 1232 | // unspecified. This covers versions strings such as: |
| 1233 | // 4.4 |
| 1234 | // 4.4.0 |
| 1235 | // 4.4.x |
| 1236 | // 4.4.2-rc4 |
| 1237 | // 4.4.x-patched |
| 1238 | // And retains any patch number it finds. |
| 1239 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); |
| 1240 | if (!PatchText.empty()) { |
Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1241 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1242 | // Try to parse the number and any suffix. |
| 1243 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || |
| 1244 | GoodVersion.Patch < 0) |
| 1245 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1246 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | return GoodVersion; |
| 1251 | } |
| 1252 | |
| 1253 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1254 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, |
| 1255 | int RHSPatch, |
| 1256 | StringRef RHSPatchSuffix) const { |
| 1257 | if (Major != RHSMajor) |
| 1258 | return Major < RHSMajor; |
| 1259 | if (Minor != RHSMinor) |
| 1260 | return Minor < RHSMinor; |
| 1261 | if (Patch != RHSPatch) { |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1262 | // Note that versions without a specified patch sort higher than those with |
| 1263 | // a patch. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1264 | if (RHSPatch == -1) |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1265 | return true; |
| 1266 | if (Patch == -1) |
| 1267 | return false; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1268 | |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1269 | // Otherwise just sort on the patch itself. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1270 | return Patch < RHSPatch; |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1271 | } |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1272 | if (PatchSuffix != RHSPatchSuffix) { |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1273 | // Sort empty suffixes higher. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1274 | if (RHSPatchSuffix.empty()) |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1275 | return true; |
| 1276 | if (PatchSuffix.empty()) |
Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1277 | return false; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1278 | |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1279 | // Provide a lexicographic sort to make this a total ordering. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1280 | return PatchSuffix < RHSPatchSuffix; |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | // The versions are equal. |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1284 | return false; |
| 1285 | } |
| 1286 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1287 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1288 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); |
| 1289 | if (A) |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1290 | return A->getValue(); |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1291 | return GCC_INSTALL_PREFIX; |
| 1292 | } |
| 1293 | |
Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1294 | /// \brief Initialize a GCCInstallationDetector from the driver. |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1295 | /// |
| 1296 | /// This performs all of the autodetection and sets up the various paths. |
Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1297 | /// Once constructed, a GCCInstallationDetector is essentially immutable. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1298 | /// |
| 1299 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and |
| 1300 | /// should instead pull the target out of the driver. This is currently |
| 1301 | /// necessary because the driver doesn't store the final version of the target |
| 1302 | /// triple. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1303 | void Generic_GCC::GCCInstallationDetector::init( |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1304 | const llvm::Triple &TargetTriple, const ArgList &Args, |
Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1305 | ArrayRef<std::string> ExtraTripleAliases) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1306 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() |
| 1307 | ? TargetTriple.get64BitArchVariant() |
| 1308 | : TargetTriple.get32BitArchVariant(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1309 | // The library directories which may contain GCC installations. |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1310 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1311 | // The compatible GCC triples for this particular architecture. |
Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1312 | SmallVector<StringRef, 16> CandidateTripleAliases; |
| 1313 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1314 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, |
| 1315 | CandidateTripleAliases, CandidateBiarchLibDirs, |
| 1316 | CandidateBiarchTripleAliases); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1317 | |
| 1318 | // Compute the set of prefixes for our search. |
| 1319 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), |
| 1320 | D.PrefixDirs.end()); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1321 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1322 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); |
| 1323 | if (GCCToolchainDir != "") { |
| 1324 | if (GCCToolchainDir.back() == '/') |
| 1325 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1326 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1327 | Prefixes.push_back(GCCToolchainDir); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1328 | } else { |
Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1329 | // If we have a SysRoot, try that first. |
| 1330 | if (!D.SysRoot.empty()) { |
| 1331 | Prefixes.push_back(D.SysRoot); |
| 1332 | Prefixes.push_back(D.SysRoot + "/usr"); |
| 1333 | } |
| 1334 | |
| 1335 | // Then look for gcc installed alongside clang. |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1336 | Prefixes.push_back(D.InstalledDir + "/.."); |
Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1337 | |
| 1338 | // And finally in /usr. |
| 1339 | if (D.SysRoot.empty()) |
| 1340 | Prefixes.push_back("/usr"); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1341 | } |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1342 | |
| 1343 | // Loop over the various components which exist and select the best GCC |
| 1344 | // installation available. GCC installs are ranked by version number. |
| 1345 | Version = GCCVersion::Parse("0.0.0"); |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1346 | for (const std::string &Prefix : Prefixes) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1347 | if (!D.getVFS().exists(Prefix)) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1348 | continue; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1349 | for (StringRef Suffix : CandidateLibDirs) { |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1350 | const std::string LibDir = Prefix + Suffix.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1351 | if (!D.getVFS().exists(LibDir)) |
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 Candidate : ExtraTripleAliases) // Try these first. |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1354 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1355 | for (StringRef Candidate : CandidateTripleAliases) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1356 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1357 | } |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1358 | for (StringRef Suffix : CandidateBiarchLibDirs) { |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1359 | const std::string LibDir = Prefix + Suffix.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1360 | if (!D.getVFS().exists(LibDir)) |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1361 | continue; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1362 | for (StringRef Candidate : CandidateBiarchTripleAliases) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1363 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1364 | /*NeedsBiarchSuffix=*/ true); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 | |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1369 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1370 | for (const auto &InstallPath : CandidateGCCInstallPaths) |
| 1371 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1372 | |
Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1373 | if (!GCCInstallPath.empty()) |
| 1374 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; |
| 1375 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1376 | for (const auto &Multilib : Multilibs) |
| 1377 | OS << "Candidate multilib: " << Multilib << "\n"; |
Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1378 | |
| 1379 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) |
| 1380 | OS << "Selected multilib: " << SelectedMultilib << "\n"; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { |
| 1384 | if (BiarchSibling.hasValue()) { |
| 1385 | M = BiarchSibling.getValue(); |
| 1386 | return true; |
| 1387 | } |
| 1388 | return false; |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1391 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1392 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1393 | SmallVectorImpl<StringRef> &LibDirs, |
| 1394 | SmallVectorImpl<StringRef> &TripleAliases, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1395 | SmallVectorImpl<StringRef> &BiarchLibDirs, |
| 1396 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1397 | // Declare a bunch of static data sets that we'll select between below. These |
| 1398 | // are specifically designed to always refer to string literals to avoid any |
| 1399 | // lifetime or initialization issues. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1400 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; |
| 1401 | static const char *const AArch64Triples[] = { |
| 1402 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", |
| 1403 | "aarch64-redhat-linux"}; |
| 1404 | static const char *const AArch64beLibDirs[] = {"/lib"}; |
| 1405 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", |
| 1406 | "aarch64_be-linux-gnu"}; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1407 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1408 | static const char *const ARMLibDirs[] = {"/lib"}; |
| 1409 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", |
| 1410 | "arm-linux-androideabi"}; |
| 1411 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", |
| 1412 | "armv7hl-redhat-linux-gnueabi"}; |
| 1413 | static const char *const ARMebLibDirs[] = {"/lib"}; |
| 1414 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", |
| 1415 | "armeb-linux-androideabi"}; |
| 1416 | static const char *const ARMebHFTriples[] = { |
| 1417 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1418 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1419 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1420 | static const char *const X86_64Triples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1421 | "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", |
| 1422 | "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E", |
| 1423 | "x86_64-redhat-linux", "x86_64-suse-linux", |
| 1424 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", |
| 1425 | "x86_64-slackware-linux", "x86_64-linux-android", |
| 1426 | "x86_64-unknown-linux"}; |
| 1427 | static const char *const X32LibDirs[] = {"/libx32"}; |
| 1428 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1429 | static const char *const X86Triples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1430 | "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", |
| 1431 | "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux", |
| 1432 | "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux", |
| 1433 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", |
| 1434 | "i586-linux-gnu"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1435 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1436 | static const char *const MIPSLibDirs[] = {"/lib"}; |
Vasileios Kalintiris | 71b0dfe | 2015-10-30 11:28:39 +0000 | [diff] [blame] | 1437 | static const char *const MIPSTriples[] = { |
| 1438 | "mips-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu"}; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1439 | static const char *const MIPSELLibDirs[] = {"/lib"}; |
| 1440 | static const char *const MIPSELTriples[] = { |
| 1441 | "mipsel-linux-gnu", "mipsel-linux-android", "mips-img-linux-gnu"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1442 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1443 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; |
| 1444 | static const char *const MIPS64Triples[] = { |
| 1445 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1446 | "mips64-linux-gnuabi64"}; |
| 1447 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; |
| 1448 | static const char *const MIPS64ELTriples[] = { |
| 1449 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1450 | "mips64el-linux-android", "mips64el-linux-gnuabi64"}; |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1451 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1452 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1453 | static const char *const PPCTriples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1454 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", |
| 1455 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; |
| 1456 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; |
| 1457 | static const char *const PPC64Triples[] = { |
| 1458 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", |
| 1459 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; |
| 1460 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; |
| 1461 | static const char *const PPC64LETriples[] = { |
| 1462 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", |
| 1463 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1464 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1465 | static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; |
| 1466 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", |
| 1467 | "sparcv8-linux-gnu"}; |
| 1468 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; |
| 1469 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", |
| 1470 | "sparcv9-linux-gnu"}; |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1471 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1472 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1473 | static const char *const SystemZTriples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1474 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", |
| 1475 | "s390x-suse-linux", "s390x-redhat-linux"}; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1476 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1477 | // Solaris. |
| 1478 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; |
| 1479 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", |
| 1480 | "i386-pc-solaris2.11"}; |
| 1481 | |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1482 | using std::begin; |
| 1483 | using std::end; |
| 1484 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1485 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 1486 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); |
| 1487 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1488 | return; |
| 1489 | } |
| 1490 | |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1491 | switch (TargetTriple.getArch()) { |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1492 | case llvm::Triple::aarch64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1493 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1494 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| 1495 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1496 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1497 | break; |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1498 | case llvm::Triple::aarch64_be: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1499 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1500 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| 1501 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1502 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1503 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1504 | case llvm::Triple::arm: |
| 1505 | case llvm::Triple::thumb: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1506 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1507 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1508 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1509 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1510 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1511 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1512 | break; |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1513 | case llvm::Triple::armeb: |
| 1514 | case llvm::Triple::thumbeb: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1515 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1516 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1517 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1518 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1519 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1520 | } |
| 1521 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1522 | case llvm::Triple::x86_64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1523 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1524 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| 1525 | // x32 is always available when x86_64 is available, so adding it as |
| 1526 | // secondary arch with x86_64 triples |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1527 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1528 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); |
| 1529 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1530 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1531 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1532 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1533 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1534 | break; |
| 1535 | case llvm::Triple::x86: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1536 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1537 | TripleAliases.append(begin(X86Triples), end(X86Triples)); |
| 1538 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1539 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1540 | break; |
| 1541 | case llvm::Triple::mips: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1542 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1543 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1544 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1545 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1546 | break; |
| 1547 | case llvm::Triple::mipsel: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1548 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1549 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1550 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1551 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1552 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1553 | break; |
| 1554 | case llvm::Triple::mips64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1555 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1556 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| 1557 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1558 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1559 | break; |
| 1560 | case llvm::Triple::mips64el: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1561 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1562 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| 1563 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1564 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1565 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1566 | break; |
| 1567 | case llvm::Triple::ppc: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1568 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1569 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| 1570 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1571 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1572 | break; |
| 1573 | case llvm::Triple::ppc64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1574 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1575 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| 1576 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1577 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1578 | break; |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1579 | case llvm::Triple::ppc64le: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1580 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); |
| 1581 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1582 | break; |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1583 | case llvm::Triple::sparc: |
Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1584 | case llvm::Triple::sparcel: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1585 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1586 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| 1587 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1588 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1589 | break; |
| 1590 | case llvm::Triple::sparcv9: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1591 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1592 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| 1593 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1594 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1595 | break; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1596 | case llvm::Triple::systemz: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1597 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); |
| 1598 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1599 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1600 | default: |
| 1601 | // By default, just rely on the standard lib directories and the original |
| 1602 | // triple. |
| 1603 | break; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1604 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1605 | |
| 1606 | // Always append the drivers target triple to the end, in case it doesn't |
| 1607 | // match any of our aliases. |
| 1608 | TripleAliases.push_back(TargetTriple.str()); |
| 1609 | |
| 1610 | // Also include the multiarch variant if it's different. |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1611 | if (TargetTriple.str() != BiarchTriple.str()) |
| 1612 | BiarchTripleAliases.push_back(BiarchTriple.str()); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1615 | // \brief -- try common CUDA installation paths looking for files we need for |
| 1616 | // CUDA compilation. |
| 1617 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1618 | void Generic_GCC::CudaInstallationDetector::init( |
| 1619 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { |
NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1620 | SmallVector<std::string, 4> CudaPathCandidates; |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1621 | |
| 1622 | if (Args.hasArg(options::OPT_cuda_path_EQ)) |
| 1623 | CudaPathCandidates.push_back( |
| 1624 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); |
| 1625 | else { |
| 1626 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); |
| 1627 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); |
| 1628 | } |
| 1629 | |
Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1630 | for (const auto &CudaPath : CudaPathCandidates) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1631 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1632 | continue; |
| 1633 | |
| 1634 | CudaInstallPath = CudaPath; |
| 1635 | CudaIncludePath = CudaInstallPath + "/include"; |
| 1636 | CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice"; |
| 1637 | CudaLibPath = |
| 1638 | CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); |
| 1639 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1640 | if (!(D.getVFS().exists(CudaIncludePath) && |
| 1641 | D.getVFS().exists(CudaLibPath) && |
| 1642 | D.getVFS().exists(CudaLibDevicePath))) |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1643 | continue; |
| 1644 | |
| 1645 | IsValid = true; |
| 1646 | break; |
| 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { |
| 1651 | if (isValid()) |
| 1652 | OS << "Found CUDA installation: " << CudaInstallPath << "\n"; |
| 1653 | } |
| 1654 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1655 | namespace { |
| 1656 | // 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] | 1657 | class FilterNonExistent { |
| 1658 | StringRef Base; |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1659 | vfs::FileSystem &VFS; |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1660 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1661 | public: |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1662 | FilterNonExistent(StringRef Base, vfs::FileSystem &VFS) |
| 1663 | : Base(Base), VFS(VFS) {} |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1664 | bool operator()(const Multilib &M) { |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1665 | return !VFS.exists(Base + M.gccSuffix() + "/crtbegin.o"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1666 | } |
| 1667 | }; |
| 1668 | } // end anonymous namespace |
| 1669 | |
| 1670 | static void addMultilibFlag(bool Enabled, const char *const Flag, |
| 1671 | std::vector<std::string> &Flags) { |
| 1672 | if (Enabled) |
| 1673 | Flags.push_back(std::string("+") + Flag); |
| 1674 | else |
| 1675 | Flags.push_back(std::string("-") + Flag); |
| 1676 | } |
| 1677 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1678 | static bool isMipsArch(llvm::Triple::ArchType Arch) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1679 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || |
| 1680 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1681 | } |
| 1682 | |
| 1683 | static bool isMips32(llvm::Triple::ArchType Arch) { |
| 1684 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; |
| 1685 | } |
| 1686 | |
| 1687 | static bool isMips64(llvm::Triple::ArchType Arch) { |
| 1688 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1689 | } |
| 1690 | |
| 1691 | static bool isMipsEL(llvm::Triple::ArchType Arch) { |
| 1692 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; |
| 1693 | } |
| 1694 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1695 | static bool isMips16(const ArgList &Args) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1696 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1697 | return A && A->getOption().matches(options::OPT_mips16); |
| 1698 | } |
| 1699 | |
| 1700 | static bool isMicroMips(const ArgList &Args) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1701 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1702 | return A && A->getOption().matches(options::OPT_mmicromips); |
| 1703 | } |
| 1704 | |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1705 | namespace { |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1706 | struct DetectedMultilibs { |
| 1707 | /// The set of multilibs that the detected installation supports. |
| 1708 | MultilibSet Multilibs; |
| 1709 | |
| 1710 | /// The primary multilib appropriate for the given flags. |
| 1711 | Multilib SelectedMultilib; |
| 1712 | |
| 1713 | /// On Biarch systems, this corresponds to the default multilib when |
| 1714 | /// targeting the non-default multilib. Otherwise, it is empty. |
| 1715 | llvm::Optional<Multilib> BiarchSibling; |
| 1716 | }; |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1717 | } // end anonymous namespace |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1718 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1719 | static Multilib makeMultilib(StringRef commonSuffix) { |
| 1720 | return Multilib(commonSuffix, commonSuffix, commonSuffix); |
| 1721 | } |
| 1722 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1723 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, |
| 1724 | StringRef Path, const ArgList &Args, |
| 1725 | DetectedMultilibs &Result) { |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 1726 | // Some MIPS toolchains put libraries and object files compiled |
| 1727 | // using different options in to the sub-directoris which names |
| 1728 | // reflects the flags used for compilation. For example sysroot |
| 1729 | // directory might looks like the following examples: |
| 1730 | // |
| 1731 | // /usr |
| 1732 | // /lib <= crt*.o files compiled with '-mips32' |
| 1733 | // /mips16 |
| 1734 | // /usr |
| 1735 | // /lib <= crt*.o files compiled with '-mips16' |
| 1736 | // /el |
| 1737 | // /usr |
| 1738 | // /lib <= crt*.o files compiled with '-mips16 -EL' |
| 1739 | // |
| 1740 | // or |
| 1741 | // |
| 1742 | // /usr |
| 1743 | // /lib <= crt*.o files compiled with '-mips32r2' |
| 1744 | // /mips16 |
| 1745 | // /usr |
| 1746 | // /lib <= crt*.o files compiled with '-mips32r2 -mips16' |
| 1747 | // /mips32 |
| 1748 | // /usr |
| 1749 | // /lib <= crt*.o files compiled with '-mips32' |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 1750 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1751 | FilterNonExistent NonExistent(Path, D.getVFS()); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 1752 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1753 | // Check for FSF toolchain multilibs |
| 1754 | MultilibSet FSFMipsMultilibs; |
| 1755 | { |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1756 | auto MArchMips32 = makeMultilib("/mips32") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1757 | .flag("+m32") |
| 1758 | .flag("-m64") |
| 1759 | .flag("-mmicromips") |
| 1760 | .flag("+march=mips32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1761 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1762 | auto MArchMicroMips = makeMultilib("/micromips") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1763 | .flag("+m32") |
| 1764 | .flag("-m64") |
| 1765 | .flag("+mmicromips"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1766 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1767 | auto MArchMips64r2 = makeMultilib("/mips64r2") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1768 | .flag("-m32") |
| 1769 | .flag("+m64") |
| 1770 | .flag("+march=mips64r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1771 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1772 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( |
| 1773 | "-march=mips64r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1774 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1775 | auto MArchDefault = makeMultilib("") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1776 | .flag("+m32") |
| 1777 | .flag("-m64") |
| 1778 | .flag("-mmicromips") |
| 1779 | .flag("+march=mips32r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1780 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1781 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1782 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1783 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1784 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1785 | auto MAbi64 = |
| 1786 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1787 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1788 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1789 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1790 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1791 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1792 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1793 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1794 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1795 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1796 | FSFMipsMultilibs = |
| 1797 | MultilibSet() |
| 1798 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, |
| 1799 | MArchDefault) |
| 1800 | .Maybe(UCLibc) |
| 1801 | .Maybe(Mips16) |
| 1802 | .FilterOut("/mips64/mips16") |
| 1803 | .FilterOut("/mips64r2/mips16") |
| 1804 | .FilterOut("/micromips/mips16") |
| 1805 | .Maybe(MAbi64) |
| 1806 | .FilterOut("/micromips/64") |
| 1807 | .FilterOut("/mips32/64") |
| 1808 | .FilterOut("^/64") |
| 1809 | .FilterOut("/mips16/64") |
| 1810 | .Either(BigEndian, LittleEndian) |
| 1811 | .Maybe(SoftFloat) |
| 1812 | .Maybe(Nan2008) |
| 1813 | .FilterOut(".*sof/nan2008") |
| 1814 | .FilterOut(NonExistent) |
| 1815 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1816 | StringRef TripleStr, const Multilib &M) { |
| 1817 | std::vector<std::string> Dirs; |
| 1818 | Dirs.push_back((InstallDir + "/include").str()); |
| 1819 | std::string SysRootInc = |
| 1820 | InstallDir.str() + "/../../../../sysroot"; |
| 1821 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| 1822 | Dirs.push_back(SysRootInc + "/uclibc/usr/include"); |
| 1823 | else |
| 1824 | Dirs.push_back(SysRootInc + "/usr/include"); |
| 1825 | return Dirs; |
| 1826 | }); |
Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1829 | // Check for Code Sourcery toolchain multilibs |
| 1830 | MultilibSet CSMipsMultilibs; |
| 1831 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1832 | auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); |
Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1833 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1834 | auto MArchMicroMips = |
| 1835 | makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1836 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1837 | auto MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1838 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1839 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1840 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1841 | auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1842 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1843 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1844 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1845 | auto DefaultFloat = |
| 1846 | makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1847 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1848 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1849 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1850 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1851 | |
| 1852 | // Note that this one's osSuffix is "" |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1853 | auto MAbi64 = makeMultilib("") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1854 | .gccSuffix("/64") |
| 1855 | .includeSuffix("/64") |
| 1856 | .flag("+mabi=n64") |
| 1857 | .flag("-mabi=n32") |
| 1858 | .flag("-m32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1859 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1860 | CSMipsMultilibs = |
| 1861 | MultilibSet() |
| 1862 | .Either(MArchMips16, MArchMicroMips, MArchDefault) |
| 1863 | .Maybe(UCLibc) |
| 1864 | .Either(SoftFloat, Nan2008, DefaultFloat) |
| 1865 | .FilterOut("/micromips/nan2008") |
| 1866 | .FilterOut("/mips16/nan2008") |
| 1867 | .Either(BigEndian, LittleEndian) |
| 1868 | .Maybe(MAbi64) |
| 1869 | .FilterOut("/mips16.*/64") |
| 1870 | .FilterOut("/micromips.*/64") |
| 1871 | .FilterOut(NonExistent) |
| 1872 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1873 | StringRef TripleStr, const Multilib &M) { |
| 1874 | std::vector<std::string> Dirs; |
| 1875 | Dirs.push_back((InstallDir + "/include").str()); |
| 1876 | std::string SysRootInc = |
| 1877 | InstallDir.str() + "/../../../../" + TripleStr.str(); |
| 1878 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| 1879 | Dirs.push_back(SysRootInc + "/libc/uclibc/usr/include"); |
| 1880 | else |
| 1881 | Dirs.push_back(SysRootInc + "/libc/usr/include"); |
| 1882 | return Dirs; |
| 1883 | }); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1886 | MultilibSet AndroidMipsMultilibs = |
| 1887 | MultilibSet() |
| 1888 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) |
| 1889 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) |
| 1890 | .FilterOut(NonExistent); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1891 | |
| 1892 | MultilibSet DebianMipsMultilibs; |
| 1893 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1894 | Multilib MAbiN32 = |
| 1895 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1896 | |
| 1897 | Multilib M64 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1898 | .gccSuffix("/64") |
| 1899 | .includeSuffix("/64") |
| 1900 | .flag("+m64") |
| 1901 | .flag("-m32") |
| 1902 | .flag("-mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1903 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1904 | Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1905 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1906 | DebianMipsMultilibs = |
| 1907 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1910 | MultilibSet ImgMultilibs; |
| 1911 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1912 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1913 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1914 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1915 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1916 | auto MAbi64 = |
| 1917 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1918 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1919 | ImgMultilibs = |
| 1920 | MultilibSet() |
| 1921 | .Maybe(Mips64r6) |
| 1922 | .Maybe(MAbi64) |
| 1923 | .Maybe(LittleEndian) |
| 1924 | .FilterOut(NonExistent) |
| 1925 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1926 | StringRef TripleStr, const Multilib &M) { |
| 1927 | std::vector<std::string> Dirs; |
| 1928 | Dirs.push_back((InstallDir + "/include").str()); |
| 1929 | Dirs.push_back( |
| 1930 | (InstallDir + "/../../../../sysroot/usr/include").str()); |
| 1931 | return Dirs; |
| 1932 | }); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 1935 | StringRef CPUName; |
| 1936 | StringRef ABIName; |
| 1937 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); |
| 1938 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1939 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| 1940 | |
| 1941 | Multilib::flags_list Flags; |
| 1942 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); |
| 1943 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); |
| 1944 | addMultilibFlag(isMips16(Args), "mips16", Flags); |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 1945 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 1946 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || |
Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 1947 | CPUName == "mips32r5" || CPUName == "p5600", |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 1948 | "march=mips32r2", Flags); |
Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 1949 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 1950 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 1951 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || |
| 1952 | CPUName == "mips64r5" || CPUName == "octeon", |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 1953 | "march=mips64r2", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1954 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1955 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); |
Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 1956 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", |
| 1957 | Flags); |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 1958 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); |
| 1959 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1960 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1961 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1962 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 1963 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1964 | |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 1965 | if (TargetTriple.isAndroid()) { |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1966 | // Select Android toolchain. It's the only choice in that case. |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1967 | if (AndroidMipsMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 1968 | Result.Multilibs = AndroidMipsMultilibs; |
| 1969 | return true; |
| 1970 | } |
| 1971 | return false; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1974 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && |
| 1975 | TargetTriple.getOS() == llvm::Triple::Linux && |
| 1976 | TargetTriple.getEnvironment() == llvm::Triple::GNU) { |
| 1977 | // Select mips-img-linux-gnu toolchain. |
| 1978 | if (ImgMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 1979 | Result.Multilibs = ImgMultilibs; |
| 1980 | return true; |
| 1981 | } |
| 1982 | return false; |
| 1983 | } |
| 1984 | |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1985 | // Sort candidates. Toolchain that best meets the directories goes first. |
| 1986 | // Then select the first toolchains matches command line flags. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1987 | MultilibSet *candidates[] = {&DebianMipsMultilibs, &FSFMipsMultilibs, |
| 1988 | &CSMipsMultilibs}; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1989 | std::sort( |
| 1990 | std::begin(candidates), std::end(candidates), |
| 1991 | [](MultilibSet *a, MultilibSet *b) { return a->size() > b->size(); }); |
| 1992 | for (const auto &candidate : candidates) { |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1993 | if (candidate->select(Flags, Result.SelectedMultilib)) { |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1994 | if (candidate == &DebianMipsMultilibs) |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1995 | Result.BiarchSibling = Multilib(); |
| 1996 | Result.Multilibs = *candidate; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1997 | return true; |
| 1998 | } |
| 1999 | } |
| 2000 | |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2001 | { |
| 2002 | // Fallback to the regular toolchain-tree structure. |
| 2003 | Multilib Default; |
| 2004 | Result.Multilibs.push_back(Default); |
| 2005 | Result.Multilibs.FilterOut(NonExistent); |
| 2006 | |
| 2007 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { |
| 2008 | Result.BiarchSibling = Multilib(); |
| 2009 | return true; |
| 2010 | } |
| 2011 | } |
| 2012 | |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2013 | return false; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2016 | static bool findBiarchMultilibs(const Driver &D, |
| 2017 | const llvm::Triple &TargetTriple, |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2018 | StringRef Path, const ArgList &Args, |
| 2019 | bool NeedsBiarchSuffix, |
| 2020 | DetectedMultilibs &Result) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2021 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs |
| 2022 | // in what would normally be GCCInstallPath and put the 64-bit |
| 2023 | // libs in a subdirectory named 64. The simple logic we follow is that |
| 2024 | // *if* there is a subdirectory of the right name with crtbegin.o in it, |
| 2025 | // we use that. If not, and if not a biarch triple alias, we look for |
| 2026 | // crtbegin.o without the subdirectory. |
| 2027 | |
| 2028 | Multilib Default; |
| 2029 | Multilib Alt64 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2030 | .gccSuffix("/64") |
| 2031 | .includeSuffix("/64") |
| 2032 | .flag("-m32") |
| 2033 | .flag("+m64") |
| 2034 | .flag("-mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2035 | Multilib Alt32 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2036 | .gccSuffix("/32") |
| 2037 | .includeSuffix("/32") |
| 2038 | .flag("+m32") |
| 2039 | .flag("-m64") |
| 2040 | .flag("-mx32"); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2041 | Multilib Altx32 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2042 | .gccSuffix("/x32") |
| 2043 | .includeSuffix("/x32") |
| 2044 | .flag("-m32") |
| 2045 | .flag("-m64") |
| 2046 | .flag("+mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2047 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2048 | FilterNonExistent NonExistent(Path, D.getVFS()); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2049 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2050 | // Determine default multilib from: 32, 64, x32 |
| 2051 | // Also handle cases such as 64 on 32, 32 on 64, etc. |
| 2052 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; |
David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2053 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; |
Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2054 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2055 | Want = WANT64; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2056 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2057 | Want = WANT64; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2058 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2059 | Want = WANT32; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2060 | else { |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2061 | if (TargetTriple.isArch32Bit()) |
| 2062 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2063 | else if (IsX32) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2064 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2065 | else |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2066 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; |
Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2069 | if (Want == WANT32) |
| 2070 | Default.flag("+m32").flag("-m64").flag("-mx32"); |
| 2071 | else if (Want == WANT64) |
| 2072 | Default.flag("-m32").flag("+m64").flag("-mx32"); |
| 2073 | else if (Want == WANTX32) |
| 2074 | Default.flag("-m32").flag("-m64").flag("+mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2075 | else |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2076 | return false; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2077 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2078 | Result.Multilibs.push_back(Default); |
| 2079 | Result.Multilibs.push_back(Alt64); |
| 2080 | Result.Multilibs.push_back(Alt32); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2081 | Result.Multilibs.push_back(Altx32); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2082 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2083 | Result.Multilibs.FilterOut(NonExistent); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2084 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2085 | Multilib::flags_list Flags; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2086 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2087 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2088 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2089 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2090 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2091 | return false; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2092 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2093 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2094 | Result.SelectedMultilib == Altx32) |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2095 | Result.BiarchSibling = Default; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2096 | |
| 2097 | return true; |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2100 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( |
| 2101 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, |
| 2102 | const std::string &LibDir, StringRef CandidateTriple, |
| 2103 | bool NeedsBiarchSuffix) { |
| 2104 | // Solaris is a special case. The GCC installation is under |
| 2105 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we |
| 2106 | // need to iterate twice. |
| 2107 | std::error_code EC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2108 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; |
| 2109 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 2110 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2111 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| 2112 | |
| 2113 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2114 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2115 | continue; // Saw this path before; no need to look at it again. |
| 2116 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| 2117 | continue; |
| 2118 | if (CandidateVersion <= Version) |
| 2119 | continue; |
| 2120 | |
| 2121 | GCCInstallPath = |
| 2122 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2123 | if (!D.getVFS().exists(GCCInstallPath)) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2124 | continue; |
| 2125 | |
| 2126 | // If we make it here there has to be at least one GCC version, let's just |
| 2127 | // use the latest one. |
| 2128 | std::error_code EEC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2129 | for (vfs::directory_iterator |
| 2130 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), |
| 2131 | LLE; |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2132 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { |
| 2133 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2134 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2135 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); |
| 2136 | |
| 2137 | if (CandidateSubVersion > Version) |
| 2138 | Version = CandidateSubVersion; |
| 2139 | } |
| 2140 | |
| 2141 | GCCTriple.setTriple(CandidateTriple); |
| 2142 | |
| 2143 | GCCInstallPath += "/" + Version.Text; |
| 2144 | GCCParentLibPath = GCCInstallPath + "/../../../../"; |
| 2145 | |
| 2146 | IsValid = true; |
| 2147 | } |
| 2148 | } |
| 2149 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2150 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2151 | const llvm::Triple &TargetTriple, const ArgList &Args, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2152 | const std::string &LibDir, StringRef CandidateTriple, |
| 2153 | bool NeedsBiarchSuffix) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2154 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2155 | // There are various different suffixes involving the triple we |
| 2156 | // 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] | 2157 | // up to the lib directory. Specifically, the number of "up" steps |
| 2158 | // in the second half of each row is 1 + the number of path separators |
| 2159 | // in the first half. |
| 2160 | const std::string LibAndInstallSuffixes[][2] = { |
| 2161 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, |
| 2162 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2163 | // Debian puts cross-compilers in gcc-cross |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2164 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, |
| 2165 | |
| 2166 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), |
| 2167 | "/../../../.."}, |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2168 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2169 | // The Freescale PPC SDK has the gcc libraries in |
| 2170 | // <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] | 2171 | {"/" + CandidateTriple.str(), "/../.."}, |
Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2172 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2173 | // Ubuntu has a strange mis-matched pair of triples that this happens to |
| 2174 | // match. |
| 2175 | // FIXME: It may be worthwhile to generalize this and look for a second |
| 2176 | // triple. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2177 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; |
| 2178 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2179 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 2180 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, |
| 2181 | NeedsBiarchSuffix); |
| 2182 | return; |
| 2183 | } |
| 2184 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2185 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2186 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - |
| 2187 | (TargetArch != llvm::Triple::x86)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2188 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2189 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; |
Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2190 | std::error_code EC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2191 | for (vfs::directory_iterator |
| 2192 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), |
| 2193 | LE; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2194 | !EC && LI != LE; LI = LI.increment(EC)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2195 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2196 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2197 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2198 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2199 | continue; // Saw this path before; no need to look at it again. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2200 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2201 | continue; |
| 2202 | if (CandidateVersion <= Version) |
| 2203 | continue; |
Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2204 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2205 | DetectedMultilibs Detected; |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2206 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2207 | // Debian mips multilibs behave more like the rest of the biarch ones, |
| 2208 | // so handle them there |
| 2209 | if (isMipsArch(TargetArch)) { |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2210 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2211 | continue; |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2212 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2213 | NeedsBiarchSuffix, Detected)) { |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2214 | continue; |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2215 | } |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2216 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2217 | Multilibs = Detected.Multilibs; |
| 2218 | SelectedMultilib = Detected.SelectedMultilib; |
| 2219 | BiarchSibling = Detected.BiarchSibling; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2220 | Version = CandidateVersion; |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2221 | GCCTriple.setTriple(CandidateTriple); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2222 | // FIXME: We hack together the directory name here instead of |
| 2223 | // using LI to ensure stable path separators across Windows and |
| 2224 | // Linux. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2225 | GCCInstallPath = |
| 2226 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); |
| 2227 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2228 | IsValid = true; |
| 2229 | } |
| 2230 | } |
| 2231 | } |
| 2232 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2233 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2234 | const ArgList &Args) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2235 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2236 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2237 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2238 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2241 | Generic_GCC::~Generic_GCC() {} |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2242 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2243 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { |
Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2244 | switch (AC) { |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2245 | case Action::PreprocessJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2246 | if (!Preprocess) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2247 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2248 | return Preprocess.get(); |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2249 | case Action::CompileJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2250 | if (!Compile) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2251 | Compile.reset(new tools::gcc::Compiler(*this)); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2252 | return Compile.get(); |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2253 | default: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2254 | return ToolChain::getTool(AC); |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2255 | } |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2256 | } |
| 2257 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2258 | Tool *Generic_GCC::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2259 | return new tools::gnutools::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2262 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2263 | |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2264 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { |
| 2265 | // Print the information about how we detected the GCC installation. |
| 2266 | GCCInstallation.print(OS); |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2267 | CudaInstallation.print(OS); |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2268 | } |
| 2269 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2270 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2271 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2274 | bool Generic_GCC::isPICDefault() const { |
| 2275 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2276 | } |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2277 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2278 | bool Generic_GCC::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2279 | |
David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2280 | bool Generic_GCC::isPICDefaultForced() const { |
| 2281 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2282 | } |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2283 | |
Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2284 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { |
Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2285 | switch (getTriple().getArch()) { |
| 2286 | case llvm::Triple::x86: |
| 2287 | case llvm::Triple::x86_64: |
| 2288 | case llvm::Triple::aarch64: |
| 2289 | case llvm::Triple::aarch64_be: |
| 2290 | case llvm::Triple::arm: |
| 2291 | case llvm::Triple::armeb: |
Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2292 | case llvm::Triple::bpfel: |
| 2293 | case llvm::Triple::bpfeb: |
Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2294 | case llvm::Triple::thumb: |
| 2295 | case llvm::Triple::thumbeb: |
| 2296 | case llvm::Triple::ppc: |
| 2297 | case llvm::Triple::ppc64: |
| 2298 | case llvm::Triple::ppc64le: |
| 2299 | case llvm::Triple::sparc: |
| 2300 | case llvm::Triple::sparcel: |
| 2301 | case llvm::Triple::sparcv9: |
| 2302 | case llvm::Triple::systemz: |
| 2303 | return true; |
| 2304 | default: |
| 2305 | return false; |
| 2306 | } |
Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2307 | } |
| 2308 | |
James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2309 | /// \brief Helper to add the variant paths of a libstdc++ installation. |
| 2310 | bool Generic_GCC::addLibStdCXXIncludePaths( |
| 2311 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, |
| 2312 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, |
| 2313 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2314 | if (!getVFS().exists(Base + Suffix)) |
| 2315 | return false; |
| 2316 | |
| 2317 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); |
| 2318 | |
| 2319 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If |
| 2320 | // that path exists or we have neither a GCC nor target multiarch triple, use |
| 2321 | // this vanilla search path. |
| 2322 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || |
| 2323 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { |
| 2324 | addSystemInclude(DriverArgs, CC1Args, |
| 2325 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); |
| 2326 | } else { |
| 2327 | // Otherwise try to use multiarch naming schemes which have normalized the |
| 2328 | // triples and put the triple before the suffix. |
| 2329 | // |
| 2330 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and |
| 2331 | // the target triple, so we support that here. |
| 2332 | addSystemInclude(DriverArgs, CC1Args, |
| 2333 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); |
| 2334 | addSystemInclude(DriverArgs, CC1Args, |
| 2335 | Base + "/" + TargetMultiarchTriple + Suffix); |
| 2336 | } |
| 2337 | |
| 2338 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); |
| 2339 | return true; |
| 2340 | } |
| 2341 | |
| 2342 | |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2343 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, |
| 2344 | ArgStringList &CC1Args) const { |
| 2345 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2346 | bool UseInitArrayDefault = |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2347 | getTriple().getArch() == llvm::Triple::aarch64 || |
Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2348 | getTriple().getArch() == llvm::Triple::aarch64_be || |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2349 | (getTriple().getOS() == llvm::Triple::Linux && |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2350 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || |
Vasileios Kalintiris | 71b0dfe | 2015-10-30 11:28:39 +0000 | [diff] [blame] | 2351 | getTriple().getOS() == llvm::Triple::NaCl; |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2352 | |
| 2353 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2354 | options::OPT_fno_use_init_array, UseInitArrayDefault)) |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2355 | CC1Args.push_back("-fuse-init-array"); |
| 2356 | } |
| 2357 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2358 | /// Hexagon Toolchain |
| 2359 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2360 | std::string HexagonToolChain::GetGnuDir(const std::string &InstalledDir, |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2361 | const ArgList &Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2362 | // Locate the rest of the toolchain ... |
Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 2363 | std::string GccToolchain = getGCCToolchainDir(Args); |
| 2364 | |
| 2365 | if (!GccToolchain.empty()) |
| 2366 | return GccToolchain; |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2367 | |
| 2368 | std::string InstallRelDir = InstalledDir + "/../../gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2369 | if (getVFS().exists(InstallRelDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2370 | return InstallRelDir; |
| 2371 | |
| 2372 | std::string PrefixRelDir = std::string(LLVM_PREFIX) + "/../gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2373 | if (getVFS().exists(PrefixRelDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2374 | return PrefixRelDir; |
| 2375 | |
| 2376 | return InstallRelDir; |
| 2377 | } |
| 2378 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2379 | const char *HexagonToolChain::GetSmallDataThreshold(const ArgList &Args) { |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2380 | Arg *A; |
| 2381 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2382 | A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2383 | options::OPT_msmall_data_threshold_EQ); |
| 2384 | if (A) |
| 2385 | return A->getValue(); |
| 2386 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2387 | A = Args.getLastArg(options::OPT_shared, options::OPT_fpic, |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2388 | options::OPT_fPIC); |
| 2389 | if (A) |
| 2390 | return "0"; |
| 2391 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2392 | return nullptr; |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2395 | bool HexagonToolChain::UsesG0(const char *smallDataThreshold) { |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2396 | return smallDataThreshold && smallDataThreshold[0] == '0'; |
| 2397 | } |
| 2398 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2399 | static void GetHexagonLibraryPaths(const HexagonToolChain &TC, |
| 2400 | const ArgList &Args, const std::string &Ver, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2401 | const std::string &MarchString, |
| 2402 | const std::string &InstalledDir, |
| 2403 | ToolChain::path_list *LibPaths) { |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2404 | bool buildingLib = Args.hasArg(options::OPT_shared); |
| 2405 | |
| 2406 | //---------------------------------------------------------------------------- |
| 2407 | // -L Args |
| 2408 | //---------------------------------------------------------------------------- |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 2409 | for (Arg *A : Args.filtered(options::OPT_L)) |
| 2410 | for (const char *Value : A->getValues()) |
| 2411 | LibPaths->push_back(Value); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2412 | |
| 2413 | //---------------------------------------------------------------------------- |
| 2414 | // Other standard paths |
| 2415 | //---------------------------------------------------------------------------- |
| 2416 | const std::string MarchSuffix = "/" + MarchString; |
| 2417 | const std::string G0Suffix = "/G0"; |
| 2418 | const std::string MarchG0Suffix = MarchSuffix + G0Suffix; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2419 | const std::string RootDir = TC.GetGnuDir(InstalledDir, Args) + "/"; |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2420 | |
| 2421 | // lib/gcc/hexagon/... |
| 2422 | std::string LibGCCHexagonDir = RootDir + "lib/gcc/hexagon/"; |
| 2423 | if (buildingLib) { |
| 2424 | LibPaths->push_back(LibGCCHexagonDir + Ver + MarchG0Suffix); |
| 2425 | LibPaths->push_back(LibGCCHexagonDir + Ver + G0Suffix); |
| 2426 | } |
| 2427 | LibPaths->push_back(LibGCCHexagonDir + Ver + MarchSuffix); |
| 2428 | LibPaths->push_back(LibGCCHexagonDir + Ver); |
| 2429 | |
| 2430 | // lib/gcc/... |
| 2431 | LibPaths->push_back(RootDir + "lib/gcc"); |
| 2432 | |
| 2433 | // hexagon/lib/... |
| 2434 | std::string HexagonLibDir = RootDir + "hexagon/lib"; |
| 2435 | if (buildingLib) { |
| 2436 | LibPaths->push_back(HexagonLibDir + MarchG0Suffix); |
| 2437 | LibPaths->push_back(HexagonLibDir + G0Suffix); |
| 2438 | } |
| 2439 | LibPaths->push_back(HexagonLibDir + MarchSuffix); |
| 2440 | LibPaths->push_back(HexagonLibDir); |
| 2441 | } |
| 2442 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2443 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2444 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2445 | : Linux(D, Triple, Args) { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2446 | const std::string InstalledDir(getDriver().getInstalledDir()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2447 | const std::string GnuDir = GetGnuDir(InstalledDir, Args); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2448 | |
| 2449 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to |
| 2450 | // program paths |
| 2451 | const std::string BinDir(GnuDir + "/bin"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2452 | if (D.getVFS().exists(BinDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2453 | getProgramPaths().push_back(BinDir); |
| 2454 | |
| 2455 | // Determine version of GCC libraries and headers to use. |
| 2456 | const std::string HexagonDir(GnuDir + "/lib/gcc/hexagon"); |
Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2457 | std::error_code ec; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2458 | GCCVersion MaxVersion = GCCVersion::Parse("0.0.0"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2459 | for (vfs::directory_iterator di = D.getVFS().dir_begin(HexagonDir, ec), de; |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2460 | !ec && di != de; di = di.increment(ec)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2461 | GCCVersion cv = GCCVersion::Parse(llvm::sys::path::filename(di->getName())); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2462 | if (MaxVersion < cv) |
| 2463 | MaxVersion = cv; |
| 2464 | } |
| 2465 | GCCLibAndIncVersion = MaxVersion; |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2466 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2467 | ToolChain::path_list *LibPaths = &getFilePaths(); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2468 | |
| 2469 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets |
| 2470 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually |
| 2471 | // support 'linux' we'll need to fix this up |
| 2472 | LibPaths->clear(); |
| 2473 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2474 | GetHexagonLibraryPaths(*this, Args, GetGCCLibAndIncVersion(), |
| 2475 | GetTargetCPU(Args), InstalledDir, LibPaths); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2476 | } |
| 2477 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2478 | HexagonToolChain::~HexagonToolChain() {} |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2479 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2480 | Tool *HexagonToolChain::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2481 | return new tools::hexagon::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2484 | Tool *HexagonToolChain::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2485 | return new tools::hexagon::Linker(*this); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2486 | } |
| 2487 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2488 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2489 | ArgStringList &CC1Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2490 | const Driver &D = getDriver(); |
| 2491 | |
| 2492 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 2493 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2494 | return; |
| 2495 | |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2496 | std::string Ver(GetGCCLibAndIncVersion()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2497 | std::string GnuDir = GetGnuDir(D.InstalledDir, DriverArgs); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2498 | std::string HexagonDir(GnuDir + "/lib/gcc/hexagon/" + Ver); |
| 2499 | addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include"); |
| 2500 | addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include-fixed"); |
| 2501 | addExternCSystemInclude(DriverArgs, CC1Args, GnuDir + "/hexagon/include"); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2504 | void HexagonToolChain::AddClangCXXStdlibIncludeArgs( |
| 2505 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2506 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2507 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2508 | return; |
| 2509 | |
| 2510 | const Driver &D = getDriver(); |
| 2511 | std::string Ver(GetGCCLibAndIncVersion()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2512 | SmallString<128> IncludeDir(GetGnuDir(D.InstalledDir, DriverArgs)); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2513 | |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 2514 | llvm::sys::path::append(IncludeDir, "hexagon/include/c++/"); |
| 2515 | llvm::sys::path::append(IncludeDir, Ver); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 2516 | addSystemInclude(DriverArgs, CC1Args, IncludeDir); |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2517 | } |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2518 | |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2519 | ToolChain::CXXStdlibType |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2520 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2521 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 2522 | if (!A) |
| 2523 | return ToolChain::CST_Libstdcxx; |
| 2524 | |
| 2525 | StringRef Value = A->getValue(); |
| 2526 | if (Value != "libstdc++") { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2527 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | return ToolChain::CST_Libstdcxx; |
| 2531 | } |
| 2532 | |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2533 | static int getHexagonVersion(const ArgList &Args) { |
| 2534 | Arg *A = Args.getLastArg(options::OPT_march_EQ, options::OPT_mcpu_EQ); |
| 2535 | // Select the default CPU (v4) if none was given. |
| 2536 | if (!A) |
| 2537 | return 4; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2538 | |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2539 | // FIXME: produce errors if we cannot parse the version. |
| 2540 | StringRef WhichHexagon = A->getValue(); |
| 2541 | if (WhichHexagon.startswith("hexagonv")) { |
| 2542 | int Val; |
| 2543 | if (!WhichHexagon.substr(sizeof("hexagonv") - 1).getAsInteger(10, Val)) |
| 2544 | return Val; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2545 | } |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2546 | if (WhichHexagon.startswith("v")) { |
| 2547 | int Val; |
| 2548 | if (!WhichHexagon.substr(1).getAsInteger(10, Val)) |
| 2549 | return Val; |
| 2550 | } |
| 2551 | |
| 2552 | // FIXME: should probably be an error. |
| 2553 | return 4; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2556 | StringRef HexagonToolChain::GetTargetCPU(const ArgList &Args) { |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2557 | int V = getHexagonVersion(Args); |
| 2558 | // FIXME: We don't support versions < 4. We should error on them. |
| 2559 | switch (V) { |
| 2560 | default: |
| 2561 | llvm_unreachable("Unexpected version"); |
| 2562 | case 5: |
| 2563 | return "v5"; |
| 2564 | case 4: |
| 2565 | return "v4"; |
| 2566 | case 3: |
| 2567 | return "v3"; |
| 2568 | case 2: |
| 2569 | return "v2"; |
| 2570 | case 1: |
| 2571 | return "v1"; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2572 | } |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2573 | } |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2574 | // End Hexagon |
Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 2575 | |
Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 2576 | /// AMDGPU Toolchain |
| 2577 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2578 | const ArgList &Args) |
| 2579 | : Generic_ELF(D, Triple, Args) { } |
| 2580 | |
| 2581 | Tool *AMDGPUToolChain::buildLinker() const { |
| 2582 | return new tools::amdgpu::Linker(*this); |
| 2583 | } |
| 2584 | // End AMDGPU |
| 2585 | |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2586 | /// NaCl Toolchain |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2587 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2588 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2589 | : Generic_ELF(D, Triple, Args) { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2590 | |
| 2591 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the |
| 2592 | // default paths, and must instead only use the paths provided |
| 2593 | // with this toolchain based on architecture. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2594 | path_list &file_paths = getFilePaths(); |
| 2595 | path_list &prog_paths = getProgramPaths(); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2596 | |
| 2597 | file_paths.clear(); |
| 2598 | prog_paths.clear(); |
| 2599 | |
| 2600 | // Path for library files (libc.a, ...) |
| 2601 | std::string FilePath(getDriver().Dir + "/../"); |
| 2602 | |
| 2603 | // Path for tools (clang, ld, etc..) |
| 2604 | std::string ProgPath(getDriver().Dir + "/../"); |
| 2605 | |
| 2606 | // Path for toolchain libraries (libgcc.a, ...) |
| 2607 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); |
| 2608 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2609 | switch (Triple.getArch()) { |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2610 | case llvm::Triple::x86: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2611 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); |
Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2612 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2613 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 2614 | file_paths.push_back(ToolPath + "i686-nacl"); |
| 2615 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2616 | case llvm::Triple::x86_64: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2617 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); |
| 2618 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); |
| 2619 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 2620 | file_paths.push_back(ToolPath + "x86_64-nacl"); |
| 2621 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2622 | case llvm::Triple::arm: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2623 | file_paths.push_back(FilePath + "arm-nacl/lib"); |
| 2624 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); |
| 2625 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); |
| 2626 | file_paths.push_back(ToolPath + "arm-nacl"); |
| 2627 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2628 | case llvm::Triple::mipsel: |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2629 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); |
| 2630 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); |
| 2631 | prog_paths.push_back(ProgPath + "bin"); |
| 2632 | file_paths.push_back(ToolPath + "mipsel-nacl"); |
| 2633 | break; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2634 | default: |
| 2635 | break; |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | // Use provided linker, not system linker |
Derek Schuff | ef465d7 | 2015-08-24 23:53:25 +0000 | [diff] [blame] | 2639 | Linker = GetLinkerPath(); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2640 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); |
| 2641 | } |
| 2642 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2643 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2644 | ArgStringList &CC1Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2645 | const Driver &D = getDriver(); |
| 2646 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2647 | return; |
| 2648 | |
| 2649 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 2650 | SmallString<128> P(D.ResourceDir); |
| 2651 | llvm::sys::path::append(P, "include"); |
| 2652 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2653 | } |
| 2654 | |
| 2655 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2656 | return; |
| 2657 | |
| 2658 | SmallString<128> P(D.Dir + "/../"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2659 | switch (getTriple().getArch()) { |
Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2660 | case llvm::Triple::x86: |
| 2661 | // x86 is special because multilib style uses x86_64-nacl/include for libc |
| 2662 | // headers but the SDK wants i686-nacl/usr/include. The other architectures |
| 2663 | // have the same substring. |
| 2664 | llvm::sys::path::append(P, "i686-nacl/usr/include"); |
| 2665 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2666 | llvm::sys::path::remove_filename(P); |
| 2667 | llvm::sys::path::remove_filename(P); |
| 2668 | llvm::sys::path::remove_filename(P); |
| 2669 | llvm::sys::path::append(P, "x86_64-nacl/include"); |
| 2670 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2671 | return; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2672 | case llvm::Triple::arm: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2673 | llvm::sys::path::append(P, "arm-nacl/usr/include"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2674 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2675 | case llvm::Triple::x86_64: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2676 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2677 | break; |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2678 | case llvm::Triple::mipsel: |
| 2679 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); |
| 2680 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2681 | default: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2682 | return; |
| 2683 | } |
| 2684 | |
| 2685 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2686 | llvm::sys::path::remove_filename(P); |
| 2687 | llvm::sys::path::remove_filename(P); |
| 2688 | llvm::sys::path::append(P, "include"); |
| 2689 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2690 | } |
| 2691 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2692 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2693 | ArgStringList &CmdArgs) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2694 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 2695 | // if the value is libc++, and emits an error for other values. |
| 2696 | GetCXXStdlibType(Args); |
| 2697 | CmdArgs.push_back("-lc++"); |
| 2698 | } |
| 2699 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2700 | void NaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2701 | ArgStringList &CC1Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2702 | const Driver &D = getDriver(); |
| 2703 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2704 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2705 | return; |
| 2706 | |
| 2707 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 2708 | // if the value is libc++, and emits an error for other values. |
| 2709 | GetCXXStdlibType(DriverArgs); |
| 2710 | |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2711 | SmallString<128> P(D.Dir + "/../"); |
| 2712 | switch (getTriple().getArch()) { |
| 2713 | case llvm::Triple::arm: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2714 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); |
| 2715 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2716 | break; |
| 2717 | case llvm::Triple::x86: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2718 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 2719 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2720 | break; |
| 2721 | case llvm::Triple::x86_64: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2722 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 2723 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2724 | break; |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2725 | case llvm::Triple::mipsel: |
| 2726 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); |
| 2727 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2728 | break; |
Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 2729 | default: |
| 2730 | break; |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2731 | } |
| 2732 | } |
| 2733 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2734 | ToolChain::CXXStdlibType |
| 2735 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2736 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 2737 | StringRef Value = A->getValue(); |
| 2738 | if (Value == "libc++") |
| 2739 | return ToolChain::CST_Libcxx; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2740 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | return ToolChain::CST_Libcxx; |
| 2744 | } |
| 2745 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2746 | std::string |
| 2747 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, |
| 2748 | types::ID InputType) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2749 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); |
| 2750 | if (TheTriple.getArch() == llvm::Triple::arm && |
| 2751 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) |
| 2752 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); |
| 2753 | return TheTriple.getTriple(); |
| 2754 | } |
| 2755 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2756 | Tool *NaClToolChain::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2757 | return new tools::nacltools::Linker(*this); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2758 | } |
| 2759 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2760 | Tool *NaClToolChain::buildAssembler() const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2761 | if (getTriple().getArch() == llvm::Triple::arm) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2762 | return new tools::nacltools::AssemblerARM(*this); |
| 2763 | return new tools::gnutools::Assembler(*this); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2764 | } |
| 2765 | // End NaCl |
| 2766 | |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2767 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 2768 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 2769 | /// Currently does not support anything else but compilation. |
| 2770 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2771 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 2772 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2773 | : ToolChain(D, Triple, Args) { |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2774 | // Path mangling to find libexec |
| 2775 | std::string Path(getDriver().Dir); |
| 2776 | |
| 2777 | Path += "/../libexec"; |
| 2778 | getProgramPaths().push_back(Path); |
| 2779 | } |
| 2780 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2781 | TCEToolChain::~TCEToolChain() {} |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2782 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2783 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2784 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2785 | bool TCEToolChain::isPICDefault() const { return false; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2786 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2787 | bool TCEToolChain::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2788 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2789 | bool TCEToolChain::isPICDefaultForced() const { return false; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2790 | |
Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2791 | // CloudABI - CloudABI tool chain which can call ld(1) directly. |
| 2792 | |
| 2793 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, |
| 2794 | const ArgList &Args) |
| 2795 | : Generic_ELF(D, Triple, Args) { |
| 2796 | SmallString<128> P(getDriver().Dir); |
| 2797 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); |
| 2798 | getFilePaths().push_back(P.str()); |
| 2799 | } |
| 2800 | |
| 2801 | void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2802 | ArgStringList &CC1Args) const { |
| 2803 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) && |
| 2804 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2805 | return; |
| 2806 | |
| 2807 | SmallString<128> P(getDriver().Dir); |
| 2808 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); |
| 2809 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2810 | } |
| 2811 | |
| 2812 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2813 | ArgStringList &CmdArgs) const { |
| 2814 | CmdArgs.push_back("-lc++"); |
| 2815 | CmdArgs.push_back("-lc++abi"); |
| 2816 | CmdArgs.push_back("-lunwind"); |
| 2817 | } |
| 2818 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2819 | Tool *CloudABI::buildLinker() const { |
| 2820 | return new tools::cloudabi::Linker(*this); |
| 2821 | } |
Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2822 | |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2823 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 2824 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2825 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, |
| 2826 | const ArgList &Args) |
| 2827 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2828 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2829 | getFilePaths().push_back("/usr/lib"); |
| 2830 | } |
| 2831 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2832 | Tool *OpenBSD::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2833 | return new tools::openbsd::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2836 | Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2837 | |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2838 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. |
| 2839 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2840 | Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 2841 | : Generic_ELF(D, Triple, Args) { |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2842 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 2843 | getFilePaths().push_back("/usr/lib"); |
| 2844 | } |
| 2845 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2846 | Tool *Bitrig::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2847 | return new tools::bitrig::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2848 | } |
| 2849 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2850 | Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2851 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2852 | ToolChain::CXXStdlibType Bitrig::GetCXXStdlibType(const ArgList &Args) const { |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 2853 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 2854 | StringRef Value = A->getValue(); |
| 2855 | if (Value == "libstdc++") |
| 2856 | return ToolChain::CST_Libstdcxx; |
| 2857 | if (Value == "libc++") |
| 2858 | return ToolChain::CST_Libcxx; |
| 2859 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2860 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 2861 | } |
| 2862 | return ToolChain::CST_Libcxx; |
| 2863 | } |
| 2864 | |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2865 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2866 | ArgStringList &CC1Args) const { |
| 2867 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2868 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2869 | return; |
| 2870 | |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2871 | switch (GetCXXStdlibType(DriverArgs)) { |
| 2872 | case ToolChain::CST_Libcxx: |
| 2873 | addSystemInclude(DriverArgs, CC1Args, |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 2874 | getDriver().SysRoot + "/usr/include/c++/v1"); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2875 | break; |
| 2876 | case ToolChain::CST_Libstdcxx: |
| 2877 | addSystemInclude(DriverArgs, CC1Args, |
| 2878 | getDriver().SysRoot + "/usr/include/c++/stdc++"); |
| 2879 | addSystemInclude(DriverArgs, CC1Args, |
| 2880 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2881 | |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2882 | StringRef Triple = getTriple().str(); |
| 2883 | if (Triple.startswith("amd64")) |
| 2884 | addSystemInclude(DriverArgs, CC1Args, |
| 2885 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2886 | Triple.substr(5)); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2887 | else |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2888 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + |
| 2889 | "/usr/include/c++/stdc++/" + |
| 2890 | Triple); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2891 | break; |
| 2892 | } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2896 | ArgStringList &CmdArgs) const { |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2897 | switch (GetCXXStdlibType(Args)) { |
| 2898 | case ToolChain::CST_Libcxx: |
| 2899 | CmdArgs.push_back("-lc++"); |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 2900 | CmdArgs.push_back("-lc++abi"); |
| 2901 | CmdArgs.push_back("-lpthread"); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2902 | break; |
| 2903 | case ToolChain::CST_Libstdcxx: |
| 2904 | CmdArgs.push_back("-lstdc++"); |
| 2905 | break; |
| 2906 | } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 2909 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 2910 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2911 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, |
| 2912 | const ArgList &Args) |
| 2913 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 2914 | |
Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 2915 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall |
| 2916 | // back to '/usr/lib' if it doesn't exist. |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 2917 | if ((Triple.getArch() == llvm::Triple::x86 || |
| 2918 | Triple.getArch() == llvm::Triple::ppc) && |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2919 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 2920 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); |
| 2921 | else |
| 2922 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2925 | ToolChain::CXXStdlibType FreeBSD::GetCXXStdlibType(const ArgList &Args) const { |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 2926 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 2927 | StringRef Value = A->getValue(); |
| 2928 | if (Value == "libstdc++") |
| 2929 | return ToolChain::CST_Libstdcxx; |
| 2930 | if (Value == "libc++") |
| 2931 | return ToolChain::CST_Libcxx; |
| 2932 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2933 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 2934 | } |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2935 | if (getTriple().getOSMajorVersion() >= 10) |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 2936 | return ToolChain::CST_Libcxx; |
| 2937 | return ToolChain::CST_Libstdcxx; |
| 2938 | } |
| 2939 | |
| 2940 | void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2941 | ArgStringList &CC1Args) const { |
| 2942 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2943 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2944 | return; |
| 2945 | |
| 2946 | switch (GetCXXStdlibType(DriverArgs)) { |
| 2947 | case ToolChain::CST_Libcxx: |
| 2948 | addSystemInclude(DriverArgs, CC1Args, |
| 2949 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| 2950 | break; |
| 2951 | case ToolChain::CST_Libstdcxx: |
| 2952 | addSystemInclude(DriverArgs, CC1Args, |
| 2953 | getDriver().SysRoot + "/usr/include/c++/4.2"); |
| 2954 | addSystemInclude(DriverArgs, CC1Args, |
| 2955 | getDriver().SysRoot + "/usr/include/c++/4.2/backward"); |
| 2956 | break; |
| 2957 | } |
| 2958 | } |
| 2959 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2960 | Tool *FreeBSD::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2961 | return new tools::freebsd::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2964 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2965 | |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 2966 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { |
Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 2967 | // FreeBSD uses SjLj exceptions on ARM oabi. |
| 2968 | switch (getTriple().getEnvironment()) { |
Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 2969 | case llvm::Triple::GNUEABIHF: |
Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 2970 | case llvm::Triple::GNUEABI: |
| 2971 | case llvm::Triple::EABI: |
| 2972 | return false; |
| 2973 | |
| 2974 | default: |
| 2975 | return (getTriple().getArch() == llvm::Triple::arm || |
| 2976 | getTriple().getArch() == llvm::Triple::thumb); |
| 2977 | } |
| 2978 | } |
| 2979 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2980 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } |
Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 2981 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2982 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 2983 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 2984 | SanitizerMask FreeBSD::getSupportedSanitizers() const { |
| 2985 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 2986 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 2987 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 2988 | getTriple().getArch() == llvm::Triple::mips64el; |
| 2989 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 2990 | Res |= SanitizerKind::Address; |
| 2991 | Res |= SanitizerKind::Vptr; |
| 2992 | if (IsX86_64 || IsMIPS64) { |
| 2993 | Res |= SanitizerKind::Leak; |
| 2994 | Res |= SanitizerKind::Thread; |
| 2995 | } |
| 2996 | if (IsX86 || IsX86_64) { |
| 2997 | Res |= SanitizerKind::SafeStack; |
| 2998 | } |
| 2999 | return Res; |
| 3000 | } |
| 3001 | |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3002 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 3003 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3004 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3005 | : Generic_ELF(D, Triple, Args) { |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3006 | |
Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3007 | if (getDriver().UseStdLib) { |
Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3008 | // When targeting a 32-bit platform, try the special directory used on |
| 3009 | // 64-bit hosts, and only fall back to the main library directory if that |
| 3010 | // doesn't work. |
| 3011 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure |
| 3012 | // what all logic is needed to emulate the '=' prefix here. |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3013 | switch (Triple.getArch()) { |
| 3014 | case llvm::Triple::x86: |
Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3015 | getFilePaths().push_back("=/usr/lib/i386"); |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3016 | break; |
| 3017 | case llvm::Triple::arm: |
Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3018 | case llvm::Triple::armeb: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3019 | case llvm::Triple::thumb: |
Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3020 | case llvm::Triple::thumbeb: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3021 | switch (Triple.getEnvironment()) { |
| 3022 | case llvm::Triple::EABI: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3023 | case llvm::Triple::GNUEABI: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3024 | getFilePaths().push_back("=/usr/lib/eabi"); |
| 3025 | break; |
Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3026 | case llvm::Triple::EABIHF: |
| 3027 | case llvm::Triple::GNUEABIHF: |
| 3028 | getFilePaths().push_back("=/usr/lib/eabihf"); |
| 3029 | break; |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3030 | default: |
| 3031 | getFilePaths().push_back("=/usr/lib/oabi"); |
| 3032 | break; |
| 3033 | } |
| 3034 | break; |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3035 | case llvm::Triple::mips64: |
| 3036 | case llvm::Triple::mips64el: |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3037 | if (tools::mips::hasMipsAbiArg(Args, "o32")) |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3038 | getFilePaths().push_back("=/usr/lib/o32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3039 | else if (tools::mips::hasMipsAbiArg(Args, "64")) |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3040 | getFilePaths().push_back("=/usr/lib/64"); |
| 3041 | break; |
Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3042 | case llvm::Triple::ppc: |
| 3043 | getFilePaths().push_back("=/usr/lib/powerpc"); |
| 3044 | break; |
Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3045 | case llvm::Triple::sparc: |
| 3046 | getFilePaths().push_back("=/usr/lib/sparc"); |
| 3047 | break; |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3048 | default: |
| 3049 | break; |
| 3050 | } |
Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3051 | |
| 3052 | getFilePaths().push_back("=/usr/lib"); |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3053 | } |
| 3054 | } |
| 3055 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3056 | Tool *NetBSD::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3057 | return new tools::netbsd::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3060 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3061 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3062 | ToolChain::CXXStdlibType NetBSD::GetCXXStdlibType(const ArgList &Args) const { |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3063 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 3064 | StringRef Value = A->getValue(); |
| 3065 | if (Value == "libstdc++") |
| 3066 | return ToolChain::CST_Libstdcxx; |
| 3067 | if (Value == "libc++") |
| 3068 | return ToolChain::CST_Libcxx; |
| 3069 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3070 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3071 | } |
| 3072 | |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3073 | unsigned Major, Minor, Micro; |
| 3074 | getTriple().getOSVersion(Major, Minor, Micro); |
Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3075 | if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 49) || Major == 0) { |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3076 | switch (getArch()) { |
Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3077 | case llvm::Triple::aarch64: |
Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3078 | case llvm::Triple::arm: |
| 3079 | case llvm::Triple::armeb: |
| 3080 | case llvm::Triple::thumb: |
| 3081 | case llvm::Triple::thumbeb: |
Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3082 | case llvm::Triple::ppc: |
Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3083 | case llvm::Triple::ppc64: |
| 3084 | case llvm::Triple::ppc64le: |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3085 | case llvm::Triple::x86: |
| 3086 | case llvm::Triple::x86_64: |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3087 | return ToolChain::CST_Libcxx; |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3088 | default: |
| 3089 | break; |
| 3090 | } |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3091 | } |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3092 | return ToolChain::CST_Libstdcxx; |
| 3093 | } |
| 3094 | |
| 3095 | void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3096 | ArgStringList &CC1Args) const { |
| 3097 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3098 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3099 | return; |
| 3100 | |
| 3101 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3102 | case ToolChain::CST_Libcxx: |
| 3103 | addSystemInclude(DriverArgs, CC1Args, |
| 3104 | getDriver().SysRoot + "/usr/include/c++/"); |
| 3105 | break; |
| 3106 | case ToolChain::CST_Libstdcxx: |
| 3107 | addSystemInclude(DriverArgs, CC1Args, |
| 3108 | getDriver().SysRoot + "/usr/include/g++"); |
| 3109 | addSystemInclude(DriverArgs, CC1Args, |
| 3110 | getDriver().SysRoot + "/usr/include/g++/backward"); |
| 3111 | break; |
| 3112 | } |
| 3113 | } |
| 3114 | |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3115 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 3116 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3117 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3118 | : Generic_ELF(D, Triple, Args) { |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3119 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3120 | getFilePaths().push_back("/usr/lib"); |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3121 | } |
| 3122 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3123 | Tool *Minix::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3124 | return new tools::minix::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3125 | } |
| 3126 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3127 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3128 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3129 | static void addPathIfExists(const Driver &D, const Twine &Path, |
| 3130 | ToolChain::path_list &Paths) { |
| 3131 | if (D.getVFS().exists(Path)) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3132 | Paths.push_back(Path.str()); |
| 3133 | } |
| 3134 | |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3135 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. |
| 3136 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3137 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3138 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3139 | : Generic_GCC(D, Triple, Args) { |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3140 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3141 | GCCInstallation.init(Triple, Args); |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3142 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3143 | path_list &Paths = getFilePaths(); |
| 3144 | if (GCCInstallation.isValid()) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3145 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3146 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3147 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3148 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3149 | addPathIfExists(D, getDriver().Dir, Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3150 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3151 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3152 | |
| 3153 | std::string LibPath = "/usr/lib/"; |
| 3154 | switch (Triple.getArch()) { |
| 3155 | case llvm::Triple::x86: |
| 3156 | case llvm::Triple::sparc: |
| 3157 | break; |
| 3158 | case llvm::Triple::x86_64: |
| 3159 | LibPath += "amd64/"; |
| 3160 | break; |
| 3161 | case llvm::Triple::sparcv9: |
| 3162 | LibPath += "sparcv9/"; |
| 3163 | break; |
| 3164 | default: |
| 3165 | llvm_unreachable("Unsupported architecture"); |
| 3166 | } |
| 3167 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3168 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3171 | Tool *Solaris::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3172 | return new tools::solaris::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3173 | } |
| 3174 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3175 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3176 | |
Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3177 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3178 | ArgStringList &CC1Args) const { |
| 3179 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3180 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3181 | return; |
| 3182 | |
| 3183 | // Include the support directory for things like xlocale and fudged system |
| 3184 | // headers. |
| 3185 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); |
| 3186 | |
| 3187 | if (GCCInstallation.isValid()) { |
| 3188 | GCCVersion Version = GCCInstallation.getVersion(); |
| 3189 | addSystemInclude(DriverArgs, CC1Args, |
| 3190 | getDriver().SysRoot + "/usr/gcc/" + |
| 3191 | Version.MajorStr + "." + |
| 3192 | Version.MinorStr + |
| 3193 | "/include/c++/" + Version.Text); |
| 3194 | addSystemInclude(DriverArgs, CC1Args, |
| 3195 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + |
| 3196 | "." + Version.MinorStr + "/include/c++/" + |
| 3197 | Version.Text + "/" + |
| 3198 | GCCInstallation.getTriple().str()); |
| 3199 | } |
| 3200 | } |
| 3201 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3202 | /// Distribution (very bare-bones at the moment). |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3203 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3204 | enum Distro { |
Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3205 | // NB: Releases of a particular Linux distro should be kept together |
| 3206 | // in this enum, because some tests are done by integer comparison against |
| 3207 | // the first and last known member in the family, e.g. IsRedHat(). |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3208 | ArchLinux, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3209 | DebianLenny, |
| 3210 | DebianSqueeze, |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3211 | DebianWheezy, |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3212 | DebianJessie, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3213 | DebianStretch, |
Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3214 | Exherbo, |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3215 | RHEL4, |
| 3216 | RHEL5, |
| 3217 | RHEL6, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3218 | RHEL7, |
Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3219 | Fedora, |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3220 | OpenSUSE, |
Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3221 | UbuntuHardy, |
| 3222 | UbuntuIntrepid, |
Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3223 | UbuntuJaunty, |
Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3224 | UbuntuKarmic, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3225 | UbuntuLucid, |
| 3226 | UbuntuMaverick, |
Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3227 | UbuntuNatty, |
Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3228 | UbuntuOneiric, |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3229 | UbuntuPrecise, |
Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3230 | UbuntuQuantal, |
| 3231 | UbuntuRaring, |
Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3232 | UbuntuSaucy, |
Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3233 | UbuntuTrusty, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3234 | UbuntuUtopic, |
| 3235 | UbuntuVivid, |
Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3236 | UbuntuWily, |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3237 | UbuntuXenial, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3238 | UnknownDistro |
| 3239 | }; |
| 3240 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3241 | static bool IsRedhat(enum Distro Distro) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3242 | return Distro == Fedora || (Distro >= RHEL4 && Distro <= RHEL7); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3245 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3246 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3247 | static bool IsDebian(enum Distro Distro) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3248 | return Distro >= DebianLenny && Distro <= DebianStretch; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3251 | static bool IsUbuntu(enum Distro Distro) { |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3252 | return Distro >= UbuntuHardy && Distro <= UbuntuXenial; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3253 | } |
| 3254 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3255 | static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3256 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = |
| 3257 | llvm::MemoryBuffer::getFile("/etc/lsb-release"); |
| 3258 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3259 | StringRef Data = File.get()->getBuffer(); |
Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3260 | SmallVector<StringRef, 16> Lines; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3261 | Data.split(Lines, "\n"); |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3262 | Distro Version = UnknownDistro; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3263 | for (StringRef Line : Lines) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3264 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) |
| 3265 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) |
| 3266 | .Case("hardy", UbuntuHardy) |
| 3267 | .Case("intrepid", UbuntuIntrepid) |
| 3268 | .Case("jaunty", UbuntuJaunty) |
| 3269 | .Case("karmic", UbuntuKarmic) |
| 3270 | .Case("lucid", UbuntuLucid) |
| 3271 | .Case("maverick", UbuntuMaverick) |
| 3272 | .Case("natty", UbuntuNatty) |
| 3273 | .Case("oneiric", UbuntuOneiric) |
| 3274 | .Case("precise", UbuntuPrecise) |
| 3275 | .Case("quantal", UbuntuQuantal) |
| 3276 | .Case("raring", UbuntuRaring) |
| 3277 | .Case("saucy", UbuntuSaucy) |
| 3278 | .Case("trusty", UbuntuTrusty) |
| 3279 | .Case("utopic", UbuntuUtopic) |
| 3280 | .Case("vivid", UbuntuVivid) |
Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3281 | .Case("wily", UbuntuWily) |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3282 | .Case("xenial", UbuntuXenial) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3283 | .Default(UnknownDistro); |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3284 | return Version; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3285 | } |
| 3286 | |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3287 | File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); |
| 3288 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3289 | StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3290 | if (Data.startswith("Fedora release")) |
| 3291 | return Fedora; |
Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3292 | if (Data.startswith("Red Hat Enterprise Linux") || |
| 3293 | Data.startswith("CentOS")) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3294 | if (Data.find("release 7") != StringRef::npos) |
| 3295 | return RHEL7; |
| 3296 | else if (Data.find("release 6") != StringRef::npos) |
Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3297 | return RHEL6; |
| 3298 | else if (Data.find("release 5") != StringRef::npos) |
| 3299 | return RHEL5; |
| 3300 | else if (Data.find("release 4") != StringRef::npos) |
| 3301 | return RHEL4; |
| 3302 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3303 | return UnknownDistro; |
| 3304 | } |
| 3305 | |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3306 | File = llvm::MemoryBuffer::getFile("/etc/debian_version"); |
| 3307 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3308 | StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3309 | if (Data[0] == '5') |
| 3310 | return DebianLenny; |
Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 3311 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3312 | return DebianSqueeze; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3313 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3314 | return DebianWheezy; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3315 | else if (Data.startswith("jessie/sid") || Data[0] == '8') |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3316 | return DebianJessie; |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3317 | else if (Data.startswith("stretch/sid") || Data[0] == '9') |
| 3318 | return DebianStretch; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3319 | return UnknownDistro; |
| 3320 | } |
| 3321 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3322 | if (D.getVFS().exists("/etc/SuSE-release")) |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3323 | return OpenSUSE; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3324 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3325 | if (D.getVFS().exists("/etc/exherbo-release")) |
Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3326 | return Exherbo; |
| 3327 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3328 | if (D.getVFS().exists("/etc/arch-release")) |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3329 | return ArchLinux; |
| 3330 | |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3331 | return UnknownDistro; |
| 3332 | } |
| 3333 | |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3334 | /// \brief Get our best guess at the multiarch triple for a target. |
| 3335 | /// |
| 3336 | /// Debian-based systems are starting to use a multiarch setup where they use |
| 3337 | /// a target-triple directory in the library and header search paths. |
| 3338 | /// Unfortunately, this triple does not align with the vanilla target triple, |
| 3339 | /// so we provide a rough mapping here. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3340 | static std::string getMultiarchTriple(const Driver &D, |
| 3341 | const llvm::Triple &TargetTriple, |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3342 | StringRef SysRoot) { |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3343 | llvm::Triple::EnvironmentType TargetEnvironment = TargetTriple.getEnvironment(); |
| 3344 | |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3345 | // For most architectures, just use whatever we have rather than trying to be |
| 3346 | // clever. |
| 3347 | switch (TargetTriple.getArch()) { |
| 3348 | default: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3349 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3350 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3351 | // We use the existence of '/lib/<triple>' as a directory to detect some |
| 3352 | // common linux triples that don't quite match the Clang triple for both |
| 3353 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
| 3354 | // regardless of what the actual target triple is. |
Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 3355 | case llvm::Triple::arm: |
| 3356 | case llvm::Triple::thumb: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3357 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3358 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3359 | return "arm-linux-gnueabihf"; |
| 3360 | } else { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3361 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3362 | return "arm-linux-gnueabi"; |
| 3363 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3364 | break; |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3365 | case llvm::Triple::armeb: |
| 3366 | case llvm::Triple::thumbeb: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3367 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3368 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3369 | return "armeb-linux-gnueabihf"; |
| 3370 | } else { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3371 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3372 | return "armeb-linux-gnueabi"; |
| 3373 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3374 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3375 | case llvm::Triple::x86: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3376 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3377 | return "i386-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3378 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3379 | case llvm::Triple::x86_64: |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3380 | // 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] | 3381 | if (TargetEnvironment != llvm::Triple::GNUX32 && |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3382 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3383 | return "x86_64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3384 | break; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3385 | case llvm::Triple::aarch64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3386 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3387 | return "aarch64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3388 | break; |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3389 | case llvm::Triple::aarch64_be: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3390 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3391 | return "aarch64_be-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3392 | break; |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3393 | case llvm::Triple::mips: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3394 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3395 | return "mips-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3396 | break; |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3397 | case llvm::Triple::mipsel: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3398 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3399 | return "mipsel-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3400 | break; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3401 | case llvm::Triple::mips64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3402 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3403 | return "mips64-linux-gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3404 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3405 | return "mips64-linux-gnuabi64"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3406 | break; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3407 | case llvm::Triple::mips64el: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3408 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3409 | return "mips64el-linux-gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3410 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3411 | return "mips64el-linux-gnuabi64"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3412 | break; |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3413 | case llvm::Triple::ppc: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3414 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) |
Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 3415 | return "powerpc-linux-gnuspe"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3416 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3417 | return "powerpc-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3418 | break; |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3419 | case llvm::Triple::ppc64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3420 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3421 | return "powerpc64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3422 | break; |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3423 | case llvm::Triple::ppc64le: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3424 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3425 | return "powerpc64le-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3426 | break; |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3427 | case llvm::Triple::sparc: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3428 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3429 | return "sparc-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3430 | break; |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3431 | case llvm::Triple::sparcv9: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3432 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3433 | return "sparc64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3434 | break; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3435 | case llvm::Triple::systemz: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3436 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3437 | return "s390x-linux-gnu"; |
| 3438 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3439 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3440 | return TargetTriple.str(); |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3441 | } |
| 3442 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3443 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3444 | if (isMipsArch(Triple.getArch())) { |
| 3445 | // lib32 directory has a special meaning on MIPS targets. |
| 3446 | // It contains N32 ABI binaries. Use this folder if produce |
| 3447 | // code for N32 ABI only. |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3448 | if (tools::mips::hasMipsAbiArg(Args, "n32")) |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3449 | return "lib32"; |
| 3450 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 3451 | } |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3452 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3453 | // 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] | 3454 | // using that variant while targeting other architectures causes problems |
| 3455 | // 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] | 3456 | // with a 'lib32' library search path being considered. So we only enable |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3457 | // them when we know we may need it. |
| 3458 | // |
| 3459 | // 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] | 3460 | // reasoning about oslibdir spellings with the lib dir spellings in the |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3461 | // GCCInstallationDetector, but that is a more significant refactoring. |
| 3462 | if (Triple.getArch() == llvm::Triple::x86 || |
| 3463 | Triple.getArch() == llvm::Triple::ppc) |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3464 | return "lib32"; |
| 3465 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3466 | if (Triple.getArch() == llvm::Triple::x86_64 && |
| 3467 | Triple.getEnvironment() == llvm::Triple::GNUX32) |
| 3468 | return "libx32"; |
| 3469 | |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3470 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 3471 | } |
| 3472 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3473 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3474 | : Generic_ELF(D, Triple, Args) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3475 | GCCInstallation.init(Triple, Args); |
| 3476 | CudaInstallation.init(Triple, Args); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3477 | Multilibs = GCCInstallation.getMultilibs(); |
Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3478 | llvm::Triple::ArchType Arch = Triple.getArch(); |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3479 | std::string SysRoot = computeSysRoot(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3480 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3481 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at |
Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 3482 | // least) put various tools in a triple-prefixed directory off of the parent |
| 3483 | // of the GCC installation. We use the GCC triple here to ensure that we end |
| 3484 | // up with tools that support the same amount of cross compiling as the |
| 3485 | // detected GCC installation. For example, if we find a GCC installation |
| 3486 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be |
| 3487 | // used to target i386. |
| 3488 | // FIXME: This seems unlikely to be Linux-specific. |
Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3489 | ToolChain::path_list &PPaths = getProgramPaths(); |
Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 3490 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3491 | GCCInstallation.getTriple().str() + "/bin") |
| 3492 | .str()); |
Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3493 | |
Logan Chien | eb9162f | 2014-06-26 14:23:45 +0000 | [diff] [blame] | 3494 | Linker = GetLinkerPath(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3495 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3496 | Distro Distro = DetectDistro(D, Arch); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3497 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3498 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { |
Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 3499 | ExtraOpts.push_back("-z"); |
| 3500 | ExtraOpts.push_back("relro"); |
| 3501 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3502 | |
Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3503 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3504 | ExtraOpts.push_back("-X"); |
| 3505 | |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 3506 | const bool IsAndroid = Triple.isAndroid(); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3507 | const bool IsMips = isMipsArch(Arch); |
| 3508 | |
| 3509 | if (IsMips && !SysRoot.empty()) |
| 3510 | ExtraOpts.push_back("--sysroot=" + SysRoot); |
Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3511 | |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3512 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
| 3513 | // and the MIPS ABI require .dynsym to be sorted in different ways. |
| 3514 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
| 3515 | // ABI requires a mapping between the GOT and the symbol table. |
Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3516 | // Android loader does not support .gnu.hash. |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3517 | if (!IsMips && !IsAndroid) { |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3518 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3519 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3520 | ExtraOpts.push_back("--hash-style=gnu"); |
| 3521 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3522 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3523 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) |
| 3524 | ExtraOpts.push_back("--hash-style=both"); |
| 3525 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3526 | |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3527 | if (IsRedhat(Distro)) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3528 | ExtraOpts.push_back("--no-add-needed"); |
| 3529 | |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3530 | if ((IsDebian(Distro) && Distro >= DebianSqueeze) || IsOpenSUSE(Distro) || |
Rafael Espindola | d8f92c8 | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 3531 | (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3532 | (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3533 | ExtraOpts.push_back("--build-id"); |
| 3534 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3535 | if (IsOpenSUSE(Distro)) |
Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 3536 | ExtraOpts.push_back("--enable-new-dtags"); |
Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 3537 | |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3538 | // The selection of paths to try here is designed to match the patterns which |
| 3539 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
| 3540 | // This was determined by running GCC in a fake filesystem, creating all |
| 3541 | // possible permutations of these directories, and seeing which ones it added |
| 3542 | // to the link paths. |
| 3543 | path_list &Paths = getFilePaths(); |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3544 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3545 | const std::string OSLibDir = getOSLibDir(Triple, Args); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3546 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3547 | |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3548 | // Add the multilib suffixed paths where they are available. |
| 3549 | if (GCCInstallation.isValid()) { |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 3550 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3551 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3552 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 3553 | |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3554 | // Sourcery CodeBench MIPS toolchain holds some libraries under |
Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 3555 | // a biarch-like suffix of the GCC installation. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3556 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3557 | Paths); |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3558 | |
| 3559 | // GCC cross compiling toolchains will install target libraries which ship |
| 3560 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as |
| 3561 | // any part of the GCC installation in |
| 3562 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat |
| 3563 | // debatable, but is the reality today. We need to search this tree even |
| 3564 | // when we have a sysroot somewhere else. It is the responsibility of |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 3565 | // whomever is doing the cross build targeting a sysroot using a GCC |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3566 | // installation that is *not* within the system root to ensure two things: |
| 3567 | // |
| 3568 | // 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] | 3569 | // above must be present on the system root and found via an |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3570 | // appropriate rpath. |
| 3571 | // 2) There must not be libraries installed into |
| 3572 | // <prefix>/<triple>/<libdir> unless they should be preferred over |
| 3573 | // those within the system root. |
| 3574 | // |
| 3575 | // Note that this matches the GCC behavior. See the below comment for where |
| 3576 | // Clang diverges from GCC's behavior. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3577 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + |
| 3578 | OSLibDir + Multilib.osSuffix(), |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3579 | Paths); |
| 3580 | |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3581 | // If the GCC installation we found is inside of the sysroot, we want to |
| 3582 | // prefer libraries installed in the parent prefix of the GCC installation. |
| 3583 | // 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] | 3584 | // outside of the system root as that can pick up unintended libraries. |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3585 | // This usually happens when there is an external cross compiler on the |
| 3586 | // 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] | 3587 | // the cross. Note that GCC does include some of these directories in some |
| 3588 | // configurations but this seems somewhere between questionable and simply |
| 3589 | // a bug. |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3590 | if (StringRef(LibPath).startswith(SysRoot)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3591 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); |
| 3592 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3593 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3594 | } |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3595 | |
| 3596 | // 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] | 3597 | // of the requested system root, add its parent library paths to |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3598 | // those searched. |
| 3599 | // FIXME: It's not clear whether we should use the driver's installed |
| 3600 | // directory ('Dir' below) or the ResourceDir. |
| 3601 | if (StringRef(D.Dir).startswith(SysRoot)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3602 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); |
| 3603 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3604 | } |
| 3605 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3606 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); |
| 3607 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); |
| 3608 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); |
| 3609 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3610 | |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 3611 | // 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] | 3612 | // installations with strange symlinks. |
Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 3613 | if (GCCInstallation.isValid()) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3614 | addPathIfExists(D, |
| 3615 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3616 | "/../../" + OSLibDir, |
| 3617 | Paths); |
Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 3618 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3619 | // Add the 'other' biarch variant path |
| 3620 | Multilib BiarchSibling; |
| 3621 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3622 | addPathIfExists(D, GCCInstallation.getInstallPath() + |
| 3623 | BiarchSibling.gccSuffix(), |
| 3624 | Paths); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3625 | } |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3626 | |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3627 | // See comments above on the multilib variant for details of why this is |
| 3628 | // included even from outside the sysroot. |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3629 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| 3630 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| 3631 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3632 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + |
| 3633 | Multilib.osSuffix(), |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3634 | Paths); |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3635 | |
| 3636 | // See comments above on the multilib variant for details of why this is |
| 3637 | // only included from within the sysroot. |
| 3638 | if (StringRef(LibPath).startswith(SysRoot)) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3639 | addPathIfExists(D, LibPath, Paths); |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3640 | } |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3641 | |
| 3642 | // Similar to the logic for GCC above, if we are currently running Clang |
| 3643 | // inside of the requested system root, add its parent library path to those |
| 3644 | // searched. |
| 3645 | // FIXME: It's not clear whether we should use the driver's installed |
| 3646 | // directory ('Dir' below) or the ResourceDir. |
| 3647 | if (StringRef(D.Dir).startswith(SysRoot)) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3648 | addPathIfExists(D, D.Dir + "/../lib", Paths); |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3649 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3650 | addPathIfExists(D, SysRoot + "/lib", Paths); |
| 3651 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3654 | bool Linux::HasNativeLLVMSupport() const { return true; } |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3655 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3656 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3657 | |
| 3658 | Tool *Linux::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3659 | return new tools::gnutools::Assembler(*this); |
Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 3660 | } |
| 3661 | |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3662 | std::string Linux::computeSysRoot() const { |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3663 | if (!getDriver().SysRoot.empty()) |
| 3664 | return getDriver().SysRoot; |
| 3665 | |
| 3666 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) |
| 3667 | return std::string(); |
| 3668 | |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3669 | // Standalone MIPS toolchains use different names for sysroot folder |
| 3670 | // and put it into different places. Here we try to check some known |
| 3671 | // variants. |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3672 | |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3673 | const StringRef InstallDir = GCCInstallation.getInstallPath(); |
| 3674 | const StringRef TripleStr = GCCInstallation.getTriple().str(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3675 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3676 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3677 | std::string Path = |
| 3678 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) |
| 3679 | .str(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3680 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3681 | if (getVFS().exists(Path)) |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3682 | return Path; |
| 3683 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3684 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3685 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3686 | if (getVFS().exists(Path)) |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3687 | return Path; |
| 3688 | |
| 3689 | return std::string(); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3690 | } |
| 3691 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3692 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3693 | ArgStringList &CC1Args) const { |
| 3694 | const Driver &D = getDriver(); |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3695 | std::string SysRoot = computeSysRoot(); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3696 | |
| 3697 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 3698 | return; |
| 3699 | |
| 3700 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3701 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3702 | |
| 3703 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 3704 | SmallString<128> P(D.ResourceDir); |
| 3705 | llvm::sys::path::append(P, "include"); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3706 | addSystemInclude(DriverArgs, CC1Args, P); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3710 | return; |
| 3711 | |
| 3712 | // Check for configure-time C include directories. |
| 3713 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 3714 | if (CIncludeDirs != "") { |
| 3715 | SmallVector<StringRef, 5> dirs; |
| 3716 | CIncludeDirs.split(dirs, ":"); |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3717 | for (StringRef dir : dirs) { |
Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 3718 | StringRef Prefix = |
| 3719 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3720 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3721 | } |
| 3722 | return; |
| 3723 | } |
| 3724 | |
| 3725 | // Lacking those, try to detect the correct set of system includes for the |
| 3726 | // target triple. |
| 3727 | |
Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3728 | // Add include directories specific to the selected multilib set and multilib. |
| 3729 | if (GCCInstallation.isValid()) { |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 3730 | const auto &Callback = Multilibs.includeDirsCallback(); |
Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3731 | if (Callback) { |
| 3732 | const auto IncludePaths = Callback(GCCInstallation.getInstallPath(), |
| 3733 | GCCInstallation.getTriple().str(), |
| 3734 | GCCInstallation.getMultilib()); |
| 3735 | for (const auto &Path : IncludePaths) |
| 3736 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); |
| 3737 | } |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3738 | } |
| 3739 | |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3740 | // Implement generic Debian multiarch support. |
| 3741 | const StringRef X86_64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3742 | "/usr/include/x86_64-linux-gnu", |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3743 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3744 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 3745 | // in use in any released version of Debian, so we should consider |
| 3746 | // removing them. |
| 3747 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3748 | const StringRef X86MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3749 | "/usr/include/i386-linux-gnu", |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3750 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3751 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 3752 | // in use in any released version of Debian, so we should consider |
| 3753 | // removing them. |
| 3754 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", |
| 3755 | "/usr/include/i486-linux-gnu"}; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3756 | const StringRef AArch64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3757 | "/usr/include/aarch64-linux-gnu"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3758 | const StringRef ARMMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3759 | "/usr/include/arm-linux-gnueabi"}; |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3760 | const StringRef ARMHFMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3761 | "/usr/include/arm-linux-gnueabihf"}; |
| 3762 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3763 | const StringRef MIPSELMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3764 | "/usr/include/mipsel-linux-gnu"}; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3765 | const StringRef MIPS64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3766 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3767 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3768 | "/usr/include/mips64el-linux-gnu", |
| 3769 | "/usr/include/mips64el-linux-gnuabi64"}; |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3770 | const StringRef PPCMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3771 | "/usr/include/powerpc-linux-gnu"}; |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3772 | const StringRef PPC64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3773 | "/usr/include/powerpc64-linux-gnu"}; |
Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 3774 | const StringRef PPC64LEMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3775 | "/usr/include/powerpc64le-linux-gnu"}; |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3776 | const StringRef SparcMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3777 | "/usr/include/sparc-linux-gnu"}; |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3778 | const StringRef Sparc64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3779 | "/usr/include/sparc64-linux-gnu"}; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3780 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { |
| 3781 | "/usr/include/s390x-linux-gnu"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3782 | ArrayRef<StringRef> MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3783 | switch (getTriple().getArch()) { |
| 3784 | case llvm::Triple::x86_64: |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3785 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3786 | break; |
| 3787 | case llvm::Triple::x86: |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3788 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3789 | break; |
| 3790 | case llvm::Triple::aarch64: |
| 3791 | case llvm::Triple::aarch64_be: |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3792 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3793 | break; |
| 3794 | case llvm::Triple::arm: |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3795 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 3796 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; |
| 3797 | else |
| 3798 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3799 | break; |
| 3800 | case llvm::Triple::mips: |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3801 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3802 | break; |
| 3803 | case llvm::Triple::mipsel: |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3804 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3805 | break; |
| 3806 | case llvm::Triple::mips64: |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3807 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3808 | break; |
| 3809 | case llvm::Triple::mips64el: |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3810 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3811 | break; |
| 3812 | case llvm::Triple::ppc: |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3813 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3814 | break; |
| 3815 | case llvm::Triple::ppc64: |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3816 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3817 | break; |
| 3818 | case llvm::Triple::ppc64le: |
Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 3819 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3820 | break; |
| 3821 | case llvm::Triple::sparc: |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3822 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3823 | break; |
| 3824 | case llvm::Triple::sparcv9: |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3825 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3826 | break; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3827 | case llvm::Triple::systemz: |
| 3828 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; |
| 3829 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3830 | default: |
| 3831 | break; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3832 | } |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3833 | for (StringRef Dir : MultiarchIncludeDirs) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3834 | if (D.getVFS().exists(SysRoot + Dir)) { |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3835 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3836 | break; |
| 3837 | } |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | if (getTriple().getOS() == llvm::Triple::RTEMS) |
| 3841 | return; |
| 3842 | |
Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 3843 | // Add an include of '/include' directly. This isn't provided by default by |
| 3844 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 3845 | // 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] | 3846 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); |
Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 3847 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3848 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 3851 | |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame^] | 3852 | static std::string DetectLibcxxIncludePath(StringRef base) { |
| 3853 | std::error_code EC; |
| 3854 | int MaxVersion = 0; |
| 3855 | std::string MaxVersionString = ""; |
| 3856 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; |
| 3857 | LI = LI.increment(EC)) { |
| 3858 | StringRef VersionText = llvm::sys::path::filename(LI->path()); |
| 3859 | int Version; |
| 3860 | if (VersionText[0] == 'v' && |
| 3861 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { |
| 3862 | if (Version > MaxVersion) { |
| 3863 | MaxVersion = Version; |
| 3864 | MaxVersionString = VersionText; |
| 3865 | } |
| 3866 | } |
| 3867 | } |
| 3868 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; |
| 3869 | } |
| 3870 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3871 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3872 | ArgStringList &CC1Args) const { |
| 3873 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3874 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3875 | return; |
| 3876 | |
Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 3877 | // Check if libc++ has been enabled and provide its include paths if so. |
| 3878 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3879 | const std::string LibCXXIncludePathCandidates[] = { |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame^] | 3880 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3881 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3882 | // We also check the system as for a long time this is the only place |
| 3883 | // Clang looked. |
| 3884 | // FIXME: We should really remove this. It doesn't make any sense. |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame^] | 3885 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++")}; |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3886 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame^] | 3887 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3888 | continue; |
| 3889 | // Add the first candidate that exists. |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3890 | addSystemInclude(DriverArgs, CC1Args, IncludePath); |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3891 | break; |
| 3892 | } |
Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 3893 | return; |
| 3894 | } |
| 3895 | |
Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 3896 | // We need a detected GCC installation on Linux to provide libstdc++'s |
| 3897 | // headers. We handled the libc++ case above. |
| 3898 | if (!GCCInstallation.isValid()) |
| 3899 | return; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3900 | |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 3901 | // By default, look for the C++ headers in an include directory adjacent to |
| 3902 | // the lib directory of the GCC installation. Note that this is expect to be |
| 3903 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. |
| 3904 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 3905 | StringRef InstallDir = GCCInstallation.getInstallPath(); |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 3906 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3907 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3908 | const std::string GCCMultiarchTriple = getMultiarchTriple( |
| 3909 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 3910 | const std::string TargetMultiarchTriple = |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3911 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 3912 | const GCCVersion &Version = GCCInstallation.getVersion(); |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 3913 | |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 3914 | // The primary search for libstdc++ supports multiarch variants. |
Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 3915 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3916 | "/c++/" + Version.Text, TripleStr, |
| 3917 | GCCMultiarchTriple, TargetMultiarchTriple, |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3918 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 3919 | return; |
| 3920 | |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 3921 | // Otherwise, fall back on a bunch of options which don't use multiarch |
| 3922 | // layouts for simplicity. |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3923 | const std::string LibStdCXXIncludePathCandidates[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3924 | // Gentoo is weird and places its headers inside the GCC install, |
| 3925 | // so if the first attempt to find the headers fails, try these patterns. |
| 3926 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + |
| 3927 | Version.MinorStr, |
| 3928 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, |
| 3929 | // Android standalone toolchain has C++ headers in yet another place. |
| 3930 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 3931 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, |
| 3932 | // without a subdirectory corresponding to the gcc version. |
| 3933 | LibDir.str() + "/../include/c++", |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 3934 | }; |
| 3935 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3936 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 3937 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, |
| 3938 | /*GCCMultiarchTriple*/ "", |
| 3939 | /*TargetMultiarchTriple*/ "", |
| 3940 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 3941 | break; |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 3942 | } |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3943 | } |
| 3944 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3945 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 3946 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3947 | SanitizerMask Linux::getSupportedSanitizers() const { |
| 3948 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 3949 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 3950 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 3951 | getTriple().getArch() == llvm::Triple::mips64el; |
Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 3952 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || |
| 3953 | getTriple().getArch() == llvm::Triple::ppc64le; |
Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 3954 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || |
| 3955 | getTriple().getArch() == llvm::Triple::aarch64_be; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3956 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 3957 | Res |= SanitizerKind::Address; |
| 3958 | Res |= SanitizerKind::KernelAddress; |
| 3959 | Res |= SanitizerKind::Vptr; |
Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 3960 | Res |= SanitizerKind::SafeStack; |
Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 3961 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3962 | Res |= SanitizerKind::DataFlow; |
Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 3963 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3964 | Res |= SanitizerKind::Leak; |
Renato Golin | d45c2df | 2015-08-05 18:42:41 +0000 | [diff] [blame] | 3965 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3966 | Res |= SanitizerKind::Thread; |
Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 3967 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) |
Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 3968 | Res |= SanitizerKind::Memory; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3969 | if (IsX86 || IsX86_64) { |
| 3970 | Res |= SanitizerKind::Function; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3971 | } |
| 3972 | return Res; |
| 3973 | } |
| 3974 | |
Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 3975 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, |
| 3976 | llvm::opt::ArgStringList &CmdArgs) const { |
| 3977 | if (!needsProfileRT(Args)) return; |
| 3978 | |
| 3979 | // Add linker option -u__llvm_runtime_variable to cause runtime |
| 3980 | // initialization module to be linked in. |
| 3981 | if (!Args.hasArg(options::OPT_coverage)) |
| 3982 | CmdArgs.push_back(Args.MakeArgString( |
| 3983 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); |
| 3984 | ToolChain::addProfileRTLibs(Args, CmdArgs); |
| 3985 | } |
| 3986 | |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3987 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 3988 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3989 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, |
| 3990 | const ArgList &Args) |
| 3991 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3992 | |
| 3993 | // Path mangling to find libexec |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 3994 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 3995 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 3996 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3997 | |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3998 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3999 | getFilePaths().push_back("/usr/lib"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4000 | if (D.getVFS().exists("/usr/lib/gcc47")) |
John McCall | 65b8da0 | 2013-04-11 22:55:55 +0000 | [diff] [blame] | 4001 | getFilePaths().push_back("/usr/lib/gcc47"); |
| 4002 | else |
| 4003 | getFilePaths().push_back("/usr/lib/gcc44"); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4006 | Tool *DragonFly::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4007 | return new tools::dragonfly::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | Tool *DragonFly::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4011 | return new tools::dragonfly::Linker(*this); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4012 | } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4013 | |
Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4014 | /// Stub for CUDA toolchain. At the moment we don't have assembler or |
| 4015 | /// linker and need toolchain mainly to propagate device-side options |
| 4016 | /// to CC1. |
| 4017 | |
| 4018 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4019 | const ArgList &Args) |
| 4020 | : Linux(D, Triple, Args) {} |
| 4021 | |
| 4022 | void |
| 4023 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, |
| 4024 | llvm::opt::ArgStringList &CC1Args) const { |
| 4025 | Linux::addClangTargetOptions(DriverArgs, CC1Args); |
| 4026 | CC1Args.push_back("-fcuda-is-device"); |
| 4027 | } |
| 4028 | |
| 4029 | llvm::opt::DerivedArgList * |
| 4030 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, |
| 4031 | const char *BoundArch) const { |
| 4032 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 4033 | const OptTable &Opts = getDriver().getOpts(); |
| 4034 | |
| 4035 | for (Arg *A : Args) { |
| 4036 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 4037 | // Skip this argument unless the architecture matches BoundArch |
| 4038 | if (A->getValue(0) != StringRef(BoundArch)) |
| 4039 | continue; |
| 4040 | |
| 4041 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| 4042 | unsigned Prev = Index; |
| 4043 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| 4044 | |
| 4045 | // If the argument parsing failed or more than one argument was |
| 4046 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 4047 | // extra arguments. Emit an error and ignore. |
| 4048 | // |
| 4049 | // We also want to disallow any options which would alter the |
| 4050 | // driver behavior; that isn't going to work in our model. We |
| 4051 | // use isDriverOption() as an approximation, although things |
| 4052 | // like -O4 are going to slip through. |
| 4053 | if (!XarchArg || Index > Prev + 1) { |
| 4054 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| 4055 | << A->getAsString(Args); |
| 4056 | continue; |
| 4057 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| 4058 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| 4059 | << A->getAsString(Args); |
| 4060 | continue; |
| 4061 | } |
| 4062 | XarchArg->setBaseArg(A); |
| 4063 | A = XarchArg.release(); |
| 4064 | DAL->AddSynthesizedArg(A); |
| 4065 | } |
| 4066 | DAL->append(A); |
| 4067 | } |
| 4068 | |
| 4069 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); |
| 4070 | return DAL; |
| 4071 | } |
| 4072 | |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4073 | /// XCore tool chain |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4074 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4075 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4076 | : ToolChain(D, Triple, Args) { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4077 | // ProgramPaths are found via 'PATH' environment variable. |
| 4078 | } |
| 4079 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4080 | Tool *XCoreToolChain::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4081 | return new tools::XCore::Assembler(*this); |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4084 | Tool *XCoreToolChain::buildLinker() const { |
| 4085 | return new tools::XCore::Linker(*this); |
| 4086 | } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4087 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4088 | bool XCoreToolChain::isPICDefault() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4089 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4090 | bool XCoreToolChain::isPIEDefault() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4091 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4092 | bool XCoreToolChain::isPICDefaultForced() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4093 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4094 | bool XCoreToolChain::SupportsProfiling() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4095 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4096 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4097 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4098 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4099 | ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4100 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 4101 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 4102 | return; |
| 4103 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { |
| 4104 | SmallVector<StringRef, 4> Dirs; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4105 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4106 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4107 | ArrayRef<StringRef> DirVec(Dirs); |
| 4108 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4109 | } |
| 4110 | } |
| 4111 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4112 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, |
| 4113 | ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4114 | CC1Args.push_back("-nostdsysteminc"); |
| 4115 | } |
| 4116 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4117 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( |
| 4118 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4119 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 4120 | DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4121 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4122 | return; |
| 4123 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { |
| 4124 | SmallVector<StringRef, 4> Dirs; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4125 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4126 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4127 | ArrayRef<StringRef> DirVec(Dirs); |
| 4128 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4129 | } |
| 4130 | } |
| 4131 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4132 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 4133 | ArgStringList &CmdArgs) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4134 | // We don't output any lib args. This is handled by xcc. |
| 4135 | } |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4136 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4137 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4138 | const ArgList &Args) |
| 4139 | : Generic_GCC(D, Triple, Args) { |
| 4140 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use |
| 4141 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. |
| 4142 | // This won't work to find gcc. Instead we give the installation detector an |
| 4143 | // extra triple, which is preferable to further hacks of the logic that at |
| 4144 | // present is based solely on getArch(). In particular, it would be wrong to |
| 4145 | // choose the myriad installation when targeting a non-myriad sparc install. |
| 4146 | switch (Triple.getArch()) { |
| 4147 | default: |
| 4148 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() << "myriad"; |
| 4149 | case llvm::Triple::sparc: |
| 4150 | case llvm::Triple::sparcel: |
| 4151 | case llvm::Triple::shave: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4152 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4153 | } |
| 4154 | } |
| 4155 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4156 | MyriadToolChain::~MyriadToolChain() {} |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4157 | |
Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 4158 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4159 | ArgStringList &CC1Args) const { |
| 4160 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4161 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 4162 | } |
| 4163 | |
James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4164 | void MyriadToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 4165 | ArgStringList &CC1Args) const { |
| 4166 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4167 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4168 | return; |
| 4169 | |
| 4170 | // Only libstdc++, for now. |
| 4171 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4172 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| 4173 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| 4174 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| 4175 | |
| 4176 | addLibStdCXXIncludePaths(LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4177 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); |
| 4178 | } |
| 4179 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4180 | // MyriadToolChain handles several triples: |
| 4181 | // {shave,sparc{,el}}-myriad-{rtems,unknown}-elf |
| 4182 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { |
| 4183 | // The inherited method works fine if not targeting the SHAVE. |
| 4184 | if (!isShaveCompilation(getTriple())) |
| 4185 | return ToolChain::SelectTool(JA); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4186 | switch (JA.getKind()) { |
| 4187 | case Action::CompileJobClass: |
| 4188 | if (!Compiler) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4189 | Compiler.reset(new tools::SHAVE::Compiler(*this)); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4190 | return Compiler.get(); |
| 4191 | case Action::AssembleJobClass: |
| 4192 | if (!Assembler) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4193 | Assembler.reset(new tools::SHAVE::Assembler(*this)); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4194 | return Assembler.get(); |
| 4195 | default: |
| 4196 | return ToolChain::getTool(JA.getKind()); |
| 4197 | } |
| 4198 | } |
| 4199 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4200 | void MyriadToolChain::getCompilerSupportDir(std::string &Dir) const { |
| 4201 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. |
| 4202 | // These files are tied to a particular version of gcc. |
| 4203 | SmallString<128> Result(GCCInstallation.getInstallPath()); |
| 4204 | // There are actually 4 choices: {le,be} x {fpu,nofpu} |
| 4205 | // but as this toolchain is for LEON sparc, it can assume FPU. |
| 4206 | if (this->getTriple().getArch() == llvm::Triple::sparcel) |
| 4207 | llvm::sys::path::append(Result, "le"); |
| 4208 | Dir.assign(Result.str()); |
| 4209 | } |
| 4210 | void MyriadToolChain::getBuiltinLibDir(std::string &Dir) const { |
| 4211 | // The contents of LibDir are independent of the version of gcc. |
| 4212 | // This contains libc, libg (a superset of libc), libm, libstdc++, libssp. |
| 4213 | SmallString<128> Result(GCCInstallation.getParentLibPath()); |
| 4214 | if (this->getTriple().getArch() == llvm::Triple::sparcel) |
| 4215 | llvm::sys::path::append(Result, "../sparc-myriad-elf/lib/le"); |
| 4216 | else |
| 4217 | llvm::sys::path::append(Result, "../sparc-myriad-elf/lib"); |
| 4218 | Dir.assign(Result.str()); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4221 | Tool *MyriadToolChain::buildLinker() const { |
| 4222 | return new tools::Myriad::Linker(*this); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4223 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4224 | |
| 4225 | bool WebAssembly::IsMathErrnoDefault() const { return false; } |
| 4226 | |
| 4227 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } |
| 4228 | |
| 4229 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } |
| 4230 | |
| 4231 | bool WebAssembly::isPICDefault() const { return false; } |
| 4232 | |
| 4233 | bool WebAssembly::isPIEDefault() const { return false; } |
| 4234 | |
| 4235 | bool WebAssembly::isPICDefaultForced() const { return false; } |
| 4236 | |
| 4237 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } |
| 4238 | |
| 4239 | // TODO: Support Objective C stuff. |
| 4240 | bool WebAssembly::SupportsObjCGC() const { return false; } |
| 4241 | |
| 4242 | bool WebAssembly::hasBlocksRuntime() const { return false; } |
| 4243 | |
| 4244 | // TODO: Support profiling. |
| 4245 | bool WebAssembly::SupportsProfiling() const { return false; } |
| 4246 | |
| 4247 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, |
| 4248 | ArgStringList &CC1Args) const { |
| 4249 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 4250 | options::OPT_fno_use_init_array, true)) |
| 4251 | CC1Args.push_back("-fuse-init-array"); |
| 4252 | } |
Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4253 | |
| 4254 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 4255 | : Generic_ELF(D, Triple, Args) { |
| 4256 | if (Args.hasArg(options::OPT_static)) |
| 4257 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; |
| 4258 | |
| 4259 | // Determine where to find the PS4 libraries. We use SCE_PS4_SDK_DIR |
| 4260 | // if it exists; otherwise use the driver's installation path, which |
| 4261 | // should be <SDK_DIR>/host_tools/bin. |
| 4262 | |
| 4263 | SmallString<512> PS4SDKDir; |
| 4264 | if (const char *EnvValue = getenv("SCE_PS4_SDK_DIR")) { |
| 4265 | if (!llvm::sys::fs::exists(EnvValue)) |
| 4266 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; |
| 4267 | PS4SDKDir = EnvValue; |
| 4268 | } else { |
| 4269 | PS4SDKDir = getDriver().Dir; |
| 4270 | llvm::sys::path::append(PS4SDKDir, "/../../"); |
| 4271 | } |
| 4272 | |
| 4273 | // By default, the driver won't report a warning if it can't find |
| 4274 | // PS4's include or lib directories. This behavior could be changed if |
| 4275 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. |
| 4276 | // If -isysroot was passed, use that as the SDK base path. |
| 4277 | std::string PrefixDir; |
| 4278 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 4279 | PrefixDir = A->getValue(); |
| 4280 | if (!llvm::sys::fs::exists(PrefixDir)) |
| 4281 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; |
| 4282 | } else |
| 4283 | PrefixDir = PS4SDKDir.str(); |
| 4284 | |
| 4285 | SmallString<512> PS4SDKIncludeDir(PrefixDir); |
| 4286 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); |
| 4287 | if (!Args.hasArg(options::OPT_nostdinc) && |
| 4288 | !Args.hasArg(options::OPT_nostdlibinc) && |
| 4289 | !Args.hasArg(options::OPT_isysroot) && |
| 4290 | !Args.hasArg(options::OPT__sysroot_EQ) && |
| 4291 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { |
| 4292 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 4293 | << "PS4 system headers" << PS4SDKIncludeDir; |
| 4294 | } |
| 4295 | |
| 4296 | SmallString<512> PS4SDKLibDir(PS4SDKDir); |
| 4297 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); |
| 4298 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4299 | !Args.hasArg(options::OPT_nodefaultlibs) && |
| 4300 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && |
| 4301 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && |
| 4302 | !Args.hasArg(options::OPT_emit_ast) && |
| 4303 | !llvm::sys::fs::exists(PS4SDKLibDir)) { |
| 4304 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 4305 | << "PS4 system libraries" << PS4SDKLibDir; |
| 4306 | return; |
| 4307 | } |
| 4308 | getFilePaths().push_back(PS4SDKLibDir.str()); |
| 4309 | } |
| 4310 | |
| 4311 | Tool *PS4CPU::buildAssembler() const { |
| 4312 | return new tools::PS4cpu::Assemble(*this); |
| 4313 | } |
| 4314 | |
| 4315 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } |
| 4316 | |
| 4317 | bool PS4CPU::isPICDefault() const { return true; } |
| 4318 | |
| 4319 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } |
| 4320 | |
| 4321 | SanitizerMask PS4CPU::getSupportedSanitizers() const { |
| 4322 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 4323 | Res |= SanitizerKind::Address; |
| 4324 | Res |= SanitizerKind::Vptr; |
| 4325 | return Res; |
| 4326 | } |