From: Alexis on
Hi,

I've spent some time trying to build a gcc Ada cross compiler for i686-
elf target (well, a c,c++,ada compiler). I'm working on Windows with
Cygwin 1.7 and gcc 4.3.4 binaries and sources. I'm following the
procedure on: http://wiki.osdev.org/GCC_Cross-Compiler#Step_1_-_Bootstrap

So far GCC and libgcc have been built fine, but when I try to use i686-
elf-gcc to compile an Ada program I get the following error:

$ i686-elf-gcc -c hello.adb
fatal error, run-time library not installed correctly
cannot locate file system.ads
compilation abandoned

Thinking that this might solve the problem I've tried to build libada
following the same procedure for libgcc (make all-target-libada), only
to get multiple compilation errors such as (extract for a much larger
log):

make -C rts \
CC="`echo \"/usr/src/build-gcc/./gcc/xgcc -B/usr/src/
build-gcc/.
/gcc/ -B/usr/cross/i686-elf/bin/ -B/usr/cross/i686-elf/lib/ -isystem /
usr/cross/
i686-elf/include -isystem /usr/cross/i686-elf/sys-include\" \
| sed -e 's,^\./xgcc,../../xgcc,' -e 's,-B\./,-
B../../,'`" \
INCLUDES="-I. -I.. -I../.. -I/usr/src/gcc-4.3.4/gcc/
ada -I/usr/s
rc/gcc-4.3.4/gcc/ada/../config -I/usr/src/gcc-4.3.4/gcc/ada/../../
include -I/usr
/src/gcc-4.3.4/gcc/ada/.. -I./../.." \
CFLAGS="-g -O2 -fPIC -fexceptions -DIN_RTS" \
FORCE_DEBUG_ADAFLAGS="-g" \
srcdir=/usr/src/gcc-4.3.4/gcc/ada \
-f ../Makefile adaint.o argv.o cio.o cstreams.o
ctrl_c.o errno.o
exit.o env.o raise.o sysdep.o aux-io.o init.o initialize.o seh_init.o
cal.o fin
al.o tracebak.o expect.o mkdir.o socket.o targext.o
make[3]: Entering directory `/usr/src/build-gcc/gcc/ada/rts'
/usr/src/build-gcc/./gcc/xgcc -B/usr/src/build-gcc/./gcc/ -B/usr/cross/
i686-elf/
bin/ -B/usr/cross/i686-elf/lib/ -isystem /usr/cross/i686-elf/include -
isystem /u
sr/cross/i686-elf/sys-include -c -DCROSS_DIRECTORY_STRUCTURE -
DIN_GCC `echo -g
-O2 -fPIC -fexceptions -DIN_RTS |sed -e 's/-pedantic//g' -e 's/-
Wtraditional//g
'` -I. -I.. -I../.. -I/usr/src/gcc-4.3.4/gcc/ada -I/usr/src/
gcc-4.3.4/gcc/a
da/../config -I/usr/src/gcc-4.3.4/gcc/ada/../../include -I/usr/src/
gcc-4.3.4/gcc
/ada/.. -I./../.. adaint.c \
-o adaint.o
In file included from adaint.c:61:
/usr/src/gcc-4.3.4/gcc/ada/../tsystem.h:90:19: error: stdio.h: No such
file or d
irectory
/usr/src/gcc-4.3.4/gcc/ada/../tsystem.h:93:23: error: sys/types.h: No
such file
or directory
/usr/src/gcc-4.3.4/gcc/ada/../tsystem.h:96:19: error: errno.h: No such
file or d
irectory
/usr/src/gcc-4.3.4/gcc/ada/../tsystem.h:103:20: error: string.h: No
such file or
directory
/usr/src/gcc-4.3.4/gcc/ada/../tsystem.h:104:20: error: stdlib.h: No
such file or
directory
/usr/src/gcc-4.3.4/gcc/ada/../tsystem.h:105:20: error: unistd.h: No
such file or
directory
/usr/src/gcc-4.3.4/gcc/ada/../tsystem.h:111:18: error: time.h: No such
file or d
irectory

Can anybody please advise?

Kind regards, Alexis.
From: Yannick Duchêne (Hibou57) on
Le Thu, 20 May 2010 16:29:06 +0200, Alexis
<jose_alexis_paez_thurgood(a)hotmail.com> a écrit:

> Hi,
>
> I've spent some time trying to build a gcc Ada cross compiler for i686-
> elf target (well, a c,c++,ada compiler). I'm working on Windows with
> Cygwin 1.7 and gcc 4.3.4 binaries and sources. I'm following the
> procedure on: http://wiki.osdev.org/GCC_Cross-Compiler#Step_1_-_Bootstrap
>
> So far GCC and libgcc have been built fine, but when I try to use i686-
> elf-gcc to compile an Ada program I get the following error:
>
> $ i686-elf-gcc -c hello.adb
> fatal error, run-time library not installed correctly
> cannot locate file system.ads
> compilation abandoned
>
> Thinking that this might solve the problem I've tried to build libada
> following the same procedure for libgcc (make all-target-libada), only
> to get multiple compilation errors such as (extract for a much larger
> log):

I could create one for Windows -> Linux (Windows -> Mac still pending),
using MinGW.

What I can say: there is a --with-sysroot option in the configuration. You
must care a lot about what is contained in the directory you pass as the
--with-sysroot option. There may also be troubles due to the differences
of the directory structure on Windows compared to the one of
Linux/UNIX-like... but I guess the latter should not be a trouble with
Cygwin.

I would like to advice to check twice all of what is related to sysroot or
to --includedir or --libdir, if you use these.

Cannot tell more, as this would be too much work otherwise (building a
cross compiler is really not a piece of cake)

Wish you to succeed

--
There is even better than a pragma Assert: a SPARK --# check.
From: Alexis on
> > So far GCC and libgcc have been built fine, but when I try to use i686-
> > elf-gcc to compile an Ada program I get the following error:
>
> > $ i686-elf-gcc -c hello.adb
> > fatal error, run-time library not installed correctly
> > cannot locate file system.ads
> > compilation abandoned
>
> > Thinking that this might solve the problem I've tried to build libada
> > following the same procedure for libgcc (make all-target-libada), only
> > to get multiple compilation errors such as (extract for a much larger
> > log):
>
> I could create one for Windows -> Linux (Windows -> Mac still pending),  
> using MinGW.
>
> What I can say: there is a --with-sysroot option in the configuration. You  
> must care a lot about what is contained in the directory you pass as the  
> --with-sysroot option. There may also be troubles due to the differences  
> of the directory structure on Windows compared to the one of  
> Linux/UNIX-like... but I guess the latter should not be a trouble with  
> Cygwin.
>
> I would like to advice to check twice all of what is related to sysroot or  
> to --includedir or --libdir, if you use these.
>
> Cannot tell more, as this would be too much work otherwise (building a  
> cross compiler is really not a piece of cake)
>
> Wish you to succeed

Thanks for your reply. I have decided to stop trying to compile libada
and have managed to get the cross compiler to work by setting the RTS
option to \cygwin\lib\gcc\i686-pc-cygwin\4.3.4, which is where the
adainclude and adalib for the ada compiler bundled with Cygwin.

So far so good, but this makes me wonder, what is the RTS used for? Is
this now a real cross compiler as I'm using the RTS for the i686-pc-
cygwin target?

My guess is I should be using a proper i696-elf Ada RTS, right?

Best regards, Alexis.
From: Yannick Duchêne (Hibou57) on
Le Fri, 21 May 2010 09:31:25 +0200, Alexis
<jose_alexis_paez_thurgood(a)hotmail.com> a écrit:
> Thanks for your reply. I have decided to stop trying to compile libada
> and have managed to get the cross compiler to work by setting the RTS
> option to \cygwin\lib\gcc\i686-pc-cygwin\4.3.4, which is where the
> adainclude and adalib for the ada compiler bundled with Cygwin.
>
> So far so good, but this makes me wonder, what is the RTS used for? Is
> this now a real cross compiler as I'm using the RTS for the i686-pc-
> cygwin target?
>
> My guess is I should be using a proper i696-elf Ada RTS, right?
>
> Best regards, Alexis.
RTS stands for RunTime System. This is the GNAT runtime library (exception
handling, package elaboration, dispatching, and etc).

GNAT for Windows, is shipped with an RTS for Windows only. To target
Linux, you need an RTS for Linux... for Linux and the target architecture,
as Linux runs on multiple architectures (well, you've said the
architecture is Intel, so there should not be any trouble there).

The RTS is not the sole thing to be related to target OS and target
architecture : the Ada standard packages also have dependencies to that,
at least, the package named Standard.

So, even if you have a copy of the RTS for the target OS and architecture,
you will also need the standard packages for that OS and architecture.

You will also need a linker which can handle the OS target binary
application format.

GNAT on Windows is shipped with an LD which can only handle Windows binary
applications format.

You may find LD specific builds which can handle both Windows and ELF for
Intel architecture, however, this would not work. I know this would not
work, because I tried it in the past (that was the reason why I finally
decided to build my own cross-compiler).

All of that, to say if you want to cross-compile, you *really need* a
cross-compile tool chain : a gcc-ada cross-compiler with target RTS and
packages, some binutils for the target and an LD for the target.

I you are really in troubles with that, or fail to build a cross-compiler,
I would agree to send you mine via e-mail. But I would not provide support
for it (or may be if... well let me know), and I must say this is a MinGW
based cross-compiler, not Cygwin. It was also built to target i386, not
i686. By the way, I'm not sure I built it with C++ enabled (will have to
check).

Note: I could not really help you with building a cross-compiler with
Cygwin, as I suspect the related issues to be not the same as with MinGW..
The only thing I'm pretty sure about, reading your initial post, is that
your sysroot is not properly setup.

--
There is even better than a pragma Assert: a SPARK --# check.
From: Alexis on

>
> Note: I could not really help you with building a cross-compiler with  
> Cygwin, as I suspect the related issues to be not the same as with MinGW.  
> The only thing I'm pretty sure about, reading your initial post, is that  
> your sysroot is not properly setup.
>
> --
> There is even better than a pragma Assert: a SPARK --# check.

Hi again, and thanks again for your help.

Going back to the possibility of compiling libada for i686-elf target,
please bear with me just in case you might be able to help me with the
sysroot, this is what I have done so far:

From a standard Cygwin installation and with the src files in /usr/srx

export PREFIX=/usr/cross
export TARGET=i686-elf
cd /usr/src
mkdir build-binutils build-gcc

After successfully building the binutils then:

cd /usr/src/build-gcc
export PATH=$PATH:$PREFIX/bin
.../gcc-4.3.4/configure --target=$TARGET --prefix=$PREFIX --disable-nls
--enable-languages=c,c++,ada --without-headers
make all-gcc
make install-gcc

then:

make all-target-libgcc
make install-target-libgcc

then:

make all-target-libada

Where it fails trying to do the make -C rts.

Where should I be setting the sysroot directory?

Kind regards, Alexis.