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