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

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Nov 30, 2024

While it is already possible to enable ASan for MSVC (assuming Visual Studio 2019 16.10 or later) by passing /fsanitizer=address in the CFLAGS, it is only usable if ZEND_DEBUG is also enabled; otherwise there are STATUS_BACK_STACK errors all the time.

Since it makes some sense to combine ASan instrumentation with debug assertions enabled anyway (typical for fuzzing), we support the configure option --enable-sanitizer, which is already supported for Clang builds, also for MSVC builds. Note that MSVC supports only ASan for now; contrary to Clang which additionally supports UBSan on Windows.

Since ASan reports can be pretty useless without debug symbol information, we require such builds to also produce PDBs (i.e. --enable-debug-pack), but forbid actual debug builds (for performance reasons, and because the way it is implemented it would not make sense; that was already an issue with Clang builds with sanitizers enabled).


Note that there are basically no changes regarding Clang sanitizers (besides that --enable-debug --enable-sanitzer is explicitly forbidden; previously that would not properly enable sanitizers anyway). I have some doubts that the flags which are set for Clang sanitizers make much sense (they even might not properly work), but that could be addressed by another patch (if anyone cares about that).

Also note that phpize builds do not properly support sanitizers (with or without this patch). It is not even quite clear how that should be done (probably, if a phpize build uses an instrumented PHP build, the extension should automaticallybe instrumented as well). On the other hand, it might not make much sense to support this for phpize at all; after all, we do not provide prebuilt ASan instrumentation on Windows, and those who want to use this, might be better off doing in-tree builds, anyway. I'm not sure, but I guess it's pretty much the same for phpize builds on POSIX; these use release builds of PHP (neither ASan instrumented nor debug builds).

My main reason for suggesting this change is to be able to have ASan builds running in CI (and possibly for fuzz testing). See #15978 for a CI run. Since this is pretty slow (tests take more than an hour), it is unsuitable for pushes, but appears to be a sensible addition for nightly runs, particularly to catch memory issues in Windows only code paths.

If one needs a full debug build with ASan instrumentation for whatever reason, it is still possible to set CFLAGS=/fsanitizer=address and to configure --enable-debug.

While it is already possible to enable ASan for MSVC (assuming Visual
Studio 2019 16.10 or later) by passing `/fsanitizer=address` in the
`CFLAGS`, it is only usable if `ZEND_DEBUG` is also enabled; otherwise
there are `STATUS_BACK_STACK` errors all the time.

Since it makes some sense to combine ASan instrumentation with debug
assertions enabled anyway (typical for fuzzing), we support the
configure option `--enable-sanitizer`, which is already supported for
Clang builds, also for MSVC builds.  Note that MSVC supports only ASan
for now; contrary to Clang which additionally supports UBSan on Windows.

Since ASan reports can be pretty useless without debug symbol
information, we require such builds to also produce PDBs (i.e.
`--enable-debug-pack`), but forbid actual debug builds (for performance
reasons, and because the way it is implemented it would not make sense;
that was already an issue with Clang builds with sanitizers enabled).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant