[PATCH] D33215: Implement tls scanning for darwin LSan

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 14:52:54 PDT 2017


fjricci created this revision.
Herald added a subscriber: krytarowski.

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.


https://reviews.llvm.org/D33215

Files:
  lib/lsan/lsan_common.cc
  lib/lsan/lsan_common_mac.cc
  lib/lsan/lsan_flags.inc
  lib/sanitizer_common/sanitizer_mac.cc
  test/lsan/TestCases/many_tls_keys.cc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33215.99067.patch
Type: text/x-patch
Size: 6841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170515/2dfd6f52/attachment.bin>


More information about the llvm-commits mailing list