User Tools

Site Tools


how-to-build-a-cross-compiler

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
how-to-build-a-cross-compiler [2014/11/11 08:52]
127.0.0.1 external edit
how-to-build-a-cross-compiler [2014/11/17 07:25] (current)
Line 1: Line 1:
 +<div round alert>
 +This page describes a previous effort at cross compilation using GNU make. The currently supported method uses BSD make and is described in [[:​DevelopersGuide:​Crosscompiling]].
 +</​div>​
 +This is a short how-to describing how to compile gcc cross compiler for sparc64 target (based on my previous work on L4 for sun4v)
 +
 +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:
 +
 +<​code>​
 +./configure --target=sparc64-unknown-linux-gnu \
 +                    --enable-64-bit-bfd \
 +                    --prefix=/​opt/​xgcc-sparc64/​ \
 +                    --program-prefix=sparc64-unknown-linux-gnu-
 +make
 +make install
 +</​code>​
 +<​code>​
 +--target=sparc64-unknown-linux-gnu
 +</​code>​
 +makes the resulting compiler to generate machine code for various 64-bit as well as 32-bit sparc machines
 +
 +<​code>​
 +--enable-64-bit-bfd
 +</​code>​
 +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 :
 +
 +<​code>​
 +./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
 +</​code>​
 +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++)
 +
 +<​code>​
 +--prefix
 +</​code>​
 +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:
 +
 +<​code>​
 +CFLAGS += -mcpu=v9 -m64 -fno-builtin -ffreestanding -fno-stack-protector
 +LDFLAGS += -dn -n -melf64_sparc
 +</​code>​
 +What do the options mean?
 +
 +<​code>​
 + ​-mcpu=v9 -m64
 +</​code>​
 +generates 64-bit code for sparc V9 (//v9 //can be be substituted by //niagara// or //​niagara2//​)
 +
 +<​code>​
 + ​-fno-builtin -ffreestanding
 +</​code>​
 +forces the compiler **not** to link with any internal libraries or standard/​system libraries.
 +
 +<​code>​
 + ​-fno-stack-protector
 +</​code>​
 +newer versions of gcc can include some code to your program and link with extra libraries to detect stack corruptions. Gcc delivered as an //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
 +
 +<​code>​
 +-dn -n -melf64_sparc
 +</​code>​
 +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 config and headers to compile the full gcc and glibc compiler. You may try to change the crosstool scripts and hope for the best. Good luck {{http://​www.world45.com/​twiki/​pub/​TWiki/​SmiliesPlugin/​wink.gif|wink}}
  
how-to-build-a-cross-compiler.txt · Last modified: 2014/11/17 07:25 (external edit)