This is a short how-to describing how to compile gcc cross compiler for sparc64 target.

It s a very basic cross compiler that can produce code that is supposed to run on a bare machine, for instance a OS kernel. To get a full xcompiler is a fairly complex task that can be handled by Crosstool which contains scripts for several host-target-gcc-glibc combinations. However, the sparc scripts are fairly outdated and there are none for gcc 4.x. We are going to build only the first stage of the cross compiler.

What do we need : Recen version of binutils and gcc

First, we have to compile the binutils which in turn will be use to compile the first stage of gcc:

./configure --target=sparc64-unknown-linux-gnu \
                    --enable-64-bit-bfd \
                    --prefix=/opt/xgcc-sparc64/ \
                    --program-prefix=sparc64-unknown-linux-gnu-
make
make install

--target=sparc64-unknown-linux-gnu
makes the resulting compiler to generate machine code for various 64-bit as well as 32-bit sparc machines

--enable-64-bit-bfd
If compiling on a 32-bit machine this option forces to generate compiler than can also emit 64-bit code. It would be otherwise excluded!!!

Other options are optional and determine how and where is the cross compiler installed on your system.

sparc64-unknown-linux-gnu and sparc-unknown-linux-gnu are probably the same the important bit is to enable 64-bit BFD

Second, we will compile the first stage of the cross compiler :

./configure --prefix=/opt/xgcc-sparc64/ \
                    --target=sparc64-unknown-linux-gnu \
                    --disable-bootstrap \
                    --disable-threads \
                    --with-long-double-128 \
                    --disable-multilib \
                    --with-newlib \
                    --disable-nls \
                    --enable-symvers=gnu \
                    --enable-__cxa_atexit \
                    --enable-languages=c,c++ \
                    --disable-shared \
                    --program-prefix=sparc64-unknown-linux-gnu-
make all-gcc
make install-gcc

The compilation will not bootstrap the compiler, will not include support for threads (we don't need this), will disable all sorts of libraries (we don't have them on a bare machine anyway) and enables C and C++ (yes, L4 is written in C++)

--prefix
must be the same as for binutils! The bin utils must be already installed in this path.

And here we go! You can now use the compiler on your (i386?) machine to generate binaries for spar64. To do that, use following options:

CFLAGS += -mcpu=v9 -m64 -fno-builtin -ffreestanding -fno-stack-protector
LDFLAGS += -dn -n -melf64_sparc

What do the options mean?

 -mcpu=v9 -m64 
generates 64-bit code for sparc V9 (v9 can be be substituted by niagara or niagara2)
 -fno-builtin -ffreestanding 
forces the compiler not to link with any internal libraries or standard/system libraries.
 -fno-stack-protector 
newer versions of gcc can include some code to your program and link with extra libraries to detect stack corruptions. Gcc delivered as a Ubuntu package has this turned on by default and the turn off options is not documented in man pages! You could add the protecter hooks yourself, however, you would need to know how and when to initialize and use the *%g7% register
-dn -n -melf64_sparc
prohibits linking with standard shared libraries, page alignment of the sections in the output (e.g. wen LBA is 1M the output would contain about 1M of zeroes!!!) and genrates 64-bit ELF output.

To get a full cross compiler, you need to use the upper described process to compile glibc and use the basic cross compiler, glibc and linux congig and header to compile the full gcc and glibc compiler. You may try to change the crosstool scripts and hope for the best. Good luck wink

-- TomasHruby - 15 Jul 2008

Topic revision: r1 - 15 Jul 2008 - 02:51:49 - TomasHruby

tip TWiki Tip of the Day
Control table attributes with TablePlugin
The TablePlugin gives extra control of table display: Allows sorting Changing table properties ... Read on Read more

 
World45 Wiki
This site is powerd by World45 Wiki collaboration platformCopyright © by World45 Ltd. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback