Optimised compilation of Debian GNU/Linux packages for the SIM.ONE

Martin Guy, 4 December 2005


What's new?

11 Nov 2005: Discovered apt-build

Summary

Of the GNU/Linux distributions I have tried to use to produce Linux filesystems, Debian GNU/Linux is the most successful: I made a full-featured system filetree on a USB pendrive in an afternoon using the standard installer.

However, the precompiled Debian packages are compiled to run on a wide range of ARM processors including ARM 610, ARM 710 and StrongARM, and as such are not optimised for the ARM920T that we use.

This document explores how to compile and install Debian packages from their source code while modifying the compilation options, and of thus making SIM.ONE-specific Debian packages.

By default, GCC-4.0.2 seems to generate code for -march=armv4 (not armv4t) and for -mcpu=arm720, while the best generic options for our platform are -march=armv4t -mcpu=arm920t.

There is more detailed information on GCC option flags in the Speed-space document.

How to compile Debian package from source

We will try to recompile "aptitude" from source.

First make sure the things it needs to build it are installed:

	# apt-get build-dep aptitude
then fetch and compile the source code
	# export CFLAGS="-mcpu=arm920t -O2"
# export CXXFLAGS="$CFLAGS"
# apt-get --compile source aptitude
This fails with errors, and "aptitude --version" says that it was built with GCC 3.3.5. Let's see if it works with GCC 3.3:
	# export CC=gcc-3.3 CFLAGS="-mcpu=arm920t -O2"
# export CXX=g++-3.3 CXXFLAGS="$CFLAGS"
# apt-get --compile source aptitude
Result: 6% reduction in code size and 0.4% increase in code speed.

mpg321_0.2.10.3

Standard package:
text data bss dec hex filename Timing
30305 4812 8852 43969 abc1 /usr/bin/mpg321 73.70r 72.70u 0.15
Home-built package with cpu=arm920t:
31336 4812 8848 44996 afc4 /usr/bin/mpg321 72.17r 70.01u 0.13s
Our arm920t-specific binary has 3% more code but is 4% faster.

Making SIM.ONE-specific Debian packages (on the SIM.ONE)

	# apt-get build-dep aptitude
# apt-get source aptitude
# cd aptitude-*
# export CC=gcc-3.3 CFLAGS="-mcpu=arm920t -O2"
# export CXX=g++-3.3 CXXFLAGS="$CFLAGS"
# dpkg-buildpackage
This method works for packages that are built using the standard "configure" scripts. It does not work for (eg) bsdgames, which has its own configuration mechanism and does not react to the CFLAGS environment variable. mpg321's debian/rules file blandly sets CFLAGS with no way to insert extra options.

One way to fix every package would be to reinstall the compiler so that it always generates arm920t code by default instead of generic ARM code, or to replace "gcc" with a wrapper script that calls the real gcc inserting an extra -mcpu=arm920t option:

#! /bin/sh
exec /usr/bin/gcc-4.0 -mcpu=arm920t "$@"
This is the method used for "mpg321" above.

apt-build

Since I wrote the above, I have found out about the apt-build utility, in particular, an article in the Knoppix forum cites:
	apt-build world --reinstall
or
	apt-build install mozilla-firefox
as a command to recompile the entire current system from source code. Specific compiler flags are configured into apt-build, which then uses a gcc wrapper to supply them to the real compiler. For gcc-4, these would be "-O2 -march=armv4t -mcpu=ep9312"

On our Armadillo native ARM Debian system, apt-build says:

Segmentation fault
Great!