[llvm] 9337594 - [Support] Don't re-raise signals sent from kernel (#145759)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 9 14:53:19 PDT 2025
Author: Alex Langford
Date: 2025-07-09T14:53:15-07:00
New Revision: 9337594e3346e15b5bc90b5372b8b482aa5af37f
URL: https://github.com/llvm/llvm-project/commit/9337594e3346e15b5bc90b5372b8b482aa5af37f
DIFF: https://github.com/llvm/llvm-project/commit/9337594e3346e15b5bc90b5372b8b482aa5af37f.diff
LOG: [Support] Don't re-raise signals sent from kernel (#145759)
When an llvm tool crashes (e.g. from a segmentation fault),
SignalHandler will re-raise the signal. The effect is that crash reports
now contain SignalHandler in the stack trace. The crash reports are
still useful, but the presence of SignalHandler can confuse tooling and
automation that deduplicate or analyze crash reports.
rdar://150464802
Added:
Modified:
llvm/lib/Support/Unix/Signals.inc
Removed:
################################################################################
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index a4525a5903649..6cd38aabc734e 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -78,6 +78,10 @@
#include <__le_cwi.h>
#endif
+#if defined(__linux__)
+#include <sys/syscall.h>
+#endif
+
using namespace llvm;
static void SignalHandler(int Sig, siginfo_t *Info, void *);
@@ -413,10 +417,21 @@ static void SignalHandler(int Sig, siginfo_t *Info, void *) {
raise(Sig);
#endif
- // Signal sent from another process, do not assume that continuing the
- // execution would re-raise it.
- if (Info->si_pid != getpid())
+#if defined(__linux__)
+ // Re-raising a signal via `raise` loses the original siginfo. Recent
+ // versions of linux (>= 3.9) support processes sending a signal to itself
+ // with arbitrary signal information using a syscall. If this syscall is
+ // unsupported, errno will be set to EPERM and `raise` will be used instead.
+ int retval =
+ syscall(SYS_rt_tgsigqueueinfo, getpid(), syscall(SYS_gettid), Sig, Info);
+ if (retval != 0 && errno == EPERM)
raise(Sig);
+#else
+ // Signal sent from another userspace process, do not assume that continuing
+ // the execution would re-raise it.
+ if (Info->si_pid != getpid() && Info->si_pid != 0)
+ raise(Sig);
+#endif
}
static void InfoSignalHandler(int Sig) {
More information about the llvm-commits
mailing list