Commit 1118ecad authored by Simon Marlow's avatar Simon Marlow

Fix the interface-file incompatibility crash (#3435)

We now have a dummy 32/64-bit field near the beginning of a .hi file
for backward-compatibility reasons; see comments (Note [dummy iface
field]) in BinIface.hs.
parent af5a8f95
...@@ -38,6 +38,7 @@ import FastMutInt ...@@ -38,6 +38,7 @@ import FastMutInt
import Unique import Unique
import Outputable import Outputable
import FastString import FastString
import Constants
import Data.List import Data.List
import Data.Word import Data.Word
...@@ -92,12 +93,17 @@ readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path update_nc = do ...@@ -92,12 +93,17 @@ readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path update_nc = do
errorOnMismatch "magic number mismatch: old/corrupt interface file?" errorOnMismatch "magic number mismatch: old/corrupt interface file?"
binaryInterfaceMagic magic binaryInterfaceMagic magic
-- Get the dictionary pointer. We won't attempt to actually -- Note [dummy iface field]
-- read the dictionary until we've done the version checks below, -- read a dummy 32/64 bit value. This field used to hold the
-- just in case this isn't a valid interface. In retrospect the -- dictionary pointer in old interface file formats, but now
-- version should have come before the dictionary pointer, but this -- the dictionary pointer is after the version (where it
-- is the way it was done originally, and we can't change it now. -- should be). Also, the serialisation of value of type "Bin
dict_p <- Binary.get bh -- Get the dictionary ptr -- a" used to depend on the word size of the machine, now they
-- are always 32 bits.
--
if wORD_SIZE == 4
then do Binary.get bh :: IO Word32; return ()
else do Binary.get bh :: IO Word64; return ()
-- Check the interface file version and ways. -- Check the interface file version and ways.
check_ver <- get bh check_ver <- get bh
...@@ -114,6 +120,7 @@ readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path update_nc = do ...@@ -114,6 +120,7 @@ readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path update_nc = do
-- Read the dictionary -- Read the dictionary
-- The next word in the file is a pointer to where the dictionary is -- The next word in the file is a pointer to where the dictionary is
-- (probably at the end of the file) -- (probably at the end of the file)
dict_p <- Binary.get bh
data_p <- tellBin bh -- Remember where we are now data_p <- tellBin bh -- Remember where we are now
seekBin bh dict_p seekBin bh dict_p
dict <- getDictionary bh dict <- getDictionary bh
...@@ -139,15 +146,22 @@ writeBinIface dflags hi_path mod_iface = do ...@@ -139,15 +146,22 @@ writeBinIface dflags hi_path mod_iface = do
bh <- openBinMem initBinMemSize bh <- openBinMem initBinMemSize
put_ bh binaryInterfaceMagic put_ bh binaryInterfaceMagic
-- Remember where the dictionary pointer will go -- dummy 32/64-bit field before the version/way for
dict_p_p <- tellBin bh -- compatibility with older interface file formats.
put_ bh dict_p_p -- Placeholder for ptr to dictionary -- See Note [dummy iface field] above.
if wORD_SIZE == 4
then Binary.put_ bh (0 :: Word32)
else Binary.put_ bh (0 :: Word64)
-- The version and way descriptor go next -- The version and way descriptor go next
put_ bh (show opt_HiVersion) put_ bh (show opt_HiVersion)
let way_descr = getWayDescr dflags let way_descr = getWayDescr dflags
put_ bh way_descr put_ bh way_descr
-- Remember where the dictionary pointer will go
dict_p_p <- tellBin bh
put_ bh dict_p_p -- Placeholder for ptr to dictionary
-- Remember where the symbol table pointer will go -- Remember where the symbol table pointer will go
symtab_p_p <- tellBin bh symtab_p_p <- tellBin bh
put_ bh symtab_p_p put_ bh symtab_p_p
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment