diff --git a/lib/std/debug.zig b/lib/std/debug.zig index e00c0a21a2..b600f7245a 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -113,6 +113,13 @@ pub fn detectTTYConfig() TTY.Config { /// TODO multithreaded awareness pub fn dumpCurrentStackTrace(start_addr: ?usize) void { nosuspend { + if (comptime builtin.target.isWasm()) { + if (native_os == .wasi) { + const stderr = io.getStdErr().writer(); + stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return; + } + return; + } const stderr = io.getStdErr().writer(); if (builtin.strip_debug_info) { stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; @@ -134,6 +141,13 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void { /// TODO multithreaded awareness pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void { nosuspend { + if (comptime builtin.target.isWasm()) { + if (native_os == .wasi) { + const stderr = io.getStdErr().writer(); + stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return; + } + return; + } const stderr = io.getStdErr().writer(); if (builtin.strip_debug_info) { stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; @@ -204,6 +218,13 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackT /// TODO multithreaded awareness pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void { nosuspend { + if (comptime builtin.target.isWasm()) { + if (native_os == .wasi) { + const stderr = io.getStdErr().writer(); + stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return; + } + return; + } const stderr = io.getStdErr().writer(); if (builtin.strip_debug_info) { stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; @@ -1134,6 +1155,8 @@ pub const DebugInfo = struct { return self.lookupModuleWin32(address); } else if (native_os == .haiku) { return self.lookupModuleHaiku(address); + } else if (comptime builtin.target.isWasm()) { + return self.lookupModuleWasm(address); } else { return self.lookupModuleDl(address); } @@ -1349,6 +1372,12 @@ pub const DebugInfo = struct { _ = address; @panic("TODO implement lookup module for Haiku"); } + + fn lookupModuleWasm(self: *DebugInfo, address: usize) !*ModuleDebugInfo { + _ = self; + _ = address; + @panic("TODO implement lookup module for Wasm"); + } }; pub const ModuleDebugInfo = switch (native_os) { @@ -1628,6 +1657,13 @@ pub const ModuleDebugInfo = switch (native_os) { return getSymbolFromDwarf(relocated_address, &self.dwarf); } }, + .wasi => struct { + pub fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo { + _ = self; + _ = address; + return SymbolInfo{}; + } + }, else => DW.DwarfInfo, }; diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index ab0deb9f63..e58a3a6d65 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -871,7 +871,8 @@ fn genFunc(self: *Self) InnerError!void { // we emit an unreachable instruction to tell the stack validator that part will never be reached. if (func_type.returns.len != 0 and self.air.instructions.len > 0) { const inst = @intCast(u32, self.air.instructions.len - 1); - if (self.air.typeOfIndex(inst).isNoReturn()) { + const last_inst_ty = self.air.typeOfIndex(inst); + if (!last_inst_ty.hasRuntimeBitsIgnoreComptime() or last_inst_ty.isNoReturn()) { try self.addTag(.@"unreachable"); } } diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 1ed733774f..4f72dfe388 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -1897,7 +1897,7 @@ pub fn flushModule(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod if (data_section_index) |data_index| { try self.emitDataRelocations(file, arena, data_index, symbol_table); } - } else { + } else if (!self.base.options.strip) { try self.emitNameSection(file, arena); } } diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index 40e4440102..3a83d93310 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -2645,6 +2645,9 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, Stage1Air *executabl Stage1AirInstSaveErrRetAddr *save_err_ret_addr_instruction) { assert(g->have_err_ret_tracing); + if ((target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) || target_is_bpf(g->zig_target)) { + return nullptr; + } LLVMValueRef return_err_fn = get_return_err_fn(g); bool is_llvm_alloca; diff --git a/src/stage1/target.cpp b/src/stage1/target.cpp index 7ff3008911..da6565f0be 100644 --- a/src/stage1/target.cpp +++ b/src/stage1/target.cpp @@ -1000,7 +1000,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { } bool target_has_debug_info(const ZigTarget *target) { - return !target_is_wasm(target); + return true; } bool target_long_double_is_f128(const ZigTarget *target) { diff --git a/src/target.zig b/src/target.zig index aafd65e327..27ed1118db 100644 --- a/src/target.zig +++ b/src/target.zig @@ -455,7 +455,8 @@ pub fn classifyCompilerRtLibName(target: std.Target, name: []const u8) CompilerR } pub fn hasDebugInfo(target: std.Target) bool { - return !target.cpu.arch.isWasm(); + _ = target; + return true; } pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.Mode {