2021-06-03 15:21:41 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
IFS=$'\n'
|
2023-02-05 00:11:15 +00:00
|
|
|
export LC_ALL=C
|
2021-06-03 15:21:41 +00:00
|
|
|
|
2023-03-30 13:01:59 +00:00
|
|
|
# Prevent elfutils from trying to download debuginfos
|
|
|
|
unset DEBUGINFOD_URLS
|
|
|
|
|
2021-11-17 11:38:00 +00:00
|
|
|
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do
|
2021-11-17 15:29:49 +00:00
|
|
|
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 \
|
2023-02-05 00:11:15 +00:00
|
|
|
|| dep_pfx="kernel"
|
2021-11-17 15:29:49 +00:00
|
|
|
|
2018-08-24 06:45:49 +00:00
|
|
|
tmpfile=""
|
|
|
|
if [ "x${module%.ko}" = "x${module}" ]; then
|
|
|
|
tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
|
|
|
|
proc_bin=
|
|
|
|
case "${module##*.}" in
|
2021-11-17 11:38:00 +00:00
|
|
|
zst)
|
|
|
|
proc_bin=zstd
|
|
|
|
;;
|
2018-08-24 06:45:49 +00:00
|
|
|
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
|
|
|
|
|
2023-05-22 16:25:49 +00:00
|
|
|
# A modversion can be stored as an ELF symbol in various ways:
|
|
|
|
# - An immediate symbol whose value is available directly; it shows up
|
2023-06-01 09:20:50 +00:00
|
|
|
# in the nm or objdump -t output, for example:
|
2023-05-22 16:25:49 +00:00
|
|
|
# $ nm mlx5_core_5.14.x86_64.ko | grep '__crc_' | head -n 3
|
|
|
|
# 0000000092f175ca A __crc_mlx5_access_reg
|
|
|
|
# 000000005b88c9f1 A __crc_mlx5_add_flow_rules
|
|
|
|
# 00000000e7c0ec8a A __crc_mlx5_alloc_bfreg
|
2023-06-01 09:20:50 +00:00
|
|
|
# $ objdump -t lib/modules/mlx5_core_5.14.x86_64.ko | grep __crc_ | sort -k 5,5 | head -n 3
|
|
|
|
# 0000000092f175ca g *ABS* 0000000000000000 __crc_mlx5_access_reg
|
|
|
|
# 000000005b88c9f1 g *ABS* 0000000000000000 __crc_mlx5_add_flow_rules
|
|
|
|
# 00000000e7c0ec8a g *ABS* 0000000000000000 __crc_mlx5_alloc_bfreg
|
2023-05-22 16:25:49 +00:00
|
|
|
# $ zgrep mlx5_access_reg ./lib/modules/5.14.0-284.15.1.el9_2.x86_64/symvers.gz
|
|
|
|
# 0x92f175ca mlx5_access_reg drivers/net/ethernet/mellanox/mlx5/core/mlx5_core EXPORT_SYMBOL_GPL
|
|
|
|
# This approach was being used on x86 and arm before Linux 5.19,
|
|
|
|
# for example.
|
|
|
|
#
|
|
|
|
# - A globally or locally visible symbol in a read-only (or not;
|
|
|
|
# sometimes .rodata is not a read-only section, after all, as binutils
|
|
|
|
# commit binutils-2_33~1385 has revealed (and binutils-2_35~1768 hasn't
|
|
|
|
# concealed back)) section (historically .rodata, __kcrctab/__kcrctab_gpl
|
|
|
|
# since Linux v5.19-rc1~139^2~2):
|
|
|
|
# $ nm mlx5_core_5.14.s390x.ko | grep '__crc_' | head -n 3
|
|
|
|
# 0000000000002f7c R __crc_mlx5_access_reg
|
|
|
|
# 0000000000003304 R __crc_mlx5_add_flow_rules
|
|
|
|
# 0000000000002d2c R __crc_mlx5_alloc_bfreg
|
|
|
|
# This layout is used on ppc since Linux v4.10-rc7~15^2~1, for example,
|
|
|
|
# and on all architectures since Linux 5.19. To extract the symbol
|
|
|
|
# versions in this case, we get the offset and the section name
|
|
|
|
# from the "objdump -t" output:
|
|
|
|
# $ objdump -t lib/modules/mlx5_core_5.14.s390x.ko | grep '__crc_' | sort -k 5,5 | head -n 2
|
|
|
|
# 0000000000002f7c g .rodata 0000000000000000 __crc_mlx5_access_reg
|
|
|
|
# 0000000000003304 g .rodata 0000000000000000 __crc_mlx5_add_flow_rules
|
|
|
|
# and the section contents from the "readelf -R" call:
|
|
|
|
# $ readelf -R .rodata mlx5_core_5.14.s390x.ko
|
|
|
|
# [... skipped output ...]
|
|
|
|
# 0x00002f70 6c6f635f 6e6f6465 00000000 ed6560a8 loc_node.....e`.
|
|
|
|
# ^^^^^^^^
|
|
|
|
# comparison with the contents
|
|
|
|
# of lib/modules/5.14.0-284.15.1.el9_2.s390x/symvers.gz corroborates
|
|
|
|
# its correctness:
|
|
|
|
# 0xed6560a8 mlx5_access_reg drivers/net/ethernet/mellanox/mlx5/core/mlx5_core EXPORT_SYMBOL_GPL
|
|
|
|
# As mentioned earlier, for the later kernel versions, __kcrctab{,_gpl}
|
|
|
|
# sections are used:
|
|
|
|
# $ objdump -t lib/modules/mlx5_core_6.4.x86_64.ko | grep '__crc_' | sort -k 5,5 | head -n 2
|
|
|
|
# 0000000000000000 l __kcrctab_gpl 0000000000000000 __crc_mlx5_access_reg
|
|
|
|
# 0000000000000090 l __kcrctab 0000000000000000 __crc_mlx5_add_flow_rules
|
|
|
|
# $ readelf -R __kcrctab_gpl mlx5_core_6.4.x86_64.ko
|
|
|
|
# 0x00000000 38b0d3c3 1840ce35 b99babc7 70b4700c 8....@.5....p.p.
|
|
|
|
# ^^^^^^^^
|
|
|
|
# and in lib/modules/6.4.0-0.rc1.20230511git80e62bc8487b.19.eln126.x86_64/symvers.xz
|
|
|
|
# we see that it is correct (when accounted for the little endianness):
|
|
|
|
# 0xc3d3b038 mlx5_access_reg drivers/net/ethernet/mellanox/mlx5/core/mlx5_core EXPORT_SYMBOL_GPL
|
|
|
|
# This data, after some post-processing, can be used in the awk script
|
|
|
|
# that extracts parts of the section according to the offsets got
|
|
|
|
# from the "objdump -t" output.
|
2023-06-01 09:20:50 +00:00
|
|
|
objdump -t "$module" \
|
2023-05-23 13:02:19 +00:00
|
|
|
| awk \
|
2023-06-01 09:20:50 +00:00
|
|
|
-v 'dep_pfx='"$dep_pfx" \
|
|
|
|
-v 'module='"$module" \
|
|
|
|
--non-decimal-data \
|
|
|
|
'BEGIN { revbytes = 0 }
|
2023-05-23 13:02:19 +00:00
|
|
|
|
2023-06-01 09:20:50 +00:00
|
|
|
function check_endianness( t) {
|
|
|
|
if (revbytes) return revbytes;
|
2023-02-05 00:26:01 +00:00
|
|
|
|
2023-06-01 09:20:50 +00:00
|
|
|
revbytes = -1;
|
|
|
|
while (("readelf -h \"" module "\"" | getline t) > 0) {
|
|
|
|
if (match(t, /^ Data: *2\047s complement, little endian$/)) {
|
|
|
|
revbytes = 1;
|
|
|
|
break;
|
2023-05-22 15:53:44 +00:00
|
|
|
}
|
2023-05-23 14:17:39 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 09:20:50 +00:00
|
|
|
return revbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
function readsect(name, a, t) {
|
|
|
|
a = "";
|
|
|
|
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 (check_endianness() == 1)
|
|
|
|
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] == "*ABS*") {
|
|
|
|
printf("%s(%s) = 0x%08x\n", dep_pfx, a[3], strtonum("0x" a[1]));
|
|
|
|
} else {
|
2023-05-23 14:17:39 +00:00
|
|
|
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))
|
2023-06-01 09:20:50 +00:00
|
|
|
}
|
|
|
|
}'
|
2018-08-24 06:45:49 +00:00
|
|
|
|
|
|
|
[ -z "$tmpfile" ] || rm -f -- "$tmpfile"
|
2023-05-22 12:15:23 +00:00
|
|
|
done \
|
|
|
|
| sort -k1,1 -u
|