riscv64 target fails to build with latest llvm-11 release: LLVM ERROR: Unsupported calling convention
Summary
./configure --target=riscv64-unknown-linux-gnu
fails to build as:
$ LANG=C make
===--- building phase 0
make --no-print-directory -f ghc.mk phase=0 phase_0_builds
make[1]: Nothing to be done for 'phase_0_builds'.
===--- building phase 1
make --no-print-directory -f ghc.mk phase=1 phase_1_builds
make[1]: Nothing to be done for 'phase_1_builds'.
===--- building final phase
make --no-print-directory -f ghc.mk phase=final all
"inplace/bin/ghc-stage1" -static -H32m -O -Wall -Iincludes -Iincludes/dist -Iincludes/dist-derivedconstants/header -Iincludes/dist-ghcconstants/header -Iincludes/dist-install/build -Irts -Irts/dist/build -DCOMPILING_RTS -DFS_NAMESPACE=rts -this-unit-id rts -dcmm-lint -package-env - -i -irts -irts/dist/build -Irts/dist/build -irts/dist/build/./autogen -Irts/dist/build/./autogen -O2 -Wcpp-undef -Wnoncanonical-monad-instances -c rts/Apply.cmm -o rts/dist/build/Apply.o
LLVM ERROR: Unsupported calling convention
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc -O2 -enable-tbaa -relocation-model=static -mattr=+m,+a,+f,+d,+c,+relax -target-abi=lp64d /tmp/ghc377660_0/ghc_6.bc -o /tmp/ghc377660_0/ghc_7.lm_s
1. Running pass 'Function Pass Manager' on module '/tmp/ghc377660_0/ghc_6.bc'.
2. Running pass 'RISCV DAG->DAG Pattern Instruction Selection' on function '@"stg_ap_0_fast$def"'
#0 0x00007f8452065c6f llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xbd3c6f)
#1 0x00007f8452063f24 llvm::sys::RunSignalHandlers() (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xbd1f24)
#2 0x00007f84520640b5 (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xbd20b5)
#3 0x00007f845101d500 /tmp/portage-tmpdir/portage/sys-libs/glibc-2.33/work/glibc-2.33/signal/../sysdeps/unix/sysv/linux/sigaction.c:15:0: error:
0
#4 0x00007f845101d47e raise /tmp/portage-tmpdir/portage/sys-libs/glibc-2.33/work/glibc-2.33/signal/../sysdeps/unix/sysv/linux/raise.c:50:1
#5 0x00007f8451007536 abort /tmp/portage-tmpdir/portage/sys-libs/glibc-2.33/work/glibc-2.33/stdlib/abort.c:81:7
#6 0x00007f8451fa6a6a llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xb14a6a)
#7 0x00007f8451fa6ba8 (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xb14ba8)
#8 0x00007f8453d6722c (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0x28d522c)
#9 0x00007f8452736bd5 llvm::SelectionDAGISel::LowerArguments(llvm::Function const&) (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0x12a4bd5)
#10 0x00007f8452790566 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0x12fe566)
#11 0x00007f84527913b3 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0x12ff3b3)
#12 0x00007f8452373ba9 (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xee1ba9)
#13 0x00007f8452184522 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xcf2522)
#14 0x00007f8452184a23 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xcf2a23)
#15 0x00007f845218323d llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/llvm/11/bin/../lib64/libLLVM-11.so+0xcf123d)
#16 0x000055c340cac176 (/usr/lib/llvm/11/bin/llc+0x15176)
#17 0x000055c340ca4f9c main (/usr/lib/llvm/11/bin/llc+0xdf9c)
#18 0x00007f845100887d __libc_start_main /tmp/portage-tmpdir/portage/sys-libs/glibc-2.33/work/glibc-2.33/csu/../csu/libc-start.c:332:0: error:
16
#19 0x000055c340ca50ca _start (/usr/lib/llvm/11/bin/llc+0xe0ca)
`llc' failed in phase `LLVM Compiler'. (Exit code: -6)
make[1]: *** [rts/ghc.mk:322: rts/dist/build/Apply.o] Error 1
make: *** [Makefile:128: all] Error 2
Ben notes that https://reviews.llvm.org/D89788 was recently landed in llvm and was not released yet.
GHC's built system should fall back to unregusterised build if no suitable llvm is found.