Differences between revisions 19 and 20
Revision 19 as of 2014-11-26 19:25:51
Size: 12443
Editor: wookey
Comment:
Revision 20 as of 2014-11-27 03:59:41
Size: 11339
Editor: wookey
Comment: Add links to related docs, move design info out into Toolchain/Cross
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
This document describes plans for cross-toolchains in Debian. Some of this is now in unstable, but only cross-binutils-* made it into Jessie. Jessie-compatible packages are available in the [[http://emdebian.org/tools/debian/|Debian Cross-toolchains]] repo. See below.

cross-binutils, cross-gcc, and cross-gcc-defaults (but not pkg-config, crossbuild-essential) are available in unstable.

}}}
This document describes cross-toolchains in Debian. Some of this is now in unstable, but only cross-binutils-* is in Jessie - other Jessie-compatible packages are available in the [[http://emdebian.org/tools/debian/|Debian Cross-toolchains]] repo. Some of this is still plans and packages in experimental, intended to be released in Stretch.
}}}
Line 14: Line 13:
== Related pages ==

 * [[Toolchain/Cross]] : Overview of toolchain build methods
 * MultiarchCrossToolchainBuild : Info on building toolchains using multiarch methods
 * CoinstallableToolchains : Scheme to allow co-installable compilers
 * [[toolchain/BootstrapIssues]] : Breakage found when building debian crosstoolchains (might save you some time!)
 * [[Sprints/2014/BootstrapSprint/Results]] : Crossbuild sprint report discussing various crossbuild/toolchain issues

=== Pages of largely historical interest ===

 * EmdebianToolchain
 * [[http://psas.pdx.edu/DebianCrossCompilerHowto | HOWTO by Josh Tripplet]]
Line 26: Line 37:
 * cross-gcc packages built from gcc-4.9 only for amd64, targetting the linux architectures supported in Debian: armel, armhf, arm64, mips, mipsel, powerpc, ppc64el  * cross-gcc packages built from gcc-4.9 only for amd64, targeting the linux architectures supported in Debian: armel, armhf, arm64, mips, mipsel, powerpc, ppc64el
Line 34: Line 45:

== Status of cross-toolchains in Ubuntu ==

Current details are given on https://wiki.ubuntu.com/ToolChain#Cross_development_toolchain

If you have an Ubuntu system, cross-toolchains (i386 & amd64->armel) have been included since 10.10/Maverick. From 12.10/Quantal onwards there are crossbuild-essential-<arch> convenience packages to install cross toolchains, cross-pkgconfig and (multiarch) cross-libc. Armel then armhf were initially supported. Arm64, powerpc and ppc64el were added later.

All these toolchains search multiarch library and header paths by default so are suitable for multiarch crossbuilding.
Line 52: Line 71:
These packages did not quite get into Jessie so you need to install them from [[http://emdebian.org/tools/debian/|the Debian Cross-toolchains]] repository. Create {{{/etc/apt/sources.list.d/crosstools.list}}} containing: These packages did not make it into Jessie so you need to install them from [[http://emdebian.org/tools/debian/|the Debian Cross-toolchains]] repository. Create {{{/etc/apt/sources.list.d/crosstools.list}}} containing:
Line 98: Line 117:

=== For Wheezy ===

You are knackered. Emdebian.org did have 'unstable' packages which would work on wheezy but these need to be restored after a server compromise.

=== For Squeeze ===

You are knackered. Emdebian.org had packages which worked nicely but these need to be restored after a server compromise.

=== Older ===

Emdebian.org keeps some 2.95 vintage packages in case that's useful (people do still ask occaisionally!). Currently awaiting re-uploading.
Line 181: Line 212:
In jessie+1 build-essential implicitly depends on the compiler for the HOST architecture (which is the architecture you are building _for_) via 'gcc-for-host'. This is the default compiler, which must be run specifying the TARGET architecture (the one you want to build code for), i.e. as x86_64-linux-gnu-eabi-gcc. Don't call 'gcc' as it may not do the right thing, or work at all. In stretch build-essential implicitly depends on the compiler for the HOST architecture (which is the architecture you are building _for_) via 'gcc-for-host'. This is the default compiler, which must be run specifying the TARGET architecture (the one you want to build code for), i.e. as x86_64-linux-gnu-eabi-gcc. Don't call 'gcc' as it may not do the right thing, or work at all.
Line 191: Line 222:
''Appropriate info need extracting to here''

== Cross-toolchain building ==

There are various parts to the cross-toolchains, wich come from
several source packages. The cross-gcc packages themselves can be built
in two different ways.

 1. Multiarch gcc builds
 2. Bootstrap cross-toolchain builds

The differences are explained on MultiarchCrossTroolchainBuilds.

The former builds (for example) gcc-arm-linux-gnueabihf (and cpp,g++,gfortran) against the linux-libc-dev:armhf, libc6-dev:armhf, libstdc++-dev:armhf and libgcc1:armhf already in the archive. The build is quick and simple, but the resulting package has cross-arch
dependencies (on the various :armhf packages), so you need to enabled multiarch to install them. You will need to enable multiarch for most cross-builds anyway

The latter builds (for example) linux-libc-dev-cross-armhf, libc-dev-cross-armhf, libstdc++-dev-cross-armhf, libgcc1-cross-armhf and gcc-arm-linux-gnueabihf (and cpp,g++,gfortran) from the kernel, glibc, and gcc sources, via the toolchain bootstrap process. Because the foreign-arch libraries are converted to build-arch packages, the
toolchain does not need multiarch enabled to build, but the build is much longer and more complicated, and you end up with two copies of those libraries on your system.

This type of build is necessary when the target architecture is not in the debian archive as the libraries are not available to build against.
''Appropriate info needs extracting to here''
Line 226: Line 239:

=== Multiarch vs Multilib ===

Targetting related architectures (such as i386/amd64, armel/armhf,
mips/mipsel) can be done in two different ways. You can either build
one cross-compiler for each target, and install whichever ones you
need, or you can build one cross-compiler which has two or more
multilibs installed, install just that one cross-compiler and use
build options to control which code is output.

i.e on amd64 you can target i386 either by running
{{{i386-linux-gnu-gcc}}},
or by running
{{{x86_64-linux-gnu-gcc -m32}}}

These options are not consistent across different architecture sets,
whilst use of <triplet>-gcc always works:
  {{{arm-linux-gnueabi-gcc}}} produces the same (armel) output on all arches
  {{{arm-linux-gnueabihf-gcc -mabi=softfp}}} can be used instead on armhf to produce armel binaries.

Building these multilibbed cross-toolchains is are a lot more fiddly
than plain multiarch ones. Thus the current debian cross-toolchains
are not multilibbed and only support the <triplet>-gcc method. Install
whichever targets you need, and use the same commands
everywhere. Encourage upstreams to call tools this way, rather than
using -mabi=blah options, although in x86 world the use of m32/m64 is
rife and is probably too late to change. Some packages may need their
build options adjusting to do this right.

CrossToolchains

This is in flux

This document describes cross-toolchains in Debian. Some of this is now in unstable, but only cross-binutils-* is in Jessie - other Jessie-compatible packages are available in the Debian Cross-toolchains repo. Some of this is still plans and packages in experimental, intended to be released in Stretch.


Pages of largely historical interest

Status of cross-toolchains in the Debian archive

In jessie/testing

  • cross-binutils (targetting arm64, armel, armhf, amd64,, i386, mips, mipsel, powerpc, ppc64el)

    Other packages are available from the Debian Cross-toolchains repository. See 'Installation' below.

In unstable

  • cross-binutils
  • cross-gcc packages built from gcc-4.9 only for amd64, targeting the linux architectures supported in Debian: armel, armhf, arm64, mips, mipsel, powerpc, ppc64el gcc, g++ and gfortran cross-compilers are provided
  • cross-gcc-defaults metapackages which provide symlinks to the current version of the compilers (so that 'arm-linux-gnueabi-gcc' works when the compiler binary is actually arm-linux-gnueabi-gcc-4.9

In experimental

  • crossbuild-essential metapackage to pull in gcc, g++, libc-dev:arch and dpkg-cross (for autoconf and cmake cache/toolchain file support)

Status of cross-toolchains in Ubuntu

Current details are given on https://wiki.ubuntu.com/ToolChain#Cross_development_toolchain

If you have an Ubuntu system, cross-toolchains (i386 & amd64->armel) have been included since 10.10/Maverick. From 12.10/Quantal onwards there are crossbuild-essential-<arch> convenience packages to install cross toolchains, cross-pkgconfig and (multiarch) cross-libc. Armel then armhf were initially supported. Arm64, powerpc and ppc64el were added later.

All these toolchains search multiarch library and header paths by default so are suitable for multiarch crossbuilding.

Installation

For jessie/testing

Cross-toolchains for jessie are available, but only cross-binutils is in the main archive. Other packages come from an external repository.

The toolchains install on amd64 and i386 machines, targeting the jessie release architectures:

  • arm64
  • armel
  • armhf
  • mips
  • mipsel
  • powerpc
  • ppc64el

Currently cpp, gcc, g++, and gfortran are built. It's easy to build more languages so ask if you have a need. gccgo and gobjc will be added soon.

These packages did not make it into Jessie so you need to install them from the Debian Cross-toolchains repository. Create /etc/apt/sources.list.d/crosstools.list containing:

deb http://emdebian.org/tools/debian/ jessie main

You will need the archive key installed.

curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | sudo apt-key add -

The key fingerprint is: 084C 6C6F 3915 9EDB 6796 9AA8 7DE0 8967 1804 772E (you will need to install curl in a bare chroot)

crossbuild-essential-<arch> packages exist to aid in installing the correct cross-packages. For instance to install the armhf cross-toolchain, first enable the foreign architecture (and update), then install crossbuild-essential-armhf :

sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install crossbuild-essential-armhf

This will pull in the required packages to cross-build for the target architecture, namely libc6-dev:<arch>, gcc-<triplet>, g++-<triplet> and dpkg-cross.

For unstable

You must enable the appropriate (HOST) foreign architecture before installing the cross-compiler.

dpkg --add-architecture armhf
apt-get update

It is recommended to install the cross environment like this as that pulls in all the necessary components:

apt-get install crossbuild-essential-<arch>

i.e

apt-get install crossbuild-essential-armhf

But you can install just the compiler with

apt-get install gcc-arm-linux-gnueabihf

Note that gcc-arm-linux-gnueabihf is (like the native 'gcc') just a metapackage, which brings int he current version of the actual compiler gcc-4.9-arm-linux-gnueabihf (c.f. gcc-4.9)

g++-<triplet>, gfortran-<triplet>, gobjc-<triplet> and gccgo-<triplet> packages also exist.

For Wheezy

You are knackered. Emdebian.org did have 'unstable' packages which would work on wheezy but these need to be restored after a server compromise.

For Squeeze

You are knackered. Emdebian.org had packages which worked nicely but these need to be restored after a server compromise.

Older

Emdebian.org keeps some 2.95 vintage packages in case that's useful (people do still ask occaisionally!). Currently awaiting re-uploading.

Future cross-toolchain implementation (currently experimental)

Debian provided basic cross-toolchain support in the archive from November 2014 onwards. Previously this had only been available from external repositories.

These are generally built to run on fast architectures (amd64, ppc64el, arm64), and target all reasonably popular architectures (arm64, armel, armhf, powerpc, ppc64, i386, amd64, mips, mipsel, mips64el).

They will be automatically installed (by the magic of multiarch) if you enable the architecture you are building for, and install build-essential for a target architecture, or a package which directly depends on gcc-for-host.

!Note the BUILD architecture is the machine you are building _on_. the HOST architecture is the one you are building _for_

Installation concepts for experimental

To cross-build (or install cross toolchains) you will need to enable multiarch for the architecture you are building for (the HOST arch) (unless targetting an architecture that is not in Debian, in which case the cross-toolchain will be installable without any foreign-arch packages).

dpkg --add-architecture armhf
apt-get update

Use the debian architecture name to install toolchains (or cross-toolchains)

apt-get install -a<arch> build-essential

i.e

apt-get install -aarmhf build-essential

Note that the toolchains thus installed must be used as <triplet>-gcc, for both native _and_ cross usage. i.e. x86_64-linux-gnu-gcc for the native compiler on amd64, and arm-linux-gnueabihf-gcc for the cross-compiler targetting armhf.

Plain 'gcc' will (probably) not be installed.

Which packages are what?

  • The actual versioned cross-compiler is in gcc-4.9-arm-linux-gnueabihf
  • The package setting which version of the toolchain is currently the default is gcc-arm-linux-gnueabihf
  • The package which pulls in a specific version of the target arch cross-compiler is gcc-4.9-for-host:armhf
  • The package which pulls in the target arch cross-compiler is gcc-for-host:armhf
  • The package which pulls in the build (native) arch compiler is gcc-for-build

Packages which need a particular version of gcc should build-depend on gcc-4.9-for-host Packages which also need the build-arch gcc when cross-building, should build-depend on gcc-for-build (for the default version) or gcc-4.9-for-build (to get 4.9 specifically).

Similar packages exist for g++, cpp, gfortran, binutils and pkg-config.

Installing build-dependencies

apt-get build-dep -a <arch> <package>

e.g.

apt-get build-dep -a armhf util-linux

If the build-deps are not installable in this way (usually due to un-multiarched packages in the dependency tree), then use dpkg-checkbuilddeps and apt-get install to manually insert the right packages.

Information for package maintainers

In the pre-multiarch-crosscompiler world (jessie and earlier) a package could run 'gcc' and expect to get the compiler targetting the native arch and running on the native arch (e.g amd64,amd64). And it could build-depend on 'gcc-4.7' to get an older compiler installed. However There was no way to depend on a particular compiler version and have that version of the cross-compiler installed, so this scheme made any package needing a particular gcc version uncrossbuildable (without a lot of faffing).

In stretch build-essential implicitly depends on the compiler for the HOST architecture (which is the architecture you are building _for_) via 'gcc-for-host'. This is the default compiler, which must be run specifying the TARGET architecture (the one you want to build code for), i.e. as x86_64-linux-gnu-eabi-gcc. Don't call 'gcc' as it may not do the right thing, or work at all.

Packages that need a specific version of the compiler can now depend on 'gcc-<version>-for-host' and will get the <triplet>-gcc for the (HOST) architecture that the build is targetting.

See the multilib section for info on why it is recommended to always call the compiler as <triplet>-gcc

How does this _really_ work

Details of the gcc interface and metapackage design are in https://wiki.debian.org/Sprints/2014/BootstrapSprint/Results

Appropriate info needs extracting to here

Sources

In the archive things are arranged like this:

  • src:cross-binutils provides the binutils-<triplet> packages

  • src:gcc-cross-support provides the gcc-4.9-for-host and gcc-4.9-for-build packages

  • src:cross-gcc-defaults provides the gcc-arm-linux-gnueabihf and gcc-for-host default-version packages.

  • src:gcc-4.9 provides the native toolchain packages
  • src:cross-4.9-gcc-armhf provides the (version 4.9) cross-gcc (and cpp, g++, gfortran) compilers targetting armhf (arm-linux-gnueabihf)
  • src:cross-4.9-gcc-bootstrap-sparc provides (version 4.9) self-contained cross-gcc (and cpp, g++, gfortran) compilers targetting sparc (and other architectures which are not offical debian releases)
  • The various cross-gcc-<ver>-<arch> source packages are generated from a http://anonscm.debian.org/cgit/crosstoolchain/cross-gcc.git|git repo on alioth]]. This enables us to have one source per target arch so that arches can fail to build independently, but still meaning that there is only one core set of code to maintain.

The missing sources (cross-gcc-bootstrap, gcc-cross-support, cross-support) repos will be uploaded there shortly so that everything is in one place for maintenance.