This is somewhat similar to bug #333763, except that it affects C*FLAGS. The reporter has: CFLAGS='-flto' and the ebuild needs to be built using sys-devel/clang, so it calls strip-unsupported-flags. However, this function does not verify whether the flags work at link time, so '-flto' is not stripped. As a result, the build fails due to '-flto' failing at link time.
I'm not sure strip-unsupported-flags() should fix misconfigured systems. It's main purpose is to remove unrecognised/individual non-working flags. Flag interactions are always complex (like -m32/-m64 misconfiguration across CFLAGS/LDFLAGS). If lto is consistently broken I would expect every package merge to fail with CFLAGS=-flto. Whether package calls strip-unsupported-flags() or not. We could add a special case for -flto similar to below: --- a/eclass/flag-o-matic.eclass +++ b/eclass/flag-o-matic.eclass @@ -618,6 +618,9 @@ test_version_info() { # @DESCRIPTION: # Strip {C,CXX,F,FC}FLAGS of any flags not supported by the active toolchain. strip-unsupported-flags() { + if ! test-flag-CCLD -flto; then + filter-flags '-flto*' + fi export CFLAGS=$(test-flags-CC ${CFLAGS}) export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS}) export FFLAGS=$(test-flags-F77 ${FFLAGS}) But it will be too conservative for cases like CFLAGS=-ffat-lto-objects where -flto linker support should not matter as much. Individual ebuild might be a better place for such workarounds.