Skip to content

Commit 0e5851b

Browse files
masahir0ytoddkjos
authored andcommittedMay 10, 2022
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 7d32358 ("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>
1 parent fe25d38 commit 0e5851b

File tree

6 files changed

+25
-26
lines changed

6 files changed

+25
-26
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*.symversions
4646
*.tab.[ch]
4747
*.tar
48+
*.usyms
4849
*.xz
4950
*.zst
5051
Module.symvers

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ clean: $(clean-dirs)
19261926
-o -name '*.ko.*' \
19271927
-o -name '*.dtb' -o -name '*.dtbo' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
19281928
-o -name '*.dwo' -o -name '*.lst' \
1929-
-o -name '*.su' -o -name '*.mod' \
1929+
-o -name '*.su' -o -name '*.mod' -o -name '*.usyms' \
19301930
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
19311931
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
19321932
-o -name '*.asn1.[ch]' \

‎scripts/Makefile.build

+9-8
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ ifdef need-builtin
8686
targets-for-builtin += $(obj)/built-in.a
8787
endif
8888

89-
targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
89+
targets-for-modules := $(foreach x, mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \
90+
$(patsubst %.o, %.$x, $(filter %.o, $(obj-m))))
9091

9192
ifdef CONFIG_LTO_CLANG
9293
targets-for-modules += $(patsubst %.o, %.lto.o, $(filter %.o, $(obj-m)))
@@ -249,9 +250,6 @@ objtool_dep = $(objtool_obj) \
249250
ifdef CONFIG_TRIM_UNUSED_KSYMS
250251
cmd_gen_ksymdeps = \
251252
$(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
252-
253-
# List module undefined symbols
254-
undefined_syms = $(NM) $< | $(AWK) '$$1 == "U" { printf("%s%s", x++ ? " " : "", $$2) }';
255253
endif
256254

257255
define rule_cc_o_c
@@ -298,14 +296,17 @@ $(obj)/%.lto.o: $(obj)/%.o FORCE
298296
$(call if_changed,cc_lto_link_modules)
299297
endif
300298

301-
cmd_mod = { \
302-
echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)); \
303-
$(undefined_syms) echo; \
304-
} > $@
299+
cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) > $@
305300

306301
$(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE
307302
$(call if_changed,mod)
308303

304+
# List module undefined symbols
305+
cmd_undefined_syms = $(NM) $< | sed -n 's/^ *U //p' > $@
306+
307+
$(obj)/%.usyms: $(obj)/%$(mod-prelink-ext).o FORCE
308+
$(call if_changed,undefined_syms)
309+
309310
quiet_cmd_cc_lst_c = MKLST $@
310311
cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
311312
$(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \

‎scripts/adjust_autoksyms.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ case "$KBUILD_VERBOSE" in
3535
esac
3636

3737
# Generate a new symbol list file
38-
$CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh "$new_ksyms_file"
38+
$CONFIG_SHELL $srctree/scripts/gen_autoksyms.sh --modorder "$new_ksyms_file"
3939

4040
# Extract changes between old and new list and touch corresponding
4141
# dependency files.

‎scripts/gen_autoksyms.sh

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
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 second line of *.mod files and the user-provided symbol
6-
# whitelist.
5+
# as recorded in *.usyms files and the user-provided symbol whitelist.
76

87
set -e
98

10-
output_file="$1"
11-
129
# Use "make V=1" to debug this script.
1310
case "$KBUILD_VERBOSE" in
1411
*1*)
@@ -19,6 +16,15 @@ esac
1916
# We need access to CONFIG_ symbols
2017
. include/config/auto.conf
2118

19+
read_modorder=
20+
21+
if [ "$1" = --modorder ]; then
22+
shift
23+
read_modorder=1
24+
fi
25+
26+
output_file="$1"
27+
2228
needed_symbols=
2329

2430
# Special case for modversions (see modpost.c)
@@ -46,10 +52,8 @@ cat > "$output_file" << EOT
4652
4753
EOT
4854

49-
[ -f modules.order ] && modlist=modules.order || modlist=/dev/null
50-
5155
{
52-
sed 's/ko$/mod/' $modlist | xargs -n1 sed -n -e '2p'
56+
[ -n "${read_modorder}" ] && sed 's/ko$/usyms/' modules.order | xargs cat
5357
echo "$needed_symbols"
5458
[ -n "$ksym_wl" ] && cat "$ksym_wl"
5559
} | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' |

‎scripts/mod/sumversion.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
387387
/* Calc and record src checksum. */
388388
void get_src_version(const char *modname, char sum[], unsigned sumlen)
389389
{
390-
char *buf, *pos, *firstline;
390+
char *buf;
391391
struct md4_ctx md;
392392
char *fname;
393393
char filelist[PATH_MAX + 1];
@@ -397,15 +397,8 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
397397

398398
buf = read_text_file(filelist);
399399

400-
pos = buf;
401-
firstline = get_line(&pos);
402-
if (!firstline) {
403-
warn("bad ending versions file for %s\n", modname);
404-
goto free;
405-
}
406-
407400
md4_init(&md);
408-
while ((fname = strsep(&firstline, " "))) {
401+
while ((fname = strsep(&buf, " \n"))) {
409402
if (!*fname)
410403
continue;
411404
if (!(is_static_library(fname)) &&

0 commit comments

Comments
 (0)
Please sign in to comment.