From: Steven Rostedt Date: Wed, 22 Oct 2025 00:43:42 +0000 (-0400) Subject: tracing: Allow tracepoint-update.c to work with modules X-Git-Url: https://gentwo.org/gitweb/?a=commitdiff_plain;h=eec3516b25069d8cb51b78375e337c69a3f9e789;p=linux%2F.git tracing: Allow tracepoint-update.c to work with modules In order for tracepoint-update.c to work with modules, it cannot error out if both "__tracepoint_check" and "__tracepoints_strings" are not found. When enabled, the vmlinux.o may be required to have both, but modules only have these sections if they have tracepoints. Modules without tracepoints will not have either. They should not fail to build because of that. If one section exists the other one should too. Note, if a module defines a tracepoint but doesn't use any, it can cause this to fail. Add a new "--module" parameter to tracepoint-update to be used when running on module code. It will not error out if this is set and both sections are missing. If this is set, and only the "__tracepoint_check" section is missing, it means the module has defined tracepoints but none of them are used. In that case, it prints a warning that the module has only unused tracepoints and exits normally to not fail the build. If the "__tracepoint_check" section exists but not the "__tracepoint_strings", then that is an error and should fail the build. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Arnd Bergmann Cc: Masahiro Yamada Cc: Nathan Chancellor Cc: Nicolas Schier Cc: Nick Desaulniers Cc: Catalin Marinas Cc: Linus Torvalds Cc: Randy Dunlap Cc: Stephen Rothwell Link: https://lore.kernel.org/20251022004453.255696445@kernel.org Signed-off-by: Steven Rostedt (Google) --- diff --git a/scripts/tracepoint-update.c b/scripts/tracepoint-update.c index 6ec30f39d0ad..7f7d90df14ce 100644 --- a/scripts/tracepoint-update.c +++ b/scripts/tracepoint-update.c @@ -112,7 +112,7 @@ static int find_event(const char *str, void *array, size_t size) return bsearch(&str, array, size, sizeof(char *), compare_strings) != NULL; } -static void check_tracepoints(struct elf_tracepoint *etrace) +static void check_tracepoints(struct elf_tracepoint *etrace, const char *fname) { Elf_Ehdr *ehdr = etrace->ehdr; int len; @@ -129,22 +129,26 @@ static void check_tracepoints(struct elf_tracepoint *etrace) if (!len) continue; if (!find_event(str, etrace->array, etrace->count)) { - fprintf(stderr, "warning: tracepoint '%s' is unused.\n", str); + fprintf(stderr, "warning: tracepoint '%s' is unused", str); + if (fname) + fprintf(stderr, " in module %s\n", fname); + else + fprintf(stderr, "\n"); } } free(etrace->array); } -static void *tracepoint_check(struct elf_tracepoint *etrace) +static void *tracepoint_check(struct elf_tracepoint *etrace, const char *fname) { make_trace_array(etrace); - check_tracepoints(etrace); + check_tracepoints(etrace, fname); return NULL; } -static int process_tracepoints(void *addr, char const *const fname) +static int process_tracepoints(bool mod, void *addr, const char *fname) { struct elf_tracepoint etrace = {0}; Elf_Ehdr *ehdr = addr; @@ -188,7 +192,19 @@ static int process_tracepoints(void *addr, char const *const fname) } } + /* + * Modules may not have either section. But if it has one section, + * it should have both of them. + */ + if (mod && !check_data_sec && !tracepoint_data_sec) + return 0; + if (!check_data_sec) { + if (mod) { + fprintf(stderr, "warning: Module %s has only unused tracepoints\n", fname); + /* Do not fail build */ + return 0; + } fprintf(stderr, "no __tracepoint_check in file: %s\n", fname); return -1; } @@ -198,8 +214,11 @@ static int process_tracepoints(void *addr, char const *const fname) return -1; } + if (!mod) + fname = NULL; + etrace.ehdr = ehdr; - tracepoint_check(&etrace); + tracepoint_check(&etrace, fname); return 0; } @@ -208,9 +227,19 @@ int main(int argc, char *argv[]) int n_error = 0; size_t size = 0; void *addr = NULL; + bool mod = false; + + if (argc > 1 && strcmp(argv[1], "--module") == 0) { + mod = true; + argc--; + argv++; + } if (argc < 2) { - fprintf(stderr, "usage: tracepoint-update vmlinux...\n"); + if (mod) + fprintf(stderr, "usage: tracepoint-update --module module...\n"); + else + fprintf(stderr, "usage: tracepoint-update vmlinux...\n"); return 0; } @@ -222,7 +251,7 @@ int main(int argc, char *argv[]) continue; } - if (process_tracepoints(addr, argv[i])) + if (process_tracepoints(mod, addr, argv[i])) ++n_error; elf_unmap(addr, size);