[commit: ghc] wip/users-guide-forall-keyword, wip/users-guide-kind-inference: compiler: Write .o files atomically. See #14533 (0e2d300)

git at git.haskell.org git at git.haskell.org
Fri Feb 22 15:21:57 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branches: wip/users-guide-forall-keyword,wip/users-guide-kind-inference
Link       : http://ghc.haskell.org/trac/ghc/changeset/0e2d300a59b1b5c167d2e7d99a448c8663ba6d7d/ghc

>---------------------------------------------------------------

commit 0e2d300a59b1b5c167d2e7d99a448c8663ba6d7d
Author: Niklas Hambüchen <mail at nh2.me>
Date:   Sun Feb 17 20:48:45 2019 +0100

    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 <niklas at fpcomplete.com>
    Reviewed-by: Alexey Kuleshevich <alexey at fpcomplete.com>


>---------------------------------------------------------------

0e2d300a59b1b5c167d2e7d99a448c8663ba6d7d
 compiler/main/DriverPipeline.hs | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 5fe2362..3f59ed3 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -1375,7 +1375,12 @@ runPhase (RealPhase (As with_cpp)) input_fn dflags
                           ])
 
         liftIO $ debugTraceMsg dflags 4 (text "Running the assembler")
-        runAssembler input_fn output_fn
+
+        -- Atomic write by writing to temp file and then renaming
+        let temp_output_fn = output_fn <.> "tmp"
+        runAssembler input_fn temp_output_fn
+        liftIO $ renameFile temp_output_fn output_fn
+
         return (RealPhase next_phase, output_fn)
 
 



More information about the ghc-commits mailing list