potatogim / rpms / kernel

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