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
-
Create a working directory (e.g.
~/build
) and clone the ghc repository into it. -
Prepare a Debian sid x64 chroot (I am using
debian-sid-tar
from https://hub.nspawn.org/images/). -
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
-
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).
-
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
-
Setup
qemu-user-static
and binfmt-misc, and prepare a riscv64 chroot (may refer to this Debian wiki article, starting from the "Qemu" section). -
Mount the working directory into the chroot and start it:
systemd-nspawn -D /path/to/debian/rv64 --bind=~/build:/build
-
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