]> git.ipfire.org Git - thirdparty/ccache.git/commit
Only try to hard link object files to/from the cache
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 29 May 2020 18:43:19 +0000 (20:43 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 29 May 2020 19:11:36 +0000 (21:11 +0200)
commit82ecace939df039b0216333cc587546267afcb20
treed51f45cd0b134a8403b972a39095f57c9ba2dbbe
parentcca6f4fd933b649466e2498c522741976fc7c304
Only try to hard link object files to/from the cache

The compiler unlinks the destination object file before writing, but it
apparently doesn’t do that for dependency files. This means that
compilation can corrupt a .d file that shares i-node with a cached .d
file when using the hard link mode. Here is a scenario where this can
happen:

1. There is a test.c which includes test.h.
2. When test.c is compiled, the compiler writes test.d which mentions
   test.h and ccache hard links test.d into cache entry 1. test.d and
   cache entry 1's .d file now share i-nodes.
3. The include of test.h is removed from test.c.
4. When test.c is compiled again the compiler overwrites test.d with new
   content without test.h and ccache hard links test.d into cache entry
   2. test.d, cache entry 1 and cache entry 2 now share i-nodes, all of
   which contain the new content without test.h.

Since we can’t be sure how the compiler behaves for other types of files
(.dwo, .cov, etc.), only try to to hard link object files.

Fixes #599.

(cherry picked from commit 443afc179e1de3f050850103a5ba62e3cb5ab398)
src/result.cpp
test/suites/hardlink.bash