authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-05-26 18:47:21-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:13-04:00
log551f153718ee1f670ce95c4e485bfb759b84632e
treee315040ea7900391b4e2f1a999628dc4a108fa82
parent2f75d20d87fe68eb2695acd37fc2364c06c4c582

dwarf: fixes for non-64 bit systems


2 files changed, 13 insertions(+), 9 deletions(-)

lib/std/dwarf.zig+12-8
......@@ -693,8 +693,8 @@ pub const DwarfInfo = struct {
693693 }
694694
695695 pub fn deinit(di: *DwarfInfo, allocator: mem.Allocator) void {
696 for (di.sections) |s| {
697 if (s.owned) allocator.free(s.data);
696 for (di.sections) |opt_section| {
697 if (opt_section) |s| if (s.owned) allocator.free(s.data);
698698 }
699699 for (di.abbrev_table_list.items) |*abbrev| {
700700 abbrev.deinit();
......@@ -1504,12 +1504,12 @@ pub const DwarfInfo = struct {
15041504
15051505 while (stream.pos < stream.buffer.len) {
15061506 const length_offset = stream.pos;
1507 var length: u64 = try reader.readInt(u32, di.endian);
1507 var length: usize = try reader.readInt(u32, di.endian);
15081508 if (length == 0) break;
15091509
15101510 var is_64 = length == math.maxInt(u32);
15111511 if (is_64) {
1512 length = try reader.readInt(u64, di.endian);
1512 length = std.math.cast(usize, try reader.readInt(u64, di.endian)) orelse return error.LengthOverflow;
15131513 }
15141514
15151515 const id_len = @as(u8, if (is_64) 8 else 4);
......@@ -1746,10 +1746,14 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
17461746 };
17471747
17481748 if ((enc & EH.PE.indirect) > 0 and ctx.follow_indirect) {
1749 if (@sizeOf(usize) != addr_size_bytes) {
1750 // See the documentation for `follow_indirect`
1751 return error.NonNativeIndirection;
1752 }
1753
1754 const native_ptr = math.cast(usize, ptr) orelse return error.PointerOverflow;
17491755 return switch (addr_size_bytes) {
1750 2 => return @intToPtr(*const u16, ptr).*,
1751 4 => return @intToPtr(*const u32, ptr).*,
1752 8 => return @intToPtr(*const u64, ptr).*,
1756 2, 4, 8 => return @intToPtr(*const usize, native_ptr).*,
17531757 else => return error.UnsupportedAddrSize,
17541758 };
17551759 } else {
......@@ -1960,7 +1964,7 @@ pub const FrameDescriptionEntry = struct {
19601964
19611965 var aug_data: []const u8 = &[_]u8{};
19621966 const lsda_pointer = if (cie.aug_str.len > 0) blk: {
1963 const aug_data_len = try leb.readULEB128(u64, reader);
1967 const aug_data_len = try leb.readULEB128(usize, reader);
19641968 const aug_data_start = stream.pos;
19651969 aug_data = fde_bytes[aug_data_start..][0..aug_data_len];
19661970
lib/std/dwarf/call_frame.zig+1-1
......@@ -99,7 +99,7 @@ const Operand = enum {
9999 .u16_delta => try reader.readInt(u16, endian),
100100 .u32_delta => try reader.readInt(u32, endian),
101101 .block => {
102 const block_len = try leb.readULEB128(u64, reader);
102 const block_len = try leb.readULEB128(usize, reader);
103103 if (stream.pos + block_len > stream.buffer.len) return error.InvalidOperand;
104104
105105 const block = stream.buffer[stream.pos..][0..block_len];