Skip to content

Commit

Permalink
plugins/Makefile: use files to avoid hitting ARG_MAX during build
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MatthewCroughan committed Dec 17, 2024
1 parent e4abb1c commit 6c8489f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)/$<)"
Expand Down

0 comments on commit 6c8489f

Please sign in to comment.