Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 1 | //===--- ToolChains.cpp - ToolChain Implementations -------------*- C++ -*-===// |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "ToolChains.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 11 | #include "clang/Basic/ObjCRuntime.h" |
| 12 | #include "clang/Basic/Version.h" |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 13 | #include "clang/Basic/VirtualFileSystem.h" |
Alp Toker | 1d257e1 | 2014-06-04 03:28:55 +0000 | [diff] [blame] | 14 | #include "clang/Config/config.h" // for GCC_INSTALL_PREFIX |
Daniel Dunbar | 6232d34 | 2010-05-20 21:48:38 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Compilation.h" |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 17 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | da13faf | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 18 | #include "clang/Driver/Options.h" |
Alexey Samsonov | 609213f9 | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 19 | #include "clang/Driver/SanitizerArgs.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallString.h" |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringExtras.h" |
Bob Wilson | 997a97f | 2011-10-07 00:37:57 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringSwitch.h" |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 24 | #include "llvm/Option/Arg.h" |
| 25 | #include "llvm/Option/ArgList.h" |
| 26 | #include "llvm/Option/OptTable.h" |
| 27 | #include "llvm/Option/Option.h" |
Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 28 | #include "llvm/ProfileData/InstrProf.h" |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | f6efe58 | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 30 | #include "llvm/Support/FileSystem.h" |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 31 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Path.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Program.h" |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/TargetParser.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 36 | #include <cstdlib> // ::getenv |
Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 37 | #include <system_error> |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 38 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 39 | using namespace clang::driver; |
| 40 | using namespace clang::driver::toolchains; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 41 | using namespace clang; |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 42 | using namespace llvm::opt; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 43 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 44 | MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 45 | : ToolChain(D, Triple, Args) { |
Tim Northover | 15ff71d | 2014-05-22 13:12:14 +0000 | [diff] [blame] | 46 | // We expect 'as', 'ld', etc. to be adjacent to our install dir. |
| 47 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
| 48 | if (getDriver().getInstalledDir() != getDriver().Dir) |
| 49 | getProgramPaths().push_back(getDriver().Dir); |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 50 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 51 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 52 | /// Darwin - Darwin tool chain for i386 and x86_64. |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 53 | Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 54 | : MachO(D, Triple, Args), TargetInitialized(false) {} |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 55 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 56 | types::ID MachO::LookupTypeForExtension(const char *Ext) const { |
Daniel Dunbar | cc7df6c | 2010-08-02 05:43:56 +0000 | [diff] [blame] | 57 | types::ID Ty = types::lookupTypeForExtension(Ext); |
| 58 | |
| 59 | // Darwin always preprocesses assembly files (unless -x is used explicitly). |
| 60 | if (Ty == types::TY_PP_Asm) |
| 61 | return types::TY_Asm; |
| 62 | |
| 63 | return Ty; |
| 64 | } |
| 65 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 66 | bool MachO::HasNativeLLVMSupport() const { return true; } |
Daniel Dunbar | 62123a1 | 2010-09-17 00:24:52 +0000 | [diff] [blame] | 67 | |
John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 68 | /// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 69 | ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 70 | if (isTargetWatchOSBased()) |
Tim Northover | 756447a | 2015-10-30 16:30:36 +0000 | [diff] [blame] | 71 | return ObjCRuntime(ObjCRuntime::WatchOS, TargetVersion); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 72 | if (isTargetIOSBased()) |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 73 | return ObjCRuntime(ObjCRuntime::iOS, TargetVersion); |
Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 74 | if (isNonFragile) |
| 75 | return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion); |
| 76 | return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion); |
John McCall | 24fc0de | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 77 | } |
| 78 | |
John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 79 | /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2. |
| 80 | bool Darwin::hasBlocksRuntime() const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 81 | if (isTargetWatchOSBased()) |
| 82 | return true; |
| 83 | else if (isTargetIOSBased()) |
John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 84 | return !isIPhoneOSVersionLT(3, 2); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 85 | else { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 86 | assert(isTargetMacOS() && "unexpected darwin target"); |
| 87 | return !isMacosxVersionLT(10, 6); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 88 | } |
John McCall | 7959fee | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 91 | // This is just a MachO name translation routine and there's no |
| 92 | // way to join this into ARMTargetParser without breaking all |
| 93 | // other assumptions. Maybe MachO should consider standardising |
| 94 | // their nomenclature. |
| 95 | static const char *ArmMachOArchName(StringRef Arch) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 96 | return llvm::StringSwitch<const char *>(Arch) |
| 97 | .Case("armv6k", "armv6") |
| 98 | .Case("armv6m", "armv6m") |
| 99 | .Case("armv5tej", "armv5") |
| 100 | .Case("xscale", "xscale") |
| 101 | .Case("armv4t", "armv4t") |
| 102 | .Case("armv7", "armv7") |
| 103 | .Cases("armv7a", "armv7-a", "armv7") |
| 104 | .Cases("armv7r", "armv7-r", "armv7") |
| 105 | .Cases("armv7em", "armv7e-m", "armv7em") |
| 106 | .Cases("armv7k", "armv7-k", "armv7k") |
| 107 | .Cases("armv7m", "armv7-m", "armv7m") |
| 108 | .Cases("armv7s", "armv7-s", "armv7s") |
| 109 | .Default(nullptr); |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 112 | static const char *ArmMachOArchNameCPU(StringRef CPU) { |
Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 113 | unsigned ArchKind = llvm::ARM::parseCPUArch(CPU); |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 114 | if (ArchKind == llvm::ARM::AK_INVALID) |
| 115 | return nullptr; |
Chandler Carruth | aa0caeb | 2015-08-30 02:16:36 +0000 | [diff] [blame] | 116 | StringRef Arch = llvm::ARM::getArchName(ArchKind); |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 117 | |
| 118 | // FIXME: Make sure this MachO triple mangling is really necessary. |
| 119 | // ARMv5* normalises to ARMv5. |
| 120 | if (Arch.startswith("armv5")) |
| 121 | Arch = Arch.substr(0, 5); |
| 122 | // ARMv6*, except ARMv6M, normalises to ARMv6. |
| 123 | else if (Arch.startswith("armv6") && !Arch.endswith("6m")) |
| 124 | Arch = Arch.substr(0, 5); |
| 125 | // ARMv7A normalises to ARMv7. |
| 126 | else if (Arch.endswith("v7a")) |
| 127 | Arch = Arch.substr(0, 5); |
| 128 | return Arch.data(); |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 131 | static bool isSoftFloatABI(const ArgList &Args) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 132 | Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 133 | options::OPT_mfloat_abi_EQ); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 134 | if (!A) |
| 135 | return false; |
Rafael Auler | 3f7abf7 | 2014-09-29 21:50:34 +0000 | [diff] [blame] | 136 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 137 | return A->getOption().matches(options::OPT_msoft_float) || |
| 138 | (A->getOption().matches(options::OPT_mfloat_abi_EQ) && |
| 139 | A->getValue() == StringRef("soft")); |
| 140 | } |
| 141 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 142 | StringRef MachO::getMachOArchName(const ArgList &Args) const { |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 143 | switch (getTriple().getArch()) { |
| 144 | default: |
Rafael Espindola | ed1233e | 2014-08-28 21:23:05 +0000 | [diff] [blame] | 145 | return getDefaultUniversalArchName(); |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 146 | |
Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 147 | case llvm::Triple::aarch64: |
| 148 | return "arm64"; |
| 149 | |
Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 150 | case llvm::Triple::thumb: |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 151 | case llvm::Triple::arm: |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 152 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 153 | if (const char *Arch = ArmMachOArchName(A->getValue())) |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 154 | return Arch; |
| 155 | |
| 156 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
Renato Golin | 33e1f82 | 2015-05-28 15:49:28 +0000 | [diff] [blame] | 157 | if (const char *Arch = ArmMachOArchNameCPU(A->getValue())) |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 158 | return Arch; |
| 159 | |
| 160 | return "arm"; |
| 161 | } |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 164 | Darwin::~Darwin() {} |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 165 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 166 | MachO::~MachO() {} |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 167 | |
| 168 | std::string MachO::ComputeEffectiveClangTriple(const ArgList &Args, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 169 | types::ID InputType) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 170 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
| 171 | |
| 172 | return Triple.getTriple(); |
| 173 | } |
| 174 | |
Chad Rosier | d3a0f95 | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 175 | std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args, |
| 176 | types::ID InputType) const { |
| 177 | llvm::Triple Triple(ComputeLLVMTriple(Args, InputType)); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 178 | |
| 179 | // If the target isn't initialized (e.g., an unknown Darwin platform, return |
| 180 | // the default triple). |
| 181 | if (!isTargetInitialized()) |
| 182 | return Triple.getTriple(); |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 183 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 184 | SmallString<16> Str; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 185 | if (isTargetWatchOSBased()) |
| 186 | Str += "watchos"; |
| 187 | else if (isTargetTvOSBased()) |
| 188 | Str += "tvos"; |
| 189 | else if (isTargetIOSBased()) |
| 190 | Str += "ios"; |
| 191 | else |
| 192 | Str += "macosx"; |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 193 | Str += getTargetVersion().getAsString(); |
| 194 | Triple.setOSName(Str); |
Daniel Dunbar | 82eb4ce | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 195 | |
| 196 | return Triple.getTriple(); |
| 197 | } |
| 198 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 199 | void Generic_ELF::anchor() {} |
| 200 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 201 | Tool *MachO::getTool(Action::ActionClass AC) const { |
Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 202 | switch (AC) { |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 203 | case Action::LipoJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 204 | if (!Lipo) |
| 205 | Lipo.reset(new tools::darwin::Lipo(*this)); |
| 206 | return Lipo.get(); |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 207 | case Action::DsymutilJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 208 | if (!Dsymutil) |
| 209 | Dsymutil.reset(new tools::darwin::Dsymutil(*this)); |
| 210 | return Dsymutil.get(); |
Ben Langmuir | 9b9a8d3 | 2014-02-06 18:53:25 +0000 | [diff] [blame] | 211 | case Action::VerifyDebugInfoJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 212 | if (!VerifyDebug) |
| 213 | VerifyDebug.reset(new tools::darwin::VerifyDebug(*this)); |
| 214 | return VerifyDebug.get(); |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 215 | default: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 216 | return ToolChain::getTool(AC); |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 217 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 220 | Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); } |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 221 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 222 | Tool *MachO::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 223 | return new tools::darwin::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 224 | } |
Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 225 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 226 | DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 227 | const ArgList &Args) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 228 | : Darwin(D, Triple, Args) {} |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 229 | |
Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 230 | void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 231 | // For modern targets, promote certain warnings to errors. |
| 232 | if (isTargetWatchOSBased() || getTriple().isArch64Bit()) { |
Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 233 | // Always enable -Wdeprecated-objc-isa-usage and promote it |
| 234 | // to an error. |
| 235 | CC1Args.push_back("-Wdeprecated-objc-isa-usage"); |
| 236 | CC1Args.push_back("-Werror=deprecated-objc-isa-usage"); |
| 237 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 238 | // For iOS and watchOS, also error about implicit function declarations, |
| 239 | // as that can impact calling conventions. |
| 240 | if (!isTargetMacOS()) |
| 241 | CC1Args.push_back("-Werror=implicit-function-declaration"); |
Tim Northover | 336f189 | 2014-03-29 13:16:12 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 245 | /// \brief Determine whether Objective-C automated reference counting is |
| 246 | /// enabled. |
| 247 | static bool isObjCAutoRefCount(const ArgList &Args) { |
| 248 | return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); |
| 249 | } |
| 250 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 251 | void DarwinClang::AddLinkARCArgs(const ArgList &Args, |
| 252 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 253 | // Avoid linking compatibility stubs on i386 mac. |
| 254 | if (isTargetMacOS() && getArch() == llvm::Triple::x86) |
| 255 | return; |
| 256 | |
| 257 | ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true); |
| 258 | |
| 259 | if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) && |
| 260 | runtime.hasSubscripting()) |
| 261 | return; |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 262 | |
| 263 | CmdArgs.push_back("-force_load"); |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 264 | SmallString<128> P(getDriver().ClangExecutable); |
| 265 | llvm::sys::path::remove_filename(P); // 'clang' |
| 266 | llvm::sys::path::remove_filename(P); // 'bin' |
Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 267 | llvm::sys::path::append(P, "lib", "arc", "libarclite_"); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 268 | // Mash in the platform. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 269 | if (isTargetWatchOSSimulator()) |
| 270 | P += "watchsimulator"; |
| 271 | else if (isTargetWatchOS()) |
| 272 | P += "watchos"; |
| 273 | else if (isTargetTvOSSimulator()) |
| 274 | P += "appletvsimulator"; |
| 275 | else if (isTargetTvOS()) |
| 276 | P += "appletvos"; |
| 277 | else if (isTargetIOSSimulator()) |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 278 | P += "iphonesimulator"; |
Argyrios Kyrtzidis | 058b451 | 2011-10-18 17:40:15 +0000 | [diff] [blame] | 279 | else if (isTargetIPhoneOS()) |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 280 | P += "iphoneos"; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 281 | else |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 282 | P += "macosx"; |
| 283 | P += ".a"; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 284 | |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 285 | CmdArgs.push_back(Args.MakeArgString(P)); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 288 | void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, |
Kuba Brecka | 2735a025 | 2014-10-31 00:08:57 +0000 | [diff] [blame] | 289 | StringRef DarwinLibName, bool AlwaysLink, |
Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 290 | bool IsEmbedded, bool AddRPath) const { |
| 291 | SmallString<128> Dir(getDriver().ResourceDir); |
| 292 | llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin"); |
| 293 | |
| 294 | SmallString<128> P(Dir); |
| 295 | llvm::sys::path::append(P, DarwinLibName); |
Eric Christopher | 551ef45 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 296 | |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 297 | // For now, allow missing resource libraries to support developers who may |
Alexey Samsonov | 8368b37 | 2012-11-21 14:17:42 +0000 | [diff] [blame] | 298 | // not have compiler-rt checked out or integrated into their build (unless |
| 299 | // we explicitly force linking with this library). |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 300 | if (AlwaysLink || getVFS().exists(P)) |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 301 | CmdArgs.push_back(Args.MakeArgString(P)); |
Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 302 | |
| 303 | // Adding the rpaths might negatively interact when other rpaths are involved, |
| 304 | // so we should make sure we add the rpaths last, after all user-specified |
| 305 | // rpaths. This is currently true from this place, but we need to be |
| 306 | // careful if this function is ever called before user's rpaths are emitted. |
| 307 | if (AddRPath) { |
| 308 | assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library"); |
| 309 | |
| 310 | // Add @executable_path to rpath to support having the dylib copied with |
| 311 | // the executable. |
| 312 | CmdArgs.push_back("-rpath"); |
| 313 | CmdArgs.push_back("@executable_path"); |
| 314 | |
| 315 | // Add the path to the resource dir to rpath to support using the dylib |
| 316 | // from the default location without copying. |
| 317 | CmdArgs.push_back("-rpath"); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 318 | CmdArgs.push_back(Args.MakeArgString(Dir)); |
Kuba Brecka | 9ff912d | 2014-11-04 17:35:17 +0000 | [diff] [blame] | 319 | } |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Justin Bogner | 2fd95f6 | 2015-05-12 06:30:48 +0000 | [diff] [blame] | 322 | void Darwin::addProfileRTLibs(const ArgList &Args, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 323 | ArgStringList &CmdArgs) const { |
Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 324 | if (!needsProfileRT(Args)) return; |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 325 | |
| 326 | // Select the appropriate runtime library for the target. |
Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame^] | 327 | if (isTargetWatchOSBased()) { |
| 328 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_watchos.a", |
| 329 | /*AlwaysLink*/ true); |
| 330 | } else if (isTargetTvOSBased()) { |
| 331 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_tvos.a", |
| 332 | /*AlwaysLink*/ true); |
| 333 | } else if (isTargetIOSBased()) { |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 334 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a", |
| 335 | /*AlwaysLink*/ true); |
Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame^] | 336 | } else { |
| 337 | assert(isTargetMacOS() && "unexpected non MacOS platform"); |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 338 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a", |
| 339 | /*AlwaysLink*/ true); |
Vedant Kumar | 0affb93 | 2015-11-10 00:20:34 +0000 | [diff] [blame^] | 340 | } |
Xinliang David Li | 69306c0 | 2015-10-22 06:15:31 +0000 | [diff] [blame] | 341 | return; |
Justin Bogner | c770124 | 2015-05-12 05:44:36 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 344 | void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, |
| 345 | ArgStringList &CmdArgs, |
| 346 | StringRef Sanitizer) const { |
| 347 | if (!Args.hasArg(options::OPT_dynamiclib) && |
| 348 | !Args.hasArg(options::OPT_bundle)) { |
| 349 | // Sanitizer runtime libraries requires C++. |
| 350 | AddCXXStdlibLibArgs(Args, CmdArgs); |
| 351 | } |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 352 | // ASan is not supported on watchOS. |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 353 | assert(isTargetMacOS() || isTargetIOSSimulator()); |
| 354 | StringRef OS = isTargetMacOS() ? "osx" : "iossim"; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 355 | AddLinkRuntimeLib( |
| 356 | Args, CmdArgs, |
| 357 | (Twine("libclang_rt.") + Sanitizer + "_" + OS + "_dynamic.dylib").str(), |
| 358 | /*AlwaysLink*/ true, /*IsEmbedded*/ false, |
| 359 | /*AddRPath*/ true); |
Hans Wennborg | 10821e5 | 2015-04-09 18:47:01 +0000 | [diff] [blame] | 360 | |
| 361 | if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { |
| 362 | // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export |
| 363 | // all RTTI-related symbols that UBSan uses. |
| 364 | CmdArgs.push_back("-lc++abi"); |
| 365 | } |
Alexey Samsonov | 498f3c3 | 2015-03-23 23:14:05 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 368 | void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 369 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 370 | // Darwin only supports the compiler-rt based runtime libraries. |
| 371 | switch (GetRuntimeLibType(Args)) { |
| 372 | case ToolChain::RLT_CompilerRT: |
| 373 | break; |
| 374 | default: |
| 375 | getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 376 | << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; |
Daniel Dunbar | f4916cd | 2011-12-07 23:03:15 +0000 | [diff] [blame] | 377 | return; |
| 378 | } |
| 379 | |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 380 | // Darwin doesn't support real static executables, don't link any runtime |
| 381 | // libraries with -static. |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 382 | if (Args.hasArg(options::OPT_static) || |
| 383 | Args.hasArg(options::OPT_fapple_kext) || |
| 384 | Args.hasArg(options::OPT_mkernel)) |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 385 | return; |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 386 | |
| 387 | // Reject -static-libgcc for now, we can deal with this when and if someone |
| 388 | // cares. This is useful in situations where someone wants to statically link |
| 389 | // something like libstdc++, and needs its runtime support routines. |
| 390 | if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 391 | getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args); |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 392 | return; |
| 393 | } |
| 394 | |
Peter Collingbourne | 3270164 | 2013-11-01 18:16:25 +0000 | [diff] [blame] | 395 | const SanitizerArgs &Sanitize = getSanitizerArgs(); |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 396 | if (Sanitize.needsAsanRt()) |
| 397 | AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); |
| 398 | if (Sanitize.needsUbsanRt()) |
| 399 | AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); |
Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 400 | if (Sanitize.needsTsanRt()) |
| 401 | AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan"); |
Daniel Dunbar | 1d6469f | 2011-12-01 23:40:18 +0000 | [diff] [blame] | 402 | |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 403 | // Otherwise link libSystem, then the dynamic runtime library, and finally any |
| 404 | // target specific static runtime library. |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 405 | CmdArgs.push_back("-lSystem"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 406 | |
| 407 | // Select the dynamic runtime library and the target specific static library. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 408 | if (isTargetWatchOSBased()) { |
| 409 | // We currently always need a static runtime library for watchOS. |
| 410 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); |
| 411 | } else if (isTargetTvOSBased()) { |
| 412 | // We currently always need a static runtime library for tvOS. |
| 413 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); |
| 414 | } else if (isTargetIOSBased()) { |
Daniel Dunbar | 2f31fb9 | 2011-04-30 04:25:16 +0000 | [diff] [blame] | 415 | // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, |
| 416 | // it never went into the SDK. |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 417 | // Linking against libgcc_s.1 isn't needed for iOS 5.0+ |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 418 | if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && |
Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 419 | getTriple().getArch() != llvm::Triple::aarch64) |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 420 | CmdArgs.push_back("-lgcc_s.1"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 421 | |
Daniel Dunbar | d107638 | 2011-04-18 23:48:36 +0000 | [diff] [blame] | 422 | // We currently always need a static runtime library for iOS. |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 423 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 424 | } else { |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 425 | assert(isTargetMacOS() && "unexpected non MacOS platform"); |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 426 | // The dynamic runtime library was merged with libSystem for 10.6 and |
| 427 | // beyond; only 10.4 and 10.5 need an additional runtime library. |
Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 428 | if (isMacosxVersionLT(10, 5)) |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 429 | CmdArgs.push_back("-lgcc_s.10.4"); |
Daniel Dunbar | 6d23b2f | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 430 | else if (isMacosxVersionLT(10, 6)) |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 431 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 432 | |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 433 | // For OS X, we thought we would only need a static runtime library when |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 434 | // targeting 10.4, to provide versions of the static functions which were |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 435 | // omitted from 10.4.dylib. |
| 436 | // |
| 437 | // Unfortunately, that turned out to not be true, because Darwin system |
| 438 | // headers can still use eprintf on i386, and it is not exported from |
| 439 | // libSystem. Therefore, we still must provide a runtime library just for |
| 440 | // the tiny tiny handful of projects that *might* use that symbol. |
| 441 | if (isMacosxVersionLT(10, 5)) { |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 442 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 443 | } else { |
| 444 | if (getTriple().getArch() == llvm::Triple::x86) |
Eric Christopher | c235d0c6 | 2011-06-22 17:41:40 +0000 | [diff] [blame] | 445 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.eprintf.a"); |
| 446 | AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); |
Daniel Dunbar | da4f6b5 | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 447 | } |
Daniel Dunbar | 7cde09a | 2010-01-22 03:38:14 +0000 | [diff] [blame] | 448 | } |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 451 | void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 452 | const OptTable &Opts = getDriver().getOpts(); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 453 | |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 454 | // Support allowing the SDKROOT environment variable used by xcrun and other |
| 455 | // Xcode tools to define the default sysroot, by making it the default for |
| 456 | // isysroot. |
Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 457 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 458 | // Warn if the path does not exist. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 459 | if (!getVFS().exists(A->getValue())) |
Chad Rosier | 6c2b11c | 2012-12-19 23:41:50 +0000 | [diff] [blame] | 460 | getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue(); |
| 461 | } else { |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 462 | if (char *env = ::getenv("SDKROOT")) { |
Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 463 | // We only use this value as the default if it is an absolute path, |
| 464 | // exists, and it is not the root path. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 465 | if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) && |
Daniel Dunbar | b254304 | 2013-01-15 20:33:56 +0000 | [diff] [blame] | 466 | StringRef(env) != "/") { |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 467 | Args.append(Args.MakeSeparateArg( |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 468 | nullptr, Opts.getOption(options::OPT_isysroot), env)); |
Daniel Dunbar | 455a049 | 2012-08-17 18:43:50 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 473 | Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 474 | Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 475 | Arg *TvOSVersion = Args.getLastArg(options::OPT_mtvos_version_min_EQ); |
| 476 | Arg *WatchOSVersion = Args.getLastArg(options::OPT_mwatchos_version_min_EQ); |
Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 477 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 478 | if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 479 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 480 | << OSXVersion->getAsString(Args) |
| 481 | << (iOSVersion ? iOSVersion : |
| 482 | TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 483 | iOSVersion = TvOSVersion = WatchOSVersion = nullptr; |
| 484 | } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) { |
| 485 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 486 | << iOSVersion->getAsString(Args) |
| 487 | << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args); |
| 488 | TvOSVersion = WatchOSVersion = nullptr; |
| 489 | } else if (TvOSVersion && WatchOSVersion) { |
| 490 | getDriver().Diag(diag::err_drv_argument_not_allowed_with) |
| 491 | << TvOSVersion->getAsString(Args) |
| 492 | << WatchOSVersion->getAsString(Args); |
| 493 | WatchOSVersion = nullptr; |
| 494 | } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) { |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 495 | // If no deployment target was specified on the command line, check for |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 496 | // environment defines. |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 497 | std::string OSXTarget; |
| 498 | std::string iOSTarget; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 499 | std::string TvOSTarget; |
| 500 | std::string WatchOSTarget; |
| 501 | |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 502 | if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET")) |
| 503 | OSXTarget = env; |
| 504 | if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET")) |
| 505 | iOSTarget = env; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 506 | if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET")) |
| 507 | TvOSTarget = env; |
| 508 | if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET")) |
| 509 | WatchOSTarget = env; |
Daniel Dunbar | b5023e9 | 2009-04-10 21:00:07 +0000 | [diff] [blame] | 510 | |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 511 | // If there is no command-line argument to specify the Target version and |
| 512 | // no environment variable defined, see if we can set the default based |
| 513 | // on -isysroot. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 514 | if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() && |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 515 | Args.hasArg(options::OPT_isysroot)) { |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 516 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 517 | StringRef isysroot = A->getValue(); |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 518 | // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk |
| 519 | size_t BeginSDK = isysroot.rfind("SDKs/"); |
| 520 | size_t EndSDK = isysroot.rfind(".sdk"); |
| 521 | if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { |
| 522 | StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); |
| 523 | // Slice the version number out. |
| 524 | // Version number is between the first and the last number. |
| 525 | size_t StartVer = SDK.find_first_of("0123456789"); |
| 526 | size_t EndVer = SDK.find_last_of("0123456789"); |
| 527 | if (StartVer != StringRef::npos && EndVer > StartVer) { |
| 528 | StringRef Version = SDK.slice(StartVer, EndVer + 1); |
| 529 | if (SDK.startswith("iPhoneOS") || |
| 530 | SDK.startswith("iPhoneSimulator")) |
| 531 | iOSTarget = Version; |
| 532 | else if (SDK.startswith("MacOSX")) |
| 533 | OSXTarget = Version; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 534 | else if (SDK.startswith("WatchOS") || |
| 535 | SDK.startswith("WatchSimulator")) |
| 536 | WatchOSTarget = Version; |
| 537 | else if (SDK.startswith("AppleTVOS") || |
| 538 | SDK.startswith("AppleTVSimulator")) |
| 539 | TvOSTarget = Version; |
Steven Wu | 7a1372c | 2015-06-25 01:59:35 +0000 | [diff] [blame] | 540 | } |
| 541 | } |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 542 | } |
| 543 | } |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 544 | |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 545 | // If no OSX or iOS target has been specified, try to guess platform |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 546 | // from arch name and compute the version from the triple. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 547 | if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() && |
| 548 | WatchOSTarget.empty()) { |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 549 | StringRef MachOArchName = getMachOArchName(Args); |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 550 | unsigned Major, Minor, Micro; |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 551 | if (MachOArchName == "armv7" || MachOArchName == "armv7s" || |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 552 | MachOArchName == "arm64") { |
| 553 | getTriple().getiOSVersion(Major, Minor, Micro); |
| 554 | llvm::raw_string_ostream(iOSTarget) << Major << '.' << Minor << '.' |
| 555 | << Micro; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 556 | } else if (MachOArchName == "armv7k") { |
| 557 | getTriple().getWatchOSVersion(Major, Minor, Micro); |
| 558 | llvm::raw_string_ostream(WatchOSTarget) << Major << '.' << Minor << '.' |
| 559 | << Micro; |
Alexey Samsonov | 905c802 | 2015-06-18 21:46:05 +0000 | [diff] [blame] | 560 | } else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" && |
| 561 | MachOArchName != "armv7em") { |
| 562 | if (!getTriple().getMacOSXVersion(Major, Minor, Micro)) { |
| 563 | getDriver().Diag(diag::err_drv_invalid_darwin_version) |
| 564 | << getTriple().getOSName(); |
| 565 | } |
| 566 | llvm::raw_string_ostream(OSXTarget) << Major << '.' << Minor << '.' |
| 567 | << Micro; |
| 568 | } |
Alexey Samsonov | fd0bb3a | 2015-06-18 00:36:38 +0000 | [diff] [blame] | 569 | } |
Chad Rosier | fe6fd36 | 2011-09-28 00:46:32 +0000 | [diff] [blame] | 570 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 571 | // Do not allow conflicts with the watchOS target. |
| 572 | if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) { |
| 573 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 574 | << "WATCHOS_DEPLOYMENT_TARGET" |
| 575 | << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" : |
| 576 | "TVOS_DEPLOYMENT_TARGET"); |
| 577 | } |
| 578 | |
| 579 | // Do not allow conflicts with the tvOS target. |
| 580 | if (!TvOSTarget.empty() && !iOSTarget.empty()) { |
| 581 | getDriver().Diag(diag::err_drv_conflicting_deployment_targets) |
| 582 | << "TVOS_DEPLOYMENT_TARGET" |
| 583 | << "IPHONEOS_DEPLOYMENT_TARGET"; |
| 584 | } |
| 585 | |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 586 | // Allow conflicts among OSX and iOS for historical reasons, but choose the |
| 587 | // default platform. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 588 | if (!OSXTarget.empty() && (!iOSTarget.empty() || |
| 589 | !WatchOSTarget.empty() || |
| 590 | !TvOSTarget.empty())) { |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 591 | if (getTriple().getArch() == llvm::Triple::arm || |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 592 | getTriple().getArch() == llvm::Triple::aarch64 || |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 593 | getTriple().getArch() == llvm::Triple::thumb) |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 594 | OSXTarget = ""; |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 595 | else |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 596 | iOSTarget = WatchOSTarget = TvOSTarget = ""; |
Daniel Dunbar | ffa70e8 | 2010-02-02 17:31:12 +0000 | [diff] [blame] | 597 | } |
Daniel Dunbar | 6596984 | 2010-01-29 17:02:25 +0000 | [diff] [blame] | 598 | |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 599 | if (!OSXTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 600 | const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 601 | OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 602 | Args.append(OSXVersion); |
Chad Rosier | 64707fe | 2011-08-31 20:56:25 +0000 | [diff] [blame] | 603 | } else if (!iOSTarget.empty()) { |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 604 | const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 605 | iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 606 | Args.append(iOSVersion); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 607 | } else if (!TvOSTarget.empty()) { |
| 608 | const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ); |
| 609 | TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget); |
| 610 | Args.append(TvOSVersion); |
| 611 | } else if (!WatchOSTarget.empty()) { |
| 612 | const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ); |
| 613 | WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget); |
| 614 | Args.append(WatchOSVersion); |
Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 615 | } |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 616 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 617 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 618 | DarwinPlatformKind Platform; |
| 619 | if (OSXVersion) |
| 620 | Platform = MacOS; |
| 621 | else if (iOSVersion) |
| 622 | Platform = IPhoneOS; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 623 | else if (TvOSVersion) |
| 624 | Platform = TvOS; |
| 625 | else if (WatchOSVersion) |
| 626 | Platform = WatchOS; |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 627 | else |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 628 | llvm_unreachable("Unable to infer Darwin variant"); |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 629 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 630 | // Set the tool chain target information. |
| 631 | unsigned Major, Minor, Micro; |
| 632 | bool HadExtra; |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 633 | if (Platform == MacOS) { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 634 | assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) && |
| 635 | "Unknown target platform!"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 636 | if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro, |
| 637 | HadExtra) || |
| 638 | HadExtra || Major != 10 || Minor >= 100 || Micro >= 100) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 639 | getDriver().Diag(diag::err_drv_invalid_version_number) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 640 | << OSXVersion->getAsString(Args); |
Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 641 | } else if (Platform == IPhoneOS) { |
| 642 | assert(iOSVersion && "Unknown target platform!"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 643 | if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro, |
| 644 | HadExtra) || |
| 645 | HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100) |
Eli Friedman | 027e9c3 | 2012-01-11 02:41:15 +0000 | [diff] [blame] | 646 | getDriver().Diag(diag::err_drv_invalid_version_number) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 647 | << iOSVersion->getAsString(Args); |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 648 | } else if (Platform == TvOS) { |
| 649 | if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor, |
| 650 | Micro, HadExtra) || HadExtra || |
| 651 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 652 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 653 | << TvOSVersion->getAsString(Args); |
| 654 | } else if (Platform == WatchOS) { |
| 655 | if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor, |
| 656 | Micro, HadExtra) || HadExtra || |
| 657 | Major >= 10 || Minor >= 100 || Micro >= 100) |
| 658 | getDriver().Diag(diag::err_drv_invalid_version_number) |
| 659 | << WatchOSVersion->getAsString(Args); |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 660 | } else |
| 661 | llvm_unreachable("unknown kind of Darwin platform"); |
Daniel Dunbar | 9aaeb64 | 2011-04-30 04:15:58 +0000 | [diff] [blame] | 662 | |
Bob Wilson | 7f294b5 | 2014-10-10 23:10:10 +0000 | [diff] [blame] | 663 | // Recognize iOS targets with an x86 architecture as the iOS simulator. |
Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 664 | if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 665 | getTriple().getArch() == llvm::Triple::x86_64)) |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 666 | Platform = IPhoneOSSimulator; |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 667 | if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 668 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 669 | Platform = TvOSSimulator; |
| 670 | if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 || |
| 671 | getTriple().getArch() == llvm::Triple::x86_64)) |
| 672 | Platform = WatchOSSimulator; |
Daniel Dunbar | b118943 | 2011-04-30 04:18:16 +0000 | [diff] [blame] | 673 | |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 674 | setTarget(Platform, Major, Minor, Micro); |
Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Daniel Dunbar | 3f7796f | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 677 | void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 678 | ArgStringList &CmdArgs) const { |
| 679 | CXXStdlibType Type = GetCXXStdlibType(Args); |
| 680 | |
| 681 | switch (Type) { |
| 682 | case ToolChain::CST_Libcxx: |
| 683 | CmdArgs.push_back("-lc++"); |
| 684 | break; |
| 685 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 686 | case ToolChain::CST_Libstdcxx: |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 687 | // Unfortunately, -lstdc++ doesn't always exist in the standard search path; |
| 688 | // it was previously found in the gcc lib dir. However, for all the Darwin |
| 689 | // platforms we care about it was -lstdc++.6, so we search for that |
| 690 | // explicitly if we can't see an obvious -lstdc++ candidate. |
| 691 | |
| 692 | // Check in the sysroot first. |
| 693 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 694 | SmallString<128> P(A->getValue()); |
Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 695 | llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 696 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 697 | if (!getVFS().exists(P)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 698 | llvm::sys::path::remove_filename(P); |
| 699 | llvm::sys::path::append(P, "libstdc++.6.dylib"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 700 | if (getVFS().exists(P)) { |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 701 | CmdArgs.push_back(Args.MakeArgString(P)); |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 702 | return; |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | // Otherwise, look in the root. |
Bob Wilson | 1a9ad0f | 2011-11-11 07:47:04 +0000 | [diff] [blame] | 708 | // FIXME: This should be removed someday when we don't have to care about |
| 709 | // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 710 | if (!getVFS().exists("/usr/lib/libstdc++.dylib") && |
| 711 | getVFS().exists("/usr/lib/libstdc++.6.dylib")) { |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 712 | CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); |
| 713 | return; |
| 714 | } |
| 715 | |
| 716 | // Otherwise, let the linker search. |
| 717 | CmdArgs.push_back("-lstdc++"); |
| 718 | break; |
| 719 | } |
Daniel Dunbar | 8fa86b1 | 2010-09-17 01:16:06 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 722 | void DarwinClang::AddCCKextLibArgs(const ArgList &Args, |
| 723 | ArgStringList &CmdArgs) const { |
| 724 | |
| 725 | // For Darwin platforms, use the compiler-rt-based support library |
| 726 | // instead of the gcc-provided one (which is also incidentally |
| 727 | // only present in the gcc lib dir, which makes it hard to find). |
| 728 | |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 729 | SmallString<128> P(getDriver().ResourceDir); |
Benjamin Kramer | 17381a0 | 2013-06-28 16:25:46 +0000 | [diff] [blame] | 730 | llvm::sys::path::append(P, "lib", "darwin"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 731 | |
| 732 | // Use the newer cc_kext for iOS ARM after 6.0. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 733 | if (isTargetWatchOS()) { |
| 734 | llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a"); |
| 735 | } else if (isTargetTvOS()) { |
| 736 | llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a"); |
| 737 | } else if (isTargetIPhoneOS()) { |
Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 738 | llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 739 | } else { |
Chris Bieneman | 25bc0de | 2015-09-23 22:52:35 +0000 | [diff] [blame] | 740 | llvm::sys::path::append(P, "libclang_rt.cc_kext.a"); |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 741 | } |
NAKAMURA Takumi | 8b73b3e | 2011-06-03 03:49:51 +0000 | [diff] [blame] | 742 | |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 743 | // For now, allow missing resource libraries to support developers who may |
| 744 | // not have compiler-rt checked out or integrated into their build. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 745 | if (getVFS().exists(P)) |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 746 | CmdArgs.push_back(Args.MakeArgString(P)); |
Shantonu Sen | afeb03b | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 749 | DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, |
| 750 | const char *BoundArch) const { |
Daniel Dunbar | b2b8a91 | 2010-07-19 17:11:33 +0000 | [diff] [blame] | 751 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 752 | const OptTable &Opts = getDriver().getOpts(); |
| 753 | |
| 754 | // FIXME: We really want to get out of the tool chain level argument |
| 755 | // translation business, as it makes the driver functionality much |
| 756 | // more opaque. For now, we follow gcc closely solely for the |
| 757 | // purpose of easily achieving feature parity & testability. Once we |
| 758 | // have something that works, we should reevaluate each translation |
| 759 | // and try to push it down into tool specific logic. |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 760 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 761 | for (Arg *A : Args) { |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 762 | if (A->getOption().matches(options::OPT_Xarch__)) { |
Daniel Dunbar | 471c4f8 | 2011-06-21 00:20:17 +0000 | [diff] [blame] | 763 | // Skip this argument unless the architecture matches either the toolchain |
| 764 | // triple arch, or the arch being bound. |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 765 | llvm::Triple::ArchType XarchArch = |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 766 | tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); |
| 767 | if (!(XarchArch == getArch() || |
| 768 | (BoundArch && |
| 769 | XarchArch == |
| 770 | tools::darwin::getArchTypeForMachOArchName(BoundArch)))) |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 771 | continue; |
| 772 | |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 773 | Arg *OriginalArg = A; |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 774 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 775 | unsigned Prev = Index; |
Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 776 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 778 | // If the argument parsing failed or more than one argument was |
| 779 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 780 | // extra arguments. Emit an error and ignore. |
| 781 | // |
| 782 | // We also want to disallow any options which would alter the |
| 783 | // driver behavior; that isn't going to work in our model. We |
| 784 | // use isDriverOption() as an approximation, although things |
| 785 | // like -O4 are going to slip through. |
Daniel Dunbar | 5a784c8 | 2011-04-21 17:41:34 +0000 | [diff] [blame] | 786 | if (!XarchArg || Index > Prev + 1) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 787 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 788 | << A->getAsString(Args); |
Daniel Dunbar | 6914a98 | 2011-04-21 17:32:21 +0000 | [diff] [blame] | 789 | continue; |
Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 790 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 791 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 792 | << A->getAsString(Args); |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 793 | continue; |
| 794 | } |
| 795 | |
Daniel Dunbar | 53b406f | 2009-03-29 22:29:05 +0000 | [diff] [blame] | 796 | XarchArg->setBaseArg(A); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 797 | |
Nico Weber | a04d5f8 | 2014-05-11 17:27:13 +0000 | [diff] [blame] | 798 | A = XarchArg.release(); |
Daniel Dunbar | 3f1a1ff | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 799 | DAL->AddSynthesizedArg(A); |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 800 | |
| 801 | // Linker input arguments require custom handling. The problem is that we |
| 802 | // have already constructed the phase actions, so we can not treat them as |
| 803 | // "input arguments". |
Michael J. Spencer | 66e2b20 | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 804 | if (A->getOption().hasFlag(options::LinkerInput)) { |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 805 | // Convert the argument into individual Zlinker_input_args. |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 806 | for (const char *Value : A->getValues()) { |
| 807 | DAL->AddSeparateArg( |
| 808 | OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value); |
Daniel Dunbar | 1094bb1 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 809 | } |
| 810 | continue; |
| 811 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | } |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 813 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 814 | // Sob. These is strictly gcc compatible for the time being. Apple |
| 815 | // gcc translates options twice, which means that self-expanding |
| 816 | // options add duplicates. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 817 | switch ((options::ID)A->getOption().getID()) { |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 818 | default: |
| 819 | DAL->append(A); |
| 820 | break; |
| 821 | |
| 822 | case options::OPT_mkernel: |
| 823 | case options::OPT_fapple_kext: |
| 824 | DAL->append(A); |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 825 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 826 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 828 | case options::OPT_dependency_file: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 829 | DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue()); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 830 | break; |
| 831 | |
| 832 | case options::OPT_gfull: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 833 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 834 | DAL->AddFlagArg( |
| 835 | A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | case options::OPT_gused: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 839 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 840 | DAL->AddFlagArg( |
| 841 | A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 842 | break; |
| 843 | |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 844 | case options::OPT_shared: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 845 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 846 | break; |
| 847 | |
| 848 | case options::OPT_fconstant_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 849 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | case options::OPT_fno_constant_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 853 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 854 | break; |
| 855 | |
| 856 | case options::OPT_Wnonportable_cfstrings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 857 | DAL->AddFlagArg(A, |
| 858 | Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 859 | break; |
| 860 | |
| 861 | case options::OPT_Wno_nonportable_cfstrings: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 862 | DAL->AddFlagArg( |
| 863 | A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case options::OPT_fpascal_strings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 867 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case options::OPT_fno_pascal_strings: |
Daniel Dunbar | 2d6e9ee | 2010-06-14 20:20:41 +0000 | [diff] [blame] | 871 | DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 872 | break; |
| 873 | } |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 876 | if (getTriple().getArch() == llvm::Triple::x86 || |
| 877 | getTriple().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | fffd181 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 878 | if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 879 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ), |
| 880 | "core2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 881 | |
| 882 | // Add the arch options based on the particular spelling of -arch, to match |
Chad Rosier | 7c5d908 | 2012-04-27 14:58:16 +0000 | [diff] [blame] | 883 | // how the driver driver works. |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 884 | if (BoundArch) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 885 | StringRef Name = BoundArch; |
Michael J. Spencer | fc79090 | 2012-10-19 22:36:40 +0000 | [diff] [blame] | 886 | const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ); |
| 887 | const Option MArch = Opts.getOption(options::OPT_march_EQ); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 888 | |
| 889 | // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, |
| 890 | // which defines the list of which architectures we accept. |
| 891 | if (Name == "ppc") |
| 892 | ; |
| 893 | else if (Name == "ppc601") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 894 | DAL->AddJoinedArg(nullptr, MCpu, "601"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 895 | else if (Name == "ppc603") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 896 | DAL->AddJoinedArg(nullptr, MCpu, "603"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 897 | else if (Name == "ppc604") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 898 | DAL->AddJoinedArg(nullptr, MCpu, "604"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 899 | else if (Name == "ppc604e") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 900 | DAL->AddJoinedArg(nullptr, MCpu, "604e"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 901 | else if (Name == "ppc750") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 902 | DAL->AddJoinedArg(nullptr, MCpu, "750"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 903 | else if (Name == "ppc7400") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 904 | DAL->AddJoinedArg(nullptr, MCpu, "7400"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 905 | else if (Name == "ppc7450") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 906 | DAL->AddJoinedArg(nullptr, MCpu, "7450"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 907 | else if (Name == "ppc970") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 908 | DAL->AddJoinedArg(nullptr, MCpu, "970"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 909 | |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 910 | else if (Name == "ppc64" || Name == "ppc64le") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 911 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 912 | |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 913 | else if (Name == "i386") |
| 914 | ; |
| 915 | else if (Name == "i486") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 916 | DAL->AddJoinedArg(nullptr, MArch, "i486"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 917 | else if (Name == "i586") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 918 | DAL->AddJoinedArg(nullptr, MArch, "i586"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 919 | else if (Name == "i686") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 920 | DAL->AddJoinedArg(nullptr, MArch, "i686"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 921 | else if (Name == "pentium") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 922 | DAL->AddJoinedArg(nullptr, MArch, "pentium"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 923 | else if (Name == "pentium2") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 924 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 925 | else if (Name == "pentpro") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 926 | DAL->AddJoinedArg(nullptr, MArch, "pentiumpro"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 927 | else if (Name == "pentIIm3") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 928 | DAL->AddJoinedArg(nullptr, MArch, "pentium2"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 929 | |
| 930 | else if (Name == "x86_64") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 931 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 932 | else if (Name == "x86_64h") { |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 933 | DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64)); |
| 934 | DAL->AddJoinedArg(nullptr, MArch, "x86_64h"); |
Jim Grosbach | 82eee26 | 2013-11-16 00:53:35 +0000 | [diff] [blame] | 935 | } |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 936 | |
| 937 | else if (Name == "arm") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 938 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 939 | else if (Name == "armv4t") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 940 | DAL->AddJoinedArg(nullptr, MArch, "armv4t"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 941 | else if (Name == "armv5") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 942 | DAL->AddJoinedArg(nullptr, MArch, "armv5tej"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 943 | else if (Name == "xscale") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 944 | DAL->AddJoinedArg(nullptr, MArch, "xscale"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 945 | else if (Name == "armv6") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 946 | DAL->AddJoinedArg(nullptr, MArch, "armv6k"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 947 | else if (Name == "armv6m") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 948 | DAL->AddJoinedArg(nullptr, MArch, "armv6m"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 949 | else if (Name == "armv7") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 950 | DAL->AddJoinedArg(nullptr, MArch, "armv7a"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 951 | else if (Name == "armv7em") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 952 | DAL->AddJoinedArg(nullptr, MArch, "armv7em"); |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 953 | else if (Name == "armv7k") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 954 | DAL->AddJoinedArg(nullptr, MArch, "armv7k"); |
Bob Wilson | 743bf67 | 2013-03-04 22:37:49 +0000 | [diff] [blame] | 955 | else if (Name == "armv7m") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 956 | DAL->AddJoinedArg(nullptr, MArch, "armv7m"); |
Bob Wilson | d7cf104 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 957 | else if (Name == "armv7s") |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 958 | DAL->AddJoinedArg(nullptr, MArch, "armv7s"); |
Daniel Dunbar | 3c7b9ca | 2009-09-09 22:33:15 +0000 | [diff] [blame] | 959 | } |
Daniel Dunbar | 0af75a1 | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 960 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 961 | return DAL; |
| 962 | } |
| 963 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 964 | void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 965 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 966 | // Embedded targets are simple at the moment, not supporting sanitizers and |
| 967 | // with different libraries for each member of the product { static, PIC } x |
| 968 | // { hard-float, soft-float } |
| 969 | llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); |
Saleem Abdulrasool | 06f6f99 | 2015-09-19 20:40:16 +0000 | [diff] [blame] | 970 | CompilerRT += |
| 971 | (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) |
| 972 | ? "hard" |
| 973 | : "soft"; |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 974 | CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; |
| 975 | |
| 976 | AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true); |
| 977 | } |
| 978 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 979 | DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, |
| 980 | const char *BoundArch) const { |
| 981 | // First get the generic Apple args, before moving onto Darwin-specific ones. |
| 982 | DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch); |
| 983 | const OptTable &Opts = getDriver().getOpts(); |
| 984 | |
Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 985 | // If no architecture is bound, none of the translations here are relevant. |
| 986 | if (!BoundArch) |
| 987 | return DAL; |
| 988 | |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 989 | // Add an explicit version min argument for the deployment target. We do this |
| 990 | // after argument translation because -Xarch_ arguments may add a version min |
| 991 | // argument. |
Bob Wilson | f8cf161 | 2014-02-21 00:20:07 +0000 | [diff] [blame] | 992 | AddDeploymentTarget(*DAL); |
Daniel Dunbar | 354e96d | 2010-07-19 17:11:36 +0000 | [diff] [blame] | 993 | |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 994 | // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext. |
| 995 | // FIXME: It would be far better to avoid inserting those -static arguments, |
| 996 | // but we can't check the deployment target in the translation code until |
| 997 | // it is set here. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 998 | if (isTargetWatchOSBased() || |
| 999 | (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) { |
| 1000 | for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) { |
Daniel Dunbar | bd847cc | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1001 | Arg *A = *it; |
| 1002 | ++it; |
| 1003 | if (A->getOption().getID() != options::OPT_mkernel && |
| 1004 | A->getOption().getID() != options::OPT_fapple_kext) |
| 1005 | continue; |
| 1006 | assert(it != ie && "unexpected argument translation"); |
| 1007 | A = *it; |
| 1008 | assert(A->getOption().getID() == options::OPT_static && |
| 1009 | "missing expected -static argument"); |
| 1010 | it = DAL->getArgs().erase(it); |
| 1011 | } |
| 1012 | } |
| 1013 | |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1014 | // Default to use libc++ on OS X 10.9+ and iOS 7+. |
| 1015 | if (((isTargetMacOS() && !isMacosxVersionLT(10, 9)) || |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1016 | (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) || |
| 1017 | isTargetWatchOSBased()) && |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1018 | !Args.getLastArg(options::OPT_stdlib_EQ)) |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 1019 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ), |
| 1020 | "libc++"); |
Bob Wilson | 0f7445b | 2013-11-02 23:19:53 +0000 | [diff] [blame] | 1021 | |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1022 | // Validate the C++ standard library choice. |
| 1023 | CXXStdlibType Type = GetCXXStdlibType(*DAL); |
| 1024 | if (Type == ToolChain::CST_Libcxx) { |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1025 | // Check whether the target provides libc++. |
| 1026 | StringRef where; |
| 1027 | |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 1028 | // Complain about targeting iOS < 5.0 in any way. |
Tim Northover | 9c7e035 | 2013-12-12 11:55:52 +0000 | [diff] [blame] | 1029 | if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0)) |
Bob Wilson | 5ad5a95 | 2012-11-09 01:59:30 +0000 | [diff] [blame] | 1030 | where = "iOS 5.0"; |
John McCall | 5fb5df9 | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1031 | |
| 1032 | if (where != StringRef()) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1033 | getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where; |
Bob Wilson | 102be44 | 2011-10-07 17:54:41 +0000 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | |
Daniel Dunbar | aabb0b1 | 2009-03-25 06:12:34 +0000 | [diff] [blame] | 1037 | return DAL; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1039 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1040 | bool MachO::IsUnwindTablesDefault() const { |
Rafael Espindola | e8bd4e5 | 2012-10-07 03:23:40 +0000 | [diff] [blame] | 1041 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1044 | bool MachO::UseDwarfDebugFlags() const { |
Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1045 | if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) |
| 1046 | return S[0] != '\0'; |
| 1047 | return false; |
| 1048 | } |
| 1049 | |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1050 | bool Darwin::UseSjLjExceptions(const ArgList &Args) const { |
Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1051 | // Darwin uses SjLj exceptions on ARM. |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 1052 | if (getTriple().getArch() != llvm::Triple::arm && |
| 1053 | getTriple().getArch() != llvm::Triple::thumb) |
| 1054 | return false; |
| 1055 | |
| 1056 | // We can't check directly for watchOS here. ComputeLLVMTriple only |
| 1057 | // fills in the ArchName correctly. |
| 1058 | llvm::Triple Triple(ComputeLLVMTriple(Args)); |
| 1059 | return !(Triple.getArchName() == "armv7k" || |
| 1060 | Triple.getArchName() == "thumbv7k"); |
| 1061 | |
Daniel Dunbar | 3241d40 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1064 | bool MachO::isPICDefault() const { return true; } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1065 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1066 | bool MachO::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 1067 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1068 | bool MachO::isPICDefaultForced() const { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1069 | return (getArch() == llvm::Triple::x86_64 || |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1070 | getArch() == llvm::Triple::aarch64); |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1073 | bool MachO::SupportsProfiling() const { |
Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1074 | // Profiling instrumentation is only supported on x86. |
Rafael Espindola | 35ca7d9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 1075 | return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 733b0f8 | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1078 | void Darwin::addMinVersionArgs(const ArgList &Args, |
| 1079 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1080 | VersionTuple TargetVersion = getTargetVersion(); |
| 1081 | |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1082 | if (isTargetWatchOS()) |
| 1083 | CmdArgs.push_back("-watchos_version_min"); |
| 1084 | else if (isTargetWatchOSSimulator()) |
| 1085 | CmdArgs.push_back("-watchos_simulator_version_min"); |
| 1086 | else if (isTargetTvOS()) |
| 1087 | CmdArgs.push_back("-tvos_version_min"); |
| 1088 | else if (isTargetTvOSSimulator()) |
| 1089 | CmdArgs.push_back("-tvos_simulator_version_min"); |
| 1090 | else if (isTargetIOSSimulator()) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1091 | CmdArgs.push_back("-ios_simulator_version_min"); |
Bob Wilson | 5cfc55e | 2014-02-01 21:06:21 +0000 | [diff] [blame] | 1092 | else if (isTargetIOSBased()) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1093 | CmdArgs.push_back("-iphoneos_version_min"); |
| 1094 | else { |
| 1095 | assert(isTargetMacOS() && "unexpected target"); |
| 1096 | CmdArgs.push_back("-macosx_version_min"); |
| 1097 | } |
| 1098 | |
| 1099 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); |
| 1100 | } |
| 1101 | |
Douglas Katzman | f08fadf | 2015-06-04 14:40:44 +0000 | [diff] [blame] | 1102 | void Darwin::addStartObjectFileArgs(const ArgList &Args, |
| 1103 | ArgStringList &CmdArgs) const { |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1104 | // Derived from startfile spec. |
| 1105 | if (Args.hasArg(options::OPT_dynamiclib)) { |
| 1106 | // Derived from darwin_dylib1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1107 | if (isTargetWatchOSBased()) { |
| 1108 | ; // watchOS does not need dylib1.o. |
| 1109 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1110 | ; // iOS simulator does not need dylib1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1111 | } else if (isTargetIPhoneOS()) { |
| 1112 | if (isIPhoneOSVersionLT(3, 1)) |
| 1113 | CmdArgs.push_back("-ldylib1.o"); |
| 1114 | } else { |
| 1115 | if (isMacosxVersionLT(10, 5)) |
| 1116 | CmdArgs.push_back("-ldylib1.o"); |
| 1117 | else if (isMacosxVersionLT(10, 6)) |
| 1118 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1119 | } |
| 1120 | } else { |
| 1121 | if (Args.hasArg(options::OPT_bundle)) { |
| 1122 | if (!Args.hasArg(options::OPT_static)) { |
| 1123 | // Derived from darwin_bundle1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1124 | if (isTargetWatchOSBased()) { |
| 1125 | ; // watchOS does not need bundle1.o. |
| 1126 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1127 | ; // iOS simulator does not need bundle1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1128 | } else if (isTargetIPhoneOS()) { |
| 1129 | if (isIPhoneOSVersionLT(3, 1)) |
| 1130 | CmdArgs.push_back("-lbundle1.o"); |
| 1131 | } else { |
| 1132 | if (isMacosxVersionLT(10, 6)) |
| 1133 | CmdArgs.push_back("-lbundle1.o"); |
| 1134 | } |
| 1135 | } |
| 1136 | } else { |
| 1137 | if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) { |
| 1138 | if (Args.hasArg(options::OPT_static) || |
| 1139 | Args.hasArg(options::OPT_object) || |
| 1140 | Args.hasArg(options::OPT_preload)) { |
| 1141 | CmdArgs.push_back("-lgcrt0.o"); |
| 1142 | } else { |
| 1143 | CmdArgs.push_back("-lgcrt1.o"); |
| 1144 | |
| 1145 | // darwin_crt2 spec is empty. |
| 1146 | } |
| 1147 | // By default on OS X 10.8 and later, we don't link with a crt1.o |
| 1148 | // file and the linker knows to use _main as the entry point. But, |
| 1149 | // when compiling with -pg, we need to link with the gcrt1.o file, |
| 1150 | // so pass the -no_new_main option to tell the linker to use the |
| 1151 | // "start" symbol as the entry point. |
| 1152 | if (isTargetMacOS() && !isMacosxVersionLT(10, 8)) |
| 1153 | CmdArgs.push_back("-no_new_main"); |
| 1154 | } else { |
| 1155 | if (Args.hasArg(options::OPT_static) || |
| 1156 | Args.hasArg(options::OPT_object) || |
| 1157 | Args.hasArg(options::OPT_preload)) { |
| 1158 | CmdArgs.push_back("-lcrt0.o"); |
| 1159 | } else { |
| 1160 | // Derived from darwin_crt1 spec. |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1161 | if (isTargetWatchOSBased()) { |
| 1162 | ; // watchOS does not need crt1.o. |
| 1163 | } else if (isTargetIOSSimulator()) { |
Bob Wilson | 74b6cd1 | 2014-01-21 00:17:10 +0000 | [diff] [blame] | 1164 | ; // iOS simulator does not need crt1.o. |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1165 | } else if (isTargetIPhoneOS()) { |
Tim Northover | 40956e6 | 2014-07-23 12:32:58 +0000 | [diff] [blame] | 1166 | if (getArch() == llvm::Triple::aarch64) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 1167 | ; // iOS does not need any crt1 files for arm64 |
| 1168 | else if (isIPhoneOSVersionLT(3, 1)) |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1169 | CmdArgs.push_back("-lcrt1.o"); |
| 1170 | else if (isIPhoneOSVersionLT(6, 0)) |
| 1171 | CmdArgs.push_back("-lcrt1.3.1.o"); |
| 1172 | } else { |
| 1173 | if (isMacosxVersionLT(10, 5)) |
| 1174 | CmdArgs.push_back("-lcrt1.o"); |
| 1175 | else if (isMacosxVersionLT(10, 6)) |
| 1176 | CmdArgs.push_back("-lcrt1.10.5.o"); |
| 1177 | else if (isMacosxVersionLT(10, 8)) |
| 1178 | CmdArgs.push_back("-lcrt1.10.6.o"); |
| 1179 | |
| 1180 | // darwin_crt2 spec is empty. |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1188 | !isTargetWatchOS() && |
Tim Northover | 157d911 | 2014-01-16 08:48:16 +0000 | [diff] [blame] | 1189 | isMacosxVersionLT(10, 5)) { |
| 1190 | const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); |
| 1191 | CmdArgs.push_back(Str); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1195 | bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); } |
Daniel Dunbar | 16334e1 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1196 | |
John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1197 | void Darwin::CheckObjCARC() const { |
Tim Northover | 6f3ff22 | 2015-10-30 16:30:27 +0000 | [diff] [blame] | 1198 | if (isTargetIOSBased() || isTargetWatchOSBased() || |
| 1199 | (isTargetMacOS() && !isMacosxVersionLT(10, 6))) |
John McCall | 3deb1ad | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 1200 | return; |
John McCall | 9320707 | 2012-08-27 01:56:21 +0000 | [diff] [blame] | 1201 | getDriver().Diag(diag::err_arc_unsupported_on_toolchain); |
Argyrios Kyrtzidis | 3dbeb55 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1204 | SanitizerMask Darwin::getSupportedSanitizers() const { |
| 1205 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1206 | if (isTargetMacOS() || isTargetIOSSimulator()) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1207 | Res |= SanitizerKind::Address; |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1208 | if (isTargetMacOS()) { |
| 1209 | if (!isMacosxVersionLT(10, 9)) |
| 1210 | Res |= SanitizerKind::Vptr; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1211 | Res |= SanitizerKind::SafeStack; |
Kuba Brecka | 85e01c0 | 2015-11-06 15:09:20 +0000 | [diff] [blame] | 1212 | Res |= SanitizerKind::Thread; |
Alexey Samsonov | 1d4cff2 | 2015-06-25 00:58:02 +0000 | [diff] [blame] | 1213 | } |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 1214 | return Res; |
| 1215 | } |
| 1216 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 1217 | /// Generic_GCC - A tool chain using the 'gcc' command to perform |
| 1218 | /// all subcommands; this relies on gcc translating the majority of |
| 1219 | /// command line options. |
| 1220 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1221 | /// \brief Parse a GCCVersion object out of a string of text. |
| 1222 | /// |
| 1223 | /// This is the primary means of forming GCCVersion objects. |
| 1224 | /*static*/ |
| 1225 | Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1226 | const GCCVersion BadVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1227 | std::pair<StringRef, StringRef> First = VersionText.split('.'); |
| 1228 | std::pair<StringRef, StringRef> Second = First.second.split('.'); |
| 1229 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1230 | GCCVersion GoodVersion = {VersionText.str(), -1, -1, -1, "", "", ""}; |
| 1231 | if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1232 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1233 | GoodVersion.MajorStr = First.first.str(); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1234 | if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1235 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1236 | GoodVersion.MinorStr = Second.first.str(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1237 | |
| 1238 | // First look for a number prefix and parse that if present. Otherwise just |
| 1239 | // stash the entire patch string in the suffix, and leave the number |
| 1240 | // unspecified. This covers versions strings such as: |
| 1241 | // 4.4 |
| 1242 | // 4.4.0 |
| 1243 | // 4.4.x |
| 1244 | // 4.4.2-rc4 |
| 1245 | // 4.4.x-patched |
| 1246 | // And retains any patch number it finds. |
| 1247 | StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str(); |
| 1248 | if (!PatchText.empty()) { |
Will Dietz | a38608b | 2013-01-10 22:20:02 +0000 | [diff] [blame] | 1249 | if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) { |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1250 | // Try to parse the number and any suffix. |
| 1251 | if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) || |
| 1252 | GoodVersion.Patch < 0) |
| 1253 | return BadVersion; |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 1254 | GoodVersion.PatchSuffix = PatchText.substr(EndNumber); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | return GoodVersion; |
| 1259 | } |
| 1260 | |
| 1261 | /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1262 | bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, |
| 1263 | int RHSPatch, |
| 1264 | StringRef RHSPatchSuffix) const { |
| 1265 | if (Major != RHSMajor) |
| 1266 | return Major < RHSMajor; |
| 1267 | if (Minor != RHSMinor) |
| 1268 | return Minor < RHSMinor; |
| 1269 | if (Patch != RHSPatch) { |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1270 | // Note that versions without a specified patch sort higher than those with |
| 1271 | // a patch. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1272 | if (RHSPatch == -1) |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1273 | return true; |
| 1274 | if (Patch == -1) |
| 1275 | return false; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1276 | |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1277 | // Otherwise just sort on the patch itself. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1278 | return Patch < RHSPatch; |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1279 | } |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1280 | if (PatchSuffix != RHSPatchSuffix) { |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1281 | // Sort empty suffixes higher. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1282 | if (RHSPatchSuffix.empty()) |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1283 | return true; |
| 1284 | if (PatchSuffix.empty()) |
Chandler Carruth | 19e8bea | 2012-12-29 13:00:47 +0000 | [diff] [blame] | 1285 | return false; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1286 | |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1287 | // Provide a lexicographic sort to make this a total ordering. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 1288 | return PatchSuffix < RHSPatchSuffix; |
Chandler Carruth | 5193dfc | 2012-12-29 12:01:08 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | // The versions are equal. |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1292 | return false; |
| 1293 | } |
| 1294 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1295 | static llvm::StringRef getGCCToolchainDir(const ArgList &Args) { |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1296 | const Arg *A = Args.getLastArg(options::OPT_gcc_toolchain); |
| 1297 | if (A) |
Richard Smith | bd55daf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1298 | return A->getValue(); |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1299 | return GCC_INSTALL_PREFIX; |
| 1300 | } |
| 1301 | |
Roman Divacky | 326d998 | 2013-12-06 18:32:18 +0000 | [diff] [blame] | 1302 | /// \brief Initialize a GCCInstallationDetector from the driver. |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1303 | /// |
| 1304 | /// This performs all of the autodetection and sets up the various paths. |
Gabor Greif | 8a45d57 | 2012-04-17 11:16:26 +0000 | [diff] [blame] | 1305 | /// Once constructed, a GCCInstallationDetector is essentially immutable. |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1306 | /// |
| 1307 | /// FIXME: We shouldn't need an explicit TargetTriple parameter here, and |
| 1308 | /// should instead pull the target out of the driver. This is currently |
| 1309 | /// necessary because the driver doesn't store the final version of the target |
| 1310 | /// triple. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1311 | void Generic_GCC::GCCInstallationDetector::init( |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1312 | const llvm::Triple &TargetTriple, const ArgList &Args, |
Douglas Katzman | 8c39e6a | 2015-09-18 15:23:16 +0000 | [diff] [blame] | 1313 | ArrayRef<std::string> ExtraTripleAliases) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1314 | llvm::Triple BiarchVariantTriple = TargetTriple.isArch32Bit() |
| 1315 | ? TargetTriple.get64BitArchVariant() |
| 1316 | : TargetTriple.get32BitArchVariant(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1317 | // The library directories which may contain GCC installations. |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1318 | SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1319 | // The compatible GCC triples for this particular architecture. |
Hans Wennborg | 90aa63f | 2014-08-11 18:09:28 +0000 | [diff] [blame] | 1320 | SmallVector<StringRef, 16> CandidateTripleAliases; |
| 1321 | SmallVector<StringRef, 16> CandidateBiarchTripleAliases; |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1322 | CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs, |
| 1323 | CandidateTripleAliases, CandidateBiarchLibDirs, |
| 1324 | CandidateBiarchTripleAliases); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1325 | |
| 1326 | // Compute the set of prefixes for our search. |
| 1327 | SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), |
| 1328 | D.PrefixDirs.end()); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1329 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1330 | StringRef GCCToolchainDir = getGCCToolchainDir(Args); |
| 1331 | if (GCCToolchainDir != "") { |
| 1332 | if (GCCToolchainDir.back() == '/') |
| 1333 | GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1334 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 1335 | Prefixes.push_back(GCCToolchainDir); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1336 | } else { |
Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1337 | // If we have a SysRoot, try that first. |
| 1338 | if (!D.SysRoot.empty()) { |
| 1339 | Prefixes.push_back(D.SysRoot); |
| 1340 | Prefixes.push_back(D.SysRoot + "/usr"); |
| 1341 | } |
| 1342 | |
| 1343 | // Then look for gcc installed alongside clang. |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1344 | Prefixes.push_back(D.InstalledDir + "/.."); |
Rafael Espindola | 0f4b04e | 2013-08-28 23:17:47 +0000 | [diff] [blame] | 1345 | |
| 1346 | // And finally in /usr. |
| 1347 | if (D.SysRoot.empty()) |
| 1348 | Prefixes.push_back("/usr"); |
Rafael Espindola | c29af94 | 2012-02-03 01:01:20 +0000 | [diff] [blame] | 1349 | } |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1350 | |
| 1351 | // Loop over the various components which exist and select the best GCC |
| 1352 | // installation available. GCC installs are ranked by version number. |
| 1353 | Version = GCCVersion::Parse("0.0.0"); |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1354 | for (const std::string &Prefix : Prefixes) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1355 | if (!D.getVFS().exists(Prefix)) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1356 | continue; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1357 | for (StringRef Suffix : CandidateLibDirs) { |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1358 | const std::string LibDir = Prefix + Suffix.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1359 | if (!D.getVFS().exists(LibDir)) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1360 | continue; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1361 | for (StringRef Candidate : ExtraTripleAliases) // Try these first. |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 1362 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1363 | for (StringRef Candidate : CandidateTripleAliases) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1364 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1365 | } |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1366 | for (StringRef Suffix : CandidateBiarchLibDirs) { |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1367 | const std::string LibDir = Prefix + Suffix.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1368 | if (!D.getVFS().exists(LibDir)) |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1369 | continue; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 1370 | for (StringRef Candidate : CandidateBiarchTripleAliases) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 1371 | ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1372 | /*NeedsBiarchSuffix=*/ true); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1377 | void Generic_GCC::GCCInstallationDetector::print(raw_ostream &OS) const { |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1378 | for (const auto &InstallPath : CandidateGCCInstallPaths) |
| 1379 | OS << "Found candidate GCC installation: " << InstallPath << "\n"; |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1380 | |
Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1381 | if (!GCCInstallPath.empty()) |
| 1382 | OS << "Selected GCC installation: " << GCCInstallPath << "\n"; |
| 1383 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 1384 | for (const auto &Multilib : Multilibs) |
| 1385 | OS << "Candidate multilib: " << Multilib << "\n"; |
Yunzhong Gao | e3f902c | 2014-02-19 19:06:58 +0000 | [diff] [blame] | 1386 | |
| 1387 | if (Multilibs.size() != 0 || !SelectedMultilib.isDefault()) |
| 1388 | OS << "Selected multilib: " << SelectedMultilib << "\n"; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { |
| 1392 | if (BiarchSibling.hasValue()) { |
| 1393 | M = BiarchSibling.getValue(); |
| 1394 | return true; |
| 1395 | } |
| 1396 | return false; |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1399 | /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1400 | const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple, |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1401 | SmallVectorImpl<StringRef> &LibDirs, |
| 1402 | SmallVectorImpl<StringRef> &TripleAliases, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1403 | SmallVectorImpl<StringRef> &BiarchLibDirs, |
| 1404 | SmallVectorImpl<StringRef> &BiarchTripleAliases) { |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1405 | // Declare a bunch of static data sets that we'll select between below. These |
| 1406 | // are specifically designed to always refer to string literals to avoid any |
| 1407 | // lifetime or initialization issues. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1408 | static const char *const AArch64LibDirs[] = {"/lib64", "/lib"}; |
| 1409 | static const char *const AArch64Triples[] = { |
| 1410 | "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-linux-android", |
| 1411 | "aarch64-redhat-linux"}; |
| 1412 | static const char *const AArch64beLibDirs[] = {"/lib"}; |
| 1413 | static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu", |
| 1414 | "aarch64_be-linux-gnu"}; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1415 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1416 | static const char *const ARMLibDirs[] = {"/lib"}; |
| 1417 | static const char *const ARMTriples[] = {"arm-linux-gnueabi", |
| 1418 | "arm-linux-androideabi"}; |
| 1419 | static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", |
| 1420 | "armv7hl-redhat-linux-gnueabi"}; |
| 1421 | static const char *const ARMebLibDirs[] = {"/lib"}; |
| 1422 | static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", |
| 1423 | "armeb-linux-androideabi"}; |
| 1424 | static const char *const ARMebHFTriples[] = { |
| 1425 | "armeb-linux-gnueabihf", "armebv7hl-redhat-linux-gnueabi"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1426 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1427 | static const char *const X86_64LibDirs[] = {"/lib64", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1428 | static const char *const X86_64Triples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1429 | "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", |
| 1430 | "x86_64-pc-linux-gnu", "x86_64-redhat-linux6E", |
| 1431 | "x86_64-redhat-linux", "x86_64-suse-linux", |
| 1432 | "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", |
| 1433 | "x86_64-slackware-linux", "x86_64-linux-android", |
| 1434 | "x86_64-unknown-linux"}; |
| 1435 | static const char *const X32LibDirs[] = {"/libx32"}; |
| 1436 | static const char *const X86LibDirs[] = {"/lib32", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1437 | static const char *const X86Triples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1438 | "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", |
| 1439 | "i386-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux", |
| 1440 | "i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux", |
| 1441 | "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android", |
| 1442 | "i586-linux-gnu"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1443 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1444 | static const char *const MIPSLibDirs[] = {"/lib"}; |
Vasileios Kalintiris | 71b0dfe | 2015-10-30 11:28:39 +0000 | [diff] [blame] | 1445 | static const char *const MIPSTriples[] = { |
| 1446 | "mips-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu"}; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1447 | static const char *const MIPSELLibDirs[] = {"/lib"}; |
| 1448 | static const char *const MIPSELTriples[] = { |
| 1449 | "mipsel-linux-gnu", "mipsel-linux-android", "mips-img-linux-gnu"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1450 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1451 | static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; |
| 1452 | static const char *const MIPS64Triples[] = { |
| 1453 | "mips64-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1454 | "mips64-linux-gnuabi64"}; |
| 1455 | static const char *const MIPS64ELLibDirs[] = {"/lib64", "/lib"}; |
| 1456 | static const char *const MIPS64ELTriples[] = { |
| 1457 | "mips64el-linux-gnu", "mips-mti-linux-gnu", "mips-img-linux-gnu", |
| 1458 | "mips64el-linux-android", "mips64el-linux-gnuabi64"}; |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1459 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1460 | static const char *const PPCLibDirs[] = {"/lib32", "/lib"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1461 | static const char *const PPCTriples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1462 | "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe", |
| 1463 | "powerpc-suse-linux", "powerpc-montavista-linuxspe"}; |
| 1464 | static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; |
| 1465 | static const char *const PPC64Triples[] = { |
| 1466 | "powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu", |
| 1467 | "powerpc64-suse-linux", "ppc64-redhat-linux"}; |
| 1468 | static const char *const PPC64LELibDirs[] = {"/lib64", "/lib"}; |
| 1469 | static const char *const PPC64LETriples[] = { |
| 1470 | "powerpc64le-linux-gnu", "powerpc64le-unknown-linux-gnu", |
| 1471 | "powerpc64le-suse-linux", "ppc64le-redhat-linux"}; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1472 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1473 | static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; |
| 1474 | static const char *const SPARCv8Triples[] = {"sparc-linux-gnu", |
| 1475 | "sparcv8-linux-gnu"}; |
| 1476 | static const char *const SPARCv9LibDirs[] = {"/lib64", "/lib"}; |
| 1477 | static const char *const SPARCv9Triples[] = {"sparc64-linux-gnu", |
| 1478 | "sparcv9-linux-gnu"}; |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1479 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1480 | static const char *const SystemZLibDirs[] = {"/lib64", "/lib"}; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1481 | static const char *const SystemZTriples[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1482 | "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu", |
| 1483 | "s390x-suse-linux", "s390x-redhat-linux"}; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1484 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1485 | // Solaris. |
| 1486 | static const char *const SolarisSPARCLibDirs[] = {"/gcc"}; |
| 1487 | static const char *const SolarisSPARCTriples[] = {"sparc-sun-solaris2.11", |
| 1488 | "i386-pc-solaris2.11"}; |
| 1489 | |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1490 | using std::begin; |
| 1491 | using std::end; |
| 1492 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1493 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 1494 | LibDirs.append(begin(SolarisSPARCLibDirs), end(SolarisSPARCLibDirs)); |
| 1495 | TripleAliases.append(begin(SolarisSPARCTriples), end(SolarisSPARCTriples)); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 1496 | return; |
| 1497 | } |
| 1498 | |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1499 | switch (TargetTriple.getArch()) { |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1500 | case llvm::Triple::aarch64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1501 | LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1502 | TripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
| 1503 | BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); |
| 1504 | BiarchTripleAliases.append(begin(AArch64Triples), end(AArch64Triples)); |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 1505 | break; |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1506 | case llvm::Triple::aarch64_be: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1507 | LibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1508 | TripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
| 1509 | BiarchLibDirs.append(begin(AArch64beLibDirs), end(AArch64beLibDirs)); |
| 1510 | BiarchTripleAliases.append(begin(AArch64beTriples), end(AArch64beTriples)); |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 1511 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1512 | case llvm::Triple::arm: |
| 1513 | case llvm::Triple::thumb: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1514 | LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1515 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1516 | TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1517 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1518 | TripleAliases.append(begin(ARMTriples), end(ARMTriples)); |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 1519 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1520 | break; |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1521 | case llvm::Triple::armeb: |
| 1522 | case llvm::Triple::thumbeb: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1523 | LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1524 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1525 | TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1526 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1527 | TripleAliases.append(begin(ARMebTriples), end(ARMebTriples)); |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1528 | } |
| 1529 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1530 | case llvm::Triple::x86_64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1531 | LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1532 | TripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
| 1533 | // x32 is always available when x86_64 is available, so adding it as |
| 1534 | // secondary arch with x86_64 triples |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1535 | if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1536 | BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs)); |
| 1537 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1538 | } else { |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1539 | BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1540 | BiarchTripleAliases.append(begin(X86Triples), end(X86Triples)); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 1541 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1542 | break; |
| 1543 | case llvm::Triple::x86: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1544 | LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); |
| 1545 | TripleAliases.append(begin(X86Triples), end(X86Triples)); |
| 1546 | BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); |
| 1547 | BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1548 | break; |
| 1549 | case llvm::Triple::mips: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1550 | LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1551 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1552 | BiarchLibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1553 | BiarchTripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1554 | break; |
| 1555 | case llvm::Triple::mipsel: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1556 | LibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1557 | TripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1558 | TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
| 1559 | BiarchLibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1560 | BiarchTripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1561 | break; |
| 1562 | case llvm::Triple::mips64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1563 | LibDirs.append(begin(MIPS64LibDirs), end(MIPS64LibDirs)); |
| 1564 | TripleAliases.append(begin(MIPS64Triples), end(MIPS64Triples)); |
| 1565 | BiarchLibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); |
| 1566 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
Simon Atanasyan | 9bb634d | 2012-04-26 19:57:02 +0000 | [diff] [blame] | 1567 | break; |
| 1568 | case llvm::Triple::mips64el: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1569 | LibDirs.append(begin(MIPS64ELLibDirs), end(MIPS64ELLibDirs)); |
| 1570 | TripleAliases.append(begin(MIPS64ELTriples), end(MIPS64ELTriples)); |
| 1571 | BiarchLibDirs.append(begin(MIPSELLibDirs), end(MIPSELLibDirs)); |
| 1572 | BiarchTripleAliases.append(begin(MIPSELTriples), end(MIPSELTriples)); |
| 1573 | BiarchTripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1574 | break; |
| 1575 | case llvm::Triple::ppc: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1576 | LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1577 | TripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
| 1578 | BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1579 | BiarchTripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1580 | break; |
| 1581 | case llvm::Triple::ppc64: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1582 | LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); |
| 1583 | TripleAliases.append(begin(PPC64Triples), end(PPC64Triples)); |
| 1584 | BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); |
| 1585 | BiarchTripleAliases.append(begin(PPCTriples), end(PPCTriples)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1586 | break; |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1587 | case llvm::Triple::ppc64le: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1588 | LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); |
| 1589 | TripleAliases.append(begin(PPC64LETriples), end(PPC64LETriples)); |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1590 | break; |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1591 | case llvm::Triple::sparc: |
Douglas Katzman | b76a3df | 2015-09-02 13:33:42 +0000 | [diff] [blame] | 1592 | case llvm::Triple::sparcel: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1593 | LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1594 | TripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
| 1595 | BiarchLibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1596 | BiarchTripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1597 | break; |
| 1598 | case llvm::Triple::sparcv9: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1599 | LibDirs.append(begin(SPARCv9LibDirs), end(SPARCv9LibDirs)); |
| 1600 | TripleAliases.append(begin(SPARCv9Triples), end(SPARCv9Triples)); |
| 1601 | BiarchLibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs)); |
| 1602 | BiarchTripleAliases.append(begin(SPARCv8Triples), end(SPARCv8Triples)); |
Jakob Stoklund Olesen | b3f938e | 2014-01-10 06:53:02 +0000 | [diff] [blame] | 1603 | break; |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1604 | case llvm::Triple::systemz: |
Benjamin Kramer | 6ec434e | 2014-10-18 10:43:51 +0000 | [diff] [blame] | 1605 | LibDirs.append(begin(SystemZLibDirs), end(SystemZLibDirs)); |
| 1606 | TripleAliases.append(begin(SystemZTriples), end(SystemZTriples)); |
Ulrich Weigand | 4744507 | 2013-05-06 16:26:41 +0000 | [diff] [blame] | 1607 | break; |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1608 | default: |
| 1609 | // By default, just rely on the standard lib directories and the original |
| 1610 | // triple. |
| 1611 | break; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1612 | } |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 1613 | |
| 1614 | // Always append the drivers target triple to the end, in case it doesn't |
| 1615 | // match any of our aliases. |
| 1616 | TripleAliases.push_back(TargetTriple.str()); |
| 1617 | |
| 1618 | // Also include the multiarch variant if it's different. |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 1619 | if (TargetTriple.str() != BiarchTriple.str()) |
| 1620 | BiarchTripleAliases.push_back(BiarchTriple.str()); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1623 | // \brief -- try common CUDA installation paths looking for files we need for |
| 1624 | // CUDA compilation. |
| 1625 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1626 | void Generic_GCC::CudaInstallationDetector::init( |
| 1627 | const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args) { |
NAKAMURA Takumi | 0c8decd | 2015-09-24 03:15:44 +0000 | [diff] [blame] | 1628 | SmallVector<std::string, 4> CudaPathCandidates; |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1629 | |
| 1630 | if (Args.hasArg(options::OPT_cuda_path_EQ)) |
| 1631 | CudaPathCandidates.push_back( |
| 1632 | Args.getLastArgValue(options::OPT_cuda_path_EQ)); |
| 1633 | else { |
| 1634 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda"); |
| 1635 | CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0"); |
| 1636 | } |
| 1637 | |
Benjamin Kramer | e8b7641 | 2015-09-24 14:48:37 +0000 | [diff] [blame] | 1638 | for (const auto &CudaPath : CudaPathCandidates) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1639 | if (CudaPath.empty() || !D.getVFS().exists(CudaPath)) |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1640 | continue; |
| 1641 | |
| 1642 | CudaInstallPath = CudaPath; |
| 1643 | CudaIncludePath = CudaInstallPath + "/include"; |
| 1644 | CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice"; |
| 1645 | CudaLibPath = |
| 1646 | CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib"); |
| 1647 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 1648 | if (!(D.getVFS().exists(CudaIncludePath) && |
| 1649 | D.getVFS().exists(CudaLibPath) && |
| 1650 | D.getVFS().exists(CudaLibDevicePath))) |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 1651 | continue; |
| 1652 | |
| 1653 | IsValid = true; |
| 1654 | break; |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const { |
| 1659 | if (isValid()) |
| 1660 | OS << "Found CUDA installation: " << CudaInstallPath << "\n"; |
| 1661 | } |
| 1662 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1663 | namespace { |
| 1664 | // 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] | 1665 | class FilterNonExistent { |
| 1666 | StringRef Base; |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1667 | vfs::FileSystem &VFS; |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1668 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1669 | public: |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1670 | FilterNonExistent(StringRef Base, vfs::FileSystem &VFS) |
| 1671 | : Base(Base), VFS(VFS) {} |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 1672 | bool operator()(const Multilib &M) { |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1673 | return !VFS.exists(Base + M.gccSuffix() + "/crtbegin.o"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1674 | } |
| 1675 | }; |
| 1676 | } // end anonymous namespace |
| 1677 | |
| 1678 | static void addMultilibFlag(bool Enabled, const char *const Flag, |
| 1679 | std::vector<std::string> &Flags) { |
| 1680 | if (Enabled) |
| 1681 | Flags.push_back(std::string("+") + Flag); |
| 1682 | else |
| 1683 | Flags.push_back(std::string("-") + Flag); |
| 1684 | } |
| 1685 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1686 | static bool isMipsArch(llvm::Triple::ArchType Arch) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1687 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel || |
| 1688 | Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1689 | } |
| 1690 | |
| 1691 | static bool isMips32(llvm::Triple::ArchType Arch) { |
| 1692 | return Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel; |
| 1693 | } |
| 1694 | |
| 1695 | static bool isMips64(llvm::Triple::ArchType Arch) { |
| 1696 | return Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el; |
| 1697 | } |
| 1698 | |
| 1699 | static bool isMipsEL(llvm::Triple::ArchType Arch) { |
| 1700 | return Arch == llvm::Triple::mipsel || Arch == llvm::Triple::mips64el; |
| 1701 | } |
| 1702 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1703 | static bool isMips16(const ArgList &Args) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1704 | Arg *A = Args.getLastArg(options::OPT_mips16, options::OPT_mno_mips16); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1705 | return A && A->getOption().matches(options::OPT_mips16); |
| 1706 | } |
| 1707 | |
| 1708 | static bool isMicroMips(const ArgList &Args) { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1709 | Arg *A = Args.getLastArg(options::OPT_mmicromips, options::OPT_mno_micromips); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 1710 | return A && A->getOption().matches(options::OPT_mmicromips); |
| 1711 | } |
| 1712 | |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1713 | namespace { |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1714 | struct DetectedMultilibs { |
| 1715 | /// The set of multilibs that the detected installation supports. |
| 1716 | MultilibSet Multilibs; |
| 1717 | |
| 1718 | /// The primary multilib appropriate for the given flags. |
| 1719 | Multilib SelectedMultilib; |
| 1720 | |
| 1721 | /// On Biarch systems, this corresponds to the default multilib when |
| 1722 | /// targeting the non-default multilib. Otherwise, it is empty. |
| 1723 | llvm::Optional<Multilib> BiarchSibling; |
| 1724 | }; |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 1725 | } // end anonymous namespace |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1726 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1727 | static Multilib makeMultilib(StringRef commonSuffix) { |
| 1728 | return Multilib(commonSuffix, commonSuffix, commonSuffix); |
| 1729 | } |
| 1730 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1731 | static bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, |
| 1732 | StringRef Path, const ArgList &Args, |
| 1733 | DetectedMultilibs &Result) { |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 1734 | // Some MIPS toolchains put libraries and object files compiled |
| 1735 | // using different options in to the sub-directoris which names |
| 1736 | // reflects the flags used for compilation. For example sysroot |
| 1737 | // directory might looks like the following examples: |
| 1738 | // |
| 1739 | // /usr |
| 1740 | // /lib <= crt*.o files compiled with '-mips32' |
| 1741 | // /mips16 |
| 1742 | // /usr |
| 1743 | // /lib <= crt*.o files compiled with '-mips16' |
| 1744 | // /el |
| 1745 | // /usr |
| 1746 | // /lib <= crt*.o files compiled with '-mips16 -EL' |
| 1747 | // |
| 1748 | // or |
| 1749 | // |
| 1750 | // /usr |
| 1751 | // /lib <= crt*.o files compiled with '-mips32r2' |
| 1752 | // /mips16 |
| 1753 | // /usr |
| 1754 | // /lib <= crt*.o files compiled with '-mips32r2 -mips16' |
| 1755 | // /mips32 |
| 1756 | // /usr |
| 1757 | // /lib <= crt*.o files compiled with '-mips32' |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 1758 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 1759 | FilterNonExistent NonExistent(Path, D.getVFS()); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 1760 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1761 | // Check for FSF toolchain multilibs |
| 1762 | MultilibSet FSFMipsMultilibs; |
| 1763 | { |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1764 | auto MArchMips32 = makeMultilib("/mips32") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1765 | .flag("+m32") |
| 1766 | .flag("-m64") |
| 1767 | .flag("-mmicromips") |
| 1768 | .flag("+march=mips32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1769 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1770 | auto MArchMicroMips = makeMultilib("/micromips") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1771 | .flag("+m32") |
| 1772 | .flag("-m64") |
| 1773 | .flag("+mmicromips"); |
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 MArchMips64r2 = makeMultilib("/mips64r2") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1776 | .flag("-m32") |
| 1777 | .flag("+m64") |
| 1778 | .flag("+march=mips64r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1779 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1780 | auto MArchMips64 = makeMultilib("/mips64").flag("-m32").flag("+m64").flag( |
| 1781 | "-march=mips64r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1782 | |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1783 | auto MArchDefault = makeMultilib("") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1784 | .flag("+m32") |
| 1785 | .flag("-m64") |
| 1786 | .flag("-mmicromips") |
| 1787 | .flag("+march=mips32r2"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1788 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1789 | auto Mips16 = makeMultilib("/mips16").flag("+mips16"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1790 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1791 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1792 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1793 | auto MAbi64 = |
| 1794 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
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 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1797 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1798 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1799 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1800 | auto SoftFloat = makeMultilib("/sof").flag("+msoft-float"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1801 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1802 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1803 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1804 | FSFMipsMultilibs = |
| 1805 | MultilibSet() |
| 1806 | .Either(MArchMips32, MArchMicroMips, MArchMips64r2, MArchMips64, |
| 1807 | MArchDefault) |
| 1808 | .Maybe(UCLibc) |
| 1809 | .Maybe(Mips16) |
| 1810 | .FilterOut("/mips64/mips16") |
| 1811 | .FilterOut("/mips64r2/mips16") |
| 1812 | .FilterOut("/micromips/mips16") |
| 1813 | .Maybe(MAbi64) |
| 1814 | .FilterOut("/micromips/64") |
| 1815 | .FilterOut("/mips32/64") |
| 1816 | .FilterOut("^/64") |
| 1817 | .FilterOut("/mips16/64") |
| 1818 | .Either(BigEndian, LittleEndian) |
| 1819 | .Maybe(SoftFloat) |
| 1820 | .Maybe(Nan2008) |
| 1821 | .FilterOut(".*sof/nan2008") |
| 1822 | .FilterOut(NonExistent) |
| 1823 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1824 | StringRef TripleStr, const Multilib &M) { |
| 1825 | std::vector<std::string> Dirs; |
| 1826 | Dirs.push_back((InstallDir + "/include").str()); |
| 1827 | std::string SysRootInc = |
| 1828 | InstallDir.str() + "/../../../../sysroot"; |
| 1829 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| 1830 | Dirs.push_back(SysRootInc + "/uclibc/usr/include"); |
| 1831 | else |
| 1832 | Dirs.push_back(SysRootInc + "/usr/include"); |
| 1833 | return Dirs; |
| 1834 | }); |
Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1837 | // Check for Code Sourcery toolchain multilibs |
| 1838 | MultilibSet CSMipsMultilibs; |
| 1839 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1840 | auto MArchMips16 = makeMultilib("/mips16").flag("+m32").flag("+mips16"); |
Simon Atanasyan | 13e965a | 2013-11-26 11:57:14 +0000 | [diff] [blame] | 1841 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1842 | auto MArchMicroMips = |
| 1843 | makeMultilib("/micromips").flag("+m32").flag("+mmicromips"); |
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 MArchDefault = makeMultilib("").flag("-mips16").flag("-mmicromips"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1846 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1847 | auto UCLibc = makeMultilib("/uclibc").flag("+muclibc"); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1848 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1849 | auto SoftFloat = makeMultilib("/soft-float").flag("+msoft-float"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1850 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1851 | auto Nan2008 = makeMultilib("/nan2008").flag("+mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1852 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1853 | auto DefaultFloat = |
| 1854 | makeMultilib("").flag("-msoft-float").flag("-mnan=2008"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1855 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1856 | auto BigEndian = makeMultilib("").flag("+EB").flag("-EL"); |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1857 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1858 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1859 | |
| 1860 | // Note that this one's osSuffix is "" |
Simon Atanasyan | 1b0542e | 2014-07-30 09:15:10 +0000 | [diff] [blame] | 1861 | auto MAbi64 = makeMultilib("") |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1862 | .gccSuffix("/64") |
| 1863 | .includeSuffix("/64") |
| 1864 | .flag("+mabi=n64") |
| 1865 | .flag("-mabi=n32") |
| 1866 | .flag("-m32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1867 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1868 | CSMipsMultilibs = |
| 1869 | MultilibSet() |
| 1870 | .Either(MArchMips16, MArchMicroMips, MArchDefault) |
| 1871 | .Maybe(UCLibc) |
| 1872 | .Either(SoftFloat, Nan2008, DefaultFloat) |
| 1873 | .FilterOut("/micromips/nan2008") |
| 1874 | .FilterOut("/mips16/nan2008") |
| 1875 | .Either(BigEndian, LittleEndian) |
| 1876 | .Maybe(MAbi64) |
| 1877 | .FilterOut("/mips16.*/64") |
| 1878 | .FilterOut("/micromips.*/64") |
| 1879 | .FilterOut(NonExistent) |
| 1880 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1881 | StringRef TripleStr, const Multilib &M) { |
| 1882 | std::vector<std::string> Dirs; |
| 1883 | Dirs.push_back((InstallDir + "/include").str()); |
| 1884 | std::string SysRootInc = |
| 1885 | InstallDir.str() + "/../../../../" + TripleStr.str(); |
| 1886 | if (StringRef(M.includeSuffix()).startswith("/uclibc")) |
| 1887 | Dirs.push_back(SysRootInc + "/libc/uclibc/usr/include"); |
| 1888 | else |
| 1889 | Dirs.push_back(SysRootInc + "/libc/usr/include"); |
| 1890 | return Dirs; |
| 1891 | }); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1894 | MultilibSet AndroidMipsMultilibs = |
| 1895 | MultilibSet() |
| 1896 | .Maybe(Multilib("/mips-r2").flag("+march=mips32r2")) |
| 1897 | .Maybe(Multilib("/mips-r6").flag("+march=mips32r6")) |
| 1898 | .FilterOut(NonExistent); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1899 | |
| 1900 | MultilibSet DebianMipsMultilibs; |
| 1901 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1902 | Multilib MAbiN32 = |
| 1903 | Multilib().gccSuffix("/n32").includeSuffix("/n32").flag("+mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1904 | |
| 1905 | Multilib M64 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1906 | .gccSuffix("/64") |
| 1907 | .includeSuffix("/64") |
| 1908 | .flag("+m64") |
| 1909 | .flag("-m32") |
| 1910 | .flag("-mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1911 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1912 | Multilib M32 = Multilib().flag("-m64").flag("+m32").flag("-mabi=n32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1913 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1914 | DebianMipsMultilibs = |
| 1915 | MultilibSet().Either(M32, M64, MAbiN32).FilterOut(NonExistent); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1918 | MultilibSet ImgMultilibs; |
| 1919 | { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1920 | auto Mips64r6 = makeMultilib("/mips64r6").flag("+m64").flag("-m32"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1921 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1922 | auto LittleEndian = makeMultilib("/el").flag("+EL").flag("-EB"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1923 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1924 | auto MAbi64 = |
| 1925 | makeMultilib("/64").flag("+mabi=n64").flag("-mabi=n32").flag("-m32"); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1926 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1927 | ImgMultilibs = |
| 1928 | MultilibSet() |
| 1929 | .Maybe(Mips64r6) |
| 1930 | .Maybe(MAbi64) |
| 1931 | .Maybe(LittleEndian) |
| 1932 | .FilterOut(NonExistent) |
| 1933 | .setIncludeDirsCallback([](StringRef InstallDir, |
| 1934 | StringRef TripleStr, const Multilib &M) { |
| 1935 | std::vector<std::string> Dirs; |
| 1936 | Dirs.push_back((InstallDir + "/include").str()); |
| 1937 | Dirs.push_back( |
| 1938 | (InstallDir + "/../../../../sysroot/usr/include").str()); |
| 1939 | return Dirs; |
| 1940 | }); |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 1943 | StringRef CPUName; |
| 1944 | StringRef ABIName; |
| 1945 | tools::mips::getMipsCPUAndABI(Args, TargetTriple, CPUName, ABIName); |
| 1946 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1947 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
| 1948 | |
| 1949 | Multilib::flags_list Flags; |
| 1950 | addMultilibFlag(isMips32(TargetArch), "m32", Flags); |
| 1951 | addMultilibFlag(isMips64(TargetArch), "m64", Flags); |
| 1952 | addMultilibFlag(isMips16(Args), "mips16", Flags); |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 1953 | addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 1954 | addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || |
Daniel Sanders | ff95258 | 2015-10-05 12:24:30 +0000 | [diff] [blame] | 1955 | CPUName == "mips32r5" || CPUName == "p5600", |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 1956 | "march=mips32r2", Flags); |
Simon Atanasyan | 3f02403 | 2015-02-25 07:31:12 +0000 | [diff] [blame] | 1957 | addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 1958 | addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); |
Simon Atanasyan | 59b25cb | 2015-02-26 04:45:57 +0000 | [diff] [blame] | 1959 | addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || |
| 1960 | CPUName == "mips64r5" || CPUName == "octeon", |
Simon Atanasyan | 9988e3a | 2014-07-16 17:34:54 +0000 | [diff] [blame] | 1961 | "march=mips64r2", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1962 | addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); |
Simon Atanasyan | d95c67d | 2014-08-13 14:34:14 +0000 | [diff] [blame] | 1963 | addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); |
Simon Atanasyan | ab6db9f | 2014-07-16 12:24:48 +0000 | [diff] [blame] | 1964 | addMultilibFlag(tools::mips::isNaN2008(Args, TargetTriple), "mnan=2008", |
| 1965 | Flags); |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 1966 | addMultilibFlag(ABIName == "n32", "mabi=n32", Flags); |
| 1967 | addMultilibFlag(ABIName == "n64", "mabi=n64", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1968 | addMultilibFlag(isSoftFloatABI(Args), "msoft-float", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1969 | addMultilibFlag(!isSoftFloatABI(Args), "mhard-float", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1970 | addMultilibFlag(isMipsEL(TargetArch), "EL", Flags); |
Simon Atanasyan | 7018e1d | 2014-07-16 12:29:22 +0000 | [diff] [blame] | 1971 | addMultilibFlag(!isMipsEL(TargetArch), "EB", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 1972 | |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 1973 | if (TargetTriple.isAndroid()) { |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1974 | // Select Android toolchain. It's the only choice in that case. |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 1975 | if (AndroidMipsMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 1976 | Result.Multilibs = AndroidMipsMultilibs; |
| 1977 | return true; |
| 1978 | } |
| 1979 | return false; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
Daniel Sanders | 2bf1366 | 2014-07-10 14:40:57 +0000 | [diff] [blame] | 1982 | if (TargetTriple.getVendor() == llvm::Triple::ImaginationTechnologies && |
| 1983 | TargetTriple.getOS() == llvm::Triple::Linux && |
| 1984 | TargetTriple.getEnvironment() == llvm::Triple::GNU) { |
| 1985 | // Select mips-img-linux-gnu toolchain. |
| 1986 | if (ImgMultilibs.select(Flags, Result.SelectedMultilib)) { |
| 1987 | Result.Multilibs = ImgMultilibs; |
| 1988 | return true; |
| 1989 | } |
| 1990 | return false; |
| 1991 | } |
| 1992 | |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1993 | // Sort candidates. Toolchain that best meets the directories goes first. |
| 1994 | // Then select the first toolchains matches command line flags. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 1995 | MultilibSet *candidates[] = {&DebianMipsMultilibs, &FSFMipsMultilibs, |
| 1996 | &CSMipsMultilibs}; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 1997 | std::sort( |
| 1998 | std::begin(candidates), std::end(candidates), |
| 1999 | [](MultilibSet *a, MultilibSet *b) { return a->size() > b->size(); }); |
| 2000 | for (const auto &candidate : candidates) { |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2001 | if (candidate->select(Flags, Result.SelectedMultilib)) { |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2002 | if (candidate == &DebianMipsMultilibs) |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2003 | Result.BiarchSibling = Multilib(); |
| 2004 | Result.Multilibs = *candidate; |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2005 | return true; |
| 2006 | } |
| 2007 | } |
| 2008 | |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 2009 | { |
| 2010 | // Fallback to the regular toolchain-tree structure. |
| 2011 | Multilib Default; |
| 2012 | Result.Multilibs.push_back(Default); |
| 2013 | Result.Multilibs.FilterOut(NonExistent); |
| 2014 | |
| 2015 | if (Result.Multilibs.select(Flags, Result.SelectedMultilib)) { |
| 2016 | Result.BiarchSibling = Multilib(); |
| 2017 | return true; |
| 2018 | } |
| 2019 | } |
| 2020 | |
Simon Atanasyan | 738f85a | 2014-03-04 18:37:28 +0000 | [diff] [blame] | 2021 | return false; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2024 | static bool findBiarchMultilibs(const Driver &D, |
| 2025 | const llvm::Triple &TargetTriple, |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2026 | StringRef Path, const ArgList &Args, |
| 2027 | bool NeedsBiarchSuffix, |
| 2028 | DetectedMultilibs &Result) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2029 | // Some versions of SUSE and Fedora on ppc64 put 32-bit libs |
| 2030 | // in what would normally be GCCInstallPath and put the 64-bit |
| 2031 | // libs in a subdirectory named 64. The simple logic we follow is that |
| 2032 | // *if* there is a subdirectory of the right name with crtbegin.o in it, |
| 2033 | // we use that. If not, and if not a biarch triple alias, we look for |
| 2034 | // crtbegin.o without the subdirectory. |
| 2035 | |
| 2036 | Multilib Default; |
| 2037 | Multilib Alt64 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2038 | .gccSuffix("/64") |
| 2039 | .includeSuffix("/64") |
| 2040 | .flag("-m32") |
| 2041 | .flag("+m64") |
| 2042 | .flag("-mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2043 | Multilib Alt32 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2044 | .gccSuffix("/32") |
| 2045 | .includeSuffix("/32") |
| 2046 | .flag("+m32") |
| 2047 | .flag("-m64") |
| 2048 | .flag("-mx32"); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2049 | Multilib Altx32 = Multilib() |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2050 | .gccSuffix("/x32") |
| 2051 | .includeSuffix("/x32") |
| 2052 | .flag("-m32") |
| 2053 | .flag("-m64") |
| 2054 | .flag("+mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2055 | |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2056 | FilterNonExistent NonExistent(Path, D.getVFS()); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2057 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2058 | // Determine default multilib from: 32, 64, x32 |
| 2059 | // Also handle cases such as 64 on 32, 32 on 64, etc. |
| 2060 | enum { UNKNOWN, WANT32, WANT64, WANTX32 } Want = UNKNOWN; |
David Blaikie | 40f842d | 2014-07-10 18:46:15 +0000 | [diff] [blame] | 2061 | const bool IsX32 = TargetTriple.getEnvironment() == llvm::Triple::GNUX32; |
Alp Toker | f45fa3d | 2014-02-25 04:21:44 +0000 | [diff] [blame] | 2062 | if (TargetTriple.isArch32Bit() && !NonExistent(Alt32)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2063 | Want = WANT64; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2064 | else if (TargetTriple.isArch64Bit() && IsX32 && !NonExistent(Altx32)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2065 | Want = WANT64; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2066 | else if (TargetTriple.isArch64Bit() && !IsX32 && !NonExistent(Alt64)) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2067 | Want = WANT32; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2068 | else { |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2069 | if (TargetTriple.isArch32Bit()) |
| 2070 | Want = NeedsBiarchSuffix ? WANT64 : WANT32; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2071 | else if (IsX32) |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2072 | Want = NeedsBiarchSuffix ? WANT64 : WANTX32; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2073 | else |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2074 | Want = NeedsBiarchSuffix ? WANT32 : WANT64; |
Jonathan Roelofs | 0e7ec60 | 2014-02-12 01:29:25 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2077 | if (Want == WANT32) |
| 2078 | Default.flag("+m32").flag("-m64").flag("-mx32"); |
| 2079 | else if (Want == WANT64) |
| 2080 | Default.flag("-m32").flag("+m64").flag("-mx32"); |
| 2081 | else if (Want == WANTX32) |
| 2082 | Default.flag("-m32").flag("-m64").flag("+mx32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2083 | else |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2084 | return false; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2085 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2086 | Result.Multilibs.push_back(Default); |
| 2087 | Result.Multilibs.push_back(Alt64); |
| 2088 | Result.Multilibs.push_back(Alt32); |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2089 | Result.Multilibs.push_back(Altx32); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2090 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2091 | Result.Multilibs.FilterOut(NonExistent); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2092 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2093 | Multilib::flags_list Flags; |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2094 | addMultilibFlag(TargetTriple.isArch64Bit() && !IsX32, "m64", Flags); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2095 | addMultilibFlag(TargetTriple.isArch32Bit(), "m32", Flags); |
Zinovy Nis | 6e3c630 | 2014-07-10 15:42:35 +0000 | [diff] [blame] | 2096 | addMultilibFlag(TargetTriple.isArch64Bit() && IsX32, "mx32", Flags); |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2097 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2098 | if (!Result.Multilibs.select(Flags, Result.SelectedMultilib)) |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2099 | return false; |
Jonathan Roelofs | 3fa96d8 | 2014-02-12 01:36:51 +0000 | [diff] [blame] | 2100 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2101 | if (Result.SelectedMultilib == Alt64 || Result.SelectedMultilib == Alt32 || |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 2102 | Result.SelectedMultilib == Altx32) |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2103 | Result.BiarchSibling = Default; |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2104 | |
| 2105 | return true; |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 2106 | } |
| 2107 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2108 | void Generic_GCC::GCCInstallationDetector::scanLibDirForGCCTripleSolaris( |
| 2109 | const llvm::Triple &TargetArch, const llvm::opt::ArgList &Args, |
| 2110 | const std::string &LibDir, StringRef CandidateTriple, |
| 2111 | bool NeedsBiarchSuffix) { |
| 2112 | // Solaris is a special case. The GCC installation is under |
| 2113 | // /usr/gcc/<major>.<minor>/lib/gcc/<triple>/<major>.<minor>.<patch>/, so we |
| 2114 | // need to iterate twice. |
| 2115 | std::error_code EC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2116 | for (vfs::directory_iterator LI = D.getVFS().dir_begin(LibDir, EC), LE; |
| 2117 | !EC && LI != LE; LI = LI.increment(EC)) { |
| 2118 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2119 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
| 2120 | |
| 2121 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2122 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2123 | continue; // Saw this path before; no need to look at it again. |
| 2124 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
| 2125 | continue; |
| 2126 | if (CandidateVersion <= Version) |
| 2127 | continue; |
| 2128 | |
| 2129 | GCCInstallPath = |
| 2130 | LibDir + "/" + VersionText.str() + "/lib/gcc/" + CandidateTriple.str(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2131 | if (!D.getVFS().exists(GCCInstallPath)) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2132 | continue; |
| 2133 | |
| 2134 | // If we make it here there has to be at least one GCC version, let's just |
| 2135 | // use the latest one. |
| 2136 | std::error_code EEC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2137 | for (vfs::directory_iterator |
| 2138 | LLI = D.getVFS().dir_begin(GCCInstallPath, EEC), |
| 2139 | LLE; |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2140 | !EEC && LLI != LLE; LLI = LLI.increment(EEC)) { |
| 2141 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2142 | StringRef SubVersionText = llvm::sys::path::filename(LLI->getName()); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2143 | GCCVersion CandidateSubVersion = GCCVersion::Parse(SubVersionText); |
| 2144 | |
| 2145 | if (CandidateSubVersion > Version) |
| 2146 | Version = CandidateSubVersion; |
| 2147 | } |
| 2148 | |
| 2149 | GCCTriple.setTriple(CandidateTriple); |
| 2150 | |
| 2151 | GCCInstallPath += "/" + Version.Text; |
| 2152 | GCCParentLibPath = GCCInstallPath + "/../../../../"; |
| 2153 | |
| 2154 | IsValid = true; |
| 2155 | } |
| 2156 | } |
| 2157 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2158 | void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2159 | const llvm::Triple &TargetTriple, const ArgList &Args, |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 2160 | const std::string &LibDir, StringRef CandidateTriple, |
| 2161 | bool NeedsBiarchSuffix) { |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2162 | llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2163 | // There are various different suffixes involving the triple we |
| 2164 | // 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] | 2165 | // up to the lib directory. Specifically, the number of "up" steps |
| 2166 | // in the second half of each row is 1 + the number of path separators |
| 2167 | // in the first half. |
| 2168 | const std::string LibAndInstallSuffixes[][2] = { |
| 2169 | {"/gcc/" + CandidateTriple.str(), "/../../.."}, |
| 2170 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2171 | // Debian puts cross-compilers in gcc-cross |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2172 | {"/gcc-cross/" + CandidateTriple.str(), "/../../.."}, |
| 2173 | |
| 2174 | {"/" + CandidateTriple.str() + "/gcc/" + CandidateTriple.str(), |
| 2175 | "/../../../.."}, |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2176 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2177 | // The Freescale PPC SDK has the gcc libraries in |
| 2178 | // <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] | 2179 | {"/" + CandidateTriple.str(), "/../.."}, |
Hal Finkel | f358791 | 2012-09-18 22:25:07 +0000 | [diff] [blame] | 2180 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2181 | // Ubuntu has a strange mis-matched pair of triples that this happens to |
| 2182 | // match. |
| 2183 | // FIXME: It may be worthwhile to generalize this and look for a second |
| 2184 | // triple. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2185 | {"/i386-linux-gnu/gcc/" + CandidateTriple.str(), "/../../../.."}}; |
| 2186 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 2187 | if (TargetTriple.getOS() == llvm::Triple::Solaris) { |
| 2188 | scanLibDirForGCCTripleSolaris(TargetTriple, Args, LibDir, CandidateTriple, |
| 2189 | NeedsBiarchSuffix); |
| 2190 | return; |
| 2191 | } |
| 2192 | |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2193 | // Only look at the final, weird Ubuntu suffix for i386-linux-gnu. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2194 | const unsigned NumLibSuffixes = (llvm::array_lengthof(LibAndInstallSuffixes) - |
| 2195 | (TargetArch != llvm::Triple::x86)); |
Chandler Carruth | 866faab | 2012-01-25 07:21:38 +0000 | [diff] [blame] | 2196 | for (unsigned i = 0; i < NumLibSuffixes; ++i) { |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2197 | StringRef LibSuffix = LibAndInstallSuffixes[i][0]; |
Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2198 | std::error_code EC; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2199 | for (vfs::directory_iterator |
| 2200 | LI = D.getVFS().dir_begin(LibDir + LibSuffix, EC), |
| 2201 | LE; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2202 | !EC && LI != LE; LI = LI.increment(EC)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2203 | StringRef VersionText = llvm::sys::path::filename(LI->getName()); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2204 | GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); |
Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2205 | if (CandidateVersion.Major != -1) // Filter obviously bad entries. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2206 | if (!CandidateGCCInstallPaths.insert(LI->getName()).second) |
Benjamin Kramer | a97e4d1 | 2013-08-14 18:38:51 +0000 | [diff] [blame] | 2207 | continue; // Saw this path before; no need to look at it again. |
Benjamin Kramer | 604e848 | 2013-08-09 17:17:48 +0000 | [diff] [blame] | 2208 | if (CandidateVersion.isOlderThan(4, 1, 1)) |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2209 | continue; |
| 2210 | if (CandidateVersion <= Version) |
| 2211 | continue; |
Hal Finkel | 221e11e | 2011-12-08 05:50:03 +0000 | [diff] [blame] | 2212 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2213 | DetectedMultilibs Detected; |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2214 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2215 | // Debian mips multilibs behave more like the rest of the biarch ones, |
| 2216 | // so handle them there |
| 2217 | if (isMipsArch(TargetArch)) { |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2218 | if (!findMIPSMultilibs(D, TargetTriple, LI->getName(), Args, Detected)) |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 2219 | continue; |
Benjamin Kramer | c5862f0 | 2015-10-09 13:03:18 +0000 | [diff] [blame] | 2220 | } else if (!findBiarchMultilibs(D, TargetTriple, LI->getName(), Args, |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2221 | NeedsBiarchSuffix, Detected)) { |
Simon Atanasyan | ee1accf | 2013-09-28 13:45:11 +0000 | [diff] [blame] | 2222 | continue; |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2223 | } |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2224 | |
Simon Atanasyan | 60280b4 | 2014-05-12 07:37:51 +0000 | [diff] [blame] | 2225 | Multilibs = Detected.Multilibs; |
| 2226 | SelectedMultilib = Detected.SelectedMultilib; |
| 2227 | BiarchSibling = Detected.BiarchSibling; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2228 | Version = CandidateVersion; |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 2229 | GCCTriple.setTriple(CandidateTriple); |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2230 | // FIXME: We hack together the directory name here instead of |
| 2231 | // using LI to ensure stable path separators across Windows and |
| 2232 | // Linux. |
Douglas Katzman | cb07d15 | 2015-08-14 15:52:12 +0000 | [diff] [blame] | 2233 | GCCInstallPath = |
| 2234 | LibDir + LibAndInstallSuffixes[i][0] + "/" + VersionText.str(); |
| 2235 | GCCParentLibPath = GCCInstallPath + LibAndInstallSuffixes[i][1]; |
Chandler Carruth | 4c90fba | 2011-11-06 23:39:34 +0000 | [diff] [blame] | 2236 | IsValid = true; |
| 2237 | } |
| 2238 | } |
| 2239 | } |
| 2240 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2241 | Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 2242 | const ArgList &Args) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2243 | : ToolChain(D, Triple, Args), GCCInstallation(D), CudaInstallation(D) { |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2244 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 2245 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 2246 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2249 | Generic_GCC::~Generic_GCC() {} |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2250 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2251 | Tool *Generic_GCC::getTool(Action::ActionClass AC) const { |
Rafael Espindola | 260e28d | 2013-03-18 20:48:54 +0000 | [diff] [blame] | 2252 | switch (AC) { |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2253 | case Action::PreprocessJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2254 | if (!Preprocess) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2255 | Preprocess.reset(new tools::gcc::Preprocessor(*this)); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2256 | return Preprocess.get(); |
Rafael Espindola | c8e3a01 | 2013-03-18 18:50:01 +0000 | [diff] [blame] | 2257 | case Action::CompileJobClass: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2258 | if (!Compile) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2259 | Compile.reset(new tools::gcc::Compiler(*this)); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2260 | return Compile.get(); |
Rafael Espindola | d15a891 | 2013-03-19 00:36:57 +0000 | [diff] [blame] | 2261 | default: |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2262 | return ToolChain::getTool(AC); |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2263 | } |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2266 | Tool *Generic_GCC::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2267 | return new tools::gnutools::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2268 | } |
| 2269 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2270 | Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); } |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2271 | |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2272 | void Generic_GCC::printVerboseInfo(raw_ostream &OS) const { |
| 2273 | // Print the information about how we detected the GCC installation. |
| 2274 | GCCInstallation.print(OS); |
Artem Belevich | 98607b6 | 2015-09-23 21:49:39 +0000 | [diff] [blame] | 2275 | CudaInstallation.print(OS); |
Chandler Carruth | 0ae39aa | 2013-07-30 17:57:09 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2278 | bool Generic_GCC::IsUnwindTablesDefault() const { |
Rafael Espindola | 08f1ebb | 2012-09-22 15:04:11 +0000 | [diff] [blame] | 2279 | return getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2282 | bool Generic_GCC::isPICDefault() const { |
| 2283 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2284 | } |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 2285 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2286 | bool Generic_GCC::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2287 | |
David Majnemer | 17f448b | 2015-06-28 04:23:33 +0000 | [diff] [blame] | 2288 | bool Generic_GCC::isPICDefaultForced() const { |
| 2289 | return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows(); |
| 2290 | } |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2291 | |
Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2292 | bool Generic_GCC::IsIntegratedAssemblerDefault() const { |
Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2293 | switch (getTriple().getArch()) { |
| 2294 | case llvm::Triple::x86: |
| 2295 | case llvm::Triple::x86_64: |
| 2296 | case llvm::Triple::aarch64: |
| 2297 | case llvm::Triple::aarch64_be: |
| 2298 | case llvm::Triple::arm: |
| 2299 | case llvm::Triple::armeb: |
Alexei Starovoitov | f657ca8 | 2015-06-10 22:59:13 +0000 | [diff] [blame] | 2300 | case llvm::Triple::bpfel: |
| 2301 | case llvm::Triple::bpfeb: |
Douglas Katzman | 7ae27b8 | 2015-06-03 19:40:30 +0000 | [diff] [blame] | 2302 | case llvm::Triple::thumb: |
| 2303 | case llvm::Triple::thumbeb: |
| 2304 | case llvm::Triple::ppc: |
| 2305 | case llvm::Triple::ppc64: |
| 2306 | case llvm::Triple::ppc64le: |
| 2307 | case llvm::Triple::sparc: |
| 2308 | case llvm::Triple::sparcel: |
| 2309 | case llvm::Triple::sparcv9: |
| 2310 | case llvm::Triple::systemz: |
| 2311 | return true; |
| 2312 | default: |
| 2313 | return false; |
| 2314 | } |
Rafael Espindola | a8b3b68 | 2013-11-25 18:50:53 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 2317 | /// \brief Helper to add the variant paths of a libstdc++ installation. |
| 2318 | bool Generic_GCC::addLibStdCXXIncludePaths( |
| 2319 | Twine Base, Twine Suffix, StringRef GCCTriple, StringRef GCCMultiarchTriple, |
| 2320 | StringRef TargetMultiarchTriple, Twine IncludeSuffix, |
| 2321 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
| 2322 | if (!getVFS().exists(Base + Suffix)) |
| 2323 | return false; |
| 2324 | |
| 2325 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix); |
| 2326 | |
| 2327 | // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If |
| 2328 | // that path exists or we have neither a GCC nor target multiarch triple, use |
| 2329 | // this vanilla search path. |
| 2330 | if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) || |
| 2331 | getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) { |
| 2332 | addSystemInclude(DriverArgs, CC1Args, |
| 2333 | Base + Suffix + "/" + GCCTriple + IncludeSuffix); |
| 2334 | } else { |
| 2335 | // Otherwise try to use multiarch naming schemes which have normalized the |
| 2336 | // triples and put the triple before the suffix. |
| 2337 | // |
| 2338 | // GCC surprisingly uses *both* the GCC triple with a multilib suffix and |
| 2339 | // the target triple, so we support that here. |
| 2340 | addSystemInclude(DriverArgs, CC1Args, |
| 2341 | Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix); |
| 2342 | addSystemInclude(DriverArgs, CC1Args, |
| 2343 | Base + "/" + TargetMultiarchTriple + Suffix); |
| 2344 | } |
| 2345 | |
| 2346 | addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward"); |
| 2347 | return true; |
| 2348 | } |
| 2349 | |
| 2350 | |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2351 | void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, |
| 2352 | ArgStringList &CC1Args) const { |
| 2353 | const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2354 | bool UseInitArrayDefault = |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2355 | getTriple().getArch() == llvm::Triple::aarch64 || |
Christian Pirker | 9b019ae | 2014-02-25 13:51:00 +0000 | [diff] [blame] | 2356 | getTriple().getArch() == llvm::Triple::aarch64_be || |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2357 | (getTriple().getOS() == llvm::Triple::Linux && |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 2358 | (!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) || |
Vasileios Kalintiris | 71b0dfe | 2015-10-30 11:28:39 +0000 | [diff] [blame] | 2359 | getTriple().getOS() == llvm::Triple::NaCl; |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2360 | |
| 2361 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2362 | options::OPT_fno_use_init_array, UseInitArrayDefault)) |
Kristof Beyls | fb38729 | 2014-01-10 13:44:34 +0000 | [diff] [blame] | 2363 | CC1Args.push_back("-fuse-init-array"); |
| 2364 | } |
| 2365 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2366 | /// Hexagon Toolchain |
| 2367 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2368 | std::string HexagonToolChain::GetGnuDir(const std::string &InstalledDir, |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2369 | const ArgList &Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2370 | // Locate the rest of the toolchain ... |
Samuel Antao | c909c99 | 2014-11-07 17:48:03 +0000 | [diff] [blame] | 2371 | std::string GccToolchain = getGCCToolchainDir(Args); |
| 2372 | |
| 2373 | if (!GccToolchain.empty()) |
| 2374 | return GccToolchain; |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2375 | |
| 2376 | std::string InstallRelDir = InstalledDir + "/../../gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2377 | if (getVFS().exists(InstallRelDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2378 | return InstallRelDir; |
| 2379 | |
| 2380 | std::string PrefixRelDir = std::string(LLVM_PREFIX) + "/../gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2381 | if (getVFS().exists(PrefixRelDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2382 | return PrefixRelDir; |
| 2383 | |
| 2384 | return InstallRelDir; |
| 2385 | } |
| 2386 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2387 | const char *HexagonToolChain::GetSmallDataThreshold(const ArgList &Args) { |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2388 | Arg *A; |
| 2389 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2390 | A = Args.getLastArg(options::OPT_G, options::OPT_G_EQ, |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2391 | options::OPT_msmall_data_threshold_EQ); |
| 2392 | if (A) |
| 2393 | return A->getValue(); |
| 2394 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2395 | A = Args.getLastArg(options::OPT_shared, options::OPT_fpic, |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2396 | options::OPT_fPIC); |
| 2397 | if (A) |
| 2398 | return "0"; |
| 2399 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2400 | return nullptr; |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2403 | bool HexagonToolChain::UsesG0(const char *smallDataThreshold) { |
Ikhlas Ajbar | 522e619 | 2015-05-14 13:52:08 +0000 | [diff] [blame] | 2404 | return smallDataThreshold && smallDataThreshold[0] == '0'; |
| 2405 | } |
| 2406 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2407 | static void GetHexagonLibraryPaths(const HexagonToolChain &TC, |
| 2408 | const ArgList &Args, const std::string &Ver, |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2409 | const std::string &MarchString, |
| 2410 | const std::string &InstalledDir, |
| 2411 | ToolChain::path_list *LibPaths) { |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2412 | bool buildingLib = Args.hasArg(options::OPT_shared); |
| 2413 | |
| 2414 | //---------------------------------------------------------------------------- |
| 2415 | // -L Args |
| 2416 | //---------------------------------------------------------------------------- |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 2417 | for (Arg *A : Args.filtered(options::OPT_L)) |
| 2418 | for (const char *Value : A->getValues()) |
| 2419 | LibPaths->push_back(Value); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2420 | |
| 2421 | //---------------------------------------------------------------------------- |
| 2422 | // Other standard paths |
| 2423 | //---------------------------------------------------------------------------- |
| 2424 | const std::string MarchSuffix = "/" + MarchString; |
| 2425 | const std::string G0Suffix = "/G0"; |
| 2426 | const std::string MarchG0Suffix = MarchSuffix + G0Suffix; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2427 | const std::string RootDir = TC.GetGnuDir(InstalledDir, Args) + "/"; |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2428 | |
| 2429 | // lib/gcc/hexagon/... |
| 2430 | std::string LibGCCHexagonDir = RootDir + "lib/gcc/hexagon/"; |
| 2431 | if (buildingLib) { |
| 2432 | LibPaths->push_back(LibGCCHexagonDir + Ver + MarchG0Suffix); |
| 2433 | LibPaths->push_back(LibGCCHexagonDir + Ver + G0Suffix); |
| 2434 | } |
| 2435 | LibPaths->push_back(LibGCCHexagonDir + Ver + MarchSuffix); |
| 2436 | LibPaths->push_back(LibGCCHexagonDir + Ver); |
| 2437 | |
| 2438 | // lib/gcc/... |
| 2439 | LibPaths->push_back(RootDir + "lib/gcc"); |
| 2440 | |
| 2441 | // hexagon/lib/... |
| 2442 | std::string HexagonLibDir = RootDir + "hexagon/lib"; |
| 2443 | if (buildingLib) { |
| 2444 | LibPaths->push_back(HexagonLibDir + MarchG0Suffix); |
| 2445 | LibPaths->push_back(HexagonLibDir + G0Suffix); |
| 2446 | } |
| 2447 | LibPaths->push_back(HexagonLibDir + MarchSuffix); |
| 2448 | LibPaths->push_back(HexagonLibDir); |
| 2449 | } |
| 2450 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2451 | HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2452 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2453 | : Linux(D, Triple, Args) { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2454 | const std::string InstalledDir(getDriver().getInstalledDir()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2455 | const std::string GnuDir = GetGnuDir(InstalledDir, Args); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2456 | |
| 2457 | // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to |
| 2458 | // program paths |
| 2459 | const std::string BinDir(GnuDir + "/bin"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2460 | if (D.getVFS().exists(BinDir)) |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2461 | getProgramPaths().push_back(BinDir); |
| 2462 | |
| 2463 | // Determine version of GCC libraries and headers to use. |
| 2464 | const std::string HexagonDir(GnuDir + "/lib/gcc/hexagon"); |
Rafael Espindola | c080917 | 2014-06-12 14:02:15 +0000 | [diff] [blame] | 2465 | std::error_code ec; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2466 | GCCVersion MaxVersion = GCCVersion::Parse("0.0.0"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2467 | for (vfs::directory_iterator di = D.getVFS().dir_begin(HexagonDir, ec), de; |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2468 | !ec && di != de; di = di.increment(ec)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2469 | GCCVersion cv = GCCVersion::Parse(llvm::sys::path::filename(di->getName())); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2470 | if (MaxVersion < cv) |
| 2471 | MaxVersion = cv; |
| 2472 | } |
| 2473 | GCCLibAndIncVersion = MaxVersion; |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2474 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2475 | ToolChain::path_list *LibPaths = &getFilePaths(); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2476 | |
| 2477 | // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets |
| 2478 | // 'elf' OS type, so the Linux paths are not appropriate. When we actually |
| 2479 | // support 'linux' we'll need to fix this up |
| 2480 | LibPaths->clear(); |
| 2481 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2482 | GetHexagonLibraryPaths(*this, Args, GetGCCLibAndIncVersion(), |
| 2483 | GetTargetCPU(Args), InstalledDir, LibPaths); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2486 | HexagonToolChain::~HexagonToolChain() {} |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2487 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2488 | Tool *HexagonToolChain::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2489 | return new tools::hexagon::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2492 | Tool *HexagonToolChain::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2493 | return new tools::hexagon::Linker(*this); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2496 | void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2497 | ArgStringList &CC1Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2498 | const Driver &D = getDriver(); |
| 2499 | |
| 2500 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 2501 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2502 | return; |
| 2503 | |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2504 | std::string Ver(GetGCCLibAndIncVersion()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2505 | std::string GnuDir = GetGnuDir(D.InstalledDir, DriverArgs); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2506 | std::string HexagonDir(GnuDir + "/lib/gcc/hexagon/" + Ver); |
| 2507 | addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include"); |
| 2508 | addExternCSystemInclude(DriverArgs, CC1Args, HexagonDir + "/include-fixed"); |
| 2509 | addExternCSystemInclude(DriverArgs, CC1Args, GnuDir + "/hexagon/include"); |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2512 | void HexagonToolChain::AddClangCXXStdlibIncludeArgs( |
| 2513 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2514 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2515 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2516 | return; |
| 2517 | |
| 2518 | const Driver &D = getDriver(); |
| 2519 | std::string Ver(GetGCCLibAndIncVersion()); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2520 | SmallString<128> IncludeDir(GetGnuDir(D.InstalledDir, DriverArgs)); |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2521 | |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 2522 | llvm::sys::path::append(IncludeDir, "hexagon/include/c++/"); |
| 2523 | llvm::sys::path::append(IncludeDir, Ver); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 2524 | addSystemInclude(DriverArgs, CC1Args, IncludeDir); |
Chandler Carruth | 76a943b | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 2525 | } |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2526 | |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2527 | ToolChain::CXXStdlibType |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2528 | HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2529 | Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 2530 | if (!A) |
| 2531 | return ToolChain::CST_Libstdcxx; |
| 2532 | |
| 2533 | StringRef Value = A->getValue(); |
| 2534 | if (Value != "libstdc++") { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2535 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Matthew Curtis | e689b05 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | return ToolChain::CST_Libstdcxx; |
| 2539 | } |
| 2540 | |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2541 | static int getHexagonVersion(const ArgList &Args) { |
| 2542 | Arg *A = Args.getLastArg(options::OPT_march_EQ, options::OPT_mcpu_EQ); |
| 2543 | // Select the default CPU (v4) if none was given. |
| 2544 | if (!A) |
| 2545 | return 4; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2546 | |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2547 | // FIXME: produce errors if we cannot parse the version. |
| 2548 | StringRef WhichHexagon = A->getValue(); |
| 2549 | if (WhichHexagon.startswith("hexagonv")) { |
| 2550 | int Val; |
| 2551 | if (!WhichHexagon.substr(sizeof("hexagonv") - 1).getAsInteger(10, Val)) |
| 2552 | return Val; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2553 | } |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2554 | if (WhichHexagon.startswith("v")) { |
| 2555 | int Val; |
| 2556 | if (!WhichHexagon.substr(1).getAsInteger(10, Val)) |
| 2557 | return Val; |
| 2558 | } |
| 2559 | |
| 2560 | // FIXME: should probably be an error. |
| 2561 | return 4; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2564 | StringRef HexagonToolChain::GetTargetCPU(const ArgList &Args) { |
Rafael Espindola | bfd88f2 | 2013-09-24 13:28:24 +0000 | [diff] [blame] | 2565 | int V = getHexagonVersion(Args); |
| 2566 | // FIXME: We don't support versions < 4. We should error on them. |
| 2567 | switch (V) { |
| 2568 | default: |
| 2569 | llvm_unreachable("Unexpected version"); |
| 2570 | case 5: |
| 2571 | return "v5"; |
| 2572 | case 4: |
| 2573 | return "v4"; |
| 2574 | case 3: |
| 2575 | return "v3"; |
| 2576 | case 2: |
| 2577 | return "v2"; |
| 2578 | case 1: |
| 2579 | return "v1"; |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2580 | } |
Matthew Curtis | f10a595 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 2581 | } |
Matthew Curtis | 22dd8da | 2012-12-06 12:43:18 +0000 | [diff] [blame] | 2582 | // End Hexagon |
Daniel Dunbar | dac54a8 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 2583 | |
Tom Stellard | 8fa3309 | 2015-07-18 01:49:05 +0000 | [diff] [blame] | 2584 | /// AMDGPU Toolchain |
| 2585 | AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2586 | const ArgList &Args) |
| 2587 | : Generic_ELF(D, Triple, Args) { } |
| 2588 | |
| 2589 | Tool *AMDGPUToolChain::buildLinker() const { |
| 2590 | return new tools::amdgpu::Linker(*this); |
| 2591 | } |
| 2592 | // End AMDGPU |
| 2593 | |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2594 | /// NaCl Toolchain |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2595 | NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, |
| 2596 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2597 | : Generic_ELF(D, Triple, Args) { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2598 | |
| 2599 | // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the |
| 2600 | // default paths, and must instead only use the paths provided |
| 2601 | // with this toolchain based on architecture. |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2602 | path_list &file_paths = getFilePaths(); |
| 2603 | path_list &prog_paths = getProgramPaths(); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2604 | |
| 2605 | file_paths.clear(); |
| 2606 | prog_paths.clear(); |
| 2607 | |
| 2608 | // Path for library files (libc.a, ...) |
| 2609 | std::string FilePath(getDriver().Dir + "/../"); |
| 2610 | |
| 2611 | // Path for tools (clang, ld, etc..) |
| 2612 | std::string ProgPath(getDriver().Dir + "/../"); |
| 2613 | |
| 2614 | // Path for toolchain libraries (libgcc.a, ...) |
| 2615 | std::string ToolPath(getDriver().ResourceDir + "/lib/"); |
| 2616 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2617 | switch (Triple.getArch()) { |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2618 | case llvm::Triple::x86: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2619 | file_paths.push_back(FilePath + "x86_64-nacl/lib32"); |
Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2620 | file_paths.push_back(FilePath + "i686-nacl/usr/lib"); |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2621 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 2622 | file_paths.push_back(ToolPath + "i686-nacl"); |
| 2623 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2624 | case llvm::Triple::x86_64: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2625 | file_paths.push_back(FilePath + "x86_64-nacl/lib"); |
| 2626 | file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); |
| 2627 | prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); |
| 2628 | file_paths.push_back(ToolPath + "x86_64-nacl"); |
| 2629 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2630 | case llvm::Triple::arm: |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2631 | file_paths.push_back(FilePath + "arm-nacl/lib"); |
| 2632 | file_paths.push_back(FilePath + "arm-nacl/usr/lib"); |
| 2633 | prog_paths.push_back(ProgPath + "arm-nacl/bin"); |
| 2634 | file_paths.push_back(ToolPath + "arm-nacl"); |
| 2635 | break; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 2636 | case llvm::Triple::mipsel: |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2637 | file_paths.push_back(FilePath + "mipsel-nacl/lib"); |
| 2638 | file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); |
| 2639 | prog_paths.push_back(ProgPath + "bin"); |
| 2640 | file_paths.push_back(ToolPath + "mipsel-nacl"); |
| 2641 | break; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2642 | default: |
| 2643 | break; |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | // Use provided linker, not system linker |
Derek Schuff | ef465d7 | 2015-08-24 23:53:25 +0000 | [diff] [blame] | 2647 | Linker = GetLinkerPath(); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2648 | NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); |
| 2649 | } |
| 2650 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2651 | void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 2652 | ArgStringList &CC1Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2653 | const Driver &D = getDriver(); |
| 2654 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 2655 | return; |
| 2656 | |
| 2657 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 2658 | SmallString<128> P(D.ResourceDir); |
| 2659 | llvm::sys::path::append(P, "include"); |
| 2660 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2661 | } |
| 2662 | |
| 2663 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 2664 | return; |
| 2665 | |
| 2666 | SmallString<128> P(D.Dir + "/../"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2667 | switch (getTriple().getArch()) { |
Derek Schuff | 9afb050 | 2015-08-26 17:14:08 +0000 | [diff] [blame] | 2668 | case llvm::Triple::x86: |
| 2669 | // x86 is special because multilib style uses x86_64-nacl/include for libc |
| 2670 | // headers but the SDK wants i686-nacl/usr/include. The other architectures |
| 2671 | // have the same substring. |
| 2672 | llvm::sys::path::append(P, "i686-nacl/usr/include"); |
| 2673 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2674 | llvm::sys::path::remove_filename(P); |
| 2675 | llvm::sys::path::remove_filename(P); |
| 2676 | llvm::sys::path::remove_filename(P); |
| 2677 | llvm::sys::path::append(P, "x86_64-nacl/include"); |
| 2678 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2679 | return; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2680 | case llvm::Triple::arm: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2681 | llvm::sys::path::append(P, "arm-nacl/usr/include"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2682 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2683 | case llvm::Triple::x86_64: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2684 | llvm::sys::path::append(P, "x86_64-nacl/usr/include"); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2685 | break; |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2686 | case llvm::Triple::mipsel: |
| 2687 | llvm::sys::path::append(P, "mipsel-nacl/usr/include"); |
| 2688 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2689 | default: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2690 | return; |
| 2691 | } |
| 2692 | |
| 2693 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2694 | llvm::sys::path::remove_filename(P); |
| 2695 | llvm::sys::path::remove_filename(P); |
| 2696 | llvm::sys::path::append(P, "include"); |
| 2697 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2698 | } |
| 2699 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2700 | void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2701 | ArgStringList &CmdArgs) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2702 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 2703 | // if the value is libc++, and emits an error for other values. |
| 2704 | GetCXXStdlibType(Args); |
| 2705 | CmdArgs.push_back("-lc++"); |
| 2706 | } |
| 2707 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2708 | void NaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2709 | ArgStringList &CC1Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2710 | const Driver &D = getDriver(); |
| 2711 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2712 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2713 | return; |
| 2714 | |
| 2715 | // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 2716 | // if the value is libc++, and emits an error for other values. |
| 2717 | GetCXXStdlibType(DriverArgs); |
| 2718 | |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2719 | SmallString<128> P(D.Dir + "/../"); |
| 2720 | switch (getTriple().getArch()) { |
| 2721 | case llvm::Triple::arm: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2722 | llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); |
| 2723 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2724 | break; |
| 2725 | case llvm::Triple::x86: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2726 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 2727 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2728 | break; |
| 2729 | case llvm::Triple::x86_64: |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2730 | llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); |
| 2731 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 2732 | break; |
Petar Jovanovic | 26a4a40 | 2015-07-08 13:07:31 +0000 | [diff] [blame] | 2733 | case llvm::Triple::mipsel: |
| 2734 | llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); |
| 2735 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2736 | break; |
Douglas Katzman | 9ad0ec2 | 2015-06-23 04:20:44 +0000 | [diff] [blame] | 2737 | default: |
| 2738 | break; |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2739 | } |
| 2740 | } |
| 2741 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2742 | ToolChain::CXXStdlibType |
| 2743 | NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2744 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 2745 | StringRef Value = A->getValue(); |
| 2746 | if (Value == "libc++") |
| 2747 | return ToolChain::CST_Libcxx; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2748 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | return ToolChain::CST_Libcxx; |
| 2752 | } |
| 2753 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2754 | std::string |
| 2755 | NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, |
| 2756 | types::ID InputType) const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2757 | llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); |
| 2758 | if (TheTriple.getArch() == llvm::Triple::arm && |
| 2759 | TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) |
| 2760 | TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); |
| 2761 | return TheTriple.getTriple(); |
| 2762 | } |
| 2763 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2764 | Tool *NaClToolChain::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2765 | return new tools::nacltools::Linker(*this); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 2768 | Tool *NaClToolChain::buildAssembler() const { |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2769 | if (getTriple().getArch() == llvm::Triple::arm) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2770 | return new tools::nacltools::AssemblerARM(*this); |
| 2771 | return new tools::gnutools::Assembler(*this); |
Derek Schuff | 6ab52fa | 2015-03-30 20:31:33 +0000 | [diff] [blame] | 2772 | } |
| 2773 | // End NaCl |
| 2774 | |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2775 | /// TCEToolChain - A tool chain using the llvm bitcode tools to perform |
| 2776 | /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. |
| 2777 | /// Currently does not support anything else but compilation. |
| 2778 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2779 | TCEToolChain::TCEToolChain(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 84b588b | 2013-03-18 18:10:27 +0000 | [diff] [blame] | 2780 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2781 | : ToolChain(D, Triple, Args) { |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2782 | // Path mangling to find libexec |
| 2783 | std::string Path(getDriver().Dir); |
| 2784 | |
| 2785 | Path += "/../libexec"; |
| 2786 | getProgramPaths().push_back(Path); |
| 2787 | } |
| 2788 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 2789 | TCEToolChain::~TCEToolChain() {} |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2790 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2791 | bool TCEToolChain::IsMathErrnoDefault() const { return true; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2792 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2793 | bool TCEToolChain::isPICDefault() const { return false; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2794 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2795 | bool TCEToolChain::isPIEDefault() const { return false; } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 2796 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2797 | bool TCEToolChain::isPICDefaultForced() const { return false; } |
Chris Lattner | 0979754 | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2798 | |
Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2799 | // CloudABI - CloudABI tool chain which can call ld(1) directly. |
| 2800 | |
| 2801 | CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, |
| 2802 | const ArgList &Args) |
| 2803 | : Generic_ELF(D, Triple, Args) { |
| 2804 | SmallString<128> P(getDriver().Dir); |
| 2805 | llvm::sys::path::append(P, "..", getTriple().str(), "lib"); |
| 2806 | getFilePaths().push_back(P.str()); |
| 2807 | } |
| 2808 | |
| 2809 | void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2810 | ArgStringList &CC1Args) const { |
| 2811 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) && |
| 2812 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2813 | return; |
| 2814 | |
| 2815 | SmallString<128> P(getDriver().Dir); |
| 2816 | llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); |
| 2817 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 2818 | } |
| 2819 | |
| 2820 | void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2821 | ArgStringList &CmdArgs) const { |
| 2822 | CmdArgs.push_back("-lc++"); |
| 2823 | CmdArgs.push_back("-lc++abi"); |
| 2824 | CmdArgs.push_back("-lunwind"); |
| 2825 | } |
| 2826 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2827 | Tool *CloudABI::buildLinker() const { |
| 2828 | return new tools::cloudabi::Linker(*this); |
| 2829 | } |
Ed Schouten | 3c3e58c | 2015-03-26 11:13:44 +0000 | [diff] [blame] | 2830 | |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2831 | /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. |
| 2832 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2833 | OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple, |
| 2834 | const ArgList &Args) |
| 2835 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2836 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2837 | getFilePaths().push_back("/usr/lib"); |
| 2838 | } |
| 2839 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2840 | Tool *OpenBSD::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2841 | return new tools::openbsd::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2842 | } |
| 2843 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2844 | Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); } |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2845 | |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2846 | /// Bitrig - Bitrig tool chain which can call as(1) and ld(1) directly. |
| 2847 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2848 | Bitrig::Bitrig(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 2849 | : Generic_ELF(D, Triple, Args) { |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2850 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 2851 | getFilePaths().push_back("/usr/lib"); |
| 2852 | } |
| 2853 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2854 | Tool *Bitrig::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2855 | return new tools::bitrig::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2858 | Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2859 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2860 | ToolChain::CXXStdlibType Bitrig::GetCXXStdlibType(const ArgList &Args) const { |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 2861 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 2862 | StringRef Value = A->getValue(); |
| 2863 | if (Value == "libstdc++") |
| 2864 | return ToolChain::CST_Libstdcxx; |
| 2865 | if (Value == "libc++") |
| 2866 | return ToolChain::CST_Libcxx; |
| 2867 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2868 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 2869 | } |
| 2870 | return ToolChain::CST_Libcxx; |
| 2871 | } |
| 2872 | |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2873 | void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2874 | ArgStringList &CC1Args) const { |
| 2875 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2876 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2877 | return; |
| 2878 | |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2879 | switch (GetCXXStdlibType(DriverArgs)) { |
| 2880 | case ToolChain::CST_Libcxx: |
| 2881 | addSystemInclude(DriverArgs, CC1Args, |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 2882 | getDriver().SysRoot + "/usr/include/c++/v1"); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2883 | break; |
| 2884 | case ToolChain::CST_Libstdcxx: |
| 2885 | addSystemInclude(DriverArgs, CC1Args, |
| 2886 | getDriver().SysRoot + "/usr/include/c++/stdc++"); |
| 2887 | addSystemInclude(DriverArgs, CC1Args, |
| 2888 | getDriver().SysRoot + "/usr/include/c++/stdc++/backward"); |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2889 | |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2890 | StringRef Triple = getTriple().str(); |
| 2891 | if (Triple.startswith("amd64")) |
| 2892 | addSystemInclude(DriverArgs, CC1Args, |
| 2893 | getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2894 | Triple.substr(5)); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2895 | else |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2896 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + |
| 2897 | "/usr/include/c++/stdc++/" + |
| 2898 | Triple); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args, |
| 2904 | ArgStringList &CmdArgs) const { |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2905 | switch (GetCXXStdlibType(Args)) { |
| 2906 | case ToolChain::CST_Libcxx: |
| 2907 | CmdArgs.push_back("-lc++"); |
Richard Smith | 51af519 | 2014-05-01 23:24:24 +0000 | [diff] [blame] | 2908 | CmdArgs.push_back("-lc++abi"); |
| 2909 | CmdArgs.push_back("-lpthread"); |
Chandler Carruth | c0f5cd1 | 2012-10-08 21:31:38 +0000 | [diff] [blame] | 2910 | break; |
| 2911 | case ToolChain::CST_Libstdcxx: |
| 2912 | CmdArgs.push_back("-lstdc++"); |
| 2913 | break; |
| 2914 | } |
Eli Friedman | 9fa2885 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 2917 | /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. |
| 2918 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2919 | FreeBSD::FreeBSD(const Driver &D, const llvm::Triple &Triple, |
| 2920 | const ArgList &Args) |
| 2921 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | a18a487 | 2010-08-02 05:43:59 +0000 | [diff] [blame] | 2922 | |
Chandler Carruth | 0b1756b | 2012-01-26 01:35:15 +0000 | [diff] [blame] | 2923 | // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall |
| 2924 | // back to '/usr/lib' if it doesn't exist. |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 2925 | if ((Triple.getArch() == llvm::Triple::x86 || |
| 2926 | Triple.getArch() == llvm::Triple::ppc) && |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 2927 | D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o")) |
Chandler Carruth | f7bf3db | 2012-01-25 11:24:24 +0000 | [diff] [blame] | 2928 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32"); |
| 2929 | else |
| 2930 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2933 | ToolChain::CXXStdlibType FreeBSD::GetCXXStdlibType(const ArgList &Args) const { |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 2934 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 2935 | StringRef Value = A->getValue(); |
| 2936 | if (Value == "libstdc++") |
| 2937 | return ToolChain::CST_Libstdcxx; |
| 2938 | if (Value == "libc++") |
| 2939 | return ToolChain::CST_Libcxx; |
| 2940 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2941 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 2942 | } |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2943 | if (getTriple().getOSMajorVersion() >= 10) |
David Chisnall | 867ccd8 | 2013-11-09 15:10:56 +0000 | [diff] [blame] | 2944 | return ToolChain::CST_Libcxx; |
| 2945 | return ToolChain::CST_Libstdcxx; |
| 2946 | } |
| 2947 | |
| 2948 | void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 2949 | ArgStringList &CC1Args) const { |
| 2950 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 2951 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 2952 | return; |
| 2953 | |
| 2954 | switch (GetCXXStdlibType(DriverArgs)) { |
| 2955 | case ToolChain::CST_Libcxx: |
| 2956 | addSystemInclude(DriverArgs, CC1Args, |
| 2957 | getDriver().SysRoot + "/usr/include/c++/v1"); |
| 2958 | break; |
| 2959 | case ToolChain::CST_Libstdcxx: |
| 2960 | addSystemInclude(DriverArgs, CC1Args, |
| 2961 | getDriver().SysRoot + "/usr/include/c++/4.2"); |
| 2962 | addSystemInclude(DriverArgs, CC1Args, |
| 2963 | getDriver().SysRoot + "/usr/include/c++/4.2/backward"); |
| 2964 | break; |
| 2965 | } |
| 2966 | } |
| 2967 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2968 | Tool *FreeBSD::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2969 | return new tools::freebsd::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 2972 | Tool *FreeBSD::buildLinker() const { return new tools::freebsd::Linker(*this); } |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2973 | |
Tim Northover | e931f9f | 2015-10-30 16:30:41 +0000 | [diff] [blame] | 2974 | bool FreeBSD::UseSjLjExceptions(const ArgList &Args) const { |
Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 2975 | // FreeBSD uses SjLj exceptions on ARM oabi. |
| 2976 | switch (getTriple().getEnvironment()) { |
Renato Golin | f4421f7 | 2014-02-19 10:44:07 +0000 | [diff] [blame] | 2977 | case llvm::Triple::GNUEABIHF: |
Rafael Espindola | 0f207ed | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 2978 | case llvm::Triple::GNUEABI: |
| 2979 | case llvm::Triple::EABI: |
| 2980 | return false; |
| 2981 | |
| 2982 | default: |
| 2983 | return (getTriple().getArch() == llvm::Triple::arm || |
| 2984 | getTriple().getArch() == llvm::Triple::thumb); |
| 2985 | } |
| 2986 | } |
| 2987 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2988 | bool FreeBSD::HasNativeLLVMSupport() const { return true; } |
Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 2989 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 2990 | bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
Alexey Samsonov | e65ceb9 | 2014-02-25 13:26:03 +0000 | [diff] [blame] | 2991 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 2992 | SanitizerMask FreeBSD::getSupportedSanitizers() const { |
| 2993 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 2994 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 2995 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 2996 | getTriple().getArch() == llvm::Triple::mips64el; |
| 2997 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 2998 | Res |= SanitizerKind::Address; |
| 2999 | Res |= SanitizerKind::Vptr; |
| 3000 | if (IsX86_64 || IsMIPS64) { |
| 3001 | Res |= SanitizerKind::Leak; |
| 3002 | Res |= SanitizerKind::Thread; |
| 3003 | } |
| 3004 | if (IsX86 || IsX86_64) { |
| 3005 | Res |= SanitizerKind::SafeStack; |
| 3006 | } |
| 3007 | return Res; |
| 3008 | } |
| 3009 | |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3010 | /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. |
| 3011 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3012 | NetBSD::NetBSD(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3013 | : Generic_ELF(D, Triple, Args) { |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3014 | |
Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3015 | if (getDriver().UseStdLib) { |
Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3016 | // When targeting a 32-bit platform, try the special directory used on |
| 3017 | // 64-bit hosts, and only fall back to the main library directory if that |
| 3018 | // doesn't work. |
| 3019 | // FIXME: It'd be nicer to test if this directory exists, but I'm not sure |
| 3020 | // what all logic is needed to emulate the '=' prefix here. |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3021 | switch (Triple.getArch()) { |
| 3022 | case llvm::Triple::x86: |
Joerg Sonnenberger | bc923f3 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 3023 | getFilePaths().push_back("=/usr/lib/i386"); |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3024 | break; |
| 3025 | case llvm::Triple::arm: |
Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3026 | case llvm::Triple::armeb: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3027 | case llvm::Triple::thumb: |
Joerg Sonnenberger | 3a6c28a | 2014-05-07 08:24:23 +0000 | [diff] [blame] | 3028 | case llvm::Triple::thumbeb: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3029 | switch (Triple.getEnvironment()) { |
| 3030 | case llvm::Triple::EABI: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3031 | case llvm::Triple::GNUEABI: |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3032 | getFilePaths().push_back("=/usr/lib/eabi"); |
| 3033 | break; |
Joerg Sonnenberger | 17a80e4 | 2014-08-09 19:01:52 +0000 | [diff] [blame] | 3034 | case llvm::Triple::EABIHF: |
| 3035 | case llvm::Triple::GNUEABIHF: |
| 3036 | getFilePaths().push_back("=/usr/lib/eabihf"); |
| 3037 | break; |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3038 | default: |
| 3039 | getFilePaths().push_back("=/usr/lib/oabi"); |
| 3040 | break; |
| 3041 | } |
| 3042 | break; |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3043 | case llvm::Triple::mips64: |
| 3044 | case llvm::Triple::mips64el: |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3045 | if (tools::mips::hasMipsAbiArg(Args, "o32")) |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3046 | getFilePaths().push_back("=/usr/lib/o32"); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3047 | else if (tools::mips::hasMipsAbiArg(Args, "64")) |
Joerg Sonnenberger | e7f9759 | 2014-02-02 22:59:16 +0000 | [diff] [blame] | 3048 | getFilePaths().push_back("=/usr/lib/64"); |
| 3049 | break; |
Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3050 | case llvm::Triple::ppc: |
| 3051 | getFilePaths().push_back("=/usr/lib/powerpc"); |
| 3052 | break; |
Joerg Sonnenberger | 8280abe | 2014-04-16 20:44:17 +0000 | [diff] [blame] | 3053 | case llvm::Triple::sparc: |
| 3054 | getFilePaths().push_back("=/usr/lib/sparc"); |
| 3055 | break; |
Joerg Sonnenberger | 25de31d | 2014-02-02 22:47:37 +0000 | [diff] [blame] | 3056 | default: |
| 3057 | break; |
| 3058 | } |
Chandler Carruth | 1ccbed8 | 2012-01-25 11:18:20 +0000 | [diff] [blame] | 3059 | |
| 3060 | getFilePaths().push_back("=/usr/lib"); |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3061 | } |
| 3062 | } |
| 3063 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3064 | Tool *NetBSD::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3065 | return new tools::netbsd::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3068 | Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); } |
Benjamin Kramer | 24f1d3e | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3069 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3070 | ToolChain::CXXStdlibType NetBSD::GetCXXStdlibType(const ArgList &Args) const { |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3071 | if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { |
| 3072 | StringRef Value = A->getValue(); |
| 3073 | if (Value == "libstdc++") |
| 3074 | return ToolChain::CST_Libstdcxx; |
| 3075 | if (Value == "libc++") |
| 3076 | return ToolChain::CST_Libcxx; |
| 3077 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3078 | getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3081 | unsigned Major, Minor, Micro; |
| 3082 | getTriple().getOSVersion(Major, Minor, Micro); |
Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3083 | if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 49) || Major == 0) { |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3084 | switch (getArch()) { |
Joerg Sonnenberger | 323cea9 | 2014-08-09 18:28:36 +0000 | [diff] [blame] | 3085 | case llvm::Triple::aarch64: |
Joerg Sonnenberger | 1ea6647 | 2014-05-07 08:45:26 +0000 | [diff] [blame] | 3086 | case llvm::Triple::arm: |
| 3087 | case llvm::Triple::armeb: |
| 3088 | case llvm::Triple::thumb: |
| 3089 | case llvm::Triple::thumbeb: |
Joerg Sonnenberger | c888757 | 2014-07-25 20:57:24 +0000 | [diff] [blame] | 3090 | case llvm::Triple::ppc: |
Joerg Sonnenberger | dd13b30 | 2014-08-13 14:17:32 +0000 | [diff] [blame] | 3091 | case llvm::Triple::ppc64: |
| 3092 | case llvm::Triple::ppc64le: |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3093 | case llvm::Triple::x86: |
| 3094 | case llvm::Triple::x86_64: |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3095 | return ToolChain::CST_Libcxx; |
Joerg Sonnenberger | d769a1e | 2014-01-18 00:50:49 +0000 | [diff] [blame] | 3096 | default: |
| 3097 | break; |
| 3098 | } |
Joerg Sonnenberger | a443563 | 2013-10-14 20:13:05 +0000 | [diff] [blame] | 3099 | } |
Joerg Sonnenberger | 428ef1e | 2013-04-30 01:21:43 +0000 | [diff] [blame] | 3100 | return ToolChain::CST_Libstdcxx; |
| 3101 | } |
| 3102 | |
| 3103 | void NetBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3104 | ArgStringList &CC1Args) const { |
| 3105 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3106 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3107 | return; |
| 3108 | |
| 3109 | switch (GetCXXStdlibType(DriverArgs)) { |
| 3110 | case ToolChain::CST_Libcxx: |
| 3111 | addSystemInclude(DriverArgs, CC1Args, |
| 3112 | getDriver().SysRoot + "/usr/include/c++/"); |
| 3113 | break; |
| 3114 | case ToolChain::CST_Libstdcxx: |
| 3115 | addSystemInclude(DriverArgs, CC1Args, |
| 3116 | getDriver().SysRoot + "/usr/include/g++"); |
| 3117 | addSystemInclude(DriverArgs, CC1Args, |
| 3118 | getDriver().SysRoot + "/usr/include/g++/backward"); |
| 3119 | break; |
| 3120 | } |
| 3121 | } |
| 3122 | |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3123 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 3124 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3125 | Minix::Minix(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 3126 | : Generic_ELF(D, Triple, Args) { |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3127 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 3128 | getFilePaths().push_back("/usr/lib"); |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3129 | } |
| 3130 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3131 | Tool *Minix::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3132 | return new tools::minix::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3133 | } |
| 3134 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3135 | Tool *Minix::buildLinker() const { return new tools::minix::Linker(*this); } |
Chris Lattner | 3e2ee14 | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3136 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3137 | static void addPathIfExists(const Driver &D, const Twine &Path, |
| 3138 | ToolChain::path_list &Paths) { |
| 3139 | if (D.getVFS().exists(Path)) |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3140 | Paths.push_back(Path.str()); |
| 3141 | } |
| 3142 | |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3143 | /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly. |
| 3144 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3145 | Solaris::Solaris(const Driver &D, const llvm::Triple &Triple, |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3146 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3147 | : Generic_GCC(D, Triple, Args) { |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3148 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3149 | GCCInstallation.init(Triple, Args); |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3150 | |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3151 | path_list &Paths = getFilePaths(); |
| 3152 | if (GCCInstallation.isValid()) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3153 | addPathIfExists(D, GCCInstallation.getInstallPath(), Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3154 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3155 | addPathIfExists(D, getDriver().getInstalledDir(), Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3156 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3157 | addPathIfExists(D, getDriver().Dir, Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3158 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3159 | addPathIfExists(D, getDriver().SysRoot + getDriver().Dir + "/../lib", Paths); |
Rafael Espindola | c53c5b1 | 2015-08-31 19:17:51 +0000 | [diff] [blame] | 3160 | |
| 3161 | std::string LibPath = "/usr/lib/"; |
| 3162 | switch (Triple.getArch()) { |
| 3163 | case llvm::Triple::x86: |
| 3164 | case llvm::Triple::sparc: |
| 3165 | break; |
| 3166 | case llvm::Triple::x86_64: |
| 3167 | LibPath += "amd64/"; |
| 3168 | break; |
| 3169 | case llvm::Triple::sparcv9: |
| 3170 | LibPath += "sparcv9/"; |
| 3171 | break; |
| 3172 | default: |
| 3173 | llvm_unreachable("Unsupported architecture"); |
| 3174 | } |
| 3175 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3176 | addPathIfExists(D, getDriver().SysRoot + LibPath, Paths); |
David Chisnall | f571cde | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3179 | Tool *Solaris::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3180 | return new tools::solaris::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3183 | Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); } |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3184 | |
Rafael Espindola | d511726 | 2015-09-09 13:36:00 +0000 | [diff] [blame] | 3185 | void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3186 | ArgStringList &CC1Args) const { |
| 3187 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3188 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3189 | return; |
| 3190 | |
| 3191 | // Include the support directory for things like xlocale and fudged system |
| 3192 | // headers. |
| 3193 | addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris"); |
| 3194 | |
| 3195 | if (GCCInstallation.isValid()) { |
| 3196 | GCCVersion Version = GCCInstallation.getVersion(); |
| 3197 | addSystemInclude(DriverArgs, CC1Args, |
| 3198 | getDriver().SysRoot + "/usr/gcc/" + |
| 3199 | Version.MajorStr + "." + |
| 3200 | Version.MinorStr + |
| 3201 | "/include/c++/" + Version.Text); |
| 3202 | addSystemInclude(DriverArgs, CC1Args, |
| 3203 | getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr + |
| 3204 | "." + Version.MinorStr + "/include/c++/" + |
| 3205 | Version.Text + "/" + |
| 3206 | GCCInstallation.getTriple().str()); |
| 3207 | } |
| 3208 | } |
| 3209 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3210 | /// Distribution (very bare-bones at the moment). |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3211 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3212 | enum Distro { |
Douglas Katzman | a5df0c8 | 2015-06-22 20:55:31 +0000 | [diff] [blame] | 3213 | // NB: Releases of a particular Linux distro should be kept together |
| 3214 | // in this enum, because some tests are done by integer comparison against |
| 3215 | // the first and last known member in the family, e.g. IsRedHat(). |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3216 | ArchLinux, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3217 | DebianLenny, |
| 3218 | DebianSqueeze, |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3219 | DebianWheezy, |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3220 | DebianJessie, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3221 | DebianStretch, |
Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3222 | Exherbo, |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3223 | RHEL4, |
| 3224 | RHEL5, |
| 3225 | RHEL6, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3226 | RHEL7, |
Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3227 | Fedora, |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3228 | OpenSUSE, |
Douglas Gregor | 0a36f4d | 2011-03-14 15:39:50 +0000 | [diff] [blame] | 3229 | UbuntuHardy, |
| 3230 | UbuntuIntrepid, |
Rafael Espindola | 66b291a | 2010-11-10 05:00:22 +0000 | [diff] [blame] | 3231 | UbuntuJaunty, |
Zhongxing Xu | 14776cf | 2010-11-15 09:01:52 +0000 | [diff] [blame] | 3232 | UbuntuKarmic, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3233 | UbuntuLucid, |
| 3234 | UbuntuMaverick, |
Ted Kremenek | 43d47cc | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 3235 | UbuntuNatty, |
Benjamin Kramer | f90b5de | 2011-06-05 16:08:59 +0000 | [diff] [blame] | 3236 | UbuntuOneiric, |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3237 | UbuntuPrecise, |
Rafael Espindola | 62e8770 | 2012-12-13 20:26:05 +0000 | [diff] [blame] | 3238 | UbuntuQuantal, |
| 3239 | UbuntuRaring, |
Sylvestre Ledru | 93c47b7 | 2013-06-13 11:52:27 +0000 | [diff] [blame] | 3240 | UbuntuSaucy, |
Sylvestre Ledru | aaf01a7 | 2013-11-07 09:31:30 +0000 | [diff] [blame] | 3241 | UbuntuTrusty, |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3242 | UbuntuUtopic, |
| 3243 | UbuntuVivid, |
Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3244 | UbuntuWily, |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3245 | UbuntuXenial, |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3246 | UnknownDistro |
| 3247 | }; |
| 3248 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3249 | static bool IsRedhat(enum Distro Distro) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3250 | return Distro == Fedora || (Distro >= RHEL4 && Distro <= RHEL7); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3251 | } |
| 3252 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3253 | static bool IsOpenSUSE(enum Distro Distro) { return Distro == OpenSUSE; } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3254 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3255 | static bool IsDebian(enum Distro Distro) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3256 | return Distro >= DebianLenny && Distro <= DebianStretch; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3259 | static bool IsUbuntu(enum Distro Distro) { |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3260 | return Distro >= UbuntuHardy && Distro <= UbuntuXenial; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3263 | static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) { |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3264 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = |
| 3265 | llvm::MemoryBuffer::getFile("/etc/lsb-release"); |
| 3266 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3267 | StringRef Data = File.get()->getBuffer(); |
Hans Wennborg | 3b7dd8d | 2014-08-11 18:09:32 +0000 | [diff] [blame] | 3268 | SmallVector<StringRef, 16> Lines; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3269 | Data.split(Lines, "\n"); |
Thomas Schwinge | 6d94da0 | 2013-03-28 19:02:48 +0000 | [diff] [blame] | 3270 | Distro Version = UnknownDistro; |
Benjamin Kramer | 72e6431 | 2015-09-24 14:48:49 +0000 | [diff] [blame] | 3271 | for (StringRef Line : Lines) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3272 | if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME=")) |
| 3273 | Version = llvm::StringSwitch<Distro>(Line.substr(17)) |
| 3274 | .Case("hardy", UbuntuHardy) |
| 3275 | .Case("intrepid", UbuntuIntrepid) |
| 3276 | .Case("jaunty", UbuntuJaunty) |
| 3277 | .Case("karmic", UbuntuKarmic) |
| 3278 | .Case("lucid", UbuntuLucid) |
| 3279 | .Case("maverick", UbuntuMaverick) |
| 3280 | .Case("natty", UbuntuNatty) |
| 3281 | .Case("oneiric", UbuntuOneiric) |
| 3282 | .Case("precise", UbuntuPrecise) |
| 3283 | .Case("quantal", UbuntuQuantal) |
| 3284 | .Case("raring", UbuntuRaring) |
| 3285 | .Case("saucy", UbuntuSaucy) |
| 3286 | .Case("trusty", UbuntuTrusty) |
| 3287 | .Case("utopic", UbuntuUtopic) |
| 3288 | .Case("vivid", UbuntuVivid) |
Benjamin Kramer | 2d46980 | 2015-07-09 15:31:17 +0000 | [diff] [blame] | 3289 | .Case("wily", UbuntuWily) |
Sylvestre Ledru | 43b9571 | 2015-10-29 17:27:55 +0000 | [diff] [blame] | 3290 | .Case("xenial", UbuntuXenial) |
Douglas Katzman | 6bbffc4 | 2015-06-25 18:51:37 +0000 | [diff] [blame] | 3291 | .Default(UnknownDistro); |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3292 | return Version; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3295 | File = llvm::MemoryBuffer::getFile("/etc/redhat-release"); |
| 3296 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3297 | StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | 0d2cbc0 | 2013-10-25 18:09:41 +0000 | [diff] [blame] | 3298 | if (Data.startswith("Fedora release")) |
| 3299 | return Fedora; |
Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3300 | if (Data.startswith("Red Hat Enterprise Linux") || |
| 3301 | Data.startswith("CentOS")) { |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3302 | if (Data.find("release 7") != StringRef::npos) |
| 3303 | return RHEL7; |
| 3304 | else if (Data.find("release 6") != StringRef::npos) |
Benjamin Kramer | 6af073b | 2014-05-05 12:39:32 +0000 | [diff] [blame] | 3305 | return RHEL6; |
| 3306 | else if (Data.find("release 5") != StringRef::npos) |
| 3307 | return RHEL5; |
| 3308 | else if (Data.find("release 4") != StringRef::npos) |
| 3309 | return RHEL4; |
| 3310 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3311 | return UnknownDistro; |
| 3312 | } |
| 3313 | |
Rafael Espindola | 2d2b420 | 2014-07-06 17:43:24 +0000 | [diff] [blame] | 3314 | File = llvm::MemoryBuffer::getFile("/etc/debian_version"); |
| 3315 | if (File) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3316 | StringRef Data = File.get()->getBuffer(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3317 | if (Data[0] == '5') |
| 3318 | return DebianLenny; |
Rafael Espindola | 1510c85 | 2011-12-28 18:17:14 +0000 | [diff] [blame] | 3319 | else if (Data.startswith("squeeze/sid") || Data[0] == '6') |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3320 | return DebianSqueeze; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3321 | else if (Data.startswith("wheezy/sid") || Data[0] == '7') |
Eli Friedman | f760094 | 2011-06-02 21:36:53 +0000 | [diff] [blame] | 3322 | return DebianWheezy; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3323 | else if (Data.startswith("jessie/sid") || Data[0] == '8') |
Sylvestre Ledru | bdef289 | 2013-01-06 08:09:29 +0000 | [diff] [blame] | 3324 | return DebianJessie; |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3325 | else if (Data.startswith("stretch/sid") || Data[0] == '9') |
| 3326 | return DebianStretch; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3327 | return UnknownDistro; |
| 3328 | } |
| 3329 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3330 | if (D.getVFS().exists("/etc/SuSE-release")) |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3331 | return OpenSUSE; |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3332 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3333 | if (D.getVFS().exists("/etc/exherbo-release")) |
Rafael Espindola | 1247984 | 2010-11-11 02:07:13 +0000 | [diff] [blame] | 3334 | return Exherbo; |
| 3335 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3336 | if (D.getVFS().exists("/etc/arch-release")) |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3337 | return ArchLinux; |
| 3338 | |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3339 | return UnknownDistro; |
| 3340 | } |
| 3341 | |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3342 | /// \brief Get our best guess at the multiarch triple for a target. |
| 3343 | /// |
| 3344 | /// Debian-based systems are starting to use a multiarch setup where they use |
| 3345 | /// a target-triple directory in the library and header search paths. |
| 3346 | /// Unfortunately, this triple does not align with the vanilla target triple, |
| 3347 | /// so we provide a rough mapping here. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3348 | static std::string getMultiarchTriple(const Driver &D, |
| 3349 | const llvm::Triple &TargetTriple, |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3350 | StringRef SysRoot) { |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3351 | llvm::Triple::EnvironmentType TargetEnvironment = TargetTriple.getEnvironment(); |
| 3352 | |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3353 | // For most architectures, just use whatever we have rather than trying to be |
| 3354 | // clever. |
| 3355 | switch (TargetTriple.getArch()) { |
| 3356 | default: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3357 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3358 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3359 | // We use the existence of '/lib/<triple>' as a directory to detect some |
| 3360 | // common linux triples that don't quite match the Clang triple for both |
| 3361 | // 32-bit and 64-bit targets. Multiarch fixes its install triples to these |
| 3362 | // regardless of what the actual target triple is. |
Chad Rosier | 4dce73a | 2012-07-11 19:08:21 +0000 | [diff] [blame] | 3363 | case llvm::Triple::arm: |
| 3364 | case llvm::Triple::thumb: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3365 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3366 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabihf")) |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3367 | return "arm-linux-gnueabihf"; |
| 3368 | } else { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3369 | if (D.getVFS().exists(SysRoot + "/lib/arm-linux-gnueabi")) |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3370 | return "arm-linux-gnueabi"; |
| 3371 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3372 | break; |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3373 | case llvm::Triple::armeb: |
| 3374 | case llvm::Triple::thumbeb: |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3375 | if (TargetEnvironment == llvm::Triple::GNUEABIHF) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3376 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabihf")) |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3377 | return "armeb-linux-gnueabihf"; |
| 3378 | } else { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3379 | if (D.getVFS().exists(SysRoot + "/lib/armeb-linux-gnueabi")) |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3380 | return "armeb-linux-gnueabi"; |
| 3381 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3382 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3383 | case llvm::Triple::x86: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3384 | if (D.getVFS().exists(SysRoot + "/lib/i386-linux-gnu")) |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3385 | return "i386-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3386 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3387 | case llvm::Triple::x86_64: |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3388 | // 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] | 3389 | if (TargetEnvironment != llvm::Triple::GNUX32 && |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3390 | D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3391 | return "x86_64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3392 | break; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3393 | case llvm::Triple::aarch64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3394 | if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu")) |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3395 | return "aarch64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3396 | break; |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3397 | case llvm::Triple::aarch64_be: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3398 | if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) |
Christian Pirker | a74c791 | 2014-03-14 12:15:45 +0000 | [diff] [blame] | 3399 | return "aarch64_be-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3400 | break; |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3401 | case llvm::Triple::mips: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3402 | if (D.getVFS().exists(SysRoot + "/lib/mips-linux-gnu")) |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3403 | return "mips-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3404 | break; |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3405 | case llvm::Triple::mipsel: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3406 | if (D.getVFS().exists(SysRoot + "/lib/mipsel-linux-gnu")) |
Eli Friedman | 27b8c4f | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 3407 | return "mipsel-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3408 | break; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3409 | case llvm::Triple::mips64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3410 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3411 | return "mips64-linux-gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3412 | if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnuabi64")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3413 | return "mips64-linux-gnuabi64"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3414 | break; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3415 | case llvm::Triple::mips64el: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3416 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3417 | return "mips64el-linux-gnu"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3418 | if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnuabi64")) |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3419 | return "mips64el-linux-gnuabi64"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3420 | break; |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3421 | case llvm::Triple::ppc: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3422 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe")) |
Sylvestre Ledru | e0bf581 | 2013-03-15 16:22:43 +0000 | [diff] [blame] | 3423 | return "powerpc-linux-gnuspe"; |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3424 | if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnu")) |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3425 | return "powerpc-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3426 | break; |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3427 | case llvm::Triple::ppc64: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3428 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64-linux-gnu")) |
Chandler Carruth | af3c209 | 2012-02-26 09:03:21 +0000 | [diff] [blame] | 3429 | return "powerpc64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3430 | break; |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3431 | case llvm::Triple::ppc64le: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3432 | if (D.getVFS().exists(SysRoot + "/lib/powerpc64le-linux-gnu")) |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3433 | return "powerpc64le-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3434 | break; |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3435 | case llvm::Triple::sparc: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3436 | if (D.getVFS().exists(SysRoot + "/lib/sparc-linux-gnu")) |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3437 | return "sparc-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3438 | break; |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3439 | case llvm::Triple::sparcv9: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3440 | if (D.getVFS().exists(SysRoot + "/lib/sparc64-linux-gnu")) |
James Y Knight | c0aeadf | 2015-06-04 15:36:30 +0000 | [diff] [blame] | 3441 | return "sparc64-linux-gnu"; |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3442 | break; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3443 | case llvm::Triple::systemz: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3444 | if (D.getVFS().exists(SysRoot + "/lib/s390x-linux-gnu")) |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3445 | return "s390x-linux-gnu"; |
| 3446 | break; |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3447 | } |
Douglas Katzman | ecddb3a | 2015-06-26 18:37:15 +0000 | [diff] [blame] | 3448 | return TargetTriple.str(); |
Chandler Carruth | fb7fa24 | 2011-10-31 08:42:24 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3451 | static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) { |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3452 | if (isMipsArch(Triple.getArch())) { |
| 3453 | // lib32 directory has a special meaning on MIPS targets. |
| 3454 | // It contains N32 ABI binaries. Use this folder if produce |
| 3455 | // code for N32 ABI only. |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3456 | if (tools::mips::hasMipsAbiArg(Args, "n32")) |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3457 | return "lib32"; |
| 3458 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 3459 | } |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3460 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3461 | // 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] | 3462 | // using that variant while targeting other architectures causes problems |
| 3463 | // 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] | 3464 | // with a 'lib32' library search path being considered. So we only enable |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3465 | // them when we know we may need it. |
| 3466 | // |
| 3467 | // 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] | 3468 | // reasoning about oslibdir spellings with the lib dir spellings in the |
Chandler Carruth | da79704 | 2013-10-29 10:27:30 +0000 | [diff] [blame] | 3469 | // GCCInstallationDetector, but that is a more significant refactoring. |
| 3470 | if (Triple.getArch() == llvm::Triple::x86 || |
| 3471 | Triple.getArch() == llvm::Triple::ppc) |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3472 | return "lib32"; |
| 3473 | |
Zinovy Nis | 1db9573 | 2014-07-10 15:27:19 +0000 | [diff] [blame] | 3474 | if (Triple.getArch() == llvm::Triple::x86_64 && |
| 3475 | Triple.getEnvironment() == llvm::Triple::GNUX32) |
| 3476 | return "libx32"; |
| 3477 | |
Simon Atanasyan | d441388 | 2012-09-14 11:27:24 +0000 | [diff] [blame] | 3478 | return Triple.isArch32Bit() ? "lib" : "lib64"; |
| 3479 | } |
| 3480 | |
Rafael Espindola | 1af7c21 | 2012-02-19 01:38:32 +0000 | [diff] [blame] | 3481 | Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3482 | : Generic_ELF(D, Triple, Args) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3483 | GCCInstallation.init(Triple, Args); |
| 3484 | CudaInstallation.init(Triple, Args); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3485 | Multilibs = GCCInstallation.getMultilibs(); |
Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3486 | llvm::Triple::ArchType Arch = Triple.getArch(); |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3487 | std::string SysRoot = computeSysRoot(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3488 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3489 | // Cross-compiling binutils and GCC installations (vanilla and openSUSE at |
Chandler Carruth | d6c62b6 | 2013-06-20 23:37:54 +0000 | [diff] [blame] | 3490 | // least) put various tools in a triple-prefixed directory off of the parent |
| 3491 | // of the GCC installation. We use the GCC triple here to ensure that we end |
| 3492 | // up with tools that support the same amount of cross compiling as the |
| 3493 | // detected GCC installation. For example, if we find a GCC installation |
| 3494 | // targeting x86_64, but it is a bi-arch GCC installation, it can also be |
| 3495 | // used to target i386. |
| 3496 | // FIXME: This seems unlikely to be Linux-specific. |
Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3497 | ToolChain::path_list &PPaths = getProgramPaths(); |
Chandler Carruth | 4be70dd | 2011-11-06 09:21:54 +0000 | [diff] [blame] | 3498 | PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3499 | GCCInstallation.getTriple().str() + "/bin") |
| 3500 | .str()); |
Rafael Espindola | 5f344ff | 2011-09-01 16:25:49 +0000 | [diff] [blame] | 3501 | |
Logan Chien | eb9162f | 2014-06-26 14:23:45 +0000 | [diff] [blame] | 3502 | Linker = GetLinkerPath(); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3503 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3504 | Distro Distro = DetectDistro(D, Arch); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3505 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3506 | if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { |
Rafael Espindola | c568862 | 2010-11-08 14:48:47 +0000 | [diff] [blame] | 3507 | ExtraOpts.push_back("-z"); |
| 3508 | ExtraOpts.push_back("relro"); |
| 3509 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3510 | |
Douglas Gregor | d9bb152 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3511 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3512 | ExtraOpts.push_back("-X"); |
| 3513 | |
Evgeniy Stepanov | 14deb7b | 2015-10-08 21:21:44 +0000 | [diff] [blame] | 3514 | const bool IsAndroid = Triple.isAndroid(); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3515 | const bool IsMips = isMipsArch(Arch); |
| 3516 | |
| 3517 | if (IsMips && !SysRoot.empty()) |
| 3518 | ExtraOpts.push_back("--sysroot=" + SysRoot); |
Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3519 | |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3520 | // Do not use 'gnu' hash style for Mips targets because .gnu.hash |
| 3521 | // and the MIPS ABI require .dynsym to be sorted in different ways. |
| 3522 | // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS |
| 3523 | // ABI requires a mapping between the GOT and the symbol table. |
Evgeniy Stepanov | 2ca1aa5 | 2012-01-13 09:30:38 +0000 | [diff] [blame] | 3524 | // Android loader does not support .gnu.hash. |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3525 | if (!IsMips && !IsAndroid) { |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3526 | if (IsRedhat(Distro) || IsOpenSUSE(Distro) || |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3527 | (IsUbuntu(Distro) && Distro >= UbuntuMaverick)) |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3528 | ExtraOpts.push_back("--hash-style=gnu"); |
| 3529 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3530 | if (IsDebian(Distro) || IsOpenSUSE(Distro) || Distro == UbuntuLucid || |
Chandler Carruth | 0b84291 | 2011-12-09 04:45:18 +0000 | [diff] [blame] | 3531 | Distro == UbuntuJaunty || Distro == UbuntuKarmic) |
| 3532 | ExtraOpts.push_back("--hash-style=both"); |
| 3533 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3534 | |
Chris Lattner | 84e3855 | 2011-05-22 05:36:06 +0000 | [diff] [blame] | 3535 | if (IsRedhat(Distro)) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3536 | ExtraOpts.push_back("--no-add-needed"); |
| 3537 | |
Benjamin Kramer | 1a8fa8b | 2015-04-06 12:30:43 +0000 | [diff] [blame] | 3538 | if ((IsDebian(Distro) && Distro >= DebianSqueeze) || IsOpenSUSE(Distro) || |
Rafael Espindola | d8f92c8 | 2011-06-03 15:23:24 +0000 | [diff] [blame] | 3539 | (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || |
Benjamin Kramer | 7c3f09d | 2012-02-06 14:36:09 +0000 | [diff] [blame] | 3540 | (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3541 | ExtraOpts.push_back("--build-id"); |
| 3542 | |
Rafael Espindola | 10a63c2 | 2013-07-03 14:14:00 +0000 | [diff] [blame] | 3543 | if (IsOpenSUSE(Distro)) |
Chandler Carruth | e5d9d90 | 2011-05-24 07:51:17 +0000 | [diff] [blame] | 3544 | ExtraOpts.push_back("--enable-new-dtags"); |
Chris Lattner | d075c82 | 2011-05-22 16:45:07 +0000 | [diff] [blame] | 3545 | |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3546 | // The selection of paths to try here is designed to match the patterns which |
| 3547 | // the GCC driver itself uses, as this is part of the GCC-compatible driver. |
| 3548 | // This was determined by running GCC in a fake filesystem, creating all |
| 3549 | // possible permutations of these directories, and seeing which ones it added |
| 3550 | // to the link paths. |
| 3551 | path_list &Paths = getFilePaths(); |
Chandler Carruth | 6a4e8e3 | 2011-02-25 06:39:53 +0000 | [diff] [blame] | 3552 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3553 | const std::string OSLibDir = getOSLibDir(Triple, Args); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3554 | const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3555 | |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3556 | // Add the multilib suffixed paths where they are available. |
| 3557 | if (GCCInstallation.isValid()) { |
Chandler Carruth | 4d9d768 | 2012-01-24 19:28:29 +0000 | [diff] [blame] | 3558 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
Chandler Carruth | 96bae7b | 2012-01-24 20:08:17 +0000 | [diff] [blame] | 3559 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3560 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Simon Atanasyan | 53fefd1 | 2012-10-03 17:46:38 +0000 | [diff] [blame] | 3561 | |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3562 | // Sourcery CodeBench MIPS toolchain holds some libraries under |
Chandler Carruth | 9b6ce93 | 2013-10-29 02:27:56 +0000 | [diff] [blame] | 3563 | // a biarch-like suffix of the GCC installation. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3564 | addPathIfExists(D, GCCInstallation.getInstallPath() + Multilib.gccSuffix(), |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3565 | Paths); |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3566 | |
| 3567 | // GCC cross compiling toolchains will install target libraries which ship |
| 3568 | // as part of the toolchain under <prefix>/<triple>/<libdir> rather than as |
| 3569 | // any part of the GCC installation in |
| 3570 | // <prefix>/<libdir>/gcc/<triple>/<version>. This decision is somewhat |
| 3571 | // debatable, but is the reality today. We need to search this tree even |
| 3572 | // when we have a sysroot somewhere else. It is the responsibility of |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 3573 | // whomever is doing the cross build targeting a sysroot using a GCC |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3574 | // installation that is *not* within the system root to ensure two things: |
| 3575 | // |
| 3576 | // 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] | 3577 | // above must be present on the system root and found via an |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3578 | // appropriate rpath. |
| 3579 | // 2) There must not be libraries installed into |
| 3580 | // <prefix>/<triple>/<libdir> unless they should be preferred over |
| 3581 | // those within the system root. |
| 3582 | // |
| 3583 | // Note that this matches the GCC behavior. See the below comment for where |
| 3584 | // Clang diverges from GCC's behavior. |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3585 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" + |
| 3586 | OSLibDir + Multilib.osSuffix(), |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3587 | Paths); |
| 3588 | |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3589 | // If the GCC installation we found is inside of the sysroot, we want to |
| 3590 | // prefer libraries installed in the parent prefix of the GCC installation. |
| 3591 | // 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] | 3592 | // outside of the system root as that can pick up unintended libraries. |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3593 | // This usually happens when there is an external cross compiler on the |
| 3594 | // 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] | 3595 | // the cross. Note that GCC does include some of these directories in some |
| 3596 | // configurations but this seems somewhere between questionable and simply |
| 3597 | // a bug. |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3598 | if (StringRef(LibPath).startswith(SysRoot)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3599 | addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); |
| 3600 | addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3601 | } |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3602 | } |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3603 | |
| 3604 | // 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] | 3605 | // of the requested system root, add its parent library paths to |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3606 | // those searched. |
| 3607 | // FIXME: It's not clear whether we should use the driver's installed |
| 3608 | // directory ('Dir' below) or the ResourceDir. |
| 3609 | if (StringRef(D.Dir).startswith(SysRoot)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3610 | addPathIfExists(D, D.Dir + "/../lib/" + MultiarchTriple, Paths); |
| 3611 | addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3614 | addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); |
| 3615 | addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); |
| 3616 | addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); |
| 3617 | addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); |
Chandler Carruth | d0b93d6 | 2011-11-06 23:09:05 +0000 | [diff] [blame] | 3618 | |
Chandler Carruth | b427c56 | 2013-06-22 11:35:51 +0000 | [diff] [blame] | 3619 | // 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] | 3620 | // installations with strange symlinks. |
Rafael Espindola | b625016 | 2013-10-25 17:06:04 +0000 | [diff] [blame] | 3621 | if (GCCInstallation.isValid()) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3622 | addPathIfExists(D, |
| 3623 | SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3624 | "/../../" + OSLibDir, |
| 3625 | Paths); |
Rafael Espindola | 3049021 | 2011-06-03 15:39:42 +0000 | [diff] [blame] | 3626 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3627 | // Add the 'other' biarch variant path |
| 3628 | Multilib BiarchSibling; |
| 3629 | if (GCCInstallation.getBiarchSibling(BiarchSibling)) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3630 | addPathIfExists(D, GCCInstallation.getInstallPath() + |
| 3631 | BiarchSibling.gccSuffix(), |
| 3632 | Paths); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3633 | } |
Chandler Carruth | 69a125b | 2012-04-06 16:32:06 +0000 | [diff] [blame] | 3634 | |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3635 | // See comments above on the multilib variant for details of why this is |
| 3636 | // included even from outside the sysroot. |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3637 | const std::string &LibPath = GCCInstallation.getParentLibPath(); |
| 3638 | const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); |
| 3639 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3640 | addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib" + |
| 3641 | Multilib.osSuffix(), |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3642 | Paths); |
Chandler Carruth | 7f8042c | 2013-07-31 00:37:07 +0000 | [diff] [blame] | 3643 | |
| 3644 | // See comments above on the multilib variant for details of why this is |
| 3645 | // only included from within the sysroot. |
| 3646 | if (StringRef(LibPath).startswith(SysRoot)) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3647 | addPathIfExists(D, LibPath, Paths); |
Chandler Carruth | 413e5ac | 2011-10-03 05:28:29 +0000 | [diff] [blame] | 3648 | } |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3649 | |
| 3650 | // Similar to the logic for GCC above, if we are currently running Clang |
| 3651 | // inside of the requested system root, add its parent library path to those |
| 3652 | // searched. |
| 3653 | // FIXME: It's not clear whether we should use the driver's installed |
| 3654 | // directory ('Dir' below) or the ResourceDir. |
| 3655 | if (StringRef(D.Dir).startswith(SysRoot)) |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3656 | addPathIfExists(D, D.Dir + "/../lib", Paths); |
Chandler Carruth | 902efc6 | 2014-01-21 22:49:05 +0000 | [diff] [blame] | 3657 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3658 | addPathIfExists(D, SysRoot + "/lib", Paths); |
| 3659 | addPathIfExists(D, SysRoot + "/usr/lib", Paths); |
Rafael Espindola | c8f008f | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3660 | } |
| 3661 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3662 | bool Linux::HasNativeLLVMSupport() const { return true; } |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 3663 | |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3664 | Tool *Linux::buildLinker() const { return new tools::gnutools::Linker(*this); } |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 3665 | |
| 3666 | Tool *Linux::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 3667 | return new tools::gnutools::Assembler(*this); |
Rafael Espindola | 92b0093 | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3670 | std::string Linux::computeSysRoot() const { |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3671 | if (!getDriver().SysRoot.empty()) |
| 3672 | return getDriver().SysRoot; |
| 3673 | |
| 3674 | if (!GCCInstallation.isValid() || !isMipsArch(getTriple().getArch())) |
| 3675 | return std::string(); |
| 3676 | |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3677 | // Standalone MIPS toolchains use different names for sysroot folder |
| 3678 | // and put it into different places. Here we try to check some known |
| 3679 | // variants. |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3680 | |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3681 | const StringRef InstallDir = GCCInstallation.getInstallPath(); |
| 3682 | const StringRef TripleStr = GCCInstallation.getTriple().str(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3683 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3684 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3685 | std::string Path = |
| 3686 | (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix()) |
| 3687 | .str(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3688 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3689 | if (getVFS().exists(Path)) |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3690 | return Path; |
| 3691 | |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3692 | Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str(); |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3693 | |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3694 | if (getVFS().exists(Path)) |
Simon Atanasyan | a61b7ec | 2013-10-10 07:57:44 +0000 | [diff] [blame] | 3695 | return Path; |
| 3696 | |
| 3697 | return std::string(); |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3698 | } |
| 3699 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3700 | void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3701 | ArgStringList &CC1Args) const { |
| 3702 | const Driver &D = getDriver(); |
Simon Atanasyan | a0d8957 | 2013-10-05 14:37:55 +0000 | [diff] [blame] | 3703 | std::string SysRoot = computeSysRoot(); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3704 | |
| 3705 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 3706 | return; |
| 3707 | |
| 3708 | if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3709 | addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3710 | |
| 3711 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
Rafael Espindola | 358256c | 2013-06-26 02:13:00 +0000 | [diff] [blame] | 3712 | SmallString<128> P(D.ResourceDir); |
| 3713 | llvm::sys::path::append(P, "include"); |
Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3714 | addSystemInclude(DriverArgs, CC1Args, P); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3718 | return; |
| 3719 | |
| 3720 | // Check for configure-time C include directories. |
| 3721 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 3722 | if (CIncludeDirs != "") { |
| 3723 | SmallVector<StringRef, 5> dirs; |
| 3724 | CIncludeDirs.split(dirs, ":"); |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3725 | for (StringRef dir : dirs) { |
Benjamin Kramer | 33cd6dc | 2015-02-18 18:45:54 +0000 | [diff] [blame] | 3726 | StringRef Prefix = |
| 3727 | llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3728 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3729 | } |
| 3730 | return; |
| 3731 | } |
| 3732 | |
| 3733 | // Lacking those, try to detect the correct set of system includes for the |
| 3734 | // target triple. |
| 3735 | |
Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3736 | // Add include directories specific to the selected multilib set and multilib. |
| 3737 | if (GCCInstallation.isValid()) { |
Benjamin Kramer | ac75baa | 2015-03-22 15:56:12 +0000 | [diff] [blame] | 3738 | const auto &Callback = Multilibs.includeDirsCallback(); |
Simon Atanasyan | 9e49e14 | 2014-08-06 05:44:47 +0000 | [diff] [blame] | 3739 | if (Callback) { |
| 3740 | const auto IncludePaths = Callback(GCCInstallation.getInstallPath(), |
| 3741 | GCCInstallation.getTriple().str(), |
| 3742 | GCCInstallation.getMultilib()); |
| 3743 | for (const auto &Path : IncludePaths) |
| 3744 | addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); |
| 3745 | } |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3746 | } |
| 3747 | |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3748 | // Implement generic Debian multiarch support. |
| 3749 | const StringRef X86_64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3750 | "/usr/include/x86_64-linux-gnu", |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3751 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3752 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 3753 | // in use in any released version of Debian, so we should consider |
| 3754 | // removing them. |
| 3755 | "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3756 | const StringRef X86MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3757 | "/usr/include/i386-linux-gnu", |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3758 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3759 | // FIXME: These are older forms of multiarch. It's not clear that they're |
| 3760 | // in use in any released version of Debian, so we should consider |
| 3761 | // removing them. |
| 3762 | "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu", |
| 3763 | "/usr/include/i486-linux-gnu"}; |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3764 | const StringRef AArch64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3765 | "/usr/include/aarch64-linux-gnu"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3766 | const StringRef ARMMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3767 | "/usr/include/arm-linux-gnueabi"}; |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3768 | const StringRef ARMHFMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3769 | "/usr/include/arm-linux-gnueabihf"}; |
| 3770 | const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3771 | const StringRef MIPSELMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3772 | "/usr/include/mipsel-linux-gnu"}; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3773 | const StringRef MIPS64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3774 | "/usr/include/mips64-linux-gnu", "/usr/include/mips64-linux-gnuabi64"}; |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3775 | const StringRef MIPS64ELMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3776 | "/usr/include/mips64el-linux-gnu", |
| 3777 | "/usr/include/mips64el-linux-gnuabi64"}; |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3778 | const StringRef PPCMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3779 | "/usr/include/powerpc-linux-gnu"}; |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3780 | const StringRef PPC64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3781 | "/usr/include/powerpc64-linux-gnu"}; |
Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 3782 | const StringRef PPC64LEMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3783 | "/usr/include/powerpc64le-linux-gnu"}; |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3784 | const StringRef SparcMultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3785 | "/usr/include/sparc-linux-gnu"}; |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3786 | const StringRef Sparc64MultiarchIncludeDirs[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3787 | "/usr/include/sparc64-linux-gnu"}; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3788 | const StringRef SYSTEMZMultiarchIncludeDirs[] = { |
| 3789 | "/usr/include/s390x-linux-gnu"}; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3790 | ArrayRef<StringRef> MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3791 | switch (getTriple().getArch()) { |
| 3792 | case llvm::Triple::x86_64: |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3793 | MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3794 | break; |
| 3795 | case llvm::Triple::x86: |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3796 | MultiarchIncludeDirs = X86MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3797 | break; |
| 3798 | case llvm::Triple::aarch64: |
| 3799 | case llvm::Triple::aarch64_be: |
Tim Northover | 9bb857a | 2013-01-31 12:13:10 +0000 | [diff] [blame] | 3800 | MultiarchIncludeDirs = AArch64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3801 | break; |
| 3802 | case llvm::Triple::arm: |
Jiangning Liu | 61b06cb | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 3803 | if (getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 3804 | MultiarchIncludeDirs = ARMHFMultiarchIncludeDirs; |
| 3805 | else |
| 3806 | MultiarchIncludeDirs = ARMMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3807 | break; |
| 3808 | case llvm::Triple::mips: |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3809 | MultiarchIncludeDirs = MIPSMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3810 | break; |
| 3811 | case llvm::Triple::mipsel: |
Eli Friedman | 7771c83 | 2011-11-11 03:05:19 +0000 | [diff] [blame] | 3812 | MultiarchIncludeDirs = MIPSELMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3813 | break; |
| 3814 | case llvm::Triple::mips64: |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3815 | MultiarchIncludeDirs = MIPS64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3816 | break; |
| 3817 | case llvm::Triple::mips64el: |
Simon Atanasyan | 3a46afa | 2014-06-24 19:00:12 +0000 | [diff] [blame] | 3818 | MultiarchIncludeDirs = MIPS64ELMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3819 | break; |
| 3820 | case llvm::Triple::ppc: |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3821 | MultiarchIncludeDirs = PPCMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3822 | break; |
| 3823 | case llvm::Triple::ppc64: |
Chandler Carruth | 2e9d731 | 2012-02-26 09:21:43 +0000 | [diff] [blame] | 3824 | MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3825 | break; |
| 3826 | case llvm::Triple::ppc64le: |
Ulrich Weigand | a8331b9 | 2014-06-20 13:41:24 +0000 | [diff] [blame] | 3827 | MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3828 | break; |
| 3829 | case llvm::Triple::sparc: |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3830 | MultiarchIncludeDirs = SparcMultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3831 | break; |
| 3832 | case llvm::Triple::sparcv9: |
James Y Knight | 09677ad | 2015-06-05 13:44:43 +0000 | [diff] [blame] | 3833 | MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3834 | break; |
Sylvestre Ledru | c0babf2 | 2015-08-28 12:26:09 +0000 | [diff] [blame] | 3835 | case llvm::Triple::systemz: |
| 3836 | MultiarchIncludeDirs = SYSTEMZMultiarchIncludeDirs; |
| 3837 | break; |
Douglas Katzman | 7e37afb | 2015-06-23 03:02:39 +0000 | [diff] [blame] | 3838 | default: |
| 3839 | break; |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3840 | } |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3841 | for (StringRef Dir : MultiarchIncludeDirs) { |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3842 | if (D.getVFS().exists(SysRoot + Dir)) { |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3843 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir); |
Chandler Carruth | 5b77c6c | 2011-11-06 08:21:07 +0000 | [diff] [blame] | 3844 | break; |
| 3845 | } |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | if (getTriple().getOS() == llvm::Triple::RTEMS) |
| 3849 | return; |
| 3850 | |
Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 3851 | // Add an include of '/include' directly. This isn't provided by default by |
| 3852 | // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 3853 | // 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] | 3854 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); |
Chandler Carruth | 475ab6a | 2011-11-08 17:19:47 +0000 | [diff] [blame] | 3855 | |
Simon Atanasyan | 08450bd | 2013-04-20 08:15:03 +0000 | [diff] [blame] | 3856 | addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 3859 | |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 3860 | static std::string DetectLibcxxIncludePath(StringRef base) { |
| 3861 | std::error_code EC; |
| 3862 | int MaxVersion = 0; |
| 3863 | std::string MaxVersionString = ""; |
| 3864 | for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE; |
| 3865 | LI = LI.increment(EC)) { |
| 3866 | StringRef VersionText = llvm::sys::path::filename(LI->path()); |
| 3867 | int Version; |
| 3868 | if (VersionText[0] == 'v' && |
| 3869 | !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) { |
| 3870 | if (Version > MaxVersion) { |
| 3871 | MaxVersion = Version; |
| 3872 | MaxVersionString = VersionText; |
| 3873 | } |
| 3874 | } |
| 3875 | } |
| 3876 | return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; |
| 3877 | } |
| 3878 | |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3879 | void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3880 | ArgStringList &CC1Args) const { |
| 3881 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3882 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3883 | return; |
| 3884 | |
Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 3885 | // Check if libc++ has been enabled and provide its include paths if so. |
| 3886 | if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3887 | const std::string LibCXXIncludePathCandidates[] = { |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 3888 | DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3889 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3890 | // We also check the system as for a long time this is the only place |
| 3891 | // Clang looked. |
| 3892 | // FIXME: We should really remove this. It doesn't make any sense. |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 3893 | DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++")}; |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3894 | for (const auto &IncludePath : LibCXXIncludePathCandidates) { |
Evgeniy Stepanov | 65bc2b1 | 2015-11-09 21:10:54 +0000 | [diff] [blame] | 3895 | if (IncludePath.empty() || !getVFS().exists(IncludePath)) |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3896 | continue; |
| 3897 | // Add the first candidate that exists. |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3898 | addSystemInclude(DriverArgs, CC1Args, IncludePath); |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3899 | break; |
| 3900 | } |
Chandler Carruth | f470173 | 2011-11-07 09:01:17 +0000 | [diff] [blame] | 3901 | return; |
| 3902 | } |
| 3903 | |
Chandler Carruth | a1f1fd3 | 2012-01-25 08:04:13 +0000 | [diff] [blame] | 3904 | // We need a detected GCC installation on Linux to provide libstdc++'s |
| 3905 | // headers. We handled the libc++ case above. |
| 3906 | if (!GCCInstallation.isValid()) |
| 3907 | return; |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3908 | |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 3909 | // By default, look for the C++ headers in an include directory adjacent to |
| 3910 | // the lib directory of the GCC installation. Note that this is expect to be |
| 3911 | // equivalent to '/usr/include/c++/X.Y' in almost all cases. |
| 3912 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 3913 | StringRef InstallDir = GCCInstallation.getInstallPath(); |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 3914 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3915 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3916 | const std::string GCCMultiarchTriple = getMultiarchTriple( |
| 3917 | getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot); |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 3918 | const std::string TargetMultiarchTriple = |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 3919 | getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); |
Chandler Carruth | 1f2b2f8 | 2013-08-26 08:59:53 +0000 | [diff] [blame] | 3920 | const GCCVersion &Version = GCCInstallation.getVersion(); |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 3921 | |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 3922 | // The primary search for libstdc++ supports multiarch variants. |
Chandler Carruth | 8677d92 | 2013-10-29 08:53:03 +0000 | [diff] [blame] | 3923 | if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3924 | "/c++/" + Version.Text, TripleStr, |
| 3925 | GCCMultiarchTriple, TargetMultiarchTriple, |
Jonathan Roelofs | 2cea1be | 2014-02-12 03:21:20 +0000 | [diff] [blame] | 3926 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
Dmitri Gribenko | 15225ae | 2013-03-06 17:14:05 +0000 | [diff] [blame] | 3927 | return; |
| 3928 | |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 3929 | // Otherwise, fall back on a bunch of options which don't use multiarch |
| 3930 | // layouts for simplicity. |
Chandler Carruth | 5a3d898 | 2014-01-20 09:42:24 +0000 | [diff] [blame] | 3931 | const std::string LibStdCXXIncludePathCandidates[] = { |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3932 | // Gentoo is weird and places its headers inside the GCC install, |
| 3933 | // so if the first attempt to find the headers fails, try these patterns. |
| 3934 | InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + |
| 3935 | Version.MinorStr, |
| 3936 | InstallDir.str() + "/include/g++-v" + Version.MajorStr, |
| 3937 | // Android standalone toolchain has C++ headers in yet another place. |
| 3938 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 3939 | // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++, |
| 3940 | // without a subdirectory corresponding to the gcc version. |
| 3941 | LibDir.str() + "/../include/c++", |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 3942 | }; |
| 3943 | |
Simon Atanasyan | 6f657c4 | 2014-05-08 19:32:46 +0000 | [diff] [blame] | 3944 | for (const auto &IncludePath : LibStdCXXIncludePathCandidates) { |
Chandler Carruth | c44f4d4 | 2014-08-27 08:41:41 +0000 | [diff] [blame] | 3945 | if (addLibStdCXXIncludePaths(IncludePath, /*Suffix*/ "", TripleStr, |
| 3946 | /*GCCMultiarchTriple*/ "", |
| 3947 | /*TargetMultiarchTriple*/ "", |
| 3948 | Multilib.includeSuffix(), DriverArgs, CC1Args)) |
Evgeniy Stepanov | 763671e | 2012-09-03 09:05:50 +0000 | [diff] [blame] | 3949 | break; |
Chandler Carruth | f5d4df9 | 2011-11-06 10:31:01 +0000 | [diff] [blame] | 3950 | } |
Chandler Carruth | a796f53 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3953 | bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } |
Peter Collingbourne | 54d770c | 2013-04-09 04:35:11 +0000 | [diff] [blame] | 3954 | |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3955 | SanitizerMask Linux::getSupportedSanitizers() const { |
| 3956 | const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; |
| 3957 | const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; |
| 3958 | const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || |
| 3959 | getTriple().getArch() == llvm::Triple::mips64el; |
Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 3960 | const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 || |
| 3961 | getTriple().getArch() == llvm::Triple::ppc64le; |
Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 3962 | const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 || |
| 3963 | getTriple().getArch() == llvm::Triple::aarch64_be; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3964 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 3965 | Res |= SanitizerKind::Address; |
| 3966 | Res |= SanitizerKind::KernelAddress; |
| 3967 | Res |= SanitizerKind::Vptr; |
Evgeniy Stepanov | 299238a | 2015-09-24 17:22:46 +0000 | [diff] [blame] | 3968 | Res |= SanitizerKind::SafeStack; |
Adhemerval Zanella | 76aee67 | 2015-07-30 20:50:39 +0000 | [diff] [blame] | 3969 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3970 | Res |= SanitizerKind::DataFlow; |
Adhemerval Zanella | bffb20d | 2015-10-05 19:16:42 +0000 | [diff] [blame] | 3971 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3972 | Res |= SanitizerKind::Leak; |
Renato Golin | d45c2df | 2015-08-05 18:42:41 +0000 | [diff] [blame] | 3973 | if (IsX86_64 || IsMIPS64 || IsAArch64) |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3974 | Res |= SanitizerKind::Thread; |
Adhemerval Zanella | 567b926 | 2015-09-16 15:11:21 +0000 | [diff] [blame] | 3975 | if (IsX86_64 || IsMIPS64 || IsPowerPC64 || IsAArch64) |
Jay Foad | e967dd0 | 2015-06-25 10:35:19 +0000 | [diff] [blame] | 3976 | Res |= SanitizerKind::Memory; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3977 | if (IsX86 || IsX86_64) { |
| 3978 | Res |= SanitizerKind::Function; |
Alexey Samsonov | 7f2a0d2 | 2015-06-19 21:36:47 +0000 | [diff] [blame] | 3979 | } |
| 3980 | return Res; |
| 3981 | } |
| 3982 | |
Xinliang David Li | 170cd10 | 2015-10-27 05:15:35 +0000 | [diff] [blame] | 3983 | void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, |
| 3984 | llvm::opt::ArgStringList &CmdArgs) const { |
| 3985 | if (!needsProfileRT(Args)) return; |
| 3986 | |
| 3987 | // Add linker option -u__llvm_runtime_variable to cause runtime |
| 3988 | // initialization module to be linked in. |
| 3989 | if (!Args.hasArg(options::OPT_coverage)) |
| 3990 | CmdArgs.push_back(Args.MakeArgString( |
| 3991 | Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); |
| 3992 | ToolChain::addProfileRTLibs(Args, CmdArgs); |
| 3993 | } |
| 3994 | |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3995 | /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. |
| 3996 | |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 3997 | DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, |
| 3998 | const ArgList &Args) |
| 3999 | : Generic_ELF(D, Triple, Args) { |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4000 | |
| 4001 | // Path mangling to find libexec |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4002 | getProgramPaths().push_back(getDriver().getInstalledDir()); |
Benjamin Kramer | 51477bd | 2011-03-01 22:50:47 +0000 | [diff] [blame] | 4003 | if (getDriver().getInstalledDir() != getDriver().Dir) |
Daniel Dunbar | 8897991 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 4004 | getProgramPaths().push_back(getDriver().Dir); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4005 | |
Daniel Dunbar | 083edf7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4006 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4007 | getFilePaths().push_back("/usr/lib"); |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4008 | if (D.getVFS().exists("/usr/lib/gcc47")) |
John McCall | 65b8da0 | 2013-04-11 22:55:55 +0000 | [diff] [blame] | 4009 | getFilePaths().push_back("/usr/lib/gcc47"); |
| 4010 | else |
| 4011 | getFilePaths().push_back("/usr/lib/gcc44"); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4012 | } |
| 4013 | |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4014 | Tool *DragonFly::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4015 | return new tools::dragonfly::Assembler(*this); |
Rafael Espindola | 7cf3221 | 2013-03-20 03:05:54 +0000 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | Tool *DragonFly::buildLinker() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4019 | return new tools::dragonfly::Linker(*this); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4020 | } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4021 | |
Artem Belevich | 0ff05cd | 2015-07-13 23:27:56 +0000 | [diff] [blame] | 4022 | /// Stub for CUDA toolchain. At the moment we don't have assembler or |
| 4023 | /// linker and need toolchain mainly to propagate device-side options |
| 4024 | /// to CC1. |
| 4025 | |
| 4026 | CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4027 | const ArgList &Args) |
| 4028 | : Linux(D, Triple, Args) {} |
| 4029 | |
| 4030 | void |
| 4031 | CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, |
| 4032 | llvm::opt::ArgStringList &CC1Args) const { |
| 4033 | Linux::addClangTargetOptions(DriverArgs, CC1Args); |
| 4034 | CC1Args.push_back("-fcuda-is-device"); |
| 4035 | } |
| 4036 | |
| 4037 | llvm::opt::DerivedArgList * |
| 4038 | CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, |
| 4039 | const char *BoundArch) const { |
| 4040 | DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); |
| 4041 | const OptTable &Opts = getDriver().getOpts(); |
| 4042 | |
| 4043 | for (Arg *A : Args) { |
| 4044 | if (A->getOption().matches(options::OPT_Xarch__)) { |
| 4045 | // Skip this argument unless the architecture matches BoundArch |
| 4046 | if (A->getValue(0) != StringRef(BoundArch)) |
| 4047 | continue; |
| 4048 | |
| 4049 | unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1)); |
| 4050 | unsigned Prev = Index; |
| 4051 | std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index)); |
| 4052 | |
| 4053 | // If the argument parsing failed or more than one argument was |
| 4054 | // consumed, the -Xarch_ argument's parameter tried to consume |
| 4055 | // extra arguments. Emit an error and ignore. |
| 4056 | // |
| 4057 | // We also want to disallow any options which would alter the |
| 4058 | // driver behavior; that isn't going to work in our model. We |
| 4059 | // use isDriverOption() as an approximation, although things |
| 4060 | // like -O4 are going to slip through. |
| 4061 | if (!XarchArg || Index > Prev + 1) { |
| 4062 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) |
| 4063 | << A->getAsString(Args); |
| 4064 | continue; |
| 4065 | } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { |
| 4066 | getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) |
| 4067 | << A->getAsString(Args); |
| 4068 | continue; |
| 4069 | } |
| 4070 | XarchArg->setBaseArg(A); |
| 4071 | A = XarchArg.release(); |
| 4072 | DAL->AddSynthesizedArg(A); |
| 4073 | } |
| 4074 | DAL->append(A); |
| 4075 | } |
| 4076 | |
| 4077 | DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch); |
| 4078 | return DAL; |
| 4079 | } |
| 4080 | |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4081 | /// XCore tool chain |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4082 | XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4083 | const ArgList &Args) |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4084 | : ToolChain(D, Triple, Args) { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4085 | // ProgramPaths are found via 'PATH' environment variable. |
| 4086 | } |
| 4087 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4088 | Tool *XCoreToolChain::buildAssembler() const { |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4089 | return new tools::XCore::Assembler(*this); |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4090 | } |
| 4091 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4092 | Tool *XCoreToolChain::buildLinker() const { |
| 4093 | return new tools::XCore::Linker(*this); |
| 4094 | } |
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::isPICDefault() 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 | bool XCoreToolChain::isPIEDefault() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4099 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4100 | bool XCoreToolChain::isPICDefaultForced() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4101 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4102 | bool XCoreToolChain::SupportsProfiling() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4103 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4104 | bool XCoreToolChain::hasBlocksRuntime() const { return false; } |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4105 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4106 | void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4107 | ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4108 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
| 4109 | DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 4110 | return; |
| 4111 | if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) { |
| 4112 | SmallVector<StringRef, 4> Dirs; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4113 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4114 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4115 | ArrayRef<StringRef> DirVec(Dirs); |
| 4116 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4117 | } |
| 4118 | } |
| 4119 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4120 | void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs, |
| 4121 | ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4122 | CC1Args.push_back("-nostdsysteminc"); |
| 4123 | } |
| 4124 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4125 | void XCoreToolChain::AddClangCXXStdlibIncludeArgs( |
| 4126 | const ArgList &DriverArgs, ArgStringList &CC1Args) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4127 | if (DriverArgs.hasArg(options::OPT_nostdinc) || |
Robert Lytton | f9710b3 | 2014-08-01 13:11:46 +0000 | [diff] [blame] | 4128 | DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4129 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4130 | return; |
| 4131 | if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) { |
| 4132 | SmallVector<StringRef, 4> Dirs; |
Douglas Katzman | a67e50c | 2015-06-26 15:47:46 +0000 | [diff] [blame] | 4133 | const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'}; |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4134 | StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); |
| 4135 | ArrayRef<StringRef> DirVec(Dirs); |
| 4136 | addSystemIncludes(DriverArgs, CC1Args, DirVec); |
| 4137 | } |
| 4138 | } |
| 4139 | |
Douglas Katzman | 5436607 | 2015-07-27 16:53:08 +0000 | [diff] [blame] | 4140 | void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 4141 | ArgStringList &CmdArgs) const { |
Robert Lytton | cf1dd69 | 2013-10-11 10:29:40 +0000 | [diff] [blame] | 4142 | // We don't output any lib args. This is handled by xcc. |
| 4143 | } |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4144 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4145 | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, |
| 4146 | const ArgList &Args) |
| 4147 | : Generic_GCC(D, Triple, Args) { |
| 4148 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use |
| 4149 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. |
| 4150 | // This won't work to find gcc. Instead we give the installation detector an |
| 4151 | // extra triple, which is preferable to further hacks of the logic that at |
| 4152 | // present is based solely on getArch(). In particular, it would be wrong to |
| 4153 | // choose the myriad installation when targeting a non-myriad sparc install. |
| 4154 | switch (Triple.getArch()) { |
| 4155 | default: |
| 4156 | D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() << "myriad"; |
| 4157 | case llvm::Triple::sparc: |
| 4158 | case llvm::Triple::sparcel: |
| 4159 | case llvm::Triple::shave: |
Benjamin Kramer | d45b205 | 2015-10-07 15:48:01 +0000 | [diff] [blame] | 4160 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4164 | MyriadToolChain::~MyriadToolChain() {} |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4165 | |
Douglas Katzman | b1278f3 | 2015-09-17 21:20:16 +0000 | [diff] [blame] | 4166 | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 4167 | ArgStringList &CC1Args) const { |
| 4168 | if (!DriverArgs.hasArg(options::OPT_nostdinc)) |
| 4169 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
| 4170 | } |
| 4171 | |
James Y Knight | a6c9ee7 | 2015-10-16 18:46:26 +0000 | [diff] [blame] | 4172 | void MyriadToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 4173 | ArgStringList &CC1Args) const { |
| 4174 | if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 4175 | DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 4176 | return; |
| 4177 | |
| 4178 | // Only libstdc++, for now. |
| 4179 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
| 4180 | const GCCVersion &Version = GCCInstallation.getVersion(); |
| 4181 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
| 4182 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
| 4183 | |
| 4184 | addLibStdCXXIncludePaths(LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
| 4185 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); |
| 4186 | } |
| 4187 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4188 | // MyriadToolChain handles several triples: |
| 4189 | // {shave,sparc{,el}}-myriad-{rtems,unknown}-elf |
| 4190 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { |
| 4191 | // The inherited method works fine if not targeting the SHAVE. |
| 4192 | if (!isShaveCompilation(getTriple())) |
| 4193 | return ToolChain::SelectTool(JA); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4194 | switch (JA.getKind()) { |
| 4195 | case Action::CompileJobClass: |
| 4196 | if (!Compiler) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4197 | Compiler.reset(new tools::SHAVE::Compiler(*this)); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4198 | return Compiler.get(); |
| 4199 | case Action::AssembleJobClass: |
| 4200 | if (!Assembler) |
Douglas Katzman | 9535429 | 2015-06-23 20:42:09 +0000 | [diff] [blame] | 4201 | Assembler.reset(new tools::SHAVE::Assembler(*this)); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4202 | return Assembler.get(); |
| 4203 | default: |
| 4204 | return ToolChain::getTool(JA.getKind()); |
| 4205 | } |
| 4206 | } |
| 4207 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4208 | void MyriadToolChain::getCompilerSupportDir(std::string &Dir) const { |
| 4209 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. |
| 4210 | // These files are tied to a particular version of gcc. |
| 4211 | SmallString<128> Result(GCCInstallation.getInstallPath()); |
| 4212 | // There are actually 4 choices: {le,be} x {fpu,nofpu} |
| 4213 | // but as this toolchain is for LEON sparc, it can assume FPU. |
| 4214 | if (this->getTriple().getArch() == llvm::Triple::sparcel) |
| 4215 | llvm::sys::path::append(Result, "le"); |
| 4216 | Dir.assign(Result.str()); |
| 4217 | } |
| 4218 | void MyriadToolChain::getBuiltinLibDir(std::string &Dir) const { |
| 4219 | // The contents of LibDir are independent of the version of gcc. |
| 4220 | // This contains libc, libg (a superset of libc), libm, libstdc++, libssp. |
| 4221 | SmallString<128> Result(GCCInstallation.getParentLibPath()); |
| 4222 | if (this->getTriple().getArch() == llvm::Triple::sparcel) |
| 4223 | llvm::sys::path::append(Result, "../sparc-myriad-elf/lib/le"); |
| 4224 | else |
| 4225 | llvm::sys::path::append(Result, "../sparc-myriad-elf/lib"); |
| 4226 | Dir.assign(Result.str()); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
Douglas Katzman | d6e597c | 2015-09-17 19:56:40 +0000 | [diff] [blame] | 4229 | Tool *MyriadToolChain::buildLinker() const { |
| 4230 | return new tools::Myriad::Linker(*this); |
Douglas Katzman | 84a7564 | 2015-06-19 14:55:19 +0000 | [diff] [blame] | 4231 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 4232 | |
| 4233 | bool WebAssembly::IsMathErrnoDefault() const { return false; } |
| 4234 | |
| 4235 | bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } |
| 4236 | |
| 4237 | bool WebAssembly::UseObjCMixedDispatch() const { return true; } |
| 4238 | |
| 4239 | bool WebAssembly::isPICDefault() const { return false; } |
| 4240 | |
| 4241 | bool WebAssembly::isPIEDefault() const { return false; } |
| 4242 | |
| 4243 | bool WebAssembly::isPICDefaultForced() const { return false; } |
| 4244 | |
| 4245 | bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } |
| 4246 | |
| 4247 | // TODO: Support Objective C stuff. |
| 4248 | bool WebAssembly::SupportsObjCGC() const { return false; } |
| 4249 | |
| 4250 | bool WebAssembly::hasBlocksRuntime() const { return false; } |
| 4251 | |
| 4252 | // TODO: Support profiling. |
| 4253 | bool WebAssembly::SupportsProfiling() const { return false; } |
| 4254 | |
| 4255 | void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs, |
| 4256 | ArgStringList &CC1Args) const { |
| 4257 | if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 4258 | options::OPT_fno_use_init_array, true)) |
| 4259 | CC1Args.push_back("-fuse-init-array"); |
| 4260 | } |
Filipe Cabecinhas | c888e19 | 2015-10-14 12:25:43 +0000 | [diff] [blame] | 4261 | |
| 4262 | PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 4263 | : Generic_ELF(D, Triple, Args) { |
| 4264 | if (Args.hasArg(options::OPT_static)) |
| 4265 | D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4"; |
| 4266 | |
| 4267 | // Determine where to find the PS4 libraries. We use SCE_PS4_SDK_DIR |
| 4268 | // if it exists; otherwise use the driver's installation path, which |
| 4269 | // should be <SDK_DIR>/host_tools/bin. |
| 4270 | |
| 4271 | SmallString<512> PS4SDKDir; |
| 4272 | if (const char *EnvValue = getenv("SCE_PS4_SDK_DIR")) { |
| 4273 | if (!llvm::sys::fs::exists(EnvValue)) |
| 4274 | getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue; |
| 4275 | PS4SDKDir = EnvValue; |
| 4276 | } else { |
| 4277 | PS4SDKDir = getDriver().Dir; |
| 4278 | llvm::sys::path::append(PS4SDKDir, "/../../"); |
| 4279 | } |
| 4280 | |
| 4281 | // By default, the driver won't report a warning if it can't find |
| 4282 | // PS4's include or lib directories. This behavior could be changed if |
| 4283 | // -Weverything or -Winvalid-or-nonexistent-directory options are passed. |
| 4284 | // If -isysroot was passed, use that as the SDK base path. |
| 4285 | std::string PrefixDir; |
| 4286 | if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 4287 | PrefixDir = A->getValue(); |
| 4288 | if (!llvm::sys::fs::exists(PrefixDir)) |
| 4289 | getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir; |
| 4290 | } else |
| 4291 | PrefixDir = PS4SDKDir.str(); |
| 4292 | |
| 4293 | SmallString<512> PS4SDKIncludeDir(PrefixDir); |
| 4294 | llvm::sys::path::append(PS4SDKIncludeDir, "target/include"); |
| 4295 | if (!Args.hasArg(options::OPT_nostdinc) && |
| 4296 | !Args.hasArg(options::OPT_nostdlibinc) && |
| 4297 | !Args.hasArg(options::OPT_isysroot) && |
| 4298 | !Args.hasArg(options::OPT__sysroot_EQ) && |
| 4299 | !llvm::sys::fs::exists(PS4SDKIncludeDir)) { |
| 4300 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 4301 | << "PS4 system headers" << PS4SDKIncludeDir; |
| 4302 | } |
| 4303 | |
| 4304 | SmallString<512> PS4SDKLibDir(PS4SDKDir); |
| 4305 | llvm::sys::path::append(PS4SDKLibDir, "target/lib"); |
| 4306 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4307 | !Args.hasArg(options::OPT_nodefaultlibs) && |
| 4308 | !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) && |
| 4309 | !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) && |
| 4310 | !Args.hasArg(options::OPT_emit_ast) && |
| 4311 | !llvm::sys::fs::exists(PS4SDKLibDir)) { |
| 4312 | getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected) |
| 4313 | << "PS4 system libraries" << PS4SDKLibDir; |
| 4314 | return; |
| 4315 | } |
| 4316 | getFilePaths().push_back(PS4SDKLibDir.str()); |
| 4317 | } |
| 4318 | |
| 4319 | Tool *PS4CPU::buildAssembler() const { |
| 4320 | return new tools::PS4cpu::Assemble(*this); |
| 4321 | } |
| 4322 | |
| 4323 | Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); } |
| 4324 | |
| 4325 | bool PS4CPU::isPICDefault() const { return true; } |
| 4326 | |
| 4327 | bool PS4CPU::HasNativeLLVMSupport() const { return true; } |
| 4328 | |
| 4329 | SanitizerMask PS4CPU::getSupportedSanitizers() const { |
| 4330 | SanitizerMask Res = ToolChain::getSupportedSanitizers(); |
| 4331 | Res |= SanitizerKind::Address; |
| 4332 | Res |= SanitizerKind::Vptr; |
| 4333 | return Res; |
| 4334 | } |