Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 915389 - sys-devel/gcc-13.2.1_p20230826: bootstrap stage failed with "-O3" (---param=l1-cache-size differs between stage2 and stage3)
Summary: sys-devel/gcc-13.2.1_p20230826: bootstrap stage failed with "-O3" (---param=l...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords: PullRequest
: 927718 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-10-08 17:48 UTC by Andrei Liavonchykau
Modified: 2024-03-27 20:23 UTC (History)
14 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
temp directory with build artifacts (log, etc) (temp.tar.xz,185.16 KB, application/octet-stream)
2023-10-08 19:31 UTC, Andrei Liavonchykau
Details
"emerge --info" output (info.txt,7.58 KB, text/plain)
2023-10-08 20:31 UTC, Andrei Liavonchykau
Details
build logs (gcc-build-logs.tar.xz,260.03 KB, application/x-xz)
2023-10-08 21:01 UTC, Andrei Liavonchykau
Details
Result from resolv-march-native, running 20k over a loop (resolv-march-native.log.gz,13.23 KB, application/gzip)
2023-10-11 03:22 UTC, Marcos Rodrigues Gonzalez
Details
Build logs (gcc-build-logs.tar.xz,270.37 KB, application/x-xz)
2023-11-27 16:50 UTC, Andrei Liavonchykau
Details
lscpu -p (lscpu-p.txt,499 bytes, text/plain)
2024-03-23 14:09 UTC, Marcos Rodrigues Gonzalez
Details
cat /proc/cpuinfo (cpuinfo.txt,26.24 KB, text/plain)
2024-03-23 14:09 UTC, Marcos Rodrigues Gonzalez
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Liavonchykau 2023-10-08 17:48:10 UTC
With latest version of ebuilds (and eclesses) I try to build system with "-O2" flag and get bootratap error for compiler.

Reproducible: Always

Steps to Reproduce:
1. Set COMMON_FLAGS="-O3 -pipe -march=native" into /etc/portage/make.conf
2. Run command "emerge -avO sys-devel/gcc"
Actual Results:  
Botstrap stage failed.

Expected Results:  
Bootstrap stage ok.
Comment 1 Andrei Liavonchykau 2023-10-08 17:51:44 UTC
"emerge --info" output - into "URL" field of bug information.
Comment 2 Andrei Liavonchykau 2023-10-08 19:31:34 UTC
Created attachment 872353 [details]
temp directory with build artifacts (log, etc)
Comment 3 Greg Kubaryk 2023-10-08 20:23:54 UTC
(In reply to Andrei Liavonchykau from comment #1)
> "emerge --info" output - into "URL" field of bug information.

emerge --info output needs to be a comment on this bug
Comment 4 Andrei Liavonchykau 2023-10-08 20:31:54 UTC
Created attachment 872356 [details]
"emerge --info" output
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-08 20:57:23 UTC
(In reply to Andrei Liavonchykau from comment #2)
> Created attachment 872353 [details]
> temp directory with build artifacts (log, etc)

Please include the tarball it mentions at the end of build.log:
> [31;01m*[0m Please include /var/tmp/portage/sys-devel/gcc-13.2.1_p20230826/work/gcc-build-logs.tar.xz in your bug report.

I might need you to upload some of the differing files as well but we can do that in a minute.
Comment 6 Andrei Liavonchykau 2023-10-08 21:01:31 UTC
Created attachment 872357 [details]
build logs
Comment 7 Andrei Liavonchykau 2023-10-08 21:02:58 UTC
(In reply to Sam James from comment #5)
> (In reply to Andrei Liavonchykau from comment #2)
> > Created attachment 872353 [details]
> > temp directory with build artifacts (log, etc)
> 
> Please include the tarball it mentions at the end of build.log:
> > [31;01m*[0m Please include /var/tmp/portage/sys-devel/gcc-13.2.1_p20230826/work/gcc-build-logs.tar.xz in your bug report.
> 
> I might need you to upload some of the differing files as well but we can do
> that in a minute.

Done.

P.S.: I’m having trouble thinking at night, I’m still trying to fix a complex dependency of 5 packages...
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-08 21:47:41 UTC
Could you find *both* versions of the following (I've picked a subset of the list of differing files in the log):

gcc/crtfastmath.o differs
gcc/32/crtprec80.o differs
gcc/32/crtprec64.o differs
x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/atomicity.o differs
x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/tinfo2.o differs
x86_64-pc-linux-gnu/32/libgcc/eqhf2.o differs
x86_64-pc-linux-gnu/32/libgcc/trunchfbf2.o differs
x86_64-pc-linux-gnu/32/libgcc/truncsfbf2.o differs
x86_64-pc-linux-gnu/libgcc/eqtf2_s.o differs
x86_64-pc-linux-gnu/libgcc/eqhf2_s.o differs
x86_64-pc-linux-gnu/libgcc/floatuntibf_s.o differs
x86_64-pc-linux-gnu/libgcc/floattihf_s.o differs

in a tarball where you put the old variants in old/, and the newer ones in new/?

(All the old versions of e.g. crtfastmath.o should be under one diff. directory for stage2, then a newer version in another dir for stage3)

We should really add some helper to the eclass to do this
Comment 9 Andrei Liavonchykau 2023-10-08 22:22:29 UTC
Ugh, limitation to posting the link... Pls, remove spaces ;)
All "work/build" directory:
https : // drive.google.com /file/d/1zm-5TK3-ciz0i_1c2jNtkZtif_TnM9sT/view?usp=sharing
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-09 00:57:34 UTC
Could you try attach it here as a tarball?
Comment 11 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-09 00:58:20 UTC
(In reply to Sam James from comment #10)
> Could you try attach it here as a tarball?

nevermind, I see it's too big.
Comment 12 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-09 01:06:48 UTC
Okay, this looks familiar, actually.

```
$ diffoscope ./stage2-x86_64-pc-linux-gnu/32/libgcc/eqhf2.o ./stage3-x86_64-pc-linux-gnu/32/libgcc/eqhf2.o
```
[...]
│ -  [    33]  GNU C17 13.2.1 20230826 -march=alderlake -mmmx -mpopcnt -msse -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mpku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mshstk -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex --param=l1-cache-size=48 --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -m32 -mlong-double-80 -msse2 -g -g -g -O2 -O3 -O2 -O2 -O3 -fbuilding-libgcc -fno-stack-protector -fno-stack-clash-protection -fpic -fvisibility=hidden
│ -  [   578]  _Float16
│ -  [   581]  _FP_UNPACK_RAW_1_flo
│ -  [   596]  long long unsigned int
│ -  [   5ad]  sign
│ -  [   5b2]  _fcw
│ +  [    33]  _Float16
│ +  [    3c]  _FP_UNPACK_RAW_1_flo
│ +  [    51]  long long unsigned int
│ +  [    68]  sign
│ +  [    6d]  _fcw
│ +  [    72]  GNU C17 13.2.1 20230826 -march=alderlake -mmmx -mpopcnt -msse -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mpku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mshstk -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex --param=l1-cache-size=32 --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -m32 -mlong-double-80 -msse2 -g -g -g -O2 -O3 -O2 -O2 -O3 -fbuilding-libgcc -fno-stack-protector -fno-stack-clash-protection -fpic -fvisibility=hidden
[...]
```

$ wdiff /tmp/a /tmp/b
<d>   DW_AT_producer    : (strp) (offset: [-0x33):-] {+0x72):+} GNU C17 13.2.1 20230826 -march=alderlake -mmmx -mpopcnt -msse -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mpku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mshstk -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex [---param=l1-cache-size=48-] {+--param=l1-cache-size=32+} --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -m32 -mlong-double-80 -msse2 -g -g -g -O2 -O3 -O2 -O2 -O3 -fbuilding-libgcc -fno-stack-protector -fno-stack-clash-protection -fpic -fvisibility=hidden

We have two differences:
* the offset (let's ignore that)
* l1 cache size: [---param=l1-cache-size=48-] {+--param=l1-cache-size=32+}
Comment 13 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-09 01:17:06 UTC
In bug 904426, we had both the same cache size problem but specifically involving alderlake too.
Comment 14 Andrei Liavonchykau 2023-10-09 08:16:52 UTC
(In reply to Sam James from comment #13)
> In bug 904426, we had both the same cache size problem but specifically
> involving alderlake too.

Hm, thanks for information - this is work for me - change "-march=native" to "-march=alderlake -mabm -mno-cldemote -mno-kl -mno-sgx -mno-widekl -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=48 --param=l2-cache-size=24576" (from output of command 'resolve-march-native').
Comment 15 Paul Zander 2023-10-09 20:48:34 UTC
Alder Lake and Raptor Lake CPUs employ a hybrid architecture with two different cores (named P- and E-cores). They differ in performance and power consumption, and most importantly here cache sizes. The datasheets for Alder Lake [1] and Raptor Lake [2] list the cache sizes as:

> L1 Data cache (DCU) - 48KB (P-core) - 32KB (E-Core)
> L1 Instruction cache (IFU) - 32KB (P-Core) - 64KB (E-Core)
> MLC - Mid Level Cache - 1.25MB (P-Core) - 2MB (shared by 4 E-Cores)

Looking at the observed differences in `--param=l1-cache-size` it seems reasonable to assume that `-march=native` resolution ran once on a P-core and once on a E-core.

This needs to be fixed upstream.

Stop-gap solutions include:
- using resolve-march-native
- disable e-cores
- changing cpu affinity, pinning -march=native resolution the same core type in all stages.


[1] https://edc.intel.com/content/www/us/en/design/ipla/software-development-platforms/client/platforms/alder-lake-desktop/12th-generation-intel-core-processors-datasheet-volume-1-of-2/ia-cores-level-1-and-level-2-caches/

[2] https://edc.intel.com/content/www/us/en/design/products/platforms/details/raptor-lake-s/13th-generation-core-processors-datasheet-volume-1-of-2/003/ia-cores-level-1-and-level-2-caches/
Comment 16 Paul Zander 2023-10-09 21:53:39 UTC
Microcode version and lack of updates might effect the outcome as well.

Early Alder Lake CPUs reported different CPUIDs for P- and E-Cores.

There might be changes to the scheduling between different cores (see Intel Thread Director). At the moment it looks like stage 3 is started on the "cooler" E-cores (see L1 Data Cache size going from 48 KB to 32 KB).
Comment 17 Marcos Rodrigues Gonzalez 2023-10-11 03:22:05 UTC
Created attachment 872522 [details]
Result from resolv-march-native, running 20k over a loop

Discusing on -chat about it, we ran a loop of the resolv-march-native command on an alder lake box, and it returned the l1-cache-size=32 instead of 48, 41 times (in a loop of 20000).
Comment 18 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-11 10:12:46 UTC
Filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111768 upstream.
Comment 19 Paul Zander 2023-10-11 10:13:54 UTC
ht Flow: same cause https://www.mono-project.com/news/2016/09/12/arm64-icache/
Comment 20 Andrei Liavonchykau 2023-10-11 11:06:01 UTC
Hi, Sam.
On my case, this is Raptor Lake arch. Into GCC bugzilla, you fill only a Alder Lake arch.
Comment 21 Larry the Git Cow gentoo-dev 2023-11-26 23:18:43 UTC Comment hidden (obsolete)
Comment 22 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-11-26 23:19:24 UTC
Sorry, I didn't mean to close this (tagged wrong bug).

(In reply to Andrei Liavonchykau from comment #20)
> Hi, Sam.
> On my case, this is Raptor Lake arch. Into GCC bugzilla, you fill only a
> Alder Lake arch.

Thanks, this is fine though, it's about the general principle of hybrid CPUs.
Comment 23 Andrei Liavonchykau 2023-11-27 16:50:07 UTC
Hi, Sam.
I sync portage, try to build sys-devel/gcc-14.0.0_pre20231126 with "-march=native" option and get same error
Comment 24 Andrei Liavonchykau 2023-11-27 16:50:45 UTC
Created attachment 875829 [details]
Build logs
Comment 25 Andrei Liavonchykau 2023-11-27 17:05:34 UTC
$ diffoscope stage2-x86_64-pc-linux-gnu/libgcc/_gcov_fork.o stage3-x86_64-pc-linux-gnu/libgcc/_gcov_fork.o

[...]
│ -  [    35]  GNU C17 14.0.0 20231126 (experimental) -march=alderlake -mmmx -mpopcnt -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mpku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mshstk -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex -mno-avxvnniint16 -mno-sm3 -mno-sha512 -mno-sm4 -mno-apxf -musermsr --param=l1-cache-size=32 --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -mlong-double-80 -g -g -g -O2 -O3 -O2 -O2 -O3 -fbuilding-libgcc -fno-stack-protector -fno-stack-clash-protection -fpic
│ -  [   5b4]  __data
│ -  [   5bb]  pid_t
│ -  [   5c1]  __pthread_mutex_s
│ -  [   5d3]  __owner
│ -  [   5db]  __kind
│ -  [   5e2]  pthread_mutex_t
│ -  [   5f2]  __lock
│ -  [   5f9]  __size
│ -  [   600]  unsigned char
│ -  [   60e]  __gcov_fork
│ -  [   61a]  long unsigned int
│ +  [    35]  __data
│ +  [    3c]  pid_t
│ +  [    42]  __pthread_mutex_s
│ +  [    54]  __owner
│ +  [    5c]  __kind
│ +  [    63]  pthread_mutex_t
│ +  [    73]  __lock
│ +  [    7a]  __size
│ +  [    81]  unsigned char
│ +  [    8f]  __gcov_fork
│ +  [    9b]  long unsigned int
│ +  [    ad]  GNU C17 14.0.0 20231126 (experimental) -march=alderlake -mmmx -mpopcnt -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mpku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mshstk -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex -mno-avxvnniint16 -mno-sm3 -mno-sha512 -mno-sm4 -mno-apxf -musermsr --param=l1-cache-size=48 --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -mlong-double-80 -g -g -g -O2 -O3 -O2 -O2 -O3 -fbuilding-libgcc -fno-stack-protector -fno-stack-clash-protection -fpic
[...]
Comment 26 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-11-28 07:26:47 UTC
Sorry, to be clear, I accidentally tagged this bug with a typo for another issue and it's definitely not fixed. Just pretend that didn't happen - sorry for the noise!
Comment 27 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-23 13:33:09 UTC
Could someone with a hybrid CPU show me:
* cat /proc/cpuinfo
* lscpu -p

Thanks
Comment 28 Marcos Rodrigues Gonzalez 2024-03-23 14:09:07 UTC
Created attachment 888275 [details]
lscpu -p
Comment 29 Marcos Rodrigues Gonzalez 2024-03-23 14:09:49 UTC
Created attachment 888276 [details]
cat /proc/cpuinfo
Comment 30 Marcos Rodrigues Gonzalez 2024-03-23 14:11:04 UTC
(In reply to Sam James from comment #27)
> Could someone with a hybrid CPU show me:
> * cat /proc/cpuinfo
> * lscpu -p
> 
> Thanks

Hey, Sam, please check if this is it.
Comment 31 Larry the Git Cow gentoo-dev 2024-03-23 14:49:12 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4fba38fc35fe2966574dd6bfd68ee82cd354976c

commit 4fba38fc35fe2966574dd6bfd68ee82cd354976c
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-03-23 14:16:38 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-03-23 14:48:47 +0000

    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 <sam@gentoo.org>

 eclass/toolchain.eclass | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Comment 32 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-23 16:27:25 UTC
Thank you everyone for helping.
Comment 33 Larry the Git Cow gentoo-dev 2024-03-24 14:05:42 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f64da62e50ad607de3a95b6a1d0d2ed8ba8bd268

commit f64da62e50ad607de3a95b6a1d0d2ed8ba8bd268
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-03-24 14:05:00 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-03-24 14:05:31 +0000

    toolchain.eclass: improve hybrid check
    
    Thanks to stikonas for debugging on IRC.
    
    Bug: https://bugs.gentoo.org/904426
    Bug: https://bugs.gentoo.org/908523
    Bug: https://bugs.gentoo.org/915389
    Signed-off-by: Sam James <sam@gentoo.org>

 eclass/toolchain.eclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 34 Andrei Liavonchykau 2024-03-24 15:10:19 UTC
Hi, Sam.
I try to build a GCC with this WA, but it's still failing. On "build.log" I see a additional flags:
> >>> Configuring source in /var/tmp/portage/sys-devel/gcc-13.2.1_p20240210/work/gcc-13-20240210 ...
>  * CFLAGS="-pipe -march=native -O3 --param=l1-cache-size=32"
>  * CXXFLAGS="-pipe -march=native -O3 --param=l1-cache-size=32"

# diffoscope ./stage2-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/atomicity.o ./stage3-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/atomicity.o
[....]
│ -    <d>   DW_AT_producer    : (strp) (offset: 0x8b): GNU C++17 13.2.1 20240210 -march=alderlake -mmmx -mpopcnt -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mno-pku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex --param=l1-cache-size=48 --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -mshstk -g -O2 -O3 -fno-implicit-templates -ffunction-sections -fdata-sections -frandom-seed=atomicity.lo -fcf-protection=full -fPIC --param=l1-cache-size=32
│ +    <d>   DW_AT_producer    : (strp) (offset: 0x64): GNU C++17 13.2.1 20240210 -march=alderlake -mmmx -mpopcnt -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mno-pku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex --param=l1-cache-size=32 --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -mshstk -g -O2 -O3 -fno-implicit-templates -ffunction-sections -fdata-sections -frandom-seed=atomicity.lo -fcf-protection=full -fPIC --param=l1-cache-size=32
[....]
│ -  [    8b]  GNU C++17 13.2.1 20240210 -march=alderlake -mmmx -mpopcnt -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mno-pku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex --param=l1-cache-size=48 --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -mshstk -g -O2 -O3 -fno-implicit-templates -ffunction-sections -fdata-sections -frandom-seed=atomicity.lo -fcf-protection=full -fPIC --param=l1-cache-size=32
│ +  [    64]  GNU C++17 13.2.1 20240210 -march=alderlake -mmmx -mpopcnt -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mno-sse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512er -mno-avx512pf -mno-avx512vbmi -mno-avx512ifma -mno-avx5124vnniw -mno-avx5124fmaps -mno-avx512vpopcntdq -mno-avx512vbmi2 -mgfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mno-clzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mmovdir64b -mmovdiri -mno-mwaitx -mpconfig -mno-pku -mno-prefetchwt1 -mprfchw -mptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mserialize -mno-sgx -msha -mno-tbm -mno-tsxldtrk -mvaes -mwaitpkg -mno-wbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mhreset -mno-kl -mno-widekl -mavxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex --param=l1-cache-size=32 --param=l1-cache-line-size=64 --param=l2-cache-size=24576 -mtune=alderlake -mshstk -g -O2 -O3 -fno-implicit-templates -ffunction-sections -fdata-sections -frandom-seed=atomicity.lo -fcf-protection=full -fPIC --param=l1-cache-size=32
Comment 35 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-24 15:12:37 UTC
Is there any chance you'd mind hopping onto IRC, either #gentoo or #gentoo-toolchain so we can debug it together? It's OK if not.
Comment 36 Andrei Liavonchykau 2024-03-24 15:32:27 UTC
I'm already on #gentoo-toolchain, https://web.libera.chat/#gentoo-toolchain
Comment 37 Larry the Git Cow gentoo-dev 2024-03-24 17:47:26 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e897f91e8e81b8168e7045db2f6d8dd9ebdb9ddf

commit e897f91e8e81b8168e7045db2f6d8dd9ebdb9ddf
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-03-24 17:19:46 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-03-24 17:47:08 +0000

    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@gmail.com>
    Signed-off-by: Sam James <sam@gentoo.org>

 eclass/toolchain.eclass | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
Comment 38 Steffen Weber 2024-03-25 16:39:34 UTC
If "resolve-march-native" reports different "l1-cache-size" values from run to run, should I continue with the bigger value (48) or the smaller value (32)?

# resolve-march-native 
-march=alderlake -mabm -mno-cldemote -mno-kl -mno-pconfig -mno-sgx -mno-widekl -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=48 --param=l2-cache-size=12288

# resolve-march-native 
-march=alderlake -mabm -mno-cldemote -mno-kl -mno-pconfig -mno-sgx -mno-widekl -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=12288

# cat /proc/cpuinfo | grep name | head -n1
model name	: 13th Gen Intel(R) Core(TM) i7-1355U
Comment 39 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-25 16:42:54 UTC
(In reply to Steffen Weber from comment #38)
> If "resolve-march-native" reports different "l1-cache-size" values from run
> to run, should I continue with the bigger value (48) or the smaller value
> (32)?
> 
> # resolve-march-native 
> -march=alderlake -mabm -mno-cldemote -mno-kl -mno-pconfig -mno-sgx
> -mno-widekl -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=48
> --param=l2-cache-size=12288
> 
> # resolve-march-native 
> -march=alderlake -mabm -mno-cldemote -mno-kl -mno-pconfig -mno-sgx
> -mno-widekl -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=32
> --param=l2-cache-size=12288
> 
> # cat /proc/cpuinfo | grep name | head -n1
> model name	: 13th Gen Intel(R) Core(TM) i7-1355U

It doesn't matter really if it's just for GCC, but I think the smaller is preferable.
Comment 40 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-25 19:17:35 UTC
*** Bug 927718 has been marked as a duplicate of this bug. ***
Comment 41 Kai Krakow 2024-03-26 23:09:26 UTC
Looks like strip-flags removes most of the flags suggested by `resolve-march-native`, and thus it still fails:

>>> Configuring source in /var/tmp/portage/sys-devel/gcc-13.2.1_p20240210/work/gcc-13-20240210 ...
 * strip-flags: CFLAGS: changed '-O2 -march=native -fomit-frame-pointer -g -ftree-slp-vectorize -falign-functions=32 -g0 -march=alderlake -mabm -mno-cldemote -mno-kl -mno-sgx -mno-widekl -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=25600' to '-O2 -march=native -g -g0 -march=alderlake'

Since I only appended CFLAGS, I implied that the latter overrides the former march. I may be wrong here. But I think that stripping the flags in the ebuild is the main problem.

For the moment, I'm running emerge with `taskset -c 0-15 ...` and it works.
Comment 42 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-26 23:12:26 UTC
(In reply to Kai Krakow from comment #41)
> Looks like strip-flags removes most of the flags suggested by
> `resolve-march-native`, and thus it still fails:
> 
> >>> Configuring source in /var/tmp/portage/sys-devel/gcc-13.2.1_p20240210/work/gcc-13-20240210 ...
>  * strip-flags: CFLAGS: changed '-O2 -march=native -fomit-frame-pointer -g
> -ftree-slp-vectorize -falign-functions=32 -g0 -march=alderlake -mabm
> -mno-cldemote -mno-kl -mno-sgx -mno-widekl -mshstk
> --param=l1-cache-line-size=64 --param=l1-cache-size=32
> --param=l2-cache-size=25600' to '-O2 -march=native -g -g0 -march=alderlake'
> 

You can't keep the -march=native in there - that's why it's a problem. Subsequent --param won't help which is why our earlier workaround failed.

We can add more of these to the filter exemption, but it won't actually help.
Comment 43 Andrei Liavonchykau 2024-03-26 23:20:41 UTC
Yes, you need to remove "-march=native" and use a march variant from script, with all sets of flags.
Comment 44 David Carlos Manuelda 2024-03-27 20:20:57 UTC
I've removed the -march=native in favor of what resolve-march-native says and the result after filtering is:

 * strip-flags: CFLAGS: changed '-march=alderlake -mabm -mno-cldemote -mno-kl -mno-pconfig -mno-sgx -mno-widekl -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=48 --param=l2-cache-size=36864 -O2 -pipe' to '-march=alderlake -O2 -pipe'
 * strip-flags: CXXFLAGS: changed '-march=alderlake -mabm -mno-cldemote -mno-kl -mno-pconfig -mno-sgx -mno-widekl -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=48 --param=l2-cache-size=36864 -O2 -pipe' to '-march=alderlake -O2 -pipe'
 * CFLAGS="-march=alderlake -pipe -O2"
 * CXXFLAGS="-march=alderlake -pipe -O2"
 * LDFLAGS="-Wl,--as-needed -Wl,--sort-common -Wl,-O2 -fuse-ld=bfd"

Isn't it a bad idea to remove the -mno-* flags?
Comment 45 David Carlos Manuelda 2024-03-27 20:23:01 UTC
(In reply to David Carlos Manuelda from comment #44)
> I've removed the -march=native in favor of what resolve-march-native says
> and the result after filtering is:
> 
>  * strip-flags: CFLAGS: changed '-march=alderlake -mabm -mno-cldemote
> -mno-kl -mno-pconfig -mno-sgx -mno-widekl -mshstk
> --param=l1-cache-line-size=64 --param=l1-cache-size=48
> --param=l2-cache-size=36864 -O2 -pipe' to '-march=alderlake -O2 -pipe'
>  * strip-flags: CXXFLAGS: changed '-march=alderlake -mabm -mno-cldemote
> -mno-kl -mno-pconfig -mno-sgx -mno-widekl -mshstk
> --param=l1-cache-line-size=64 --param=l1-cache-size=48
> --param=l2-cache-size=36864 -O2 -pipe' to '-march=alderlake -O2 -pipe'
>  * CFLAGS="-march=alderlake -pipe -O2"
>  * CXXFLAGS="-march=alderlake -pipe -O2"
>  * LDFLAGS="-Wl,--as-needed -Wl,--sort-common -Wl,-O2 -fuse-ld=bfd"
> 
> Isn't it a bad idea to remove the -mno-* flags?

Ah, ignore this comment, on the compile lines I saw the full flags I set