Skip to content

Commit cd195bc

Browse files
Quentin Perretmasahir0y
authored andcommitted
kbuild: split adjust_autoksyms.sh in two parts
In order to prepare the ground for a build-time optimization, split adjust_autoksyms.sh into two scripts: one that generates autoksyms.h based on all currently available information (whitelist, and .mod files), and the other to inspect the diff between two versions of autoksyms.h and trigger appropriate rebuilds. Acked-by: Nicolas Pitre <nico@fluxnic.net> Tested-by: Matthias Maennich <maennich@google.com> Reviewed-by: Matthias Maennich <maennich@google.com> Signed-off-by: Quentin Perret <qperret@google.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 1518c63 commit cd195bc

2 files changed

Lines changed: 55 additions & 32 deletions

File tree

‎scripts/adjust_autoksyms.sh‎

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0-only
33

4-
# Script to create/update include/generated/autoksyms.h and dependency files
4+
# Script to update include/generated/autoksyms.h and dependency files
55
#
66
# Copyright: (C) 2016 Linaro Limited
77
# Created by: Nicolas Pitre, January 2016
88
#
99

10-
# Create/update the include/generated/autoksyms.h file from the list
11-
# of all module's needed symbols as recorded on the second line of *.mod files.
10+
# Update the include/generated/autoksyms.h file.
1211
#
1312
# For each symbol being added or removed, the corresponding dependency
1413
# file's timestamp is updated to force a rebuild of the affected source
@@ -38,35 +37,8 @@ esac
3837
# We need access to CONFIG_ symbols
3938
. include/config/auto.conf
4039

41-
ksym_wl=/dev/null
42-
if [ -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
50-
fi
51-
52-
# Generate a new ksym list file with symbols needed by the current
53-
# set of modules.
54-
cat > "$new_ksyms_file" << EOT
55-
/*
56-
* Automatically generated file; DO NOT EDIT.
57-
*/
58-
59-
EOT
60-
sed 's/ko$/mod/' modules.order |
61-
xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- |
62-
cat - "$ksym_wl" |
63-
sort -u |
64-
sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$new_ksyms_file"
65-
66-
# Special case for modversions (see modpost.c)
67-
if [ -n "$CONFIG_MODVERSIONS" ]; then
68-
echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
69-
fi
40+
# Generate a new symbol list file
41+
$CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh "$new_ksyms_file"
7042

7143
# Extract changes between old and new list and touch corresponding
7244
# dependency files.

‎scripts/gen_autoksyms.sh‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
19+
# We need access to CONFIG_ symbols
20+
. include/config/auto.conf
21+
22+
ksym_wl=/dev/null
23+
if [ -n "$CONFIG_UNUSED_KSYMS_WHITELIST" ]; then
24+
# Use 'eval' to expand the whitelist path and check if it is relative
25+
eval ksym_wl="$CONFIG_UNUSED_KSYMS_WHITELIST"
26+
[ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl"
27+
if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then
28+
echo "ERROR: '$ksym_wl' whitelist file not found" >&2
29+
exit 1
30+
fi
31+
fi
32+
33+
# Generate a new ksym list file with symbols needed by the current
34+
# set of modules.
35+
cat > "$output_file" << EOT
36+
/*
37+
* Automatically generated file; DO NOT EDIT.
38+
*/
39+
40+
EOT
41+
42+
sed 's/ko$/mod/' modules.order |
43+
xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- |
44+
cat - "$ksym_wl" |
45+
sort -u |
46+
sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"
47+
48+
# Special case for modversions (see modpost.c)
49+
if [ -n "$CONFIG_MODVERSIONS" ]; then
50+
echo "#define __KSYM_module_layout 1" >> "$output_file"
51+
fi

0 commit comments

Comments
 (0)