Skip to content

Commit be5ec4a

Browse files
committed
[Driver] Improve error when a compiler-rt library is not found
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 cebb8f0 commit be5ec4a

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
@@ -656,19 +656,29 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
656656
// Check for runtime files in the new layout without the architecture first.
657657
std::string CRTBasename =
658658
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
659+
SmallString<128> Path;
659660
for (const auto &LibPath : getLibraryPaths()) {
660661
SmallString<128> P(LibPath);
661662
llvm::sys::path::append(P, CRTBasename);
662663
if (getVFS().exists(P))
663664
return std::string(P);
665+
if (Path.empty())
666+
Path = P;
664667
}
668+
if (getTriple().isOSAIX())
669+
Path.clear();
665670

666-
// Fall back to the old expected compiler-rt name if the new one does not
667-
// exist.
671+
// Check the filename for the old layout if the new one does not exist.
668672
CRTBasename =
669673
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
670-
SmallString<128> Path(getCompilerRTPath());
671-
llvm::sys::path::append(Path, CRTBasename);
674+
SmallString<128> OldPath(getCompilerRTPath());
675+
llvm::sys::path::append(OldPath, CRTBasename);
676+
if (Path.empty() || getVFS().exists(OldPath))
677+
return std::string(OldPath);
678+
679+
// If none is found, use a file name from the new layout, which may get
680+
// printed in an error message, aiding users in knowing what Clang is
681+
// looking for.
672682
return std::string(Path);
673683
}
674684

0 commit comments

Comments
 (0)