Skip to content

Commit c60f613

Browse files
troelsbjerreAleksei.Glushko
authored andcommitted
Disable signal handling of JVM GC signals
The JVM uses signals as an efficient way to do GC safe-pointing. When clang is loaded as a native library on the JVM, the LLVM signal handler ends up getting triggered by the signals generated by the GC mechanism. This problem is addressed by libjsig, but that approach requires preloading the library on JVM startup, which cannot be ensured when using Gradle daemons. Furthermore, libjsig does not work on newer versions of MacOS.
1 parent a04e121 commit c60f613

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

llvm/lib/Support/CrashRecoveryContext.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,12 @@ static void uninstallExceptionOrSignalHandlers() {
344344

345345
#include <signal.h>
346346

347+
/// KOTLIN/NATIVE SPECIFIC HACK
348+
///
349+
/// We need to disable handling of signals that can originate from the JVM GC,
350+
/// since they should not trigger the LLVM signal handler.
347351
static const int Signals[] =
348-
{ SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP };
352+
{ SIGABRT, /* SIGBUS, SIGFPE, SIGILL, SIGSEGV, */ SIGTRAP };
349353
static const unsigned NumSignals = std::size(Signals);
350354
static struct sigaction PrevActions[NumSignals];
351355

llvm/lib/Support/Unix/Signals.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,17 @@ static void RegisterHandlers() { // Not signal-safe.
303303

304304
enum class SignalKind { IsKill, IsInfo };
305305
auto registerHandler = [&](int Signal, SignalKind Kind) {
306+
/// KOTLIN/NATIVE SPECIFIC HACK
307+
///
308+
/// We need to disable handling of signals that can originate from the JVM GC,
309+
/// since they should not trigger the LLVM signal handler.
310+
311+
static const int JvmSigs[] = {
312+
SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGUSR1, SIGUSR2
313+
};
314+
315+
for (auto S : JvmSigs) if (Signal == S) return;
316+
306317
unsigned Index = NumRegisteredSignals.load();
307318
assert(Index < std::size(RegisteredSignalInfo) &&
308319
"Out of space for signal handlers!");

0 commit comments

Comments
 (0)