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. 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.
0001-Speed-up-native-bootstrap-by-caching-configure-resul.patch
Description: 0001-Speed-up-native-bootstrap-by-caching-configure-resul.patch
