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