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