[compiler-rt] r298214 - Use pthreads for thread-local lsan allocator cache on darwin
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 20 17:33:45 PDT 2017
Could you please take a look?
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1117/steps/test%20standalone%20compiler-rt/logs/stdio
******************** TEST 'LeakSanitizer-AddressSanitizer-i386 ::
TestCases/use_tls_dynamic.cc' FAILED ********************
Script:
--
LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0"
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm_build64/bin/clang
--driver-mode=g++ -O0 -m32 -gline-tables-only
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/lsan/TestCases/use_tls_dynamic.cc
-DBUILD_DSO -fPIC -shared -o
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/compiler_rt_build/test/lsan/I386AsanConfig/TestCases/Output/use_tls_dynamic.cc.tmp-so.so
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm_build64/bin/clang
--driver-mode=g++ -O0 -m32 -gline-tables-only -fsanitize=address
-I/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/lsan/../
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/lsan/TestCases/use_tls_dynamic.cc
-o /mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/compiler_rt_build/test/lsan/I386AsanConfig/TestCases/Output/use_tls_dynamic.cc.tmp
LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/compiler_rt_build/test/lsan/I386AsanConfig/TestCases/Output/use_tls_dynamic.cc.tmp
2>&1 | FileCheck
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/lsan/TestCases/use_tls_dynamic.cc
LSAN_OPTIONS=$LSAN_BASE:"use_tls=1"
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/compiler_rt_build/test/lsan/I386AsanConfig/TestCases/Output/use_tls_dynamic.cc.tmp
2>&1
LSAN_OPTIONS=""
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/compiler_rt_build/test/lsan/I386AsanConfig/TestCases/Output/use_tls_dynamic.cc.tmp
2>&1
--
Exit Code: 1
Command Output (stderr):
--
/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/lsan/TestCases/use_tls_dynamic.cc:34:11:
error: expected string not found in input
// CHECK: LeakSanitizer: detected memory leaks
^
<stdin>:2:1: note: scanning from here
On Sun, Mar 19, 2017 at 8:14 AM Francis Ricci via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: fjricci
> Date: Sun Mar 19 10:02:43 2017
> New Revision: 298214
>
> URL: http://llvm.org/viewvc/llvm-project?rev=298214&view=rev
> Log:
> Use pthreads for thread-local lsan allocator cache on darwin
>
> Summary:
> This patch allows us to move away from using __thread on darwin,
> which is requiring for building lsan for darwin on ios version 7
> and on iossim i386.
>
> Reviewers: kubamracek, kcc
>
> Subscribers: llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D29994
>
> Modified:
> compiler-rt/trunk/lib/lsan/lsan_allocator.cc
> compiler-rt/trunk/lib/lsan/lsan_allocator.h
> compiler-rt/trunk/lib/lsan/lsan_common_linux.cc
> compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
>
> Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=298214&r1=298213&r2=298214&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/lsan/lsan_allocator.cc (original)
> +++ compiler-rt/trunk/lib/lsan/lsan_allocator.cc Sun Mar 19 10:02:43 2017
> @@ -24,53 +24,18 @@
> extern "C" void *memset(void *ptr, int value, uptr num);
>
> namespace __lsan {
> -
> -struct ChunkMetadata {
> - u8 allocated : 8; // Must be first.
> - ChunkTag tag : 2;
> -#if SANITIZER_WORDSIZE == 64
> - uptr requested_size : 54;
> -#else
> - uptr requested_size : 32;
> - uptr padding : 22;
> -#endif
> - u32 stack_trace_id;
> -};
> -
> -#if defined(__mips64) || defined(__aarch64__) || defined(__i386__)
> #if defined(__i386__)
> static const uptr kMaxAllowedMallocSize = 1UL << 30;
> -#else
> +#elif defined(__mips64) || defined(__aarch64__)
> static const uptr kMaxAllowedMallocSize = 4UL << 30;
> -#endif
> -static const uptr kRegionSizeLog = 20;
> -static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >>
> kRegionSizeLog;
> -typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap;
> -typedef CompactSizeClassMap SizeClassMap;
> -typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE,
> - sizeof(ChunkMetadata), SizeClassMap, kRegionSizeLog, ByteMap>
> - PrimaryAllocator;
> #else
> static const uptr kMaxAllowedMallocSize = 8UL << 30;
> -
> -struct AP64 { // Allocator64 parameters. Deliberately using a short name.
> - static const uptr kSpaceBeg = 0x600000000000ULL;
> - static const uptr kSpaceSize = 0x40000000000ULL; // 4T.
> - static const uptr kMetadataSize = sizeof(ChunkMetadata);
> - typedef DefaultSizeClassMap SizeClassMap;
> - typedef NoOpMapUnmapCallback MapUnmapCallback;
> - static const uptr kFlags = 0;
> -};
> -
> -typedef SizeClassAllocator64<AP64> PrimaryAllocator;
> #endif
> -typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
> typedef LargeMmapAllocator<> SecondaryAllocator;
> typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
> SecondaryAllocator> Allocator;
>
> static Allocator allocator;
> -static THREADLOCAL AllocatorCache cache;
>
> void InitializeAllocator() {
> allocator.InitLinkerInitialized(
> @@ -79,7 +44,7 @@ void InitializeAllocator() {
> }
>
> void AllocatorThreadFinish() {
> - allocator.SwallowCache(&cache);
> + allocator.SwallowCache(GetAllocatorCache());
> }
>
> static ChunkMetadata *Metadata(const void *p) {
> @@ -111,7 +76,7 @@ void *Allocate(const StackTrace &stack,
> Report("WARNING: LeakSanitizer failed to allocate %zu bytes\n", size);
> return nullptr;
> }
> - void *p = allocator.Allocate(&cache, size, alignment, false);
> + void *p = allocator.Allocate(GetAllocatorCache(), size, alignment,
> false);
> // Do not rely on the allocator to clear the memory (it's slow).
> if (cleared && allocator.FromPrimary(p))
> memset(p, 0, size);
> @@ -125,7 +90,7 @@ void Deallocate(void *p) {
> if (&__sanitizer_free_hook) __sanitizer_free_hook(p);
> RunFreeHooks(p);
> RegisterDeallocation(p);
> - allocator.Deallocate(&cache, p);
> + allocator.Deallocate(GetAllocatorCache(), p);
> }
>
> void *Reallocate(const StackTrace &stack, void *p, uptr new_size,
> @@ -133,17 +98,17 @@ void *Reallocate(const StackTrace &stack
> RegisterDeallocation(p);
> if (new_size > kMaxAllowedMallocSize) {
> Report("WARNING: LeakSanitizer failed to allocate %zu bytes\n",
> new_size);
> - allocator.Deallocate(&cache, p);
> + allocator.Deallocate(GetAllocatorCache(), p);
> return nullptr;
> }
> - p = allocator.Reallocate(&cache, p, new_size, alignment);
> + p = allocator.Reallocate(GetAllocatorCache(), p, new_size, alignment);
> RegisterAllocation(stack, p, new_size);
> return p;
> }
>
> void GetAllocatorCacheRange(uptr *begin, uptr *end) {
> - *begin = (uptr)&cache;
> - *end = *begin + sizeof(cache);
> + *begin = (uptr)GetAllocatorCache();
> + *end = *begin + sizeof(AllocatorCache);
> }
>
> uptr GetMallocUsableSize(const void *p) {
>
> Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.h?rev=298214&r1=298213&r2=298214&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/lsan/lsan_allocator.h (original)
> +++ compiler-rt/trunk/lib/lsan/lsan_allocator.h Sun Mar 19 10:02:43 2017
> @@ -15,8 +15,10 @@
> #ifndef LSAN_ALLOCATOR_H
> #define LSAN_ALLOCATOR_H
>
> +#include "sanitizer_common/sanitizer_allocator.h"
> #include "sanitizer_common/sanitizer_common.h"
> #include "sanitizer_common/sanitizer_internal_defs.h"
> +#include "lsan_common.h"
>
> namespace __lsan {
>
> @@ -34,6 +36,41 @@ void GetAllocatorCacheRange(uptr *begin,
> void AllocatorThreadFinish();
> void InitializeAllocator();
>
> +struct ChunkMetadata {
> + u8 allocated : 8; // Must be first.
> + ChunkTag tag : 2;
> +#if SANITIZER_WORDSIZE == 64
> + uptr requested_size : 54;
> +#else
> + uptr requested_size : 32;
> + uptr padding : 22;
> +#endif
> + u32 stack_trace_id;
> +};
> +
> +#if defined(__mips64) || defined(__aarch64__) || defined(__i386__)
> +static const uptr kRegionSizeLog = 20;
> +static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >>
> kRegionSizeLog;
> +typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap;
> +typedef CompactSizeClassMap SizeClassMap;
> +typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE,
> + sizeof(ChunkMetadata), SizeClassMap, kRegionSizeLog, ByteMap>
> + PrimaryAllocator;
> +#elif defined(__x86_64__)
> +struct AP64 { // Allocator64 parameters. Deliberately using a short name.
> + static const uptr kSpaceBeg = 0x600000000000ULL;
> + static const uptr kSpaceSize = 0x40000000000ULL; // 4T.
> + static const uptr kMetadataSize = sizeof(ChunkMetadata);
> + typedef DefaultSizeClassMap SizeClassMap;
> + typedef NoOpMapUnmapCallback MapUnmapCallback;
> + static const uptr kFlags = 0;
> +};
> +
> +typedef SizeClassAllocator64<AP64> PrimaryAllocator;
> +#endif
> +typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
> +
> +AllocatorCache *GetAllocatorCache();
> } // namespace __lsan
>
> #endif // LSAN_ALLOCATOR_H
>
> Modified: compiler-rt/trunk/lib/lsan/lsan_common_linux.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_linux.cc?rev=298214&r1=298213&r2=298214&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/lsan/lsan_common_linux.cc (original)
> +++ compiler-rt/trunk/lib/lsan/lsan_common_linux.cc Sun Mar 19 10:02:43
> 2017
> @@ -22,6 +22,7 @@
> #include "sanitizer_common/sanitizer_flags.h"
> #include "sanitizer_common/sanitizer_linux.h"
> #include "sanitizer_common/sanitizer_stackdepot.h"
> +#include "lsan_allocator.h"
>
> namespace __lsan {
>
> @@ -38,6 +39,9 @@ static THREADLOCAL u32 current_thread_ti
> u32 GetCurrentThread() { return current_thread_tid; }
> void SetCurrentThread(u32 tid) { current_thread_tid = tid; }
>
> +static THREADLOCAL AllocatorCache allocator_cache;
> +AllocatorCache *GetAllocatorCache() { return &allocator_cache; }
> +
> __attribute__((tls_model("initial-exec")))
> THREADLOCAL int disable_counter;
> bool DisabledInThisThread() { return disable_counter > 0; }
>
> Modified: compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_mac.cc?rev=298214&r1=298213&r2=298214&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/lsan/lsan_common_mac.cc (original)
> +++ compiler-rt/trunk/lib/lsan/lsan_common_mac.cc Sun Mar 19 10:02:43 2017
> @@ -12,12 +12,14 @@
> //
>
> //===----------------------------------------------------------------------===//
>
> -#include "sanitizer_common/sanitizer_allocator_internal.h"
> #include "sanitizer_common/sanitizer_platform.h"
> #include "lsan_common.h"
>
> #if CAN_SANITIZE_LEAKS && SANITIZER_MAC
>
> +#include "sanitizer_common/sanitizer_allocator_internal.h"
> +#include "lsan_allocator.h"
> +
> #include <pthread.h>
>
> namespace __lsan {
> @@ -25,6 +27,7 @@ namespace __lsan {
> typedef struct {
> int disable_counter;
> u32 current_thread_id;
> + AllocatorCache cache;
> } thread_local_data_t;
>
> static pthread_key_t key;
> @@ -40,6 +43,7 @@ static thread_local_data_t *get_tls_val(
> ptr = (thread_local_data_t *)InternalAlloc(sizeof(*ptr));
> ptr->disable_counter = 0;
> ptr->current_thread_id = kInvalidTid;
> + ptr->cache = AllocatorCache();
> pthread_setspecific(key, ptr);
> }
>
> @@ -62,6 +66,8 @@ u32 GetCurrentThread() { return get_tls_
>
> void SetCurrentThread(u32 tid) { get_tls_val()->current_thread_id = tid; }
>
> +AllocatorCache *GetAllocatorCache() { return &get_tls_val()->cache; }
> +
> void InitializePlatformSpecificModules() {
> CHECK(0 && "unimplemented");
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170321/1c825f00/attachment.html>
More information about the llvm-commits
mailing list