8000 Add configure flags for msan and ubsan. · python/cpython@f0184ab · GitHub
[go: up one dir, main page]

Skip to content

Commit f0184ab

Browse files
committed
Add configure flags for msan and ubsan.
This makes it easier to enable clang's memory and undefined behavior sanitizers on a build without manually setting CFLAGS and LDFLAGS. This also encodes the detail that address sanitizer and memory sanitizer should disable pymalloc.
1 parent 0f221d0 commit f0184ab

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

configure

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ enable_optimizations
819819
with_lto
820820
with_hash_algorithm
821821
with_address_sanitizer
822+
with_memory_sanitizer
823+
with_undefined_behavior_sanitizer
822824
with_libs
823825
with_system_expat
824826
with_system_ffi
@@ -1515,7 +1517,10 @@ Optional Packages:
15151517
--with-hash-algorithm=[fnv|siphash24]
15161518
select hash algorithm
15171519
--with-address-sanitizer
1518-
enable AddressSanitizer
1520+
enable AddressSanitizer (asan)
1521+
--with-memory-sanitizer enable MemorySanitizer (msan)
1522+
--with-undefined-behavior-sanitizer
1523+
enable UndefinedBehaviorSanitizer (ubsan)
15191524
--with-libs='lib1 ...' link against additional libs
15201525
--with-system-expat build pyexpat module using an installed expat
15211526
library
@@ -10038,6 +10043,44 @@ if test "${with_address_sanitizer+set}" = set; then :
1003810043
$as_echo "$withval" >&6; }
1003910044
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
1004010045
LDFLAGS="-fsanitize=address $LDFLAGS"
10046+
# ASan works by controlling memory allocation, our own malloc interferes.
10047+
with_pymalloc="no"
10048+
10049+
else
10050+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
10051+
$as_echo "no" >&6; }
10052+
fi
10053+
10054+
10055+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-memory-sanitizer" >&5
10056+
$as_echo_n "checking for --with-memory-sanitizer... " >&6; }
10057+
10058+
# Check whether --with-memory_sanitizer was given.
10059+
if test "${with_memory_sanitizer+set}" = set; then :
10060+
withval=$with_memory_sanitizer;
10061+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $withval" >&5
10062+
$as_echo "$withval" >&6; }
10063+
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
10064+
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
10065+
# MSan works by controlling memory allocation, our own malloc interferes.
10066+
with_pymalloc="no"
10067+
10068+
else
10069+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
10070+
$as_echo "no" >&6; }
10071+
fi
10072+
10073+
10074+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-undefined-behavior-sanitizer" >&5
10075+
$as_echo_n "checking for --with-undefined-behavior-sanitizer... " >&6; }
10076+
10077+
# Check whether --with-undefined_behavior_sanitizer was given.
10078+
if test "${with_undefined_behavior_sanitizer+set}" = set; then :
10079+
withval=$with_undefined_behavior_sanitizer;
10080+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $withval" >&5
10081+
$as_echo "$withval" >&6; }
10082+
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
10083+
LDFLAGS="-fsanitize=undefined $LDFLAGS"
1004110084

1004210085
else
1004310086
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5

configure.ac

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2854,11 +2854,37 @@ esac
28542854
AC_MSG_CHECKING(for --with-address-sanitizer)
28552855
AC_ARG_WITH(address_sanitizer,
28562856
AS_HELP_STRING([--with-address-sanitizer],
2857-
[enable AddressSanitizer]),
2857+
[enable AddressSanitizer (asan)]),
28582858
[
28592859
AC_MSG_RESULT($withval)
28602860
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
28612861
LDFLAGS="-fsanitize=address $LDFLAGS"
2862+
# ASan works by controlling memory allocation, our own malloc interferes.
2863+
with_pymalloc="no"
2864+
],
2865+
[AC_MSG_RESULT(no)])
2866+
2867+
AC_MSG_CHECKING(for --with-memory-sanitizer)
2868+
AC_ARG_WITH(memory_sanitizer,
2869+
AS_HELP_STRING([--with-memory-sanitizer],
2870+
[enable MemorySanitizer (msan)]),
2871+
[
2872+
AC_MSG_RESULT($withval)
2873+
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
2874+
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
2875+
# MSan works by controlling memory allocation, our own malloc interferes.
2876+
with_pymalloc="no"
2877+
],
2878+
[AC_MSG_RESULT(no)])
2879+
2880+
AC_MSG_CHECKING(for --with-undefined-behavior-sanitizer)
2881+
AC_ARG_WITH(undefined_behavior_sanitizer,
2882+
AS_HELP_STRING([--with-undefined-behavior-sanitizer],
2883+
[enable UndefinedBehaviorSanitizer (ubsan)]),
2884+
[
2885+
AC_MSG_RESULT($withval)
2886+
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
2887+
LDFLAGS="-fsanitize=undefined $LDFLAGS"
28622888
],
28632889
[AC_MSG_RESULT(no)])
28642890

0 commit comments

Comments
 (0)
0