Skip to content

Commit 6c8489f

Browse files
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
1 parent e4abb1c commit 6c8489f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

plugins/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ endif
14381438

14391439
clean:
14401440
rm -f *.a
1441+
rm -f plugin_objs_list.txt mini_plugin_objs_list.txt
14411442
rm -rf $(BUILD_DIR)
14421443
rm -rf surgext/build
14431444

@@ -2060,12 +2061,18 @@ custom_per_file_names = -D${1}=${2}_${1}
20602061
plugins$(TARGET_SUFFIX).a: $(PLUGIN_OBJS)
20612062
@echo "Creating $@"
20622063
$(SILENT)rm -f $@
2063-
$(SILENT)$(AR) crs $@ $^
2064+
# Write object file list to a response file and use it in the `ar` command
2065+
# to avoid hitting stack limits when using large number of modules
2066+
$(SILENT)$(file > plugin_objs_list.txt,$(PLUGIN_OBJS))
2067+
$(SILENT)$(AR) crs $@ @plugin_objs_list.txt
2068+
$(SILENT)rm -f plugin_objs_list.txt
20642069

20652070
plugins-mini$(TARGET_SUFFIX).a: $(MINIPLUGIN_OBJS)
20662071
@echo "Creating $@"
20672072
$(SILENT)rm -f $@
2068-
$(SILENT)$(AR) crs $@ $^
2073+
$(SILENT)$(file > mini_plugin_objs_list.txt,$(MINIPLUGIN_OBJS))
2074+
$(SILENT)$(AR) crs $@ @mini_plugin_objs_list.txt
2075+
$(SILENT)rm -f mini_plugin_objs_list.txt
20692076

20702077
$(BUILD_DIR)/%.bin.c: % ../deps/res2c.py
20712078
-@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)"

0 commit comments

Comments
 (0)