From 051aadd7810de9b68f415ec00a3867f6f783b961 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 8 Aug 2020 02:15:46 -0700 Subject: [PATCH] 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. --- doc/langref.html.in | 2 +- lib/std/heap/general_purpose_allocator.zig | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index dbdeb0fb42..edafc82ab8 100644 --- a/doc/langref.html.in +++ b/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. diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig index 5369560356..27f2d10586 100644 --- a/lib/std/heap/general_purpose_allocator.zig +++ b/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.