[PATCH] More MSan/ASan annotations.

Evgeniy Stepanov eugenis at google.com
Thu Jan 31 06:34:41 PST 2013


  Switched from config.h to llvm-config.h

Hi kcc, samsonov, chandlerc, chapuni,

http://llvm-reviews.chandlerc.com/D354

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D354?vs=839&id=843#toc

Files:
  lib/Support/Unix/Program.inc
  lib/Target/X86/X86JITInfo.cpp
  include/llvm/Support/Compiler.h
  include/llvm/Config/llvm-config.h.cmake
  include/llvm/Config/config.h.cmake

Index: lib/Support/Unix/Program.inc
===================================================================
--- lib/Support/Unix/Program.inc
+++ lib/Support/Unix/Program.inc
@@ -17,6 +17,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Unix.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/FileSystem.h"
 #include <llvm/Config/config.h>
 #if HAVE_SYS_STAT_H
@@ -164,12 +165,16 @@
   setrlimit (RLIMIT_RSS, &r);
 #endif
 #ifdef RLIMIT_AS  // e.g. NetBSD doesn't have it.
+  // Don't set virtual memory limit if built with any Sanitizer. They need 80Tb
+  // of virtual memory for shadow memory mapping.
+#if !LLVM_MEMORY_SANITIZER_BUILD && !LLVM_ADDRESS_SANITIZER_BUILD
   // Virtual memory.
   getrlimit (RLIMIT_AS, &r);
   r.rlim_cur = limit;
   setrlimit (RLIMIT_AS, &r);
 #endif
 #endif
+#endif
 }
 
 bool
Index: lib/Target/X86/X86JITInfo.cpp
===================================================================
--- lib/Target/X86/X86JITInfo.cpp
+++ lib/Target/X86/X86JITInfo.cpp
@@ -351,6 +351,9 @@
 void LLVM_ATTRIBUTE_USED
 X86CompilationCallback2(intptr_t *StackPtr, intptr_t RetAddr) {
   intptr_t *RetAddrLoc = &StackPtr[1];
+  // We are reading raw stack data here. Tell MemorySanitizer that it is
+  // sufficiently initialized.
+  __msan_unpoison(RetAddrLoc, sizeof(*RetAddrLoc));
   assert(*RetAddrLoc == RetAddr &&
          "Could not find return address on the stack!");
 
Index: include/llvm/Support/Compiler.h
===================================================================
--- include/llvm/Support/Compiler.h
+++ include/llvm/Support/Compiler.h
@@ -15,7 +15,7 @@
 #ifndef LLVM_SUPPORT_COMPILER_H
 #define LLVM_SUPPORT_COMPILER_H
 
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 
 #ifndef __has_feature
 # define __has_feature(x) 0
@@ -295,12 +295,11 @@
 # define LLVM_FUNCTION_NAME __func__
 #endif
 
-/// \macro LLVM_ENABLE_MSAN_ANNOTATIONS
-/// \brief Are MemorySanitizer annotations available.
-#if defined(HAVE_SANITIZER_MSAN_INTERFACE_H)
+#if defined(LLVM_HAVE_MSAN_ANNOTATIONS)
 # include <sanitizer/msan_interface.h>
 #else
 # define __msan_allocated_memory(p, size)
+# define __msan_unpoison(p, size)
 #endif
 
 /// \macro LLVM_MEMORY_SANITIZER_BUILD
@@ -311,4 +310,12 @@
 # define LLVM_MEMORY_SANITIZER_BUILD 0
 #endif
 
+/// \macro LLVM_ADDRESS_SANITIZER_BUILD
+/// \brief Whether LLVM itself is built with AddressSanitizer instrumentation.
+#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
+# define LLVM_ADDRESS_SANITIZER_BUILD 1
+#else
+# define LLVM_ADDRESS_SANITIZER_BUILD 0
+#endif
+
 #endif
Index: include/llvm/Config/llvm-config.h.cmake
===================================================================
--- include/llvm/Config/llvm-config.h.cmake
+++ include/llvm/Config/llvm-config.h.cmake
@@ -124,4 +124,7 @@
 /* Minor version of the LLVM API */
 #cmakedefine LLVM_VERSION_MINOR ${LLVM_VERSION_MINOR}
 
+/* Define to 1 if you have the <sanitizer/msan_interface.h> header file. */
+#cmakedefine LLVM_HAVE_MSAN_ANNOTATIONS ${HAVE_SANITIZER_MSAN_INTERFACE_H}
+
 #endif
Index: include/llvm/Config/config.h.cmake
===================================================================
--- include/llvm/Config/config.h.cmake
+++ include/llvm/Config/config.h.cmake
@@ -468,9 +468,6 @@
 /* Define to 1 if the system has the type `u_int64_t'. */
 #cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T}
 
-/* Define to 1 if you have the <sanitizer/msan_interface.h> header file. */
-#cmakedefine HAVE_SANITIZER_MSAN_INTERFACE_H ${HAVE_SANITIZER_MSAN_INTERFACE_H}
-
 /* Define to 1 if you have the <valgrind/valgrind.h> header file. */
 #cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D354.2.patch
Type: text/x-patch
Size: 3732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130131/3265d267/attachment.bin>


More information about the llvm-commits mailing list