[clang] [Driver] Omit crtbegin.o and crtend.o with --rtlib=none (PR #245160)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 00:54:17 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Petr Hosek (petrhosek)

<details>
<summary>Changes</summary>

This is a follow up to #<!-- -->245001 to make the Linux driver match the behavior of other drivers in the --rtlib=none case.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+3-2) 
- (modified) clang/test/Driver/linux-ld.c (+2-2) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 90fc71c147364..97f9867946bfb 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -291,8 +291,9 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   const bool IsStaticPIE = getStaticPIE(Args, ToolChain);
   const bool IsStatic = getStatic(Args);
   const bool HasCRTBeginEndFiles =
-      ToolChain.getTriple().hasEnvironment() ||
-      (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
+      ToolChain.GetRuntimeLibType(Args) != ToolChain::RLT_None &&
+      (ToolChain.getTriple().hasEnvironment() ||
+       (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies));
 
   ArgStringList CmdArgs;
 
diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c
index 100d4f47621b7..d227c37d3f721 100644
--- a/clang/test/Driver/linux-ld.c
+++ b/clang/test/Driver/linux-ld.c
@@ -74,13 +74,13 @@
 // RUN:     --rtlib=none \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-RT-NONE %s
 // CHECK-LD-RT-NONE: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-LD-RT-NONE-SAME: "{{.*}}/usr/lib/gcc/x86_64-unknown-linux/10.2.0{{/|\\\\}}crtbegin.o"
+// CHECK-LD-RT-NONE-NOT: "crtbegin.o"
 // CHECK-LD-RT-NONE-NOT: "clang_rt.builtins"
 // CHECK-LD-RT-NONE-NOT: "-lgcc"
 // CHECK-LD-RT-NONE-SAME: "-lc"
 // CHECK-LD-RT-NONE-NOT: "clang_rt.builtins"
 // CHECK-LD-RT-NONE-NOT: "-lgcc"
-// CHECK-LD-RT-NONE-SAME: "crtend.o"
+// CHECK-LD-RT-NONE-NOT: "crtend.o"
 
 // RUN: %clang -### %s -Werror -no-pie 2>&1 \
 // RUN:     --target=i686-unknown-linux \

``````````

</details>


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


More information about the cfe-commits mailing list