Blame SOURCES/find-provides.ksyms

67e50c
#! /bin/bash
67e50c
67e50c
IFS=$'\n'
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 \
936cd0
	|| 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
67e50c
    if [[ -n $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p') ]]; then
67e50c
        nm $module \
67e50c
        | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \
936cd0
        | awk --non-decimal-data '{printf("'"${dep_pfx}"'(%s) = 0x%08x\n", $2, $1)}' \
67e50c
        | LC_ALL=C sort -u
67e50c
    else
67e50c
        ELFRODATA=$(readelf -R .rodata $module | awk '/0x/{printf $2$3$4$5}')
67e50c
        if [[ -n $(readelf -h $module | grep "little endian") ]]; then
67e50c
            RODATA=$(echo $ELFRODATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g')
67e50c
        else
67e50c
            RODATA=$ELFRODATA
67e50c
        fi
67e50c
        for sym in $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) R __crc_(.+):0x\1 \2:p'); do
67e50c
            echo $sym $RODATA
67e50c
        done \
936cd0
        | awk --non-decimal-data '{printf("'"${dep_pfx}"'(%s) = 0x%08s\n", $2, substr($3,($1*2)+1,8))}' \
67e50c
        | LC_ALL=C sort -u
67e50c
    fi
936cd0
936cd0
    [ -z "$tmpfile" ] || rm -f -- "$tmpfile"
67e50c
done