Compiler API

Introduction

Here's the proposed compiler interface for the system and for people. FreeBSD will support compiling itself with different compilers, and may support having multiple compilers in the base system. FreeBSD will support using external compilers to build the base, even if they aren't in the base (eg, building FreeBSD with gcc 4.6 or with some chip vendor's special compiler).

User Interface

Users control which compiler is used based on a few variables.

Variable

Values

Meaning

SYSTEM_COMPILER

gcc or clang

The class of compiler that is installed as ${CC}

GCC_VERSION

421

gcc 4.2.1 -- The version of the gcc compiler being used

CLANG_VERSION

311

clang 3.1.1 -- The version of the clang compiler installed

EXT_COMP

armv6-freebsd- or /usr/local/fred/bin/

Used to specify the location of the compiler (but not what kind of compiler it actually is). If this is set, then the external compiler is used. Otherwise the bootstrap default system compiler is used. The external compiler is really the entire external toolchain.

Programmer Interface

Generally, the traditional names for the C compiler, etc are used for the defaults. The above variables would be used something like the following:

.if ${SYSTEM_COMPILER} == "gcc"
CFLAGS += -Wall
.endif
.if ${SYSTEM_COMPILER} == "clang"
CFLAGS += -Weverything
.endif
.if ${SYSTEM_COMPILER} == "gcc" && ${GCC_VERSION} < 421
CFLAGS += -Wno-turtle-graphics
.endif

Most of the yucky part of this will live in a file, bsd.compiler.mk, that will be used to keep things contained. Some individual makefiles might need tweaks, however, based on what they are compiling.

bsd.compiler.mk

This file will hold all the common code for supporting different compilers. It is somewhat similar to bsd.cpu.mk which is compiler support for optimizing for specific CPUs, but more general. It may be possible to use bsd.cpu.mk for this, or rename it to bsd.compiler.mk.

External Compiler support

For an external compiler to work, it needs to have the following binaries in its bin directory (optionally, it can install all its binaries with a unique prefix too, so where it says 'cc' 'as' etc below, you could have 'armv6-freebsd-cc' 'armv6-freebsd-as' etc.

Program

Purpose

ar

Archiver

as

Assembler

c++

C++ Compiler

cc

C Compiler

cpp

C preprocessor stage

ld

loader

nm

symbol name reporter

objcopy

copy binary sections around

ranlib

Library indexing program

size

Report the size of the different sections of the binary

strip

Remove symbols from the binary

The following are optional...

Program

Purpose

addr2line

Convert an address to a line number

CC

C++ Compiler -- historically present

c++filt

demangle C++ names. Not directly used in the FreeBSD build

g++

Gnu name for c++ compiler

gcpp

Gnu name for c preprossor

gcov

Coverage tool

gnu-ar

Gnu interface ar

gnu-ranlib

Gnu interface to ranlib the library indexing program

objdump

examine the contents of binaries

readelf

another binary manipulation program

strings

extract any printable strings from the binary

Proposed_Compiler_API (last edited 2012-04-23 04:28:09 by WarnerLosh)