Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of -march=native for shared cache may result in false positive cache hits #824

Open
jrosdahl opened this issue Mar 21, 2021 · 3 comments
Labels
bug Does not work as intended/documented

Comments

@jrosdahl
Copy link
Member

How to reproduce

  1. Share the cache between two systems with different architectures so that -march=native produces different object files.
  2. Compile a file with -march=native on system 1.
  3. Compile the same file with exactly the same compiler, command line and environment on system 2.

Actual behavior

  1. The latter compilation will get a false positive cache hit since -march=native works differently between the systems.

Expected behavior

  1. The latter compilation should be a cache miss since -march=native works differently between the systems.

Environment

ccache version 4.2.

See also

Discussion #823.

@jrosdahl jrosdahl added the bug Does not work as intended/documented label Mar 21, 2021
@gt7-void
Copy link

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%.

@jrosdahl
Copy link
Member Author

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.

Not currently. It would be quite easy to add a token that expands to the compiler arguments (e.g. %arguments%), though.

@PhilMiller
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Does not work as intended/documented
Projects
None yet
Development

No branches or pull requests

3 participants