id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	os	architecture	failure	difficulty	testcase	blockedby	blocking	related
6086	Cross compilation fails using system linker for other architecture binaries	mtjm	simonmar	"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.)"	bug	closed	high	7.8.1	Build System	7.5	fixed			Linux	Unknown/Multiple	Building GHC failed	Unknown				
