From b51c0974d357cda597ab3a242f5723ab516f5503 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Thu, 19 Dec 2024 14:00:54 -0800 Subject: [PATCH 1/7] fix cmake for visual studio on arm64 --- CMakeLists.txt | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8896dfd7..e371a33d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,11 @@ if (NOT CMAKE_BUILD_TYPE) endif() endif() +if (CMAKE_GENERATOR MATCHES "^Visual Studio.*$") + message(STATUS "Note: when building with Visual Studio the build type is specified when building.") + message(STATUS "For example: 'cmake --build . --config=Release") +endif() + if("${CMAKE_BINARY_DIR}" MATCHES ".*(S|s)ecure$") message(STATUS "Default to secure build") set(MI_SECURE "ON") @@ -326,11 +331,11 @@ set(MI_OPT_ARCH_FLAGS "") set(MI_ARCH "unknown") if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86|i[3456]86)$" OR CMAKE_GENERATOR_PLATFORM MATCHES "^(x86|Win32)$") set(MI_ARCH "x86") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "x64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "x64") # must be before arm64 set(MI_ARCH "x64") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv8.?)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv8.?|ARM64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") set(MI_ARCH "arm64") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567])$") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567]|ARM)$") set(MI_ARCH "arm32") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv|riscv32|riscv64)$") if(CMAKE_SIZEOF_VOID_P==4) @@ -341,7 +346,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv|riscv32|riscv64)$") else() set(MI_ARCH ${CMAKE_SYSTEM_PROCESSOR}) endif() -message(STATUS "Architecture: ${MI_ARCH}") +message(STATUS "Architecture: ${MI_ARCH}") # (${CMAKE_SYSTEM_PROCESSOR}, ${CMAKE_GENERATOR_PLATFORM}, ${CMAKE_GENERATOR})") # Check /proc/cpuinfo for an SV39 MMU and limit the virtual address bits. # (this will skip the aligned hinting in that case. Issue #939, #949) @@ -533,8 +538,14 @@ if(MI_BUILD_SHARED) ) if(WIN32 AND MI_WIN_REDIRECT) # On windows, link and copy the mimalloc redirection dll too. - if(MI_ARCH STREQUAL "x64") + if(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64ec") + set(MIMALLOC_REDIRECT_SUFFIX "-arm64ec") + 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.") + endif() elseif(MI_ARCH STREQUAL "x86") set(MIMALLOC_REDIRECT_SUFFIX "32") else() From 3a9c402e5107984324bfea6424370aac37c97a88 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Thu, 19 Dec 2024 14:18:16 -0800 Subject: [PATCH 2/7] update readme for cmake on windows --- readme.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index a0296b43..7fa5eb54 100644 --- a/readme.md +++ b/readme.md @@ -164,7 +164,7 @@ The `mimalloc` project builds a static library (in `out/msvc-x64`), while the `mimalloc-override` project builds a DLL for overriding malloc in the entire program. -## macOS, Linux, BSD, etc. +## Linux, macOS, BSD, etc. We use [`cmake`](https://cmake.org)1 as the build system: @@ -200,13 +200,25 @@ free lists, etc., as: > make ``` This will name the shared library as `libmimalloc-secure.so`. -Use `ccmake`2 instead of `cmake` -to see and customize all the available build options. +Use `cmake ../.. -LH` to see all the available build options. -Notes: -1. Install CMake: `sudo apt-get install cmake` -2. Install CCMake: `sudo apt-get install cmake-curses-gui` +The examples use the default compiler. If you like to use another, use: +``` +> CC=clang CXX=clang++ cmake ../.. +``` +## Cmake with Visual Studio + +You can also use cmake on Windows. Open a Visual Studio development prompt +and invoke `cmake` with the right generator and architecture, like: +``` +> cmake ..\.. -G "Visual Studio 17 2022" -A x64 -DMI_OVERRIDE=ON +``` + +The cmake build type is specified when actually building, for example: +``` +> cmake --build . --config=Release +``` ## Single source From 7456d22fe36b21a025b2be33ab043256a9e6a3e3 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Thu, 19 Dec 2024 14:22:10 -0800 Subject: [PATCH 3/7] add link for VS generator --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7fa5eb54..564ac6d7 100644 --- a/readme.md +++ b/readme.md @@ -210,7 +210,8 @@ The examples use the default compiler. If you like to use another, use: ## Cmake with Visual Studio You can also use cmake on Windows. Open a Visual Studio development prompt -and invoke `cmake` with the right generator and architecture, like: +and invoke `cmake` with the right [generator](https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2017%202022.html) +and architecture, like: ``` > cmake ..\.. -G "Visual Studio 17 2022" -A x64 -DMI_OVERRIDE=ON ``` From f8a253e6e8e0f3a811745d7a9449cd73e49509f2 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 20 Dec 2024 12:51:13 -0800 Subject: [PATCH 4/7] update IDE settings to match cmake output; in particular mimalloc-override.dll -> mimalloc.dll --- ide/vs2022/mimalloc-override-test.vcxproj | 2 +- ide/vs2022/mimalloc-override.vcxproj | 18 +++++++++--------- ide/vs2022/mimalloc-test.vcxproj | 2 +- ide/vs2022/mimalloc.vcxproj | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ide/vs2022/mimalloc-override-test.vcxproj b/ide/vs2022/mimalloc-override-test.vcxproj index 97803b9c..0e87cf36 100644 --- a/ide/vs2022/mimalloc-override-test.vcxproj +++ b/ide/vs2022/mimalloc-override-test.vcxproj @@ -39,7 +39,7 @@ {FEF7868F-750E-4C21-A04D-22707CC66879} mimalloc-override-test 10.0 - mimalloc-override-test + mimalloc-test-override diff --git a/ide/vs2022/mimalloc-override.vcxproj b/ide/vs2022/mimalloc-override.vcxproj index 9de18895..1278cd0f 100644 --- a/ide/vs2022/mimalloc-override.vcxproj +++ b/ide/vs2022/mimalloc-override.vcxproj @@ -39,7 +39,7 @@ {ABB5EAE7-B3E6-432E-B636-333449892EA7} mimalloc-override 10.0 - mimalloc-override + mimalloc-override-dll @@ -116,49 +116,49 @@ $(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\ $(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ .dll - mimalloc-override + mimalloc $(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\ $(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ .dll - mimalloc-override + mimalloc $(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\ $(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ .dll - mimalloc-override + mimalloc $(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\ $(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ .dll - mimalloc-override + mimalloc $(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\ $(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ .dll - mimalloc-override + mimalloc $(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\ $(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ .dll - mimalloc-override + mimalloc $(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\ $(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ .dll - mimalloc-override + mimalloc $(SolutionDir)..\..\out\msvc-$(Platform)\$(Configuration)\ $(SolutionDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ .dll - mimalloc-override + mimalloc diff --git a/ide/vs2022/mimalloc-test.vcxproj b/ide/vs2022/mimalloc-test.vcxproj index fc9e9102..a8b36d5e 100644 --- a/ide/vs2022/mimalloc-test.vcxproj +++ b/ide/vs2022/mimalloc-test.vcxproj @@ -39,7 +39,7 @@ {FEF7858F-750E-4C21-A04D-22707CC66878} mimalloctest 10.0 - mimalloc-test + mimalloc-test-static diff --git a/ide/vs2022/mimalloc.vcxproj b/ide/vs2022/mimalloc.vcxproj index 34a9317a..9964310d 100644 --- a/ide/vs2022/mimalloc.vcxproj +++ b/ide/vs2022/mimalloc.vcxproj @@ -39,7 +39,7 @@ {ABB5EAE7-B3E6-432E-B636-333449892EA6} mimalloc 10.0 - mimalloc + mimalloc-lib From 4b7313914ee702f1abe16d9021f5ac4867894cf4 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 20 Dec 2024 12:52:00 -0800 Subject: [PATCH 5/7] add updated minject v1.2 that defaults to mimalloc.dll instead of mimalloc-override.dll --- bin/minject-arm64.exe | Bin 20992 -> 20992 bytes bin/minject.exe | Bin 22016 -> 22016 bytes bin/minject32.exe | Bin 18944 -> 18944 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/bin/minject-arm64.exe b/bin/minject-arm64.exe index 97188c4f14e644b66d938ce44a940f3058153a13..637c95d91576043ff83cf2f0ceb5a5555c544764 100644 GIT binary patch delta 1656 zcmY*ZZERCz6h7zPwrjU_9qqc+t)m}Hwh(CnD57uBdb|nEqU?Uo;B+3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FPY31b73D#kmP| z=Mhqmv941PuAwnQ%tS&K=cACrPz`(&jq!cJRD2<{fj0sx6`A1 zqP+weUykynw+Ax2{Mbb{6*9wJ1tfq}&+oKUv~iu0bHn+#w%zXCFYPAf$OR=b&n>vi S-3#26?pimT4scroBK`r<)^nr) diff --git a/bin/minject32.exe b/bin/minject32.exe index 926facfda8018cf58df19310837661b76dac67c9..6dcb8da9ccb189f0e31daf31b06aa9449c840f9d 100644 GIT binary patch delta 3508 zcmd^CeN>cH9=;bCKIFs6ForJyVGvE|eP5Yr240E3wzk2Z5e zOqy81>-KTNv-we*=d>F&m1esx9av~vw^N&^W7&sGtG$JrX6Vvp%|3U~6aBe=@8vwd z=Xamq?|#1b-Z}UVP~QRCV+td*ci|$r&hLvL0pHLy46-3WY3=Y)N%VJTs`bT2CjTS5B+ zyTK9XK$O|i4+d#pQFPoEA9#U2bxqsfH$%f>r~;<`;Ix+4w} z6kB(B#2TA&F|ae?M;h<8TM6kZoAAW=%$~rb>OGV`#1dwt(F}Iy3@vSAD`zZ((lcXU z!b3cD`tBa|;WM`d@^Ak#oJwqF((L8Qn05E^=&of~#+LXN=1S0w|$cY+OxmjnDF6wp4NAa+?lG3o~&ytLH zD4VRLyZg#d!JyLcO)%Iol-YUCZDRQv(=^{7xs18>v2INUyQWHI?`U>;yDtTU{$&&X z4{XZSfAba*3kEiBxX*v#{z3V`5-U;Gj|GGBS?;ZZS0h)H!z~ZFIovhzxKasEf_J*6 zfhwQH5uz+mVH=h3c(_?`{a2JZ@Ed5CpnS+zJ`}fM_kf%IH92OjHXp6;jX>sg7@P7u z+OJ*PIpA5TT;{43?K=nDvGR#|NZiGvN+dJ|=YuHcc*@C8!`DKg5%}m@rPx`1O2PD< zTpVmjl!cXOt!51=TB>F}DT!)zot4PdB`_5*%4POyiZ*62mJdFnQnS&NTHStLQ)*!S z6G|&5L3seQrY0yTqZ53?;;=LoCW0Zi?mp*HDXUm>YHsQm(|A9FeuttAPfkek?fjA; zp2Yf7b7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A4d$_1>j~MbUSqZYSO4_x zCux~6B4igUEx*>{sIulL^WbJIqPvZ^;ZOD_jS<|QtoC^Av)i^l`{K_kzphvJ)r>u# zl|0ildwYe{wqx{p@Atf}RR`yP+(BGzS!LXzz!e_NTa))B4=0~b{#SCeMx&85^_uOP zcFi8mS4T6WqUX&cfOq%Tj; zPp?UTwmIFE9;^@7|4uLHv-P*@*Xy_HAJ&iP&*{I@|ERyAKbSF=kz*(@lo-qgo1xa= zF#O)I&(Lf5qd_)YFYQjbO}^=TsSE73(pI$2yX}{g}(~t zgfE0k!uP^e!7ccT;bNkw6SKrZu~@uEEEgrQMzo7fqEp-{c8Pn$N5v<^!{XE8QSlY= zb@46nZSj5atoV2Fg7}SiS^Pn~A=WN+u(y>F-$VQl?V+52$X@*ceZQV$gk?Z4#0MGF PDzpoSQHSe=oILK|rd?g| From 4ed44f96210c71f6d1945ae950387bc262a75f20 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 20 Dec 2024 12:52:34 -0800 Subject: [PATCH 6/7] update readme to use mimalloc.dll (instead of mimalloc-override.dll) --- bin/readme.md | 38 ++++++++++++++++++------------------ readme.md | 53 ++++++++++++++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/bin/readme.md b/bin/readme.md index d6c3775f..bc115ce1 100644 --- a/bin/readme.md +++ b/bin/readme.md @@ -9,20 +9,20 @@ There are four requirements to make the overriding work well: 1. Use the C-runtime library as a DLL (using the `/MD` or `/MDd` switch). -2. Link your program explicitly with the `mimalloc-override.lib` export library for - the `mimalloc-override.dll` -- which contains all mimalloc functionality. - To ensure the `mimalloc-override.dll` is actually loaded at run-time it is easiest +2. Link your program explicitly with the `mimalloc.lib` export library for + the `mimalloc.dll` -- which contains all mimalloc functionality. + To ensure the `mimalloc.dll` is actually loaded at run-time it is easiest to insert some call to the mimalloc API in the `main` function, like `mi_version()` (or use the `/include:mi_version` switch on the linker, or - use `#pragma comment(linker, "/include:mi_version")` in some source file). - See the `mimalloc-override-test` project for an example on how to use this. + similarly, `#pragma comment(linker, "/include:mi_version")` in some source file). + See the `mimalloc-test-override` project for an example on how to use this. 3. The `mimalloc-redirect.dll` must be put in the same folder as the main - `mimalloc-override.dll` at runtime (as it is a dependency of that DLL). + `mimalloc.dll` at runtime (as it is a dependency of that DLL). The redirection DLL ensures that all calls to the C runtime malloc API get - redirected to mimalloc functions (which reside in `mimalloc-override.dll`). + redirected to mimalloc functions (which reside in `mimalloc.dll`). -4. Ensure the `mimalloc-override.dll` comes as early as possible in the import +4. Ensure the `mimalloc.dll` comes as early as possible in the import list of the final executable (so it can intercept all potential allocations). You can use `minject -l ` to check this if needed. @@ -37,8 +37,8 @@ redirected. ### Other Platforms -You always link with `mimalloc-override.dll` but for different platforms you may -need a specific `mimalloc-redirect.dll`: +You always link with `mimalloc.dll` but for different platforms you may +need a specific redirection DLL: - __x64__: `mimalloc-redirect.dll`. - __x86__: `mimalloc-redirect32.dll`. Use for older 32-bit Windows programs. @@ -47,12 +47,12 @@ need a specific `mimalloc-redirect.dll`: mode on Windows arm64. Unfortunately we cannot run x64 code emulated on Windows arm64 with the x64 mimalloc override directly (since the C runtime always uses `arm64ec`). Instead: 1. Build the program as normal for x64 and link as normal with the x64 - `mimalloc-override.lib` export library. - 2. Now separately build `mimalloc-override.dll` in `arm64ec` mode and _overwrite_ your - previous (x64) `mimalloc-override.dll` -- the loader can handle the mix of arm64ec + `mimalloc.lib` export library. + 2. Now separately build `mimalloc.dll` in `arm64ec` mode and _overwrite_ your + previous (x64) `mimalloc.dll` -- the loader can handle the mix of arm64ec and x64 code. Now use `mimalloc-redirect-arm64ec.dll` to match your new - arm64ec `mimalloc-override.dll`. The main program stays as is and can be fully x64 - or contain more arm64ec modules. At runtime, the arm64ec `mimalloc-override.dll` will + arm64ec `mimalloc.dll`. The main program stays as is and can be fully x64 + or contain more arm64ec modules. At runtime, the arm64ec `mimalloc.dll` will run with native arm64 instructions while the rest of the program runs emulated x64. [arm64ec]: https://learn.microsoft.com/en-us/windows/arm/arm64ec @@ -60,11 +60,11 @@ need a specific `mimalloc-redirect.dll`: ### Minject -We cannot always re-link an executable with `mimalloc-override.dll`, and similarly, we +We cannot always re-link an executable with `mimalloc.dll`, and similarly, we cannot always ensure that the DLL comes first in the import table of the final executable. In many cases though we can patch existing executables without any recompilation if they are linked with the dynamic C runtime (`ucrtbase.dll`) -- just put the -`mimalloc-override.dll` into the import table (and put `mimalloc-redirect.dll` in the same +`mimalloc.dll` into the import table (and put `mimalloc-redirect.dll` in the same directory) Such patching can be done for example with [CFF Explorer](https://ntcore.com/?page_id=388). The `minject` program can also do this from the command line @@ -86,8 +86,8 @@ options: -l --list only list imported modules -i --inplace update the exe in-place (make sure there is a backup!) -f --force always overwrite without prompting - --postfix=

use

as a postfix to the mimalloc dll (default is 'override') - e.g. use --postfix=override-debug to link with mimalloc-override-debug.dll + --postfix=

use

as a postfix to the mimalloc dll. + e.g. use --postfix=debug to link with mimalloc-debug.dll notes: Without '--inplace' an injected is generated with the same name ending in '-mi'. diff --git a/readme.md b/readme.md index 564ac6d7..11f62da4 100644 --- a/readme.md +++ b/readme.md @@ -428,43 +428,48 @@ Note that certain security restrictions may apply when doing this from the [shell](https://stackoverflow.com/questions/43941322/dyld-insert-libraries-ignored-when-calling-application-through-bash). -### Dynamic Override on Windows +# Windows Override Dynamically overriding on mimalloc on Windows -is robust and has the particular advantage to be able to redirect all malloc/free calls that go through -the (dynamic) C runtime allocator, including those from other DLL's or libraries. -As it intercepts all allocation calls on a low level, it can be used reliably +is robust and has the particular advantage to be able to redirect all malloc/free calls +that go through the (dynamic) C runtime allocator, including those from other DLL's or +libraries. As it intercepts all allocation calls on a low level, it can be used reliably on large programs that include other 3rd party components. -There are four requirements to make the overriding work robustly: +There are four requirements to make the overriding work well: 1. Use the C-runtime library as a DLL (using the `/MD` or `/MDd` switch). -2. Link your program explicitly with `mimalloc-override.dll` library. - To ensure the `mimalloc-override.dll` is loaded at run-time it is easiest to insert some - call to the mimalloc API in the `main` function, like `mi_version()` - (or use the `/INCLUDE:mi_version` switch on the linker). See the `mimalloc-override-test` project - for an example on how to use this. -3. The [`mimalloc-redirect.dll`](bin) (or `mimalloc-redirect32.dll`) must be put - in the same folder as the main `mimalloc-override.dll` at runtime (as it is a dependency of that DLL). - The redirection DLL ensures that all calls to the C runtime malloc API get redirected to - mimalloc functions (which reside in `mimalloc-override.dll`). -4. Ensure the `mimalloc-override.dll` comes as early as possible in the import + +2. Link your program explicitly with the `mimalloc.lib` export library for the `mimalloc.dll`. + (which must be compiled with `-DMI_OVERRIDE=ON`, which is the default though). + To ensure the `mimalloc.dll` is actually loaded at run-time it is easiest + to insert some call to the mimalloc API in the `main` function, like `mi_version()` + (or use the `/include:mi_version` switch on the linker command, or + similarly, `#pragma comment(linker, "/include:mi_version")` in some source file). + See the `mimalloc-test-override` project for an example on how to use this. + +3. The `mimalloc-redirect.dll` must be put in the same folder as the main + `mimalloc.dll` at runtime (as it is a dependency of that DLL). + The redirection DLL ensures that all calls to the C runtime malloc API get + redirected to mimalloc functions (which reside in `mimalloc.dll`). + +4. Ensure the `mimalloc.dll` comes as early as possible in the import list of the final executable (so it can intercept all potential allocations). + You can use `minject -l ` to check this if needed. For best performance on Windows with C++, it is also recommended to also override the `new`/`delete` operations (by including -[`mimalloc-new-delete.h`](include/mimalloc-new-delete.h) +[`mimalloc-new-delete.h`](../include/mimalloc-new-delete.h) a single(!) source file in your project). The environment variable `MIMALLOC_DISABLE_REDIRECT=1` can be used to disable dynamic -overriding at run-time. Use `MIMALLOC_VERBOSE=1` to check if mimalloc was successfully redirected. +overriding at run-time. Use `MIMALLOC_VERBOSE=1` to check if mimalloc was successfully +redirected. + +For different platforms than x64, you may need a specific [redirection dll](bin). +Furthermore, we cannot always re-link an executable or ensure `mimalloc.dll` comes +first in the import table. In such cases the [`minject`](bin) tool can be used +to patch the executable's import tables. -We cannot always re-link an executable with `mimalloc-override.dll`, and similarly, we cannot always -ensure the the DLL comes first in the import table of the final executable. -In many cases though we can patch existing executables without any recompilation -if they are linked with the dynamic C runtime (`ucrtbase.dll`) -- just put the `mimalloc-override.dll` -into the import table (and put `mimalloc-redirect.dll` in the same folder) -Such patching can be done for example with [CFF Explorer](https://ntcore.com/?page_id=388) or -the [`minject`](bin) program. ## Static override From 26eaa1f4e2804fc7dd3cc3997a481c55d484b4f1 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 20 Dec 2024 12:52:58 -0800 Subject: [PATCH 7/7] fix cmake to generate mimalloc.dll on windows --- CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e371a33d..e84283fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -667,12 +667,7 @@ endif() # ----------------------------------------------------------------------------- if (MI_OVERRIDE) if (MI_BUILD_SHARED) - target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE) - if (WIN32) - # on windows we should generate mimalloc-override.dll. - string(REPLACE "mimalloc" "mimalloc-override" mi_override_output_name ${mi_basename}) - set_target_properties(mimalloc PROPERTIES OUTPUT_NAME ${mi_override_output_name}) - endif() + target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE) endif() if(NOT WIN32) # It is only possible to override malloc on Windows when building as a DLL.