Whamcloud - gitweb
LU-6142 misc: update headers in config, debian, rpm
[fs/lustre-release.git] / rpm / find-provides.ksyms
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
4 #
5 # This file is part of Lustre, http://www.lustre.org/
6 #
7 # rpm/find-provides.ksyms
8 #
9 # Find which kernel symbols a particular module provides
10 #
11
12 IFS=$'\n'
13
14 MODULE_SYMVERS=$RPM_BUILD_ROOT/Module.symvers
15
16 for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz)?$'); do
17     tmpfile=""
18     if [ "x${module%.ko}" = "x${module}" ]; then
19         tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko)
20         proc_bin=
21         case "${module##*.}" in
22         xz)
23                 proc_bin=xz
24                 ;;
25         bz2)
26                 proc_bin=bzip2
27                 ;;
28         gz)
29                 proc_bin=gzip
30                 ;;
31         esac
32
33         [ -n "$proc_bin" ] || continue
34
35         "$proc_bin" -d -c - < "$module" > "$tmpfile" || continue
36         module="$tmpfile"
37     fi
38
39     if [[ -f $MODULE_SYMVERS ]] ; then
40         # all symbols prefixed with __rcr_ where the symbol is:
41         #  A   - symbol is an absolute value
42         #  D,d - symbol is in the initialized data section
43         #  R,r - symbol is in the read-only data section
44         #  T,t - symbol is in the text (code) section
45         for sym in $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) [ADdRr] __crc_(.+):\2:p'); do
46             grep -w $sym $MODULE_SYMVERS | awk '{printf("ksym(%s) = %08s\n", $2, $1)}'
47         done \
48         | LC_ALL=C sort -u
49     else
50         >&2 echo "Module.symvers required for provides."
51     fi
52     [ -z "$tmpfile" ] || rm -f -- "$tmpfile"
53 done