This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix sanitize-undefined config check. Don't ALLOW_UNALIGNED when checking.


The -fsanitize=undefined check need to use AC_LINK_IFELSE to make sure
libubsan is installed. When doing undefined checking we should disable
ALLOW_UNALIGNED memory accesses to catch issues where we do unaligned
accesses by accident.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 ChangeLog       |  5 +++++
 configure.ac    | 12 +++++++++---
 lib/ChangeLog   |  4 ++++
 lib/eu-config.h |  3 ++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f281f98..c67894e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-05-31  Mark Wielaard  <mjw@redhat.com>
+
+	* configure.ac (use_undefined): Use AC_LINK_IFELSE. AC_DEFINE
+	CHECK_UNDEFINED.
+
 2015-05-30  Mark Wielaard  <mjw@redhat.com>
 
 	* configure.ac: Check for bunzip2. Check flex and bison are
diff --git a/configure.ac b/configure.ac
index 6386e96..58366d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -202,13 +202,19 @@ if test "$use_undefined" = yes; then
   old_CXXFLAGS="$CXXFLAGS"
   # We explicitly use unaligned access when possible (see ALLOW_UNALIGNED)
   # We want to fail immediately on first error, don't try to recover.
-  CFLAGS="$CFLAGS -fsanitize=undefined -fno-sanitize=alignment -fno-sanitize-recover"
-  CXXFLAGS="$CXXFLAGS -fsanitize=undefined -fno-sanitize=alignment -fno-sanitize-recover"
-  AC_COMPILE_IFELSE([AC_LANG_SOURCE([])], use_undefined=yes, use_undefined=no)
+  CFLAGS="$CFLAGS -fsanitize=undefined -fno-sanitize-recover"
+  CXXFLAGS="$CXXFLAGS -fsanitize=undefined -fno-sanitize-recover"
+  AC_LINK_IFELSE([AC_LANG_SOURCE([int main (int argc, char **argv) { return 0; }])], use_undefined=yes, use_undefined=no)
   AS_IF([test "x$use_undefined" != xyes],
         AC_MSG_WARN([gcc undefined behaviour sanitizer not available])
         CFLAGS="$old_CFLAGS" CXXFLAGS="$old_CXXFLAGS")
 fi
+case $use_undefined in
+ yes) check_undefined_val=1 ;;
+ *)   check_undefined_val=0 ;;
+esac
+AC_DEFINE_UNQUOTED(CHECK_UNDEFINED, $check_undefined_val,
+		   [Building with -fsanitize=undefined or not])
 
 AC_ARG_ENABLE([valgrind],
 AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]),
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 166f047..d04bf17 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,7 @@
+2015-05-31  Mark Wielaard  <mjw@redhat.com>
+
+	* eu-config.h (ALLOW_UNALIGNED): Define when ! CHECK_UNDEFINED.
+
 2015-04-23  Max Filippov  <jcmvbkbc@gmail.com>
 
 	* eu-config.h: Use SYMBOL_VERSIONING as guard.
diff --git a/lib/eu-config.h b/lib/eu-config.h
index 5bb21c1..400cdc6 100644
--- a/lib/eu-config.h
+++ b/lib/eu-config.h
@@ -73,7 +73,8 @@
 
 /* Define ALLOW_UNALIGNED if the architecture allows operations on
    unaligned memory locations.  */
-#if defined __i386__ || defined __x86_64__
+#define SANITIZE_UNDEFINED 1
+#if (defined __i386__ || defined __x86_64__) && ! CHECK_UNDEFINED
 # define ALLOW_UNALIGNED	1
 #else
 # define ALLOW_UNALIGNED	0
-- 
2.4.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]