This is an archive of the discontinued LLVM Phabricator instance.

Correct crashes in TSan on NetBSD
AbandonedPublic

Authored by krytarowski on Nov 3 2017, 1:06 PM.

Details

Summary

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.
  1. Add interceptor for _lwp_exit() on NetBSD-only.
  1. Disable detection of on_exit() on NetBSD. Introduce TSAN_MAYBE_INTERCEPT_ON_EXIT. It looks like this code fixes build for Darwin.
  1. 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.
  1. 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>

Diff Detail

Repository
rL LLVM

Event Timeline

krytarowski created this revision.Nov 3 2017, 1:06 PM
vitalybuka edited edge metadata.Nov 3 2017, 1:16 PM

It's not obvious to guess which of 1,2,..5 correspond to which line of the patch
Could you please split patches accordingly?

krytarowski abandoned this revision.Nov 3 2017, 1:18 PM

This patch will be divided into smaller chunks.