Blame SOURCES/find-provides.ksyms

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