From c35a95ac9cae632c2dad2bb0bb242f3228d8100a Mon Sep 17 00:00:00 2001 From: Florian Krohm Date: Tue, 23 Jun 2015 20:31:52 +0000 Subject: [PATCH] Beef up configury for the undefined behaviour sanitiser. If the compiler supports -fno-sanitize=alignment use it. Otherwise, there will be complaints about misaligned memory accesses. This is needed for GCC 5.1. If that flag is not supported simply pass in -fsantize=undefined and assume that it won't check for alignment violations (which is true for GCC 4.9). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15351 --- configure.ac | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index bac11efda1..558adf3313 100644 --- a/configure.ac +++ b/configure.ac @@ -1834,11 +1834,26 @@ CFLAGS=$safe_CFLAGS AC_SUBST(FLAG_FNO_IPA_ICF) -# Does this compiler support -fsanitize=undefined? +# Does this compiler support -fsanitize=undefined. This is true for +# GCC 4.9 and newer. However, the undefined behaviour sanitiser in GCC 5.1 +# also checks for alignment violations on memory accesses which the valgrind +# code base is sprinkled (if not littered) with. As those alignment issues +# don't pose a problem we want to suppress warnings about them. +# In GCC 5.1 this can be done by passing -fno-sanitize=alignment. Earlier +# GCCs do not support that. +# # Only checked for if --enable-ubsan was given. if test "x${vg_cv_ubsan}" = "xyes"; then -AC_MSG_CHECKING([if gcc accepts -fsanitize=undefined]) +AC_MSG_CHECKING([if gcc accepts -fsanitize=undefined -fno-sanitize=alignment]) safe_CFLAGS=$CFLAGS +CFLAGS="-fsanitize=undefined -fno-sanitize=alignment -Werror" +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ + return 0; +]])], [ +FLAG_FSANITIZE="-fsanitize=undefined -fno-sanitize=alignment" +LIB_UBSAN="-static-libubsan" +AC_MSG_RESULT([yes]) +], [ CFLAGS="-fsanitize=undefined -Werror" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; @@ -1851,6 +1866,7 @@ FLAG_FSANITIZE="" LIB_UBSAN="" AC_MSG_RESULT([no]) ]) +]) CFLAGS=$safe_CFLAGS AC_SUBST(FLAG_FSANITIZE) AC_SUBST(LIB_UBSAN) -- 2.47.2