authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-08 02:15:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-08 02:38:32-07:00
log051aadd7810de9b68f415ec00a3867f6f783b961
tree01b324db1cfc39840e4368ed28911bfc73968c8f
parent72b5ceed66005f03933a4e5bbd0eda08378b0fd0

std lib general purpose allocator: disable stack tracing on mips

Sadly, trying to collect stack frames goes into an infinite loop on mips. This sets the default number of stack frames to collect to 0 on mips.

2 files changed, 17 insertions(+), 3 deletions(-)

doc/langref.html.in+1-1
...@@ -9363,7 +9363,7 @@ pub fn main() !void {...@@ -9363,7 +9363,7 @@ pub fn main() !void {
9363 Finally, if none of the above apply, you need a general purpose allocator.9363 Finally, if none of the above apply, you need a general purpose allocator.
9364 Zig's general purpose allocator is available as a function that takes a {#link|comptime#}9364 Zig's general purpose allocator is available as a function that takes a {#link|comptime#}
9365 {#link|struct#} of configuration options and returns a type.9365 {#link|struct#} of configuration options and returns a type.
9366 Generally, you will set up one {#syntax#}std.heap.GeneralPurposeAllocator#{endsyntax#} in9366 Generally, you will set up one {#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#} in
9367 your main function, and then pass it or sub-allocators around to various parts of your9367 your main function, and then pass it or sub-allocators around to various parts of your
9368 application.9368 application.
9369 </li>9369 </li>
lib/std/heap/general_purpose_allocator.zig+16-2
...@@ -102,8 +102,22 @@ const StackTrace = std.builtin.StackTrace;...@@ -102,8 +102,22 @@ const StackTrace = std.builtin.StackTrace;
102/// Integer type for pointing to slots in a small allocation102/// Integer type for pointing to slots in a small allocation
103const SlotIndex = std.meta.Int(false, math.log2(page_size) + 1);103const SlotIndex = std.meta.Int(false, math.log2(page_size) + 1);
104104
105// WebAssembly doesn't support stack tracing yet.105const sys_can_stack_trace = switch (std.Target.current.cpu.arch) {
106const default_stack_trace_frames: usize = if (std.Target.current.cpu.arch.isWasm()) 0 else 4;106 // Observed to go into an infinite loop.
107 // TODO: Make this work.
108 .mips,
109 .mipsel,
110 => false,
111
112 // `@returnAddress()` in LLVM 10 gives
113 // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address".
114 .wasm32,
115 .wasm64,
116 => std.Target.current.os.tag == .emscripten,
117
118 else => true,
119};
120const default_stack_trace_frames: usize = if (sys_can_stack_trace) 4 else 0;
107121
108pub const Config = struct {122pub const Config = struct {
109 /// Number of stack frames to capture.123 /// Number of stack frames to capture.