authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-03-21 11:38:49+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-03-21 11:38:49+01:00
log073f9a18a92fd233e07470e737e15e651618e47f
treebdb4754cf874e8a3536bcecbd0d310fd7d3b6ff5
parenta88ffa7fa91e568fe234ac9ea2b15f005876cca6

macho+zld: return null rather than error on invalid AbbrevKind


1 files changed, 3 insertions(+), 18 deletions(-)

src/link/MachO/DwarfInfo.zig+3-18
......@@ -27,7 +27,7 @@ const CompileUnitIterator = struct {
2727 pub fn next(self: *CompileUnitIterator) !?CompileUnit {
2828 if (self.pos >= self.ctx.debug_info.len) return null;
2929
30 var stream = std.io.fixedBufferStream(self.ctx.debug_info);
30 var stream = std.io.fixedBufferStream(self.ctx.debug_info[self.pos..]);
3131 var creader = std.io.countingReader(stream.reader());
3232 const reader = creader.reader();
3333
......@@ -37,7 +37,7 @@ const CompileUnitIterator = struct {
3737
3838 const cu = CompileUnit{
3939 .cuh = cuh,
40 .debug_info_off = offset,
40 .debug_info_off = self.pos + offset,
4141 };
4242
4343 self.pos += (math.cast(usize, total_length) orelse return error.Overflow);
......@@ -188,7 +188,7 @@ const AbbrevEntryIterator = struct {
188188 return AbbrevEntry.null();
189189 }
190190
191 const abbrev_pos = lookup.get(kind) orelse return error.MalformedDwarf;
191 const abbrev_pos = lookup.get(kind) orelse return null;
192192 const len = try findAbbrevEntrySize(
193193 self.ctx,
194194 abbrev_pos.pos,
......@@ -290,21 +290,6 @@ pub const Attribute = struct {
290290 };
291291 }
292292
293 pub fn getReference(self: Attribute, ctx: DwarfInfo) !?u64 {
294 const debug_info = self.getDebugInfo(ctx);
295 var stream = std.io.fixedBufferStream(debug_info);
296 const reader = stream.reader();
297
298 return switch (self.form) {
299 dwarf.FORM.ref1 => debug_info[0],
300 dwarf.FORM.ref2 => mem.readIntLittle(u16, debug_info[0..2]),
301 dwarf.FORM.ref4 => mem.readIntLittle(u32, debug_info[0..4]),
302 dwarf.FORM.ref8 => mem.readIntLittle(u64, debug_info[0..8]),
303 dwarf.FORM.ref_udata => try leb.readULEB128(u64, reader),
304 else => null,
305 };
306 }
307
308293 pub fn getAddr(self: Attribute, ctx: DwarfInfo, cuh: CompileUnit.Header) ?u64 {
309294 if (self.form != dwarf.FORM.addr) return null;
310295 const debug_info = self.getDebugInfo(ctx);