KBUILD: export-symbol usage report generator
PATCH 4/4 KBUILD: export-symbol usage report generator
From: Ram Pai <[email protected]>
The following patch provides the ability to generate a report of
(1) All the exported symbols and their in-kernel-module usage count
(2) For each module, lists the modules and their exported symbols, on which it depends.
The report generation is integrated in the build process. 'make exportcheck' prints out the report.
'make exportcheck EXPORTFILE=Documentation/export_report.txt'
generates the report in the file Documentation/export_report.txt
NOTE: the same report can also be generated by executing
perl scripts/export_report
Makefile | 16 ++++- scripts/Makefile.modpost | 7 ++ scripts/export_report.pl | 148 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+), 1 deletion(-)
scripts/Makefile.modpost +7 -0
@@ -60,9 +60,16 @@ quiet_cmd_modpost = MODPOST $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ $(filter-out FORCE,$^) +quiet_cmd_importfile = IMPORT_EXTRACT + cmd_importfile = perl $(objtree)/scripts/export_report.pl \ + -k $(kernelsymfile) \ + $(if $(KBUILD_EXPORT_REPORT:1=),-o $(KBUILD_EXPORT_REPORT),) \ + -f $(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 +148 -0
148 lines not on this page · raw message
Makefile +15 -1
@@ -207,7 +207,7 @@ endif # in addition to whatever we do anyway. # Just "make" or "make all" shall build modules as well -ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) +ifneq ($(filter all _all modules exportcheck,$(MAKECMDGOALS)),) KBUILD_MODULES := 1 endif
@@ -1029,6 +1029,8 @@ help: @echo ' cscope - Generate cscope index' @echo ' kernelrelease - Output the release version string' @echo ' kernelversion - Output the version stored in Makefile' + @echo ' exportcheck [EXPORTFILE=file] - Export symbol usage analysis ' + @echo ' on compiled kernel' @echo '' @echo 'Static analysers' @echo ' checkstack - Generate a list of stack hogs'
@@ -1258,6 +1260,18 @@ versioncheck: namespacecheck: $(PERL) $(srctree)/scripts/namespace.pl +ifeq ($(MAKECMDGOALS), exportcheck) + KBUILD_EXPORT_REPORT := 1 + ifdef EXPORTFILE + ifeq ("$(origin EXPORTFILE)", "command line") + KBUILD_EXPORT_REPORT = $(EXPORTFILE) + endif + endif + export KBUILD_EXPORT_REPORT +endif +PHONY += exportcheck +exportcheck: vmlinux modules + endif #ifeq ($(config-targets),1) endif #ifeq ($(mixed-targets),1)
Quoted 6 lines · [email protected] (Ram Pai) writes:
From: Ram Pai <[email protected]>
The following patch provides the ability to generate a report of
(1) All the exported symbols and their in-kernel-module usage count
(2) For each module, lists the modules and their exported symbols, on which it depends.
Very nice.
One thing I always wanted to see was a more focussed EXPORT_SYMBOL.
A lot of symbols are only exported for a single other module (e.g. most of the networking exports are for IPv6) but are actually internal and shouldn't be messed with by other modules. It would be nice if name spaces could be defined that say "this export is only for modules in this name space" and then e.g. have IPv6 be in the TCPINTERNALS name space and nobody else.
I think adding something like this could clean up the bewildering jungle of exports greatly.
_GPL is kind of like that already, but it is not fine grained enough.
-Andi
Quoted 20 lines · Andi Kleen
Quoted 6 lines · [email protected] (Ram Pai) writes:
From: Ram Pai <[email protected]>
The following patch provides the ability to generate a report of
(1) All the exported symbols and their in-kernel-module usage count
(2) For each module, lists the modules and their exported symbols, on which it depends.Very nice.
One thing I always wanted to see was a more focussed
EXPORT_SYMBOL.A lot of symbols are only exported for a single other module (e.g. most of the networking exports are for IPv6) but are actually internal and shouldn't be messed with by other modules. It would be nice if name spaces could be defined that say "this export is only for modules in this name space" and then e.g. have IPv6 be in the TCPINTERNALS name space and nobody else.
Quoted 4 lines
I think adding something like this could clean up the bewildering jungle of exports greatly.
_GPLis kind of like that already, but it is not fine grained enough.
I'd go even further and say every symbol should have a category. These catgories than could get labels such as mostly stable, public but volatile or internal (the latter is what's oddly named _GPL) now. That way a small look at a driver can say if it's doing something wrong, e.g. if a network driver imports symbols from anything but BASE, PCI and NETDEV something is most likely wrong.
Quoted 2 lines
I'd go even further and say every symbol should have a category.
That would be a _lot_ of work. I was thinking more for some specialized symbols first where the meaning is very clear. Also someone has to write the infrastructure first.
Quoted 2 lines
These
catgories than could get labels such as mostly stable
I don't labels like "stable" etc. very much because it would give false expectations to external users.
-Andi