authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-09 13:25:40+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-13 11:47:50+02:00
log5154ece8b9fd64f276fb6cb6f88fdfda1fc0f935
tree28ef7c84fb840760fdc490ca7e0593b04dfab6df
parente72c41a32af41c15f4f73b46c902c01ed838462f

macho: fix incorrect DWARF subprogram generation


2 files changed, 29 insertions(+), 10 deletions(-)

src/link/Dwarf.zig+12-3
......@@ -150,7 +150,7 @@ pub const DeclState = struct {
150150 .type = ty,
151151 .offset = undefined,
152152 });
153 log.debug("%{d}: {}", .{ sym_index, ty.fmtDebug() });
153 log.debug("%{d}: {}", .{ sym_index, ty.fmt(self.mod) });
154154 try self.abbrev_resolver.putNoClobberContext(self.gpa, ty, sym_index, .{
155155 .mod = self.mod,
156156 });
......@@ -570,7 +570,7 @@ pub const DeclState = struct {
570570 try dbg_info_buffer.append(0);
571571 },
572572 else => {
573 log.debug("TODO implement .debug_info for type '{}'", .{ty.fmtDebug()});
573 log.debug("TODO implement .debug_info for type '{}'", .{ty.fmt(self.mod)});
574574 try dbg_info_buffer.append(@enumToInt(AbbrevKind.pad1));
575575 },
576576 }
......@@ -1055,6 +1055,10 @@ pub fn commitDeclState(
10551055 },
10561056 }
10571057 {
1058 log.debug("relocating subprogram high PC value: {x} => {x}", .{
1059 self.getRelocDbgInfoSubprogramHighPC(),
1060 sym_size,
1061 });
10581062 const ptr = dbg_info_buffer.items[self.getRelocDbgInfoSubprogramHighPC()..][0..4];
10591063 mem.writeInt(u32, ptr, @intCast(u32, sym_size), target_endian);
10601064 }
......@@ -1263,7 +1267,12 @@ pub fn commitDeclState(
12631267 } else {
12641268 const atom = self.getAtom(.di_atom, symbol.atom_index);
12651269 const value = atom.off + symbol.offset + reloc.addend;
1266 log.debug("{x}: [() => {x}] (%{d}, '{}')", .{ reloc.offset, value, target, ty.fmtDebug() });
1270 log.debug("{x}: [() => {x}] (%{d}, '{}')", .{
1271 reloc.offset,
1272 value,
1273 target,
1274 ty.fmt(module),
1275 });
12671276 mem.writeInt(
12681277 u32,
12691278 dbg_info_buffer.items[reloc.offset..][0..@sizeOf(u32)],
src/link/MachO.zig+17-7
......@@ -2070,8 +2070,6 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
20702070 self.freeUnnamedConsts(decl_index);
20712071 Atom.freeRelocations(self, atom_index);
20722072
2073 const atom = self.getAtom(atom_index);
2074
20752073 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
20762074 defer code_buffer.deinit();
20772075
......@@ -2100,7 +2098,13 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
21002098 const addr = try self.updateDeclCode(decl_index, code);
21012099
21022100 if (decl_state) |*ds| {
2103 try self.d_sym.?.dwarf.commitDeclState(module, decl_index, addr, atom.size, ds);
2101 try self.d_sym.?.dwarf.commitDeclState(
2102 module,
2103 decl_index,
2104 addr,
2105 self.getAtom(atom_index).size,
2106 ds,
2107 );
21042108 }
21052109
21062110 // 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)
21962200 }
21972201
21982202 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
2203 const sym_index = self.getAtom(atom_index).getSymbolIndex().?;
21992204 Atom.freeRelocations(self, atom_index);
2200 const atom = self.getAtom(atom_index);
22012205
22022206 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
22032207 defer code_buffer.deinit();
......@@ -2216,14 +2220,14 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
22162220 }, &code_buffer, .{
22172221 .dwarf = ds,
22182222 }, .{
2219 .parent_atom_index = atom.getSymbolIndex().?,
2223 .parent_atom_index = sym_index,
22202224 })
22212225 else
22222226 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
22232227 .ty = decl.ty,
22242228 .val = decl_val,
22252229 }, &code_buffer, .none, .{
2226 .parent_atom_index = atom.getSymbolIndex().?,
2230 .parent_atom_index = sym_index,
22272231 });
22282232
22292233 var code = switch (res) {
......@@ -2237,7 +2241,13 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
22372241 const addr = try self.updateDeclCode(decl_index, code);
22382242
22392243 if (decl_state) |*ds| {
2240 try self.d_sym.?.dwarf.commitDeclState(module, decl_index, addr, atom.size, ds);
2244 try self.d_sym.?.dwarf.commitDeclState(
2245 module,
2246 decl_index,
2247 addr,
2248 self.getAtom(atom_index).size,
2249 ds,
2250 );
22412251 }
22422252
22432253 // Since we updated the vaddr and the size, each corresponding export symbol also