]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Hash "apparent real path" of object file when using -fprofile-arcs
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 6 May 2024 18:43:43 +0000 (20:43 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 6 May 2024 18:43:43 +0000 (20:43 +0200)
The object file stores an absolute path based on apparent CWD when
-fprofile-arcs is used, not only the relative object filename.

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

index 05dcbc4f0d7bcbad207beb02e688232d267a969c..7a01db5769b6221acb61b8d6a8cba324b358a861 100644 (file)
@@ -1526,16 +1526,23 @@ hash_common_info(const Context& ctx,
     hash.hash(output_obj_dir);
   }
 
-  if (ctx.args_info.seen_split_dwarf || ctx.args_info.profile_arcs) {
-    // When using -gsplit-dwarf: Object files include a link to the
+  if (ctx.args_info.seen_split_dwarf) {
+    // When using -gsplit-dwarf the object file includes a link to the
     // 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.
+    LOG_RAW("Hashing object filename due to -gsplit-dwarf");
     hash.hash_delimiter("object file");
-    hash.hash(ctx.args_info.output_obj);
+    hash.hash(pstr(fs::path(ctx.args_info.output_obj).filename()).str());
+  }
+
+  if (ctx.args_info.profile_arcs) {
+    // When using -fprofile-arcs (including implicitly via --coverage) the
+    // object file contains a .gcda path based on the absolute object file path.
+    LOG_RAW("Hashing absolute object filename due to -fprofile-arcs");
+    hash.hash_delimiter("Absolute object file path");
+    // -fprofile-arcs stores "apparent absolute path" for some reason.
+    hash.hash(ctx.apparent_cwd / ctx.args_info.output_obj);
   }
 
   if (ctx.args_info.generating_coverage
index 3bd45bcd0d58fd51927f0dded4d09325a90117f3..233d65c2bfdfd85f220d46f44659a08230890fde 100644 (file)
@@ -200,21 +200,24 @@ fi
 
     mkdir obj1 obj2
 
-    $CCACHE_COMPILE -fprofile-arcs -c test.c -o obj1/test.o
+    cd obj1
+    $CCACHE_COMPILE -fprofile-arcs -c ../test.c -o test.o
     expect_stat direct_cache_hit 0
     expect_stat cache_miss 1
 
-    $CCACHE_COMPILE -fprofile-arcs -c test.c -o obj1/test.o
+    $CCACHE_COMPILE -fprofile-arcs -c ../test.c -o test.o
     expect_stat direct_cache_hit 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
+    cd ../obj2
+
+    $CCACHE_COMPILE -fprofile-arcs -c ../test.c -o test.o
+    expect_different_content ../obj1/test.o test.o # different paths to .gcda file
     expect_stat direct_cache_hit 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
+    $CCACHE_COMPILE -fprofile-arcs -c ../test.c -o test.o
+    expect_different_content ../obj1/test.o test.o # different paths to .gcda file
     expect_stat direct_cache_hit 2
     expect_stat cache_miss 2