https://github.com/Un1q32 updated https://github.com/llvm/llvm-project/pull/124651
>From d4e97c4113086c3d2dfa3bf6e9ecfee377f8c4b6 Mon Sep 17 00:00:00 2001 From: Un1q32 <joey.t.reinh...@gmail.com> Date: Mon, 27 Jan 2025 18:00:34 -0500 Subject: [PATCH 1/3] [Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older --- clang/lib/Driver/ToolChains/Darwin.cpp | 9 +++++---- clang/test/Driver/darwin-ld.c | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 55c55bad73934..67f27a599b4c3 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1645,12 +1645,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, CmdArgs.push_back("-lSystem"); // Select the dynamic runtime library and the target specific static library. - if (isTargetIOSBased()) { + if (isTargetIOSBased() || isTargetMacOSBased()) { // 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) + // Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+ + if ((isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && + getTriple().getArch() != llvm::Triple::aarch64) || + isMacosxVersionLT(10, 6)) 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..5b10daaf007a2 100644 --- a/clang/test/Driver/darwin-ld.c +++ b/clang/test/Driver/darwin-ld.c @@ -240,6 +240,11 @@ // 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 macOS 10.5 and earlier +// RUN: %clang -target x86_64-apple-macos10.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 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 +390,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 4407312c3b8f2edfd9279183a9d4fae316639469 Mon Sep 17 00:00:00 2001 From: Un1q32 <joey.t.reinh...@gmail.com> Date: Mon, 27 Jan 2025 18:59:53 -0500 Subject: [PATCH 2/3] fix --- clang/lib/Driver/ToolChains/Darwin.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 67f27a599b4c3..82f7d4597d0c7 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1645,15 +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() || isTargetMacOSBased()) { + 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+ or macOS 10.6+ - if ((isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && - getTriple().getArch() != llvm::Triple::aarch64) || - isMacosxVersionLT(10, 6)) + if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && + getTriple().getArch() != llvm::Triple::aarch64) CmdArgs.push_back("-lgcc_s.1"); - } + } else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6)) + CmdArgs.push_back("-lgcc_s.1"); AddLinkRuntimeLib(Args, CmdArgs, "builtins"); } >From 31bdca90a631f744f86fa3e25e1a178455901503 Mon Sep 17 00:00:00 2001 From: Un1q32 <joey.t.reinh...@gmail.com> Date: Mon, 17 Mar 2025 18:44:08 -0400 Subject: [PATCH 3/3] tidy this up a bit, also don't link libgcc_s on arm64 ever --- clang/lib/Driver/ToolChains/Darwin.cpp | 16 ++++++++-------- clang/test/Driver/darwin-ld.c | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 757ba50e4c865..acc0f9ca59316 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1642,14 +1642,14 @@ 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+ or macOS 10.6+ - if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && - getTriple().getArch() != llvm::Triple::aarch64) - CmdArgs.push_back("-lgcc_s.1"); - } else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6)) + // 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 5b10daaf007a2..9a8d98cdb9c2c 100644 --- a/clang/test/Driver/darwin-ld.c +++ b/clang/test/Driver/darwin-ld.c @@ -240,11 +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 macOS 10.5 and earlier -// RUN: %clang -target x86_64-apple-macos10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log +// 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits