Skip to content

Commit b94fdb7

Browse files
gh-75382: Fail configure early if a sanitizer cannot be linked (#159496)
Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent bb55157 commit b94fdb7

3 files changed

Lines changed: 130 additions & 66 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Make :program:`configure` fail early with a clear error when a
2+
``--with-*-sanitizer`` option is used but a program cannot be linked with
3+
the corresponding ``-fsanitize`` flag, for example because the sanitizer
4+
runtime library is not installed.

‎configure‎

Lines changed: 101 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3527,6 +3527,11 @@ AC_ARG_WITH([address_sanitizer],
35273527
AC_MSG_RESULT([$withval])
35283528
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
35293529
LDFLAGS="-fsanitize=address $LDFLAGS"
3530+
AC_MSG_CHECKING([whether a program links with -fsanitize=address])
3531+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
3532+
[AC_MSG_RESULT([yes])],
3533+
[AC_MSG_RESULT([no])
3534+
AC_MSG_ERROR([cannot link with -fsanitize=address: the compiler does not support AddressSanitizer or its runtime library is not installed; see config.log])])
35303535
],
35313536
[AC_MSG_RESULT([no])])
35323537

@@ -3546,10 +3551,13 @@ hwasan_flags="-fsanitize=hwaddress"
35463551
AS_CASE([$host_cpu],
35473552
[x86_64|amd64], [hwasan_flags="$hwasan_flags -fsanitize-hwaddress-experimental-aliasing"]
35483553
)
3549-
AX_CHECK_COMPILE_FLAG([$hwasan_flags],[
35503554
BASECFLAGS="$hwasan_flags -fno-omit-frame-pointer $BASECFLAGS"
35513555
LDFLAGS="$hwasan_flags $LDFLAGS"
3552-
],[AC_MSG_ERROR([The selected compiler doesn't support hardware address sanitizer])])
3556+
AC_MSG_CHECKING([whether a program links with $hwasan_flags])
3557+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
3558+
[AC_MSG_RESULT([yes])],
3559+
[AC_MSG_RESULT([no])
3560+
AC_MSG_ERROR([cannot link with $hwasan_flags: the compiler does not support HWAddressSanitizer or its runtime library is not installed; see config.log])])
35533561
],
35543562
[AC_MSG_RESULT([no])])
35553563

@@ -3562,10 +3570,13 @@ AC_ARG_WITH(
35623570
)],
35633571
[
35643572
AC_MSG_RESULT([$withval])
3565-
AX_CHECK_COMPILE_FLAG([-fsanitize=memory],[
35663573
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
35673574
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
3568-
],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])])
3575+
AC_MSG_CHECKING([whether a program links with -fsanitize=memory])
3576+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
3577+
[AC_MSG_RESULT([yes])],
3578+
[AC_MSG_RESULT([no])
3579+
AC_MSG_ERROR([cannot link with -fsanitize=memory: the compiler does not support MemorySanitizer or its runtime library is not installed; see config.log])])
35693580
],
35703581
[AC_MSG_RESULT([no])])
35713582

@@ -3581,6 +3592,11 @@ AC_MSG_RESULT([$withval])
35813592
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
35823593
LDFLAGS="-fsanitize=undefined $LDFLAGS"
35833594
with_ubsan="yes"
3595+
AC_MSG_CHECKING([whether a program links with -fsanitize=undefined])
3596+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
3597+
[AC_MSG_RESULT([yes])],
3598+
[AC_MSG_RESULT([no])
3599+
AC_MSG_ERROR([cannot link with -fsanitize=undefined: the compiler does not support UndefinedBehaviorSanitizer or its runtime library is not installed; see config.log])])
35843600
],
35853601
[
35863602
AC_MSG_RESULT([no])
@@ -3599,6 +3615,11 @@ AC_MSG_RESULT([$withval])
35993615
BASECFLAGS="-fsanitize=thread $BASECFLAGS"
36003616
LDFLAGS="-fsanitize=thread $LDFLAGS"
36013617
with_tsan="yes"
3618+
AC_MSG_CHECKING([whether a program links with -fsanitize=thread])
3619+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
3620+
[AC_MSG_RESULT([yes])],
3621+
[AC_MSG_RESULT([no])
3622+
AC_MSG_ERROR([cannot link with -fsanitize=thread: the compiler does not support ThreadSanitizer or its runtime library is not installed; see config.log])])
36023623
],
36033624
[
36043625
AC_MSG_RESULT([no])

0 commit comments

Comments
 (0)