This is an old revision of the document!


Modern versions of GCC and binutils are not contained in the FreeBSD base system for licensing reasons. However, some platforms are not supported by the LLVM-based toolchain (especially, clang and lld). In addition, some users may wish to use a GNU toolchain even on platforms supported by 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 version of GCC and binutils in the base system.

The external GNU toolchain consists of two packages: binutils and GCC. These packages are provided in two different ways.

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/<arch>-binutils and devel/<arch>-gcc ports. In addition, a devel/<arch>-xtoolchain-gcc port builds a package that includes a suitable CROSS_TOOLCHAIN Makefile and depends on the binutils and GCC packages. These packages install cross-build binaries under /usr/local and can be used like so:

# pkg install amd64-xtoolchain-gcc
# cd /path/to/src
# make CROSS_TOOLCHAIN=amd64-gcc buildworld

Almost all the devel/<arch>-binutils ports are all slave ports of devel/binutils. The “main” external GCC port is the devel/powerpc64-gcc port and almost all of the other devel/<arch>-gcc ports are slaves of that port.

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/gcc ports. Currently, these packages must be built as cross-built packages using CROSS_TOOLCHAIN and CROSS_SYSROOT. Thus, the steps to build a native toolchain consist of:

  • Install the appropriate external toolchain packages on a build host (e.g. amd64-xtoolchain-gcc).
  • 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/gcc 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-xtoolchain-gcc
# cd /usr/src
# make CROSS_TOOLCHAIN=mips-gcc TARGET_ARCH=mips buildworld
# mkdir /usr/mips/sysroot
# make CROSS_TOOLCHAIN=mips-gcc 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-gcc CROSS_SYSROOT=/usr/mips/sysroot package
# cp work/pkg/* /usr/mips/packages
# cd ../../base/binutils
# make CROSS_TOOLCHAIN=mips-gcc CROSS_SYSROOT=/usr/mips/sysroot package
# cp work/pkg/* /usr/mips/packages
# cd ../../base/gcc
# make CROSS_TOOLCHAIN=mips-gcc 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-gcc. 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-gcc'.

(There is more information about which packages are currently being provided for which architecture.)

This is a list of general MI todo items.

Name Status Owner Review Commits Comments
Enable .init_array/.fini_array Committed JohnBaldwin D16014 474469 Enable use of .init_array / .fini_array
Don't require CROSS_* for base/* Committed JohnBaldwin D19128 D19129 493400 493401 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/gcc In review JohnBaldwin D19482 D19720 I have built and installed a world using them. This removes the need for an explicit CROSS_TOOLCHAIN.
Add 'make sysroot' related targets In testing AlexRichardson This would build a subset of world closer to 'make toolchain'
Upgrade GCC from 6.4.0 to 8.x Inactive Bdragon28 Had a go at updating plists / porting patches for 8.2 in my local tree, ran with it as my main compiler on powerpc64/elfv2 for several months. See here for a starting point if anyone else wants to pick this back up. Got sidetracked with getting set up for arm*/mips/sparc64 testing and didn't finish those dependencies. – – Bdragon28 2019-05-20 18:45:37 UTC
Replace crtstuff.c Committed AndrewTurner 339738 340213 340841
Replace libssp Not started Apple publishes these in their libc under an APSL license. NetBSD has a rough implementation that doesn't work on clang. Bionic libc has BSD licensed versions that are a bit less usable (mixed C, C++, some odd conventions). An implementation based on examining the symbols libssp and Linux Standards Base (LSB) 4.1 also looks straightforward. Also see FreeBSDLibcSecurityExtensions
Merge base/gcc and devel/powerc64-gcc Not started
Use flavors for devel/*-binutils and devel/*-gcc? Not started
Rebase RISC-V toolchain packages on “standard” packages Waiting for GCC upgrade JohnBaldwin D16503 473489 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.

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
Task aarch64 amd64 arm i386 mips mips64 powerpc powerpc64 powerpcspe riscv64 sparc64
devel/<arch>-xtoolchain-gcc port ✔ ✔ ✔ ✔ ✔ ✔ D16351 ✔ ✔
Boot a system built with xtoolchain ✔ ✔ ✔
Build with xtoolchain in Jenkins/CI ✔ ✔
Use LLVM's libunwind (1) ✔ ✔ ✔ ✔ ✔ ✔
Build base/* in Jenkins/CI
base/binutils build and pkg-plist ✔ ✔ ✔ ✔ ✔
base/gcc 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
Publish releases using external GCC N/A N/A N/A N/A

(1) This is not required for external toolchain but is required for removing src/contrib/gcc.

  • externalgcc.1558377937.txt.gz
  • Last modified: 2019/05/20 18:45
  • by Bdragon28