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