Opened 3 years ago

Closed 8 months ago

Last modified 7 months ago

#6086 closed bug (fixed)

Cross compilation fails using system linker for other architecture binaries

Reported by: mtjm Owned by:
Priority: high Milestone:
Component: Build System Version: 7.8.3
Keywords: Cc:
Operating System: Linux Architecture: arm
Type of failure: Building GHC failed Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Building ghc from git revision 4b089dbacd2a14f38a335103cf8ac0779d92f937 this command run by make fails (broken lines for readability):

CROSS_COMPILE="mips64el-unknown-linux-gnu-" "inplace/bin/ghc-cabal" \
configure --with-ghc="/home/mtjm/git/ghc-cross/inplace/bin/ghc-stage1" \
--with-ghc-pkg="/home/mtjm/git/ghc-cross/inplace/bin/ghc-pkg" \
--flag=include-ghc-prim --disable-library-for-ghci \
--configure-option=CFLAGS="-g -O2 -fno-stack-protector" \
--configure-option=LDFLAGS=" -Wl,--hash-size=31 -Wl,--reduce-memory-overheads  " \
--configure-option=CPPFLAGS="   " --with-gcc="/home/mtjm/x-tools/mips64el-unknown-linux-gnu/bin/mips64el-unknown-linux-gnu-gcc" \
--configure-option=--with-cc="/home/mtjm/x-tools/mips64el-unknown-linux-gnu/bin/mips64el-unknown-linux-gnu-gcc" \
--with-ar="/usr/bin/ar" --with-ranlib="true" --with-alex="/usr/bin/alex" --with-happy="/usr/bin/happy" \
-- dist-install libraries/ghc-prim
Configuring ghc-prim-0.2.0.0...
ghc-cabal: /tmp/32545.o: does not exist

After adding the --verbose=3 option its output includes this:

searching for ld in path.
found ld at /usr/bin/ld
("/home/mtjm/git/ghc-cross/inplace/bin/ghc-stage1",["-c","/tmp/32649.c","-o","/tmp/32649.o"])
("/usr/bin/ld",["-x","-r","/tmp/32649.o","-o","/tmp/32650.o"])
/usr/bin/ld returned ExitFailure 1 with error message:
/usr/bin/ld: /tmp/32649.o: Relocations in generic ELF (EM: 8)
/tmp/32649.o: could not read symbols: File in wrong format
ghc-cabal: /tmp/32650.o: does not exist

So it uses the system (x86_64) linker to link MIPS binaries. Adding the --with-ld option pointing to the correct cross linker makes it run without errors.

I think this could be fixed correctly by finding the target linker like the compiler in configure and changing rules/build-package-data.mk to pass the --with-ld option depending on stage.

(mips64el-unknown-linux-gnu targets aren't supported, I believe this issue wouldn't occur only for them and I want to fix bugs preventing an unregistered build from working.)

Change History (27)

comment:1 Changed 3 years ago by igloo

  • difficulty set to Unknown
  • Milestone set to 7.8.1

Thanks for the report

comment:2 Changed 2 years ago by simonmar

  • Owner set to simonmar
  • Priority changed from normal to high

I just ran into the same thing, cross-compiling for Raspberry Pi. Fix coming...

comment:3 Changed 2 years ago by marlowsd@…

commit f77291d60f33fe601dbe0ff94b0192c5cd4ad6b5

Author: Simon Marlow <[email protected]>
Date:   Wed Jan 16 14:15:47 2013 +0000

    Pass --with-ld=$(LD) to ghc-cabal when configuring packages (#6086)

 rules/build-package-data.mk |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

comment:4 Changed 2 years ago by simonmar

  • Resolution set to fixed
  • Status changed from new to closed

comment:5 follow-up: Changed 10 months ago by boo

  • Owner simonmar deleted
  • Resolution fixed deleted
  • Status changed from closed to new

I'm just trying to crosscompile GHC-7.8.3 from Linux (x86) to Raspberry Pi following this instruction and getting following error:

"inplace/bin/ghc-cabal" configure libraries/ghc-prim dist-install "" --with-ghc="/home/boo/projects/rpi/ghc-7.8.3/inplace/bin/ghc-stage1" --with-ghc-pkg="/home/boo/projects/rpi/ghc-7.8.3/inplace/bin/ghc-pkg" --flag=include-ghc-prim --disable-library-for-ghci --enable-library-vanilla --disable-library-profiling --enable-shared --configure-option=CFLAGS=" -fno-stack-protector   " --configure-option=LDFLAGS="   " --configure-option=CPPFLAGS="   " --gcc-options=" -fno-stack-protector       " --configure-option=--host=arm-unknown-linux-gnueabihf --with-gcc="/usr/bin/gcc" --with-ld="/home/boo/projects/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld" --configure-option=--with-cc="/usr/bin/gcc" --with-ar="/home/boo/projects/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ar" --with-ranlib="/home/boo/projects/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ranlib" --with-alex="/usr/local/bin/alex" --with-happy="/usr/local/bin/happy"
Configuring ghc-prim-0.3.1.0...
ghc-cabal: /tmp/3624.o: does not exist
make[1]: *** [libraries/ghc-prim/dist-install/package-data.mk] Error 1
make: *** [all] Error 2

comment:6 Changed 10 months ago by boo

  • Architecture changed from Unknown/Multiple to arm
  • Milestone changed from 7.8.1 to 7.8.4
  • Version changed from 7.5 to 7.8.3

comment:7 in reply to: ↑ 5 Changed 8 months ago by cetu86

I have to confirm having exactly the same problem. build command line is

./configure --target=arm-unknown-linux-gnueabi --enable-unregisterised --with-nm=/usr/bin/nm --prefix=$HOME/haskell/ghc-build  && make quick-cross

comment:8 follow-up: Changed 8 months ago by rwbarton

Try adding --with-gcc=[whatever the path to the C cross-compiler is] to the configure command line. I've found that I need to do this when cross-compiling.

I think that configure detecting the C cross-compiler worked in 7.8.2 and broke in 7.8.3 but I'm not 100% sure.

comment:9 in reply to: ↑ 8 Changed 8 months ago by cetu86

Thanks for that quick answer. I did as you told me, also passing the argument

--with-gcc=`which arm-unknown-linux-gnueabi-gcc`

to configure.
Now it goes past the last error. But some way down the road this happens

/bin/sh ./libtool   --mode=compile /usr/bin/gcc -DHAVE_CONFIG_H -I. -I..  -I. -I../include -Iinclude -I../src -DFFI_BUILDING  -I. -I../include -Iinclude -I../src -DFFI_BUILDING -g -fno-stack-protector -w -MT src/arm/sysv.lo -MMD -MP -MF $depbase.Tpo -c -o src/arm/sysv.lo ../src/arm/sysv.S &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  /usr/bin/gcc -DHAVE_CONFIG_H -I. -I.. -I. -I../include -Iinclude -I../src -DFFI_BUILDING -I. -I../include -Iinclude -I../src -DFFI_BUILDING -g -fno-stack-protector -w -MT src/arm/sysv.lo -MMD -MP -MF src/arm/.deps/sysv.Tpo -c ../src/arm/sysv.S  -fPIC -DPIC -o src/arm/.libs/sysv.o
../src/arm/sysv.S: Assembler messages:
../src/arm/sysv.S:64: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:160: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:161: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:162: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:163: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:164: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:166: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:167: Error: unknown pseudo-op: `.arm'
../src/arm/sysv.S:167: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:168: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:169: Error: no such instruction: `stmfd sp!,{r0-r3,fp,lr}'
../src/arm/sysv.S:170: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:171: Error: too many memory references for `mov'
../src/arm/sysv.S:173: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:175: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:176: Error: too many memory references for `sub'
../src/arm/sysv.S:178: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:179: Error: too many memory references for `mov'
../src/arm/sysv.S:180: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:182: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:183: Error: no such instruction: `bl ffi_prep_args'
../src/arm/sysv.S:185: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:186: Error: no such instruction: `ldmia sp,{r0-r3}'
../src/arm/sysv.S:188: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:189: Error: too many memory references for `sub'
../src/arm/sysv.S:190: Error: no such instruction: `ldr ip,[fp]@load fn()in advance'
../src/arm/sysv.S:191: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:192: Error: no such instruction: `movhs lr,'
../src/arm/sysv.S:193: Error: too many memory references for `add'
../src/arm/sysv.S:195: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:196: Error: too many memory references for `mov'
../src/arm/sysv.S:196: Error: too many memory references for `mov'
../src/arm/sysv.S:198: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:199: Error: too many memory references for `mov'
../src/arm/sysv.S:201: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:202: Error: no such instruction: `ldr r2,[sp,'
../src/arm/sysv.S:204: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:205: Error: no such instruction: `ldr r3,[sp,'
../src/arm/sysv.S:207: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:208: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:209: Error: no such instruction: `beq .Lepilogue'
../src/arm/sysv.S:211: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:212: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:216: Error: no such instruction: `streq r0,[r2]'
../src/arm/sysv.S:217: Error: no such instruction: `beq .Lepilogue'
../src/arm/sysv.S:219: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:220: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:224: Error: no such instruction: `stmeqia r2,{r0,r1}'
../src/arm/sysv.S:227: Error: no such instruction: `beq .Lepilogue'
../src/arm/sysv.S:229: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:230: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:231: Error: no such instruction: `stfeqs f0,[r2]'
../src/arm/sysv.S:232: Error: no such instruction: `beq .Lepilogue'
../src/arm/sysv.S:234: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:235: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:236: Error: no such instruction: `stfeqd f0,[r2]'
../src/arm/sysv.S:244: Error: no such instruction: `ldmia sp!,{r0-r3,fp,pc}'
../src/arm/sysv.S:248: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:269: Error: unknown pseudo-op: `.arm'
../src/arm/sysv.S:269: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:270: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:271: Error: too many memory references for `add'
../src/arm/sysv.S:272: Error: no such instruction: `stmfd sp!,{ip,lr}'
../src/arm/sysv.S:273: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:274: Error: too many memory references for `add'
../src/arm/sysv.S:275: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:276: Error: too many memory references for `sub'
../src/arm/sysv.S:277: Error: invalid char '[' beginning operand 2 `[sp'
../src/arm/sysv.S:278: Error: too many memory references for `add'
../src/arm/sysv.S:279: Error: no such instruction: `bl ffi_closure_SYSV_inner'
../src/arm/sysv.S:280: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:281: Error: no such instruction: `beq .Lretint'
../src/arm/sysv.S:283: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:287: Error: no such instruction: `beq .Lretfloat'
../src/arm/sysv.S:290: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:294: Error: no such instruction: `beq .Lretdouble'
../src/arm/sysv.S:297: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:301: Error: no such instruction: `beq .Lretlongdouble'
../src/arm/sysv.S:304: Error: expecting operand after ','; got nothing
../src/arm/sysv.S:305: Error: no such instruction: `beq .Lretlonglong'
../src/arm/sysv.S:307: Error: too many memory references for `add'
../src/arm/sysv.S:308: Error: no such instruction: `ldmfd sp,{sp,pc}'
../src/arm/sysv.S:310: Error: no such instruction: `ldr r0,[sp]'
../src/arm/sysv.S:311: Error: no such instruction: `b .Lclosure_epilogue'
../src/arm/sysv.S:313: Error: no such instruction: `ldr r0,[sp]'
../src/arm/sysv.S:314: Error: no such instruction: `ldr r1,[sp,'
../src/arm/sysv.S:315: Error: no such instruction: `b .Lclosure_epilogue'
../src/arm/sysv.S:319: Error: no such instruction: `ldfs f0,[sp]'
../src/arm/sysv.S:320: Error: no such instruction: `b .Lclosure_epilogue'
../src/arm/sysv.S:322: Error: no such instruction: `ldfd f0,[sp]'
../src/arm/sysv.S:323: Error: no such instruction: `b .Lclosure_epilogue'
../src/arm/sysv.S:325: Error: no such instruction: `ldfd f0,[sp]'
../src/arm/sysv.S:326: Error: no such instruction: `b .Lclosure_epilogue'
../src/arm/sysv.S:330: Error: junk at end of line, first unrecognized character is `@'
../src/arm/sysv.S:499: Error: no such instruction: `stmfd sp!,{r0-r3}'
../src/arm/sysv.S:500: Error: no such instruction: `ldr r0,[pc]'
../src/arm/sysv.S:501: Error: no such instruction: `ldr pc,[pc]'
make[5]: *** [src/arm/sysv.lo] Error 1
make[5]: Leaving directory `/mnt/hd/extra/haskell/ghc/libffi/build/arm-unknown-linux-gnueabi'
make[4]: *** [all-recursive] Error 1
make[4]: Leaving directory `/mnt/hd/extra/haskell/ghc/libffi/build/arm-unknown-linux-gnueabi'
make[3]: *** [all] Error 2
make[3]: Leaving directory `/mnt/hd/extra/haskell/ghc/libffi/build/arm-unknown-linux-gnueabi'
make[2]: *** [all-all] Error 2
make[1]: *** [libffi/stamp.ffi.static-shared.build] Error 2
make: *** [quick-cross] Error 2

Looks like its trying to compile arm-stuff using my normal gcc, not the cross-gcc.

comment:10 follow-up: Changed 8 months ago by rwbarton

Hmm, so that's in libffi. Check how it was configured (libffi/build/arm-unknown-linux-gnueabi/config.log should tell you) and see whether anything looks amiss there. Perhaps you needed to clean more before re-configuring (make distclean should probably be enough, but make maintainer-clean is the ultimate hammer).

comment:11 in reply to: ↑ 10 Changed 8 months ago by cetu86

I did the maintainer-clean, then a

perl boot

and then again

./configure --target=arm-unknown-linux-gnueabi --enable-unregisterised --with-gcc=`which arm-unknown-linux-gnueabi-gcc` --with-nm=/usr/bin/nm --prefix=/home/daniel/haskell/ghc-build  && make quick-cross

Now I get

mv libraries/integer-gmp/gmp/gmpbuild/ltmain.sh libraries/integer-gmp/gmp/gmpbuild/ltmain.sh.orig
sed 's#cmd //c echo "\$1"#cmd /c "echo $1"#' < libraries/integer-gmp/gmp/gmpbuild/ltmain.sh.orig > libraries/integer-gmp/gmp/gmpbuild/ltmain.sh
cd libraries/integer-gmp/gmp; (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
    PATH=`pwd`:$PATH; \
    export PATH; \
    cd gmpbuild && \
    CC=/home/daniel/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc NM=/usr/bin/nm AR=/home/daniel/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-ar /bin/sh ./configure \
          --enable-shared=no \
          --host=x86_64-unknown-linux --build=x86_64-unknown-linux
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=64
checking whether /home/daniel/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc is gcc... yes
checking compiler /home/daniel/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc -O2 -pedantic -m64 ... no
checking ABI=32
checking whether /home/daniel/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc is gcc... yes
checking compiler /home/daniel/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc -m32 -O2 -pedantic -fomit-frame-pointer ... no
checking compiler /home/daniel/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc -O2 -pedantic -fomit-frame-pointer ... no, program does not run
configure: error: could not find a working compiler, see config.log for details
make[1]: *** [libraries/integer-gmp/gmp/gmp.h] Error 1
make: *** [quick-cross] Error 2

Again, it's seems like it's trying to compile gmp with an arm compiler for x64, or am I wrong?

comment:12 follow-up: Changed 8 months ago by rwbarton

libgmp should be being configured with --host=arm-unknown-linux-gnueabi. I think this is a bug in the build system and currently you probably just want to use integer-simple instead.

I don't think make quick-cross actually does anything... you should set up a build.mk (copied from build.mk.sample) and add INTEGER_LIBRARY = integer-simple. I think pretty much any BuildFlavour should work but note that the quick-cross and perf-cross flavours only build a cross-compiler and not a cross-compiled compiler that runs on the target.

comment:13 Changed 8 months ago by MikolajKonarski

I get the original problem (the need to manually insert --ld-option="-melf_i386") already when using a 32bit GHC on 64bit Linux (no proper cross-compilation):

https://ghc.haskell.org/trac/ghc/ticket/9421#comment:2

It would be helpful if that and other parameters where inserted automatically based on HOST/BUILD/TARGET.

comment:14 Changed 8 months ago by MikolajKonarski

  • Blocking 9421 added

comment:15 in reply to: ↑ 12 Changed 8 months ago by cetu86

Thanks again, for the reply. :-)
Don't know why I thought passing "quick-cross" as an argument to make would choose the flavor.
I now did as you said, created a build.mk from build.mk.sample and set

BuildFlavour  = quick-cross

which pulls in

INTEGER_LIBRARY    = integer-simple

I only need the simple cross-compiler (at the moment).
Now I come as far as

"inplace/bin/ghc-stage1" -hisuf hi -osuf  o -hcsuf hc -static  -H64m -O0    -package-name ghc-7.8.3 -hide-all-packages -i -icompiler/basicTypes -icompiler/cmm -icompiler/codeGen -icompiler/coreSyn -icompiler/deSugar -icompiler/ghci -icompiler/hsSyn -icompiler/iface -icompiler/llvmGen -icompiler/main -icompiler/nativeGen -icompiler/parser -icompiler/prelude -icompiler/profiling -icompiler/rename -icompiler/simplCore -icompiler/simplStg -icompiler/specialise -icompiler/stgSyn -icompiler/stranal -icompiler/typecheck -icompiler/types -icompiler/utils -icompiler/vectorise -icompiler/stage2/build -icompiler/stage2/build/autogen -Icompiler/stage2/build -Icompiler/stage2/build/autogen -Icompiler/. -Icompiler/parser -Icompiler/utils -Icompiler/../rts/dist/build -Icompiler/stage2   -optP-DGHCI -optP-include -optPcompiler/stage2/build/autogen/cabal_macros.h -package Cabal-1.18.1.3 -package array-0.5.0.1 -package base-4.7.0.0 -package bin-package-db-0.0.0.0 -package bytestring-0.10.4.0 -package containers-0.5.5.1 -package directory-1.2.1.0 -package filepath-1.3.0.2 -package hoopl-3.10.0.1 -package hpc-0.6.0.1 -package process-1.2.0.0 -package template-haskell-2.10.0.0 -package time-1.4.2 -package transformers-0.3.0.0 -package unix-2.7.0.2 -Wall -fno-warn-name-shadowing -XHaskell98 -XCPP -XMagicHash -XUnboxedTuples -XPatternGuards -XForeignFunctionInterface -XEmptyDataDecls -XTypeSynonymInstances -XMultiParamTypeClasses -XFlexibleInstances -XRankNTypes -XScopedTypeVariables -XDeriveDataTypeable -XBangPatterns -XNondecreasingIndentation -DNO_REGS -DNOSMP -optc-DNOSMP -optc-DTHREADED_RTS -DSTAGE=2 -O0 -fllvm  -no-user-package-db -rtsopts      -odir compiler/stage2/build -hidir compiler/stage2/build -stubdir compiler/stage2/build   -c compiler/hsSyn/Convert.lhs -o compiler/stage2/build/Convert.o 

compiler/hsSyn/Convert.lhs:895:10:
    Not in scope: data constructor ‘TH.ClassP’
    Perhaps you meant one of these:
      ‘TH.ClassD’ (imported from Language.Haskell.TH.Syntax),
      ‘TH.ClassD’ (imported from Language.Haskell.TH),
      ‘TH.ClassI’ (imported from Language.Haskell.TH.Syntax)

compiler/hsSyn/Convert.lhs:900:10:
    Not in scope: data constructor ‘TH.EqualP’
make[1]: *** [compiler/stage2/build/Convert.o] Error 1
make: *** [all] Error 2

TH stands for template haskell, right?

Last edited 8 months ago by cetu86 (previous) (diff)

comment:16 follow-up: Changed 8 months ago by rwbarton

It does. Probably you have gotten your non-submodule subrepositories into an inconsistent state, something which is easy to do when checking out 7.8. The reliable way to check out 7.8 correctly is to start with a fresh clone:

git clone -b ghc-7.8 git://git.haskell.org/ghc.git
cd ghc
./sync-all get -b ghc-7.8

Sorry the wiki can be unclear in places...

comment:17 in reply to: ↑ 16 ; follow-up: Changed 8 months ago by cetu86

This did it. Thank you!

So here is a summary of the steps I took to get a stage1 cross compiler for my raspberry-pi

  1. Do a clean checkout
git clone -b ghc-7.8 git://git.haskell.org/ghc.git
cd ghc
./sync-all --no-dph get -b ghc-7.8
  1. perl boot
    
  1. cp mk/build.mk.sample mk/build.mk
    
  1. uncomment line
BuildFlavour  = quick-cross

in build.mk

  1. ./configure --target=arm-unknown-linux-gnueabi --enable-unregisterised --with-gcc=`which arm-unknown-linux-gnueabi-gcc` --with-nm=/usr/bin/nm --prefix=/home/daniel/haskell/ghc-build  && make
    
  1. make install
    
Last edited 8 months ago by cetu86 (previous) (diff)

comment:18 Changed 8 months ago by jpmasseria

@cetu86 Which toolchain are you using?

I'm following these (https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation/RaspberryPi) instructions and the target that I'm going to try is arm-linux-gnueabihf and my with-gcc is which arm-linux-gnueabihf-gcc.

comment:19 follow-up: Changed 8 months ago by jpmasseria

@cetu86 following your instructions I get:

johnma@aspire-ubuntu:~/ghc$ make -j2
===--- building phase 0
make -r --no-print-directory -f ghc.mk phase=0 phase_0_builds
libraries/hpc/ghc.mk:3: libraries/hpc/dist-boot/package-data.mk: No such file or directory
libraries/Cabal/Cabal/ghc.mk:3: libraries/Cabal/Cabal/dist-boot/package-data.mk: No such file or directory
libraries/bin-package-db/ghc.mk:3: libraries/bin-package-db/dist-boot/package-data.mk: No such file or directory
libraries/hoopl/ghc.mk:3: libraries/hoopl/dist-boot/package-data.mk: No such file or directory
libraries/transformers/ghc.mk:3: libraries/transformers/dist-boot/package-data.mk: No such file or directory
libraries/terminfo/ghc.mk:3: libraries/terminfo/dist-boot/package-data.mk: No such file or directory
libraries/dph/ghc.mk:134: *** dph_th_deps(v): libraries/dph/dph-base_dist-install_GHCI_LIB not defined!.  Stop.
make: *** [all] Error 2

comment:20 in reply to: ↑ 17 Changed 8 months ago by rwbarton

  • Resolution set to fixed
  • Status changed from new to closed

Replying to cetu86:

This did it. Thank you!

Glad it's working. I took the opportunity to clean up Building/GettingTheSources a bit and investigate why -with-gcc is needed (https://phabricator.haskell.org/D204).

Replying to jpmasseria:

libraries/dph/ghc.mk:134: *** dph_th_deps(v): libraries/dph/dph-base_dist-install_GHCI_LIB not defined!.  Stop.

I encountered this error too when messing around with this stuff. I didn't really investigate what caused it, it seemed to be due to configure detecting the wrong C compiler possibly. I "resolved" it by removing libraries/dph since it isn't needed anyways and slows down the build.

comment:21 in reply to: ↑ 19 Changed 8 months ago by cetu86

@jpmasseria: I edited comment 17 to add the "--no-dph" switch to sync-all. I actually did it that way, just forgot to post the right instructions here, sorry!

I didn't use the official raspbian-toolchain, because I'm running archlinux on the pi and many libraries have different versions there. So I build a toolchain using crosstool-ng following these instructions http://www.kitware.com/blog/home/post/426.

comment:22 follow-up: Changed 8 months ago by jpmasseria

After I manually deleted libraries/dph I now get:

configure: error: in `/home/johnma/ghc/libraries/terminfo':
configure: error: curses headers could not be found, so this package cannot be built
See `config.log' for more details
make[1]: *** [libraries/terminfo/dist-install/package-data.mk] Error 1
make: *** [all] Error 2

Should I just start over and re-clone from git? (I'm going to try that).

Hum, this https://ghc.haskell.org/trac/ghc/ticket/7754 appears to be my new problem. Not sure how I correct this issue. Is this a toolchain problem?

Last edited 8 months ago by jpmasseria (previous) (diff)

comment:23 in reply to: ↑ 22 ; follow-up: Changed 8 months ago by cetu86

You don't need to start over. You just need ncurses.
I downloaded ncurses and cross compiled it for arm, then put it in the cross-tools' sysroot directory under sysroot/usr.
Or I guess you could just copy ncurses from your existing installation on your raspberry pi. That way you can be sure you got the right version. Cause when you create dynamically linked executable, you have to have matching versions.

comment:24 in reply to: ↑ 23 ; follow-up: Changed 8 months ago by jpmasseria

Replying to cetu86:

Thanks for the continued help. I'm still stuck where my GHC build doesn't find ncurses.

I have done the following (my main issue is that I don't really understand where I need to "install" my cross compiled version of ncurses.

    wget ftp.de.debian.org/debian/pool/main/n/ncurses/ncurses_5.9.orig.tar.gz
    tar xf ncurses_5.9.orig.tar.gz
    cd ncurses-5.9/
    ./configure --target=arm-linux-gnueabihf --with-gcc=arm-linux-gnueabihf-gcc --target=arm-linux-gnueabihf --prefix=/home/johnma/arm-linux-gnueabihf
    make && make install

As I understand it this placed the cross compiled ncurses into my directory /home/johnma/arm-linux/gnueabihf

I then tried to build GHC using this as follows:

    cd ../ghc/
    ./configure --target=arm-linux-gnueabihf --enable-unregisterised --with-gcc=`which arm-linux-gnueabihf-gcc` --with-nm=/usr/bin/nm --with-sysroot=/home/johnma/arm-linux-gnueabihf
    make -j2

Needless to say that achieved the same ncurses not found error. Again, my confusion is how I tell the GHC build to find this ncurses.

Thank you!

comment:25 in reply to: ↑ 24 Changed 8 months ago by cetu86

Inside your cross toolchain there is a directory that is literally called "sysroot". Inside it you'll find a typical unix root. Looks like this

.
└── arm-unknown-linux-gnueabi
    ├── arm-unknown-linux-gnueabi
    │   └── sysroot
    │       ├── bin
    │       ├── etc
    │       ├── include
    │       ├── lib
    │       ├── sbin
    │       ├── share
    │       ├── usr
    │       │   ├── bin
    │       │   ├── include --> ncurses.h, curses.h go here
    │       │   ├── lib --> libncurses.a goes here
    │       └── var

If you use ".../sysroot/usr" as prefix everything should go fine. Except ncurses puts its header files in a subdirectory "include/ncurses" but ghc includes the header file as

#include <ncurses.h>

not as

#include <ncurses/ncurses.h>

What it did was move all files in the ncurses directory one up and create a symlink for compatibility. (in case I'd later install something that expects ncurses in its original place) Like this:

cd sysroot/usr/inlude/ncurses
mv * ..
cd ..
rmdir ncurses
ln -s . ncurses

Now I have

daniel@inferno:~/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot/usr/include/ > ls -l ncurs* curs*
-rw-r--r-- 1 daniel users  6590  9. Sep 12:38 cursesapp.h
-rw-r--r-- 1 daniel users 27646  9. Sep 12:38 cursesf.h
-rw-r--r-- 1 daniel users 76252  9. Sep 12:38 curses.h
-rw-r--r-- 1 daniel users 19518  9. Sep 12:38 cursesm.h
-rw-r--r-- 1 daniel users  8489  9. Sep 12:38 cursesp.h
-rw-r--r-- 1 daniel users 49280  9. Sep 12:38 cursesw.h
-rw-r--r-- 1 daniel users  7312  9. Sep 12:38 cursslk.h
lrwxrwxrwx 1 daniel users     1  9. Sep 14:19 ncurses -> .
-rw-r--r-- 1 daniel users  3925  9. Sep 12:38 ncurses_dll.h
lrwxrwxrwx 1 daniel users     8  9. Sep 12:38 ncurses.h -> curses.h
Last edited 8 months ago by cetu86 (previous) (diff)

comment:26 Changed 8 months ago by rwbarton

  • Blocking 9421 removed

comment:27 Changed 7 months ago by thoughtpolice

  • Milestone 7.8.4 deleted
Note: See TracTickets for help on using tickets.