Skip to content

Commit 3d65c60

Browse files
committed
fix(mem): define MI_MINGW_UCRT64 for MinGW mimalloc builds
mimalloc 3.5.3 treats a MinGW build as having a process-attach hook only when MI_MINGW_UCRT64 is defined (src/prim/windows/prim.c). Upstream's CMake sets it; Makefile.cbm did not. src/prim/prim.c therefore also compiled its constructor, and _mi_auto_process_init ran twice on Windows: once from that constructor and once from the CRT TLS callback. The second run flushes the delayed-output buffer to stderr again, and the first flush had left a newline in it, so every Windows run started with a blank line on stderr. That is what failed smoke-win's one-line --version check. In the MI_DEBUG=2 test build the same second run reaches mi_assert_internal(mi_out_default == NULL) in options.c, which aborts. 3.3.2 had no such condition. Define it for IS_MINGW builds in both the production and the test mimalloc flags. Every MinGW toolchain this repository builds with (MSYS2 CLANG64 and CLANGARM64) is UCRT. No vendored source changes. Signed-off-by: Martin Vogel <[email protected]>
1 parent 7e55bc1 commit 3d65c60

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎Makefile.cbm‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,18 @@ ifneq ($(filter yes,$(IS_MINGW) $(IS_LINUX)),)
646646
MIMALLOC_OVERRIDE_DEFINE := -DMI_MALLOC_OVERRIDE=1
647647
GLOBAL_OVERRIDE_DEFINE := -DCBM_MEM_GLOBAL_OVERRIDE=1
648648
endif
649+
# MI_MINGW_UCRT64: since 3.5.3, mimalloc treats a MinGW build as having a
650+
# process-attach hook only when this is defined (src/prim/windows/prim.c);
651+
# upstream's CMake sets it, this Makefile must too. Without it src/prim/prim.c
652+
# also compiles its constructor, so _mi_auto_process_init runs twice (that
653+
# constructor plus the CRT TLS callback) and the second options flush writes a
654+
# stray newline to stderr before main: a blank first line on every run, which
655+
# failed smoke-win's one-line --version check. Every MinGW toolchain we build
656+
# with (MSYS2 CLANG64/CLANGARM64) is UCRT. 3.3.2 had no such condition.
657+
MIMALLOC_WIN_DEFINE :=
658+
ifeq ($(IS_MINGW),yes)
659+
MIMALLOC_WIN_DEFINE := -DMI_MINGW_UCRT64=1
660+
endif
649661
# MI_DEBUG=0: the production allocator is mimalloc's RELEASE build. Its header
650662
# defaults to MI_DEBUG=2 unless NDEBUG is defined, and nothing here defined it,
651663
# so every shipped binary up to v0.11.0 ran mimalloc's debug build: internal
@@ -663,11 +675,11 @@ MIMALLOC_CFLAGS = -std=c11 -O2 -w \
663675
-Ivendored/mimalloc/include \
664676
-Ivendored/mimalloc/src \
665677
-DMI_OVERRIDE=1 -DMI_DEBUG=0 -DMI_PROFILE=0 \
666-
$(MIMALLOC_OVERRIDE_DEFINE)
678+
$(MIMALLOC_OVERRIDE_DEFINE) $(MIMALLOC_WIN_DEFINE)
667679
MIMALLOC_CFLAGS_TEST = -std=c11 -g -O1 -w \
668680
-Ivendored/mimalloc/include \
669681
-Ivendored/mimalloc/src \
670-
-DMI_OVERRIDE=0
682+
-DMI_OVERRIDE=0 $(MIMALLOC_WIN_DEFINE)
671683

672684
# sqlite3 (vendored amalgamation — compiled ourselves for ASan instrumentation)
673685
# SQLITE_ENABLE_FTS5: enables the FTS5 full-text search extension used by the

0 commit comments

Comments
 (0)