Skip to content

Commit 6279ab3

Browse files
author
Jonas Blixt
committed
plat: qemu: Update gcov to support gcc >= 12
1 parent 8c0fdb9 commit 6279ab3

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/plat/qemu/gcov.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ static int gcov_load_data(struct gcov_info *info)
147147
goto gcov_init_err;
148148
}
149149

150+
rc = gcov_read_u32(fd, &val); // Ignore 'checksum'
151+
152+
if (rc != 0) {
153+
LOG_ERR("Could not read checksum field (%i)", rc);
154+
rc = -4;
155+
goto gcov_init_err;
156+
}
157+
150158
for (unsigned int i = 0; i < info->n_functions; i++) {
151159
rc = gcov_read_u32(fd, &val);
152160

@@ -158,7 +166,7 @@ static int gcov_load_data(struct gcov_info *info)
158166

159167
rc = gcov_read_u32(fd, &val);
160168

161-
if (val != GCOV_TAG_FUNCTION_LENGTH || rc != 0) {
169+
if (val != GCOV_TAG_FUNCTION_LENGTH * GCOV_UNIT_SIZE || rc != 0) {
162170
LOG_ERR("Invalid function length tag %x, %i", val, rc);
163171
rc = -6;
164172
goto gcov_init_err;
@@ -312,12 +320,18 @@ int gcov_store_output(void)
312320
if (rc != 0)
313321
return rc;
314322

323+
#if (__GNUC__ >= 12)
324+
/* Checksum */
325+
rc = gcov_write_u32(fd, 0);
326+
if (rc != 0)
327+
return rc;
328+
#endif
315329
for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
316330
fi_ptr = info->functions[fi_idx];
317331
rc = gcov_write_u32(fd, GCOV_TAG_FUNCTION);
318332
if (rc != 0)
319333
return rc;
320-
rc = gcov_write_u32(fd, GCOV_TAG_FUNCTION_LENGTH);
334+
rc = gcov_write_u32(fd, GCOV_TAG_FUNCTION_LENGTH * GCOV_UNIT_SIZE);
321335
if (rc != 0)
322336
return rc;
323337
rc = gcov_write_u32(fd, fi_ptr->ident);

src/plat/qemu/gcov.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ typedef uint64_t gcov_type;
2525

2626
#define GCOV_TAG_FUNCTION_LENGTH 3
2727

28+
#if (__GNUC__ >= 12)
29+
#define GCOV_UNIT_SIZE 4
30+
#else
31+
#define GCOV_UNIT_SIZE 1
32+
#endif
33+
2834
struct gcov_ctr_info {
2935
unsigned int num;
3036
gcov_type *values;
@@ -42,6 +48,9 @@ struct gcov_info {
4248
unsigned int version;
4349
struct gcov_info *next;
4450
unsigned int stamp;
51+
#if (__GNUC__ >= 12)
52+
unsigned int checksum;
53+
#endif
4554
const char *filename;
4655
void (*merge[GCOV_COUNTERS])(gcov_type *, unsigned int);
4756
unsigned int n_functions;

0 commit comments

Comments
 (0)