5

I bought a new windows 10 PC and installed WSL 2 using (as admin)

wsl --install 

This installed WSL 2 with Ubuntu 20.04 LTS. I then copied my files from the old PC which was using the same windows 10 pro OS and using WSL2 with Ubuntu 18.04.6 LTS.

Now, using the same exact Makefile on the same folder gives the error

 make[1]: execvp: /bin/bash: Argument list too long 
›cd /mnt/g/public_html/ ›cd my_notes/ ›cd solving_ODE/ ›cd current_version ›cd OUTPUT/ ›make -I$HOME all make: execvp: /bin/bash: Argument list too long make: *** [common.mk:761: all] Error 127 

Which when doing a search seems related to ARG_MAX. On the new PC

 >getconf ARG_MAX 4611686018427387903 

And on the old PC

 >getconf ARG_MAX 2097152 

Both PC's run the same OS (windows 10) and both are 64 bits.

Do I need to correct ARG_MAX on the new PC? The value above looks strange on the new PC.

fyi, on the new PC, Ubuntu says

>xargs --show-limits Your environment variables take up 2463 bytes POSIX upper limit on argument length (this system): 4611686018427383392 POSIX smallest allowable upper limit on argument length (all systems): 4096 Maximum length of command we could actually use: 4611686018427380929 Size of command buffer we are actually using: 131072 Maximum parallelism (--max-procs must be no greater): 2147483647 

The command that fails now in the Makefile is

DIRS = $(wildcard */.) 

Where it gets list of the folders in the current directory. I also tried

DIRS = ${shell find . -type d -print} 

Same error.

There are 8727 folders with long names. Same exact number of folder in the old PC as nothing changed. It seems the shell in Ubuntu 20.04 finds this too large.

The version of make on the new PC is GNU make 4.2.1 and on the old PC is GNU make 4.1. The version of Bash on new PC is GNU bash 5.0.16 and on the old PC is 4.4.20.

Why would the same exact Makefile fail now on Ubuntu 20.04 under windows 10 WSL2? Is it possible to modify the value of ARG_MAX using some configuration setting? Or what would be a way to change DIRS = $(wildcard */.) to something else in order to avoid this issue in the first place?

Fyi, there is a very similar question in makefile-argument-list-too-long-but-only-in-some-configurations with exactly same setup I have. But the question here is why the same makefile works on WSL2 with Ubuntu 18 and not with newer WSL2 with Ubuntu 20? All on same OS (windows 10 pro).

I will now install Virtual Box on windows 10 and install latest Ubuntu there and see if I get the same error or not. If not, then it must be how Microsoft builds Linux Ubuntu for their WSL?

Update

I found a workaround. I rewrote the Makefile to avoid this long argument processing. So instead of passing a very long list of directory names to process, (I use recursive make), now it does one directory name one by one in a loop. This made it work.

Still it is strange that on a newer WSL2 Ubuntu it will fail but not on older WSL2 Ubuntu. I had this Makefile this way for years now and never had a problem.

I am all set now. But this could be an issue with how Microsoft build the kernel Linux for Ubuntu 20.04. I do not know. But there does not seem to be a way to change ARG_MAX other than by recompiling Linux itself from sources it seems.

1 Answer 1

3

The make (v4.1) in Ubuntu 18 is patched to be able to handle longer arguments.  See patch file make-dfsg_4.1-9.1ubuntu1.diff.gz in https://packages.ubuntu.com/en/source/bionic/make-dfsg:

+ if (unixy_shell && line_len > MAX_ARG_STRLEN) + { + unsigned j; + memcpy (ap, eval_line, sizeof (eval_line) - 1); + ap += sizeof (eval_line) - 1; + for (j = 1; j <= 2 * line_len / (MAX_ARG_STRLEN - 2); j++) + ap += sprintf (ap, "\\$\\{%u\\}", j); + *ap++ = '\\'; + *ap++ = '"'; + *ap++ = ' '; + /* Copy only the first word of SHELL to $0. */ + for (p = shell; *p != '\0'; ++p) + { + if (isspace ((unsigned char)*p)) + break; + *ap++ = *p; + } + *ap++ = ' '; + } 

In Ubuntu 20, make is upgraded to v4.2.1, and this patch is no longer there.  You will have to optimize your Makefile to avoid long arguments.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.