gmake change the stack size limit

2019-08-06 02:29发布

问题:

If my current environment,

$ ulimit -s
10240

But if I run a process through gmake, the stack size is unlimited. For instance (the ;: is to make gmake use the shell to execute the command, otherwise it will try to find an executable by that name)

$ cat Makefile
default:
        ulimit -s; :
$ gmake
ulimit -s; :
unlimited
  • is it possible to get gmake not changing the limit?

  • if not, is it possible to reset the limit to what I want for all the rules without modifying them (while I may change the main Makefile, some rules comes from included files which are generated and changing the generation logic starts to bring its own problems).

Edit: @MadScientist learned me that it is a problem with 3.81 which is fixed in 3.82. But I'd still appreciate a work around.

回答1:

This sounds like https://savannah.gnu.org/bugs/?22010 fixed in GNU make 3.82.

If you can't update your version of GNU make (3.82 is, like, over 3 years old now...) and you can't backport the patch, you could try something like this (untested); create a shell script to modify the stack:

$ cat stacksh
#!/bin/sh
ulimit -s ...
exec /bin/sh "$@"

$ chmod 755 stacksh

Then in your makefile, reset SHELL to use your script:

SHELL := /path/to/stacksh

Now make will invoke your shell script to run commands, instead of /bin/sh



回答2:

That is a BUG, which is solved in 3.82, but 3.82 has other bugs.

It seems that make has a (very questionable, imho) only-every-4-years update policy. I guess most Linux distros will update their make not before late 2014.

I read this blog about a breaking bug in 3.82, which is fixed in this fork.