Use a larger stack if sigaltstack is too small
Summary: The signal handler might use nearly 9KB stack for symbolization. That would cause stack overflow if the signal handler is running on a small alternative stack set by sigaltstack. We have seen that in Rust programs. The Rust stdlib sets up [8KB](https://github.com/rust-lang/libc/blob/4bd52f5e3ef5d6c8abdd1fbaf7c9975800a0dc93/src/unix/notbsd/linux/other/b64/x86_64.rs#L505) stacks [using sigaltstack](https://github.com/rust-lang/rust/blob/55b54a999bcdb0b1c1f42b6e1ae670beb0717086/src/libstd/sys/unix/stack_overflow.rs#L173) for all threads created by Rust on x64 Linux. Talked with jsgf, we'd still like to get a nice symbolized stack trace if segfault happens in a binary including both Rust and C++ code, since it's more likely the C++ part being wrong, so C++ symbol demangling is more important than Rust demangling. This diff detects the small sigaltstack case, then allocates larger stack for symbolization. Note the stack manipulation logic is not signal-safe, so it's not used for non-small-sigaltstack cases. Programs not using sigaltstack, or use sigaltstack with >9KB stacks won't be affected. As we're here, teach the signal handler to save and restore errno. Also add a note about golang's SA_ONSTACK requirement. Reviewed By: luciang Differential Revision: D9846902 fbshipit-source-id: f0dc81b1c1249d8a724e112906e0ff0b14c14ea9
Showing
Please register or sign in to comment