3.6 newlib in the middle of a GCC build: the one no_c=true
Source references in this chapter are to GCC 15.2.0 (releases/gcc-15.2.0).
You link newlib/ and libgloss/ into a GCC source tree. You run the top-level
configure with a target and a prefix, and nothing else. The top-level
Makefile then orders one make to build the compiler, libgcc, the C library
and libstdc++, with newlib built once for every multilib the compiler has. You
never typed --with-newlib.
Then a colleague runs newlib/configure by hand in the same tree, to rebuild
only the C library. That configure looks for an installed compiler. It builds
newlib with a different compiler, or it stops because it finds none.
The top-level build declares newlib a target module like libstdc++, and then
exempts it, with one no_c=true, from the C-library dependency that every other
target module gets. The rest of this chapter is what the top level hands
newlib once that edge is gone: a compiler, flags, --with-newlib, and the
multilib list.
This chapter crosses an interface on purpose. The book covers the C library only
where GCC meets it, but a combined tree is GCC's top level running newlib's
configure, and the handshake has code on both sides. newlib sources are cited
at the newlib-4.5.0 tag, and the link text says so.
This chapter assumes Chapter 2.3, for
Makefile.def, Autogen and target modules, Chapter 3.2,
for inhibit_libc, and Chapter 1.6, for
-print-multi-lib and the driver's two-pass multilib search.
Chapter 3.4 builds the same toolchain in
separate phases. This chapter builds it in one.
The combined tree: newlib/ and libgloss/ beside gcc/
$ tar xf gcc-15.2.0.tar.xz
$ tar xf newlib-4.5.0.20241231.tar.gz
$ ln -s ../newlib-4.5.0.20241231/newlib gcc-15.2.0/newlib
$ ln -s ../newlib-4.5.0.20241231/libgloss gcc-15.2.0/libgloss
$ mkdir build && cd build
$ ../gcc-15.2.0/configure --target=arm-none-eabi --prefix=/opt/arm \
--enable-languages=c,c++
$ make
$ make install
Nobody ran this recipe at the pin. Each mechanism below is read from the sources at the tags named. The sequence is the conventional one, not a tested one.
binutils can go into the same tree, or be installed into the same prefix first.
The install manual documents both. Under Downloading the source
it says to link the binutils components into the GCC source directory
(install.texi:698-704). Under Building it says where the
assembler and linker go if you do not (install.texi:3281-3286). The list of
components is the top level's own module list: bfd waits for libsframe
(Makefile.def:489) and ld waits for libctf
(:505), so those directories go in too.
What makes the top level see newlib: three tests in configure.ac
The top-level configure keeps target-newlib in its list of target
directories only if three tests pass.
The source directory must have a newlib/configure. The loop that applies this
test describes itself well:
Quietly strip out all directories which aren't configurable in this tree.
The target must not exclude it. A long case adds target-newlib to
noconfigdirs for operating systems that have their own C library, including
every *-*-linux* triple (configure.ac:1017-1090). When
newlib goes, libgloss goes with it, "since libgloss depends upon some newlib
header files" (:1398-1403).
The build must be a cross. A native build puts newlib in skipdirs
(configure.ac:277-281), and only an explicit --with-newlib
takes it out again (:292-296). Chapter 3.2 covers that flag's
other effect.
Why GCC's top level, and not newlib's
The newlib release ships its own copy of the same top-level files. Its
Makefile.def declares newlib with the same no_c=true line
(newlib-4.5.0 Makefile.def:542). But the copy is not GCC 15's.
It has no libcody module. GCC 15's all-gcc has a hard dependency on all-libcody
(Makefile.def:393). So you link newlib into GCC's tree, and GCC's
top level runs the build.
Why not newlib/configure directly
newlib's configure finds its compiler the Autoconf way, through AC_PROG_CC
(newlib-4.5.0 newlib/acinclude.m4:123). Nothing in it knows that
gcc/xgcc exists in your build directory. Everything the next four sections
describe comes from the top level, and a hand-run configure gets none of it.
newlib's own README states the standalone contract plainly:
NOTE THAT YOU MUST HAVE ALREADY BUILT AND INSTALLED GCC and BINUTILS.
What the top level adds by itself: --with-newlib, twice
Once newlib is in the target list, the top level tells two different audiences.
# If using newlib, add --with-newlib to the extra_host_args so that gcc/configure
# can detect this case.
if test x${with_newlib} != xno && echo " ${target_configdirs} " | grep " target-newlib " > /dev/null 2>&1 ; then
with_newlib=yes
extra_host_args="$extra_host_args --with-newlib"
fi
Listing 3.6-1: --with-newlib for gcc/configure (configure.ac:2997-3003).
extra_host_args goes into the arguments of every host module, gcc/ included
(configure.ac:3681). A second block, about 700 lines later, adds
--with-newlib to target_configargs, which every target library receives
(configure.ac:3719-3723).
In gcc/configure: inhibit_libc turns on by itself
--with-newlib satisfies the first clause of the inhibit_libc condition. The
second clause looks for stdio.h in $target_header_dir, which is
$exec_prefix/<target>/sys-include when there is no sysroot
(gcc/configure.ac:2556-2559). newlib never installs there. It puts
its headers in $(tooldir)/include
(newlib-4.5.0 newlib/Makefile.am:263-268). So on a fresh
prefix, inhibit_libc is true, and you needed neither --with-newlib nor
--without-headers. The comment above the condition names this case:
If this is using newlib, without having the headers available now, then define inhibit_libc in LIBGCC2_CFLAGS.
Chapter 3.2 quotes the condition in full and lists what it removes from libgcc.
The fact that matters here comes from the ordering in the next section: libgcc
configures before newlib, and the same make does not build libgcc again. The
libgcc a combined tree installs is the inhibit_libc libgcc.
In the target libraries: libstdc++ stops probing
libstdc++ reads --with-newlib. In a cross build, it then skips its link probes
and defines a fixed list of features it knows newlib has
(libstdc++-v3/configure.ac:340). The comment above that branch
says why the probes cannot run in this build:
Here's why GLIBCXX_CHECK_MATH_SUPPORT, and other autoconf macros that involve linking, can't be used: "cannot open sim-crt0.o" "cannot open crt0.o"
How libstdc++ configures is Part IV's subject. For this chapter, the point is
that --with-newlib reaches every target library without you.
no_c=true in lang_env_dependencies: why newlib does not wait for itself
Every target library needs a C library before it can configure. The top level writes that need into the dependency graph once, for all target modules, and then lists the exceptions:
// Target modules. These can also have dependencies on the language
// environment (e.g. on libstdc++). By default target modules depend
// on libgcc and newlib/libgloss.
lang_env_dependencies = { module=libitm; cxx=true; };
lang_env_dependencies = { module=libffi; cxx=true; };
lang_env_dependencies = { module=newlib; no_c=true; };
lang_env_dependencies = { module=libgloss; no_c=true; };
lang_env_dependencies = { module=libgcc; no_gcc=true; no_c=true; };
Listing 3.6-2: the exemptions (Makefile.def:647-654).
The template turns "by default" into one line per target module, and no_c
switches that line off:
[+ FOR target_modules +][+ IF (not (lang-dep "no_c")) +]
configure-target-[+module+]: maybe-all-target-newlib maybe-all-target-libgloss[+
ENDIF +][+ IF (lang-dep "cxx") +]
configure-target-[+module+]: maybe-all-target-libstdc++-v3[+
ENDIF +]
[+ ENDFOR target_modules +]
Listing 3.6-3: the C-library edge, and its switch (Makefile.tpl:2113-2118).
In the generated Makefile.in, libstdc++ gets
configure-target-libstdc++-v3: maybe-all-target-newlib maybe-all-target-libgloss
(Makefile.in:69398). newlib and libgloss get no such line.
Without the exemption, configure-target-newlib would wait for
all-target-newlib, and all-target-newlib already waits for
configure-target-newlib (Makefile.in:49510). newlib
would wait for a C library that is newlib.
The maybe- prefix is what makes the default cheap. maybe-all-target-newlib
is an empty target, and it depends on the real all-target-newlib only inside
an @if target-newlib block (Makefile.in:49503-49509).
configure deletes that block when newlib is not in the tree
(configure.ac:3400-3413). So every target module can carry
the edge, and in a tree without newlib it costs nothing.
The edges newlib does have
Makefile.def names only two explicit edges for newlib, to all-binutils and
all-ld. It is easy to read those as its only dependencies. The generated
Makefile.in has two more:
configure-target-newlib waits for | Because | Source |
|---|---|---|
maybe-all-binutils, maybe-all-ld | explicit in Makefile.def | Makefile.def:705-706 |
maybe-all-gcc | every target module waits for the compiler | Makefile.tpl:1927-1930 |
maybe-all-target-libgcc | newlib has no_c but not no_gcc | Makefile.tpl:2108-2111, Makefile.in:69375 |
not all-target-newlib | no_c=true | Makefile.def:652 |
The gcc and libgcc edges sit in @if gcc-no-bootstrap blocks. A cross
compiler does not bootstrap by default (configure.ac:1532-1541), so
those blocks stay in its Makefile. libgloss waits for all-target-newlib
(Makefile.def:703), and every target library without
no_c waits for both. The order of one cross make is therefore binutils, then gcc
(Makefile.def:373-375), then libgcc, newlib, libgloss, and
the rest.
To see the edges in your own build directory, read the generated Makefile after
the top-level configure:
$ grep -n '^configure-target-newlib:' Makefile
$ grep -n '^configure-target-libstdc++-v3:' Makefile
Chapter 2.3 explains why grep and not make -n:
GNU make runs $(MAKE) lines even under -n.
What newlib is handed: CC_FOR_TARGET and FLAGS_FOR_TARGET
CC_FOR_TARGET is xgcc -B into the build tree
The top level picks the target compiler with a macro, GCC_TARGET_TOOL. When
gcc/ is in the tree and the build machine is the host, the macro reports "just
compiled" and sets the variable to the in-tree program
(config/acx.m4:550-585). For the C compiler, that program
is gcc/xgcc -B$$r/$(HOST_SUBDIR)/gcc/
(configure.ac:4059). $$r is the build directory. The
configure rule sets r before it runs anything
(Makefile.in:49463).
newlib's configure receives that compiler as CC, with more flags after it:
CC="$(CC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CC; \
CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
Listing 3.6-4: CC for every target library
(Makefile.tpl:308-309).
XGCC_FLAGS_FOR_TARGET is FLAGS_FOR_TARGET plus the build sysroot and debug
prefix maps (Makefile.tpl:637). The sub-make gets the same
CC again through EXTRA_TARGET_FLAGS (Makefile.tpl:787).
FLAGS_FOR_TARGET: the build tree dressed as an install
When --with-newlib is in target_configargs, the top level fills
FLAGS_FOR_TARGET for every target library. If gcc/ is in the tree, it starts
with -nostdinc (configure.ac:3750-3752). Then, for a cross:
# If we're building newlib, use its generic headers last, but search
# for any libc-related directories first (so make it the last -B
# switch).
FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -B$$r/$(TARGET_SUBDIR)/newlib/ -isystem $$r/$(TARGET_SUBDIR)/newlib/targ-include -isystem $$s/newlib/libc/include'
# If we're building libgloss, find the startup file, simulator library
# and linker script.
case " $target_configdirs " in
*" libgloss "*)
# Look for startup file, simulator library and maybe linker script.
FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -B$$r/$(TARGET_SUBDIR)/libgloss/'"$libgloss_dir"
# Look for libnosys.a in case the target needs it.
FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -L$$r/$(TARGET_SUBDIR)/libgloss/libnosys'
# Most targets have the linker script in the source directory.
FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -L$$s/libgloss/'"$libgloss_dir"
;;
esac
Listing 3.6-5: what every target library compiles with in a newlib tree
(configure.ac:3780-3796).
Read it as two halves.
Headers. -nostdinc drops every standard include directory, GCC's own
included (Chapter 1.10). That also drops
the tooldir include/ under your prefix, where an older newlib may already be
installed (Chapter 1.8). GCC's own headers come
back through the -B in CC_FOR_TARGET. Each -B directory joins
include_prefixes (gcc/gcc.cc:4615-4616), and the %I
directive in cpp_unique_options (gcc.cc:1248-1249) turns
each one that exists into -isystem DIR/include and
-isystem DIR/include-fixed (gcc.cc:6604-6632). It is
Chapter 1.10's -nostdinc -isystem pair, done with -B. The two -isystem
options in Listing 3.6-5 add newlib's configured headers from its build
directory, targ-include/, and its generic headers from the source tree, which
the comment wants searched last.
newlib checks for this half. If CC already names a libc/include directory, it
adds no -I of its own:
# These get added in the top-level configure.in, except in the case where
# newlib is being built natively.
LIBC_INCLUDE_GREP=`echo ${CC} | grep \/libc\/include`
if test -z "${LIBC_INCLUDE_GREP}"; then
CC_FOR_NEWLIB="${CC} -I$PWD/targ-include -I${abs_newlib_basedir}/libc/include"
else
CC_FOR_NEWLIB="${CC}"
fi
Listing 3.6-6: newlib's side of the handshake
(newlib-4.5.0 newlib/configure.ac:334-341).
Libraries. -B$$r/$(TARGET_SUBDIR)/newlib/ makes every library built after
newlib find crt0.o, libc.a and libm.a in newlib's build directory, as if
they were installed. libgloss adds its startup files, libnosys.a, and the
linker scripts in its source directory. What libgloss is, and what libnosys
does, is Chapter 3.4's subject.
A -B directory alone is not enough for a multilib toolchain, because the
driver searches each prefix with the multilib directory appended first. newlib
copies its outputs into a multilib-shaped subdirectory of its build directory
for that reason (newlib-4.5.0 newlib/Makefile.am:78-84), and
its configure.ac explains the copy:
The search directories specified by -B are a bit special, see for_each_path() in gcc.c of the GCC sources. First a search is performed on all search paths with the multilib directory appended (if desired), then a second search is performed on demand with the base directory only.
That is the two-pass search of Chapter 1.6, seen from the library's side.
CFLAGS_FOR_TARGET and --enable-target-optspace
A cross build compiles its target libraries with -g -O2 unless you set
CFLAGS_FOR_TARGET (configure.ac:2895-2897).
The install manual documents --enable-target-optspace under
Configuration: target libraries are optimized for code space
(install.texi:1898-1901). The mechanism is a makefile fragment.
configure selects config/mt-ospace (configure.ac:3098-3117),
the top-level Makefile includes it (Makefile.tpl:650), and
the fragment appends to the flags of every target library:
CFLAGS_FOR_TARGET += -g -Os
CXXFLAGS_FOR_TARGET += -g -Os
Listing 3.6-7: config/mt-ospace (config/mt-ospace:2-3).
The result is -g -O2 -g -Os. The GCC manual documents that the last -O
option wins, under Optimize Options (invoke.texi:12918-12919).
The same flag also reaches newlib's own configure, which adds a second -Os
(newlib-4.5.0 newlib/configure.host:82-85).
That is the general rule for newlib options in a combined tree. The top level
passes most of your --enable-* and --with-* options to every target
library's configure (configure.ac:3473-3611,
:3683), and adds --disable-option-checking
(:3646). So an option such as --enable-newlib-nano-malloc
goes on the GCC top-level command line, and each library that does not know it
ignores it.
The multilib matrix: --print-multi-lib, multilib.out and config-ml.in
Chapter 1.6 left a promise: prune multilibs in GCC and you prune them in newlib. Two pieces of code keep it, one in each project's build.
The top level records the list in multilib.out
Before it configures newlib, the top level asks the new compiler for its variants and compares the answer with the last one:
echo "Checking multilib configuration for newlib..."; \
$(SHELL) $(srcdir)/mkinstalldirs $(TARGET_SUBDIR)/newlib; \
$(CC_FOR_TARGET) --print-multi-lib > $(TARGET_SUBDIR)/newlib/multilib.tmp 2> /dev/null; \
if test -r $(TARGET_SUBDIR)/newlib/multilib.out; then \
if cmp -s $(TARGET_SUBDIR)/newlib/multilib.tmp $(TARGET_SUBDIR)/newlib/multilib.out; then \
rm -f $(TARGET_SUBDIR)/newlib/multilib.tmp; \
else \
rm -f $(TARGET_SUBDIR)/newlib/Makefile; \
mv $(TARGET_SUBDIR)/newlib/multilib.tmp $(TARGET_SUBDIR)/newlib/multilib.out; \
fi; \
else \
mv $(TARGET_SUBDIR)/newlib/multilib.tmp $(TARGET_SUBDIR)/newlib/multilib.out; \
fi; \
test ! -f $(TARGET_SUBDIR)/newlib/Makefile || exit 0; \
Listing 3.6-8: the start of configure-target-newlib
(Makefile.in:49465-49478).
This code does not hand the list to newlib. It decides whether newlib needs a new
configure. If the list changed, the rule deletes newlib's Makefile, and the
test on the last line lets the configure run again. Every target module gets the
same check, from check_multilibs=true in the template
(Makefile.tpl:1174-1188, :1488-1493).
config-ml.in builds one newlib per line
newlib's configure.ac calls AM_ENABLE_MULTILIB(, ..)
(newlib-4.5.0 newlib/configure.ac:316), which runs the shared
top-level script config-ml.in. In a combined tree that is GCC's copy. Its own
header draws the result, with newlib as the example:
# The build tree is layed out as
#
# ./
# newlib
# m68020/
# newlib
# m68881/
# newlib
Listing 3.6-9: one build directory per variant (config-ml.in:54-61).
The directory list comes from ${CC-gcc} --print-multi-lib, with the . line
dropped (config-ml.in:217-229). CC here is the xgcc from
Listing 3.6-4. For each directory, the script finds that directory's line again
and turns its options into compiler flags:
for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
dir=`echo $i | sed -e 's/;.*$//'`
if [ "${dir}" = "${ml_dir}" ]; then
flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`
break
fi
done
ml_config_env='CC="${CC_}$flags" CXX="${CXX_}$flags" F77="${F77_}$flags" GFORTRAN="${GFORTRAN_}$flags" GOC="${GOC_}$flags" GDC="${GDC_}$flags"'
Listing 3.6-10: a -print-multi-lib line becomes CC
(config-ml.in:755-762).
thumb;@mthumb becomes -mthumb, appended to CC. Before that, the script
rewrites every -B, -I or -L argument, and every bare path, that points into
the target build directory, so that it points into the variant's directory
instead (config-ml.in:776-788). So Listing 3.6-5's
-B$$r/arm-none-eabi/newlib/ becomes -B$$r/arm-none-eabi/thumb/newlib/ for the
thumb variant, and each variant links against its own newlib.
make install then puts each variant's libraries in
$(tooldir)/lib$(MULTISUBDIR)
(newlib-4.5.0 newlib/Makefile.am:67-68). That is the tooldir
prefix of Chapter 1.5 with the multilib
directory of Chapter 1.6 appended, so the installed driver finds each variant
where it looks first.
newlib builds exactly the variants that xgcc -print-multi-lib prints, with
exactly the options it prints. The install manual documents
--disable-multilib under Configuration
(install.texi:1298-1302). The top level passes it to gcc/configure and to
every library, so the compiler and newlib agree on one variant.
The switches that prune newlib and not the compiler
The same page lists finer-grained switches for some targets, such as
--disable-fpu and --disable-interwork for arm-*-*
(install.texi:1304-1322). Those switches are read in exactly one place.
config-ml.in turns each --disable-NAME into enable_NAME=no
(config-ml.in:131-134) and then drops matching directories from
the library's list (config-ml.in:234-489). Nothing in
gcc/configure.ac, gcc/config.gcc or the top level reads them. So the
compiler still lists the variant, and newlib does not build it.
On arm-none-eabi, the default multilib set comes from t-arm-elf
(gcc/config.gcc:1497-1504), and it names its two hard-float
variants with a final fpu directory
(gcc/config/arm/t-arm-elf:71-86). Configure with --disable-fpu,
and -print-multi-lib still prints both fpu lines while newlib builds neither.
An option set that selects one of them finds no libc.a in its directory, and
the driver's second pass takes the default variant's libc.a instead
(Chapter 1.6). That is the "surprise link error on an
exotic -m option" that Chapter 3.4 sends here: the compiler and the library
disagree about which variants exist.
Watching it work: -print-multi-lib against the newlib log
These commands need a finished combined build. Nobody ran them at the pin, so no output is shown.
$ gcc/xgcc -Bgcc/ -print-multi-lib
$ cat arm-none-eabi/newlib/multilib.out
$ grep -e 'Configuring in arm-none-eabi/' \
-e 'Running configure in multilib subdirs' build.log
The first two must match line for line, because Listing 3.6-8 wrote the second
from the same command. build.log is your saved make output. The top level
prints "Configuring in" before each target configure
(Makefile.in:49481), and config-ml.in prints the
directory list before it configures the variants
(config-ml.in:664-668). In a serial build, the list that follows
"Configuring in arm-none-eabi/newlib" is newlib's. Every line of
-print-multi-lib except . appears in it, unless one of the switches in the
previous section pruned it.
The nano variant: --enable-newlib-nano-formatted-io and nano.specs
newlib has a small-footprint configuration, called nano. Using it takes two halves that live in different places, and a combined tree supplies only one of them.
The build half is a newlib configure run with
--enable-newlib-nano-malloc and --enable-newlib-nano-formatted-io
(newlib-4.5.0 newlib/configure.ac:232-280). newlib's README
explains what each one changes (newlib-4.5.0 README:336-342).
The link half is a specs file. libgloss installs nano.specs for ARM
(newlib-4.5.0 libgloss/arm/Makefile.inc:7-8), copied
from elf-nano.specs on ELF targets (:81-82):
*cpp_unique_options:
-isystem =/include/newlib-nano %(nano_cpp_unique_options)
*nano_libc:
-lc_nano
Listing 3.6-11: nano.specs, abridged
(newlib-4.5.0 libgloss/arm/elf-nano.specs:5-9).
It expects a libc_nano.a and an include/newlib-nano directory. Nothing in
newlib-4.5.0's build files creates either name. So they must come from a second
newlib build, configured with the nano options and renamed by whoever assembles
the toolchain. A combined tree cannot be that second build. It configures newlib
once, in $(TARGET_SUBDIR)/newlib, so one make produces one newlib. How
%rename and -specs= rewrite the spec table is
Chapter 1.3's subject.
If you do put --enable-newlib-nano-formatted-io on GCC's top-level command
line, the whole newlib in the tree becomes the nano-I/O one, and GCC notices in
one place. The testsuite's newlib_nano_io effective target searches the
"Configured with:" line of gcc -v for that option
(gcc/testsuite/lib/target-supports.exp:10217-10220,
:279-291). The internals manual lists the keyword under
Effective-Target Keywords (sourcebuild.texi:2911-2913).
Chapter 3.7 runs that testsuite.
Three things to carry away
One no_c=true breaks the deadlock. Every target module waits for newlib and
libgloss by default, and the two of them are exempt.
The top level hands newlib everything. The in-tree xgcc, the -B and
-isystem flags that make build directories look installed, and --with-newlib,
which you never typed.
newlib's multilibs are xgcc -print-multi-lib, line for line. Prune the
compiler and you prune newlib. Prune only newlib and the driver links the wrong
variant.
Things that surprise people
newlib's headers never pass through fixincludes. The stmp-fixinc rule runs
inside all-gcc (gcc/Makefile.in:3602-3639, reached from
all.cross through libgcc-support and stmp-int-hdrs,
:2219-2220, :2459,
:3475), before newlib can configure. It scans
$(gcc_tooldir)/sys-include on a cross without a sysroot
(gcc/configure.ac:188, :2537-2545).
newlib installs into the tooldir's include/, not sys-include/.
newlib waits for libgcc. It has no_c but not no_gcc, so libgcc is
configured and built first, before any newlib header exists in the build tree.
A combined tree needs no --with-newlib. The top level passes it to
gcc/configure and to every target library as soon as newlib/configure is in
the tree. Passing it yourself changes nothing on a cross.
Documentation coverage
GCC's manuals document the combined tree for binutils, not for newlib. The
install manual's Downloading the source page says how to link
binutils components into the GCC source directory (install.texi:698-704). For
newlib, the only such instruction is in the nvptx notes on the
Host/target specific installation notes page: "add a symbolic
link to nvptx-newlib's newlib directory to the directory containing the GCC
sources" (install.texi:4684-4687). Building mentions "a C library
in the same source tree as GCC" once, to say what you must supply when you do
not have one (install.texi:3313-3322). Configuration
documents --with-newlib only as omitting __eprintf from libgcc.a
(install.texi:2776-2780), and documents --disable-multilib, the per-target
multilib switches and --enable-target-optspace (:1298-1322, :1898-1901).
-print-multi-lib is in Developer Options
(invoke.texi:21583-21589).
The internals manual sends the reader elsewhere. Its
Top Level Source Directory node says the top-level build
system, "including how recursion into subdirectories works and how building
runtime libraries for multilibs is handled, is documented in a separate manual,
included with GNU Binutils" (sourcebuild.texi:157-160). This chapter reads the
source instead. newlib's own documentation and its README describe
newlib's options and a standalone build after GCC is installed.
What is not documented:
- That newlib is exempt from the default C-library dependency through
no_c=true, and that it still waits forgccand libgcc. - That the top level passes
--with-newlibtogcc/configureand to every target library whennewlib/is in the tree, and thatinhibit_libcis then true on a fresh prefix with no other flag. - That a combined tree installs the
inhibit_libclibgcc. FLAGS_FOR_TARGET: the-nostdinc,-Band-isystemflags that let target libraries use newlib's build directory as if it were installed.- That
config-ml.inbuilds one newlib per-print-multi-libline, and that the top level reconfigures newlib when that list changes. - That the per-target multilib switches act on the libraries only, so the compiler can select a variant that newlib never built.
- That
--enable-target-optspaceappends to the default-O2rather than replacing it. - That newlib's headers are not processed by fixincludes.
Next: the toolchain exists. Chapter 3.7 asks whether it works, and runs GCC's own testsuite against it on a simulator or a board.
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.