Skip to content

Commit 754949f

Browse files
committed
Revert "Upgrade bundled mimalloc to 3.0.8"
This reverts commit 1b76a11. Closes #1502
1 parent 05f5cdc commit 754949f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5875
-7235
lines changed

third-party/mimalloc/CMakeLists.txt

Lines changed: 28 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,25 @@ option(MI_PADDING "Enable padding to detect heap block overflow (alway
1010
option(MI_OVERRIDE "Override the standard malloc interface (i.e. define entry points for 'malloc', 'free', etc)" ON)
1111
option(MI_XMALLOC "Enable abort() call on memory allocation failure by default" OFF)
1212
option(MI_SHOW_ERRORS "Show error and warning messages by default (only enabled by default in DEBUG mode)" OFF)
13-
option(MI_GUARDED "Build with guard pages behind certain object allocations (implies MI_NO_PADDING=ON)" OFF)
13+
option(MI_TRACK_VALGRIND "Compile with Valgrind support (adds a small overhead)" OFF)
14+
option(MI_TRACK_ASAN "Compile with address sanitizer support (adds a small overhead)" OFF)
15+
option(MI_TRACK_ETW "Compile with Windows event tracing (ETW) support (adds a small overhead)" OFF)
1416
option(MI_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF)
15-
option(MI_OPT_ARCH "Only for optimized builds: turn on architecture specific optimizations (for x64: '-march=haswell;-mavx2' (2013), for arm64: '-march=armv8.1-a' (2016))" OFF)
16-
option(MI_OPT_SIMD "Use SIMD instructions (requires MI_OPT_ARCH to be enabled)" OFF)
17+
option(MI_OPT_ARCH "Only for optimized builds: turn on architecture specific optimizations (for arm64: '-march=armv8.1-a' (2016))" OFF)
1718
option(MI_SEE_ASM "Generate assembly files" OFF)
1819
option(MI_OSX_INTERPOSE "Use interpose to override standard malloc on macOS" ON)
1920
option(MI_OSX_ZONE "Use malloc zone to override standard malloc on macOS" ON)
2021
option(MI_WIN_REDIRECT "Use redirection module ('mimalloc-redirect') on Windows if compiling mimalloc as a DLL" ON)
2122
option(MI_WIN_USE_FIXED_TLS "Use a fixed TLS slot on Windows to avoid extra tests in the malloc fast path" OFF)
2223
option(MI_LOCAL_DYNAMIC_TLS "Use local-dynamic-tls, a slightly slower but dlopen-compatible thread local storage mechanism (Unix)" OFF)
23-
option(MI_LIBC_MUSL "Enable this when linking with musl libc" OFF)
24-
25-
option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF)
26-
option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clang++)" OFF)
27-
option(MI_TRACK_VALGRIND "Compile with Valgrind support (adds a small overhead)" OFF)
28-
option(MI_TRACK_ASAN "Compile with address sanitizer support (adds a small overhead)" OFF)
29-
option(MI_TRACK_ETW "Compile with Windows event tracing (ETW) support (adds a small overhead)" OFF)
30-
24+
option(MI_LIBC_MUSL "Set this when linking with musl libc" OFF)
3125
option(MI_BUILD_SHARED "Build shared library" ON)
3226
option(MI_BUILD_STATIC "Build static library" ON)
3327
option(MI_BUILD_OBJECT "Build object library" ON)
3428
option(MI_BUILD_TESTS "Build test executables" ON)
35-
29+
option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF)
30+
option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clang++)" OFF)
31+
option(MI_GUARDED "Build with guard pages behind certain object allocations (implies MI_NO_PADDING=ON)" OFF)
3632
option(MI_SKIP_COLLECT_ON_EXIT "Skip collecting memory on program exit" OFF)
3733
option(MI_NO_PADDING "Force no use of padding even in DEBUG mode etc." OFF)
3834
option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version" OFF)
@@ -58,16 +54,16 @@ set(mi_sources
5854
src/alloc-aligned.c
5955
src/alloc-posix.c
6056
src/arena.c
61-
src/arena-meta.c
6257
src/bitmap.c
6358
src/heap.c
6459
src/init.c
6560
src/libc.c
6661
src/options.c
6762
src/os.c
6863
src/page.c
69-
src/page-map.c
7064
src/random.c
65+
src/segment.c
66+
src/segment-map.c
7167
src/stats.c
7268
src/prim/prim.c)
7369

@@ -130,7 +126,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64)$" OR CMAKE_GENE
130126
set(MI_ARCH "x64")
131127
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv[89].?|ARM64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
132128
set(MI_ARCH "arm64")
133-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567].?|ARM)$")
129+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567]|ARM)$")
134130
set(MI_ARCH "arm32")
135131
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv|riscv32|riscv64)$")
136132
if(CMAKE_SIZEOF_VOID_P==4)
@@ -177,8 +173,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "Intel")
177173
list(APPEND mi_cflags -Wall)
178174
endif()
179175

180-
# force C++ compilation with msvc or clang-cl to use modern C++ atomics
181-
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR MI_CLANG_CL)
176+
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel")
182177
set(MI_USE_CXX "ON")
183178
endif()
184179

@@ -283,7 +278,7 @@ endif()
283278
if(MI_SEE_ASM)
284279
message(STATUS "Generate assembly listings (MI_SEE_ASM=ON)")
285280
list(APPEND mi_cflags -save-temps)
286-
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 14)
281+
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
287282
message(STATUS "No GNU Line marker")
288283
list(APPEND mi_cflags -Wno-gnu-line-marker)
289284
endif()
@@ -432,39 +427,28 @@ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM
432427
list(APPEND mi_cflags -ftls-model=initial-exec)
433428
endif()
434429
endif()
435-
endif()
436-
437-
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel")
438430
if(MI_OVERRIDE)
439431
list(APPEND mi_cflags -fno-builtin-malloc)
440432
endif()
441433
endif()
442434

443-
# Compiler and architecture specific flags
444435
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM_NAME MATCHES "Haiku")
445436
if(MI_OPT_ARCH)
446-
if(APPLE AND CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang" AND CMAKE_OSX_ARCHITECTURES) # to support multi-arch binaries (#999)
437+
if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_OSX_ARCHITECTURES) # to support multi-arch binaries (#999)
447438
if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
448439
list(APPEND MI_OPT_ARCH_FLAGS "-Xarch_arm64;-march=armv8.1-a")
449440
endif()
450-
if("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
451-
list(APPEND MI_OPT_ARCH_FLAGS "-Xarch_x86_64;-march=haswell;-Xarch_x86_64;-mavx2")
452-
endif()
453-
elseif(MI_ARCH STREQUAL "x64")
454-
set(MI_OPT_ARCH_FLAGS "-march=haswell;-mavx2") # fast bit scan (since 2013)
455441
elseif(MI_ARCH STREQUAL "arm64")
456-
set(MI_OPT_ARCH_FLAGS "-march=armv8.1-a") # fast atomics (since 2016)
442+
set(MI_OPT_ARCH_FLAGS "-march=armv8.1-a") # fast atomics
457443
endif()
458444
endif()
459445
endif()
460446

461-
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914) # vs2017+
447+
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
462448
list(APPEND mi_cflags /Zc:__cplusplus)
463449
if(MI_OPT_ARCH AND NOT MI_CLANG_CL)
464-
if(MI_ARCH STREQUAL "x64")
465-
set(MI_OPT_ARCH_FLAGS "/arch:AVX2")
466-
elseif(MI_ARCH STREQUAL "arm64")
467-
set(MI_OPT_ARCH_FLAGS "/arch:armv8.1")
450+
if(MI_ARCH STREQUAL "arm64")
451+
set(MI_OPT_ARCH_FLAGS "/arch:armv8.1") # fast atomics
468452
endif()
469453
endif()
470454
endif()
@@ -476,12 +460,6 @@ endif()
476460
if(MI_OPT_ARCH_FLAGS)
477461
list(APPEND mi_cflags ${MI_OPT_ARCH_FLAGS})
478462
message(STATUS "Architecture specific optimization is enabled (with ${MI_OPT_ARCH_FLAGS}) (MI_OPT_ARCH=ON)")
479-
if (MI_OPT_SIMD)
480-
list(APPEND mi_defines "MI_OPT_SIMD=1")
481-
message(STATUS "SIMD instructions are enabled (MI_OPT_SIMD=ON)")
482-
endif()
483-
elseif(MI_OPT_SIMD)
484-
message(STATUS "SIMD instructions are not enabled (either MI_OPT_ARCH=OFF or this architecture has no SIMD support)")
485463
endif()
486464

487465
# extra needed libraries
@@ -554,9 +532,7 @@ if(MI_TRACK_ASAN)
554532
endif()
555533
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC)
556534
list(APPEND mi_defines "MI_CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE_LC}") #todo: multi-config project needs $<CONFIG> ?
557-
if(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$")
558-
list(APPEND mi_defines MI_BUILD_RELEASE)
559-
else()
535+
if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$"))
560536
set(mi_libname "${mi_libname}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version
561537
endif()
562538

@@ -606,7 +582,7 @@ if(MI_BUILD_SHARED)
606582
install(TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
607583
install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
608584

609-
if(WIN32 AND NOT MINGW)
585+
if(WIN32)
610586
# On windows, the import library name for the dll would clash with the static mimalloc.lib library
611587
# so we postfix the dll import library with `.dll.lib` (and also the .pdb debug file)
612588
set_property(TARGET mimalloc PROPERTY ARCHIVE_OUTPUT_NAME "${mi_libname}.dll" )
@@ -616,9 +592,6 @@ if(MI_BUILD_SHARED)
616592
# install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.pdb" DESTINATION ${CMAKE_INSTALL_LIBDIR})
617593
endif()
618594
if(WIN32 AND MI_WIN_REDIRECT)
619-
if(MINGW)
620-
set_property(TARGET mimalloc PROPERTY PREFIX "")
621-
endif()
622595
# On windows, link and copy the mimalloc redirection dll too.
623596
if(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64ec")
624597
set(MIMALLOC_REDIRECT_SUFFIX "-arm64ec")
@@ -734,12 +707,10 @@ if (MI_BUILD_TESTS)
734707
target_compile_definitions(mimalloc-test-${TEST_NAME} PRIVATE ${mi_defines})
735708
target_compile_options(mimalloc-test-${TEST_NAME} PRIVATE ${mi_cflags})
736709
target_include_directories(mimalloc-test-${TEST_NAME} PRIVATE include)
737-
if(MI_BUILD_STATIC AND NOT MI_DEBUG_TSAN)
738-
target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc-static ${mi_libraries})
739-
elseif(MI_BUILD_SHARED)
710+
if(MI_BUILD_SHARED AND (MI_TRACK_ASAN OR MI_DEBUG_TSAN OR MI_DEBUG_UBSAN))
740711
target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc ${mi_libraries})
741712
else()
742-
message(STATUS "cannot build TSAN tests without MI_BUILD_SHARED being enabled")
713+
target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc-static ${mi_libraries})
743714
endif()
744715
add_test(NAME test-${TEST_NAME} COMMAND mimalloc-test-${TEST_NAME})
745716
endforeach()
@@ -748,19 +719,21 @@ if (MI_BUILD_TESTS)
748719
if(MI_BUILD_SHARED AND NOT (MI_TRACK_ASAN OR MI_DEBUG_TSAN OR MI_DEBUG_UBSAN))
749720
add_executable(mimalloc-test-stress-dynamic test/test-stress.c)
750721
target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE ${mi_defines} "USE_STD_MALLOC=1")
722+
if(WIN32)
723+
target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE "MI_LINK_VERSION=1")
724+
endif()
751725
target_compile_options(mimalloc-test-stress-dynamic PRIVATE ${mi_cflags})
752726
target_include_directories(mimalloc-test-stress-dynamic PRIVATE include)
727+
target_link_libraries(mimalloc-test-stress-dynamic PRIVATE mimalloc ${mi_libraries}) # mi_version
753728
if(WIN32)
754-
target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE "MI_LINK_VERSION=1") # link mi_version
755-
target_link_libraries(mimalloc-test-stress-dynamic PRIVATE mimalloc ${mi_libraries}) # link mi_version
756-
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_VERBOSE=1 $<TARGET_FILE:mimalloc-test-stress-dynamic>)
729+
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_SHOW_STATS=1 $<TARGET_FILE:mimalloc-test-stress-dynamic>)
757730
else()
758731
if(APPLE)
759732
set(LD_PRELOAD "DYLD_INSERT_LIBRARIES")
760733
else()
761734
set(LD_PRELOAD "LD_PRELOAD")
762735
endif()
763-
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_VERBOSE=1 ${LD_PRELOAD}=$<TARGET_FILE:mimalloc> $<TARGET_FILE:mimalloc-test-stress-dynamic>)
736+
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_SHOW_STATS=1 ${LD_PRELOAD}=$<TARGET_FILE:mimalloc> $<TARGET_FILE:mimalloc-test-stress-dynamic>)
764737
endif()
765738
endif()
766739
endif()

third-party/mimalloc/azure-pipelines.yml

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
trigger:
77
branches:
88
include:
9-
- main
10-
- dev*
9+
- master
10+
- dev
11+
- dev2
12+
- dev3
1113
tags:
1214
include:
1315
- v*
@@ -28,10 +30,6 @@ jobs:
2830
BuildType: release
2931
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
3032
MSBuildConfiguration: Release
31-
Release SIMD:
32-
BuildType: release-simd
33-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_OPT_SIMD=ON -DMI_WIN_USE_FIXED_TLS=ON
34-
MSBuildConfiguration: Release
3533
Secure:
3634
BuildType: secure
3735
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
@@ -91,11 +89,6 @@ jobs:
9189
CXX: clang++
9290
BuildType: release-clang
9391
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
94-
Release SIMD Clang:
95-
CC: clang
96-
CXX: clang++
97-
BuildType: release-simd-clang
98-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_OPT_SIMD=ON
9992
Secure Clang:
10093
CC: clang
10194
CXX: clang++
@@ -155,9 +148,6 @@ jobs:
155148
Release:
156149
BuildType: release
157150
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
158-
Release SIMD:
159-
BuildType: release-simd
160-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_OPT_SIMD=ON
161151
Secure:
162152
BuildType: secure
163153
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
@@ -171,13 +161,43 @@ jobs:
171161
- script: ctest --verbose --timeout 240
172162
workingDirectory: $(BuildType)
173163
displayName: CTest
164+
174165
# - upload: $(Build.SourcesDirectory)/$(BuildType)
175166
# artifact: mimalloc-macos-$(BuildType)
176167

177168
# ----------------------------------------------------------
178169
# Other OS versions (just debug mode)
179170
# ----------------------------------------------------------
180171

172+
- job:
173+
displayName: Windows 2019
174+
pool:
175+
vmImage:
176+
windows-2019
177+
strategy:
178+
matrix:
179+
Debug:
180+
BuildType: debug
181+
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
182+
MSBuildConfiguration: Debug
183+
Release:
184+
BuildType: release
185+
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
186+
MSBuildConfiguration: Release
187+
steps:
188+
- task: CMake@1
189+
inputs:
190+
workingDirectory: $(BuildType)
191+
cmakeArgs: .. $(cmakeExtraArgs)
192+
- task: MSBuild@1
193+
inputs:
194+
solution: $(BuildType)/libmimalloc.sln
195+
configuration: '$(MSBuildConfiguration)'
196+
msbuildArguments: -m
197+
- script: ctest --verbose --timeout 240 -C $(MSBuildConfiguration)
198+
workingDirectory: $(BuildType)
199+
displayName: CTest
200+
181201
- job:
182202
displayName: Ubuntu 24.04
183203
pool:
@@ -244,28 +264,3 @@ jobs:
244264
- script: ctest --verbose --timeout 240
245265
workingDirectory: $(BuildType)
246266
displayName: CTest
247-
248-
- job:
249-
displayName: macOS 13 (Ventura)
250-
pool:
251-
vmImage:
252-
macOS-13
253-
strategy:
254-
matrix:
255-
Debug:
256-
BuildType: debug
257-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
258-
Release:
259-
BuildType: release
260-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
261-
steps:
262-
- task: CMake@1
263-
inputs:
264-
workingDirectory: $(BuildType)
265-
cmakeArgs: .. $(cmakeExtraArgs)
266-
- script: make -j$(sysctl -n hw.ncpu) -C $(BuildType)
267-
displayName: Make
268-
- script: ctest --verbose --timeout 180
269-
workingDirectory: $(BuildType)
270-
displayName: CTest
271-

third-party/mimalloc/bin/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<span id="override_on_windows">We use a separate redirection DLL to override mimalloc on Windows</span>
44
such that we redirect all malloc/free calls that go through the (dynamic) C runtime allocator,
55
including those from other DLL's or libraries. As it intercepts all allocation calls on a low level,
6-
it can be used reliably on large programs that include other 3rd party components.
6+
it can be used on large programs that include other 3rd party components.
77
There are four requirements to make the overriding work well:
88

99
1. Use the C-runtime library as a DLL (using the `/MD` or `/MDd` switch).
@@ -63,7 +63,7 @@ need a specific redirection DLL:
6363
mode on Windows arm64. Unfortunately we cannot run x64 code emulated on Windows arm64 with
6464
the x64 mimalloc override directly (since the C runtime always uses `arm64ec`). Instead:
6565
1. Build the program as normal for x64 and link as normal with the x64
66-
`mimalloc.dll.lib` export library.
66+
`mimalloc.lib` export library.
6767
2. Now separately build `mimalloc.dll` in `arm64ec` mode and _overwrite_ your
6868
previous (x64) `mimalloc.dll` -- the loader can handle the mix of arm64ec
6969
and x64 code. Now use `mimalloc-redirect-arm64ec.dll` to match your new

third-party/mimalloc/cmake/mimalloc-config-version.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
set(mi_version_major 3)
2-
set(mi_version_minor 0)
3-
set(mi_version_patch 8)
1+
set(mi_version_major 2)
2+
set(mi_version_minor 2)
3+
set(mi_version_patch 2)
44
set(mi_version ${mi_version_major}.${mi_version_minor})
55

66
set(PACKAGE_VERSION ${mi_version})

0 commit comments

Comments
 (0)