Subject: Help building a cross compiler from Linux to NetBSD...
To: None <netbsd-help@NetBSD.ORG>
From: Dick Munroe <munroe@csworks.com>
List: netbsd-help
Date: 01/03/2001 12:38:59
OK, for reasons I won't get into I need to build the EGCS 1.0.3a
compiler (circa mid 1998) as a cross compiler on Linux to product a.out
format executables for NetBSD (actually a slightly different varient but
NetBSD does fine as a target).

Anyway, I grab a copy of binutils 2.10 and build them for a target of
i386-unknown-netbsd.

That seems to work.
'
Then I grab a copy of the NetBSD comp.tgz and extract the include files
(/usr/include) and the object libraries (/usr/lib) from them and
construct an EGCS cross compiler using the same target.  This gets all
the way through the compiler construction phase and then the following
happens:

loading site script /dev/null
loading cache ./config.cache
checking for gcc... /home/egcs/gcc/xgcc -B/home/egcs/gcc/
checking whether the C compiler (/home/egcs/gcc/xgcc -B/home/egcs/gcc/
-g -O2 ) works... no
configure: error: installation or configuration problem: C compiler
cannot create executables.
make[1]: *** [stmp-f2c.h] Error 1
make[1]: Leaving directory `/home/egcs/gcc'
make: *** [all-gcc] Error 2

So I build a little hello world program and run the cross compiler in
verbose mode and find:

[root@linux egcs]# /home/egcs/gcc/xgcc -B/home/egcs/gcc/ -g -O2 foo.c -v

Reading specs from /home/egcs/gcc/specs
gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
 /home/egcs/gcc/cpp -lang-c -v -isystem /home/egcs/gcc/include -undef
-D__GNUC__=2 -D__GNUC_MINOR__=90 -Dunix -Di386 -D__NetBSD__ -D
__unix__ -D__i386__ -D__NetBSD__ -D__unix -D__i386 -Asystem(unix)
-Asystem(NetBSD) -Acpu(i386) -Amachine(i386) -D__OPTIMIZE__ -g foo
.c /tmp/ccDfjQeZ.i
GNU CPP version egcs-2.90.29 980515 (egcs-1.0.3 release) (80386, BSD
syntax)
#include "..." search starts here:
#include <...> search starts here:
 /home/egcs/gcc/include
 /home/usr/local/lib/gcc-lib/i386-unknown-netbsd/egcs-2.90.29/include
 /home/usr/local/i386-unknown-netbsd/sys-include
 /home/usr/local/i386-unknown-netbsd/include
End of search list.
 /home/egcs/gcc/cc1 /tmp/ccDfjQeZ.i -quiet -dumpbase foo.c -g -O2
-version -o /tmp/ccDfjQeZ.s
GNU C version egcs-2.90.29 980515 (egcs-1.0.3 release)
(i386-unknown-netbsd) compiled by GNU C version egcs-2.91.66
19990314/Linux (
egcs-1.1.2 release).
 /home/usr/local/i386-unknown-netbsd/bin/as -o /tmp/ccDfjQeZ1.o
/tmp/ccDfjQeZ.s
 /home/egcs/gcc/ld -e start -dc -dp
/home/usr/local/i386-unknown-netbsd/lib/crt0.o -L/home/egcs/gcc
-L/home/usr/local/lib/gcc-lib/i3
86-unknown-netbsd/egcs-2.90.29 -L/home/usr/local/i386-unknown-netbsd/lib
/tmp/ccDfjQeZ1.o -lgcc -lc -lgcc
/home/usr/local/i386-unknown-netbsd/lib/crt0.o: file not recognized:
File format not recognized
collect2: ld returned 1 exit status

And when I check for the type of crt0.o I find:

[root@linux egcs]# file /home/usr/local/i386-unknown-netbsd/lib/crt0.o
/home/usr/local/i386-unknown-netbsd/lib/crt0.o: ELF 32-bit LSB
relocatable, Intel 80386, version 1, not stripped

So it looks like the binutils/gcc cross compiler doesn't like the format
of crt0.o but the real question is why?

The compiler is from about mid 1998.  Did the elf format evolve
substantially from then until now?  Enough to mean that the compiler
from 1998 ago can't process it?

Any and all help would be appreciated.

Dick Munroe

p.s. a request dealing with this has been posted to the CrossGCC mailing
list as well.  I'm hoping that the NetBSD expertise available here will
be of some use as well.