import CS kernel-srpm-macros-1.0-13.el9

This commit is contained in:
eabdullin 2023-09-21 18:55:16 +00:00
parent 4336082828
commit 4e0189b3f4
6 changed files with 133 additions and 67 deletions

View File

@ -3,6 +3,10 @@
IFS=$'\n' IFS=$'\n'
export LC_ALL=C export LC_ALL=C
# Prevent elfutils from trying to download debuginfos
unset DEBUGINFOD_URLS
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
dep_pfx="ksym" dep_pfx="ksym"
# For built-in kmods, "kernel()" syntax is used instead of "ksym()" # For built-in kmods, "kernel()" syntax is used instead of "ksym()"
@ -34,36 +38,54 @@ for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
module="$tmpfile" module="$tmpfile"
fi fi
if nm "$module" | grep -qE '^([0-9a-f]+) A __crc_(.+)' 2> /dev/null; then # awk script return code:
# 0 - absolute __crc_* symbols have been found, output has been
# generated;
# 23 - a non-absolute __crc_* symbold has been found;
# 42 - no __crc_* symbols have been found.
nm "$module" \ nm "$module" \
| awk \ | awk \
-v 'dep_pfx='"$dep_pfx" \ -v 'dep_pfx='"$dep_pfx" \
--non-decimal-data \ --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])) }' \ 'BEGIN { exit_code = 42 }
| sort -u match($0, /^([0-9a-f]+) (.) __crc_(.+)/, a) {
else if (a[2] == "A") {
objdump -t "$module" \ printf("%s(%s) = 0x%08x\n", dep_pfx, a[3], strtonum("0x" a[1]));
| sed -n 's/^[0-9a-f][0-9a-f]* g...... \(.*\) [0-9a-f][0-9a-f]* __crc_.*$/\1/p' \ exit_code = 0;
| sort -u \ } else {
| while read sectname; do exit_code = 23;
[ -n "$sectname" ] || continue exit;
}
}
END { exit exit_code }'
ELFSECTDATA=$(readelf -R "$sectname" "$module" | awk '/0x/{printf $2$3$4$5}') [ 23 = "$?" ] && {
if [[ -n $(readelf -h $module | grep "little endian") ]]; then kmod_elf_hdr="$(readelf -h "$module")"
SECTDATA=$(echo $ELFSECTDATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g') [ "x$kmod_elf_hdr" = "x${kmod_elf_hdr%Data:*little endian*}" ]
else revbytes="$?"
SECTDATA=$ELFSECTDATA
fi
objdump -t "$module" \ objdump -t "$module" \
| awk \ | awk \
-v 'dep_pfx='"$dep_pfx" \ -v 'dep_pfx='"$dep_pfx" \
-v 'sectdata='"$SECTDATA" \ -v 'module='"$module" \
-v 'revbytes='"$revbytes" \
--non-decimal-data \ --non-decimal-data \
'match($0, /^([0-9a-f]+) g...... .* [0-9a-f]+ __crc_(.*)$/, a) { printf("%s(%s) = 0x%08s\n", dep_pfx, a[2], substr(sectdata, (strtonum("0x" a[1]) * 2) + 1, 8)) }' 'function readsect(name, a, t) {
done \ a = "";
| sort -u while (("readelf -R \"" name "\" \"" module "\"" | getline t) > 0) {
fi if (match(t, /^ 0x[0-9a-f]{8}/))
a = a substr(t, 14, 8) substr(t, 23, 8) substr(t, 32, 8) substr(t, 41, 8);
}
if (revbytes) { a = gensub(/(..)(..)(..)(..)/, "\\4\\3\\2\\1", "g", a); }
sectdata[name] = a;
}
match($0, /^([0-9a-f]+) [gl]...... (.*) [0-9a-f]+ __crc_(.*)$/, a) {
if (!(a[2] in sectdata)) { readsect(a[2]) }
printf("%s(%s) = 0x%08s\n", dep_pfx, a[3], substr(sectdata[a[2]], (strtonum("0x" a[1]) * 2) + 1, 8))
}'
}
[ -z "$tmpfile" ] || rm -f -- "$tmpfile" [ -z "$tmpfile" ] || rm -f -- "$tmpfile"
done done \
| sort -k1,1 -u

76
SOURCES/find-requires.ksyms Executable file → Normal file
View File

@ -6,6 +6,11 @@
# provided by an external module and "ksym" replaces th regular "kernel" dep. # provided by an external module and "ksym" replaces th regular "kernel" dep.
IFS=$'\n' IFS=$'\n'
export LC_ALL=C
# Prevent elfutils from trying to download debuginfos
unset DEBUGINFOD_URLS
# Extract all of the symbols provided by this module. # Extract all of the symbols provided by this module.
all_provides() { all_provides() {
@ -35,38 +40,57 @@ all_provides() {
module="$tmpfile" module="$tmpfile"
fi fi
if nm "$module" | grep -qE '^([0-9a-f]+) A __crc_(.+)' 2> /dev/null; then # awk script return code:
# 0 - absolute __crc_* symbols have been found, output has been
# generated;
# 23 - a non-absolute __crc_* symbold has been found;
# 42 - no __crc_* symbols have been found.
nm "$module" \ nm "$module" \
| awk \ | awk \
-v 'dep_pfx='"$dep_pfx" \ -v 'dep_pfx='"$dep_pfx" \
--non-decimal-data \ --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])) }' 'BEGIN { exit_code = 42 }
else match($0, /^([0-9a-f]+) (.) __crc_(.+)/, a) {
objdump -t "$module" \ if (a[2] == "A") {
| sed -n 's/^[0-9a-f][0-9a-f]* g...... \(.*\) [0-9a-f][0-9a-f]* __crc_.*$/\1/p' \ printf("%s(%s) = 0x%08x\n", dep_pfx, a[3], strtonum("0x" a[1]));
| sort -u \ exit_code = 0;
| while read sectname; do } else {
[ -n "$sectname" ] || continue exit_code = 23;
exit;
}
}
END { exit exit_code }'
ELFSECTDATA=$(readelf -R .rodata "$module" | awk '/0x/{printf $2$3$4$5}') [ 23 = "$?" ] && {
if [[ -n $(readelf -h "$module" | grep "little endian") ]]; then kmod_elf_hdr="$(readelf -h "$module")"
SECTDATA=$(echo $ELFSECTDATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g') [ "x$kmod_elf_hdr" = "x${kmod_elf_hdr%Data:*little endian*}" ]
else revbytes="$?"
SECTDATA=$ELFSECTDATA
fi
objdump -t "$module" \ objdump -t "$module" \
| awk \ | awk \
-v 'dep_pfx='"$dep_pfx" \ -v 'dep_pfx='"$dep_pfx" \
-v 'sectdata='"$SECTDATA" \ -v 'module='"$module" \
-v 'revbytes='"$revbytes" \
--non-decimal-data \ --non-decimal-data \
'match($0, /^([0-9a-f]+) g...... .* [0-9a-f]+ __crc_(.*)$/, a) { printf("%s(%s) = 0x%08s\n", dep_pfx, a[2], substr(sectdata, (strtonum("0x" a[1]) * 2) + 1, 8)) }' 'function readsect(name, a, t) {
done a = "";
fi while (("readelf -R \"" name "\" \"" module "\"" | getline t) > 0) {
if (match(t, /^ 0x[0-9a-f]{8}/))
a = a substr(t, 14, 8) substr(t, 23, 8) substr(t, 32, 8) substr(t, 41, 8);
}
if (revbytes) { a = gensub(/(..)(..)(..)(..)/, "\\4\\3\\2\\1", "g", a); }
sectdata[name] = a;
}
match($0, /^([0-9a-f]+) [gl]...... (.*) [0-9a-f]+ __crc_(.*)$/, a) {
if (!(a[2] in sectdata)) { readsect(a[2]) }
printf("%s(%s) = 0x%08s\n", dep_pfx, a[3], substr(sectdata[a[2]], (strtonum("0x" a[1]) * 2) + 1, 8))
}'
}
[ -z "$tmpfile" ] || rm -f -- "$tmpfile" [ -z "$tmpfile" ] || rm -f -- "$tmpfile"
done \ done \
| LC_ALL=C sort -k1,1 -u | sort -k1,1 -u
} }
# Extract all of the requirements of this module. # Extract all of the requirements of this module.
@ -79,15 +103,15 @@ all_requires() {
{printf("%s:0x%08x\n", $2, $1)}' \ {printf("%s:0x%08x\n", $2, $1)}' \
| sed -r -e 's:$:\t'"$1"':' | sed -r -e 's:$:\t'"$1"':'
done \ done \
| LC_ALL=C sort -k1,1 -u | sort -k1,1 -u
} }
# Filter out requirements fulfilled by the module itself. # Filter out requirements fulfilled by the module itself.
mod_requires() { mod_requires() {
LC_ALL=C join -t $'\t' -j 1 -v 1 \ join -t $'\t' -j 1 -v 1 \
<(all_requires "$@") \ <(all_requires "$@") \
<(all_provides "$@") \ <(all_provides "$@") \
| LC_ALL=C sort -k1,1 -u | sort -k1,1 -u
} }
if ! [ -e /sbin/modinfo -a -e /sbin/modprobe ]; then if ! [ -e /sbin/modinfo -a -e /sbin/modprobe ]; then
@ -150,21 +174,21 @@ if [ ${#modules[@]} -gt 0 ]; then
{ print $2 ":" $1 } { print $2 ":" $1 }
' \ ' \
| sed -r -e 's:$:\t'"$kernel"':' \ | sed -r -e 's:$:\t'"$kernel"':' \
| LC_ALL=C sort -k1,1 -u > $symvers | sort -k1,1 -u > $symvers
# Symbols matching with the kernel get a "kernel" dependency # Symbols matching with the kernel get a "kernel" dependency
mod_req=$(mktemp -t mod_req.XXXXX) mod_req=$(mktemp -t mod_req.XXXXX)
mod_requires "${modules[@]}" > "$mod_req" mod_requires "${modules[@]}" > "$mod_req"
LC_ALL=C join -t $'\t' -j 1 $symvers "$mod_req" | LC_ALL=C sort -u \ join -t $'\t' -j 1 $symvers "$mod_req" | sort -u \
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "kernel(" $1 ") = " $2 }' | awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "kernel(" $1 ") = " $2 }'
# Symbols from elsewhere get a "ksym" dependency # Symbols from elsewhere get a "ksym" dependency
LC_ALL=C join -t $'\t' -j 1 -v 2 $symvers "$mod_req" | LC_ALL=C sort -u \ join -t $'\t' -j 1 -v 2 $symvers "$mod_req" | sort -u \
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "ksym(" $1 ") = " $2 }' | awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "ksym(" $1 ") = " $2 }'
# Check kABI if the kabi-stablelists package is installed # Check kABI if the kabi-stablelists package is installed
# Do this last so we can try to output this error at the end # Do this last so we can try to output this error at the end
kabi_check_symbols=($(LC_ALL=C join -t $'\t' -j 1 $symvers "$mod_req" | LC_ALL=C sort -u \ kabi_check_symbols=($(join -t $'\t' -j 1 $symvers "$mod_req" | sort -u \
| awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print $1 }')) | awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print $1 }'))
check_kabi "${kabi_check_symbols[@]}" check_kabi "${kabi_check_symbols[@]}"
fi fi

View File

@ -1,2 +1,2 @@
%__kabi_provides %{_rpmconfigdir}/kabi.sh %__kabi_provides %{_rpmconfigdir}/kabi.sh
%__kabi_path ^(/boot/symvers-.*|/lib/modules/[1-9].*/symvers)\.gz$ %__kabi_path ^(/boot/symvers-.*|/lib/modules/[1-9].*/symvers)\.(gz|xz)$

View File

@ -7,10 +7,16 @@
IFS=$'\n' IFS=$'\n'
for symvers in $(grep -E '(/boot/symvers-.*|/lib/modules/[1-9].*/symvers)\.gz') "$@"; for symvers in $(grep -E '(/boot/symvers-.*|/lib/modules/[1-9].*/symvers)\.(gz|xz)') "$@";
do do
cat_prog="cat"
case "$symvers" in
*.gz) cat_prog="zcat" ;;
*.xz) cat_prog="xzcat" ;;
esac
# We generate dependencies only for symbols exported by vmlinux itself # We generate dependencies only for symbols exported by vmlinux itself
# and not for kmods here as they are spread across subpackages, # and not for kmods here as they are spread across subpackages,
# so Provides: generation for kmods is handled by find-provides.ksyms. # so Provides: generation for kmods is handled by find-provides.ksyms.
zcat $symvers | awk '/[^ ]* [^ ]* vmlinux .*/ { print "kernel(" $2 ") = " $1 }' "$cat_prog" "$symvers" | awk '/[^ ]* [^ ]* vmlinux .*/ { print "kernel(" $2 ") = " $1 }'
done done

View File

@ -1,6 +1,6 @@
Name: kernel-srpm-macros Name: kernel-srpm-macros
Version: 1.0 Version: 1.0
Release: 12%{?dist} Release: 13%{?dist}
Summary: RPM macros that list arches the full kernel is built on Summary: RPM macros that list arches the full kernel is built on
# This package only exist in Fedora repositories # This package only exist in Fedora repositories
# The license is the standard (MIT) specified in # The license is the standard (MIT) specified in
@ -134,6 +134,20 @@ install -p -m 644 -t "%{buildroot}%{_fileattrsdir}" modalias.attr
%{rrcdir}/find-provides.d/modalias.prov %{rrcdir}/find-provides.d/modalias.prov
%changelog %changelog
* Mon Jun 12 2023 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-13
- Handle symvers.xz in kabi.attr (#2209253).
- Fix indirect __crc_* sumbols parsing in find-provides.ksyms
and find-requires.ksyms to avoid matching multiple sections
producing bogus duplicate provides for kmods that have both __kcrctab
and __kcrctab_gpl sections (#2115811, #2178935).
- Call "readelf -R" on a correct section in find-requires.ksyms.
- Rewrite section data extraction in find-provides.ksyms and find-requires.ksyms
to avoid garbage at the end of extracted sections, causing unnecessary awk
complaints (#2115811).
- Perform section parsing inside the awk script in find-provides.ksyms
and find-requires.ksyms to avoid hitting command line argument limit
when handling large .rodata sections (#2178935).
* Tue Jan 31 2023 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-12 * Tue Jan 31 2023 Eugene Syromiatnikov <esyr@redhat.com> - 1.0-12
- Support storing of __crc_* symbols in sections other than .rodata. - Support storing of __crc_* symbols in sections other than .rodata.
- Resolves: #2135047 - Resolves: #2135047