Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,269
    • Issues 4,269
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 413
    • Merge Requests 413
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17572

Closed
Open
Opened Dec 13, 2019 by Sylvain Henry@hsyl20Developer

Heap census and shrunk array

Summary

In a specific fork of GHC I get one test failing (space_leak_001) with a segfault. It only fails when +RTS -h is passed. I think it is not related directly to my changes. It seems related to #9666 (closed).

Steps to reproduce

  • clone https://gitlab.haskell.org/hsyl20/ghc/tree/hsyl20-bignum
  • build with Hadrian (make is broken in this branch): ./hadrian/build.stack.sh -c -j --flavour=perf test --only=space_leak_001
Wrong exit code for space_leak_001(normal)(expected 0 , actual 139 )
*** unexpected failure for space_leak_001(normal)

Expected behavior

Don't crash.

Debugging

My current guess is that ByteArrays that have been shrunk are not correctly handled by heapCensusChain in rts/ProfHeap.c. At the beginning of this function we find:

        // HACK: pretend a pinned block is just one big ARR_WORDS
        // owned by CCS_PINNED.  These blocks can be full of holes due
        // to alignment constraints so we can't traverse the memory
        // and do a proper census.

It seems to me that we don't handle shrunk arrays that are not pinned to avoid traversing garbage data.

Debugging this function with GDB, the first closure in the block is an ARR_WORDS which (I think) has been shrunk of 8 bytes:

(gdb) p (StgArrBytes*)p
$6 = (StgArrBytes *) 0x42002ac000
(gdb) p *(StgArrBytes*)p
$7 = {header = {info = 0x77dd40 <stg_ARR_WORDS_info>}, bytes = 56976, payload = 0x42002ac010}

The next computed closure address is 0x42002b9ea0 while bd->free is 0x42002b9ea8 (i.e. 8 bytes, smaller than StgClosure). The info pointer read is garbage and it crashes.

A workaround is to fill shrunk cells with 0. It works because we have this code at the end of the loop:

            /* skip over slop */
            while (p < bd->free && !*p) p++; // skip slop
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#17572