Skip to contentSkip to conversation

Makefile: export-symbol usage report generator.

RFC PATCH In review Ram Pai 2 participants 6 messages Apr 14, 2006 – Apr 20, 2006 Kbuild

lore
Share & tools
lore

Ram Pai

author
#0 lore raw

RFC PATCH 1/2 Makefile: export-symbol usage report generator.

I ran a report to extract export-symbol usage by kernel modules. The results are at http://www.sudhaa.com/~ram/misc/export_report.txt

The report lists:
1. All the exported symbols and their usage counts by in-kernel modules.
2. for each in-kernel module, lists the modules and the exported symbols from those modules, that it depends on.

Highlights:
On x86 architecture
(1) 880 exported symbols not used by any in-kernel modules.
(2) 1792 exported symbols used only once.

I hope this report/tool shall help all inkernel modules to revisit their usage of kernel interfaces.

This patch integrates the report-generator into the kernel build process. After applying this patch, invoke 'make export_report' and it creates the report in Documentation/export_report.txt

Signed-off-by Ram Pai ([email protected])

 Makefile                 |   12 ++++
 scripts/Makefile.modpost |    7 ++
 scripts/export_report.pl    |  135 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 154 insertions(+)
scripts/Makefile.modpost +7 -0
Index: 2617rc1/scripts/Makefile.modpost
===================================================================
@@ -60,9 +60,16 @@
 	$(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
 	$(filter-out FORCE,$^)
 
+quiet_cmd_importfile = IMPORT_EXTRACT
+      cmd_importfile =  perl $(objtree)/scripts/export_report.pl  \
+	-k $(kernelsymfile) \
+	-o $(objtree)/Documentation/export_report.txt	\
+	$(patsubst %.o,%.mod.c,$(filter-out vmlinux FORCE, $^))
+
 PHONY += __modpost
 __modpost: $(wildcard vmlinux) $(modules:.ko=.o) FORCE
 	$(call cmd,modpost)
+	$(if $(KBUILD_EXPORT_REPORT), $(call cmd,importfile))
 
 # Declare generated files as targets for modpost
 $(symverfile):         __modpost ;
scripts/export_report.pl new file +134 -0

134 lines not on this page · raw message

Makefile +13 -1
Index: 2617rc1/Makefile
===================================================================
@@ -363,7 +363,7 @@
 # Detect when mixed targets is specified, and make a second invocation
 # of make so .config is not included in this case either (for *config).
 
-no-dot-config-targets := clean mrproper distclean \
+no-dot-config-targets := clean mrproper distclean export_report\
 			 cscope TAGS tags help %docs check%
 
 config-targets := 0
@@ -433,6 +433,16 @@
 core-y		:= usr/
 endif # KBUILD_EXTMOD
 
+ifeq ($(MAKECMDGOALS), export_report)
+  	KBUILD_EXPORT_REPORT := 1
+	export KBUILD_EXPORT_REPORT
+endif
+
+PHONY += export_report
+export_report: FORCE
+	$(Q)$(MAKE) allmodconfig 
+	$(Q)$(MAKE) vmlinux modules
+
 ifeq ($(dot-config),1)
 # In this section, we need .config
 
@@ -1029,6 +1039,8 @@
 	@echo  '  cscope	  - Generate cscope index'
 	@echo  '  kernelrelease	  - Output the release version string'
 	@echo  '  kernelversion	  - Output the version stored in Makefile'
+	@echo  '  export_report	  - Output the export symbol usage '
+	@echo  '		 	in Documentation/export_symbol.txt'
 	@echo  ''
 	@echo  'Static analysers'
 	@echo  '  checkstack      - Generate a list of stack hogs'
#1 lore raw
Quoted 13 lines · Ram Pai

I ran a report to extract export-symbol usage by kernel modules. The results are at http://www.sudhaa.com/~ram/misc/export_report.txt

The report lists:
1. All the exported symbols and their usage counts by in-kernel modules.
2. for each in-kernel module, lists the modules and the exported symbols from those modules, that it depends on.

Highlights:
On x86 architecture
(1) 880 exported symbols not used by any in-kernel modules.
(2) 1792 exported symbols used only once.

Quoted 7 lines

I hope this report/tool shall help all inkernel modules to revisit their usage of kernel interfaces.

This patch integrates the report-generator into the kernel build process. After applying this patch, invoke 'make export_report' and it creates the report in Documentation/export_report.txt
...

I like your patch, but I have observed two issues:
- please don't force an allmodconfig, simply use the currently compiled kernel
- please output to stdout instead of a fixed file

This way, it would also be consistent with other Makefile targets like namespacecheck.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
author
#2 lore raw
Quoted 18 lines · Adrian Bunk
Quoted 16 lines · Ram Pai

I ran a report to extract export-symbol usage by kernel modules. The results are at http://www.sudhaa.com/~ram/misc/export_report.txt

The report lists:
1. All the exported symbols and their usage counts by in-kernel modules.
2. for each in-kernel module, lists the modules and the exported symbols from those modules, that it depends on.

Highlights:
On x86 architecture
(1) 880 exported symbols not used by any in-kernel modules.
(2) 1792 exported symbols used only once.

I hope this report/tool shall help all inkernel modules to revisit their usage of kernel interfaces.

Quoted 8 lines
Quoted 4 lines

This patch integrates the report-generator into the kernel build process. After applying this patch, invoke 'make export_report' and it creates the report in Documentation/export_report.txt
...

I like your patch, but I have observed two issues:
- please don't force an allmodconfig, simply use the currently compiled kernel

Looking for ideas. Its hard to extract out the imported symbols unless they are compiled as modules. Running the report on a currently compiled kernel will miss most of the subsystems that are not compile as modules. Hence the report wont be complete. Any suggestions?

Quoted 1 line

- please output to stdout instead of a fixed file

ok.

Quoted 7 lines

This way, it would also be consistent with other Makefile targets like namespacecheck.

cu
Adrian

#3 lore raw
Quoted 28 lines · Ram Pai
Quoted 18 lines · Adrian Bunk
Quoted 16 lines · Ram Pai

I ran a report to extract export-symbol usage by kernel modules. The results are at http://www.sudhaa.com/~ram/misc/export_report.txt

The report lists:
1. All the exported symbols and their usage counts by in-kernel modules.
2. for each in-kernel module, lists the modules and the exported symbols from those modules, that it depends on.

Highlights:
On x86 architecture
(1) 880 exported symbols not used by any in-kernel modules.
(2) 1792 exported symbols used only once.

I hope this report/tool shall help all inkernel modules to revisit their usage of kernel interfaces.

Quoted 8 lines
Quoted 4 lines

This patch integrates the report-generator into the kernel build process. After applying this patch, invoke 'make export_report' and it creates the report in Documentation/export_report.txt
...

I like your patch, but I have observed two issues:
- please don't force an allmodconfig, simply use the currently compiled kernel

Quoted 5 lines

Looking for ideas. Its hard to extract out the imported symbols unless they are compiled as modules. Running the report on a currently compiled kernel will miss most of the subsystems that are not compile as modules. Hence the report wont be complete. Any suggestions?
...

- it's a tool for kernel hackers who know what they are doing
- it's a tool to help you finding unused exports, but each one still requires manual verification

Besides this, e.g. CONFIG_SMP=n brings you more modules and therefore a better coverage than allmodconfig.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
author
#4 lore raw
Quoted 35 lines · Adrian Bunk
Quoted 28 lines · Ram Pai
Quoted 18 lines · Adrian Bunk
Quoted 16 lines · Ram Pai

I ran a report to extract export-symbol usage by kernel modules. The results are at http://www.sudhaa.com/~ram/misc/export_report.txt

The report lists:
1. All the exported symbols and their usage counts by in-kernel modules.
2. for each in-kernel module, lists the modules and the exported symbols from those modules, that it depends on.

Highlights:
On x86 architecture
(1) 880 exported symbols not used by any in-kernel modules.
(2) 1792 exported symbols used only once.

I hope this report/tool shall help all inkernel modules to revisit their usage of kernel interfaces.

Quoted 8 lines
Quoted 4 lines

This patch integrates the report-generator into the kernel build process. After applying this patch, invoke 'make export_report' and it creates the report in Documentation/export_report.txt
...

I like your patch, but I have observed two issues:
- please don't force an allmodconfig, simply use the currently compiled kernel

Quoted 5 lines

Looking for ideas. Its hard to extract out the imported symbols unless they are compiled as modules. Running the report on a currently compiled kernel will miss most of the subsystems that are not compile as modules. Hence the report wont be complete. Any suggestions?
...

Quoted 3 lines

- it's a tool for kernel hackers who know what they are doing
- it's a tool to help you finding unused exports, but each one still requires manual verification

I am not sure I understand you. Are you saying:

A) the tool should report the export symbol usage with whatever set of modules the user has configured in his .config ?

or

B) the tool should report the export symbol usage for all the modules irrespective of what has been configured in the users .config ?
RP

Quoted 7 lines

Besides this, e.g. CONFIG_SMP=n brings you more modules and therefore a better coverage than allmodconfig.

cu
Adrian

#5 lore raw
Quoted 8 lines · Ram Pai
Quoted 4 lines · Adrian Bunk

- it's a tool for kernel hackers who know what they are doing
- it's a tool to help you finding unused exports, but each one still requires manual verification

I am not sure I understand you. Are you saying:

Quoted 8 lines

A) the tool should report the export symbol usage with whatever set of modules the user has configured in his .config ?

or

B) the tool should report the export symbol usage for all the modules irrespective of what has been configured in the users .config ?

A)

Quoted 1 line

RP

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed