0017-clang-Fix-resource-dir-location-for-cross-toolchains.patch 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. From 0427b4e815f6cdcc0ba24691807c211305c8f3c5 Mon Sep 17 00:00:00 2001
  2. From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
  3. Date: Tue, 9 Nov 2021 10:33:07 +0800
  4. Subject: [PATCH 17/34] clang: Fix resource dir location for cross toolchains
  5. When clang looks for the resources directory, it does so based on the binary
  6. location and assumes that the containing directory is a sibling to lib. The
  7. Yocto cross.bbclass defines the default bindir as
  8. ${exec_prefix}/bin/${CROSS_TARGET_SYS_DIR}. ex: /usr/bin/aarch64-poky-linux/.
  9. This causes clang to form a path that looks like /usr/bin/lib/clang/...
  10. As a fix for this, check the parent directory name. If that is "bin", then
  11. use that directory's parent.
  12. Rebased to LLVM 14.0.0 by Jun Yuan Tan
  13. Signed-off-by: Jim Broadus <jbroadus@xevo.com>
  14. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  15. Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
  16. ---
  17. clang/lib/Driver/Driver.cpp | 8 +++++++-
  18. 1 file changed, 7 insertions(+), 1 deletion(-)
  19. diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
  20. index b2fb21b7052a..7e8c64a62f7e 100644
  21. --- a/clang/lib/Driver/Driver.cpp
  22. +++ b/clang/lib/Driver/Driver.cpp
  23. @@ -122,7 +122,13 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath,
  24. // With a static-library build of libclang, LibClangPath will contain the
  25. // path of the embedding binary, which for LLVM binaries will be in bin/.
  26. // ../lib gets us to lib/ in both cases.
  27. - P = llvm::sys::path::parent_path(Dir);
  28. + Dir = std::string(llvm::sys::path::parent_path(Dir));
  29. +
  30. + // OE cross toolchains are installed, by default, in a subdir of bin.
  31. + if (llvm::sys::path::filename(Dir) == "bin") {
  32. + Dir = std::string(llvm::sys::path::parent_path(Dir));
  33. + }
  34. + P = Dir;
  35. llvm::sys::path::append(P, Twine("lib") + CLANG_LIBDIR_SUFFIX, "clang",
  36. CLANG_VERSION_STRING);
  37. }
  38. --
  39. 2.33.1