Quentin Perret | cd195bc | 2020-02-28 17:20:14 +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 | |
Masahiro Yamada | a6aaeb8 | 2021-02-26 15:25:48 +0900 | [diff] [blame] | 19 | needed_symbols= |
| 20 | |
| 21 | # Special case for modversions (see modpost.c) |
Masahiro Yamada | 7d15369 | 2021-12-14 11:53:52 +0900 | [diff] [blame] | 22 | if grep -q "^CONFIG_MODVERSIONS=y$" include/config/auto.conf; then |
Masahiro Yamada | a6aaeb8 | 2021-02-26 15:25:48 +0900 | [diff] [blame] | 23 | needed_symbols="$needed_symbols module_layout" |
| 24 | fi |
| 25 | |
Masahiro Yamada | 129ab0d | 2021-12-14 11:53:53 +0900 | [diff] [blame] | 26 | ksym_wl=$(sed -n 's/^CONFIG_UNUSED_KSYMS_WHITELIST=\(.*\)$/\1/p' include/config/auto.conf) |
Masahiro Yamada | 7d15369 | 2021-12-14 11:53:52 +0900 | [diff] [blame] | 27 | if [ -n "$ksym_wl" ]; then |
Quentin Perret | cd195bc | 2020-02-28 17:20:14 +0000 | [diff] [blame] | 28 | [ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl" |
| 29 | if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then |
| 30 | echo "ERROR: '$ksym_wl' whitelist file not found" >&2 |
| 31 | exit 1 |
| 32 | fi |
| 33 | fi |
| 34 | |
| 35 | # Generate a new ksym list file with symbols needed by the current |
| 36 | # set of modules. |
| 37 | cat > "$output_file" << EOT |
| 38 | /* |
| 39 | * Automatically generated file; DO NOT EDIT. |
| 40 | */ |
| 41 | |
| 42 | EOT |
| 43 | |
Quentin Perret | 88694cf | 2020-02-28 17:20:15 +0000 | [diff] [blame] | 44 | [ -f modules.order ] && modlist=modules.order || modlist=/dev/null |
Masahiro Yamada | a6aaeb8 | 2021-02-26 15:25:48 +0900 | [diff] [blame] | 45 | |
| 46 | { |
| 47 | sed 's/ko$/mod/' $modlist | xargs -n1 sed -n -e '2p' |
| 48 | echo "$needed_symbols" |
| 49 | [ -n "$ksym_wl" ] && cat "$ksym_wl" |
| 50 | } | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' | |
Masahiro Yamada | 29500f1 | 2021-02-11 15:14:16 +0900 | [diff] [blame] | 51 | # Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry |
| 52 | # point addresses. |
| 53 | sed -e 's/^\.//' | |
Quentin Perret | cd195bc | 2020-02-28 17:20:14 +0000 | [diff] [blame] | 54 | sort -u | |
| 55 | sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file" |