diff --git a/CMakeLists.txt b/CMakeLists.txt index 09204a08..ea560ead 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ option(MI_XMALLOC "Enable abort() call on memory allocation failure by option(MI_SHOW_ERRORS "Show error and warning messages by default (only enabled by default in DEBUG mode)" OFF) option(MI_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF) option(MI_SEE_ASM "Generate assembly files" OFF) -option(MI_INTERPOSE "Use interpose to override standard malloc on macOS" OFF) +option(MI_OSX_INTERPOSE "Use interpose to override standard malloc on macOS" OFF) option(MI_OSX_ZONE "Use malloc zone to override standard malloc on macOS" ON) option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" OFF) option(MI_BUILD_SHARED "Build shared library" ON) @@ -23,6 +23,7 @@ option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF) option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clang++)" OFF) option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF) option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version" OFF) +option(MI_USE_LIBATOMIC "Explicitly link with -latomic (on older systems)" OFF) include("cmake/mimalloc-config-version.cmake") @@ -78,11 +79,11 @@ if(MI_OVERRIDE) list(APPEND mi_sources src/alloc-override-osx.c) list(APPEND mi_defines MI_OSX_ZONE=1) endif() - if(MI_INTERPOSE) + if(MI_OSX_INTERPOSE) # use interpose on macOS - message(STATUS " Use interpose to override malloc (MI_INTERPOSE=ON)") + message(STATUS " Use interpose to override malloc (MI_OSX_INTERPOSE=ON)") message(STATUS " WARNING: interpose does not seem to work reliably on the M1; use -DMI_OSX_ZONE=ON instead") - list(APPEND mi_defines MI_INTERPOSE) + list(APPEND mi_defines MI_OSX_INTERPOSE) endif() endif() endif() @@ -203,6 +204,10 @@ else() endif() endif() +if (MI_USE_LIBATOMIC) + list(APPEND mi_libraries atomic) +endif() + # ----------------------------------------------------------------------------- # Install and output names # ----------------------------------------------------------------------------- diff --git a/src/alloc-override-osx.c b/src/alloc-override-osx.c index f506d30a..a2e341bb 100644 --- a/src/alloc-override-osx.c +++ b/src/alloc-override-osx.c @@ -229,7 +229,7 @@ static malloc_zone_t mi_malloc_zone = { }; -#if defined(MI_SHARED_LIB_EXPORT) && defined(MI_INTERPOSE) +#if defined(MI_SHARED_LIB_EXPORT) && defined(MI_OSX_INTERPOSE) static malloc_zone_t *mi_malloc_default_zone(void) { return &mi_malloc_zone; diff --git a/src/alloc-override.c b/src/alloc-override.c index 6a87e7bd..f97b6e78 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -13,7 +13,7 @@ terms of the MIT license. A copy of the license can be found in the file #error "It is only possible to override "malloc" on Windows when building as a DLL (and linking the C runtime as a DLL)" #endif -#if defined(MI_MALLOC_OVERRIDE) && !(defined(_WIN32)) // || (defined(__APPLE__) && !defined(MI_INTERPOSE))) +#if defined(MI_MALLOC_OVERRIDE) && !(defined(_WIN32)) // || (defined(__APPLE__) && !defined(MI_OSX_INTERPOSE))) // ------------------------------------------------------ // Override system malloc @@ -40,7 +40,7 @@ terms of the MIT license. A copy of the license can be found in the file #define MI_FORWARD02(fun,x,y) { fun(x,y); } #endif -#if defined(__APPLE__) && defined(MI_SHARED_LIB_EXPORT) && defined(MI_INTERPOSE) +#if defined(__APPLE__) && defined(MI_SHARED_LIB_EXPORT) && defined(MI_OSX_INTERPOSE) // use interposing so `DYLD_INSERT_LIBRARIES` works without `DYLD_FORCE_FLAT_NAMESPACE=1` // See: struct mi_interpose_s { diff --git a/test/test-api.c b/test/test-api.c index f72cfaf5..8ddbf7cf 100644 --- a/test/test-api.c +++ b/test/test-api.c @@ -4,7 +4,9 @@ This is free software; you can redistribute it and/or modify it under the terms of the MIT license. A copy of the license can be found in the file "LICENSE" at the root of this distribution. -----------------------------------------------------------------------------*/ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic ignored "-Walloc-size-larger-than=" +#endif /* Testing allocators is difficult as bugs may only surface after particular