
Matthew Pickering pushed to branch wip/stable-ipe-info at Glasgow Haskell Compiler / GHC Commits: 5cd6a720 by GHC GitLab CI at 2025-08-07T11:14:19+00:00 fix - - - - - 1 changed file: - compiler/GHC/StgToCmm/InfoTableProv.hs Changes: ===================================== compiler/GHC/StgToCmm/InfoTableProv.hs ===================================== @@ -10,6 +10,7 @@ import qualified Data.ByteString.Internal as BSI import GHC.IO (unsafePerformIO) #endif +import Data.Char import GHC.Prelude import GHC.Platform import GHC.Types.SrcLoc (pprUserRealSpan, srcSpanFile) @@ -82,7 +83,7 @@ objcopy --remove-section .ipe <your-exe> upx <your-exe> ``` -The .ipe section starts with a magic 64-bit word "IPE\nIPE\n`, encoded as ascii. +The .ipe section starts with a magic 64-bit word "IPE\0IPE\0`, encoded as ascii. The RTS checks to see if the .ipe section starts with the magic word. If the section has been stripped then it won't start with the magic word and the @@ -132,7 +133,7 @@ emitIpeBufferListNode this_mod ents dus0 = do strings_bytes = compress defaultCompressionLevel uncompressed_strings strings :: [CmmStatic] - strings = [CmmString strings_bytes] + strings = [CmmString (ipe_header `mappend` strings_bytes)] uncompressed_entries :: BS.ByteString uncompressed_entries = toIpeBufferEntries (platformByteOrder platform) cg_ipes @@ -141,17 +142,31 @@ emitIpeBufferListNode this_mod ents dus0 = do entries_bytes = compress defaultCompressionLevel uncompressed_entries entries :: [CmmStatic] - entries = [CmmString entries_bytes] + entries = [CmmString (ipe_header `mappend` entries_bytes)] ipe_buffer_lbl :: CLabel ipe_buffer_lbl = mkIPELabel this_mod + -- A string which fits into one 64-bit word. + ipe_header_word :: Word64 + ipe_header_word = stringToWord64BE "IPE\0IPE\0" + + -- Convert 8 bytes to Word64 using big-endian interpretation + stringToWord64BE :: String -> Word64 + stringToWord64BE = foldl' (\acc b -> GHC.Prelude.shiftL acc 8 .|. fromIntegral (ord b)) 0 + -- A magic word we can use to see if the IPE information has been stripped -- or not -- See Note [IPE Stripping and magic words] - -- "IPE\nIPE\n", null terminated. - ipe_header :: CmmStatic - ipe_header = CmmStaticLit (CmmInt 0x4950450049504500 W64) + -- On little-endian machines, it is reversed + -- so that when the first word of the string is read then it literally + -- reads IPE\0IPE\0 in hex dumps. + ipe_header :: BS.ByteString + ipe_header = BSL.toStrict . BSB.toLazyByteString $ + case platformByteOrder platform of + LittleEndian -> BSB.word64LE ipe_header_word + BigEndian -> BSB.word64BE ipe_header_word + ipe_buffer_node :: [CmmStatic] ipe_buffer_node = map CmmStaticLit @@ -197,12 +212,12 @@ emitIpeBufferListNode this_mod ents dus0 = do -- Emit the strings table emitDecl $ CmmData (Section IPE strings_lbl) - (CmmStaticsRaw strings_lbl (ipe_header : strings)) + (CmmStaticsRaw strings_lbl strings) -- Emit the list of IPE buffer entries emitDecl $ CmmData (Section IPE entries_lbl) - (CmmStaticsRaw entries_lbl (ipe_header : entries)) + (CmmStaticsRaw entries_lbl entries) -- Emit the IPE buffer list node emitDecl $ CmmData View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5cd6a7204674dc4e21f404a1c1913260... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5cd6a7204674dc4e21f404a1c1913260... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Matthew Pickering (@mpickering)