FreeBSD stopped including modern versions of GCC and binutils in the base system; the project focused initially on bringing the excellent LLVM-based toolchain (especially, clang and lld), but there were also licensing motivations. However, being so recent, some platforms are not supported by LLVM and some users may wish to use a GNU toolchain even on platforms where there is support for LLVM. The purpose of this page is to document the steps required to facilitate the use of a modern GNU toolchain tracking both a "global" TODO list as well as a per-platform checklist of needed steps. One of the goals of this process is to deprecate and remove the old GCC 4.2.1 and binutils 2.17.50 in the base system.
Toolchain Packages
The external GNU toolchain consists of two packages: binutils and GCC. These packages are provided in two different ways.
External Toolchain
First a set of "external toolchain" packages are provided which can be used to cross-build (or natively build) a FreeBSD base system. These packages are built by the devel/binutils and devel/freebsd-gcc[69] ports. Each of these ports has a "flavor" for each supported architecture. These build packages named <arch>-binutils and <arch>-gcc[69]. The GCC package includes a suitable CROSS_TOOLCHAIN Makefile and depends on the appropriate binutils package. These packages install cross-build binaries under /usr/local and can be used like so:
# pkg install amd64-gcc6 # cd /path/to/src # make CROSS_TOOLCHAIN=amd64-gcc6 buildworld
Native Toolchain
The second set of packages are used to build a native toolchain for a given architecture that provides a system toolchain (e.g. /usr/bin/cc and /usr/bin/ld) via the base/binutils and base/gcc6 ports. These packages can either be built natively or as cross-built packages using CROSS_TOOLCHAIN and CROSS_SYSROOT. The steps to cross-build a native toolchain consist of:
- Install the appropriate external toolchain packages on a build host.
- Build a world using this external toolchain via CROSS_TOOLCHAIN.
- Install this world to a suitable location via DESTDIR. This installed location will then be used as the CROSS_SYSROOT when cross-building packages.
- Install native packages on the build host for build dependencies of binutils and gcc.
- Build the base/binutils and base/gcc6 packages using CROSS_TOOLCHAIN and CROSS_SYSROOT. In addition, you will want to cross-build pkg itself so that the packages be installed on a target host.
For example:
# pkg install mips-gcc6 # cd /usr/src # make CROSS_TOOLCHAIN=mips-gcc6 TARGET_ARCH=mips buildworld # mkdir /usr/mips/sysroot # make CROSS_TOOLCHAIN=mips-gcc6 TARGET_ARCH=mips installworld DESTDIR=/usr/mips/sysroot # pkg install math/gmp math/mpfr bison gmake gettext-tools # mkdir /usr/mips/packages # cd /usr/ports/ports-mgmt/pkg # make CROSS_TOOLCHAIN=mips-gcc6 CROSS_SYSROOT=/usr/mips/sysroot package # cp work/pkg/* /usr/mips/packages # cd ../../base/binutils # make CROSS_TOOLCHAIN=mips-gcc6 CROSS_SYSROOT=/usr/mips/sysroot package # cp work/pkg/* /usr/mips/packages # cd ../../base/gcc6 # make CROSS_TOOLCHAIN=mips-gcc6 CROSS_SYSROOT=/usr/mips/sysroot package # cp work/pkg/* /usr/mips/packages
This would result in /usr/mips/packages containing three packages: pkg, freebsd-binutils, and freebsd-gcc6. These can be used to seed an initial package repository (in case no packages are currently provided for this architecture) such that an installed target system can use 'pkg install freebsd-binutils' and 'pkg install freebsd-gcc6'.
(There is more information about which packages are currently being provided for which architecture.)
TODO List
This is a list of general MI todo items.
Name |
Status |
Owner |
Review |
Commits |
Comments |
Enable .init_array/.fini_array |
Committed |
Enable use of .init_array / .fini_array |
|||
Don't require CROSS_* for base/* |
Committed |
This would permit building packages in native package builds and on a target host directly without requiring a sysroot. |
|||
Add toolchain makefiles to base/binutils and base/gcc6 |
Committed |
|
|
||
Add 'make sysroot' related targets |
In testing |
|
|
This would build a subset of world closer to 'make toolchain' |
|
Add packages for GCC 9.x |
Committed |
|
|||
Replace crtstuff.c |
Committed |
|
|
||
Replace libssp |
Committed |
An implementation based on examining the symbols libssp and Linux Standards Base (LSB) 4.1 is straightforward. Also see SummerOfCode2015/FreeBSDLibcSecurityExtensions |
|||
Merge base/gcc and devel/powerc64-gcc |
Not started |
|
|
|
Probably not useful |
Use flavors for devel/*-binutils and devel/*-gcc? |
Committed |
|
|
||
Rebase RISC-V toolchain packages on "standard" packages |
Waiting for GCC upgrade |
Rebasing riscv64-gcc requires updating powerpc64-gcc to 7.2 or later |
|||
Teach poudriere about a world image requiring base/gcc |
Not started |
|
|
|
|
Support releases built by external GCC (xtoolchain for cross-build or base/gcc if native) |
Not started |
|
|
|
|
Remove ${OSREL} from binary names in devel/*-binutils and devel/*-gcc |
Not started |
|
|
|
This requires teaching GCC to pick a sensible "default" OS major version |
Remove binaries from base/* packages with tuple names |
Not started |
|
This confuses ports that depend on devel/binutils. |
Per-architecture Checklist
This table contains a set of steps required by each architecture to support an external GNU toolchain.
Legend
Optional |
Required for future |
Task |
aarch64 |
amd64 |
arm |
i386 |
mips |
mips64 |
powerpc |
powerpc64 |
powerpcspe |
riscv64 |
sparc64 |
devel/<arch>-xtoolchain-gcc port |
|
|
|
|
|
|
|
|
|
|
|
devel/freebsd-gcc6 flavor |
|
|
|
|
|
|
|
|
|
|
|
devel/freebsd-gcc9 flavor |
|
|
|
|
|
|
|
|
|
|
|
Boot a system built with xtoolchain |
|
|
|
|
|
|
|
|
|
|
|
Build with xtoolchain in CI |
|
|
|
|
|
|
|
N/A |
|||
Use LLVM's libunwind (1) |
|
|
|
|
|
|
|
|
|
|
|
Build base/* in CI |
|
|
|
|
|
|
|
|
|
|
|
base/binutils build and pkg-plist |
|
|
|
|
|
|
|
|
|
|
|
base/gcc6 build and pkg-plist |
|
|
|
|
|
|
|
|
|
|
|
Self-hosted system build using base/* |
|
|
|
|
|
|
|
|
|
|
|
Boot self-hosted system build |
|
|
|
|
|
|
|
|
|
|
|
Run kyua tests on self-hosted system |
|
|
|
|
|
|
|
|
|
|
|
kyua tests have same or less failures |
|
|
|
|
|
|
|
|
|
|
|
Publish base/* packages |
|
|
|
|
|
|
|
|
|
|
|
Use external GCC as default compiler |
N/A |
N/A |
N/A |
N/A |
|
|
N/A |
N/A |
N/A |
N/A |
|
Publish releases using external GCC |
N/A |
N/A |
N/A |
N/A |
|
|
N/A |
N/A |
N/A |
N/A |
|
(1) This is not required for external toolchain but is required for removing src/contrib/gcc.
Task
aarch64
amd64
arm
i386
mips
mips64
powerpc
powerpc64
powerpcspe
riscv64
sparc64