I'm confused why it show `exit` in the backtrace, this code is executed before main, if I continue execution I will hit `_errno` in `main`. ________________________________ From: Pali Rohár <[email protected]> Sent: Friday, November 14, 2025 3:52 AM To: Kirill Makurin <[email protected]> Cc: LIU Hao <[email protected]>; [email protected] <[email protected]> Subject: Re: [Mingw-w64-public] errno is set to EINVAL when entering main
But this _errno is called from exit function. Does not seem to be from the main() usage. On Thursday 13 November 2025 12:19:02 Kirill Makurin wrote: > I see a hit for `_errno` from _setmbcp[1]: > > ``` > (gdb) b _errno > Breakpoint 1 at 0x140002620 > (gdb) r > Starting program: I:\crt-tests\init.exe > [New Thread 17720.0x3b9c] > [New Thread 17720.0x48c8] > > Thread 1 hit Breakpoint 1.1, 0x00007ffbbc7d7454 in _errno () from > C:\WINDOWS\SYSTEM32\msvcr110.dll > (gdb) bt > #0 0x00007ffbbc7d7454 in _errno () from C:\WINDOWS\SYSTEM32\msvcr110.dll > #1 0x00007ffbbc7f3825 in _setmbcp () from C:\WINDOWS\SYSTEM32\msvcr110.dll > #2 0x00007ffbbc7f34f2 in _ismbcl2_l () from C:\WINDOWS\SYSTEM32\msvcr110.dll > #3 0x00007ffbbc7d31a2 in exit () from C:\WINDOWS\SYSTEM32\msvcr110.dll > #4 0x00007ffbea39f96e in ntdll!RtlEncodeRemotePointer () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #5 0x00007ffbea24bcae in ntdll!RtlRaiseException () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #6 0x00007ffbea2497ac in ntdll!RtlDeleteElementGenericTableAvlEx () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #7 0x00007ffbea2d76ea in ntdll!LdrGetProcedureAddressForCaller () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #8 0x00007ffbea2d7716 in ntdll!LdrGetProcedureAddressForCaller () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #9 0x00007ffbea2fd8c6 in ntdll!EtwEventWriteNoRegistration () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #10 0x00007ffbea2fba50 in ntdll!EtwEventWriteNoRegistration () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #11 0x00007ffbea2fb83a in ntdll!EtwEventWriteNoRegistration () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #12 0x00007ffbea32910e in ntdll!LdrInitializeThunk () from > C:\WINDOWS\SYSTEM32\ntdll.dll > #13 0x0000000000000000 in ?? () > ``` > > I think I see what's going on. I have UTF-8 enabled globally on my system and > it seems that CRT attempts to set multibyte code page (with _setmbcp) to > active ANSI code page (GetACP() == CP_UTF8, in my case), and since > msvcr110.dll does not support UTF-8, its _setmbcp fails with EINVAL. (What's > interesting is that it does not happen with msvcrt.dll.) > > If I set a breakpoint for GetACP it will be hit in the same place. > > - Kirill Makurin > > [1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmbcp > > ________________________________ > From: LIU Hao > Sent: Thursday, November 13, 2025 8:56 PM > To: [email protected]; Kirill Makurin > Cc: Pali Rohár > Subject: Re: [Mingw-w64-public] errno is set to EINVAL when entering main > > 在 2025-11-13 14:52, Kirill Makurin 写道: > > I wanted to quickly test whether library I'm working on builds and works > > with msvcr*.dll, and when I was running the tests, I noticed that all tests > > for C89/C95/uchar.h conversion functions failed. After small investigation > > I realized that errno was to EINVAL upon entry to `main`. > > > > Can anyone look into this? > > This doesn't reproduce the issue for me. You may try starting the program > using GDB, with breakpoints on > `_errno` and `_set_errno`. > > > -- > Best regards, > LIU Hao _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
