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
28df6c
        # Commit binutils-2_33~1385[1] has changed (and binutils-2_35~1768[2]
28df6c
        # has not reverted it) the calculated type for symbols in read-write
28df6c
        # .rodata section from 'R' to 'D', since, apparently, many kernel
28df6c
        # modules have it indeed read-write.
28df6c
        #
28df6c
        # [1] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=a288c270991d
28df6c
        # [2] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=49d9fd42acef
28df6c
        for sym in $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) [DR] __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