Skip to content

Commit 69ec5a6

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 983b460 commit 69ec5a6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

clang/lib/Options/OptionUtils.cpp

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

214214
// Dir is bin/ or lib/, depending on where BinaryPath is.
215215
StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
216+
StringRef LastDirName = llvm::sys::path::filename(Dir);
216217
SmallString<128> P(Dir);
217218

218219
StringRef ConfiguredResourceDir(CLANG_RESOURCE_DIR);
@@ -229,9 +230,15 @@ std::string clang::GetResourcesPath(StringRef BinaryPath) {
229230
// With a static-library build of libclang, LibClangPath will contain the
230231
// path of the embedding binary, which for LLVM binaries will be in bin/.
231232
// ../lib gets us to lib/ in both cases.
232-
P = llvm::sys::path::parent_path(Dir);
233233
// This search path is also created in the COFF driver of lld, so any
234234
// changes here also needs to happen in lld/COFF/Driver.cpp
235+
236+
// OE cross toolchains are installed, by default, in a subdir of bin.
237+
if (LastDirName == "bin") {
238+
P = llvm::sys::path::parent_path(Dir);
239+
} else {
240+
P = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
241+
}
235242
llvm::sys::path::append(P, CLANG_INSTALL_LIBDIR_BASENAME, "clang",
236243
CLANG_VERSION_MAJOR_STRING);
237244
}

0 commit comments

Comments
 (0)