Bug 1058500 - Add MSan support to the build system. r=ted,waldo
authorChristian Holler <choller@mozilla.com>
Thu, 11 Sep 2014 23:21:46 +0200
changeset 205003 12cc55488b9c8c39ce5fb724c19757976ae57879
parent 205002 4322addcf9970018abaaa68f3793dce2c5774d15
child 205004 b4e8253d215dafa1da862a83b210ddb47907dcd8
push idunknown
push userunknown
push dateunknown
reviewersted, waldo
bugs1058500
milestone35.0a1
Bug 1058500 - Add MSan support to the build system. r=ted,waldo
build/autoconf/frameptr.m4
configure.in
js/src/configure.in
mfbt/MemoryChecking.h
--- a/build/autoconf/frameptr.m4
+++ b/build/autoconf/frameptr.m4
@@ -23,18 +23,19 @@ AC_DEFUN([MOZ_SET_FRAMEPTR_FLAGS], [
     case "$target" in
     *-mingw*)
       MOZ_ENABLE_FRAME_PTR="-Oy-"
       MOZ_DISABLE_FRAME_PTR="-Oy"
     ;;
     esac
   fi
 
-  # if we are debugging, profiling or using ASAN, we want a frame pointer.
+  # if we are debugging, profiling or using sanitizers, we want a frame pointer.
   if test -z "$MOZ_OPTIMIZE" -o \
           -n "$MOZ_PROFILING" -o \
           -n "$MOZ_DEBUG" -o \
+          -n "$MOZ_MSAN" -o \
           -n "$MOZ_ASAN"; then
     MOZ_FRAMEPTR_FLAGS="$MOZ_ENABLE_FRAME_PTR"
   else
     MOZ_FRAMEPTR_FLAGS="$MOZ_DISABLE_FRAME_PTR"
   fi
 ])
--- a/configure.in
+++ b/configure.in
@@ -1259,16 +1259,32 @@ MOZ_ARG_ENABLE_BOOL(address-sanitizer,
     MOZ_ASAN=1,
     MOZ_ASAN= )
 if test -n "$MOZ_ASAN"; then
     MOZ_LLVM_HACKS=1
     AC_DEFINE(MOZ_ASAN)
     MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
 fi
 AC_SUBST(MOZ_ASAN)
+
+dnl ========================================================
+dnl = Use Memory Sanitizer
+dnl ========================================================
+MOZ_ARG_ENABLE_BOOL(memory-sanitizer,
+[  --enable-memory-sanitizer       Enable Memory Sanitizer (default=no)],
+    MOZ_MSAN=1,
+    MOZ_MSAN= )
+if test -n "$MOZ_MSAN"; then
+    MOZ_LLVM_HACKS=1
+    AC_DEFINE(MOZ_MSAN)
+    MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
+fi
+AC_SUBST(MOZ_MSAN)
+
+# The LLVM symbolizer is used by all sanitizers
 AC_SUBST(LLVM_SYMBOLIZER)
 
 dnl ========================================================
 dnl = Enable hacks required for LLVM instrumentations
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(llvm-hacks,
 [  --enable-llvm-hacks       Enable workarounds required for several LLVM instrumentations (default=no)],
     MOZ_LLVM_HACKS=1,
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -1072,16 +1072,32 @@ MOZ_ARG_ENABLE_BOOL(address-sanitizer,
     MOZ_ASAN=1,
     MOZ_ASAN= )
 if test -n "$MOZ_ASAN"; then
     MOZ_LLVM_HACKS=1
     AC_DEFINE(MOZ_ASAN)
     MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
 fi
 AC_SUBST(MOZ_ASAN)
+
+dnl ========================================================
+dnl = Use Memory Sanitizer
+dnl ========================================================
+MOZ_ARG_ENABLE_BOOL(memory-sanitizer,
+[  --enable-memory-sanitizer       Enable Memory Sanitizer (default=no)],
+    MOZ_MSAN=1,
+    MOZ_MSAN= )
+if test -n "$MOZ_MSAN"; then
+    MOZ_LLVM_HACKS=1
+    AC_DEFINE(MOZ_MSAN)
+    MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
+fi
+AC_SUBST(MOZ_MSAN)
+
+# The LLVM symbolizer is used by all sanitizers
 AC_SUBST(LLVM_SYMBOLIZER)
 
 dnl ========================================================
 dnl = Enable hacks required for LLVM instrumentations
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(llvm-hacks,
 [  --enable-llvm-hacks       Enable workarounds required for several LLVM instrumentations (default=no)],
     MOZ_LLVM_HACKS=1,
--- a/mfbt/MemoryChecking.h
+++ b/mfbt/MemoryChecking.h
@@ -49,16 +49,39 @@ void MOZ_EXPORT
   __asan_poison_memory_region((addr), (size))
 
 #define MOZ_MAKE_MEM_UNDEFINED(addr, size) \
   __asan_unpoison_memory_region((addr), (size))
 
 #define MOZ_MAKE_MEM_DEFINED(addr, size) \
   __asan_unpoison_memory_region((addr), (size))
 }
+#elif defined(MOZ_MSAN)
+#include <stddef.h>
+
+#include "mozilla/Types.h"
+
+extern "C" {
+/* These definitions are usually provided through the
+ * sanitizer/msan_interface.h header installed by MSan.
+ */
+void MOZ_EXPORT
+__msan_poison(void const volatile *addr, size_t size);
+void MOZ_EXPORT
+__msan_unpoison(void const volatile *addr, size_t size);
+
+#define MOZ_MAKE_MEM_NOACCESS(addr, size) \
+  __msan_poison((addr), (size))
+
+#define MOZ_MAKE_MEM_UNDEFINED(addr, size) \
+  __msan_poison((addr), (size))
+
+#define MOZ_MAKE_MEM_DEFINED(addr, size) \
+  __msan_unpoison((addr), (size))
+}
 #elif defined(MOZ_VALGRIND)
 #define MOZ_MAKE_MEM_NOACCESS(addr, size) \
   VALGRIND_MAKE_MEM_NOACCESS((addr), (size))
 
 #define MOZ_MAKE_MEM_UNDEFINED(addr, size) \
   VALGRIND_MAKE_MEM_UNDEFINED((addr), (size))
 
 #define MOZ_MAKE_MEM_DEFINED(addr, size) \