MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.73k stars 254 forks source link

Help Clang find bottom of stacks for safety, use desired stack size #873

Open dtzWill opened 2 years ago

dtzWill commented 2 years ago

noteBottomOfStack:

Without this, checks against stack space within Clang don't work as Clang doesn't know where the stack begins.

Needed per-thread, as early as possible. (on threads using Clang)

Using Clang's desired stack size:

Additionally increase stack size of pthreads to Clang's desired size.

This is presently 8MB, and is used by Clang's stack management mechanisms to check* if close to stack exhaustion when determining if there's sufficient space (and warn or run on a new thread with more). (see runWithSufficientStackSpace)

The constant is available in LLVM 7 onwards.

dtzWill commented 2 years ago

This fixes crashes encountered pointing ccls at CIRCT (+llvm submodule), which was my motivation. I haven't looked into making that reproducible (on other systems), so not sure if that's specific to my setup. Stack was very deep (just shy of 10k frames) and included many calls to runWithSufficientStackSpace that were doing nothing. For some reason this actually took down my ccls instance (despite CrashRecoveryContext/runSafely), which made it particularly problematic.