[llvm] [Support] Don't re-raise signals sent from kernel (PR #145759)

Alex Langford via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 14:58:18 PDT 2025


https://github.com/bulbazord updated https://github.com/llvm/llvm-project/pull/145759

>From 89e3365513a20868208eabec3b5d49b674d522ad Mon Sep 17 00:00:00 2001
From: Alex Langford <alangford at apple.com>
Date: Wed, 25 Jun 2025 11:08:03 -0700
Subject: [PATCH 1/3] [Support] Don't re-raise signals sent from kernel

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
---
 llvm/lib/Support/Unix/Signals.inc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index a4525a5903649..b575e50d6ee6d 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -413,9 +413,9 @@ 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())
+  // 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);
 }
 

>From c215577d966ac7938aec399188e2847924ba4ac2 Mon Sep 17 00:00:00 2001
From: Alex Langford <alangford at apple.com>
Date: Tue, 8 Jul 2025 13:32:46 -0700
Subject: [PATCH 2/3] fixup! [Support] Don't re-raise signals sent from kernel

---
 llvm/lib/Support/Unix/Signals.inc | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index b575e50d6ee6d..392737244c236 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -415,8 +415,20 @@ static void SignalHandler(int Sig, siginfo_t *Info, void *) {
 
   // 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)
+  if (Info->si_pid != getpid() && Info->si_pid != 0) {
+#if defined(__linux__) || defined(__ANDROID__)
+    // 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
     raise(Sig);
+#endif
+  }
 }
 
 static void InfoSignalHandler(int Sig) {

>From 546850e1f7fecd5087a39b97645355c828d181d3 Mon Sep 17 00:00:00 2001
From: Alex Langford <alangford at apple.com>
Date: Tue, 8 Jul 2025 14:58:02 -0700
Subject: [PATCH 3/3] fixup! fixup! [Support] Don't re-raise signals sent from
 kernel

---
 llvm/lib/Support/Unix/Signals.inc | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 392737244c236..1109e8aa5dd4b 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -413,22 +413,21 @@ static void SignalHandler(int Sig, siginfo_t *Info, void *) {
     raise(Sig);
 #endif
 
-  // 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) {
 #if defined(__linux__) || defined(__ANDROID__)
-    // 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);
+  // 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