3 # (C) Copyright IBM Corporation 2006.
4 # Released under GPL v2.
5 # Author : Ram Pai (linuxram@us.ibm.com)
7 # Usage: export_report.pl -k Module.symvers [-o report_file ] -f *.mod.c
14 my $no1 = (split /\s+/, $a)[1];
15 my $no2 = (split /\s+/, $b)[1];
20 my ($module1, $value1) = @{$a};
21 my ($module2, $value2) = @{$b};
22 return $value1 <=> $value2 || $module2 cmp $module1;
25 sub print_depends_on {
28 while (my ($mod, $list) = each %$href) {
30 foreach my $sym (sort numerically @{$list}) {
31 my ($symbol, $no) = split /\s+/, $sym;
32 printf("\t\t%-25s\t%-25d\n", $symbol, $no);
41 print "Usage: @_ -h -k Module.symvers [ -o outputfile ] \n",
42 "\t-f: treat all the non-option argument as .mod.c files. ",
43 "Recommend using this as the last option\n",
44 "\t-h: print detailed help\n",
45 "\t-k: the path to Module.symvers file. By default uses ",
46 "the file from the current directory\n",
47 "\t-o outputfile: output the report to outputfile\n";
53 while (<.tmp_versions/*.mod>) {
54 open my $fh, '<', $_ or die "cannot open $_: $!\n";
56 grep s/\.ko/.mod.c/, # change the suffix
57 grep m/.+\.ko/, # find the .ko path
58 <$fh>); # lines in opened file
64 my (%SYMBOL, %MODULE, %opt, @allcfiles);
66 if (not getopts('hk:o:f',\%opt) or defined $opt{'h'}) {
70 if (defined $opt{'f'}) {
73 @allcfiles = collectcfiles();
76 if (not defined $opt{'k'}) {
77 $opt{'k'} = "Module.symvers";
80 open (my $module_symvers, '<', $opt{'k'})
81 or die "Sorry, cannot open $opt{'k'}: $!\n";
83 if (defined $opt{'o'}) {
84 open (my $out, '>', $opt{'o'})
85 or die "Sorry, cannot open $opt{'o'} $!\n";
91 # collect all the symbols and their attributes from the
94 while ( <$module_symvers> ) {
96 my (undef, $symbol, $module, $gpl) = split;
97 $SYMBOL { $symbol } = [ $module , "0" , $symbol, $gpl];
99 close($module_symvers);
102 # collect the usage count of each symbol.
104 foreach my $thismod (@allcfiles) {
107 unless (open ($module, '<', $thismod)) {
108 warn "Sorry, cannot open $thismod: $!\n";
113 while ( <$module> ) {
116 $state = 1 if ($_ =~ /static const struct modversion_info/);
120 $state = 2 if ($_ =~ /__attribute__\(\(section\("__versions"\)\)\)/);
124 if ( $_ !~ /0x[0-9a-f]+,/ ) {
127 my $sym = (split /([,"])/,)[4];
128 my ($module, $value, $symbol, $gpl) = @{$SYMBOL{$sym}};
129 $SYMBOL{ $sym } = [ $module, $value+1, $symbol, $gpl];
130 push(@{$MODULE{$thismod}} , $sym);
134 print "WARNING:$thismod is not built with CONFIG_MODVERSION enabled\n";
139 print "\tThis file reports the exported symbols usage patterns by in-tree\n",
141 printf("%s\n\n\n","x"x80);
142 printf("\t\t\t\tINDEX\n\n\n");
143 printf("SECTION 1: Usage counts of all exported symbols\n");
144 printf("SECTION 2: List of modules and the exported symbols they use\n");
145 printf("%s\n\n\n","x"x80);
146 printf("SECTION 1:\tThe exported symbols and their usage count\n\n");
147 printf("%-25s\t%-25s\t%-5s\t%-25s\n", "Symbol", "Module", "Usage count",
151 # print the list of unused exported symbols
153 foreach my $list (sort alphabetically values(%SYMBOL)) {
154 my ($module, $value, $symbol, $gpl) = @{$list};
155 printf("%-25s\t%-25s\t%-10s\t", $symbol, $module, $value);
157 printf("%-25s\n",$gpl);
162 printf("%s\n\n\n","x"x80);
164 printf("SECTION 2:\n\tThis section reports export-symbol-usage of in-kernel
165 modules. Each module lists the modules, and the symbols from that module that
166 it uses. Each listed symbol reports the number of modules using it\n");
169 while (my ($thismod, $list) = each %MODULE) {
171 $thismod =~ s/\.mod\.c/.ko/;
172 print "\t\t\t$thismod\n";
173 foreach my $symbol (@{$list}) {
174 my ($module, $value, undef, $gpl) = @{$SYMBOL{$symbol}};
175 push (@{$depends{"$module"}}, "$symbol $value");
177 print_depends_on(\%depends);