From 1ebc28a8ff169aa484c38a795b8f29ae6a983cdd Mon Sep 17 00:00:00 2001 From: Daan Date: Fri, 10 May 2024 15:58:37 -0700 Subject: [PATCH 1/2] update comment --- include/mimalloc/prim.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/mimalloc/prim.h b/include/mimalloc/prim.h index 89266817..4ee6d43f 100644 --- a/include/mimalloc/prim.h +++ b/include/mimalloc/prim.h @@ -130,8 +130,9 @@ void _mi_prim_thread_associate_default_heap(mi_heap_t* heap); // If you test on another platform and it works please send a PR :-) // see also https://akkadia.org/drepper/tls.pdf for more info on the TLS register. // -// Note: on most platforms this is not actually used anymore as we prefer `__builtin_thread_pointer()` nowadays. -// However, we do still use it with older clang compilers and Apple OS (as we use TLS slot for the default heap there). +// Note: we would like to prefer `__builtin_thread_pointer()` nowadays instead of using assembly, +// but unfortunately we can not detect support reliably (see issue #883) +// We also use it on Apple OS as we use a TLS slot for the default heap there. #if defined(__GNUC__) && ( \ (defined(__GLIBC__) && (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))) \ || (defined(__APPLE__) && (defined(__x86_64__) || defined(__aarch64__) || defined(__POWERPC__))) \ From e5267a31b03b5ada98b544a421c2a0fbd082bf39 Mon Sep 17 00:00:00 2001 From: Daan Date: Fri, 10 May 2024 17:03:42 -0700 Subject: [PATCH 2/2] only override strdup/strndup if those are not macros (issue #885) --- src/alloc-override.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/alloc-override.c b/src/alloc-override.c index 75afc202..12837cdd 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -136,8 +136,11 @@ typedef void* mi_nothrow_t; mi_decl_export void* realloc(void* p, size_t newsize) MI_FORWARD2(mi_realloc, p, newsize) mi_decl_export void free(void* p) MI_FORWARD0(mi_free, p) // In principle we do not need to forward `strdup`/`strndup` but on some systems these do not use `malloc` internally (but a more primitive call) + // We only override if `strdup` is not a macro (as on some older libc's, see issue #885) + #if !defined(strdup) mi_decl_export char* strdup(const char* str) MI_FORWARD1(mi_strdup, str) - #if !defined(__APPLE__) || (defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) + #endif + #if !defined(strndup) && (!defined(__APPLE__) || (defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)) mi_decl_export char* strndup(const char* str, size_t n) MI_FORWARD2(mi_strndup, str, n) #endif #endif