[InitLLVM] Ensure SIGPIPE handler installed before sigaction()
authorVedant Kumar <vsk@apple.com>
Fri, 8 Jan 2021 19:08:52 +0000 (11:08 -0800)
committerVedant Kumar <vsk@apple.com>
Fri, 8 Jan 2021 23:13:04 +0000 (15:13 -0800)
commite05baf40de8a3bbfcf4a765761b1147e94b7309c
treeee78b49ebaad0c1c1add313860d31dd4ee3bef5d
parentd86e16e4bd5ed90f08e6e787785b485636a2184d
[InitLLVM] Ensure SIGPIPE handler installed before sigaction()

The pipe signal handler must be installed before any other handlers are
registered. This is because the Unix RegisterHandlers function does not
perform a sigaction() for SIGPIPE unless a one-shot handler is present,
to allow long-lived processes (like lldb) to fully opt-out of llvm's
SIGPIPE handling and ignore the signal safely.

Fixes a bug introduced in D70277.

Tested by running Nick's test case:

% xcrun ./bin/clang -E -fno-integrated-cc1 x.c | tee foo.txt | head

I verified that child cc1 process exits with IO_ERR, and that the parent
recognizes the error code, exiting cleanly.

Differential Revision: https://reviews.llvm.org/D94324
clang/test/Driver/sigpipe-handling.c [new file with mode: 0644]
llvm/include/llvm/Support/InitLLVM.h
llvm/lib/Support/InitLLVM.cpp