Skip to content

Commit 1c6aff6

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 <[email protected]> Signed-off-by: Khem Raj <[email protected]>
1 parent ea30639 commit 1c6aff6

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

132132
// Dir is bin/ or lib/, depending on where BinaryPath is.
133133
StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
134+
StringRef LastDirName = llvm::sys::path::filename(Dir);
134135
SmallString<128> P(Dir);
135136

136137
StringRef ConfiguredResourceDir(CLANG_RESOURCE_DIR);
@@ -147,9 +148,15 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath) {
147148
// With a static-library build of libclang, LibClangPath will contain the
148149
// path of the embedding binary, which for LLVM binaries will be in bin/.
149150
// ../lib gets us to lib/ in both cases.
150-
P = llvm::sys::path::parent_path(Dir);
151151
// This search path is also created in the COFF driver of lld, so any
152152
// changes here also needs to happen in lld/COFF/Driver.cpp
153+
154+
// OE cross toolchains are installed, by default, in a subdir of bin.
155+
if (LastDirName == "bin") {
156+
P = llvm::sys::path::parent_path(Dir);
157+
} else {
158+
P = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
159+
}
153160
llvm::sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang",
154161
CLANG_VERSION_MAJOR_STRING);
155162
}

0 commit comments

Comments
 (0)