Skip to content

Commit

Permalink
Disable signal handling of JVM GC signals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
troelsbjerre committed Jan 10, 2024
1 parent 9205ffc commit 657a62f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions llvm/lib/Support/Unix/Signals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,17 @@ static void RegisterHandlers() { // Not signal-safe.

enum class SignalKind { IsKill, IsInfo };
auto registerHandler = [&](int Signal, SignalKind Kind) {
/// KOTLIN/NATIVE SPECIFIC HACK
///
/// We need to disable handling of signals that can originate from the JVM GC,
/// since they should not trigger the LLVM signal handler.

static const int JvmSigs[] = {
SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGUSR1, SIGUSR2
};

for (auto S : JvmSigs) if (Signal == S) return;

unsigned Index = NumRegisteredSignals.load();
assert(Index < array_lengthof(RegisteredSignalInfo) &&
"Out of space for signal handlers!");
Expand Down

0 comments on commit 657a62f

Please sign in to comment.