<div dir="ltr">I think this is still breaking sanitizer bots...<div><br></div><div>See <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1125">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1125</a> which is the closest sanitizer build that isn't horribly broken by something unrelated, and specifically the failure here:</div><div><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1125/steps/64-bit%20check-asan-dynamic/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1125/steps/64-bit%20check-asan-dynamic/logs/stdio</a> </div><div><br></div><div>You can also see the failure in the latest build:</div><div><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1130">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1130</a> </div><div><br></div><div>I think this error first showed up with an earlier version of the patch you can find here:</div><div><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1117">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1117</a> (1116 didn't fail check-asan-dynamic).</div><div><br></div><div>I'm going to try reverting to see if that brings the bot back to healthy.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Mar 20, 2017 at 6:18 PM Francis Ricci via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: fjricci<br class="gmail_msg">
Date: Mon Mar 20 12:06:42 2017<br class="gmail_msg">
New Revision: 298274<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=298274&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=298274&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
Use pthreads for thread-local lsan allocator cache on darwin<br class="gmail_msg">
<br class="gmail_msg">
Summary:<br class="gmail_msg">
This patch allows us to move away from using __thread on darwin,<br class="gmail_msg">
which is requiring for building lsan for darwin on ios version 7<br class="gmail_msg">
and on iossim i386.<br class="gmail_msg">
<br class="gmail_msg">
Reviewers: kubamracek, kcc<br class="gmail_msg">
<br class="gmail_msg">
Subscribers: llvm-commits<br class="gmail_msg">
<br class="gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D29994" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D29994</a><br class="gmail_msg">
<br class="gmail_msg">
Modified:<br class="gmail_msg">
    compiler-rt/trunk/lib/lsan/lsan_allocator.cc<br class="gmail_msg">
    compiler-rt/trunk/lib/lsan/lsan_allocator.h<br class="gmail_msg">
    compiler-rt/trunk/lib/lsan/lsan_common_linux.cc<br class="gmail_msg">
    compiler-rt/trunk/lib/lsan/lsan_common_mac.cc<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=298274&r1=298273&r2=298274&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=298274&r1=298273&r2=298274&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/lsan/lsan_allocator.cc (original)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/lsan/lsan_allocator.cc Mon Mar 20 12:06:42 2017<br class="gmail_msg">
@@ -24,53 +24,18 @@<br class="gmail_msg">
 extern "C" void *memset(void *ptr, int value, uptr num);<br class="gmail_msg">
<br class="gmail_msg">
 namespace __lsan {<br class="gmail_msg">
-<br class="gmail_msg">
-struct ChunkMetadata {<br class="gmail_msg">
-  u8 allocated : 8;  // Must be first.<br class="gmail_msg">
-  ChunkTag tag : 2;<br class="gmail_msg">
-#if SANITIZER_WORDSIZE == 64<br class="gmail_msg">
-  uptr requested_size : 54;<br class="gmail_msg">
-#else<br class="gmail_msg">
-  uptr requested_size : 32;<br class="gmail_msg">
-  uptr padding : 22;<br class="gmail_msg">
-#endif<br class="gmail_msg">
-  u32 stack_trace_id;<br class="gmail_msg">
-};<br class="gmail_msg">
-<br class="gmail_msg">
-#if defined(__mips64) || defined(__aarch64__) || defined(__i386__)<br class="gmail_msg">
 #if defined(__i386__)<br class="gmail_msg">
 static const uptr kMaxAllowedMallocSize = 1UL << 30;<br class="gmail_msg">
-#else<br class="gmail_msg">
+#elif defined(__mips64) || defined(__aarch64__)<br class="gmail_msg">
 static const uptr kMaxAllowedMallocSize = 4UL << 30;<br class="gmail_msg">
-#endif<br class="gmail_msg">
-static const uptr kRegionSizeLog = 20;<br class="gmail_msg">
-static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;<br class="gmail_msg">
-typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap;<br class="gmail_msg">
-typedef CompactSizeClassMap SizeClassMap;<br class="gmail_msg">
-typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE,<br class="gmail_msg">
-    sizeof(ChunkMetadata), SizeClassMap, kRegionSizeLog, ByteMap><br class="gmail_msg">
-    PrimaryAllocator;<br class="gmail_msg">
 #else<br class="gmail_msg">
 static const uptr kMaxAllowedMallocSize = 8UL << 30;<br class="gmail_msg">
-<br class="gmail_msg">
-struct AP64 {  // Allocator64 parameters. Deliberately using a short name.<br class="gmail_msg">
-  static const uptr kSpaceBeg = 0x600000000000ULL;<br class="gmail_msg">
-  static const uptr kSpaceSize =  0x40000000000ULL; // 4T.<br class="gmail_msg">
-  static const uptr kMetadataSize = sizeof(ChunkMetadata);<br class="gmail_msg">
-  typedef DefaultSizeClassMap SizeClassMap;<br class="gmail_msg">
-  typedef NoOpMapUnmapCallback MapUnmapCallback;<br class="gmail_msg">
-  static const uptr kFlags = 0;<br class="gmail_msg">
-};<br class="gmail_msg">
-<br class="gmail_msg">
-typedef SizeClassAllocator64<AP64> PrimaryAllocator;<br class="gmail_msg">
 #endif<br class="gmail_msg">
-typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;<br class="gmail_msg">
 typedef LargeMmapAllocator<> SecondaryAllocator;<br class="gmail_msg">
 typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,<br class="gmail_msg">
           SecondaryAllocator> Allocator;<br class="gmail_msg">
<br class="gmail_msg">
 static Allocator allocator;<br class="gmail_msg">
-static THREADLOCAL AllocatorCache cache;<br class="gmail_msg">
<br class="gmail_msg">
 void InitializeAllocator() {<br class="gmail_msg">
   allocator.InitLinkerInitialized(<br class="gmail_msg">
@@ -79,7 +44,7 @@ void InitializeAllocator() {<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 void AllocatorThreadFinish() {<br class="gmail_msg">
-  allocator.SwallowCache(&cache);<br class="gmail_msg">
+  allocator.SwallowCache(GetAllocatorCache());<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 static ChunkMetadata *Metadata(const void *p) {<br class="gmail_msg">
@@ -111,7 +76,7 @@ void *Allocate(const StackTrace &stack,<br class="gmail_msg">
     Report("WARNING: LeakSanitizer failed to allocate %zu bytes\n", size);<br class="gmail_msg">
     return nullptr;<br class="gmail_msg">
   }<br class="gmail_msg">
-  void *p = allocator.Allocate(&cache, size, alignment, false);<br class="gmail_msg">
+  void *p = allocator.Allocate(GetAllocatorCache(), size, alignment, false);<br class="gmail_msg">
   // Do not rely on the allocator to clear the memory (it's slow).<br class="gmail_msg">
   if (cleared && allocator.FromPrimary(p))<br class="gmail_msg">
     memset(p, 0, size);<br class="gmail_msg">
@@ -125,7 +90,7 @@ void Deallocate(void *p) {<br class="gmail_msg">
   if (&__sanitizer_free_hook) __sanitizer_free_hook(p);<br class="gmail_msg">
   RunFreeHooks(p);<br class="gmail_msg">
   RegisterDeallocation(p);<br class="gmail_msg">
-  allocator.Deallocate(&cache, p);<br class="gmail_msg">
+  allocator.Deallocate(GetAllocatorCache(), p);<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 void *Reallocate(const StackTrace &stack, void *p, uptr new_size,<br class="gmail_msg">
@@ -133,17 +98,17 @@ void *Reallocate(const StackTrace &stack<br class="gmail_msg">
   RegisterDeallocation(p);<br class="gmail_msg">
   if (new_size > kMaxAllowedMallocSize) {<br class="gmail_msg">
     Report("WARNING: LeakSanitizer failed to allocate %zu bytes\n", new_size);<br class="gmail_msg">
-    allocator.Deallocate(&cache, p);<br class="gmail_msg">
+    allocator.Deallocate(GetAllocatorCache(), p);<br class="gmail_msg">
     return nullptr;<br class="gmail_msg">
   }<br class="gmail_msg">
-  p = allocator.Reallocate(&cache, p, new_size, alignment);<br class="gmail_msg">
+  p = allocator.Reallocate(GetAllocatorCache(), p, new_size, alignment);<br class="gmail_msg">
   RegisterAllocation(stack, p, new_size);<br class="gmail_msg">
   return p;<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 void GetAllocatorCacheRange(uptr *begin, uptr *end) {<br class="gmail_msg">
-  *begin = (uptr)&cache;<br class="gmail_msg">
-  *end = *begin + sizeof(cache);<br class="gmail_msg">
+  *begin = (uptr)GetAllocatorCache();<br class="gmail_msg">
+  *end = *begin + sizeof(AllocatorCache);<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
 uptr GetMallocUsableSize(const void *p) {<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.h?rev=298274&r1=298273&r2=298274&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.h?rev=298274&r1=298273&r2=298274&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/lsan/lsan_allocator.h (original)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/lsan/lsan_allocator.h Mon Mar 20 12:06:42 2017<br class="gmail_msg">
@@ -15,8 +15,10 @@<br class="gmail_msg">
 #ifndef LSAN_ALLOCATOR_H<br class="gmail_msg">
 #define LSAN_ALLOCATOR_H<br class="gmail_msg">
<br class="gmail_msg">
+#include "sanitizer_common/sanitizer_allocator.h"<br class="gmail_msg">
 #include "sanitizer_common/sanitizer_common.h"<br class="gmail_msg">
 #include "sanitizer_common/sanitizer_internal_defs.h"<br class="gmail_msg">
+#include "lsan_common.h"<br class="gmail_msg">
<br class="gmail_msg">
 namespace __lsan {<br class="gmail_msg">
<br class="gmail_msg">
@@ -34,6 +36,41 @@ void GetAllocatorCacheRange(uptr *begin,<br class="gmail_msg">
 void AllocatorThreadFinish();<br class="gmail_msg">
 void InitializeAllocator();<br class="gmail_msg">
<br class="gmail_msg">
+struct ChunkMetadata {<br class="gmail_msg">
+  u8 allocated : 8;  // Must be first.<br class="gmail_msg">
+  ChunkTag tag : 2;<br class="gmail_msg">
+#if SANITIZER_WORDSIZE == 64<br class="gmail_msg">
+  uptr requested_size : 54;<br class="gmail_msg">
+#else<br class="gmail_msg">
+  uptr requested_size : 32;<br class="gmail_msg">
+  uptr padding : 22;<br class="gmail_msg">
+#endif<br class="gmail_msg">
+  u32 stack_trace_id;<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+#if defined(__mips64) || defined(__aarch64__) || defined(__i386__)<br class="gmail_msg">
+static const uptr kRegionSizeLog = 20;<br class="gmail_msg">
+static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;<br class="gmail_msg">
+typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap;<br class="gmail_msg">
+typedef CompactSizeClassMap SizeClassMap;<br class="gmail_msg">
+typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE,<br class="gmail_msg">
+    sizeof(ChunkMetadata), SizeClassMap, kRegionSizeLog, ByteMap><br class="gmail_msg">
+    PrimaryAllocator;<br class="gmail_msg">
+#elif defined(__x86_64__)<br class="gmail_msg">
+struct AP64 {  // Allocator64 parameters. Deliberately using a short name.<br class="gmail_msg">
+  static const uptr kSpaceBeg = 0x600000000000ULL;<br class="gmail_msg">
+  static const uptr kSpaceSize =  0x40000000000ULL; // 4T.<br class="gmail_msg">
+  static const uptr kMetadataSize = sizeof(ChunkMetadata);<br class="gmail_msg">
+  typedef DefaultSizeClassMap SizeClassMap;<br class="gmail_msg">
+  typedef NoOpMapUnmapCallback MapUnmapCallback;<br class="gmail_msg">
+  static const uptr kFlags = 0;<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+typedef SizeClassAllocator64<AP64> PrimaryAllocator;<br class="gmail_msg">
+#endif<br class="gmail_msg">
+typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;<br class="gmail_msg">
+<br class="gmail_msg">
+AllocatorCache *GetAllocatorCache();<br class="gmail_msg">
 }  // namespace __lsan<br class="gmail_msg">
<br class="gmail_msg">
 #endif  // LSAN_ALLOCATOR_H<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/lib/lsan/lsan_common_linux.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_linux.cc?rev=298274&r1=298273&r2=298274&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_linux.cc?rev=298274&r1=298273&r2=298274&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/lsan/lsan_common_linux.cc (original)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/lsan/lsan_common_linux.cc Mon Mar 20 12:06:42 2017<br class="gmail_msg">
@@ -22,6 +22,7 @@<br class="gmail_msg">
 #include "sanitizer_common/sanitizer_flags.h"<br class="gmail_msg">
 #include "sanitizer_common/sanitizer_linux.h"<br class="gmail_msg">
 #include "sanitizer_common/sanitizer_stackdepot.h"<br class="gmail_msg">
+#include "lsan_allocator.h"<br class="gmail_msg">
<br class="gmail_msg">
 namespace __lsan {<br class="gmail_msg">
<br class="gmail_msg">
@@ -38,6 +39,9 @@ static THREADLOCAL u32 current_thread_ti<br class="gmail_msg">
 u32 GetCurrentThread() { return current_thread_tid; }<br class="gmail_msg">
 void SetCurrentThread(u32 tid) { current_thread_tid = tid; }<br class="gmail_msg">
<br class="gmail_msg">
+static THREADLOCAL AllocatorCache allocator_cache;<br class="gmail_msg">
+AllocatorCache *GetAllocatorCache() { return &allocator_cache; }<br class="gmail_msg">
+<br class="gmail_msg">
 __attribute__((tls_model("initial-exec")))<br class="gmail_msg">
 THREADLOCAL int disable_counter;<br class="gmail_msg">
 bool DisabledInThisThread() { return disable_counter > 0; }<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/lib/lsan/lsan_common_mac.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_mac.cc?rev=298274&r1=298273&r2=298274&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_mac.cc?rev=298274&r1=298273&r2=298274&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/lsan/lsan_common_mac.cc (original)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/lsan/lsan_common_mac.cc Mon Mar 20 12:06:42 2017<br class="gmail_msg">
@@ -12,12 +12,14 @@<br class="gmail_msg">
 //<br class="gmail_msg">
 //===----------------------------------------------------------------------===//<br class="gmail_msg">
<br class="gmail_msg">
-#include "sanitizer_common/sanitizer_allocator_internal.h"<br class="gmail_msg">
 #include "sanitizer_common/sanitizer_platform.h"<br class="gmail_msg">
 #include "lsan_common.h"<br class="gmail_msg">
<br class="gmail_msg">
 #if CAN_SANITIZE_LEAKS && SANITIZER_MAC<br class="gmail_msg">
<br class="gmail_msg">
+#include "sanitizer_common/sanitizer_allocator_internal.h"<br class="gmail_msg">
+#include "lsan_allocator.h"<br class="gmail_msg">
+<br class="gmail_msg">
 #include <pthread.h><br class="gmail_msg">
<br class="gmail_msg">
 namespace __lsan {<br class="gmail_msg">
@@ -25,6 +27,7 @@ namespace __lsan {<br class="gmail_msg">
 typedef struct {<br class="gmail_msg">
   int disable_counter;<br class="gmail_msg">
   u32 current_thread_id;<br class="gmail_msg">
+  AllocatorCache cache;<br class="gmail_msg">
 } thread_local_data_t;<br class="gmail_msg">
<br class="gmail_msg">
 static pthread_key_t key;<br class="gmail_msg">
@@ -40,6 +43,7 @@ static thread_local_data_t *get_tls_val(<br class="gmail_msg">
     ptr = (thread_local_data_t *)InternalAlloc(sizeof(*ptr));<br class="gmail_msg">
     ptr->disable_counter = 0;<br class="gmail_msg">
     ptr->current_thread_id = kInvalidTid;<br class="gmail_msg">
+    ptr->cache = AllocatorCache();<br class="gmail_msg">
     pthread_setspecific(key, ptr);<br class="gmail_msg">
   }<br class="gmail_msg">
<br class="gmail_msg">
@@ -62,6 +66,8 @@ u32 GetCurrentThread() { return get_tls_<br class="gmail_msg">
<br class="gmail_msg">
 void SetCurrentThread(u32 tid) { get_tls_val()->current_thread_id = tid; }<br class="gmail_msg">
<br class="gmail_msg">
+AllocatorCache *GetAllocatorCache() { return &get_tls_val()->cache; }<br class="gmail_msg">
+<br class="gmail_msg">
 void InitializePlatformSpecificModules() {<br class="gmail_msg">
   CHECK(0 && "unimplemented");<br class="gmail_msg">
 }<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div>