On Tue, Jun 9, 2026 at 6:03 AM Kyrylo Tkachov <[email protected]> wrote:
>
> Hi all,
>
> A native "make bootstrap" runs every subdirectory's autoconf configure
> three times, once per stage, because each stage is built in a fresh
> directory (stageN-MODULE is created empty and renamed to MODULE), so the
> per-directory config.cache that the build system already requests with
> --cache-file=./config.cache starts out empty in every stage.  The
> configure scripts are serial, and the host-module configures are
> serialized with respect to each other, so on a machine with many cores
> the configure phases leave it almost completely idle.
>
> Measured on a large multi-core aarch64 machine, a --enable-languages=c,c++
> bootstrap spends about 30% of its wall time in configure and is
> configure-bound at under 15% machine utilization for about 41% of the
> build; the single largest contributor is stage 2 gcc/configure, which
> compiles its test programs with the not-yet-optimized stage 1 compiler.
>
> For a native bootstrap build == host == target, so a module's configure
> test results do not change between stages.  This makes the bootstrapped
> host modules whose configure only probes the host system reuse a
> per-module config.cache across the three stages instead of recomputing
> everything.  The cache file is an absolute path under the build tree
> (stage-config-cache/MODULE.cache) shared by every stage's build
> directory; because the stages run sequentially and each module has its
> own file there is never a concurrent writer.  The ac_cv_env_* environment
> snapshot is stripped before each load so that autoconf's "environment
> changed" check does not abort when CC/CXX/... legitimately differ between
> stages.
>
> Only modules flagged bootstrap_cache in Makefile.def are cached, and only
> for a native build (the recipe compares build/host/target aliases).  The
> in-tree prerequisite libraries (gmp, mpfr, mpc, isl) and gettext are
> intentionally excluded: their configure runs perform cross-library ABI
> link tests and record the compiler version, which do change once the
> bootstrap compiler replaces the system one.  Target libraries are not
> bootstrapped host modules and are unaffected; --disable-bootstrap is
> unaffected as the non-bootstrap configure recipe is untouched.
>
> This roughly halves the time spent in configure (about a 43% reduction)
> and cuts the overall bootstrap wall time by about 15%, with no change in
> the generated configuration: the produced config headers are identical to
> a non-cached build and the stage 2 / stage 3 comparison still succeeds.
> Verified with "make bootstrap”; cross, Canadian and
> --disable-bootstrap builds should be unaffected.
>
> Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux.
> I’d appreciate wider testing on configuration others care about.

I think this is a hack. There seems to be a lot of cleanups in the
configure.ac that might be able to reduce the time spent in configure.
And that would also speed up cross compiling and not just bootstrap.
An example is I filed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125701 for checking for
unordered_map, tr1/unordered_map and ext/hash_map header files. But
since we already require a C++14 compiler (and most of the standard
library), this check is useless.
An example is I filed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125702. Right now we
search for ldopen (NOTE not dlopen) in a few libraries but the only 2
options that matter is empty and `-lld` as the other ones were for
IRIX/MIPS sysv but those support is now removed. We test for 3
libraries/paths which are no longer supported.

So far that is 6 less compiling/linking cases.
There are most likely others which could be cleaned up/removed.
gold support is another example; gold has been deprecated in binutils
for a few years now so maybe it is time to remove support for
bootstrapping with it.

Thanks,
Andrea

> Thanks,
> Kyrill
>
> Signed-off-by: Kyrylo Tkachov <[email protected]>
>
> ChangeLog:
>
>         * Makefile.def: Add bootstrap_cache to the bootstrapped host modules
>         whose configure only probes the host system (gcc, libcpp, libiberty,
>         libdecnumber, libcody, fixincludes, lto-plugin, libbacktrace).
>         * Makefile.tpl: For a bootstrap_cache module in a native bootstrap,
>         point --cache-file at a per-module config.cache shared across stages
>         and strip ac_cv_env_* from it before reuse.  Remove the cache 
> directory
>         in local-distclean.
>         * Makefile.in: Regenerate.
>

Reply via email to