From cbb2d023069d3774a68ac37aa9815ba5e80f2903 Mon Sep 17 00:00:00 2001
From: Oleksandr Ocheretnyi <oocheret@cisco.com>
Date: Wed, 15 Apr 2020 00:08:39 +0300
Subject: [PATCH] clang: driver: Add dyld-prefix when checking sysroot for ldso
 path

 * the dyld-prefix shall be taken into account when the default
   path for the dynamic linker has to be checked.

 * this patch shall be used as annex to the next patch:
   'clang: driver: Check sysroot for ldso path' which includes
   the usrmerge scenario.

Upstream-Status: Pending
Signed-off-by: Oleksandr Ocheretnyi <oocheret@cisco.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 clang/lib/Driver/ToolChains/Linux.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 67e922e08228..3ee2d56df00f 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -517,8 +517,8 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
 
     Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3";
     LibDir = "lib32";
-    if (!getVFS().exists(getDriver().SysRoot + "/" + LibDir + "/" + Loader) &&
-         getVFS().exists(getDriver().SysRoot + "/lib/" + Loader)) {
+    if (!getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/lib/" + Loader)) {
         LibDir = "lib";
     }
     break;
@@ -574,8 +574,8 @@ 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)) {
+    if (!getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/lib/" + Loader)) {
         LibDir = "lib";
     }
     break;
@@ -583,8 +583,8 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
     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)) {
+    if (!getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/lib/" + Loader)) {
         LibDir = "lib";
     }
     break;
@@ -604,8 +604,8 @@ 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)) {
+    if (!getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/lib/" + Loader)) {
         LibDir = "lib";
     }
     break;
@@ -622,8 +622,8 @@ 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)) {
+    if (!getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/" + LibDir + "/" + Loader) &&
+         getVFS().exists(getDriver().SysRoot + getDriver().DyldPrefix + "/lib/" + Loader)) {
         LibDir = "lib";
     }
     break;
