From 6c8489f4c539042b4b59b04c612ed940526f21e5 Mon Sep 17 00:00:00 2001 From: matthewcroughan Date: Tue, 17 Dec 2024 17:48:13 +0000 Subject: [PATCH] plugins/Makefile: use files to avoid hitting ARG_MAX during build When adding more modules to the build, ar will be passed far more .o files as arguments on the command line than the limits specified by most host kernels by default, which will cause the build to fail with "/bin/bash: Argument list too long" Using xargs can show you what these limits are on POSIX systems, e.g: $ xargs --show-limits Your environment variables take up 6774 bytes POSIX upper limit on argument length (this system): 2088330 POSIX smallest allowable upper limit on argument length (all systems): 4096 Maximum length of command we could actually use: 2081556 Size of command buffer we are actually using: 131072 Maximum parallelism (--max-procs must be no greater): 2147483647 --- plugins/Makefile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/Makefile b/plugins/Makefile index 58bd3006..d92784d2 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -1438,6 +1438,7 @@ endif clean: rm -f *.a + rm -f plugin_objs_list.txt mini_plugin_objs_list.txt rm -rf $(BUILD_DIR) rm -rf surgext/build @@ -2060,12 +2061,18 @@ custom_per_file_names = -D${1}=${2}_${1} plugins$(TARGET_SUFFIX).a: $(PLUGIN_OBJS) @echo "Creating $@" $(SILENT)rm -f $@ - $(SILENT)$(AR) crs $@ $^ + # Write object file list to a response file and use it in the `ar` command + # to avoid hitting stack limits when using large number of modules + $(SILENT)$(file > plugin_objs_list.txt,$(PLUGIN_OBJS)) + $(SILENT)$(AR) crs $@ @plugin_objs_list.txt + $(SILENT)rm -f plugin_objs_list.txt plugins-mini$(TARGET_SUFFIX).a: $(MINIPLUGIN_OBJS) @echo "Creating $@" $(SILENT)rm -f $@ - $(SILENT)$(AR) crs $@ $^ + $(SILENT)$(file > mini_plugin_objs_list.txt,$(MINIPLUGIN_OBJS)) + $(SILENT)$(AR) crs $@ @mini_plugin_objs_list.txt + $(SILENT)rm -f mini_plugin_objs_list.txt $(BUILD_DIR)/%.bin.c: % ../deps/res2c.py -@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)"