diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Driver/ToolChains.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Driver/ToolChains.cpp | 494 |
1 files changed, 373 insertions, 121 deletions
diff --git a/contrib/llvm/tools/clang/lib/Driver/ToolChains.cpp b/contrib/llvm/tools/clang/lib/Driver/ToolChains.cpp index 8bd8298..115a16f 100644 --- a/contrib/llvm/tools/clang/lib/Driver/ToolChains.cpp +++ b/contrib/llvm/tools/clang/lib/Driver/ToolChains.cpp @@ -29,6 +29,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" +#include "llvm/Support/TargetParser.h" #include "llvm/Support/raw_ostream.h" #include <cstdlib> // ::getenv #include <system_error> @@ -108,8 +109,12 @@ bool Darwin::hasBlocksRuntime() const { } } -static const char *GetArmArchForMArch(StringRef Value) { - return llvm::StringSwitch<const char*>(Value) +// This is just a MachO name translation routine and there's no +// way to join this into ARMTargetParser without breaking all +// other assumptions. Maybe MachO should consider standardising +// their nomenclature. +static const char *ArmMachOArchName(StringRef Arch) { + return llvm::StringSwitch<const char*>(Arch) .Case("armv6k", "armv6") .Case("armv6m", "armv6m") .Case("armv5tej", "armv5") @@ -125,21 +130,23 @@ static const char *GetArmArchForMArch(StringRef Value) { .Default(nullptr); } -static const char *GetArmArchForMCpu(StringRef Value) { - return llvm::StringSwitch<const char *>(Value) - .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "arm926ej-s","armv5") - .Cases("arm10e", "arm10tdmi", "armv5") - .Cases("arm1020t", "arm1020e", "arm1022e", "arm1026ej-s", "armv5") - .Case("xscale", "xscale") - .Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "arm1176jzf-s", "armv6") - .Case("cortex-m0", "armv6m") - .Cases("cortex-a5", "cortex-a7", "cortex-a8", "armv7") - .Cases("cortex-a9", "cortex-a12", "cortex-a15", "cortex-a17", "krait", "armv7") - .Cases("cortex-r4", "cortex-r5", "armv7r") - .Case("cortex-m3", "armv7m") - .Cases("cortex-m4", "cortex-m7", "armv7em") - .Case("swift", "armv7s") - .Default(nullptr); +static const char *ArmMachOArchNameCPU(StringRef CPU) { + unsigned ArchKind = llvm::ARMTargetParser::parseCPUArch(CPU); + if (ArchKind == llvm::ARM::AK_INVALID) + return nullptr; + StringRef Arch = llvm::ARMTargetParser::getArchName(ArchKind); + + // FIXME: Make sure this MachO triple mangling is really necessary. + // ARMv5* normalises to ARMv5. + if (Arch.startswith("armv5")) + Arch = Arch.substr(0, 5); + // ARMv6*, except ARMv6M, normalises to ARMv6. + else if (Arch.startswith("armv6") && !Arch.endswith("6m")) + Arch = Arch.substr(0, 5); + // ARMv7A normalises to ARMv7. + else if (Arch.endswith("v7a")) + Arch = Arch.substr(0, 5); + return Arch.data(); } static bool isSoftFloatABI(const ArgList &Args) { @@ -164,11 +171,11 @@ StringRef MachO::getMachOArchName(const ArgList &Args) const { case llvm::Triple::thumb: case llvm::Triple::arm: { if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) - if (const char *Arch = GetArmArchForMArch(A->getValue())) + if (const char *Arch = ArmMachOArchName(A->getValue())) return Arch; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) - if (const char *Arch = GetArmArchForMCpu(A->getValue())) + if (const char *Arch = ArmMachOArchNameCPU(A->getValue())) return Arch; return "arm"; @@ -302,8 +309,8 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, // For now, allow missing resource libraries to support developers who may // not have compiler-rt checked out or integrated into their build (unless // we explicitly force linking with this library). - if (AlwaysLink || llvm::sys::fs::exists(P.str())) - CmdArgs.push_back(Args.MakeArgString(P.str())); + if (AlwaysLink || llvm::sys::fs::exists(P)) + CmdArgs.push_back(Args.MakeArgString(P)); // Adding the rpaths might negatively interact when other rpaths are involved, // so we should make sure we add the rpaths last, after all user-specified @@ -320,7 +327,49 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, // Add the path to the resource dir to rpath to support using the dylib // from the default location without copying. CmdArgs.push_back("-rpath"); - CmdArgs.push_back(Args.MakeArgString(Dir.str())); + CmdArgs.push_back(Args.MakeArgString(Dir)); + } +} + +void Darwin::addProfileRTLibs(const ArgList &Args, + ArgStringList &CmdArgs) const { + if (!(Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, + false) || + Args.hasArg(options::OPT_fprofile_generate) || + Args.hasArg(options::OPT_fprofile_instr_generate) || + Args.hasArg(options::OPT_fprofile_instr_generate_EQ) || + Args.hasArg(options::OPT_fcreate_profile) || + Args.hasArg(options::OPT_coverage))) + return; + + // Select the appropriate runtime library for the target. + if (isTargetIOSBased()) + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a", + /*AlwaysLink*/ true); + else + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a", + /*AlwaysLink*/ true); +} + +void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, + ArgStringList &CmdArgs, + StringRef Sanitizer) const { + if (!Args.hasArg(options::OPT_dynamiclib) && + !Args.hasArg(options::OPT_bundle)) { + // Sanitizer runtime libraries requires C++. + AddCXXStdlibLibArgs(Args, CmdArgs); + } + assert(isTargetMacOS() || isTargetIOSSimulator()); + StringRef OS = isTargetMacOS() ? "osx" : "iossim"; + AddLinkRuntimeLib(Args, CmdArgs, (Twine("libclang_rt.") + Sanitizer + "_" + + OS + "_dynamic.dylib").str(), + /*AlwaysLink*/ true, /*IsEmbedded*/ false, + /*AddRPath*/ true); + + if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) { + // Add explicit dependcy on -lc++abi, as -lc++ doesn't re-export + // all RTTI-related symbols that UBSan uses. + CmdArgs.push_back("-lc++abi"); } } @@ -352,63 +401,26 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, return; } - // If we are building profile support, link that library in. - if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, - false) || - Args.hasArg(options::OPT_fprofile_generate) || - Args.hasArg(options::OPT_fprofile_instr_generate) || - Args.hasArg(options::OPT_fcreate_profile) || - Args.hasArg(options::OPT_coverage)) { - // Select the appropriate runtime library for the target. - if (isTargetIOSBased()) - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_ios.a"); - else - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.profile_osx.a"); - } const SanitizerArgs &Sanitize = getSanitizerArgs(); - // Add Ubsan runtime library, if required. - if (Sanitize.needsUbsanRt()) { - // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds. - if (isTargetIOSBased()) { + if (Sanitize.needsAsanRt()) { + if (!isTargetMacOS() && !isTargetIOSSimulator()) { + // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds. getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) - << "-fsanitize=undefined"; + << "-fsanitize=address"; } else { - assert(isTargetMacOS() && "unexpected non OS X target"); - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a", true); - - // The Ubsan runtime library requires C++. - AddCXXStdlibLibArgs(Args, CmdArgs); + AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); } } - // Add ASAN runtime library, if required. Dynamic libraries and bundles - // should not be linked with the runtime library. - if (Sanitize.needsAsanRt()) { - // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds. - if (isTargetIPhoneOS()) { + if (Sanitize.needsUbsanRt()) { + if (!isTargetMacOS() && !isTargetIOSSimulator()) { + // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds. getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) - << "-fsanitize=address"; + << "-fsanitize=undefined"; } else { - if (!Args.hasArg(options::OPT_dynamiclib) && - !Args.hasArg(options::OPT_bundle)) { - // The ASAN runtime library requires C++. - AddCXXStdlibLibArgs(Args, CmdArgs); - } - if (isTargetMacOS()) { - AddLinkRuntimeLib(Args, CmdArgs, - "libclang_rt.asan_osx_dynamic.dylib", - /*AlwaysLink*/ true, /*IsEmbedded*/ false, - /*AddRPath*/ true); - } else { - if (isTargetIOSSimulator()) { - AddLinkRuntimeLib(Args, CmdArgs, - "libclang_rt.asan_iossim_dynamic.dylib", - /*AlwaysLink*/ true, /*IsEmbedded*/ false, - /*AddRPath*/ true); - } - } + AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); } } @@ -599,11 +611,11 @@ void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, SmallString<128> P(A->getValue()); llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib"); - if (!llvm::sys::fs::exists(P.str())) { + if (!llvm::sys::fs::exists(P)) { llvm::sys::path::remove_filename(P); llvm::sys::path::append(P, "libstdc++.6.dylib"); - if (llvm::sys::fs::exists(P.str())) { - CmdArgs.push_back(Args.MakeArgString(P.str())); + if (llvm::sys::fs::exists(P)) { + CmdArgs.push_back(Args.MakeArgString(P)); return; } } @@ -646,8 +658,8 @@ void DarwinClang::AddCCKextLibArgs(const ArgList &Args, // For now, allow missing resource libraries to support developers who may // not have compiler-rt checked out or integrated into their build. - if (llvm::sys::fs::exists(P.str())) - CmdArgs.push_back(Args.MakeArgString(P.str())); + if (llvm::sys::fs::exists(P)) + CmdArgs.push_back(Args.MakeArgString(P)); } DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, @@ -867,8 +879,8 @@ DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, return DAL; } -void MachO::AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) const { +void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { // Embedded targets are simple at the moment, not supporting sanitizers and // with different libraries for each member of the product { static, PIC } x // { hard-float, soft-float } @@ -977,8 +989,8 @@ bool MachO::SupportsProfiling() const { return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64; } -void Darwin::addMinVersionArgs(const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) const { +void Darwin::addMinVersionArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { VersionTuple TargetVersion = getTargetVersion(); if (isTargetIOSSimulator()) @@ -993,8 +1005,8 @@ void Darwin::addMinVersionArgs(const llvm::opt::ArgList &Args, CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); } -void Darwin::addStartObjectFileArgs(const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) const { +void Darwin::addStartObjectFileArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { // Derived from startfile spec. if (Args.hasArg(options::OPT_dynamiclib)) { // Derived from darwin_dylib1 spec. @@ -1498,11 +1510,12 @@ bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const { namespace { // Filter to remove Multilibs that don't exist as a suffix to Path -class FilterNonExistent : public MultilibSet::FilterCallback { - std::string Base; +class FilterNonExistent { + StringRef Base; + public: - FilterNonExistent(std::string Base) : Base(Base) {} - bool operator()(const Multilib &M) const override { + FilterNonExistent(StringRef Base) : Base(Base) {} + bool operator()(const Multilib &M) { return !llvm::sys::fs::exists(Base + M.gccSuffix() + "/crtbegin.o"); } }; @@ -1562,7 +1575,7 @@ static Multilib makeMultilib(StringRef commonSuffix) { } static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path, - const llvm::opt::ArgList &Args, + const ArgList &Args, DetectedMultilibs &Result) { // Some MIPS toolchains put libraries and object files compiled // using different options in to the sub-directoris which names @@ -1783,10 +1796,13 @@ static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path, addMultilibFlag(isMips64(TargetArch), "m64", Flags); addMultilibFlag(isMips16(Args), "mips16", Flags); addMultilibFlag(CPUName == "mips32", "march=mips32", Flags); - addMultilibFlag(CPUName == "mips32r2", "march=mips32r2", Flags); + addMultilibFlag(CPUName == "mips32r2" || CPUName == "mips32r3" || + CPUName == "mips32r5", + "march=mips32r2", Flags); addMultilibFlag(CPUName == "mips32r6", "march=mips32r6", Flags); addMultilibFlag(CPUName == "mips64", "march=mips64", Flags); - addMultilibFlag(CPUName == "mips64r2" || CPUName == "octeon", + addMultilibFlag(CPUName == "mips64r2" || CPUName == "mips64r3" || + CPUName == "mips64r5" || CPUName == "octeon", "march=mips64r2", Flags); addMultilibFlag(isMicroMips(Args), "mmicromips", Flags); addMultilibFlag(tools::mips::isUCLibc(Args), "muclibc", Flags); @@ -2061,20 +2077,26 @@ bool Generic_GCC::isPICDefaultForced() const { } bool Generic_GCC::IsIntegratedAssemblerDefault() const { - return getTriple().getArch() == llvm::Triple::x86 || - getTriple().getArch() == llvm::Triple::x86_64 || - getTriple().getArch() == llvm::Triple::aarch64 || - getTriple().getArch() == llvm::Triple::aarch64_be || - getTriple().getArch() == llvm::Triple::arm || - getTriple().getArch() == llvm::Triple::armeb || - getTriple().getArch() == llvm::Triple::thumb || - getTriple().getArch() == llvm::Triple::thumbeb || - getTriple().getArch() == llvm::Triple::ppc || - getTriple().getArch() == llvm::Triple::ppc64 || - getTriple().getArch() == llvm::Triple::ppc64le || - getTriple().getArch() == llvm::Triple::sparc || - getTriple().getArch() == llvm::Triple::sparcv9 || - getTriple().getArch() == llvm::Triple::systemz; + switch (getTriple().getArch()) { + case llvm::Triple::x86: + case llvm::Triple::x86_64: + case llvm::Triple::aarch64: + case llvm::Triple::aarch64_be: + case llvm::Triple::arm: + case llvm::Triple::armeb: + case llvm::Triple::thumb: + case llvm::Triple::thumbeb: + case llvm::Triple::ppc: + case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: + case llvm::Triple::sparc: + case llvm::Triple::sparcel: + case llvm::Triple::sparcv9: + case llvm::Triple::systemz: + return true; + default: + return false; + } } void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, @@ -2085,7 +2107,8 @@ void Generic_ELF::addClangTargetOptions(const ArgList &DriverArgs, getTriple().getArch() == llvm::Triple::aarch64_be || (getTriple().getOS() == llvm::Triple::Linux && (!V.isOlderThan(4, 7, 0) || - getTriple().getEnvironment() == llvm::Triple::Android)); + getTriple().getEnvironment() == llvm::Triple::Android)) || + getTriple().getOS() == llvm::Triple::NaCl; if (DriverArgs.hasFlag(options::OPT_fuse_init_array, options::OPT_fno_use_init_array, @@ -2115,6 +2138,30 @@ std::string Hexagon_TC::GetGnuDir(const std::string &InstalledDir, return InstallRelDir; } +const char *Hexagon_TC::GetSmallDataThreshold(const ArgList &Args) +{ + Arg *A; + + A = Args.getLastArg(options::OPT_G, + options::OPT_G_EQ, + options::OPT_msmall_data_threshold_EQ); + if (A) + return A->getValue(); + + A = Args.getLastArg(options::OPT_shared, + options::OPT_fpic, + options::OPT_fPIC); + if (A) + return "0"; + + return 0; +} + +bool Hexagon_TC::UsesG0(const char* smallDataThreshold) +{ + return smallDataThreshold && smallDataThreshold[0] == '0'; +} + static void GetHexagonLibraryPaths( const ArgList &Args, const std::string &Ver, @@ -2127,14 +2174,9 @@ static void GetHexagonLibraryPaths( //---------------------------------------------------------------------------- // -L Args //---------------------------------------------------------------------------- - for (arg_iterator - it = Args.filtered_begin(options::OPT_L), - ie = Args.filtered_end(); - it != ie; - ++it) { - for (unsigned i = 0, e = (*it)->getNumValues(); i != e; ++i) - LibPaths->push_back((*it)->getValue(i)); - } + for (const Arg *A : Args.filtered(options::OPT_L)) + for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) + LibPaths->push_back(A->getValue(i)); //---------------------------------------------------------------------------- // Other standard paths @@ -2246,7 +2288,7 @@ void Hexagon_TC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, llvm::sys::path::append(IncludeDir, "hexagon/include/c++/"); llvm::sys::path::append(IncludeDir, Ver); - addSystemInclude(DriverArgs, CC1Args, IncludeDir.str()); + addSystemInclude(DriverArgs, CC1Args, IncludeDir); } ToolChain::CXXStdlibType @@ -2308,6 +2350,159 @@ StringRef Hexagon_TC::GetTargetCPU(const ArgList &Args) } // End Hexagon +/// NaCl Toolchain +NaCl_TC::NaCl_TC(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args) + : Generic_ELF(D, Triple, Args) { + + // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the + // default paths, and must instead only use the paths provided + // with this toolchain based on architecture. + path_list& file_paths = getFilePaths(); + path_list& prog_paths = getProgramPaths(); + + file_paths.clear(); + prog_paths.clear(); + + // Path for library files (libc.a, ...) + std::string FilePath(getDriver().Dir + "/../"); + + // Path for tools (clang, ld, etc..) + std::string ProgPath(getDriver().Dir + "/../"); + + // Path for toolchain libraries (libgcc.a, ...) + std::string ToolPath(getDriver().ResourceDir + "/lib/"); + + switch(Triple.getArch()) { + case llvm::Triple::x86: { + file_paths.push_back(FilePath + "x86_64-nacl/lib32"); + file_paths.push_back(FilePath + "x86_64-nacl/usr/lib32"); + prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); + file_paths.push_back(ToolPath + "i686-nacl"); + break; + } + case llvm::Triple::x86_64: { + file_paths.push_back(FilePath + "x86_64-nacl/lib"); + file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); + prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); + file_paths.push_back(ToolPath + "x86_64-nacl"); + break; + } + case llvm::Triple::arm: { + file_paths.push_back(FilePath + "arm-nacl/lib"); + file_paths.push_back(FilePath + "arm-nacl/usr/lib"); + prog_paths.push_back(ProgPath + "arm-nacl/bin"); + file_paths.push_back(ToolPath + "arm-nacl"); + break; + } + default: + break; + } + + // Use provided linker, not system linker + Linker = GetProgramPath("ld"); + NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); +} + +void NaCl_TC::AddClangSystemIncludeArgs(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { + const Driver &D = getDriver(); + if (DriverArgs.hasArg(options::OPT_nostdinc)) + return; + + if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { + SmallString<128> P(D.ResourceDir); + llvm::sys::path::append(P, "include"); + addSystemInclude(DriverArgs, CC1Args, P.str()); + } + + if (DriverArgs.hasArg(options::OPT_nostdlibinc)) + return; + + SmallString<128> P(D.Dir + "/../"); + if (getTriple().getArch() == llvm::Triple::arm) { + llvm::sys::path::append(P, "arm-nacl/usr/include"); + } else if (getTriple().getArch() == llvm::Triple::x86) { + llvm::sys::path::append(P, "x86_64-nacl/usr/include"); + } else if (getTriple().getArch() == llvm::Triple::x86_64) { + llvm::sys::path::append(P, "x86_64-nacl/usr/include"); + } else { + return; + } + + addSystemInclude(DriverArgs, CC1Args, P.str()); + llvm::sys::path::remove_filename(P); + llvm::sys::path::remove_filename(P); + llvm::sys::path::append(P, "include"); + addSystemInclude(DriverArgs, CC1Args, P.str()); +} + +void NaCl_TC::AddCXXStdlibLibArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + // Check for -stdlib= flags. We only support libc++ but this consumes the arg + // if the value is libc++, and emits an error for other values. + GetCXXStdlibType(Args); + CmdArgs.push_back("-lc++"); +} + +void NaCl_TC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { + const Driver &D = getDriver(); + if (DriverArgs.hasArg(options::OPT_nostdlibinc) || + DriverArgs.hasArg(options::OPT_nostdincxx)) + return; + + // Check for -stdlib= flags. We only support libc++ but this consumes the arg + // if the value is libc++, and emits an error for other values. + GetCXXStdlibType(DriverArgs); + + if (getTriple().getArch() == llvm::Triple::arm) { + SmallString<128> P(D.Dir + "/../"); + llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); + addSystemInclude(DriverArgs, CC1Args, P.str()); + } else if (getTriple().getArch() == llvm::Triple::x86) { + SmallString<128> P(D.Dir + "/../"); + llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); + addSystemInclude(DriverArgs, CC1Args, P.str()); + } else if (getTriple().getArch() == llvm::Triple::x86_64) { + SmallString<128> P(D.Dir + "/../"); + llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); + addSystemInclude(DriverArgs, CC1Args, P.str()); + } +} + +ToolChain::CXXStdlibType NaCl_TC::GetCXXStdlibType(const ArgList &Args) const { + if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { + StringRef Value = A->getValue(); + if (Value == "libc++") + return ToolChain::CST_Libcxx; + getDriver().Diag(diag::err_drv_invalid_stdlib_name) + << A->getAsString(Args); + } + + return ToolChain::CST_Libcxx; +} + +std::string NaCl_TC::ComputeEffectiveClangTriple( + const ArgList &Args, types::ID InputType) const { + llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); + if (TheTriple.getArch() == llvm::Triple::arm && + TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) + TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); + return TheTriple.getTriple(); +} + +Tool *NaCl_TC::buildLinker() const { + return new tools::nacltools::Link(*this); +} + +Tool *NaCl_TC::buildAssembler() const { + if (getTriple().getArch() == llvm::Triple::arm) + return new tools::nacltools::AssembleARM(*this); + return new tools::gnutools::Assemble(*this); +} +// End NaCl + /// TCEToolChain - A tool chain using the llvm bitcode tools to perform /// all subcommands. See http://tce.cs.tut.fi for our peculiar target. /// Currently does not support anything else but compilation. @@ -2341,6 +2536,36 @@ bool TCEToolChain::isPICDefaultForced() const { return false; } +// CloudABI - CloudABI tool chain which can call ld(1) directly. + +CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args) + : Generic_ELF(D, Triple, Args) { + SmallString<128> P(getDriver().Dir); + llvm::sys::path::append(P, "..", getTriple().str(), "lib"); + getFilePaths().push_back(P.str()); +} + +void CloudABI::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { + if (DriverArgs.hasArg(options::OPT_nostdlibinc) && + DriverArgs.hasArg(options::OPT_nostdincxx)) + return; + + SmallString<128> P(getDriver().Dir); + llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); + addSystemInclude(DriverArgs, CC1Args, P.str()); +} + +void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + CmdArgs.push_back("-lc++"); + CmdArgs.push_back("-lc++abi"); + CmdArgs.push_back("-lunwind"); +} + +Tool *CloudABI::buildLinker() const { return new tools::cloudabi::Link(*this); } + /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. OpenBSD::OpenBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) @@ -2677,10 +2902,12 @@ enum Distro { DebianSqueeze, DebianWheezy, DebianJessie, + DebianStretch, Exherbo, RHEL4, RHEL5, RHEL6, + RHEL7, Fedora, OpenSUSE, UbuntuHardy, @@ -2696,11 +2923,13 @@ enum Distro { UbuntuRaring, UbuntuSaucy, UbuntuTrusty, + UbuntuUtopic, + UbuntuVivid, UnknownDistro }; static bool IsRedhat(enum Distro Distro) { - return Distro == Fedora || (Distro >= RHEL4 && Distro <= RHEL6); + return Distro == Fedora || (Distro >= RHEL4 && Distro <= RHEL7); } static bool IsOpenSUSE(enum Distro Distro) { @@ -2708,11 +2937,11 @@ static bool IsOpenSUSE(enum Distro Distro) { } static bool IsDebian(enum Distro Distro) { - return Distro >= DebianLenny && Distro <= DebianJessie; + return Distro >= DebianLenny && Distro <= DebianStretch; } static bool IsUbuntu(enum Distro Distro) { - return Distro >= UbuntuHardy && Distro <= UbuntuTrusty; + return Distro >= UbuntuHardy && Distro <= UbuntuVivid; } static Distro DetectDistro(llvm::Triple::ArchType Arch) { @@ -2739,6 +2968,8 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) { .Case("raring", UbuntuRaring) .Case("saucy", UbuntuSaucy) .Case("trusty", UbuntuTrusty) + .Case("utopic", UbuntuUtopic) + .Case("vivid", UbuntuVivid) .Default(UnknownDistro); return Version; } @@ -2750,7 +2981,9 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) { return Fedora; if (Data.startswith("Red Hat Enterprise Linux") || Data.startswith("CentOS")) { - if (Data.find("release 6") != StringRef::npos) + if (Data.find("release 7") != StringRef::npos) + return RHEL7; + else if (Data.find("release 6") != StringRef::npos) return RHEL6; else if (Data.find("release 5") != StringRef::npos) return RHEL5; @@ -2771,6 +3004,8 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) { return DebianWheezy; else if (Data.startswith("jessie/sid") || Data[0] == '8') return DebianJessie; + else if (Data.startswith("stretch/sid") || Data[0] == '9') + return DebianStretch; return UnknownDistro; } @@ -2875,6 +3110,14 @@ static std::string getMultiarchTriple(const llvm::Triple &TargetTriple, if (llvm::sys::fs::exists(SysRoot + "/lib/powerpc64le-linux-gnu")) return "powerpc64le-linux-gnu"; return TargetTriple.str(); + case llvm::Triple::sparc: + if (llvm::sys::fs::exists(SysRoot + "/lib/sparc-linux-gnu")) + return "sparc-linux-gnu"; + return TargetTriple.str(); + case llvm::Triple::sparcv9: + if (llvm::sys::fs::exists(SysRoot + "/lib/sparc64-linux-gnu")) + return "sparc64-linux-gnu"; + return TargetTriple.str(); } } @@ -2967,8 +3210,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) if (IsRedhat(Distro)) ExtraOpts.push_back("--no-add-needed"); - if (Distro == DebianSqueeze || Distro == DebianWheezy || - Distro == DebianJessie || IsOpenSUSE(Distro) || + if ((IsDebian(Distro) && Distro >= DebianSqueeze) || IsOpenSUSE(Distro) || (IsRedhat(Distro) && Distro != RHEL4 && Distro != RHEL5) || (IsUbuntu(Distro) && Distro >= UbuntuKarmic)) ExtraOpts.push_back("--build-id"); @@ -3144,7 +3386,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { SmallString<128> P(D.ResourceDir); llvm::sys::path::append(P, "include"); - addSystemInclude(DriverArgs, CC1Args, P.str()); + addSystemInclude(DriverArgs, CC1Args, P); } if (DriverArgs.hasArg(options::OPT_nostdlibinc)) @@ -3168,7 +3410,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, // Add include directories specific to the selected multilib set and multilib. if (GCCInstallation.isValid()) { - auto Callback = Multilibs.includeDirsCallback(); + const auto &Callback = Multilibs.includeDirsCallback(); if (Callback) { const auto IncludePaths = Callback(GCCInstallation.getInstallPath(), GCCInstallation.getTriple().str(), @@ -3228,6 +3470,12 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, const StringRef PPC64LEMultiarchIncludeDirs[] = { "/usr/include/powerpc64le-linux-gnu" }; + const StringRef SparcMultiarchIncludeDirs[] = { + "/usr/include/sparc-linux-gnu" + }; + const StringRef Sparc64MultiarchIncludeDirs[] = { + "/usr/include/sparc64-linux-gnu" + }; ArrayRef<StringRef> MultiarchIncludeDirs; if (getTriple().getArch() == llvm::Triple::x86_64) { MultiarchIncludeDirs = X86_64MultiarchIncludeDirs; @@ -3255,6 +3503,10 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, MultiarchIncludeDirs = PPC64MultiarchIncludeDirs; } else if (getTriple().getArch() == llvm::Triple::ppc64le) { MultiarchIncludeDirs = PPC64LEMultiarchIncludeDirs; + } else if (getTriple().getArch() == llvm::Triple::sparc) { + MultiarchIncludeDirs = SparcMultiarchIncludeDirs; + } else if (getTriple().getArch() == llvm::Triple::sparcv9) { + MultiarchIncludeDirs = Sparc64MultiarchIncludeDirs; } for (StringRef Dir : MultiarchIncludeDirs) { if (llvm::sys::fs::exists(SysRoot + Dir)) { @@ -3466,8 +3718,8 @@ void XCore::AddClangSystemIncludeArgs(const ArgList &DriverArgs, } } -void XCore::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args) const { +void XCore::addClangTargetOptions(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { CC1Args.push_back("-nostdsysteminc"); } |