Skip to content

Commit cd3d050

Browse files
authored
[3.15] gh-157354: Honor --with-<name>-sanitizer=no and --without-<name>-sanitizer in configure (GH-157355) (#160655)
1 parent b547124 commit cd3d050

4 files changed

Lines changed: 92 additions & 57 deletions

File tree

‎Lib/test/support/__init__.py‎

Lines changed: 18 additions & 5 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
@@ -444,22 +445,34 @@ def check_sanitizer(*, address=False, memory=False, ub=False, thread=False,
444445

445446

446447
cflags = sysconfig.get_config_var('CFLAGS') or ''
447-
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
448+
config_args = shlex.split(sysconfig.get_config_var('CONFIG_ARGS') or '')
449+
450+
def configured_with_sanitizer(name):
451+
with_option = f'--with-{name}-sanitizer'
452+
without_option = f'--without-{name}-sanitizer'
453+
enabled = False
454+
for arg in config_args:
455+
if arg == without_option or arg == f'{with_option}=no':
456+
enabled = False
457+
elif arg == with_option or arg.startswith(f'{with_option}='):
458+
enabled = True
459+
return enabled
460+
448461
memory_sanitizer = (
449462
'-fsanitize=memory' in cflags or
450-
'--with-memory-sanitizer' in config_args
463+
configured_with_sanitizer('memory')
451464
)
452465
address_sanitizer = (
453466
'-fsanitize=address' in cflags or
454-
'--with-address-sanitizer' in config_args
467+
configured_with_sanitizer('address')
455468
)
456469
ub_sanitizer = (
457470
'-fsanitize=undefined' in cflags or
458-
'--with-undefined-behavior-sanitizer' in config_args
471+
configured_with_sanitizer('undefined-behavior')
459472
)
460473
thread_sanitizer = (
461474
'-fsanitize=thread' in cflags or
462-
'--with-thread-sanitizer' in config_args
475+
configured_with_sanitizer('thread')
463476
)
464477
function_sanitizer = (
465478
'-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: 54 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,14 +3496,14 @@ AC_MSG_CHECKING([for --with-address-sanitizer])
34963496
AC_ARG_WITH([address_sanitizer],
34973497
AS_HELP_STRING([--with-address-sanitizer],
34983498
[enable AddressSanitizer memory error detector, 'asan' (default is no)]),
3499-
[
3500-
AC_MSG_RESULT([$withval])
3499+
[], [with_address_sanitizer=no])
3500+
AC_MSG_RESULT([$with_address_sanitizer])
3501+
AS_VAR_IF([with_address_sanitizer], [no], [], [
35013502
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
35023503
LDFLAGS="-fsanitize=address $LDFLAGS"
35033504
# ASan works by controlling memory allocation, our own malloc interferes.
35043505
with_pymalloc="no"
3505-
],
3506-
[AC_MSG_RESULT([no])])
3506+
])
35073507

35083508
AC_MSG_CHECKING([for --with-memory-sanitizer])
35093509
AC_ARG_WITH(
@@ -3512,16 +3512,16 @@ AC_ARG_WITH(
35123512
[--with-memory-sanitizer],
35133513
[enable MemorySanitizer allocation error detector, 'msan' (default is no)]
35143514
)],
3515-
[
3516-
AC_MSG_RESULT([$withval])
3515+
[], [with_memory_sanitizer=no])
3516+
AC_MSG_RESULT([$with_memory_sanitizer])
3517+
AS_VAR_IF([with_memory_sanitizer], [no], [], [
35173518
AX_CHECK_COMPILE_FLAG([-fsanitize=memory],[
35183519
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
35193520
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
35203521
],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])])
35213522
# MSan works by controlling memory allocation, our own malloc interferes.
35223523
with_pymalloc="no"
3523-
],
3524-
[AC_MSG_RESULT([no])])
3524+
])
35253525

35263526
AC_MSG_CHECKING([for --with-undefined-behavior-sanitizer])
35273527
AC_ARG_WITH(
@@ -3530,15 +3530,14 @@ AC_ARG_WITH(
35303530
[--with-undefined-behavior-sanitizer],
35313531
[enable UndefinedBehaviorSanitizer undefined behaviour detector, 'ubsan' (default is no)]
35323532
)],
3533-
[
3534-
AC_MSG_RESULT([$withval])
3533+
[], [with_undefined_behavior_sanitizer=no])
3534+
AC_MSG_RESULT([$with_undefined_behavior_sanitizer])
3535+
AS_VAR_IF([with_undefined_behavior_sanitizer], [no], [
3536+
with_ubsan="no"
3537+
], [
35353538
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
35363539
LDFLAGS="-fsanitize=undefined $LDFLAGS"
35373540
with_ubsan="yes"
3538-
],
3539-
[
3540-
AC_MSG_RESULT([no])
3541-
with_ubsan="no"
35423541
])
35433542

35443543
AC_MSG_CHECKING([for --with-thread-sanitizer])
@@ -3548,15 +3547,14 @@ AC_ARG_WITH(
35483547
[--with-thread-sanitizer],
35493548
[enable ThreadSanitizer data race detector, 'tsan' (default is no)]
35503549
)],
3551-
[
3552-
AC_MSG_RESULT([$withval])
3550+
[], [with_thread_sanitizer=no])
3551+
AC_MSG_RESULT([$with_thread_sanitizer])
3552+
AS_VAR_IF([with_thread_sanitizer], [no], [
3553+
with_tsan="no"
3554+
], [
35533555
BASECFLAGS="-fsanitize=thread $BASECFLAGS"
35543556
LDFLAGS="-fsanitize=thread $LDFLAGS"
35553557
with_tsan="yes"
3556-
],
3557-
[
3558-
AC_MSG_RESULT([no])
3559-
with_tsan="no"
35603558
])
35613559

35623560
# Set info about shared libraries.

0 commit comments

Comments
 (0)