• [gentoo-dev] [PATCH] dot-a.eclass: make strip-lto remember if guarantee

    From Eli Schwartz@21:1/5 to All on Fri Jul 4 05:30:01 2025
    The current implementation checks repeatedly if `tc-is-lto` is true. In addition to running a small compile check redundantly, this has a
    potential correctness downside. An ebuild could do this:

    ```
    lto-guarantee-fat
    tc-is-lto && myeconfargs+=( --enable-lto )
    filter-lto
    ```

    The idea is, the configure script has special handling and simply adding
    -flto is too "simple" to work. e.g. not all sources build with LTO.

    When this happens, strip-lto-bytecode "thinks" we didn't build with LTO
    at all, and returns early. By tracking state across functions -- and
    across phases -- we can reliably tell if `lto-guarantee-fat` actually "succeeded".

    Bug: https://bugs.gentoo.org/958412
    Acked-by: Sam James <sam@gentoo.org>
    Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
    ---
    eclass/dot-a.eclass | 11 ++++++++++-
    1 file changed, 10 insertions(+), 1 deletion(-)

    diff --git a/eclass/dot-a.eclass b/eclass/dot-a.eclass
    index ffd34d9e08aa..8d866e6dedb2 100644
    --- a/eclass/dot-a.eclass
    +++ b/eclass/dot-a.eclass
    @@ -50,6 +50,12 @@ _DOT_A_ECLASS=1

    inherit flag-o-matic toolchain-funcs

    +# @VARIABLE: _DOT_A_IS_LTO
    +# @INTERNAL
    +# @DESCRIPTION:
    +# Records the state of tc-is-lto across eclass function calls. +_DOT_A_IS_LTO=0
    +
    # TODO: QA check

    # @FUNCTION: lto-guarantee-fat
    @@ -59,6 +65,7 @@ inherit flag-o-matic toolchain-funcs
    lto-guarantee-fat() {
    tc-is-lto || return

    + _DOT_A_IS_LTO=1
    # We add this for all languages as LTO obviously can't be done
    # if different compilers are used for e.g. C vs C++ anyway.
    append-flags $(test-flags-CC -ffat-lto-objects)
    @@ -73,7 +80,9 @@ lto-guarantee-fat() {
    # As an optimisation, if USE=static-libs exists for a package and is disabled,
    # the default-searching behaviour with no arguments is suppressed.
    s