https://github.com/python/cpython/commit/b94fdb726156b15e1017e7b9c76153a1254f5f7b
commit: b94fdb726156b15e1017e7b9c76153a1254f5f7b
branch: main
author: Vasiliy Kiryanov <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-10-21T19:20:14Z
summary:

gh-75382: Fail configure early if a sanitizer cannot be linked (#159496)

Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Misc/NEWS.d/next/Build/2026-10-15-19-09-31.gh-issue-75382.DSrcra.rst
M configure
M configure.ac

diff --git 
a/Misc/NEWS.d/next/Build/2026-10-15-19-09-31.gh-issue-75382.DSrcra.rst 
b/Misc/NEWS.d/next/Build/2026-10-15-19-09-31.gh-issue-75382.DSrcra.rst
new file mode 100644
index 00000000000000..eb295fd292a611
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2026-10-15-19-09-31.gh-issue-75382.DSrcra.rst
@@ -0,0 +1,4 @@
+Make :program:`configure` fail early with a clear error when a
+``--with-*-sanitizer`` option is used but a program cannot be linked with
+the corresponding ``-fsanitize`` flag, for example because the sanitizer
+runtime library is not installed.
diff --git a/configure b/configure
index 38fd8575530e8a..ce630035cb053a 100755
--- a/configure
+++ b/configure
@@ -14159,6 +14159,31 @@ then :
 printf "%s\n" "$withval" >&6; }
 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
+printf %s "checking whether a program links with -fsanitize=address... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+else case e in #(
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+   as_fn_error $? "cannot link with -fsanitize=address: the compiler does not 
support AddressSanitizer or its runtime library is not installed; see 
config.log" "$LINENO" 5 ;;
+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
@@ -14187,17 +14212,11 @@ case $host_cpu in #(
   *) :
      ;;
 esac
-as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags__$hwasan_flags" | sed 
"$as_sed_sh"`
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler 
accepts $hwasan_flags" >&5
-printf %s "checking whether C compiler accepts $hwasan_flags... " >&6; }
-if eval test \${$as_CACHEVAR+y}
-then :
-  printf %s "(cached) " >&6
-else case e in #(
-  e)
-  ax_check_save_flags=$CFLAGS
-  CFLAGS="$CFLAGS  $hwasan_flags"
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+BASECFLAGS="$hwasan_flags -fno-omit-frame-pointer $BASECFLAGS"
+LDFLAGS="$hwasan_flags $LDFLAGS"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program links 
with $hwasan_flags" >&5
+printf %s "checking whether a program links with $hwasan_flags... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 int
@@ -14208,31 +14227,18 @@ main (void)
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"
-then :
-  eval "$as_CACHEVAR=yes"
-else case e in #(
-  e) eval "$as_CACHEVAR=no" ;;
-esac
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
-  CFLAGS=$ax_check_save_flags ;;
-esac
-fi
-eval ac_res=\$$as_CACHEVAR
-              { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" 
>&5
-printf "%s\n" "$ac_res" >&6; }
-if eval test \"x\$"$as_CACHEVAR"\" = x"yes"
+if ac_fn_c_try_link "$LINENO"
 then :
-
-BASECFLAGS="$hwasan_flags -fno-omit-frame-pointer $BASECFLAGS"
-LDFLAGS="$hwasan_flags $LDFLAGS"
-
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
 else case e in #(
-  e) as_fn_error $? "The selected compiler doesn't support hardware address 
sanitizer" "$LINENO" 5 ;;
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+   as_fn_error $? "cannot link with $hwasan_flags: the compiler does not 
support HWAddressSanitizer or its runtime library is not installed; see 
config.log" "$LINENO" 5 ;;
 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
@@ -14250,16 +14256,11 @@ then :
   withval=$with_memory_sanitizer;
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $withval" >&5
 printf "%s\n" "$withval" >&6; }
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler 
accepts -fsanitize=memory" >&5
-printf %s "checking whether C compiler accepts -fsanitize=memory... " >&6; }
-if test ${ax_cv_check_cflags___fsanitize_memory+y}
-then :
-  printf %s "(cached) " >&6
-else case e in #(
-  e)
-  ax_check_save_flags=$CFLAGS
-  CFLAGS="$CFLAGS  -fsanitize=memory"
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+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
+printf %s "checking whether a program links with -fsanitize=memory... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 int
@@ -14270,30 +14271,18 @@ main (void)
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"
-then :
-  ax_cv_check_cflags___fsanitize_memory=yes
-else case e in #(
-  e) ax_cv_check_cflags___fsanitize_memory=no ;;
-esac
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
-  CFLAGS=$ax_check_save_flags ;;
-esac
-fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: 
$ax_cv_check_cflags___fsanitize_memory" >&5
-printf "%s\n" "$ax_cv_check_cflags___fsanitize_memory" >&6; }
-if test "x$ax_cv_check_cflags___fsanitize_memory" = xyes
+if ac_fn_c_try_link "$LINENO"
 then :
-
-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}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
 else case e in #(
-  e) as_fn_error $? "The selected compiler doesn't support memory sanitizer" 
"$LINENO" 5 ;;
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+   as_fn_error $? "cannot link with -fsanitize=memory: the compiler does not 
support MemorySanitizer or its runtime library is not installed; see 
config.log" "$LINENO" 5 ;;
 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
@@ -14314,6 +14303,31 @@ printf "%s\n" "$withval" >&6; }
 BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
 LDFLAGS="-fsanitize=undefined $LDFLAGS"
 with_ubsan="yes"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program links 
with -fsanitize=undefined" >&5
+printf %s "checking whether a program links with -fsanitize=undefined... " 
>&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+else case e in #(
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+   as_fn_error $? "cannot link with -fsanitize=undefined: the compiler does 
not support UndefinedBehaviorSanitizer or its runtime library is not installed; 
see config.log" "$LINENO" 5 ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext conftest.$ac_ext
 
 else case e in #(
   e)
@@ -14337,6 +14351,31 @@ printf "%s\n" "$withval" >&6; }
 BASECFLAGS="-fsanitize=thread $BASECFLAGS"
 LDFLAGS="-fsanitize=thread $LDFLAGS"
 with_tsan="yes"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program links 
with -fsanitize=thread" >&5
+printf %s "checking whether a program links with -fsanitize=thread... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"
+then :
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+printf "%s\n" "yes" >&6; }
+else case e in #(
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
+printf "%s\n" "no" >&6; }
+   as_fn_error $? "cannot link with -fsanitize=thread: the compiler does not 
support ThreadSanitizer or its runtime library is not installed; see 
config.log" "$LINENO" 5 ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext conftest.$ac_ext
 
 else case e in #(
   e)
diff --git a/configure.ac b/configure.ac
index 777ced94454594..51367b254c4590 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3527,6 +3527,11 @@ AC_ARG_WITH([address_sanitizer],
 AC_MSG_RESULT([$withval])
 BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
 LDFLAGS="-fsanitize=address $LDFLAGS"
+AC_MSG_CHECKING([whether a program links with -fsanitize=address])
+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])])
 
@@ -3546,10 +3551,13 @@ hwasan_flags="-fsanitize=hwaddress"
 AS_CASE([$host_cpu],
   [x86_64|amd64], [hwasan_flags="$hwasan_flags 
-fsanitize-hwaddress-experimental-aliasing"]
 )
-AX_CHECK_COMPILE_FLAG([$hwasan_flags],[
 BASECFLAGS="$hwasan_flags -fno-omit-frame-pointer $BASECFLAGS"
 LDFLAGS="$hwasan_flags $LDFLAGS"
-],[AC_MSG_ERROR([The selected compiler doesn't support hardware address 
sanitizer])])
+AC_MSG_CHECKING([whether a program links with $hwasan_flags])
+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])])
 
@@ -3562,10 +3570,13 @@ AC_ARG_WITH(
   )],
 [
 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"
-],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])])
+AC_MSG_CHECKING([whether a program links with -fsanitize=memory])
+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])])
 
@@ -3581,6 +3592,11 @@ AC_MSG_RESULT([$withval])
 BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
 LDFLAGS="-fsanitize=undefined $LDFLAGS"
 with_ubsan="yes"
+AC_MSG_CHECKING([whether a program links with -fsanitize=undefined])
+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])
@@ -3599,6 +3615,11 @@ AC_MSG_RESULT([$withval])
 BASECFLAGS="-fsanitize=thread $BASECFLAGS"
 LDFLAGS="-fsanitize=thread $LDFLAGS"
 with_tsan="yes"
+AC_MSG_CHECKING([whether a program links with -fsanitize=thread])
+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])

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to