[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251022004453.255696445@kernel.org>
Date: Tue, 21 Oct 2025 20:43:42 -0400
From: Steven Rostedt <rostedt@...nel.org>
To: linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org,
linux-kbuild@...r.kernel.org
Cc: Masami Hiramatsu <mhiramat@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Arnd Bergmann <arnd@...db.de>,
Masahiro Yamada <masahiroy@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Nicolas Schier <nicolas.schier@...ux.dev>,
Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
Catalin Marinas <catalin.marinas@....com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Randy Dunlap <rdunlap@...radead.org>,
Stephen Rothwell <sfr@...b.auug.org.au>
Subject: [PATCH v10 4/5] tracing: Allow tracepoint-update.c to work with modules
From: Steven Rostedt <rostedt@...dmis.org>
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.
Signed-off-by: Steven Rostedt (Google) <rostedt@...dmis.org>
---
scripts/tracepoint-update.c | 45 ++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 8 deletions(-)
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);
--
2.51.0
Powered by blists - more mailing lists