diff options
Diffstat (limited to 'libgcc/libgcov-driver.c')
-rw-r--r-- | libgcc/libgcov-driver.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index 1c07761..cdb611d 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -213,6 +213,56 @@ static struct gcov_fn_buffer *fn_buffer; /* Including system dependent components. */ #include "libgcov-driver-system.c" +/* Prune TOP N value COUNTERS. It's needed in order to preserve + reproducibility of builds. */ + +static void +prune_topn_counter (gcov_type *counters, gcov_type all) +{ + if (counters[1] == -1) + return; + + for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++) + { + if (counters[2 * i + 1] < all) + { + counters[2 * i] = 0; + counters[2 * i + 1] = 0; + } + } +} + +/* Prune counters so that they are ready to store or merge. */ + +static void +prune_counters (struct gcov_info *gi) +{ + for (unsigned i = 0; i < gi->n_functions; i++) + { + const struct gcov_fn_info *gfi = gi->functions[i]; + const struct gcov_ctr_info *ci = gfi->ctrs; + + for (unsigned j = 0; j < GCOV_COUNTERS; j++) + { + if (gi->merge[j] == NULL) + continue; + + if (gi->merge[j] == __gcov_merge_topn) + { + gcc_assert (!(ci->num % GCOV_TOPN_VALUES_COUNTERS)); + for (unsigned k = 0; k < (ci->num / GCOV_TOPN_VALUES_COUNTERS); + k++) + { + gcov_type *counters + = ci->values + (k * GCOV_TOPN_VALUES_COUNTERS); + prune_topn_counter (counters + 1, *counters); + } + } + ci++; + } + } +} + /* This function merges counters in GI_PTR to an existing gcda file. Return 0 on success. Return -1 on error. In this case, caller will goto read_fatal. */ @@ -429,9 +479,11 @@ dump_one_gcov (struct gcov_info *gi_ptr, struct gcov_filename *gf, struct gcov_summary summary = {}; int error; gcov_unsigned_t tag; - fn_buffer = 0; + /* Prune current counters before we merge them. */ + prune_counters (gi_ptr); + error = gcov_exit_open_gcda_file (gi_ptr, gf); if (error == -1) return; |