From 657a62f763d66469adf351219e6968022337cddf Mon Sep 17 00:00:00 2001 From: Troels Bjerre Lund Date: Wed, 10 Jan 2024 12:27:16 +0100 Subject: [PATCH] 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. --- llvm/lib/Support/Unix/Signals.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc index f68374d29f023d..1be98af0966396 100644 --- a/llvm/lib/Support/Unix/Signals.inc +++ b/llvm/lib/Support/Unix/Signals.inc @@ -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!");