[clang] Clang: Return new layout path if cannot find CRT (PR #87319)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 2 00:56:47 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: YunQiang Su (wzssyqa)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/87319.diff


1 Files Affected:

- (modified) clang/lib/Driver/ToolChain.cpp (+10-1) 


``````````diff
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);
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/87319


More information about the cfe-commits mailing list