On Wed, 19 Nov 2025, Pali Rohár wrote:

On Wednesday 19 November 2025 15:59:05 Martin Storsjö wrote:
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?

There is nothing CRT specific. I was just thinking that this change is
not required for crtdll and msvcrt20 which do not support those
translated UTF-8/UTF-16 mode, and can use the native _assert symbol.
But that would complicate build process, so I put this wrapper for all
CRT libraries. And I forgot that I could move it into libmingwex.a.

So when you are applying this change, feel free to move the _assert.c in
mingwex section in Makefile.am file.

Ok, pushed this now.

// Martin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to