[sanitizer_common] Replace forkpty with posix_spawn on Darwin
authorJulian Lettner <jlettner@apple.com>
Thu, 15 Aug 2019 00:18:55 +0000 (00:18 +0000)
committerJulian Lettner <jlettner@apple.com>
Thu, 15 Aug 2019 00:18:55 +0000 (00:18 +0000)
commit399408a92f1dbbefeb708f718b0d8eb62dfa9f09
tree317602ab47cb67e49146f4136f748a724e361e7a
parent5edd6843fa148ddc1b1a45b2bc66d1272a68d3c2
[sanitizer_common] Replace forkpty with posix_spawn on Darwin

On Darwin, we currently use forkpty to communicate with the "atos"
symbolizer. There are several problems that fork[pty] has, e.g. that
after fork, interceptors are still active and this sometimes causes
crashes or hangs. This is especially problematic for TSan, which uses
interceptors for OS-provided locks and mutexes, and even Libc functions
use those.

This patch replaces forkpty with posix_spawn on Darwin. Since
posix_spawn doesn't fork (at least on Darwin), the interceptors are not
a problem. Another benefit is that we'll handle post-fork failures (e.g.
sandbox disallows "exec") gracefully now.

Related revisions and previous attempts that were blocked by or had to
be revered due to test failures:
https://reviews.llvm.org/D48451
https://reviews.llvm.org/D40032

Reviewed By: kubamracek

Differential Revision: https://reviews.llvm.org/D65253

llvm-svn: 368947
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
compiler-rt/lib/sanitizer_common/sanitizer_posix.h
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_internal.h
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_mac.cpp
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
compiler-rt/test/asan/TestCases/Darwin/dladdr-demangling.cpp