Skip to content

Commit 977ef30

Browse files
marxinakpm00
authored andcommitted
gcov: support GCC 12.1 and newer compilers
Starting with GCC 12.1, the created .gcda format can't be read by gcov tool. There are 2 significant changes to the .gcda file format that need to be supported: a) [gcov: Use system IO buffering] (23eb66d1d46a34cb28c4acbdf8a1deb80a7c5a05) changed that all sizes in the format are in bytes and not in words (4B) b) [gcov: make profile merging smarter] (72e0c742bd01f8e7e6dcca64042b9ad7e75979de) add a new checksum to the file header. Tested with GCC 7.5, 10.4, 12.2 and the current master. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Martin Liska <[email protected]> Tested-by: Peter Oberparleiter <[email protected]> Reviewed-by: Peter Oberparleiter <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4249a05 commit 977ef30

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

kernel/gcov/gcc_4_7.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030

3131
#define GCOV_TAG_FUNCTION_LENGTH 3
3232

33+
/* Since GCC 12.1 sizes are in BYTES and not in WORDS (4B). */
34+
#if (__GNUC__ >= 12)
35+
#define GCOV_UNIT_SIZE 4
36+
#else
37+
#define GCOV_UNIT_SIZE 1
38+
#endif
39+
3340
static struct gcov_info *gcov_info_head;
3441

3542
/**
@@ -383,12 +390,18 @@ size_t convert_to_gcda(char *buffer, struct gcov_info *info)
383390
pos += store_gcov_u32(buffer, pos, info->version);
384391
pos += store_gcov_u32(buffer, pos, info->stamp);
385392

393+
#if (__GNUC__ >= 12)
394+
/* Use zero as checksum of the compilation unit. */
395+
pos += store_gcov_u32(buffer, pos, 0);
396+
#endif
397+
386398
for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
387399
fi_ptr = info->functions[fi_idx];
388400

389401
/* Function record. */
390402
pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION);
391-
pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION_LENGTH);
403+
pos += store_gcov_u32(buffer, pos,
404+
GCOV_TAG_FUNCTION_LENGTH * GCOV_UNIT_SIZE);
392405
pos += store_gcov_u32(buffer, pos, fi_ptr->ident);
393406
pos += store_gcov_u32(buffer, pos, fi_ptr->lineno_checksum);
394407
pos += store_gcov_u32(buffer, pos, fi_ptr->cfg_checksum);
@@ -402,7 +415,8 @@ size_t convert_to_gcda(char *buffer, struct gcov_info *info)
402415
/* Counter record. */
403416
pos += store_gcov_u32(buffer, pos,
404417
GCOV_TAG_FOR_COUNTER(ct_idx));
405-
pos += store_gcov_u32(buffer, pos, ci_ptr->num * 2);
418+
pos += store_gcov_u32(buffer, pos,
419+
ci_ptr->num * 2 * GCOV_UNIT_SIZE);
406420

407421
for (cv_idx = 0; cv_idx < ci_ptr->num; cv_idx++) {
408422
pos += store_gcov_u64(buffer, pos,

0 commit comments

Comments
 (0)