Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 455
    • Merge requests 455
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20519
Closed
Open
Created Oct 15, 2021 by hexchain@hexchain

Cross-compiled riscv64 binary fails to execute under qemu-user-riscv64

Summary

Bootstrapping a riscv64 toolchain on x64 results in some unusable stage2 binaries.

Steps to reproduce

  1. Create a working directory (e.g. ~/build) and clone the ghc repository into it.

  2. Prepare a Debian sid x64 chroot (I am using debian-sid-tar from https://hub.nspawn.org/images/).

  3. Mount the directory inside the chroot and start it. Personally I found it very simple with systemd-nspawn:

    systemd-nspawn -D /path/to/debian/x64 --bind=~/build:/build
  4. Install required tools in the chroot (git, build-essential, gcc-12, autoconf, python3, riscv64-linux-gnu-gcc, llvm-12, ghc 8.10.6 from experimental, happy, alex).

  5. Build the ghc-9.2 branch with !6765 (merged) because rv64 gcc requires explicitly linking to libatomic for sub-word atomic operations.

    (debian-sid-x64-chroot) $ ./boot
    (debian-sid-x64-chroot) $ ./configure --target=riscv64-linux-gnu
    (debian-sid-x64-chroot) $ make

    build.mk:

    ...
    BuildFlavour = quick
    ...
    WITH_TERMINFO         = NO
    BUILD_EXTRA_PKGS      = NO
    HADDOCK_DOCS          = NO
    BUILD_MAN             = NO
    BUILD_SPHINX_HTML     = NO
    BUILD_SPHINX_PDF      = NO
    
    GhcRtsCcOpts += -fkeep-inline-functions
    DYNAMIC_GHC_PROGRAMS  =  NO
    GhcLibWays = v
    GhcRTSWays = debug
    GhcThreaded = NO
    GhcDebugged = YES
  6. Setup qemu-user-static and binfmt-misc, and prepare a riscv64 chroot (may refer to this Debian wiki article, starting from the "Qemu" section).

  7. Mount the working directory into the chroot and start it:

    systemd-nspawn -D /path/to/debian/rv64 --bind=~/build:/build
  8. Try to execute the stage2 binary:

    (debian-rv64-chroot) $ inplace/bin/ghc-stage2
    ghc-stage2: internal error: ASSERTION FAILED: file rts/dist/build/AutoApply.cmm, line 2317
    
        (GHC version 9.2.0.20211020 for riscv64_unknown_linux)
        Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug
    Aborted (core dumped)

    A more detailed log, with +RTS -Di -Da -Ds -DS, can be found at https://ix.io/3CkH.

    I've also tried to pull in 8b5e5b05 and cb862ecf (the branch is at https://gitlab.haskell.org/hexchain/ghc/-/tree/ghc-9.2-rv64-bootstrap). The compiler still crashes, but only with a "Segmentation fault". With +RTS -Di -Da -Ds -DS there is not much difference.

Expected behavior

The stage2 binary should work without any problem.

Environment

  • GHC version used: 8.10.6 (from debian experimental)
  • LLVM: 12.0
  • GCC: riscv64-linux-gnu-gcc 11.2.0

Optional:

  • Operating System: Arch Linux
  • System Architecture: x64
Edited Oct 20, 2021 by hexchain
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking