r270351 - Driver: simplify getDynameLinker
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Sat May 21 18:37:38 PDT 2016
Author: compnerd
Date: Sat May 21 20:37:36 2016
New Revision: 270351
URL: http://llvm.org/viewvc/llvm-project?rev=270351&view=rev
Log:
Driver: simplify getDynameLinker
Convert the cascading if/else to a switch. This makes it easier to follow the
logic. Minor difference is that we no longer default to x86_64 but rather to
the architecture specified by the architecture.
Modified:
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=270351&r1=270350&r2=270351&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Sat May 21 20:37:36 2016
@@ -8989,66 +8989,68 @@ static std::string getLinuxDynamicLinker
const llvm::Triple::ArchType Arch = ToolChain.getArch();
const llvm::Triple &Triple = ToolChain.getTriple();
- if (Triple.isAndroid()) {
- if (Triple.isArch64Bit())
- return "/system/bin/linker64";
- else
- return "/system/bin/linker";
- } else if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::sparc ||
- Arch == llvm::Triple::sparcel)
- return "/lib/ld-linux.so.2";
- else if (Arch == llvm::Triple::aarch64)
+ 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";
- else if (Arch == llvm::Triple::aarch64_be)
+ case llvm::Triple::aarch64_be:
return "/lib/ld-linux-aarch64_be.so.1";
- else if (Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) {
- if (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
- arm::getARMFloatABI(ToolChain, Args) == arm::FloatABI::Hard)
- return "/lib/ld-linux-armhf.so.3";
- else
- return "/lib/ld-linux.so.3";
- } else if (Arch == llvm::Triple::armeb || Arch == llvm::Triple::thumbeb) {
- // TODO: check which dynamic linker name.
- if (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
- arm::getARMFloatABI(ToolChain, Args) == arm::FloatABI::Hard)
- return "/lib/ld-linux-armhf.so.3";
- else
- return "/lib/ld-linux.so.3";
- } else if (Arch == llvm::Triple::mips || Arch == llvm::Triple::mipsel ||
- Arch == llvm::Triple::mips64 || Arch == llvm::Triple::mips64el) {
+ 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;
- bool IsNaN2008 = mips::isNaN2008(Args, Triple);
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) {
- bool LE = (Triple.getArch() == llvm::Triple::mipsel) ||
- (Triple.getArch() == llvm::Triple::mips64el);
+ Triple.getVendor() == llvm::Triple::VendorType::MipsTechnologies)
LibName = LE ? "ld-musl-mipsel.so.1" : "ld-musl-mips.so.1";
- } else
+ else
LibName = IsNaN2008 ? "ld-linux-mipsn8.so.1" : "ld.so.1";
return (LibDir + "/" + LibName).str();
- } else if (Arch == llvm::Triple::ppc)
+ }
+ case llvm::Triple::ppc:
return "/lib/ld.so.1";
- else if (Arch == llvm::Triple::ppc64) {
- if (ppc::hasPPCAbiArg(Args, "elfv2"))
- return "/lib64/ld64.so.2";
- return "/lib64/ld64.so.1";
- } else if (Arch == llvm::Triple::ppc64le) {
- if (ppc::hasPPCAbiArg(Args, "elfv1"))
- return "/lib64/ld64.so.1";
- return "/lib64/ld64.so.2";
- } else if (Arch == llvm::Triple::systemz)
- return "/lib/ld64.so.1";
- else if (Arch == llvm::Triple::sparcv9)
+ 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";
- else if (Arch == llvm::Triple::x86_64 &&
- Triple.getEnvironment() == llvm::Triple::GNUX32)
- return "/libx32/ld-linux-x32.so.2";
- else
- return "/lib64/ld-linux-x86-64.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,
More information about the cfe-commits
mailing list