From 7ff4f134a5e5e1f6ffe31637a474cf118ae0079b Mon Sep 17 00:00:00 2001
From: Dan McGregor <dan.mcgregor@usask.ca>
Date: Wed, 26 Apr 2017 20:29:41 -0600
Subject: [PATCH] clang: driver: Check sysroot for ldso path

OE does not necessarily follow the default path for the dynamic linker,
therefore adjust it for OE. Check for the default path, and if it isn't
there, check /lib.

Signed-off-by: Dan McGregor <dan.mcgregor@usask.ca>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 clang/lib/Driver/ToolChains/Linux.cpp | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index f85c04df4f6c..97e987c37e4a 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -493,11 +493,19 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
     LibDir = "lib64";
     Loader =
         (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2" : "ld64.so.1";
+    if (!getVFS().exists(getDriver().SysRoot + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + "/lib/" + Loader)) {
+        LibDir = "lib";
+    }
     break;
   case llvm::Triple::ppc64le:
     LibDir = "lib64";
     Loader =
         (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2";
+    if (!getVFS().exists(getDriver().SysRoot + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + "/lib/" + Loader)) {
+        LibDir = "lib";
+    }
     break;
   case llvm::Triple::riscv32: {
     StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
@@ -519,6 +527,10 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
   case llvm::Triple::sparcv9:
     LibDir = "lib64";
     Loader = "ld-linux.so.2";
+    if (!getVFS().exists(getDriver().SysRoot + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + "/lib/" + Loader)) {
+        LibDir = "lib";
+    }
     break;
   case llvm::Triple::systemz:
     LibDir = "lib";
@@ -533,6 +545,10 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
 
     LibDir = X32 ? "libx32" : "lib64";
     Loader = X32 ? "ld-linux-x32.so.2" : "ld-linux-x86-64.so.2";
+    if (!getVFS().exists(getDriver().SysRoot + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + "/lib/" + Loader)) {
+        LibDir = "lib";
+    }
     break;
   }
   case llvm::Triple::ve:
