Merge branch 'leonylgao/master' into 'master' (merge request !25)
kabi: provide kabi check/update/create commands for local users
This commit is contained in:
commit
175e1c3850
30
Makefile
30
Makefile
|
@ -283,7 +283,8 @@ no-dot-config-targets := $(clean-targets) \
|
|||
cscope gtags TAGS tags help% %docs check% coccicheck \
|
||||
$(version_h) headers headers_% archheaders archscripts \
|
||||
%asm-generic kernelversion %src-pkg dt_binding_check \
|
||||
outputmakefile rustavailable rustfmt rustfmtcheck
|
||||
outputmakefile rustavailable rustfmt rustfmtcheck \
|
||||
check-kabi update-kabi create-kabi
|
||||
# Installation targets should not require compiler. Unfortunately, vdso_install
|
||||
# is an exception where build artifacts may be updated. This must be fixed.
|
||||
no-compiler-targets := $(no-dot-config-targets) install dtbs_install \
|
||||
|
@ -1596,6 +1597,9 @@ help:
|
|||
@echo ''
|
||||
@echo 'Tools:'
|
||||
@echo ' nsdeps - Generate missing symbol namespace dependencies'
|
||||
@echo ' check-kabi - Check whether TencentOS Kennel KABI is compatible'
|
||||
@echo ' update-kabi - Update TencentOS Kennel KABI file'
|
||||
@echo ' create-kabi - Create TencentOS Kennel KABI file'
|
||||
@echo ''
|
||||
@echo 'Kernel selftest:'
|
||||
@echo ' kselftest - Build and run kernel selftest'
|
||||
|
@ -1966,6 +1970,30 @@ nsdeps: export KBUILD_NSDEPS=1
|
|||
nsdeps: modules
|
||||
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
|
||||
|
||||
# Check whether TencentOS Kennel KABI is compatible
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
PHONY += check-kabi
|
||||
|
||||
check-kabi:
|
||||
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/tos-kabi.sh check $(ARCH)
|
||||
|
||||
# Update TencentOS Kennel KABI file
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
PHONY += update-kabi
|
||||
|
||||
update-kabi:
|
||||
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/tos-kabi.sh update $(ARCH)
|
||||
|
||||
# Create TencentOS Kennel KABI file
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
PHONY += create-kabi
|
||||
|
||||
create-kabi:
|
||||
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/tos-kabi.sh create $(ARCH)
|
||||
|
||||
# Clang Tooling
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,3 @@
|
|||
CONFIG_LOCALVERSION_AUTO=y
|
||||
# CONFIG_MODULE_SIG is not set
|
||||
# CONFIG_SECURITY_LOCKDOWN_LSM is not set
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python2
|
||||
#!/usr/bin/python3
|
||||
#
|
||||
# check-kabi - Red Hat kABI reference checking tool
|
||||
#
|
||||
|
@ -11,7 +11,8 @@
|
|||
# General Public License (GPL).
|
||||
|
||||
# Changelog:
|
||||
#
|
||||
#
|
||||
# 2018/06/01 - Update for python3 by Petr Oros.
|
||||
# 2009/08/15 - Updated for use in RHEL6.
|
||||
# 2007/06/13 - Initial rewrite in python by Jon Masters.
|
||||
|
||||
|
@ -22,125 +23,134 @@ __copyright__ = "Copyright (C) 2007-2009 Red Hat, Inc"
|
|||
__license__ = "GPL"
|
||||
|
||||
import getopt
|
||||
import os
|
||||
import re
|
||||
import string
|
||||
import sys
|
||||
|
||||
true = 1
|
||||
false = 0
|
||||
|
||||
def load_symvers(symvers,filename):
|
||||
"""Load a Module.symvers file."""
|
||||
def load_symvers(symvers, filename):
|
||||
"""Load a Module.symvers file."""
|
||||
|
||||
symvers_file = open(filename,"r")
|
||||
symvers_file = open(filename, "r")
|
||||
|
||||
while true:
|
||||
in_line = symvers_file.readline()
|
||||
if in_line == "":
|
||||
break
|
||||
if in_line == "\n":
|
||||
continue
|
||||
checksum,symbol,directory,type = string.split(in_line)
|
||||
while true:
|
||||
in_line = symvers_file.readline()
|
||||
if in_line == "":
|
||||
break
|
||||
if in_line == "\n":
|
||||
continue
|
||||
try:
|
||||
checksum, symbol, directory, type = in_line.split()
|
||||
except ValueError:
|
||||
# Firmware symbol may have an extra field
|
||||
checksum, symbol, directory, type, extra = in_line.split()
|
||||
|
||||
symvers[symbol] = in_line[0:-1]
|
||||
symvers[symbol] = " ".join([checksum, symbol, directory, type])
|
||||
|
||||
def load_kabi(kabi,filename):
|
||||
"""Load a Module.kabi file."""
|
||||
|
||||
kabi_file = open(filename,"r")
|
||||
def load_kabi(kabi, filename):
|
||||
"""Load a Module.kabi file."""
|
||||
|
||||
while true:
|
||||
in_line = kabi_file.readline()
|
||||
if in_line == "":
|
||||
break
|
||||
if in_line == "\n":
|
||||
continue
|
||||
checksum,symbol,directory,type = string.split(in_line)
|
||||
kabi_file = open(filename, "r")
|
||||
|
||||
kabi[symbol] = in_line[0:-1]
|
||||
while true:
|
||||
in_line = kabi_file.readline()
|
||||
if in_line == "":
|
||||
break
|
||||
if in_line == "\n":
|
||||
continue
|
||||
try:
|
||||
checksum, symbol, directory, type = in_line.split()
|
||||
except ValueError:
|
||||
# Firmware symbol may have an extra field
|
||||
checksum, symbol, directory, type, extra = in_line.split()
|
||||
|
||||
def check_kabi(symvers,kabi):
|
||||
"""Check Module.kabi and Module.symvers files."""
|
||||
kabi[symbol] = " ".join([checksum, symbol, directory, type])
|
||||
|
||||
fail=0
|
||||
warn=0
|
||||
changed_symbols=[]
|
||||
moved_symbols=[]
|
||||
|
||||
for symbol in kabi:
|
||||
abi_hash,abi_sym,abi_dir,abi_type = string.split(kabi[symbol])
|
||||
if symvers.has_key(symbol):
|
||||
sym_hash,sym_sym,sym_dir,sym_type = string.split(symvers[symbol])
|
||||
if abi_hash != sym_hash:
|
||||
fail=1
|
||||
changed_symbols.append(symbol)
|
||||
def check_kabi(symvers, kabi):
|
||||
"""Check Module.kabi and Module.symvers files."""
|
||||
|
||||
if abi_dir != sym_dir:
|
||||
warn=1
|
||||
moved_symbols.append(symbol)
|
||||
else:
|
||||
fail=1
|
||||
changed_symbols.append(symbol)
|
||||
fail = 0
|
||||
warn = 0
|
||||
changed_symbols = []
|
||||
moved_symbols = []
|
||||
|
||||
if fail:
|
||||
print "*** ERROR - ABI BREAKAGE WAS DETECTED ***"
|
||||
print ""
|
||||
print "The following symbols have been changed (this will cause an ABI breakage):"
|
||||
print ""
|
||||
for symbol in changed_symbols:
|
||||
print symbol
|
||||
print ""
|
||||
for symbol in kabi:
|
||||
abi_hash, abi_sym, abi_dir, abi_type = kabi[symbol].split()
|
||||
if symbol in symvers:
|
||||
sym_hash, sym_sym, sym_dir, sym_type = symvers[symbol].split()
|
||||
if abi_hash != sym_hash:
|
||||
fail = 1
|
||||
changed_symbols.append(symbol)
|
||||
|
||||
if warn:
|
||||
print "*** WARNING - ABI SYMBOLS MOVED ***"
|
||||
print ""
|
||||
print "The following symbols moved (typically caused by moving a symbol from being"
|
||||
print "provided by the kernel vmlinux out to a loadable module):"
|
||||
print ""
|
||||
for symbol in moved_symbols:
|
||||
print symbol
|
||||
print ""
|
||||
if abi_dir != sym_dir:
|
||||
warn = 1
|
||||
moved_symbols.append(symbol)
|
||||
else:
|
||||
fail = 1
|
||||
changed_symbols.append(symbol)
|
||||
|
||||
if fail:
|
||||
print("*** ERROR - ABI BREAKAGE WAS DETECTED ***")
|
||||
print("")
|
||||
print("The following symbols have been changed (this will cause an ABI breakage):")
|
||||
print("")
|
||||
for symbol in changed_symbols:
|
||||
print(symbol)
|
||||
print("")
|
||||
|
||||
if warn:
|
||||
print("*** WARNING - ABI SYMBOLS MOVED ***")
|
||||
print("")
|
||||
print("The following symbols moved (typically caused by moving a symbol from being")
|
||||
print("provided by the kernel vmlinux out to a loadable module):")
|
||||
print("")
|
||||
for symbol in moved_symbols:
|
||||
print(symbol)
|
||||
print("")
|
||||
|
||||
"""Halt the build, if we got errors and/or warnings. In either case,
|
||||
double-checkig is required to avoid introducing / concealing
|
||||
KABI inconsistencies."""
|
||||
if fail or warn:
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
"""Halt the build, if we got errors and/or warnings. In either case,
|
||||
double-checkig is required to avoid introducing / concealing
|
||||
KABI inconsistencies."""
|
||||
if fail or warn:
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
def usage():
|
||||
print """
|
||||
print("""
|
||||
check-kabi: check Module.kabi and Module.symvers files.
|
||||
|
||||
check-kabi [ -k Module.kabi ] [ -s Module.symvers ]
|
||||
check-kabi [ -k Module.kabi ] [ -s Module.symvers ]
|
||||
|
||||
""")
|
||||
|
||||
"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
symvers_file = ""
|
||||
kabi_file = ""
|
||||
symvers_file = ""
|
||||
kabi_file = ""
|
||||
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'hk:s:')
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'hk:s:')
|
||||
|
||||
for o, v in opts:
|
||||
if o == "-s":
|
||||
symvers_file = v
|
||||
if o == "-h":
|
||||
usage()
|
||||
sys.exit(0)
|
||||
if o == "-k":
|
||||
kabi_file = v
|
||||
|
||||
if (symvers_file == "") or (kabi_file == ""):
|
||||
usage()
|
||||
sys.exit(1)
|
||||
for o, v in opts:
|
||||
if o == "-s":
|
||||
symvers_file = v
|
||||
if o == "-h":
|
||||
usage()
|
||||
sys.exit(0)
|
||||
if o == "-k":
|
||||
kabi_file = v
|
||||
|
||||
symvers={}
|
||||
kabi={}
|
||||
if (symvers_file == "") or (kabi_file == ""):
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
load_symvers(symvers,symvers_file)
|
||||
load_kabi(kabi,kabi_file)
|
||||
check_kabi(symvers,kabi)
|
||||
symvers = {}
|
||||
kabi = {}
|
||||
|
||||
load_symvers(symvers, symvers_file)
|
||||
load_kabi(kabi, kabi_file)
|
||||
check_kabi(symvers, kabi)
|
||||
|
|
|
@ -0,0 +1,222 @@
|
|||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# 1. Check whether TencentOS Kennel KABI is compatible
|
||||
# 2. Update TencentOS Kennel KABI file
|
||||
# 3. Create TencentOS Kennel KABI file
|
||||
#
|
||||
RED='\E[1;31m'
|
||||
GREEN='\E[1;32m'
|
||||
YELLOW='\E[1;33m'
|
||||
END='\E[0m'
|
||||
|
||||
srctree=$(dirname "$0")/../
|
||||
|
||||
function usage_info()
|
||||
{
|
||||
echo "Usage: $0 <type> <arch>"
|
||||
echo " type: check update create"
|
||||
echo " arch: x86 x86_64 arm64"
|
||||
}
|
||||
|
||||
function compile_kernel()
|
||||
{
|
||||
local machine=$1
|
||||
local arch=$2
|
||||
local thread_num=$(nproc)
|
||||
thread_num=$((thread_num * 2))
|
||||
|
||||
if [ "${machine}" == "x86_64" ] && [ "${arch}" == "arm64" ] && [ "X$CROSS_COMPILE" == "X" ]; then
|
||||
local CROSS_COMPILE="aarch64-linux-gnu-"
|
||||
fi
|
||||
|
||||
make ARCH=${arch} CROSS_COMPILE=${CROSS_COMPILE} tencentconfig tkci.config -sk 1> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${RED}make tencentconfig tkci.config failed${END}\n"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "start to compile kernel, may take a long time..."
|
||||
make ARCH=${arch} CROSS_COMPILE=${CROSS_COMPILE} -j ${thread_num} -sk 1> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${RED}compile kernel failed${END}\n"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function create_kabi()
|
||||
{
|
||||
local kabi_file=$1
|
||||
local core_kabi_list="dist/kabi/core-kabi-list"
|
||||
|
||||
if [ ! -s ${core_kabi_list} ]; then
|
||||
printf "${RED}get ${core_kabi_list} failed${END}\n"
|
||||
return 1
|
||||
fi
|
||||
|
||||
while read kabi
|
||||
do
|
||||
grep -w ${kabi} Module.symvers 1>> ${kabi_file}
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${YELLOW}function ${kabi} miss\n"
|
||||
fi
|
||||
done < ${core_kabi_list}
|
||||
|
||||
sed -i 's/[[:space:]]*$//' ${kabi_file}
|
||||
printf "${GREEN}create KABI file ${kabi_file} success${END}\n"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function update_kabi()
|
||||
{
|
||||
local kabi_file=$1
|
||||
local new_kabi_file=${kabi_file}_new
|
||||
local core_kabi_list="dist/kabi/core-kabi-list"
|
||||
|
||||
if [ ! -s ${core_kabi_list} ]; then
|
||||
printf "${RED}get ${core_kabi_list} failed${END}\n"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -rf ${new_kabi_file}
|
||||
while read kabi
|
||||
do
|
||||
grep -w ${kabi} Module.symvers 1>> ${new_kabi_file}
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${YELLOW}function ${kabi} miss\n"
|
||||
fi
|
||||
done < ${core_kabi_list}
|
||||
sed -i 's/[[:space:]]*$//' ${new_kabi_file}
|
||||
|
||||
diff ${kabi_file} ${new_kabi_file} > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
rm -rf ${new_kabi_file}
|
||||
printf "${YELLOW}KABI file no change, not need update${END}\n"
|
||||
return 0
|
||||
fi
|
||||
|
||||
mv ${new_kabi_file} ${kabi_file}
|
||||
printf "${GREEN}update KABI file ${kabi_file} success${END}\n"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function check_kabi()
|
||||
{
|
||||
local kabi_file=$1
|
||||
|
||||
./script/check-kabi -k ${kabi_file} -s Module.symvers
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${RED}check KABI failed${END}\n"
|
||||
return 1
|
||||
fi
|
||||
printf "${GREEN}check KABI success${END}\n"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function check_param()
|
||||
{
|
||||
local type=$1
|
||||
local arch=$2
|
||||
local machine=`uname -m`
|
||||
|
||||
if [ "$#" -ne 2 ]; then
|
||||
usage_info
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${type}" != "check" ] && [ "${type}" != "update" ] && [ "${type}" != "create" ]; then
|
||||
printf "${RED}not support type:${type}${END}\n"
|
||||
usage_info
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${machine}" != "x86_64" ] && [ "${machine}" != "aarch64" ]; then
|
||||
printf "${RED}not support machine:${machine}${END}\n"
|
||||
usage_info
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${arch}" != "x86" ] && [ "${arch}" != "x86_64" ] && [ "${arch}" != "arm64" ]; then
|
||||
printf "${RED}not support arch:${arch}${END}\n"
|
||||
usage_info
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${machine}" == "aarch64" ] && [ "${arch}" == "x86" -o "${arch}" == "x86_64" ]; then
|
||||
printf "${RED}machine aarch64 not support cross compile${END}\n"
|
||||
usage_info
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
local type=$1
|
||||
local arch=$2
|
||||
local machine=`uname -m`
|
||||
local kabi_file=""
|
||||
|
||||
check_param $@
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
cd ${srctree}
|
||||
|
||||
if [ "${arch}" == "x86" ] || [ "${arch}" == "x86_64" ]; then
|
||||
kabi_file="dist/kabi/Module.kabi_x86_64"
|
||||
elif [ "${arch}" == "arm64" ]; then
|
||||
kabi_file="dist/kabi/Module.kabi_aarch64"
|
||||
fi
|
||||
|
||||
if [ "${type}" == "create" ]; then
|
||||
if [ -s ${kabi_file} ]; then
|
||||
printf "${RED}${kabi_file} is exist${END}\n"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if [ ! -s ${kabi_file} ]; then
|
||||
printf "${RED}get kabi file failed${END}\n"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "type: ${type}"
|
||||
echo "arch: ${arch}"
|
||||
echo "machine: ${machine}"
|
||||
echo "kabi_file: ${kabi_file}"
|
||||
|
||||
compile_kernel ${machine} ${arch}
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${type}" == "check" ]; then
|
||||
check_kabi ${kabi_file}
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
elif [ "${type}" == "update" ]; then
|
||||
update_kabi ${kabi_file}
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
elif [ "${type}" == "create" ]; then
|
||||
create_kabi ${kabi_file}
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
main $@
|
||||
exit $?
|
Loading…
Reference in New Issue