Skip to content

Commit a6aaeb8

Browse files
committed
kbuild: fix UNUSED_KSYMS_WHITELIST for Clang LTO
Commit fbe078d ("kbuild: lto: add a default list of used symbols") does not work as expected if the .config file has already specified CONFIG_UNUSED_KSYMS_WHITELIST="my/own/white/list" before enabling CONFIG_LTO_CLANG. So, the user-supplied whitelist and LTO-specific white list must be independent of each other. I refactored the shell script so CONFIG_MODVERSIONS and CONFIG_CLANG_LTO handle whitelists in the same way. Fixes: fbe078d ("kbuild: lto: add a default list of used symbols") Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
1 parent da83616 commit a6aaeb8

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

init/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,6 @@ config TRIM_UNUSED_KSYMS
22832283
config UNUSED_KSYMS_WHITELIST
22842284
string "Whitelist of symbols to keep in ksymtab"
22852285
depends on TRIM_UNUSED_KSYMS
2286-
default "scripts/lto-used-symbollist.txt" if LTO_CLANG
22872286
help
22882287
By default, all unused exported symbols will be un-exported from the
22892288
build when TRIM_UNUSED_KSYMS is selected.

scripts/gen_autoksyms.sh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,26 @@ esac
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"
@@ -40,16 +59,14 @@ cat > "$output_file" << EOT
4059
EOT
4160

4261
[ -f modules.order ] && modlist=modules.order || modlist=/dev/null
43-
sed 's/ko$/mod/' $modlist |
44-
xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- |
45-
cat - "$ksym_wl" |
62+
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' |
4668
# Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry
4769
# point addresses.
4870
sed -e 's/^\.//' |
4971
sort -u |
5072
sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"
51-
52-
# Special case for modversions (see modpost.c)
53-
if [ -n "$CONFIG_MODVERSIONS" ]; then
54-
echo "#define __KSYM_module_layout 1" >> "$output_file"
55-
fi

scripts/lto-used-symbollist.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)