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