Skip to content

Commit eec3516

Browse files
committed
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>
1 parent faf9381 commit eec3516

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

scripts/tracepoint-update.c

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int find_event(const char *str, void *array, size_t size)
112112
return bsearch(&str, array, size, sizeof(char *), compare_strings) != NULL;
113113
}
114114

115-
static void check_tracepoints(struct elf_tracepoint *etrace)
115+
static void check_tracepoints(struct elf_tracepoint *etrace, const char *fname)
116116
{
117117
Elf_Ehdr *ehdr = etrace->ehdr;
118118
int len;
@@ -129,22 +129,26 @@ static void check_tracepoints(struct elf_tracepoint *etrace)
129129
if (!len)
130130
continue;
131131
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");
133137
}
134138
}
135139

136140
free(etrace->array);
137141
}
138142

139-
static void *tracepoint_check(struct elf_tracepoint *etrace)
143+
static void *tracepoint_check(struct elf_tracepoint *etrace, const char *fname)
140144
{
141145
make_trace_array(etrace);
142-
check_tracepoints(etrace);
146+
check_tracepoints(etrace, fname);
143147

144148
return NULL;
145149
}
146150

147-
static int process_tracepoints(void *addr, char const *const fname)
151+
static int process_tracepoints(bool mod, void *addr, const char *fname)
148152
{
149153
struct elf_tracepoint etrace = {0};
150154
Elf_Ehdr *ehdr = addr;
@@ -188,7 +192,19 @@ static int process_tracepoints(void *addr, char const *const fname)
188192
}
189193
}
190194

195+
/*
196+
* Modules may not have either section. But if it has one section,
197+
* it should have both of them.
198+
*/
199+
if (mod && !check_data_sec && !tracepoint_data_sec)
200+
return 0;
201+
191202
if (!check_data_sec) {
203+
if (mod) {
204+
fprintf(stderr, "warning: Module %s has only unused tracepoints\n", fname);
205+
/* Do not fail build */
206+
return 0;
207+
}
192208
fprintf(stderr, "no __tracepoint_check in file: %s\n", fname);
193209
return -1;
194210
}
@@ -198,8 +214,11 @@ static int process_tracepoints(void *addr, char const *const fname)
198214
return -1;
199215
}
200216

217+
if (!mod)
218+
fname = NULL;
219+
201220
etrace.ehdr = ehdr;
202-
tracepoint_check(&etrace);
221+
tracepoint_check(&etrace, fname);
203222
return 0;
204223
}
205224

@@ -208,9 +227,19 @@ int main(int argc, char *argv[])
208227
int n_error = 0;
209228
size_t size = 0;
210229
void *addr = NULL;
230+
bool mod = false;
231+
232+
if (argc > 1 && strcmp(argv[1], "--module") == 0) {
233+
mod = true;
234+
argc--;
235+
argv++;
236+
}
211237

212238
if (argc < 2) {
213-
fprintf(stderr, "usage: tracepoint-update vmlinux...\n");
239+
if (mod)
240+
fprintf(stderr, "usage: tracepoint-update --module module...\n");
241+
else
242+
fprintf(stderr, "usage: tracepoint-update vmlinux...\n");
214243
return 0;
215244
}
216245

@@ -222,7 +251,7 @@ int main(int argc, char *argv[])
222251
continue;
223252
}
224253

225-
if (process_tracepoints(addr, argv[i]))
254+
if (process_tracepoints(mod, addr, argv[i]))
226255
++n_error;
227256

228257
elf_unmap(addr, size);

0 commit comments

Comments
 (0)