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

Configure Feed

Select the types of activity you want to include in your feed.

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 <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas.schier@linux.dev>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Link: https://lore.kernel.org/20251022004453.255696445@kernel.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+37 -8
+37 -8
scripts/tracepoint-update.c
··· 112 112 return bsearch(&str, array, size, sizeof(char *), compare_strings) != NULL; 113 113 } 114 114 115 - static void check_tracepoints(struct elf_tracepoint *etrace) 115 + static void check_tracepoints(struct elf_tracepoint *etrace, const char *fname) 116 116 { 117 117 Elf_Ehdr *ehdr = etrace->ehdr; 118 118 int len; ··· 129 129 if (!len) 130 130 continue; 131 131 if (!find_event(str, etrace->array, etrace->count)) { 132 - fprintf(stderr, "warning: tracepoint '%s' is unused.\n", str); 132 + fprintf(stderr, "warning: tracepoint '%s' is unused", str); 133 + if (fname) 134 + fprintf(stderr, " in module %s\n", fname); 135 + else 136 + fprintf(stderr, "\n"); 133 137 } 134 138 } 135 139 136 140 free(etrace->array); 137 141 } 138 142 139 - static void *tracepoint_check(struct elf_tracepoint *etrace) 143 + static void *tracepoint_check(struct elf_tracepoint *etrace, const char *fname) 140 144 { 141 145 make_trace_array(etrace); 142 - check_tracepoints(etrace); 146 + check_tracepoints(etrace, fname); 143 147 144 148 return NULL; 145 149 } 146 150 147 - static int process_tracepoints(void *addr, char const *const fname) 151 + static int process_tracepoints(bool mod, void *addr, const char *fname) 148 152 { 149 153 struct elf_tracepoint etrace = {0}; 150 154 Elf_Ehdr *ehdr = addr; ··· 192 188 } 193 189 } 194 190 191 + /* 192 + * Modules may not have either section. But if it has one section, 193 + * it should have both of them. 194 + */ 195 + if (mod && !check_data_sec && !tracepoint_data_sec) 196 + return 0; 197 + 195 198 if (!check_data_sec) { 199 + if (mod) { 200 + fprintf(stderr, "warning: Module %s has only unused tracepoints\n", fname); 201 + /* Do not fail build */ 202 + return 0; 203 + } 196 204 fprintf(stderr, "no __tracepoint_check in file: %s\n", fname); 197 205 return -1; 198 206 } ··· 214 198 return -1; 215 199 } 216 200 201 + if (!mod) 202 + fname = NULL; 203 + 217 204 etrace.ehdr = ehdr; 218 - tracepoint_check(&etrace); 205 + tracepoint_check(&etrace, fname); 219 206 return 0; 220 207 } 221 208 ··· 227 208 int n_error = 0; 228 209 size_t size = 0; 229 210 void *addr = NULL; 211 + bool mod = false; 212 + 213 + if (argc > 1 && strcmp(argv[1], "--module") == 0) { 214 + mod = true; 215 + argc--; 216 + argv++; 217 + } 230 218 231 219 if (argc < 2) { 232 - fprintf(stderr, "usage: tracepoint-update vmlinux...\n"); 220 + if (mod) 221 + fprintf(stderr, "usage: tracepoint-update --module module...\n"); 222 + else 223 + fprintf(stderr, "usage: tracepoint-update vmlinux...\n"); 233 224 return 0; 234 225 } 235 226 ··· 251 222 continue; 252 223 } 253 224 254 - if (process_tracepoints(addr, argv[i])) 225 + if (process_tracepoints(mod, addr, argv[i])) 255 226 ++n_error; 256 227 257 228 elf_unmap(addr, size);