hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/scripts/gen_autoksyms.sh
....@@ -2,7 +2,7 @@
22 # SPDX-License-Identifier: GPL-2.0-only
33
44 # Create an autoksyms.h header file from the list of all module's needed symbols
5
-# as recorded on the third line of *.mod files and the user-provided symbol
5
+# as recorded on the second line of *.mod files and the user-provided symbol
66 # whitelist.
77
88 set -e
....@@ -19,7 +19,26 @@
1919 # We need access to CONFIG_ symbols
2020 . include/config/auto.conf
2121
22
-ksym_wl=/dev/null
22
+needed_symbols=
23
+
24
+# Special case for modversions (see modpost.c)
25
+if [ -n "$CONFIG_MODVERSIONS" ]; then
26
+ needed_symbols="$needed_symbols module_layout"
27
+fi
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.
32
+if [ -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"
39
+fi
40
+
41
+ksym_wl=
2342 if [ -n "$CONFIG_UNUSED_KSYMS_WHITELIST" ]; then
2443 # Use 'eval' to expand the whitelist path and check if it is relative
2544 eval ksym_wl="$CONFIG_UNUSED_KSYMS_WHITELIST"
....@@ -39,14 +58,15 @@
3958
4059 EOT
4160
42
-for mod in "$MODVERDIR"/*.mod; do
43
- [ -f "$mod" ] && sed -n -e '3{s/ /\n/g;/^$/!p;}' "$mod"
44
-done | cat - "$ksym_wl" | sort -u |
45
-while read sym; do
46
- echo "#define __KSYM_${sym} 1"
47
-done >> "$output_file"
61
+[ -f modules.order ] && modlist=modules.order || modlist=/dev/null
4862
49
-# Special case for modversions (see modpost.c)
50
-if [ -n "$CONFIG_MODVERSIONS" ]; then
51
- echo "#define __KSYM_module_layout 1" >> "$output_file"
52
-fi
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' |
68
+# Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry
69
+# point addresses.
70
+sed -e 's/^\.//' |
71
+sort -u |
72
+sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"