[PATCH] More MSan/ASan annotations.

Evgeniy Stepanov eugenis at google.com
Thu Jan 31 02:18:17 PST 2013


Hi kcc, samsonov, chandlerc,

This change lets us bootstrap LLVM/Clang under ASan and MSan. It contains fixes for 2 issues:

X86JIT reads return address from stack, which MSan does not know is initialized.
bugpoint tests run binaries with RLIMIT_AS. This does not work with any Sanitizers.


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

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

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: 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: include/llvm/Support/Compiler.h
===================================================================
--- include/llvm/Support/Compiler.h
+++ include/llvm/Support/Compiler.h
@@ -301,6 +301,7 @@
 # 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 +312,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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D354.1.patch
Type: text/x-patch
Size: 2193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130131/edb1dbd4/attachment.bin>


More information about the llvm-commits mailing list