From 783fc635f6252f1d6e978118770f1e949ffd580b Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 22 May 2016 03:12:19 +0000 Subject: [PATCH] Driver: sink getLinuxDynamicLoader into the Toolchain The parameter already requires the toolchain, sink the method into the class. This also enables the use of the distro detection logic which will be needed to support Exherbo's multiarch approach. llvm-svn: 270352 --- clang/lib/Driver/ToolChains.cpp | 69 ++++++++++++++++++++++++++++++++ clang/lib/Driver/ToolChains.h | 2 + clang/lib/Driver/Tools.cpp | 71 +-------------------------------- 3 files changed, 72 insertions(+), 70 deletions(-) diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 556d24084445..3988c726b2de 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -3918,6 +3918,75 @@ std::string Linux::computeSysRoot() const { return std::string(); } +std::string Linux::getDynamicLinker(const ArgList &Args) const { + const llvm::Triple::ArchType Arch = getArch(); + const llvm::Triple &Triple = getTriple(); + + if (Triple.isAndroid()) + return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; + + switch (Arch) { + default: llvm_unreachable("unsupported architecture"); + + case llvm::Triple::aarch64: + return "/lib/ld-linux-aarch64.so.1"; + case llvm::Triple::aarch64_be: + return "/lib/ld-linux-aarch64_be.so.1"; + case llvm::Triple::arm: + case llvm::Triple::thumb: + case llvm::Triple::armeb: + case llvm::Triple::thumbeb: { + const bool IsHardFloat = + Triple.getEnvironment() == llvm::Triple::GNUEABIHF || + tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard; + + return IsHardFloat ? "/lib/ld-linux-armhf.so.3" : "/lib/ld-linux.so.3"; + } + case llvm::Triple::mips: + case llvm::Triple::mipsel: + case llvm::Triple::mips64: + case llvm::Triple::mips64el: { + bool IsNaN2008 = tools::mips::isNaN2008(Args, Triple); + bool LE = (Triple.getArch() == llvm::Triple::mipsel) || + (Triple.getArch() == llvm::Triple::mips64el); + + std::string LibDir = + "/lib" + tools::mips::getMipsABILibSuffix(Args, Triple); + StringRef LibName; + if (tools::mips::isUCLibc(Args)) + LibName = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0"; + else if (!Triple.hasEnvironment() && + Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies) + LibName = LE ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1"; + else + LibName = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1"; + + return (LibDir + "/" + LibName).str(); + } + case llvm::Triple::ppc: + return "/lib/ld.so.1"; + case llvm::Triple::ppc64: + return (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "/lib64/ld64.so.2" + : "/lib64/ld64.so.1"; + case llvm::Triple::ppc64le: + return (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "/lib64/ld64.so.1" + : "/lib64/ld64.so.2"; + case llvm::Triple::sparc: + case llvm::Triple::sparcel: + return "/lib/ld-linux.so.2"; + case llvm::Triple::sparcv9: + return "/lib64/ld-linux.so.2"; + case llvm::Triple::systemz: + return "/lib/ld64.so.1"; + case llvm::Triple::x86: + return "/lib/ld-linux.so.2"; + case llvm::Triple::x86_64: + return (Triple.getEnvironment() == llvm::Triple::GNUX32) + ? "/libx32/ld-linux-x32.so.2" + : "/lib64/ld-linux-x86-64.so.2"; + } +} + void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Driver &D = getDriver(); diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index 5e1e6ca2f22b..244c22a9646c 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -826,6 +826,8 @@ public: llvm::opt::ArgStringList &CmdArgs) const override; virtual std::string computeSysRoot() const; + virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const; + std::vector ExtraOpts; protected: diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 2eee8b8fbca0..35ca4706d54b 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -8984,75 +8984,6 @@ static void AddLibgcc(const llvm::Triple &Triple, const Driver &D, CmdArgs.push_back("-ldl"); } -static std::string getLinuxDynamicLinker(const ArgList &Args, - const toolchains::Linux &ToolChain) { - const llvm::Triple::ArchType Arch = ToolChain.getArch(); - const llvm::Triple &Triple = ToolChain.getTriple(); - - if (Triple.isAndroid()) - return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; - - switch (Arch) { - default: llvm_unreachable("unsupported architecture"); - - case llvm::Triple::aarch64: - return "/lib/ld-linux-aarch64.so.1"; - case llvm::Triple::aarch64_be: - return "/lib/ld-linux-aarch64_be.so.1"; - case llvm::Triple::arm: - case llvm::Triple::thumb: - case llvm::Triple::armeb: - case llvm::Triple::thumbeb: { - const bool IsHardFloat = - Triple.getEnvironment() == llvm::Triple::GNUEABIHF || - arm::getARMFloatABI(ToolChain, Args) == arm::FloatABI::Hard; - - return IsHardFloat ? "/lib/ld-linux-armhf.so.3" : "/lib/ld-linux.so.3"; - } - case llvm::Triple::mips: - case llvm::Triple::mipsel: - case llvm::Triple::mips64: - case llvm::Triple::mips64el: { - bool IsNaN2008 = mips::isNaN2008(Args, Triple); - bool LE = (Triple.getArch() == llvm::Triple::mipsel) || - (Triple.getArch() == llvm::Triple::mips64el); - - std::string LibDir = "/lib" + mips::getMipsABILibSuffix(Args, Triple); - StringRef LibName; - if (mips::isUCLibc(Args)) - LibName = IsNaN2008 ? "ld-uClibc-mipsn8.so.0" : "ld-uClibc.so.0"; - else if (!Triple.hasEnvironment() && - Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies) - LibName = LE ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1"; - else - LibName = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1"; - - return (LibDir + "/" + LibName).str(); - } - case llvm::Triple::ppc: - return "/lib/ld.so.1"; - case llvm::Triple::ppc64: - return (ppc::hasPPCAbiArg(Args, "elfv2")) ? "/lib64/ld64.so.2" - : "/lib64/ld64.so.1"; - case llvm::Triple::ppc64le: - return (ppc::hasPPCAbiArg(Args, "elfv1")) ? "/lib64/ld64.so.1" - : "/lib64/ld64.so.2"; - case llvm::Triple::sparc: - case llvm::Triple::sparcel: - return "/lib/ld-linux.so.2"; - case llvm::Triple::sparcv9: - return "/lib64/ld-linux.so.2"; - case llvm::Triple::systemz: - return "/lib/ld64.so.1"; - case llvm::Triple::x86: - return "/lib/ld-linux.so.2"; - case llvm::Triple::x86_64: - return (Triple.getEnvironment() == llvm::Triple::GNUX32) - ? "/libx32/ld-linux-x32.so.2" - : "/lib64/ld-linux-x86-64.so.2"; - } -} - static void AddRunTimeLibs(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args) { // Make use of compiler-rt if --rtlib option is used @@ -9212,7 +9143,7 @@ void gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_shared)) { const std::string Loader = - D.DyldPrefix + getLinuxDynamicLinker(Args, ToolChain); + D.DyldPrefix + ToolChain.getDynamicLinker(Args); CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back(Args.MakeArgString(Loader)); }