commit:     e897f91e8e81b8168e7045db2f6d8dd9ebdb9ddf
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 24 17:19:46 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Mar 24 17:47:08 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e897f91e

toolchain.eclass: abort if hybrid CPU detected w/ -march=native

Unfortunately, the previous approach can't work. --param doesn't fully
wipe out the previous value added by -march=native, so we still get a failed
comparison.

Users hitting this should install app-misc/resolve-march-native, run
resolve-march-native, and use that in their *FLAGS instead of -march=native -
at least for sys-devel/gcc via package.env, if not in make.conf.

Therefore, our only real option is to just abort when we detect a problematic
situation and tell users what to do.

The only other idea I had was to try taskset in src_compile which feels super
brittle and not sure it'd even work at all.

Thanks to Andrei for testing and debugging with us on IRC & the bug.

Bug: https://bugs.gentoo.org/904426
Bug: https://bugs.gentoo.org/908523
Bug: https://bugs.gentoo.org/915389
Bug: https://bugs.gentoo.org/927688
Thanks-to: Andrei Liavonchykau <andreil499 <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 eclass/toolchain.eclass | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
index 01fbd62dc12c..6a515f9b5c69 100644
--- a/eclass/toolchain.eclass
+++ b/eclass/toolchain.eclass
@@ -1619,9 +1619,16 @@ gcc_do_filter_flags() {
                        [[ -n ${l1_cache_size} && ${l1_cache_size} =~ ^[0-9]+$ 
]] || break
                        l1_cache_sizes[${l1_cache_size}]=1
                done
-               # If any of them are different, just pick the first one.
+               # If any of them are different, abort. We can't just pass one 
value of
+               # l1-cache-size because it doesn't cancel out the -march=native 
one.
                if [[ ${#l1_cache_sizes[@]} -gt 1 ]] ; then
-                       append-flags --param=l1-cache-size=${l1_cache_size}
+                       eerror "Different values of l1-cache-size detected!"
+                       eerror "GCC will fail to bootstrap when comparing files 
with these flags."
+                       eerror "This CPU is likely big.little/hybrid hardware 
with power/efficiency cores."
+                       eerror "Please install app-misc/resolve-march-native 
and run 'resolve-march-native'"
+                       eerror "to find a safe value of CFLAGS for this CPU. 
Note that this may vary"
+                       eerror "depending on the core it ran on. taskset can be 
used to fix the cores used."
+                       die "Varying l1-cache-size found, aborting (bug 
#915389, gcc PR#111768)"
                fi
        fi
 

Reply via email to