File kabi-checks of Package kernel-source (Revision dd9fdb8e2db553d4e73e2da013a5c790)
Currently displaying revision dd9fdb8e2db553d4e73e2da013a5c790, show latest
x
1
#!/bin/bash
2
# Tool to do kABI checks.
3
# (c) Kurt Garloff <garloff@suse.de>, GNU GPL, 11/2005
4
# $Id$
5
#
6
# This tool looks at the generated symvers and compares it to the
7
# reference file (if existent). It prints warnings for changed symbol
8
# versions.
9
#
10
# Return value:
11
# 0 -- no changes
12
# 1 -- usage/input error
13
# 2 -- internal error
14
# 4 -- only additions
15
# >= 8 -- removed or changed symbols (see below)
16
#
17
# Severity classification:
18
# - 8 -- 15: if it's not found in a list (commonsyms or usedsyms)
19
# The score depends on the source; symbols in vmlinux are more
20
# likely to be used by anyone.
21
# - 16 -- 23: symbol is found in the list usedsyms
22
# - 24 -- 31: symbol is found in the list commonsyms
23
24
severities="
25
# unimportant ---. .--- important
26
# v v
27
28
drivers/base/* 13
29
drivers/char/ipmi/* 10
30
drivers/char/tpm/tpm 9
31
drivers/hwmon/* 10
32
drivers/i2c/i2c-core 9
33
drivers/md/* 13
34
drivers/message/fusion/* 6
35
drivers/pci/* 12
36
drivers/pci/hotplug/pci_hotplug 10
37
drivers/scsi/libata 12
38
drivers/scsi/scsi* 12
39
drivers/scsi/*/scsi_transport_* 12
40
drivers/scsi/libiscsi* 12
41
drivers/ide/ide-core 11
42
drivers/usb/core/usbcore 10
43
drivers/usb/serial/usbserial 9
44
fs/dmapi/dmapi 11
45
fs/fat/fat 11
46
fs/jbd/jbd 11
47
net/ipv4/netfilter/ip_tables 9
48
vmlinux 15
49
"
50
51
# Turning off UTF-8 processing provides a major speedup.
52
export LC_ALL=C
53
54
echo "${0##*/} $@"
55
56
unset quiet verbose
57
if [ "$1" = "-q" ]; then
58
shift
59
quiet=1
60
fi
61
if [ "$1" = "-v" ]; then
62
shift
63
verbose=1
64
fi
65
66
if [ $# -lt 2 -o $# -gt 4 ]; then
67
echo "Usage: ${0##*/} [-q] [-v] reference symvers [commonsyms [usedsyms]]" >&2
68
exit 1
69
fi
70
for file in "$@"; do
71
[ -r "$file" ] && continue
72
echo "Cannot read from '$file'" >&2
73
exit 1
74
done
75
76
declare_symbol_severity() {
77
declare severity=$1
78
79
while [ $# -ge 2 ]; do
80
if ! eval "severity_of_${2//[^a-zA-Z0-9_]/_}=$severity"; then
81
echo "Internal error" >&2
82
exit 2
83
fi
84
shift
85
done
86
}
87
88
consistency_check() {
89
declare_symbol_severity 16 consistency_check_foo
90
check_modified_symbols >/dev/null <<-EOF
91
consistency_check_foo -0x12345678 consistency/check/foo +0x98765432 consistency/check/foo
92
EOF
93
if [ $? -ne 31 ]; then
94
echo "Internal error" >&2
95
exit 2
96
fi
97
}
98
99
#set -x
100
eval '
101
severity() {
102
case $2 in
103
'"$(
104
105
( echo "$severities"
106
echo "consistency/check/* 15" # For the consistency test
107
) \
108
| sed -e '/^#/d' -e '/^$/d' \
109
| while read glob severity; do
110
echo " ($glob) _rc=$severity ;;"
111
done
112
113
)"'
114
(*) _rc=8 ;;
115
esac
116
117
# Is a particular severity defined for this symbol?
118
declare severity=severity_of_$1
119
if [ -n "${!severity}" ]; then
120
((_rc += ${!severity}))
121
fi
122
123
return $_rc
124
}'
125
#set +x
126
127
grab_symvers_from_rpm() {(
128
# (Run in subshell to make trap work.)
129
130
tmpdir=$(mktemp -t -d ${0##*/}.XXXXXX)
131
trap "cd /; rm -rf $tmpdir" EXIT
132
cd $tmpdir
133
rpm2cpio "$file" \
134
| cpio -dim --quiet './boot/symvers-*.gz'
135
set -- boot/symvers-*.gz
136
if ! [ -e "$1" ]; then
137
echo "Failed to extract symvers-*.gz from $file" >&2
138
exit 1
139
fi
140
zcat "$1"
141
)}
142
143
grab_symvers() {
144
declare tag=$1 file=$2 pwd tmpdir
145
146
case "$(file -b - <"$file")" in
147
gzip*)
148
zcat "$file"
149
;;
150
RPM*)
151
grab_symvers_from_rpm "$file"
152
;;
153
*)
154
cat "$file"
155
;;
156
esac \
157
| sed -e "/^#/d" -e "s/^/$tag/" \
158
| sort -k 2
159
}
160
161
filter_out_identical_symbols() {
162
# This expression works no matter how many columns the files have.
163
grep -v -P '^\S+ -(\S+)( \S+)+ \+\1( \S+)+$'
164
}
165
166
check_modified_symbols() {
167
declare -i RC=0 _rc
168
declare ignored
169
170
while read symbol tail; do
171
# Split in half no matter how many columns the files have.
172
set -- $tail ; half=$(($#/2+1))
173
version1=$1 ; version2=${!half} ; shift
174
source1=$1 ; source2=${!half} ; shift
175
176
case "$version1$version2" in
177
-\#*)
178
continue
179
;;
180
-*+* | -*)
181
ignored=
182
case "$version1" in
183
*=\>*)
184
if [ "${version1#*=>}" = "${version2#+}" ]; then
185
version1="${version1%=>*}"
186
ignored="; ignored"
187
fi
188
;;
189
esac
190
severity $symbol $source1 && continue
191
_rc=$?
192
if [ -z "$quiet" ]; then
193
echo -n "Warning: $source1: $symbol(${version1#-}) "
194
if [ -n "$version2" ]; then
195
echo -n "changed to $symbol(${version2#+})"
196
[ "$source1" != "$source2" ] &&
197
echo -n " and moved to $source2"
198
else
199
echo -n "removed"
200
fi
201
echo " (badness ${_rc}$ignored)"
202
fi
203
[ -n "$ignored" ] && _rc=0
204
;;
205
*)
206
if [ -n "$verbose" ]; then
207
echo " new symbol $symbol: ${version1#+}"
208
fi
209
_rc=4
210
;;
211
esac
212
if [ ${_rc} -gt $RC ]; then RC=${_rc}; fi
213
done
214
return $RC
215
}
216
217
sort_by_badness() {
218
sed -e 's/.*(badness \([0-9]\+\)).*/\1 &/' -e 't' -e 's/^/0 /' \
219
| sort -n -r \
220
| sed -e 's/^[0-9]* //'
221
}
222
223
consistency_check
224
225
[ -n "$4" ] && declare_symbol_severity 8 $(< $4)
226
[ -n "$3" ] && declare_symbol_severity 16 $(< $3)
227
228
join -j 2 -a 1 -a 2 <(grab_symvers - $1) <(grab_symvers + $2) \
229
| filter_out_identical_symbols \
230
| check_modified_symbols \
231
| sort_by_badness
232
233
RC=${PIPESTATUS[2]}
234
echo "kABI verdict: $RC"
235
exit $RC
236