Blame SOURCES/check-kabi

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