export symbol report: export-symbol usage report generator.
RFC PATCH 2/3 export symbol report: export-symbol usage report generator.
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 export_report' prints out the report.
'make export_report EXPORT_REPORT=Documentation/export_report.txt'
generates the report in the file Documentation/export_report.txt
Makefile | 12 ++++ scripts/Makefile.modpost | 7 ++ scripts/export_report.pl | 135 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+)
scripts/Makefile.modpost +7 -0
@@ -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) \ + $(if $(KBUILD_EXPORT_REPORT:1=),-o $(KBUILD_EXPORT_REPORT),) \ + $(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 +19 -3
@@ -185,8 +185,10 @@ HOSTCC = gcc HOSTCXX = g++ -HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -HOSTCXXFLAGS = -O2 +#HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer +HOSTCFLAGS = -Wall -Wstrict-prototypes -g -fomit-frame-pointer +#HOSTCXXFLAGS = -O2 +HOSTCXXFLAGS = -g # Decide whether to build built-in, modular, or both. # Normally, just do built-in.
@@ -433,6 +435,7 @@ core-y := usr/ endif # KBUILD_EXTMOD + ifeq ($(dot-config),1) # In this section, we need .config
@@ -873,7 +876,6 @@ @echo ' Building modules, stage 2.'; $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost - # Target to prepare building external modules PHONY += modules_prepare modules_prepare: prepare scripts
@@ -1033,6 +1035,7 @@ @echo 'Static analysers' @echo ' checkstack - Generate a list of stack hogs' @echo ' namespacecheck - Name space analysis on compiled kernel' + @echo ' export_report - Export symbols usage analysis on compile kernel' @echo '' @echo 'Kernel packaging:' @$(MAKE) $(build)=$(package-dir) help
@@ -1259,6 +1262,19 @@ namespacecheck: $(PERL) $(srctree)/scripts/namespace.pl +ifeq ($(MAKECMDGOALS), export_report) + KBUILD_EXPORT_REPORT := 1 + ifdef EXPORT_REPORT + ifeq ("$(origin EXPORT_REPORT)", "command line") + KBUILD_EXPORT_REPORT = $(EXPORT_REPORT) + endif + endif + export KBUILD_EXPORT_REPORT +endif + +PHONY += export_report +export_report: vmlinux modules + endif #ifeq ($(config-targets),1) endif #ifeq ($(mixed-targets),1)
Quoted 4 lines · [email protected] (Ram Pai) writes:
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.
Neat. Just a few Perl nits (sorry, couldn't resist).
Quoted 1 line
Signed-off-by Ram Pai <[email protected]>
[...]
Quoted 5 lines
Index:
2617rc1/scripts/export_report.pl
===================================================================scripts/export_report.pl new file +0
-0@@ -0,0 +1,134 @@
[...]
scripts/export_report.pl line 20
Quoted 3 lines
scripts/export_report.pl new file +3
-0+sub alphabetically { + ($module1, $value1, undef) = split / /, "@{$a}"; + ($module2, $value2, undef) = split / /, "@{$b}";
This:
scripts/export_report.pl line 29
Quoted 9 lines
scripts/export_report.pl new file +9
-0+ if ($value1 == $value2) { + if ($module1 lt $module2) { + return 1; + } elsif ($module1 eq $module2) { + return 0; + } + return -1; + } + return $value1 <=> $value2;
can be written more idiomatically (and readably, IMHO):
return $value1 <=> $value2 || $module1 cmp $module2;
Quoted 1 line
+}
[...]
scripts/export_report.pl line 80
Quoted 3 lines
scripts/export_report.pl new file +3
-0+# +# collect the usage count of each symbol. +#
And this:
scripts/export_report.pl line 82
Quoted 2 lines
scripts/export_report.pl new file +2
-0+for ($i = 0; $i <= $#ARGV; $i++) { + $thismod = $ARGV[$i];
could be:
foreach $thismod (@ARGV) {scripts/export_report.pl line 91
Quoted 9 lines
scripts/export_report.pl new file +9
-0+ unless (open(MODULE_MODULE, $thismod)) { + print "Sorry, cannot open $kernel: $!\n"; + next; + } + while ( <MODULE_MODULE> ) { + chomp; + if ( $_ !~ /0x[0-9a-f]{7,8},/ ) { + next; + }
Instead of this:
scripts/export_report.pl line 92
Quoted 1 line
scripts/export_report.pl new file +1
-0+ (undef, undef, undef, undef, $symbol) = split /([,"])/, $_;
some may prefer:
$symbol = (split /([,"])/)[4];
Quoted 6 lines
scripts/export_report.pl new file +6
-0+ ($module, $value, $symbol, $gpl) = @{$SYMBOL{$symbol}}; + $SYMBOL{ $symbol } = [ $module , $value+1 , $symbol, $gpl]; + push(@{$MODULE{$thismod}} , $symbol); + } + close(MODULE_MODULE); +}
[...]
scripts/export_report.pl line 127
Quoted 2 lines
scripts/export_report.pl new file +2
-0+while (($thismod, $list) = each %MODULE) { + undef %depends;
If you instead use
my %depends;
the variable will be lexically scoped to the body of the loop and thus undef at the start of each iteration. I notice the lack of 'use strict' and lexically scoped variables throughout this script, which makes it less readable and maintainable than possible, IMHO.
Quoted 7 lines
scripts/export_report.pl new file +7
-0+ print "\t\t\t$thismod\n"; + foreach $symbol (@{$list}) { + ($module, $value, undef, $gpl) = @{$SYMBOL{$symbol}}; + push (@{$depends{"$module"}}, "$symbol $value"); + } + print_depends_on(\%depends); +}
Signature · 3 lines
ilmari "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen