]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tools build: Make in-target rule robust against too long argument error
authorChangqing Li <changqing.li@windriver.com>
Mon, 28 Jul 2025 09:31:53 +0000 (17:31 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 4 Mar 2026 14:21:48 +0000 (11:21 -0300)
The command length of in-target scales with the depth of the directory
times the number of objects in the Makefile.

When there are many objects, and O=[absolute_path] is set, and the
absolute_path is relatively long.

It is possible that this line "$(call if_changed,$(host)ld_multi)" will
report error: "make[4]: /bin/sh: Argument list too long"

For example, build perf tools with O=/long/output/path

Like built-in.a and *.mod rules in scripts/Makefile.build, add
$(objpredix)/ by the shell command instead of by Make's builtin
function.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Changqing Li <changqing.li@windriver.com>
Cc: Charlie Jenkins <charlie@rivosinc.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/build/Makefile.build

index 60e65870eae145b33b80b972d5b3cc2f4bfcef74..ad69efdd4e85c055410f0d9b30375960a0603dc2 100644 (file)
@@ -70,11 +70,13 @@ quiet_cmd_gen = GEN     $@
 # If there's nothing to link, create empty $@ object.
 quiet_cmd_ld_multi = LD      $@
       cmd_ld_multi = $(if $(strip $(obj-y)),\
-                     $(LD) -r -o $@  $(filter $(obj-y),$^),rm -f $@; $(AR) rcs $@)
+                     printf "$(objprefix)%s " $(patsubst $(objprefix)%,%,$(filter $(obj-y),$^)) | \
+                     xargs $(LD) -r -o $@,rm -f $@; $(AR) rcs $@)
 
 quiet_cmd_host_ld_multi = HOSTLD  $@
       cmd_host_ld_multi = $(if $(strip $(obj-y)),\
-                          $(HOSTLD) -r -o $@  $(filter $(obj-y),$^),rm -f $@; $(HOSTAR) rcs $@)
+                          printf "$(objprefix)%s " $(patsubst $(objprefix)%,%,$(filter $(obj-y),$^)) | \
+                          xargs $(HOSTLD) -r -o $@,rm -f $@; $(HOSTAR) rcs $@)
 
 rust_common_cmd = \
        $(RUSTC) $(rust_flags) \