From acc64ee5cd58277490a89d4c4f97e3f3839beff5 Mon Sep 17 00:00:00 2001 From: Igor Vlasenko Date: Sun, 28 Nov 2021 19:14:31 +0200 Subject: [PATCH 1/8] added SOVERSION to mimalloc shared lib (issue #490) This is a portability improvement. A cross-platform library needs SOVERSION field for Unix platforms. With SOVERSION field cmake itself will do proper management of libmimalloc.so.SOVERSION -> libmimalloc.so.VERSION symlink on Unix, so a piece of code that tried to emulate this behavior manually is no more needed and is removed here too. --- CMakeLists.txt | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c2c6cfc..8eb5c958 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -280,7 +280,7 @@ message(STATUS "") # shared library if(MI_BUILD_SHARED) add_library(mimalloc SHARED ${mi_sources}) - set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} OUTPUT_NAME ${mi_basename} ) + set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} SOVERSION ${mi_version_major} OUTPUT_NAME ${mi_basename} ) target_compile_definitions(mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT) target_compile_options(mimalloc PRIVATE ${mi_cflags}) target_link_libraries(mimalloc PUBLIC ${mi_libraries}) @@ -336,16 +336,6 @@ install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_incdir}) install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_cmakedir}) install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_cmakedir}) -if(NOT WIN32 AND MI_BUILD_SHARED AND NOT MI_INSTALL_TOPLEVEL) - # install a symlink in the /usr/local/lib to the versioned library - # note: use delayed prefix expansion as \${CMAKE_INSTALL_PREFIX} - set(mi_symlink "${CMAKE_SHARED_MODULE_PREFIX}${mi_basename}${CMAKE_SHARED_LIBRARY_SUFFIX}") - set(mi_soname "mimalloc-${mi_version}/${mi_symlink}.${mi_version}") - install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${mi_soname} ${mi_symlink} WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib)") - install(CODE "MESSAGE(\"-- Symbolic link: \${CMAKE_INSTALL_PREFIX}/lib/${mi_symlink} -> ${mi_soname}\")") - install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${mi_soname} ${mi_symlink}.${mi_version} WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib)") - install(CODE "MESSAGE(\"-- Symbolic link: \${CMAKE_INSTALL_PREFIX}/lib/${mi_symlink}.${mi_version} -> ${mi_soname}\")") -endif() # single object file for more predictable static overriding if (MI_BUILD_OBJECT) From f82e13ac91716ff60d4e656e1f825ce727b7fd7d Mon Sep 17 00:00:00 2001 From: Igor Vlasenko Date: Sun, 28 Nov 2021 19:20:12 +0200 Subject: [PATCH 2/8] let the library VERSION = the project's one (issue #490) This is a cross-platform usability improvement. On Unix platforms it is customary for library to have VERSION and SOVERSION, where SOVERSION changes on major API changes and VERSION is the same as project's version, so library users always know what vesion this library belongs to just by name. With this patch we have a proper libmimalloc.so.VERSION on Unix. --- cmake/mimalloc-config-version.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/mimalloc-config-version.cmake b/cmake/mimalloc-config-version.cmake index ed95c19e..3768d7de 100644 --- a/cmake/mimalloc-config-version.cmake +++ b/cmake/mimalloc-config-version.cmake @@ -1,6 +1,7 @@ set(mi_version_major 1) set(mi_version_minor 7) -set(mi_version ${mi_version_major}.${mi_version_minor}) +set(mi_version_patch 3) +set(mi_version ${mi_version_major}.${mi_version_minor}.${mi_version_patch}) set(PACKAGE_VERSION ${mi_version}) if(PACKAGE_FIND_VERSION_MAJOR) From 3a212d1895c8722a31a78d354793fbd6b2f3192f Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 12 Dec 2021 10:35:13 -0800 Subject: [PATCH 3/8] fix assembly for mi_tls_slot_set on x32 and x64. Issue #488 --- include/mimalloc-internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index cf5b6783..4713a75e 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -746,9 +746,9 @@ static inline void mi_tls_slot_set(size_t slot, void* value) mi_attr_noexcept { #elif defined(__APPLE__) && defined(__x86_64__) __asm__("movq %1,%%gs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x86_64 macOSX uses GS #elif defined(__x86_64__) && (MI_INTPTR_SIZE==4) - __asm__("movl %1,%%fs:%1" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x32 ABI + __asm__("movl %1,%%fs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x32 ABI #elif defined(__x86_64__) - __asm__("movq %1,%%fs:%1" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x86_64 Linux, BSD uses FS + __asm__("movq %1,%%fs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x86_64 Linux, BSD uses FS #elif defined(__arm__) void** tcb; MI_UNUSED(ofs); __asm__ volatile ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tcb)); From d575aacfde579c241580d61297ec2430c4994109 Mon Sep 17 00:00:00 2001 From: Daan Date: Mon, 13 Dec 2021 13:10:33 -0800 Subject: [PATCH 4/8] use find_library for pthread (issue #496) --- CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c2c6cfc..47b43ce5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,13 +210,14 @@ endif() if(WIN32) list(APPEND mi_libraries psapi shell32 user32 advapi32 bcrypt) else() - if(NOT ${CMAKE_C_COMPILER} MATCHES "android") - list(APPEND mi_libraries pthread) - find_library(LIBRT rt) - if(LIBRT) - list(APPEND mi_libraries ${LIBRT}) - endif() + find_library(LIBPTHREAD pthread) + if (LIBPTHREAD) + list(APPEND mi_libraries ${LIBPTHREAD}) endif() + find_library(LIBRT rt) + if(LIBRT) + list(APPEND mi_libraries ${LIBRT}) + endif() endif() if (MI_USE_LIBATOMIC) @@ -270,6 +271,8 @@ else() message(STATUS "C Compiler : ${CMAKE_C_COMPILER}") endif() message(STATUS "Compiler flags : ${mi_cflags}") +message(STATUS "Compiler defines : ${mi_defines}") +message(STATUS "Link libraries : ${mi_libraries}") message(STATUS "Build targets : ${mi_build_targets}") message(STATUS "") From 69b6b246880d04e911416ffce8e8ccf6539ae2d7 Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 14 Dec 2021 18:29:14 -0800 Subject: [PATCH 5/8] further improvements to installation directories --- CMakeLists.txt | 19 +++++++++++-------- cmake/mimalloc-config-version.cmake | 4 ++-- cmake/mimalloc-config.cmake | 19 +++++++++++-------- include/mimalloc.h | 2 +- test/CMakeLists.txt | 2 +- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3790b09..0ceadffd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -228,14 +228,17 @@ endif() # Install and output names # ----------------------------------------------------------------------------- +set(mi_install_libdir "${CMAKE_INSTALL_LIBDIR}") # for dynamic/shared library and symlinks + +# install at top level or use versioned directories for side-by-side installation? if (MI_INSTALL_TOPLEVEL) - set(mi_install_libdir "${CMAKE_INSTALL_LIBDIR}") - set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}") - set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc") + set(mi_install_objdir "${CMAKE_INSTALL_LIBDIR}") + set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}") + set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc") else() - set(mi_install_libdir "lib/mimalloc-${mi_version}") - set(mi_install_incdir "include/mimalloc-${mi_version}") - set(mi_install_cmakedir "share/mimalloc-${mi_version}/cmake") + set(mi_install_objdir "${CMAKE_INSTALL_LIBDIR}/mimalloc-${mi_version}") # for static library and object files + set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}/mimalloc-${mi_version}") # for includes + set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc-${mi_version}") # for cmake package info endif() if(MI_SECURE) @@ -329,7 +332,7 @@ if (MI_BUILD_STATIC) set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename}) endif() - install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_libdir} LIBRARY) + install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_objdir} LIBRARY) endif() # install include files @@ -357,7 +360,7 @@ if (MI_BUILD_OBJECT) # the FILES expression can also be: $ # but that fails cmake versions less than 3.10 so we leave it as is for now install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/mimalloc-obj.dir/src/static.c${CMAKE_C_OUTPUT_EXTENSION} - DESTINATION ${mi_install_libdir} + DESTINATION ${mi_install_objdir} RENAME ${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} ) endif() diff --git a/cmake/mimalloc-config-version.cmake b/cmake/mimalloc-config-version.cmake index 3768d7de..7bbd7313 100644 --- a/cmake/mimalloc-config-version.cmake +++ b/cmake/mimalloc-config-version.cmake @@ -1,7 +1,7 @@ set(mi_version_major 1) set(mi_version_minor 7) -set(mi_version_patch 3) -set(mi_version ${mi_version_major}.${mi_version_minor}.${mi_version_patch}) +set(mi_version_patch 4) +set(mi_version ${mi_version_major}.${mi_version_minor}) set(PACKAGE_VERSION ${mi_version}) if(PACKAGE_FIND_VERSION_MAJOR) diff --git a/cmake/mimalloc-config.cmake b/cmake/mimalloc-config.cmake index 9b0a56d7..45d9692f 100644 --- a/cmake/mimalloc-config.cmake +++ b/cmake/mimalloc-config.cmake @@ -1,11 +1,14 @@ include(${CMAKE_CURRENT_LIST_DIR}/mimalloc.cmake) -get_filename_component(MIMALLOC_SHARE_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH) # one up from the cmake dir, e.g. /usr/local/share/mimalloc-2.0 -if (MIMALLOC_SHARE_DIR MATCHES "/share/") - string(REPLACE "/share/" "/lib/" MIMALLOC_LIBRARY_DIR ${MIMALLOC_SHARE_DIR}) - string(REPLACE "/share/" "/include/" MIMALLOC_INCLUDE_DIR ${MIMALLOC_SHARE_DIR}) -else() - # installed with -DMI_INSTALL_TOPLEVEL=ON - string(REPLACE "/lib/cmake" "/lib" MIMALLOC_LIBRARY_DIR "${MIMALLOC_SHARE_DIR}") - string(REPLACE "/lib/cmake" "/include" MIMALLOC_INCLUDE_DIR "${MIMALLOC_SHARE_DIR}") +get_filename_component(MIMALLOC_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH) # one up from the cmake dir, e.g. /usr/local/lib/cmake/mimalloc-2.0 +get_filename_component(MIMALLOC_VER_DIR "${CMAKE_CURRENT_LIST_DIR}" NAME) +string(REPLACE "/lib/cmake" "/lib" MIMALLOC_LIBRARY_DIR "${MIMALLOC_CMAKE_DIR}") +if("${MIMALLOC_VER_DIR}" EQUAL "mimalloc") + # top level install + string(REPLACE "/lib/cmake" "/include" MIMALLOC_INCLUDE_DIR "${MIMALLOC_CMAKE_DIR}") + set(MIMALLOC_OBJECT_DIR "${MIMALLOC_LIBRARY_DIR}") +else() + # versioned + string(REPLACE "/lib/cmake/" "/include/" MIMALLOC_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}") + string(REPLACE "/lib/cmake/" "/lib/" MIMALLOC_OBJECT_DIR "${CMAKE_CURRENT_LIST_DIR}") endif() set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}") # legacy diff --git a/include/mimalloc.h b/include/mimalloc.h index 06a16703..a955e35c 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file #ifndef MIMALLOC_H #define MIMALLOC_H -#define MI_MALLOC_VERSION 173 // major + 2 digits minor +#define MI_MALLOC_VERSION 174 // major + 2 digits minor // ------------------------------------------------------ // Compiler specific attributes diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 13bf32de..407dbee9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,7 +29,7 @@ target_link_libraries(dynamic-override-cxx PUBLIC mimalloc) # overriding with a static object file works reliable as the symbols in the # object file have priority over those in library files -add_executable(static-override-obj main-override.c ${MIMALLOC_LIBRARY_DIR}/mimalloc.o) +add_executable(static-override-obj main-override.c ${MIMALLOC_OBJECT_DIR}/mimalloc.o) target_include_directories(static-override-obj PUBLIC ${MIMALLOC_INCLUDE_DIR}) target_link_libraries(static-override-obj PUBLIC pthread) From 73ced777dd11feeafc4664e8fe1814fa942481af Mon Sep 17 00:00:00 2001 From: daan Date: Tue, 14 Dec 2021 18:42:10 -0800 Subject: [PATCH 6/8] upgrade macos to latest --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index aeb2908b..7261fc13 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -115,7 +115,7 @@ jobs: displayName: macOS pool: vmImage: - macOS-10.14 + macOS-latest strategy: matrix: Debug: From 6503ad7a76dacfae142ed4f8f23d1039a18dede8 Mon Sep 17 00:00:00 2001 From: daan Date: Tue, 14 Dec 2021 18:45:44 -0800 Subject: [PATCH 7/8] check if using bcryptgenrandom fixes windows pipeline --- src/random.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/random.c b/src/random.c index 1220401a..fabd6c6e 100644 --- a/src/random.c +++ b/src/random.c @@ -167,8 +167,8 @@ If we cannot get good randomness, we fall back to weak randomness based on a tim #if defined(_WIN32) -#if defined(MI_USE_BCRYPTGENRANDOM) -// We would like to use BCryptGenRandom instead of RtlGenRandom but it can lead to a deadlock +#if !defined(MI_USE_RTLGENRANDOM) +// We prefer to use BCryptGenRandom instead of RtlGenRandom but it can lead to a deadlock // under the VS debugger when using dynamic overriding. #pragma comment (lib,"bcrypt.lib") #include From 2d9b8aa6b56241ff3cc88ed5d5e3d862d91fd096 Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 15 Dec 2021 08:33:14 -0800 Subject: [PATCH 8/8] rename VER_DIR to VERSION_DIR --- cmake/mimalloc-config.cmake | 4 ++-- test/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/mimalloc-config.cmake b/cmake/mimalloc-config.cmake index 45d9692f..8a28e37e 100644 --- a/cmake/mimalloc-config.cmake +++ b/cmake/mimalloc-config.cmake @@ -1,8 +1,8 @@ include(${CMAKE_CURRENT_LIST_DIR}/mimalloc.cmake) get_filename_component(MIMALLOC_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH) # one up from the cmake dir, e.g. /usr/local/lib/cmake/mimalloc-2.0 -get_filename_component(MIMALLOC_VER_DIR "${CMAKE_CURRENT_LIST_DIR}" NAME) +get_filename_component(MIMALLOC_VERSION_DIR "${CMAKE_CURRENT_LIST_DIR}" NAME) string(REPLACE "/lib/cmake" "/lib" MIMALLOC_LIBRARY_DIR "${MIMALLOC_CMAKE_DIR}") -if("${MIMALLOC_VER_DIR}" EQUAL "mimalloc") +if("${MIMALLOC_VERSION_DIR}" EQUAL "mimalloc") # top level install string(REPLACE "/lib/cmake" "/include" MIMALLOC_INCLUDE_DIR "${MIMALLOC_CMAKE_DIR}") set(MIMALLOC_OBJECT_DIR "${MIMALLOC_LIBRARY_DIR}") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 407dbee9..054d9409 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,7 +17,7 @@ endif() # Import mimalloc (if installed) find_package(mimalloc 1.7 REQUIRED NO_SYSTEM_ENVIRONMENT_PATH) -message(STATUS "Found mimalloc installed at: ${MIMALLOC_LIBRARY_DIR}") +message(STATUS "Found mimalloc installed at: ${MIMALLOC_LIBRARY_DIR} (${MIMALLOC_VERSION_DIR})") # overriding with a dynamic library add_executable(dynamic-override main-override.c)