Skip to content

Commit b876596

Browse files
authored
[Driver] Improve error when a compiler-rt library is not found (#81037)
BSD, Linux, and z/OS enable `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR` by default. When a compiler-rt library is not found, we currently report an incorrect filename `libclang_rt.XXX-$arch.a` ``` % /tmp/Debug/bin/clang++ a.cc -fsanitize=address -o a ld.lld: error: cannot open /tmp/Debug/lib/clang/19/lib/linux/libclang_rt.asan-x86_64.a: No such file or directory clang++: error: linker command failed with exit code 1 (use -v to see invocation) ``` With this change, we will correctly report: ``` % /tmp/Debug/bin/clang++ a.cc -fsanitize=address -o a ld.lld: error: cannot open /tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.a: No such file or directory clang++: error: linker command failed with exit code 1 (use -v to see invocation) ``` Link: https://discourse.llvm.org/t/runtime-directory-fallback/76860
1 parent 695b630 commit b876596

32 files changed

+114
-104
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,19 +681,29 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
681681
// Check for runtime files in the new layout without the architecture first.
682682
std::string CRTBasename =
683683
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
684+
SmallString<128> Path;
684685
for (const auto &LibPath : getLibraryPaths()) {
685686
SmallString<128> P(LibPath);
686687
llvm::sys::path::append(P, CRTBasename);
687688
if (getVFS().exists(P))
688689
return std::string(P);
690+
if (Path.empty())
691+
Path = P;
689692
}
693+
if (getTriple().isOSAIX())
694+
Path.clear();
690695

691-
// Fall back to the old expected compiler-rt name if the new one does not
692-
// exist.
696+
// Check the filename for the old layout if the new one does not exist.
693697
CRTBasename =
694698
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
695-
SmallString<128> Path(getCompilerRTPath());
696-
llvm::sys::path::append(Path, CRTBasename);
699+
SmallString<128> OldPath(getCompilerRTPath());
700+
llvm::sys::path::append(OldPath, CRTBasename);
701+
if (Path.empty() || getVFS().exists(OldPath))
702+
return std::string(OldPath);
703+
704+
// If none is found, use a file name from the new layout, which may get
705+
// printed in an error message, aiding users in knowing what Clang is
706+
// looking for.
697707
return std::string(Path);
698708
}
699709

0 commit comments

Comments
 (0)