2
votes

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?

2

2 Answers

1
votes

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

(I will, of course, leave the actual implementation as an exercise to the reader..)

0
votes

You can make sure to use machines with identical architectures in your build farm. Apart from that, I don't see how you can solve that problem.

Also remember that if you use -march=native then anyone who wants to run your binary needs to have the same (or possibly, newer but backwards-compatible) machine architecture. Which may or may not be a problem.