alexl / rpms / kernel-automotive

Forked from rpms/kernel-automotive 2 years ago
Clone

Blame check-kabi

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