Skip to contentSkip to conversation

gcov: add prototypes for internal functions

PATCH In review Arnd Bergmann 2 participants 2 messages May 17, 2023 – Jun 21, 2023 Gcov based kernel profiling

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gcov: add prototypes for internal functions

From: Arnd Bergmann <[email protected]>

gcov uses global functions that are called from generated code, but these have no prototype in a header, which causes a W=1 build warning:

kernel/gcov/gcc_base.c:12:6: error: no previous prototype for '__gcov_init' [-Werror=missing-prototypes] kernel/gcov/gcc_base.c:40:6: error: no previous prototype for '__gcov_flush' [-Werror=missing-prototypes] kernel/gcov/gcc_base.c:46:6: error: no previous prototype for '__gcov_merge_add' [-Werror=missing-prototypes] kernel/gcov/gcc_base.c:52:6: error: no previous prototype for '__gcov_merge_single' [-Werror=missing-prototypes]

Add prototypes for all of these to an internal header.

---
 kernel/gcov/gcov.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
kernel/gcov/gcov.h +30 -0
index 912b8ea01d33..6df99772406c 100644
@@ -82,4 +82,34 @@ extern const struct gcov_link gcov_link[];
 extern int gcov_events_enabled;
 extern struct mutex gcov_lock;
 
+void __gcov_init(struct gcov_info *info);
+void __gcov_flush(void);
+void __gcov_merge_add(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_single(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_delta(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_ior(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_time_profile(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_icall_topn(gcov_type *counters, unsigned int n_counters);
+void __gcov_exit(void);
+
+size_t convert_to_gcda(char *buffer, struct gcov_info *info);
+void gcov_info_add(struct gcov_info *dst, struct gcov_info *src);
+struct gcov_info *gcov_info_dup(struct gcov_info *info);
+const char *gcov_info_filename(struct gcov_info *info);
+void gcov_info_free(struct gcov_info *info);
+int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2);
+void gcov_info_link(struct gcov_info *info);
+struct gcov_info *gcov_info_next(struct gcov_info *info);
+void gcov_info_reset(struct gcov_info *info);
+void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info);
+unsigned int gcov_info_version(struct gcov_info *info);
+bool gcov_info_within_module(struct gcov_info *info, struct module *mod);
+void llvm_gcda_emit_arcs(u32 num_counters, u64 *counters);
+void llvm_gcda_emit_function(u32 ident, u32 func_checksum, u32 cfg_checksum);
+void llvm_gcda_end_file(void);
+void llvm_gcda_start_file(const char *orig_filename, u32 version, u32 checksum);
+void llvm_gcda_summary_info(void);
+typedef void (*llvm_gcov_callback)(void);
+void llvm_gcov_init(llvm_gcov_callback writeout, llvm_gcov_callback flush);
+
 #endif /* GCOV_H */
Signature · 1 line
2.39.2
#1 lore raw
Quoted 5 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

gcov uses global functions that are called from generated code, but these have no prototype in a header, which causes a W=1 build warning:

Sorry for the late reply. I can confirm that the problem exists, both with GCC and Clang compiles. I see some issues with your fix though:

1. It contains extraneous prototypes that are duplicates of existing prototypes in gcov.h (everything that doesn't start with __gcov or llvm)

2. Adding the list of prototypes, though not actually needed by kernel source code, will require updating gcov.h if new calls from generated code are introduced - this is extra work I'd like to avoid if possible

Because this situation is special, I would rather prefer to silence these warnings by removing the associated compiler flags (-Wmissing-prototypes and I think also -Wmissing-declarations) for gcc_base.c and clang.c using CFLAGS_REMOVE.

If you agree, do you want to provide a v2 along these lines?

[...]

kernel/gcov/gcov.h extern const struct gcov_link gcov_link[]; · line 84

Quoted 6 lines
kernel/gcov/gcov.h +0 -0
@@ -82,4 +82,34 @@ extern const struct gcov_link gcov_link[];
 extern int gcov_events_enabled;
 extern struct mutex gcov_lock;
 

FYI - these are defined in gcc_base.c and called only by GCC generated code:

kernel/gcov/gcov.h extern const struct gcov_link gcov_link[]; · line 93

Quoted 9 lines
kernel/gcov/gcov.h +9 -0
+void __gcov_init(struct gcov_info *info);
+void __gcov_flush(void);
+void __gcov_merge_add(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_single(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_delta(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_ior(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_time_profile(gcov_type *counters, unsigned int n_counters);
+void __gcov_merge_icall_topn(gcov_type *counters, unsigned int n_counters);
+void __gcov_exit(void);

These are defined in both gcc_4_7.c and clang.c and used by other code in kernel/gcov/*:

kernel/gcov/gcov.h extern const struct gcov_link gcov_link[]; · line 106

Quoted 12 lines
kernel/gcov/gcov.h +12 -0
+size_t convert_to_gcda(char *buffer, struct gcov_info *info);
+void gcov_info_add(struct gcov_info *dst, struct gcov_info *src);
+struct gcov_info *gcov_info_dup(struct gcov_info *info);
+const char *gcov_info_filename(struct gcov_info *info);
+void gcov_info_free(struct gcov_info *info);
+int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2);
+void gcov_info_link(struct gcov_info *info);
+struct gcov_info *gcov_info_next(struct gcov_info *info);
+void gcov_info_reset(struct gcov_info *info);
+void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info);
+unsigned int gcov_info_version(struct gcov_info *info);
+bool gcov_info_within_module(struct gcov_info *info, struct module *mod);

And these are defined in clang.c and called only by Clang generated code:

Quoted 7 lines
kernel/gcov/gcov.h +7 -0
+void llvm_gcda_emit_arcs(u32 num_counters, u64 *counters);
+void llvm_gcda_emit_function(u32 ident, u32 func_checksum, u32 cfg_checksum);
+void llvm_gcda_end_file(void);
+void llvm_gcda_start_file(const char *orig_filename, u32 version, u32 checksum);
+void llvm_gcda_summary_info(void);
+typedef void (*llvm_gcov_callback)(void);
+void llvm_gcov_init(llvm_gcov_callback writeout, llvm_gcov_callback flush);
Signature · 2 lines
Peter Oberparleiter
Linux on IBM Z Development - IBM Germany R&D