Skip to content

Commit bdc6237

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 26e6755 commit bdc6237

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);
@@ -204,9 +205,15 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath) {
204205
// With a static-library build of libclang, LibClangPath will contain the
205206
// path of the embedding binary, which for LLVM binaries will be in bin/.
206207
// ../lib gets us to lib/ in both cases.
207-
P = llvm::sys::path::parent_path(Dir);
208208
// This search path is also created in the COFF driver of lld, so any
209209
// changes here also needs to happen in lld/COFF/Driver.cpp
210+
211+
// OE cross toolchains are installed, by default, in a subdir of bin.
212+
if (LastDirName == "bin") {
213+
P = llvm::sys::path::parent_path(Dir);
214+
} else {
215+
P = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
216+
}
210217
llvm::sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang",
211218
CLANG_VERSION_MAJOR_STRING);
212219
}

0 commit comments

Comments
 (0)