blob: 7dd95eafdaafd552ebd80ad52d44c7aa1fd5dcba [file] [log] [blame]
Quentin Perretcd195bc2020-02-28 17:20:14 +00001#!/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 Yamada0e5851b2022-04-07 00:30:20 +09005# as recorded in *.usyms files and the user-provided symbol whitelist.
Quentin Perretcd195bc2020-02-28 17:20:14 +00006
7set -e
8
Quentin Perretcd195bc2020-02-28 17:20:14 +00009# Use "make V=1" to debug this script.
10case "$KBUILD_VERBOSE" in
11*1*)
12 set -x
13 ;;
14esac
15
16# We need access to CONFIG_ symbols
17. include/config/auto.conf
18
Masahiro Yamada0e5851b2022-04-07 00:30:20 +090019read_modorder=
20
21if [ "$1" = --modorder ]; then
22 shift
23 read_modorder=1
24fi
25
26output_file="$1"
27
Masahiro Yamadaa6aaeb82021-02-26 15:25:48 +090028needed_symbols=
29
30# Special case for modversions (see modpost.c)
31if [ -n "$CONFIG_MODVERSIONS" ]; then
32 needed_symbols="$needed_symbols module_layout"
33fi
34
Masahiro Yamadaa6aaeb82021-02-26 15:25:48 +090035ksym_wl=
Quentin Perretcd195bc2020-02-28 17:20:14 +000036if [ -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 Hongd94e1652024-05-29 16:52:55 +000039 [ "${ksym_wl}" != "${ksym_wl#/}" ] || [ -f "$ksym_wl" ] || ksym_wl="$abs_srctree/$ksym_wl"
Quentin Perretcd195bc2020-02-28 17:20:14 +000040 if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then
41 echo "ERROR: '$ksym_wl' whitelist file not found" >&2
42 exit 1
43 fi
44fi
45
46# Generate a new ksym list file with symbols needed by the current
47# set of modules.
48cat > "$output_file" << EOT
49/*
50 * Automatically generated file; DO NOT EDIT.
51 */
52
53EOT
54
Masahiro Yamadaa6aaeb82021-02-26 15:25:48 +090055{
Masahiro Yamada0e5851b2022-04-07 00:30:20 +090056 [ -n "${read_modorder}" ] && sed 's/ko$/usyms/' modules.order | xargs cat
Masahiro Yamadaa6aaeb82021-02-26 15:25:48 +090057 echo "$needed_symbols"
58 [ -n "$ksym_wl" ] && cat "$ksym_wl"
59} | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' |
Masahiro Yamada29500f12021-02-11 15:14:16 +090060# Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry
61# point addresses.
62sed -e 's/^\.//' |
Quentin Perretcd195bc2020-02-28 17:20:14 +000063sort -u |
Sami Tolvanen2a2b8762022-06-16 19:57:59 +000064# Ignore __this_module. It's not an exported symbol, and will be resolved
65# when the final .ko's are linked.
66grep -v '^__this_module$' |
Quentin Perretcd195bc2020-02-28 17:20:14 +000067sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"