From: Joel Rosdahl Date: Sat, 8 May 2021 14:47:22 +0000 (+0200) Subject: Include object path in input hash for -fprofile-arcs (--coverage) X-Git-Tag: v4.3~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2fd39b06a2d783197d22e4b10405e7e23f8f3df8;p=thirdparty%2Fccache.git Include object path in input hash for -fprofile-arcs (--coverage) The object file contains a .gcda path based on the object file path. Fixes #845. --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 08e9447bc..008356e02 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1426,7 +1426,7 @@ hash_common_info(const Context& ctx, if ((!should_rewrite_dependency_target(ctx.args_info) && ctx.args_info.generating_dependencies) - || ctx.args_info.seen_split_dwarf) { + || ctx.args_info.seen_split_dwarf || ctx.args_info.profile_arcs) { // If generating dependencies: The output object file name is part of the .d // file, so include the path in the hash. // @@ -1434,6 +1434,9 @@ hash_common_info(const Context& ctx, // corresponding .dwo file based on the target object filename, so hashing // the object file path will do it, although just hashing the object file // base name would be enough. + // + // When using -fprofile-arcs (including implicitly via --coverage), the + // object file contains a .gcda path based on the object file path. hash.hash_delimiter("object file"); hash.hash(ctx.args_info.output_obj); } diff --git a/test/suites/profiling.bash b/test/suites/profiling.bash index b7abaa2a5..dbe36d41f 100644 --- a/test/suites/profiling.bash +++ b/test/suites/profiling.bash @@ -128,6 +128,29 @@ SUITE_profiling() { rm "$gcno_name" done done + + # ------------------------------------------------------------------------- + TEST "-fprofile-arcs for different object file paths" + + mkdir obj1 obj2 + + $CCACHE_COMPILE -fprofile-arcs -c test.c -o obj1/test.o + expect_stat 'cache hit (direct)' 0 + expect_stat 'cache miss' 1 + + $CCACHE_COMPILE -fprofile-arcs -c test.c -o obj1/test.o + expect_stat 'cache hit (direct)' 1 + expect_stat 'cache miss' 1 + + $CCACHE_COMPILE -fprofile-arcs -c test.c -o obj2/test.o + expect_different_content obj1/test.o obj2/test.o # different paths to .gcda file + expect_stat 'cache hit (direct)' 1 + expect_stat 'cache miss' 2 + + $CCACHE_COMPILE -fprofile-arcs -c test.c -o obj2/test.o + expect_different_content obj1/test.o obj2/test.o # different paths to .gcda file + expect_stat 'cache hit (direct)' 2 + expect_stat 'cache miss' 2 } merge_profiling_data() {