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