This allows stack overflows to print stack traces. The size of the
sigaltstack (and whether it is actually set) can be configured by
setting std.Options.signal_stack_size.
The default value for the signal stack size was chosen experimentally by
doubling the value required to get stack traces on stack overflow with
the self-hosted x86_64 backend. While some targets may typically use
more stack space than x86_64-linux, the self-hosted x86_64 backend is
quite wasteful with stack at the moment, making it a fair benchmark.
Executables produced by the LLVM backend should have lower stack usage.
Example:
constuse_thread=false;pubfnmain()!void{if(use_thread){constt=trystd.Thread.spawn(.{},iEatStackForBreakfast,.{1_000_000});t.join();}else{iEatStackForBreakfast(1_000_000);}std.log.info("done",.{});}noinlinefniEatStackForBreakfast(n:u32)void{if(n!=0)iEatStackForBreakfast(n-1);}conststd=@import("std");
$ zig run stack_overflow.zig --zig-lib-dir master/lib
Segmentation fault zig run stack_overflow.zig
$ zig run stack_overflow.zig --zig-lib-dir branch/lib
Segmentation fault at address 0x7ffc7e5e7ff8
/home/mlugg/zig/stack-traces/stack_overflow.zig:12:38: 0x11953dc in iEatStackForBreakfast (stack_overflow.zig)
if (n != 0) iEatStackForBreakfast(n - 1);
^
/home/mlugg/zig/stack-traces/stack_overflow.zig:12:38: 0x11953e0 in iEatStackForBreakfast (stack_overflow.zig)
if (n != 0) iEatStackForBreakfast(n - 1);
^
/home/mlugg/zig/stack-traces/stack_overflow.zig:12:38: 0x11953e0 in iEatStackForBreakfast (stack_overflow.zig)
if (n != 0) iEatStackForBreakfast(n - 1);
^
/home/mlugg/zig/stack-traces/stack_overflow.zig:12:38: 0x11953e0 in iEatStackForBreakfast (stack_overflow.zig)
if (n != 0) iEatStackForBreakfast(n - 1);
^
(for 10,000 frames). And same behavior with use_thread = true.
This allows stack overflows to print stack traces. The size of the
sigaltstack (and whether it is actually set) can be configured by
setting `std.Options.signal_stack_size`.
The default value for the signal stack size was chosen experimentally by
doubling the value required to get stack traces on stack overflow with
the self-hosted x86_64 backend. While some targets may typically use
more stack space than x86_64-linux, the self-hosted x86_64 backend is
quite wasteful with stack at the moment, making it a fair benchmark.
Executables produced by the LLVM backend should have lower stack usage.
---
Example:
```zig
const use_thread = false;
pub fn main() !void {
if (use_thread) {
const t = try std.Thread.spawn(.{}, iEatStackForBreakfast, .{1_000_000});
t.join();
} else {
iEatStackForBreakfast(1_000_000);
}
std.log.info("done", .{});
}
noinline fn iEatStackForBreakfast(n: u32) void {
if (n != 0) iEatStackForBreakfast(n - 1);
}
const std = @import("std");
```
```
$ zig run stack_overflow.zig --zig-lib-dir master/lib
Segmentation fault zig run stack_overflow.zig
$ zig run stack_overflow.zig --zig-lib-dir branch/lib
Segmentation fault at address 0x7ffc7e5e7ff8
/home/mlugg/zig/stack-traces/stack_overflow.zig:12:38: 0x11953dc in iEatStackForBreakfast (stack_overflow.zig)
if (n != 0) iEatStackForBreakfast(n - 1);
^
/home/mlugg/zig/stack-traces/stack_overflow.zig:12:38: 0x11953e0 in iEatStackForBreakfast (stack_overflow.zig)
if (n != 0) iEatStackForBreakfast(n - 1);
^
/home/mlugg/zig/stack-traces/stack_overflow.zig:12:38: 0x11953e0 in iEatStackForBreakfast (stack_overflow.zig)
if (n != 0) iEatStackForBreakfast(n - 1);
^
/home/mlugg/zig/stack-traces/stack_overflow.zig:12:38: 0x11953e0 in iEatStackForBreakfast (stack_overflow.zig)
if (n != 0) iEatStackForBreakfast(n - 1);
^
```
(for 10,000 frames). And same behavior with `use_thread = true`.