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