This is mandatory on ARM64EC and also required on AArch64 for ARM64X builds. Instead of extending the existing logic, unify it by always including it in mingwex.
Fill CF Guard fields with zeroes when CF Guard is not enabled in CRT builds. This leverages existing LLD load config validation warnings to signal potential issues if the user enables CF Guard while using a CRT that was not built with it. In practice, this means load config will always be present in output images when using LLD. Since ld.bfd does not support load config, it remains unaffected. --- v3: Use CFGSYM for checker function pointers too, drop @feat.00 changes.y mingw-w64-crt/Makefile.am | 8 ++---- mingw-w64-crt/configure.ac | 4 +-- .../mingw_cfguard_loadcfg.S => crt/loadcfg.S} | 28 +++++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-) rename mingw-w64-crt/{cfguard/mingw_cfguard_loadcfg.S => crt/loadcfg.S} (81%) diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index 423e233ac..186e17979 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -22,6 +22,7 @@ endif AM_CPPFLAGS=$(sysincludes) AM_CFLAGS=-pipe -std=gnu99 -D_CRTBLD -D_WIN32_WINNT=0x0f00 -D__MSVCRT_VERSION__=0x600 -D__USE_MINGW_ANSI_STDIO=0 @IMAGEBASE_CFLAGS@ @CFGUARD_CFLAGS@ @ADD_C_CXX_WARNING_FLAGS@ @ADD_C_ONLY_WARNING_FLAGS@ AM_CXXFLAGS=@ADD_C_CXX_WARNING_FLAGS@ @ADD_CXX_ONLY_WARNING_FLAGS@ +AM_CCASFLAGS=@CFGUARD_CFLAGS@ CPPFLAGSARM32=-mfpu=vfpv3 CPPFLAGS32=-m32 -masm=att CPPFLAGS64=-m64 -masm=att @@ -928,6 +929,7 @@ src_msvcr120_app=\ # These mingwex sources are target independent: src_libmingwex=\ + crt/loadcfg.S \ cfguard/mingw_cfguard_support.c \ \ misc/dllmain.c \ @@ -1015,12 +1017,6 @@ src_libmingwex=\ stdio/vsnprintf.c stdio/vsnwprintf.c \ stdio/wtoll.c stdio/mingw_asprintf.c stdio/mingw_vasprintf.c -# Include the default load config struct only for Control Flow Guard support. -if CFGUARD -src_libmingwex+=\ - cfguard/mingw_cfguard_loadcfg.S -endif - # these go into both 32 and 64 bit x86 versions: src_libmingwex_x86=\ math/cbrtl.c math/erfl.c math/fdiml.c math/fmal.c math/fmaxl.c \ diff --git a/mingw-w64-crt/configure.ac b/mingw-w64-crt/configure.ac index 37851f605..f4f8d954d 100644 --- a/mingw-w64-crt/configure.ac +++ b/mingw-w64-crt/configure.ac @@ -273,10 +273,8 @@ AC_ARG_ENABLE([cfguard], AC_MSG_RESULT([$enable_cfguard]) AS_CASE([$enable_cfguard], [no],[], - [yes],[AS_VAR_SET([CFGUARD]) - AS_VAR_SET([CFGUARD_CFLAGS],[-mguard=cf])], + [yes],[AS_VAR_SET([CFGUARD_CFLAGS],["-mguard=cf -DHAS_CFGUARD"])], [AC_MSG_ERROR([invalid argument. Must be either yes or no.])]) -AM_CONDITIONAL([CFGUARD], [AS_VAR_TEST_SET([CFGUARD])]) AC_SUBST([CFGUARD_CFLAGS]) AC_MSG_CHECKING([whether to enable experimental features]) diff --git a/mingw-w64-crt/cfguard/mingw_cfguard_loadcfg.S b/mingw-w64-crt/crt/loadcfg.S similarity index 81% rename from mingw-w64-crt/cfguard/mingw_cfguard_loadcfg.S rename to mingw-w64-crt/crt/loadcfg.S index a7028b1a8..eb012b530 100644 --- a/mingw-w64-crt/cfguard/mingw_cfguard_loadcfg.S +++ b/mingw-w64-crt/crt/loadcfg.S @@ -37,6 +37,12 @@ Ref: https://docs.microsoft.com/en-us/windows/win32/secbp/pe-metadata # define SYM(x) x #endif +#ifdef HAS_CFGUARD +# define CFGSYM(x) SYM(x) +#else +# define CFGSYM(x) 0 +#endif + #if defined(INCLUDE_MSVC_FEATURES) /* These features are specific to MSVC as far as I am aware. @@ -81,23 +87,23 @@ SYM(_load_config_used): PTR 0 /* SEHandlerTable */ PTR 0 /* SEHandlerCount */ #endif - PTR SYM(__guard_check_icall_fptr) /* GuardCFCheckFunction */ + PTR CFGSYM(__guard_check_icall_fptr) /* GuardCFCheckFunction */ #if defined(CFGUARD_USE_DISPATCH) - PTR SYM(__guard_dispatch_icall_fptr) /* GuardCFCheckDispatch */ + PTR CFGSYM(__guard_dispatch_icall_fptr) /* GuardCFCheckDispatch */ #else PTR 0 /* GuardCFCheckDispatch */ #endif - PTR SYM(__guard_fids_table) /* GuardCFFunctionTable */ - PTR SYM(__guard_fids_count) /* GuardCFFunctionCount */ - .4byte SYM(__guard_flags) /* GuardFlags */ + PTR CFGSYM(__guard_fids_table) /* GuardCFFunctionTable */ + PTR CFGSYM(__guard_fids_count) /* GuardCFFunctionCount */ + .4byte CFGSYM(__guard_flags) /* GuardFlags */ .2byte 0 /* CodeIntegrity_Flags */ .2byte 0 /* CodeIntegrity_Catalog */ .4byte 0 /* CodeIntegrity_CatalogOffset */ .4byte 0 /* CodeIntegrity_Reserved */ - PTR SYM(__guard_iat_table) /* GuardAddressTakenIatEntryTable */ - PTR SYM(__guard_iat_count) /* GuardAddressTakenIatEntryCount */ - PTR SYM(__guard_longjmp_table) /* GuardLongJumpTargetTable */ - PTR SYM(__guard_longjmp_count) /* GuardLongJumpTargetCount */ + PTR CFGSYM(__guard_iat_table) /* GuardAddressTakenIatEntryTable */ + PTR CFGSYM(__guard_iat_count) /* GuardAddressTakenIatEntryCount */ + PTR CFGSYM(__guard_longjmp_table) /* GuardLongJumpTargetTable */ + PTR CFGSYM(__guard_longjmp_count) /* GuardLongJumpTargetCount */ PTR 0 /* DynamicValueRelocTable */ PTR 0 /* CHPEMetadataPointer */ PTR 0 /* GuardRFFailureRoutine */ @@ -114,8 +120,8 @@ SYM(_load_config_used): PTR 0 /* EnclaveConfigurationPointer */ #endif PTR 0 /* VolatileMetadataPointer */ - PTR SYM(__guard_eh_cont_table) /* GuardEHContinuationTable */ - PTR SYM(__guard_eh_cont_count) /* GuardEHContinuationCount */ + PTR CFGSYM(__guard_eh_cont_table) /* GuardEHContinuationTable */ + PTR CFGSYM(__guard_eh_cont_count) /* GuardEHContinuationCount */ PTR 0 /* GuardXFGCheckFunctionPointer */ PTR 0 /* GuardXFGDispatchFunctionPointer */ PTR 0 /* GuardXFGTableDispatchFunctionPointer */ -- 2.45.3 _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public