[PATCH] perf build: Avoid argument list too long in orphan pruning

From: cp0613

Date: Fri Mar 13 2026 - 03:25:17 EST


From: Chen Pei <cp0613@xxxxxxxxxxxxxxxxx>

When the output directory contains a large number of orphaned files with
deep file paths, directly passing the entire ORPHAN_FILES list to the
execve command will exceed the system's parameter length limit (it should
be MAX_ARG_STRLEN), causing "argument list too long" error during build.
See below:

make[6]: execvp: /bin/sh: Argument list too long
make[6]: *** [pmu-events/Build:217: prune_orphans] Error 127
make[6]: *** Waiting for unfinished jobs....

Fix this by using GNU Make's $(file ...) function to write the orphan file
list to a temporary file, then use xargs to read from the file and remove
the orphan files. The temporary file is deleted after pruning completes.

This method avoids the argument length limitation since $(file ...) writes
directly without spawning a shell process with command-line arguments.

Signed-off-by: Chen Pei <cp0613@xxxxxxxxxxxxxxxxx>
---
tools/perf/pmu-events/Build | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build
index 63c65788d442..ec5bf89ddfe1 100644
--- a/tools/perf/pmu-events/Build
+++ b/tools/perf/pmu-events/Build
@@ -209,12 +209,17 @@ endif
ifneq ($(strip $(ORPHAN_FILES)),)
.PHONY: prune_orphans

+# Store ORPHAN_FILES in a file to avoid argument list too long errors
+ORPHAN_LIST_FILE := $(OUTPUT)pmu-events/.orphan_list
+$(file >$(ORPHAN_LIST_FILE),$(ORPHAN_FILES))
+
# Message for $(call echo-cmd,rm). Generally cleaning files isn't part
# of a build step.
quiet_cmd_rm = RM $^

-prune_orphans: $(ORPHAN_FILES)
- $(Q)$(call echo-cmd,rm)rm -f $^
+prune_orphans: $(ORPHAN_LIST_FILE)
+ $(Q)$(call echo-cmd,rm)cat $^ | xargs rm -f
+ $(Q)rm -f $(ORPHAN_LIST_FILE)

JEVENTS_DEPS += prune_orphans
endif
--
2.50.1