mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-03 05:59:31 +03:00
merge from dev
This commit is contained in:
commit
191ea046e4
20 changed files with 269 additions and 60 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
build
|
||||
ide/vs20??/*.db
|
||||
ide/vs20??/*.opendb
|
||||
ide/vs20??/*.user
|
||||
|
@ -8,3 +9,5 @@ docs/
|
|||
*.zip
|
||||
*.tar
|
||||
*.gz
|
||||
.vscode
|
||||
.DS_STore
|
||||
|
|
|
@ -35,6 +35,10 @@ option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead
|
|||
option(MI_NO_THP "Disable transparent huge pages support on Linux/Android for the mimalloc process only" OFF)
|
||||
option(MI_EXTRA_CPPDEFS "Extra pre-processor definitions (use as `-DMI_EXTRA_CPPDEFS=\"opt1=val1;opt2=val2\"`)" "")
|
||||
|
||||
# negated options for vcpkg features
|
||||
option(MI_NO_USE_CXX "Use plain C compilation (has priority over MI_USE_CXX)" OFF)
|
||||
option(MI_NO_OPT_ARCH "Do not use architecture specific optimizations (like '-march=armv8.1-a' for example) (has priority over MI_OPT_ARCH)" OFF)
|
||||
|
||||
# deprecated options
|
||||
option(MI_WIN_USE_FLS "Use Fiber local storage on Windows to detect thread termination (deprecated)" OFF)
|
||||
option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF)
|
||||
|
@ -121,6 +125,15 @@ if(CMAKE_C_COMPILER_ID MATCHES "Intel")
|
|||
list(APPEND mi_cflags -Wall)
|
||||
endif()
|
||||
|
||||
# negative overrides (mainly to support vcpkg features)
|
||||
if(MI_NO_USE_CXX)
|
||||
set(MI_USE_CXX "OFF")
|
||||
endif()
|
||||
if(MI_NO_OPT_ARCH)
|
||||
set(MI_OPT_ARCH "OFF")
|
||||
endif()
|
||||
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel")
|
||||
set(MI_USE_CXX "ON")
|
||||
endif()
|
||||
|
@ -385,7 +398,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU" AND NOT MI_CLANG_CL)
|
|||
endif()
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
|
||||
list(APPEND mi_cflags -Wno-static-in-inline)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Intel")
|
||||
|
@ -422,7 +435,7 @@ if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
|
|||
list(APPEND mi_cflags /Zc:__cplusplus)
|
||||
if(MI_OPT_ARCH AND NOT MI_CLANG_CL)
|
||||
if(MI_ARCH STREQUAL "arm64")
|
||||
set(MI_OPT_ARCH_FLAGS "/arch:armv8.1") # fast atomics
|
||||
set(MI_OPT_ARCH_FLAGS "/arch:armv8.1") # fast atomics
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
@ -479,8 +492,7 @@ endif()
|
|||
# -----------------------------------------------------------------------------
|
||||
|
||||
# dynamic/shared library and symlinks always go to /usr/local/lib equivalent
|
||||
set(mi_install_libdir "${CMAKE_INSTALL_LIBDIR}")
|
||||
set(mi_install_bindir "${CMAKE_INSTALL_BINDIR}")
|
||||
# we use ${CMAKE_INSTALL_BINDIR} and ${CMAKE_INSTALL_LIBDIR}.
|
||||
|
||||
# static libraries and object files, includes, and cmake config files
|
||||
# are either installed at top level, or use versioned directories for side-by-side installation (default)
|
||||
|
@ -494,19 +506,19 @@ else()
|
|||
set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc-${mi_version}") # for cmake package info
|
||||
endif()
|
||||
|
||||
set(mi_basename "mimalloc")
|
||||
set(mi_libname "mimalloc")
|
||||
if(MI_SECURE)
|
||||
set(mi_basename "${mi_basename}-secure")
|
||||
set(mi_libname "${mi_libname}-secure")
|
||||
endif()
|
||||
if(MI_TRACK_VALGRIND)
|
||||
set(mi_basename "${mi_basename}-valgrind")
|
||||
set(mi_libname "${mi_libname}-valgrind")
|
||||
endif()
|
||||
if(MI_TRACK_ASAN)
|
||||
set(mi_basename "${mi_basename}-asan")
|
||||
set(mi_libname "${mi_libname}-asan")
|
||||
endif()
|
||||
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC)
|
||||
if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$"))
|
||||
set(mi_basename "${mi_basename}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version
|
||||
set(mi_libname "${mi_libname}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version
|
||||
endif()
|
||||
|
||||
if(MI_BUILD_SHARED)
|
||||
|
@ -523,7 +535,7 @@ if(MI_BUILD_TESTS)
|
|||
endif()
|
||||
|
||||
message(STATUS "")
|
||||
message(STATUS "Library base name: ${mi_basename}")
|
||||
message(STATUS "Library name : ${mi_libname}")
|
||||
message(STATUS "Version : ${mi_version}.${mi_version_patch}")
|
||||
message(STATUS "Build type : ${CMAKE_BUILD_TYPE_LC}")
|
||||
if(MI_USE_CXX)
|
||||
|
@ -544,7 +556,7 @@ message(STATUS "")
|
|||
# shared library
|
||||
if(MI_BUILD_SHARED)
|
||||
add_library(mimalloc SHARED ${mi_sources})
|
||||
set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} SOVERSION ${mi_version_major} OUTPUT_NAME ${mi_basename} )
|
||||
set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} SOVERSION ${mi_version_major} OUTPUT_NAME ${mi_libname} )
|
||||
target_compile_definitions(mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT)
|
||||
target_compile_options(mimalloc PRIVATE ${mi_cflags} ${mi_cflags_dynamic})
|
||||
target_link_libraries(mimalloc PRIVATE ${mi_libraries})
|
||||
|
@ -552,6 +564,15 @@ if(MI_BUILD_SHARED)
|
|||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${mi_install_incdir}>
|
||||
)
|
||||
install(TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
|
||||
|
||||
if(WIN32)
|
||||
# On windows, the import library name for the dll would clash with the static mimalloc.lib
|
||||
# so we postfix the dll import library with `.dll.lib`.
|
||||
set_property(TARGET mimalloc PROPERTY ARCHIVE_OUTPUT_NAME "${mi_libname}.dll" )
|
||||
install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.lib" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
if(WIN32 AND MI_WIN_REDIRECT)
|
||||
# On windows, link and copy the mimalloc redirection dll too.
|
||||
if(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64ec")
|
||||
|
@ -559,8 +580,8 @@ if(MI_BUILD_SHARED)
|
|||
elseif(MI_ARCH STREQUAL "x64")
|
||||
set(MIMALLOC_REDIRECT_SUFFIX "")
|
||||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
|
||||
message(STATUS "Note: x64 code emulated on Windows for arm64 should use an arm64ec build of 'mimalloc-override.dll'")
|
||||
message(STATUS " with 'mimalloc-redirect-arm64ec.dll'. See the 'bin\\readme.md' for more information.")
|
||||
message(STATUS "Note: x64 code emulated on Windows for arm64 should use an arm64ec build of 'mimalloc.dll'")
|
||||
message(STATUS " together with 'mimalloc-redirect-arm64ec.dll'. See the 'bin\\readme.md' for more information.")
|
||||
endif()
|
||||
elseif(MI_ARCH STREQUAL "x86")
|
||||
set(MIMALLOC_REDIRECT_SUFFIX "32")
|
||||
|
@ -568,20 +589,19 @@ if(MI_BUILD_SHARED)
|
|||
set(MIMALLOC_REDIRECT_SUFFIX "-${MI_ARCH}") # -arm64 etc.
|
||||
endif()
|
||||
|
||||
target_link_libraries(mimalloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.lib)
|
||||
target_link_libraries(mimalloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.lib) # the DLL import library
|
||||
add_custom_command(TARGET mimalloc POST_BUILD
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" $<TARGET_FILE_DIR:mimalloc>
|
||||
COMMENT "Copy mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll to output directory")
|
||||
install(FILES "$<TARGET_FILE_DIR:mimalloc>/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${mi_install_bindir})
|
||||
install(FILES "$<TARGET_FILE_DIR:mimalloc>/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
install(TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION ${mi_install_libdir} RUNTIME DESTINATION ${mi_install_bindir} LIBRARY DESTINATION ${mi_install_libdir})
|
||||
install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
|
||||
endif()
|
||||
|
||||
|
||||
# static library
|
||||
if (MI_BUILD_STATIC)
|
||||
add_library(mimalloc-static STATIC ${mi_sources})
|
||||
set_property(TARGET mimalloc-static PROPERTY OUTPUT_NAME ${mi_libname})
|
||||
set_property(TARGET mimalloc-static PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
target_compile_definitions(mimalloc-static PRIVATE ${mi_defines} MI_STATIC_LIB)
|
||||
target_compile_options(mimalloc-static PRIVATE ${mi_cflags} ${mi_cflags_static})
|
||||
|
@ -590,15 +610,6 @@ if (MI_BUILD_STATIC)
|
|||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${mi_install_incdir}>
|
||||
)
|
||||
if(WIN32)
|
||||
# When building both static and shared libraries on Windows, a static library should use a
|
||||
# different output name to avoid the conflict with the import library of a shared one.
|
||||
string(REPLACE "mimalloc" "mimalloc-static" mi_output_name ${mi_basename})
|
||||
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_output_name})
|
||||
else()
|
||||
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename})
|
||||
endif()
|
||||
|
||||
install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_objdir} LIBRARY)
|
||||
install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
|
||||
endif()
|
||||
|
@ -623,12 +634,15 @@ if (MI_BUILD_OBJECT)
|
|||
)
|
||||
|
||||
# Copy the generated object file (`static.o`) to the output directory (as `mimalloc.o`)
|
||||
if(NOT WIN32)
|
||||
if(CMAKE_GENERATOR MATCHES "^Visual Studio.*$")
|
||||
set(mimalloc-obj-static "${CMAKE_CURRENT_BINARY_DIR}/mimalloc-obj.dir/$<CONFIG>/static${CMAKE_C_OUTPUT_EXTENSION}")
|
||||
else()
|
||||
set(mimalloc-obj-static "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/mimalloc-obj.dir/src/static.c${CMAKE_C_OUTPUT_EXTENSION}")
|
||||
set(mimalloc-obj-out "${CMAKE_CURRENT_BINARY_DIR}/${mi_basename}${CMAKE_C_OUTPUT_EXTENSION}")
|
||||
add_custom_command(OUTPUT ${mimalloc-obj-out} DEPENDS mimalloc-obj COMMAND "${CMAKE_COMMAND}" -E copy "${mimalloc-obj-static}" "${mimalloc-obj-out}")
|
||||
add_custom_target(mimalloc-obj-target ALL DEPENDS ${mimalloc-obj-out})
|
||||
endif()
|
||||
set(mimalloc-obj-out "${CMAKE_CURRENT_BINARY_DIR}/${mi_libname}${CMAKE_C_OUTPUT_EXTENSION}")
|
||||
add_custom_command(OUTPUT ${mimalloc-obj-out} DEPENDS mimalloc-obj COMMAND "${CMAKE_COMMAND}" -E copy "${mimalloc-obj-static}" "${mimalloc-obj-out}")
|
||||
add_custom_target(mimalloc-obj-target ALL DEPENDS ${mimalloc-obj-out})
|
||||
|
||||
|
||||
# the following seems to lead to cmake warnings/errors on some systems, disable for now :-(
|
||||
# install(TARGETS mimalloc-obj EXPORT mimalloc DESTINATION ${mi_install_objdir})
|
||||
|
@ -637,22 +651,23 @@ if (MI_BUILD_OBJECT)
|
|||
# but that fails cmake versions less than 3.10 so we leave it as is for now
|
||||
install(FILES ${mimalloc-obj-static}
|
||||
DESTINATION ${mi_install_objdir}
|
||||
RENAME ${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} )
|
||||
RENAME ${mi_libname}${CMAKE_C_OUTPUT_EXTENSION} )
|
||||
endif()
|
||||
|
||||
|
||||
# pkg-config file support
|
||||
set(pc_libraries "")
|
||||
set(mi_pc_libraries "")
|
||||
foreach(item IN LISTS mi_libraries)
|
||||
if(item MATCHES " *[-].*")
|
||||
set(pc_libraries "${pc_libraries} ${item}")
|
||||
set(mi_pc_libraries "${mi_pc_libraries} ${item}")
|
||||
else()
|
||||
set(pc_libraries "${pc_libraries} -l${item}")
|
||||
set(mi_pc_libraries "${mi_pc_libraries} -l${item}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
include("cmake/JoinPaths.cmake")
|
||||
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
|
||||
join_paths(mi_pc_includedir "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
join_paths(mi_pc_libdir "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
|
||||
|
||||
configure_file(mimalloc.pc.in mimalloc.pc @ONLY)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc"
|
||||
|
|
Binary file not shown.
BIN
bin/minject.exe
BIN
bin/minject.exe
Binary file not shown.
Binary file not shown.
63
contrib/vcpkg/portfile.cmake
Normal file
63
contrib/vcpkg/portfile.cmake
Normal file
|
@ -0,0 +1,63 @@
|
|||
vcpkg_from_github(
|
||||
OUT_SOURCE_PATH SOURCE_PATH
|
||||
REPO microsoft/mimalloc
|
||||
HEAD_REF master
|
||||
|
||||
# The "REF" can be a commit hash, branch name (dev2), or a version (v2.2.1).
|
||||
# REF "v${VERSION}"
|
||||
REF be05b232e8a51e076aae6d8f4a5c3049ce51cb01
|
||||
|
||||
# The sha512 is the hash of the tar.gz bundle.
|
||||
# (To get the sha512, run `vcpkg install mimalloc[override] --overlay-ports=<dir of this file>` and copy the sha from the error message.)
|
||||
SHA512 24f640db050d6263e557fe9d024e6c0435762118605c0d04801efbcb32e96382b0b995000715fc0c2dcd67c67825a100a6690ecf0ef097b0a3ae107a82d74f7d
|
||||
)
|
||||
|
||||
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
|
||||
FEATURES
|
||||
c MI_NO_USE_CXX
|
||||
guarded MI_GUARDED
|
||||
secure MI_SECURE
|
||||
override MI_OVERRIDE
|
||||
xmalloc MI_XMALLOC
|
||||
asm MI_SEE_ASM
|
||||
)
|
||||
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" MI_BUILD_STATIC)
|
||||
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" MI_BUILD_SHARED)
|
||||
|
||||
vcpkg_cmake_configure(
|
||||
SOURCE_PATH "${SOURCE_PATH}"
|
||||
OPTIONS_RELEASE
|
||||
-DMI_OPT_ARCH=ON
|
||||
OPTIONS
|
||||
-DMI_USE_CXX=ON
|
||||
-DMI_BUILD_TESTS=OFF
|
||||
-DMI_BUILD_OBJECT=ON
|
||||
${FEATURE_OPTIONS}
|
||||
-DMI_BUILD_STATIC=${MI_BUILD_STATIC}
|
||||
-DMI_BUILD_SHARED=${MI_BUILD_SHARED}
|
||||
-DMI_INSTALL_TOPLEVEL=ON
|
||||
)
|
||||
|
||||
vcpkg_cmake_install()
|
||||
vcpkg_copy_pdbs()
|
||||
|
||||
file(COPY
|
||||
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/usage"
|
||||
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}"
|
||||
)
|
||||
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/mimalloc)
|
||||
|
||||
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
|
||||
# todo: why is this needed?
|
||||
vcpkg_replace_string(
|
||||
"${CURRENT_PACKAGES_DIR}/include/mimalloc.h"
|
||||
"!defined(MI_SHARED_LIB)"
|
||||
"0 // !defined(MI_SHARED_LIB)"
|
||||
)
|
||||
endif()
|
||||
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
|
||||
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
|
||||
|
||||
vcpkg_fixup_pkgconfig()
|
||||
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
|
40
contrib/vcpkg/readme.md
Normal file
40
contrib/vcpkg/readme.md
Normal file
|
@ -0,0 +1,40 @@
|
|||
# Vcpkg support
|
||||
|
||||
This directory is meant to provide the sources for the official [vcpkg port]
|
||||
of mimalloc, but can also be used to override the official port with
|
||||
your own variant.
|
||||
|
||||
For example, you can edit the [`portfile.cmake`](portfile.cmake)
|
||||
to check out a specific commit, version, or branch of mimalloc, or set further options.
|
||||
You can install such custom port as:
|
||||
|
||||
```sh
|
||||
$ vcpkg install mimalloc[override] --recurse --overlay-ports=./contrib/vcpkg
|
||||
```
|
||||
|
||||
This will also show the correct sha512 hash if you use a custom version.
|
||||
Another way is to refer to the overlay from the [vcpkg-configuration.json](https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-configuration-json) file.
|
||||
See also the vcpkg [documentation](https://learn.microsoft.com/en-us/vcpkg/produce/update-package-version) for more information.
|
||||
|
||||
|
||||
# Using mimalloc from vcpkg
|
||||
|
||||
When using [cmake with vcpkg](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?pivots=shell-powershell),
|
||||
you can use mimalloc from the `CMakeLists.txt` as:
|
||||
|
||||
```cmake
|
||||
find_package(mimalloc CONFIG REQUIRED)
|
||||
target_link_libraries(main PRIVATE mimalloc)
|
||||
```
|
||||
|
||||
See [`test/CMakeLists.txt](../../test/CMakeLists.txt) for more examples.
|
||||
|
||||
|
||||
# Acknowledgements
|
||||
|
||||
The original port for vckpg was contributed by many people, including: @vicroms, @myd7349, @PhoubeHui, @LilyWangL,
|
||||
@JonLiu1993, @RT2Code, Remy Tassoux, @wangao, @BillyONeal, @jiayuehua, @dg0yt, @gerar-ryan-immersaview, @nickdademo,
|
||||
and @jimwang118 -- Thank you so much!
|
||||
|
||||
|
||||
[vcpkg port]: https://github.com/microsoft/vcpkg/tree/master/ports/mimalloc
|
20
contrib/vcpkg/usage
Normal file
20
contrib/vcpkg/usage
Normal file
|
@ -0,0 +1,20 @@
|
|||
Use the following CMake targets to import mimalloc:
|
||||
|
||||
find_package(mimalloc CONFIG REQUIRED)
|
||||
target_link_libraries(main PRIVATE mimalloc)
|
||||
|
||||
And use mimalloc in your sources as:
|
||||
|
||||
#include <mimalloc.h>
|
||||
#include <stdio.h>
|
||||
int main(int argc, char** argv) {
|
||||
int* p = mi_malloc_tp(int);
|
||||
*p = mi_version();
|
||||
printf("mimalloc version: %d\n", *p);
|
||||
mi_free(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
When dynamically overriding on Windows, ensure `mimalloc.dll` is linked through some call to
|
||||
mimalloc (e.g. `mi_version()`), and that the `mimalloc-redirect.dll` is in the same directory.
|
||||
See https://github.com/microsoft/mimalloc/blob/dev/bin/readme.md for detailed information.
|
20
contrib/vcpkg/vcpkg-cmake-wrapper.cmake
Normal file
20
contrib/vcpkg/vcpkg-cmake-wrapper.cmake
Normal file
|
@ -0,0 +1,20 @@
|
|||
_find_package(${ARGS})
|
||||
|
||||
if(CMAKE_CURRENT_LIST_DIR STREQUAL "${MIMALLOC_CMAKE_DIR}/${MIMALLOC_VERSION_DIR}")
|
||||
set(MIMALLOC_INCLUDE_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
|
||||
# As in vcpkg.cmake
|
||||
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$")
|
||||
set(MIMALLOC_LIBRARY_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib")
|
||||
else()
|
||||
set(MIMALLOC_LIBRARY_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib")
|
||||
endif()
|
||||
set(MIMALLOC_OBJECT_DIR "${MIMALLOC_LIBRARY_DIR}")
|
||||
set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}")
|
||||
endif()
|
||||
|
||||
# vcpkg always configures either a static or dynamic library.
|
||||
# ensure to always expose the mimalloc target as either the static or dynamic build.
|
||||
if(TARGET mimalloc-static AND NOT TARGET mimalloc)
|
||||
add_library(mimalloc INTERFACE IMPORTED)
|
||||
set_target_properties(mimalloc PROPERTIES INTERFACE_LINK_LIBRARIES mimalloc-static)
|
||||
endif()
|
36
contrib/vcpkg/vcpkg.json
Normal file
36
contrib/vcpkg/vcpkg.json
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "mimalloc",
|
||||
"version": "1.9.2",
|
||||
"port-version": 2,
|
||||
"description": "Compact general purpose allocator with excellent performance",
|
||||
"homepage": "https://github.com/microsoft/mimalloc",
|
||||
"license": "MIT",
|
||||
"supports": "!uwp",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "vcpkg-cmake",
|
||||
"host": true
|
||||
},
|
||||
{
|
||||
"name": "vcpkg-cmake-config",
|
||||
"host": true
|
||||
}
|
||||
],
|
||||
"features": {
|
||||
"c": {
|
||||
"description": "Use C11 compilation (this can still override new/delete)"
|
||||
},
|
||||
"override": {
|
||||
"description": "Override the standard malloc/free interface"
|
||||
},
|
||||
"secure": {
|
||||
"description": "Use full security mitigations (like guard pages and randomization)"
|
||||
},
|
||||
"xmalloc": {
|
||||
"description": "If out-of-memory, call abort() instead of returning NULL"
|
||||
},
|
||||
"asm": {
|
||||
"description": "Generate assembly files"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -120,49 +120,49 @@
|
|||
<OutDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
<TargetExt>.lib</TargetExt>
|
||||
<TargetName>mimalloc-static</TargetName>
|
||||
<TargetName>mimalloc</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
<TargetExt>.lib</TargetExt>
|
||||
<TargetName>mimalloc-static</TargetName>
|
||||
<TargetName>mimalloc</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
<TargetExt>.lib</TargetExt>
|
||||
<TargetName>mimalloc-static</TargetName>
|
||||
<TargetName>mimalloc</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
|
||||
<OutDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
<TargetExt>.lib</TargetExt>
|
||||
<TargetName>mimalloc-static</TargetName>
|
||||
<TargetName>mimalloc</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64EC'">
|
||||
<OutDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
<TargetExt>.lib</TargetExt>
|
||||
<TargetName>mimalloc-static</TargetName>
|
||||
<TargetName>mimalloc</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
<TargetExt>.lib</TargetExt>
|
||||
<TargetName>mimalloc-static</TargetName>
|
||||
<TargetName>mimalloc</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
|
||||
<OutDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
<TargetExt>.lib</TargetExt>
|
||||
<TargetName>mimalloc-static</TargetName>
|
||||
<TargetName>mimalloc</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64EC'">
|
||||
<OutDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
<TargetExt>.lib</TargetExt>
|
||||
<TargetName>mimalloc-static</TargetName>
|
||||
<TargetName>mimalloc</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
|
|
|
@ -180,6 +180,7 @@
|
|||
</ModuleDefinitionFile>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ImportLibrary>$(OutDir)$(TargetName).dll.lib</ImportLibrary>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect32.dll" "$(OutputPath)"</Command>
|
||||
|
@ -208,6 +209,7 @@
|
|||
</ModuleDefinitionFile>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ImportLibrary>$(OutDir)$(TargetName).dll.lib</ImportLibrary>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect.dll" "$(OutputPath)"</Command>
|
||||
|
@ -236,6 +238,7 @@
|
|||
</ModuleDefinitionFile>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ImportLibrary>$(OutDir)$(TargetName).dll.lib</ImportLibrary>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect-arm64.dll" "$(OutputPath)"</Command>
|
||||
|
@ -264,6 +267,7 @@
|
|||
</ModuleDefinitionFile>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ImportLibrary>$(OutDir)$(TargetName).dll.lib</ImportLibrary>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect-arm64ec.dll" "$(OutputPath)"</Command>
|
||||
|
@ -296,6 +300,7 @@
|
|||
</ModuleDefinitionFile>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ImportLibrary>$(OutDir)$(TargetName).dll.lib</ImportLibrary>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect32.dll" "$(OutputPath)"</Command>
|
||||
|
@ -328,6 +333,7 @@
|
|||
</ModuleDefinitionFile>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ImportLibrary>$(OutDir)$(TargetName).dll.lib</ImportLibrary>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect.dll" "$(OutputPath)"</Command>
|
||||
|
@ -361,6 +367,7 @@
|
|||
</ModuleDefinitionFile>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ImportLibrary>$(OutDir)$(TargetName).dll.lib</ImportLibrary>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect-arm64.dll" "$(OutputPath)"</Command>
|
||||
|
@ -394,6 +401,7 @@
|
|||
</ModuleDefinitionFile>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ImportLibrary>$(OutDir)$(TargetName).dll.lib</ImportLibrary>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect-arm64ec.dll" "$(OutputPath)"</Command>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
libdir=@libdir_for_pc_file@
|
||||
includedir=@includedir_for_pc_file@
|
||||
libdir=@mi_pc_libdir@
|
||||
includedir=@mi_pc_includedir@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: A compact general purpose allocator with excellent performance
|
||||
Version: @PACKAGE_VERSION@
|
||||
URL: https://github.com/microsoft/mimalloc/
|
||||
Libs: -L${libdir} -lmimalloc
|
||||
Libs.private: @pc_libraries@
|
||||
Libs: -L${libdir} -l@mi_libname@
|
||||
Libs.private: @mi_pc_libraries@
|
||||
Cflags: -I${includedir}
|
||||
|
|
|
@ -127,7 +127,7 @@ void _mi_prim_mem_init( mi_os_mem_config_t* config )
|
|||
ULONGLONG memInKiB = 0;
|
||||
if (GetPhysicallyInstalledSystemMemory(&memInKiB)) {
|
||||
if (memInKiB > 0 && memInKiB < (SIZE_MAX / MI_KiB)) {
|
||||
config->physical_memory = memInKiB * MI_KiB;
|
||||
config->physical_memory = (size_t)memInKiB * MI_KiB;
|
||||
}
|
||||
}
|
||||
// get the VirtualAlloc2 function
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
project(mimalloc-test C CXX)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
@ -16,10 +16,12 @@ if (NOT CMAKE_BUILD_TYPE)
|
|||
endif()
|
||||
|
||||
# Import mimalloc (if installed)
|
||||
find_package(mimalloc 2.0 REQUIRED NO_SYSTEM_ENVIRONMENT_PATH)
|
||||
find_package(mimalloc 2.2 CONFIG REQUIRED)
|
||||
message(STATUS "Found mimalloc installed at: ${MIMALLOC_LIBRARY_DIR} (${MIMALLOC_VERSION_DIR})")
|
||||
|
||||
# overriding with a dynamic library
|
||||
|
||||
# link with a dynamic shared library
|
||||
# use `LD_PRELOAD` to actually override malloc/free at runtime with mimalloc
|
||||
add_executable(dynamic-override main-override.c)
|
||||
target_link_libraries(dynamic-override PUBLIC mimalloc)
|
||||
|
||||
|
@ -29,9 +31,9 @@ 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_OBJECT_DIR}/mimalloc.o)
|
||||
add_executable(static-override-obj main-override.c ${MIMALLOC_OBJECT_DIR}/mimalloc${CMAKE_C_OUTPUT_EXTENSION})
|
||||
target_include_directories(static-override-obj PUBLIC ${MIMALLOC_INCLUDE_DIR})
|
||||
target_link_libraries(static-override-obj PUBLIC pthread)
|
||||
target_link_libraries(static-override-obj PUBLIC mimalloc-static)
|
||||
|
||||
|
||||
# overriding with a static library works too if using the `mimalloc-override.h`
|
||||
|
|
|
@ -40,9 +40,9 @@ static void test_thread_local(); // issue #944
|
|||
static void test_mixed1(); // issue #942
|
||||
static void test_stl_allocators();
|
||||
|
||||
#if _WIN32
|
||||
#if x_WIN32
|
||||
#include "main-override-dep.h"
|
||||
static void test_dep(); // issue #981: test overriding in another DLL
|
||||
static void test_dep(); // issue #981: test overriding in another DLL
|
||||
#else
|
||||
static void test_dep() { };
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@ int main() {
|
|||
test_mixed1();
|
||||
|
||||
test_dep();
|
||||
|
||||
|
||||
//test_std_string();
|
||||
//test_thread_local();
|
||||
// heap_thread_free_huge();
|
||||
|
@ -117,8 +117,10 @@ static void various_tests() {
|
|||
t->~Test();
|
||||
delete[] tbuf;
|
||||
|
||||
#if _WIN32
|
||||
const char* ptr = ::_Getdays(); // test _base overrid
|
||||
free((void*)ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
class Static {
|
||||
|
@ -148,7 +150,7 @@ static bool test_stl_allocator1() {
|
|||
struct some_struct { int i; int j; double z; };
|
||||
|
||||
|
||||
#if _WIN32
|
||||
#if x_WIN32
|
||||
static void test_dep()
|
||||
{
|
||||
TestAllocInDll t;
|
||||
|
@ -417,7 +419,7 @@ void large_alloc(void)
|
|||
|
||||
// issue #372
|
||||
static void fail_aslr() {
|
||||
size_t sz = (4ULL << 40); // 4TiB
|
||||
size_t sz = (size_t)(4ULL << 40); // 4TiB
|
||||
void* p = malloc(sz);
|
||||
printf("pointer p: %p: area up to %p\n", p, (uint8_t*)p + sz);
|
||||
*(int*)0x5FFFFFFF000 = 0; // should segfault
|
||||
|
|
Loading…
Add table
Reference in a new issue