From: Joel Rosdahl Date: Tue, 27 Sep 2016 21:20:36 +0000 (+0200) Subject: Hash source path when generating dependencies to avoid false positive X-Git-Tag: v3.3.2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cffdc692054fd0b3434d851aaefacf7e207efc5;p=thirdparty%2Fccache.git Hash source path when generating dependencies to avoid false positive 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. --- diff --git a/NEWS.txt b/NEWS.txt index 8eaf4b6ab..c33cd1c2f 100644 --- 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 diff --git a/ccache.c b/ccache.c index 8ffadccc1..d91ecc3c9 100644 --- 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 b46feaad3..9c7314ea0 100755 --- 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"