|
|
33ac90 |
#!/usr/bin/python
|
|
|
33ac90 |
#
|
|
|
33ac90 |
# check-kabi - Red Hat kABI reference checking tool
|
|
|
33ac90 |
#
|
|
|
33ac90 |
# We use this script to check against reference Module.kabi files.
|
|
|
33ac90 |
#
|
|
|
33ac90 |
# Author: Jon Masters <jcm@redhat.com>
|
|
|
33ac90 |
# Copyright (C) 2007-2009 Red Hat, Inc.
|
|
|
33ac90 |
#
|
|
|
33ac90 |
# This software may be freely redistributed under the terms of the GNU
|
|
|
33ac90 |
# General Public License (GPL).
|
|
|
33ac90 |
|
|
|
33ac90 |
# Changelog:
|
|
|
33ac90 |
#
|
|
|
33ac90 |
# 2009/08/15 - Updated for use in RHEL6.
|
|
|
33ac90 |
# 2007/06/13 - Initial rewrite in python by Jon Masters.
|
|
|
33ac90 |
|
|
|
33ac90 |
__author__ = "Jon Masters <jcm@redhat.com>"
|
|
|
33ac90 |
__version__ = "2.0"
|
|
|
33ac90 |
__date__ = "2009/08/15"
|
|
|
33ac90 |
__copyright__ = "Copyright (C) 2007-2009 Red Hat, Inc"
|
|
|
33ac90 |
__license__ = "GPL"
|
|
|
33ac90 |
|
|
|
33ac90 |
import getopt
|
|
|
33ac90 |
import os
|
|
|
33ac90 |
import re
|
|
|
33ac90 |
import string
|
|
|
33ac90 |
import sys
|
|
|
33ac90 |
|
|
|
33ac90 |
true = 1
|
|
|
33ac90 |
false = 0
|
|
|
33ac90 |
|
|
|
33ac90 |
def load_symvers(symvers,filename):
|
|
|
33ac90 |
"""Load a Module.symvers file."""
|
|
|
33ac90 |
|
|
|
33ac90 |
symvers_file = open(filename,"r")
|
|
|
33ac90 |
|
|
|
33ac90 |
while true:
|
|
|
33ac90 |
in_line = symvers_file.readline()
|
|
|
33ac90 |
if in_line == "":
|
|
|
33ac90 |
break
|
|
|
33ac90 |
if in_line == "\n":
|
|
|
33ac90 |
continue
|
|
|
33ac90 |
checksum,symbol,directory,type = string.split(in_line)
|
|
|
33ac90 |
|
|
|
33ac90 |
symvers[symbol] = in_line[0:-1]
|
|
|
33ac90 |
|
|
|
33ac90 |
def load_kabi(kabi,filename):
|
|
|
33ac90 |
"""Load a Module.kabi file."""
|
|
|
33ac90 |
|
|
|
33ac90 |
kabi_file = open(filename,"r")
|
|
|
33ac90 |
|
|
|
33ac90 |
while true:
|
|
|
33ac90 |
in_line = kabi_file.readline()
|
|
|
33ac90 |
if in_line == "":
|
|
|
33ac90 |
break
|
|
|
33ac90 |
if in_line == "\n":
|
|
|
33ac90 |
continue
|
|
|
33ac90 |
checksum,symbol,directory,type = string.split(in_line)
|
|
|
33ac90 |
|
|
|
33ac90 |
kabi[symbol] = in_line[0:-1]
|
|
|
33ac90 |
|
|
|
33ac90 |
def check_kabi(symvers,kabi):
|
|
|
33ac90 |
"""Check Module.kabi and Module.symvers files."""
|
|
|
33ac90 |
|
|
|
33ac90 |
fail=0
|
|
|
33ac90 |
warn=0
|
|
|
33ac90 |
changed_symbols=[]
|
|
|
33ac90 |
moved_symbols=[]
|
|
|
33ac90 |
|
|
|
33ac90 |
for symbol in kabi:
|
|
|
33ac90 |
abi_hash,abi_sym,abi_dir,abi_type = string.split(kabi[symbol])
|
|
|
33ac90 |
if symvers.has_key(symbol):
|
|
|
33ac90 |
sym_hash,sym_sym,sym_dir,sym_type = string.split(symvers[symbol])
|
|
|
33ac90 |
if abi_hash != sym_hash:
|
|
|
33ac90 |
fail=1
|
|
|
33ac90 |
changed_symbols.append(symbol)
|
|
|
33ac90 |
|
|
|
33ac90 |
if abi_dir != sym_dir:
|
|
|
33ac90 |
warn=1
|
|
|
33ac90 |
moved_symbols.append(symbol)
|
|
|
33ac90 |
else:
|
|
|
33ac90 |
fail=1
|
|
|
33ac90 |
changed_symbols.append(symbol)
|
|
|
33ac90 |
|
|
|
33ac90 |
if fail:
|
|
|
33ac90 |
print "*** ERROR - ABI BREAKAGE WAS DETECTED ***"
|
|
|
33ac90 |
print ""
|
|
|
33ac90 |
print "The following symbols have been changed (this will cause an ABI breakage):"
|
|
|
33ac90 |
print ""
|
|
|
33ac90 |
for symbol in changed_symbols:
|
|
|
33ac90 |
print symbol
|
|
|
33ac90 |
print ""
|
|
|
33ac90 |
|
|
|
33ac90 |
if warn:
|
|
|
33ac90 |
print "*** WARNING - ABI SYMBOLS MOVED ***"
|
|
|
33ac90 |
print ""
|
|
|
33ac90 |
print "The following symbols moved (typically caused by moving a symbol from being"
|
|
|
33ac90 |
print "provided by the kernel vmlinux out to a loadable module):"
|
|
|
33ac90 |
print ""
|
|
|
33ac90 |
for symbol in moved_symbols:
|
|
|
33ac90 |
print symbol
|
|
|
33ac90 |
print ""
|
|
|
33ac90 |
|
|
|
33ac90 |
"""Halt the build, if we got errors and/or warnings. In either case,
|
|
|
33ac90 |
double-checkig is required to avoid introducing / concealing
|
|
|
33ac90 |
KABI inconsistencies."""
|
|
|
33ac90 |
if fail or warn:
|
|
|
33ac90 |
sys.exit(1)
|
|
|
33ac90 |
sys.exit(0)
|
|
|
33ac90 |
|
|
|
33ac90 |
def usage():
|
|
|
33ac90 |
print """
|
|
|
33ac90 |
check-kabi: check Module.kabi and Module.symvers files.
|
|
|
33ac90 |
|
|
|
33ac90 |
check-kabi [ -k Module.kabi ] [ -s Module.symvers ]
|
|
|
33ac90 |
|
|
|
33ac90 |
"""
|
|
|
33ac90 |
|
|
|
33ac90 |
if __name__ == "__main__":
|
|
|
33ac90 |
|
|
|
33ac90 |
symvers_file = ""
|
|
|
33ac90 |
kabi_file = ""
|
|
|
33ac90 |
|
|
|
33ac90 |
opts, args = getopt.getopt(sys.argv[1:], 'hk:s:')
|
|
|
33ac90 |
|
|
|
33ac90 |
for o, v in opts:
|
|
|
33ac90 |
if o == "-s":
|
|
|
33ac90 |
symvers_file = v
|
|
|
33ac90 |
if o == "-h":
|
|
|
33ac90 |
usage()
|
|
|
33ac90 |
sys.exit(0)
|
|
|
33ac90 |
if o == "-k":
|
|
|
33ac90 |
kabi_file = v
|
|
|
33ac90 |
|
|
|
33ac90 |
if (symvers_file == "") or (kabi_file == ""):
|
|
|
33ac90 |
usage()
|
|
|
33ac90 |
sys.exit(1)
|
|
|
33ac90 |
|
|
|
33ac90 |
symvers={}
|
|
|
33ac90 |
kabi={}
|
|
|
33ac90 |
|
|
|
33ac90 |
load_symvers(symvers,symvers_file)
|
|
|
33ac90 |
load_kabi(kabi,kabi_file)
|
|
|
33ac90 |
check_kabi(symvers,kabi)
|
|
|
33ac90 |
|