llvm-project/compiler-rt/lib/lsan
Francis Ricci 86e070f7e9 Implement tls scanning for darwin LSan
Summary:
This required for any users who call exit() after creating
thread-specific data, as tls destructors are only called when
pthread_exit() or pthread_cancel() are used. This should also
match tls behavior on linux.

Getting the base address of the tls section is straightforward,
as it's stored as a section offset in %gs. The size is a bit trickier
to work out, as there doesn't appear to be any official documentation
or source code referring to it. The size used in this patch was determined
by taking the difference between the base address and the address of the
subsequent memory region returned by vm_region_recurse_64, which was
1024 * sizeof(uptr) on all threads except the main thread, where it was
larger. Since the section must be the same size on all of the threads,
1024 * sizeof(uptr) seemed to be a reasonable size to use, barring
a more programtic way to get the size.

1024 seems like a reasonable number, given that PTHREAD_KEYS_MAX
is 512 on darwin, so pthread keys will fit inside the region while
leaving space for other tls data. A larger size would overflow the
memory region returned by vm_region_recurse_64, and a smaller size
wouldn't leave room for all the pthread keys. In addition, the
stress test added here passes, which means that we are scanning at
least the full set of possible pthread keys, and probably
the full tls section.

Reviewers: alekseyshl, kubamracek

Subscribers: krytarowski, llvm-commits

Differential Revision: https://reviews.llvm.org/D33215

llvm-svn: 303887
2017-05-25 17:41:13 +00:00
..
.clang-format Tell clang-format that (most) sanitizers are written using Google style guide. 2015-11-19 22:11:10 +00:00
CMakeLists.txt Implement standalone lsan interceptors for OS X 2017-04-11 20:05:02 +00:00
lsan.cc Implement standalone lsan interceptors for OS X 2017-04-11 20:05:02 +00:00
lsan.h Implement standalone lsan interceptors for OS X 2017-04-11 20:05:02 +00:00
lsan_allocator.cc Implement standalone lsan interceptors for OS X 2017-04-11 20:05:02 +00:00
lsan_allocator.h [sanitizer] Change SizeClassAllocator32 to accept just one template 2017-05-15 14:47:19 +00:00
lsan_common.cc Implement tls scanning for darwin LSan 2017-05-25 17:41:13 +00:00
lsan_common.h [lsan] Enable LSan on PowerPC64. 2017-04-21 21:59:53 +00:00
lsan_common_linux.cc [lsan] Report the missing linker only when the linker is actually missing. 2017-05-15 23:11:01 +00:00
lsan_common_mac.cc Implement tls scanning for darwin LSan 2017-05-25 17:41:13 +00:00
lsan_flags.inc Implement tls scanning for darwin LSan 2017-05-25 17:41:13 +00:00
lsan_interceptors.cc [sanitizer] Intercept mcheck and mprobe on Linux 2017-05-03 07:09:10 +00:00
lsan_linux.cc Implement standalone lsan interceptors for OS X 2017-04-11 20:05:02 +00:00
lsan_malloc_mac.cc Implement standalone lsan interceptors for OS X 2017-04-11 20:05:02 +00:00
lsan_preinit.cc [Sanitizer] Introduce SANITIZER_CAN_USE_PREINIT_ARRAY definition and use it across sanitizers. 2014-07-25 22:05:02 +00:00
lsan_thread.cc [sanitizer] Introduce tid_t as a typedef for OS-provided thread IDs 2017-04-17 18:17:38 +00:00
lsan_thread.h [sanitizer] Introduce tid_t as a typedef for OS-provided thread IDs 2017-04-17 18:17:38 +00:00
weak_symbols.txt Add cmake build support for lsan on OS X 2017-02-14 00:56:53 +00:00