[PATCH] D35513: Don't call exit() from atexit handlers on Darwin

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 15:09:12 PDT 2017


fjricci created this revision.

Calling exit() from an atexit handler is undefined behavior.
On Linux, it's unavoidable, since we cannot intercept exit (_exit isn't called
if a user program uses return instead of exit()), and I haven't
seen it cause issues regardless.

However, on Darwin, I have a fairly complex internal test that hangs roughly
once in every 300 runs after leak reporting finishes, which is resolved with
this patch, and is presumably due to the undefined behavior (since the Die() is
the only thing that happens after the end of leak reporting).

In addition, this is the way TSan works as well, where an atexit handler+Die()
is used on Linux, and an _exit() interceptor is used on Darwin. I'm not sure if it's
intentionally structured that way in TSan, since TSan sets up the atexit handler and the
_exit() interceptor on both platforms, but I have observed that on Darwin, only the
_exit() interceptor is used, and on Linux the atexit handler is used.

There is some additional related discussion here: https://reviews.llvm.org/D35085


https://reviews.llvm.org/D35513

Files:
  lib/asan/asan_interceptors.cc
  lib/lsan/lsan_common.cc
  lib/lsan/lsan_common.h
  lib/lsan/lsan_common_linux.cc
  lib/lsan/lsan_common_mac.cc
  lib/lsan/lsan_interceptors.cc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35513.106964.patch
Type: text/x-patch
Size: 3542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170717/8aaa9c8d/attachment.bin>


More information about the llvm-commits mailing list