Skip to content

Commit ea3a97f

Browse files
authored
gh-157354: Honor --with-<name>-sanitizer=no and --without-<name>-sanitizer in configure (#157355)
1 parent d59d968 commit ea3a97f

4 files changed

Lines changed: 110 additions & 69 deletions

File tree

‎Lib/test/support/__init__.py‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import _opcode
1212
import os
1313
import re
14+
import shlex
1415
import stat
1516
import sys
1617
import sysconfig
@@ -469,27 +470,39 @@ def check_sanitizer(*, address=False, hwaddress=False, memory=False, ub=False,
469470

470471

471472
cflags = sysconfig.get_config_var('CFLAGS') or ''
472-
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
473+
config_args = shlex.split(sysconfig.get_config_var('CONFIG_ARGS') or '')
474+
475+
def configured_with_sanitizer(name):
476+
with_option = f'--with-{name}-sanitizer'
477+
without_option = f'--without-{name}-sanitizer'
478+
enabled = False
479+
for arg in config_args:
480+
if arg == without_option or arg == f'{with_option}=no':
481+
enabled = False
482+
elif arg == with_option or arg.startswith(f'{with_option}='):
483+
enabled = True
484+
return enabled
485+
473486
memory_sanitizer = (
474487
'-fsanitize=memory' in cflags or
475-
'--with-memory-sanitizer' in config_args
488+
configured_with_sanitizer('memory')
476489
)
477490
hwaddress_sanitizer = (
478491
'-fsanitize=hwaddress' in cflags or
479-
'--with-hwaddress-sanitizer' in config_args
492+
configured_with_sanitizer('hwaddress')
480493
)
481494
address_sanitizer = (
482495
'-fsanitize=address' in cflags or
483-
'--with-address-sanitizer' in config_args or
496+
configured_with_sanitizer('address') or
484497
hwaddress_sanitizer
485498
)
486499
ub_sanitizer = (
487500
'-fsanitize=undefined' in cflags or
488-
'--with-undefined-behavior-sanitizer' in config_args
501+
configured_with_sanitizer('undefined-behavior')
489502
)
490503
thread_sanitizer = (
491504
'-fsanitize=thread' in cflags or
492-
'--with-thread-sanitizer' in config_args
505+
configured_with_sanitizer('thread')
493506
)
494507
function_sanitizer = (
495508
'-fsanitize=function' in cflags
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the :samp:`--with-{name}-sanitizer=no` and :samp:`--without-{name}-sanitizer`
2+
:program:`configure` options enabling the sanitizer instead of disabling it.

‎configure‎

Lines changed: 67 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,17 +3728,17 @@ AC_MSG_CHECKING([for --with-address-sanitizer])
37283728
AC_ARG_WITH([address_sanitizer],
37293729
AS_HELP_STRING([--with-address-sanitizer],
37303730
[enable AddressSanitizer memory error detector, 'asan' (default is no)]),
3731-
[
3732-
AC_MSG_RESULT([$withval])
3731+
[], [with_address_sanitizer=no])
3732+
AC_MSG_RESULT([$with_address_sanitizer])
3733+
AS_VAR_IF([with_address_sanitizer], [no], [], [
37333734
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
37343735
LDFLAGS="-fsanitize=address $LDFLAGS"
37353736
AC_MSG_CHECKING([whether a program links with -fsanitize=address])
37363737
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
37373738
[AC_MSG_RESULT([yes])],
37383739
[AC_MSG_RESULT([no])
37393740
AC_MSG_ERROR([cannot link with -fsanitize=address: the compiler does not support AddressSanitizer or its runtime library is not installed; see config.log])])
3740-
],
3741-
[AC_MSG_RESULT([no])])
3741+
])
37423742

37433743
AC_MSG_CHECKING([for --with-hwaddress-sanitizer])
37443744
AC_ARG_WITH(
@@ -3747,8 +3747,9 @@ AC_ARG_WITH(
37473747
[--with-hwaddress-sanitizer],
37483748
[enable HWAddressSanitizer memory error detector, 'hwasan' (default is no)]
37493749
)],
3750-
[
3751-
AC_MSG_RESULT([$withval])
3750+
[], [with_hwaddress_sanitizer=no])
3751+
AC_MSG_RESULT([$with_hwaddress_sanitizer])
3752+
AS_VAR_IF([with_hwaddress_sanitizer], [no], [], [
37523753
hwasan_flags="-fsanitize=hwaddress"
37533754
# x86-64 lacks address tagging, so HWASan needs the page aliasing mode there.
37543755
# See gh-156049 and
@@ -3763,8 +3764,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
37633764
[AC_MSG_RESULT([yes])],
37643765
[AC_MSG_RESULT([no])
37653766
AC_MSG_ERROR([cannot link with $hwasan_flags: the compiler does not support HWAddressSanitizer or its runtime library is not installed; see config.log])])
3766-
],
3767-
[AC_MSG_RESULT([no])])
3767+
])
37683768

37693769
AC_MSG_CHECKING([for --with-memory-sanitizer])
37703770
AC_ARG_WITH(
@@ -3773,17 +3773,17 @@ AC_ARG_WITH(
37733773
[--with-memory-sanitizer],
37743774
[enable MemorySanitizer allocation error detector, 'msan' (default is no)]
37753775
)],
3776-
[
3777-
AC_MSG_RESULT([$withval])
3776+
[], [with_memory_sanitizer=no])
3777+
AC_MSG_RESULT([$with_memory_sanitizer])
3778+
AS_VAR_IF([with_memory_sanitizer], [no], [], [
37783779
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
37793780
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
37803781
AC_MSG_CHECKING([whether a program links with -fsanitize=memory])
37813782
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
37823783
[AC_MSG_RESULT([yes])],
37833784
[AC_MSG_RESULT([no])
37843785
AC_MSG_ERROR([cannot link with -fsanitize=memory: the compiler does not support MemorySanitizer or its runtime library is not installed; see config.log])])
3785-
],
3786-
[AC_MSG_RESULT([no])])
3786+
])
37873787

37883788
AC_MSG_CHECKING([for --with-undefined-behavior-sanitizer])
37893789
AC_ARG_WITH(
@@ -3792,8 +3792,11 @@ AC_ARG_WITH(
37923792
[--with-undefined-behavior-sanitizer],
37933793
[enable UndefinedBehaviorSanitizer undefined behaviour detector, 'ubsan' (default is no)]
37943794
)],
3795-
[
3796-
AC_MSG_RESULT([$withval])
3795+
[], [with_undefined_behavior_sanitizer=no])
3796+
AC_MSG_RESULT([$with_undefined_behavior_sanitizer])
3797+
AS_VAR_IF([with_undefined_behavior_sanitizer], [no], [
3798+
with_ubsan="no"
3799+
], [
37973800
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
37983801
LDFLAGS="-fsanitize=undefined $LDFLAGS"
37993802
with_ubsan="yes"
@@ -3802,10 +3805,6 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
38023805
[AC_MSG_RESULT([yes])],
38033806
[AC_MSG_RESULT([no])
38043807
AC_MSG_ERROR([cannot link with -fsanitize=undefined: the compiler does not support UndefinedBehaviorSanitizer or its runtime library is not installed; see config.log])])
3805-
],
3806-
[
3807-
AC_MSG_RESULT([no])
3808-
with_ubsan="no"
38093808
])
38103809

38113810
AC_MSG_CHECKING([for --with-thread-sanitizer])
@@ -3815,8 +3814,11 @@ AC_ARG_WITH(
38153814
[--with-thread-sanitizer],
38163815
[enable ThreadSanitizer data race detector, 'tsan' (default is no)]
38173816
)],
3818-
[
3819-
AC_MSG_RESULT([$withval])
3817+
[], [with_thread_sanitizer=no])
3818+
AC_MSG_RESULT([$with_thread_sanitizer])
3819+
AS_VAR_IF([with_thread_sanitizer], [no], [
3820+
with_tsan="no"
3821+
], [
38203822
BASECFLAGS="-fsanitize=thread $BASECFLAGS"
38213823
LDFLAGS="-fsanitize=thread $LDFLAGS"
38223824
with_tsan="yes"
@@ -3825,10 +3827,6 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
38253827
[AC_MSG_RESULT([yes])],
38263828
[AC_MSG_RESULT([no])
38273829
AC_MSG_ERROR([cannot link with -fsanitize=thread: the compiler does not support ThreadSanitizer or its runtime library is not installed; see config.log])])
3828-
],
3829-
[
3830-
AC_MSG_RESULT([no])
3831-
with_tsan="no"
38323830
])
38333831

38343832
# Set info about shared libraries.

0 commit comments

Comments
 (0)