authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-18 22:24:40+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-19 03:44:42+01:00
logc70a3d9022b4cb3e848a5f092a5eab7f7217cca0
tree5c191190d49962c062baed34ff5a8bbac1292242
parent35f5d437688841d1c908cd81f205d7c9b44e3ae6

macho: port arm64 and x86_64 compact unwind defs verbatim

We do not need more for the purpose of parsing and synthesising unwind info by the linker. If we ever decide to generate unwind info for Zig by the compiler, we can re-add packed struct defs again.

1 files changed, 50 insertions(+), 91 deletions(-)

lib/std/macho.zig+50-91
......@@ -2004,96 +2004,55 @@ pub const UnwindInfoCompressedEntry = packed struct {
20042004 encodingIndex: u8,
20052005};
20062006
2007// TODO add corresponding x86_64 tagged union
2008pub const UnwindEncodingArm64 = union(enum) {
2009 frame: Frame,
2010 frameless: Frameless,
2011 dwarf: Dwarf,
2012
2013 pub const Frame = packed struct {
2014 x_reg_pairs: packed struct {
2015 x19_x20: u1,
2016 x21_x22: u1,
2017 x23_x24: u1,
2018 x25_x26: u1,
2019 x27_x28: u1,
2020 },
2021 d_reg_pairs: packed struct {
2022 d8_d9: u1,
2023 d10_d11: u1,
2024 d12_d13: u1,
2025 d14_d15: u1,
2026 },
2027 unused: u15,
2028 mode: Mode = .frame,
2029 personality_index: u2,
2030 has_lsda: u1,
2031 start: u1,
2032 };
2033
2034 pub const Frameless = packed struct {
2035 unused: u12 = 0,
2036 stack_size: u12,
2037 mode: Mode = .frameless,
2038 personality_index: u2,
2039 has_lsda: u1,
2040 start: u1,
2041 };
2042
2043 pub const Dwarf = packed struct {
2044 section_offset: u24,
2045 mode: Mode = .dwarf,
2046 personality_index: u2,
2047 has_lsda: u1,
2048 start: u1,
2049 };
2050
2051 pub const Mode = enum(u4) {
2052 frameless = 0x2,
2053 dwarf = 0x3,
2054 frame = 0x4,
2055 _,
2056 };
2057
2058 pub const mode_mask: u32 = 0x0F000000;
2059
2060 pub fn fromU32(enc: u32) !UnwindEncodingArm64 {
2061 const m = (enc & mode_mask) >> 24;
2062 return switch (@intToEnum(Mode, m)) {
2063 .frame => .{ .frame = @bitCast(Frame, enc) },
2064 .frameless => .{ .frameless = @bitCast(Frameless, enc) },
2065 .dwarf => .{ .dwarf = @bitCast(Dwarf, enc) },
2066 else => return error.UnknownEncoding,
2067 };
2068 }
2069
2070 pub fn toU32(enc: UnwindEncodingArm64) u32 {
2071 return switch (enc) {
2072 inline else => |x| @bitCast(u32, x),
2073 };
2074 }
2075
2076 pub fn start(enc: UnwindEncodingArm64) bool {
2077 return switch (enc) {
2078 inline else => |x| x.start == 0b1,
2079 };
2080 }
2081
2082 pub fn hasLsda(enc: UnwindEncodingArm64) bool {
2083 return switch (enc) {
2084 inline else => |x| x.has_lsda == 0b1,
2085 };
2086 }
2087
2088 pub fn personalityIndex(enc: UnwindEncodingArm64) u2 {
2089 return switch (enc) {
2090 inline else => |x| x.personality_index,
2091 };
2092 }
2007pub const UNWIND_IS_NOT_FUNCTION_START: u32 = 0x80000000;
2008pub const UNWIND_HAS_LSDA: u32 = 0x40000000;
2009pub const UNWIND_PERSONALITY_MASK: u32 = 0x30000000;
2010
2011// x86_64
2012pub const UNWIND_X86_64_MODE_MASK: u32 = 0x0F000000;
2013pub const UNWIND_X86_64_MODE = enum(u4) {
2014 RBP_FRAME = 1,
2015 STACK_IMMD = 2,
2016 STACK_IND = 3,
2017 DWARF = 4,
2018};
2019pub const UNWIND_X86_64_RBP_FRAME_REGISTERS: u32 = 0x00007FFF;
2020pub const UNWIND_X86_64_RBP_FRAME_OFFSET: u32 = 0x00FF0000;
2021
2022pub const UNWIND_X86_64_FRAMELESS_STACK_SIZE: u32 = 0x00FF0000;
2023pub const UNWIND_X86_64_FRAMELESS_STACK_ADJUST: u32 = 0x0000E000;
2024pub const UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT: u32 = 0x00001C00;
2025pub const UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION: u32 = 0x000003FF;
2026
2027pub const UNWIND_X86_64_DWARF_SECTION_OFFSET: u32 = 0x00FFFFFF;
2028
2029pub const UNWIND_X86_64_REG = enum(u3) {
2030 NONE = 0,
2031 RBX = 1,
2032 R12 = 2,
2033 R13 = 3,
2034 R14 = 4,
2035 R15 = 5,
2036 RBP = 6,
2037};
20932038
2094 pub fn mode(enc: UnwindEncodingArm64) Mode {
2095 return switch (enc) {
2096 inline else => |x| x.mode,
2097 };
2098 }
2039// arm64
2040pub const UNWIND_ARM64_MODE_MASK: u32 = 0x0F000000;
2041pub const UNWIND_ARM64_MODE = enum(u4) {
2042 FRAMELESS = 2,
2043 DWARF = 3,
2044 FRAME = 4,
20992045};
2046
2047pub const UNWIND_ARM64_FRAME_X19_X20_PAIR: u32 = 0x00000001;
2048pub const UNWIND_ARM64_FRAME_X21_X22_PAIR: u32 = 0x00000002;
2049pub const UNWIND_ARM64_FRAME_X23_X24_PAIR: u32 = 0x00000004;
2050pub const UNWIND_ARM64_FRAME_X25_X26_PAIR: u32 = 0x00000008;
2051pub const UNWIND_ARM64_FRAME_X27_X28_PAIR: u32 = 0x00000010;
2052pub const UNWIND_ARM64_FRAME_D8_D9_PAIR: u32 = 0x00000100;
2053pub const UNWIND_ARM64_FRAME_D10_D11_PAIR: u32 = 0x00000200;
2054pub const UNWIND_ARM64_FRAME_D12_D13_PAIR: u32 = 0x00000400;
2055pub const UNWIND_ARM64_FRAME_D14_D15_PAIR: u32 = 0x00000800;
2056
2057pub const UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK: u32 = 0x00FFF000;
2058pub const UNWIND_ARM64_DWARF_SECTION_OFFSET: u32 = 0x00FFFFFF;