gccstackmingwexestack-size

How to know the stack size limit of .exe program?


It seems my program (built with mingw g++) crashes due to insufficient stack memory. I use the compiling option -Wl,--stack,64000000 to increase the stack limit but the problem persists. I want to know if there is a utility or method to check the current stack limit of my .exe program, so I can verify the limit is indeed changed to that value.


Solution

  • From this answer, to check the stack size you need to install Visual Studio and use the visual studio tool dumpbin. Usually there is a script that can be run to bring a command prompt windows with all the visual studio tools in path, this is vcvarsall.bat or "x64 Native Tools Command Prompt for VS 2019" (or something like that) from the start menu.

    Run

    dumpbin /headers executable.exe
    

    This will return a long output. In that output, look for OPTIONAL HEADER VALUES and in that part, there will be a size of stack reserve . The default stacksize is written as 100000 (hex) i.e. 1 Megabytes.

    You can change the stacksize of an executable by using editbin, also provided by Visual Studio:

    editbin /stack:N executable.exe
    

    Here N is the number in bytes (in decimal) for the stacksize.