[PATCH] D29786: Use pthreads to manage thread-local storage on darwin for leak sanitizer

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 9 13:19:04 PST 2017


fjricci created this revision.

__thread is supported on Darwin, but is implemented dynamically via
function calls to __tls_get_addr. This causes two issues when combined
with leak sanitizer, due to malloc() interception.

- The dynamic loader calls malloc during the process of loading

the sanitizer dylib, while swapping a placeholder tlv_boostrap
function for __tls_get_addr. This will cause tlv_bootstrap to
be called in DisabledInThisThread() via the asan allocator.

- The first time __tls_get_addr is called, it allocates memory

for the thread-local object, during which it calls malloc(). This
call will be intercepted, leading to an infinite loop in the asan
allocator, in which the allocator calls DisabledInThisThread,
which calls tls_get_addr, which calls into the allocator again.


https://reviews.llvm.org/D29786

Files:
  lib/lsan/lsan_common.cc
  lib/lsan/lsan_common_linux.cc
  lib/lsan/lsan_common_mac.cc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29786.87866.patch
Type: text/x-patch
Size: 2849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170209/bd9d44df/attachment.bin>


More information about the llvm-commits mailing list