2 # SPDX-License-Identifier: GPL-2.0-only
4 # (C) Copyright IBM Corporation 2006.
5 # Author : Ram Pai (linuxram@us.ibm.com)
7 # Usage: export_report.pl -k Module.symvers [-o report_file ] -f *.mod.c
15 my $no1 = (split /\s+/, $a)[1];
16 my $no2 = (split /\s+/, $b)[1];
21 my ($module1, $value1) = @
{$a};
22 my ($module2, $value2) = @
{$b};
23 return $value1 <=> $value2 || $module2 cmp $module1;
26 sub print_depends_on
{
29 for my $mod (sort keys %$href) {
30 my $list = $href->{$mod};
32 foreach my $sym (sort numerically @
{$list}) {
33 my ($symbol, $no) = split /\s+/, $sym;
34 printf("\t\t%-25s\n", $symbol);
43 print "Usage: @_ -h -k Module.symvers [ -o outputfile ] \n",
44 "\t-f: treat all the non-option argument as .mod.c files. ",
45 "Recommend using this as the last option\n",
46 "\t-h: print detailed help\n",
47 "\t-k: the path to Module.symvers file. By default uses ",
48 "the file from the current directory\n",
49 "\t-o outputfile: output the report to outputfile\n";
55 open my $fh, '< modules.order' or die "cannot open modules.order: $!\n";
65 my (%SYMBOL, %MODULE, %opt, @allcfiles);
67 if (not getopts
('hk:o:f',\
%opt) or defined $opt{'h'}) {
71 if (defined $opt{'f'}) {
74 @allcfiles = collectcfiles
();
77 if (not defined $opt{'k'}) {
78 $opt{'k'} = "Module.symvers";
81 open (my $module_symvers, '<', $opt{'k'})
82 or die "Sorry, cannot open $opt{'k'}: $!\n";
84 if (defined $opt{'o'}) {
85 open (my $out, '>', $opt{'o'})
86 or die "Sorry, cannot open $opt{'o'} $!\n";
92 # collect all the symbols and their attributes from the
95 while ( <$module_symvers> ) {
97 my (undef, $symbol, $namespace, $module, $gpl) = split('\t');
98 $SYMBOL { $symbol } = [ $module , "0" , $symbol, $gpl];
100 close($module_symvers);
103 # collect the usage count of each symbol.
105 my $modversion_warnings = 0;
107 foreach my $thismod (@allcfiles) {
110 unless (open ($module, '<', $thismod)) {
111 warn "Sorry, cannot open $thismod: $!\n";
116 while ( <$module> ) {
119 $state = 1 if ($_ =~ /static const struct modversion_info/);
123 $state = 2 if ($_ =~ /__attribute__\(\(section\("__versions"\)\)\)/);
127 if ( $_ !~ /0x[0-9a-f]+,/ ) {
130 my $sym = (split /([,"])/,)[4];
131 my ($module, $value, $symbol, $gpl) = @
{$SYMBOL{$sym}};
132 $SYMBOL{ $sym } = [ $module, $value+1, $symbol, $gpl];
133 push(@
{$MODULE{$thismod}} , $sym);
137 warn "WARNING:$thismod is not built with CONFIG_MODVERSIONS enabled\n";
138 $modversion_warnings++;
143 print "\tThis file reports the exported symbols usage patterns by in-tree\n",
145 printf("%s\n\n\n","x"x80
);
146 printf("\t\t\t\tINDEX\n\n\n");
147 printf("SECTION 1: Usage counts of all exported symbols\n");
148 printf("SECTION 2: List of modules and the exported symbols they use\n");
149 printf("%s\n\n\n","x"x80
);
150 printf("SECTION 1:\tThe exported symbols and their usage count\n\n");
151 printf("%-25s\t%-25s\t%-5s\t%-25s\n", "Symbol", "Module", "Usage count",
155 # print the list of unused exported symbols
157 foreach my $list (sort alphabetically
values(%SYMBOL)) {
158 my ($module, $value, $symbol, $gpl) = @
{$list};
159 printf("%-25s\t%-25s\t%-10s\t", $symbol, $module, $value);
161 printf("%-25s\n",$gpl);
166 printf("%s\n\n\n","x"x80
);
168 printf("SECTION 2:\n\tThis section reports export-symbol-usage of in-kernel
169 modules. Each module lists the modules, and the symbols from that module that
170 it uses. Each listed symbol reports the number of modules using it\n");
172 print "\nNOTE: Got $modversion_warnings CONFIG_MODVERSIONS warnings\n\n"
173 if $modversion_warnings;
176 for my $thismod (sort keys %MODULE) {
177 my $list = $MODULE{$thismod};
179 $thismod =~ s/\.mod\.c/.ko/;
180 print "\t\t\t$thismod\n";
181 foreach my $symbol (@
{$list}) {
182 my ($module, $value, undef, $gpl) = @
{$SYMBOL{$symbol}};
183 push (@
{$depends{"$module"}}, "$symbol $value");
185 print_depends_on
(\
%depends);