Broken aarch64 cross-compiler with Hadrian
I have previously successfully built a Linux x86_64 to aarch64 cross-compiling GHC using:
echo '
V=0
BUILD_MAN = NO
BUILD_SPHINX_HTML = NO
BUILD_SPHINX_PDF = NO
HADDOCK_DOCS = NO
Stage1Only = YES
BuildFlavour = quick
WITH_TERMINFO = NO
BIGNUM_BACKEND = native
' > build.mk
ghcup compile ghc -v 9.2.7 -b 9.0.2 -x aarch64-none-linux-gnu -c $(pwd)/build.mk
Where my cross toolchain comes from this package, which wraps a binary release direct from ARM themselves.
I'm trying to migrate this to Hadrian now that it's the only option for newer GHCs:
ghcup compile ghc --hadrian -v 9.6.2 -b 9.6.2 -x aarch64-none-linux-gnu -j $(nproc) --flavour=quick+native_bignum
This builds a compiler which, when run on even a trivial program, generates hundreds of errors like:
...
Error: expecting operand after ','; got nothing
Error: no such instruction: `b stg_ap_p_fast'
Error: no such instruction: `ldr x18,[ sp,64]'
Error: no such instruction: `ldr x18,[ x18]'
Error: no such instruction: `br x18'
Error: operand size mismatch for `mov'
Error: no such instruction: `ldr x18,[ x19,-16]'
Error: no such instruction: `br x18'
Something is clearly very broken. It looks rather like we're trying to run the wrong kind of assembly for the host platform. So I suspected that perhaps what had been built was a stage 2 compiler, with host=aarch64, especially given that my Hadrian command above is missing any equivalent to Stage1Only = YES
from the Make version. But aarch64-none-linux-gnu-ghc --print-stage
does output 1
.
If it isn't clear what's going on here, I can go and work out how to invoke Hadrian directly, rather than via GHCUP (this was not obvious, not least because the cross-compilation wiki page doesn't even mention Hadrian). It is possible that this is actually a bug in GHCUP. I can also try to avoid the mismatched GHC versions, though I did have unrelated issues getting older GHCs to even build with Hadrian.