|
|
67e50c |
#! /bin/bash
|
|
|
936cd0 |
#
|
|
|
936cd0 |
# This script is called during external module building to create dependencies
|
|
|
936cd0 |
# both upon the RHEL kernel, and on additional external modules. Symbols that
|
|
|
936cd0 |
# cannot be reconciled against those provided by the kernel are assumed to be
|
|
|
936cd0 |
# provided by an external module and "ksym" replaces th regular "kernel" dep.
|
|
|
67e50c |
|
|
|
67e50c |
IFS=$'\n'
|
|
|
67e50c |
|
|
|
67e50c |
# Extract all of the symbols provided by this module.
|
|
|
67e50c |
all_provides() {
|
|
|
936cd0 |
for module in "$@"; do
|
|
|
936cd0 |
tmpfile=""
|
|
|
936cd0 |
if [ "x${module%.ko}" = "x${module}" ]; then
|
|
|
936cd0 |
tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
|
|
|
936cd0 |
proc_bin=
|
|
|
936cd0 |
case "${module##*.}" in
|
|
|
936cd0 |
zst)
|
|
|
936cd0 |
proc_bin=zstd
|
|
|
936cd0 |
;;
|
|
|
936cd0 |
xz)
|
|
|
936cd0 |
proc_bin=xz
|
|
|
936cd0 |
;;
|
|
|
936cd0 |
bz2)
|
|
|
936cd0 |
proc_bin=bzip2
|
|
|
936cd0 |
;;
|
|
|
936cd0 |
gz)
|
|
|
936cd0 |
proc_bin=gzip
|
|
|
936cd0 |
;;
|
|
|
936cd0 |
esac
|
|
|
936cd0 |
|
|
|
936cd0 |
[ -n "$proc_bin" ] || continue
|
|
|
936cd0 |
|
|
|
936cd0 |
"$proc_bin" -d -c - < "$module" > "$tmpfile" || continue
|
|
|
936cd0 |
module="$tmpfile"
|
|
|
936cd0 |
fi
|
|
|
936cd0 |
|
|
|
936cd0 |
if [[ -n $(nm "$module" | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p') ]]; then
|
|
|
936cd0 |
nm "$module" \
|
|
|
936cd0 |
| sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \
|
|
|
936cd0 |
| awk --non-decimal-data '{printf("%s:0x%08x\n", $2, $1)}'
|
|
|
67e50c |
else
|
|
|
936cd0 |
ELFRODATA=$(readelf -R .rodata "$module" | awk '/0x/{printf $2$3$4$5}')
|
|
|
936cd0 |
if [[ -n $(readelf -h "$module" | grep "little endian") ]]; then
|
|
|
936cd0 |
RODATA=$(echo $ELFRODATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g')
|
|
|
936cd0 |
else
|
|
|
936cd0 |
RODATA=$ELFRODATA
|
|
|
936cd0 |
fi
|
|
|
936cd0 |
for sym in $(nm "$module" | sed -r -ne 's:^0*([0-9a-f]+) R __crc_(.+):0x\1 \2:p'); do
|
|
|
936cd0 |
echo $sym $RODATA
|
|
|
936cd0 |
done \
|
|
|
936cd0 |
| awk --non-decimal-data '{printf("%s:0x%08s\n", $2, substr($3,($1*2)+1,8))}'
|
|
|
67e50c |
fi
|
|
|
936cd0 |
|
|
|
936cd0 |
[ -z "$tmpfile" ] || rm -f -- "$tmpfile"
|
|
|
936cd0 |
done \
|
|
|
936cd0 |
| LC_ALL=C sort -k1,1 -u
|
|
|
67e50c |
}
|
|
|
67e50c |
|
|
|
67e50c |
# Extract all of the requirements of this module.
|
|
|
67e50c |
all_requires() {
|
|
|
67e50c |
for module in "$@"; do
|
|
|
67e50c |
set -- $(/sbin/modinfo -F vermagic "$module" | sed -e 's: .*::' -e q)
|
|
|
67e50c |
/sbin/modprobe --dump-modversions "$module" \
|
|
|
67e50c |
| awk --non-decimal-data '
|
|
|
67e50c |
BEGIN { FS = "\t" ; OFS = "\t" }
|
|
|
936cd0 |
{printf("%s:0x%08x\n", $2, $1)}' \
|
|
|
67e50c |
| sed -r -e 's:$:\t'"$1"':'
|
|
|
67e50c |
done \
|
|
|
936cd0 |
| LC_ALL=C sort -k1,1 -u
|
|
|
67e50c |
}
|
|
|
67e50c |
|
|
|
67e50c |
# Filter out requirements fulfilled by the module itself.
|
|
|
67e50c |
mod_requires() {
|
|
|
936cd0 |
LC_ALL=C join -t $'\t' -j 1 -v 1 \
|
|
|
67e50c |
<(all_requires "$@") \
|
|
|
67e50c |
<(all_provides "$@") \
|
|
|
67e50c |
| LC_ALL=C sort -k1,1 -u
|
|
|
67e50c |
}
|
|
|
67e50c |
|
|
|
67e50c |
if ! [ -e /sbin/modinfo -a -e /sbin/modprobe ]; then
|
|
|
67e50c |
cat > /dev/null
|
|
|
67e50c |
exit 0
|
|
|
67e50c |
fi
|
|
|
67e50c |
|
|
|
936cd0 |
check_kabi() {
|
|
|
936cd0 |
arch=$(uname -m)
|
|
|
936cd0 |
kabi_file="/lib/modules/kabi-current/kabi_stablelist_$arch"
|
|
|
936cd0 |
|
|
|
936cd0 |
# If not installed, output a warning and return (continue)
|
|
|
936cd0 |
if [ ! -f "$kabi_file" ]; then
|
|
|
936cd0 |
echo "" >&2
|
|
|
936cd0 |
echo "********************************************************************************" >&2
|
|
|
936cd0 |
echo "*********************** KERNEL ABI COMPATIBILITY WARNING ***********************" >&2
|
|
|
936cd0 |
echo "********************************************************************************" >&2
|
|
|
936cd0 |
echo "The kernel ABI reference files (provided by "kabi-stablelists") were not found." >&2
|
|
|
936cd0 |
echo "No compatibility check was performed. Please install the kABI reference files" >&2
|
|
|
936cd0 |
echo "and rebuild if you would like to verify compatibility with kernel ABI." >&2
|
|
|
936cd0 |
echo "" >&2
|
|
|
936cd0 |
return
|
|
|
936cd0 |
fi
|
|
|
936cd0 |
|
|
|
936cd0 |
unset non_kabi
|
|
|
936cd0 |
for symbol in "$@"; do
|
|
|
936cd0 |
if ! egrep "^[[:space:]]$symbol\$" $kabi_file >/dev/null; then
|
|
|
936cd0 |
non_kabi=("${non_kabi[@]}" "$symbol")
|
|
|
936cd0 |
fi
|
|
|
936cd0 |
done
|
|
|
936cd0 |
|
|
|
936cd0 |
if [ ${#non_kabi[@]} -gt 0 ]; then
|
|
|
936cd0 |
echo "" >&2
|
|
|
936cd0 |
echo "********************************************************************************" >&2
|
|
|
936cd0 |
echo "*********************** KERNEL ABI COMPATIBILITY WARNING ***********************" >&2
|
|
|
936cd0 |
echo "********************************************************************************" >&2
|
|
|
936cd0 |
echo "The following kernel symbols are not guaranteed to remain compatible with" >&2
|
|
|
936cd0 |
echo "future kernel updates to this RHEL release:" >&2
|
|
|
936cd0 |
echo "" >&2
|
|
|
936cd0 |
for symbol in "${non_kabi[@]}"; do
|
|
|
936cd0 |
printf "\t$symbol\n" >&2
|
|
|
936cd0 |
done
|
|
|
936cd0 |
echo "" >&2
|
|
|
936cd0 |
echo "Red Hat recommends that you consider using only official kernel ABI symbols" >&2
|
|
|
936cd0 |
echo "where possible. Requests for additions to the kernel ABI can be filed with" >&2
|
|
|
936cd0 |
echo "your partner or customer representative (component: driver-update-program)." >&2
|
|
|
936cd0 |
echo "" >&2
|
|
|
936cd0 |
fi
|
|
|
936cd0 |
}
|
|
|
936cd0 |
|
|
|
936cd0 |
modules=($(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@")
|
|
|
67e50c |
if [ ${#modules[@]} -gt 0 ]; then
|
|
|
67e50c |
kernel=$(/sbin/modinfo -F vermagic "${modules[0]}" | sed -e 's: .*::' -e q)
|
|
|
67e50c |
|
|
|
67e50c |
# get all that kernel provides
|
|
|
67e50c |
symvers=$(mktemp -t ${0##*/}.XXXXX)
|
|
|
67e50c |
|
|
|
67e50c |
cat /usr/src/kernels/$kernel/Module.symvers | awk '
|
|
|
67e50c |
BEGIN { FS = "\t" ; OFS = "\t" }
|
|
|
936cd0 |
{ print $2 ":" $1 }
|
|
|
67e50c |
' \
|
|
|
67e50c |
| sed -r -e 's:$:\t'"$kernel"':' \
|
|
|
67e50c |
| LC_ALL=C sort -k1,1 -u > $symvers
|
|
|
67e50c |
|
|
|
67e50c |
# Symbols matching with the kernel get a "kernel" dependency
|
|
|
936cd0 |
mod_req=$(mktemp -t mod_req.XXXXX)
|
|
|
936cd0 |
mod_requires "${modules[@]}" > "$mod_req"
|
|
|
936cd0 |
LC_ALL=C join -t $'\t' -j 1 $symvers "$mod_req" | LC_ALL=C sort -u \
|
|
|
936cd0 |
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "kernel(" $1 ") = " $2 }'
|
|
|
67e50c |
|
|
|
67e50c |
# Symbols from elsewhere get a "ksym" dependency
|
|
|
936cd0 |
LC_ALL=C join -t $'\t' -j 1 -v 2 $symvers "$mod_req" | LC_ALL=C sort -u \
|
|
|
936cd0 |
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "ksym(" $1 ") = " $2 }'
|
|
|
936cd0 |
|
|
|
936cd0 |
# Check kABI if the kabi-stablelists package is installed
|
|
|
936cd0 |
# Do this last so we can try to output this error at the end
|
|
|
936cd0 |
kabi_check_symbols=($(LC_ALL=C join -t $'\t' -j 1 $symvers "$mod_req" | LC_ALL=C sort -u \
|
|
|
936cd0 |
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print $1 }'))
|
|
|
936cd0 |
check_kabi "${kabi_check_symbols[@]}"
|
|
|
67e50c |
fi
|