[clang] [Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older (PR #141401)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 3 21:06:04 PDT 2025
https://github.com/Un1q32 updated https://github.com/llvm/llvm-project/pull/141401
>From 3cf20444591e70a8a6d8782048ca4f6c0e211112 Mon Sep 17 00:00:00 2001
From: Un1q32 <joey.t.reinhart at gmail.com>
Date: Mon, 27 Jan 2025 18:00:34 -0500
Subject: [PATCH 1/2] [Clang] Link libgcc_s.1.dylib when building for macOS
10.5 and older (intel)
---
clang/lib/Driver/ToolChains/Darwin.cpp | 17 +++++++++--------
clang/test/Driver/darwin-ld.c | 11 ++++++++++-
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 452820159435f..ddc066d3d18a3 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1645,14 +1645,15 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
CmdArgs.push_back("-lSystem");
// Select the dynamic runtime library and the target specific static library.
- if (isTargetIOSBased()) {
- // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
- // it never went into the SDK.
- // Linking against libgcc_s.1 isn't needed for iOS 5.0+
- if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
- getTriple().getArch() != llvm::Triple::aarch64)
- CmdArgs.push_back("-lgcc_s.1");
- }
+ // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
+ // it never went into the SDK.
+ // Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+
+ if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0) &&
+ !isTargetIOSSimulator() && getTriple().getArch() != llvm::Triple::aarch64)
+ CmdArgs.push_back("-lgcc_s.1");
+ else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6) &&
+ getTriple().getArch() != llvm::Triple::aarch64)
+ CmdArgs.push_back("-lgcc_s.1");
AddLinkRuntimeLib(Args, CmdArgs, "builtins");
}
diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c
index f0ca411430cc7..9a8d98cdb9c2c 100644
--- a/clang/test/Driver/darwin-ld.c
+++ b/clang/test/Driver/darwin-ld.c
@@ -240,6 +240,15 @@
// RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_LIBGCC_S %s < %t.log
// LINK_NO_IOS_ARM64_LIBGCC_S-NOT: lgcc_s.1
+// Check that clang links with libgcc_s.1 for Mac OS X 10.5 and earlier, but not arm64
+// RUN: %clang -target x86_64-apple-macosx10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=LINK_OSX_LIBGCC_S %s < %t.log
+// LINK_OSX_LIBGCC_S: lgcc_s.1
+
+// RUN: %clang -target arm64-apple-macosx10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=LINK_NO_OSX_ARM64_LIBGCC_S %s < %t.log
+// LINK_NO_OSX_ARM64_LIBGCC_S-NOT: lgcc_s.1
+
// RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
// RUN: -fuse-ld= -mlinker-version=100 2> %t.log
// RUN: FileCheck -check-prefix=LINK_NO_EXPORT_DYNAMIC %s < %t.log
@@ -385,4 +394,4 @@
// RUN: %clang -target armv7em-apple-darwin -mno-outline -### %t.o 2> %t.log
// RUN: FileCheck -check-prefix=ARMV7EM-MNO_OUTLINE %s < %t.log
// ARMV7EM-MNO_OUTLINE: {{ld(.exe)?"}}
-// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" "-mllvm" "-enable-linkonceodr-outlining"
\ No newline at end of file
+// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" "-mllvm" "-enable-linkonceodr-outlining"
>From c82c7704c306f3d86b5226b137521bf7bf98a3cd Mon Sep 17 00:00:00 2001
From: Un1q32 <joey.t.reinhart at gmail.com>
Date: Wed, 4 Jun 2025 00:05:56 -0400
Subject: [PATCH 2/2] change the order of the if statmenets to check aarch64
first
---
clang/lib/Driver/ToolChains/Darwin.cpp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index ddc066d3d18a3..516082192a0c9 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1648,12 +1648,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
// If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
// it never went into the SDK.
// Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+
- if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0) &&
- !isTargetIOSSimulator() && getTriple().getArch() != llvm::Triple::aarch64)
- CmdArgs.push_back("-lgcc_s.1");
- else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6) &&
- getTriple().getArch() != llvm::Triple::aarch64)
- CmdArgs.push_back("-lgcc_s.1");
+ if (getTriple().getArch() != llvm::Triple::aarch64) {
+ if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0) &&
+ !isTargetIOSSimulator())
+ CmdArgs.push_back("-lgcc_s.1");
+ else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6))
+ CmdArgs.push_back("-lgcc_s.1");
+ }
AddLinkRuntimeLib(Args, CmdArgs, "builtins");
}
More information about the cfe-commits
mailing list