Blame SOURCES/find-requires.ksyms

a008c1
#! /bin/bash
a008c1
#
a008c1
# This script is called during external module building to create dependencies
a008c1
# both upon the RHEL kernel, and on additional external modules. Symbols that
a008c1
# cannot be reconciled against those provided by the kernel are assumed to be
a008c1
# provided by an external module and "ksym" replaces th regular "kernel" dep.
a008c1
a008c1
IFS=$'\n'
a008c1
a008c1
# Extract all of the symbols provided by this module.
a008c1
all_provides() {
a008c1
    for module in "$@"; do
a008c1
        tmpfile=""
a008c1
        if [ "x${module%.ko}" = "x${module}" ]; then
a008c1
            tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
a008c1
            proc_bin=
a008c1
            case "${module##*.}" in
a008c1
            xz)
a008c1
                    proc_bin=xz
a008c1
                    ;;
a008c1
            bz2)
a008c1
                    proc_bin=bzip2
a008c1
                    ;;
a008c1
            gz)
a008c1
                    proc_bin=gzip
a008c1
                    ;;
a008c1
            esac
a008c1
a008c1
            [ -n "$proc_bin" ] || continue
a008c1
a008c1
            "$proc_bin" -d -c - < "$module" > "$tmpfile" || continue
a008c1
            module="$tmpfile"
a008c1
        fi
a008c1
a008c1
        if [[ -n $(nm "$module" | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p') ]]; then
a008c1
            nm "$module" \
a008c1
            | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):0x\1 \2:p' \
a008c1
            | awk --non-decimal-data '{printf("%s:0x%08x\n", $2, $1)}'
a008c1
        else
a008c1
            ELFRODATA=$(readelf -R .rodata "$module" | awk '/0x/{printf $2$3$4$5}')
a008c1
            if [[ -n $(readelf -h "$module" | grep "little endian") ]]; then
a008c1
                RODATA=$(echo $ELFRODATA | sed 's/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/g')
a008c1
            else
a008c1
                RODATA=$ELFRODATA
a008c1
            fi
a008c1
            for sym in $(nm "$module" | sed -r -ne 's:^0*([0-9a-f]+) R __crc_(.+):0x\1 \2:p'); do
a008c1
                echo $sym $RODATA
a008c1
            done \
a008c1
            | awk --non-decimal-data '{printf("%s:0x%08s\n", $2, substr($3,($1*2)+1,8))}'
a008c1
        fi
a008c1
a008c1
        [ -z "$tmpfile" ] || rm -f -- "$tmpfile"
a008c1
    done \
a008c1
    | LC_ALL=C sort -k1,1 -u
a008c1
}
a008c1
a008c1
# Extract all of the requirements of this module.
a008c1
all_requires() {
a008c1
    for module in "$@"; do
a008c1
        set -- $(/sbin/modinfo -F vermagic "$module" | sed -e 's: .*::' -e q)
a008c1
        /sbin/modprobe --dump-modversions "$module" \
a008c1
        | awk --non-decimal-data '
a008c1
            BEGIN { FS = "\t" ; OFS = "\t" }
a008c1
            {printf("%s:0x%08x\n", $2, $1)}' \
a008c1
        | sed -r -e 's:$:\t'"$1"':'
a008c1
    done \
a008c1
    | LC_ALL=C sort -k1,1 -u
a008c1
}
a008c1
a008c1
# Filter out requirements fulfilled by the module itself.
a008c1
mod_requires() {
a008c1
    LC_ALL=C join -t $'\t' -j 1 -v 1 \
a008c1
        <(all_requires "$@") \
a008c1
        <(all_provides "$@") \
a008c1
    | LC_ALL=C sort -k1,1 -u
a008c1
}
a008c1
a008c1
if ! [ -e /sbin/modinfo -a -e /sbin/modprobe ]; then
a008c1
    cat > /dev/null
a008c1
    exit 0
a008c1
fi
a008c1
a008c1
check_kabi() {
a008c1
    arch=$(uname -m)
a008c1
    kabi_file="/lib/modules/kabi-current/kabi_whitelist_$arch"
a008c1
a008c1
    # If not installed, output a warning and return (continue)
a008c1
    if [ ! -f "$kabi_file" ]; then
a008c1
        echo "" >&2
a008c1
        echo "********************************************************************************" >&2
a008c1
        echo "*********************** KERNEL ABI COMPATIBILITY WARNING ***********************" >&2
a008c1
        echo "********************************************************************************" >&2
a008c1
        echo "The kernel ABI reference files (provided by "kabi-whitelists") were not found." >&2
a008c1
        echo "No compatibility check was performed. Please install the kABI reference files" >&2
a008c1
        echo "and rebuild if you would like to verify compatibility with kernel ABI." >&2
a008c1
        echo "" >&2
a008c1
        return
a008c1
    fi
a008c1
a008c1
    unset non_kabi
a008c1
    for symbol in "$@"; do
a008c1
        if ! egrep "^[[:space:]]$symbol\$" $kabi_file >/dev/null; then
a008c1
            non_kabi=("${non_kabi[@]}" "$symbol")
a008c1
        fi
a008c1
    done
a008c1
a008c1
    if [ ${#non_kabi[@]} -gt 0 ]; then
a008c1
        echo "" >&2
a008c1
        echo "********************************************************************************" >&2
a008c1
        echo "*********************** KERNEL ABI COMPATIBILITY WARNING ***********************" >&2
a008c1
        echo "********************************************************************************" >&2
a008c1
        echo "The following kernel symbols are not guaranteed to remain compatible with" >&2
a008c1
        echo "future kernel updates to this RHEL release:" >&2
a008c1
        echo "" >&2
a008c1
        for symbol in "${non_kabi[@]}"; do
a008c1
            printf "\t$symbol\n" >&2
a008c1
        done
a008c1
        echo "" >&2
a008c1
        echo "Red Hat recommends that you consider using only official kernel ABI symbols" >&2
a008c1
        echo "where possible. Requests for additions to the kernel ABI can be filed with" >&2
a008c1
        echo "your partner or customer representative (component: driver-update-program)." >&2
a008c1
        echo "" >&2
a008c1
    fi
a008c1
}
a008c1
a008c1
modules=($(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz)?$'))
a008c1
if [ ${#modules[@]} -gt 0 ]; then
a008c1
    kernel=$(/sbin/modinfo -F vermagic "${modules[0]}" | sed -e 's: .*::' -e q)
a008c1
a008c1
    # get all that kernel provides
a008c1
    symvers=$(mktemp -t ${0##*/}.XXXXX)
a008c1
a008c1
    cat /usr/src/kernels/$kernel/Module.symvers | awk '
a008c1
        BEGIN { FS = "\t" ; OFS = "\t" }
a008c1
        { print $2 ":" $1 }
a008c1
    ' \
a008c1
    | sed -r -e 's:$:\t'"$kernel"':' \
a008c1
    | LC_ALL=C sort -k1,1 -u > $symvers
a008c1
a008c1
    # Symbols matching with the kernel get a "kernel" dependency
a008c1
    mod_req=$(mktemp -t mod_req.XXXXX)
a008c1
    mod_requires "${modules[@]}" > "$mod_req"
a008c1
    LC_ALL=C join -t $'\t' -j 1 $symvers "$mod_req" | LC_ALL=C sort -u \
a008c1
    | awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "kernel(" $1 ") = " $2 }'
a008c1
a008c1
    # Symbols from elsewhere get a "ksym" dependency
a008c1
    LC_ALL=C join -t $'\t' -j 1 -v 2 $symvers "$mod_req" | LC_ALL=C sort -u \
a008c1
    | awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print "ksym(" $1 ") = " $2 }'
a008c1
a008c1
    # Check kABI if the kabi-whitelists package is installed
a008c1
    # Do this last so we can try to output this error at the end
a008c1
    kabi_check_symbols=($(LC_ALL=C join -t $'\t' -j 1 $symvers "$mod_req" | LC_ALL=C sort -u \
a008c1
    | awk 'BEGIN { FS = "[\t:]" ; OFS = "\t" } { print $1 }'))
a008c1
    check_kabi "${kabi_check_symbols[@]}"
a008c1
fi