From 181b3757d878955345830de905d5357e815c007d Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 22 Aug 2024 18:05:04 +0200 Subject: [PATCH 1/2] Support --enable-debug-assertions configure option on Windows This has been introduced for non Windows system years ago[1] mainly to improve fuzzer SAPI. While this is still not available on Windows, the option can still make sense, particularly for CI runs or other environments where full debugging support would be useless, but where enabled assertions would be helpful. [1] --- win32/build/config.w32 | 4 ++++ win32/build/confutils.js | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/win32/build/config.w32 b/win32/build/config.w32 index 668995045725..5e6787272810 100644 --- a/win32/build/config.w32 +++ b/win32/build/config.w32 @@ -32,6 +32,10 @@ ARG_ENABLE('debug-pack', 'Release binaries with external debug symbols (--enable if (PHP_DEBUG == "yes" && PHP_DEBUG_PACK == "yes") { ERROR("Use of both --enable-debug and --enable-debug-pack not allowed."); } +ARG_ENABLE('debug-assertions', 'Release binaries with debug assertions (--enable-debug must not be specified)', "no"); +if (PHP_DEBUG == "yes" && PHP_DEBUG_ASSERTIONS == "yes") { + ERROR("Use of both --enable-debug and --enable-debug-assertions not allowed."); +} if (PHP_DEBUG == "yes") { ADD_FLAG("CFLAGS"," /Wall "); diff --git a/win32/build/confutils.js b/win32/build/confutils.js index 95a4e5ce3c13..49e15834fd63 100644 --- a/win32/build/confutils.js +++ b/win32/build/confutils.js @@ -456,7 +456,7 @@ can be built that way. \ var snapshot_build_exclusions = new Array( 'debug', 'lzf-better-compression', 'php-build', 'snapshot-template', 'zts', 'ipv6', 'fd-setsize', 'pgi', 'pgo', 'all-shared', 'config-profile', 'sanitizer', - 'phpdbg-debug' + 'phpdbg-debug', 'debug-assertions' ); var force; @@ -3475,10 +3475,15 @@ function toolset_setup_build_mode() } ADD_FLAG("CFLAGS", "/LD /MD"); if (PHP_SANITIZER == "yes" && CLANG_TOOLSET) { - ADD_FLAG("CFLAGS", "/Od /D NDebug /D NDEBUG /D ZEND_WIN32_NEVER_INLINE /D ZEND_DEBUG=0"); + ADD_FLAG("CFLAGS", "/Od /D NDebug /D ZEND_WIN32_NEVER_INLINE"); } else { // Equivalent to Release_TSInline build -> best optimization - ADD_FLAG("CFLAGS", "/Ox /D NDebug /D NDEBUG /GF /D ZEND_DEBUG=0"); + ADD_FLAG("CFLAGS", "/Ox /D NDebug /GF"); + } + if (PHP_DEBUG_ASSERTIONS == "yes") { + ADD_FLAG("CFLAGS", "/D ZEND_DEBUG=1"); + } else { + ADD_FLAG("CFLAGS", "/D ZEND_DEBUG=0 /D NDEBUG"); } // if you have VS.Net /GS hardens the binary against buffer overruns From 5ffe299f7acdfa0aa6a2f043c90180fc3b430a62 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 22 Aug 2024 18:06:35 +0200 Subject: [PATCH 2/2] Fix erroneous preprocessor check `PHP_DEBUG` actually doesn't tell whether have a debug build; the MSVC specific `_DEBUG` does, though. --- win32/winutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/winutil.c b/win32/winutil.c index e09944d131b9..6e4325dcaecc 100644 --- a/win32/winutil.c +++ b/win32/winutil.c @@ -486,7 +486,7 @@ PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err) {/*{{{*/ #if PHP_LINKER_MAJOR == 14 /* Extend for other CRT if needed. */ -# if PHP_DEBUG +# if _DEBUG const char *crt_name = "vcruntime140d.dll"; # else const char *crt_name = "vcruntime140.dll";