From b598add0d1adc9b8ad311b0928f63254fe69073c Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Jul 2021 11:07:31 +0100 Subject: [PATCH 1/4] Fix the build with GCC and libc cleanup. (#341) GCC is a lot more picky about extern "C" definitions in namespaces than clang and so the `friend` declaration wasn't picked up by the version of the function declared in the `snmalloc` namespace. Move it out to where GCC is happy with it. --- src/mem/threadalloc.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/mem/threadalloc.h b/src/mem/threadalloc.h index 306c782..0fd0dc4 100644 --- a/src/mem/threadalloc.h +++ b/src/mem/threadalloc.h @@ -254,14 +254,6 @@ namespace snmalloc }; # ifdef SNMALLOC_USE_THREAD_CLEANUP - /** - * Entry point that allows libc to call into the allocator for per-thread - * cleanup. - */ - extern "C" void _malloc_thread_cleanup() - { - ThreadAllocLibcCleanup::inner_release(); - } using ThreadAlloc = ThreadAllocLibcCleanup; # else using ThreadAlloc = ThreadAllocThreadDestructor; @@ -306,3 +298,13 @@ namespace snmalloc } #endif } // namespace snmalloc +#ifdef SNMALLOC_USE_THREAD_CLEANUP +/** + * Entry point that allows libc to call into the allocator for per-thread + * cleanup. + */ +void _malloc_thread_cleanup() +{ + snmalloc::ThreadAllocLibcCleanup::inner_release(); +} +#endif From dcd47a044998e4a583e898ae9e2fed2cfeaab71d Mon Sep 17 00:00:00 2001 From: Istvan Haller Date: Mon, 5 Jul 2021 13:08:42 +0100 Subject: [PATCH 2/4] Allow disabling the Debug-mode check in the ABA --- src/ds/aba.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ds/aba.h b/src/ds/aba.h index c9a5d20..5e66323 100644 --- a/src/ds/aba.h +++ b/src/ds/aba.h @@ -13,7 +13,7 @@ */ namespace snmalloc { -#ifndef NDEBUG +#if !defined(NDEBUG) && !defined(SNMALLOC_DISABLE_ABA_VERIFY) // LL/SC typically can only perform one operation at a time // check this on other platforms using a thread_local. inline thread_local bool operation_in_flight = false; @@ -75,7 +75,7 @@ namespace snmalloc Cmp read() { -# ifndef NDEBUG +# if !defined(NDEBUG) && !defined(SNMALLOC_DISABLE_ABA_VERIFY) if (operation_in_flight) error("Only one inflight ABA operation at a time is allowed."); operation_in_flight = true; @@ -127,7 +127,7 @@ namespace snmalloc ~Cmp() { -# ifndef NDEBUG +# if !defined(NDEBUG) && !defined(SNMALLOC_DISABLE_ABA_VERIFY) operation_in_flight = false; # endif } @@ -170,7 +170,7 @@ namespace snmalloc while (lock.test_and_set(std::memory_order_acquire)) Aal::pause(); -# ifndef NDEBUG +# if !defined(NDEBUG) && !defined(SNMALLOC_DISABLE_ABA_VERIFY) if (operation_in_flight) error("Only one inflight ABA operation at a time is allowed."); operation_in_flight = true; @@ -198,7 +198,7 @@ namespace snmalloc ~Cmp() { parent->lock.clear(std::memory_order_release); -# ifndef NDEBUG +# if !defined(NDEBUG) && !defined(SNMALLOC_DISABLE_ABA_VERIFY) operation_in_flight = false; # endif } From e60dd3dc953c8663703b3fedd535feace8f35e9b Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 19 Jul 2021 11:40:27 +0100 Subject: [PATCH 3/4] Don't depend on if we don't need it. (#350) Including brings in , which breaks the in-libc build. --- src/mem/entropy.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mem/entropy.h b/src/mem/entropy.h index fa1b4ec..329e102 100644 --- a/src/mem/entropy.h +++ b/src/mem/entropy.h @@ -2,8 +2,10 @@ #include "../pal/pal.h" #include -#include #include +#ifndef SNMALLOC_PLATFORM_HAS_GETENTROPY +# include +#endif namespace snmalloc { @@ -16,9 +18,13 @@ namespace snmalloc template std::enable_if_t, uint64_t> get_entropy64() { +#ifdef SNMALLOC_PLATFORM_HAS_GETENTROPY + return DefaultPal::get_entropy64(); +#else std::random_device rd; uint64_t a = rd(); return (a << 32) ^ rd(); +#endif } class LocalEntropy @@ -135,4 +141,4 @@ namespace snmalloc return result; } }; -} // namespace snmalloc \ No newline at end of file +} // namespace snmalloc From 704bc423cc77f0d5c1a12550a31c6b04b885c610 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Tue, 20 Jul 2021 15:59:44 +0800 Subject: [PATCH 4/4] refact(cmake): change mcx16 detection to facilitate cross compiling (#351) * refact(cmake): change mcx16 detection to facilitate cross compiling Signed-off-by: SchrodingerZhu --- CMakeLists.txt | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34f6e53..613af3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,16 +116,6 @@ if(NOT MSVC) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") target_link_libraries(snmalloc_lib INTERFACE atomic) endif() - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - # XXX elseif ARM? - endif() endif() if (WIN32) @@ -141,17 +131,11 @@ if (WIN32) endif() endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - endif() -endif () +# detect support for cmpxchg16b; werror is needed to make sure mcx16 must be used by targets +check_cxx_compiler_flag("-Werror -Wextra -Wall -mcx16" SNMALLOC_COMPILER_SUPPORT_MCX16) +if(SNMALLOC_COMPILER_SUPPORT_MCX16) + target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) +endif() # Have to set this globally, as can't be set on an interface target. if(SNMALLOC_USE_CXX20)