Skip to content

Commit c6031b1

Browse files
committed
kbuild: make *.mod rule robust against too long argument error
Like built-in.a, the command length of the *.mod rule scales with the depth of the directory times the number of objects in the Makefile. Add $(obj)/ by the shell command (awk) instead of by Make's builtin function. In-tree modules still have some room to the limit (ARG_MAX=2097152), but this is more future-proof for big modules in a deep directory. For example, you can build i915 as a module (CONFIG_DRM_I915=m) and compare drivers/gpu/drm/i915/.i915.mod.cmd with/without this commit. The issue is more critical for external modules because the M= path can be very long as Jeff Johnson reported before [1]. [1] https://lore.kernel.org/linux-kbuild/[email protected]/ Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Tested-by: Sedat Dilek <[email protected]> # LLVM-14 (x86-64)
1 parent cd968b9 commit c6031b1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

scripts/Makefile.build

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
275275
$(call if_changed_rule,cc_o_c)
276276
$(call cmd,force_checksrc)
277277

278-
cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \
279-
$(AWK) -v RS='( |\n)' '!x[$$0]++' > $@
278+
# To make this rule robust against "Argument list too long" error,
279+
# ensure to add $(obj)/ prefix by a shell command.
280+
cmd_mod = echo $(call real-search, $*.o, .o, -objs -y -m) | \
281+
$(AWK) -v RS='( |\n)' '!x[$$0]++ { print("$(obj)/"$$0) }' > $@
280282

281283
$(obj)/%.mod: FORCE
282284
$(call if_changed,mod)

0 commit comments

Comments
 (0)