mirror of
https://github.com/python/cpython.git
synced 2026-10-28 10:25:05 +08:00
gh-157354: Honor --with-<name>-sanitizer=no and --without-<name>-sanitizer in configure (#157355)
This commit is contained in:
1 parent
d59d96853b
commit
ea3a97f245
4 files changed
+110
-69
No files matched your search
@@ -11,6 +11,7 @@ import logging
|
||||
import _opcode
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import stat
|
||||
import sys
|
||||
import sysconfig
|
||||
@@ -469,27 +470,39 @@ def check_sanitizer(*, address=False, hwaddress=False, memory=False, ub=False,
|
||||
|
||||
|
||||
cflags = sysconfig.get_config_var('CFLAGS') or ''
|
||||
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
|
||||
config_args = shlex.split(sysconfig.get_config_var('CONFIG_ARGS') or '')
|
||||
|
||||
def configured_with_sanitizer(name):
|
||||
with_option = f'--with-{name}-sanitizer'
|
||||
without_option = f'--without-{name}-sanitizer'
|
||||
enabled = False
|
||||
for arg in config_args:
|
||||
if arg == without_option or arg == f'{with_option}=no':
|
||||
enabled = False
|
||||
elif arg == with_option or arg.startswith(f'{with_option}='):
|
||||
enabled = True
|
||||
return enabled
|
||||
|
||||
memory_sanitizer = (
|
||||
'-fsanitize=memory' in cflags or
|
||||
'--with-memory-sanitizer' in config_args
|
||||
configured_with_sanitizer('memory')
|
||||
)
|
||||
hwaddress_sanitizer = (
|
||||
'-fsanitize=hwaddress' in cflags or
|
||||
'--with-hwaddress-sanitizer' in config_args
|
||||
configured_with_sanitizer('hwaddress')
|
||||
)
|
||||
address_sanitizer = (
|
||||
'-fsanitize=address' in cflags or
|
||||
'--with-address-sanitizer' in config_args or
|
||||
configured_with_sanitizer('address') or
|
||||
hwaddress_sanitizer
|
||||
)
|
||||
ub_sanitizer = (
|
||||
'-fsanitize=undefined' in cflags or
|
||||
'--with-undefined-behavior-sanitizer' in config_args
|
||||
configured_with_sanitizer('undefined-behavior')
|
||||
)
|
||||
thread_sanitizer = (
|
||||
'-fsanitize=thread' in cflags or
|
||||
'--with-thread-sanitizer' in config_args
|
||||
configured_with_sanitizer('thread')
|
||||
)
|
||||
function_sanitizer = (
|
||||
'-fsanitize=function' in cflags
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Fix the :samp:`--with-{name}-sanitizer=no` and :samp:`--without-{name}-sanitizer`
|
||||
:program:`configure` options enabling the sanitizer instead of disabling it.
|
||||
@@ -14369,8 +14369,18 @@ printf %s "checking for --with-address-sanitizer... " >&6; }
|
||||
if test ${with_address_sanitizer+y}
|
||||
then :
|
||||
withval=$with_address_sanitizer;
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $withval" >&5
|
||||
printf "%s\n" "$withval" >&6; }
|
||||
else case e in #(
|
||||
e) with_address_sanitizer=no ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_address_sanitizer" >&5
|
||||
printf "%s\n" "$with_address_sanitizer" >&6; }
|
||||
if test "x$with_address_sanitizer" = xno
|
||||
then :
|
||||
|
||||
else case e in #(
|
||||
e)
|
||||
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
|
||||
LDFLAGS="-fsanitize=address $LDFLAGS"
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program links with -fsanitize=address" >&5
|
||||
@@ -14398,14 +14408,10 @@ esac
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.beam \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
|
||||
else case e in #(
|
||||
e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; } ;;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-hwaddress-sanitizer" >&5
|
||||
printf %s "checking for --with-hwaddress-sanitizer... " >&6; }
|
||||
|
||||
@@ -14413,8 +14419,18 @@ printf %s "checking for --with-hwaddress-sanitizer... " >&6; }
|
||||
if test ${with_hwaddress_sanitizer+y}
|
||||
then :
|
||||
withval=$with_hwaddress_sanitizer;
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $withval" >&5
|
||||
printf "%s\n" "$withval" >&6; }
|
||||
else case e in #(
|
||||
e) with_hwaddress_sanitizer=no ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_hwaddress_sanitizer" >&5
|
||||
printf "%s\n" "$with_hwaddress_sanitizer" >&6; }
|
||||
if test "x$with_hwaddress_sanitizer" = xno
|
||||
then :
|
||||
|
||||
else case e in #(
|
||||
e)
|
||||
hwasan_flags="-fsanitize=hwaddress"
|
||||
# x86-64 lacks address tagging, so HWASan needs the page aliasing mode there.
|
||||
# See gh-156049 and
|
||||
@@ -14453,14 +14469,10 @@ esac
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.beam \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
|
||||
else case e in #(
|
||||
e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; } ;;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-memory-sanitizer" >&5
|
||||
printf %s "checking for --with-memory-sanitizer... " >&6; }
|
||||
|
||||
@@ -14468,8 +14480,18 @@ printf %s "checking for --with-memory-sanitizer... " >&6; }
|
||||
if test ${with_memory_sanitizer+y}
|
||||
then :
|
||||
withval=$with_memory_sanitizer;
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $withval" >&5
|
||||
printf "%s\n" "$withval" >&6; }
|
||||
else case e in #(
|
||||
e) with_memory_sanitizer=no ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_memory_sanitizer" >&5
|
||||
printf "%s\n" "$with_memory_sanitizer" >&6; }
|
||||
if test "x$with_memory_sanitizer" = xno
|
||||
then :
|
||||
|
||||
else case e in #(
|
||||
e)
|
||||
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
|
||||
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program links with -fsanitize=memory" >&5
|
||||
@@ -14497,14 +14519,10 @@ esac
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.beam \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
|
||||
else case e in #(
|
||||
e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; } ;;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-undefined-behavior-sanitizer" >&5
|
||||
printf %s "checking for --with-undefined-behavior-sanitizer... " >&6; }
|
||||
|
||||
@@ -14512,8 +14530,20 @@ printf %s "checking for --with-undefined-behavior-sanitizer... " >&6; }
|
||||
if test ${with_undefined_behavior_sanitizer+y}
|
||||
then :
|
||||
withval=$with_undefined_behavior_sanitizer;
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $withval" >&5
|
||||
printf "%s\n" "$withval" >&6; }
|
||||
else case e in #(
|
||||
e) with_undefined_behavior_sanitizer=no ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_undefined_behavior_sanitizer" >&5
|
||||
printf "%s\n" "$with_undefined_behavior_sanitizer" >&6; }
|
||||
if test "x$with_undefined_behavior_sanitizer" = xno
|
||||
then :
|
||||
|
||||
with_ubsan="no"
|
||||
|
||||
else case e in #(
|
||||
e)
|
||||
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
|
||||
LDFLAGS="-fsanitize=undefined $LDFLAGS"
|
||||
with_ubsan="yes"
|
||||
@@ -14542,17 +14572,10 @@ esac
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.beam \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
|
||||
else case e in #(
|
||||
e)
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; }
|
||||
with_ubsan="no"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-thread-sanitizer" >&5
|
||||
printf %s "checking for --with-thread-sanitizer... " >&6; }
|
||||
|
||||
@@ -14560,8 +14583,20 @@ printf %s "checking for --with-thread-sanitizer... " >&6; }
|
||||
if test ${with_thread_sanitizer+y}
|
||||
then :
|
||||
withval=$with_thread_sanitizer;
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $withval" >&5
|
||||
printf "%s\n" "$withval" >&6; }
|
||||
else case e in #(
|
||||
e) with_thread_sanitizer=no ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_thread_sanitizer" >&5
|
||||
printf "%s\n" "$with_thread_sanitizer" >&6; }
|
||||
if test "x$with_thread_sanitizer" = xno
|
||||
then :
|
||||
|
||||
with_tsan="no"
|
||||
|
||||
else case e in #(
|
||||
e)
|
||||
BASECFLAGS="-fsanitize=thread $BASECFLAGS"
|
||||
LDFLAGS="-fsanitize=thread $LDFLAGS"
|
||||
with_tsan="yes"
|
||||
@@ -14590,17 +14625,10 @@ esac
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.beam \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
|
||||
else case e in #(
|
||||
e)
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; }
|
||||
with_tsan="no"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
# Set info about shared libraries.
|
||||
|
||||
|
||||
|
||||
+22
-24
@@ -3728,8 +3728,9 @@ AC_MSG_CHECKING([for --with-address-sanitizer])
|
||||
AC_ARG_WITH([address_sanitizer],
|
||||
AS_HELP_STRING([--with-address-sanitizer],
|
||||
[enable AddressSanitizer memory error detector, 'asan' (default is no)]),
|
||||
[
|
||||
AC_MSG_RESULT([$withval])
|
||||
[], [with_address_sanitizer=no])
|
||||
AC_MSG_RESULT([$with_address_sanitizer])
|
||||
AS_VAR_IF([with_address_sanitizer], [no], [], [
|
||||
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
|
||||
LDFLAGS="-fsanitize=address $LDFLAGS"
|
||||
AC_MSG_CHECKING([whether a program links with -fsanitize=address])
|
||||
@@ -3737,8 +3738,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([cannot link with -fsanitize=address: the compiler does not support AddressSanitizer or its runtime library is not installed; see config.log])])
|
||||
],
|
||||
[AC_MSG_RESULT([no])])
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING([for --with-hwaddress-sanitizer])
|
||||
AC_ARG_WITH(
|
||||
@@ -3747,8 +3747,9 @@ AC_ARG_WITH(
|
||||
[--with-hwaddress-sanitizer],
|
||||
[enable HWAddressSanitizer memory error detector, 'hwasan' (default is no)]
|
||||
)],
|
||||
[
|
||||
AC_MSG_RESULT([$withval])
|
||||
[], [with_hwaddress_sanitizer=no])
|
||||
AC_MSG_RESULT([$with_hwaddress_sanitizer])
|
||||
AS_VAR_IF([with_hwaddress_sanitizer], [no], [], [
|
||||
hwasan_flags="-fsanitize=hwaddress"
|
||||
# x86-64 lacks address tagging, so HWASan needs the page aliasing mode there.
|
||||
# See gh-156049 and
|
||||
@@ -3763,8 +3764,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([cannot link with $hwasan_flags: the compiler does not support HWAddressSanitizer or its runtime library is not installed; see config.log])])
|
||||
],
|
||||
[AC_MSG_RESULT([no])])
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING([for --with-memory-sanitizer])
|
||||
AC_ARG_WITH(
|
||||
@@ -3773,8 +3773,9 @@ AC_ARG_WITH(
|
||||
[--with-memory-sanitizer],
|
||||
[enable MemorySanitizer allocation error detector, 'msan' (default is no)]
|
||||
)],
|
||||
[
|
||||
AC_MSG_RESULT([$withval])
|
||||
[], [with_memory_sanitizer=no])
|
||||
AC_MSG_RESULT([$with_memory_sanitizer])
|
||||
AS_VAR_IF([with_memory_sanitizer], [no], [], [
|
||||
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
|
||||
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
|
||||
AC_MSG_CHECKING([whether a program links with -fsanitize=memory])
|
||||
@@ -3782,8 +3783,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([cannot link with -fsanitize=memory: the compiler does not support MemorySanitizer or its runtime library is not installed; see config.log])])
|
||||
],
|
||||
[AC_MSG_RESULT([no])])
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING([for --with-undefined-behavior-sanitizer])
|
||||
AC_ARG_WITH(
|
||||
@@ -3792,8 +3792,11 @@ AC_ARG_WITH(
|
||||
[--with-undefined-behavior-sanitizer],
|
||||
[enable UndefinedBehaviorSanitizer undefined behaviour detector, 'ubsan' (default is no)]
|
||||
)],
|
||||
[
|
||||
AC_MSG_RESULT([$withval])
|
||||
[], [with_undefined_behavior_sanitizer=no])
|
||||
AC_MSG_RESULT([$with_undefined_behavior_sanitizer])
|
||||
AS_VAR_IF([with_undefined_behavior_sanitizer], [no], [
|
||||
with_ubsan="no"
|
||||
], [
|
||||
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
|
||||
LDFLAGS="-fsanitize=undefined $LDFLAGS"
|
||||
with_ubsan="yes"
|
||||
@@ -3802,10 +3805,6 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([cannot link with -fsanitize=undefined: the compiler does not support UndefinedBehaviorSanitizer or its runtime library is not installed; see config.log])])
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT([no])
|
||||
with_ubsan="no"
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING([for --with-thread-sanitizer])
|
||||
@@ -3815,8 +3814,11 @@ AC_ARG_WITH(
|
||||
[--with-thread-sanitizer],
|
||||
[enable ThreadSanitizer data race detector, 'tsan' (default is no)]
|
||||
)],
|
||||
[
|
||||
AC_MSG_RESULT([$withval])
|
||||
[], [with_thread_sanitizer=no])
|
||||
AC_MSG_RESULT([$with_thread_sanitizer])
|
||||
AS_VAR_IF([with_thread_sanitizer], [no], [
|
||||
with_tsan="no"
|
||||
], [
|
||||
BASECFLAGS="-fsanitize=thread $BASECFLAGS"
|
||||
LDFLAGS="-fsanitize=thread $LDFLAGS"
|
||||
with_tsan="yes"
|
||||
@@ -3825,10 +3827,6 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([cannot link with -fsanitize=thread: the compiler does not support ThreadSanitizer or its runtime library is not installed; see config.log])])
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT([no])
|
||||
with_tsan="no"
|
||||
])
|
||||
|
||||
# Set info about shared libraries.
|
||||
|
||||
Reference in new issue
Block a user