llvm-project/compiler-rt/lib
Francis Ricci eab89eb850 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: 303262
2017-05-17 14:35:17 +00:00
..
BlocksRuntime Move tests for BlocksRuntime and builtins to corresponding directories under test/ 2014-02-14 09:47:31 +00:00
asan [sanitizer] Change SizeClassAllocator32 to accept just one template 2017-05-15 14:47:19 +00:00
builtins builtins: fix guard __AEABI__ -> __ARM_EABI__ 2017-05-16 20:25:07 +00:00
cfi CFI: Add a blacklist entry for std::_Sp_counted_ptr_inplace::_Sp_counted_ptr_inplace(). 2017-05-05 18:46:14 +00:00
dfsan [sanitizer-coverage] remove more unused code 2017-04-19 23:05:53 +00:00
esan [asan] Recommit of r301904: Add strndup/__strndup interceptors 2017-05-11 08:53:24 +00:00
interception [interception] Check for export table's size before referring to its elements. 2017-01-30 18:23:37 +00:00
lsan Implement tls scanning for darwin LSan 2017-05-17 14:35:17 +00:00
msan [sanitizer] Change SizeClassAllocator32 to accept just one template 2017-05-15 14:47:19 +00:00
profile [profile] Sync up InstrProfData.inc (NFC) 2017-04-15 00:10:33 +00:00
safestack [compiler-rt] Do not introduce __sanitizer namespace globally 2016-09-15 21:02:18 +00:00
sanitizer_common Implement tls scanning for darwin LSan 2017-05-17 14:35:17 +00:00
scudo [sanitizer] Change SizeClassAllocator32 to accept just one template 2017-05-15 14:47:19 +00:00
stats Revert "[sancov] moving sancov rt to sancov/ directory" 2017-01-12 01:37:35 +00:00
tsan [tsan] Update tsan test for r303084 2017-05-16 02:06:15 +00:00
ubsan [ubsan] Implement __sanitizer_print_stack_trace for standalone UBSan runtime. 2017-05-05 09:02:28 +00:00
xray [XRay][compiler-rt] Remove unused variable after refactoring 2017-05-12 01:43:20 +00:00
CMakeLists.txt Revert "[sancov] moving sancov rt to sancov/ directory" 2017-01-12 01:37:35 +00:00