From d4121c0c5ad01dab4f3c35d4fc59ec92bdca36b7 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Thu, 16 Mar 2017 19:06:26 -0700
Subject: [PATCH 5/7] clang: Look inside the target sysroot for compiler
 runtime

In OE compiler-rt and libc++ are built and staged into target
sysroot and not into resourcedir which is relative to clang
driver installation where the libraries are not instlled

Specific to cross compiling the way yocto/OE works

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 lib/Driver/ToolChain.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index f96a1182e3..d286622f8d 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -12,6 +12,7 @@
 #include "ToolChains/Arch/ARM.h"
 #include "ToolChains/Clang.h"
 #include "clang/Basic/ObjCRuntime.h"
+#include "clang/Basic/Version.h"
 #include "clang/Basic/VirtualFileSystem.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Action.h"
@@ -324,7 +325,10 @@ static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
 }
 
 std::string ToolChain::getCompilerRTPath() const {
-  SmallString<128> Path(getDriver().ResourceDir);
+  SmallString<128> Path(getDriver().SysRoot);
+  StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);
+  llvm::sys::path::append(Path, "/usr/", Twine("lib") + ClangLibdirSuffix, "clang",
+                            CLANG_VERSION_STRING);
   if (Triple.isOSUnknown()) {
     llvm::sys::path::append(Path, "lib");
   } else {
-- 
2.16.1

