]> git.proxmox.com Git - pve-kernel.git/blame - debian/scripts/abi-check
debian/scripts: add patchqueue scripts
[pve-kernel.git] / debian / scripts / abi-check
CommitLineData
2f2c2430
FG
1#!/usr/bin/perl -w
2
9bdcd713
FG
3my $abinew = shift;
4my $abiold = shift;
2f2c2430
FG
5my $skipabi = shift;
6
b1d53c94
FG
7# to catch multiple abi-prev-* files being passed in
8die "invalid value for skipabi parameter\n"
9 if (defined($skipabi) && $skipabi !~ /^[01]$/);
10
9bdcd713 11$abinew =~ /abi-(.*)/;
b1d53c94
FG
12my $abistr = $1;
13$abiold =~ /abi-prev-(.*)/;
14my $prev_abistr = $1;
9bdcd713 15
2f2c2430
FG
16my $fail_exit = 1;
17my $EE = "EE:";
18my $errors = 0;
19my $abiskip = 0;
20
21my $count;
22
9bdcd713 23print "II: Checking ABI...\n";
2f2c2430 24
9bdcd713 25if ($skipabi) {
2f2c2430
FG
26 print "WW: Explicitly asked to ignore ABI, running in no-fail mode\n";
27 $fail_exit = 0;
28 $abiskip = 1;
29 $EE = "WW:";
30}
31
b1d53c94
FG
32if ($prev_abistr ne $abistr) {
33 print "II: Different ABI's, running in no-fail mode\n";
34 $fail_exit = 0;
35 $EE = "WW:";
36}
37
9bdcd713 38if (not -f "$abinew" or not -f "$abiold") {
2f2c2430 39 print "EE: Previous or current ABI file missing!\n";
9bdcd713
FG
40 print " $abinew\n" if not -f "$abinew";
41 print " $abiold\n" if not -f "$abiold";
2f2c2430
FG
42
43 # Exit if the ABI files are missing, but return status based on whether
44 # skip ABI was indicated.
45 if ("$abiskip" eq "1") {
46 exit(0);
47 } else {
48 exit(1);
49 }
50}
51
52my %symbols;
53my %symbols_ignore;
54my %modules_ignore;
55my %module_syms;
56
57# See if we have any ignores
58my $ignore = 0;
59print " Reading symbols/modules to ignore...";
60
9bdcd713 61for $file ("abi-blacklist") {
2f2c2430
FG
62 if (-f $file) {
63 open(IGNORE, "< $file") or
64 die "Could not open $file";
65 while (<IGNORE>) {
66 chomp;
67 if ($_ =~ m/M: (.*)/) {
68 $modules_ignore{$1} = 1;
69 } else {
70 $symbols_ignore{$_} = 1;
71 }
72 $ignore++;
73 }
74 close(IGNORE);
75 }
76}
77print "read $ignore symbols/modules.\n";
78
79sub is_ignored($$) {
80 my ($mod, $sym) = @_;
81
82 die "Missing module name in is_ignored()" if not defined($mod);
83 die "Missing symbol name in is_ignored()" if not defined($sym);
84
85 if (defined($symbols_ignore{$sym}) or defined($modules_ignore{$mod})) {
86 return 1;
87 }
88 return 0;
89}
90
91# Read new syms first
b1d53c94 92print " Reading new symbols ($abistr)...";
2f2c2430 93$count = 0;
9bdcd713
FG
94open(NEW, "< $abinew") or
95 die "Could not open $abinew";
2f2c2430
FG
96while (<NEW>) {
97 chomp;
98 m/^(\S+)\s(.+)\s(0x[0-9a-f]+)\s(.+)$/;
99 $symbols{$4}{'type'} = $1;
100 $symbols{$4}{'loc'} = $2;
101 $symbols{$4}{'hash'} = $3;
102 $module_syms{$2} = 0;
103 $count++;
104}
105close(NEW);
106print "read $count symbols.\n";
107
108# Now the old symbols, checking for missing ones
9bdcd713 109print " Reading old symbols...";
2f2c2430 110$count = 0;
9bdcd713
FG
111open(OLD, "< $abiold") or
112 die "Could not open $abiold";
2f2c2430
FG
113while (<OLD>) {
114 chomp;
115 m/^(\S+)\s(.+)\s(0x[0-9a-f]+)\s(.+)$/;
116 $symbols{$4}{'old_type'} = $1;
117 $symbols{$4}{'old_loc'} = $2;
118 $symbols{$4}{'old_hash'} = $3;
119 $count++;
120}
121close(OLD);
122
123print "read $count symbols.\n";
124
125print "II: Checking for missing symbols in new ABI...";
126$count = 0;
127foreach $sym (keys(%symbols)) {
128 if (!defined($symbols{$sym}{'type'})) {
129 print "\n" if not $count;
130 printf(" MISS : %s%s\n", $sym,
131 is_ignored($symbols{$sym}{'old_loc'}, $sym) ? " (ignored)" : "");
132 $count++ if !is_ignored($symbols{$sym}{'old_loc'}, $sym);
133 }
134}
135print " " if $count;
136print "found $count missing symbols\n";
137if ($count) {
138 print "$EE Symbols gone missing (what did you do!?!)\n";
139 $errors++;
140}
141
142
143print "II: Checking for new symbols in new ABI...";
144$count = 0;
145foreach $sym (keys(%symbols)) {
146 if (!defined($symbols{$sym}{'old_type'})) {
147 print "\n" if not $count;
148 print " NEW : $sym\n";
149 $count++;
150 }
151}
152print " " if $count;
153print "found $count new symbols\n";
9bdcd713
FG
154if ($count) {
155 print "WW: Found new symbols. Not recommended unless ABI was bumped\n";
2f2c2430
FG
156}
157
158print "II: Checking for changes to ABI...\n";
159$count = 0;
160my $moved = 0;
161my $changed_type = 0;
162my $changed_hash = 0;
163foreach $sym (keys(%symbols)) {
164 if (!defined($symbols{$sym}{'old_type'}) or
165 !defined($symbols{$sym}{'type'})) {
166 next;
167 }
168
169 # Changes in location don't hurt us, but log it anyway
170 if ($symbols{$sym}{'loc'} ne $symbols{$sym}{'old_loc'}) {
171 printf(" MOVE : %-40s : %s => %s\n", $sym, $symbols{$sym}{'old_loc'},
172 $symbols{$sym}{'loc'});
173 $moved++;
174 }
175
176 # Changes to export type are only bad if new type isn't
177 # EXPORT_SYMBOL. Changing things to GPL are bad.
178 if ($symbols{$sym}{'type'} ne $symbols{$sym}{'old_type'}) {
179 printf(" TYPE : %-40s : %s => %s%s\n", $sym, $symbols{$sym}{'old_type'}.
180 $symbols{$sym}{'type'}, is_ignored($symbols{$sym}{'loc'}, $sym)
181 ? " (ignored)" : "");
182 $changed_type++ if $symbols{$sym}{'type'} ne "EXPORT_SYMBOL"
183 and !is_ignored($symbols{$sym}{'loc'}, $sym);
184 }
185
186 # Changes to the hash are always bad
187 if ($symbols{$sym}{'hash'} ne $symbols{$sym}{'old_hash'}) {
188 printf(" HASH : %-40s : %s => %s%s\n", $sym, $symbols{$sym}{'old_hash'},
189 $symbols{$sym}{'hash'}, is_ignored($symbols{$sym}{'loc'}, $sym)
190 ? " (ignored)" : "");
191 $changed_hash++ if !is_ignored($symbols{$sym}{'loc'}, $sym);
192 $module_syms{$symbols{$sym}{'loc'}}++;
193 }
194}
195
196print "WW: $moved symbols changed location\n" if $moved;
197print "$EE $changed_type symbols changed export type and weren't ignored\n" if $changed_type;
198print "$EE $changed_hash symbols changed hash and weren't ignored\n" if $changed_hash;
199
200$errors++ if $changed_hash or $changed_type;
201if ($changed_hash) {
202 print "II: Module hash change summary...\n";
203 foreach $mod (sort { $module_syms{$b} <=> $module_syms{$a} } keys %module_syms) {
204 next if ! $module_syms{$mod};
205 printf(" %-40s: %d\n", $mod, $module_syms{$mod});
206 }
207}
208
209print "II: Done\n";
210
211if ($errors) {
212 exit($fail_exit);
213} else {
214 exit(0);
215}