From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Arnd Bergmann <arnd@arndb.de>,
Masahiro Yamada <masahiroy@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nicolas.schier@linux.dev>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Stephen Rothwell <sfr@canb.auug.org.au>
Subject: [PATCH v10 4/5] tracing: Allow tracepoint-update.c to work with modules
Date: Tue, 21 Oct 2025 20:43:42 -0400 [thread overview]
Message-ID: <20251022004453.255696445@kernel.org> (raw)
In-Reply-To: 20251022004338.731044739@kernel.org
From: Steven Rostedt <rostedt@goodmis.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@goodmis.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
next prev parent reply other threads:[~2025-10-22 0:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 0:43 [PATCH v10 0/5] tracepoints: Add warnings for unused tracepoints and trace events Steven Rostedt
2025-10-22 0:43 ` [PATCH v10 1/5] sorttable: Move ELF parsing into scripts/elf-parse.[ch] Steven Rostedt
2025-10-22 0:43 ` [PATCH v10 2/5] tracing: Add a tracepoint verification check at build time Steven Rostedt
2025-10-22 0:43 ` [PATCH v10 3/5] tracepoint: Do not warn for unused event that is exported Steven Rostedt
2025-10-22 0:43 ` Steven Rostedt [this message]
2025-10-22 0:43 ` [PATCH v10 5/5] tracing: Add warnings for unused tracepoints for modules Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251022004453.255696445@kernel.org \
--to=rostedt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=catalin.marinas@arm.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=nicolas.schier@linux.dev \
--cc=rdunlap@infradead.org \
--cc=sfr@canb.auug.org.au \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).