From 4fba38fc35fe2966574dd6bfd68ee82cd354976c Mon Sep 17 00:00:00 2001 From: Sam James Date: Sat, 23 Mar 2024 14:16:38 +0000 Subject: toolchain.eclass: add workaround for hybrid CPUs Hybrid/big.little/PE CPUs may report an inconsistent cache size across cores which can cause GCC's bootstrapping to fail its self-comparison. When CBUILD is amd64 or x86 and -march=native is in CFLAGS, iterate over all cores and record l1-cache-size. If any differ, use the first one we found. Bug: https://gcc.gnu.org/PR111768 Closes: https://bugs.gentoo.org/904426 Closes: https://bugs.gentoo.org/908523 Closes: https://bugs.gentoo.org/915389 Signed-off-by: Sam James --- eclass/toolchain.eclass | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass index f59b8d61f6f5..ec35591ec8fb 100644 --- a/eclass/toolchain.eclass +++ b/eclass/toolchain.eclass @@ -1567,6 +1567,24 @@ gcc_do_filter_flags() { fi fi + declare -A l1_cache_sizes=() + # Workaround for inconsistent cache sizes on hybrid P/E cores + # See PR111768 (and bug #904426, bug #908523, and bug #915389) + if [[ ${CBUILD} == x86_64* || ${CBUILD} == i?86* && ${CFLAGS} == *-march=native* ]] && tc-is-gcc ; then + local x + local l1_cache_size + # Iterate over all cores and find their L1 cache size + for x in $(seq 0 $(($(nproc)-1))) ; do + [[ -z ${x} || ${x} -gt 64 ]] && break + l1_cache_size=$(taskset --cpu-list ${x} $(tc-getCC) -Q --help=params -O2 -march=native \ + | awk '{ if ($1 ~ /^.*param.*l1-cache-size/) print $2; }' || die) + l1_cache_sizes[${l1_cache_size}]=1 + done + # If any of them are different, just pick the first one. + if [[ ${#l1_cache_sizes} != 1 ]] ; then + append-flags --param=l1-cache-size=${l1_cache_size} + fi + fi if ver_test -lt 13.6 ; then # These aren't supported by the just-built compiler either. -- cgit v1.2.3-65-gdbad