Skip to content

Atomic writes patch 1

Niklas Hambüchen requested to merge nh2/ghc:issue-14533-atomic-writes into master

See #14533 (https://ghc.haskell.org/trac/ghc/ticket/14533)

This is the first MR of (likely) many to make GHC write all files atomically that are considered during incremental recompilation.

It's intended to solve numerous bugs reported in stack, Cabal etc, where users complain about builds being unfixably stuck with errors like

/tmp/ghc31452_0/ghc_2.o:ghc_1.c:function main: error: undefined reference to 'ZCMain_main_closure'

because GHC was interrupted while writing .o files, but its modification-time based check considers these files as "done" and does not rebuild them.

In some cases such truncated object files could also result in the creation of corrupt executables that GHC creates (with exit code 0!), but that crash in production.

hatrace spoiler

As mentioned in the main commit message:

This issue was reproduced with, and the fix confirmed with, the hatrace tool for syscall-based fault injection that I wrote specifically to repro bugs in GHC.

The concrete test case for GHC is at https://github.com/nh2/hatrace/blob/e23d35a2d2c79e8bf49e9e2266b3ff7094267f29/test/HatraceSpec.hs#L185; this change makes it pass.

A previous, nondeterministic reproducer for the issue was provided by Alexey Kuleshevich in https://github.com/lehins/exec-kill-loop

Edited by Niklas Hambüchen

Merge request reports