Skip to content

Commit 727b0d3

Browse files
autotools: Disable eager MSan in ctime_tests
Co-authored-by: Hennadii Stepanov <[email protected]>
1 parent 06bff6d commit 727b0d3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

build-aux/m4/bitcoin_secp.m4

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ fi
4545
AC_MSG_RESULT($has_valgrind)
4646
])
4747

48+
AC_DEFUN([SECP_MSAN_CHECK], [
49+
AC_MSG_CHECKING(whether MemorySanitizer is enabled)
50+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
51+
#if defined(__has_feature)
52+
# if __has_feature(memory_sanitizer)
53+
# error "MemorySanitizer is enabled."
54+
# endif
55+
#endif
56+
]])], [msan_enabled=no], [msan_enabled=yes])
57+
AC_MSG_RESULT([$msan_enabled])
58+
])
59+
4860
dnl SECP_TRY_APPEND_CFLAGS(flags, VAR)
4961
dnl Append flags to VAR if CC accepts them.
5062
AC_DEFUN([SECP_TRY_APPEND_CFLAGS], [

configure.ac

+21
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ if test x"$enable_ctime_tests" = x"auto"; then
247247
enable_ctime_tests=$enable_valgrind
248248
fi
249249

250+
print_msan_notice=no
251+
if test x"$enable_ctime_tests" = x"yes" && test x"$GCC" = x"yes"; then
252+
SECP_MSAN_CHECK
253+
# MSan on Clang >=16 reports unitialized memory in function parameters and return values, even if
254+
# the uninitalized variable is never actually "used". This is called "eager" checking, and it's
255+
# sounds like good idea for normal use of MSan. However, it yields many false positives in the
256+
# ctime_tests because many return values depend on secret (i.e., "uninitialized") values, and
257+
# we're only interested in detecting branches (which count as "uses") on secret data.
258+
if test x"$msan_enabled" = x"yes"; then
259+
SECP_TRY_APPEND_CFLAGS([-fno-sanitize-memory-param-retval], SECP_CFLAGS)
260+
fi
261+
print_msan_notice=yes
262+
fi
263+
250264
if test x"$enable_coverage" = x"yes"; then
251265
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOVERAGE=1"
252266
SECP_CFLAGS="-O0 --coverage $SECP_CFLAGS"
@@ -492,3 +506,10 @@ echo " CPPFLAGS = $CPPFLAGS"
492506
echo " SECP_CFLAGS = $SECP_CFLAGS"
493507
echo " CFLAGS = $CFLAGS"
494508
echo " LDFLAGS = $LDFLAGS"
509+
510+
if test x"$print_msan_notice" = x"yes"; then
511+
echo
512+
echo "Note:"
513+
echo " MemorySanitizer detected, tried to add -fno-sanitize-memory-param-retval to SECP_CFLAGS"
514+
echo " to avoid false positives in ctime_tests. Pass --disable-ctime-tests to avoid this."
515+
fi

0 commit comments

Comments
 (0)