[clang] Clang: Return new layout path if cannot find CRT (PR #87319)
YunQiang Su via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 2 00:56:16 PDT 2024
https://github.com/wzssyqa created https://github.com/llvm/llvm-project/pull/87319
In ToolChain::getCompilerRT:
If none is found, use a file name from the new layout, which may get
printed in an error message, aiding users in knowing what Clang is
looking for.
But in current code, the old layout is printed if no libclang_rt.builtin is found with cmd like:
./bin/clang --target=aarch64-linux-gnu -rtlib=compiler-rt hello.c
aarch64-linux-gnu/bin/ld: cannot find <path>/lib/clang/19/lib/linux/libclang_rt.builtins-aarch64.a: No such file or directory
>From 2c8132f08eedfe522ca4dcdcc5bbb11ffb629dd2 Mon Sep 17 00:00:00 2001
From: YunQiang Su <syq at gcc.gnu.org>
Date: Tue, 2 Apr 2024 15:50:23 +0800
Subject: [PATCH] Clang: Return new layout path if cannot find CRT
In ToolChain::getCompilerRT:
// If none is found, use a file name from the new layout, which may get
// printed in an error message, aiding users in knowing what Clang is
// looking for.
But in current code, the old layout is printed if no
libclang_rt.builtin is found with cmd like:
./bin/clang --target=aarch64-linux-gnu -rtlib=compiler-rt hello.c
---
clang/lib/Driver/ToolChain.cpp | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 03450fc0f57b93..3b5960992a9dd1 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -692,12 +692,21 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
SmallString<128> OldPath(getCompilerRTPath());
llvm::sys::path::append(OldPath, CRTBasename);
- if (Path.empty() || getVFS().exists(OldPath))
+ if (getVFS().exists(OldPath))
return std::string(OldPath);
// If none is found, use a file name from the new layout, which may get
// printed in an error message, aiding users in knowing what Clang is
// looking for.
+ if (Path.empty()) {
+ CRTBasename =
+ buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+ SmallString<128> NewP(D.ResourceDir);
+ llvm::sys::path::append(NewP, "lib");
+ llvm::sys::path::append(NewP, getTriple().str());
+ llvm::sys::path::append(NewP, CRTBasename);
+ return std::string(NewP);
+ }
return std::string(Path);
}
More information about the cfe-commits
mailing list