Skip to content

Commit 9337594

Browse files
authored
[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
1 parent 6d00c42 commit 9337594

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
@@ -78,6 +78,10 @@
7878
#include <__le_cwi.h>
7979
#endif
8080

81+
#if defined(__linux__)
82+
#include <sys/syscall.h>
83+
#endif
84+
8185
using namespace llvm;
8286

8387
static void SignalHandler(int Sig, siginfo_t *Info, void *);
@@ -413,10 +417,21 @@ static void SignalHandler(int Sig, siginfo_t *Info, void *) {
413417
raise(Sig);
414418
#endif
415419

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

422437
static void InfoSignalHandler(int Sig) {

0 commit comments

Comments
 (0)