diff options
author | Vedant Kumar <vsk@apple.com> | 2019-11-14 14:30:56 -0800 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2019-11-18 10:27:27 -0800 |
commit | 4624e83ce7b124545b55e45ba13f2d900ed65654 (patch) | |
tree | 740c1cb7f4666d5cd5f1895184e0a3d4699f1004 /lldb/tools/driver/Driver.cpp | |
parent | 5a4a05d776d3adacad344b2b5e15cf594c906bce (diff) | |
download | bcm5719-llvm-4624e83ce7b124545b55e45ba13f2d900ed65654.tar.gz bcm5719-llvm-4624e83ce7b124545b55e45ba13f2d900ed65654.zip |
[Signal] Allow llvm clients to opt into one-shot SIGPIPE handling
Allow clients of the llvm library to opt-in to one-shot SIGPIPE
handling, instead of forcing them to undo llvm's SIGPIPE handler
registration (which is brittle).
The current behavior is preserved for all llvm-derived tools (except
lldb) by means of a default-`true` flag in the InitLLVM constructor.
This prevents "IO error" crashes in long-lived processes (lldb is the
motivating example) which both a) load llvm as a dynamic library and b)
*really* need to ignore SIGPIPE.
As llvm signal handlers can be installed when calling into libclang
(say, via RemoveFileOnSignal), thereby overriding a previous SIG_IGN for
SIGPIPE, there is no clean way to opt-out of "exit-on-SIGPIPE" in the
current model.
Differential Revision: https://reviews.llvm.org/D70277
Diffstat (limited to 'lldb/tools/driver/Driver.cpp')
-rw-r--r-- | lldb/tools/driver/Driver.cpp | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp index 2070e55d7d2..b77350190be 100644 --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -810,7 +810,7 @@ int main(int argc, char const *argv[]) { // Setup LLVM signal handlers and make sure we call llvm_shutdown() on // destruction. - llvm::InitLLVM IL(argc, argv); + llvm::InitLLVM IL(argc, argv, /*InstallPipeSignalExitHandler=*/false); // Parse arguments. LLDBOptTable T; @@ -841,25 +841,6 @@ int main(int argc, char const *argv[]) } SBHostOS::ThreadCreated("<lldb.driver.main-thread>"); - // Install llvm's signal handlers up front to prevent lldb's handlers from - // being ignored. This is (hopefully) a stopgap workaround. - // - // When lldb invokes an llvm API that installs signal handlers (e.g. - // llvm::sys::RemoveFileOnSignal, possibly via a compiler embedded within - // lldb), lldb's signal handlers are overriden if llvm is installing its - // handlers for the first time. - // - // To work around llvm's behavior, force it to install its handlers up front, - // and *then* install lldb's handlers. In practice this is used to prevent - // lldb test processes from exiting due to IO_ERR when SIGPIPE is received. - // - // Note that when llvm installs its handlers, it 1) records the old handlers - // it replaces and 2) re-installs the old handlers when its new handler is - // invoked. That means that a signal not explicitly handled by lldb can fall - // back to being handled by llvm's handler the first time it is received, - // and then by the default handler the second time it is received. - llvm::sys::AddSignalHandler([](void *) -> void {}, nullptr); - signal(SIGINT, sigint_handler); #if !defined(_MSC_VER) signal(SIGPIPE, SIG_IGN); |