diff --git a/Misc/NEWS.d/next/Build/2023-03-20-09-47-46.gh-issue-102838.k3MRiC.rst b/Misc/NEWS.d/next/Build/2023-03-20-09-47-46.gh-issue-102838.k3MRiC.rst new file mode 100644 index 00000000000000..2a1c3c8617241c --- /dev/null +++ b/Misc/NEWS.d/next/Build/2023-03-20-09-47-46.gh-issue-102838.k3MRiC.rst @@ -0,0 +1,2 @@ +Ignore acceptable access of an uninitialized value to fix building +``--with-memory-sanitizer``. Patch by Illia Volochii. diff --git a/Misc/README b/Misc/README index 3dab768ba1a7a4..798ad7f14f65fc 100644 --- a/Misc/README +++ b/Misc/README @@ -19,6 +19,7 @@ README The file you're reading now README.AIX Information about using Python on AIX README.coverity Information about running Coverity's Prevent on Python README.valgrind Information for Valgrind users, see valgrind-python.supp +sanitize-ignorelist.txt Entities to be ignored by sanitizers SpecialBuilds.txt Describes extra symbols you can set for debug builds svnmap.txt Map of old SVN revs and branches to hg changeset ids, help history-digging diff --git a/Misc/sanitize-ignorelist.txt b/Misc/sanitize-ignorelist.txt new file mode 100644 index 00000000000000..ae39f572cfb216 --- /dev/null +++ b/Misc/sanitize-ignorelist.txt @@ -0,0 +1,12 @@ +# +# This is a file listing entities to be ignored by sanitizers. +# https://clang.llvm.org/docs/SanitizerSpecialCaseList.html +# + +[memory] +# medium_value called by maybe_small_long accesses an uninitialized +# integer in the case of PyLong of size 0, but the integer is then +# multiplied by zero immediately, so the lack of initialisation has no +# adverse effect. +# https://github.com/python/cpython/issues/102509 +fun:maybe_small_long diff --git a/configure b/configure index 7aad4fe89e3cbf..8b0bd636fd75bf 100755 --- a/configure +++ b/configure @@ -11330,8 +11330,8 @@ fi $as_echo "$ax_cv_check_cflags___fsanitize_memory" >&6; } if test "x$ax_cv_check_cflags___fsanitize_memory" = xyes; then : -BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS" -LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS" +BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -fsanitize-ignorelist=Misc/sanitize-ignorelist.txt $BASECFLAGS" +LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-ignorelist=Misc/sanitize-ignorelist.txt $LDFLAGS" else as_fn_error $? "The selected compiler doesn't support memory sanitizer" "$LINENO" 5 diff --git a/configure.ac b/configure.ac index 115998e0753b26..36d63eded91289 100644 --- a/configure.ac +++ b/configure.ac @@ -3102,8 +3102,8 @@ AC_ARG_WITH(memory_sanitizer, [ AC_MSG_RESULT($withval) AX_CHECK_COMPILE_FLAG([-fsanitize=memory],[ -BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS" -LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS" +BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -fsanitize-ignorelist=Misc/sanitize-ignorelist.txt $BASECFLAGS" +LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-ignorelist=Misc/sanitize-ignorelist.txt $LDFLAGS" ],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])]) # MSan works by controlling memory allocation, our own malloc interferes. with_pymalloc="no"