commit:     e91760a3bbc3d9267fb0bfd018b8af834e0b4286
Author:     Ionen Wolkens <ionen <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 19 12:49:43 2024 +0000
Commit:     Ionen Wolkens <ionen <AT> gentoo <DOT> org>
CommitDate: Sat Oct 19 13:47:15 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e91760a3

qt6-build.eclass: extend -m* flags sanitizing

A user on the forums reported a build failure with:
`-march=znver4 -mavx512vp2intersect`

On its own, there is no issue there (expanded from -march=native) but
when Qt passes `-march=haswell` to build certain parts (e.g. avx2 bits
for runtime detection regardless of what CHOST supports), it overrides
znver4 and keeps -mavx512vp2intersect resulting in an incomplete set
and then qsimd_p.h complains

Do not plan to pursue this myself, but this specific issue could
be improved upstream by passing -mavx2 and others rather than
-march=haswell (this would also allow overriding a -mno-avx2 that
we currently need to change), and/or ideally by making qsimd_p.h
be able to deal with these configurations without #error.

If problems keep piling up, could consider always filtering *all*
-m{,no-}<instr> flags and doing x86-64-v* unconditionally. Albeit
that'd still require maintaining a list of these not to filter
unrelated -m* flags which could be important.

Signed-off-by: Ionen Wolkens <ionen <AT> gentoo.org>

 eclass/qt6-build.eclass | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/eclass/qt6-build.eclass b/eclass/qt6-build.eclass
index c6b8db578f46..2dec4b7ec14e 100644
--- a/eclass/qt6-build.eclass
+++ b/eclass/qt6-build.eclass
@@ -301,18 +301,31 @@ _qt6-build_sanitize_cpu_flags() {
                fma4 sse4a
        )
 
+       # extras for which -mno-* does not matter, but can lead to enabling
+       # other flags when set and breaking the -march=haswell case below
+       # (add more as needed if users use these)
+       local cpuflags_filter_only=(
+               avx512vp2intersect
+       )
+
        # check if any known problematic -mno-* C(XX)FLAGS
        if ! is-flagq "@($(IFS='|'; echo "${cpuflags[*]/#/-mno-}"))"; then
-               # check if qsimd_p.h (search for "enable all") will accept 
-march
-               : "$($(tc-getCXX) -E -P ${CXXFLAGS} ${CPPFLAGS} - <<-EOF | tail 
-n 1
-                               #if (defined(__AVX2__) && (__BMI__ + __BMI2__ + 
__F16C__ + __FMA__ + __LZCNT__ + __POPCNT__) != 6) || \
-                                       (defined(__AVX512F__) && (__AVX512BW__ 
+ __AVX512CD__ + __AVX512DQ__ + __AVX512VL__) != 4)
-                               bad
-                               #endif
-                       EOF
-                       assert
-               )"
-               [[ ${_} == bad ]] || return 0 # *should* be fine as-is
+               # check if qsimd_p.h (search for "enable all") will accept 
-march, and
+               # further check when -march=haswell is appended (which Qt uses 
for some
+               # parts) given combination with other -m* could lead to partial 
support
+               local bad flags
+               for flags in '' '-march=haswell'; do
+                       : "$($(tc-getCXX) -E -P ${CXXFLAGS} ${CPPFLAGS} 
${flags} - <<-EOF | tail -n 1
+                                       #if (defined(__AVX2__) && (__BMI__ + 
__BMI2__ + __F16C__ + __FMA__ + __LZCNT__ + __POPCNT__) != 6) || \
+                                               (defined(__AVX512F__) && 
(__AVX512BW__ + __AVX512CD__ + __AVX512DQ__ + __AVX512VL__) != 4)
+                                       bad
+                                       #endif
+                               EOF
+                               assert
+                       )"
+                       [[ ${_} == bad ]] && bad=1 && break
+               done
+               [[ -v bad ]] || return 0 # *should* be fine as-is
        fi
 
        # determine highest(known) usable x86-64 feature level
@@ -332,6 +345,7 @@ _qt6-build_sanitize_cpu_flags() {
                assert
        )
 
+       cpuflags+=("${cpuflags_filter_only[@]}")
        filter-flags '-march=*' "${cpuflags[@]/#/-m}" "${cpuflags[@]/#/-mno-}"
        [[ ${march} == x86-64* ]] && append-flags $(test-flags-CXX 
-march=${march})
        einfo "C(XX)FLAGS were adjusted due to Qt limitations: ${CXXFLAGS}"

Reply via email to