GCC ≥9 has changed behavior for -ftest-coverage and --coverage in
combination with -fprofile-dir=dir:
- Without -fprofile-dir=dir the file is placed next to the object file
but with a “.gcno” extension.
- With -fprofile-dir=dir the file is also place next to the object file
(i.e. not in the specified profile directory) but the same style of
name as used for “.gcda” files (full pathname with slashes replaced
with hash characters).
Fix this by:
- Checking if the expected (GCC <9) .gcno file is present. If not, fall
back to running the compiler and increment the “unsupported option”
counter.
- Making sure to perform the above check before copying the object file
to the cache so that a later ccache invocation won’t believe that
there is a result in the cache.
- Improving the copy_file routine to not create the destination file
until it knows that there is a source file to copy from.
Fixes #674.
(cherry picked from commit
6abd78b5ec7cdfeedff36454b07a8dbff312b554)
result_writer.write(Result::FileType::dependency, ctx.args_info.output_dep);
}
if (ctx.args_info.generating_coverage) {
+ if (!Stat::stat(ctx.args_info.output_cov)) {
+ // The .gcno file is missing. This is likely due to compiling with GCC 9+,
+ // which uses another name for the .gcno file when using -ftest-coverage
+ // or --coverage when -fprofile-dir=dir is given. The .gcno file is still
+ // placed next to the object file, not in the specified profile directory,
+ // though.
+ log("{} is missing", ctx.args_info.output_cov);
+ throw Failure(Statistic::unsupported_compiler_option);
+ }
result_writer.write(Result::FileType::coverage, ctx.args_info.output_cov);
}
if (ctx.args_info.generating_stackusage) {