Blame SOURCES/check-kabi

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