4854
Comment:
|
5544
|
Deletions are marked like this. | Additions are marked like this. |
Line 7: | Line 7: |
=== Short Version === | <<TableOfContents()>> === Building (Short Version) === |
Line 27: | Line 29: |
=== Long Version === | === Building (Long Version) === |
Line 138: | Line 140: |
=== Usage === For autoconf, add the Barrelfish target triple to {{{config.sub}}}: {{{ @@ -1244,6 +1244,7 @@ case $os in | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ | -aos* \ + | -barrelfish* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ }}} ... and run the configure script in cross-compile mode: {{{ ./configure --host=x86_64-pc-barrelfish }}} |
C/C++ cross compiler
This page contains instructions on how to build a GCC toolchain, which can be used to cross-compile C and C++ applications for Barrelfish.
In general, most language constructs work (libstdc++, RTTI, virtual functions, templates, global constructors, inline assembler, thread locals) but exceptions are not supported (read here for more details).
Building (Short Version)
First, you will need to install a few packages:
$ sudo apt-get install gcc g++ make patch bison flex texinfo
Optional: to enable Graphite loop optimizations you will also need libcloog-ppl-dev.
Next, download the build script and corresponding patches:
The recommended versions (shown in bold) should be preferred as these have been tested and have several improvements and fixes. These are known to work with Barrelfish release2013-03-22.
Finally, modify any configuration parameters in the script, run it and a few minutes later the toolchain should be installed in the toolchain directory of your Barrelfish tree.
Hint: Each toolchain is specific to a build tree, so it can be helpful to use smartcd to automatically add/remove this from the PATH environment variable.
Building (Long Version)
These instructions have been tested on Ubuntu 12.10.
1. Edit $HOME/.bashrc and add these lines (modify these variables as you wish):
export PREFIX=$HOME/arm/opt/bf-tools export PATH=$PATH:$PREFIX/bin export TARGET=x86_64-pc-barrelfish export TOOLS=$HOME/bsc/bf-tools export BF_BUILD=$HOME/arm/bf/build
PREFIX is where the toolchain will be installed
TOOLS is the initially empty working directory
BF_BUILD is the Barrelfish build directory
TARGET is the cross compiler target. It can be:
- x86_64-pc-barrelfish
- i586-pc-barrelfish
- i586-scc-barrelfish
We exit the shell and run it again to load these variables.
2. Download and build Barrelfish for x86_64, x86_32 or scc target (this step may have been done previously). The Barrelfish release tested is 2012-11-03:
cd $TOOLS hg clone http://hg.barrelfish.org bf mkdir bf/build cd bf/build ../hake/hake.sh -a x86_64 -s .. make
3. Then, we need to install needed packages to build the toolchain:
sudo apt-get install texinfo flex gcc libgmp-dev libmpfr-dev libmpc-dev
These steps have been done using the system compiler (gcc version 4.7.2).
4. Build and install binutils: Save file binutils-2.21-bf.patch file attached in this page to the TOOLS directory
cd $TOOLS wget http://mirrors.usc.edu/pub/gnu/binutils/binutils-2.21.tar.bz2 tar xjvf binutils-2.21.tar.bz2 cd binutils-2.21/ patch -p1 < ../binutils-2.21-bf.patch cd .. mkdir binutils-2.21-build cd binutils-2.21-build/ ../binutils-2.21/configure --prefix=$PREFIX --target=$TARGET make make install
5. Build and install gcc and g++: Save file gcc-4.5.2-bf.patch file attached in this page to the TOOLS directory
cd $TOOLS wget http://ftp.gnu.org/gnu/gcc/gcc-4.5.2/gcc-4.5.2.tar.bz2 tar xjvf gcc-4.5.2.tar.bz2 cd gcc-4.5.2/ patch -p1 < ../gcc-4.5.2-bf.patch
Now we need to edit the files gcc/config/i386/bf-*.h and change the first two lines:
BF_SRC holds the directory of Barrelfish source.
BF_BUILD is the Barrelfish build directory.
Then we proceed with the compilation:
cd $TOOLS mkdir gcc-4.5.2-build cd gcc-4.5.2-build/ ../gcc-4.5.2/configure --prefix=$PREFIX --target=$TARGET --disable-nls --enable-languages=c,c++ --disable-libssp make make install
6. We can try the C++ compiler by creating a simple program test.cc and running it in Barrelfish:
#include <iostream> int main(int argc, char *argv[]) { std::cout << "Hello!" << std::endl; return 0; }
We compile it with:
x86_64-pc-barrelfish-g++ test.cc -o test
Then we copy the executable to the Barrelfish build directory and add the line to menu.lst:
cp test $BF_BUILD/x86_64/sbin cd $BF_BUILD echo "module /x86_64/sbin/test" >> menu.lst make sim
Usage
For autoconf, add the Barrelfish target triple to config.sub:
@@ -1244,6 +1244,7 @@ case $os in | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ | -aos* \ + | -barrelfish* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
... and run the configure script in cross-compile mode:
./configure --host=x86_64-pc-barrelfish