Mulitarch Cross Toolchains
Cross Toolchains can be built using multiarch mechanisms. Specifically they need the ability to build-depend on foreign-arch packages. (arm-linux-gnueabi-gcc needs libc:armel and linux-libc-dev:armel to build).
This page documents the state of work to make this a useful reality, integrated into Debian.
How is this different from before
There have been binary cross-toolchains built for Debian for a decade or so now, using various schemes. (toolchain-source, buildcross). The Emdebian project has provided these, and currently builds them using buildcross, which relies on there already being a suitable glibc package for the target architecture, which is transformed using dpkg-cross so that everything exists in one architecture. The buildcross process is not designed for use on normal buildds due to the cross-arch buildd-deps so these packages have never been available in Debian proper. Hector Oron wrote buildcross and maintained
Ubuntu (with Linaro sponsorship) took a different approach in order to get toolchains into the archive. armel-cross-toolchain-base is a package which uses binary source packages from binutils, eglibc, linux-kernel and gcc (binutils-source, eglibc-source, linux-<ver>-source, gcc-<ver>-source) to run a 3-stage bootstrap on a normal buildd and thus generate in-archive toolchains. It works, but it's not pretty. This package has support for doing builds on Debian too, alkthough it is only occaisionally maintained.
Multiarch, combined with staged builds, lets us simplify the build process by using the normal source packages, but building them for specified targets and stages, with cross-arch dependencies. (or at least it should...)
Initial work on this was done as a 2012 GSOC project, and has just (Dec 2012) been updated to gcc4.7.2-12, which already includes the libsdtc++-dev split part of that work. Current work is on checking that this works in the bootstrap context.
Credits: Nikita Youshchenko for toolchain-source and initial Debian packaging cross support Hector Oron (Zumbi): for Buildcross, toolchain build maintenance, GSOC mentoring Marcin Juscewiekcz for cross-toolchain-base and gcc-cross-defaults, GSOC mentoring Wookey: initial emdebian cross-toolchains, GSOC proposals and general badgering Thibaut Girka: initial multiarch toolchain support
Repository
The sources and binaries from this process are being uploaded to Wookey's bootstrap repos. The multiarch toolchain bootstrap is being done in Debian using packages from unstable and experimental.
Bootstrapping the toolchain MA-style
Manual full bootstrap toolchain build
Get suitable binutils source (2.23.1 or later), unpack, install build-deps, then build a BUILD_ARCH package with a specified TARGET_ARCH.
TARGET=arm64 dpkg-buildpackage -b
which should produce: binutils-aarch64-linux-gnu_2.23.1-1~exp2_amd64.deb
Get suitable linux kernel source (from bootstrap repo or see ), unpack. Source has been modified to allow a stage1 build of just linux-libc-dev using minimal build-deps.
DEB_BUILD_PROFILE=stage1 apt-get build-dep linux-3.6.4
Then build the package for the target arch:
DEB_BUILD_PROFILE=stage1 dpkg-buildpackage -aarm64
which should get you linux-libc-dev_3.6.4-1~experimental.1_arm64.deb (i.e. linux-libc-dev:arm64)
Now on the gcc/eglibc 3-stage bootstrap dance: Using this set of patches: http://emdebian.org/~thibg/patches/gcc-4.7/4.7.2-12/ plus a little bit of BUILD_PROFILE support:
Index: gcc-4.7-4.7.2.MAquilt/debian/rules.defs =================================================================== --- gcc-4.7-4.7.2.MAquilt.orig/debian/rules.defs 2012-12-10 04:48:11.000000000 +0000 +++ gcc-4.7-4.7.2.MAquilt/debian/rules.defs 2012-12-10 18:08:30.000000000 +0000 @@ -214,7 +214,19 @@ endif # ------------------------------------------------------------------- -# stage options +# stage/build_profile options + +ifneq (,$(findstring stage1,$(DEB_BUILD_PROFILE))) + DEB_STAGE := stage1 + DEB_CROSS_NO_BIARCH := yes +endif + +ifneq (,$(findstring stage2,$(DEB_BUILD_PROFILE))) + DEB_STAGE := stage2 + DEB_CROSS_NO_BIARCH := yes +endif + + ifdef DEB_STAGE with_cdev := yes separate_lang := yes
we should be able to build with: GCC_TARGET=arm64 DEB_BUILD_PROFILE=stage1 debuild --preserve-env but it fails with -12 because that version doesn't build libgcc1 any more but does try to package it.
Slick apt-driven bootstrap
This process can be made very slick by using apt-get --build, as that gets sources, unpacks them, and builds them. apt-get build-dep will get all the build-deps needed (but does only work on deps listed in a Sources file so if you've change them locally it doesn't do what you want.
This could be the basis for automation of the process.
First add the target architecture
dpkg --add-architecture arm64
Binutils: (no source changes)
apt-get build-dep binutils/experimental TARGET=arm64 apt-get --build -oDpkg::Build-options="-k BEA7C52D -b" source binutils/experimental
- modified verion:
DEB_TARGET_ARCH=arm64 apt-get --build -oDpkg::Build-options="-k BEA7C52D -b" source binutils=2.23.1~bootstrap
Kernel-headers:
DEB_BUILD_PROFILE=stage1 apt-get build-dep linux-3.6.4 DEB_BUILD_PROFILE=stage1 apt-get --build -oDpkg::Build-options="-aarm64 -k BEA7C52D -B" source kernel-3.6.4=3.6.4-1~experimental.1arm64
gcc stage 1 build: (needs version 4.7.2-13~multiarch)
DEB_BUILD_PROFILE=stage1 apt-get build-dep gcc-4.7 DEB_BUILD_PROFILE=stage1 apt-get --build -oDpkg::Build-options="-aarm64 -k BEA7C52D -B" source gcc-4.7=4.7.2-13~multiarch
What actually happens here is the equivalent of DEB_STAGE=stage1 DEB_CROSS_NO_BIARCH=yes BACKPORT=false dpkg-buildpackage
eglibc stage 1 build: (needs version 2.16)
Consistent target specifications
Packages that are built for a target architecture (because they generate code) need a way to specify that. This has been a little haphazard to date. For this to be automatable by build tools which don't necessarily know the specifics of every package we need a bit more regularity.
binutils uses TARGET=<arch> or a file debian/target. (<arch here can be Debian or GNU name)
gcc uses DEB_GCC_TARGET (or GCC_TARGET)=<arch> or a file debian/target. (<arch> here is Debian name)
Using a consistent variable of the same form as the BUILD and HOST vars makes sense as a way of making this consistent. e.g. DEB_TARGET_ARCH=arm64
It should also be possible to set the target arch in dpkg-buildpackage, as is currently possible for the host arch. a --target-arch=<arch> seems the obvious way. An unfinished patch for this exists.
A bug for binutils to honour DEB_TARGET_ARCH has been filed.
Normal cross-toolchains builds
Normally we will already have a target_arch glibc so the first two stages can be skipped.