1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[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
This commit is contained in:
Vedant Kumar 2021-01-08 11:08:52 -08:00
parent 028f228360
commit 3533461f4c
2 changed files with 11 additions and 3 deletions

View File

@ -9,6 +9,7 @@
#ifndef LLVM_SUPPORT_LLVM_H
#define LLVM_SUPPORT_LLVM_H
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/PrettyStackTrace.h"
@ -44,7 +45,7 @@ public:
private:
BumpPtrAllocator Alloc;
SmallVector<const char *, 0> Args;
PrettyStackTraceProgram StackPrinter;
Optional<PrettyStackTraceProgram> StackPrinter;
};
} // namespace llvm

View File

@ -22,10 +22,17 @@ using namespace llvm;
using namespace llvm::sys;
InitLLVM::InitLLVM(int &Argc, const char **&Argv,
bool InstallPipeSignalExitHandler)
: StackPrinter(Argc, Argv) {
bool InstallPipeSignalExitHandler) {
if (InstallPipeSignalExitHandler)
// The pipe signal handler must be installed before any other handlers are
// registered. This is because the Unix \ref 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.
sys::SetOneShotPipeSignalFunction(sys::DefaultOneShotPipeSignalHandler);
// Initialize the stack printer after installing the one-shot pipe signal
// handler, so we can perform a sigaction() for SIGPIPE on Unix if requested.
StackPrinter.emplace(Argc, Argv);
sys::PrintStackTraceOnErrorSignal(Argv[0]);
install_out_of_memory_new_handler();