How to increase the gcc executable stack size?
Asked Answered
C

3

15

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.

Cryptocrystalline answered 21/7, 2009 at 0:56 Comment(2)
I'm curious - what are you working on? Having your metaprograms blow the stack on the compiler is quite a feat.Elnaelnar
I'm working on a DSL for real-time event analysis in a distributed rules engine.Cryptocrystalline
D
15

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.

Dividend answered 21/7, 2009 at 1:1 Comment(2)
If it's a soft-limit, it can be increased without re-logging in by entering ulimit -s <limit>. This only applies for the current shell of course.Sprain
I just used some very big value: sourav soft stack 2000000. Then I was unable to launch apps like chromium and falkon and edge browsers on Linux! They were all writing 10 GB to my SSD when I launched them...Maricruzmaridel
T
2

I use that in my compiler script:

CFLAGS += -Wl,--stack,10485760

Thermae answered 25/3, 2015 at 5:4 Comment(0)
Z
0

The stack size can be configured during linking. You should look at details regarding the linker scripts. That will only change the stack size for your single programme.

Zonazonal answered 21/7, 2009 at 1:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.