]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Hash source path when generating dependencies to avoid false positive
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 27 Sep 2016 21:20:36 +0000 (23:20 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 27 Sep 2016 21:20:36 +0000 (23:20 +0200)
5908e656ef2a6493b42159acff4b1f490016d055 introduced a regression: If a
source file is compiled in directory A and an identical source file in
directory B results in a preprocessed hit, then the dependency file from
the first compilation will be overwritten by the second compilation.
Since the source path is part of the dependency file, an incorrect
dependency file will be retrieved from the cache when recompiling the
source in directory A.

The solution is to include the source path part in the object hash if a
dependency file is being generated.

Fixes #134.

NEWS.txt
ccache.c
test.sh

index 1bbe5e286cc1cf9180968edc4015a869750abb9d..ef89bf5e58e6e52e033f0b383193ed900b6cf706 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -11,6 +11,14 @@ New features and improvements
   `--sysroot=arg` form.
 
 
+Bug fixes
+~~~~~~~~~
+
+- Fixed a regression in ccache 3.3 related to potentially bad content of
+  dependency files when compiling identical source code but with different
+  source paths.
+
+
 ccache 3.3.1
 ------------
 Release date: 2016-09-07
index 76139b93571865c34306f14920aefb3d825b96b1..a301c7ef84f36c3fa17186ecccb5c8e3a9a235f0 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1536,6 +1536,13 @@ calculate_common_hash(struct args *args, struct mdfour *hash)
                }
        }
 
+       // Possibly hash input file location to avoid false positive cache hits since
+       // the dependency file includes the source file path.
+       if (generating_dependencies) {
+               hash_delimiter(hash, "inputfile");
+               hash_string(hash, input_file);
+       }
+
        // Possibly hash the coverage data file path.
        if (generating_coverage && profile_arcs) {
                char *dir = dirname(output_obj);
diff --git a/test.sh b/test.sh
index 6ca18c9bf036a4e14b8252e92f8cb2b7cb751fe9..db049ebaa2350efdb4dbabfcc004b082285c30f6 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -975,6 +975,20 @@ EOF
     expect_stat 'cache miss' 0
     expect_stat 'unsupported compiler option' 1
 
+    # -------------------------------------------------------------------------
+    TEST "-MMD for different source files"
+
+    mkdir a b
+    touch a/source.c b/source.c
+    $CCACHE_COMPILE -MMD -c a/source.c
+    expect_file_content source.d "source.o: a/source.c"
+
+    $CCACHE_COMPILE -MMD -c b/source.c
+    expect_file_content source.d "source.o: b/source.c"
+
+    $CCACHE_COMPILE -MMD -c a/source.c
+    expect_file_content source.d "source.o: a/source.c"
+
     # -------------------------------------------------------------------------
     TEST "-Wp,-P"
 
@@ -1610,6 +1624,20 @@ EOF
     expect_stat 'cache hit (preprocessed)' 1
     expect_stat 'cache miss' 1
 
+    # -------------------------------------------------------------------------
+    TEST "-MMD for different source files"
+
+    mkdir a b
+    touch a/source.c b/source.c
+    $CCACHE_COMPILE -MMD -c a/source.c
+    expect_file_content source.d "source.o: a/source.c"
+
+    $CCACHE_COMPILE -MMD -c b/source.c
+    expect_file_content source.d "source.o: b/source.c"
+
+    $CCACHE_COMPILE -MMD -c a/source.c
+    expect_file_content source.d "source.o: a/source.c"
+
     # -------------------------------------------------------------------------
     TEST "Multiple object entries in manifest"