Is there a way to increase the stack size of a Windows application at compile/link time with GCC?
Asked
Active
Viewed 3.1k times
10
-
1Could any one explain me what does Increasing stack size mean? stack frame is portion occupied by a function on stack. and stack is decided by operating system right? How does `editbin` helps it? I'm confused! – claws Aug 04 '10 at 19:27
4 Answers
22
IIRC, In GCC you can provide the --stack,[bytes] parameter to ld.
E.g.
gcc -Wl,--stack,16777216 -o file.exe file.c
To have a stack of 16MiB, I think that the default size is 8MiB.

Jonas Engström
- 5,015
- 3
- 37
- 36
-
This is what I was originally looking for. Unfortunately, I haven't had any luck with this on Windows. Have you? – Landon Oct 02 '08 at 00:56
-
4+1 This does indeed work when I tried it on gcc 4.5.2. Without this switch, compiled programs start segfaulting with static array sizes ~500k. After applying this switch, I was able to increase the size all the way up to 3million elements without incident. – greatwolf May 08 '11 at 07:57
-
In CMake, this looks something like [this](https://stackoverflow.com/a/43342925) and it works for me. – Gumby The Green May 05 '19 at 05:48
6
You could run editbin after linking.

leppie
- 115,091
- 17
- 196
- 297
-
I definitely could - and this appears to be what I'll inevitably have to do - but I was looking for a way to do it at link time. Thanks though. – Landon Oct 02 '08 at 00:56
2
There are two stack sizes in Windows. The initially commited size, and the total reserved size. You can set both with a STACKSIZE statement in a .def file.

MSalters
- 173,980
- 10
- 155
- 350
0
When creating threads you use the dwStackSize paremater, but I'm not sure how to change the size for the main thread, this indicates its in the exe's header, so it may be an option for the compiler/linker, else you need to find the relevant part of the header and change it yourself.
http://msdn.microsoft.com/en-us/library/ms686774(VS.85).aspx

Fire Lancer
- 29,364
- 31
- 116
- 182