add MI_USE_LIBATOMIC to link with -latomic on older systems (see also PR #429); rename MI_INTERPOSE to MI_OSX_INTERPOSE

This commit is contained in:
Daan 2021-10-20 09:35:58 -07:00
parent 8dd8db8354
commit 4d89176eb4
3 changed files with 12 additions and 7 deletions

View File

@ -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
# -----------------------------------------------------------------------------

View File

@ -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;

View File

@ -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: <https://books.google.com/books?id=K8vUkpOXhN4C&pg=PA73>
struct mi_interpose_s {