Cross Container Support Project

This page is aimed to introduce the GSoC 2012 project: Cross Container Support.

I will document the progress of my project here.

Running Qemu-user on Chroot
This section updates the qemu-user and describes how to build a chroot with qemu-user on x86 machine.

Qemu-user Installation
In order to take advantage of qemu-user mode we need to do a few things. First we need to merge the main package we are going to need. Note the use of the static use flag. Python is needed during qemu-user compiling.

Binfmt_misc Configuration
First you need to build the kernel module binfmt_misc. Add this to your kernel .config: CONFIG_BINFMT_MISC=m or CONFIG_BINFMT_MISC=y. If this module is not built already, then the devel host will require a reboot after the kernel update and modules_install. The complete list of relevant kernel options (tested on 3.2.1-gentoo-r2) is as follows.

Mount the binfmt_misc handler if it's not already, then we need to register our format with the kernel via the procfs.

Next, register qemu-user-arch to the binfmt_misc module. You don't need to add them one by one and Luca has provided a initscript to get the bin formats registered. You can use it:

or start the service on bootstrap:

You could learn more detail of registering bin formats through /usr/portage/app-emulation/qemu-user/files/qemu-binfmt.initd.

Enter/Exit the Chroot
Firstly, you should chose and download a stage3 tarball from installation media. We take arm arch as an example to show how to enter/exit the chroot.


 * Download and unpack arm stage tarball


 * Install the static qemu-user into the chroot


 * Mount the required directories


 * Chroot into the environment


 * Unmount stuff when not in use

Setup Crossdev
The first thing that is necessary is the creation of an overlay. If you have one, emerge the script:

This will provide you with the crossdev script. This script automates the steps necessary to build a toolchain. These steps are, in short:


 * 1) binutils: Build a cross-binutils, which links and processes for the target architecture.
 * 2) linux-headers: Install a set of C library and kernel headers for the target architecture.
 * 3) libc-headers: Additional header files
 * 4) gcc-stage-1: Build a basic (stage 1) gcc cross-compiler. This will be used to compile the C library. It will be unable to build anything almost else (because it can't link against the C library it doesn't have).
 * 5) libc: Build the cross-compiled C library (using the stage 1 cross compiler).
 * 6) gcc-stage-2: Build a full (stage 2) C cross-compiler.

All cross toolchains will be kept locally in the overlay, separate from native tools.

The script is used like:

This will build a cross-compiling toolchain for PowerPC machines.

By default, the newest stable version of the binutils, libraries, and C compiler will be used. It is quite often the case they will not compile themselves through the entire build process. Less bleeding edge versions can be specified with additional flags:

--b 2.22     # specifies the version of binutils --g 4.6.3    # specifies the version of gcc --l 2.15-r2  # specifies the version of the tuple-specified libc --k 3.5      # specifies the version of the kernel headers

It is recommended trying older versions, particularly of gcc, if the script fails.

If you want to remove a toolchain, use the clean flag:

This will unmerge the packages created by crossdev.

If you got the errors about fortran, use the fellow command:

Cross Container
The lxc.sh tool can download, configure and create a multi-arch gentoo guest. Using this tool, the user build a native gcc in chroot. You can download it here: lxc.sh

Next, we will take armv7a_hardfloat as a example to build the native compiler in chroot.

Install a cross compiler
You must install the cross compiler manually:

Create the chroot
You can create an arm gentoo guest:

You can also start and destroy the arm gentoo guest:

Additional developers, bug fixes, comments, etc. are welcome.

Switch to native compiler
In chroot, you can switch to native compiler:

Then, you can get the native armv7a-hardfloat-linux-gnueabi-gcc. To use it, just specify the CC=armv7a-hardfloat-linux-gnueabi-gcc in the Makefile.

You also could switch to emulated gcc as well: