compiler: Write .o files atomically. See #14533
compiler: Write .o files atomically. See #14533

This issue was reproduced with, and the fix confirmed with,
the `hatrace` tool for syscall-based fault injection:

    https://github.com/nh2/hatrace

The concrete test case for GHC is at

    https://github.com/nh2/hatrace/blob/e23d35a2d2c79e8bf49e9e2266b3ff7094267f29/test/HatraceSpec.hs#L185

A previous, nondeterministic reproducer for the issue was provided by
Alexey Kuleshevich in

    https://github.com/lehins/exec-kill-loop

Signed-off-by: Niklas Hambüchen <61ebf6bc14ce01e4cc9d59ee9f469c902ea13918@fpcomplete.com>
Reviewed-by: Alexey Kuleshevich <ddcae1f7fb5ed59c43367a8e69a32583fd34fee0@fpcomplete.com>

sdiehl/ghc,sdiehl/ghc,sdiehl/ghc,sdiehl/ghc,sdiehl/ghc,sdiehl/ghc,sdiehl/ghc