[Git][ghc/ghc][master] 8 commits: linker: Remove DotA and DotDLL constructors of LinkablePart
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: e02a40c5 by Zubin Duggal at 2026-11-26T21:20:10-05:00 linker: Remove DotA and DotDLL constructors of LinkablePart As far as I can, we have never actually used these constructors, and they have never appeared in a positive position, ever since they were introduced a long time ago. Foreign libraries aren't loaded through these either, that happens either through `loadPackages` which uses `LibrarySpec` or through 'loadCmdLineLibs' Also, a Linkable defines the build product of a single home module. DotA/DotDLL are library like things, so they don't fit into a Linkable anyway. - - - - - 56ae5186 by Zubin Duggal at 2026-11-26T21:20:10-05:00 Identify Linkable with fingerprints of their contents rather than modtimes - - - - - 3b1fe950 by Zubin Duggal at 2026-11-26T21:20:10-05:00 Linker cleanup delete a bunch of unused functions - - - - - 8f2d4513 by Zubin Duggal at 2026-11-26T21:20:10-05:00 Record constituent hashes for bytecode libraries A bytecode library now records the combined hash of its constituents, so relinking can be skipped when they haven't changed. - - - - - bd43176e by Zubin Duggal at 2026-11-26T21:20:10-05:00 bytecode: Give persistent bytecode files a fixed-size header with a hash The header of .gbc and .bytecodelib files now consists of the magic word, the compiler version and a hash, all with fixed-length encodings. The hash is the gbc_hash of a bytecode file, or the inputs hash of a bytecode library. readBinByteCodeHash and readBytecodeLibInputsHash now read only the header rather than the whole file. The version is written as its four numeric components instead of as a string. - - - - - c62000f2 by Zubin Duggal at 2026-11-26T21:20:10-05:00 driver: Refresh ms_bytecode_date when reusing a ModSummary - - - - - f979f719 by Zubin Duggal at 2026-11-26T21:20:10-05:00 bytecode: Treat persistent bytecode files with a bad header as stale - - - - - cf85181f by Zubin Duggal at 2026-11-26T21:20:10-05:00 bytecode: Record the inputs hash in BytecodeLib ------------------------- Metric Increase: MultiLayerModulesRecomp MultiLayerModulesTH_Make MultiLayerModulesTH_OneShot ------------------------- - - - - - 22 changed files: - compiler/GHC/ByteCode/Binary.hs - compiler/GHC/ByteCode/Serialize.hs - compiler/GHC/Driver/Downsweep.hs - compiler/GHC/Driver/Main/Compile.hs - compiler/GHC/Driver/Main/Passes.hs - compiler/GHC/Driver/Pipeline.hs - compiler/GHC/Linker/ByteCode.hs - compiler/GHC/Linker/Deps.hs - compiler/GHC/Linker/Loader.hs - compiler/GHC/Linker/Types.hs - compiler/GHC/Unit/Finder.hs - testsuite/tests/driver/bytecode-object/Makefile - testsuite/tests/driver/bytecode-object/all.T - + testsuite/tests/driver/bytecode-object/bytecode_object27.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object28.script - + testsuite/tests/driver/bytecode-object/bytecode_object28.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object29.stdout - + testsuite/tests/driver/recomp023/M.hs - + testsuite/tests/driver/recomp023/M2.hs - + testsuite/tests/driver/recomp023/Makefile - + testsuite/tests/driver/recomp023/all.T - + testsuite/tests/driver/recomp023/recomp023.stdout Changes: ===================================== compiler/GHC/ByteCode/Binary.hs ===================================== @@ -66,6 +66,7 @@ type BytecodeLib = BytecodeLibX (Maybe InterpreterLibrary) -- | A bytecode library is a collection of CompiledByteCode objects and a .so file containing the combination of foreign stubs data BytecodeLibX a = BytecodeLib { bytecodeLibUnitId :: UnitId, + bytecodeLibInputsHash :: Fingerprint, -- ^ See Note [Hash of bytecode libs] in GHC.ByteCode.Serialize bytecodeLibFiles :: [CompiledByteCode], bytecodeLibForeign :: a -- A library file containing the combination of foreign stubs. (Ie arising from CApiFFI) } @@ -113,12 +114,14 @@ instance Binary OnDiskModuleByteCode where instance Binary OnDiskBytecodeLib where get bh = do bytecodeLibUnitId <- get bh + bytecodeLibInputsHash <- get bh bytecodeLibFiles <- get bh bytecodeLibForeign <- get bh pure BytecodeLib {..} put_ bh BytecodeLib {..} = do put_ bh bytecodeLibUnitId + put_ bh bytecodeLibInputsHash put_ bh bytecodeLibFiles put_ bh bytecodeLibForeign ===================================== compiler/GHC/ByteCode/Serialize.hs ===================================== @@ -6,7 +6,7 @@ {- | This module implements the serialization of bytecode objects to and from disk. -} module GHC.ByteCode.Serialize - ( writeBinByteCode, readBinByteCode, readOnDiskModuleByteCode + ( writeBinByteCode, readBinByteCode, readBinByteCodeHash, readOnDiskModuleByteCode , ModuleByteCode(..) , BytecodeLibX(..) , BytecodeLib @@ -15,6 +15,8 @@ module GHC.ByteCode.Serialize , InterpreterLibraryContents(..) , writeBytecodeLib , readBytecodeLib + , readBytecodeLibInputsHash + , fingerprintBytecodeLibInputs , mkModuleByteCode , fingerprintModuleByteCodeContents , decodeOnDiskModuleByteCode @@ -27,22 +29,25 @@ import GHC.Prelude import GHC.ByteCode.Binary import GHC.ByteCode.Recomp.Binary (computeFingerprint) import GHC.ByteCode.Types +import GHC.Data.Maybe (rightToMaybe) import GHC.Driver.DynFlags import GHC.Driver.Env import GHC.Iface.Binary import GHC.Iface.Recomp.Binary (putNameLiterally) import GHC.Linker.Types -import GHC.Settings.Constants (hiVersion) import GHC.Unit.Types import GHC.Utils.Binary -import GHC.Utils.Fingerprint (Fingerprint) +import GHC.Utils.Exception (tryIO) +import GHC.Utils.Fingerprint (Fingerprint(..), fingerprintFingerprints) import GHC.Utils.Logger import GHC.Utils.Panic import GHC.Utils.TmpFs +import GHC.Version (cProjectVersionInt, cProjectPatchLevel1, cProjectPatchLevel2) import Data.ByteString (ByteString) import Data.ByteString qualified as BS import Data.Char (ord) +import Data.List (intercalate, sort) import Data.Traversable import Data.Word import System.Directory @@ -84,6 +89,7 @@ The ticket where bytecode objects were dicussed is #26298 See Note [-fwrite-byte-code is not the default] See Note [Recompilation avoidance with bytecode objects] See Note [Persistent bytecode file headers] +See Note [Hash of bytecode libs] Note [Persistent bytecode file headers] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -92,30 +98,59 @@ are version-specific binary formats. Without a small file-level header, stale or corrupt files are only discovered once we start deserialising the payload, which can lead to confusing failures. -To make these failures explicit, we write a file-kind-specific magic word and -the current `hiVersion` ahead of the binary payload. Readers validate this -header before setting up the normal `Name`/`FastString` deserialisation -machinery. This follows the same approach as normal interface files. +To make these failures explicit, we write a header ahead of the binary payload: + + * a file-kind-specific magic word, + * the version of the compiler (`PersistentBytecodeVersion`), + * a hash: the `gbc_hash` of a bytecode file, or the inputs hash of a + bytecode library (see Note [Hash of bytecode libs]). + +We ensure everthing has a fixed length encoding (see +`persistentBytecodeHeaderSize`, so that `readPersistentBytecodeHash` can read +the hash without reading the rest of the file. + +Note [Hash of bytecode libs] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +A bytecode library records the combined hash of its constituents, so +that relinking can be skipped when they haven't changed. + +We can't hash the library file itself: we would have to build the +library to know which hash to expect. So we compare the inputs. + +The hash is part of the file header, see Note [Persistent bytecode file +headers]. The constituent hashes are sorted before they are combined, so +the order of the modules doesn't matter. -} +-- | The 'bytecodeLibInputsHash' of a bytecode library, given the hash of each +-- constituent. +-- See Note [Hash of bytecode libs] +fingerprintBytecodeLibInputs :: [Fingerprint] -> Fingerprint +fingerprintBytecodeLibInputs = fingerprintFingerprints . sort + writeBytecodeLib :: BytecodeLib -> FilePath -> IO () writeBytecodeLib lib path = do odbco <- encodeBytecodeLib lib createDirectoryIfMissing True (takeDirectory path) bh' <- openBinMem initBinMemSize bh <- addBinNameWriter bh' - writePersistentBytecodeHeader BytecodeLibraryFile bh + writePersistentBytecodeHeader BytecodeLibraryFile (bytecodeLibInputsHash lib) bh putWithUserData QuietBinIFace NormalCompression bh odbco writeBinMem bh path readBytecodeLib :: HscEnv -> FilePath -> IO OnDiskBytecodeLib readBytecodeLib hsc_env path = do bh' <- readBinMem path - readPersistentBytecodeHeader BytecodeLibraryFile path bh' + _inputs_hash <- readPersistentBytecodeHeader BytecodeLibraryFile path bh' bh <- addBinNameReader (hsc_NC hsc_env) bh' res <- getWithUserData (hsc_NC hsc_env) bh pure res +-- | 'Nothing' if the file can't be read or its header is not valid. +-- See Note [Hash of bytecode libs] +readBytecodeLibInputsHash :: FilePath -> IO (Maybe Fingerprint) +readBytecodeLibInputsHash = readPersistentBytecodeHash BytecodeLibraryFile + -- | Convert an 'OnDiskModuleByteCode' to an 'ModuleByteCode'. -- 'OnDiskModuleByteCode' is the representation which we read from a file, -- the 'ModuleByteCode' is the representation which is manipulated by program logic. @@ -139,6 +174,7 @@ decodeOnDiskBytecodeLib hsc_env odbco = do foreign_contents <- traverse (writeInterpreterLibraryFile (hsc_logger hsc_env) (hsc_tmpfs hsc_env) (tmpDir (hsc_dflags hsc_env))) (bytecodeLibForeign odbco) pure $ BytecodeLib { bytecodeLibUnitId = bytecodeLibUnitId odbco, + bytecodeLibInputsHash = bytecodeLibInputsHash odbco, bytecodeLibFiles = bytecodeLibFiles odbco, bytecodeLibForeign = foreign_contents } @@ -148,6 +184,7 @@ encodeBytecodeLib (BytecodeLib {..}) = do foreign_contents <- traverse readInterpreterLibraryFile bytecodeLibForeign pure $ BytecodeLib { bytecodeLibUnitId = bytecodeLibUnitId, + bytecodeLibInputsHash = bytecodeLibInputsHash, bytecodeLibFiles = bytecodeLibFiles, bytecodeLibForeign = foreign_contents } @@ -200,10 +237,15 @@ readBinByteCode hsc_env f = do odbco <- readOnDiskModuleByteCode hsc_env f decodeOnDiskModuleByteCode hsc_env odbco +-- | Read the hash of a bytecode file, without reading the rest of the file. +-- 'Nothing' if the file can't be read or its header is not valid. +readBinByteCodeHash :: FilePath -> IO (Maybe Fingerprint) +readBinByteCodeHash = readPersistentBytecodeHash ModuleByteCodeFile + readOnDiskModuleByteCode :: HscEnv -> FilePath -> IO OnDiskModuleByteCode readOnDiskModuleByteCode hsc_env f = do bh' <- readBinMem f - readPersistentBytecodeHeader ModuleByteCodeFile f bh' + _hash <- readPersistentBytecodeHeader ModuleByteCodeFile f bh' bh <- addBinNameReader (hsc_NC hsc_env) bh' getWithUserData (hsc_NC hsc_env) bh @@ -214,7 +256,7 @@ writeBinByteCode f cbc = do bh' <- openBinMem initBinMemSize bh <- addBinNameWriter bh' odbco <- encodeOnDiskModuleByteCode cbc - writePersistentBytecodeHeader ModuleByteCodeFile bh + writePersistentBytecodeHeader ModuleByteCodeFile (gbc_hash cbc) bh putWithUserData QuietBinIFace NormalCompression bh odbco writeBinMem bh f @@ -242,30 +284,82 @@ data PersistentBytecodeFile = ModuleByteCodeFile | BytecodeLibraryFile +-- | The version of the compiler: major, minor, patch1, patch2 +data PersistentBytecodeVersion + = PersistentBytecodeVersion !Word32 !Word32 !Word32 !Word32 + deriving Eq + +instance Binary PersistentBytecodeVersion where + put_ bh (PersistentBytecodeVersion a b c d) = + mapM_ (put_ bh . FixedLengthEncoding) [a, b, c, d] + get bh = PersistentBytecodeVersion <$> field <*> field <*> field <*> field + where field = unFixedLength <$> get bh + +persistentBytecodeVersion :: PersistentBytecodeVersion +persistentBytecodeVersion = + PersistentBytecodeVersion + (version_int `div` 100) (version_int `mod` 100) + (read cProjectPatchLevel1) (read cProjectPatchLevel2) + where + version_int = read cProjectVersionInt + +showPersistentBytecodeVersion :: PersistentBytecodeVersion -> String +showPersistentBytecodeVersion (PersistentBytecodeVersion a b c d) = + intercalate "." (map show [a, b, c, d]) + +-- | The size in bytes of the header: the magic word, the version and the hash. -- See Note [Persistent bytecode file headers] -writePersistentBytecodeHeader :: PersistentBytecodeFile -> WriteBinHandle -> IO () -writePersistentBytecodeHeader file_kind bh = do - put_ bh (persistentBytecodeMagic file_kind) - put_ bh (show hiVersion) +persistentBytecodeHeaderSize :: Int +persistentBytecodeHeaderSize = 4 + 4 * 4 + 2 * 8 -readPersistentBytecodeHeader :: PersistentBytecodeFile -> FilePath -> ReadBinHandle -> IO () -readPersistentBytecodeHeader file_kind path bh = do - let mismatch what expected actual = - throwGhcExceptionIO $ ProgramError $ - persistentBytecodeFileDescription file_kind ++ " header mismatch in " ++ path ++ - ": " ++ what ++ " (expected " ++ expected ++ ", got " ++ actual ++ ")" +-- See Note [Persistent bytecode file headers] +writePersistentBytecodeHeader :: PersistentBytecodeFile -> Fingerprint -> WriteBinHandle -> IO () +writePersistentBytecodeHeader file_kind (Fingerprint w1 w2) bh = do + put_ bh (persistentBytecodeMagic file_kind) + put_ bh persistentBytecodeVersion + put_ bh (FixedLengthEncoding w1) + put_ bh (FixedLengthEncoding w2) +-- | Read only the header of a persistent bytecode file. +getPersistentBytecodeHeader :: PersistentBytecodeFile -> ReadBinHandle -> IO (Either String Fingerprint) +getPersistentBytecodeHeader file_kind bh = do magic <- get bh - let expected_magic = persistentBytecodeMagic file_kind - if unFixedLength magic == unFixedLength expected_magic - then pure () - else mismatch "magic" (show $ unFixedLength expected_magic) (show $ unFixedLength magic) - - version <- get bh - let expected_version = show hiVersion - if version == expected_version - then pure () - else mismatch "version" expected_version version + if unFixedLength magic /= unFixedLength expected_magic + then mismatch "magic" (show $ unFixedLength expected_magic) (show $ unFixedLength magic) + else do + version <- get bh + if version /= persistentBytecodeVersion + then mismatch "version" + (showPersistentBytecodeVersion persistentBytecodeVersion) + (showPersistentBytecodeVersion version) + else do + w1 <- get bh + w2 <- get bh + pure $ Right (Fingerprint (unFixedLength w1) (unFixedLength w2)) + where + expected_magic = persistentBytecodeMagic file_kind + mismatch what expected actual = + pure $ Left $ what ++ " (expected " ++ expected ++ ", got " ++ actual ++ ")" + +-- | Validate the header of a persistent bytecode file, and return its hash. +readPersistentBytecodeHeader :: PersistentBytecodeFile -> FilePath -> ReadBinHandle -> IO Fingerprint +readPersistentBytecodeHeader file_kind path bh = do + r <- getPersistentBytecodeHeader file_kind bh + case r of + Right hash -> pure hash + Left what -> throwGhcExceptionIO $ ProgramError $ + persistentBytecodeFileDescription file_kind ++ " header mismatch in " ++ path ++ + ": " ++ what + +-- | Read the hash from the header of a persistent bytecode file, without +-- reading the rest of the file. 'Nothing' if the file can't be read or its +-- header is not valid. +readPersistentBytecodeHash :: PersistentBytecodeFile -> FilePath -> IO (Maybe Fingerprint) +readPersistentBytecodeHash file_kind path = do + r <- tryIO $ readBinMemN persistentBytecodeHeaderSize path + case r of + Right (Just bh) -> rightToMaybe <$> getPersistentBytecodeHeader file_kind bh + _ -> pure Nothing persistentBytecodeFileDescription :: PersistentBytecodeFile -> String persistentBytecodeFileDescription ModuleByteCodeFile = "bytecode file" ===================================== compiler/GHC/Driver/Downsweep.hs ===================================== @@ -1835,12 +1835,14 @@ checkSummaryHash obj_timestamp <- modificationTimeIfExists (ml_obj_file_ospath location) hi_timestamp <- modificationTimeIfExists (ml_hi_file_ospath location) hie_timestamp <- modificationTimeIfExists (ml_hie_file_ospath location) + bytecode_timestamp <- modificationTimeIfExists (ml_bytecode_file_ospath location) return $ Right ( old_summary { ms_obj_date = obj_timestamp , ms_iface_date = hi_timestamp , ms_hie_date = hie_timestamp + , ms_bytecode_date = bytecode_timestamp } ) ===================================== compiler/GHC/Driver/Main/Compile.hs ===================================== @@ -131,7 +131,6 @@ import GHC.Data.OsPath (unsafeEncodeUtf) import qualified GHC.Data.Stream as Stream -import Data.Traversable (for) import Control.Monad import Data.IORef import System.Directory @@ -140,7 +139,6 @@ import Data.Map (Map) import qualified Data.Set as S import GHC.Unit.Module.WholeCoreBindings import GHC.Types.TypeEnv -import Data.Time import System.IO.Unsafe ( unsafeInterleaveIO ) import GHC.Iface.Env ( trace_if ) @@ -217,12 +215,7 @@ loadIfaceByteCode hsc_env iface location type_env = where compile decls = do bco <- compileWholeCoreBindings hsc_env type_env decls - linkable $ pure $ DotGBC bco - - linkable parts = do - if_time <- modificationTimeIfExists (ml_hi_file_ospath location) - time <- maybe getCurrentTime pure if_time - return $! Linkable time (mi_module iface) parts + return $! Linkable (gbc_hash bco) (mi_module iface) (pure (DotGBC bco)) loadIfaceByteCodeLazy :: HscEnv -> @@ -239,12 +232,7 @@ loadIfaceByteCodeLazy hsc_env iface location type_env = compile decls = do bco <- unsafeInterleaveIO $ do compileWholeCoreBindings hsc_env type_env decls - linkable bco - - linkable parts = do - if_time <- modificationTimeIfExists (ml_hi_file_ospath location) - time <- maybe getCurrentTime pure if_time - return $!Linkable time (mi_module iface) parts + return $! Linkable (gbc_hash bco) (mi_module iface) bco -- | If the 'Linkable' contains Core bindings loaded from an interface, replace -- them with a lazy IO thunk that compiles them to bytecode and foreign objects, @@ -282,12 +270,13 @@ initWholeCoreBindings hsc_env iface details (RecompLinkables bc o) = do go :: RecompBytecodeLinkable -> IO (Maybe (LinkableWith ModuleByteCode)) go (NormalLinkable l) = pure l - go (WholeCoreBindingsLinkable wcbl) = - fmap Just $ for wcbl $ \wcb -> do - add_iface_to_hpt iface details hsc_env - bco <- unsafeInterleaveIO $ do - compileWholeCoreBindings hsc_env type_env wcb - pure bco + go (WholeCoreBindingsLinkable wcbl) = do + add_iface_to_hpt iface details hsc_env + bco <- unsafeInterleaveIO $ do + compileWholeCoreBindings hsc_env type_env (linkableParts wcbl) + -- We need to fill in the hash over here, replacing the panic + -- because WholeCoreBindingsLinkable doesn't have a hash. + pure $ Just $ Linkable (gbc_hash bco) (linkableModule wcbl) bco -- | Hydrate interface Core bindings and compile them to bytecode. -- @@ -842,11 +831,7 @@ make user's opt into writing the files. generateAndWriteByteCodeLinkable :: HscEnv -> CgInteractiveGuts -> ModLocation -> IO (LinkableWith ModuleByteCode) generateAndWriteByteCodeLinkable hsc_env cgguts mod_location = do bco_object <- generateAndWriteByteCode hsc_env cgguts mod_location - -- Either, get the same time as the .gbc file if it exists, or just the current time. - -- It's important the time of the linkable matches the time of the .gbc file for recompilation - -- checking. - bco_time <- maybe getCurrentTime pure =<< modificationTimeIfExists (ml_bytecode_file_ospath mod_location) - return $ mkOnlyModuleByteCodeLinkable bco_time bco_object + return $ mkOnlyModuleByteCodeLinkable bco_object mkModuleByteCode :: HscEnv -> Module -> ModLocation -> CgInteractiveGuts -> IO ModuleByteCode mkModuleByteCode hsc_env mod mod_location cgguts = do @@ -861,9 +846,8 @@ generateFreshByteCodeLinkable :: HscEnv -> ModLocation -> IO Linkable generateFreshByteCodeLinkable hsc_env mod_name cgguts mod_location = do - bco_time <- getCurrentTime bco_object <- mkModuleByteCode hsc_env (mkHomeModule (hsc_home_unit hsc_env) mod_name) mod_location cgguts - return $ mkModuleByteCodeLinkable bco_time bco_object + return $ mkModuleByteCodeLinkable bco_object ------------------------------ hscCompileCmmFile :: HscEnv -> FilePath -> FilePath -> FilePath -> IO (Maybe FilePath) ===================================== compiler/GHC/Driver/Main/Passes.hs ===================================== @@ -153,7 +153,7 @@ import GHC.Types.Unique.Set import GHC.Types.Var.Env ( mkEmptyTidyEnv ) import GHC.Types.Var.Set -import GHC.Utils.Fingerprint ( Fingerprint ) +import GHC.Utils.Fingerprint ( Fingerprint, getFileHash ) import GHC.Utils.Panic import GHC.Utils.Error import GHC.Utils.Outputable @@ -168,8 +168,8 @@ import GHC.Data.Maybe import qualified GHC.Data.Strict as Strict import qualified Data.Array as A -import Data.List ( nub, isPrefixOf, partition ) import qualified Data.List.NonEmpty as NE +import Data.List ( nub, isPrefixOf, partition ) import Control.Monad import Data.IORef import System.FilePath as FilePath @@ -180,7 +180,6 @@ import Data.Set (Set) import Control.DeepSeq (force) import Control.Exception as E (mask_, finally) import Data.List.NonEmpty (NonEmpty ((:|))) -import Data.Time import System.IO.Unsafe ( unsafeInterleaveIO ) import GHC.Iface.Env ( trace_if ) @@ -707,15 +706,24 @@ checkObjects dflags mb_old_linkable summary = do -- Not in dynamic-too mode else k + -- We check by date first, even though we have the hash + -- If a compilation is interupted after writing the .hi + -- but before writing the .o, then we catch this through + -- modtimes. + -- If the object file is newer than the .hi file, and the + -- .hi file is up to date, we also assume the object file + -- is up to date. checkDynamicObj $ case (,) <$> mb_obj_date <*> mb_if_date of Just (obj_date, if_date) - | obj_date >= if_date -> + | obj_date >= if_date -> do + disk_hash <- getFileHash obj_fn case mb_old_linkable of Just old_linkable - | linkableIsNativeCodeOnly old_linkable, linkableTime old_linkable == obj_date + | linkableIsNativeCodeOnly old_linkable + , linkableHash old_linkable == disk_hash -> return $ UpToDateItem old_linkable - _ -> UpToDateItem <$> findObjectLinkable this_mod obj_fn obj_date + _ -> return $ UpToDateItem (mkObjectLinkable this_mod obj_fn disk_hash) _ -> return $ outOfDateItemBecause MissingObjectFile Nothing -- | Check to see if we can reuse the old linkable, by this point we will @@ -724,15 +732,22 @@ checkObjects dflags mb_old_linkable summary = do checkByteCodeInMemory :: HscEnv -> ModSummary -> Maybe (LinkableWith ModuleByteCode) -> IO (MaybeValidated (LinkableWith ModuleByteCode)) checkByteCodeInMemory hsc_env mod_sum mb_old_linkable = case mb_old_linkable of - Just old_linkable + Just old_linkable -> do -- If `-fwrite-byte-code` is enabled, then check that the .gbc file is -- up-to-date with the linkable we have in our hand. -- If ms_bytecode_date is Nothing, then the .gbc file does not exist yet. - -- Otherwise, check that the date matches the linkable date exactly. - | if gopt Opt_WriteByteCode (hsc_dflags hsc_env) - then maybe False (linkableTime old_linkable ==) (ms_bytecode_date mod_sum) - else True - -> return $ (UpToDateItem old_linkable) + -- Otherwise, check that the hash matches the disk. + ok <- if gopt Opt_WriteByteCode (hsc_dflags hsc_env) + then case ms_bytecode_date mod_sum of + Nothing -> pure False + Just _ -> do + disk_hash <- ByteCode.readBinByteCodeHash + (ml_bytecode_file (ms_location mod_sum)) + pure (disk_hash == Just (linkableHash old_linkable)) + else pure True + if ok + then return (UpToDateItem old_linkable) + else return $ outOfDateItemBecause MissingBytecode Nothing _ -> return $ outOfDateItemBecause MissingBytecode Nothing -- | Load bytecode from a ".gbc" object file if it exists and is up-to-date @@ -745,12 +760,17 @@ checkByteCodeFromObject hsc_env mod_sum = do case (,) <$> obj_date <*> if_date of Just (obj_date, if_date) | obj_date >= if_date -> do - -- Don't force this if we reuse the linkable already loaded into memory, but we have to check - -- that the one we have on disk would be suitable as well. - linkable <- unsafeInterleaveIO $ do - bco <- ByteCode.readBinByteCode hsc_env obj_fn - return $ mkOnlyModuleByteCodeLinkable obj_date bco - return $ UpToDateItem linkable + -- A file without a valid header is treated as missing + mb_disk_hash <- ByteCode.readBinByteCodeHash obj_fn + case mb_disk_hash of + Nothing -> return $ outOfDateItemBecause MissingBytecode Nothing + Just _ -> do + -- Don't force this if we reuse the linkable already loaded into memory, but we have to check + -- that the one we have on disk would be suitable as well. + linkable <- unsafeInterleaveIO $ do + bco <- ByteCode.readBinByteCode hsc_env obj_fn + return $ mkOnlyModuleByteCodeLinkable bco + return $ UpToDateItem linkable _ -> return $ outOfDateItemBecause MissingBytecode Nothing -- | Attempt to load bytecode from whole core bindings in the interface if they exist. @@ -759,9 +779,11 @@ checkByteCodeFromIfaceCoreBindings :: HscEnv -> ModIface -> ModSummary -> IO (Ma checkByteCodeFromIfaceCoreBindings _hsc_env iface mod_sum = do let this_mod = ms_mod mod_sum - if_date = fromJust $ ms_iface_date mod_sum + -- This hash isn't used, initWholeCoreBindings will replace it + -- with a real linkable with bytecode that has a hash. + wcb_hash = panic "linkableHash: WholeCoreBindingsLinkable" case iface_core_bindings iface (ms_location mod_sum) of - Just fi -> return $ UpToDateItem (Linkable if_date this_mod fi) + Just fi -> return $ UpToDateItem (Linkable wcb_hash this_mod fi) _ -> return $ outOfDateItemBecause MissingBytecode Nothing @@ -1621,10 +1643,9 @@ hscCompileCoreExpr' hsc_env srcspan ds_expr = do Strict.Nothing -- no hpc info {- load it -} - bco_time <- getCurrentTime mbc <- ByteCode.mkModuleByteCode this_mod bcos [] (mods_needed, units_needed) <- loadDecls interp hsc_env srcspan $ - Linkable bco_time this_mod $ NE.singleton (DotGBC mbc) + mkModuleByteCodeLinkable mbc -- Get the foreign reference to the name we should have just loaded. mhvs <- lookupFromLoadedEnv interp (idName binding_id) {- Get the HValue for the root -} ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -128,7 +128,8 @@ import qualified Data.Set as Set import qualified Data.List.NonEmpty as NE import Data.List.NonEmpty (NonEmpty(..)) -import Data.Time ( getCurrentTime ) +import GHC.Utils.Fingerprint ( getFileHash ) +import GHC.ByteCode.Serialize ( fingerprintBytecodeLibInputs, readBytecodeLibInputsHash ) import GHC.Tc.Utils.Monad (shutdownTcMPluginsIO, FrontendResult (..), tcg_plugins) @@ -547,11 +548,13 @@ checkBytecodeLibraryLinkingNeeded _logger dflags unit_env linkables _pkg_deps = e_bytecode_lib_time <- modificationTimeIfExists exe_file_os case e_bytecode_lib_time of Nothing -> return $ NeedsRecompile MustCompile - Just t -> do - let bytecode_times = map linkableTime linkables - if any (t <) bytecode_times - then return $ needsRecompileBecause ObjectsChanged - else return UpToDate + Just _ -> do + -- See Note [Hash of bytecode libs] in GHC.ByteCode.Serialize + recorded <- readBytecodeLibInputsHash exe_file + let current = fingerprintBytecodeLibInputs (map linkableHash linkables) + if recorded == Just current + then return UpToDate + else return $ needsRecompileBecause ObjectsChanged checkNativeLibraryLinkingNeeded :: Bool -> Logger -> DynFlags -> UnitEnv -> [Linkable] -> [UnitId] -> IO RecompileRequired checkNativeLibraryLinkingNeeded staticLink _ dflags unit_env linkables pkg_deps = do @@ -576,8 +579,9 @@ checkNativeLibraryLinkingNeeded staticLink _ dflags unit_env linkables pkg_deps Just t -> do -- first check object files and extra_ld_inputs let extra_ld_inputs = [ f | FileOption _ f <- ldInputs dflags ] - (errs,extra_times) <- partitionWithM (tryIO . getModificationUTCTime) extra_ld_inputs - let obj_times = map linkableTime linkables ++ extra_times + obj_files = concatMap linkableFiles linkables + (errs,obj_times) <- partitionWithM (tryIO . getModificationUTCTime) + (obj_files ++ extra_ld_inputs) if not (null errs) || any (t <) obj_times then return $ needsRecompileBecause ObjectsChanged else do @@ -936,9 +940,9 @@ hscGenBackendPipeline pipe_env hsc_env mod_sum result = do -- No object file produced, bytecode or NoBackend Nothing -> return mlinkable Just o_fp -> do - part_time <- liftIO getCurrentTime final_object <- use (T_MergeForeign pipe_env hsc_env o_fp fos) - let !linkable = Linkable part_time (ms_mod mod_sum) (NE.singleton (DotO final_object ModuleObject)) + !obj_hash <- liftIO $ getFileHash final_object + let !linkable = Linkable obj_hash (ms_mod mod_sum) (NE.singleton (DotO final_object ModuleObject)) -- Add the object linkable to the potential bytecode linkable which was generated in HscBackend. return (mlinkable { homeMod_object = Just linkable }) ===================================== compiler/GHC/Linker/ByteCode.hs ===================================== @@ -37,6 +37,8 @@ linkBytecodeLib hsc_env gbcs = do let bytecodeLib' = BytecodeLib { bytecodeLibUnitId = homeUnitId_ dflags, + bytecodeLibInputsHash = fingerprintBytecodeLibInputs + [ gbc_hash m | m <- on_disk_bcos ++ gbcs ], bytecodeLibFiles = all_cbcs, bytecodeLibForeign = interpreter_foreign_lib } ===================================== compiler/GHC/Linker/Deps.hs ===================================== @@ -208,8 +208,6 @@ get_link_deps opts pls maybe_normal_osuf span mods = do <> quotes (text new_file) $$ while_linking_expr else return (DotO new_file ModuleObject) DotO file ForeignObject -> pure (DotO file ForeignObject) - DotA fp -> panic ("adjust_ul DotA " ++ show fp) - DotDLL fp -> panic ("adjust_ul DotDLL " ++ show fp) DotGBC {} -> pure part ===================================== compiler/GHC/Linker/Loader.hs ===================================== @@ -44,7 +44,6 @@ where import GHC.Prelude import GHC.Settings -import GHC.Utils.Misc import GHC.Platform import GHC.Platform.Ways @@ -673,14 +672,13 @@ findWholeCoreBindings hsc_env mod = do findBytecodeLinkableMaybe :: HscEnv -> ModLocation -> IO (Maybe Linkable) findBytecodeLinkableMaybe hsc_env locn = do - let bytecode_fn = ml_bytecode_file locn - bytecode_fn_os = ml_bytecode_file_ospath locn - maybe_bytecode_time <- modificationTimeIfExists bytecode_fn_os - case maybe_bytecode_time of - Nothing -> return Nothing - Just bytecode_time -> do + let bytecode_fn = ml_bytecode_file locn + exists <- doesFileExist bytecode_fn + if not exists + then return Nothing + else do bco <- readBinByteCode hsc_env bytecode_fn - return $ Just $ mkModuleByteCodeLinkable bytecode_time bco + return $ Just $ mkModuleByteCodeLinkable bco get_reachable_nodes :: HscEnv -> [Module] -> IO ([Module], UniqDSet UnitId) get_reachable_nodes hsc_env mods @@ -834,7 +832,7 @@ linkableInSet :: Linkable -> LinkableSet LinkableUsage -> Bool linkableInSet l objs_loaded = case lookupModuleEnv objs_loaded (linkableModule l) of Nothing -> False - Just m -> linkableTime l == linkableTime m + Just m -> linkableHash l == linkableHash m {- ********************************************************************** @@ -1390,7 +1388,7 @@ loadBytecodeLibrary :: HscEnv -> Interp -> LoaderState -> FilePath -> IO LoaderS loadBytecodeLibrary hsc_env interp pls path = do path' <- canonicalizePath path -- Note [loadObj and relative paths] -- 1. Read the bytecode library - (BytecodeLib uid cbcs stubs_so) <- decodeOnDiskBytecodeLib hsc_env =<< readBytecodeLib hsc_env path' + (BytecodeLib uid _hash cbcs stubs_so) <- decodeOnDiskBytecodeLib hsc_env =<< readBytecodeLib hsc_env path' debugTraceMsg (hsc_logger hsc_env) 3 $ text "loadBytecodeLibrary: " $$ vcat [ text "uid: " <+> ppr uid , text "cbcs: " <+> ppr (length cbcs) , text "stubs_so: " <+> ppr stubs_so ] ===================================== compiler/GHC/Linker/Types.hs ===================================== @@ -36,8 +36,6 @@ module GHC.Linker.Types , LinkedBreaks(..) , emptyLinkedBreaks , LinkableSet - , mkLinkableSet - , unionLinkableSet , ObjFile , SptEntry(..) , LibrarySpec(..) @@ -54,16 +52,12 @@ module GHC.Linker.Types , LinkableObjectSort (..) , linkableIsNativeCodeOnly , linkableObjs - , linkableLibs , linkableFiles , linkableBCOs , linkablePartBCOs , linkableModuleByteCodes - , linkableNativeParts - , linkablePartitionParts , linkablePartPath , isNativeCode - , isNativeLib , linkableFilterByteCode , linkableFilterNative , partitionLinkables @@ -104,7 +98,6 @@ import Control.Applicative ((<|>)) import Control.Concurrent.MVar import Data.Array import Data.Functor.Identity -import Data.Time ( UTCTime ) import Data.Maybe (mapMaybe) import Data.List.NonEmpty (NonEmpty, nonEmpty) import qualified Data.List.NonEmpty as NE @@ -378,10 +371,10 @@ instance Outputable LoadedPkgInfo where -- | Information we can use to dynamically link modules into the compiler data LinkableWith parts = Linkable - { linkableTime :: !UTCTime - -- ^ Time at which this linkable was built - -- (i.e. when the bytecodes were produced, - -- or the mod date on the files) + { linkableHash :: Fingerprint + -- ^ The identity of the linkable, derived from the hash of its contents + -- Lazy because bytecode is compiled lazily (see 'loadIfaceByteCodeLazy'), + -- and inspecting the hash can force compiling the bytecode itself. , linkableModule :: !Module -- ^ The linkable module itself @@ -398,22 +391,12 @@ type LinkableUsage = LinkableWith (NonEmpty LinkablePartUsage) type LinkableSet = ModuleEnv -mkLinkableSet :: [Linkable] -> LinkableSet Linkable -mkLinkableSet ls = mkModuleEnv [(linkableModule l, l) | l <- ls] - --- | Union of LinkableSets. --- --- In case of conflict, keep the most recent Linkable (as per linkableTime) -unionLinkableSet :: LinkableSet (LinkableWith a) -> LinkableSet (LinkableWith a) -> LinkableSet (LinkableWith a) -unionLinkableSet = plusModuleEnv_C go - where - go l1 l2 - | linkableTime l1 > linkableTime l2 = l1 - | otherwise = l2 instance Outputable a => Outputable (LinkableWith a) where - ppr (Linkable when_made mod parts) - = (text "Linkable" <+> parens (text (show when_made)) <+> ppr mod) + -- Don't print the hash, forcing it can trigger compilation + -- See the comment on 'linkableHash' + ppr (Linkable _ mod parts) + = (text "Linkable" <+> ppr mod) $$ nest 3 (ppr parts) type ObjFile = FilePath @@ -441,12 +424,6 @@ data LinkablePart -- should not be adapted to the interpreter's way. Used for foreign stubs -- loaded from interfaces. - | DotA FilePath - -- ^ Static archive file (.a) - - | DotDLL FilePath - -- ^ Dynamically linked library file (.so, .dll, .dylib) - | DotGBC -- ^ A byte-code object, lives only in memory. ModuleByteCode @@ -460,13 +437,13 @@ data ModuleByteCode = ModuleByteCode { gbc_module :: Module , gbc_hash :: !Fingerprint } -mkModuleByteCodeLinkable :: UTCTime -> ModuleByteCode -> Linkable -mkModuleByteCodeLinkable linkable_time bco = do - Linkable linkable_time (gbc_module bco) (pure (DotGBC bco)) +mkModuleByteCodeLinkable :: ModuleByteCode -> Linkable +mkModuleByteCodeLinkable bco = + Linkable (gbc_hash bco) (gbc_module bco) (pure (DotGBC bco)) -mkOnlyModuleByteCodeLinkable :: UTCTime -> ModuleByteCode -> LinkableWith ModuleByteCode -mkOnlyModuleByteCodeLinkable linkable_time bco = do - Linkable linkable_time (gbc_module bco) bco +mkOnlyModuleByteCodeLinkable :: ModuleByteCode -> LinkableWith ModuleByteCode +mkOnlyModuleByteCodeLinkable bco = + Linkable (gbc_hash bco) (gbc_module bco) bco instance Outputable ModuleByteCode where ppr (ModuleByteCode mod _cbc _fos _) = text "ModuleByteCode" <+> ppr mod @@ -477,8 +454,6 @@ instance Outputable LinkablePart where pprSort = \case ModuleObject -> empty ForeignObject -> brackets (text "foreign") - ppr (DotA path) = text "DotA" <+> text path - ppr (DotDLL path) = text "DotDLL" <+> text path ppr (DotGBC bco) = text "DotGBC" <+> ppr bco -- | Return true if the linkable only consists of native code (no BCO) @@ -494,67 +469,32 @@ linkableBCOs l = [ gbc_compiled_byte_code gbc | DotGBC gbc <- NE.toList (linkabl linkableModuleByteCodes :: Linkable -> [ModuleByteCode] linkableModuleByteCodes l = [ mbc | DotGBC mbc <- NE.toList (linkableParts l) ] --- | List the native linkable parts (.o/.so/.dll) of a linkable -linkableNativeParts :: Linkable -> [LinkablePart] -linkableNativeParts l = NE.filter isNativeCode (linkableParts l) - --- | Split linkable parts into (native code parts, BCOs parts) -linkablePartitionParts :: Linkable -> ([LinkablePart],[LinkablePart]) -linkablePartitionParts l = NE.partition isNativeCode (linkableParts l) - -- | List the native objects (.o) of a linkable linkableObjs :: Linkable -> [FilePath] linkableObjs l = concatMap linkablePartObjectPaths (linkableParts l) --- | List the native libraries (.so/.dll) of a linkable -linkableLibs :: Linkable -> [LinkablePart] -linkableLibs l = NE.filter isNativeLib (linkableParts l) - --- | List the paths of the native objects and libraries (.o/.so/.dll) +-- | List the paths of the native objects (.o) linkableFiles :: Linkable -> [FilePath] -linkableFiles l = concatMap linkablePartNativePaths (NE.toList (linkableParts l)) +linkableFiles l = mapMaybe linkablePartPath (NE.toList (linkableParts l)) ------------------------------------------- --- | Is the part a native object or library? (.o/.so/.dll) +-- | Is the part a native object? (.o) isNativeCode :: LinkablePart -> Bool isNativeCode = \case DotO {} -> True - DotA {} -> True - DotDLL {} -> True - DotGBC {} -> False - --- | Is the part a native library? (.so/.dll) -isNativeLib :: LinkablePart -> Bool -isNativeLib = \case - DotO {} -> False - DotA {} -> True - DotDLL {} -> True DotGBC {} -> False -- | Get the FilePath of linkable part (if applicable) linkablePartPath :: LinkablePart -> Maybe FilePath linkablePartPath = \case DotO fn _ -> Just fn - DotA fn -> Just fn - DotDLL fn -> Just fn DotGBC {} -> Nothing --- | Return the paths of all object code files (.o, .a, .so) contained in this --- 'LinkablePart'. -linkablePartNativePaths :: LinkablePart -> [FilePath] -linkablePartNativePaths = \case - DotO fn _ -> [fn] - DotA fn -> [fn] - DotDLL fn -> [fn] - DotGBC {} -> [] - -- | Return the paths of all object files (.o) contained in this 'LinkablePart'. linkablePartObjectPaths :: LinkablePart -> [FilePath] linkablePartObjectPaths = \case DotO fn _ -> [fn] - DotA _ -> [] - DotDLL _ -> [] DotGBC bco -> gbc_foreign_files bco -- | Retrieve the compiled byte-code from the linkable part. @@ -573,8 +513,6 @@ linkableFilter f linkable = do linkablePartNative :: LinkablePart -> [LinkablePart] linkablePartNative u = case u of DotO {} -> [u] - DotA {} -> [u] - DotDLL {} -> [u] DotGBC bco -> [DotO f ForeignObject | f <- gbc_foreign_files bco] linkablePartByteCode :: LinkablePart -> [LinkablePart] @@ -583,7 +521,7 @@ linkablePartByteCode = \case _ -> [] -- | Transform the 'LinkablePart' list in this 'Linkable' to contain only --- object code files (.o, .a, .so) without 'BCOs'. +-- object code files (.o) without 'BCOs'. -- If no 'LinkablePart' remains, return 'Nothing'. linkableFilterNative :: Linkable -> Maybe Linkable linkableFilterNative = linkableFilter linkablePartNative @@ -595,7 +533,7 @@ linkableFilterByteCode :: Linkable -> Maybe Linkable linkableFilterByteCode = linkableFilter linkablePartByteCode -- | Split the 'LinkablePart' lists in each 'Linkable' into only object code --- files (.o, .a, .so) and only byte code, and return two +-- files (.o) and only byte code, and return two -- lists containing the nonempty 'Linkable's for each. partitionLinkables :: [Linkable] -> ([Linkable], [Linkable]) partitionLinkables linkables = @@ -621,7 +559,9 @@ mkLinkableUsage lnk = seqNonEmpty linkablesWithUsage linkablesWithUsage } in - linkableParts lnkUsage `seq` lnkUsage + -- Also force the hash so that we don't retain the actual bytecode + -- from a LinkableUsage + linkableHash lnkUsage `seq` linkableParts lnkUsage `seq` lnkUsage where mkFileLinkablePartUsage m fp objs = FileLinkablePartUsage @@ -642,8 +582,6 @@ mkLinkableUsage lnk = go :: Module -> LinkablePart -> LinkablePartUsage go m lnkPart = case lnkPart of DotO fn _ -> mkFileLinkablePartUsage m fn (linkablePartObjectPaths lnkPart) - DotA fn -> mkFileLinkablePartUsage m fn (linkablePartObjectPaths lnkPart) - DotDLL fn -> mkFileLinkablePartUsage m fn (linkablePartObjectPaths lnkPart) DotGBC mbc -> mkByteCodeLinkablePartUsage m (gbc_hash mbc) (linkablePartObjectPaths lnkPart) mkLinkablesUsage :: [Linkable] -> [LinkableUsage] ===================================== compiler/GHC/Unit/Finder.hs ===================================== @@ -42,7 +42,7 @@ module GHC.Unit.Finder ( mkStubPaths, findObjectLinkableMaybe, - findObjectLinkable, + mkObjectLinkable, -- important that GHC.HsToCore.Usage uses the same hashing method for usage dirs as is used here. getDirHash, @@ -76,7 +76,6 @@ import GHC.Unit.State import GHC.Unit.Finder.Cache import GHC.Unit.Finder.Types -import GHC.Utils.Misc import GHC.Utils.Outputable as Outputable import GHC.Utils.Panic @@ -88,7 +87,6 @@ import GHC.Types.UnresolvedImport import Control.Applicative ((<|>)) import Control.Exception (throwIO) -import Control.Monad import Control.Monad.IO.Class import Data.IORef import qualified Data.List as L(sort) @@ -97,7 +95,6 @@ import qualified Data.List.NonEmpty as NE import qualified Data.Map as M import Data.Set (Set) import qualified Data.Set as Set (empty, intersection, difference, null, toList) -import Data.Time import GHC.Fingerprint import GHC.TypeError (ErrorMessage(..), Unsatisfiable, unsatisfiable) import qualified System.Directory as SD @@ -1088,15 +1085,15 @@ mkStubPaths fopts mod location = do findObjectLinkableMaybe :: Module -> ModLocation -> IO (Maybe Linkable) findObjectLinkableMaybe mod locn = do let obj_fn = ml_obj_file locn - maybe_obj_time <- modificationTimeIfExists (ml_obj_file_ospath locn) - case maybe_obj_time of - Nothing -> return Nothing - Just obj_time -> liftM Just (findObjectLinkable mod obj_fn obj_time) - --- Make an object linkable when we know the object file exists, and we know --- its modification time. -findObjectLinkable :: Module -> FilePath -> UTCTime -> IO Linkable -findObjectLinkable mod obj_fn obj_time = - pure (Linkable obj_time mod (NE.singleton (DotO obj_fn ModuleObject))) + exists <- doesFileExist (ml_obj_file_ospath locn) + if not exists + then return Nothing + else do + obj_hash <- getFileHash obj_fn + return (Just (mkObjectLinkable mod obj_fn obj_hash)) + +mkObjectLinkable :: Module -> FilePath -> Fingerprint -> Linkable +mkObjectLinkable mod obj_fn obj_hash = + Linkable obj_hash mod (NE.singleton (DotO obj_fn ModuleObject)) -- We used to look for _stub.o files here, but that was a bug (#706) -- Now GHC merges the stub.o into the main .o (#3687) ===================================== testsuite/tests/driver/bytecode-object/Makefile ===================================== @@ -165,3 +165,19 @@ bytecode_object26: @printf 'bad!' | dd of=BytecodeTest.gbc bs=1 count=4 conv=notrunc 2>/dev/null ! "$(TEST_HC)" $(TEST_HC_OPTS) -c -bytecodelib -o linked.bytecode BytecodeTest.gbc 2> bytecode_object26.stderr @grep -F "bytecode file header mismatch" bytecode_object26.stderr >/dev/null + +# Test reloading in GHCi with the .gbc file written by the first load +# The module should not be recompiled. +bytecode_object27: + @echo ":reload" | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -v1 -fno-hide-source-paths -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs + +# Test corrupting the header of the .gbc file and reloading in GHCi +# The module should be recompiled. +bytecode_object28: + @cat bytecode_object28.script | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) -v1 -fno-hide-source-paths -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs + +# Test that a bytecode library with a corrupt header is linked again +bytecode_object29: + "$(TEST_HC)" $(TEST_HC_OPTS) -bytecodelib -o linked.bytecode BytecodeTest.hs -fwrite-byte-code -fbyte-code -fwrite-interface + @printf 'bad!' | dd of=linked.bytecode bs=1 count=4 conv=notrunc 2>/dev/null + "$(TEST_HC)" $(TEST_HC_OPTS) -bytecodelib -o linked.bytecode BytecodeTest.hs -fwrite-byte-code -fbyte-code -fwrite-interface ===================================== testsuite/tests/driver/bytecode-object/all.T ===================================== @@ -27,3 +27,6 @@ test('bytecode_object23', bytecode_opts, makefile_test, ['bytecode_object23']) test('bytecode_object24', bytecode_opts + [copy_files], makefile_test, ['bytecode_object24']) test('bytecode_object25', [bytecode_opts, req_interp, extra_files(['BytecodeForeign.hs', 'BytecodeForeign.c'])], makefile_test, ['bytecode_object25']) test('bytecode_object26', [bytecode_opts], makefile_test, ['bytecode_object26']) +test('bytecode_object27', [bytecode_opts, req_interp, filter_stdout_lines(r'.*Compiling.*') ], makefile_test, ['bytecode_object27']) +test('bytecode_object28', [bytecode_opts, req_interp, filter_stdout_lines(r'.*Compiling.*') ], makefile_test, ['bytecode_object28']) +test('bytecode_object29', bytecode_opts, makefile_test, ['bytecode_object29']) ===================================== testsuite/tests/driver/bytecode-object/bytecode_object27.stdout ===================================== @@ -0,0 +1 @@ +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, BytecodeTest.gbc )[main] ===================================== testsuite/tests/driver/bytecode-object/bytecode_object28.script ===================================== @@ -0,0 +1,3 @@ +System.IO.withBinaryFile "BytecodeTest.gbc" System.IO.ReadWriteMode (\h -> System.IO.hPutStr h "bad!") +:reload +:quit ===================================== testsuite/tests/driver/bytecode-object/bytecode_object28.stdout ===================================== @@ -0,0 +1,2 @@ +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, BytecodeTest.gbc )[main] +ghci> ghci> [1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, BytecodeTest.gbc )[main] [Missing bytecode] ===================================== testsuite/tests/driver/bytecode-object/bytecode_object29.stdout ===================================== @@ -0,0 +1,3 @@ +[1 of 2] Compiling BytecodeTest ( BytecodeTest.hs, BytecodeTest.gbc ) +[2 of 2] Linking linked.bytecode +[2 of 2] Linking linked.bytecode [Objects changed] ===================================== testsuite/tests/driver/recomp023/M.hs ===================================== @@ -0,0 +1,4 @@ +module M where + +m :: Int +m = 5 ===================================== testsuite/tests/driver/recomp023/M2.hs ===================================== @@ -0,0 +1,4 @@ +module M where + +m :: Int +m = 6 ===================================== testsuite/tests/driver/recomp023/Makefile ===================================== @@ -0,0 +1,21 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +# Recompilation test for bytecode libraries: the library is only relinked +# when one of its constituents changes + +BUILD = '$(TEST_HC)' $(TEST_HC_OPTS) --make -bytecodelib -fbyte-code \ + -fwrite-interface -fwrite-byte-code -this-unit-id=recomp023 \ + -o recomp023.bytecodelib M.hs + +clean: + +recomp023: clean + echo "first build" + $(BUILD) + echo "second build" + $(BUILD) + mv M2.hs M.hs + echo "third build" + $(BUILD) ===================================== testsuite/tests/driver/recomp023/all.T ===================================== @@ -0,0 +1,2 @@ +test('recomp023', [extra_files(['M.hs', 'M2.hs']), req_bco, normalise_slashes], + makefile_test, []) ===================================== testsuite/tests/driver/recomp023/recomp023.stdout ===================================== @@ -0,0 +1,7 @@ +first build +[1 of 2] Compiling M ( M.hs, M.gbc ) +[2 of 2] Linking recomp023.bytecodelib +second build +third build +[1 of 2] Compiling M ( M.hs, M.gbc ) [Source file changed] +[2 of 2] Linking recomp023.bytecodelib [Objects changed] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/24055252cbaf0a78168866c383fd08c... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/24055252cbaf0a78168866c383fd08c... 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)
-
Marge Bot (@marge-bot)