From 3ad4639aea68db870c97cb7199327a7859c3d602 Mon Sep 17 00:00:00 2001 From: daan Date: Mon, 31 Oct 2022 15:53:36 -0700 Subject: [PATCH 1/2] fix atomic lib reference, see PR #586 --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 144395d4..2bc0f76b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,8 +262,11 @@ else() set(pc_libraries "${pc_libraries} -lrt") endif() find_library(MI_LIBATOMIC atomic) - if (MI_LIBATOMIC OR MI_USE_LIBATOMIC) - list(APPEND mi_libraries atomic) + if (NOT MI_LIBATOMIC AND MI_USE_LIBATOMIC) + set(MI_LIBATOMIC atomic) + endif() + if (MI_LIBATOMIC) + list(APPEND mi_libraries ${MI_LIBATOMIC}) set(pc_libraries "${pc_libraries} -latomic") endif() endif() From 65eb5c65ecbf7ddcc14a0a060585a711abaff52e Mon Sep 17 00:00:00 2001 From: daan Date: Mon, 31 Oct 2022 16:07:29 -0700 Subject: [PATCH 2/2] relax restriction of size to be an integral multiple of the alignment in 'alloc_aligned' as too many programs need this; see PR #584 --- src/alloc-posix.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/alloc-posix.c b/src/alloc-posix.c index e1b4a286..57e15d05 100644 --- a/src/alloc-posix.c +++ b/src/alloc-posix.c @@ -83,13 +83,16 @@ mi_decl_nodiscard mi_decl_restrict void* mi_pvalloc(size_t size) mi_attr_noexcep } mi_decl_nodiscard mi_decl_restrict void* mi_aligned_alloc(size_t alignment, size_t size) mi_attr_noexcept { - if mi_unlikely((size&(alignment-1)) != 0) { // C11 requires alignment>0 && integral multiple, see - #if MI_DEBUG > 0 - _mi_error_message(EOVERFLOW, "(mi_)aligned_alloc requires the size to be an integral multiple of the alignment (size %zu, alignment %zu)\n", size, alignment); - #endif - return NULL; - } - // C11 also requires alignment to be a power-of-two which is checked in mi_malloc_aligned + // C11 requires the size to be an integral multiple of the alignment, see . + // unfortunately, it turns out quite some programs pass a size that is not an integral multiple so skip this check.. + /* if mi_unlikely((size & (alignment - 1)) != 0) { // C11 requires alignment>0 && integral multiple, see + #if MI_DEBUG > 0 + _mi_error_message(EOVERFLOW, "(mi_)aligned_alloc requires the size to be an integral multiple of the alignment (size %zu, alignment %zu)\n", size, alignment); + #endif + return NULL; + } + */ + // C11 also requires alignment to be a power-of-two (and > 0) which is checked in mi_malloc_aligned void* p = mi_malloc_aligned(size, alignment); mi_assert_internal(((uintptr_t)p % alignment) == 0); return p;