kernel-srpm-macros/find-provides.ksyms
Eugene Syromiatnikov 4eeb063077 find-provides.ksyms, find-requires.ksyms: rewrite absolute CRC parsing
Avoid running sed on the whole "nm" output and also avoid "sed | awk"
pipe in favor of a single awk call.  Overall, this gives around 20%
speedup on some quick synthetic tests:

    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" | find-provides.ksyms.old > /dev/null 2> /dev/null'
    sh -c   14.20s user 8.93s system 144% cpu 16.014 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" | find-provides.ksyms.new > /dev/null 2> /dev/null'
    sh -c   12.01s user 7.46s system 143% cpu 13.567 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" -exec sh -c "echo {} | find-provides.ksyms.old" \; > /dev/null 2> /dev/null'
    sh -c   16.31s user 10.77s system 134% cpu 20.092 total
    $ time sh -c 'find ./lib/modules/5.14.0-258.el9.x86_64 -name "*.ko.xz" -exec sh -c "echo {} | find-provides.ksyms.new" \; > /dev/null 2> /dev/null'
    sh -c   13.95s user 8.92s system 135% cpu 16.836 total

* find-provides.ksyms: Check presence of absolute __crc_* symbols with
"grep -q" exit code and not presence of sed output;  rewrite awk script to match
the __crc_* symbols instead of preprocessing the nm output with sed.
* find-requires.ksyms: Likewise.

Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Resolves: #2135047
2023-03-07 14:52:22 +01:00

60 lines
1.8 KiB
Bash
Executable File

#! /bin/bash
IFS=$'\n'
export LC_ALL=C
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
dep_pfx="ksym"
# For built-in kmods, "kernel()" syntax is used instead of "ksym()"
printf "%s" "$module" | grep -v "^${RPM_BUILD_ROOT}/\?lib/modules/[1-9][^/]*/kernel" > /dev/null \
|| dep_pfx="kernel"
tmpfile=""
if [ "x${module%.ko}" = "x${module}" ]; then
tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
proc_bin=
case "${module##*.}" in
zst)
proc_bin=zstd
;;
xz)
proc_bin=xz
;;
bz2)
proc_bin=bzip2
;;
gz)
proc_bin=gzip
;;
esac
[ -n "$proc_bin" ] || continue
"$proc_bin" -d -c - < "$module" > "$tmpfile" || continue
module="$tmpfile"
fi
if nm "$module" | grep -qE '^([0-9a-f]+) A __crc_(.+)' 2> /dev/null; then
nm "$module" \
| awk \
-v 'dep_pfx='"$dep_pfx" \
--non-decimal-data \
'match($0, /^([0-9a-f]+) A __crc_(.+)/, a) { printf("%s(%s) = 0x%08x\n", dep_pfx, a[2], strtonum("0x" a[1])) }' \
| sort -u
else
ELFRODATA=$(readelf -R .rodata $module | awk '/0x/{printf $2$3$4$5}')
if [[ -n $(readelf -h $module | grep "little endian") ]]; then
RODATA=$(echo $ELFRODATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g')
else
RODATA=$ELFRODATA
fi
for sym in $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) R __crc_(.+):0x\1 \2:p'); do
echo $sym $RODATA
done \
| awk --non-decimal-data '{printf("'"${dep_pfx}"'(%s) = 0x%08s\n", $2, substr($3,($1*2)+1,8))}' \
| sort -u
fi
[ -z "$tmpfile" ] || rm -f -- "$tmpfile"
done