diff --git a/find-provides.ksyms b/find-provides.ksyms index a507708..d498598 100755 --- a/find-provides.ksyms +++ b/find-provides.ksyms @@ -59,33 +59,30 @@ for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz|\.zst)?$') "$@"; do END { exit exit_code }' [ 23 = "$?" ] && { + kmod_elf_hdr="$(readelf -h "$module")" + [ "x$kmod_elf_hdr" = "x${kmod_elf_hdr%Data:*little endian*}" ] + revbytes="$?" + objdump -t "$module" \ - | sed -n 's/^[0-9a-f][0-9a-f]* [gl]...... \(.*\) [0-9a-f][0-9a-f]* __crc_.*$/\1/p' \ - | sort -u \ - | while read -r sectname; do - [ -n "$sectname" ] || continue - - kmod_elf_hdr="$(readelf -h "$module")" - [ "x$kmod_elf_hdr" = "x${kmod_elf_hdr%Data:*little endian*}" ] - revbytes="$?" - - objdump -t "$module" \ - | awk \ - -v 'dep_pfx='"$dep_pfx" \ - -v 'module='"$module" \ - -v 'revbytes='"$revbytes" \ - -v 'sectname='"$sectname" \ - --non-decimal-data \ - 'BEGIN { - sectdata = ""; - while (("readelf -R \"" sectname "\" \"" module "\"" | getline t) > 0) { - if (match(t, /^ 0x[0-9a-f]{8}/)) - sectdata = sectdata substr(t, 14, 8) substr(t, 23, 8) substr(t, 32, 8) substr(t, 41, 8); - } - if (revbytes) { sectdata = gensub(/(..)(..)(..)(..)/, "\\4\\3\\2\\1", "g", sectdata); } + | awk \ + -v 'dep_pfx='"$dep_pfx" \ + -v 'module='"$module" \ + -v 'revbytes='"$revbytes" \ + --non-decimal-data \ + '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); } - match($0, /^([0-9a-f]+) [gl]...... (.*) [0-9a-f]+ __crc_(.*)$/, a) && a[2] == sectname { printf("%s(%s) = 0x%08s\n", dep_pfx, a[3], substr(sectdata, (strtonum("0x" a[1]) * 2) + 1, 8)) }' - done + 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" diff --git a/find-requires.ksyms b/find-requires.ksyms index 15a5971..40b8f2e 100755 --- a/find-requires.ksyms +++ b/find-requires.ksyms @@ -61,33 +61,30 @@ all_provides() { END { exit exit_code }' [ 23 = "$?" ] && { + kmod_elf_hdr="$(readelf -h "$module")" + [ "x$kmod_elf_hdr" = "x${kmod_elf_hdr%Data:*little endian*}" ] + revbytes="$?" + objdump -t "$module" \ - | sed -n 's/^[0-9a-f][0-9a-f]* [gl]...... \(.*\) [0-9a-f][0-9a-f]* __crc_.*$/\1/p' \ - | sort -u \ - | while read -r sectname; do - [ -n "$sectname" ] || continue - - kmod_elf_hdr="$(readelf -h "$module")" - [ "x$kmod_elf_hdr" = "x${kmod_elf_hdr%Data:*little endian*}" ] - revbytes="$?" - - objdump -t "$module" \ - | awk \ - -v 'dep_pfx='"$dep_pfx" \ - -v 'module='"$module" \ - -v 'revbytes='"$revbytes" \ - -v 'sectname='"$sectname" \ - --non-decimal-data \ - 'BEGIN { - sectdata = ""; - while (("readelf -R \"" sectname "\" \"" module "\"" | getline t) > 0) { - if (match(t, /^ 0x[0-9a-f]{8}/)) - sectdata = sectdata substr(t, 14, 8) substr(t, 23, 8) substr(t, 32, 8) substr(t, 41, 8); - } - if (revbytes) { sectdata = gensub(/(..)(..)(..)(..)/, "\\4\\3\\2\\1", "g", sectdata); } + | awk \ + -v 'dep_pfx='"$dep_pfx" \ + -v 'module='"$module" \ + -v 'revbytes='"$revbytes" \ + --non-decimal-data \ + '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); } - match($0, /^([0-9a-f]+) [gl]...... (.*) [0-9a-f]+ __crc_(.*)$/, a) && a[2] == sectname { printf("%s(%s) = 0x%08s\n", dep_pfx, a[3], substr(sectdata, (strtonum("0x" a[1]) * 2) + 1, 8)) }' - done + 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"