Re: [Mingw-w64-public] [PATCH] crt: Remove the vestigial gs_support.c
On Thu, 23 Apr 2020, Jacek Caban wrote: Hi Martin, This patch looks right to me. If it never really worked, backward compatibility is not an issue. If someone wants those features, using UCRT seems to be the right answer. Ok - if there's no objections to it, I'd go ahead and push this one - as long as nobody is tagging a new release soon, we have time to revisit it in the highly unlikely event that it actually causes some issues. // Martin ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] crt: Remove the vestigial gs_support.c
Hi Martin, This patch looks right to me. If it never really worked, backward compatibility is not an issue. If someone wants those features, using UCRT seems to be the right answer. Thanks, Jacek On 22.04.2020 23:00, Martin Storsjö wrote: This was a partial (but incomplete!) support for the MSVC stack cookie handling (under the MSVC option /GS, similar to GCC and Clang/MinGW's -fstack-protector-strong). This contained the stack cookie itself and the init function, and the error reporting function, but not the checking function (__security_check_cookie). And these functions would only end up being called by code generated by MSVC anyway. Signed-off-by: Martin Storsjö --- This is one out of two alternative ways of handling the potentially problematic function __report_gsfailure, which calls a number of functions that aren't available for UWP apps - the other alternative is to keep the functions but move __report_gsfailure to the msvcrt import library, as more modern msvcrt versions, and ucrt, does provide their own versions of the function - and in normal cases, nothing references the symbol so it won't end up linked in (unless it's in the same object file as __security_init_cookie). --- mingw-w64-crt/Makefile.am | 2 +- mingw-w64-crt/crt/crtdll.c | 1 - mingw-w64-crt/crt/crtexe.c | 2 - mingw-w64-crt/crt/gs_support.c | 154 mingw-w64-headers/crt/process.h | 10 --- 5 files changed, 1 insertion(+), 168 deletions(-) delete mode 100644 mingw-w64-crt/crt/gs_support.c diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index 0f882ae2a..86b0b0d73 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -115,7 +115,7 @@ src_libntoskrnl=libsrc/memcmp.c src_libmingw32=include/oscalls.h include/internal.h include/sect_attribs.h \ crt/crt0_c.ccrt/dll_argv.c crt/gccmain.c crt/natstart.c crt/pseudo-reloc-list.c crt/wildcard.c \ - crt/charmax.c crt/crt0_w.c crt/dllargv.c crt/gs_support.c crt/_newmode.c crt/tlssup.c crt/xncommod.c \ + crt/charmax.c crt/crt0_w.c crt/dllargv.c crt/_newmode.c crt/tlssup.c crt/xncommod.c \ crt/cinitexe.c crt/crt0_w.c crt/merr.c crt/pesect.c crt/udllargc.c crt/xthdloc.ccrt/CRT_fp10.c \ crt/mingw_custom.c crt/mingw_helpers.c \ crt/pseudo-reloc.c crt/udll_argv.c \ diff --git a/mingw-w64-crt/crt/crtdll.c b/mingw-w64-crt/crt/crtdll.c index 6187f10d2..797c1beeb 100644 --- a/mingw-w64-crt/crt/crtdll.c +++ b/mingw-w64-crt/crt/crtdll.c @@ -156,7 +156,6 @@ DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) mingw_app_type = 0; if (dwReason == DLL_PROCESS_ATTACH) { - __security_init_cookie (); #ifdef __x86_64__ __mingw_init_ehandler (); #endif diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c index b730dc479..f521b54cd 100644 --- a/mingw-w64-crt/crt/crtexe.c +++ b/mingw-w64-crt/crt/crtexe.c @@ -189,7 +189,6 @@ int WinMainCRTStartup (void) ); #endif mingw_app_type = 1; - __security_init_cookie (); ret = __tmainCRTStartup (); #ifdef SEH_INLINE_ASM asm ("\tnop\n" @@ -217,7 +216,6 @@ int mainCRTStartup (void) ); #endif mingw_app_type = 0; - __security_init_cookie (); ret = __tmainCRTStartup (); #ifdef SEH_INLINE_ASM asm ("\tnop\n" diff --git a/mingw-w64-crt/crt/gs_support.c b/mingw-w64-crt/crt/gs_support.c deleted file mode 100644 index 0c6ac68cd..0 --- a/mingw-w64-crt/crt/gs_support.c +++ /dev/null @@ -1,154 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#define WIN32_NO_STATUS -#include /* abort () */ -#include -#undef WIN32_NO_STATUS -#include /* STATUS macros */ -#ifdef _WIN64 -#include -#endif - -#ifdef _WIN64 -#define DEFAULT_SECURITY_COOKIE 0x2B992DDFA232ll -#else -#define DEFAULT_SECURITY_COOKIE 0xBB40E64E -#endif - -/* Externals. */ - -typedef LONG NTSTATUS; /* same as in ntdef.h / winternl.h */ - -#define UNW_FLAG_NHANDLER 0x0 - -typedef union -{ - unsigned __int64 ft_scalar; - FILETIME ft_struct; -} FT; - -static EXCEPTION_RECORD GS_ExceptionRecord; -static CONTEXT GS_ContextRecord; - -static const EXCEPTION_POINTERS GS_ExceptionPointers = { - &GS_ExceptionRecord,&GS_ContextRecord -}; - -DECLSPEC_SELECTANY UINT_PTR __security_cookie = DEFAULT_SECURITY_COOKIE; -DECLSPEC_SELECTANY UINT_PTR __security_cookie_complement = ~(DEFAULT_SECURITY_COOKIE); - -void __cdecl __security_init_cookie (void); - -void __cdecl -__security_init_cookie (void) -{ - UINT_PTR cookie; - FT systime = { 0, }; - LARGE_INTEGER perfctr; - - if (__security_cookie != DEFAULT_SECURI
[Mingw-w64-public] [PATCH] crt: Remove the vestigial gs_support.c
This was a partial (but incomplete!) support for the MSVC stack cookie handling (under the MSVC option /GS, similar to GCC and Clang/MinGW's -fstack-protector-strong). This contained the stack cookie itself and the init function, and the error reporting function, but not the checking function (__security_check_cookie). And these functions would only end up being called by code generated by MSVC anyway. Signed-off-by: Martin Storsjö --- This is one out of two alternative ways of handling the potentially problematic function __report_gsfailure, which calls a number of functions that aren't available for UWP apps - the other alternative is to keep the functions but move __report_gsfailure to the msvcrt import library, as more modern msvcrt versions, and ucrt, does provide their own versions of the function - and in normal cases, nothing references the symbol so it won't end up linked in (unless it's in the same object file as __security_init_cookie). --- mingw-w64-crt/Makefile.am | 2 +- mingw-w64-crt/crt/crtdll.c | 1 - mingw-w64-crt/crt/crtexe.c | 2 - mingw-w64-crt/crt/gs_support.c | 154 mingw-w64-headers/crt/process.h | 10 --- 5 files changed, 1 insertion(+), 168 deletions(-) delete mode 100644 mingw-w64-crt/crt/gs_support.c diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index 0f882ae2a..86b0b0d73 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -115,7 +115,7 @@ src_libntoskrnl=libsrc/memcmp.c src_libmingw32=include/oscalls.h include/internal.h include/sect_attribs.h \ crt/crt0_c.ccrt/dll_argv.c crt/gccmain.c crt/natstart.c crt/pseudo-reloc-list.c crt/wildcard.c \ - crt/charmax.c crt/crt0_w.c crt/dllargv.c crt/gs_support.c crt/_newmode.c crt/tlssup.c crt/xncommod.c \ + crt/charmax.c crt/crt0_w.c crt/dllargv.c crt/_newmode.c crt/tlssup.c crt/xncommod.c \ crt/cinitexe.c crt/crt0_w.c crt/merr.c crt/pesect.c crt/udllargc.c crt/xthdloc.ccrt/CRT_fp10.c \ crt/mingw_custom.c crt/mingw_helpers.c \ crt/pseudo-reloc.c crt/udll_argv.c \ diff --git a/mingw-w64-crt/crt/crtdll.c b/mingw-w64-crt/crt/crtdll.c index 6187f10d2..797c1beeb 100644 --- a/mingw-w64-crt/crt/crtdll.c +++ b/mingw-w64-crt/crt/crtdll.c @@ -156,7 +156,6 @@ DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) mingw_app_type = 0; if (dwReason == DLL_PROCESS_ATTACH) { - __security_init_cookie (); #ifdef __x86_64__ __mingw_init_ehandler (); #endif diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c index b730dc479..f521b54cd 100644 --- a/mingw-w64-crt/crt/crtexe.c +++ b/mingw-w64-crt/crt/crtexe.c @@ -189,7 +189,6 @@ int WinMainCRTStartup (void) ); #endif mingw_app_type = 1; - __security_init_cookie (); ret = __tmainCRTStartup (); #ifdef SEH_INLINE_ASM asm ("\tnop\n" @@ -217,7 +216,6 @@ int mainCRTStartup (void) ); #endif mingw_app_type = 0; - __security_init_cookie (); ret = __tmainCRTStartup (); #ifdef SEH_INLINE_ASM asm ("\tnop\n" diff --git a/mingw-w64-crt/crt/gs_support.c b/mingw-w64-crt/crt/gs_support.c deleted file mode 100644 index 0c6ac68cd..0 --- a/mingw-w64-crt/crt/gs_support.c +++ /dev/null @@ -1,154 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#define WIN32_NO_STATUS -#include /* abort () */ -#include -#undef WIN32_NO_STATUS -#include /* STATUS macros */ -#ifdef _WIN64 -#include -#endif - -#ifdef _WIN64 -#define DEFAULT_SECURITY_COOKIE 0x2B992DDFA232ll -#else -#define DEFAULT_SECURITY_COOKIE 0xBB40E64E -#endif - -/* Externals. */ - -typedef LONG NTSTATUS; /* same as in ntdef.h / winternl.h */ - -#define UNW_FLAG_NHANDLER 0x0 - -typedef union -{ - unsigned __int64 ft_scalar; - FILETIME ft_struct; -} FT; - -static EXCEPTION_RECORD GS_ExceptionRecord; -static CONTEXT GS_ContextRecord; - -static const EXCEPTION_POINTERS GS_ExceptionPointers = { - &GS_ExceptionRecord,&GS_ContextRecord -}; - -DECLSPEC_SELECTANY UINT_PTR __security_cookie = DEFAULT_SECURITY_COOKIE; -DECLSPEC_SELECTANY UINT_PTR __security_cookie_complement = ~(DEFAULT_SECURITY_COOKIE); - -void __cdecl __security_init_cookie (void); - -void __cdecl -__security_init_cookie (void) -{ - UINT_PTR cookie; - FT systime = { 0, }; - LARGE_INTEGER perfctr; - - if (__security_cookie != DEFAULT_SECURITY_COOKIE) -{ - __security_cookie_complement = ~__security_cookie; - return; -} - - GetSystemTimeAsFileTime (&systime.ft_struct); -#ifdef _WIN64 - cookie = systime.ft_scalar; -#else - cookie = systime.ft_struct.dwLowDateTime; - cookie ^= systime.ft_struct.dwHig