diff --git a/cmake/ConfigureCompiler.cmake b/cmake/ConfigureCompiler.cmake index df2235759e..a29edf28e5 100644 --- a/cmake/ConfigureCompiler.cmake +++ b/cmake/ConfigureCompiler.cmake @@ -221,9 +221,14 @@ else() # Check whether we can use dtrace probes include(CheckSymbolExists) check_symbol_exists(DTRACE_PROBE sys/sdt.h SUPPORT_DTRACE) + check_symbol_exists(aligned_alloc stdlib.h HAS_ALIGNED_ALLOC) + message(STATUS "Has aligned_alloc: ${HAS_ALIGNED_ALLOC}") if(SUPPORT_DTRACE) add_compile_definitions(DTRACE_PROBES) endif() + if(HAS_ALIGNED_ALLOC) + add_compile_definitions(HAS_ALIGNED_ALLOC) + endif() if(CMAKE_COMPILER_IS_GNUCXX) set(USE_LTO OFF CACHE BOOL "Do link time optimization") diff --git a/flow/Platform.h b/flow/Platform.h index fd511d4e6c..217dd0f645 100644 --- a/flow/Platform.h +++ b/flow/Platform.h @@ -524,6 +524,7 @@ inline static void aligned_free(void* ptr) { free(ptr); } inline static void* aligned_alloc(size_t alignment, size_t size) { return memalign(alignment, size); } #endif #elif defined(__APPLE__) +#if !defined(HAS_ALIGNED_ALLOC) #include inline static void* aligned_alloc(size_t alignment, size_t size) { // Linux's aligned_alloc() requires alignment to be a power of 2. While posix_memalign() @@ -540,6 +541,7 @@ inline static void* aligned_alloc(size_t alignment, size_t size) { posix_memalign(&ptr, alignment, size); return ptr; } +#endif inline static void aligned_free(void* ptr) { free(ptr); } #endif