Logoj0ke.net Open Build Service > Projects > home:jg:playground > kernel > check-kabi
Sign Up | Log In

File check-kabi of Package kernel

x
 
1
#!/usr/bin/python
2
#
3
# check-kabi - Red Hat kABI reference checking tool
4
#
5
# We use this script to check against reference Module.kabi files.
6
#
7
# Author: Jon Masters <jcm@redhat.com>
8
# Copyright (C) 2007-2009 Red Hat, Inc.
9
#
10
# This software may be freely redistributed under the terms of the GNU
11
# General Public License (GPL).
12
13
# Changelog:
14
# 
15
# 2009/08/15 - Updated for use in RHEL6.
16
# 2007/06/13 - Initial rewrite in python by Jon Masters.
17
18
__author__ = "Jon Masters <jcm@redhat.com>"
19
__version__ = "2.0"
20
__date__ = "2009/08/15"
21
__copyright__ = "Copyright (C) 2007-2009 Red Hat, Inc"
22
__license__ = "GPL"
23
24
import getopt
25
import os
26
import re
27
import string
28
import sys
29
30
true = 1
31
false = 0
32
33
def load_symvers(symvers,filename):
34
    """Load a Module.symvers file."""
35
36
    symvers_file = open(filename,"r")
37
38
    while true:
39
        in_line = symvers_file.readline()
40
        if in_line == "":
41
            break
42
        if in_line == "\n":
43
            continue
44
        checksum,symbol,directory,type = string.split(in_line)
45
46
        symvers[symbol] = in_line[0:-1]
47
48
def load_kabi(kabi,filename):
49
    """Load a Module.kabi file."""
50
51
    kabi_file = open(filename,"r")
52
53
    while true:
54
        in_line = kabi_file.readline()
55
        if in_line == "":
56
            break
57
        if in_line == "\n":
58
            continue
59
        checksum,symbol,directory,type = string.split(in_line)
60
61
        kabi[symbol] = in_line[0:-1]
62
63
def check_kabi(symvers,kabi):
64
    """Check Module.kabi and Module.symvers files."""
65
66
    fail=0
67
    warn=0
68
    changed_symbols=[]
69
    moved_symbols=[]
70
71
    for symbol in kabi:
72
        abi_hash,abi_sym,abi_dir,abi_type = string.split(kabi[symbol])
73
        if symvers.has_key(symbol):
74
            sym_hash,sym_sym,sym_dir,sym_type = string.split(symvers[symbol])
75
            if abi_hash != sym_hash:
76
                fail=1
77
                changed_symbols.append(symbol)
78
79
            if abi_dir != sym_dir:
80
                warn=1
81
                moved_symbols.append(symbol)
82
        else:
83
            fail=1
84
            changed_symbols.append(symbol)
85
86
    if fail:
87
        print "*** ERROR - ABI BREAKAGE WAS DETECTED ***"
88
        print ""
89
        print "The following symbols have been changed (this will cause an ABI breakage):"
90
        print ""
91
        for symbol in changed_symbols:
92
            print symbol
93
        print ""
94
95
    if warn:
96
        print "*** WARNING - ABI SYMBOLS MOVED ***"
97
        print ""
98
        print "The following symbols moved (typically caused by moving a symbol from being"
99
        print "provided by the kernel vmlinux out to a loadable module):"
100
        print ""
101
        for symbol in moved_symbols:
102
            print symbol
103
        print ""
104
105
    if fail:
106
        sys.exit(1)
107
    else:
108
        sys.exit(0)
109
110
def usage():
111
    print """
112
check-kabi: check Module.kabi and Module.symvers files.
113
114
    check-kabi [ -k Module.kabi ] [ -s Module.symvers ]
115
116
"""
117
118
if __name__ == "__main__":
119
120
    symvers_file = ""
121
    kabi_file = ""
122
123
    opts, args = getopt.getopt(sys.argv[1:], 'hk:s:')
124
125
    for o, v in opts:
126
        if o == "-s":
127
            symvers_file = v
128
        if o == "-h":
129
            usage()
130
            sys.exit(0)
131
        if o == "-k":
132
            kabi_file = v
133
    
134
    if (symvers_file == "") or (kabi_file == ""):
135
        usage()
136
        sys.exit(1)
137
138
    symvers={}
139
    kabi={}
140
141
    load_symvers(symvers,symvers_file)
142
    load_kabi(kabi,kabi_file)
143
    check_kabi(symvers,kabi)
144
145