Skip to content

Commit c3167fe

Browse files
committed
[Driver] Improve error when a compiler-rt library is not found
BSD/Linux/OS390x 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 9f6c005 commit c3167fe

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,19 +655,22 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
655655
// Check for runtime files in the new layout without the architecture first.
656656
std::string CRTBasename =
657657
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
658+
SmallString<128> Path;
658659
for (const auto &LibPath : getLibraryPaths()) {
659-
SmallString<128> P(LibPath);
660-
llvm::sys::path::append(P, CRTBasename);
661-
if (getVFS().exists(P))
662-
return std::string(P);
660+
Path = LibPath;
661+
llvm::sys::path::append(Path, CRTBasename);
662+
if (getVFS().exists(Path))
663+
return std::string(Path);
663664
}
664665

665-
// Fall back to the old expected compiler-rt name if the new one does not
666-
// exist.
666+
#if !LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
667+
// When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is off, fall back to the old
668+
// expected compiler-rt name if the new one does not exist.
667669
CRTBasename =
668670
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
669-
SmallString<128> Path(getCompilerRTPath());
671+
Path = getCompilerRTPath();
670672
llvm::sys::path::append(Path, CRTBasename);
673+
#endif
671674
return std::string(Path);
672675
}
673676

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
/* Doesn't use `cmakedefine` because it is allowed to be empty. */
2222
#define LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}"
2323

24+
#cmakedefine01 LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
25+
2426
/* Define if threads enabled */
2527
#cmakedefine01 LLVM_ENABLE_THREADS
2628

0 commit comments

Comments
 (0)