[clang] [Driver] Omit crtbegin.o and crtend.o with --rtlib=none (PR #245160)
Petr Hosek via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 00:53:39 PST 2026
https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/245160
This is a follow up to #245001 to make the Linux driver match the behavior of other drivers in the --rtlib=none case.
>From 19844c81609fdbdfa11788e1497fbc0fc9d18316 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Mon, 23 Nov 2026 08:50:53 +0000
Subject: [PATCH] [Driver] Omit crtbegin.o and crtend.o with --rtlib=none
This is a follow up to #245001 to make the Linux driver match the
behavior of other drivers in the --rtlib=none case.
---
clang/lib/Driver/ToolChains/Gnu.cpp | 5 +++--
clang/test/Driver/linux-ld.c | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 90fc71c147364d..97f9867946bfb2 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 100d4f47621b7a..d227c37d3f7211 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 \
More information about the cfe-commits
mailing list