Skip to content

Commit 9346d8d

Browse files
committed
[Support] Don't re-raise signals sent from kernel (llvm#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 (cherry picked from commit 9337594)
1 parent 4858864 commit 9346d8d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

llvm/lib/Support/Unix/Signals.inc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
#endif
8181
#endif
8282

83+
#if defined(__linux__)
84+
#include <sys/syscall.h>
85+
#endif
86+
8387
using namespace llvm;
8488

8589
static void SignalHandler(int Sig, siginfo_t *Info, void *);
@@ -411,10 +415,21 @@ static void SignalHandler(int Sig, siginfo_t *Info, void *) {
411415
raise(Sig);
412416
#endif
413417

414-
// Signal sent from another process, do not assume that continuing the
415-
// execution would re-raise it.
416-
if (Info->si_pid != getpid())
418+
#if defined(__linux__)
419+
// Re-raising a signal via `raise` loses the original siginfo. Recent
420+
// versions of linux (>= 3.9) support processes sending a signal to itself
421+
// with arbitrary signal information using a syscall. If this syscall is
422+
// unsupported, errno will be set to EPERM and `raise` will be used instead.
423+
int retval =
424+
syscall(SYS_rt_tgsigqueueinfo, getpid(), syscall(SYS_gettid), Sig, Info);
425+
if (retval != 0 && errno == EPERM)
417426
raise(Sig);
427+
#else
428+
// Signal sent from another userspace process, do not assume that continuing
429+
// the execution would re-raise it.
430+
if (Info->si_pid != getpid() && Info->si_pid != 0)
431+
raise(Sig);
432+
#endif
418433
}
419434

420435
static void InfoSignalHandler(int Sig) {

0 commit comments

Comments
 (0)