macho: fix incorrect DWARF subprogram generation

This commit is contained in:
Jakub Konka 2023-04-09 13:25:40 +02:00
parent e72c41a32a
commit 5154ece8b9
2 changed files with 29 additions and 10 deletions

View File

@ -150,7 +150,7 @@ pub const DeclState = struct {
.type = ty, .type = ty,
.offset = undefined, .offset = undefined,
}); });
log.debug("%{d}: {}", .{ sym_index, ty.fmtDebug() }); log.debug("%{d}: {}", .{ sym_index, ty.fmt(self.mod) });
try self.abbrev_resolver.putNoClobberContext(self.gpa, ty, sym_index, .{ try self.abbrev_resolver.putNoClobberContext(self.gpa, ty, sym_index, .{
.mod = self.mod, .mod = self.mod,
}); });
@ -570,7 +570,7 @@ pub const DeclState = struct {
try dbg_info_buffer.append(0); try dbg_info_buffer.append(0);
}, },
else => { else => {
log.debug("TODO implement .debug_info for type '{}'", .{ty.fmtDebug()}); log.debug("TODO implement .debug_info for type '{}'", .{ty.fmt(self.mod)});
try dbg_info_buffer.append(@enumToInt(AbbrevKind.pad1)); try dbg_info_buffer.append(@enumToInt(AbbrevKind.pad1));
}, },
} }
@ -1055,6 +1055,10 @@ pub fn commitDeclState(
}, },
} }
{ {
log.debug("relocating subprogram high PC value: {x} => {x}", .{
self.getRelocDbgInfoSubprogramHighPC(),
sym_size,
});
const ptr = dbg_info_buffer.items[self.getRelocDbgInfoSubprogramHighPC()..][0..4]; const ptr = dbg_info_buffer.items[self.getRelocDbgInfoSubprogramHighPC()..][0..4];
mem.writeInt(u32, ptr, @intCast(u32, sym_size), target_endian); mem.writeInt(u32, ptr, @intCast(u32, sym_size), target_endian);
} }
@ -1263,7 +1267,12 @@ pub fn commitDeclState(
} else { } else {
const atom = self.getAtom(.di_atom, symbol.atom_index); const atom = self.getAtom(.di_atom, symbol.atom_index);
const value = atom.off + symbol.offset + reloc.addend; const value = atom.off + symbol.offset + reloc.addend;
log.debug("{x}: [() => {x}] (%{d}, '{}')", .{ reloc.offset, value, target, ty.fmtDebug() }); log.debug("{x}: [() => {x}] (%{d}, '{}')", .{
reloc.offset,
value,
target,
ty.fmt(module),
});
mem.writeInt( mem.writeInt(
u32, u32,
dbg_info_buffer.items[reloc.offset..][0..@sizeOf(u32)], dbg_info_buffer.items[reloc.offset..][0..@sizeOf(u32)],

View File

@ -2070,8 +2070,6 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
self.freeUnnamedConsts(decl_index); self.freeUnnamedConsts(decl_index);
Atom.freeRelocations(self, atom_index); Atom.freeRelocations(self, atom_index);
const atom = self.getAtom(atom_index);
var code_buffer = std.ArrayList(u8).init(self.base.allocator); var code_buffer = std.ArrayList(u8).init(self.base.allocator);
defer code_buffer.deinit(); defer code_buffer.deinit();
@ -2100,7 +2098,13 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
const addr = try self.updateDeclCode(decl_index, code); const addr = try self.updateDeclCode(decl_index, code);
if (decl_state) |*ds| { if (decl_state) |*ds| {
try self.d_sym.?.dwarf.commitDeclState(module, decl_index, addr, atom.size, ds); try self.d_sym.?.dwarf.commitDeclState(
module,
decl_index,
addr,
self.getAtom(atom_index).size,
ds,
);
} }
// Since we updated the vaddr and the size, each corresponding export symbol also // Since we updated the vaddr and the size, each corresponding export symbol also
@ -2196,8 +2200,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
} }
const atom_index = try self.getOrCreateAtomForDecl(decl_index); const atom_index = try self.getOrCreateAtomForDecl(decl_index);
const sym_index = self.getAtom(atom_index).getSymbolIndex().?;
Atom.freeRelocations(self, atom_index); Atom.freeRelocations(self, atom_index);
const atom = self.getAtom(atom_index);
var code_buffer = std.ArrayList(u8).init(self.base.allocator); var code_buffer = std.ArrayList(u8).init(self.base.allocator);
defer code_buffer.deinit(); defer code_buffer.deinit();
@ -2216,14 +2220,14 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
}, &code_buffer, .{ }, &code_buffer, .{
.dwarf = ds, .dwarf = ds,
}, .{ }, .{
.parent_atom_index = atom.getSymbolIndex().?, .parent_atom_index = sym_index,
}) })
else else
try codegen.generateSymbol(&self.base, decl.srcLoc(), .{ try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
.ty = decl.ty, .ty = decl.ty,
.val = decl_val, .val = decl_val,
}, &code_buffer, .none, .{ }, &code_buffer, .none, .{
.parent_atom_index = atom.getSymbolIndex().?, .parent_atom_index = sym_index,
}); });
var code = switch (res) { var code = switch (res) {
@ -2237,7 +2241,13 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
const addr = try self.updateDeclCode(decl_index, code); const addr = try self.updateDeclCode(decl_index, code);
if (decl_state) |*ds| { if (decl_state) |*ds| {
try self.d_sym.?.dwarf.commitDeclState(module, decl_index, addr, atom.size, ds); try self.d_sym.?.dwarf.commitDeclState(
module,
decl_index,
addr,
self.getAtom(atom_index).size,
ds,
);
} }
// Since we updated the vaddr and the size, each corresponding export symbol also // Since we updated the vaddr and the size, each corresponding export symbol also