2.1 How config.gcc picks your part of a GCC checkout
GCC 15.2.0. To run the commands: a GCC checkout, and an arm-none-eabi-gcc cross compiler.
You clone GCC to read the backend of your x86-64 compiler, and there is no
gcc/config/x86_64/. You look for the rule that builds __aeabi_uldivmod for
your arm-none-eabi toolchain, and gcc/config/arm/t-bpabi is one line about a
header. The checkout has 38 top-level directories, 1,051 files directly in
gcc/ and 52 directories in gcc/config/, and most of them do not apply to the
compiler you build (top level, gcc/,
gcc/config/).
One shell script, gcc/config.gcc, turns --target= into the list of backend
files, headers, macros and makefile fragments that your compiler is built from.
The tree is arranged so that this script, and its twin libgcc/config.host, can
make that choice. Read with the two scripts in mind, the layout is not
arbitrary.
This chapter assumes Chapter 1.2, for build, host
and target, and for the split between host code and target code, and
Chapter 1.3, for the spec language. It also uses -### and
-v from Chapter 1.1, the multilib fragments of
Chapter 1.6, and the Configured with: line that
Chapter 1.14 reads.
Makefile.def: the top level is a list of modules
The top level of a GCC checkout builds modules, and Makefile.def is the list
of them. The top level is shared with other projects, so the list names many
modules that a GCC checkout does not contain, and the top-level configure
keeps only those whose directory is present. That presence test decides which
top-level directories matter for your build, and which ones you can add.
The internals manual says that the top-level directory "contains several files
and directories that are shared with other software distributions such as that
of GNU Binutils" (sourcebuild.texi:23-26). The more than
forty modules in Makefile.def that a GCC checkout does not contain include
bfd, gas, ld, gdb, gmp and mpfr as host modules, and newlib,
libgloss and winsup as target modules (Makefile.def:36,
:48, :97, :182,
:200-201). libgloss is newlib's companion library of
board-specific startup code and input/output support, which
Chapter 3.4 describes. The loop in the
top-level configure that drops the absent ones tests each directory for a
configure script:
# Quietly strip out all directories which aren't configurable in this tree.
# This relies on all configurable subdirectories being autoconfiscated, which
# is now the case.
...
configdirs_all="$configdirs"
configdirs=
for i in ${configdirs_all} ; do
if test -f ${srcdir}/$i/configure ; then
configdirs="${configdirs} $i"
fi
done
Listing 2.1-1: modules that are not in the tree disappear, abridged
(configure.ac:2755-2773). The same check runs for build and
target modules.
The directory names are the module names, so you add a module to the build by
adding its directory. The install manual relies on this when it tells you to put
bfd, gas and ld, or gmp, mpfr and mpc, next to gcc/ and build them
together, under Downloading GCC (install.texi:698-713). A
checkout with other projects' directories added beside gcc/ is a combined
tree, and Chapter 3.6 uses one to build newlib
inside a GCC build.
Each module in Makefile.def has a kind: build, host or target. Sorted by that
kind, the directories that a GCC checkout does contain, apart from .github and
.forgejo, fall into five groups:
Kind in Makefile.def | Directories in GCC 15.2.0 |
|---|---|
| host | gcc, c++tools, gnattools, gotools, libcc1, libcody, libdecnumber, lto-plugin |
| build and host | fixincludes, libcpp, libiberty |
| host and target | libbacktrace, libgrust, zlib |
| target | libgcc, libstdc++-v3, libatomic, libgomp, libitm, libquadmath, libsanitizer, libssp, libvtv, libada, libgfortran, libgo, libgm2, libgcobol, libobjc, libphobos, libffi |
| none | config, contrib, include, INSTALL, maintainer-scripts |
Sources: the build_modules, host_modules and target_modules entries of
Makefile.def:27-212.
A directory with two kinds is built once for each. zlib, for example, is a
host module that the compiler uses for LTO data
(sourcebuild.texi:152-154, Makefile.def:141)
and also a target module (:204). The last row holds the
shared Autoconf macros and makefile fragments (config/), the libiberty
headers (include/), and scripts. Chapter 2.3
shows the order in which make builds the modules.
The set of directories also changes between releases. Three top-level directories appeared or went between GCC 12 and GCC 15, so a search in a tree of another release can find nothing:
-
GCC 14 removed
intl/. Commitfbe4e643("intl: remove, in favor of out-of-tree gettext") deleted it. It is present atreleases/gcc-13.3.0. -
GCC 13 added
libgm2/. It is absent atreleases/gcc-12.1.0, and present atreleases/gcc-13.1.0with the Modula-2 front end ingcc/m2/. -
GCC 15 added
libgcobol/. It and the COBOL front end ingcc/cobol/are absent atreleases/gcc-14.3.0and present atreleases/gcc-15.1.0.
Why libgcc/ is not inside gcc/: target_subdir
libgcc/ sits beside gcc/, and not inside it, because the two are built for
different machines by different compilers. gcc is a host module and libgcc
is a target module (Makefile.def:49, :183), and
a module's kind decides where it is built and which compiler builds it. A comment
in the shared Autoconf macros gives the rule, one build subdirectory per machine,
with target_subdir for the target modules:
dnl # GCC & friends build 'build', 'host', and 'target' tools. These must
dnl # be separated into three well-known subdirectories of the build directory:
dnl # build_subdir, host_subdir, and target_subdir. The values are determined
dnl # here so that they can (theoretically) be changed in the future. They
dnl # were previously reproduced across many different files.
...
build_subdir="build-${build_noncanonical}"
...
target_subdir=${target_noncanonical}
Listing 2.1-2: one build subdirectory per machine, abridged
(config/acx.m4:66-101).
For an arm-none-eabi cross built on x86-64 Linux, libgcc is therefore
configured and built in arm-none-eabi/libgcc/ under the build directory, the
directory where you run the top-level configure. When the build and host
machines are the same and gcc/ is in the tree, the compiler that builds
libgcc is the one that the gcc module built before it. The top-level
configure sets CC_FOR_TARGET to gcc/xgcc -B$$r/$(HOST_SUBDIR)/gcc/
(configure.ac:4059), and it reports that choice before
anything is built:
$ ../gcc/configure --target=arm-none-eabi 2>&1 | grep 'where to find the target cc'
The line reports that compiler as "just compiled"
(config/acx.m4:562-577). For a Canadian cross the macro
takes a compiler that is already installed instead.
gcc/ is configured once, for the host, and compiled by the host's compiler.
libgcc must be configured for the target and compiled by a compiler that does
not exist until gcc/ is built. A directory inside gcc/ cannot have both
properties. Every other target library in the module table has the same
constraint, so every one is a top-level directory.
The internals manual still lists crtstuff.c and unwind-dw2.c as files
"under the gcc directory" that belong to runtime libraries
(sourcebuild.texi:316-320). In GCC 15.2.0 they are in
libgcc/, and gcc/ has neither (libgcc/crtstuff.c,
libgcc/unwind-dw2.c).
The split still leaves libgcc reading files from the gcc build directory,
such as libgcc.mvars. Its makefile names that directory gcc_objdir
(libgcc/Makefile.in:25, :184). Like the other
target modules, libgcc is configured only after the gcc module is built
(Makefile.in:67908), and
Chapter 2.3 shows where that dependency comes
from.
Inside gcc/: config-lang.in, c-family/ and common/
gcc/ holds the compiler: the driver, the front ends, the middle end and the
backends. Only some of these have a subdirectory, so the layout tells you where
to start a search. The subdirectories fall into three groups: front ends, which
a config-lang.in file marks, code that several programs share, in c-family/
and common/, and everything else.
gcc/ has 24 subdirectories and 1,051 files of its own (tree). The
middle end and the target-independent half of the back end are among the files,
not in a subdirectory. gimplify.cc, passes.cc, cfgexpand.cc, ira.cc and
final.cc sit directly in gcc/, beside the driver's gcc.cc, and Part V
walks through them.
Front ends. A subdirectory of gcc/ is a front end if it contains
config-lang.in. gcc/configure finds them with one glob,
for lang in ${srcdir}/*/config-lang.in
(gcc/configure.ac:7287), sources each file
(:7337), and adds its Make-lang.in to the makefile
(:7358-7363). In GCC 15.2.0, 13 directories qualify: ada, c,
cobol, cp, d, fortran, go, jit, lto, m2, objc, objcp and
rust. Chapter 2.2 covers how
--enable-languages selects among them.
Shared code. c-family/ holds the parts of the C, C++ and Objective-C
front ends that are the same. The makefile calls them "object files
shared by all C-family front ends" (gcc/Makefile.in:1313-1314),
and both cc1 and cc1plus link them (c/Make-lang.in:53-56,
cp/Make-lang.in:93-94). common/ holds code that the driver and the
compilers share. A target that needs a hook in both places puts it in
common/config/<cpu>/ (sourcebuild.texi:201-205), so the ARM
version is gcc/common/config/arm/arm-common.cc, not a file in
gcc/config/arm/.
Everything else. config/ holds the backends. doc/ holds the Texinfo
manuals, ginclude/ the freestanding headers that GCC installs, po/ the
message catalogues, and testsuite/ the compiler's tests
(sourcebuild.texi:207-235). The objects of analyzer/,
rtl-ssa/ and sym-exec/ are part of OBJS, the compiler's own object list
(gcc/Makefile.in:1382-1848). text-art/ goes into libcommon.a,
which is "potentially used by all host binaries"
(:1850-1878).
gcc/config/: one directory per CPU type
gcc/config/ has one subdirectory for each CPU type, and the operating-system
headers that several CPUs share sit at its top level. A triple picks one CPU
directory and some of those shared headers, so this layout is what config.gcc
chooses from. The README in the directory states the rule in five lines:
This directory contains machine-specific files for the GNU C compiler.
It has a subdirectory for each basic CPU type.
The only files in this directory itself
are some .h files that pertain to particular operating systems
and are used for more than one CPU type.
Listing 2.1-3: the layout of gcc/config/ (gcc/config/README:1-5).
The rule holds for 49 of the 52 directories. mingw/, vms/ and vxworks/
are operating-system directories, and the top level of gcc/config/ now has
.cc, .opt and t-* files as well as headers (tree). The
headers there form the operating-system layer, such as elfos.h, linux.h,
newlib-stdint.h and rtems.h.
The directory is named after the CPU type, which is not always the first field
of the triple. That is why there is no gcc/config/x86_64/: x86_64-*-* uses
i386/ (config.gcc:413-414), powerpc*-*-* uses rs6000/
(:524-525), and amdgcn* uses gcn/ (:361-362).
Inside one CPU directory, the file names follow a convention that config.gcc
and gcc/configure rely on. If a file with the expected name exists, it is used
unless the target says otherwise. The table gives the expected names for ARM,
the variable that each one fills, and where its default is set:
File in gcc/config/arm/ | Variable | Where the default comes from |
|---|---|---|
arm.h | tm_file | config.gcc:602 |
arm-protos.h | tm_p_file | config.gcc:603-606, if the file exists |
arm.cc | out_file | gcc/configure.ac:1946-1947 |
arm.md | md_file | gcc/configure.ac:1943-1944 |
arm.opt | extra_options | config.gcc:629-632, if the file exists |
arm-modes.def | extra_modes | config.gcc:624-628, if the file exists |
arm-d.h | tm_d_file | config.gcc:608-612, if the file exists |
t-arm | tmake_file | gcc/configure.ac:1949-1951, unless the target sets it |
The other 131 files in the directory are named explicitly somewhere: headers in
the target's entry, extra .md files in t-arm, built-in tables and scheduling
models (tree).
Before GCC 12. The
out_filedefault was$cpu_type/$cpu_type.c, as atreleases/gcc-11.1.0(gcc/configure.ac:1783). Commit5c69acb3("Rename .c files to .cc files.") renamed the sources, and atreleases/gcc-12.1.0the default is$cpu_type/$cpu_type.cc(gcc/configure.ac:1852). The comment at the top ofconfig.gccstill says.c(config.gcc:96-97).
config.gcc: a shell script that configure sources
config.gcc is a shell fragment that gcc/configure sources, so it runs in
configure's own shell, with configure's variables in scope. It is not a configure
test and not a makefile, and gcc/configure later substitutes the variables it
sets, such as tmake_file and tm_defines, into gcc/Makefile. Listing 2.1-4
shows where it is sourced, after one file for each of the other two machines:
# --------------------------------------------------------
# Build, host, and target specific configuration fragments
# --------------------------------------------------------
# Collect build-machine-specific information.
. ${srcdir}/config.build || exit 1
# Collect host-machine-specific information.
. ${srcdir}/config.host || exit 1
target_gtfiles=
# Collect target-machine-specific information.
. ${srcdir}/config.gcc || exit 1
Listing 2.1-4: the three machine files (gcc/configure.ac:1918-1931).
The three files match the three machines, and the internals manual says that
config.gcc "is usually needed" while the other two are "rarely needed"
(sourcebuild.texi:285-293). The file's own header says why
it is a separate file: "Putting it in a separate shell file lets us skip running
autoconf when modifying target-specific information"
(config.gcc:21-25). The same header lists every variable that the
file reads and sets, with a description of each, and that list is the closest
thing to a specification the file has (config.gcc:30-212).
The 6,162 lines of config.gcc run in seven steps, in a fixed order, and each
step can override the ones before it. The arm-none-eabi example refers to the
steps by number:
- The CPU type is the first field of the triple, cut with
sed 's/-.*$//'(config.gcc:339). - A
caseon the triple sets the CPU type where it differs, and the per-CPU variables: objects, installed headers, extra.optfiles (:341-600). - The file-name defaults from the table above (
:602-632). - A
casefor operating-system families such as*-*-linux*and*-*-elf(:725-1175). - The large
casewith one entry per supported triple pattern (:1188-3645). - A
casethat validates--with-cpu,--with-arch,--with-floatand the others for each target (:4247-5867). - A loop that turns the accepted
--with-*values intoconfigure_default_options(:6116-6144).
Following arm-none-eabi through config.gcc
Following --target=arm-none-eabi through the seven steps of config.gcc shows
how one triple becomes four decisions: the headers, the makefile fragments, the
macros and the default CPU. Every target goes through the same steps, so the
example is also a guide to reading the entry for your own triple.
Step 1 gives cpu_type=arm. Step 2 matches arm*-*-* and adds the ARM objects,
arm_neon.h and its siblings as installed headers, and arm-c.o for the C and
C++ compilers (config.gcc:375-385). Step 3 sets tm_file=arm/arm.h
and finds arm/arm-protos.h. Step 4 matches nothing, because no
operating-system entry matches eabi. Step 5 decides the triple, in the entry
of Listing 2.1-5, where the lines to watch are the tm_file and tmake_file
assignments and target_cpu_cname:
arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems* | arm*-*-fuchsia*)
case ${target} in
arm*eb-*-eabi*)
tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
esac
default_use_cxa_atexit=yes
tm_file="elfos.h arm/unknown-elf.h arm/elf.h arm/bpabi.h"
tmake_file="${tmake_file} arm/t-arm arm/t-arm-elf"
target_cpu_cname="arm7tdmi"
case ${target} in
arm*-*-eabi*)
tm_file="$tm_file newlib-stdint.h"
tmake_file="${tmake_file} arm/t-bpabi"
use_gcc_stdint=wrap
;;
...
esac
tm_file="${tm_file} arm/aout.h arm/arm.h"
;;
Listing 2.1-5: the arm-none-eabi entry, abridged
(gcc/config.gcc:1497-1530). The omitted branches are for Fuchsia,
RTEMS and Symbian.
The headers. The entry replaces tm_file instead of adding to it. The
result layers three sources: the object-file format (elfos.h, from the top of
gcc/config/), the ARM ELF and EABI headers, and the C library's integer types
(newlib-stdint.h). arm/arm.h goes last. A later step puts vxworks-dummy.h
in front of every ARM, x86, MIPS, PowerPC, SH and SPARC target
(config.gcc:5883-5888). So the list that leaves config.gcc
is:
vxworks-dummy.h elfos.h arm/unknown-elf.h arm/elf.h arm/bpabi.h newlib-stdint.h arm/aout.h arm/arm.h
gcc/configure then appends defaults.h, and initfini-array.h or
tm-dwarf2.h when other options ask for them
(gcc/configure.ac:1953-1960, :2209). The
list becomes the generated tm.h. Chapter 2.4
shows that file.
The makefile fragments. tmake_file collects arm/t-arm, arm/t-arm-elf
and arm/t-bpabi. Configure keeps only the names that exist as files under
gcc/config/ (gcc/configure.ac:2406-2414). A
--with-multilib-list=aprofile or rmprofile adds arm/t-multilib
(config.gcc:4488-4539). The install manual documents the two
values under Configuration: they build multilibs for the A
profile and for the R and M profiles. Chapter 1.6
shows what that fragment's variables do.
The macros. tm_defines holds "target macros to define for all
compilations" (config.gcc:70). Each one becomes a #define
in the generated tm.h (gcc/mkconfig.sh:57-62). For
arm-none-eabi the list holds only the entries that all targets get: the C
library codes LIBC_GLIBC=1 to LIBC_MUSL=4 (config.gcc:697)
and HEAP_TRAMPOLINES_INIT=0 (:1177-1186). The big-endian
triple armeb-none-eabi adds TARGET_BIG_ENDIAN_DEFAULT=1, in the first lines
of Listing 2.1-5. In config.gcc, that one macro is the whole difference between
the two triples.
The default CPU. The entry sets target_cpu_cname="arm7tdmi", and step 6
accepts eight --with-* options for ARM (config.gcc:4402).
The install manual documents all eight under Configuration, and
says that the --with-cpu= value "will be used as the default value of the
-mcpu= switch". Step 6 ends with with_cpu=${with_cpu:-$target_cpu_cname}
(:4541), so if you did not pass --with-cpu, with_cpu is
now arm7tdmi.
The loop in step 7 records the value in configure_default_options, which
gcc/configure writes into the generated configargs.h
(gcc/configure.ac:2242-2250). The backend's arm.h turns it
back into a driver option, in its OPTION_DEFAULT_SPECS:
{"cpu", "%{!march=*|march=unset:"\
"%{!mcpu=*|mcpu=unset:%<march=* %<mcpu=* -mcpu=%(VALUE)}}" }, \
Listing 2.1-6: the cpu entry of OPTION_DEFAULT_SPECS
(gcc/config/arm/arm.h:400-401).
The driver expands these entries at start-up, with %(VALUE) replaced by the
configured value (gcc/gcc.cc:8519-8523,
:5874-5920). In the spec language of
Chapter 1.3, the entry says: if the command line has no
-march= and no -mcpu=, add -mcpu=arm7tdmi. cc1_options passes every -m
switch to the compiler (gcc.cc:1288). So an arm-none-eabi toolchain
configured with neither --with-cpu nor --with-arch compiles for ARM7TDMI
unless you say otherwise, and one line in Listing 2.1-5 made that choice.
The same value also reaches cc1 by a second path. config.gcc copies it into
target_cpu_default (config.gcc:5900-5908,
:6146-6154), the generated tm.h defines it as
TARGET_CPU_DEFAULT (gcc/mkconfig.sh:51-54), and arm.cc
uses it "If the user did not specify a processor or architecture"
(gcc/config/arm/arm.cc:3424-3434). That path matters only
when you run cc1 without the driver.
gcc/Makefile: where config.gcc's choices become paths
The variables that config.gcc sets end in gcc/Makefile, where
gcc/configure substitutes each one, most of them as paths into the source
tree. From there they are the build's input, and you can read them back before
anything is compiled. Listing 2.1-7 shows the substitutions and the line that
includes the target's t-* fragments:
tmake_file=@tmake_file@
...
out_file=$(srcdir)/config/@out_file@
out_object_file=@out_object_file@
common_out_file=$(srcdir)/common/config/@common_out_file@
...
md_file=$(srcdir)/common.md $(srcdir)/config/@md_file@
tm_file_list=@tm_file_list@
...
tm_defines=@tm_defines@
...
# target overrides
-include $(tmake_file)
Listing 2.1-7: the target's files in gcc/Makefile.in, abridged
(gcc/Makefile.in:599-611, :2004-2005).
out_file is the backend's .cc file, and md_file is the backend's machine
description after the target-independent common.md. common_out_file is the
target's file under gcc/common/config/, where a hook that the driver and the
compilers share lives. The t-* fragments are included into the makefile
itself, after the front ends' fragments, so a target can change any variable
that gcc/Makefile.in defines.
To read the choice back, run the top-level configure in a build directory,
then configure only the gcc module with the configure-gcc target of the
generated top-level makefile (Makefile.in:12099). Grep its
output and its makefile:
$ make configure-gcc 2>&1 | grep -A10 '^Using'
$ grep -E '^(out_file|md_file|tmake_file|tm_file_list|tm_defines)=' gcc/Makefile
The first command shows the lines that gcc/configure prints about its choice:
Using `<srcdir>/config/arm/arm.cc' for machine-specific logic., the same
line for arm.md, and the target macro files one per line
(gcc/configure.ac:1963-1964, :2000-2007). The
second shows the values substituted into the variables of Listing 2.1-7.
libgcc/config.host: a second selection, for libgcc
libgcc/config.host selects for libgcc what config.gcc selects for the
compiler, from a separate libgcc/config/ tree. The run-time functions that a
target program links come from this side, so a search for the rule that builds
__aeabi_uldivmod starts here, not in gcc/config/arm/.
config.gcc's header asks you to keep the two files in step: "When you change
the cases in the OS or target switches, consider updating ../libgcc/config.host
also" (config.gcc:27-28). The header of config.host explains
why its case reads a different variable:
This file bears an obvious resemblance to gcc/config.gcc. The cases should be kept similar, to ease moving library-specific settings from config.gcc to this file. That is also why tmake_file is left as tmake_file, rather than hmake_file, even though this library switches on ${host}.
libgcc switches on ${host} because it is configured as a target module: for
the library, the host is the machine it runs on, and that machine is your
target. libgcc/configure.ac calls AC_CANONICAL_HOST and sources
config.host (libgcc/configure.ac:156, :471).
The arm*-*-eabi* entry of config.host adds crtbegin.o, crtend.o,
crti.o and crtn.o, the soft-float fragments and the ARM unwinder header
(libgcc/config.host:578-595).
Both files name a fragment called arm/t-bpabi, and they are not the same file.
gcc/configure looks for it under gcc/config/, and libgcc/configure under
libgcc/config/ (libgcc/configure.ac:685-694). The
compiler's copy, the one a search in gcc/config/arm/ finds, is one line:
EXTRA_HEADERS += $(srcdir)/ginclude/unwind-arm-common.h
Listing 2.1-8: the whole of gcc/config/arm/t-bpabi (gcc/config/arm/t-bpabi:1).
The library's copy is where the EABI run-time functions come from. Its second
line is the rule for __aeabi_uldivmod, with the other functions that
bpabi.S provides:
# Add the bpabi.S functions.
LIB1ASMFUNCS += _aeabi_lcmp _aeabi_ulcmp _aeabi_ldivmod _aeabi_uldivmod
# Add the BPABI C functions.
LIB2ADD += $(srcdir)/config/arm/bpabi.c \
$(srcdir)/config/arm/unaligned-funcs.c
LIB2ADD_ST += $(srcdir)/config/arm/fp16.c
LIB2ADDEH = $(srcdir)/config/arm/unwind-arm.c \
$(srcdir)/config/arm/libunwind.S \
$(srcdir)/config/arm/pr-support.c $(srcdir)/unwind-c.c
Listing 2.1-9: the start of libgcc/config/arm/t-bpabi
(libgcc/config/arm/t-bpabi:1-12).
When a target-specific question is about code that runs on the target, start in
libgcc/config/<cpu>/. When it is about how the compiler behaves, start in
gcc/config/<cpu>/. Chapter 4.1 explains
what goes into libgcc.
Checking the target selection with -### and gcc -v
An installed arm-none-eabi-gcc shows two results of config.gcc with no build
tree: the default CPU, on the cc1 line that -### prints, and the configure
arguments, which gcc -v prints. The GCC manual documents both options under
Overall Options: -v prints the commands that the driver runs,
and -### prints them without running them. With any C file as foo.c, the
default CPU appears on the cc1 line:
$ arm-none-eabi-gcc -### -c foo.c 2>&1 | grep -o -- '-mcpu=[^ ]*'
On a toolchain configured with neither --with-cpu nor --with-arch, Listing
2.1-6 makes this print -mcpu=arm7tdmi. If you pass -mcpu= or -march=
yourself, the default does not apply, and the command prints only your own
option.
gcc -v reads back what configure recorded. It prints the target and the
configure line, from the print_configuration function
(gcc/gcc.cc:7709-7710):
$ arm-none-eabi-gcc -v
The Configured with: line records the top-level configure's arguments as
typed. gcc/configure writes them into the same generated configargs.h as the
default CPU (gcc/configure.ac:2244), and
Chapter 1.14 reads that line for the flags
it records.
The Target: line is not the ${target} that config.gcc switches on
(config.gcc:30). Chapter 2.2
explains the two names, and why neither line shows the canonical triple.
Three things to carry away
gcc/config.gcc turns the triple into file names. It picks the CPU
directory, the header list, the makefile fragments, the macros and the default
--with-* values, in a fixed order where later steps override earlier ones.
A top-level directory is a module, built for one machine. libgcc/ is
outside gcc/ because it is a target module, compiled by the compiler that
gcc/ produces.
The triple is read twice. gcc/config.gcc chooses for the compiler, and
libgcc/config.host chooses for libgcc, from two different config/ trees.
Things that surprise people
There is no gcc/config/x86_64/. The x86-64 backend is in
gcc/config/i386/, and the PowerPC backend is in gcc/config/rs6000/.
Every ARM compiler includes a VxWorks header. vxworks-dummy.h is first in
the header list of arm-none-eabi, so that shared ARM code can test VxWorks
markers safely (config.gcc:5878-5881).
A misspelled t-* fragment is dropped without a message. gcc/configure
keeps a tmake_file entry only if the file exists
(gcc/configure.ac:2409-2412).
The --with-* validation step changes the build on ARM. Its comment says
that it "should set nothing besides supported_defaults"
(config.gcc:4240-4244). The ARM branch adds multilib
fragments and headers, and sets --with-float=soft for the built-in multilib
profiles (config.gcc:4488-4539).
Documentation coverage
The internals manual describes the tree in its
Source Tree Structure and Build System chapter
(gcc/doc/sourcebuild.texi:5). The Top Level node lists the
top-level directories (:21), Subdirectories lists those of
gcc/ (:183), System Config covers config.build,
config.host and config.gcc (:282), and
Anatomy of a Target Back End lists the files of a
gcc/config/<machine>/ directory (:789). The install manual's
Downloading GCC page documents building binutils, GMP, MPFR and
MPC in the same tree (install.texi:698-713), and its
Configuration page documents --with-cpu
(install.texi:1681).
Where the internals manual is out of date for GCC 15.2.0:
- The Top Level list still has
intl(sourcebuild.texi:64-66), which GCC 14 removed, and has no entry forlibgrust. - The Subdirectories list omits
c-family,analyzer,rtl-ssa,sym-execandtext-art. - The Back End node names the backend source
machine.c(:799). The default ismachine.ccsince GCC 12. - The Library Files node places
crtstuff.candunwind-dw2.cundergcc/(:316-320). They are inlibgcc/. - The Configuration nodes name
acconfig.h(:243) andconfigure.frag(:278). Neither file is ingcc/in GCC 15.2.0.
What is not documented:
- What
config.gccsets. The System Config node is a FIXME (:298-299) that points at the comment at the top of the file, and that comment is the only description. - How the top-level build system works. The manual says it "is documented in a
separate manual, included with GNU Binutils" (
:157-160). A GCC checkout does not contain that manual. - That
Makefile.defnames modules the checkout does not contain, and thatconfiguredrops them without a message. - That
libgcc/config.hostmakes a second, separate selection, with fragment names that repeat those ingcc/config/. - That an
arm-none-eabitoolchain defaults to-mcpu=arm7tdmi. Thearm-*-eabientry of the target notes (install.texi:4102) does not say so, and the--with-cpuentry does not say what happens without it.
Next: Chapter 2.2, What configure does with your triple,
what happens to the triple before config.gcc sees it, and which of its two
names ends up on your compiler.