Skip to content

Commit 9562fd1

Browse files
nickdesaulnierstorvalds
authored andcommitted
gcov: re-fix clang-11+ support
LLVM changed the expected function signature for llvm_gcda_emit_function() in the clang-11 release. Users of clang-11 or newer may have noticed their kernels producing invalid coverage information: $ llvm-cov gcov -a -c -u -f -b <input>.gcda -- gcno=<input>.gcno 1 <func>: checksum mismatch, \ (<lineno chksum A>, <cfg chksum B>) != (<lineno chksum A>, <cfg chksum C>) 2 Invalid .gcda File! ... Fix up the function signatures so calling this function interprets its parameters correctly and computes the correct cfg checksum. In particular, in clang-11, the additional checksum is no longer optional. Link: https://reviews.llvm.org/rG25544ce2df0daa4304c07e64b9c8b0f7df60c11d Link: https://lkml.kernel.org/r/[email protected] Reported-by: Prasad Sodagudi <[email protected]> Tested-by: Prasad Sodagudi <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Cc: <[email protected]> [5.4+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a3a8833 commit 9562fd1

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

kernel/gcov/clang.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ struct gcov_fn_info {
7070

7171
u32 ident;
7272
u32 checksum;
73+
#if CONFIG_CLANG_VERSION < 110000
7374
u8 use_extra_checksum;
75+
#endif
7476
u32 cfg_checksum;
7577

7678
u32 num_counters;
@@ -145,10 +147,8 @@ void llvm_gcda_emit_function(u32 ident, const char *function_name,
145147

146148
list_add_tail(&info->head, &current_info->functions);
147149
}
148-
EXPORT_SYMBOL(llvm_gcda_emit_function);
149150
#else
150-
void llvm_gcda_emit_function(u32 ident, u32 func_checksum,
151-
u8 use_extra_checksum, u32 cfg_checksum)
151+
void llvm_gcda_emit_function(u32 ident, u32 func_checksum, u32 cfg_checksum)
152152
{
153153
struct gcov_fn_info *info = kzalloc(sizeof(*info), GFP_KERNEL);
154154

@@ -158,12 +158,11 @@ void llvm_gcda_emit_function(u32 ident, u32 func_checksum,
158158
INIT_LIST_HEAD(&info->head);
159159
info->ident = ident;
160160
info->checksum = func_checksum;
161-
info->use_extra_checksum = use_extra_checksum;
162161
info->cfg_checksum = cfg_checksum;
163162
list_add_tail(&info->head, &current_info->functions);
164163
}
165-
EXPORT_SYMBOL(llvm_gcda_emit_function);
166164
#endif
165+
EXPORT_SYMBOL(llvm_gcda_emit_function);
167166

168167
void llvm_gcda_emit_arcs(u32 num_counters, u64 *counters)
169168
{
@@ -293,11 +292,16 @@ int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2)
293292
!list_is_last(&fn_ptr2->head, &info2->functions)) {
294293
if (fn_ptr1->checksum != fn_ptr2->checksum)
295294
return false;
295+
#if CONFIG_CLANG_VERSION < 110000
296296
if (fn_ptr1->use_extra_checksum != fn_ptr2->use_extra_checksum)
297297
return false;
298298
if (fn_ptr1->use_extra_checksum &&
299299
fn_ptr1->cfg_checksum != fn_ptr2->cfg_checksum)
300300
return false;
301+
#else
302+
if (fn_ptr1->cfg_checksum != fn_ptr2->cfg_checksum)
303+
return false;
304+
#endif
301305
fn_ptr1 = list_next_entry(fn_ptr1, head);
302306
fn_ptr2 = list_next_entry(fn_ptr2, head);
303307
}
@@ -529,17 +533,22 @@ static size_t convert_to_gcda(char *buffer, struct gcov_info *info)
529533

530534
list_for_each_entry(fi_ptr, &info->functions, head) {
531535
u32 i;
532-
u32 len = 2;
533-
534-
if (fi_ptr->use_extra_checksum)
535-
len++;
536536

537537
pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION);
538-
pos += store_gcov_u32(buffer, pos, len);
538+
#if CONFIG_CLANG_VERSION < 110000
539+
pos += store_gcov_u32(buffer, pos,
540+
fi_ptr->use_extra_checksum ? 3 : 2);
541+
#else
542+
pos += store_gcov_u32(buffer, pos, 3);
543+
#endif
539544
pos += store_gcov_u32(buffer, pos, fi_ptr->ident);
540545
pos += store_gcov_u32(buffer, pos, fi_ptr->checksum);
546+
#if CONFIG_CLANG_VERSION < 110000
541547
if (fi_ptr->use_extra_checksum)
542548
pos += store_gcov_u32(buffer, pos, fi_ptr->cfg_checksum);
549+
#else
550+
pos += store_gcov_u32(buffer, pos, fi_ptr->cfg_checksum);
551+
#endif
543552

544553
pos += store_gcov_u32(buffer, pos, GCOV_TAG_COUNTER_BASE);
545554
pos += store_gcov_u32(buffer, pos, fi_ptr->num_counters * 2);

0 commit comments

Comments
 (0)