|
|
837a2d |
#! /bin/bash
|
|
|
837a2d |
|
|
|
837a2d |
IFS=$'\n'
|
|
|
837a2d |
|
|
|
837a2d |
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
|
|
|
837a2d |
dep_pfx="ksym"
|
|
|
837a2d |
# For built-in kmods, "kernel()" syntax is used instead of "ksym()"
|
|
|
837a2d |
printf "%s" "$module" | grep -v "^${RPM_BUILD_ROOT}/\?lib/modules/[1-9][^/]*/kernel" > /dev/null \
|
|
|
837a2d |
|| dep_pfx="kernel"
|
|
|
837a2d |
|
|
|
837a2d |
tmpfile=""
|
|
|
837a2d |
if [ "x${module%.ko}" = "x${module}" ]; then
|
|
|
837a2d |
tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
|
|
|
837a2d |
proc_bin=
|
|
|
837a2d |
case "${module##*.}" in
|
|
|
837a2d |
zst)
|
|
|
837a2d |
proc_bin=zstd
|
|
|
837a2d |
;;
|
|
|
837a2d |
xz)
|
|
|
837a2d |
proc_bin=xz
|
|
|
837a2d |
;;
|
|
|
837a2d |
bz2)
|
|
|
837a2d |
proc_bin=bzip2
|
|
|
837a2d |
;;
|
|
|
837a2d |
gz)
|
|
|
837a2d |
proc_bin=gzip
|
|
|
837a2d |
;;
|
|
|
837a2d |
esac
|
|
|
837a2d |
|
|
|
837a2d |
[ -n "$proc_bin" ] || continue
|
|
|
837a2d |
|
|
|
837a2d |
"$proc_bin" -d -c - < "$module" > "$tmpfile" || continue
|
|
|
837a2d |
module="$tmpfile"
|
|
|
837a2d |
fi
|
|
|
837a2d |
|
|
|
837a2d |
if [[ -n $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p') ]]; then
|
|
|
837a2d |
nm $module \
|
|
|
837a2d |
| sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \
|
|
|
837a2d |
| awk --non-decimal-data '{printf("'"${dep_pfx}"'(%s) = 0x%08x\n", $2, $1)}' \
|
|
|
837a2d |
| LC_ALL=C sort -u
|
|
|
837a2d |
else
|
|
|
837a2d |
ELFRODATA=$(readelf -R .rodata $module | awk '/0x/{printf $2$3$4$5}')
|
|
|
837a2d |
if [[ -n $(readelf -h $module | grep "little endian") ]]; then
|
|
|
837a2d |
RODATA=$(echo $ELFRODATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g')
|
|
|
837a2d |
else
|
|
|
837a2d |
RODATA=$ELFRODATA
|
|
|
837a2d |
fi
|
|
|
837a2d |
# Commit binutils-2_33~1385[1] has changed (and binutils-2_35~1768[2]
|
|
|
837a2d |
# has not reverted it) the calculated type for symbols in read-write
|
|
|
837a2d |
# .rodata section from 'R' to 'D', since, apparently, many kernel
|
|
|
837a2d |
# modules have it indeed read-write.
|
|
|
837a2d |
#
|
|
|
837a2d |
# [1] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=a288c270991d
|
|
|
837a2d |
# [2] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=49d9fd42acef
|
|
|
837a2d |
for sym in $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) [DR] __crc_(.+):0x\1 \2:p'); do
|
|
|
837a2d |
echo $sym $RODATA
|
|
|
837a2d |
done \
|
|
|
837a2d |
| awk --non-decimal-data '{printf("'"${dep_pfx}"'(%s) = 0x%08s\n", $2, substr($3,($1*2)+1,8))}' \
|
|
|
837a2d |
| LC_ALL=C sort -u
|
|
|
837a2d |
fi
|
|
|
837a2d |
|
|
|
837a2d |
[ -z "$tmpfile" ] || rm -f -- "$tmpfile"
|
|
|
837a2d |
done
|