tools/build: Let link command read option from file
cover tools/build: Let link command read option from file
From: Changqing Li <[email protected]>
Hi, Dear Maintainers
I am building perf with yocto project, and we don't want to put compile object files to source folder, so pass O=xxx;
When we use a relatively long path like this:
O=/buildarea1/wrlinux-10.25/build/Virtualization/customized-WRLINUX1025_Nightly_Linux_systemd/250609-044304/lxbuilds/Harcuvar_platform_up/intel-x86-64-preempt-rt-glibc-std/wrlinux/build/tmp/work/intel_x86_64-wrs-linux/perf/1.0/perf-1.0
perf will compile failed with error:
| make[4]: /bin/sh: Argument list too long
| make[4]: *** [.../perf/1.0/perf-1.0/tools/build/Makefile.build:156: .../perf/1.0/perf-1.0/util/perf-in.o] Error 127
The error is from this line: "$(call if_changed,$(host)ld_multi)", Since perf have many .o, and when above long O passed, if_changed will evoke sh with long argument list.
So I try to fix this issue by this RFC patch. This is the first time I touch this part, so the patch may not perfect, please help to review and give your comments, thanks.
Changqing Li (1):
tools/build: Let link command read option from file
tools/build/Makefile.build | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/1 tools/build: Let link command read option from file
From: Changqing Li <[email protected]>
ld_multi will link multiple objects, 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"
So make the ld command read option from file to fix above error. In order to convenient debug, write the file content in dot-target.cmd as comments.
--- tools/build/Makefile.build | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/build/Makefile.build +7 -2
@@ -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 $@) + $(LD) -r -o $@ @[email protected],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 $@) + $(HOSTLD) -r -o $@ @[email protected],rm -f $@; $(HOSTAR) rcs $@) + +output_ld_multi_dotin = $(if $(quiet),,@printf "# %s:\n# " [email protected] >> $(dot-target).cmd;cat [email protected] >> $(dot-target).cmd) ifneq ($(filter $(obj),$(hostprogs)),) host = host_
@@ -145,7 +147,10 @@ $(sort $(subdir-obj-y)): $(subdir-y) ; $(in-target): $(obj-y) $(test-y) FORCE $(call rule_mkdir) + $(file >[email protected],$(filter $(obj-y),$^)) $(call if_changed,$(host)ld_multi) + $(if $(strip $(any-prereq) $(arg-check)), $(output_ld_multi_dotin)) + @rm [email protected] __build: $(in-target) @:
Signature · 1 line
2.34.1
Quoted 9 lines · On Mon, Jul 21, 2025 at 11:13 PM <[email protected]> wrote:
From: Changqing Li <[email protected]>
ld_multiwill link multiple objects, when there are many objects, and O=[absolute_path] is set, and theabsolute_pathis 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"
Quoted 5 lines
So make the ld command read option from file to fix above error. In order to convenient debug, write the file content in dot-target.cmd as comments.
Signed-off-by Changqing Li <[email protected]>
Hi Changqing,
I believe your change makes sense. I notice that the regular kernel build has had to work around this problem too:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/Makefile.build#n290
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/Makefile.build#n463
but in those workarounds the need for an extra .in file isn't necessary. Would such a change be possible here and avoid the need for cleaning up an extra file?
Thanks,
Ian
Quoted 38 lines
--- tools/build/Makefile.build | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)tools/build/Makefile.build +7
-3@@ -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 $@) + $(LD) -r -o $@ @[email protected],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 $@) + $(HOSTLD) -r -o $@ @[email protected],rm -f $@; $(HOSTAR) rcs $@) + +output_ld_multi_dotin = $(if $(quiet),,@printf "# %s:\n# " [email protected] >> $(dot-target).cmd;cat [email protected] >> $(dot-target).cmd) ifneq ($(filter $(obj),$(hostprogs)),) host = host_@@ -145,7 +147,10 @@ $(sort $(subdir-obj-y)): $(subdir-y) ; $(in-target): $(obj-y) $(test-y) FORCE $(call rule_mkdir) + $(file >[email protected],$(filter $(obj-y),$^)) $(call if_changed,$(host)ld_multi) + $(if $(strip $(any-prereq) $(arg-check)), $(output_ld_multi_dotin)) + @rm [email protected] __build: $(in-target) @: --2.34.1
Quoted 27 lines · Ian Rogers
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 8 lines · On Mon, Jul 21, 2025 at 11:13 PM <[email protected]> wrote:
From: Changqing Li <[email protected]>
ld_multiwill link multiple objects, when there are many objects, and O=[absolute_path] is set, and theabsolute_pathis 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"Quoted 5 lines
So make the ld command read option from file to fix above error. In order to convenient debug, write the file content in dot-target.cmd as comments.
Signed-off-by Changqing Li <[email protected]>Hi Changqing,
I believe your change makes sense. I notice that the regular kernel build has had to work around this problem too:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/Makefile.build#n290
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/Makefile.build#n463
but in those workarounds the need for an extra .in file isn't necessary. Would such a change be possible here and avoid the need for cleaning up an extra file?
Quoted 2 lines
Thanks,
Ian
Hi, Ian
Thanks for your help. I have resend a patch as what you suggested, could you help to review it?
subject: "tools/build: make in-target rule robust against too long argument error"
Regards
changqing
Quoted 38 lines
Quoted 38 lines
--- tools/build/Makefile.build | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)tools/build/Makefile.build +7
-3@@ -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 $@) + $(LD) -r -o $@ @[email protected],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 $@) + $(HOSTLD) -r -o $@ @[email protected],rm -f $@; $(HOSTAR) rcs $@) + +output_ld_multi_dotin = $(if $(quiet),,@printf "# %s:\n# " [email protected] >> $(dot-target).cmd;cat [email protected] >> $(dot-target).cmd) ifneq ($(filter $(obj),$(hostprogs)),) host = host_@@ -145,7 +147,10 @@ $(sort $(subdir-obj-y)): $(subdir-y) ; $(in-target): $(obj-y) $(test-y) FORCE $(call rule_mkdir) + $(file >[email protected],$(filter $(obj-y),$^)) $(call if_changed,$(host)ld_multi) + $(if $(strip $(any-prereq) $(arg-check)), $(output_ld_multi_dotin)) + @rm [email protected] __build: $(in-target) @: --2.34.1