sunder icon indicating copy to clipboard operation
sunder copied to clipboard

Non-optimizing builds can easily exhaust stack space

Open ashn-dot-dev opened this issue 1 year ago • 0 comments

Discovered here.

A non-recursive function, client_render, in natac commit a23e04a9af4414462582c1f763a7553bc477c09b produced a stack overflow on ARM64 macOS when compiled with -O0 and -O1 optimization. My default guess would be that the large number of local variables used in the generated C are not optimized away, leading to the default 8 MB stack becoming quickly exhausted. This behavior would presumably happen in other programs where many expressions/sloc are executed in one large function (or a handful of medium-sized functions).

Current workarounds are to compile with optimizations such as -Os, or to increase the stack size with -O0 -Wl,-stack_size -Wl,<NUMBER-LARGER-THAN-8-MB> when compiling in a debug build.

ashn-dot-dev avatar Jan 30 '24 21:01 ashn-dot-dev