From: Steven Rostedt <rostedt@goodmis.org>
If a modules has TRACE_EVENT() but does not use it, add a warning about it
at build time.
Currently, the build must be made by adding "UT=1" to the make command
line in order for this to trigger.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
scripts/Makefile.modfinal | 7 +++++++
scripts/tracepoint-update.c | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 542ba462ed3e..6f909979af91 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -28,6 +28,12 @@ ccflags-remove-y := $(CC_FLAGS_CFI)
.module-common.o: $(srctree)/scripts/module-common.c FORCE
$(call if_changed_rule,cc_o_c)
+ifneq ($(WARN_ON_UNUSED_TRACEPOINTS),"")
+cmd_check_tracepoint = ${objtree}/scripts/tracepoint-update $<;
+else
+cmd_check_tracepoint =
+endif
+
quiet_cmd_ld_ko_o = LD [M] $@
cmd_ld_ko_o = \
$(LD) -r $(KBUILD_LDFLAGS) \
@@ -57,6 +63,7 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \
ifdef CONFIG_DEBUG_INFO_BTF_MODULES
+$(if $(newer-prereqs),$(call cmd,btf_ko))
endif
+ +$(call cmd,check_tracepoint)
targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) .module-common.o
diff --git a/scripts/tracepoint-update.c b/scripts/tracepoint-update.c
index 6ec30f39d0ad..7e068de9c7f1 100644
--- a/scripts/tracepoint-update.c
+++ b/scripts/tracepoint-update.c
@@ -188,6 +188,13 @@ 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 (!check_data_sec && !tracepoint_data_sec)
+ return 0;
+
if (!check_data_sec) {
fprintf(stderr, "no __tracepoint_check in file: %s\n", fname);
return -1;
--
2.51.0
Hi Steven, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-everything] [also build test ERROR on linus/master v6.18-rc1 next-20251015] [cannot apply to trace/for-next arnd-asm-generic/master] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Steven-Rostedt/sorttable-Move-ELF-parsing-into-scripts-elf-parse-ch/20251016-044008 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20251015203924.731213165%40kernel.org patch subject: [PATCH v9 4/4] tracing: Add warnings for unused tracepoints for modules config: microblaze-defconfig (https://download.01.org/0day-ci/archive/20251016/202510161811.9iIH3K15-lkp@intel.com/config) compiler: microblaze-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251016/202510161811.9iIH3K15-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202510161811.9iIH3K15-lkp@intel.com/ All errors (new ones prefixed by >>): >> /bin/bash: line 1: ./scripts/tracepoint-update: No such file or directory -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Hi Steve,
On Wed, Oct 15, 2025 at 04:38:46PM -0400, Steven Rostedt wrote:
> diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
> index 542ba462ed3e..6f909979af91 100644
> --- a/scripts/Makefile.modfinal
> +++ b/scripts/Makefile.modfinal
> @@ -28,6 +28,12 @@ ccflags-remove-y := $(CC_FLAGS_CFI)
> .module-common.o: $(srctree)/scripts/module-common.c FORCE
> $(call if_changed_rule,cc_o_c)
>
> +ifneq ($(WARN_ON_UNUSED_TRACEPOINTS),"")
Drop the "", nowhere else in Kbuild appears to do this.
> +cmd_check_tracepoint = ${objtree}/scripts/tracepoint-update $<;
Please use $(objtree) to be consistent with the rest of Kbuild.
> +else
> +cmd_check_tracepoint =
> +endif
> +
> quiet_cmd_ld_ko_o = LD [M] $@
> cmd_ld_ko_o = \
> $(LD) -r $(KBUILD_LDFLAGS) \
> @@ -57,6 +63,7 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \
> ifdef CONFIG_DEBUG_INFO_BTF_MODULES
> +$(if $(newer-prereqs),$(call cmd,btf_ko))
> endif
> + +$(call cmd,check_tracepoint)
>
> targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) .module-common.o
>
> diff --git a/scripts/tracepoint-update.c b/scripts/tracepoint-update.c
> index 6ec30f39d0ad..7e068de9c7f1 100644
> --- a/scripts/tracepoint-update.c
> +++ b/scripts/tracepoint-update.c
> @@ -188,6 +188,13 @@ 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 (!check_data_sec && !tracepoint_data_sec)
> + return 0;
> +
This feels like it could be its own patch but I guess it does not make
much sense without enablement. It might be worth calling this out a bit
more in the commit message.
> if (!check_data_sec) {
> fprintf(stderr, "no __tracepoint_check in file: %s\n", fname);
> return -1;
> --
> 2.51.0
>
>
On Wed, 15 Oct 2025 16:19:28 -0700
Nathan Chancellor <nathan@kernel.org> wrote:
> Hi Steve,
>
> On Wed, Oct 15, 2025 at 04:38:46PM -0400, Steven Rostedt wrote:
> > diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
> > index 542ba462ed3e..6f909979af91 100644
> > --- a/scripts/Makefile.modfinal
> > +++ b/scripts/Makefile.modfinal
> > @@ -28,6 +28,12 @@ ccflags-remove-y := $(CC_FLAGS_CFI)
> > .module-common.o: $(srctree)/scripts/module-common.c FORCE
> > $(call if_changed_rule,cc_o_c)
> >
> > +ifneq ($(WARN_ON_UNUSED_TRACEPOINTS),"")
>
> Drop the "", nowhere else in Kbuild appears to do this.
>
> > +cmd_check_tracepoint = ${objtree}/scripts/tracepoint-update $<;
>
> Please use $(objtree) to be consistent with the rest of Kbuild.
OK for both.
>
> > +else
> > +cmd_check_tracepoint =
> > +endif
> > +
> > quiet_cmd_ld_ko_o = LD [M] $@
> > cmd_ld_ko_o = \
> > $(LD) -r $(KBUILD_LDFLAGS) \
> > @@ -57,6 +63,7 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \
> > ifdef CONFIG_DEBUG_INFO_BTF_MODULES
> > +$(if $(newer-prereqs),$(call cmd,btf_ko))
> > endif
> > + +$(call cmd,check_tracepoint)
> >
> > targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) .module-common.o
> >
> > diff --git a/scripts/tracepoint-update.c b/scripts/tracepoint-update.c
> > index 6ec30f39d0ad..7e068de9c7f1 100644
> > --- a/scripts/tracepoint-update.c
> > +++ b/scripts/tracepoint-update.c
> > @@ -188,6 +188,13 @@ 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 (!check_data_sec && !tracepoint_data_sec)
> > + return 0;
> > +
>
> This feels like it could be its own patch but I guess it does not make
> much sense without enablement. It might be worth calling this out a bit
> more in the commit message.
>
It was found during debugging. I could make this a separate patch in
preparation for this patch.
-- Steve
> > if (!check_data_sec) {
> > fprintf(stderr, "no __tracepoint_check in file: %s\n", fname);
> > return -1;
> > --
> > 2.51.0
> >
> >
On Wed, Oct 15, 2025 at 04:19:28PM -0700, Nathan Chancellor wrote:
> Hi Steve,
>
> On Wed, Oct 15, 2025 at 04:38:46PM -0400, Steven Rostedt wrote:
> > diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
> > index 542ba462ed3e..6f909979af91 100644
> > --- a/scripts/Makefile.modfinal
> > +++ b/scripts/Makefile.modfinal
> > @@ -28,6 +28,12 @@ ccflags-remove-y := $(CC_FLAGS_CFI)
> > .module-common.o: $(srctree)/scripts/module-common.c FORCE
> > $(call if_changed_rule,cc_o_c)
> >
> > +ifneq ($(WARN_ON_UNUSED_TRACEPOINTS),"")
>
> Drop the "", nowhere else in Kbuild appears to do this.
>
> > +cmd_check_tracepoint = ${objtree}/scripts/tracepoint-update $<;
>
> Please use $(objtree) to be consistent with the rest of Kbuild.
>
> > +else
> > +cmd_check_tracepoint =
> > +endif
The else part is not required, cp. definition of e.g. cmd_checkdoc in
scripts/Makefile.build.
Kind regards
Nicolas
On Fri, 17 Oct 2025 22:22:32 +0200
Nicolas Schier <nsc@kernel.org> wrote:
> On Wed, Oct 15, 2025 at 04:19:28PM -0700, Nathan Chancellor wrote:
> > Hi Steve,
> >
> > On Wed, Oct 15, 2025 at 04:38:46PM -0400, Steven Rostedt wrote:
> > > diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
> > > index 542ba462ed3e..6f909979af91 100644
> > > --- a/scripts/Makefile.modfinal
> > > +++ b/scripts/Makefile.modfinal
> > > @@ -28,6 +28,12 @@ ccflags-remove-y := $(CC_FLAGS_CFI)
> > > .module-common.o: $(srctree)/scripts/module-common.c FORCE
> > > $(call if_changed_rule,cc_o_c)
> > >
> > > +ifneq ($(WARN_ON_UNUSED_TRACEPOINTS),"")
> >
> > Drop the "", nowhere else in Kbuild appears to do this.
> >
> > > +cmd_check_tracepoint = ${objtree}/scripts/tracepoint-update $<;
> >
> > Please use $(objtree) to be consistent with the rest of Kbuild.
> >
> > > +else
> > > +cmd_check_tracepoint =
> > > +endif
>
> The else part is not required, cp. definition of e.g. cmd_checkdoc in
> scripts/Makefile.build.
Thanks, will do.
-- Steve
© 2016 - 2025 Red Hat, Inc.