Skip to content

Clang: Return new layout path if cannot find CRT #87319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

wzssyqa
Copy link
Contributor

@wzssyqa wzssyqa commented Apr 2, 2024

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

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
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Apr 2, 2024
@wzssyqa wzssyqa requested a review from MaskRay April 2, 2024 07:56
@llvmbot
Copy link
Member

llvmbot commented Apr 2, 2024

@llvm/pr-subscribers-clang

Author: YunQiang Su (wzssyqa)

Changes

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

@llvmbot
Copy link
Member

llvmbot commented Apr 2, 2024

@llvm/pr-subscribers-clang-driver

Author: YunQiang Su (wzssyqa)

Changes

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

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add another copy of buildCompilerRTBasename to getCompilerRT to make it more complex. Let's keep the discussion in #87150

@wzssyqa
Copy link
Contributor Author

wzssyqa commented Apr 8, 2024

Replaced by: #87150

@wzssyqa wzssyqa closed this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants