Blame SOURCES/find-provides.ksyms

837a2d
#! /bin/bash
837a2d
837a2d
IFS=$'\n'
2fc89e
export LC_ALL=C
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 \
2fc89e
        || 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
2fc89e
    if nm "$module" | grep -qE '^([0-9a-f]+) A __crc_(.+)' 2> /dev/null; then
2fc89e
        nm "$module" \
2fc89e
        | awk \
2fc89e
           -v 'dep_pfx='"$dep_pfx" \
2fc89e
           --non-decimal-data \
2fc89e
          'match($0, /^([0-9a-f]+) A __crc_(.+)/, a) { printf("%s(%s) = 0x%08x\n", dep_pfx, a[2], strtonum("0x" a[1])) }' \
2fc89e
        | sort -u
837a2d
    else
2fc89e
        objdump -t "$module" \
2fc89e
        | sed -n 's/^[0-9a-f][0-9a-f]* g...... \(.*\)	[0-9a-f][0-9a-f]* __crc_.*$/\1/p' \
2fc89e
        | sort -u \
2fc89e
        | while read sectname; do
2fc89e
            [ -n "$sectname" ] || continue
2fc89e
2fc89e
            ELFSECTDATA=$(readelf -R "$sectname" "$module" | awk '/0x/{printf $2$3$4$5}')
2fc89e
            if [[ -n $(readelf -h $module | grep "little endian") ]]; then
2fc89e
                SECTDATA=$(echo $ELFSECTDATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g')
2fc89e
            else
2fc89e
                SECTDATA=$ELFSECTDATA
2fc89e
            fi
2fc89e
2fc89e
            objdump -t "$module" \
2fc89e
            | awk \
2fc89e
              -v 'dep_pfx='"$dep_pfx" \
2fc89e
              -v 'sectdata='"$SECTDATA" \
2fc89e
              --non-decimal-data \
2fc89e
              '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)) }'
837a2d
        done \
2fc89e
        | sort -u
837a2d
    fi
837a2d
837a2d
    [ -z "$tmpfile" ] || rm -f -- "$tmpfile"
837a2d
done