From af86bd2ceeaebaa2c96e2f608d74df678479ba45 Mon Sep 17 00:00:00 2001
From: "Kirill A. Korinsky" <kirill@korins.ky>
Date: Mon, 7 Aug 2023 12:05:37 +0200
Subject: [PATCH] [libcxx] link gcc_s.1 on macOS before 10.6

leopard and before has some symbols at libgcc_s.1 instead of libSystem.
---
 libcxx/CMakeLists.txt        | 4 ++++
 libcxxabi/src/CMakeLists.txt | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 910d04b54b6d..d1408b4a58c5 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -738,6 +738,10 @@ function(cxx_link_system_libraries target)
     target_link_libraries(${target} PRIVATE System)
   endif()
 
+  if (APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.6)
+    target_link_libraries(${target} PRIVATE gcc_s.1)
+  endif()
+
   if (LIBCXX_HAS_PTHREAD_LIB)
     target_link_libraries(${target} PRIVATE pthread)
   endif()
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 42bec421d2be..b85bbc8053a4 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -65,6 +65,9 @@ endif()
 
 if (APPLE)
   add_library_flags_if(LIBCXXABI_HAS_SYSTEM_LIB System)
+  if (CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.6)
+    add_library_flags(gcc_s.1)
+  endif()
 else()
   if (LIBCXXABI_ENABLE_THREADS)
     add_library_flags_if(LIBCXXABI_HAS_PTHREAD_LIB pthread)
-- 
2.41.0

