From: Joel Rosdahl Date: Mon, 6 May 2024 18:43:43 +0000 (+0200) Subject: fix: Hash "apparent real path" of object file when using -fprofile-arcs X-Git-Tag: v4.10~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=350d354b4502ddfc2638362be9f0d48862659900;p=thirdparty%2Fccache.git fix: Hash "apparent real path" of object file when using -fprofile-arcs The object file stores an absolute path based on apparent CWD when -fprofile-arcs is used, not only the relative object filename. --- diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 05dcbc4f..7a01db57 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -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 diff --git a/test/suites/profiling.bash b/test/suites/profiling.bash index 3bd45bcd..233d65c2 100644 --- a/test/suites/profiling.bash +++ b/test/suites/profiling.bash @@ -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