blob: da320151e7c39cd900dabac81c0ab0202c500bfb [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
5# as recorded on the second line of *.mod files and the user-provided symbol
6# whitelist.
7
8set -e
9
10output_file="$1"
11
12# Use "make V=1" to debug this script.
13case "$KBUILD_VERBOSE" in
14*1*)
15 set -x
16 ;;
17esac
18
19# We need access to CONFIG_ symbols
20. include/config/auto.conf
21
Masahiro Yamadaa6aaeb82021-02-26 15:25:48 +090022needed_symbols=
23
24# Special case for modversions (see modpost.c)
25if [ -n "$CONFIG_MODVERSIONS" ]; then
26 needed_symbols="$needed_symbols module_layout"
27fi
28
29# With CONFIG_LTO_CLANG, LLVM bitcode has not yet been compiled into a binary
30# when the .mod files are generated, which means they don't yet contain
31# references to certain symbols that will be present in the final binaries.
32if [ -n "$CONFIG_LTO_CLANG" ]; then
33 # intrinsic functions
34 needed_symbols="$needed_symbols memcpy memmove memset"
35 # ftrace
36 needed_symbols="$needed_symbols _mcount"
37 # stack protector symbols
38 needed_symbols="$needed_symbols __stack_chk_fail __stack_chk_guard"
39fi
40
41ksym_wl=
Quentin Perretcd195bc2020-02-28 17:20:14 +000042if [ -n "$CONFIG_UNUSED_KSYMS_WHITELIST" ]; then
43 # Use 'eval' to expand the whitelist path and check if it is relative
44 eval ksym_wl="$CONFIG_UNUSED_KSYMS_WHITELIST"
45 [ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl"
46 if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then
47 echo "ERROR: '$ksym_wl' whitelist file not found" >&2
48 exit 1
49 fi
50fi
51
52# Generate a new ksym list file with symbols needed by the current
53# set of modules.
54cat > "$output_file" << EOT
55/*
56 * Automatically generated file; DO NOT EDIT.
57 */
58
59EOT
60
Quentin Perret88694cf2020-02-28 17:20:15 +000061[ -f modules.order ] && modlist=modules.order || modlist=/dev/null
Masahiro Yamadaa6aaeb82021-02-26 15:25:48 +090062
63{
64 sed 's/ko$/mod/' $modlist | xargs -n1 sed -n -e '2p'
65 echo "$needed_symbols"
66 [ -n "$ksym_wl" ] && cat "$ksym_wl"
67} | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' |
Masahiro Yamada29500f12021-02-11 15:14:16 +090068# Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry
69# point addresses.
70sed -e 's/^\.//' |
Quentin Perretcd195bc2020-02-28 17:20:14 +000071sort -u |
72sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"