Skip to content

Add ASan and UBSan options #6825

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

Merged
merged 1 commit into from
Apr 16, 2021
Merged
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
10 changes: 3 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
42 changes: 40 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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
CFLAGS="$CFLAGS -fsanitize=memory -fsanitize-memory-track-origins"
CXXFLAGS="$CXXFLAGS -fsanitize=memory -fsanitize-memory-track-origins"
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
Expand Down