Usage of -march=native for shared cache may result in false positive cache hits
How to reproduce
- Share the cache between two systems with different architectures so that
-march=nativeproduces different object files. - Compile a file with
-march=nativeon system 1. - Compile the same file with exactly the same compiler, command line and environment on system 2.
Actual behavior
- The latter compilation will get a false positive cache hit since
-march=nativeworks differently between the systems.
Expected behavior
- The latter compilation should be a cache miss since
-march=nativeworks differently between the systems.
Environment
ccache version 4.2.
See also
Discussion #823.
Here's one way to have gcc print what -march=native is equivalent to:
$ cc -march=native -### -E - < /dev/null 2>&1 | grep cc1
/usr/lib64/gcc/x86_64-unknown-linux-gnu/10.2.1/cc1 -E -quiet - "-march=nehalem" -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mno-movbe -mno-aes -mno-sha -mno-pclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-sgx -mno-bmi2 -mno-pconfig -mno-wbnoinvd -mno-tbm -mno-avx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mno-rdrnd -mno-f16c -mno-fsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mno-xsave -mno-xsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt -mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-avx5124fmaps -mno-avx5124vnniw -mno-clwb -mno-mwaitx -mno-clzero -mno-pku -mno-rdpid -mno-gfni -mno-shstk -mno-avx512vbmi2 -mno-avx512vnni -mno-vaes -mno-vpclmulqdq -mno-avx512bitalg -mno-avx512vpopcntdq -mno-movdiri -mno-movdir64b -mno-waitpkg -mno-cldemote -mno-ptwrite -mno-avx512bf16 -mno-enqcmd -mno-avx512vp2intersect --param "l1-cache-size=32" --param "l1-cache-line-size=64" --param "l2-cache-size=8192" "-mtune=nehalem"
A more concise output could be:
$ cc -march=native -### -E - < /dev/null 2>&1 | sed -ne 's/.*cc1 .*-march=\([^ "]*\)[ "].*/\1/p'
nehalem
Is there an easy way I can have this appended to the default compiler_check only when using -march=native? In this way, the ccache can be shared among different architectures, split only for -march=native compilations.
The explanation of compiler_check in the man page does not indicate if it's possible for the command to depend on the parameters, analogue to %compiler%.
Is there an easy way I can have this appended to the default
compiler_checkonly when using-march=native? In this way, the ccache can be shared among different architectures, split only for-march=nativecompilations.
Not currently. It would be quite easy to add a token that expands to the compiler arguments (e.g. %arguments%), though.
While this remains open, it would be nice if the manual mentioned the caveat that -march=native will cause trouble if a cache is shared across machines of different architecture.