Opened 2 years ago

Closed 15 months ago

#6086 closed bug (fixed)

Cross compilation fails using system linker for other architecture binaries

Reported by: mtjm Owned by: simonmar
Priority: high Milestone: 7.8.1
Component: Build System Version: 7.5
Keywords: Cc:
Operating System: Linux Architecture: Unknown/Multiple
Type of failure: Building GHC failed Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:


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-
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
/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/ 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 (4)

comment:1 Changed 18 months ago by igloo

  • Difficulty set to Unknown
  • Milestone set to 7.8.1

Thanks for the report

comment:2 Changed 15 months 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 15 months ago by marlowsd@…

commit f77291d60f33fe601dbe0ff94b0192c5cd4ad6b5

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

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

 rules/ |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

comment:4 Changed 15 months ago by simonmar

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.