The -march=native option to gcc generates different code depending on the architecture of the host. ccache does not store the machine architecture in its hash which means that if you change the architecture of the machine, for example to switch to a high performance VPS node, the cached object files may be incompatible.
How can I make sure I get the correct object files while still taking advantage of caching?
ccache does not store the architecture, but it does store the compiler flags that were used when building an object for the first time. Therefore a potential solution to your problem could be to use a thin wrapper script that would expand
-march=native to the actual set of flags (e.g. using something like this), before passing them to
(I will, of course, leave the actual implementation as an exercise to the reader..)