Commit 661028a907

kcbanner <kcbanner@gmail.com>
2023-07-26 07:26:26
target: emit unwind tables if the platform supports unwinding
1 parent f2aab12
Changed files (3)
lib
src
lib/std/dwarf/abi.zig
@@ -3,13 +3,24 @@ const std = @import("../std.zig");
 const os = std.os;
 const mem = std.mem;
 
-pub fn isSupportedArch(arch: std.Target.Cpu.Arch) bool {
-    return switch (arch) {
-        .x86,
-        .x86_64,
-        .arm,
-        .aarch64,
-        => true,
+pub fn supportsUnwinding(target: std.Target) bool {
+    return switch (target.cpu.arch) {
+        .x86 => switch (target.os.tag) {
+            .linux, .netbsd, .solaris => true,
+            else => false,
+        },
+        .x86_64 => switch (target.os.tag) {
+            .linux, .netbsd, .freebsd, .openbsd, .macos, .solaris => true,
+            else => false,
+        },
+        .arm => switch (target.os.tag) {
+            .linux => true,
+            else => false,
+        },
+        .aarch64 => switch (target.os.tag) {
+            .linux, .netbsd, .freebsd, .macos => true,
+            else => false,
+        },
         else => false,
     };
 }
lib/std/dwarf.zig
@@ -1656,7 +1656,7 @@ pub const DwarfInfo = struct {
     /// `explicit_fde_offset` is for cases where the FDE offset is known, such as when __unwind_info
     /// defers unwinding to DWARF. This is an offset into the `.eh_frame` section.
     pub fn unwindFrame(di: *const DwarfInfo, context: *UnwindContext, explicit_fde_offset: ?usize) !usize {
-        if (!comptime abi.isSupportedArch(builtin.target.cpu.arch)) return error.UnsupportedCpuArchitecture;
+        if (!comptime abi.supportsUnwinding(builtin.target)) return error.UnsupportedCpuArchitecture;
         if (context.pc == 0) return 0;
 
         // Find the FDE and CIE
src/target.zig
@@ -510,7 +510,7 @@ pub fn clangAssemblerSupportsMcpuArg(target: std.Target) bool {
 }
 
 pub fn needUnwindTables(target: std.Target) bool {
-    return target.os.tag == .windows or target.isDarwin();
+    return target.os.tag == .windows or target.isDarwin() or std.dwarf.abi.supportsUnwinding(target);
 }
 
 pub fn defaultAddressSpace(