VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_norml
fi
+#----------------------------------------------------------------------------
+# Undefined behaviour sanitiser
+#----------------------------------------------------------------------------
+# Check whether we should build with the undefined beahviour sanitiser.
+
+AC_CACHE_CHECK([for using the undefined behaviour sanitiser], vg_cv_ubsan,
+ [AC_ARG_ENABLE(ubsan,
+ [ --enable-ubsan enables the undefined behaviour sanitiser],
+ [vg_cv_ubsan=$enableval],
+ [vg_cv_ubsan=no])])
#----------------------------------------------------------------------------
# Define MIPS_PAGE_SHIFT (--with-pagesize)
AC_SUBST(FLAG_FNO_STACK_PROTECTOR)
+
+# Does this compiler support -fsanitize=undefined?
+# Only checked for if --enable-ubsan was given.
+if test "x${vg_cv_ubsan}" = "xyes"; then
+AC_MSG_CHECKING([if gcc accepts -fsanitize=undefined])
+safe_CFLAGS=$CFLAGS
+CFLAGS="-fsanitize=undefined"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
+ return 0;
+]])], [
+FLAG_FSANITIZE="-fsanitize=undefined"
+LIB_UBSAN="-static-libubsan"
+AC_MSG_RESULT([yes])
+], [
+FLAG_FSANITIZE=""
+LIB_UBSAN=""
+AC_MSG_RESULT([no])
+])
+CFLAGS=$safe_CFLAGS
+AC_SUBST(FLAG_FSANITIZE)
+AC_SUBST(LIB_UBSAN)
+fi
# does this compiler support --param inline-unit-growth=... ?
AC_MSG_CHECKING([if gcc accepts --param inline-unit-growth])
valgrind_CPPFLAGS = $(AM_CPPFLAGS_PRI)
valgrind_CFLAGS = $(AM_CFLAGS_PRI)
valgrind_CCASFLAGS = $(AM_CCASFLAGS_PRI)
-valgrind_LDFLAGS = $(AM_CFLAGS_PRI)
+valgrind_LDFLAGS = $(AM_CFLAGS_PRI) @LIB_UBSAN@
if VGCONF_PLATFORMS_INCLUDE_X86_DARWIN
valgrind_LDFLAGS += -Wl,-read_only_relocs -Wl,suppress
endif
vgdb_CPPFLAGS = $(AM_CPPFLAGS_PRI)
vgdb_CFLAGS = $(AM_CFLAGS_PRI)
vgdb_CCASFLAGS = $(AM_CCASFLAGS_PRI)
-vgdb_LDFLAGS = $(AM_CFLAGS_PRI)
+vgdb_LDFLAGS = $(AM_CFLAGS_PRI) @LIB_UBSAN@
if VGCONF_PLATVARIANT_IS_ANDROID
vgdb_CFLAGS += -static
endif
#include "config.h"
#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_debuglog.h"
#ifndef HAVE_BUILTIN_POPCOUT
#endif
+
+/*====================================================================*/
+/*=== gcc -fsanitize=undefined helper function support ===*/
+/*====================================================================*/
+
+void __ubsan_handle_type_mismatch ( void );
+void __ubsan_handle_type_mismatch ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_mul_overflow ( void );
+void __ubsan_handle_mul_overflow ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_add_overflow ( void );
+void __ubsan_handle_add_overflow ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_sub_overflow ( void );
+void __ubsan_handle_sub_overflow ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_divrem_overflow ( void );
+void __ubsan_handle_divrem_overflow ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_negate_overflow ( void );
+void __ubsan_handle_negate_overflow ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_out_of_bounds ( void );
+void __ubsan_handle_out_of_bounds ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_shift_out_of_bounds ( void );
+void __ubsan_handle_shift_out_of_bounds ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_vla_bound_not_positive ( void );
+void __ubsan_handle_vla_bound_not_positive ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
+void __ubsan_handle_nonnull_arg ( void );
+void __ubsan_handle_nonnull_arg ( void )
+{
+ VG_(debugLog)(0, "main:ubsan", "In %s", __func__);
+ vg_assert(0);
+}
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/