From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id CC9601581D3 for ; Sun, 2 Jun 2024 08:22:30 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1C957E2AE3; Sun, 2 Jun 2024 08:22:30 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D6CB9E2AE3 for ; Sun, 2 Jun 2024 08:22:29 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CC57233D3CF for ; Sun, 2 Jun 2024 08:22:28 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6994F19F3 for ; Sun, 2 Jun 2024 08:22:27 +0000 (UTC) From: "Ionen Wolkens" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ionen Wolkens" Message-ID: <1717316527.3373a27c24cd4b06084f8e0ac9fb9d2a695ac214.ionen@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/qt6-build.eclass X-VCS-Directories: eclass/ X-VCS-Committer: ionen X-VCS-Committer-Name: Ionen Wolkens X-VCS-Revision: 3373a27c24cd4b06084f8e0ac9fb9d2a695ac214 X-VCS-Branch: master Date: Sun, 2 Jun 2024 08:22:27 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 554aee5c-afca-4e94-8d57-b33e8ab8941d X-Archives-Hash: e1eb13516a40571fff2764b89d2def81 commit: 3373a27c24cd4b06084f8e0ac9fb9d2a695ac214 Author: Ionen Wolkens gentoo org> AuthorDate: Sun Jun 2 07:08:01 2024 +0000 Commit: Ionen Wolkens gentoo org> CommitDate: Sun Jun 2 08:22:07 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3373a27c qt6-build.eclass: use different workaround for cpu flags issues This also replaces the nasty workaround from qtbase's ebuild on top of the function here. Should "hopefully" be far less error prone, while still allowing -march=native for people who aren't affected. Does mean slightly worse optimizations for those affected, but this still tries to use the highest x86-64-v* and should be insignificant. Tentative, can't fully test without having an affected cpu so may still need work. Closes: https://bugs.gentoo.org/933374 Signed-off-by: Ionen Wolkens gentoo.org> eclass/qt6-build.eclass | 87 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 29 deletions(-) diff --git a/eclass/qt6-build.eclass b/eclass/qt6-build.eclass index 4fc838c478af..4966c52adc4c 100644 --- a/eclass/qt6-build.eclass +++ b/eclass/qt6-build.eclass @@ -122,7 +122,7 @@ qt6-build_src_prepare() { fi _qt6-build_prepare_env - _qt6-build_match_cpu_flags + _qt6-build_sanitize_cpu_flags # LTO cause test failures in several components (e.g. qtcharts, # multimedia, scxml, wayland, webchannel, ...). @@ -235,34 +235,6 @@ _qt6-build_create_user_facing_links() { done < "${BUILD_DIR}"/user_facing_tool_links.txt || die } -# @FUNCTION: _qt6-build_match_cpu_flags -# @INTERNAL -# @DESCRIPTION: -# Try to adjust -m* cpu CXXFLAGS so that they match a configuration -# accepted by Qt's headers, see bug #908420. -_qt6-build_match_cpu_flags() { - use amd64 || use x86 || return 0 - - local flags=() intrin intrins - while IFS=' ' read -ra intrins; do - [[ ${intrins[*]} == *=[^_]* && ${intrins[*]} == *=_* ]] && - for intrin in "${intrins[@]%=*}"; do - [[ ${intrin} ]] && flags+=( -mno-${intrin} ) - done - done < <( - $(tc-getCXX) -E -P ${CXXFLAGS} ${CPPFLAGS} - <<-EOF | tail -n 2 - avx2=__AVX2__ =__BMI__ =__BMI2__ =__F16C__ =__FMA__ =__LZCNT__ =__POPCNT__ - avx512f=__AVX512F__ avx512bw=__AVX512BW__ avx512cd=__AVX512CD__ avx512dq=__AVX512DQ__ avx512vl=__AVX512VL__ - EOF - assert - ) - - if (( ${#flags[@]} )); then - einfo "Adjusting CXXFLAGS for https://bugs.gentoo.org/908420 with: ${flags[*]}" - append-cxxflags "${flags[@]}" - fi -} - # @FUNCTION: _qt6-build_prepare_env # @INTERNAL # @DESCRIPTION: @@ -289,6 +261,63 @@ _qt6-build_prepare_env() { readonly QT6_TRANSLATIONDIR=${QT6_DATADIR}/translations } +# @FUNCTION: _qt6-build_sanitize_cpu_flags +# @INTERNAL +# @DESCRIPTION: +# Qt hardly support use of -mno-* or -march=native for unusual CPUs +# (or VMs) that support incomplete x86-64 feature levels, and attempts +# to allow this anyway has worked poorly. This instead tries to detect +# unusual configurations and fallbacks to generic -march=x86-64* if so +# (bug #898644,#908420,#913400,#933374). +_qt6-build_sanitize_cpu_flags() { + # less of an issue with non-amd64, will revisit only if needed + use amd64 || return 0 + + local cpuflags=( + # list of checked cpu features by qtbase in configure.cmake + aes avx avx2 avx512{bw,cd,dq,er,f,ifma,pf,vbmi,vbmi2,vl} + f16c rdrnd rdseed sha sse2 sse3 sse4_1 sse4_2 ssse3 vaes + + # extras checked by qtbase's qsimd_p.h + bmi bmi2 f16c fma lzcnt popcnt + ) + + # 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 + fi + + # determine highest(known) usable x86-64 feature level + local march=$( + $(tc-getCXX) -E -P ${CXXFLAGS} ${CPPFLAGS} - <<-EOF | tail -n 1 + default + #if (__CRC32__ + __LAHF_SAHF__ + __POPCNT__ + __SSE3__ + __SSE4_1__ + __SSE4_2__ + __SSSE3__) == 7 + x86-64-v2 + # if (__AVX__ + __AVX2__ + __BMI__ + __BMI2__ + __F16C__ + __FMA__ + __LZCNT__ + __MOVBE__ + __XSAVE__) == 9 + x86-64-v3 + # if (__AVX512BW__ + __AVX512CD__ + __AVX512DQ__ + __AVX512F__ + __AVX512VL__ + __EVEX256__ + __EVEX512__) == 7 + x86-64-v4 + # endif + # endif + #endif + EOF + assert + ) + + 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}" +} + fi EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_test src_install