Quentin Perret | a85058e | 2020-02-18 09:41:38 +0000 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | |
| 4 | # Create an autoksyms.h header file from the list of all module's needed symbols |
| 5 | # as recorded on the second line of *.mod files and the user-provided symbol |
| 6 | # whitelist. |
| 7 | |
| 8 | set -e |
| 9 | |
| 10 | output_file="$1" |
| 11 | |
| 12 | # Use "make V=1" to debug this script. |
| 13 | case "$KBUILD_VERBOSE" in |
| 14 | *1*) |
| 15 | set -x |
| 16 | ;; |
| 17 | esac |
| 18 | |
| 19 | # We need access to CONFIG_ symbols |
| 20 | . include/config/auto.conf |
| 21 | |
| 22 | ksym_wl=/dev/null |
| 23 | if [ -n "$CONFIG_UNUSED_KSYMS_WHITELIST" ]; then |
| 24 | # Use 'eval' to expand the whitelist path and check if it is relative |
| 25 | eval ksym_wl="$CONFIG_UNUSED_KSYMS_WHITELIST" |
| 26 | [ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl" |
| 27 | if [ ! -f "$ksym_wl" ]; then |
| 28 | echo "ERROR: '$ksym_wl' whitelist file not found" >&2 |
| 29 | exit 1 |
| 30 | fi |
| 31 | fi |
| 32 | |
| 33 | # Generate a new ksym list file with symbols needed by the current |
| 34 | # set of modules. |
| 35 | cat > "$output_file" << EOT |
| 36 | /* |
| 37 | * Automatically generated file; DO NOT EDIT. |
| 38 | */ |
| 39 | |
| 40 | EOT |
| 41 | |
| 42 | sed 's/ko$/mod/' modules.order | |
| 43 | xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- | |
| 44 | cat - "$ksym_wl" | |
| 45 | sort -u | |
| 46 | sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file" |
| 47 | |
| 48 | # Special case for modversions (see modpost.c) |
| 49 | if [ -n "$CONFIG_MODVERSIONS" ]; then |
| 50 | echo "#define __KSYM_module_layout 1" >> "$output_file" |
| 51 | fi |