Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the gcc executable stack size?

I have large Boost/Spirit metaprogram that is blowing gcc's stack when I try to compile it.

How can I increase gcc's stack size, so I can compile this program?

Note: There's no infinite recursion going on, but there is enough incidental recursion to exhaust gcc's stack.

like image 538
Jeff Leonard Avatar asked Jul 21 '09 00:07

Jeff Leonard


People also ask

How do you increase stack?

You may need to increase the stack size if your program gets stack-overflow messages at runtime. You can also set the stack size by: Using the /STACK linker option. For more information, see /STACK (Stack allocations).

Can stack size increase?

One cannot increase the stack size.


2 Answers

On Linux, you can expand the stack size in /etc/security/limits.conf.

You can check your current stack size by using

$ ulimit -s
8192

Then expand the stack to be double than that:

youruser    soft    stack    16384

And then relog.

This will increase stack size for all executable you're running, not just GCC's.

like image 54
LiraNuna Avatar answered Oct 11 '22 07:10

LiraNuna


I use that in my compiler script:

CFLAGS += -Wl,--stack,10485760

like image 29
Tanguy Avatar answered Oct 11 '22 08:10

Tanguy