2018-04-19 23:07:42 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
export LC_COLLATE=C
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
echo "Tool to generate list of symbols that are used to build kernel livepatches"
|
|
|
|
echo
|
|
|
|
echo "Usage: ${0##*/} kernel_build_dir klp_symbols"
|
|
|
|
echo " kernel_build_dir Directory where to find the built kernel binaries"
|
|
|
|
echo " klp_symbols Output file with the list of symbols"
|
|
|
|
}
|
|
|
|
|
|
|
|
if test "$1" == "-h" -o "$1" == "--help" -o $# -ne 2 ; then
|
|
|
|
usage >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-02-15 10:39:41 +01:00
|
|
|
KLP_DATA_VERSION="0.1"
|
2018-04-19 23:07:42 +02:00
|
|
|
KERNEL_BUILD_DIR="$1"
|
|
|
|
KLP_SYMBOLS="$2"
|
|
|
|
|
|
|
|
VMLINUX="$KERNEL_BUILD_DIR/vmlinux"
|
|
|
|
MODVER_DIR="$KERNEL_BUILD_DIR/.tmp_versions"
|
|
|
|
|
|
|
|
if ! test -f "$VMLINUX" ; then
|
|
|
|
echo "Error: Cannot open file: $VMLINUX" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! test -d "$MODVER_DIR" ; then
|
|
|
|
echo "Error: Directory does not exist: $MODVER_DIR" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
get_symbols()
|
|
|
|
{
|
2019-03-04 09:10:18 +01:00
|
|
|
nm -f posix "$1" | grep -v '\( [UN] \)\|\(\.L\|__crc_\)' | cut -d\ -f1,2
|
2018-04-19 23:07:42 +02:00
|
|
|
}
|
|
|
|
|
2019-02-15 10:39:41 +01:00
|
|
|
echo "klp-convert-symbol-data.$KLP_DATA_VERSION" > "$KLP_SYMBOLS"
|
|
|
|
echo "*vmlinux" >> "$KLP_SYMBOLS"
|
2018-04-19 23:07:42 +02:00
|
|
|
get_symbols "$VMLINUX" >> "$KLP_SYMBOLS"
|
|
|
|
|
|
|
|
find "$MODVER_DIR" -iname '*.mod' | while read KMOD ; do
|
|
|
|
# read .ko path and file from .mod file
|
|
|
|
KO_FILE="$(head -n1 $KMOD)"
|
|
|
|
|
|
|
|
# obtain module name and its object file by processing .ko file name
|
|
|
|
NO_SUFFIX="$(basename -s .ko $KO_FILE)"
|
|
|
|
KMOD_NAME="$(echo $NO_SUFFIX | sed 's/-/_/g')"
|
|
|
|
OBJ_FILE="$(dirname $KO_FILE)/$NO_SUFFIX.o"
|
|
|
|
|
|
|
|
# write module name to Symbols file
|
|
|
|
echo "*$KMOD_NAME" >> "$KLP_SYMBOLS"
|
|
|
|
|
|
|
|
# extract symbols from object file and write them to Symbols file
|
|
|
|
get_symbols "$OBJ_FILE" >> "$KLP_SYMBOLS"
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|