Blame SOURCES/find-requires.ksyms

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