Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kcov: add prototypes for helper functions

A number of internal functions in kcov are only called from generated code
and don't technically need a declaration, but 'make W=1' warns about
global symbols without a prototype:

kernel/kcov.c:199:14: error: no previous prototype for '__sanitizer_cov_trace_pc' [-Werror=missing-prototypes]
kernel/kcov.c:264:14: error: no previous prototype for '__sanitizer_cov_trace_cmp1' [-Werror=missing-prototypes]
kernel/kcov.c:270:14: error: no previous prototype for '__sanitizer_cov_trace_cmp2' [-Werror=missing-prototypes]
kernel/kcov.c:276:14: error: no previous prototype for '__sanitizer_cov_trace_cmp4' [-Werror=missing-prototypes]
kernel/kcov.c:282:14: error: no previous prototype for '__sanitizer_cov_trace_cmp8' [-Werror=missing-prototypes]
kernel/kcov.c:288:14: error: no previous prototype for '__sanitizer_cov_trace_const_cmp1' [-Werror=missing-prototypes]
kernel/kcov.c:295:14: error: no previous prototype for '__sanitizer_cov_trace_const_cmp2' [-Werror=missing-prototypes]
kernel/kcov.c:302:14: error: no previous prototype for '__sanitizer_cov_trace_const_cmp4' [-Werror=missing-prototypes]
kernel/kcov.c:309:14: error: no previous prototype for '__sanitizer_cov_trace_const_cmp8' [-Werror=missing-prototypes]
kernel/kcov.c:316:14: error: no previous prototype for '__sanitizer_cov_trace_switch' [-Werror=missing-prototypes]

Adding prototypes for these in a header solves that problem, but now there
is a mismatch between the built-in type and the prototype on 64-bit
architectures because they expect some functions to take a 64-bit
'unsigned long' argument rather than an 'unsigned long long' u64 type:

include/linux/kcov.h:84:6: error: conflicting types for built-in function '__sanitizer_cov_trace_switch'; expected 'void(long long unsigned int, void *)' [-Werror=builtin-declaration-mismatch]
84 | void __sanitizer_cov_trace_switch(u64 val, u64 *cases);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Avoid this as well with a custom type definition.

Link: https://lkml.kernel.org/r/20230517124944.929997-1-arnd@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Rong Tao <rongtao@cestc.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Arnd Bergmann and committed by
Andrew Morton
e0ddec73 3403bb4e

+21 -3
+17
include/linux/kcov.h
··· 72 72 kcov_remote_stop(); 73 73 } 74 74 75 + #ifdef CONFIG_64BIT 76 + typedef unsigned long kcov_u64; 77 + #else 78 + typedef unsigned long long kcov_u64; 79 + #endif 80 + 81 + void __sanitizer_cov_trace_pc(void); 82 + void __sanitizer_cov_trace_cmp1(u8 arg1, u8 arg2); 83 + void __sanitizer_cov_trace_cmp2(u16 arg1, u16 arg2); 84 + void __sanitizer_cov_trace_cmp4(u32 arg1, u32 arg2); 85 + void __sanitizer_cov_trace_cmp8(kcov_u64 arg1, kcov_u64 arg2); 86 + void __sanitizer_cov_trace_const_cmp1(u8 arg1, u8 arg2); 87 + void __sanitizer_cov_trace_const_cmp2(u16 arg1, u16 arg2); 88 + void __sanitizer_cov_trace_const_cmp4(u32 arg1, u32 arg2); 89 + void __sanitizer_cov_trace_const_cmp8(kcov_u64 arg1, kcov_u64 arg2); 90 + void __sanitizer_cov_trace_switch(kcov_u64 val, void *cases); 91 + 75 92 #else 76 93 77 94 static inline void kcov_task_init(struct task_struct *t) {}
+4 -3
kernel/kcov.c
··· 279 279 } 280 280 EXPORT_SYMBOL(__sanitizer_cov_trace_cmp4); 281 281 282 - void notrace __sanitizer_cov_trace_cmp8(u64 arg1, u64 arg2) 282 + void notrace __sanitizer_cov_trace_cmp8(kcov_u64 arg1, kcov_u64 arg2) 283 283 { 284 284 write_comp_data(KCOV_CMP_SIZE(3), arg1, arg2, _RET_IP_); 285 285 } ··· 306 306 } 307 307 EXPORT_SYMBOL(__sanitizer_cov_trace_const_cmp4); 308 308 309 - void notrace __sanitizer_cov_trace_const_cmp8(u64 arg1, u64 arg2) 309 + void notrace __sanitizer_cov_trace_const_cmp8(kcov_u64 arg1, kcov_u64 arg2) 310 310 { 311 311 write_comp_data(KCOV_CMP_SIZE(3) | KCOV_CMP_CONST, arg1, arg2, 312 312 _RET_IP_); 313 313 } 314 314 EXPORT_SYMBOL(__sanitizer_cov_trace_const_cmp8); 315 315 316 - void notrace __sanitizer_cov_trace_switch(u64 val, u64 *cases) 316 + void notrace __sanitizer_cov_trace_switch(kcov_u64 val, void *arg) 317 317 { 318 318 u64 i; 319 + u64 *cases = arg; 319 320 u64 count = cases[0]; 320 321 u64 size = cases[1]; 321 322 u64 type = KCOV_CMP_CONST;