3.4 Bare metal: two GCC configures around newlib, and no sysroot
Source references in this chapter are to GCC 15.2.0 (releases/gcc-15.2.0).
The bare-metal recipe you found has four steps. Its first GCC has
--disable-multilib, and its last step is make all in the build directory of
that first GCC. Everything builds, and the toolchain links a test program. Then a
colleague adds --coverage to a build, and the sources say that the link will
fail on an undefined __gcov_exit. Another colleague passes
-mthumb -march=armv7e-m+fp -mfloat-abi=hard and gets the one libc.a that
newlib built, for the default variant.
A bare-metal toolchain is two configure runs of GCC with newlib installed
between them, and no sysroot anywhere. The first GCC only has to compile
newlib. newlib asks that first compiler which variants to build. Everything the
first configure decided stays decided in its build tree, and every target file
lands in the tooldir, $prefix/<target>/, which the driver already searches.
This chapter assumes Chapter 3.1 for the
cycle and for why stage 1 stops at make all-gcc, and
Chapter 3.2 for the inhibit_libc condition. It
also assumes Chapter 1.5 for the tooldir prefix and
Chapter 1.6 for the multilib fallback.
The recipe for arm-none-eabi
Nobody ran this recipe end to end at
releases/gcc-15.2.0. Each flag, and each claim about what a step needs, is checked against the sources this chapter cites. The order of the steps is the conventional one. newlib claims cite newlib 4.5.0.
$ # 1. binutils
$ $SRC/binutils/configure --target=arm-none-eabi --prefix=/opt/cross
$ make && make install
$ export PATH=/opt/cross/bin:$PATH
$ # 2. stage 1: a compiler, and no target libraries
$ $SRC/gcc-15.2.0/configure --target=arm-none-eabi --prefix=/opt/cross \
--enable-languages=c --without-headers --with-multilib-list=rmprofile
$ make all-gcc && make install-gcc
$ # 3. newlib, from the top of its own source tree
$ $SRC/newlib-4.5.0/configure --target=arm-none-eabi --prefix=/opt/cross
$ make && make install
$ # 4. stage 2: a new build directory and a new configure
$ $SRC/gcc-15.2.0/configure --target=arm-none-eabi --prefix=/opt/cross \
--enable-languages=c,c++ --with-newlib --with-multilib-list=rmprofile
$ make && make install
There are two GCC phases, not three, because there is no C library to build in
two passes. The hosted recipe in
Chapter 3.3 needs kernel headers and a
minimal libc before its second GCC. Here, newlib is complete after one build.
The install manual documents each GCC flag in this recipe on its
Configuration page: --prefix (install.texi:910),
--enable-languages (:2094), --with-multilib-list (:1325),
--without-headers (:2763) and --with-newlib (:2776). The sections below
say why each one is at its step.
Step 1: binutils, and the target name that names directories
GCC needs a cross assembler and linker before stage 1. The install manual's
Building a cross compiler section documents where they go:
$prefix/<target>/bin (install.texi:3281-3310). The driver searches that
directory through the tooldir prefix (gcc.cc:5534-5536).
binutils takes no --with-sysroot here, and its own flags are binutils'
business.
Spell --target the same way in all four steps. The string you type becomes a
directory name on both sides. GCC's top level sets
tooldir='${exec_prefix}'/${target_noncanonical}
(configure.ac:3121-3122), and
Chapter 2.2 shows that
target_noncanonical is the target as typed. newlib's top level gives each of
its libraries that same string as --host (newlib 4.5.0
Makefile.tpl:48 and :1349), and newlib
installs into $(exec_prefix)/$(host_alias) (Listing 3.4-2). So
--target=arm-eabi for GCC and --target=arm-none-eabi for newlib give two
tooldirs, and the driver searches only one of them.
The export PATH line is for step 3. newlib's configure looks for the target
compiler as <target>-gcc on PATH (newlib 4.5.0
configure.ac:3433). The macro behind that line prefixes
the program name with the target as typed
(config/acx.m4:116-117), and newlib carries the same macro.
Step 2: stage 1 with --without-headers and make all-gcc
Stage 1 exists to compile newlib, and newlib never links anything while it
configures. Its configure macro calls AC_NO_EXECUTABLES (newlib 4.5.0
newlib/acinclude.m4:121), and libgloss does the same
(libgloss/configure.ac:38). So the stage-1 compiler and binutils
are enough. Stage 1 needs no libgcc, no crt0.o and no linker script.
Chapter 3.1 explains why make all-gcc
stops before libgcc.
--without-headers makes inhibit_libc true without looking at the disk.
Chapter 3.2 gives the condition. On this layout, a
cross build with no sysroot already satisfies its first clause, so
--with-newlib adds nothing in stage 1. gcc/configure reads with_newlib in
exactly one place, that condition (gcc/configure.ac:2579).
Many recipes pass it in stage 1 anyway. It is harmless there, and it earns its
place in step 4.
Stage 1 must use the same multilib setting as stage 2. That is not about stage 1
itself, which builds no libraries. It is about newlib, which asks the stage-1
compiler for its variant list in step 3. A stage-1 --disable-multilib gives the
driver one variant: s-mlib then runs genmultilib with every list empty
(gcc/Makefile.in:2479-2499). The section on
--with-multilib-list=rmprofile below says which list to choose.
Step 3: newlib, built by the stage-1 compiler
newlib's own README states the order: "NOTE THAT YOU MUST HAVE ALREADY BUILT AND
INSTALLED GCC and BINUTILS." (newlib 4.5.0 newlib/README:40).
Configure newlib from the top of its source tree. That top level is built from
the same Makefile.tpl as GCC's, and it turns --target into each library's
--host (Makefile.tpl:1349).
newlib builds one copy of libc.a per line that the compiler prints for
--print-multi-lib:
multidirs=
for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
dir=`echo $i | sed -e 's/;.*$//'`
Listing 3.4-1: newlib's variant list comes from the compiler (newlib 4.5.0
config-ml.in:217-219).
CC is the stage-1 arm-none-eabi-gcc. This is the whole reason the stage-1
multilib setting matters. A one-variant stage 1 gives a one-variant newlib. The
stage-2 driver then asks for a Thumb hard-float libc.a, finds no such
directory, and falls back to the default one. That is the second pass of
for_each_path, and Chapter 1.6 shows why it does not
fail. In a combined tree the top level hands newlib the same list from xgcc.
That is Chapter 3.6's subject.
config-ml.in can only remove lines from that list. The install manual lists
per-target switches under --disable-multilib, such as fpu for arm-*-*
(install.texi:1304-1308). For Arm, config-ml.in drops every directory whose
name contains fpu when it sees --disable-fpu (newlib 4.5.0
config-ml.in:234-245). Nothing in gcc/configure.ac,
gcc/config.gcc or the top-level configure.ac reads that switch, so the
driver still selects the variants that newlib skipped.
newlib installs into the tooldir:
tooldir = $(exec_prefix)/$(host_alias)
toollibdir = $(tooldir)/lib$(MULTISUBDIR)
Listing 3.4-2: newlib's install directories (newlib 4.5.0
newlib/Makefile.am:67-68).
libc.a, libm.a and crt0.o go to toollibdir, one directory per variant
(:75-76 and :86). The headers go to
$(tooldir)/include (:264-268). That is
/opt/cross/arm-none-eabi/include, not sys-include. The difference matters in
step 4.
Step 4: stage 2 is a new configure, not make all
The stage-1 build tree keeps every decision its configure made. configure
substitutes inhibit_libc into gcc/Makefile
(gcc/configure.ac:2583), and the makefile turns true into
-Dinhibit_libc for libgcc (gcc/Makefile.in:789-794). Because
stage 1 had --without-headers, that value is true whatever is on disk. The
multilib list is fixed in multilib.h by the s-mlib rule
(gcc/Makefile.in:2479-2499). The install manual documents that
--enable-languages builds only the listed compilers and their runtime
libraries (install.texi:2094-2096). So make all in the stage-1 tree builds a
C-only toolchain whose libgcc can never have its libc-dependent parts. Configure
again, in a new directory, with the same --prefix and --target.
The stage-2 build compiles libgcc and libstdc++ with the xgcc it has just
built, not with the installed driver. The top level tells that xgcc where the
installed newlib is:
if test "${build}" = "${host}" && test -d ${srcdir}/gcc; then
# Search for pre-installed headers if nothing else fits.
FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -B$(build_tooldir)/bin/ -B$(build_tooldir)/lib/ -isystem $(build_tooldir)/include -isystem $(build_tooldir)/sys-include'
fi
Listing 3.4-3: the installed tooldir, handed to the build-tree compiler
(configure.ac:3829-3832).
build_tooldir is GCC's tooldir, $exec_prefix/<target>
(configure.ac:3121-3122). That is the directory newlib
installed into in Listing 3.4-2. FLAGS_FOR_TARGET becomes part of
the CC that every target library is configured with
(Makefile.tpl:637 and :308). That is why
newlib must be installed at the same prefix before step 4 runs.
--with-newlib in stage 2 is for libstdc++
The top level passes every --with-* option on to the target libraries'
configure scripts. It holds back only the GMP, MPFR, MPC and isl options, and
libintl and libiconv (configure.ac:3548 and
:3557, in the loop at :3472-3617). So libstdc++'s
configure sees --with-newlib, and that is where the option does its real work.
libstdc++ cannot link test programs on a cross target. Its configure explains
why, in a comment that names the file you lack: "cannot open crt0.o"
(libstdc++-v3/configure.ac:309-322). So it hard-codes what it
knows about the C library:
# Construct crosses by hand, eliminating bits that need ld...
# GLIBCXX_CHECK_MATH_SUPPORT
# First, test for "known" system libraries. We may be using newlib even
# on a hosted environment.
if test "x${with_newlib}" = "xyes"; then
os_include_dir="os/newlib"
Listing 3.4-4: the newlib branch of libstdc++'s cross configuration
(libstdc++-v3/configure.ac:335-341).
Without --with-newlib, and with headers allowed, configure takes the other
branch and calls GLIBCXX_CROSSCONFIG
(:420-421). That macro chooses by target name, and
nothing in it matches arm-none-eabi:
*)
AC_MSG_ERROR([No support for this host/target combination.])
Listing 3.4-5: the default case of GLIBCXX_CROSSCONFIG
(libstdc++-v3/crossconfig.m4:302-303).
So a stage 2 with C++ and no --with-newlib stops in libstdc++'s configure.
inhibit_libc is still true after stage 2
A fresh configure does not make libgcc complete. The second clause of the
condition probes for stdio.h in $target_header_dir. With no sysroot, that is
${test_exec_prefix}/${target_noncanonical}/sys-include
(gcc/configure.ac:2558-2559). newlib installed its headers in
include, next to it. So the probe fails, and stage 2's libgcc is built with
-Dinhibit_libc like stage 1's. Chapter 3.2 lists
what that removes, starting with the --coverage failure in this chapter's
first paragraph.
If you need those parts, give stage 2 --with-headers=DIR. The install manual
documents the option under Configuration, as deprecated in favour
of --with-sysroot, and says that fixincludes runs on the copied files
(install.texi:2751-2762). The source shows when the copy happens. The top-level
configure copies DIR into $prefix/<target>/sys-include
(configure.ac:2931-2942) during its own run
(:3005-3033). gcc/configure runs later, from make, and then
finds stdio.h. For this recipe, DIR is /opt/cross/arm-none-eabi/include.
The tooldir, instead of a sysroot
No step passes --with-sysroot, so the driver has none. -print-sysroot then
prints nothing (gcc.cc:8876-8886), as the GCC manual
documents under Developer Options (invoke.texi:21635-21640).
The tooldir does the sysroot's job:
| What | Installed by | Directory | How the driver finds it |
|---|---|---|---|
arm-none-eabi-as, -ld | binutils | $prefix/<target>/bin | tooldir bin prefix, gcc.cc:5534-5536 |
stdio.h and the other libc headers | newlib | $prefix/<target>/include | TOOL_INCLUDE_DIR, gcc/Makefile.in:2613 |
nothing, unless --with-headers=DIR | top-level configure | $prefix/<target>/sys-include | CROSS_INCLUDE_DIR, before include |
libc.a, libm.a, crt0.o | newlib | $prefix/<target>/lib/<variant> | tooldir lib prefix, gcc.cc:5537-5539 |
libnosys.a, nosys.specs, nano.specs | libgloss | $prefix/<target>/lib/<variant> | the same prefix |
libgcc.a, crti.o, crtbegin.o, crtend.o, crtn.o | libgcc | $prefix/lib/gcc/<target>/15.2.0/<variant> | GCC's own prefix, Chapter 1.5 |
On a cross build with no sysroot, cppdefault.cc drops /usr/include and
/usr/local/include from the header search and keeps sys-include
(gcc/cppdefault.cc:30-35). sys-include then comes just
before the tooldir's include (:90-97).
sys-include is CROSS_SYSTEM_HEADER_DIR, $(gcc_tooldir)/sys-include, when no
sysroot is given (gcc/configure.ac:185-189).
Chapter 1.8 covers the rest of the list.
This is the layout's one trap. The compiler finds newlib's headers in include.
The inhibit_libc probe looks for them in sys-include. Both directories are
in the table, and only one of them has the files.
The arm-none-eabi link line: __aeabi_*, crt0.o and --start-group
The most common bare-metal link failure is an undefined __aeabi_idiv after
-nostdlib. Chapter 1.10 owns it: the
compiler emits calls into libgcc whatever you link, so -nostdlib needs -lgcc
back by hand. On this target, the names come from the Arm back end:
/* For SImode division the ABI provides div-without-mod routines,
which are faster. */
set_optab_libfunc (sdiv_optab, SImode, "__aeabi_idiv");
set_optab_libfunc (udiv_optab, SImode, "__aeabi_uidiv");
Listing 3.4-6: where __aeabi_idiv gets its name
(gcc/config/arm/arm.cc:2663-2666).
arm_init_libfuncs returns early unless the target uses the BPABI
(arm.cc:2573-2576). arm-none-eabi does: bpabi.h makes
AAPCS the default ABI and defines TARGET_BPABI as TARGET_AAPCS_BASED
(bpabi.h:27-30).
STARTFILE_SPEC in arm/unknown-elf.h: three providers
Without -nostdlib, the startfiles come from arm/unknown-elf.h, which
config.gcc puts in the arm*-*-eabi* header list:
/* Now we define the strings used to build the spec file. */
#define UNKNOWN_ELF_STARTFILE_SPEC " crti%O%s crtbegin%O%s crt0%O%s"
#undef STARTFILE_SPEC
#define STARTFILE_SPEC \
"%{Ofast|ffast-math|funsafe-math-optimizations:%{!shared:crtfastmath.o%s}} " \
UNKNOWN_ELF_STARTFILE_SPEC
#define UNKNOWN_ELF_ENDFILE_SPEC "crtend%O%s crtn%O%s"
#undef ENDFILE_SPEC
#define ENDFILE_SPEC UNKNOWN_ELF_ENDFILE_SPEC
Listing 3.4-7: the bare-metal Arm startfiles
(gcc/config/arm/unknown-elf.h:31-42).
libgcc supplies crti.o, crtbegin.o, crtend.o and crtn.o on this target
(libgcc/config.host:578-584), and t-crtfm in the same entry
supplies crtfastmath.o. crt0.o is the C library's. By default newlib builds
it (newlib/Makefile.am:86). With
--disable-newlib-supplied-syscalls, newlib has no crt0.o for Arm (newlib
4.5.0 newlib/configure.host:466-470), and libgloss installs one
instead (libgloss/arm/Makefile.inc:1-3). Either way, the file
lands in the tooldir and %s finds it.
The port also adds no linker script. Its LINK_SPEC has no -T
(bpabi.h:81-87), so the script is yours or a board package's.
The GCC manual says as much under Link Options: on bare-board targets
-T "may be required when linking to avoid references to undefined symbols"
(invoke.texi:19437-19441).
LINK_GCC_C_SEQUENCE_SPEC: libgcc and libc in one group
Chapter 1.10 showed the generic library sequence, %G %L %G. This port replaces
it, and the comment says why:
/* The libgcc udivmod functions may throw exceptions. If newlib is
configured to support long longs in I/O, then printf will depend on
udivmoddi4, which will depend on the exception unwind routines,
which will depend on abort, which is defined in libc. */
#undef LINK_GCC_C_SEQUENCE_SPEC
#define LINK_GCC_C_SEQUENCE_SPEC "--start-group %G %{!nolibc:%L} --end-group"
Listing 3.4-8: libgcc and newlib depend on each other
(gcc/config/arm/unknown-elf.h:91-96).
The cycle of Chapter 3.1 is back, at link
time. printf in newlib needs a libgcc helper, the helper needs the unwinder,
and the unwinder needs abort from newlib. A linker group lets the linker go
around that loop.
Syscalls: what newlib leaves to libgloss and libnosys
newlib's libc.a does its I/O through a small set of functions that it does not
always define. _write_r, for example, calls _write (newlib 4.5.0
newlib/libc/reent/writer.c:49). Someone has to supply _write,
_sbrk, _exit and their relatives.
By default, newlib supplies them itself on Arm. It compiles its syscalls for a
debug monitor: the comment in configure.host says that ARM_RDI_MONITOR
"selects the Angel monitor" (newlib/configure.host:653-666). The
README documents --disable-newlib-supplied-syscalls as the switch that turns
this off (newlib/README:396-398). Then libc.a leaves
the names undefined, and a library from libgloss must define them. libgloss
describes itself in its README:
Libgloss is a library for all the details that usually get glossed over. This library refers to things like startup code, and usually I/O support for GCC and the C library.
newlib 4.5.0
libgloss/README:1-3
libgloss is a separate module because its pieces depend on the board or the
debug monitor, not only on the CPU. The Arm directory alone builds startup files
and libraries for RedBoot, the RDP monitor and Linux
(libgloss/arm/Makefile.inc:10-30). When you have no board
package, libnosys gives every name a stub that fails:
int
_write (int file,
char *ptr,
int len)
{
errno = ENOSYS;
return -1;
}
stub_warning(_write)
Listing 3.4-9: a libnosys stub (newlib 4.5.0
libgloss/libnosys/write.c:13-22).
stub_warning puts a string in a .gnu.warning. section named after the
symbol (libgloss/libnosys/warning.h:19-22), and the
string says that _write "is not implemented and will always fail"
(:38-42). The GNU linker prints it when the link uses the stub.
The link succeeds, and every call to _write fails at run time with ENOSYS.
-specs=nosys.specs: how libgloss reaches the link line
libgloss plugs libnosys into the driver with a specs file. It uses the
%rename idiom of Chapter 1.3:
%rename link_gcc_c_sequence nosys_link_gcc_c_sequence
*nosys_libgloss:
-lnosys
*nosys_libc:
%{!specs=nano.specs:-lc} %{specs=nano.specs:-lc_nano}
*link_gcc_c_sequence:
%(nosys_link_gcc_c_sequence) --start-group %G %(nosys_libc) %(nosys_libgloss) --end-group
Listing 3.4-10: nosys.specs (newlib 4.5.0
libgloss/libnosys/nosys.specs:1-10).
The new link_gcc_c_sequence keeps the port's group from Listing 3.4-8 and adds
a second group with -lnosys in it.
You write -specs=nosys.specs with no directory, and the driver finds it. The
driver looks up each -specs= file along the startfile prefixes, with the
multilib subdirectory first (gcc.cc:8633-8640). libgloss installs
nosys.specs in $(tooldir)/lib$(MULTISUBDIR)
(libgloss/libnosys/Makefile.inc:1 and
libgloss/Makefile.am:15-17), and that is the tooldir prefix of
the table above. The GCC manual documents -specs= under
Overall Options (invoke.texi:2257-2265), but not where the
driver looks for the file.
nano.specs works the same way. libgloss copies it from elf-nano.specs for
Arm (libgloss/arm/Makefile.inc:81-82). It renames link,
link_gcc_c_sequence and cpp_unique_options, swaps -lc for -lc_nano with
%:replace-outfile, and adds an include/newlib-nano header directory
(libgloss/arm/elf-nano.specs:1-21). newlib's own install creates
neither of those. It installs libc.a and libm.a
(newlib/Makefile.am:75-76), and its makefile never names
libc_nano.a. A toolchain that ships nano.specs working has a second newlib
build installed under those names by whoever packaged it.
--with-multilib-list=rmprofile, and the variants newlib gets
Without --with-multilib-list, arm*-*-eabi* builds the variants in
arm/t-arm-elf (config.gcc:1504):
# Build a very basic set of libraries that should cater for most cases.
# Single-precision floating-point is NOT supported; we don't build a
# suitable library for that. Use the rm-profile config in that case.
...
# Build a total of 4 library variants (base options plus the following):
MULTILIB_REQUIRED += mthumb
MULTILIB_REQUIRED += marm/mfpu=auto/march=armv5te+fp/mfloat-abi=hard
MULTILIB_REQUIRED += mthumb/mfpu=auto/march=armv7+fp/mfloat-abi=hard
Listing 3.4-11: the default variant set, abridged
(gcc/config/arm/t-arm-elf:19-22 and
:83-86).
The -march=armv7e-m+fp of this chapter's first paragraph falls in that gap.
t-arm-elf puts armv7e-m in its all_sp_only group
(t-arm-elf:61), and it maps only armv7e-m+fp.dp onto a
library (:122-123). The fragment's own comment sends you to
the R and M profile set.
--with-multilib-list=rmprofile selects arm/t-multilib
(config.gcc:4489-4497), which includes
arm/t-rmprofile (t-multilib:87). config.gcc refuses it
together with any of --with-arch, --with-cpu, --with-fpu, --with-float or
--with-mode (:4515-4524). The install manual
documents the aprofile and rmprofile values on its
Configuration page (install.texi:1357-1365).
Pass the same list to steps 2 and 4. Step 2's list is the one newlib reads
(Listing 3.4-1). Step 4's list is the one the driver selects from at every
link. If they differ, the driver searches variant directories that newlib never
filled, and Chapter 1.6's fallback hands the link the
default libc.a without a diagnostic from GCC.
Checking the result with -print-file-name and -print-multi-lib
These commands need only the finished toolchain:
$ arm-none-eabi-gcc -print-sysroot
$ arm-none-eabi-gcc -print-search-dirs
$ arm-none-eabi-gcc -print-file-name=libc.a
$ arm-none-eabi-gcc -print-file-name=crt0.o
$ arm-none-eabi-gcc -print-file-name=nosys.specs
$ arm-none-eabi-gcc -print-multi-lib
$ arm-none-eabi-gcc -mthumb -march=armv7e-m+fp -mfloat-abi=hard \
-print-multi-directory
$ arm-none-eabi-gcc -mthumb -march=armv7e-m+fp -mfloat-abi=hard \
-print-file-name=libc.a
$ grep '^inhibit_libc' build-stage2/gcc/Makefile
What the source predicts:
-print-sysrootprints nothing, because no step configured a sysroot.-print-search-dirslists the tooldir'slib/underlibraries. Expect it in an unnormalised form,.../lib/gcc/arm-none-eabi/15.2.0/../../../../arm-none-eabi/lib/. The driver builds the tooldir from its own versioned directory with../steps (gcc.cc:5522-5531andgcc/Makefile.in:2607).-print-file-name=libc.aprints a path that resolves to/opt/cross/arm-none-eabi/lib/libc.a. An answer that echoeslibc.aback means newlib is not where the driver looks. Chapter 1.5 explains the echo rule.-print-file-namesearches the startfile prefixes with the multilib subdirectory first (gcc.cc:8068-8072). So the two variant commands must agree: thelibc.apath must contain the directory that-print-multi-directoryprinted. A path without it is the fallback at work.- The last line prints
inhibit_libc = trueunless stage 2 had--with-headers=DIR. Chapter 3.2 gives this observable.
The __aeabi_idiv observable is
Chapter 1.10's Listing 1.10-5, and it
runs on this toolchain as written.
Three things to carry away
Stage 2 is a second configure, not a second make. The stage-1 build tree
keeps C only, its multilib list and inhibit_libc as they were configured.
newlib builds the variants that the stage-1 compiler reports. Give stage 1 the multilib list you want at the end.
There is no sysroot, and the tooldir replaces it. newlib's include and lib
in $prefix/<target>/ are on the driver's search lists already, but the
inhibit_libc probe looks in sys-include.
Things that surprise people
-print-sysroot prints nothing on a working bare-metal toolchain. That is the
normal state for this layout, not a broken install.
--with-newlib changes nothing in stage 1. On a cross build without a sysroot
it only repeats a clause that is already true. In stage 2 it keeps libstdc++'s
configure away from "No support for this host/target combination."
The target name is a directory name. arm-eabi and arm-none-eabi describe
the same machine and name two different tooldirs.
nano.specs names a sysroot path, and this layout has no sysroot. It adds
-isystem =/include/newlib-nano
(libgloss/arm/elf-nano.specs:5-6). cc1 replaces a leading
= only when it has a sysroot (gcc/incpath.cc:354-363). A
compiler configured without one starts with none
(c-family/c-opts.cc:52-53 and :91-92),
and the driver passes -isysroot only when a sysroot is set
(gcc.cc:6592-6601). So the path stays =/include/newlib-nano,
relative to the current directory, and gcc -v reports it as a nonexistent
directory (incpath.cc:83-85).
Documentation coverage
The install manual documents every configure flag in the recipe on its
Configuration page: --prefix (gcc/doc/install.texi:910),
--disable-multilib (:1298), --with-multilib-list with the Arm values
(:1325, :1357-1365), --enable-languages (:2094), --with-headers
(:2751-2762), --without-headers (:2763-2766) and --with-newlib
(:2776-2780). Its Building a cross compiler section
(install.texi:3247-3322) documents where binutils go and names crt0.o and
STARTFILE_SPEC. The host/target notes for arm-*-eabi
(install.texi:4102-4108) cover only an Ada build problem. The GCC manual
documents -specs= under Overall Options
(gcc/doc/invoke.texi:2257-2265), -nostdlib and -T under
Link Options (:19227, :19437-19441), and -print-file-name,
-print-multi-lib, -print-search-dirs and -print-sysroot under
Developer Options (:21571, :21584, :21622, :21635).
newlib documents its own configure options in newlib/README, which ships in
newlib's source tree, not on the web.
What is not documented:
- That a bare-metal toolchain needs two GCC configures, and that
make allin the stage-1 tree keeps stage 1'sinhibit_libc, languages and multilibs. - That the
inhibit_libcprobe looks in$prefix/<target>/sys-include, while newlib installs its headers in$prefix/<target>/include. The--with-headersentry hints at it: the option is "required" ifsys-include"doesn't pre-exist" (install.texi:2756-2759). - What
--with-newlibdoes at the pin. The manual names one effect, omitting__eprintffromlibgcc.a(install.texi:2776-2780).__eprintfis omitted byinhibit_libc, not by--with-newlibdirectly (libgcc/libgcc2.c:2979-2980). The effect that matters for C++ is libstdc++'s newlib branch, which the manual does not mention. - That
-specs=files are looked up along the startfile prefixes, multilib directories first, which is how-specs=nosys.specsworks without a path. - That newlib takes its variant list from the compiler that builds it.
- The
arm*-*-eabi*default variant set. The manual says that omitting--with-multilib-liston Arm means "only the default run-time library will be enabled" (install.texi:1363-1365). Forarm*-*-eabi*,t-arm-elfbuilds four variants (Listing 3.4-11).
Next: when someone hands you a sysroot, one configure and one make is the
documented path. The next chapter reads what goes wrong when that sysroot lacks
a file GCC needs.
All source references in this chapter are to GCC 15.2.0
(releases/gcc-15.2.0). Line numbers in other releases will differ; the
surrounding code rarely does. Where behaviour itself changed across a major
version, it is flagged inline.