From e02f88a11c31f33b0bdde1f0a46086b7901087b7 Mon Sep 17 00:00:00 2001 From: Daan Date: Wed, 20 Oct 2021 09:55:03 -0700 Subject: [PATCH 1/2] Fix warnings with g++-11 compilation --- CMakeLists.txt | 5 ++++- src/arena.c | 2 +- src/region.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b872e375..c46ffdac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,7 +166,10 @@ endif() # Compiler flags if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU") - list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -Wstrict-prototypes -fvisibility=hidden) + list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden) + if(NOT MI_USE_CXX) + list(APPEND mi_cflags -Wstrict-prototypes) + endif() if(CMAKE_C_COMPILER_ID MATCHES "GNU") list(APPEND mi_cflags -Wno-invalid-memory-model) endif() diff --git a/src/arena.c b/src/arena.c index 9d717e9e..5e883b28 100644 --- a/src/arena.c +++ b/src/arena.c @@ -310,7 +310,7 @@ bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_la // the bitmaps are already zero initialized due to os_alloc // initialize committed bitmap? if (arena->blocks_committed != NULL && is_committed) { - memset(arena->blocks_committed, 0xFF, fields*sizeof(mi_bitmap_field_t)); + memset((void*)arena->blocks_committed, 0xFF, fields*sizeof(mi_bitmap_field_t)); // cast to void* to avoid atomic warning } // and claim leftover blocks if needed (so we never allocate there) ptrdiff_t post = (fields * MI_BITMAP_FIELD_BITS) - bcount; diff --git a/src/region.c b/src/region.c index 2f68b140..d9232450 100644 --- a/src/region.c +++ b/src/region.c @@ -463,7 +463,7 @@ void _mi_mem_collect(mi_os_tld_t* tld) { uint8_t* start = (uint8_t*)mi_atomic_load_ptr_acquire(uint8_t,®ions[i].start); size_t arena_memid = mi_atomic_load_relaxed(®ions[i].arena_memid); uintptr_t commit = mi_atomic_load_relaxed(®ions[i].commit); - memset(®ions[i], 0, sizeof(mem_region_t)); + memset((void*)®ions[i], 0, sizeof(mem_region_t)); // cast to void* to avoid atomic warning // and release the whole region mi_atomic_store_release(®ion->info, (uintptr_t)0); if (start != NULL) { // && !_mi_os_is_huge_reserved(start)) { From d482555675fb80a60ebf194a605661062a390091 Mon Sep 17 00:00:00 2001 From: Daan Date: Wed, 20 Oct 2021 09:55:21 -0700 Subject: [PATCH 2/2] Fix warnings on osx with g++ compilation --- src/alloc-override-osx.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/alloc-override-osx.c b/src/alloc-override-osx.c index a2e341bb..723ef226 100644 --- a/src/alloc-override-osx.c +++ b/src/alloc-override-osx.c @@ -189,6 +189,10 @@ static malloc_zone_t* mi_get_default_zone() } } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + static malloc_introspection_t mi_introspect = { .enumerator = &intro_enumerator, .good_size = &intro_good_size, @@ -199,23 +203,23 @@ static malloc_introspection_t mi_introspect = { .force_unlock = &intro_force_unlock, #if defined(MAC_OS_X_VERSION_10_6) && \ MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 - .zone_locked = &intro_zone_locked, .statistics = &intro_statistics, + .zone_locked = &intro_zone_locked, #endif }; static malloc_zone_t mi_malloc_zone = { .size = &zone_size, - .zone_name = "mimalloc", - .introspect = &mi_introspect, .malloc = &zone_malloc, .calloc = &zone_calloc, .valloc = &zone_valloc, .free = &zone_free, .realloc = &zone_realloc, .destroy = &zone_destroy, + .zone_name = "mimalloc", .batch_malloc = &zone_batch_malloc, .batch_free = &zone_batch_free, + .introspect = &mi_introspect, #if defined(MAC_OS_X_VERSION_10_6) && \ MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 // switch to version 9 on OSX 10.6 to support memalign. @@ -243,16 +247,22 @@ __attribute__((used)) static struct { }; #endif -static void __attribute__((constructor(0))) _mi_macos_override_malloc() { + +#if defined(__clang__) +__attribute__((constructor(0))) +#else +__attribute__((constructor)) // seems not supported by g++-11 on the M1 +#endif +static void _mi_macos_override_malloc() { malloc_zone_t* purgeable_zone = NULL; -#if defined(MAC_OS_X_VERSION_10_6) && \ + #if defined(MAC_OS_X_VERSION_10_6) && \ MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 // force the purgeable zone to exist to avoid strange bugs if (malloc_default_purgeable_zone) { purgeable_zone = malloc_default_purgeable_zone(); } -#endif + #endif // Register our zone. // thomcc: I think this is still needed to put us in the zone list.