Skip to content

Commit 7d32358

Browse files
committed
kbuild: avoid split lines in .mod files
"xargs echo" is not a safe way to remove line breaks because the input may exceed the command line limit and xargs may break it up into multiple invocations of echo. This should never happen because scripts/gen_autoksyms.sh expects all undefined symbols are placed in the second line of .mod files. One possible way is to replace "xargs echo" with "sed ':x;N;$!bx;s/\n/ /g'" or something, but I rewrote the code by using awk because it is more readable. This issue was reported by Sami Tolvanen; in his Clang LTO patch set, $(multi-used-m) is no longer an ELF object, but a thin archive that contains LLVM bitcode files. llvm-nm prints out symbols for each archive member separately, which results a lot of dupications, in some places, beyond the system-defined limit. This problem must be fixed irrespective of LTO, and we must ensure zero possibility of having this issue. Link: https://lkml.org/lkml/2020/12/1/1658 Reported-by: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
1 parent d5750cd commit 7d32358

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

scripts/Makefile.build

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ objtool_dep = $(objtool_obj) \
252252
ifdef CONFIG_TRIM_UNUSED_KSYMS
253253
cmd_gen_ksymdeps = \
254254
$(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
255+
256+
# List module undefined symbols
257+
undefined_syms = $(NM) $< | $(AWK) '$$1 == "U" { printf("%s%s", x++ ? " " : "", $$2) }';
255258
endif
256259

257260
define rule_cc_o_c
@@ -271,21 +274,14 @@ define rule_as_o_S
271274
$(call cmd,modversions_S)
272275
endef
273276

274-
# List module undefined symbols (or empty line if not enabled)
275-
ifdef CONFIG_TRIM_UNUSED_KSYMS
276-
cmd_undef_syms = $(NM) $< | sed -n 's/^ *U //p' | xargs echo
277-
else
278-
cmd_undef_syms = echo
279-
endif
280-
281277
# Built-in and composite module parts
282278
$(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
283279
$(call if_changed_rule,cc_o_c)
284280
$(call cmd,force_checksrc)
285281

286282
cmd_mod = { \
287283
echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
288-
$(cmd_undef_syms); \
284+
$(undefined_syms) echo; \
289285
} > $@
290286

291287
$(obj)/%.mod: $(obj)/%.o FORCE

0 commit comments

Comments
 (0)