authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-02 12:35:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-02 14:15:03-07:00
log6d606cc38b4df2b20af9d77367f8ab22bbbea092
treefd00a5a549afccf68b6b50cb1f693dc4251eb4a9
parent975c185b92a7d470ea705b28f46a8004bdda3c60

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.

3 files changed, 61 insertions(+), 25 deletions(-)

lib/std/debug/Dwarf.zig-24
......@@ -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
2027pub 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+25
......@@ -5,6 +5,31 @@ const mem = std.mem;
55const posix = std.posix;
66const 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.
12pub 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.
934pub fn ipRegNum(arch: Arch) ?u8 {
1035 return switch (arch) {
lib/std/debug/SelfInfo.zig+36-1
......@@ -1982,7 +1982,42 @@ fn spRegNum(reg_context: Dwarf.abi.RegisterContext) u8 {
19821982}
19831983
19841984const ip_reg_num = Dwarf.abi.ipRegNum(native_arch).?;
1985pub const supports_unwinding = Dwarf.supportsUnwinding(builtin.target);
1985
1986/// Tells whether unwinding for the host is implemented.
1987pub const supports_unwinding = supportsUnwinding(builtin.target);
1988
1989comptime {
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*.
1998pub 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
19872022fn unwindFrameMachODwarf(
19882023 context: *UnwindContext,