Skip to content

Commit 6d606cc

Browse files
committed
reintroduce std.Dwarf.abi.supportsUnwinding
There are two concepts here: one for whether dwarf supports unwinding on that target, and another for whether the Zig standard library implements it yet.
1 parent 975c185 commit 6d606cc

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

lib/std/debug/Dwarf.zig

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,27 +2023,3 @@ fn pcRelBase(field_ptr: usize, pc_rel_offset: i64) !usize {
20232023
return std.math.add(usize, field_ptr, @as(usize, @intCast(pc_rel_offset)));
20242024
}
20252025
}
2026-
2027-
pub fn supportsUnwinding(target: std.Target) bool {
2028-
return switch (target.cpu.arch) {
2029-
.x86 => switch (target.os.tag) {
2030-
.linux, .netbsd, .solaris, .illumos => true,
2031-
else => false,
2032-
},
2033-
.x86_64 => switch (target.os.tag) {
2034-
.linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris, .illumos => true,
2035-
else => false,
2036-
},
2037-
.arm => switch (target.os.tag) {
2038-
.linux => true,
2039-
else => false,
2040-
},
2041-
.aarch64 => switch (target.os.tag) {
2042-
.linux, .netbsd, .freebsd, .macos, .ios => true,
2043-
else => false,
2044-
},
2045-
// Unwinding is possible on other targets but this implementation does
2046-
// not support them...yet!
2047-
else => false,
2048-
};
2049-
}

lib/std/debug/Dwarf/abi.zig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ const mem = std.mem;
55
const posix = std.posix;
66
const Arch = std.Target.Cpu.Arch;
77

8+
/// Tells whether unwinding for this target is supported by the Dwarf standard.
9+
///
10+
/// See also `std.debug.SelfInfo.supportsUnwinding` which tells whether the Zig
11+
/// standard library has a working implementation of unwinding for this target.
12+
pub fn supportsUnwinding(target: std.Target) bool {
13+
return switch (target.cpu.arch) {
14+
.amdgcn,
15+
.nvptx,
16+
.nvptx64,
17+
.spirv,
18+
.spirv32,
19+
.spirv64,
20+
.spu_2,
21+
=> false,
22+
23+
// Enabling this causes relocation errors such as:
24+
// error: invalid relocation type R_RISCV_SUB32 at offset 0x20
25+
.riscv64, .riscv32 => false,
26+
27+
// Conservative guess. Feel free to update this logic with any targets
28+
// that are known to not support Dwarf unwinding.
29+
else => true,
30+
};
31+
}
32+
833
/// Returns `null` for CPU architectures without an instruction pointer register.
934
pub fn ipRegNum(arch: Arch) ?u8 {
1035
return switch (arch) {

lib/std/debug/SelfInfo.zig

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,42 @@ fn spRegNum(reg_context: Dwarf.abi.RegisterContext) u8 {
19821982
}
19831983

19841984
const ip_reg_num = Dwarf.abi.ipRegNum(native_arch).?;
1985-
pub const supports_unwinding = Dwarf.supportsUnwinding(builtin.target);
1985+
1986+
/// Tells whether unwinding for the host is implemented.
1987+
pub const supports_unwinding = supportsUnwinding(builtin.target);
1988+
1989+
comptime {
1990+
if (supports_unwinding) assert(Dwarf.abi.supportsUnwinding(builtin.target));
1991+
}
1992+
1993+
/// Tells whether unwinding for this target is *implemented* here in the Zig
1994+
/// standard library.
1995+
///
1996+
/// See also `Dwarf.abi.supportsUnwinding` which tells whether Dwarf supports
1997+
/// unwinding on that target *in theory*.
1998+
pub fn supportsUnwinding(target: std.Target) bool {
1999+
return switch (target.cpu.arch) {
2000+
.x86 => switch (target.os.tag) {
2001+
.linux, .netbsd, .solaris, .illumos => true,
2002+
else => false,
2003+
},
2004+
.x86_64 => switch (target.os.tag) {
2005+
.linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris, .illumos => true,
2006+
else => false,
2007+
},
2008+
.arm => switch (target.os.tag) {
2009+
.linux => true,
2010+
else => false,
2011+
},
2012+
.aarch64 => switch (target.os.tag) {
2013+
.linux, .netbsd, .freebsd, .macos, .ios => true,
2014+
else => false,
2015+
},
2016+
// Unwinding is possible on other targets but this implementation does
2017+
// not support them...yet!
2018+
else => false,
2019+
};
2020+
}
19862021

19872022
fn unwindFrameMachODwarf(
19882023
context: *UnwindContext,

0 commit comments

Comments
 (0)