Skip to content

Commit 6fa1b4c

Browse files
Jim Broaduskraj
authored andcommitted
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. Upstream-Status: Pending Signed-off-by: Jim Broadus <jbroadus@xevo.com> Signed-off-by: Khem Raj <raj.khem@gmail.com>
1 parent db33f6f commit 6fa1b4c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath) {
188188

189189
// Dir is bin/ or lib/, depending on where BinaryPath is.
190190
StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
191+
StringRef LastDirName = llvm::sys::path::filename(Dir);
191192
SmallString<128> P(Dir);
192193

193194
StringRef ConfiguredResourceDir(CLANG_RESOURCE_DIR);
@@ -199,9 +200,15 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath) {
199200
// With a static-library build of libclang, LibClangPath will contain the
200201
// path of the embedding binary, which for LLVM binaries will be in bin/.
201202
// ../lib gets us to lib/ in both cases.
202-
P = llvm::sys::path::parent_path(Dir);
203203
// This search path is also created in the COFF driver of lld, so any
204204
// changes here also needs to happen in lld/COFF/Driver.cpp
205+
206+
// OE cross toolchains are installed, by default, in a subdir of bin.
207+
if (LastDirName == "bin") {
208+
P = llvm::sys::path::parent_path(Dir);
209+
} else {
210+
P = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
211+
}
205212
llvm::sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang",
206213
CLANG_VERSION_MAJOR_STRING);
207214
}

0 commit comments

Comments
 (0)