Add ASan and UBSan options (#6825)

When we need to enable ASan/UBSan in PHP extension, we also need to enable it in PHP kernel. Providing these options makes it easier for us to enable ASan/UBSan when compiling PHP.
And we use --enable-address-sanitizer and --enable-undefined-sanitizer in azure-pipelines.yml instead of changing CFLAGS manually.
We also add compile flag check to MSan.
This commit is contained in:
twosee 2021-04-16 12:41:25 +08:00 committed by GitHub
parent 559c3f6d86
commit 122deea506
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 9 deletions

View file

@ -74,10 +74,7 @@ jobs:
- template: azure/job.yml
parameters:
configurationName: DEBUG_ZTS_ASAN_UBSAN
configurationParameters: >-
--enable-debug --enable-zts
CFLAGS='-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC'
LDFLAGS='-fsanitize=undefined,address'
configurationParameters: '--enable-debug --enable-zts --enable-address-sanitizer --enable-undefined-sanitizer'
runTestsParameters: --asan
timeoutInMinutes: 360
- template: azure/msan_job.yml
@ -90,9 +87,8 @@ jobs:
parameters:
configurationName: COMMUNITY
configurationParameters: >-
--enable-debug --enable-zts
CFLAGS='-fsanitize=undefined,address -fno-sanitize-recover -DZEND_TRACK_ARENA_ALLOC'
LDFLAGS='-fsanitize=undefined,address'
--enable-debug --enable-zts --enable-address-sanitizer --enable-undefined-sanitizer
CFLAGS='-fno-sanitize-recover'
- template: azure/coverage_job.yml
parameters:
configurationName: COVERAGE_DEBUG_ZTS

View file

@ -982,6 +982,16 @@ PHP_ARG_ENABLE([memory-sanitizer],,
[Enable memory sanitizer (clang only)])],
[no],
[no])
PHP_ARG_ENABLE([address-sanitizer],,
[AS_HELP_STRING([--enable-address-sanitizer],
[Enable address sanitizer])],
[no],
[no])
PHP_ARG_ENABLE([undefined-sanitizer],,
[AS_HELP_STRING([--enable-undefined-sanitizer],
[Enable undefined sanitizer])],
[no],
[no])
dnl Extension configuration.
dnl ----------------------------------------------------------------------------
@ -1372,10 +1382,38 @@ if test "$PHP_WERROR" = "yes"; then
CXXFLAGS="$CXXFLAGS -Werror"
fi
if test "$PHP_MEMORY_SANITIZER" = "yes" &&
test "$PHP_ADDRESS_SANITIZER" = "yes"; then
AC_MSG_ERROR([MemorySanitizer and AddressSanitizer are mutually exclusive])
fi
dnl Enable -fsanitize=memory late, because interceptors may break linking detection.
if test "$PHP_MEMORY_SANITIZER" = "yes"; then
AX_CHECK_COMPILE_FLAG([-fsanitize=memory -fsanitize-memory-track-origins], [
CFLAGS="$CFLAGS -fsanitize=memory -fsanitize-memory-track-origins"
CXXFLAGS="$CXXFLAGS -fsanitize=memory -fsanitize-memory-track-origins"
], [AC_MSG_ERROR([MemorySanitizer is not available])])
fi
if test "$PHP_ADDRESS_SANITIZER" = "yes"; then
AX_CHECK_COMPILE_FLAG([-fsanitize=address], [
CFLAGS="$CFLAGS -fsanitize=address -DZEND_TRACK_ARENA_ALLOC"
CXXFLAGS="$CXXFLAGS -fsanitize=address -DZEND_TRACK_ARENA_ALLOC"
], [AC_MSG_ERROR([AddressSanitizer is not available])])
fi
if test "$PHP_UNDEFINED_SANITIZER" = "yes"; then
AX_CHECK_COMPILE_FLAG([-fsanitize=undefined], [
CFLAGS="$CFLAGS -fsanitize=undefined"
CXXFLAGS="$CXXFLAGS -fsanitize=undefined"
], [AC_MSG_ERROR([UndefinedBehaviorSanitizer is not available])])
fi
if test "$PHP_MEMORY_SANITIZER" = "yes" ||
test "$PHP_ADDRESS_SANITIZER" = "yes" ||
test "$PHP_UNDEFINED_SANITIZER" = "yes"; then
CFLAGS="$CFLAGS -fno-omit-frame-pointer"
CXXFLAGS="$CXXFLAGS -fno-omit-frame-pointer"
fi
dnl