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