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