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:

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

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/gcc6

Committed

JohnBaldwin

521870 356289

Add 'make sysroot' related targets

In testing

AlexRichardson

This would build a subset of world closer to 'make toolchain'

Add packages for GCC 9.x

Committed

JohnBaldwin

D22863

520398

Replace crtstuff.c

Committed

AndrewTurner

339738 340213 340841

Replace libssp

Committed

KyleEvans

D22943

356356 356358

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

BaptisteDaroussin, JohnBaldwin

517642 517976

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

JohnBaldwin

518973

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

(./)

(./)

(./)

(./)

(./)

(./)

D16351

(./)

(./)

devel/freebsd-gcc6 flavor

(./)

(./)

(./)

(./)

(./)

(./)

(./)

devel/freebsd-gcc9 flavor

(./)

(./)

(./)

(./)

(./)

(./)

(./)

(./)

(./)

Boot a system built with xtoolchain

(./)

(./)

(./)

(./)

(./)

Build with xtoolchain in CI

(./) gcc6

(./) gcc6

(./) gcc6

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.

See Also

ExternalToolchain


CategoryHowTo

ExternalGCC (last edited 2020-04-10T10:07:36+0000 by LiWenHsu)