Skip to content

Commit 142aa9b

Browse files
authored
[3.14] gh-157354: Honor --with-<name>-sanitizer=no and --without-<name>-sanitizer in configure (GH-157355) (#160656)
1 parent bc8294c commit 142aa9b

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
@@ -443,22 +444,34 @@ def check_sanitizer(*, address=False, memory=False, ub=False, thread=False,
443444

444445

445446
cflags = sysconfig.get_config_var('CFLAGS') or ''
446-
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
447+
config_args = shlex.split(sysconfig.get_config_var('CONFIG_ARGS') or '')
448+
449+
def configured_with_sanitizer(name):
450+
with_option = f'--with-{name}-sanitizer'
451+
without_option = f'--without-{name}-sanitizer'
452+
enabled = False
453+
for arg in config_args:
454+
if arg == without_option or arg == f'{with_option}=no':
455+
enabled = False
456+
elif arg == with_option or arg.startswith(f'{with_option}='):
457+
enabled = True
458+
return enabled
459+
447460
memory_sanitizer = (
448461
'-fsanitize=memory' in cflags or
449-
'--with-memory-sanitizer' in config_args
462+
configured_with_sanitizer('memory')
450463
)
451464
address_sanitizer = (
452465
'-fsanitize=address' in cflags or
453-
'--with-address-sanitizer' in config_args
466+
configured_with_sanitizer('address')
454467
)
455468
ub_sanitizer = (
456469
'-fsanitize=undefined' in cflags or
457-
'--with-undefined-behavior-sanitizer' in config_args
470+
configured_with_sanitizer('undefined-behavior')
458471
)
459472
thread_sanitizer = (
460473
'-fsanitize=thread' in cflags or
461-
'--with-thread-sanitizer' in config_args
474+
configured_with_sanitizer('thread')
462475
)
463476
function_sanitizer = (
464477
'-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
@@ -3401,14 +3401,14 @@ AC_MSG_CHECKING([for --with-address-sanitizer])
34013401
AC_ARG_WITH([address_sanitizer],
34023402
AS_HELP_STRING([--with-address-sanitizer],
34033403
[enable AddressSanitizer memory error detector, 'asan' (default is no)]),
3404-
[
3405-
AC_MSG_RESULT([$withval])
3404+
[], [with_address_sanitizer=no])
3405+
AC_MSG_RESULT([$with_address_sanitizer])
3406+
AS_VAR_IF([with_address_sanitizer], [no], [], [
34063407
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
34073408
LDFLAGS="-fsanitize=address $LDFLAGS"
34083409
# ASan works by controlling memory allocation, our own malloc interferes.
34093410
with_pymalloc="no"
3410-
],
3411-
[AC_MSG_RESULT([no])])
3411+
])
34123412

34133413
AC_MSG_CHECKING([for --with-memory-sanitizer])
34143414
AC_ARG_WITH(
@@ -3417,16 +3417,16 @@ AC_ARG_WITH(
34173417
[--with-memory-sanitizer],
34183418
[enable MemorySanitizer allocation error detector, 'msan' (default is no)]
34193419
)],
3420-
[
3421-
AC_MSG_RESULT([$withval])
3420+
[], [with_memory_sanitizer=no])
3421+
AC_MSG_RESULT([$with_memory_sanitizer])
3422+
AS_VAR_IF([with_memory_sanitizer], [no], [], [
34223423
AX_CHECK_COMPILE_FLAG([-fsanitize=memory],[
34233424
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
34243425
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
34253426
],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])])
34263427
# MSan works by controlling memory allocation, our own malloc interferes.
34273428
with_pymalloc="no"
3428-
],
3429-
[AC_MSG_RESULT([no])])
3429+
])
34303430

34313431
AC_MSG_CHECKING([for --with-undefined-behavior-sanitizer])
34323432
AC_ARG_WITH(
@@ -3435,15 +3435,14 @@ AC_ARG_WITH(
34353435
[--with-undefined-behavior-sanitizer],
34363436
[enable UndefinedBehaviorSanitizer undefined behaviour detector, 'ubsan' (default is no)]
34373437
)],
3438-
[
3439-
AC_MSG_RESULT([$withval])
3438+
[], [with_undefined_behavior_sanitizer=no])
3439+
AC_MSG_RESULT([$with_undefined_behavior_sanitizer])
3440+
AS_VAR_IF([with_undefined_behavior_sanitizer], [no], [
3441+
with_ubsan="no"
3442+
], [
34403443
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
34413444
LDFLAGS="-fsanitize=undefined $LDFLAGS"
34423445
with_ubsan="yes"
3443-
],
3444-
[
3445-
AC_MSG_RESULT([no])
3446-
with_ubsan="no"
34473446
])
34483447

34493448
AC_MSG_CHECKING([for --with-thread-sanitizer])
@@ -3453,15 +3452,14 @@ AC_ARG_WITH(
34533452
[--with-thread-sanitizer],
34543453
[enable ThreadSanitizer data race detector, 'tsan' (default is no)]
34553454
)],
3456-
[
3457-
AC_MSG_RESULT([$withval])
3455+
[], [with_thread_sanitizer=no])
3456+
AC_MSG_RESULT([$with_thread_sanitizer])
3457+
AS_VAR_IF([with_thread_sanitizer], [no], [
3458+
with_tsan="no"
3459+
], [
34583460
BASECFLAGS="-fsanitize=thread $BASECFLAGS"
34593461
LDFLAGS="-fsanitize=thread $LDFLAGS"
34603462
with_tsan="yes"
3461-
],
3462-
[
3463-
AC_MSG_RESULT([no])
3464-
with_tsan="no"
34653463
])
34663464

34673465
# Set info about shared libraries.

0 commit comments

Comments
 (0)