On Sat, 15 Nov 2025, Pali Rohár wrote:
OS system msvcrt40.dll and msvcrt.dll libraries since Windows Vista, UCRT library, versioned msvcr80.dll libraries and new have semi-broken _assert() function which do not print anything to stderr in case the stderr FILE* stream was set to translated UTF-8/UTF-16 mode (_O_U8TEXT or _O_U16TEXT or _O_U16TEXT). This is because _assert() function is using fprintf() for writing to stderr and it is limitation of fprintf() function that it does not work on streams configured in one of those modes. Only fwprintf() function can be used on FILE* stream in that mode. Add a workaround for _assert() function. Implement a small mingw-w64 wrapper around the DLL _assert() function and change mode to _O_TEXT before calling _assert(). Import symbol name is renamed to __msvcrt_assert and in def file is defined with DATA keyword which prevent having function with __msvcrt_assert name. mingw-w64 wrapper calls directly function via its import name. ---
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index acb5f5fb2779..08f48e7de858 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -173,6 +173,7 @@ src_msvcrt_common=\ include/mingw-wchar.h \ misc/__mingw_mbrtowc_cp.c \ misc/__mingw_wcrtomb_cp.c \ + misc/_assert.c \ misc/_onexit.c \ misc/mbrlen.c \ misc/mbrtowc.c \ @@ -433,6 +434,7 @@ src_ucrtbase=\ misc/__p__osver_emul.c \ misc/__initenv.c \ misc/__winitenv.c \ + misc/_assert.c \ misc/_onexit.c \ misc/output_format.c \ misc/ucrt-access.c \
When this function is inserted in every crt library, can't we just add it to libmingwex.a, which reduces the amount of extra copies of it that we end up compiling? Or is there anything CRT specific in it?
Other than that, this looks ok - complicated, but probably relevant, since it's important to get assert messages visible despite such stdio modes.
It's nice that you managed to make a testcase for this! // Martin _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
