potatogim / rpms / kernel

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