]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Include object path in input hash for -fprofile-arcs (--coverage)
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 8 May 2021 14:47:22 +0000 (16:47 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 8 May 2021 16:49:10 +0000 (18:49 +0200)
The object file contains a .gcda path based on the object file path.

Fixes #845.

src/ccache.cpp
test/suites/profiling.bash

index 08e9447bcdb9df01e07721b199baa351107be033..008356e0251762cc61c625843e54108a00cadac0 100644 (file)
@@ -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);
   }
index b7abaa2a53f0e99a2d67a072ba863027e3114e31..dbe36d41f9211bedf600950be5bae854393c92f4 100644 (file)
@@ -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() {