Duncan Coutts pushed to branch wip/dcoutts/signals-cleanup at Glasgow Haskell Compiler / GHC Commits: d72505e4 by Simon Jakobi at 2026-11-12T15:26:14-05:00 testsuite: Fix T17088 flakiness and restore bug coverage T17088 reads and prints a byte from an uninitialized array. Debug RTS ways fill allocated memory with 0xaa, so the test can fail due to an output mismatch unrelated to the pointer-tagging bug it covers. Initialize the byte to zero to make the output deterministic. The original bug requires the compacting collector and particular compiler and RTS settings. Run the test only in the compacting_gc way with -O1 and -A128k. Also disable STG lambda lifting because it removes the closure shape needed to reproduce the pointer-tagging failure. This makes the test reliable while ensuring it remains an effective reproducer for #17088. Closes #27534. Assisted-by: gpt-5.6-sol via Codex CLI - - - - - 5a7591b3 by David Eichmann at 2026-11-12T15:26:56-05:00 testsuite: Fix python type errors These errors appear when using the VSCode python extension which uses Pylance under the hood. - - - - - 52f129f8 by David Eichmann at 2026-11-12T15:26:56-05:00 Add test modifier to test over all IO Managers - - - - - 22e8b92a by David Eichmann at 2026-11-12T15:26:56-05:00 testsuite: include custom IO Manager in test name - - - - - 82c34ccd by Simon Jakobi at 2026-11-12T15:27:40-05:00 Make T2464 actually test #ifdef'd pragmas The test guarded a LANGUAGE EmptyDataDecls pragma behind #if, but EmptyDataDecls is on by default since Haskell2010, so the module compiled even when the guarded pragma was ignored. Guard MagicHash instead, which is unlikely to be included in a future default language. The test also checks that warnings from file-header pragmas are emitted only once, even though the pragmas are parsed both before and after CPP, using the -fffi deprecation warning as the canary. Use an unrecognised warning flag instead, so the test no longer depends on a deprecated flag that is about to be removed. Context: #27939 Assisted-by: Claude Fable 5.1 - - - - - 419f2a12 by Simon Jakobi at 2026-11-12T15:27:40-05:00 Remove command-line flags deprecated in GHC 8.2 or earlier Also remove the INCLUDE file-header pragma, which only expanded to the now-removed -#include. Closes #27939. Assisted-by: Claude Fable 5.1 - - - - - adc294d0 by Erik de Castro Lopo at 2026-11-12T15:28:21-05:00 TimerManager: publish only evaluated timeout queues (#9809) The issue in #9809 was triggered by many threads registering timeouts at the same time and those timeouts being stored as unevaluated thunks in the shared list. When say 100,000 timeouts are registered at the same time, the program can be slowed down considerably and the memory usage grow unacceptably large. The commit that caused the problem was 2d5eccdf1c, a 2013 change that fixed #7653. The fix is to add a modifyTimeouts function which applies an edit to a copy of the list and fully evaluates the result before replacing the shared list with a CAS operation. Performance has improved for the threaded case and not regressed for the single thread case: Forked registrations of 100k timeouts (median of 5 runs): -N4: 0.577 s, 428 MB -> 0.078 s, 39 MB -N12: 1.227 s, 479 MB -> 0.127 s, 80 MB Forked registrations of 1M timeouts on -N1 (median of 3 and 10 runs): 5.21 s (range 0.67-9.47 s), 1613 MB -> 0.67 s, 250 MB Single-thread registrations are unchanged or slightly faster, and timer latency during registration storms improves (p99 lateness of a 1 ms threadDelay during 100k forked registrations on -N4: 302-394 ms -> 3.5-4.1 ms). The registration code still runs in constant stack, so #7653 stays fixed; T7653 and the concurrent, base and ghc-internal testsuites pass. modifyTimeouts is OPAQUE so that the optimiser cannot expose the edit function's inspection of the old queue next to the compare-and-swap and replace the expected pointer with the evaluated queue, which would make the compare-and-swap keep failing when the MutVar# holds a thunk or indirection. Regression test T9809.hs included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> - - - - - b294b82f by Moritz Angermann at 2026-11-12T15:28:21-05:00 testsuite: give pause_resume_via_safe_ffi_concurrent 60s on Darwin CI The 10s System.Timeout watchdog was a false deadlock: five serialized 1s pauses plus rts_pause waiting on threadDelay/timer-manager traffic overruns that budget on loaded Mac runners. Keep a watchdog so a real hang still fails. - - - - - 1543f834 by Simon Jakobi at 2026-11-12T15:29:03-05:00 testsuite/README: Don't append new tests at the end of all.T Patches that each add a test at the end of the same all.T conflict with each other. Tests added elsewhere in the file usually merge cleanly. Context: #26285 Assisted-by: Claude Opus 5.5 - - - - - 9ad25cb2 by Sven Tennie at 2026-11-14T06:20:13-05:00 hadrian: Add Stage3 cross-compiled target bindist (#26924) Add a `binary-dist-stage3` Hadrian target that packages target executables (produced by the stage2 compiler) into a separate '_build/bindist-stage3/' folder, distinct from the stage2 regular or cross-compiler bindist in '_build/bindist/'. This allows a single CI pipeline job to produce both a cross-compiler bindist (e.g. x86_64 -> RISC-V) and a target-architecture bindist (e.g. RISC-V -> RISC-V) that can be installed and run natively on the target. To avoid issues with stale files or race-conditions on them, generate the `configure` script per stage in `_build/<stage>/distrib` directories. - - - - - ca91017d by Sven Tennie at 2026-11-14T06:20:13-05:00 ci: Build Stage3 and Stage2 bindists for cross targets in one job (#26924) Building the stage3 target bindist already produces most of the stage2 cross-compiler bindist as a byproduct, so building them in separate jobs duplicates the build efforts for no benefit. Instead of a separate CROSS_STAGE=3 job, the stage3 job now also builds and publishes the stage2 bindist. The stage3 tarball is named and versioned as if it were built natively on the target (target triple prefix, non-cross opsys), so its artifact name stays what downstream consumers already expect and no changes are needed on their side. For now, this is only enabled for the RISC-V job. Others can easily follow. - - - - - 71b41e09 by Sven Tennie at 2026-11-14T06:20:14-05:00 ci: model cross targets as structured TargetPlatform triples (#26924) Storing the cross target as a raw triple forced ad-hoc parsing at every use, and broke the single responsibility rule. Modelling it as a structured `TargetPlatform`` instead, avoids parsing and provides a clear separation of concerns. - - - - - 8067c2f9 by Sven Tennie at 2026-11-14T06:20:14-05:00 ci: extract the cross smoke tests into a separate smoke_test command (#26924) This reduces if-nesting and complexity of the main `test_hadrian` command. The decision how to test is now made by the caller. This is a fair choice, because most test cases can run under emulation - they are just very slow then. The Stage3 smoke test also checks that the target compiler does not report itself as cross-compiling and, when supported, runs a small GHCi expression. - - - - - 7ece99a7 by fendor at 2026-11-14T06:20:57-05:00 Add `-dep-json` flag to `ghc -M` Add an optional flag to `ghc -M` that allows to write the dependency information in JSON Lines format. The JSON Lines format enables us to stream the output of the dependency generation to a consumer. The output of `-dep-json` is streamed to a temporary file and then copied to the final destination to avoid partial writes. Each line contains one of two possible json objects: 1. A Home Unit Dependency * Contains the name of the home module, its unit, where it is located, whether a preprocessor is used, and all of its imports. Importantly, the imports include `-XExplicitLevelImports` information. * If requested via `-include-pkg-deps`, includes imports of external units, e.g. modules from `base`. * If requested via `-include-cpp-deps`, files included via CPP. 2. External Unit Dependency * Only if `-include-pkg-deps` is given * Contains unit-id, its package name and package id. --- This PR refactors the Makefile generation to use phases appropriately. We introduce an intermediate data structure that is generated based on the module graph nodes, and only then generate the Makefile rules. This allows the dep-json and dep-makefile generation to use the same dependency processing. - - - - - 0f6e0146 by fendor at 2026-11-14T06:20:57-05:00 Add multiple home unit support to `ghc -M` Allows to process the module graph of multiple home units at once using the same syntax as `--make` and `--interactive`: ghc -M -unit @unitA -unit @unitB The semantics are identical to `--make` and `--interactive`. Each home unit can declare individually to use `-include-cpp-deps` and `-include-pkg-deps`. However, there can only be one output file, and `-dep-json` and `-dep-makefile` can only be provided at the top of the cli invocation. We introduce a new GHC API `doMkDepend` that allows to use multiple home units conveniently. The output of `-dep-json` and `-dep-makefile` does not change, since we were careful to choose a format that supports multiple home units from the start. Single home units are still accepted like before with no changes. - - - - - 5598e6a0 by fendor at 2026-11-14T06:20:57-05:00 Deprecate `doMkDependHS` in favour of `doMkDepend` - - - - - 39f2943e by David Eichmann at 2026-11-14T06:21:41-05:00 rts: Expose getRtsSymbols() and store redirect labels and external symbols tag - - - - - aa159605 by David Eichmann at 2026-11-14T06:21:41-05:00 hadrian: when running tests, properly set have_gdb and have_readelf - - - - - ff826da4 by David Eichmann at 2026-11-14T06:21:41-05:00 testsuite: add have_ldd() test modifier - - - - - b9f0b7e2 by David Eichmann at 2026-11-14T06:21:41-05:00 testsuite driver: on windows, ensure PATH correctly contains mingw and ghc-pkg libraries - - - - - 543c108e by David Eichmann at 2026-11-14T06:21:41-05:00 testsuite: driver now sets WAY_FLAGS variable for makefile tests - - - - - 13408a2b by David Eichmann at 2026-11-14T06:21:41-05:00 Add golden test for rts/RtsSymbols.c This test compares declared symbols against symbols observed in the rts DSO (.so file). - - - - - 70b3b388 by Duncan Coutts at 2026-11-16T09:44:02+00:00 Move idle GC tracking to its own file, step 1 of 2 Add a new IdleGC.{c,h} module. Move the RecentActivity type, recent_activity variable and {get,set}RecentActivity wrappers. - - - - - 320cbae7 by Duncan Coutts at 2026-11-16T09:44:02+00:00 Move idle GC functionality to its own file, step 2 of 2 We can now fully encapsulate the recent_activity state, exposing just three hooks, and one query used in the scheduler and timer tick. This is a prelude to making changes to the implementation of tracking when to perform an idle gc. - - - - - 79c6ec7b by Duncan Coutts at 2026-11-16T09:44:02+00:00 Correct comments in idle GC code The comments still referred to stopTimer/startTimer. These were replaced recently by pauseTimer/unpauseTimer, but the comment was not updated. - - - - - 4aba01ba by Duncan Coutts at 2026-11-16T09:44:02+00:00 Make signal handling be a responsibility of the I/O manager(s) Previously it was scattered between I/O managers and the scheduler, and especially the scheduler's deadlock detection. Previously the scheduler would poll for pending signals each iteration of the scheduler loop. The scheduler also had some hairy signal functionality in the deadlock detection: in the non-threaded RTS (only) if there were still no threads running after deadlock detection then it would block waiting for signals. But signals can and (in my opinion) should be thought of as just a funny kind of I/O, and thus should be a responsibility of the I/O manager. So now we have the I/O managers poll for signals when they are polling for I/O completion (and removing the separate poll in the scheduler). And when I/O managers block waiting for I/O then they now also start signal handlers if they get interrupted by a signal. Crucially, if there is no pending I/O or timers, the awaitCompletedTimeoutsOrIO will still block waiting for signals. This patch puts us into an intermediate state: it temporarily breaks deadlock detection in the non-threaded RTS. The waiting on I/O currently happens before deadlock detection. This means we'll now wait forever on signals before doing deadlock detection. We need to move waiting after deadlock detection. We'll do that in a later patch. - - - - - 8a9f484c by Duncan Coutts at 2026-11-16T09:44:02+00:00 Clean up the RTS internal signal handling API Now that the I/O manager is responsible for signals, we can simplify the API we present for signal handling. We now just need startPendingSignalHandlers, which is called from the I/O managers. We can get rid of awaitUserSignals. We also don't need RtsSignals.h to re-export the platform-specific posix/Signals.h or win32/ConsoleHandler.h We can also hide more of the implementation of signals. Less has to be exposed in posix/Signals.h or win32/ConsoleHandler.h. Indeed, posix/Signals.h becomes empty and we remove it. Partly this is because we don't need inline functions (or macros) in the interface. Also remove signal_handlers from RTS ABI exported symbols list. It does not appear to have any users in the core libs, and its really an internal implementation detail. It should not be exposed unless it's really necessary. - - - - - 91d8fe68 by Duncan Coutts at 2026-11-16T09:44:02+00:00 Narrow the window in which signals might be missed before poll/select Any signals delivered just before poll/select block will be missed until they are woken later by unrelated events. This arbitrarily delays the delivery of signals. This is not a complete solution. It is a cheap way to narrow but not close the window. A full solution will have to come later. This issue existed already, and is documented in issue #27540. - - - - - e9d0c2d0 by Duncan Coutts at 2026-11-16T09:44:03+00:00 In the scheduler, move I/O blocking after deadlock detection To make deadlock detection effective in the non-threaded RTS when there are deadlocked threads and other unrelated threads waiting on I/O, we need to arrange to do deadlock detection before we block in scheduler to wait on I/O. The solution is to: 1. adjust scheduleFindWork, which runs before deadlock detection, to only poll for I/O and not block; and 2. add a step after deadlock detection to wait on I/O if there are still no threads to run (and there's any I/O or timeouts outstanding) The scheduleCheckBlockedThreads is now so simple that it made more sense to inline it into scheduleFindWork. - - - - - 400bd5e3 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Remove bogus anyPendingTimeoutsOrIO guard from scheduleDetectDeadlock The deadlock detection was only invoked if both of these conditions hold: 1. the run queue is empty 2. there is no pending I/O or timeouts The second condition is unnecessary. The deadlock detection mechanism can find deadlocks even if there are other threads waiting on I/O or timers. Having this extra condition means that we fail to detect blocked threads if there are any threads waiting on I/O or timers. Part of fixing issue #26408 - - - - - e0f0d817 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Don't consider pending I/O for early context switch optimisation Context switches are normally initiated by the timer signal. If however the user specifies "context switch as often as possible", with +RTS -C0 then the scheduler arranges for an early context switch (when it's just about to run a Haskell thread). Context switching very often is expensive, so as an optimisation there cases where we do not arrange an early context switch: 1. if there's no other threads to run 2. if there is no pending I/O or timers This patch eliminates case 2, leaving only case 1. The rationale is as follows. The use of this was inconsistent across platforms and threaded/non-threaded RTS ways. It only worked on the non-threaded RTS and on Windows only worked for the win32-legacy I/O manager. On all other combinations anyPendingTimeoutsOrIO would always return false. The fact that nobody noticed and complained about this inconsistency suggests that the feature is not relied upon. If however it turns out that applications do rely on this, then the proper thing to do is not to restore this check, but to add a new I/O manager hint function that returns if there is any pending events that are likely to happen *soon*: for example timeouts expiring within one timeslice, or I/O waits on things likely to complete soon like disk I/O, but not for example socket/pipe I/O. The motivation to avoid this use of anyPendingTimeoutsOrIO is to allow us to eliminate anyPendingTimeoutsOrIO entirely. All other uses of this are just guards on {await,poll}CompletedTimeoutsOrIO and the guards can safely be folded into those functions. This will better cope with some I/O managers having no proper implementation of anyPendingTimeoutsOrIO. Ultimately this will let us simplify the scheduler which currently has to have special #ifdef mingw32_HOST_OS cases to cope with the lack of a working anyPendingTimeoutsOrIO for some Windows I/O managers - - - - - 8bcd8361 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Remove anyPendingTimeoutsOrIO guarding {poll,await}CompletedTimeoutsOrIO Previously the API of the I/O manager used a two step process: check anyPendingTimeoutsOrIO and then call {poll,await}CompletedTimeoutsOrIO. This was primarily there as a performance thing, to cheaply check if we need to do anything. And then because anyPendingTimeoutsOrIO existed, it was used for other things too. We have now eliminated the other uses, and are just left with the performance pattern. But this was problematic because not all I/O managers correctly implement anyPendingTimeoutsOrIO (specifically the win32 ones), and now that we also make I/O managers responsible for signals then we need to poll/await even if there is no pending I/O or timeouts. If there is no pending I/O or timeouts then await needs to degenerate to just waiting forever for any signals. - - - - - 9e1b6564 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Remove anyPendingTimeoutsOrIO, it is no longer used And this avoids the problems arising from the win32 I/O managers having had a bogus implementation. - - - - - 82e08b86 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Remove second scheduler call to awaitCompletedTimeoutsOrIO Previously awaitCompletedTimeoutsOrIO was called both before and after deadlock detection in the scheduler. The reason for that was that the win32 I/O managers had a bogus implementation of anyPendingTimeoutsOrIO and this was used to guard the call of awaitCompletedTimeoutsOrIO prior to deadlock detection. This meant the first call site was never actually called when using the win32 I/O managers. This was the reason for the second call: the first one was never used. What a mess. So now we have a simple design in the scheduler: 1. poll for completed I/O, timers or signals 2. if no runnable threads: do deadlock detection 3. if still no runnable threads: block waiting for I/O, timers or signals. - - - - - 27ddfe3c by Duncan Coutts at 2026-11-16T09:44:03+00:00 Lift emptyRunQueue guard out of scheduleDetectDeadlock this improved the clarity of the logic when reading the scheduler code. And improve the comment about scheduleDoGC that was rather unclear. - - - - - eedc44c3 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Make interruptIOManager work for WinIO (non-threaded) Fixes #27403 The idle GC scheme now fundamentally relies on interruptIOManager working, so it's no longer acceptable for it to be missing for WinIO. Not having it would cause lock ups. - - - - - c3afa03c by Duncan Coutts at 2026-11-16T09:44:03+00:00 Make non-threaded deadlock detection also rely on idle GC Only do deadlock detection GC when idle GC kicks in. This also relies on using wakeUpRts, so now do this unconditionally. Previously wakeUpRts was for the threaded rts only. - - - - - 7be97c5a by Duncan Coutts at 2026-11-16T09:44:03+00:00 Enable idle GC by default on non-threaded RTS The behaviour is now uniform between the threaded and non-threaded RTS ways. The deadlock detection now relies on idle GC for both threaded and non-threaded ways. Previously deadlock detection did not rely on idle GC for the non-threaded way. Also tweak test T7275 to account for idle GC. This test's output is sensitive to the number of major GCs run. Since this commit enables idle GC for the non-threaded RTS, for this test that increases the number of major GCs, since the test program is frequently idle for more than 300ms. - - - - - 119fb03e by Duncan Coutts at 2026-11-16T09:44:03+00:00 Fix state of idle GC control vars with +RTS -V0 Currently when the user uses +RTS -I0, then doIdleGC is set to false. But if the master tick interval -V is set to 0 then the idleGCDelayTime was being set to 0 but doIdleGC was not being set to false, which is inconsistent, and almost certainly buggy. - - - - - 5b2ef052 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Add a long Note [Deadlock detection] It describes the historical and modern designs and their trade-offs. The point is we've now unified the code for deadlock detection between the threaded and non-threaded ways, by changing the non-threaded to follow the same design as the threaded. - - - - - d60ee3ba by Duncan Coutts at 2026-11-16T09:44:03+00:00 Refactor the utils providing the I/O timeout for different system APIs We have to provide a timeout in three different time formats (int milliseconds, struct timeval *, and struct timespec *). These are for platform APIs including poll, select, ppoll, pselect, epoll_wait, epoll_wait2 and in future kevent and io_uring. Previously we had one util for each format that both worked out what the timeout should be and converted it into the particular format. This duplicates some logic and it also makes it awkward to modify the timeout value (since there's no common format). Modifying the timeout value is exactly what we want to do, in a subsequent commit, where we want to adjust the timeout to take account of idle GC. - - - - - 617a8aa2 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Update the old select I/O manager to use the new timeout utils This will make it much easier to adjust the timeout to take account of idle GC. - - - - - 590db639 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Add opportunistic deadlock detection without idle GC Our general design is now that comprehensive deadlock detection relies on idle GC. This allows us to detect partial deadlocks that are not system deadlocks. But it's not prompt. It's a nice to have feature to be able to promptly detect the cases that are system deadlocks. There's no hope to do this in the threaded RTS with -N > 1, but it can be done for the non-threaded RTS and _could_ be done for the threaded RTS with -N1. We can integrate this feature into the general design without too many contortions. We just need the I/O managers to check before sleeping if they would be about to sleep indefinately with no I/O and no registered signal handlers. If so, they can notify the idle GC that we're deadlocked and we schedule and idle GC. - - - - - 56213456 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Add idle GC mode for !HAVE_PREEMPTION We have to do idle GC (and thus deadlock detection) differently when we do not have the ticker and the ability to interrupt the I/O manager when it's blocking. - - - - - 831654c6 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Add and use USED_IF_PREEMPTION to avoid warnings - - - - - 8107b91c by Duncan Coutts at 2026-11-16T09:44:03+00:00 Add performDeadlockDetection and export via ghc-experimental When documenting the idle GC and deadlock detection behaviour in the user guide, it becomes obiovus that in some cases one would want manual control over deadlock detection. In particular, for applications that disable idle GC, for debugging or robustness, they may want to invoke deadlock detecting GC manually. Bind it in ghc-internal GHC.Internal.System.Mem and re-export via ghc-experimental in System.Mem.Experimental. It is clearly implementation specific behaviour, especially since in GHC the deadlock detection is tied to doing a major GC. - - - - - e0324c95 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Add tests for deadlock detection, issue #26408 We have three tests: T26408a: make sure that we can detect a /partial deadlock/ that is not also a /system deadlock/ T26408b: make sure that we can detect a /system deadlock/ promptly without relying on idle GC T26408c: make sure that we do not falsely detect a deadlock when there is nothing to do except wait on signals T26408d: make sure that we can detect a system deadlock with idle GC disabled, after the idle GC timeout has elapsed. - - - - - 5e52b4ce by Duncan Coutts at 2026-11-16T09:44:03+00:00 Update the user guide with the revised idle GC behaviour It's now not just for the threaded RTS, but general. Add a new section in the RTS chapter: Idle GC and deadlock detection. Provide general documentation on both topics. In particular, document the behaviour of deadlock detection and how it depends on idle GC. Move the existing entries for -I and -Iw to this section. Add a changelog entry. - - - - - b47e3a72 by Duncan Coutts at 2026-11-16T09:44:03+00:00 Remove variable n_haskell_handlers which has become write-only - - - - - 76a70710 by Duncan Coutts at 2026-11-16T09:44:18+00:00 Remove use of (un)blockUserSignals in GC Once upon a time, prior to 7ed3f7556f46b957f7efb97ed7ebdc92db2f8ab7 in 2009, the signal handlers were stored within the RTS as a table of StablePtrs. This meant that the table could be accessed concurrently by the C signal handler (picking out a Haskell signal handler when the signal was delivered) and by the GC when it looks at the stable pointers. To avoid problems, the relevant signals were masked around this critical section in the GC. The use of blockUserSignals/unblockUserSignals in the GC was missed when the scheme was rewritten. We can safely remove it now. The GC no longer has anything to do with the data structures within the RTS used for signals. This probably fixes #10686, by avoiding using blockUserSignals in the GC, but the proper fix is later. - - - - - 23fd41bc by Duncan Coutts at 2026-11-16T09:44:18+00:00 Change sigprocmask to pthread_sigmask in a couple places in the rts This is part of a series of changes to fix or remove uses of sigprocmask. See issue #27968. According to Posix:
The use of the sigprocmask() function is unspecified in a multi-threaded process.
and indeed it does different things on different platforms. In particular on macOS the behaviour is to change the signal mask for every thread in the process (there is no per-process mask, it changes the per-thread mask for every thread). This obviously does not mix well with other concurrent changes to signal masks in other threads. The use of sigprocmask in exitBySignal just needs to unmask a signal in the current OS thread so that it can send a signal to itself. This purpose only requires changing the signal mask of the calling thread, which is exactly what pthread_sigmask is specified to do. In resetTerminalSettings, sigprocmask (now pthread_sigmask) is used in an attempt to mask a signal. It is unclear if this is effective. It depends on whether there are any remaining threads running by the time the function is called during shutdown. Add a Note [pthread_sigmask and the ineffectiveness of masking signals] and refer to it. - - - - - 9f952eb2 by Duncan Coutts at 2026-11-16T09:44:18+00:00 Change (un)blockUserSignals to use pthread_sigmask, not sigprocmask These functions are exported from the RTS (on posix platforms). They are used in the process library to temporarily mask signals during a fork(). This is only needed to ensure the new process has the signals masked initially. So in particular for this use case we want it to only affect the signal mask of the calling thread. Thus pthread_sigmask is appropriate. This probably fixes #10686. It should mean that there's no interaction between threads that create new processes (which manipulate the signal mask) and GC (which no longer uses blockUserSignals), or multiple OS threads that create processes concurrently, because now they only manipulate their local thread's signal mask. - - - - - 6cc97e36 by Duncan Coutts at 2026-11-16T09:44:18+00:00 Make (un)blockUserSignals local functions in win32 console handling These functions were defined for all platforms in the RTS public headers but only exported from the RTS on non-win32 platforms. They are only used externally (by the process library) on posix platforms. So for win32, break the link with the exported names and use local only C static functions. They do serve a local purpose, but are now unrelated to the posix ones. - - - - - f9d912ec by Duncan Coutts at 2026-11-16T09:44:18+00:00 In System.Posix.Internals, change import of sigprocmask to pthread_sigmask and refer to the Note. It's still pretty dubious! - - - - - 1d3b0cee by Duncan Coutts at 2026-11-16T09:44:18+00:00 Drop use of sigprocmask in stg_sig_install It is somewhat unclear what the signal masking was trying to protect in stg_sig_install. The comment said // Block the signal until we figure out what to do There are no shared data structured between stg_sig_install and the generic_handler that it installs. In any case, masking signals does not in general work, so whatever it was doing was a false sense of security. This was the last use of sigprocmask within the RTS. This completes the fix for #27968. - - - - - fbaf8e76 by Duncan Coutts at 2026-11-16T09:44:18+00:00 Make startPendingSignalHandlers a per-platform, not common, API The direction of travel is that user-signal handling should be managed by the I/O manager(s). This is because signals (& win32 console events) are (a funny kind of) I/O, and also because they have to be involved in noticing signals and starting signal handlers. And how we communicate between the low level signal handler and starting the Haskell signal handler threads is also speific to the I/O manager implementation. There is no need for a common API here. These are just utilities shared between some I/O manager implementations. - - - - - faa4c657 by Duncan Coutts at 2026-11-16T09:44:18+00:00 Unify freeSignalHandlers and finiUserSignals in RTS shutdown They were called at different stages of shutdown. Historically this might have made sense when the handler mechanism used stable pointers. Now there appears to be no good reason. On win32, freeSignalHandlers did nothing. On posix, finiUserSignals did nothing. There appears to be no dependency on the stage of shutdown. It is all local resources. - - - - - e7dc9f88 by Duncan Coutts at 2026-11-16T09:44:18+00:00 Push checks on install_signal_handlers flag into signal functions Also, change the logic slightly. The docs for --install-signal-handlers say that it installs handlers for ctl-c etc. It does _not_ say that it disables the API for Haskell code to install signal handerls. Previously however the RTS startup code would guard initUserSignals behind the flag install_signal_handlers. All that code does is initalise variables properly. This meant that when user code installs a handler, it would be working with ill-defined userSignals value and an un-initialised mutex! Similarly, in the win32 console handling, it would skip initialising the hConsoleEvent, which certainly cannot lead to good outcomes. So now we only guard initDefaultHandlers and resetDefaultHandlers behind the install_signal_handlers flag. - - - - - e6370908 by Duncan Coutts at 2026-11-16T09:44:18+00:00 Fix user guide reference to --install-signal-handlers While reviewing --install-signal-handlers docs, noticed a typo in the --generate-crash-dumps docs that referred to --install-signal-handlers when it means --install-seh-handlers. Yes I double-checked the code. - - - - - 36438ad1 by Duncan Coutts at 2026-11-16T09:44:18+00:00 Split user signal functions out of posix/Signals into new file The direction of travel is that user-signal handling should be managed by the I/O manager(s). The user signal functions (i.e. to allow Haskell code to set signal handlers) should stop being first class functions called by the rest of the RTS and become utilities used by the I/O managers. Start here by splitting them out. - - - - - 8f74a0fe by Duncan Coutts at 2026-11-16T09:44:19+00:00 Make stg_sig_install part of the IOManager API This is the external entry point for user code to install signal handlers. So it becomes part of the I/O manager API. Eventually it will dispatch to the I/O manager implementations (which will do different things), but for now it dispatches to the same old implementation, under a new name. - - - - - 198e634a by Duncan Coutts at 2026-11-16T09:44:19+00:00 Document that nocldstop is a totally mad implicit parameter and it's part of our public API! - - - - - 8282b9f3 by Duncan Coutts at 2026-11-16T09:44:19+00:00 Move user signal init and fini into the I/O manager Initially just moved into start/stopIOManager, but a later step will be to make that be part of the initialisation of each I/O manager. Why? Because they cannot have a common init if they have different data structures that need initialisation. In fact they already do have different code and data (threaded/non-threaded, windows/other), but this is fudged using CPP. - - - - - fe8606ff by Duncan Coutts at 2026-11-16T09:44:19+00:00 Push {init,fini}{UserSignals,ConsoleEvents} down into I/O managers So they become part of individual I/O managers, which will allow us to start specialising them more sanely. Rename the Win32 ones to {init,fini}ConsoleEvents. - - - - - 36ba30fc by Duncan Coutts at 2026-11-16T09:44:19+00:00 Push installUserSignalHandler down into individual I/O managers This will allow us to specialise them. Initally they all use the same (existing) generic_handler. - - - - - fd943b58 by Duncan Coutts at 2026-11-16T09:44:19+00:00 Specialise MIO's installing of signals It already used a separate implementation, but using cpp via the signal "generic_handler". Now it is much more direct and local. MIO writes signals into a pipe and reads and dispatches them at the other end (in Haskell). - - - - - 3d95658b by Duncan Coutts at 2026-11-16T09:44:19+00:00 Introduce an I/O manager data structure shared between all caps Accessed via iomgr->shared, but it points to the same struct for all capabilities. We initialise and free this with cap 0. We will use it initially for signal handling, since only one capability needs to dispatch signals. This is a fairly general mechanism, so I/O managers may be able to make use of it for other purposes, especially once in-RTS ones are adapted to work in the threaded RTS with multiple capabilities. - - - - - 2ca06f0b by Duncan Coutts at 2026-11-16T09:44:19+00:00 Use the shared I/O manager data structure for MIO for signals Move the MIO I/O manager's timer manager control fd from a global variable into the shared I/O manager struct. Soon we will use the same mechanism for the same purpose of signal handling for the other posix I/O managers. - - - - - 90ee915d by Duncan Coutts at 2026-11-16T09:44:19+00:00 Extract and add more utility functions for the signal self-pipe trick Extract a utility function writeSignalInfoToPipe from the MIO I/O manager so we can use it in other I/O managers too. Also add related utility functions readSignalInfoFromPipe, newNonBlockingPipe and startSignalHandler. We will use these in the poll and selectbis I/O managers. - - - - - f8e6d7ab by Duncan Coutts at 2026-11-16T09:44:19+00:00 Redo the scheme for special fds in the poll and selectbis I/O managers At the moment we only have one special fd for these I/O managers: the pipe (or eventfd) for interrupting them when they're sleeping. We're about to gain a second for signal handling. The existing scheme was rather ad-hoc and hard to extend. It was already complicated by the fact that the interrupt fd is optional. The signal fd will also be optional in the sense that cap 0 will have it but cap >0 will not. So the new scheme is that we add special aiop entries into the aiop_table, and for the most part we can treat these uniformly with other aiops. But the action we take for them if/when they are ready is handled specially. This seems much cleaner and will be easy to extend for signals. - - - - - 83052e66 by Duncan Coutts at 2026-11-16T09:44:19+00:00 Use the signal self-pipe trick for the poll and selectbis I/O managers So now the low level signal handler delivers signals into a pipe that is monitored by the I/O manager (on cap 0). The I/O manager then dispatches the handler (starting a Haskell thread). There are two important reasons for this change: 1. This method does not have any windows of time where signals can be missed for arbitrary periods of time. The previous method has a race where a signal delivered just before the I/O manager calls poll/select will not notice the signal until some unrelated event causes poll/select to return. See issue #27540. The new method ensures that a fd is ready and so poll/select will notice immediately (if the signal was delivered prior to the call to poll/select) or later. 2. The existing method relies on temporarily masking signals for concurrency safety which cannot work reliably in a multi-threaded process. Fixing this is a necessary pre-requisite to enable these in-RTS I/O managers to work in the threaded RTS. The issue is that startPendingSignalHandlers and the low level signal handler share the pending_handler_buf data structure, and so startPendingSignalHandlers has to mask delivery of signals to avoid the shared data being mutated concurrently. But masking signals in a multi-threaded process is not generally effective because the signal can still be delivered in any thread Document the self-pipe trick in a Note. This fixes issue #27540. - - - - - e7574be0 by Duncan Coutts at 2026-11-16T09:44:19+00:00 Move the legacy user signal handler into legacy select I/O manager We do not convert the legacy select I/O manager to use the self-pipe trick. It keeps the existing code, but since it is now the only user of it, then that code can move from being a shared utility to live with the select I/O manager. There are some minor modifications to the code moved so that it is not entangled with other remaining shared signal utils. - - - - - 4ad3ce25 by Duncan Coutts at 2026-11-16T09:46:20+00:00 Deprecate (un)blockUserSignals for external RTS users Encourage external users to stop using these actions. - - - - - 8ffc4013 by Duncan Coutts at 2026-11-16T09:46:22+00:00 Split interruptStgRts and remove wakeUpRtsViaTicker. Split the two uses of interruptStgRts into their posix and win32 cases, and move them to their use sites. Make the posix case not rely on wakeUpRts or wakeUpRtsViaTicker. The use of wakeUpRtsViaTicker while it seemed to cleverly solve overly-close coupling in one area, causes overly-close coupling in another area: ticker(s). And we want to start improving the ticker(s) but the existence of wakeUpRtsViaTicker holds that back. Delete wakeUpRtsViaTicker and its related implementation pieces. In the posix case, we add interruptIOManagerFromSignal, which is specific for the circumstance of use within a signal handler. The implementation of this for the in-RTS I/O managers is just interruptIOManager but for MIO it has to wake up the timer manager thread. All of this seems pretty unnecessary since it is all to support a ctl-c handler that is almost never used since it is duplicated and overridden by a ctl-c handler installed by runMainIO. See issue #28066. - - - - - 1ebfeb6a by Duncan Coutts at 2026-11-16T09:46:22+00:00 Simplify execution of signal handlers We make a few related changes: 1. Don't use malloc/free for passing siginfo_t from C to Haskell, use heap allocated byte arrays indead. The Haskell side already uses ForeignPtr which can use byte array directly. 2. Don't redundantly fork IO threads for signal handlers, when invoked from in-RTS I/O managers. The I/O manager already creates a new IO thread, but the existing runHandlers would then redundantly forkIO again. This is a waste of resources but also means signal handlers end up getting scheduled last. 3. Schedule signal handler threads first. This should fix #28067 Introduce new runHandler/runHandlerPtr to replace the existing runHandlers/runHandlersPtr. Conveniently the old ones have a weird name (they only invoke one handler!) so we can use a sensible name, and leave the old ones (which are exported via base!) alone. Add deprecation warnings though, since nobody should be using them via base. Update the caller in ghc-internal: the MIO timer manager. This one does need to use forkIO, but it's clearer if that forkIO is done there. - - - - - 0176641d by Duncan Coutts at 2026-11-16T09:46:22+00:00 Stop using signal-unsafe functions in signal handlers Fixes #19205 Unfortunately this does mean that the SIGQUIT functionality of dumping a stack trace has to be disabled for now. There's no short term practical way to allow that to work. The stack trace functions all use dynamic memory allocation using malloc/free, which is verboten in signal handlers. See #28071 about re-enabling the stack trace info. - - - - - bc643a84 by Duncan Coutts at 2026-11-16T09:46:22+00:00 Add a changelog entry for the signals changes - - - - - 203 changed files: - .gitignore - .gitlab/ci.sh - .gitlab/generate-ci/gen_ci.hs - .gitlab/jobs.yaml - + changelog.d/T9809-timer-manager-contention - + changelog.d/idle-gc-and-deadlock-detection - + changelog.d/make-depends-deprecate-doMkDependHS - + changelog.d/make-depends-json - + changelog.d/make-depends-multiple-home-units - + changelog.d/remove-long-deprecated-flags.md - + changelog.d/signals-cleanup - + changelog.d/stage3-cross-bindists - compiler/GHC/CmmToC.hs - compiler/GHC/CoreToStg.hs - compiler/GHC/Driver/DynFlags.hs - compiler/GHC/Driver/Flags.hs - compiler/GHC/Driver/MakeFile.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Driver/Session/Units.hs - compiler/GHC/Parser/Errors/Ppr.hs - compiler/GHC/Parser/Errors/Types.hs - compiler/GHC/Parser/Header.hs - compiler/GHC/Parser/Lexer.x - compiler/GHC/Stg/Make.hs - compiler/GHC/Types/Tickish.hs - compiler/GHC/Utils/Json.hs - docs/users_guide/codegens.rst - docs/users_guide/expected-undocumented-flags.txt - docs/users_guide/exts/control.rst - docs/users_guide/exts/ffi.rst - docs/users_guide/exts/pragmas.rst - docs/users_guide/ghc.rst - + docs/users_guide/make-depends-json-schema-1_0.json - docs/users_guide/profiling.rst - docs/users_guide/runtime_control.rst - docs/users_guide/separate_compilation.rst - − docs/users_guide/what_glasgow_exts_does.rst - ghc/Main.hs - hadrian/src/BindistConfig.hs - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/BinaryDist.hs - hadrian/src/Rules/Generate.hs - hadrian/src/Settings/Builders/RunTest.hs - hadrian/src/Settings/Packages.hs - libraries/base/tests/.gitignore - + libraries/base/tests/T9809.hs - libraries/base/tests/all.T - libraries/ghc-experimental/src/System/Mem/Experimental.hs - libraries/ghc-internal/include/RtsIfaceSymbols.h - libraries/ghc-internal/src/GHC/Internal/Conc/Signal.hs - libraries/ghc-internal/src/GHC/Internal/Event/Control.hs - libraries/ghc-internal/src/GHC/Internal/Event/TimerManager.hs - libraries/ghc-internal/src/GHC/Internal/System/Mem.hs - libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs - rts/Capability.c - rts/IOManager.c - rts/IOManager.h - rts/IOManagerInternals.h - + rts/IdleGC.c - + rts/IdleGC.h - rts/Linker.c - rts/LinkerInternals.h - rts/Prelude.h - rts/RtsFlags.c - rts/RtsSignals.h - rts/RtsStartup.c - rts/RtsSymbols.c - rts/RtsSymbols.h - rts/RtsUtils.c - rts/Schedule.c - rts/Schedule.h - rts/Ticker.h - rts/Timer.c - rts/configure.ac - rts/include/Rts.h - rts/include/rts/BlockSignals.h - rts/include/rts/IOInterface.h - rts/include/rts/OSThreads.h - rts/include/rts/PosixSource.h - + rts/include/rts/RtsSymbols.h - rts/include/rts/RtsToHsIface.h - rts/include/rts/storage/Closures.h - rts/include/rts/storage/GC.h - rts/linker/PEi386.c - rts/posix/MIO.c - rts/posix/MIO.h - rts/posix/Poll.c - rts/posix/Poll.h - rts/posix/Select.c - rts/posix/Select.h - rts/posix/SelectBis.c - rts/posix/SelectBis.h - rts/posix/Signals.c - − rts/posix/Signals.h - rts/posix/TTY.c - rts/posix/Ticker.c - rts/posix/Timeout.c - rts/posix/Timeout.h - + rts/posix/UserSignals.c - + rts/posix/UserSignals.h - rts/rts.cabal - rts/sm/GC.c - rts/win32/AsyncMIO.c - rts/win32/AsyncMIO.h - rts/win32/AsyncWinIO.c - rts/win32/AsyncWinIO.h - rts/win32/AwaitEvent.c - rts/win32/ConsoleHandler.c - rts/win32/ConsoleHandler.h - testsuite/README.md - testsuite/config/ghc - testsuite/driver/junit.py - testsuite/driver/runtests.py - testsuite/driver/testglobals.py - testsuite/driver/testlib.py - testsuite/driver/testutil.py - testsuite/mk/test.mk - testsuite/tests/cmm/should_run/all.T - testsuite/tests/driver/Makefile - testsuite/tests/driver/T2464.hs - testsuite/tests/driver/T2464.stderr - + testsuite/tests/driver/mkdepend/Makefile - + testsuite/tests/driver/mkdepend/README.md - + testsuite/tests/driver/mkdepend/T24384/A.hs - + testsuite/tests/driver/mkdepend/T24384/C.hs - + testsuite/tests/driver/mkdepend/T24384/C.hs-boot - + testsuite/tests/driver/mkdepend/T24384/D.hs - + testsuite/tests/driver/mkdepend/T24384/E.hs - + testsuite/tests/driver/mkdepend/T24384/dep-internal/DepInternal.hs - + testsuite/tests/driver/mkdepend/T24384/dep-internal/dep-internal.pkg - + testsuite/tests/driver/mkdepend/T24384/dep-public/DepPublic.hs - + testsuite/tests/driver/mkdepend/T24384/dep-public/dep-public.pkg - + testsuite/tests/driver/mkdepend/T24384/dep/Dep.hs - + testsuite/tests/driver/mkdepend/T24384/dep/dep.pkg - + testsuite/tests/driver/mkdepend/T24384/foo.h - + testsuite/tests/driver/mkdepend/T24384/lib/B.hs - + testsuite/tests/driver/mkdepend/T24384/lib/B.hs-boot - + testsuite/tests/driver/mkdepend/T24384/preproc.sh - + testsuite/tests/driver/mkdepend/T24384a.stdout - + testsuite/tests/driver/mkdepend/T24384b.stdout - + testsuite/tests/driver/mkdepend/T24384c.stdout - + testsuite/tests/driver/mkdepend/all.T - + testsuite/tests/driver/mkdepend/format_json.sh - + testsuite/tests/driver/mkdepend/format_makefile.sh - + testsuite/tests/driver/mkdepend/mhu01/a/A/Base.hs - + testsuite/tests/driver/mkdepend/mhu01/a/A/Base.hs-boot - + testsuite/tests/driver/mkdepend/mhu01/a/A/TH.hs - + testsuite/tests/driver/mkdepend/mhu01/a/Util.hs - + testsuite/tests/driver/mkdepend/mhu01/b/B/Normal.hs - + testsuite/tests/driver/mkdepend/mhu01/b/B/Splice.hs - + testsuite/tests/driver/mkdepend/mhu01/b/Util.hs - + testsuite/tests/driver/mkdepend/mhu01/c/C.hs - + testsuite/tests/driver/mkdepend/mhu01/unitA - + testsuite/tests/driver/mkdepend/mhu01/unitB - + testsuite/tests/driver/mkdepend/mhu01/unitC - + testsuite/tests/driver/mkdepend/mhu02/A.hs - + testsuite/tests/driver/mkdepend/mhu02/B.hs - + testsuite/tests/driver/mkdepend/mhu02/pp.sh - + testsuite/tests/driver/mkdepend/mhu02/unitA - + testsuite/tests/driver/mkdepend/mhu02/unitB - + testsuite/tests/driver/mkdepend/mhu03/pkg/A.hs - + testsuite/tests/driver/mkdepend/mhu03/pkg/pp.sh - + testsuite/tests/driver/mkdepend/mhu03/unitA - + testsuite/tests/driver/mkdepend/mkdepend01.dep-json - + testsuite/tests/driver/mkdepend/mkdepend01.dep-makefile - + testsuite/tests/driver/mkdepend/mkdepend01/A.hs - + testsuite/tests/driver/mkdepend/mkdepend_mhu01.dep-json - + testsuite/tests/driver/mkdepend/mkdepend_mhu01.dep-makefile - + testsuite/tests/driver/mkdepend/mkdepend_mhu02.dep-json - + testsuite/tests/driver/mkdepend/mkdepend_mhu03.dep-json - testsuite/tests/ffi/should_run/T2594.hs - testsuite/tests/ffi/should_run/ffi015.hs - testsuite/tests/ffi/should_run/fptr01.hs - testsuite/tests/ffi/should_run/fptrfail01.hs - testsuite/tests/ghci/linking/T25155_iserv_main.c - testsuite/tests/indexed-types/should_compile/all.T - testsuite/tests/indexed-types/should_fail/SkolemOccursLoop.hs - testsuite/tests/interface-stability/ghc-experimental-exports.stdout - testsuite/tests/interface-stability/ghc-experimental-exports.stdout-mingw32 - testsuite/tests/perf/compiler/large-project/all.T - + testsuite/tests/perf/compiler/large-project/large-project-mhu.sh - testsuite/tests/primops/should_run/all.T - testsuite/tests/profiling/should_run/Makefile - testsuite/tests/rts/Makefile - testsuite/tests/rts/T17088.hs - + testsuite/tests/rts/T26408a.hs - + testsuite/tests/rts/T26408a.stderr - + testsuite/tests/rts/T26408b.hs - + testsuite/tests/rts/T26408b.stderr - + testsuite/tests/rts/T26408c.hs - + testsuite/tests/rts/T26408c.stdout - + testsuite/tests/rts/T26408d.hs - + testsuite/tests/rts/T26408d.stderr - testsuite/tests/rts/all.T - testsuite/tests/rts/pause-resume/all.T - testsuite/tests/rts/pause-resume/pause_resume_via_safe_ffi_concurrent.hs - + testsuite/tests/rts/symbols/Main.hs - + testsuite/tests/rts/symbols/Makefile - + testsuite/tests/rts/symbols/all.T - + testsuite/tests/rts/symbols/dumpDeclaredSymbols.c - + testsuite/tests/rts/symbols/rts-check-symbols.sh - + testsuite/tests/rts/symbols/rts-check-symbols.stdout - utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs The diff was not included because it is too large. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/77be18109cde52bb64026c3c3b7fe0a... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/77be18109cde52bb64026c3c3b7fe0a... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Duncan Coutts (@dcoutts)