Blame SOURCES/find-provides.ksyms

7b79ae
#! /bin/bash
7b79ae
7b79ae
IFS=$'\n'
7b79ae
7b79ae
for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz)?$'); do
7b79ae
    tmpfile=""
7b79ae
    if [ "x${module%.ko}" = "x${module}" ]; then
7b79ae
        tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
7b79ae
        proc_bin=
7b79ae
        case "${module##*.}" in
7b79ae
        xz)
7b79ae
                proc_bin=xz
7b79ae
                ;;
7b79ae
        bz2)
7b79ae
                proc_bin=bzip2
7b79ae
                ;;
7b79ae
        gz)
7b79ae
                proc_bin=gzip
7b79ae
                ;;
7b79ae
        esac
7b79ae
7b79ae
        [ -n "$proc_bin" ] || continue
7b79ae
7b79ae
        "$proc_bin" -d -c - < "$module" > "$tmpfile" || continue
7b79ae
        module="$tmpfile"
7b79ae
    fi
7b79ae
7b79ae
    if [[ -n $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p') ]]; then
7b79ae
        nm $module \
7b79ae
        | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \
7b79ae
        | awk --non-decimal-data '{printf("ksym(%s) = 0x%08x\n", $2, $1)}' \
7b79ae
        | LC_ALL=C sort -u
7b79ae
    else
7b79ae
        ELFRODATA=$(readelf -R .rodata $module | awk '/0x/{printf $2$3$4$5}')
7b79ae
        if [[ -n $(readelf -h $module | grep "little endian") ]]; then
7b79ae
            RODATA=$(echo $ELFRODATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g')
7b79ae
        else
7b79ae
            RODATA=$ELFRODATA
7b79ae
        fi
7b79ae
        for sym in $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) R __crc_(.+):0x\1 \2:p'); do
7b79ae
            echo $sym $RODATA
7b79ae
        done \
7b79ae
        | awk --non-decimal-data '{printf("ksym(%s) = 0x%08s\n", $2, substr($3,($1*2)+1,8))}' \
7b79ae
        | LC_ALL=C sort -u
7b79ae
    fi
7b79ae
7b79ae
    [ -z "$tmpfile" ] || rm -f -- "$tmpfile"
7b79ae
done