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