torsdag 21 oktober 2010

Building the LLVM based binary translator.

Lars.Rasmusson@sics.se 2010-10-21

1. Create clean build root file system

To make sure that we know what software we are using to build, we first create an entire root file system in a catalog. It containts its own build tools, independent of what the host OS itself uses.
Use debootstrap to install a bare bones root file system from a local repository:

A linux running in Xen gets its console on hvc0, and for Ubuntu to start a getty on hvc0, put hvc0.conf in /etc/init/hvc0.conf

# hvc0 - getty
#
# This service maintains a getty on Xen's ttyhvc0 from the point the system is
# started until it is shut down again.
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
exec /sbin/getty -8 115200 hvc0

Now you should be able to reboot and select the xen kernel from grub's boot menu. When you have booted, verify with

xm info

that Xen and xend are running.

6. build stub domain

This is done in the chrooted xenbuild directory.
First we build a stub domain, which makes the Xen Makefiles pull in several packages such as lwip, newlib, etc. and then compile mini-os which uses the packages.

D=~/xen-4.0-testing/stubdom
cd$Dmake c-stubdom

Now the mini-os object files are compiled. We put them for convenience into a library

9. Building a cross compiler

You can compile some c++ programs for minios using the system's normal gcc, but it can't use iostreams etc, because the header files for g++ depend on the linux header files, and will break when compiling for minios.

We need a special c++ compiler that uses the right system include files, and newlib instead of glibc, or else
include iostream will not work. A g++ compiled for linux relies on some definitions
in the ctype.h file. Those definitions do not exist in minios, and therefore the iostream header files
generated for a linux g++ will not work on a minios system.

To build a g++ for minios, the sysroot of mini os must exist.

It got created (above) when we did make c-stubdom in the stubdom directory in the xen repository.
The minios sysroot is placed in $HOME/xen-4.0-testing/stubdom/cross-root-i686

11. Building an LLVM program for minios

The following has to be defined in some c source file, because newlib doesn't providelseek and fstat correctly after the xen patches (which renames them).
The domain crashes if linked with crt{begin,end}.o so instead
declare the missing variable __dso_handle.
The code below could be placed in main.cpp, for instance.