Skip to content

Commit dae85dd

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 83e186a commit dae85dd

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
@@ -176,6 +176,7 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath) {
176176

177177
// Dir is bin/ or lib/, depending on where BinaryPath is.
178178
StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
179+
StringRef LastDirName = llvm::sys::path::filename(Dir);
179180
SmallString<128> P(Dir);
180181

181182
StringRef ConfiguredResourceDir(CLANG_RESOURCE_DIR);
@@ -187,9 +188,15 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath) {
187188
// With a static-library build of libclang, LibClangPath will contain the
188189
// path of the embedding binary, which for LLVM binaries will be in bin/.
189190
// ../lib gets us to lib/ in both cases.
190-
P = llvm::sys::path::parent_path(Dir);
191191
// This search path is also created in the COFF driver of lld, so any
192192
// changes here also needs to happen in lld/COFF/Driver.cpp
193+
194+
// OE cross toolchains are installed, by default, in a subdir of bin.
195+
if (LastDirName == "bin") {
196+
P = llvm::sys::path::parent_path(Dir);
197+
} else {
198+
P = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
199+
}
193200
llvm::sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang",
194201
CLANG_VERSION_MAJOR_STRING);
195202
}

0 commit comments

Comments
 (0)