Skip to content

Commit 431aaec

Browse files
nickdesaulniersgregkh
authored andcommitted
gcov: fix clang-11+ support
commit 60bcf72 upstream. LLVM changed the expected function signatures for llvm_gcda_start_file() and llvm_gcda_emit_function() in the clang-11 release. Users of clang-11 or newer may have noticed their kernels failing to boot due to a panic when enabling CONFIG_GCOV_KERNEL=y +CONFIG_GCOV_PROFILE_ALL=y. Fix up the function signatures so calling these functions doesn't panic the kernel. Link: https://reviews.llvm.org/rGcdd683b516d147925212724b09ec6fb792a40041 Link: https://reviews.llvm.org/rG13a633b438b6500ecad9e4f936ebadf3411d0f44 Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Nick Desaulniers <[email protected]> Reported-by: Prasad Sodagudi <[email protected]> Suggested-by: Nathan Chancellor <[email protected]> Reviewed-by: Fangrui Song <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Acked-by: Peter Oberparleiter <[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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4748b6d commit 431aaec

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

kernel/gcov/clang.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ struct gcov_fn_info {
7575

7676
u32 num_counters;
7777
u64 *counters;
78+
#if CONFIG_CLANG_VERSION < 110000
7879
const char *function_name;
80+
#endif
7981
};
8082

8183
static struct gcov_info *current_info;
@@ -105,6 +107,7 @@ void llvm_gcov_init(llvm_gcov_callback writeout, llvm_gcov_callback flush)
105107
}
106108
EXPORT_SYMBOL(llvm_gcov_init);
107109

110+
#if CONFIG_CLANG_VERSION < 110000
108111
void llvm_gcda_start_file(const char *orig_filename, const char version[4],
109112
u32 checksum)
110113
{
@@ -113,7 +116,17 @@ void llvm_gcda_start_file(const char *orig_filename, const char version[4],
113116
current_info->checksum = checksum;
114117
}
115118
EXPORT_SYMBOL(llvm_gcda_start_file);
119+
#else
120+
void llvm_gcda_start_file(const char *orig_filename, u32 version, u32 checksum)
121+
{
122+
current_info->filename = orig_filename;
123+
current_info->version = version;
124+
current_info->checksum = checksum;
125+
}
126+
EXPORT_SYMBOL(llvm_gcda_start_file);
127+
#endif
116128

129+
#if CONFIG_CLANG_VERSION < 110000
117130
void llvm_gcda_emit_function(u32 ident, const char *function_name,
118131
u32 func_checksum, u8 use_extra_checksum, u32 cfg_checksum)
119132
{
@@ -133,6 +146,24 @@ void llvm_gcda_emit_function(u32 ident, const char *function_name,
133146
list_add_tail(&info->head, &current_info->functions);
134147
}
135148
EXPORT_SYMBOL(llvm_gcda_emit_function);
149+
#else
150+
void llvm_gcda_emit_function(u32 ident, u32 func_checksum,
151+
u8 use_extra_checksum, u32 cfg_checksum)
152+
{
153+
struct gcov_fn_info *info = kzalloc(sizeof(*info), GFP_KERNEL);
154+
155+
if (!info)
156+
return;
157+
158+
INIT_LIST_HEAD(&info->head);
159+
info->ident = ident;
160+
info->checksum = func_checksum;
161+
info->use_extra_checksum = use_extra_checksum;
162+
info->cfg_checksum = cfg_checksum;
163+
list_add_tail(&info->head, &current_info->functions);
164+
}
165+
EXPORT_SYMBOL(llvm_gcda_emit_function);
166+
#endif
136167

137168
void llvm_gcda_emit_arcs(u32 num_counters, u64 *counters)
138169
{
@@ -295,6 +326,7 @@ void gcov_info_add(struct gcov_info *dst, struct gcov_info *src)
295326
}
296327
}
297328

329+
#if CONFIG_CLANG_VERSION < 110000
298330
static struct gcov_fn_info *gcov_fn_info_dup(struct gcov_fn_info *fn)
299331
{
300332
size_t cv_size; /* counter values size */
@@ -322,6 +354,28 @@ static struct gcov_fn_info *gcov_fn_info_dup(struct gcov_fn_info *fn)
322354
kfree(fn_dup);
323355
return NULL;
324356
}
357+
#else
358+
static struct gcov_fn_info *gcov_fn_info_dup(struct gcov_fn_info *fn)
359+
{
360+
size_t cv_size; /* counter values size */
361+
struct gcov_fn_info *fn_dup = kmemdup(fn, sizeof(*fn),
362+
GFP_KERNEL);
363+
if (!fn_dup)
364+
return NULL;
365+
INIT_LIST_HEAD(&fn_dup->head);
366+
367+
cv_size = fn->num_counters * sizeof(fn->counters[0]);
368+
fn_dup->counters = vmalloc(cv_size);
369+
if (!fn_dup->counters) {
370+
kfree(fn_dup);
371+
return NULL;
372+
}
373+
374+
memcpy(fn_dup->counters, fn->counters, cv_size);
375+
376+
return fn_dup;
377+
}
378+
#endif
325379

326380
/**
327381
* gcov_info_dup - duplicate profiling data set
@@ -362,6 +416,7 @@ struct gcov_info *gcov_info_dup(struct gcov_info *info)
362416
* gcov_info_free - release memory for profiling data set duplicate
363417
* @info: profiling data set duplicate to free
364418
*/
419+
#if CONFIG_CLANG_VERSION < 110000
365420
void gcov_info_free(struct gcov_info *info)
366421
{
367422
struct gcov_fn_info *fn, *tmp;
@@ -375,6 +430,20 @@ void gcov_info_free(struct gcov_info *info)
375430
kfree(info->filename);
376431
kfree(info);
377432
}
433+
#else
434+
void gcov_info_free(struct gcov_info *info)
435+
{
436+
struct gcov_fn_info *fn, *tmp;
437+
438+
list_for_each_entry_safe(fn, tmp, &info->functions, head) {
439+
vfree(fn->counters);
440+
list_del(&fn->head);
441+
kfree(fn);
442+
}
443+
kfree(info->filename);
444+
kfree(info);
445+
}
446+
#endif
378447

379448
#define ITER_STRIDE PAGE_SIZE
380449

0 commit comments

Comments
 (0)