From 1b2b79912db32e20299f4256ded3a692945d27cc Mon Sep 17 00:00:00 2001 From: Vasiliy Kiryanov Date: Thu, 15 Oct 2026 19:09:43 -0400 Subject: [PATCH] gh-75382: Fail configure early if a sanitizer cannot be linked Link a test program after each --with-*-sanitizer option and stop with a clear error if the flag is unsupported or the runtime is missing. --- ...6-10-15-19-09-31.gh-issue-75382.DSrcra.rst | 5 + configure | 163 +++++++++++------- configure.ac | 29 +++- 3 files changed, 131 insertions(+), 66 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2026-10-15-19-09-31.gh-issue-75382.DSrcra.rst 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 000000000000000..b8083d1e2e6268e --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-10-15-19-09-31.gh-issue-75382.DSrcra.rst @@ -0,0 +1,5 @@ +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. Previously the failure surfaced later as +unrelated errors. diff --git a/configure b/configure index 217d8e135600e16..29c3e85b5855dda 100755 --- a/configure +++ b/configure @@ -14153,6 +14153,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 @@ -14181,17 +14206,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 -fsanitize=hwaddress" >&5 +printf %s "checking whether a program links with -fsanitize=hwaddress... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int @@ -14202,31 +14221,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 -fsanitize=hwaddress: the compiler does not support Hardware-assisted 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 @@ -14244,16 +14250,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 @@ -14264,30 +14265,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 @@ -14308,6 +14297,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) @@ -14331,6 +14345,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 ca804d6448810d2..812286d96332334 100644 --- a/configure.ac +++ b/configure.ac @@ -3526,6 +3526,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])]) @@ -3545,10 +3550,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 -fsanitize=hwaddress]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + AC_MSG_ERROR([cannot link with -fsanitize=hwaddress: the compiler does not support Hardware-assisted AddressSanitizer or its runtime library is not installed; see config.log])]) ], [AC_MSG_RESULT([no])]) @@ -3561,10 +3569,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])]) @@ -3580,6 +3591,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]) @@ -3598,6 +3614,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])