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 {...@@ -693,8 +693,8 @@ pub const DwarfInfo = struct {
693 }693 }
694694
695 pub fn deinit(di: *DwarfInfo, allocator: mem.Allocator) void {695 pub fn deinit(di: *DwarfInfo, allocator: mem.Allocator) void {
696 for (di.sections) |s| {696 for (di.sections) |opt_section| {
697 if (s.owned) allocator.free(s.data);697 if (opt_section) |s| if (s.owned) allocator.free(s.data);
698 }698 }
699 for (di.abbrev_table_list.items) |*abbrev| {699 for (di.abbrev_table_list.items) |*abbrev| {
700 abbrev.deinit();700 abbrev.deinit();
...@@ -1504,12 +1504,12 @@ pub const DwarfInfo = struct {...@@ -1504,12 +1504,12 @@ pub const DwarfInfo = struct {
15041504
1505 while (stream.pos < stream.buffer.len) {1505 while (stream.pos < stream.buffer.len) {
1506 const length_offset = stream.pos;1506 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);
1508 if (length == 0) break;1508 if (length == 0) break;
15091509
1510 var is_64 = length == math.maxInt(u32);1510 var is_64 = length == math.maxInt(u32);
1511 if (is_64) {1511 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;
1513 }1513 }
15141514
1515 const id_len = @as(u8, if (is_64) 8 else 4);1515 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...@@ -1746,10 +1746,14 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
1746 };1746 };
17471747
1748 if ((enc & EH.PE.indirect) > 0 and ctx.follow_indirect) {1748 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;
1749 return switch (addr_size_bytes) {1755 return switch (addr_size_bytes) {
1750 2 => return @intToPtr(*const u16, ptr).*,1756 2, 4, 8 => return @intToPtr(*const usize, native_ptr).*,
1751 4 => return @intToPtr(*const u32, ptr).*,
1752 8 => return @intToPtr(*const u64, ptr).*,
1753 else => return error.UnsupportedAddrSize,1757 else => return error.UnsupportedAddrSize,
1754 };1758 };
1755 } else {1759 } else {
...@@ -1960,7 +1964,7 @@ pub const FrameDescriptionEntry = struct {...@@ -1960,7 +1964,7 @@ pub const FrameDescriptionEntry = struct {
19601964
1961 var aug_data: []const u8 = &[_]u8{};1965 var aug_data: []const u8 = &[_]u8{};
1962 const lsda_pointer = if (cie.aug_str.len > 0) blk: {1966 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);
1964 const aug_data_start = stream.pos;1968 const aug_data_start = stream.pos;
1965 aug_data = fde_bytes[aug_data_start..][0..aug_data_len];1969 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 {...@@ -99,7 +99,7 @@ const Operand = enum {
99 .u16_delta => try reader.readInt(u16, endian),99 .u16_delta => try reader.readInt(u16, endian),
100 .u32_delta => try reader.readInt(u32, endian),100 .u32_delta => try reader.readInt(u32, endian),
101 .block => {101 .block => {
102 const block_len = try leb.readULEB128(u64, reader);102 const block_len = try leb.readULEB128(usize, reader);
103 if (stream.pos + block_len > stream.buffer.len) return error.InvalidOperand;103 if (stream.pos + block_len > stream.buffer.len) return error.InvalidOperand;
104104
105 const block = stream.buffer[stream.pos..][0..block_len];105 const block = stream.buffer[stream.pos..][0..block_len];