commit:     bb2d045c02a6ca647ef3280f4987cbc0d14e5a7e
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Sep 28 23:27:06 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Sep 30 09:38:40 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=bb2d045c

toolchain.eclass: rework bootstrapping logic

* Build stage1 compiler with user's CFLAGS. This consistently ends up
  saving at least 15 minutes for me on a fast amd64 machine and should save
  more on slower machines and architectures.

  There's only any risk here if the host compiler is ancient/very buggy and
  even then, you get a failed bootstrap later on. The GCC developers, per the
  linked bug, end up using STAGE1_CFLAGS="-O2" anyway to speed up the process
  so it's not like this is untested at all.

  mattst88 actually brought this up.. 10 years ago (bug #477548). Let's try
  make that right now.

* Respect LDFLAGS for target libraries for native builds. Not touching this
  for cross builds, at least for now, as it's a bit more delicate.

  (Unfortunately, we have to put a hack in here for now until we can fix
  multilib.eclass - see bug #914881).

Bug: https://gcc.gnu.org/PR111619
Bug: https://bugs.gentoo.org/914881
Closes: https://bugs.gentoo.org/477548
Closes: https://bugs.gentoo.org/831423
Closes: https://bugs.gentoo.org/840392
Apologies-to: Matt Turner <mattst88 <AT> gentoo.org>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 eclass/toolchain.eclass | 52 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
index d93068619cf9..a145e74d5521 100644
--- a/eclass/toolchain.eclass
+++ b/eclass/toolchain.eclass
@@ -1647,19 +1647,48 @@ gcc_do_make() {
                fi
        fi
 
-       if [[ ${GCC_MAKE_TARGET} == "all" ]] ; then
-               STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"}
-       fi
+       local emakeargs=(
+               LDFLAGS="${LDFLAGS}"
+               LIBPATH="${LIBPATH}"
+       )
 
        if is_crosscompile; then
                # In 3.4, BOOT_CFLAGS is never used on a crosscompile...
                # but I'll leave this in anyways as someone might have had
                # some reason for putting it in here... --eradicator
                BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"}
+               emakeargs+=( BOOT_CFLAGS="${BOOT_CFLAGS}" )
        else
-               # we only want to use the system's CFLAGS if not building a
+               # XXX: Hack for bug #914881, clean this up when fixed and go 
back
+               # to just calling get_abi_LDFLAGS as before.
+               local abi_ldflags="$(get_abi_LDFLAGS ${TARGET_DEFAULT_ABI})"
+               printf -v abi_ldflags -- "-Wl,%s " ${abi_ldflags}
+
+               # If the host compiler is too old, let's use -O0 per the 
upstream
+               # default to be safe (to avoid a bootstrap comparison failure 
later).
+               #
+               # The last known issues are with < GCC 4.9 or so, but it's 
easier
+               # to keep this bound somewhat fresh just to avoid problems. 
Ultimately,
+               # using not-O0 is just a build-time speed improvement anyway.
+               if tc-is-gcc && ver_test $(gcc-fullversion) -lt 10 ; then
+                       STAGE1_CFLAGS="-O0"
+               fi
+
+               # We only want to use the system's CFLAGS if not building a
                # cross-compiler.
+               STAGE1_CFLAGS=${STAGE1_CFLAGS-"$(get_abi_CFLAGS 
${TARGET_DEFAULT_ABI}) ${CFLAGS}"}
+               STAGE1_LDFLAGS=${STAGE1_LDFLAGS-"${abi_ldflags} ${LDFLAGS}"}
                BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS 
${TARGET_DEFAULT_ABI}) ${CFLAGS}"}
+               BOOT_LDFLAGS=${BOOT_LDFLAGS-"${abi_ldflags} ${LDFLAGS}"}
+               LDFLAGS_FOR_TARGET="${LDFLAGS_FOR_TARGET:-${LDFLAGS}}"
+
+               emakeargs+=(
+                       STAGE1_CFLAGS="${STAGE1_CFLAGS}"
+                       STAGE1_LDFLAGS="${STAGE1_LDFLAGS}"
+                       BOOT_CFLAGS="${BOOT_CFLAGS}"
+                       BOOT_LDFLAGS="${BOOT_LDFLAGS}"
+                       LDFLAGS_FOR_TARGET="${LDFLAGS_FOR_TARGET}"
+               )
        fi
 
        if is_jit ; then
@@ -1667,24 +1696,13 @@ gcc_do_make() {
                pushd "${WORKDIR}"/build-jit > /dev/null || die
 
                einfo "Building JIT"
-               emake \
-                       LDFLAGS="${LDFLAGS}" \
-                       STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
-                       LIBPATH="${LIBPATH}" \
-                       BOOT_CFLAGS="${BOOT_CFLAGS}"
+               emake "${emakeargs[@]}"
                popd > /dev/null || die
        fi
 
        einfo "Compiling ${PN} (${GCC_MAKE_TARGET})..."
-
        pushd "${WORKDIR}"/build >/dev/null || die
-
-       emake \
-               LDFLAGS="${LDFLAGS}" \
-               STAGE1_CFLAGS="${STAGE1_CFLAGS}" \
-               LIBPATH="${LIBPATH}" \
-               BOOT_CFLAGS="${BOOT_CFLAGS}" \
-               ${GCC_MAKE_TARGET}
+       emake "${emakeargs[@]}" ${GCC_MAKE_TARGET}
 
        if is_ada; then
                # Without these links, it is not getting the good compiler

Reply via email to