public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/build: make in-target rule robust against too long argument error
@ 2025-07-28  9:31 changqing.li
  2025-08-18 20:38 ` Ian Rogers
  0 siblings, 1 reply; 7+ messages in thread
From: changqing.li @ 2025-07-28  9:31 UTC (permalink / raw)
  To: namhyung, james.clark, irogers, charlie, linux-kernel; +Cc: changqing.li

From: Changqing Li <changqing.li@windriver.com>

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 possile 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.

Signed-off-by: Changqing Li <changqing.li@windriver.com>
---
 tools/build/Makefile.build | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build
index 3584ff308607..39066a3ef2fc 100644
--- a/tools/build/Makefile.build
+++ b/tools/build/Makefile.build
@@ -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 $@)
 
 ifneq ($(filter $(obj),$(hostprogs)),)
   host = host_
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-04 14:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-28  9:31 [PATCH] tools/build: make in-target rule robust against too long argument error changqing.li
2025-08-18 20:38 ` Ian Rogers
2025-08-19  3:01   ` Changqing Li
2025-10-28  2:15     ` Changqing Li
2026-03-03 22:33       ` Ian Rogers
2026-03-04  2:35         ` Changqing Li
2026-03-04 14:13         ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox