gnu-nm reports an error when cross compiling GHC to loongarch64 Stage1:exe:ghc-bin
Summary
When cross compiling GHC 9.2.3 to a new architecture, LoongArch64, at Stage1:exe:ghc-bin, an error occurred with exit code -8.
Steps to reproduce
System Preparations
- Prepare system (Fedora 36) as GHC wiki suggested.
- Install
Cabal
- Set user env variables as below:
export BASEDIR="/opt/workload"
export BUILDDIR="${BASEDIR}/build"
export DOWNLOADDIR="${BASEDIR}/downloads"
export LC_ALL=POSIX
export CROSS_HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
export CROSS_TARGET="loongarch64-unknown-linux-gnu"
export MABI="lp64d"
export BUILD64="-mabi=lp64d"
export PATH=${BASEDIR}/cross-tools/bin:/bin:/usr/bin
export CROSS_TOOLS="${BASEDIR}/cross-tools/bin"
Files Download
- Cross-tools:
cd $DOWNLOADDIR
wget https://github.com/sunhaiyong1978/CLFS-for-LoongArch/releases/download/5.0/loongarch64-clfs-5.0-cross-tools-gcc_and_clang-full.tar.xz
tar -xvf loongarch64-clfs-5.0-cross-tools-gcc_and_clang-full.tar.xz
cp -ir ./cross-tools $BASEDIR
- GHC source tree:
cd $DOWNLOADDIR
wget https://downloads.haskell.org/~ghc/9.2.3/ghc-9.2.3-src.tar.xz
tar -xvf ghc-9.2.3-src.tar.xz
cp -r ghc-9.2.3/ $BUILDDIR
Cross Compiling: Stage0:lib:ghc
./boot && ./configure
sudo ./hadrian/build stage0:lib:ghc -j
Cross Compiling: Stage1:exe:ghc-bin
Modify two files under m4/ to add a new architecture.
# In m4/fptools_set_haskell_platform_vars.m4
# Line 51, modify to be as below.
...
loongarch64|hppa|hppa1_1|ia64|m68k|nios2|riscv32|rs6000|s390|sh4|vax)
test -z "[$]2" || eval "[$]2=ArchUnknown"
...
# In m4/ghc_convert_cpu.m4
# Between line 82 and 83, add as below.
loongarch64)
$2="loongarch64"
;;
Run the following commands to apply changes.
autoupdate
autoreconf
Generate configuration.
./configure \
CC=${CROSS_TOOLS}/${CROSS_TARGET}-gcc \
LD=${CROSS_TOOLS}/${CROSS_TARGET}-ld \
NM=${CROSS_TOOLS}/${CROSS_TARGET}-nm \
OBJDUMP=${CROSS_TOOLS}/${CROSS_TARGET}-objdump \
STRIP=${CROSS_TOOLS}/${CROSS_TARGET}-strip \
RANLIB=${CROSS_TOOLS}/${CROSS_TARGET}-ranlib \
CLANG=${CROSS_TOOLS}/clang \
LLC=${CROSS_TOOLS}/llc \
--target=${CROSS_TARGET}
Compile Stage1:exe:ghc-bin.
sudo ./hadrian/build -j stage1:exe:ghc-bin --flavour=quick-cross
And ... Here comes the error. Errors are reported by hadrian as below.
| Run Ghc LinkHs Stage0: _build/stage0/utils/genprimopcode/build/Main.o (and 4 more) => _build/stage0/bin/loongarch64-unknown-linux-gnu-genprimopcode
| Run DeriveConstants: none => _build/stage0/compiler/build/GHC/Platform/Constants.hs (and 2 more)
| Run DeriveConstants: none => _build/stage0/lib/DerivedConstants.h (and 1 more)
loongarch64-unknown-linux-gnu-deriveConstants: readCreateProcess: /opt/workload/cross-tools/bin/loongarch64-unknown-linux-gnu-nm "-P" "/tmp/extra-dir-43474175754543/tmp.o" (exit -8): failed
Error when running Shake build system:
at want, called at src/Main.hs:104:30 in main:Main
* Depends on: stage1:exe:ghc-bin
at need, called at src/Rules/SimpleTargets.hs:35:5 in main:Rules.SimpleTargets
* Depends on: _build/stage0/bin/loongarch64-unknown-linux-gnu-ghc
at need, called at src/Rules/Register.hs:79:5 in main:Rules.Register
* Depends on: _build/stage0/lib/x86_64-linux-ghc-8.10.5/ghc-9.2.3/libHSghc-9.2.3.a
at need, called at src/Rules/Library.hs:45:5 in main:Rules.Library
* Depends on: _build/stage0/lib/package.conf.d/ghc-9.2.3.conf
at need, called at src/Rules/Register.hs:119:5 in main:Rules.Register
* Depends on: _build/stage0/compiler/build/libHSghc-9.2.3.a
at need, called at src/Rules/Library.hs:159:5 in main:Rules.Library
* Depends on: _build/stage0/compiler/build/Language/Haskell/Syntax/Type.o
* Depends on: _build/stage0/compiler/build/Language/Haskell/Syntax/Type.o _build/stage0/compiler/build/Language/Haskell/Syntax/Type.hi
* Depends on: OracleQ (KeyValues ("_build/stage0/compiler/.dependencies","_build/stage0/compiler/build/Language/Haskell/Syntax/Type.o"))
* Depends on: _build/stage0/compiler/.dependencies
* Depends on: _build/stage0/compiler/.dependencies.mk
at need, called at src/Rules/Dependencies.hs:26:9 in main:Rules.Dependencies
* Depends on: _build/stage0/lib/DerivedConstants.h
at cmd', called at src/Builder.hs:379:23 in main:Builder
at cmd, called at src/Builder.hs:483:8 in main:Builder
* Raised the exception:
Development.Shake.cmd, system command failed
Command line: _build/stage0/bin/loongarch64-unknown-linux-gnu-deriveConstants --gen-header -o _build/stage0/lib/DerivedConstants.h --tmpdir /tmp/extra-dir-43474175754543 --gcc-program /opt/workload/cross-tools/bin/loongarch64-unknown-linux-gnu-gcc --gcc-flag -Wall --gcc-flag -Werror=unused-but-set-variable --gcc-flag -Wno-error=inline --gcc-flag -DUSE_MINIINTERPRETER --gcc-flag -Irts --gcc-flag -Iincludes --gcc-flag -I_build/stage0/lib --gcc-flag -DNOSMP --gcc-flag -fcommon --nm-program /opt/workload/cross-tools/bin/loongarch64-unknown-linux-gnu-nm --objdump-program /opt/workload/cross-tools/bin/loongarch64-unknown-linux-gnu-objdump --target-os linux
Exit code: 1
Stderr and Stdout:
loongarch64-unknown-linux-gnu-deriveConstants: readCreateProcess: /opt/workload/cross-tools/bin/loongarch64-unknown-linux-gnu-nm "-P" "/tmp/extra-dir-43474175754543/tmp.o" (exit -8): failed
Expected behavior
Hadrian builds Stage1:exe:ghc-bin.
Environment
- GHC version used: 8.10.5
- Operating System: Fedora Server 36
- System Architecture: x86_64
A summary report by ./configure
has been saved in Configuration_results.md