+dnl Check the available mount options
+dnl
+AX_CHECK_MOUNT_OPT(nosuid)
+AX_CHECK_MOUNT_OPT(nodev)
+dnl Enable LTO for all packages
+dnl
+AC_ARG_ENABLE([lto],
+[ --enable-lto enable link time optimization],,
+enable_lto=no)
+if test "$enable_lto" = "yes" || test "$enable_lto" = "probe"; then
+ AC_MSG_CHECKING([if C compiler supports LTO])
+ OLD_CFLAGS="$CFLAGS"
+ OLD_LDFLAGS="$LDFLAGS"
+ LTO_FLAGS="-g -flto -ffat-lto-objects"
+ CFLAGS="$CFLAGS $LTO_FLAGS"
+ LDFLAGS="$LDFLAGS $LTO_FLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [AC_MSG_RESULT([yes])]
+ [lto_cflags=$LTO_FLAGS]
+ [lto_ldflags=$LTO_FLAGS]
+ [AC_PATH_PROG(gcc_ar, gcc-ar,,)]
+ [AC_PATH_PROG(gcc_ranlib, gcc-ranlib,,)],
+ [AC_MSG_RESULT([no])])
+ if test -x "$gcc_ar" && test -x "$gcc_ranlib"; then
+ have_lto=yes
+ AR="${gcc_ar}"
+ RANLIB="${gcc_ranlib}"
+ fi
+ CFLAGS="${OLD_CFLAGS}"
+ LDFLAGS="${OLD_LDFLAGS}"
+ AC_SUBST(have_lto)
+ AC_SUBST(lto_cflags)
+ AC_SUBST(lto_ldflags)
+fi
+if test "$enable_lto" = "yes" && test "$have_lto" != "yes"; then
+ AC_MSG_ERROR([LTO not supported by compiler.])
+fi
+dnl
+dnl Enable UBSAN for all packages
+dnl
+AC_ARG_ENABLE([ubsan],
+[ --enable-ubsan enable undefined behavior sanitizer],,
+enable_ubsan=no)
+if test "$enable_ubsan" = "yes" || test "$enable_ubsan" = "probe"; then
+ AC_MSG_CHECKING([if C compiler supports UBSAN])
+ OLD_CFLAGS="$CFLAGS"
+ OLD_LDFLAGS="$LDFLAGS"
+ UBSAN_FLAGS="-fsanitize=undefined"
+ CFLAGS="$CFLAGS $UBSAN_FLAGS"
+ LDFLAGS="$LDFLAGS $UBSAN_FLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [AC_MSG_RESULT([yes])]
+ [ubsan_cflags=$UBSAN_FLAGS]
+ [ubsan_ldflags=$UBSAN_FLAGS]
+ [have_ubsan=yes],
+ [AC_MSG_RESULT([no])])
+ CFLAGS="${OLD_CFLAGS}"
+ LDFLAGS="${OLD_LDFLAGS}"
+ AC_SUBST(have_ubsan)
+ AC_SUBST(ubsan_cflags)
+ AC_SUBST(ubsan_ldflags)
+fi
+if test "$enable_ubsan" = "yes" && test "$have_ubsan" != "yes"; then
+ AC_MSG_ERROR([UBSAN not supported by compiler.])
+fi
+dnl
+dnl Enable ADDRSAN for all packages
+dnl
+AC_ARG_ENABLE([addrsan],
+[ --enable-addrsan enable address sanitizer],,
+enable_addrsan=no)
+if test "$enable_addrsan" = "yes" || test "$enable_addrsan" = "probe"; then
+ AC_MSG_CHECKING([if C compiler supports ADDRSAN])
+ OLD_CFLAGS="$CFLAGS"
+ OLD_LDFLAGS="$LDFLAGS"
+ ADDRSAN_FLAGS="-fsanitize=address"
+ CFLAGS="$CFLAGS $ADDRSAN_FLAGS"
+ LDFLAGS="$LDFLAGS $ADDRSAN_FLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [AC_MSG_RESULT([yes])]
+ [addrsan_cflags=$ADDRSAN_FLAGS]
+ [addrsan_ldflags=$ADDRSAN_FLAGS]
+ [have_addrsan=yes],
+ [AC_MSG_RESULT([no])])
+ CFLAGS="${OLD_CFLAGS}"
+ LDFLAGS="${OLD_LDFLAGS}"
+ AC_SUBST(have_addrsan)
+ AC_SUBST(addrsan_cflags)
+ AC_SUBST(addrsan_ldflags)
+fi
+if test "$enable_addrsan" = "yes" && test "$have_addrsan" != "yes"; then
+ AC_MSG_ERROR([ADDRSAN not supported by compiler.])
+fi
+dnl
+dnl Enable THREADSAN for all packages
+dnl
+AC_ARG_ENABLE([threadsan],
+[ --enable-threadsan enable thread sanitizer],,
+enable_threadsan=no)
+if test "$enable_threadsan" = "yes" || test "$enable_threadsan" = "probe"; then
+ AC_MSG_CHECKING([if C compiler supports THREADSAN])
+ OLD_CFLAGS="$CFLAGS"
+ OLD_LDFLAGS="$LDFLAGS"
+ THREADSAN_FLAGS="-fsanitize=thread"
+ CFLAGS="$CFLAGS $THREADSAN_FLAGS"
+ LDFLAGS="$LDFLAGS $THREADSAN_FLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [AC_MSG_RESULT([yes])]
+ [threadsan_cflags=$THREADSAN_FLAGS]
+ [threadsan_ldflags=$THREADSAN_FLAGS]
+ [have_threadsan=yes],
+ [AC_MSG_RESULT([no])])
+ CFLAGS="${OLD_CFLAGS}"
+ LDFLAGS="${OLD_LDFLAGS}"
+ AC_SUBST(have_threadsan)
+ AC_SUBST(threadsan_cflags)
+ AC_SUBST(threadsan_ldflags)
+fi
+if test "$enable_threadsan" = "yes" && test "$have_threadsan" != "yes"; then
+ AC_MSG_ERROR([THREADSAN not supported by compiler.])
+fi
+if test "$have_threadsan" = "yes" && test "$have_addrsan" = "yes"; then
+ AC_MSG_WARN([ADDRSAN and THREADSAN are not known to work together.])
+fi
+dnl