From 438ce8c5bcc4f6d579c1a59bfd209e09862c1beb Mon Sep 17 00:00:00 2001
From: "Kirill A. Korinsky" <kirill@korins.ky>
Date: Mon, 7 Aug 2023 15:52:29 +0200
Subject: [PATCH] [libcxx] use malloc/free only on macOS before 10.6

---
 libcxx/include/new | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libcxx/include/new b/libcxx/include/new
index 0c826f4a061c..6a3a787e65f5 100644
--- a/libcxx/include/new
+++ b/libcxx/include/new
@@ -355,9 +355,14 @@ inline _LIBCPP_INLINE_VISIBILITY void* __libcpp_aligned_alloc(std::size_t __alig
     return ::aligned_alloc(__alignment, __size > __rounded_size ? __size : __rounded_size);
 #  else
     void* __result = nullptr;
+#  if defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060
     (void)::posix_memalign(&__result, __alignment, __size);
     // If posix_memalign fails, __result is unmodified so we still return `nullptr`.
     return __result;
+#  else
+    // macOS before 10.6 hasn't got alligned malloc, fallback to just malloc
+    return ::malloc(__size);
+#  endif
 #  endif
 }
 
-- 
2.41.0

