diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp @@ -161,30 +161,41 @@ // flexibility. namespace SingletonCounterCoverage { -static char *counters_start, *counters_end; +static char *counters_beg, *counters_end; +static const uptr *pcs_beg, *pcs_end; static void DumpCoverage() { const char* file_path = common_flags()->cov_8bit_counters_out; - if (!file_path || !internal_strlen(file_path)) - return; - fd_t fd = OpenFile(file_path); - FileCloser file_closer(fd); - WriteToFile(fd, counters_start, counters_end - counters_start); + if (file_path && internal_strlen(file_path)) { + fd_t fd = OpenFile(file_path); + FileCloser file_closer(fd); + uptr size = counters_end - counters_beg; + WriteToFile(fd, counters_beg, size); + if (common_flags()->verbosity) + __sanitizer::Printf("cov_8bit_counters_out: written %zd bytes to %s\n", + size, file_path); + } + file_path = common_flags()->cov_pcs_out; + if (file_path && internal_strlen(file_path)) { + fd_t fd = OpenFile(file_path); + FileCloser file_closer(fd); + uptr size = (pcs_end - pcs_beg) * sizeof(uptr); + WriteToFile(fd, pcs_beg, size); + if (common_flags()->verbosity) + __sanitizer::Printf("cov_pcs_out: written %zd bytes to %s\n", size, + file_path); + } } static void Cov8bitCountersInit(char* beg, char* end) { - counters_start = beg; + counters_beg = beg; counters_end = end; Atexit(DumpCoverage); } -static void CovPcsInit(const uptr* pcs_beg, const uptr* pcs_end) { - const char* file_path = common_flags()->cov_pcs_out; - if (!file_path || !internal_strlen(file_path)) - return; - fd_t fd = OpenFile(file_path); - FileCloser file_closer(fd); - WriteToFile(fd, pcs_beg, (pcs_end - pcs_beg) * sizeof(uptr)); +static void CovPcsInit(const uptr* beg, const uptr* end) { + pcs_beg = beg; + pcs_end = end; } } // namespace SingletonCounterCoverage diff --git a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter_default_impl.cpp b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter_default_impl.cpp --- a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter_default_impl.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter_default_impl.cpp @@ -5,7 +5,7 @@ // RUN: %clangxx -O0 %s -fsanitize-coverage=inline-8bit-counters,pc-table -o %t // RUN: rm -f %t-counters %t-pcs -// RUN: env %tool_options="cov_8bit_counters_out=%t-counters cov_pcs_out=%t-pcs" %run %t 2>&1 | FileCheck %s +// RUN: env %tool_options="cov_8bit_counters_out=%t-counters cov_pcs_out=%t-pcs verbosity=1" %run %t 2>&1 | FileCheck %s // Check the file sizes // RUN: wc -c %t-counters | grep "^2 " @@ -19,4 +19,6 @@ foo(); fprintf(stderr, "PASS\n"); // CHECK: PASS + // CHECK: cov_8bit_counters_out: written {{.*}} bytes to {{.*}}-counter + // CHECK: cov_pcs_out: written {{.*}} bytes to {{.*}}-pcs }