FROMGIT: kbuild: split the second line of *.mod into *.usyms

The *.mod files have two lines; the first line lists the member objects
of the module, and the second line, if CONFIG_TRIM_UNUSED_KSYMS=y, lists
the undefined symbols.

Currently, we generate *.mod after constructing composite modules,
otherwise, we cannot compute the second line. No prerequisite is
required to print the first line.

They are orthogonal. Splitting them into separate commands will ease
further cleanups.

This commit splits the list of undefined symbols out to *.usyms files.

Previously, the list of undefined symbols ended up with a very long
line, but now it has one symbol per line.

Use sed like we did before commit 7d32358be8 ("kbuild: avoid split
lines in .mod files").

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>

Bug: 175420575
(cherry picked from commit 2f6b64906adf99b4c5ea9356df793766d290cfb4
 https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git kbuild)
Change-Id: Ic801d2bf085aff6e50d15d196c43da4df3aa88c8
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
This commit is contained in:
Masahiro Yamada
2022-04-07 00:30:20 +09:00
committed by Todd Kjos
parent fe25d38e6a
commit 0e5851bf31
6 changed files with 25 additions and 26 deletions

1
.gitignore vendored
View File

@@ -45,6 +45,7 @@
*.symversions *.symversions
*.tab.[ch] *.tab.[ch]
*.tar *.tar
*.usyms
*.xz *.xz
*.zst *.zst
Module.symvers Module.symvers

View File

@@ -1926,7 +1926,7 @@ clean: $(clean-dirs)
-o -name '*.ko.*' \ -o -name '*.ko.*' \
-o -name '*.dtb' -o -name '*.dtbo' -o -name '*.dtb.S' -o -name '*.dt.yaml' \ -o -name '*.dtb' -o -name '*.dtbo' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
-o -name '*.dwo' -o -name '*.lst' \ -o -name '*.dwo' -o -name '*.lst' \
-o -name '*.su' -o -name '*.mod' \ -o -name '*.su' -o -name '*.mod' -o -name '*.usyms' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-o -name '*.lex.c' -o -name '*.tab.[ch]' \ -o -name '*.lex.c' -o -name '*.tab.[ch]' \
-o -name '*.asn1.[ch]' \ -o -name '*.asn1.[ch]' \

View File

@@ -86,7 +86,8 @@ ifdef need-builtin
targets-for-builtin += $(obj)/built-in.a targets-for-builtin += $(obj)/built-in.a
endif endif
targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) targets-for-modules := $(foreach x, mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \
$(patsubst %.o, %.$x, $(filter %.o, $(obj-m))))
ifdef CONFIG_LTO_CLANG ifdef CONFIG_LTO_CLANG
targets-for-modules += $(patsubst %.o, %.lto.o, $(filter %.o, $(obj-m))) targets-for-modules += $(patsubst %.o, %.lto.o, $(filter %.o, $(obj-m)))
@@ -249,9 +250,6 @@ objtool_dep = $(objtool_obj) \
ifdef CONFIG_TRIM_UNUSED_KSYMS ifdef CONFIG_TRIM_UNUSED_KSYMS
cmd_gen_ksymdeps = \ cmd_gen_ksymdeps = \
$(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
# List module undefined symbols
undefined_syms = $(NM) $< | $(AWK) '$$1 == "U" { printf("%s%s", x++ ? " " : "", $$2) }';
endif endif
define rule_cc_o_c define rule_cc_o_c
@@ -298,14 +296,17 @@ $(obj)/%.lto.o: $(obj)/%.o FORCE
$(call if_changed,cc_lto_link_modules) $(call if_changed,cc_lto_link_modules)
endif endif
cmd_mod = { \ cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) > $@
echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)); \
$(undefined_syms) echo; \
} > $@
$(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE
$(call if_changed,mod) $(call if_changed,mod)
# List module undefined symbols
cmd_undefined_syms = $(NM) $< | sed -n 's/^ *U //p' > $@
$(obj)/%.usyms: $(obj)/%$(mod-prelink-ext).o FORCE
$(call if_changed,undefined_syms)
quiet_cmd_cc_lst_c = MKLST $@ quiet_cmd_cc_lst_c = MKLST $@
cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
$(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \

View File

@@ -35,7 +35,7 @@ case "$KBUILD_VERBOSE" in
esac esac
# Generate a new symbol list file # Generate a new symbol list file
$CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh "$new_ksyms_file" $CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh --modorder "$new_ksyms_file"
# Extract changes between old and new list and touch corresponding # Extract changes between old and new list and touch corresponding
# dependency files. # dependency files.

View File

@@ -2,13 +2,10 @@
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-2.0-only
# Create an autoksyms.h header file from the list of all module's needed symbols # Create an autoksyms.h header file from the list of all module's needed symbols
# as recorded on the second line of *.mod files and the user-provided symbol # as recorded in *.usyms files and the user-provided symbol whitelist.
# whitelist.
set -e set -e
output_file="$1"
# Use "make V=1" to debug this script. # Use "make V=1" to debug this script.
case "$KBUILD_VERBOSE" in case "$KBUILD_VERBOSE" in
*1*) *1*)
@@ -19,6 +16,15 @@ esac
# We need access to CONFIG_ symbols # We need access to CONFIG_ symbols
. include/config/auto.conf . include/config/auto.conf
read_modorder=
if [ "$1" = --modorder ]; then
shift
read_modorder=1
fi
output_file="$1"
needed_symbols= needed_symbols=
# Special case for modversions (see modpost.c) # Special case for modversions (see modpost.c)
@@ -46,10 +52,8 @@ cat > "$output_file" << EOT
EOT EOT
[ -f modules.order ] && modlist=modules.order || modlist=/dev/null
{ {
sed 's/ko$/mod/' $modlist | xargs -n1 sed -n -e '2p' [ -n "${read_modorder}" ] && sed 's/ko$/usyms/' modules.order | xargs cat
echo "$needed_symbols" echo "$needed_symbols"
[ -n "$ksym_wl" ] && cat "$ksym_wl" [ -n "$ksym_wl" ] && cat "$ksym_wl"
} | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' | } | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' |

View File

@@ -387,7 +387,7 @@ out_file:
/* Calc and record src checksum. */ /* Calc and record src checksum. */
void get_src_version(const char *modname, char sum[], unsigned sumlen) void get_src_version(const char *modname, char sum[], unsigned sumlen)
{ {
char *buf, *pos, *firstline; char *buf;
struct md4_ctx md; struct md4_ctx md;
char *fname; char *fname;
char filelist[PATH_MAX + 1]; char filelist[PATH_MAX + 1];
@@ -397,15 +397,8 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
buf = read_text_file(filelist); buf = read_text_file(filelist);
pos = buf;
firstline = get_line(&pos);
if (!firstline) {
warn("bad ending versions file for %s\n", modname);
goto free;
}
md4_init(&md); md4_init(&md);
while ((fname = strsep(&firstline, " "))) { while ((fname = strsep(&buf, " \n"))) {
if (!*fname) if (!*fname)
continue; continue;
if (!(is_static_library(fname)) && if (!(is_static_library(fname)) &&