Skip to content

Commit cd968b9

Browse files
committed
kbuild: make built-in.a rule robust against too long argument error
Kbuild runs at the top of objtree instead of changing the working directory to subdirectories. I think this design is nice overall but some commands have a scalability issue. The build command of built-in.a is one of them whose length scales with: O(D * N) Here, D is the length of the directory path (i.e. $(obj)/ prefix), N is the number of objects in the Makefile, O() is the big O notation. The deeper directory the Makefile directory is located, the more easily it will hit the too long argument error. We can make it better. Trim the $(obj)/ by Make's builtin function, and restore it by a shell command (sed). With this, the command length scales with: O(D + N) 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 builtin (CONFIG_DRM_I915=y) and compare drivers/gpu/drm/i915/.built-in.a.cmd with/without this commit. 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 31cb50b commit cd968b9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

scripts/Makefile.build

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,14 @@ $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
377377
#
378378
# Rule to compile a set of .o files into one .a file (without symbol table)
379379
#
380+
# To make this rule robust against "Argument list too long" error,
381+
# remove $(obj)/ prefix, and restore it by a shell command.
380382

381383
quiet_cmd_ar_builtin = AR $@
382-
cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs)
384+
cmd_ar_builtin = rm -f $@; \
385+
echo $(patsubst $(obj)/%,%,$(real-prereqs)) | \
386+
sed -E 's:([^ ]+):$(obj)/\1:g' | \
387+
xargs $(AR) cDPrST $@
383388

384389
$(obj)/built-in.a: $(real-obj-y) FORCE
385390
$(call if_changed,ar_builtin)

0 commit comments

Comments
 (0)