Skip to content

Support --enable-sanitizer for MSVC builds #16999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions win32/build/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,20 @@ if (PHP_SECURITY_FLAGS == "yes") {
}

ARG_WITH("uncritical-warn-choke", "Disable some uncritical warnings", "yes");
ARG_ENABLE("sanitizer", "Enable ASan and UBSan extensions", "no");
if (CLANG_TOOLSET) {
ARG_ENABLE("sanitizer", "Enable ASan (and UBSan) extensions", "no");
if (PHP_SANITIZER == "yes" && PHP_DEBUG == "yes") {
ERROR("Use of both --enable-sanitizer and --enable-debug not allowed.");
}
if (PHP_SANITIZER == "yes" && PHP_DEBUG_PACK == "no") {
ERROR("--enable-sanitizer requires --enable-debug-pack");
}
if (VS_TOOLSET) {
if (PHP_SANITIZER == "yes") {
if (COMPILER_NUMERIC_VERSION < 1929) {
ERROR("MSVC at least 16.0 required for sanitation plugins");
}
}
} else if (CLANG_TOOLSET) {
if (PHP_UNCRITICAL_WARN_CHOKE != "no") {
ADD_FLAG("CFLAGS", "-Wno-ignored-attributes -Wno-deprecated-declarations -Wno-missing-braces " +
"-Wno-logical-op-parentheses -Wno-msvc-include -Wno-invalid-source-encoding -Wno-unknown-pragmas " +
Expand Down
10 changes: 8 additions & 2 deletions win32/build/confutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ function SAPI(sapiname, file_list, makefiletarget, cflags, obj_dir)
if (PHP_SANITIZER == "yes") {
if (CLANG_TOOLSET) {
add_asan_opts("CFLAGS_" + SAPI, "LIBS_" + SAPI, (is_lib ? "ARFLAGS_" : "LDFLAGS_") + SAPI);
} else if (VS_TOOLSET) {
ADD_FLAG("CFLAGS", "/fsanitize=address");
}
}

Expand Down Expand Up @@ -3442,8 +3444,12 @@ function toolset_setup_build_mode()
ADD_FLAG("LDFLAGS", "/incremental:no /debug /opt:ref,icf");
}
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");
if (PHP_SANITIZER == "yes") {
if (VS_TOOLSET) {
ADD_FLAG("CFLAGS", "/Ox /U NDebug /U NDEBUG /D ZEND_DEBUG=1");
} else if (CLANG_TOOLSET) {
ADD_FLAG("CFLAGS", "/Od /D NDebug /D NDEBUG /D ZEND_WIN32_NEVER_INLINE /D ZEND_DEBUG=0");
}
} else {
// Equivalent to Release_TSInline build -> best optimization
ADD_FLAG("CFLAGS", "/Ox /D NDebug /D NDEBUG /GF /D ZEND_DEBUG=0");
Expand Down