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