[Mingw-w64-public] [PATCH 6/6] crt: Fix executing of functions in __xi_a[] ... __xi_z[] array

2024-11-27 Thread Pali Rohár
Use _initterm_e() for executing functions in __xi_a[] ... __xi_z[] array. This function properly stops execution on error and returns error value. Same logic is doing Visual C++ startup code. This fixes error handling of function callbacks defined in that array. --- mingw-w64-crt/crt/crtdll.c | 3

[Mingw-w64-public] [PATCH 1/2] crt: Call __mingw_init_ehandler() after _pei386_runtime_relocator() also for DLL builds

2024-11-27 Thread Pali Rohár
For EXE builds __mingw_init_ehandler() function is called after the _pei386_runtime_relocator() from the __tmainCRTStartup() (and not from the WinMainCRTStartup() function). Do same for DLL builds and call __mingw_init_ehandler() from __DllMainCRTStartup() instead of DllMainCRTStartup(). --- ming

[Mingw-w64-public] [PATCH] crt: Replace wprintf() by __ms_wprintf() call and use %ls for wchar_t* types

2024-11-27 Thread Pali Rohár
This ensures that mingwex wprintf implementation will not be used and statically linked when not needed. And also make it more predictable as %ls format is always using wide string. --- mingw-w64-crt/crt/crtexe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mingw-w64-crt

[Mingw-w64-public] [PATCH] crt: Avoid calling memset in crt_handler.c

2024-11-27 Thread Pali Rohár
Explicitly initialize variable to zeros, which has same effect as initialzing it via memset. --- mingw-w64-crt/crt/crt_handler.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mingw-w64-crt/crt/crt_handler.c b/mingw-w64-crt/crt/crt_handler.c index c49a2b3b573d..0a08880

[Mingw-w64-public] [PATCH] crt: Localize usage of startinfo variable

2024-11-27 Thread Pali Rohár
Variable startinfo is used only by __(w)getmainargs() call passed by the pointer in pre_cpp_init() function. The __(w)getmainargs() function does not use or store the pointer value, so the variable does not have to be static. Declare this variable just on the pre_cpp_init() function stack. --- min

[Mingw-w64-public] [PATCH 5/6] crt: Fix definition of __xi_a[] and __xi_z[] arrays

2024-11-27 Thread Pali Rohár
They are of _PIFV types, not of _PVFV. --- mingw-w64-crt/crt/cinitexe.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mingw-w64-crt/crt/cinitexe.c b/mingw-w64-crt/crt/cinitexe.c index ee441ed77f90..9e6931c4fc4b 100644 --- a/mingw-w64-crt/crt/cinitexe.c +++ b/mingw-w64-

[Mingw-w64-public] [PATCH 2/6] crt: Check for return value from __(w)getmainargs() calls

2024-11-27 Thread Pali Rohár
Functions __getmainargs() and __wgetmainargs() in system msvcrt.dll library since Windows XP and in Visual C++ libraries since msvcr70.dll return negative value on error and expect that caller handle it and terminate process. Visual C++ 2002+ startup code calls _amsg_exit(_RT_SPACEARG) on failure.

[Mingw-w64-public] [PATCH 4/6] crt: Add mingw-w64 emulation of _initterm_e function into pre-msvcr80 import libraries

2024-11-27 Thread Pali Rohár
Function _initterm_e() is available since msvcr80.dll. Add emulation of this function into all pre-msvcr80 import libraries for compatibility. --- mingw-w64-crt/Makefile.am | 3 +++ mingw-w64-crt/lib-common/msvcrt.def.in | 2 +- mingw-w64-crt/misc/_initterm_e.c | 25 ++

[Mingw-w64-public] [PATCH 1/6] crt: Fix __getmainargs() and __wgetmainargs() ABI for msvcrt40.dll and msvcrt.dll

2024-11-27 Thread Pali Rohár
Visual C++ CRT DLL libraries older than VC70 / msvcr70.dll have different ABI of __getmainargs() and __wgetmainargs() functions. Their return value is void, instead of int. This includes VC++ libs crtdll.dll, msvcrt10.dll, msvcrt20.dll, msvcrt40.dll, msvcr40d.dll, msvcrt.dll and msvcrtd.dll. Same

[Mingw-w64-public] [PATCH 3/6] crt: Process return value from _(w)setargv()

2024-11-27 Thread Pali Rohár
Function _(w)setargv() provided by the application itself (not by the CRT DLL runtime library) can fail, which is indicated by the return value. Check for this failure and call _amsg_exit(_RT_SPACEARG) on error. Same behavior has Visual C++ startup code. --- mingw-w64-crt/crt/crtexe.c | 7 +--

[Mingw-w64-public] [PATCH 0/6] crt: Check for errors in startup code

2024-11-27 Thread Pali Rohár
Check for return value of functions called in startup code and exit process on failure. Pali Rohár (6): crt: Fix __getmainargs() and __wgetmainargs() ABI for msvcrt40.dll and msvcrt.dll crt: Check for return value from __(w)getmainargs() calls crt: Process return value from _(w)setargv()

Re: [Mingw-w64-public] getmainargs changes

2024-11-27 Thread Lasse Collin
On 2024-11-27 Pali Rohár wrote: > I think that we should not ignore memory allocation failures. I agree. I'm not able to comment the implementation ideas though. -- Lasse Collin ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net

[Mingw-w64-public] [PATCH 2/2] crt: Align i386 stack to 16-bytes for DLL builds due to SSE

2024-11-27 Thread Pali Rohár
i386 DLL builds have same issue as EXE builds, entry point (DllMain or DllEntryPoint) can use SSE and therefore stack should be aligned to 16-bytes. Use attribute force_align_arg_pointer for __DllMainCRTStartup, like it is already for __tmainCRTStartup. Also mark it as static. This code was copied

Re: [Mingw-w64-public] getmainargs changes

2024-11-27 Thread Pali Rohár
On Wednesday 27 November 2024 15:11:52 Pali Rohár wrote: > On Wednesday 27 November 2024 16:02:35 Lasse Collin wrote: > > On 2024-11-27 Pali Rohár wrote: > > > I think that we should not ignore memory allocation failures. > > > > I agree. I'm not able to comment the implementation ideas though. >

Re: [Mingw-w64-public] getmainargs changes

2024-11-27 Thread Pali Rohár
On Wednesday 27 November 2024 16:02:35 Lasse Collin wrote: > On 2024-11-27 Pali Rohár wrote: > > I think that we should not ignore memory allocation failures. > > I agree. I'm not able to comment the implementation ideas though. > > -- > Lasse Collin Just to note that this issue is mostly rare.

[Mingw-w64-public] [PATCH 2/2] crt: Deduplicate common vcruntime140*.def.in content into vcruntime140-common.def.in

2024-11-27 Thread Pali Rohár
All 3 vcruntime140 def files (vcruntime140.def.in, vcruntime140d.def.in and vcruntime140_app.def.in) contains exactly same symbols. Deduplicate symbols into new common file vcruntime140-common.def.in and include it in all 3 def files. --- ...e140.def.in => vcruntime140-common.def.in} | 5 - mingw

[Mingw-w64-public] [PATCH 1/2] crt: Fix i386 _NLG_ symbols in vcruntime140_app.def.in

2024-11-27 Thread Pali Rohár
Both _NLG_Dispatch2 and _NLG_Return symbols in i386 version have stdcall convention, like in all other CRT libraries. So add missing @4 / @12. Also sort symbols by name and make library name uppercase as it is stored in the vcruntime140_app.dll and as gendef detects it. --- mingw-w64-crt/lib-comm

Re: [Mingw-w64-public] getmainargs changes

2024-11-27 Thread Pali Rohár
On Saturday 09 November 2024 16:27:09 Pali Rohár wrote: > Hello, now, when looking at this issue, I have figured out that in > mingw-w64 is declaration of __getmainargs() and __wgetmainargs() > functions incompatible with msvcrt.dll library. > > In header file mingw-w64-crt/include/internal.h is:

Re: [Mingw-w64-public] Question about wdmsec

2024-11-27 Thread Johannes Khoshnazar-Thoma
Hi Martin Storsjö, Am 22.11.24 um 13:13 schrieb Martin Storsjö: > > This patch was approved and merged now (after some discussion and some tweaks to > the implementation), see > https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=3c557e1ae9c320efcfd4a7a91b752413a7bfd280. > > // Martin

Re: [Mingw-w64-public] __MSVCRT_VERSION__ value for msvcrt.dll

2024-11-27 Thread Pali Rohár
Hello, do you have any opinion how to move forward with this issue? Do we really needed special value for __MSVCRT_VERSION__ (e.g. 0x6FF pr 0x7FF)? Or can we just reuse 0x600 value together with _WIN32_WINNT check? On Saturday 19 October 2024 13:04:44 Pali Rohár wrote: > On Saturday 19 October 20

[Mingw-w64-public] [PATCH 2/2] headers: Declare debug _CRTDBG_MAP_ALLOC macros

2024-11-27 Thread Pali Rohár
In Visual Studio when including crtdbg.h file with both _DEBUG and _CRTDBG_MAP_ALLOC macros set, all standard memory allocation functions are redefined and forwarded to their *_dbg siblings. This allows to track memory allocation in program compiled and linked with debug version of CRT DLL library.

[Mingw-w64-public] [PATCH 1/2] headers: Declare CRT debug functions and macros for CRT debug DLL

2024-11-27 Thread Pali Rohár
msvc compiler for msvcrt and ucrt debug builds declare debug CRT function when _DEBUG macro is defined. All those functions and macros are defined in crtdbg.h include file. Do same in mingw-w64 headers. This allows applications to be compiled with gcc's -mcrtdll=msvcrtd and -D_DEBUG switches and t

[Mingw-w64-public] [PATCH] headers: Improve _STATIC_ASSERT for modern compilers

2024-11-27 Thread Pali Rohár
C11 supports two-arg _Static_assert keyword C++11 supports two-arg static_assert keyword C++17 supports one-arg static_assert keyword C23 supports one-arg static_assert keyword So when possible expand _STATIC_ASSERT macro to the suitable C/C++ keyword. --- mingw-w64-headers/crt/crtdbg.h | 8 +