[commit: ghc] ghc-7.10: newTempName: Do not include pid in basename (1ff03e4)

git at git.haskell.org git at git.haskell.org
Tue Jun 2 21:16:13 UTC 2015


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

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/1ff03e466c9edb46aa9e148ef1dc45933796083c/ghc

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

commit 1ff03e466c9edb46aa9e148ef1dc45933796083c
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Tue Jun 2 16:12:43 2015 -0500

    newTempName: Do not include pid in basename
    
    The filename of temporary files, especially the basename of C files, can
    end up in the output in some form, e.g. as part of linker debug
    information. In the interest of bit-wise exactly reproducible
    compilation (#4012), the basename of the temporary file no longer
    contains random information (it used to ontain the process id).
    
    This is ok, as the temporary directory used contains the pid (see
    getTempDir).
    
    This patch has been applied to the Debian package (version 7.10.1-5) and
    allowed a fully bit-wise reproducible build:
    https://reproducible.debian.net/rb-pkg/experimental/amd64/ghc.html
    
    Reviewed By: austin, rwbarton
    
    Differential Revision: https://phabricator.haskell.org/D910
    
    GHC Trac Issues: #4012
    
    (cherry picked from commit 7a82b77691fb90c4af6863673f10e454a449739e)


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

1ff03e466c9edb46aa9e148ef1dc45933796083c
 compiler/main/SysTools.hs | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 540d7c4..811b930 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -1083,8 +1083,7 @@ newTempSuffix dflags = atomicModifyIORef (nextTempSuffix dflags) $ \n -> (n+1,n)
 newTempName :: DynFlags -> Suffix -> IO FilePath
 newTempName dflags extn
   = do d <- getTempDir dflags
-       x <- getProcessID
-       findTempName (d </> "ghc" ++ show x ++ "_")
+       findTempName (d </> "ghc_") -- See Note [Deterministic base name]
   where
     findTempName :: FilePath -> IO FilePath
     findTempName prefix
@@ -1099,12 +1098,11 @@ newTempName dflags extn
 newTempLibName :: DynFlags -> Suffix -> IO (FilePath, FilePath, String)
 newTempLibName dflags extn
   = do d <- getTempDir dflags
-       x <- getProcessID
-       findTempName d ("ghc" ++ show x ++ "_")
+       findTempName d ("ghc_")
   where
     findTempName :: FilePath -> String -> IO (FilePath, FilePath, String)
     findTempName dir prefix
-      = do n <- newTempSuffix dflags
+      = do n <- newTempSuffix dflags -- See Note [Deterministic base name]
            let libname = prefix ++ show n
                filename = dir </> "lib" ++ libname <.> extn
            b <- doesFileExist filename
@@ -1157,6 +1155,17 @@ getTempDir dflags = do
       `catchIO` \e -> if isAlreadyExistsError e
                       then mkTempDir prefix else ioError e
 
+-- Note [Deterministic base name]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--
+-- The filename of temporary files, especially the basename of C files, can end
+-- up in the output in some form, e.g. as part of linker debug information. In the
+-- interest of bit-wise exactly reproducible compilation (#4012), the basename of
+-- the temporary file no longer contains random information (it used to contain
+-- the process id).
+--
+-- This is ok, as the temporary directory used contains the pid (see getTempDir).
+
 addFilesToClean :: DynFlags -> [FilePath] -> IO ()
 -- May include wildcards [used by DriverPipeline.run_phase SplitMangle]
 addFilesToClean dflags new_files



More information about the ghc-commits mailing list