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 {...@@ -150,7 +150,7 @@ pub const DeclState = struct {
150 .type = ty,150 .type = ty,
151 .offset = undefined,151 .offset = undefined,
152 });152 });
153 log.debug("%{d}: {}", .{ sym_index, ty.fmtDebug() });153 log.debug("%{d}: {}", .{ sym_index, ty.fmt(self.mod) });
154 try self.abbrev_resolver.putNoClobberContext(self.gpa, ty, sym_index, .{154 try self.abbrev_resolver.putNoClobberContext(self.gpa, ty, sym_index, .{
155 .mod = self.mod,155 .mod = self.mod,
156 });156 });
...@@ -570,7 +570,7 @@ pub const DeclState = struct {...@@ -570,7 +570,7 @@ pub const DeclState = struct {
570 try dbg_info_buffer.append(0);570 try dbg_info_buffer.append(0);
571 },571 },
572 else => {572 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)});
574 try dbg_info_buffer.append(@enumToInt(AbbrevKind.pad1));574 try dbg_info_buffer.append(@enumToInt(AbbrevKind.pad1));
575 },575 },
576 }576 }
...@@ -1055,6 +1055,10 @@ pub fn commitDeclState(...@@ -1055,6 +1055,10 @@ pub fn commitDeclState(
1055 },1055 },
1056 }1056 }
1057 {1057 {
1058 log.debug("relocating subprogram high PC value: {x} => {x}", .{
1059 self.getRelocDbgInfoSubprogramHighPC(),
1060 sym_size,
1061 });
1058 const ptr = dbg_info_buffer.items[self.getRelocDbgInfoSubprogramHighPC()..][0..4];1062 const ptr = dbg_info_buffer.items[self.getRelocDbgInfoSubprogramHighPC()..][0..4];
1059 mem.writeInt(u32, ptr, @intCast(u32, sym_size), target_endian);1063 mem.writeInt(u32, ptr, @intCast(u32, sym_size), target_endian);
1060 }1064 }
...@@ -1263,7 +1267,12 @@ pub fn commitDeclState(...@@ -1263,7 +1267,12 @@ pub fn commitDeclState(
1263 } else {1267 } else {
1264 const atom = self.getAtom(.di_atom, symbol.atom_index);1268 const atom = self.getAtom(.di_atom, symbol.atom_index);
1265 const value = atom.off + symbol.offset + reloc.addend;1269 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 });
1267 mem.writeInt(1276 mem.writeInt(
1268 u32,1277 u32,
1269 dbg_info_buffer.items[reloc.offset..][0..@sizeOf(u32)],1278 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...@@ -2070,8 +2070,6 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
2070 self.freeUnnamedConsts(decl_index);2070 self.freeUnnamedConsts(decl_index);
2071 Atom.freeRelocations(self, atom_index);2071 Atom.freeRelocations(self, atom_index);
20722072
2073 const atom = self.getAtom(atom_index);
2074
2075 var code_buffer = std.ArrayList(u8).init(self.base.allocator);2073 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
2076 defer code_buffer.deinit();2074 defer code_buffer.deinit();
20772075
...@@ -2100,7 +2098,13 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv...@@ -2100,7 +2098,13 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
2100 const addr = try self.updateDeclCode(decl_index, code);2098 const addr = try self.updateDeclCode(decl_index, code);
21012099
2102 if (decl_state) |*ds| {2100 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 );
2104 }2108 }
21052109
2106 // Since we updated the vaddr and the size, each corresponding export symbol also2110 // 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)...@@ -2196,8 +2200,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
2196 }2200 }
21972201
2198 const atom_index = try self.getOrCreateAtomForDecl(decl_index);2202 const atom_index = try self.getOrCreateAtomForDecl(decl_index);
2203 const sym_index = self.getAtom(atom_index).getSymbolIndex().?;
2199 Atom.freeRelocations(self, atom_index);2204 Atom.freeRelocations(self, atom_index);
2200 const atom = self.getAtom(atom_index);
22012205
2202 var code_buffer = std.ArrayList(u8).init(self.base.allocator);2206 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
2203 defer code_buffer.deinit();2207 defer code_buffer.deinit();
...@@ -2216,14 +2220,14 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)...@@ -2216,14 +2220,14 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
2216 }, &code_buffer, .{2220 }, &code_buffer, .{
2217 .dwarf = ds,2221 .dwarf = ds,
2218 }, .{2222 }, .{
2219 .parent_atom_index = atom.getSymbolIndex().?,2223 .parent_atom_index = sym_index,
2220 })2224 })
2221 else2225 else
2222 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{2226 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2223 .ty = decl.ty,2227 .ty = decl.ty,
2224 .val = decl_val,2228 .val = decl_val,
2225 }, &code_buffer, .none, .{2229 }, &code_buffer, .none, .{
2226 .parent_atom_index = atom.getSymbolIndex().?,2230 .parent_atom_index = sym_index,
2227 });2231 });
22282232
2229 var code = switch (res) {2233 var code = switch (res) {
...@@ -2237,7 +2241,13 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)...@@ -2237,7 +2241,13 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
2237 const addr = try self.updateDeclCode(decl_index, code);2241 const addr = try self.updateDeclCode(decl_index, code);
22382242
2239 if (decl_state) |*ds| {2243 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 );
2241 }2251 }
22422252
2243 // Since we updated the vaddr and the size, each corresponding export symbol also2253 // Since we updated the vaddr and the size, each corresponding export symbol also