From 12b439deed0381e603155a11f3aec5eb20cd6803 Mon Sep 17 00:00:00 2001
From: Changqing Li <changqing.li@windriver.com>
Date: Tue, 7 Dec 2021 04:55:48 +0000
Subject: [PATCH] Correct library search path for OpenEmbedded Host

For OpenEmbedded Host, the gcc install path is
/usr/lib/x86_64-[distroname]-linux/[gcc-version].
So the library search path is not found with default triple
'x86_64-linux-gnu' for x86_64. Causing following error:
[snip]
compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/clang
-target x86_64-linux
-isystem/path/to/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/include
-O2 -pipe
/path/to/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/share/cmake-3.21/Modules/CMakeCCompilerABI.c`
|     /build/tmp-glibc/hosttools/ld: cannot find -lgcc
|     /build/tmp-glibc/hosttools/ld: cannot find -lgcc
|     clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
[snip]

before this patch:
b59da142f2b0:$ /path/to/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/clang --print-search-dirs
programs: =/build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin
libraries: =/build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/lib/clang/13.0.1:/build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/../lib://lib://usr/lib

after this patch:
b59da142f2b0:$ /path/to/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/clang --print-search-dirs
programs: =/build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin
libraries: =/build/tmp-glibc/work/x84_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/lib/clang/13.0.1:/usr/lib/x86_64-wrs-linux/10.2.0://lib/x86_64-wrs-linux://usr/lib/x86_64-wrs-linux:/build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/../lib://lib://usr/lib

Upstream-Status: Inappropriate [oe specific]

Signed-off-by: Changqing Li <changqing.li@windriver.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 clang/include/clang/Driver/Distro.h   | 2 ++
 clang/lib/Driver/Distro.cpp           | 1 +
 clang/lib/Driver/ToolChains/Linux.cpp | 1 +
 3 files changed, 4 insertions(+)

diff --git a/clang/include/clang/Driver/Distro.h b/clang/include/clang/Driver/Distro.h
index 2723f75e8945..cd43e8f11574 100644
--- a/clang/include/clang/Driver/Distro.h
+++ b/clang/include/clang/Driver/Distro.h
@@ -44,6 +44,7 @@ public:
     RHEL7,
     Fedora,
     Gentoo,
+    //CLANG_EXTRA_OE_DISTRO_NAME
     OpenSUSE,
     UbuntuHardy,
     UbuntuIntrepid,
@@ -132,6 +133,7 @@ public:
 
   bool IsGentoo() const { return DistroVal == Gentoo; }
 
+  //CLANG_EXTRA_OE_DISTRO_CHECK
   /// @}
 };
 
diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index 5ac38c34d112..f20dd4b526e5 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -44,6 +44,7 @@ static Distro::DistroType DetectOsRelease(llvm::vfs::FileSystem &VFS) {
                     .Case("sles", Distro::OpenSUSE)
                     .Case("opensuse", Distro::OpenSUSE)
                     .Case("exherbo", Distro::Exherbo)
+                    //CLANG_EXTRA_OE_DISTRO_CASE
                     .Default(Distro::UnknownDistro);
   return Version;
 }
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index eb92a037c930..c92cef442005 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -77,6 +77,7 @@ std::string Linux::getMultiarchTriple(const Driver &D,
       return "x86_64-linux-android";
     if (TargetEnvironment == llvm::Triple::GNUX32)
       return "x86_64-linux-gnux32";
+    //CLANG_EXTRA_OE_DISTRO_TRIPLE
     return "x86_64-linux-gnu";
   case llvm::Triple::aarch64:
     if (IsAndroid)
