Blame SOURCES/find-requires.ksyms

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