Using newer version of GCC and binutils with the FreeBSD Ports Collection

Martin Matuska

Revision: 44683

FreeBSD is a registered trademark of the FreeBSD Foundation.

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this document, and the FreeBSD Project was aware of the trademark claim, the designations have been followed by the or the ® symbol.

Last modified on 2014-04-28 by wblock.

This article describes how to use newer versions of the GCC compilers and binutils from the FreeBSD ports tree. Custom GCC configurations are also discussed.

[ Split HTML / Single HTML ]

Table of Contents
1. Introduction
2. Prerequisites
3. Configuring ports for custom version of GCC
4. Impact on the binary performance

1. Introduction

The default system compiler as of FreeBSD 8.0 is GCC version 4.2.1. In addition, the base system of FreeBSD includes binutils version 2.15. These versions are several years old and lack, among other things, support for recent CPU instructions like SSSE3, SSE4.1, SSE4.2, etc. Due to licensing issues, new versions of these applications will not be integrated into the base system. Luckily, it is possible to use a newer version of the GCC compiler (e.g. version 4.4) with the help of the FreeBSD ports tree.

2. Prerequisites

2.1. Installing binutils from ports

To make use of all of the new features in the latest GCC versions, the latest version of binutils needs to be installed. Installation of the newer version of binutils is optional; but without it, there will be no support for new CPU instructions.

To install the latest available version of binutils using the FreeBSD ports tree, issue the following command:

# cd /usr/ports/devel/binutils && make install

2.2. Installing GCC from ports

The FreeBSD ports tree offers several new versions of GCC. The following example is for the stable version 4.4. However, it is possible to install previous or later development versions (e.g. lang/gcc43 or lang/gcc45).

To install one of the mentioned GCC ports, run the following command:

# cd /usr/ports/lang/gcc44 && make install

3. Configuring ports for custom version of GCC

Additional system configuration is required in order to use custom version of GCC installed from the FreeBSD ports tree.

3.1. Adjusting make.conf

Add the following lines to the /etc/make.conf file (or modify appropriately):

.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc44)

Alternatively, it is possible to specify the ${CC} and ${CPP} variables manually.


The examples above are for GCC version 4.4. To use gcc43, replace "gcc44" with "gcc43" and "4.4" with "4.3" and so on.

3.2. Adjusting libmap.conf

Many of the ports' binaries and libraries link to libgcc_s or libstdc++. The base system already includes these libraries, but from an earlier version of GCC (version 4.2.1). To supply rtld (and ldd) with correct versions, add the following lines to the /etc/libmap.conf file (or modify appropriately):   gcc44/    gcc44/    gcc44/     gcc44/  gcc44/


The examples above are for GCC version 4.4. To use gcc43, replace "gcc44" with "gcc43" and so on. Note also that all of these libraries are fully backwards compatible with base system libraries.


Some C++ programs may refuse to work if these libraries are not mapped correctly. If it is not feasible to map them all, it is recommended to map at least

3.3. Custom CFLAGS for the ports tree

To add custom CFLAGS for the ports tree which are unsupported by the base system, adjust the /etc/make.conf according to the following example:

.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc44)

It is possible to completely replace CFLAGS and/or define custom CPUTYPE as well. We recommend setting CPUTYPE because many ports decide their optimizations flags based on this variable.

3.4. Excluding ports that do not build with new version of GCC

To exclude ports that have problems with custom version of GCC, adjust the /etc/make.conf according to the following example:

.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc44)
.if empty(.CURDIR:M/usr/ports/net/openldap*)

The example above excludes the forced use of gcc 4.4 for the net/openldap* ports. It is also possible to specify more ports on a single line:

.if empty(.CURDIR:M/usr/ports/net/openldap*) && empty(.CURDIR:M/usr/ports/xxx/yyy) && ...

4. Impact on the binary performance

Using GCC version 4.4 with SSSE3 instruction set enabled (if supported by the CPU) may yield up to 10% average increase in binary performance. In certain tests, the results show more than a 20% performance boost (e.g. in multimedia processing).

The table located at shows a comparison of GCC versions currently available in base FreeBSD system, GCC version 4.3 and GCC version 4.4 with various combinations of CFLAGS using the perlbench benchmark suite.