VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
cb77f0d623ff3 (Kamil Rytarowski  2017-05-07 23:25:26 +0200   1) #!/usr/bin/env perl
59bd9ded4d780 (Thomas Gleixner   2019-05-28 10:10:12 -0700   2) # SPDX-License-Identifier: GPL-2.0-only
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700   3) #
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700   4) # (C) Copyright IBM Corporation 2006.
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700   5) #	Author : Ram Pai (linuxram@us.ibm.com)
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700   6) #
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700   7) # Usage: export_report.pl -k Module.symvers [-o report_file ] -f *.mod.c
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700   8) #
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700   9) 
cb77f0d623ff3 (Kamil Rytarowski  2017-05-07 23:25:26 +0200  10) use warnings;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  11) use Getopt::Std;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  12) use strict;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  13) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  14) sub numerically {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  15) 	my $no1 = (split /\s+/, $a)[1];
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  16) 	my $no2 = (split /\s+/, $b)[1];
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  17) 	return $no1 <=> $no2;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  18) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  19) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  20) sub alphabetically {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  21) 	my ($module1, $value1) = @{$a};
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  22) 	my ($module2, $value2) = @{$b};
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  23) 	return $value1 <=> $value2 || $module2 cmp $module1;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  24) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  25) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  26) sub print_depends_on {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  27) 	my ($href) = @_;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  28) 	print "\n";
bdabc7a345db9 (Jim Cromie        2011-05-23 12:44:56 -0600  29) 	for my $mod (sort keys %$href) {
bdabc7a345db9 (Jim Cromie        2011-05-23 12:44:56 -0600  30) 		my $list = $href->{$mod};
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  31) 		print "\t$mod:\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  32) 		foreach my $sym (sort numerically @{$list}) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  33) 			my ($symbol, $no) = split /\s+/, $sym;
bdabc7a345db9 (Jim Cromie        2011-05-23 12:44:56 -0600  34) 			printf("\t\t%-25s\n", $symbol);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  35) 		}
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  36) 		print "\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  37) 	}
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  38) 	print "\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  39) 	print "~"x80 , "\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  40) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  41) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  42) sub usage {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  43)         print "Usage: @_ -h -k Module.symvers  [ -o outputfile ] \n",
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  44) 	      "\t-f: treat all the non-option argument as .mod.c files. ",
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  45) 	      "Recommend using this as the last option\n",
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  46) 	      "\t-h: print detailed help\n",
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  47) 	      "\t-k: the path to Module.symvers file. By default uses ",
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  48) 	      "the file from the current directory\n",
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  49) 	      "\t-o outputfile: output the report to outputfile\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  50) 	exit 0;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  51) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  52) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  53) sub collectcfiles {
de7b0b4110795 (Jim Cromie        2011-05-23 12:44:55 -0600  54)     my @file;
7deb55f57159f (Masahiro Yamada   2019-07-17 15:17:56 +0900  55)     open my $fh, '< modules.order' or die "cannot open modules.order: $!\n";
7deb55f57159f (Masahiro Yamada   2019-07-17 15:17:56 +0900  56)     while (<$fh>) {
7deb55f57159f (Masahiro Yamada   2019-07-17 15:17:56 +0900  57) 	s/\.ko$/.mod.c/;
7deb55f57159f (Masahiro Yamada   2019-07-17 15:17:56 +0900  58) 	push (@file, $_)
de7b0b4110795 (Jim Cromie        2011-05-23 12:44:55 -0600  59)     }
7deb55f57159f (Masahiro Yamada   2019-07-17 15:17:56 +0900  60)     close($fh);
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  61)     chomp @file;
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  62)     return @file;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  63) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  64) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  65) my (%SYMBOL, %MODULE, %opt, @allcfiles);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  66) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  67) if (not getopts('hk:o:f',\%opt) or defined $opt{'h'}) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  68)         usage($0);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  69) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  70) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  71) if (defined $opt{'f'}) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  72) 	@allcfiles = @ARGV;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  73) } else {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  74) 	@allcfiles = collectcfiles();
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  75) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  76) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  77) if (not defined $opt{'k'}) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  78) 	$opt{'k'} = "Module.symvers";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  79) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  80) 
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  81) open (my $module_symvers, '<', $opt{'k'})
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  82)     or die "Sorry, cannot open $opt{'k'}: $!\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  83) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  84) if (defined $opt{'o'}) {
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  85)     open (my $out, '>', $opt{'o'})
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  86) 	or die "Sorry, cannot open $opt{'o'} $!\n";
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  87) 
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  88)     select $out;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  89) }
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  90) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  91) #
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  92) # collect all the symbols and their attributes from the
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  93) # Module.symvers file
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  94) #
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800  95) while ( <$module_symvers> ) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  96) 	chomp;
5190044c29655 (Jessica Yu        2020-03-11 18:01:20 +0100  97) 	my (undef, $symbol, $module, $gpl, $namespace) = split('\t');
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  98) 	$SYMBOL { $symbol } =  [ $module , "0" , $symbol, $gpl];
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700  99) }
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800 100) close($module_symvers);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 101) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 102) #
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 103) # collect the usage count of each symbol.
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 104) #
ca995cbf77f3d (Jim Cromie        2011-05-23 12:44:57 -0600 105) my $modversion_warnings = 0;
ca995cbf77f3d (Jim Cromie        2011-05-23 12:44:57 -0600 106) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 107) foreach my $thismod (@allcfiles) {
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800 108) 	my $module;
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800 109) 
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800 110) 	unless (open ($module, '<', $thismod)) {
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800 111) 		warn "Sorry, cannot open $thismod: $!\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 112) 		next;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 113) 	}
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800 114) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 115) 	my $state=0;
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800 116) 	while ( <$module> ) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 117) 		chomp;
88f567f3a3c19 (Ram Pai           2007-08-24 15:32:22 -0700 118) 		if ($state == 0) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 119) 			$state = 1 if ($_ =~ /static const struct modversion_info/);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 120) 			next;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 121) 		}
88f567f3a3c19 (Ram Pai           2007-08-24 15:32:22 -0700 122) 		if ($state == 1) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 123) 			$state = 2 if ($_ =~ /__attribute__\(\(section\("__versions"\)\)\)/);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 124) 			next;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 125) 		}
88f567f3a3c19 (Ram Pai           2007-08-24 15:32:22 -0700 126) 		if ($state == 2) {
cf9a6adeae706 (Adrian Bunk       2007-08-24 23:04:51 +0200 127) 			if ( $_ !~ /0x[0-9a-f]+,/ ) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 128) 				next;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 129) 			}
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 130) 			my $sym = (split /([,"])/,)[4];
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 131) 			my ($module, $value, $symbol, $gpl) = @{$SYMBOL{$sym}};
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 132) 			$SYMBOL{ $sym } =  [ $module, $value+1, $symbol, $gpl];
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 133) 			push(@{$MODULE{$thismod}} , $sym);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 134) 		}
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 135) 	}
88f567f3a3c19 (Ram Pai           2007-08-24 15:32:22 -0700 136) 	if ($state != 2) {
ca995cbf77f3d (Jim Cromie        2011-05-23 12:44:57 -0600 137) 		warn "WARNING:$thismod is not built with CONFIG_MODVERSIONS enabled\n";
ca995cbf77f3d (Jim Cromie        2011-05-23 12:44:57 -0600 138) 		$modversion_warnings++;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 139) 	}
91416cfdf98bd (Stephen Hemminger 2010-02-22 15:17:22 -0800 140) 	close($module);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 141) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 142) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 143) print "\tThis file reports the exported symbols usage patterns by in-tree\n",
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 144) 	"\t\t\t\tmodules\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 145) printf("%s\n\n\n","x"x80);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 146) printf("\t\t\t\tINDEX\n\n\n");
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 147) printf("SECTION 1: Usage counts of all exported symbols\n");
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 148) printf("SECTION 2: List of modules and the exported symbols they use\n");
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 149) printf("%s\n\n\n","x"x80);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 150) printf("SECTION 1:\tThe exported symbols and their usage count\n\n");
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 151) printf("%-25s\t%-25s\t%-5s\t%-25s\n", "Symbol", "Module", "Usage count",
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 152) 	"export type");
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 153) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 154) #
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 155) # print the list of unused exported symbols
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 156) #
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 157) foreach my $list (sort alphabetically values(%SYMBOL)) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 158) 	my ($module, $value, $symbol, $gpl) = @{$list};
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 159) 	printf("%-25s\t%-25s\t%-10s\t", $symbol, $module, $value);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 160) 	if (defined $gpl) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 161) 		printf("%-25s\n",$gpl);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 162) 	} else {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 163) 		printf("\n");
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 164) 	}
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 165) }
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 166) printf("%s\n\n\n","x"x80);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 167) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 168) printf("SECTION 2:\n\tThis section reports export-symbol-usage of in-kernel
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 169) modules. Each module lists the modules, and the symbols from that module that
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 170) it uses.  Each listed symbol reports the number of modules using it\n");
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 171) 
ca995cbf77f3d (Jim Cromie        2011-05-23 12:44:57 -0600 172) print "\nNOTE: Got $modversion_warnings CONFIG_MODVERSIONS warnings\n\n"
ca995cbf77f3d (Jim Cromie        2011-05-23 12:44:57 -0600 173)     if $modversion_warnings;
ca995cbf77f3d (Jim Cromie        2011-05-23 12:44:57 -0600 174) 
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 175) print "~"x80 , "\n";
bdabc7a345db9 (Jim Cromie        2011-05-23 12:44:56 -0600 176) for my $thismod (sort keys %MODULE) {
bdabc7a345db9 (Jim Cromie        2011-05-23 12:44:56 -0600 177) 	my $list = $MODULE{$thismod};
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 178) 	my %depends;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 179) 	$thismod =~ s/\.mod\.c/.ko/;
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 180) 	print "\t\t\t$thismod\n";
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 181) 	foreach my $symbol (@{$list}) {
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 182) 		my ($module, $value, undef, $gpl) = @{$SYMBOL{$symbol}};
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 183) 		push (@{$depends{"$module"}}, "$symbol $value");
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 184) 	}
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 185) 	print_depends_on(\%depends);
c5e3003381f4e (Ram Pai           2006-06-23 16:44:38 -0700 186) }