liuyingdong / rpms / kernel

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