]> 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:27:33 +0000 (23:27 +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 8eaf4b6abb827ad52c2664f015020c9e9cbed043..c33cd1c2fab16085e15799cccec19d4ff23515c0 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,6 +1,17 @@
 ccache news
 ===========
 
+Unreleased 3.3.2
+----------------
+
+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 8ffadccc164ea11929801b87cec9c110bda8014c..d91ecc3c9663267ba7d3c6ee6a9c9b009b78bf3f 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 b46feaad36623b2fc37b2753e697316845175d29..9c7314ea0a967226637f571c39534519f0f00ac6 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"