• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 in *.usyms files and the user-provided symbol whitelist.
6
7set -e
8
9# 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
19read_modorder=
20
21if [ "$1" = --modorder ]; then
22	shift
23	read_modorder=1
24fi
25
26output_file="$1"
27
28needed_symbols=
29
30# Special case for modversions (see modpost.c)
31if [ -n "$CONFIG_MODVERSIONS" ]; then
32	needed_symbols="$needed_symbols module_layout"
33fi
34
35ksym_wl=
36if [ -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"
39	[ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl"
40	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
55{
56	[ -n "${read_modorder}" ] && sed 's/ko$/usyms/' modules.order | xargs cat
57	echo "$needed_symbols"
58	[ -n "$ksym_wl" ] && cat "$ksym_wl"
59} | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' |
60# Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry
61# point addresses.
62sed -e 's/^\.//' |
63sort -u |
64# 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$' |
67sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"
68