Skip to content

Commit d8dd297

Browse files
committed
add cmake option MI_WIN_REDIRECT to be able to explicitly disable linking with mimalloc-redirect on windows; always OFF on ARM, fixes issue microsoft#591 and microsoft#590
1 parent c466346 commit d8dd297

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CMakeLists.txt

+16-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ option(MI_USE_CXX "Use the C++ compiler to compile the library (instea
1515
option(MI_SEE_ASM "Generate assembly files" OFF)
1616
option(MI_OSX_INTERPOSE "Use interpose to override standard malloc on macOS" ON)
1717
option(MI_OSX_ZONE "Use malloc zone to override standard malloc on macOS" ON)
18+
option(MI_WIN_REDIRECT "Use redirection module ('mimalloc-redirect') on Windows if compiling mimalloc as a DLL" ON)
1819
option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" OFF)
1920
option(MI_BUILD_SHARED "Build shared library" ON)
2021
option(MI_BUILD_STATIC "Build static library" ON)
@@ -105,6 +106,19 @@ if(MI_OVERRIDE)
105106
endif()
106107
endif()
107108

109+
if(WIN32)
110+
if (MI_WIN_REDIRECT)
111+
if (MSVC_C_ARCHITECTURE_ID MATCHES "ARM")
112+
message(STATUS "Cannot use redirection on Windows ARM (MI_WIN_REDIRECT=OFF)")
113+
set(MI_WIN_REDIRECT OFF)
114+
endif()
115+
endif()
116+
if (NOT MI_WIN_REDIRECT)
117+
# use a negative define for backward compatibility
118+
list(APPEND mi_defines MI_WIN_NOREDIRECT=1)
119+
endif()
120+
endif()
121+
108122
if(MI_SECURE)
109123
message(STATUS "Set full secure build (MI_SECURE=ON)")
110124
list(APPEND mi_defines MI_SECURE=4)
@@ -323,8 +337,8 @@ if(MI_BUILD_SHARED)
323337
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
324338
$<INSTALL_INTERFACE:${mi_install_incdir}>
325339
)
326-
if(WIN32)
327-
# On windows copy the mimalloc redirection dll too.
340+
if(WIN32 AND MI_WIN_REDIRECT)
341+
# On windows, link and copy the mimalloc redirection dll too.
328342
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
329343
set(MIMALLOC_REDIRECT_SUFFIX "32")
330344
else()

src/init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ mi_decl_nodiscard bool mi_is_redirected(void) mi_attr_noexcept {
463463
}
464464

465465
// Communicate with the redirection module on Windows
466-
#if defined(_WIN32) && defined(MI_SHARED_LIB)
466+
#if defined(_WIN32) && defined(MI_SHARED_LIB) && !defined(MI_WIN_NOREDIRECT)
467467
#ifdef __cplusplus
468468
extern "C" {
469469
#endif

0 commit comments

Comments
 (0)