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 |
Masahiro Yamada | 0e5851b | 2022-04-07 00:30:20 +0900 | [diff] [blame] | 5 | # as recorded in *.usyms files and the user-provided symbol whitelist. |
Quentin Perret | cd195bc | 2020-02-28 17:20:14 +0000 | [diff] [blame] | 6 | |
| 7 | set -e |
| 8 | |
Quentin Perret | cd195bc | 2020-02-28 17:20:14 +0000 | [diff] [blame] | 9 | # Use "make V=1" to debug this script. |
| 10 | case "$KBUILD_VERBOSE" in |
| 11 | *1*) |
| 12 | set -x |
| 13 | ;; |
| 14 | esac |
| 15 | |
| 16 | # We need access to CONFIG_ symbols |
| 17 | . include/config/auto.conf |
| 18 | |
Masahiro Yamada | 0e5851b | 2022-04-07 00:30:20 +0900 | [diff] [blame] | 19 | read_modorder= |
| 20 | |
| 21 | if [ "$1" = --modorder ]; then |
| 22 | shift |
| 23 | read_modorder=1 |
| 24 | fi |
| 25 | |
| 26 | output_file="$1" |
| 27 | |
Masahiro Yamada | a6aaeb8 | 2021-02-26 15:25:48 +0900 | [diff] [blame] | 28 | needed_symbols= |
| 29 | |
| 30 | # Special case for modversions (see modpost.c) |
| 31 | if [ -n "$CONFIG_MODVERSIONS" ]; then |
| 32 | needed_symbols="$needed_symbols module_layout" |
| 33 | fi |
| 34 | |
Masahiro Yamada | a6aaeb8 | 2021-02-26 15:25:48 +0900 | [diff] [blame] | 35 | ksym_wl= |
Quentin Perret | cd195bc | 2020-02-28 17:20:14 +0000 | [diff] [blame] | 36 | if [ -n "$CONFIG_UNUSED_KSYMS_WHITELIST" ]; then |
| 37 | # Use 'eval' to expand the whitelist path and check if it is relative |
| 38 | eval ksym_wl="$CONFIG_UNUSED_KSYMS_WHITELIST" |
Yifan Hong | d94e165 | 2024-05-29 16:52:55 +0000 | [diff] [blame] | 39 | [ "${ksym_wl}" != "${ksym_wl#/}" ] || [ -f "$ksym_wl" ] || ksym_wl="$abs_srctree/$ksym_wl" |
Quentin Perret | cd195bc | 2020-02-28 17:20:14 +0000 | [diff] [blame] | 40 | if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then |
| 41 | echo "ERROR: '$ksym_wl' whitelist file not found" >&2 |
| 42 | exit 1 |
| 43 | fi |
| 44 | fi |
| 45 | |
| 46 | # Generate a new ksym list file with symbols needed by the current |
| 47 | # set of modules. |
| 48 | cat > "$output_file" << EOT |
| 49 | /* |
| 50 | * Automatically generated file; DO NOT EDIT. |
| 51 | */ |
| 52 | |
| 53 | EOT |
| 54 | |
Masahiro Yamada | a6aaeb8 | 2021-02-26 15:25:48 +0900 | [diff] [blame] | 55 | { |
Masahiro Yamada | 0e5851b | 2022-04-07 00:30:20 +0900 | [diff] [blame] | 56 | [ -n "${read_modorder}" ] && sed 's/ko$/usyms/' modules.order | xargs cat |
Masahiro Yamada | a6aaeb8 | 2021-02-26 15:25:48 +0900 | [diff] [blame] | 57 | echo "$needed_symbols" |
| 58 | [ -n "$ksym_wl" ] && cat "$ksym_wl" |
| 59 | } | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' | |
Masahiro Yamada | 29500f1 | 2021-02-11 15:14:16 +0900 | [diff] [blame] | 60 | # Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry |
| 61 | # point addresses. |
| 62 | sed -e 's/^\.//' | |
Quentin Perret | cd195bc | 2020-02-28 17:20:14 +0000 | [diff] [blame] | 63 | sort -u | |
Sami Tolvanen | 2a2b876 | 2022-06-16 19:57:59 +0000 | [diff] [blame] | 64 | # Ignore __this_module. It's not an exported symbol, and will be resolved |
| 65 | # when the final .ko's are linked. |
| 66 | grep -v '^__this_module$' | |
Quentin Perret | cd195bc | 2020-02-28 17:20:14 +0000 | [diff] [blame] | 67 | sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file" |