Browse Source

Merge branch 'update-readme' into 'starfive-hardknott'

dubhe: Update README.md

Updated several depreciated steps such as the github repo and branch, and
the dependency packages. The 'dubhe-image-initramfs' is also changed to
'qspi-image' instead.

Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
Jun Yuan Tan 2 years ago
parent
commit
8235ad1e6f
53 changed files with 2216 additions and 12 deletions
  1. 4 1
      conf/machine/starfive-dubhe.conf
  2. 2 2
      recipes-bsp/opensbi/opensbi_0.9.bbappend
  3. 3 0
      recipes-devtools/clang/clang-cross-canadian_git.bbappend
  4. 3 0
      recipes-devtools/clang/clang-cross_git.bbappend
  5. 3 0
      recipes-devtools/clang/clang-crosssdk_git.bbappend
  6. 43 0
      recipes-devtools/clang/clang/0001-lldb-Add-lxml2-to-linker-cmdline-of-xml-is-found.patch
  7. 70 0
      recipes-devtools/clang/clang/0002-libcxxabi-Find-libunwind-headers-when-LIBCXXABI_LIBU.patch
  8. 49 0
      recipes-devtools/clang/clang/0003-compiler-rt-Simplify-cross-compilation.-Don-t-use-na.patch
  9. 94 0
      recipes-devtools/clang/clang/0004-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch
  10. 40 0
      recipes-devtools/clang/clang/0005-llvm-allow-env-override-of-exe-path.patch
  11. 67 0
      recipes-devtools/clang/clang/0006-clang-driver-Check-sysroot-for-ldso-path.patch
  12. 37 0
      recipes-devtools/clang/clang/0007-clang-Driver-tools.cpp-Add-lssp_nonshared-on-musl.patch
  13. 31 0
      recipes-devtools/clang/clang/0008-clang-musl-ppc-does-not-support-128-bit-long-double.patch
  14. 44 0
      recipes-devtools/clang/clang/0009-clang-Prepend-trailing-to-sysroot.patch
  15. 46 0
      recipes-devtools/clang/clang/0010-clang-Look-inside-the-target-sysroot-for-compiler-ru.patch
  16. 52 0
      recipes-devtools/clang/clang/0011-clang-Define-releative-gcc-installation-dir.patch
  17. 40 0
      recipes-devtools/clang/clang/0012-clang-Add-lpthread-and-ldl-along-with-lunwind-for-st.patch
  18. 29 0
      recipes-devtools/clang/clang/0013-Pass-PYTHON_EXECUTABLE-when-cross-compiling-for-nati.patch
  19. 39 0
      recipes-devtools/clang/clang/0014-Check-for-atomic-double-intrinsics.patch
  20. 43 0
      recipes-devtools/clang/clang/0015-libcxx-Add-compiler-runtime-library-to-link-step-for.patch
  21. 122 0
      recipes-devtools/clang/clang/0016-clang-llvm-cmake-Fix-configure-for-packages-using-fi.patch
  22. 45 0
      recipes-devtools/clang/clang/0017-clang-Fix-resource-dir-location-for-cross-toolchains.patch
  23. 32 0
      recipes-devtools/clang/clang/0018-fix-path-to-libffi.patch
  24. 73 0
      recipes-devtools/clang/clang/0019-clang-driver-Add-dyld-prefix-when-checking-sysroot-f.patch
  25. 107 0
      recipes-devtools/clang/clang/0020-clang-Use-python3-in-python-scripts.patch
  26. 76 0
      recipes-devtools/clang/clang/0021-For-x86_64-set-Yocto-based-GCC-install-search-path.patch
  27. 50 0
      recipes-devtools/clang/clang/0022-llvm-Do-not-use-find_library-for-ncurses.patch
  28. 38 0
      recipes-devtools/clang/clang/0023-llvm-Insert-anchor-for-adding-OE-distro-vendor-names.patch
  29. 78 0
      recipes-devtools/clang/clang/0024-compiler-rt-Use-mcr-based-barrier-on-armv6.patch
  30. 35 0
      recipes-devtools/clang/clang/0025-clang-Switch-defaults-to-dwarf-5-debug-info-on-Linux.patch
  31. 75 0
      recipes-devtools/clang/clang/0026-compiler-rt-Do-not-use-backtrace-APIs-on-non-glibc-l.patch
  32. 33 0
      recipes-devtools/clang/clang/0027-clang-Fix-x86-triple-for-non-debian-multiarch-linux-.patch
  33. 34 0
      recipes-devtools/clang/clang/0028-compiler-rt-Link-scudo-with-SANITIZER_CXX_ABI_LIBRAR.patch
  34. 36 0
      recipes-devtools/clang/clang/0029-compiler-rt-Link-scudo-standalone-with-libatomic-on-.patch
  35. 61 0
      recipes-devtools/clang/clang/0030-libunwind-Added-unw_backtrace-method.patch
  36. 41 0
      recipes-devtools/clang/clang/0031-compiler-rt-Use-uintptr_t-instead-of-_Unwind_Word.patch
  37. 52 0
      recipes-devtools/clang/clang/0032-compiler-rt-Do-not-force-thumb-mode-directive.patch
  38. 74 0
      recipes-devtools/clang/clang/0033-Drop-the-git-suffix-from-various-version-variables.patch
  39. 39 0
      recipes-devtools/clang/clang/0034-clang-Do-not-use-install-relative-libc-headers.patch
  40. 65 0
      recipes-devtools/clang/clang/fix-clang-driver-gcc-install-path-on-openembedded.patch
  41. 9 0
      recipes-devtools/clang/clang/libunwind.pc.in
  42. 44 0
      recipes-devtools/clang/clang/llvm-config
  43. 7 0
      recipes-devtools/clang/clang_git.bbappend
  44. 3 0
      recipes-devtools/clang/compiler-rt_git.bbappend
  45. 3 0
      recipes-devtools/clang/libcxx_git.bbappend
  46. 52 0
      recipes-devtools/clang/llvm-project-source.bbappend
  47. 181 0
      recipes-devtools/llvm/llvm_git.bb
  48. 3 4
      recipes-kernel/linux/files/defconfig
  49. 1 1
      recipes-kernel/linux/linux-starfive-dev.bb
  50. 3 3
      recipes-kernel/linux/linux-starfive-dev.bbappend
  51. 1 0
      setup.sh
  52. 3 1
      tools/manifests/starfive.xml
  53. 1 0
      tools/setup.sh

+ 4 - 1
conf/machine/starfive-dubhe.conf

@@ -7,11 +7,14 @@
 
 #XVISOR_PLAT = "riscv/virt64"
 
+LLVMVERSION = "14.0.0"
+CLANGSDK = "1"
+EXTRA_IMAGEDEPENDS += " llvm"
+
 #EXTRA_IMAGEDEPENDS += "u-boot"
 #UBOOT_MACHINE = "qemu-riscv64_smode_defconfig"
 #UBOOT_ELF = "u-boot"
 
-
 #require conf/machine/include/qemu.inc
 # qemuboot options
 EXTRA_IMAGEDEPENDS += " qemu-helper-native "

+ 2 - 2
recipes-bsp/opensbi/opensbi_0.9.bbappend

@@ -1,5 +1,5 @@
-SRC_URI = "git://github.com/starfive-tech/opensbi.git;protocol=git;branch=starfive-dubhe"
-SRCREV = "4ad25b455be55b31f38404e82225e6d757704e26"
+SRC_URI = "git://git@192.168.110.45/starfive-tech/opensbi;protocol=ssh;branch=starfive-dubhe"
+SRCREV = "b44fd539c9ac9a53f248986a5cb4c9becf84e08d"
 
 INSANE_SKIP_${PN}-dev = "ldflags"
 INSANE_SKIP_${PN} = "ldflags"

+ 3 - 0
recipes-devtools/clang/clang-cross-canadian_git.bbappend

@@ -0,0 +1,3 @@
+MAJOR_VER = "14"
+MINOR_VER = "0"
+PATCH_VER = "0"

+ 3 - 0
recipes-devtools/clang/clang-cross_git.bbappend

@@ -0,0 +1,3 @@
+MAJOR_VER = "14"
+MINOR_VER = "0"
+PATCH_VER = "0"

+ 3 - 0
recipes-devtools/clang/clang-crosssdk_git.bbappend

@@ -0,0 +1,3 @@
+MAJOR_VER = "14"
+MINOR_VER = "0"
+PATCH_VER = "0"

+ 43 - 0
recipes-devtools/clang/clang/0001-lldb-Add-lxml2-to-linker-cmdline-of-xml-is-found.patch

@@ -0,0 +1,43 @@
+From 529df058387bae6a015b55b3d504f46775c085d4 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:10:15 +0800
+Subject: [PATCH] lldb: Add -lxml2 to linker cmdline of xml is found
+
+When cross compiling for systems where static libs
+for libxml are not available cmake's detection mechanism
+resort to linking with libxml.so but doesnt use -lxml2
+liblldbHost.a however requires libxml on linker
+cmdline _after_ itself so its use of symbols from libxml2
+can be resolved. Here check for libxml2 being detected and
+add it if its found.
+
+Fixes
+
+| ../../../../lib/liblldbHost.a(XML.cpp.o): In function `lldb_private::XMLDocument::Clear()':
+| /usr/src/debug/lldb/5.0.0+gitAUTOINC+69edad7913_08d6b47db9_cf6c5b3386-r0/git/tools/lldb/source/Host/common/XML.cpp:29: undefined reference to `xmlFreeDoc'
+| /usr/src/debug/lldb/5.0.0+gitAUTOINC+69edad7913_08d6b47db9_cf6c5b3386-r0/git/tools/lldb/source/Host/common/XML.cpp:29: undefined reference to `xmlFreeDoc'
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ lldb/source/Host/CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
+index 4374abca0506..6a802089d3b3 100644
+--- a/lldb/source/Host/CMakeLists.txt
++++ b/lldb/source/Host/CMakeLists.txt
+@@ -136,7 +136,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
+   list(APPEND EXTRA_LIBS kvm)
+ endif()
+ if (LLDB_ENABLE_LIBXML2)
+-  list(APPEND EXTRA_LIBS LibXml2::LibXml2)
++  list(APPEND EXTRA_LIBS xml2)
+ endif()
+ if (HAVE_LIBDL)
+   list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS})
+-- 
+2.33.0
+

+ 70 - 0
recipes-devtools/clang/clang/0002-libcxxabi-Find-libunwind-headers-when-LIBCXXABI_LIBU.patch

@@ -0,0 +1,70 @@
+From ec494876174df1ca3f3ca21577796914848bc1ee Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:14:13 +0800
+Subject: [PATCH] libcxxabi: Find libunwind headers when
+ LIBCXXABI_LIBUNWIND_INCLUDES is set
+
+Currently, when LIBCXXABI_LIBUNWIND_INCLUDES is set via CMake arguments
+then it ends up not searching the specified dir and unwind.h is not found
+especially for ARM targets
+
+This patch makes the searching synthesized directories and then set
+LIBCXXABI_LIBUNWIND_INCLUDES if its there in environment
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ libcxxabi/CMakeLists.txt | 21 +++++++++++----------
+ 1 file changed, 11 insertions(+), 10 deletions(-)
+
+diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
+index cc1c395b14d1..91174d19bca7 100644
+--- a/libcxxabi/CMakeLists.txt
++++ b/libcxxabi/CMakeLists.txt
+@@ -522,14 +522,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
+ # Setup Source Code
+ #===============================================================================
+ 
+-set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
+-    "Specify path to libunwind includes." FORCE)
+-set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
+-    "Specify path to libunwind source." FORCE)
+-
+ include_directories(include)
+ if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
+-  find_path(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL libunwind.h
++  find_path(LIBCXXABI_LIBUNWIND_INCLUDES libunwind.h
+     PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES}
+           ${LIBCXXABI_LIBUNWIND_PATH}/include
+           ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES}
+@@ -540,15 +535,21 @@ if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
+     NO_CMAKE_FIND_ROOT_PATH
+   )
+ 
+-  if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
+-    set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
++  if (LIBCXXABI_LIBUNWIND_INCLUDES STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES-NOTFOUND")
++    set(LIBCXXABI_LIBUNWIND_INCLUDES "")
+   endif()
+ 
+-  if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
+-    include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
++  if (NOT LIBCXXABI_LIBUNWIND_INCLUDES STREQUAL "")
++    include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES}")
+   endif()
+ endif()
+ 
++set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
++    "Specify path to libunwind includes." FORCE)
++set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
++    "Specify path to libunwind source." FORCE)
++
++
+ # Add source code. This also contains all of the logic for deciding linker flags
+ # soname, etc...
+ add_subdirectory(src)
+-- 
+2.33.0
+

+ 49 - 0
recipes-devtools/clang/clang/0003-compiler-rt-Simplify-cross-compilation.-Don-t-use-na.patch

@@ -0,0 +1,49 @@
+From 3ed15d0ff104f4faada259a26d48e9bea2443e3b Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:16:47 +0800
+Subject: [PATCH] compiler-rt: Simplify cross-compilation. Don't use
+ native-compiled llvm-config
+
+    Note: AddLLVM.cmake does not expose the LLVM source directory.
+    So if you want to run the test suite, you need to either:
+
+    1) set LLVM_MAIN_SRC_DIR explicitly (to find lit.py)
+    2) change AddLLVM.cmake to point to an installed 'lit'.
+    3) add_subdirectory(compiler-rt/test) from clang instead of compiler-rt.
+
+https://us.codeaurora.org/patches/quic/llvm/50683/compiler-rt-cross-compilation.patch
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Greg Fitzgerald <gregf@codeaurora.org>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ compiler-rt/CMakeLists.txt | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
+index 17d7e4ffbdeb..690d8e171e77 100644
+--- a/compiler-rt/CMakeLists.txt
++++ b/compiler-rt/CMakeLists.txt
+@@ -82,7 +82,16 @@ set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
+   "Build for a bare-metal target.")
+ 
+ if (COMPILER_RT_STANDALONE_BUILD)
+-  load_llvm_config()
++  find_package(LLVM REQUIRED)
++  list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
++
++  # Variables that AddLLVM.cmake depends on (included by AddCompilerRT)
++  set(LLVM_TOOLS_BINARY_DIR "${LLVM_INSTALL_PREFIX}/bin")
++  set(LLVM_LIBRARY_DIR "${LLVM_INSTALL_PREFIX}/lib")
++
++  set(LLVM_LIBRARY_OUTPUT_INTDIR
++    ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
++
+   if (TARGET intrinsics_gen)
+     # Loading the llvm config causes this target to be imported so place it
+     # under the appropriate folder in an IDE.
+-- 
+2.33.0
+

+ 94 - 0
recipes-devtools/clang/clang/0004-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch

@@ -0,0 +1,94 @@
+From 8328a4461849c81976791f5668a4452e31722a0d Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:22:00 +0800
+Subject: [PATCH] llvm: TargetLibraryInfo: Undefine libc functions if they are
+ macros
+
+musl defines some functions as macros and not inline functions
+if this is the case then make sure to undefine them
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ .../llvm/Analysis/TargetLibraryInfo.def       | 21 +++++++++++++++++++
+ 1 file changed, 21 insertions(+)
+
+diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+index ded53617b304..da612e9b4352 100644
+--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def
++++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+@@ -815,6 +815,9 @@ TLI_DEFINE_STRING_INTERNAL("fmodl")
+ TLI_DEFINE_ENUM_INTERNAL(fopen)
+ TLI_DEFINE_STRING_INTERNAL("fopen")
+ /// FILE *fopen64(const char *filename, const char *opentype)
++#ifdef fopen64
++#undef fopen64
++#endif
+ TLI_DEFINE_ENUM_INTERNAL(fopen64)
+ TLI_DEFINE_STRING_INTERNAL("fopen64")
+ /// int fork();
+@@ -862,6 +865,9 @@ TLI_DEFINE_STRING_INTERNAL("fseek")
+ /// int fseeko(FILE *stream, off_t offset, int whence);
+ TLI_DEFINE_ENUM_INTERNAL(fseeko)
+ TLI_DEFINE_STRING_INTERNAL("fseeko")
++#ifdef fseeko64
++#undef fseeko64
++#endif
+ /// int fseeko64(FILE *stream, off64_t offset, int whence)
+ TLI_DEFINE_ENUM_INTERNAL(fseeko64)
+ TLI_DEFINE_STRING_INTERNAL("fseeko64")
+@@ -872,6 +878,9 @@ TLI_DEFINE_STRING_INTERNAL("fsetpos")
+ TLI_DEFINE_ENUM_INTERNAL(fstat)
+ TLI_DEFINE_STRING_INTERNAL("fstat")
+ /// int fstat64(int filedes, struct stat64 *buf)
++#ifdef fstat64
++#undef fstat64
++#endif
+ TLI_DEFINE_ENUM_INTERNAL(fstat64)
+ TLI_DEFINE_STRING_INTERNAL("fstat64")
+ /// int fstatvfs(int fildes, struct statvfs *buf);
+@@ -887,6 +896,9 @@ TLI_DEFINE_STRING_INTERNAL("ftell")
+ TLI_DEFINE_ENUM_INTERNAL(ftello)
+ TLI_DEFINE_STRING_INTERNAL("ftello")
+ /// off64_t ftello64(FILE *stream)
++#ifdef ftello64
++#undef ftello64
++#endif
+ TLI_DEFINE_ENUM_INTERNAL(ftello64)
+ TLI_DEFINE_STRING_INTERNAL("ftello64")
+ /// int ftrylockfile(FILE *file);
+@@ -1013,6 +1025,9 @@ TLI_DEFINE_STRING_INTERNAL("logl")
+ TLI_DEFINE_ENUM_INTERNAL(lstat)
+ TLI_DEFINE_STRING_INTERNAL("lstat")
+ /// int lstat64(const char *path, struct stat64 *buf);
++#ifdef lstat64
++#undef lstat64
++#endif
+ TLI_DEFINE_ENUM_INTERNAL(lstat64)
+ TLI_DEFINE_STRING_INTERNAL("lstat64")
+ /// void *malloc(size_t size);
+@@ -1256,6 +1271,9 @@ TLI_DEFINE_STRING_INTERNAL("sscanf")
+ TLI_DEFINE_ENUM_INTERNAL(stat)
+ TLI_DEFINE_STRING_INTERNAL("stat")
+ /// int stat64(const char *path, struct stat64 *buf);
++#ifdef stat64
++#undef stat64
++#endif
+ TLI_DEFINE_ENUM_INTERNAL(stat64)
+ TLI_DEFINE_STRING_INTERNAL("stat64")
+ /// int statvfs(const char *path, struct statvfs *buf);
+@@ -1391,6 +1409,9 @@ TLI_DEFINE_STRING_INTERNAL("times")
+ TLI_DEFINE_ENUM_INTERNAL(tmpfile)
+ TLI_DEFINE_STRING_INTERNAL("tmpfile")
+ /// FILE *tmpfile64(void)
++#ifdef tmpfile64
++#undef tmpfile64
++#endif
+ TLI_DEFINE_ENUM_INTERNAL(tmpfile64)
+ TLI_DEFINE_STRING_INTERNAL("tmpfile64")
+ /// int toascii(int c);
+-- 
+2.33.0
+

+ 40 - 0
recipes-devtools/clang/clang/0005-llvm-allow-env-override-of-exe-path.patch

@@ -0,0 +1,40 @@
+From 6191588e2da0460225c00491c6a14394aa932dae Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:23:08 +0800
+Subject: [PATCH] llvm: allow env override of exe path
+
+When using a native llvm-config from inside a sysroot, we need llvm-config to
+return the libraries, include directories, etc. from inside the sysroot rather
+than from the native sysroot. Thus provide an env override for calling
+llvm-config from a target sysroot.
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Martin Kelly <mkelly@xevo.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ llvm/tools/llvm-config/llvm-config.cpp | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp
+index 8afd3593272f..02260c7eb4cf 100644
+--- a/llvm/tools/llvm-config/llvm-config.cpp
++++ b/llvm/tools/llvm-config/llvm-config.cpp
+@@ -247,6 +247,13 @@ Typical components:\n\
+ 
+ /// Compute the path to the main executable.
+ std::string GetExecutablePath(const char *Argv0) {
++  // Hack for Yocto: we need to override the root path when we are using
++  // llvm-config from within a target sysroot.
++  const char *Sysroot = std::getenv("YOCTO_ALTERNATE_EXE_PATH");
++  if (Sysroot != nullptr) {
++    return Sysroot;
++  }
++
+   // This just needs to be some symbol in the binary; C++ doesn't
+   // allow taking the address of ::main however.
+   void *P = (void *)(intptr_t)GetExecutablePath;
+-- 
+2.33.0
+

+ 67 - 0
recipes-devtools/clang/clang/0006-clang-driver-Check-sysroot-for-ldso-path.patch

@@ -0,0 +1,67 @@
+From daade280c104f13b2508e9e55d4af56629907495 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:25:45 +0800
+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.
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Dan McGregor <dan.mcgregor@usask.ca>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.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 20ed697fecbc..3d49248d7343 100644
+--- a/clang/lib/Driver/ToolChains/Linux.cpp
++++ b/clang/lib/Driver/ToolChains/Linux.cpp
+@@ -480,11 +480,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);
+@@ -506,6 +514,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";
+@@ -520,6 +532,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:
+-- 
+2.33.0
+

+ 37 - 0
recipes-devtools/clang/clang/0007-clang-Driver-tools.cpp-Add-lssp_nonshared-on-musl.patch

@@ -0,0 +1,37 @@
+From e9ee4c781d0fdee8bae1a28c01d329db3cae0a77 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:26:58 +0800
+Subject: [PATCH] clang: Driver/tools.cpp: Add -lssp_nonshared on musl
+
+musl driver will need to add ssp_nonshared for stack_check_local
+on the linker cmdline when using stack protector commands on
+compiler cmdline
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/Gnu.cpp | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
+index e599f5d2a53e..5436317cde35 100644
+--- a/clang/lib/Driver/ToolChains/Gnu.cpp
++++ b/clang/lib/Driver/ToolChains/Gnu.cpp
+@@ -625,6 +625,12 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+       if (IsIAMCU)
+         CmdArgs.push_back("-lgloss");
+ 
++      if (ToolChain.getTriple().isMusl() &&
++          (Args.hasArg(options::OPT_fstack_protector) ||
++          Args.hasArg(options::OPT_fstack_protector_strong) ||
++          Args.hasArg(options::OPT_fstack_protector_all))) {
++        CmdArgs.push_back("-lssp_nonshared");
++      }
+       if (IsStatic || IsStaticPIE)
+         CmdArgs.push_back("--end-group");
+       else
+-- 
+2.33.0
+

+ 31 - 0
recipes-devtools/clang/clang/0008-clang-musl-ppc-does-not-support-128-bit-long-double.patch

@@ -0,0 +1,31 @@
+From 5e60a031126fa4adbe67976b26d3ab8712d080df Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:28:21 +0800
+Subject: [PATCH] clang: musl/ppc does not support 128-bit long double
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Basic/Targets/PPC.h | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
+index f19d3ebbc066..97861fb0b78d 100644
+--- a/clang/lib/Basic/Targets/PPC.h
++++ b/clang/lib/Basic/Targets/PPC.h
+@@ -395,6 +395,10 @@ public:
+       LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+     }
+ 
++    if (getTriple().isMusl()) {
++      LongDoubleWidth = LongDoubleAlign = 64;
++      LongDoubleFormat = &llvm::APFloat::IEEEdouble();
++    }
+     // PPC32 supports atomics up to 4 bytes.
+     MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
+   }
+-- 
+2.33.0
+

+ 44 - 0
recipes-devtools/clang/clang/0009-clang-Prepend-trailing-to-sysroot.patch

@@ -0,0 +1,44 @@
+From cbf4798c59a02769a0749ac7ec2a4dbe9a728453 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:29:40 +0800
+Subject: [PATCH] clang: Prepend trailing '/' to sysroot
+
+This is needed to handle a case where clang
+isntall and target sysroot are perilously same
+
+e.g.
+
+sysroot = /mnt/clang/recipe-sysroot
+clang install = /mnt/clang/recipe-sysroot-native
+
+in this case it will mistakenly assume that
+clang is installed under the same sysroot dir
+and it will try to add relative ../lib paths
+to linker steps which would then be wrong
+since they will become relative to clang
+installation and not sysroot
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/Linux.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
+index 3d49248d7343..e4bb78876fa0 100644
+--- a/clang/lib/Driver/ToolChains/Linux.cpp
++++ b/clang/lib/Driver/ToolChains/Linux.cpp
+@@ -181,7 +181,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
+   Multilibs = GCCInstallation.getMultilibs();
+   SelectedMultilib = GCCInstallation.getMultilib();
+   llvm::Triple::ArchType Arch = Triple.getArch();
+-  std::string SysRoot = computeSysRoot();
++  std::string SysRoot = computeSysRoot() + "/";
+   ToolChain::path_list &PPaths = getProgramPaths();
+ 
+   Generic_GCC::PushPPaths(PPaths);
+-- 
+2.33.0
+

+ 46 - 0
recipes-devtools/clang/clang/0010-clang-Look-inside-the-target-sysroot-for-compiler-ru.patch

@@ -0,0 +1,46 @@
+From 24deb7ba16e914132713f1ea7dae9b4b089870e9 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:31:50 +0800
+Subject: [PATCH] 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
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChain.cpp | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
+index df205c37f063..28e16ef5dc81 100644
+--- a/clang/lib/Driver/ToolChain.cpp
++++ b/clang/lib/Driver/ToolChain.cpp
+@@ -13,6 +13,7 @@
+ #include "ToolChains/InterfaceStubs.h"
+ #include "clang/Basic/ObjCRuntime.h"
+ #include "clang/Basic/Sanitizers.h"
++#include "clang/Basic/Version.h"
+ #include "clang/Config/config.h"
+ #include "clang/Driver/Action.h"
+ #include "clang/Driver/Driver.h"
+@@ -410,7 +411,10 @@ StringRef ToolChain::getOSLibName() const {
+ }
+ 
+ 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.33.0
+

+ 52 - 0
recipes-devtools/clang/clang/0011-clang-Define-releative-gcc-installation-dir.patch

@@ -0,0 +1,52 @@
+From 8ff2f565e0ddf0ce7913d33eafaa7f3b8951039f Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:33:23 +0800
+Subject: [PATCH] clang: Define / releative gcc installation dir
+
+This is required for OE gcc installation to work.
+Without this its not able to find the paths for libgcc
+and other standard headers and libraries from gcc
+installation in OE
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/Gnu.cpp | 14 +++++++-------
+ 1 file changed, 7 insertions(+), 7 deletions(-)
+
+diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
+index 5436317cde35..308f0d963311 100644
+--- a/clang/lib/Driver/ToolChains/Gnu.cpp
++++ b/clang/lib/Driver/ToolChains/Gnu.cpp
+@@ -2523,19 +2523,19 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
+     // Whether this library suffix is relevant for the triple.
+     bool Active;
+   } Suffixes[] = {
+-      // This is the normal place.
+-      {"gcc/" + CandidateTriple.str(), "../..", GCCDirExists},
+-
+-      // Debian puts cross-compilers in gcc-cross.
+-      {"gcc-cross/" + CandidateTriple.str(), "../..", GCCCrossDirExists},
+-
+       // The Freescale PPC SDK has the gcc libraries in
+       // <sysroot>/usr/lib/<triple>/x.y.z so have a look there as well. Only do
+       // this on Freescale triples, though, since some systems put a *lot* of
+       // files in that location, not just GCC installation data.
+       {CandidateTriple.str(), "..",
+        TargetTriple.getVendor() == llvm::Triple::Freescale ||
+-           TargetTriple.getVendor() == llvm::Triple::OpenEmbedded}};
++           TargetTriple.getVendor() == llvm::Triple::OpenEmbedded},
++
++      // This is the normal place.
++      {"gcc/" + CandidateTriple.str(), "../..", GCCDirExists},
++
++      // Debian puts cross-compilers in gcc-cross.
++      {"gcc-cross/" + CandidateTriple.str(), "../..", GCCCrossDirExists}};
+ 
+   for (auto &Suffix : Suffixes) {
+     if (!Suffix.Active)
+-- 
+2.33.0
+

+ 40 - 0
recipes-devtools/clang/clang/0012-clang-Add-lpthread-and-ldl-along-with-lunwind-for-st.patch

@@ -0,0 +1,40 @@
+From 0ff61cb900ac870458ffa5a0b49755c3eb0367e1 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:35:03 +0800
+Subject: [PATCH] clang: Add -lpthread and -ldl along with -lunwind for static
+ linking
+
+When doing static liking with --unwindlib=libunwind -static we encounter
+undefined symbols
+libunwind/src/RWMutex.hpp:68: undefined reference to `pthread_rwlock_wrlock'
+
+and
+
+libunwind/src/AddressSpace.hpp:597: undefined reference to `dladdr'
+
+therefore we need to link in libpthread and libdl to fill these symbols
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
+index c3abdf446cfa..99dac6d394f8 100644
+--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
++++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
+@@ -1450,6 +1450,8 @@ static void AddUnwindLibrary(const ToolChain &TC, const Driver &D,
+         CmdArgs.push_back("-lunwind");
+     } else if (LGT == LibGccType::StaticLibGcc) {
+       CmdArgs.push_back("-l:libunwind.a");
++      CmdArgs.push_back("-lpthread");
++      CmdArgs.push_back("-ldl");
+     } else if (TC.getTriple().isOSCygMing()) {
+       if (LGT == LibGccType::SharedLibGcc)
+         CmdArgs.push_back("-l:libunwind.dll.a");
+-- 
+2.33.0
+

+ 29 - 0
recipes-devtools/clang/clang/0013-Pass-PYTHON_EXECUTABLE-when-cross-compiling-for-nati.patch

@@ -0,0 +1,29 @@
+From 25948f78aeb54b5103b593af57c0f50dea744bbf Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:36:29 +0800
+Subject: [PATCH] Pass PYTHON_EXECUTABLE when cross compiling for native build
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ llvm/cmake/modules/CrossCompile.cmake | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
+index 179d183ed2b7..d555eb1f2da1 100644
+--- a/llvm/cmake/modules/CrossCompile.cmake
++++ b/llvm/cmake/modules/CrossCompile.cmake
+@@ -79,6 +79,7 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
+         -DLLVM_EXTERNAL_PROJECTS="${llvm_external_projects_arg}"
+         ${external_project_source_dirs}
+         -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN="${LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN}"
++	-DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}"
+         ${build_type_flags} ${linker_flag} ${external_clang_dir}
+         ${ARGN}
+     WORKING_DIRECTORY ${${project_name}_${target_name}_BUILD}
+-- 
+2.33.0
+

+ 39 - 0
recipes-devtools/clang/clang/0014-Check-for-atomic-double-intrinsics.patch

@@ -0,0 +1,39 @@
+From 59e66928b489591a960f9663dc588f33bae65617 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:37:31 +0800
+Subject: [PATCH] Check for atomic<double> intrinsics
+
+On some architectures e.g. x86/32bit gcc decides to inline calls to
+double atomic variables but clang does not and defers it to libatomic
+therefore detect if clang can use built-ins for atomic<double> if not
+then link libatomic, this helps building clangd for x86 on linux systems
+with gcc runtime
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ llvm/cmake/modules/CheckAtomic.cmake | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/llvm/cmake/modules/CheckAtomic.cmake b/llvm/cmake/modules/CheckAtomic.cmake
+index 3c5ba72993a3..34a1b950bbed 100644
+--- a/llvm/cmake/modules/CheckAtomic.cmake
++++ b/llvm/cmake/modules/CheckAtomic.cmake
+@@ -30,10 +30,11 @@ function(check_working_cxx_atomics64 varname)
+ #include <atomic>
+ #include <cstdint>
+ std::atomic<uint64_t> x (0);
++std::atomic<double> y (0);
+ int main() {
+   uint64_t i = x.load(std::memory_order_relaxed);
+   (void)i;
+-  return 0;
++  return int(y);
+ }
+ " ${varname})
+   set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
+-- 
+2.33.0
+

+ 43 - 0
recipes-devtools/clang/clang/0015-libcxx-Add-compiler-runtime-library-to-link-step-for.patch

@@ -0,0 +1,43 @@
+From d596b3bcd348b21d523e23e60f50541f9b0e40be Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:39:25 +0800
+Subject: [PATCH] libcxx: Add compiler runtime library to link step for libcxx
+
+This corrects "undefined reference to __divti3"
+
+Upstream-Status: Inappropriate [configuration]
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Jeremy Puhlman <jpuhlman@mvista.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ libcxx/src/CMakeLists.txt | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
+index b5a870a5a499..d864080561d0 100644
+--- a/libcxx/src/CMakeLists.txt
++++ b/libcxx/src/CMakeLists.txt
+@@ -197,7 +197,7 @@ split_list(LIBCXX_LINK_FLAGS)
+ if (LIBCXX_ENABLE_SHARED)
+   add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
+   target_link_libraries(cxx_shared PUBLIC cxx-headers
+-                                   PRIVATE ${LIBCXX_LIBRARIES})
++                                   PRIVATE ${LIBCXX_LIBRARIES} "$$($$CC --print-libgcc-file-name)")
+   set_target_properties(cxx_shared
+     PROPERTIES
+       COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
+@@ -275,7 +275,7 @@ set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+ if (LIBCXX_ENABLE_STATIC)
+   add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
+   target_link_libraries(cxx_static PUBLIC cxx-headers
+-                                   PRIVATE ${LIBCXX_LIBRARIES})
++                                   PRIVATE ${LIBCXX_LIBRARIES} "$$($$CC --print-libgcc-file-name)")
+   set_target_properties(cxx_static
+     PROPERTIES
+       COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
+-- 
+2.33.0
+

+ 122 - 0
recipes-devtools/clang/clang/0016-clang-llvm-cmake-Fix-configure-for-packages-using-fi.patch

@@ -0,0 +1,122 @@
+From 2e93c0280148283e2d3d525972ad8a2a54861c5f Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:43:42 +0800
+Subject: [PATCH] clang,llvm: cmake: Fix configure for packages using
+ find_package()
+
+Currently, when a package (i.e. bcc [https://github.com/iovisor/bcc.git])
+that depends on LLVM/Clang tries to run cmake find_package() during
+do_configure, it will fail with a similar error:
+
+|   The imported target "llvm-tblgen" references the file
+|      ".../recipe-sysroot/usr/bin/llvm-tblgen"
+|
+|   but this file does not exist.  Possible reasons include:
+|   * The file was deleted, renamed, or moved to another location.
+|   * An install or uninstall procedure did not complete successfully.
+|   * The installation package was faulty and contained
+|      ".../recipe-sysroot/usr/lib/cmake/LLVMExports.cmake"
+|   but not all the files it references.
+
+This is due to the fact that currently the cmake scripts look for target
+binaries in sysroot. Work around this by not exporting the target binaries in
+Exports-* cmake files.
+
+Upstream-Status: Innapropriate [oe-specific]
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/cmake/modules/AddClang.cmake | 2 --
+ llvm/cmake/modules/AddLLVM.cmake   | 6 ------
+ llvm/cmake/modules/TableGen.cmake  | 7 -------
+ 3 files changed, 15 deletions(-)
+
+diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
+index 5752f4277444..f40ea35faf46 100644
+--- a/clang/cmake/modules/AddClang.cmake
++++ b/clang/cmake/modules/AddClang.cmake
+@@ -158,7 +158,6 @@ macro(add_clang_tool name)
+   if (CLANG_BUILD_TOOLS)
+     get_target_export_arg(${name} Clang export_to_clangtargets)
+     install(TARGETS ${name}
+-      ${export_to_clangtargets}
+       RUNTIME DESTINATION bin
+       COMPONENT ${name})
+ 
+@@ -167,7 +166,6 @@ macro(add_clang_tool name)
+                                DEPENDS ${name}
+                                COMPONENT ${name})
+     endif()
+-    set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
+   endif()
+ endmacro()
+ 
+diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
+index 6e1f97a8bbc0..e29bdee0aaa3 100644
+--- a/llvm/cmake/modules/AddLLVM.cmake
++++ b/llvm/cmake/modules/AddLLVM.cmake
+@@ -1244,7 +1244,6 @@ macro(add_llvm_tool name)
+     if( LLVM_BUILD_TOOLS )
+       get_target_export_arg(${name} LLVM export_to_llvmexports)
+       install(TARGETS ${name}
+-              ${export_to_llvmexports}
+               RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
+               COMPONENT ${name})
+ 
+@@ -1255,9 +1254,6 @@ macro(add_llvm_tool name)
+       endif()
+     endif()
+   endif()
+-  if( LLVM_BUILD_TOOLS )
+-    set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
+-  endif()
+   set_target_properties(${name} PROPERTIES FOLDER "Tools")
+ endmacro(add_llvm_tool name)
+ 
+@@ -1297,7 +1293,6 @@ macro(add_llvm_utility name)
+     if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
+       get_target_export_arg(${name} LLVM export_to_llvmexports)
+       install(TARGETS ${name}
+-              ${export_to_llvmexports}
+               RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR}
+               COMPONENT ${name})
+ 
+@@ -1306,7 +1301,6 @@ macro(add_llvm_utility name)
+                                  DEPENDS ${name}
+                                  COMPONENT ${name})
+       endif()
+-      set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
+     elseif(LLVM_BUILD_UTILS)
+       set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})
+     endif()
+diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake
+index 5e9e2674405e..3c72df35b308 100644
+--- a/llvm/cmake/modules/TableGen.cmake
++++ b/llvm/cmake/modules/TableGen.cmake
+@@ -179,14 +179,8 @@ macro(add_tablegen target project)
+   endif()
+ 
+   if ((${project} STREQUAL LLVM OR ${project} STREQUAL MLIR) AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND LLVM_BUILD_UTILS)
+-    set(export_to_llvmexports)
+-    if(${target} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
+-        NOT LLVM_DISTRIBUTION_COMPONENTS)
+-      set(export_to_llvmexports EXPORT LLVMExports)
+-    endif()
+ 
+     install(TARGETS ${target}
+-            ${export_to_llvmexports}
+             COMPONENT ${target}
+             RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR})
+     if(NOT LLVM_ENABLE_IDE)
+@@ -195,5 +189,4 @@ macro(add_tablegen target project)
+                                COMPONENT ${target})
+     endif()
+   endif()
+-  set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${target})
+ endmacro()
+-- 
+2.33.0
+

+ 45 - 0
recipes-devtools/clang/clang/0017-clang-Fix-resource-dir-location-for-cross-toolchains.patch

@@ -0,0 +1,45 @@
+From e0dabff9a904003c4032672d787a610479738b02 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:44:46 +0800
+Subject: [PATCH] clang: Fix resource dir location for cross toolchains
+
+When clang looks for the resources directory, it does so based on the binary
+location and assumes that the containing directory is a sibling to lib. The
+Yocto cross.bbclass defines the default bindir as
+${exec_prefix}/bin/${CROSS_TARGET_SYS_DIR}. ex: /usr/bin/aarch64-poky-linux/.
+This causes clang to form a path that looks like /usr/bin/lib/clang/...
+
+As a fix for this, check the parent directory name. If that is "bin", then
+use that directory's parent.
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Jim Broadus <jbroadus@xevo.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/Driver.cpp | 8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
+index b9960059e707..a64b222f7f49 100644
+--- a/clang/lib/Driver/Driver.cpp
++++ b/clang/lib/Driver/Driver.cpp
+@@ -122,7 +122,13 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath,
+     // With a static-library build of libclang, LibClangPath will contain the
+     // path of the embedding binary, which for LLVM binaries will be in bin/.
+     // ../lib gets us to lib/ in both cases.
+-    P = llvm::sys::path::parent_path(Dir);
++    Dir = std::string(llvm::sys::path::parent_path(Dir));
++
++    // OE cross toolchains are installed, by default, in a subdir of bin.
++    if (llvm::sys::path::filename(Dir) == "bin") {
++      Dir = std::string(llvm::sys::path::parent_path(Dir));
++    }
++    P = Dir;
+     llvm::sys::path::append(P, Twine("lib") + CLANG_LIBDIR_SUFFIX, "clang",
+                             CLANG_VERSION_STRING);
+   }
+-- 
+2.33.0
+

+ 32 - 0
recipes-devtools/clang/clang/0018-fix-path-to-libffi.patch

@@ -0,0 +1,32 @@
+From a1d6263590cc88211e48cc174347c8cc058c87c6 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:45:59 +0800
+Subject: [PATCH] fix path to libffi
+
+FFI_LIBRARY_PATH is the full path to libffi so when building something that links to
+libLLVMInterpreter, we were looking for libffi in clang's recipe-sysroot instead of
+the recipe's sysroot.
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt b/llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt
+index 976219830d5e..9930e01559e9 100644
+--- a/llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt
++++ b/llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt
+@@ -22,5 +22,5 @@ add_llvm_component_library(LLVMInterpreter
+   )
+ 
+ if( LLVM_ENABLE_FFI )
+-  target_link_libraries( LLVMInterpreter PRIVATE ${FFI_LIBRARY_PATH} )
++  target_link_libraries( LLVMInterpreter PRIVATE ffi )
+ endif()
+-- 
+2.33.0
+

+ 73 - 0
recipes-devtools/clang/clang/0019-clang-driver-Add-dyld-prefix-when-checking-sysroot-f.patch

@@ -0,0 +1,73 @@
+From 219dd48b4a4adf5bee26eae3557b352732aca7fe Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:48:23 +0800
+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.
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Oleksandr Ocheretnyi <oocheret@cisco.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/Linux.cpp | 16 ++++++++--------
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
+index e4bb78876fa0..2c49a2669d5a 100644
+--- a/clang/lib/Driver/ToolChains/Linux.cpp
++++ b/clang/lib/Driver/ToolChains/Linux.cpp
+@@ -480,8 +480,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;
+@@ -489,8 +489,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;
+@@ -514,8 +514,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;
+@@ -532,8 +532,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;
+-- 
+2.33.0
+

+ 107 - 0
recipes-devtools/clang/clang/0020-clang-Use-python3-in-python-scripts.patch

@@ -0,0 +1,107 @@
+From d3fd767d2857cf423dd59ba7fd9d8f8682b08061 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:54:10 +0800
+Subject: [PATCH] clang: Use python3 in python scripts
+
+Some scripts ask for python, but they work fine with python3
+and in OE python symlink is not exposed to build, only python3 is
+
+Upstream-Status: Pending
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ .../find-all-symbols/tool/run-find-all-symbols.py               | 2 +-
+ clang-tools-extra/clang-tidy/add_new_check.py                   | 2 +-
+ clang-tools-extra/clang-tidy/rename_check.py                    | 2 +-
+ clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py            | 2 +-
+ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py             | 2 +-
+ clang/tools/clang-format/git-clang-format                       | 2 +-
+ clang/tools/scan-view/bin/scan-view                             | 2 +-
+ clang/utils/hmaptool/hmaptool                                   | 2 +-
+ 8 files changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+index 8655af137bb2..e95ba59a421c 100755
+--- a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
++++ b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ #
+ #=- run-find-all-symbols.py - Parallel find-all-symbols runner -*- python  -*-=#
+ #
+diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py
+index a3554b095975..1429a387ea86 100755
+--- a/clang-tools-extra/clang-tidy/add_new_check.py
++++ b/clang-tools-extra/clang-tidy/add_new_check.py
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ #
+ #===- add_new_check.py - clang-tidy check generator ---------*- python -*--===#
+ #
+diff --git a/clang-tools-extra/clang-tidy/rename_check.py b/clang-tools-extra/clang-tidy/rename_check.py
+index 9c2021751e0e..4bb9af8cbe0a 100755
+--- a/clang-tools-extra/clang-tidy/rename_check.py
++++ b/clang-tools-extra/clang-tidy/rename_check.py
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ #
+ #===- rename_check.py - clang-tidy check renamer ------------*- python -*--===#
+ #
+diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+index 6bd05531333b..9e134123ef44 100755
+--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
++++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ #
+ #===- clang-tidy-diff.py - ClangTidy Diff Checker -----------*- python -*--===#
+ #
+diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+index acd1ed6979c0..12bd7f9c7dc3 100755
+--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
++++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ #
+ #===- run-clang-tidy.py - Parallel clang-tidy runner --------*- python -*--===#
+ #
+diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
+index c7e15eb7b483..ea29131fc5ad 100755
+--- a/clang/tools/clang-format/git-clang-format
++++ b/clang/tools/clang-format/git-clang-format
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ #
+ #===- git-clang-format - ClangFormat Git Integration ---------*- python -*--===#
+ #
+diff --git a/clang/tools/scan-view/bin/scan-view b/clang/tools/scan-view/bin/scan-view
+index 6165432e7af8..07effbca5969 100755
+--- a/clang/tools/scan-view/bin/scan-view
++++ b/clang/tools/scan-view/bin/scan-view
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ 
+ from __future__ import print_function
+ 
+diff --git a/clang/utils/hmaptool/hmaptool b/clang/utils/hmaptool/hmaptool
+index e647cde6bc46..7ed2fdf674b1 100755
+--- a/clang/utils/hmaptool/hmaptool
++++ b/clang/utils/hmaptool/hmaptool
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ from __future__ import absolute_import, division, print_function
+ 
+ import json
+-- 
+2.33.0
+

+ 76 - 0
recipes-devtools/clang/clang/0021-For-x86_64-set-Yocto-based-GCC-install-search-path.patch

@@ -0,0 +1,76 @@
+From 09620dba70723238d138f5b9b5160539768773ee Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:55:29 +0800
+Subject: [PATCH] For x86_64, set Yocto based GCC install search path
+
+Under Yocto host, while using clang-native to build, it searches
+install host gcc failed which causing the include file not found
+[snip]
+|clang++ -target x86_64-linux  -MMD -MF src/base/files/file_path_constants.o.d -I../../../tools/gn/src -I. \
+-isystem/tmp-glibc/work/x86_64-linux/gn-native/87.0.4280.141-r0/recipe-sysroot-native/usr/include -O2 -pipe \
+-std=c++17 -c ../../../tools/gn/src/base/files/file_path_constants.cc -o src/base/files/file_path_constants.o
+|../../../tools/gn/src/base/files/file_path_constants.cc:7:10: fatal error: 'iterator' file not found
+|#include <iterator>
+|         ^~~~~~~~
+[snip]
+
+Set three Yocto based GCC triple: poky, oe-core and wind river
+
+Before aplly the patch
+[snip]
+$ ../recipe-sysroot-native/usr/bin/clang++ -v
+clang version 11.0.1 (https://github.com/llvm/llvm-project 43ff75f2c3feef64f9d73328230d34dac8832a91)
+Target: x86_64-unknown-linux-gnu
+Thread model: posix
+InstalledDir:tmp-glibc/work/x86_64-linux/gn-native/87.0.4280.141-r0/chromium-87.0.4280.141/../recipe-sysroot-native/usr/bin
+[snip]
+
+After aplly the patch:
+[snip]
+$ ../recipe-sysroot-native/usr/bin/clang++ -v
+clang version 11.0.1 (https://github.com/llvm/llvm-project 22c3241ff9a6224261df48d0258957fd8acc3d64)
+Target: x86_64-unknown-linux-gnu
+Thread model: posix
+InstalledDir:tmp-glibc/work/x86_64-linux/gn-native/87.0.4280.141-r0/chromium-87.0.4280.141/../recipe-sysroot-native/usr/bin
+Found candidate GCC installation: /usr/lib//x86_64-wrs-linux/10.1.0
+Found candidate GCC installation: /usr/lib/gcc/x86_64-wrs-linux/10.1.0
+Selected GCC installation: /usr/lib//x86_64-wrs-linux/10.1.0
+Candidate multilib: .;@m64
+Selected multilib: .;@m64
+[snip]
+
+BTW, it is hardly to insert a triple by the replacement of TARGET_SYS
+(=${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}), since TARGET_VENDOR
+is different between clang and clang-native
+
+The //CLANG_EXTRA_OE_VENDORS_TRIPLES string is replaced with list of
+additional triples based on CLANG_EXTRA_OE_VENDORS variable in
+recipes-devtools/clang/llvm-project-source.inc:add_more_target_vendors()
+
+Upstream-Status: Inappropriate [oe specific]
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Martin Jansa <martin.jansa@gmail.com>
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/Gnu.cpp | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
+index 308f0d963311..5c9c14435543 100644
+--- a/clang/lib/Driver/ToolChains/Gnu.cpp
++++ b/clang/lib/Driver/ToolChains/Gnu.cpp
+@@ -2111,6 +2111,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
+       "x86_64-redhat-linux",    "x86_64-suse-linux",
+       "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
+       "x86_64-slackware-linux", "x86_64-unknown-linux",
++      "x86_64-oe-linux",//CLANG_EXTRA_OE_VENDORS_TRIPLES
+       "x86_64-amazon-linux"};
+   static const char *const X32Triples[] = {"x86_64-linux-gnux32",
+                                            "x86_64-pc-linux-gnux32"};
+-- 
+2.33.0
+

+ 50 - 0
recipes-devtools/clang/clang/0022-llvm-Do-not-use-find_library-for-ncurses.patch

@@ -0,0 +1,50 @@
+From 72a96fefcafb5aa677c2e9ec8dd36f30855f3398 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:57:22 +0800
+Subject: [PATCH] llvm: Do not use find_library for ncurses
+
+This ensures that it lets OE to decide which lib to link
+otherwise it adds absolute paths to linker cmdline and confuses it
+horribly with native and target libs when build clang for target
+
+TOPDIR/build/tmp/work/cortexa57-yoe-linux-musl/clang/12.0.0-r0/recipe-sysroot-native/usr/lib/libtinfo.so: error adding symbols: file in wrong format
+clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ compiler-rt/cmake/config-ix.cmake | 2 +-
+ llvm/cmake/config-ix.cmake        | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
+index e2985dccc645..ffe090910bd7 100644
+--- a/compiler-rt/cmake/config-ix.cmake
++++ b/compiler-rt/cmake/config-ix.cmake
+@@ -152,7 +152,7 @@ else()
+   set(MAYBE_REQUIRED)
+ endif()
+ if(LLVM_ENABLE_TERMINFO)
+-  find_library(COMPILER_RT_TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED})
++  set(TERMINFO_LIB tinfo curses ncurses ncursesw)
+ endif()
+ if(COMPILER_RT_TERMINFO_LIB)
+   set(LLVM_ENABLE_TERMINFO 1)
+diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
+index c81b7e47ac78..09491a65d12f 100644
+--- a/llvm/cmake/config-ix.cmake
++++ b/llvm/cmake/config-ix.cmake
+@@ -197,7 +197,7 @@ if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
+       set(MAYBE_REQUIRED)
+     endif()
+     if(LLVM_ENABLE_TERMINFO)
+-      find_library(TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED})
++      set(TERMINFO_LIB tinfo curses ncurses ncursesw)
+     endif()
+     if(TERMINFO_LIB)
+       set(LLVM_ENABLE_TERMINFO 1)
+-- 
+2.33.0
+

+ 38 - 0
recipes-devtools/clang/clang/0023-llvm-Insert-anchor-for-adding-OE-distro-vendor-names.patch

@@ -0,0 +1,38 @@
+From a067f57d6e782aaee39c5bd8e818c4b3cc1d4333 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 11:58:39 +0800
+Subject: [PATCH] llvm: Insert anchor for adding OE distro vendor names
+
+This helps in making right detection for OE built gcc toolchains
+
+The //CLANG_EXTRA_OE_VENDORS_CASES string is replaced with list of
+additional Ceses based on CLANG_EXTRA_OE_VENDORS variable in
+recipes-devtools/clang/llvm-project-source.inc:add_more_target_vendors()
+
+Upstream-Status: Inappropriate [OE-specific]
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Martin Jansa <martin.jansa@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ llvm/lib/Support/Triple.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp
+index ec055869adfa..e89d7b15b68e 100644
+--- a/llvm/lib/Support/Triple.cpp
++++ b/llvm/lib/Support/Triple.cpp
+@@ -496,7 +496,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) {
+     .Case("amd", Triple::AMD)
+     .Case("mesa", Triple::Mesa)
+     .Case("suse", Triple::SUSE)
+-    .Case("oe", Triple::OpenEmbedded)
++    .Case("oe", Triple::OpenEmbedded)//CLANG_EXTRA_OE_VENDORS_CASES
+     .Default(Triple::UnknownVendor);
+ }
+ 
+-- 
+2.33.0
+

+ 78 - 0
recipes-devtools/clang/clang/0024-compiler-rt-Use-mcr-based-barrier-on-armv6.patch

@@ -0,0 +1,78 @@
+From 40af4d126a4266d4bea0e7cf4a51224e96f4258c Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:00:51 +0800
+Subject: [PATCH] compiler-rt: Use mcr based barrier on armv6
+
+dsb is an armv7 instruction and wont work when we are building for armv6.
+
+Upstream-Status: Pending
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ compiler-rt/lib/builtins/arm/sync-ops.h | 8 ++++----
+ compiler-rt/lib/builtins/assembly.h     | 8 ++++++++
+ 2 files changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/compiler-rt/lib/builtins/arm/sync-ops.h b/compiler-rt/lib/builtins/arm/sync-ops.h
+index c9623249e5d2..7a26170741ad 100644
+--- a/compiler-rt/lib/builtins/arm/sync-ops.h
++++ b/compiler-rt/lib/builtins/arm/sync-ops.h
+@@ -19,14 +19,14 @@
+   .thumb;                                                                      \
+   .syntax unified;                                                             \
+   DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_##op)                      \
+-  dmb;                                                                         \
++  DMB;                                                                         \
+   mov r12, r0;                                                                 \
+   LOCAL_LABEL(tryatomic_##op) : ldrex r0, [r12];                               \
+   op(r2, r0, r1);                                                              \
+   strex r3, r2, [r12];                                                         \
+   cmp r3, #0;                                                                  \
+   bne LOCAL_LABEL(tryatomic_##op);                                             \
+-  dmb;                                                                         \
++  DMB;                                                                         \
+   bx lr
+ 
+ #define SYNC_OP_8(op)                                                          \
+@@ -35,14 +35,14 @@
+   .syntax unified;                                                             \
+   DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_##op)                      \
+   push {r4, r5, r6, lr};                                                       \
+-  dmb;                                                                         \
++  DMB;                                                                         \
+   mov r12, r0;                                                                 \
+   LOCAL_LABEL(tryatomic_##op) : ldrexd r0, r1, [r12];                          \
+   op(r4, r5, r0, r1, r2, r3);                                                  \
+   strexd r6, r4, r5, [r12];                                                    \
+   cmp r6, #0;                                                                  \
+   bne LOCAL_LABEL(tryatomic_##op);                                             \
+-  dmb;                                                                         \
++  DMB;                                                                         \
+   pop { r4, r5, r6, pc }
+ 
+ #define MINMAX_4(rD, rN, rM, cmp_kind)                                         \
+diff --git a/compiler-rt/lib/builtins/assembly.h b/compiler-rt/lib/builtins/assembly.h
+index 9c015059af5a..aec4ff59beb7 100644
+--- a/compiler-rt/lib/builtins/assembly.h
++++ b/compiler-rt/lib/builtins/assembly.h
+@@ -183,6 +183,14 @@
+   JMP(ip)
+ #endif
+ 
++#if __ARM_ARCH >= 7
++#define DMB dmb
++#elif __ARM_ARCH >= 6
++#define DMB mcr p15, #0, r0, c7, c10, #5
++#else
++#error Only use this with ARMv6+
++#endif
++
+ #if defined(USE_THUMB_2)
+ #define WIDE(op) op.w
+ #else
+-- 
+2.33.0
+

+ 35 - 0
recipes-devtools/clang/clang/0025-clang-Switch-defaults-to-dwarf-5-debug-info-on-Linux.patch

@@ -0,0 +1,35 @@
+From 4cb0d0c154acebb80112a811ed9850d27c4963a9 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:03:20 +0800
+Subject: [PATCH] clang: Switch defaults to dwarf-5 debug info on Linux
+
+GCC 11 has defaulted to DWARF-5 as well, this matches
+debug info formats,  so mix and match of components with GCC 11
+works.
+
+Upstream-Status: Pending
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/Linux.h | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/clang/lib/Driver/ToolChains/Linux.h b/clang/lib/Driver/ToolChains/Linux.h
+index 169a37c44072..f432d36c0d17 100644
+--- a/clang/lib/Driver/ToolChains/Linux.h
++++ b/clang/lib/Driver/ToolChains/Linux.h
+@@ -61,6 +61,8 @@ public:
+       const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
+       const llvm::fltSemantics *FPType = nullptr) const override;
+ 
++  unsigned GetDefaultDwarfVersion() const override { return 5; }
++
+ protected:
+   Tool *buildAssembler() const override;
+   Tool *buildLinker() const override;
+-- 
+2.33.0
+

+ 75 - 0
recipes-devtools/clang/clang/0026-compiler-rt-Do-not-use-backtrace-APIs-on-non-glibc-l.patch

@@ -0,0 +1,75 @@
+From 011c8d4ffe4b8f5cf27ca9a7181359f1c0c43ae3 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:06:04 +0800
+Subject: [PATCH] compiler-rt: Do not use backtrace APIs on non-glibc linux
+
+musl e.g. does not provide backtrace APIs
+
+Upstream-Status: Pending
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ .../lib/gwp_asan/optional/backtrace_linux_libc.cpp  | 13 ++++++++++++-
+ 1 file changed, 12 insertions(+), 1 deletion(-)
+
+diff --git a/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp b/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
+index ea8e72be287d..0344074dd254 100644
+--- a/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
++++ b/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
+@@ -7,7 +7,9 @@
+ //===----------------------------------------------------------------------===//
+ 
+ #include <assert.h>
++#ifdef __GLIBC__
+ #include <execinfo.h>
++#endif
+ #include <stddef.h>
+ #include <stdint.h>
+ #include <stdlib.h>
+@@ -21,8 +23,11 @@
+ namespace {
+ size_t Backtrace(uintptr_t *TraceBuffer, size_t Size) {
+   static_assert(sizeof(uintptr_t) == sizeof(void *), "uintptr_t is not void*");
+-
++#ifdef __GLIBC__
+   return backtrace(reinterpret_cast<void **>(TraceBuffer), Size);
++#else
++  return -1;
++#endif
+ }
+ 
+ // We don't need any custom handling for the Segv backtrace - the libc unwinder
+@@ -30,7 +35,11 @@ size_t Backtrace(uintptr_t *TraceBuffer, size_t Size) {
+ // to avoid the additional frame.
+ GWP_ASAN_ALWAYS_INLINE size_t SegvBacktrace(uintptr_t *TraceBuffer, size_t Size,
+                                             void * /*Context*/) {
++#ifdef __GLIBC__
+   return Backtrace(TraceBuffer, Size);
++#else
++  return -1;
++#endif
+ }
+ 
+ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
+@@ -40,6 +49,7 @@ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
+     return;
+   }
+ 
++#ifdef __GLIBC__
+   char **BacktraceSymbols =
+       backtrace_symbols(reinterpret_cast<void **>(Trace), TraceLength);
+ 
+@@ -53,6 +63,7 @@ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
+   Printf("\n");
+   if (BacktraceSymbols)
+     free(BacktraceSymbols);
++#endif
+ }
+ } // anonymous namespace
+ 
+-- 
+2.33.0
+

+ 33 - 0
recipes-devtools/clang/clang/0027-clang-Fix-x86-triple-for-non-debian-multiarch-linux-.patch

@@ -0,0 +1,33 @@
+From a673cf3e631818ddc59a1d420f137d1bc291994f Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:07:35 +0800
+Subject: [PATCH] clang: Fix x86 triple for non-debian multiarch linux distros
+
+OpenEmbedded does not hardcode mutli-arch like debian therefore ensure
+that it still uses the proper tuple
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/Linux.cpp | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
+index 2c49a2669d5a..cb6e57e4b976 100644
+--- a/clang/lib/Driver/ToolChains/Linux.cpp
++++ b/clang/lib/Driver/ToolChains/Linux.cpp
+@@ -623,6 +623,9 @@ void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
+       GCCInstallation.getTriple().getArch() == llvm::Triple::x86
+           ? "i386-linux-gnu"
+           : TripleStr;
++  // OpenEmbedded does not hardcode the triple to i386-linux-gnu like debian
++  if (GCCInstallation.getTriple().getVendor() == llvm::Triple::OpenEmbedded)
++	  DebianMultiarch = TripleStr;
+ 
+   // Try generic GCC detection first.
+   if (Generic_GCC::addGCCLibStdCxxIncludePaths(DriverArgs, CC1Args,
+-- 
+2.33.0
+

+ 34 - 0
recipes-devtools/clang/clang/0028-compiler-rt-Link-scudo-with-SANITIZER_CXX_ABI_LIBRAR.patch

@@ -0,0 +1,34 @@
+From 9de37866a9a16ca9ba511ad846dd2c4ae37a2371 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:08:37 +0800
+Subject: [PATCH] compiler-rt: Link scudo with SANITIZER_CXX_ABI_LIBRARIES
+
+If SANITIZER_CXX_ABI_LIBRARIES is set then link scudo with it, this
+fixes build time errors like
+
+projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.armhf.dir/sanitizer_posix_libcdep.cpp.o: in function `__sanitizer::UnsetAlternateSignalStack()':
+| sanitizer_posix_libcdep.cpp:(.text+0x3d2): undefined reference to `__cxa_guard_acquire'
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ compiler-rt/lib/scudo/CMakeLists.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/compiler-rt/lib/scudo/CMakeLists.txt b/compiler-rt/lib/scudo/CMakeLists.txt
+index 995e853e2a4d..25b79a8d17e8 100644
+--- a/compiler-rt/lib/scudo/CMakeLists.txt
++++ b/compiler-rt/lib/scudo/CMakeLists.txt
+@@ -15,6 +15,7 @@ append_list_if(COMPILER_RT_HAS_LIBDL dl SCUDO_MINIMAL_DYNAMIC_LIBS)
+ append_list_if(COMPILER_RT_HAS_LIBRT rt SCUDO_MINIMAL_DYNAMIC_LIBS)
+ append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread SCUDO_MINIMAL_DYNAMIC_LIBS)
+ append_list_if(COMPILER_RT_HAS_LIBLOG log SCUDO_MINIMAL_DYNAMIC_LIBS)
++append_list_if(SANITIZER_CXX_ABI_LIBRARIES ${SANITIZER_CXX_ABI_LIBRARIES} SCUDO_MINIMAL_DYNAMIC_LIBS)
+ append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer
+                SCUDO_CFLAGS)
+ 
+-- 
+2.33.0
+

+ 36 - 0
recipes-devtools/clang/clang/0029-compiler-rt-Link-scudo-standalone-with-libatomic-on-.patch

@@ -0,0 +1,36 @@
+From 711f43f7cec85e5c21f4a76c65695a838d84c1fa Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:09:32 +0800
+Subject: [PATCH] compiler-rt: Link scudo standalone with libatomic on mips
+
+clang on mips generate atomic built-ins which should be provided by
+libatomic
+
+Upstream-Status: Pending
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ compiler-rt/lib/scudo/standalone/CMakeLists.txt | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+index 739f131bdefd..5862545b842b 100644
+--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
++++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+@@ -137,6 +137,10 @@ append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread SCUDO_LINK_FLAGS)
+ 
+ append_list_if(FUCHSIA zircon SCUDO_LINK_LIBS)
+ 
++if (CMAKE_SYSTEM_PROCESSOR MATCHES "mips" AND CMAKE_SYSTEM_NAME MATCHES "Linux")
++    list(APPEND SCUDO_LINK_LIBS atomic)
++endif()
++
+ if(COMPILER_RT_HAS_SCUDO_STANDALONE)
+   add_compiler_rt_object_libraries(RTScudoStandalone
+     ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
+-- 
+2.33.0
+

+ 61 - 0
recipes-devtools/clang/clang/0030-libunwind-Added-unw_backtrace-method.patch

@@ -0,0 +1,61 @@
+From 34e4284dc6f57ecc69e29538bc244df5c803c7ec Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:11:57 +0800
+Subject: [PATCH] libunwind: Added unw_backtrace method
+
+Source: https://github.com/ClickHouse-Extras/libunwind/commit/52f0f7861926cbfaef7e6c97d8a6d7ba2a1f6747#diff-a82fc885e2e4facf4b92d26171c13aa4aa5db296f77e1158ba2f8664e3bd1f5c
+Upstream-Status: Pending
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ libunwind/include/libunwind.h |  1 +
+ libunwind/src/libunwind.cpp   | 18 ++++++++++++++++++
+ 2 files changed, 19 insertions(+)
+
+diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
+index 5ba63e5b7e5b..c49172f87362 100644
+--- a/libunwind/include/libunwind.h
++++ b/libunwind/include/libunwind.h
+@@ -127,6 +127,7 @@ extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
+ extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
+ extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
+ //extern int       unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
++extern int unw_backtrace(void **, int) LIBUNWIND_AVAIL;
+ 
+ extern unw_addr_space_t unw_local_addr_space;
+ 
+diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
+index 93e1bc131f0c..7ae1a10092ab 100644
+--- a/libunwind/src/libunwind.cpp
++++ b/libunwind/src/libunwind.cpp
+@@ -295,7 +295,25 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {
+ #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
+ #endif // !defined(__USING_SJLJ_EXCEPTIONS__)
+ 
++int unw_backtrace(void **buffer, int size) {
++  unw_context_t context;
++  unw_cursor_t cursor;
++  if (unw_getcontext(&context) || unw_init_local(&cursor, &context)) {
++    return 0;
++  }
++
++  unw_word_t ip;
++  int current = 0;
++  while (unw_step(&cursor) > 0) {
++    if (current >= size || unw_get_reg(&cursor, UNW_REG_IP, &ip)) {
++      break;
++    }
+ 
++    buffer[current++] = reinterpret_cast<void *>(static_cast<uintptr_t>(ip));
++  }
++
++  return current;
++}
+ 
+ // Add logging hooks in Debug builds only
+ #ifndef NDEBUG
+-- 
+2.33.0
+

+ 41 - 0
recipes-devtools/clang/clang/0031-compiler-rt-Use-uintptr_t-instead-of-_Unwind_Word.patch

@@ -0,0 +1,41 @@
+From 3c285c6071bf73a279c058dfc250faaab422602e Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:13:05 +0800
+Subject: [PATCH] compiler-rt: Use uintptr_t instead of _Unwind_Word
+
+_Unwind_Word is defined in compiler specific unwind.h but not in
+libunwind provided unwind.h header, it works in most cases because
+compilers search compiler headers ahead of system headers but for some
+systems e.g. musl bases systems the compiler provided versions are not
+preferred over system headers and therefore relying on _Unwind_Word
+means its expecting this define in all unwind.h headers which is not the
+case, using uintptr_t means we don't need this from unwind.h
+
+See https://reviews.llvm.org/D65699
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ compiler-rt/lib/hwasan/hwasan_exceptions.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/compiler-rt/lib/hwasan/hwasan_exceptions.cpp b/compiler-rt/lib/hwasan/hwasan_exceptions.cpp
+index 169e7876cb58..6ed1da335428 100644
+--- a/compiler-rt/lib/hwasan/hwasan_exceptions.cpp
++++ b/compiler-rt/lib/hwasan/hwasan_exceptions.cpp
+@@ -29,8 +29,8 @@ typedef _Unwind_Reason_Code PersonalityFn(int version, _Unwind_Action actions,
+ // is statically linked and the sanitizer runtime and the program are linked
+ // against different unwinders. The _Unwind_Context data structure is opaque so
+ // it may be incompatible between unwinders.
+-typedef _Unwind_Word GetGRFn(_Unwind_Context* context, int index);
+-typedef _Unwind_Word GetCFAFn(_Unwind_Context* context);
++typedef uintptr_t GetGRFn(_Unwind_Context* context, int index);
++typedef uintptr_t GetCFAFn(_Unwind_Context* context);
+ 
+ extern "C" SANITIZER_INTERFACE_ATTRIBUTE _Unwind_Reason_Code
+ __hwasan_personality_wrapper(int version, _Unwind_Action actions,
+-- 
+2.33.0
+

+ 52 - 0
recipes-devtools/clang/clang/0032-compiler-rt-Do-not-force-thumb-mode-directive.patch

@@ -0,0 +1,52 @@
+From fcc2ba4ad05bd5427f2bef62d034a047a3312ae5 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:14:20 +0800
+Subject: [PATCH] compiler-rt: Do not force thumb mode directive
+
+.thumb_func was not switching mode until [1]
+so it did not show up but now that .thumb_func (without argument) is
+switching mode, its causing build failures on armv6 ( rpi0 ) even when
+build is explicitly asking for this file to be built with -marm (ARM
+mode), therefore use DEFINE_COMPILERRT_FUNCTION macro to add function
+header which considers arch and mode from compiler cmdline to decide if
+the function is built using thumb mode or arm mode.
+
+[1] https://reviews.llvm.org/D101975
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ compiler-rt/lib/builtins/arm/sync-ops.h | 6 ++----
+ 1 file changed, 2 insertions(+), 4 deletions(-)
+
+diff --git a/compiler-rt/lib/builtins/arm/sync-ops.h b/compiler-rt/lib/builtins/arm/sync-ops.h
+index 7a26170741ad..d914f9d3a109 100644
+--- a/compiler-rt/lib/builtins/arm/sync-ops.h
++++ b/compiler-rt/lib/builtins/arm/sync-ops.h
+@@ -16,9 +16,8 @@
+ 
+ #define SYNC_OP_4(op)                                                          \
+   .p2align 2;                                                                  \
+-  .thumb;                                                                      \
+   .syntax unified;                                                             \
+-  DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_##op)                      \
++  DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_##op)                            \
+   DMB;                                                                         \
+   mov r12, r0;                                                                 \
+   LOCAL_LABEL(tryatomic_##op) : ldrex r0, [r12];                               \
+@@ -31,9 +30,8 @@
+ 
+ #define SYNC_OP_8(op)                                                          \
+   .p2align 2;                                                                  \
+-  .thumb;                                                                      \
+   .syntax unified;                                                             \
+-  DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_##op)                      \
++  DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_##op)                            \
+   push {r4, r5, r6, lr};                                                       \
+   DMB;                                                                         \
+   mov r12, r0;                                                                 \
+-- 
+2.33.0
+

+ 74 - 0
recipes-devtools/clang/clang/0033-Drop-the-git-suffix-from-various-version-variables.patch

@@ -0,0 +1,74 @@
+From b81d3b0aeef54a3e38b5fa89961e468d6019d772 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:17:09 +0800
+Subject: [PATCH] Drop the 'git' suffix from various version variables
+
+Upstream-Status: Backport [cherry-picked from branch 12.0.0]
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Changqing Li <changqing.li@windriver.com>
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ libcxx/CMakeLists.txt                                           | 2 +-
+ libcxxabi/CMakeLists.txt                                        | 2 +-
+ libunwind/CMakeLists.txt                                        | 2 +-
+ .../llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h | 2 +-
+ 4 files changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
+index 51951e50e16a..46964f5e2a1c 100644
+--- a/libcxx/CMakeLists.txt
++++ b/libcxx/CMakeLists.txt
+@@ -29,7 +29,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUIL
+   project(libcxx CXX C)
+ 
+   set(PACKAGE_NAME libcxx)
+-  set(PACKAGE_VERSION 14.0.0git)
++  set(PACKAGE_VERSION 14.0.0)
+   set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+   set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
+ 
+diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
+index 91174d19bca7..6196a5c3a416 100644
+--- a/libcxxabi/CMakeLists.txt
++++ b/libcxxabi/CMakeLists.txt
+@@ -30,7 +30,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_B
+   project(libcxxabi CXX C)
+ 
+   set(PACKAGE_NAME libcxxabi)
+-  set(PACKAGE_VERSION 11.0.0git)
++  set(PACKAGE_VERSION 11.0.0)
+   set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+   set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
+ 
+diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
+index 59d489b909e4..942220cbafca 100644
+--- a/libunwind/CMakeLists.txt
++++ b/libunwind/CMakeLists.txt
+@@ -26,7 +26,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_B
+   project(libunwind LANGUAGES C CXX ASM)
+ 
+   set(PACKAGE_NAME libunwind)
+-  set(PACKAGE_VERSION 14.0.0git)
++  set(PACKAGE_VERSION 14.0.0)
+   set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+   set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
+ 
+diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h
+index 6b64c9a06005..11cc1c227fbf 100644
+--- a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h
++++ b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h
+@@ -83,7 +83,7 @@
+ #define LLVM_VERSION_PATCH 0
+ 
+ /* LLVM version string */
+-#define LLVM_VERSION_STRING "14.0.0git"
++#define LLVM_VERSION_STRING "14.0.0"
+ 
+ /* Whether LLVM records statistics for use with GetStatistics(),
+  * PrintStatistics() or PrintStatisticsJSON()
+-- 
+2.33.0
+

+ 39 - 0
recipes-devtools/clang/clang/0034-clang-Do-not-use-install-relative-libc-headers.patch

@@ -0,0 +1,39 @@
+From 7000ce5145240304d0cbd55dbac37270eb7cd3e7 Mon Sep 17 00:00:00 2001
+From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+Date: Fri, 22 Oct 2021 12:18:11 +0800
+Subject: [PATCH] clang: Do not use install relative libc++ headers
+
+In OE we use same clang for native and cross builds, therefore we need
+to ensure that native sysroot install of libc++ is not searched for
+headers when doing cross compile instead it searches the target sysroot
+this is especially troublesome when libcxx-native is staged along with
+libcxx e.g. chromium
+
+Upstream-Status: Pending
+
+Rebased to LLVM 14.0.0 by Jun Yuan Tan
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
+---
+ clang/lib/Driver/ToolChains/Gnu.cpp | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
+index 5c9c14435543..6d51aacaef14 100644
+--- a/clang/lib/Driver/ToolChains/Gnu.cpp
++++ b/clang/lib/Driver/ToolChains/Gnu.cpp
+@@ -2923,7 +2923,9 @@ Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
+ 
+   // Android never uses the libc++ headers installed alongside the toolchain,
+   // which are generally incompatible with the NDK libraries anyway.
+-  if (!getTriple().isAndroid())
++  // And also do not add it when --sysroot is specified, since it would expect
++  // libc++ headers from sysroot
++  if (!getTriple().isAndroid() && SysRoot.empty())
+     if (AddIncludePath(getDriver().Dir + "/../include"))
+       return;
+   // If this is a development, non-installed, clang, libcxx will
+-- 
+2.33.0
+

+ 65 - 0
recipes-devtools/clang/clang/fix-clang-driver-gcc-install-path-on-openembedded.patch

@@ -0,0 +1,65 @@
+diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
+index e56812145e6d..b02c228d40af 100644
+--- a/clang/lib/Driver/ToolChains/Gnu.cpp
++++ b/clang/lib/Driver/ToolChains/Gnu.cpp
+@@ -1650,18 +1650,29 @@ static void findRISCVMultilibs(const Driver &D,
+     return findRISCVBareMetalMultilibs(D, TargetTriple, Path, Args, Result);
+ 
+   FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
+-  Multilib Ilp32 = makeMultilib("lib32/ilp32").flag("+m32").flag("+mabi=ilp32");
+-  Multilib Ilp32f =
++  MultilibSet RISCVMultilibs;
++
++  if (TargetTriple.getVendor() == llvm::Triple::OpenEmbedded) {
++    Multilib OpenEmbeddedIlp32d = makeMultilib("").flag("+m32").flag("+mabi=ilp32d");
++    Multilib OpenEmbeddedLp64d = makeMultilib("").flag("+m64").flag("+mabi=lp64d");
++    RISCVMultilibs =
++        MultilibSet()
++            .Either({OpenEmbeddedIlp32d, OpenEmbeddedLp64d})
++            .FilterOut(NonExistent);
++  } else {
++    Multilib Ilp32 = makeMultilib("lib32/ilp32").flag("+m32").flag("+mabi=ilp32");
++    Multilib Ilp32f =
+       makeMultilib("lib32/ilp32f").flag("+m32").flag("+mabi=ilp32f");
+-  Multilib Ilp32d =
++    Multilib Ilp32d =
+       makeMultilib("lib32/ilp32d").flag("+m32").flag("+mabi=ilp32d");
+-  Multilib Lp64 = makeMultilib("lib64/lp64").flag("+m64").flag("+mabi=lp64");
+-  Multilib Lp64f = makeMultilib("lib64/lp64f").flag("+m64").flag("+mabi=lp64f");
+-  Multilib Lp64d = makeMultilib("lib64/lp64d").flag("+m64").flag("+mabi=lp64d");
+-  MultilibSet RISCVMultilibs =
+-      MultilibSet()
+-          .Either({Ilp32, Ilp32f, Ilp32d, Lp64, Lp64f, Lp64d})
+-          .FilterOut(NonExistent);
++    Multilib Lp64 = makeMultilib("lib64/lp64").flag("+m64").flag("+mabi=lp64");
++    Multilib Lp64f = makeMultilib("lib64/lp64f").flag("+m64").flag("+mabi=lp64f");
++    Multilib Lp64d = makeMultilib("lib64/lp64d").flag("+m64").flag("+mabi=lp64d");
++    RISCVMultilibs =
++        MultilibSet()
++            .Either({Ilp32, Ilp32f, Ilp32d, Lp64, Lp64f, Lp64d})
++            .FilterOut(NonExistent);
++  }
+ 
+   Multilib::flags_list Flags;
+   bool IsRV64 = TargetTriple.getArch() == llvm::Triple::riscv64;
+@@ -2563,13 +2574,19 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
+           continue; // Saw this path before; no need to look at it again.
+       if (CandidateVersion.isOlderThan(4, 1, 1))
+         continue;
+-      if (CandidateVersion <= Version)
++      if (CandidateVersion < Version)
+         continue;
+ 
+       if (!ScanGCCForMultilibs(TargetTriple, Args, LI->path(),
+                                NeedsBiarchSuffix))
+         continue;
+ 
++      // We might have found existing directory with GCCVersion, but it
++      // might not have GCC libraries we are looking for (i.e. return an
++      // empty Mulilibs)
++      if (Multilibs.size() == 0)
++        continue;
++
+       Version = CandidateVersion;
+       GCCTriple.setTriple(CandidateTriple);
+       // FIXME: We hack together the directory name here instead of

+ 9 - 0
recipes-devtools/clang/clang/libunwind.pc.in

@@ -0,0 +1,9 @@
+prefix=/usr
+exec_prefix=/usr
+libdir=@LIBDIR@
+includedir=/usr/include
+
+Name: libunwind
+Description: libunwind base library
+Version: @VERSION@
+Libs: -lunwind

+ 44 - 0
recipes-devtools/clang/clang/llvm-config

@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# Wrapper script for llvm-config. Supplies the right environment variables
+# for the target and delegates to the native llvm-config for anything else. This
+# is needed because arguments like --ldflags, --cxxflags, etc. are set by the
+# native compile rather than the target compile.
+#
+
+SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
+NEXT_LLVM_CONFIG="$(which -a llvm-config | sed -n 2p)"
+export YOCTO_ALTERNATE_EXE_PATH="$(readlink -f "$SCRIPT_DIR/../llvm-config")"
+
+if [[ $# == 0 ]]; then
+  exec "$NEXT_LLVM_CONFIG"
+fi
+
+if [[ $1 == "--libs" ]]; then
+  exec "$NEXT_LLVM_CONFIG" $@
+fi
+
+if [[ $1 == "--bindir" ]]; then
+  unset YOCTO_ALTERNATE_EXE_PATH
+  exec "$NEXT_LLVM_CONFIG" $@
+fi
+
+for arg in "$@"; do
+  case "$arg" in
+    --cppflags)
+      echo $TARGET_CPPFLAGS
+      ;;
+    --cflags)
+      echo $TARGET_CFLAGS
+      ;;
+    --cxxflags)
+      echo $TARGET_CXXFLAGS
+      ;;
+    --ldflags)
+      echo $TARGET_LDFLAGS
+      ;;
+    *)
+      echo "$("$NEXT_LLVM_CONFIG" "$arg")"
+      ;;
+  esac
+done

+ 7 - 0
recipes-devtools/clang/clang_git.bbappend

@@ -0,0 +1,7 @@
+MAJOR_VER = "14"
+MINOR_VER = "0"
+PATCH_VER = "0"
+
+LDFLAGS:remove:class-nativesdk = "-fuse-ld=lld"
+
+FILES_${PN} += "${libdir}/*"

+ 3 - 0
recipes-devtools/clang/compiler-rt_git.bbappend

@@ -0,0 +1,3 @@
+MAJOR_VER = "14"
+MINOR_VER = "0"
+PATCH_VER = "0"

+ 3 - 0
recipes-devtools/clang/libcxx_git.bbappend

@@ -0,0 +1,3 @@
+MAJOR_VER = "14"
+MINOR_VER = "0"
+PATCH_VER = "0"

+ 52 - 0
recipes-devtools/clang/llvm-project-source.bbappend

@@ -0,0 +1,52 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/clang:"
+
+MAJOR_VER = "14"
+MINOR_VER = "0"
+PATCH_VER = "0"
+
+SRCREV = "6b715e9c4d9cc00f59906d48cd57f4c767229093"
+BRANCH = "main"
+
+SRC_URI = "\
+    ${BASEURI} \
+    file://llvm-config \
+    file://libunwind.pc.in \
+    file://0001-lldb-Add-lxml2-to-linker-cmdline-of-xml-is-found.patch \
+    file://0002-libcxxabi-Find-libunwind-headers-when-LIBCXXABI_LIBU.patch \
+    file://0003-compiler-rt-Simplify-cross-compilation.-Don-t-use-na.patch \
+    file://0004-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch \
+    file://0005-llvm-allow-env-override-of-exe-path.patch \
+    file://0006-clang-driver-Check-sysroot-for-ldso-path.patch \
+    file://0007-clang-Driver-tools.cpp-Add-lssp_nonshared-on-musl.patch \
+    file://0008-clang-musl-ppc-does-not-support-128-bit-long-double.patch \
+    file://0009-clang-Prepend-trailing-to-sysroot.patch \
+    file://0010-clang-Look-inside-the-target-sysroot-for-compiler-ru.patch \
+    file://0011-clang-Define-releative-gcc-installation-dir.patch \
+    file://0012-clang-Add-lpthread-and-ldl-along-with-lunwind-for-st.patch \
+    file://0013-Pass-PYTHON_EXECUTABLE-when-cross-compiling-for-nati.patch \
+    file://0014-Check-for-atomic-double-intrinsics.patch \
+    file://0015-libcxx-Add-compiler-runtime-library-to-link-step-for.patch \
+    file://0016-clang-llvm-cmake-Fix-configure-for-packages-using-fi.patch \
+    file://0017-clang-Fix-resource-dir-location-for-cross-toolchains.patch \
+    file://0018-fix-path-to-libffi.patch \
+    file://0019-clang-driver-Add-dyld-prefix-when-checking-sysroot-f.patch \
+    file://0020-clang-Use-python3-in-python-scripts.patch \
+    file://0021-For-x86_64-set-Yocto-based-GCC-install-search-path.patch \
+    file://0022-llvm-Do-not-use-find_library-for-ncurses.patch \
+    file://0023-llvm-Insert-anchor-for-adding-OE-distro-vendor-names.patch \
+    file://0024-compiler-rt-Use-mcr-based-barrier-on-armv6.patch \
+    file://0025-clang-Switch-defaults-to-dwarf-5-debug-info-on-Linux.patch \
+    file://0026-compiler-rt-Do-not-use-backtrace-APIs-on-non-glibc-l.patch \
+    file://0027-clang-Fix-x86-triple-for-non-debian-multiarch-linux-.patch \
+    file://0028-compiler-rt-Link-scudo-with-SANITIZER_CXX_ABI_LIBRAR.patch \
+    file://0029-compiler-rt-Link-scudo-standalone-with-libatomic-on-.patch \
+    file://0030-libunwind-Added-unw_backtrace-method.patch \
+    file://0031-compiler-rt-Use-uintptr_t-instead-of-_Unwind_Word.patch \
+    file://0032-compiler-rt-Do-not-force-thumb-mode-directive.patch \
+    file://0033-Drop-the-git-suffix-from-various-version-variables.patch \
+    file://0034-clang-Do-not-use-install-relative-libc-headers.patch \
+    "
+
+SRC_URI:append:riscv64 = " \
+        file://fix-clang-driver-gcc-install-path-on-openembedded.patch \
+        "

+ 181 - 0
recipes-devtools/llvm/llvm_git.bb

@@ -0,0 +1,181 @@
+# Copyright (C) 2017 Khem Raj <raj.khem@gmail.com>
+# Released under the MIT license (see COPYING.MIT for the terms)
+
+DESCRIPTION = "The LLVM Compiler Infrastructure"
+HOMEPAGE = "http://llvm.org"
+LICENSE = "Apache-2.0-with-LLVM-exception"
+SECTION = "devel"
+
+LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=8a15a0759ef07f2682d2ba4b893c9afe"
+
+DEPENDS = "libffi libxml2 zlib libedit ninja-native llvm-native"
+
+RDEPENDS:${PN}:append:class-target = " ncurses-terminfo"
+
+inherit cmake pkgconfig
+
+PROVIDES += "llvm${PV}"
+
+MAJOR_VERSION = "14"
+MINOR_VERSION = "0"
+PATCH_VERSION = "0"
+
+PV = "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
+
+LLVM_RELEASE = "${PV}"
+LLVM_DIR = "llvm${LLVM_RELEASE}"
+
+BRANCH = "main"
+SRCREV = "6b715e9c4d9cc00f59906d48cd57f4c767229093"
+SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH} \
+          "
+
+UPSTREAM_CHECK_GITTAGREGEX = "llvmorg-(?P<pver>\d+(\.\d+)+)"
+
+S = "${WORKDIR}/git/llvm"
+
+LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install"
+
+def get_llvm_arch(bb, d, arch_var):
+    import re
+    a = d.getVar(arch_var)
+    if   re.match(r'(i.86|athlon|x86.64)$', a):         return 'X86'
+    elif re.match(r'arm$', a):                          return 'ARM'
+    elif re.match(r'armeb$', a):                        return 'ARM'
+    elif re.match(r'aarch64$', a):                      return 'AArch64'
+    elif re.match(r'aarch64_be$', a):                   return 'AArch64'
+    elif re.match(r'mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
+    elif re.match(r'riscv(32|64)(eb|)$', a):            return 'RISCV'
+    elif re.match(r'p(pc|owerpc)(|64)', a):             return 'PowerPC'
+    else:
+        raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
+
+def get_llvm_host_arch(bb, d):
+    return get_llvm_arch(bb, d, 'HOST_ARCH')
+
+#
+# Default to build all OE-Core supported target arches (user overridable).
+#
+LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}"
+
+ARM_INSTRUCTION_SET_armv5 = "arm"
+ARM_INSTRUCTION_SET_armv4t = "arm"
+
+EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
+                  -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
+                  -DLLVM_ENABLE_PIC=ON \
+                  -DLLVM_BINDINGS_LIST='' \
+                  -DLLVM_LINK_LLVM_DYLIB=ON \
+                  -DLLVM_ENABLE_FFI=ON \
+                  -DLLVM_ENABLE_RTTI=ON \
+                  -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
+                  -DLLVM_OPTIMIZED_TABLEGEN=ON \
+                  -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \
+                  -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
+                  -DPYTHON_EXECUTABLE=${HOSTTOOLS_DIR}/python3 \
+                  -G Ninja"
+
+EXTRA_OECMAKE:append:class-target = "\
+                  -DCMAKE_CROSSCOMPILING:BOOL=ON \
+                  -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
+                  -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
+                 "
+
+EXTRA_OECMAKE:append:class-nativesdk = "\
+                  -DCMAKE_CROSSCOMPILING:BOOL=ON \
+                  -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
+                  -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
+                 "
+
+CFLAGS += "-fcommon"
+
+do_configure:prepend() {
+# Fix paths in llvm-config
+	sed -i "s|sys::path::parent_path(CurrentPath))\.str()|sys::path::parent_path(sys::path::parent_path(CurrentPath))).str()|g" ${S}/tools/llvm-config/llvm-config.cpp
+	sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp
+	sed -ri "s#lib/${LLVM_DIR}#${baselib}/${LLVM_DIR}#g" ${S}/tools/llvm-config/llvm-config.cpp
+}
+
+do_compile() {
+	ninja -v ${PARALLEL_MAKE}
+}
+
+do_compile:class-native() {
+	ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
+}
+
+do_install() {
+	DESTDIR=${LLVM_INSTALL_DIR} ninja -v install
+	install -D -m 0755 ${B}/bin/llvm-config ${D}${libdir}/${LLVM_DIR}/llvm-config
+
+	install -d ${D}${bindir}/${LLVM_DIR}
+	cp -r ${LLVM_INSTALL_DIR}${bindir}/* ${D}${bindir}/${LLVM_DIR}/
+
+	install -d ${D}${includedir}/${LLVM_DIR}
+	cp -r ${LLVM_INSTALL_DIR}${includedir}/* ${D}${includedir}/${LLVM_DIR}/
+
+	install -d ${D}${libdir}/${LLVM_DIR}
+
+	# The LLVM sources have "/lib" embedded and so we cannot completely rely on the ${libdir} variable
+	if [ -d ${LLVM_INSTALL_DIR}${libdir}/ ]; then
+		cp -r ${LLVM_INSTALL_DIR}${libdir}/* ${D}${libdir}/${LLVM_DIR}/
+	elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib ]; then
+		cp -r ${LLVM_INSTALL_DIR}${prefix}/lib/* ${D}${libdir}/${LLVM_DIR}/
+	elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib64 ]; then
+		cp -r ${LLVM_INSTALL_DIR}${prefix}/lib64/* ${D}${libdir}/${LLVM_DIR}/
+	fi
+
+	# Remove unnecessary cmake files
+	rm -rf ${D}${libdir}/${LLVM_DIR}/cmake
+
+	ln -s ${LLVM_DIR}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV} ${D}${libdir}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV}
+
+	# We'll have to delete the libLLVM.so due to multiple reasons...
+	rm -rf ${D}${libdir}/${LLVM_DIR}/libLLVM.so
+	rm -rf ${D}${libdir}/${LLVM_DIR}/libLTO.so
+}
+
+do_install:class-native() {
+	install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
+	install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
+	install -D -m 0755 ${B}/lib/libLLVM-${MAJOR_VERSION}.so ${D}${libdir}/libLLVM-${MAJOR_VERSION}.so
+}
+
+PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
+
+RRECOMMENDS:${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
+
+FILES:${PN}-bugpointpasses = "\
+    ${libdir}/${LLVM_DIR}/BugpointPasses.so \
+"
+
+FILES:${PN}-libllvm = "\
+    ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.so \
+    ${libdir}/libLLVM-${MAJOR_VERSION}.so \
+"
+
+FILES:${PN}-liblto += "\
+    ${libdir}/${LLVM_DIR}/libLTO.so.* \
+"
+
+FILES:${PN}-liboptremarks += "\
+    ${libdir}/${LLVM_DIR}/libRemarks.so.* \
+"
+
+FILES:${PN}-llvmhello = "\
+    ${libdir}/${LLVM_DIR}/LLVMHello.so \
+"
+
+FILES:${PN}-dev += " \
+    ${libdir}/${LLVM_DIR}/llvm-config \
+    ${libdir}/${LLVM_DIR}/libRemarks.so \
+    ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.so \
+"
+
+FILES:${PN}-staticdev += "\
+    ${libdir}/${LLVM_DIR}/*.a \
+"
+
+INSANE_SKIP:${PN}-libllvm += "dev-so"
+
+BBCLASSEXTEND = "native nativesdk"

+ 3 - 4
recipes-kernel/linux/files/defconfig

@@ -3,6 +3,7 @@ CONFIG_SYSVIPC=y
 CONFIG_POSIX_MQUEUE=y
 CONFIG_NO_HZ_IDLE=y
 CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BPF_SYSCALL=y
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_CGROUPS=y
@@ -15,8 +16,7 @@ CONFIG_CHECKPOINT_RESTORE=y
 CONFIG_BLK_DEV_INITRD=y
 #CONFIG_INITRAMFS_SOURCE="rootfs.cpio"
 CONFIG_EXPERT=y
-CONFIG_BPF_SYSCALL=y
-CONFIG_SOC_SIFIVE=y
+CONFIG_SOC_STARFIVE_DUBHE=y
 CONFIG_SMP=y
 CONFIG_HOTPLUG_CPU=y
 # CONFIG_EFI is not set
@@ -79,9 +79,8 @@ CONFIG_VIRTIO_MMIO=y
 CONFIG_GOLDFISH=y
 CONFIG_RPMSG_CHAR=y
 CONFIG_RPMSG_VIRTIO=y
-# CONFIG_NVDLA is not set
+CONFIG_RESET_CONTROLLER=y
 CONFIG_AUTOFS4_FS=y
-CONFIG_EXT4_FS=y
 CONFIG_MSDOS_FS=y
 CONFIG_VFAT_FS=y
 CONFIG_FAT_DEFAULT_UTF8=y

+ 1 - 1
recipes-kernel/linux/linux-starfive-dev.bb

@@ -5,7 +5,7 @@ SUMMARY = "BeagleV dev kernel recipe"
 LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"
 KERNEL_VERSION_SANITY_SKIP = "1"
 
-SRCREV = "8cb8c83456bff1938d95b88de4b5eb248e8475d8"
+SRCREV = "df274f896002ba26ab4fac799f09cac34cca6820"
 FORK ?= "starfive-tech"
 BRANCH ?= "esmil_starlight"
 SRC_URI = "git://github.com/${FORK}/linux.git;protocol=git;branch=${BRANCH} \

+ 3 - 3
recipes-kernel/linux/linux-starfive-dev.bbappend

@@ -1,12 +1,12 @@
 FORK = "starfive-tech"
-BRANCH = "starfive-5.13"
+BRANCH = "starfive-5.14"
 
-LINUX_VERSION ?= "5.13.0"
+LINUX_VERSION ?= "5.14.0"
 LINUX_VERSION_EXTENSION_append = "-starlight"
 
 FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
 
-SRC_URI = "git://github.com/starfive-tech/linux.git;protocol=git;branch=${BRANCH}"
+SRC_URI = "git://git@192.168.110.45/starfive-tech/linux;protocol=ssh;branch=${BRANCH}"
 
 INITRAMFS_IMAGE_BUNDLE = "1"
 

+ 1 - 0
setup.sh

@@ -48,6 +48,7 @@ bitbake-layers add-layer ../meta-openembedded/meta-filesystems
 bitbake-layers add-layer ../meta-openembedded/meta-networking
 bitbake-layers add-layer ../meta-riscv
 bitbake-layers add-layer ../meta-starfive
+bitbake-layers add-layer ../meta-clang
 
 # fix the configuration
 echo "Creating auto.conf"

+ 3 - 1
tools/manifests/starfive.xml

@@ -4,13 +4,15 @@
   <remote name="openembedded" fetch="git://github.com/openembedded/" />
   <remote name="riscv" fetch="git://github.com/riscv/" />
   <default remote="openembedded" revision="master" />
-  <remote name="starfive" fetch="git://github.com/starfive-tech" />
+  <remote name="starfive" fetch="ssh://git@192.168.110.45/starfive-tech" />
+  <remote name="kraj" fetch="git://github.com/kraj" />
 
   <project name="meta-riscv" remote="riscv" path="meta-riscv" revision="hardknott" />
   <project name="openembedded-core" remote="openembedded" path="openembedded-core" revision="hardknott" />
   <project name="bitbake" remote="openembedded" path="openembedded-core/bitbake" revision="1.50" />
   <project name="meta-openembedded" remote="openembedded" path="meta-openembedded" revision="hardknott" />
   <project name="meta-starfive" remote="starfive" path="meta-starfive" revision="starfive-hardknott" />
+  <project name="meta-clang" remote="kraj" path="meta-clang" revision="hardknott" />
 
 </manifest>
 

+ 1 - 0
tools/setup.sh

@@ -48,6 +48,7 @@ bitbake-layers add-layer ../meta-openembedded/meta-filesystems
 bitbake-layers add-layer ../meta-openembedded/meta-networking
 bitbake-layers add-layer ../meta-riscv
 bitbake-layers add-layer ../meta-starfive
+bitbake-layers add-layer ../meta-clang
 
 # fix the configuration
 echo "Creating auto.conf"