Commit 051aadd781

Andrew Kelley <andrew@ziglang.org>
2020-08-08 11:15:46
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.
1 parent 72b5cee
Changed files (2)
doc/langref.html.in
@@ -9363,7 +9363,7 @@ pub fn main() !void {
               Finally, if none of the above apply, you need a general purpose allocator.
               Zig's general purpose allocator is available as a function that takes a {#link|comptime#}
               {#link|struct#} of configuration options and returns a type.
-              Generally, you will set up one {#syntax#}std.heap.GeneralPurposeAllocator#{endsyntax#} in
+              Generally, you will set up one {#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#} in
               your main function, and then pass it or sub-allocators around to various parts of your
               application.
           </li>
lib/std/heap/general_purpose_allocator.zig
@@ -102,8 +102,22 @@ const StackTrace = std.builtin.StackTrace;
 /// Integer type for pointing to slots in a small allocation
 const SlotIndex = std.meta.Int(false, math.log2(page_size) + 1);
 
-// WebAssembly doesn't support stack tracing yet.
-const default_stack_trace_frames: usize = if (std.Target.current.cpu.arch.isWasm()) 0 else 4;
+const sys_can_stack_trace = switch (std.Target.current.cpu.arch) {
+    // Observed to go into an infinite loop.
+    // TODO: Make this work.
+    .mips,
+    .mipsel,
+    => false,
+
+    // `@returnAddress()` in LLVM 10 gives
+    // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address".
+    .wasm32,
+    .wasm64,
+    => std.Target.current.os.tag == .emscripten,
+
+    else => true,
+};
+const default_stack_trace_frames: usize = if (sys_can_stack_trace) 4 else 0;
 
 pub const Config = struct {
     /// Number of stack frames to capture.