2.2 What configure does with your triple

GCC 15.2.0. To run the commands: a GCC checkout, and the cross compiler arm-eabi-gcc for -dumpmachine and -v.

A tutorial tells you to configure GCC with --target=arm-eabi, and the build finishes. The driver in bin/ is arm-eabi-gcc, but your Makefile asks for arm-none-eabi-gcc. You run ./config.sub arm-eabi to see what GCC made of the name, and it prints arm-unknown-eabi. That makes three spellings of one target: the one you typed, the one config.sub made, and the arm-none-eabi that your Makefile and your binutils use.

configure keeps two forms of every machine name: the canonical form that config.sub makes, for matching, and the form you typed, which autoconf calls the alias, for naming. The case statements that decide what to build read the first. Every directory, program name and tool lookup reads the second.

This chapter assumes Chapter 1.2, for build, host and target and for the tooldir, and Chapter 1.5, for how the driver searches the tooldir and for Listing 1.5-6. It also uses collect2 from Chapter 1.1, specs from Chapter 1.3, the multilib table and MULTILIB_OSDIRNAMES from Chapter 1.6, and config.gcc and the config-lang.in files from Chapter 2.1.

config.sub and config.guess: from alias to canonical triple

config.sub turns each machine name that configure receives into a canonical triple, and config.guess names the build machine when you give no --build. The rules in config.sub explain why arm-eabi becomes arm-unknown-eabi, and the triple they produce is the one that GCC's per-target case patterns match. The install manual documents the canonicalisation under Configuration: a name "may be canonical or it may be more or less abbreviated", and config.sub "produces canonical versions".

With no --build, configure first asks config.guess to name the machine it runs on, then passes the answer to config.sub (configure:2411-2417). For the target, it passes your --target value to config.sub (configure:2505-2509). The script's header comment states its contract, a triple of CPU, manufacturer and operating system, or in some cases a newer four-part form that adds the kernel:

# The goal of this file is to map all the various variations of a given
# machine specification into a single specification in the form:
#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
# or in some cases, the newer four-part form:
#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
# It is wrong to echo any other type of specification.

Listing 2.2-1: the goal of config.sub (config.sub:48-53).

config.sub needs no build tree, so you can run it from the top of any GCC checkout:

$ ./config.sub arm-eabi
$ ./config.sub arm-none-eabi
$ ./config.sub x86_64-linux-gnu

With the config.sub in GCC 15.2.0, whose timestamp is 2021-10-27 (config.sub:7), the three commands print arm-unknown-eabi, arm-none-eabi and x86_64-pc-linux-gnu. Only arm-none-eabi comes back as typed.

arm-eabi has two fields, and when the second field is not a known manufacturer, config.sub reads it as the operating system. The CPU then has no vendor, the code's name for the manufacturer field, so the script supplies one. In the abridged listing, watch the basic_os=$field2 line and the vendor=unknown default:

			*-*)
				# Second component is usually, but not always the OS
				case $field2 in
					...
					*)
						basic_machine=$field1
						basic_os=$field2
						;;
	...
	# Recognize the basic CPU types without company name.
	*)
		cpu=$basic_machine
		vendor=unknown
		;;
...
echo "$cpu-$vendor-${kernel:+$kernel-}$os"

Listing 2.2-2: how arm-eabi becomes arm-unknown-eabi, abridged (config.sub:169-197, :963-967, :1877).

eabi passes the OS check (config.sub:1712-1713), and the table that picks a vendor from the OS has no entry for it (:1799-1875), so the vendor stays unknown. Nothing in config.sub turns arm-eabi into arm-none-eabi. The none is not a keyword: in arm-none-eabi it is the vendor field. The three-field branch keeps arm-none as CPU and vendor (config.sub:140-158), and the split of arm-none into the two leaves none as typed (:938-944).

x86_64-linux-gnu also has no vendor field, but its last two fields form a known two-part OS, linux-gnu (config.sub:143-150). A bare x86_64 gets the vendor pc, for a reason its comment gives: the word unknown tends to confuse beginning users (config.sub:946-952). The result is x86_64-pc-linux-gnu, which is also what config.guess prints on an x86_64 GNU/Linux machine (config.guess:1110-1122).

$target and $target_noncanonical: one for matching, one for names

configure keeps both forms of the target name: $target holds the canonical triple, and $target_noncanonical holds your spelling. Each consumer in the tree reads one of the two, so the variable it reads decides whether arm-eabi and arm-none-eabi look the same to it.

$target is the output of config.sub (configure:2519), and $target_alias is the --target value as you typed it. $target_noncanonical is the alias, with a fallback for the case where you typed nothing:

dnl # _GCC_TOPLEV_NONCANONICAL_TARGET
dnl # $target_alias or $host_noncanonical if blank.
dnl # Used when we would use $target_alias, but empty is not OK.
AC_DEFUN([_GCC_TOPLEV_NONCANONICAL_TARGET],
[AC_REQUIRE([_GCC_TOPLEV_NONCANONICAL_HOST]) []dnl
case ${target_alias} in
  "") target_noncanonical=${host_noncanonical} ;;
  *) target_noncanonical=${target_alias} ;;
esac
]) []dnl # _GCC_TOPLEV_NONCANONICAL_TARGET

Listing 2.2-3: target_noncanonical (config/acx.m4:29-38).

The host and build macros above it follow the same pattern (config/acx.m4:8-26). At the end of the chain, an empty --build falls back to the canonical $build. On a native build where you typed no machine name at all, all three noncanonical names are therefore the config.sub form of what config.guess printed.

gcc/configure.ac states the purpose of the second form in one comment: "Determine the noncanonical target name, for directory use" (gcc/configure.ac:41-42). The rule holds across the tree:

ConsumerForm it readsSource
"is this a cross compiler?"canonicalconfigure.ac:209-215, gcc/configure.ac:2546-2549
per-target case patterns, such as unsupported languagescanonicalconfigure.ac:918-922
backend selection in config.gcccanonicalgcc/config.gcc:1497
the tooldir, $exec_prefix/<alias>as typedconfigure.ac:3121
lib/gcc/<alias>/ and libexec/gcc/<alias>/as typedgcc/Makefile.in:682-684
the build-tree directory of the target librariesas typedconfig/acx.m4:100-101
the driver's own target name, spec_machineas typedgcc/Makefile.in:2605
collect2's <alias>-ldas typedgcc/Makefile.in:2558

The lib/gcc/<alias>/ and libexec/gcc/<alias>/ directories use real_target_noncanonical, which is "Normally identical to target_noncanonical, except for compilers built as accelerator targets" (gcc/Makefile.in:65-67).

The split has a reason on each side. A pattern such as arm*-*-eabi* needs three fields, so only the canonical form can match it. A directory name has no such need, so GCC keeps your spelling. The cost is that --target=arm-eabi and --target=arm-none-eabi canonicalise to arm-unknown-eabi and arm-none-eabi, which both match arm*-*-eabi*. The two select the same backend, and they install into two different trees.

The cross test meets two spellings of one canonical name. It compares canonical names, so --host=x86_64-linux-gnu --target=x86_64-pc-linux-gnu is a native build.

program_prefix: how a cross build gets <alias>- names

A cross build installs its programs under <alias>- names with no option, because the generated configure sets program_prefix to the target alias and a dash when you give none of the program-name options. GCC turns that default off for a native build with a guard that compares spellings, not canonical names, so a native build can still get a prefix.

Three configure options rename the programs that make install writes to bin/. --program-prefix=foo- installs gcc as foo-gcc, --program-suffix=-15 installs it as gcc-15, and --program-transform-name= applies a sed script to each name. The install manual documents the three under Configuration (gcc/doc/install.texi:998-1038).

The default prefix comes from code that autoconf writes into configure for AC_CANONICAL_SYSTEM and AC_ARG_PROGRAM (configure.ac:80-81). A search of the text of configure.ac finds only the guard in Listing 2.2-5, so the code to read is in the generated configure:

# The aliases save the names the user supplied, while $host etc.
# will get canonicalized.
test -n "$target_alias" &&
  test "$program_prefix$program_suffix$program_transform_name" = \
    NONENONEs,x,x, &&
  program_prefix=${target_alias}-

Listing 2.2-4: the default program prefix (configure:2533-2538).

NONE, NONE and s,x,x, are the defaults of the three program-name options (configure:930-932), so the prefix applies when you give a target and set none of the three options. The alias is your spelling, so --target=arm-eabi gives arm-eabi-.

Autoconf would do this for a native build too, whenever --target is on the command line. GCC's top level stops it one step earlier:

dnl Autoconf 2.5x and later will set a default program prefix if
dnl --target was used, even if it was the same as --host.  Disable
dnl that behavior.  This must be done before AC_CANONICAL_SYSTEM
dnl to take effect.
test "$host_noncanonical" = "$target_noncanonical" &&
  test "$program_prefix$program_suffix$program_transform_name" = \
    NONENONEs,x,x, &&
  program_transform_name=s,y,y,

Listing 2.2-5: no default prefix when host and target match (configure.ac:71-78).

s,y,y, is a sed command that changes nothing, so its only effect is to make the test in Listing 2.2-4 fail. The guard compares the noncanonical names, not the canonical ones that the cross test compares.

Configure natively on a machine that config.guess calls x86_64-pc-linux-gnu, pass --target=x86_64-linux-gnu and no --host, and the two spellings differ. The guard does not fire, and the prefix applies. The canonical names match, so the result is a native compiler installed as x86_64-linux-gnu-gcc.

The top level then hands the finished sed script to every subdirectory as --program-transform-name. It also replaces s,x,x, with s,y,y,, "because we want to override the logic in subdir configure scripts to choose program_transform_name" (configure.ac:3623-3637). The override matters because gcc/configure carries its own copy of Listing 2.2-4 (gcc/configure:3540-3543).

In gcc/, the script becomes the installed names:

GCC_INSTALL_NAME := $(shell echo gcc|sed '$(program_transform_name)')
GCC_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcc|sed '$(program_transform_name)')
...
FULL_DRIVER_NAME=$(target_noncanonical)-gcc-$(version)$(exeext)

Listing 2.2-6: the driver's installed names, abridged (gcc/Makefile.in:876-877, :1925).

install-driver installs GCC_INSTALL_NAME, then links <alias>-gcc-15.2.0 next to it. On a native build only, it also links GCC_TARGET_INSTALL_NAME (gcc/Makefile.in:4173-4191). The test it uses for "native" is the absence of gcc-cross, which only the cross build makes (gcc/Makefile.in:2219, :2448-2450). The version link takes $(target_noncanonical) directly, so no transformation renames it.

Sub-configures see --target=$(target_alias)

Every directory that the top level configures gets its target as --target=$(target_alias) from the generated Makefile, not from your command line. target_alias holds your spelling, so every directory sees the name as you typed it, and every directory runs config.sub on it again.

The top level drops every option that starts with --t, --ho, --bu or --program-, and forwards most others, such as --enable-languages and --disable-multilib, as you typed them (configure.ac:3579-3610). The generated Makefile adds the machine names back. In it, target_alias is @target_noncanonical@ (Makefile.tpl:48-51), and every sub-configure gets --target= with that value (Makefile.tpl:1203-1204).

For a target library, the Makefile also passes the target alias as --host (Makefile.tpl:1488-1493), because a target library runs on the target. Chapter 2.3 covers the module lists that these rules come from.

After the top-level configure succeeds, the generated Makefile shows both forms:

$ ../gcc/configure --target=arm-eabi --prefix=/opt/arm
$ grep -E '^target(_alias)?=' Makefile

From Listing 2.2-2 and the Makefile.tpl lines, target_alias holds arm-eabi and target holds arm-unknown-eabi.

-dumpmachine, the tooldir and collect2 read the alias

-dumpmachine and gcc -v report a built compiler's target as you spelled it, not in canonical form, and the tooldir and collect2 find the target's tools by the same spelling. Those lookups decide whether an arm-eabi compiler finds binutils that were installed under arm-none-eabi names.

-dumpmachine prints "the compiler's target machine" and exits, and the GCC manual documents it under Developer Options. The driver gets its target name from -DDEFAULT_TARGET_MACHINE, which the Makefile sets to $(target_noncanonical) (gcc/Makefile.in:2604-2605):

static const char *spec_machine = DEFAULT_TARGET_MACHINE;
static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE;
...
    case OPT_dumpmachine:
      printf ("%s\n", spec_machine);
      exit (0);

Listing 2.2-7: what -dumpmachine prints, abridged (gcc/gcc.cc:335-336, :4231-4233).

gcc -v prints the same string on its Target: line, and the configure arguments on the next line (gcc/gcc.cc:7709-7710). Those arguments are the top-level command line as typed, $0 and then "$@" (configure.ac:42-64):

$ arm-eabi-gcc -dumpmachine
$ arm-eabi-gcc -v 2>&1 | grep -E '^(Target|Configured with):'

For the arm-eabi build, -dumpmachine prints arm-eabi, and Configured with: repeats --target=arm-eabi. A canonical name shows up only on a native build with no machine options, because there you typed no spelling and the alias falls back to the output of config.guess.

spec_machine also names the tooldir in the driver's program search (gcc/gcc.cc:5523-5539, Listing 1.5-6). The driver asks that list for the name that the spec gives, a plain as, and never for <alias>-as (gcc/gcc.cc:3097-3118). When no prefix holds one, it runs the bare name and lets the PATH decide (gcc/gcc.cc:3295-3302, :3438-3441).

collect2, unlike the driver, adds the target name itself. On a cross compiler, it builds the linker's name from TARGET_MACHINE, which is $(target_noncanonical) (gcc/Makefile.in:2558):

  for (i = 0; i < USE_LD_MAX; i++)
#ifdef CROSS_DIRECTORY_STRUCTURE
    /* lld and mold are platform-agnostic and not prefixed with target
       triple.  */
    if (!(i == USE_LLD_LD || i == USE_MOLD_LD))
      full_ld_suffixes[i] = concat (target_machine, "-", ld_suffixes[i],
				    NULL);
    else
#endif
      full_ld_suffixes[i] = ld_suffixes[i];

Listing 2.2-8: collect2 names <alias>-ld (gcc/collect2.cc:867-876).

collect2 searches the PATH for that name last, after the compiler's own directories (gcc/collect2.cc:1107-1110). The top-level configure uses the same alias to find the target tools for the build. It tries a list of tool directories that includes $prefix/<alias>/bin, then <alias>-as on the PATH (config/acx.m4:113-118, :257-292, configure.ac:4040).

The --target you give GCC must therefore be spelled the same as the one you gave binutils. An arm-eabi driver looks for as in $prefix/arm-eabi/bin/, and its collect2 looks for arm-eabi-ld on the PATH. If your binutils use the arm-none-eabi names, neither lookup finds them.

--program-prefix does not change these lookups. It renames what make install writes to bin/, and the installed driver and collect2 never read it. One build-time rule does: on a cross build with no binutils in the tree, gcc/Makefile.in names the target ar, ranlib and strip by running the script over the bare names (gcc/Makefile.in:513-551).

config.gcc reads both names: the alias keeps pentium4

config.gcc reads the alias as well as the canonical triple, because canonicalisation can discard information that the alias carries. A pentium4 target shows both halves: the canonical form picks the backend, and the alias supplies the processor that becomes the compiler's default.

config.sub turns a pentium4 CPU into i786 (config.sub:1079-1081), so --target=pentium4-linux-gnu canonicalises to i786-unknown-linux-gnu. The canonical form still selects the 32-bit x86 backend, and config.gcc then reads the alias to recover the processor:

# Set arch and cpu from ${target} and ${target_noncanonical}.  Set cpu
# to generic if there is no processor scheduler model for the target.
...
  i686-*-* | i786-*-*)
    case ${target_noncanonical} in
...
      pentium4-*|pentium4m-*)
	arch=pentium4
	cpu=pentium4

Listing 2.2-9: the alias picks the default processor, abridged (gcc/config.gcc:3714-3715, :3775-3776, :3871-3873).

--with-arch and --with-cpu give a compiler its default processor options, and the install manual documents them under Configuration. With neither option, the arch and cpu values that Listing 2.2-9 sets become the defaults (gcc/config.gcc:4018-4027, :4105-4124). pentium4 thus becomes this compiler's default --with-arch and --with-cpu value, and neither option appears on its Configured with: line. The rest of config.gcc is the subject of Chapter 2.1.

--enable-languages: config-lang.in and noconfigdirs

The top level reads a config-lang.in fragment for every language, and a language that --enable-languages does not take loses its directories. The triple reaches this option too, because a case on the canonical $target can mark a language unsupported. The install manual documents the option under Configuration (gcc/doc/install.texi:2094-2112).

--enable-languages takes a comma-separated list of the compilers to build, with their run-time libraries. Its special values are all, for every available language, and default. In gcc/, grep ^language= */config-lang.in lists the others. A loop in the top-level configure.ac sources every gcc/*/config-lang.in and reads five variables from each (configure.ac:2340-2360). Go's fragment shows four of them:

language="go"

compilers="go1\$(exeext)"

target_libs="target-libgo target-libffi target-libbacktrace"
lang_dirs="gotools"

gtfiles="\$(srcdir)/go/go-lang.cc \$(srcdir)/go/go-c.h"

# Do not build by default.
build_by_default="no"

Listing 2.2-10: a language fragment (gcc/go/config-lang.in:27-37).

With no --enable-languages, and no deprecated LANGUAGES variable in the environment, the list is default (configure.ac:2222-2227). default takes each language whose build_by_default is yes (:2380-2382). The code that removes the directories of a language that is not taken has one arm for unsupported and one for no:

	case $add_this_lang in
	  unsupported)
            # Remove language-dependent dirs.
	    disabled_target_libs="$disabled_target_libs $target_libs"
	    noconfigdirs="$noconfigdirs $lang_dirs"
	    ;;
	  no)
            # Remove language-dependent dirs; still show language as supported.
	    disabled_target_libs="$disabled_target_libs $target_libs"
	    noconfigdirs="$noconfigdirs $lang_dirs"
            potential_languages="${potential_languages}${language},"
	    ;;

Listing 2.2-11: a disabled language removes its directories (configure.ac:2528-2539).

A disabled target library stays only if an enabled language also lists it (configure.ac:2562-2570). With --enable-languages=c,c++, the build therefore drops target-libgo and gotools, but keeps any library that Go shares with an enabled language. The comment that declares the two lists says that "Noconfigdirs are removed loudly", unlike skipdirs, which configure removes with no message (configure.ac:225-227).

One source of unsupported is a case on the canonical $target, such as the one that marks Go unsupported on Darwin, Cygwin, MinGW and BPF (configure.ac:918-922). A language that you named but that cannot be built stops configure with "The following requested languages could not be built" (configure.ac:2612-2616).

--disable-multilib: the top level, config-ml.in and multilib.h

--disable-multilib acts in three places: the top level, each target library's config-ml.in, and the multilib.h table that the driver reads. In gcc/, the rule that writes multilib.h has a second condition, so on some targets the variants that GCC builds go but the OS library directory names stay. The install manual gives the option one sentence: it stops GCC building the extra library variants (gcc/doc/install.texi:1298-1302).

At the top level, the default is on. If you give neither form, the top level adds --enable-multilib to every target library's configure line (configure.ac:3714-3717). If you give --disable-multilib, it reaches the target libraries like any other forwarded option. On a native x86_64 GNU/Linux build with neither form, configure first checks that -m32 links, and stops with an error that suggests --disable-multilib if it does not (configure.ac:3694-3712).

In each target library, config-ml.in does all of its work inside one if [ "${enable_multilib}" = yes ] (config-ml.in:177-178). When the switch is on, it asks the newly built compiler for the variant list:

multidirs=
for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
  dir=`echo $i | sed -e 's/;.*$//'`
  ...
done

# Target libraries are configured for the host they run on, so we check
# $host here, not $target.

Listing 2.2-12: target libraries take the variants from the new compiler, abridged (config-ml.in:217-232).

The comment states the same rule as the --host that the Makefile passes to a target library: in a target library's configure, $host is the target machine. With --disable-multilib, the library builds the default variant only.

In gcc/, the switch reaches multilib.h, the table that Chapter 1.6 showed the driver reading. The rule that generates it has a second condition:

s-mlib: $(srcdir)/genmultilib Makefile
	if test @enable_multilib@ = yes \
	   || test -n "$(MULTILIB_OSDIRNAMES)"; then \
	  $(SHELL) $(srcdir)/genmultilib \
	    "$(MULTILIB_OPTIONS)" \
	    ...
	    "@enable_multilib@" \
	    > tmp-mlib.h; \
	else \
	  $(SHELL) $(srcdir)/genmultilib '' '' '' '' '' '' '' '' \
	    "$(MULTIARCH_DIRNAME)" '' no \
	    > tmp-mlib.h; \
	fi

Listing 2.2-13: --disable-multilib and MULTILIB_OSDIRNAMES, abridged (gcc/Makefile.in:2480-2500).

When the target's fragment sets MULTILIB_OSDIRNAMES, genmultilib still gets the full option list, but with no as its last argument. Its header comment states the effect: with anything but yes there, every GCC multilib directory name becomes . (gcc/genmultilib:91-92). The OS directory survives next to each . (:400-402).

x86_64 GNU/Linux is such a target. It sets MULTILIB_OSDIRNAMES, with m64=../lib64 (gcc/config/i386/t-linux64:36), so --disable-multilib there removes the variants that GCC builds and keeps the OS library directory names. Some targets also choose their multilib fragment by the switch: RISC-V GNU/Linux adds riscv/t-linux-multilib only when it is yes (gcc/config.gcc:2522-2528).

Three things to carry away

$target is for case patterns, and $target_noncanonical names everything on disk. config.sub output selects the backend. Your spelling names the programs, the tooldir and lib/gcc/<alias>/.

A cross build gets <alias>- names from autoconf, with no option. The guard against a prefix on a native build compares spellings, not canonical names.

Every tool lookup uses the alias. The tooldir, -dumpmachine, collect2's <alias>-ld and configure's search for <alias>-as all read it, and --program-prefix changes none of them.

Things that surprise people

config.sub arm-eabi prints arm-unknown-eabi. No step in the script produces arm-none-eabi from a two-part name.

--target=arm-eabi and --target=arm-none-eabi build the same compiler into different trees. Both canonical forms match arm*-*-eabi*, and every directory name uses the spelling.

A native build can get a program prefix. --target=x86_64-linux-gnu with no --host, on a machine that config.guess calls x86_64-pc-linux-gnu, gives x86_64-linux-gnu-gcc.

gcc -v does not canonicalise. Configured with: is the command line as typed, and Target: is the alias.

Documentation coverage

The install manual's Configuration page (gcc/doc/install.texi:727) defines build, host and target, and says that config.sub "produces canonical versions" of configuration names (:835-867). The same page documents the program-name options (:998-1038), --disable-multilib (:1298) and --enable-languages (:2094). The internals manual's Configure Terms node (gcc/doc/configterms.texi:5) says that --target=foo-bar gives a compiler called foo-bar-gcc (:40-45). It also says that a target library's host is the target (:47-55). -dumpmachine is in Developer Options (gcc/doc/invoke.texi:21649).

Each option has an entry, but no entry says which form of the name the rest of the build uses.

What is not documented:

  • That configure keeps the canonical name for matching and your spelling for every directory and program name.
  • That the default <alias>- prefix comes from autoconf, and that GCC's guard against it compares spellings.
  • That -dumpmachine prints the alias. The manual's example, i686-pc-linux-gnu (invoke.texi:21650-21651), reads like a canonical name.
  • That the driver looks for a plain as and falls back to the PATH, while collect2 looks for <alias>-ld.
  • That --disable-multilib keeps the OS directory names of a target that sets MULTILIB_OSDIRNAMES.

What the manual says that GCC 15.2.0 does not do:

  • "As currently implemented, this option only takes effect for native builds; cross compiler binaries' names are not transformed even when a transformation is explicitly asked for by one of these options" (install.texi:1029-1031). Listing 2.2-4 skips its default when you give any of the three options. The top level then passes the resulting script to gcc/, for a cross build as for a native one. By that trace, --program-prefix=foo- installs a cross driver as foo-gcc.

Next: Chapter 2.3, Makefile.def and AutoGen: how make orders the build, how AutoGen turns Makefile.def into the top-level Makefile, and the order in which make builds the directories that the top-level configure set up.