From: Steven Rostedt <[email protected]>

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) <[email protected]>
---
 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



Reply via email to