[PATCH] Workaround some MSan bootstrap issues.

Evgeniy Stepanov eugenis at google.com
Wed Feb 13 02:46:36 PST 2013


Hi kcc,

Sanitizer tools have large TLS requirements, and can not work with 64Kb thread stack.
In order to run MSan-ized clang with the dynamic tool support (this is much faster than otherwise), we pre-initialize the ioctl() output struct.


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

Files:
  unittests/Support/ManagedStatic.cpp
  lib/Support/Unix/Process.inc

Index: unittests/Support/ManagedStatic.cpp
===================================================================
--- unittests/Support/ManagedStatic.cpp
+++ unittests/Support/ManagedStatic.cpp
@@ -29,7 +29,9 @@
 
   // Valgrind's leak checker complains glibc's stack allocation.
   // To appease valgrind, we provide our own stack for each thread.
-  void *allocate_stack(pthread_attr_t &a, size_t n = 65536) {
+  // To appease ASan/MSan/TSan (especially TSan), we provide a huge stack for
+  // each thread.
+  void *allocate_stack(pthread_attr_t &a, size_t n = 0x400000) {
     void *stack = malloc(n);
     pthread_attr_init(&a);
 #if defined(__linux__)
Index: lib/Support/Unix/Process.inc
===================================================================
--- lib/Support/Unix/Process.inc
+++ lib/Support/Unix/Process.inc
@@ -224,6 +224,8 @@
 #if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_TERMIOS_H)
   // Try to determine the width of the terminal.
   struct winsize ws;
+  // Zero-fill ws to avoid a false positive from MemorySanitizer.
+  memset(&ws, 0, sizeof(ws));
   if (ioctl(FileID, TIOCGWINSZ, &ws) == 0)
     Columns = ws.ws_col;
 #endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D402.1.patch
Type: text/x-patch
Size: 1151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130213/cbda0a97/attachment.bin>


More information about the llvm-commits mailing list