From fa9ea5ec31afd47a3433a4c8dc81145ebffbd903 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 2 Nov 2023 06:26:03 -0700 Subject: [PATCH 1/3] Enable aligned_alloc on macOS Fixes #54296 --- src/native/libs/System.Native/pal_memory.c | 4 +--- src/native/libs/configure.cmake | 25 +++++++++------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/native/libs/System.Native/pal_memory.c b/src/native/libs/System.Native/pal_memory.c index f82d7a27780c9..c5398b441989a 100644 --- a/src/native/libs/System.Native/pal_memory.c +++ b/src/native/libs/System.Native/pal_memory.c @@ -26,9 +26,7 @@ void* SystemNative_AlignedAlloc(uintptr_t alignment, uintptr_t size) { #if HAVE_ALIGNED_ALLOC - // We want to prefer the standardized aligned_alloc function. However - // it cannot be used on __APPLE__ since we target 10.13 and it was - // only added in 10.15, but we might be compiling on a 10.15 box. + // We want to prefer the standardized aligned_alloc function. return aligned_alloc(alignment, size); #elif HAVE_POSIX_MEMALIGN void* result = NULL; diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 52e9048c03075..6062d778f1433 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -581,23 +581,22 @@ if(CLR_CMAKE_TARGET_IOS) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP) unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+ - unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+ - unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+ + set(HAVE_CLOCK_MONOTONIC) + set(HAVE_CLOCK_REALTIME) unset(HAVE_FORK) # exists but blocked by kernel elseif(CLR_CMAKE_TARGET_MACCATALYST) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking - # TODO: test to see if these all actually hold true on Mac Catalyst unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP) unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+ - unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+ - unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+ + set(HAVE_CLOCK_MONOTONIC) + set(HAVE_CLOCK_REALTIME) unset(HAVE_FORK) # exists but blocked by kernel elseif(CLR_CMAKE_TARGET_TVOS) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP) unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+ - unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+ - unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+ + set(HAVE_CLOCK_MONOTONIC) + set(HAVE_CLOCK_REALTIME) unset(HAVE_FORK) # exists but blocked by kernel elseif(CLR_CMAKE_TARGET_ANDROID) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking @@ -608,14 +607,10 @@ elseif(CLR_CMAKE_TARGET_ANDROID) elseif(CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) set(HAVE_FORK 0) else() - if(CLR_CMAKE_TARGET_OSX) - unset(HAVE_ALIGNED_ALLOC) # only exists on OSX 10.15+ - else() - check_symbol_exists( - aligned_alloc - stdlib.h - HAVE_ALIGNED_ALLOC) - endif() + check_symbol_exists( + aligned_alloc + stdlib.h + HAVE_ALIGNED_ALLOC) check_c_source_runs( " From 1ce55e2983c132d3786ff2b0372255cb8196cf6f Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 13 Nov 2023 13:29:30 -0800 Subject: [PATCH 2/3] Update src/native/libs/configure.cmake Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com> --- src/native/libs/configure.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 6062d778f1433..8679a5bd58417 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -595,8 +595,8 @@ elseif(CLR_CMAKE_TARGET_TVOS) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP) unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+ - set(HAVE_CLOCK_MONOTONIC) - set(HAVE_CLOCK_REALTIME) + set(HAVE_CLOCK_MONOTONIC 1) + set(HAVE_CLOCK_REALTIME 1) unset(HAVE_FORK) # exists but blocked by kernel elseif(CLR_CMAKE_TARGET_ANDROID) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking From 27aad12005b8672bc81c8e4e5289df6b62cc56d2 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 13 Nov 2023 13:30:05 -0800 Subject: [PATCH 3/3] Apply suggestions from code review --- src/native/libs/configure.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 8679a5bd58417..42502a34b4ef2 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -581,15 +581,15 @@ if(CLR_CMAKE_TARGET_IOS) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP) unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+ - set(HAVE_CLOCK_MONOTONIC) - set(HAVE_CLOCK_REALTIME) + set(HAVE_CLOCK_MONOTONIC 1) + set(HAVE_CLOCK_REALTIME 1) unset(HAVE_FORK) # exists but blocked by kernel elseif(CLR_CMAKE_TARGET_MACCATALYST) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP) unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+ - set(HAVE_CLOCK_MONOTONIC) - set(HAVE_CLOCK_REALTIME) + set(HAVE_CLOCK_MONOTONIC 1) + set(HAVE_CLOCK_REALTIME 1) unset(HAVE_FORK) # exists but blocked by kernel elseif(CLR_CMAKE_TARGET_TVOS) # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking