[PATCH] D39614: Correct crashes in TSan on NetBSD

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 13:06:46 PDT 2017


krytarowski created this revision.
krytarowski added a project: Sanitizers.
Herald added a subscriber: kubamracek.

Fix few problems on NetBSD that caused crashes.

1. Correct handling death of a thread. Stop using the Linux solution with pthread_key_create(3). This does not work on NetBSD, because calling the thread destructor is not the latest operation on a POSIX thread entity. NetBSD's libpthread still calls at least pthread_mutex_lock and pthread_mutex_unlock. Detect _lwp_exit(2) call as it is really the latest operation called from a detaching POSIX thread.

2. Add interceptor for _lwp_exit() on NetBSD-only.

3. Disable detection of on_exit() on NetBSD. Introduce TSAN_MAYBE_INTERCEPT_ON_EXIT. It looks like this code fixes build for Darwin.

4. Correct handling atexit(3). The NetBSD specific implementation of __cxa_atexit() does not preserve the 2nd argument if dso is equal to NULL. Split paths of handling intercepted __cxa_atexit() and atexit(3). Add a local stack-like structure to hold the __cxa_atexit() context. atexit(3) is documented in the C standard as calling callback from the earliest to the oldest entry. This path also fixes potential ABI problem of passing an argument to a function from the atexit(3) callback mechanism.

  Proposal to change the behavior of __cxa_atexit() in NetBSD has been rejected.

5. Introduce new internal allocator: InternalReallocArr() that has been modeled after NetBSD's reallocarr(3) extension to libc. This function is handy to resize/free arrays.

With the above changes, TSan/NetBSD can fully bootstrap into operation.

Sponsored by <The NetBSD Foundation>


Repository:
  rL LLVM

https://reviews.llvm.org/D39614

Files:
  lib/sanitizer_common/sanitizer_allocator.cc
  lib/sanitizer_common/sanitizer_allocator_internal.h
  lib/tsan/rtl/tsan_interceptors.cc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39614.121529.patch
Type: text/x-patch
Size: 5692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171103/bbe44fef/attachment.bin>


More information about the llvm-commits mailing list