authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-01 15:03:55+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-01 15:03:55+01:00
log5de2aae63cd75322e58204a6be8df49754e4851a
treec8e61e82649f412b6a7c4b5bb422f9855df61665
parentd98fc53b8fbe479f828114b0276d5290146cc2a3

link: decouple DI atoms from linker atoms, and manage them in Dwarf linker


19 files changed, 663 insertions(+), 665 deletions(-)

src/Compilation.zig+1-1
...@@ -3299,7 +3299,7 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -3299,7 +3299,7 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
3299 const gpa = comp.gpa;3299 const gpa = comp.gpa;
3300 const module = comp.bin_file.options.module.?;3300 const module = comp.bin_file.options.module.?;
3301 const decl = module.declPtr(decl_index);3301 const decl = module.declPtr(decl_index);
3302 comp.bin_file.updateDeclLineNumber(module, decl) catch |err| {3302 comp.bin_file.updateDeclLineNumber(module, decl_index) catch |err| {
3303 try module.failed_decls.ensureUnusedCapacity(gpa, 1);3303 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
3304 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(3304 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
3305 gpa,3305 gpa,
src/Module.zig+6-6
...@@ -5186,12 +5186,12 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -5186,12 +5186,12 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
5186 .coff => {5186 .coff => {
5187 // TODO Implement for COFF5187 // TODO Implement for COFF
5188 },5188 },
5189 .elf => if (decl.fn_link.elf.len != 0) {5189 .elf => {
5190 // TODO Look into detecting when this would be unnecessary by storing enough state5190 // TODO Look into detecting when this would be unnecessary by storing enough state
5191 // in `Decl` to notice that the line number did not change.5191 // in `Decl` to notice that the line number did not change.
5192 comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });5192 comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
5193 },5193 },
5194 .macho => if (decl.fn_link.macho.len != 0) {5194 .macho => {
5195 // TODO Look into detecting when this would be unnecessary by storing enough state5195 // TODO Look into detecting when this would be unnecessary by storing enough state
5196 // in `Decl` to notice that the line number did not change.5196 // in `Decl` to notice that the line number did not change.
5197 comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });5197 comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
...@@ -5285,8 +5285,8 @@ pub fn clearDecl(...@@ -5285,8 +5285,8 @@ pub fn clearDecl(
5285 };5285 };
5286 decl.fn_link = switch (mod.comp.bin_file.tag) {5286 decl.fn_link = switch (mod.comp.bin_file.tag) {
5287 .coff => .{ .coff = {} },5287 .coff => .{ .coff = {} },
5288 .elf => .{ .elf = link.File.Dwarf.SrcFn.empty },5288 .elf => .{ .elf = {} },
5289 .macho => .{ .macho = link.File.Dwarf.SrcFn.empty },5289 .macho => .{ .macho = {} },
5290 .plan9 => .{ .plan9 = {} },5290 .plan9 => .{ .plan9 = {} },
5291 .c => .{ .c = {} },5291 .c => .{ .c = {} },
5292 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },5292 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },
...@@ -5705,8 +5705,8 @@ pub fn allocateNewDecl(...@@ -5705,8 +5705,8 @@ pub fn allocateNewDecl(
5705 },5705 },
5706 .fn_link = switch (mod.comp.bin_file.tag) {5706 .fn_link = switch (mod.comp.bin_file.tag) {
5707 .coff => .{ .coff = {} },5707 .coff => .{ .coff = {} },
5708 .elf => .{ .elf = link.File.Dwarf.SrcFn.empty },5708 .elf => .{ .elf = {} },
5709 .macho => .{ .macho = link.File.Dwarf.SrcFn.empty },5709 .macho => .{ .macho = {} },
5710 .plan9 => .{ .plan9 = {} },5710 .plan9 => .{ .plan9 = {} },
5711 .c => .{ .c = {} },5711 .c => .{ .c = {} },
5712 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },5712 .wasm => .{ .wasm = link.File.Wasm.FnData.empty },
src/arch/aarch64/CodeGen.zig+2-15
...@@ -203,13 +203,7 @@ const DbgInfoReloc = struct {...@@ -203,13 +203,7 @@ const DbgInfoReloc = struct {
203 else => unreachable, // not a possible argument203 else => unreachable, // not a possible argument
204204
205 };205 };
206 try dw.genArgDbgInfo(206 try dw.genArgDbgInfo(reloc.name, reloc.ty, function.mod_fn.owner_decl, loc);
207 reloc.name,
208 reloc.ty,
209 function.bin_file.tag,
210 function.mod_fn.owner_decl,
211 loc,
212 );
213 },207 },
214 .plan9 => {},208 .plan9 => {},
215 .none => {},209 .none => {},
...@@ -255,14 +249,7 @@ const DbgInfoReloc = struct {...@@ -255,14 +249,7 @@ const DbgInfoReloc = struct {
255 break :blk .nop;249 break :blk .nop;
256 },250 },
257 };251 };
258 try dw.genVarDbgInfo(252 try dw.genVarDbgInfo(reloc.name, reloc.ty, function.mod_fn.owner_decl, is_ptr, loc);
259 reloc.name,
260 reloc.ty,
261 function.bin_file.tag,
262 function.mod_fn.owner_decl,
263 is_ptr,
264 loc,
265 );
266 },253 },
267 .plan9 => {},254 .plan9 => {},
268 .none => {},255 .none => {},
src/arch/arm/CodeGen.zig+2-15
...@@ -282,13 +282,7 @@ const DbgInfoReloc = struct {...@@ -282,13 +282,7 @@ const DbgInfoReloc = struct {
282 else => unreachable, // not a possible argument282 else => unreachable, // not a possible argument
283 };283 };
284284
285 try dw.genArgDbgInfo(285 try dw.genArgDbgInfo(reloc.name, reloc.ty, function.mod_fn.owner_decl, loc);
286 reloc.name,
287 reloc.ty,
288 function.bin_file.tag,
289 function.mod_fn.owner_decl,
290 loc,
291 );
292 },286 },
293 .plan9 => {},287 .plan9 => {},
294 .none => {},288 .none => {},
...@@ -331,14 +325,7 @@ const DbgInfoReloc = struct {...@@ -331,14 +325,7 @@ const DbgInfoReloc = struct {
331 break :blk .nop;325 break :blk .nop;
332 },326 },
333 };327 };
334 try dw.genVarDbgInfo(328 try dw.genVarDbgInfo(reloc.name, reloc.ty, function.mod_fn.owner_decl, is_ptr, loc);
335 reloc.name,
336 reloc.ty,
337 function.bin_file.tag,
338 function.mod_fn.owner_decl,
339 is_ptr,
340 loc,
341 );
342 },329 },
343 .plan9 => {},330 .plan9 => {},
344 .none => {},331 .none => {},
src/arch/riscv64/CodeGen.zig+3-7
...@@ -1615,13 +1615,9 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {...@@ -1615,13 +1615,9 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
16151615
1616 switch (self.debug_output) {1616 switch (self.debug_output) {
1617 .dwarf => |dw| switch (mcv) {1617 .dwarf => |dw| switch (mcv) {
1618 .register => |reg| try dw.genArgDbgInfo(1618 .register => |reg| try dw.genArgDbgInfo(name, ty, self.mod_fn.owner_decl, .{
1619 name,1619 .register = reg.dwarfLocOp(),
1620 ty,1620 }),
1621 self.bin_file.tag,
1622 self.mod_fn.owner_decl,
1623 .{ .register = reg.dwarfLocOp() },
1624 ),
1625 .stack_offset => {},1621 .stack_offset => {},
1626 else => {},1622 else => {},
1627 },1623 },
src/arch/sparc64/CodeGen.zig+3-7
...@@ -3412,13 +3412,9 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {...@@ -3412,13 +3412,9 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
34123412
3413 switch (self.debug_output) {3413 switch (self.debug_output) {
3414 .dwarf => |dw| switch (mcv) {3414 .dwarf => |dw| switch (mcv) {
3415 .register => |reg| try dw.genArgDbgInfo(3415 .register => |reg| try dw.genArgDbgInfo(name, ty, self.mod_fn.owner_decl, .{
3416 name,3416 .register = reg.dwarfLocOp(),
3417 ty,3417 }),
3418 self.bin_file.tag,
3419 self.mod_fn.owner_decl,
3420 .{ .register = reg.dwarfLocOp() },
3421 ),
3422 else => {},3418 else => {},
3423 },3419 },
3424 else => {},3420 else => {},
src/arch/wasm/CodeGen.zig+2-2
...@@ -2475,7 +2475,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2475,7 +2475,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2475 .dwarf => |dwarf| {2475 .dwarf => |dwarf| {
2476 const src_index = func.air.instructions.items(.data)[inst].arg.src_index;2476 const src_index = func.air.instructions.items(.data)[inst].arg.src_index;
2477 const name = func.mod_fn.getParamName(func.bin_file.base.options.module.?, src_index);2477 const name = func.mod_fn.getParamName(func.bin_file.base.options.module.?, src_index);
2478 try dwarf.genArgDbgInfo(name, arg_ty, .wasm, func.mod_fn.owner_decl, .{2478 try dwarf.genArgDbgInfo(name, arg_ty, func.mod_fn.owner_decl, .{
2479 .wasm_local = arg.local.value,2479 .wasm_local = arg.local.value,
2480 });2480 });
2481 },2481 },
...@@ -5539,7 +5539,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {...@@ -5539,7 +5539,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void {
5539 break :blk .nop;5539 break :blk .nop;
5540 },5540 },
5541 };5541 };
5542 try func.debug_output.dwarf.genVarDbgInfo(name, ty, .wasm, func.mod_fn.owner_decl, is_ptr, loc);5542 try func.debug_output.dwarf.genVarDbgInfo(name, ty, func.mod_fn.owner_decl, is_ptr, loc);
55435543
5544 func.finishAir(inst, .none, &.{});5544 func.finishAir(inst, .none, &.{});
5545}5545}
src/arch/x86_64/CodeGen.zig+2-2
...@@ -3836,7 +3836,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {...@@ -3836,7 +3836,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void {
3836 },3836 },
3837 else => unreachable, // not a valid function parameter3837 else => unreachable, // not a valid function parameter
3838 };3838 };
3839 try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc);3839 try dw.genArgDbgInfo(name, ty, self.mod_fn.owner_decl, loc);
3840 },3840 },
3841 .plan9 => {},3841 .plan9 => {},
3842 .none => {},3842 .none => {},
...@@ -3876,7 +3876,7 @@ fn genVarDbgInfo(...@@ -3876,7 +3876,7 @@ fn genVarDbgInfo(
3876 break :blk .nop;3876 break :blk .nop;
3877 },3877 },
3878 };3878 };
3879 try dw.genVarDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, is_ptr, loc);3879 try dw.genVarDbgInfo(name, ty, self.mod_fn.owner_decl, is_ptr, loc);
3880 },3880 },
3881 .plan9 => {},3881 .plan9 => {},
3882 .none => {},3882 .none => {},
src/link.zig+12-11
...@@ -273,9 +273,9 @@ pub const File = struct {...@@ -273,9 +273,9 @@ pub const File = struct {
273 };273 };
274274
275 pub const LinkFn = union {275 pub const LinkFn = union {
276 elf: Dwarf.SrcFn,276 elf: void,
277 coff: Coff.SrcFn,277 coff: void,
278 macho: Dwarf.SrcFn,278 macho: void,
279 plan9: void,279 plan9: void,
280 c: void,280 c: void,
281 wasm: Wasm.FnData,281 wasm: Wasm.FnData,
...@@ -580,22 +580,23 @@ pub const File = struct {...@@ -580,22 +580,23 @@ pub const File = struct {
580 }580 }
581 }581 }
582582
583 pub fn updateDeclLineNumber(base: *File, module: *Module, decl: *Module.Decl) UpdateDeclError!void {583 pub fn updateDeclLineNumber(base: *File, module: *Module, decl_index: Module.Decl.Index) UpdateDeclError!void {
584 const decl = module.declPtr(decl_index);
584 log.debug("updateDeclLineNumber {*} ({s}), line={}", .{585 log.debug("updateDeclLineNumber {*} ({s}), line={}", .{
585 decl, decl.name, decl.src_line + 1,586 decl, decl.name, decl.src_line + 1,
586 });587 });
587 assert(decl.has_tv);588 assert(decl.has_tv);
588 if (build_options.only_c) {589 if (build_options.only_c) {
589 assert(base.tag == .c);590 assert(base.tag == .c);
590 return @fieldParentPtr(C, "base", base).updateDeclLineNumber(module, decl);591 return @fieldParentPtr(C, "base", base).updateDeclLineNumber(module, decl_index);
591 }592 }
592 switch (base.tag) {593 switch (base.tag) {
593 .coff => return @fieldParentPtr(Coff, "base", base).updateDeclLineNumber(module, decl),594 .coff => return @fieldParentPtr(Coff, "base", base).updateDeclLineNumber(module, decl_index),
594 .elf => return @fieldParentPtr(Elf, "base", base).updateDeclLineNumber(module, decl),595 .elf => return @fieldParentPtr(Elf, "base", base).updateDeclLineNumber(module, decl_index),
595 .macho => return @fieldParentPtr(MachO, "base", base).updateDeclLineNumber(module, decl),596 .macho => return @fieldParentPtr(MachO, "base", base).updateDeclLineNumber(module, decl_index),
596 .c => return @fieldParentPtr(C, "base", base).updateDeclLineNumber(module, decl),597 .c => return @fieldParentPtr(C, "base", base).updateDeclLineNumber(module, decl_index),
597 .wasm => return @fieldParentPtr(Wasm, "base", base).updateDeclLineNumber(module, decl),598 .wasm => return @fieldParentPtr(Wasm, "base", base).updateDeclLineNumber(module, decl_index),
598 .plan9 => return @fieldParentPtr(Plan9, "base", base).updateDeclLineNumber(module, decl),599 .plan9 => return @fieldParentPtr(Plan9, "base", base).updateDeclLineNumber(module, decl_index),
599 .spirv, .nvptx => {},600 .spirv, .nvptx => {},
600 }601 }
601 }602 }
src/link/C.zig+2-2
...@@ -219,12 +219,12 @@ pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !voi...@@ -219,12 +219,12 @@ pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !voi
219 code.shrinkAndFree(module.gpa, code.items.len);219 code.shrinkAndFree(module.gpa, code.items.len);
220}220}
221221
222pub fn updateDeclLineNumber(self: *C, module: *Module, decl: *Module.Decl) !void {222pub fn updateDeclLineNumber(self: *C, module: *Module, decl_index: Module.Decl.Index) !void {
223 // The C backend does not have the ability to fix line numbers without re-generating223 // The C backend does not have the ability to fix line numbers without re-generating
224 // the entire Decl.224 // the entire Decl.
225 _ = self;225 _ = self;
226 _ = module;226 _ = module;
227 _ = decl;227 _ = decl_index;
228}228}
229229
230pub fn flush(self: *C, comp: *Compilation, prog_node: *std.Progress.Node) !void {230pub fn flush(self: *C, comp: *Compilation, prog_node: *std.Progress.Node) !void {
src/link/Coff.zig+2-3
...@@ -195,7 +195,6 @@ pub const PtrWidth = enum {...@@ -195,7 +195,6 @@ pub const PtrWidth = enum {
195 };195 };
196 }196 }
197};197};
198pub const SrcFn = void;
199198
200pub const SymbolWithLoc = struct {199pub const SymbolWithLoc = struct {
201 // Index into the respective symbol table.200 // Index into the respective symbol table.
...@@ -1545,10 +1544,10 @@ pub fn getGlobalSymbol(self: *Coff, name: []const u8) !u32 {...@@ -1545,10 +1544,10 @@ pub fn getGlobalSymbol(self: *Coff, name: []const u8) !u32 {
1545 return global_index;1544 return global_index;
1546}1545}
15471546
1548pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !void {1547pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl_index: Module.Decl.Index) !void {
1549 _ = self;1548 _ = self;
1550 _ = module;1549 _ = module;
1551 _ = decl;1550 _ = decl_index;
1552 log.debug("TODO implement updateDeclLineNumber", .{});1551 log.debug("TODO implement updateDeclLineNumber", .{});
1553}1552}
15541553
src/link/Dwarf.zig+292-224
...@@ -27,17 +27,21 @@ bin_file: *File,...@@ -27,17 +27,21 @@ bin_file: *File,
27ptr_width: PtrWidth,27ptr_width: PtrWidth,
28target: std.Target,28target: std.Target,
2929
30/// A list of `File.LinkFn` whose Line Number Programs have surplus capacity.30/// A list of `Atom`s whose Line Number Programs have surplus capacity.
31/// This is the same concept as `text_block_free_list`; see those doc comments.31/// This is the same concept as `Section.free_list` in Elf; see those doc comments.
32dbg_line_fn_free_list: std.AutoHashMapUnmanaged(*SrcFn, void) = .{},32src_fn_free_list: std.AutoHashMapUnmanaged(Atom.Index, void) = .{},
33dbg_line_fn_first: ?*SrcFn = null,33src_fn_first_index: ?Atom.Index = null,
34dbg_line_fn_last: ?*SrcFn = null,34src_fn_last_index: ?Atom.Index = null,
35src_fns: std.ArrayListUnmanaged(Atom) = .{},
36src_fn_decls: AtomTable = .{},
3537
36/// A list of `Atom`s whose corresponding .debug_info tags have surplus capacity.38/// A list of `Atom`s whose corresponding .debug_info tags have surplus capacity.
37/// This is the same concept as `text_block_free_list`; see those doc comments.39/// This is the same concept as `text_block_free_list`; see those doc comments.
38atom_free_list: std.AutoHashMapUnmanaged(*Atom, void) = .{},40di_atom_free_list: std.AutoHashMapUnmanaged(Atom.Index, void) = .{},
39atom_first: ?*Atom = null,41di_atom_first_index: ?Atom.Index = null,
40atom_last: ?*Atom = null,42di_atom_last_index: ?Atom.Index = null,
43di_atoms: std.ArrayListUnmanaged(Atom) = .{},
44di_atom_decls: AtomTable = .{},
4145
42abbrev_table_offset: ?u64 = null,46abbrev_table_offset: ?u64 = null,
4347
...@@ -51,22 +55,23 @@ strtab: StringTable(.strtab) = .{},...@@ -51,22 +55,23 @@ strtab: StringTable(.strtab) = .{},
51/// * []file_names55/// * []file_names
52di_files: std.AutoArrayHashMapUnmanaged(*const Module.File, void) = .{},56di_files: std.AutoArrayHashMapUnmanaged(*const Module.File, void) = .{},
5357
54/// List of atoms that are owned directly by the DWARF module.
55/// TODO convert links in DebugInfoAtom into indices and make
56/// sure every atom is owned by this module.
57managed_atoms: std.ArrayListUnmanaged(*Atom) = .{},
58
59global_abbrev_relocs: std.ArrayListUnmanaged(AbbrevRelocation) = .{},58global_abbrev_relocs: std.ArrayListUnmanaged(AbbrevRelocation) = .{},
6059
61pub const Atom = struct {60const AtomTable = std.AutoHashMapUnmanaged(Module.Decl.Index, Atom.Index);
62 /// Previous/next linked list pointers.61
63 /// This is the linked list node for this Decl's corresponding .debug_info tag.62const Atom = struct {
64 prev: ?*Atom,63 /// Offset into .debug_info pointing to the tag for this Decl, or
65 next: ?*Atom,64 /// offset from the beginning of the Debug Line Program header that contains this function.
66 /// Offset into .debug_info pointing to the tag for this Decl.
67 off: u32,65 off: u32,
68 /// Size of the .debug_info tag for this Decl, not including padding.66 /// Size of the .debug_info tag for this Decl, not including padding, or
67 /// size of the line number program component belonging to this function, not
68 /// including padding.
69 len: u32,69 len: u32,
70
71 prev_index: ?Index,
72 next_index: ?Index,
73
74 pub const Index = u32;
70};75};
7176
72/// Represents state of the analysed Decl.77/// Represents state of the analysed Decl.
...@@ -76,6 +81,7 @@ pub const Atom = struct {...@@ -76,6 +81,7 @@ pub const Atom = struct {
76pub const DeclState = struct {81pub const DeclState = struct {
77 gpa: Allocator,82 gpa: Allocator,
78 mod: *Module,83 mod: *Module,
84 di_atom_decls: *const AtomTable,
79 dbg_line: std.ArrayList(u8),85 dbg_line: std.ArrayList(u8),
80 dbg_info: std.ArrayList(u8),86 dbg_info: std.ArrayList(u8),
81 abbrev_type_arena: std.heap.ArenaAllocator,87 abbrev_type_arena: std.heap.ArenaAllocator,
...@@ -89,10 +95,11 @@ pub const DeclState = struct {...@@ -89,10 +95,11 @@ pub const DeclState = struct {
89 abbrev_relocs: std.ArrayListUnmanaged(AbbrevRelocation) = .{},95 abbrev_relocs: std.ArrayListUnmanaged(AbbrevRelocation) = .{},
90 exprloc_relocs: std.ArrayListUnmanaged(ExprlocRelocation) = .{},96 exprloc_relocs: std.ArrayListUnmanaged(ExprlocRelocation) = .{},
9197
92 fn init(gpa: Allocator, mod: *Module) DeclState {98 fn init(gpa: Allocator, mod: *Module, di_atom_decls: *const AtomTable) DeclState {
93 return .{99 return .{
94 .gpa = gpa,100 .gpa = gpa,
95 .mod = mod,101 .mod = mod,
102 .di_atom_decls = di_atom_decls,
96 .dbg_line = std.ArrayList(u8).init(gpa),103 .dbg_line = std.ArrayList(u8).init(gpa),
97 .dbg_info = std.ArrayList(u8).init(gpa),104 .dbg_info = std.ArrayList(u8).init(gpa),
98 .abbrev_type_arena = std.heap.ArenaAllocator.init(gpa),105 .abbrev_type_arena = std.heap.ArenaAllocator.init(gpa),
...@@ -120,11 +127,11 @@ pub const DeclState = struct {...@@ -120,11 +127,11 @@ pub const DeclState = struct {
120127
121 /// Adds local type relocation of the form: @offset => @this + addend128 /// Adds local type relocation of the form: @offset => @this + addend
122 /// @this signifies the offset within the .debug_abbrev section of the containing atom.129 /// @this signifies the offset within the .debug_abbrev section of the containing atom.
123 fn addTypeRelocLocal(self: *DeclState, atom: *const Atom, offset: u32, addend: u32) !void {130 fn addTypeRelocLocal(self: *DeclState, atom_index: Atom.Index, offset: u32, addend: u32) !void {
124 log.debug("{x}: @this + {x}", .{ offset, addend });131 log.debug("{x}: @this + {x}", .{ offset, addend });
125 try self.abbrev_relocs.append(self.gpa, .{132 try self.abbrev_relocs.append(self.gpa, .{
126 .target = null,133 .target = null,
127 .atom = atom,134 .atom_index = atom_index,
128 .offset = offset,135 .offset = offset,
129 .addend = addend,136 .addend = addend,
130 });137 });
...@@ -133,13 +140,13 @@ pub const DeclState = struct {...@@ -133,13 +140,13 @@ pub const DeclState = struct {
133 /// Adds global type relocation of the form: @offset => @symbol + 0140 /// Adds global type relocation of the form: @offset => @symbol + 0
134 /// @symbol signifies a type abbreviation posititioned somewhere in the .debug_abbrev section141 /// @symbol signifies a type abbreviation posititioned somewhere in the .debug_abbrev section
135 /// which we use as our target of the relocation.142 /// which we use as our target of the relocation.
136 fn addTypeRelocGlobal(self: *DeclState, atom: *const Atom, ty: Type, offset: u32) !void {143 fn addTypeRelocGlobal(self: *DeclState, atom_index: Atom.Index, ty: Type, offset: u32) !void {
137 const resolv = self.abbrev_resolver.getContext(ty, .{144 const resolv = self.abbrev_resolver.getContext(ty, .{
138 .mod = self.mod,145 .mod = self.mod,
139 }) orelse blk: {146 }) orelse blk: {
140 const sym_index = @intCast(u32, self.abbrev_table.items.len);147 const sym_index = @intCast(u32, self.abbrev_table.items.len);
141 try self.abbrev_table.append(self.gpa, .{148 try self.abbrev_table.append(self.gpa, .{
142 .atom = atom,149 .atom_index = atom_index,
143 .type = ty,150 .type = ty,
144 .offset = undefined,151 .offset = undefined,
145 });152 });
...@@ -154,7 +161,7 @@ pub const DeclState = struct {...@@ -154,7 +161,7 @@ pub const DeclState = struct {
154 log.debug("{x}: %{d} + 0", .{ offset, resolv });161 log.debug("{x}: %{d} + 0", .{ offset, resolv });
155 try self.abbrev_relocs.append(self.gpa, .{162 try self.abbrev_relocs.append(self.gpa, .{
156 .target = resolv,163 .target = resolv,
157 .atom = atom,164 .atom_index = atom_index,
158 .offset = offset,165 .offset = offset,
159 .addend = 0,166 .addend = 0,
160 });167 });
...@@ -163,7 +170,7 @@ pub const DeclState = struct {...@@ -163,7 +170,7 @@ pub const DeclState = struct {
163 fn addDbgInfoType(170 fn addDbgInfoType(
164 self: *DeclState,171 self: *DeclState,
165 module: *Module,172 module: *Module,
166 atom: *Atom,173 atom_index: Atom.Index,
167 ty: Type,174 ty: Type,
168 ) error{OutOfMemory}!void {175 ) error{OutOfMemory}!void {
169 const arena = self.abbrev_type_arena.allocator();176 const arena = self.abbrev_type_arena.allocator();
...@@ -228,7 +235,7 @@ pub const DeclState = struct {...@@ -228,7 +235,7 @@ pub const DeclState = struct {
228 // DW.AT.type, DW.FORM.ref4235 // DW.AT.type, DW.FORM.ref4
229 var index = dbg_info_buffer.items.len;236 var index = dbg_info_buffer.items.len;
230 try dbg_info_buffer.resize(index + 4);237 try dbg_info_buffer.resize(index + 4);
231 try self.addTypeRelocGlobal(atom, Type.bool, @intCast(u32, index));238 try self.addTypeRelocGlobal(atom_index, Type.bool, @intCast(u32, index));
232 // DW.AT.data_member_location, DW.FORM.sdata239 // DW.AT.data_member_location, DW.FORM.sdata
233 try dbg_info_buffer.ensureUnusedCapacity(6);240 try dbg_info_buffer.ensureUnusedCapacity(6);
234 dbg_info_buffer.appendAssumeCapacity(0);241 dbg_info_buffer.appendAssumeCapacity(0);
...@@ -240,7 +247,7 @@ pub const DeclState = struct {...@@ -240,7 +247,7 @@ pub const DeclState = struct {
240 // DW.AT.type, DW.FORM.ref4247 // DW.AT.type, DW.FORM.ref4
241 index = dbg_info_buffer.items.len;248 index = dbg_info_buffer.items.len;
242 try dbg_info_buffer.resize(index + 4);249 try dbg_info_buffer.resize(index + 4);
243 try self.addTypeRelocGlobal(atom, payload_ty, @intCast(u32, index));250 try self.addTypeRelocGlobal(atom_index, payload_ty, @intCast(u32, index));
244 // DW.AT.data_member_location, DW.FORM.sdata251 // DW.AT.data_member_location, DW.FORM.sdata
245 const offset = abi_size - payload_ty.abiSize(target);252 const offset = abi_size - payload_ty.abiSize(target);
246 try leb128.writeULEB128(dbg_info_buffer.writer(), offset);253 try leb128.writeULEB128(dbg_info_buffer.writer(), offset);
...@@ -271,7 +278,7 @@ pub const DeclState = struct {...@@ -271,7 +278,7 @@ pub const DeclState = struct {
271 try dbg_info_buffer.resize(index + 4);278 try dbg_info_buffer.resize(index + 4);
272 var buf = try arena.create(Type.SlicePtrFieldTypeBuffer);279 var buf = try arena.create(Type.SlicePtrFieldTypeBuffer);
273 const ptr_ty = ty.slicePtrFieldType(buf);280 const ptr_ty = ty.slicePtrFieldType(buf);
274 try self.addTypeRelocGlobal(atom, ptr_ty, @intCast(u32, index));281 try self.addTypeRelocGlobal(atom_index, ptr_ty, @intCast(u32, index));
275 // DW.AT.data_member_location, DW.FORM.sdata282 // DW.AT.data_member_location, DW.FORM.sdata
276 try dbg_info_buffer.ensureUnusedCapacity(6);283 try dbg_info_buffer.ensureUnusedCapacity(6);
277 dbg_info_buffer.appendAssumeCapacity(0);284 dbg_info_buffer.appendAssumeCapacity(0);
...@@ -283,7 +290,7 @@ pub const DeclState = struct {...@@ -283,7 +290,7 @@ pub const DeclState = struct {
283 // DW.AT.type, DW.FORM.ref4290 // DW.AT.type, DW.FORM.ref4
284 index = dbg_info_buffer.items.len;291 index = dbg_info_buffer.items.len;
285 try dbg_info_buffer.resize(index + 4);292 try dbg_info_buffer.resize(index + 4);
286 try self.addTypeRelocGlobal(atom, Type.usize, @intCast(u32, index));293 try self.addTypeRelocGlobal(atom_index, Type.usize, @intCast(u32, index));
287 // DW.AT.data_member_location, DW.FORM.sdata294 // DW.AT.data_member_location, DW.FORM.sdata
288 try dbg_info_buffer.ensureUnusedCapacity(2);295 try dbg_info_buffer.ensureUnusedCapacity(2);
289 dbg_info_buffer.appendAssumeCapacity(ptr_bytes);296 dbg_info_buffer.appendAssumeCapacity(ptr_bytes);
...@@ -295,7 +302,7 @@ pub const DeclState = struct {...@@ -295,7 +302,7 @@ pub const DeclState = struct {
295 // DW.AT.type, DW.FORM.ref4302 // DW.AT.type, DW.FORM.ref4
296 const index = dbg_info_buffer.items.len;303 const index = dbg_info_buffer.items.len;
297 try dbg_info_buffer.resize(index + 4);304 try dbg_info_buffer.resize(index + 4);
298 try self.addTypeRelocGlobal(atom, ty.childType(), @intCast(u32, index));305 try self.addTypeRelocGlobal(atom_index, ty.childType(), @intCast(u32, index));
299 }306 }
300 },307 },
301 .Array => {308 .Array => {
...@@ -306,13 +313,13 @@ pub const DeclState = struct {...@@ -306,13 +313,13 @@ pub const DeclState = struct {
306 // DW.AT.type, DW.FORM.ref4313 // DW.AT.type, DW.FORM.ref4
307 var index = dbg_info_buffer.items.len;314 var index = dbg_info_buffer.items.len;
308 try dbg_info_buffer.resize(index + 4);315 try dbg_info_buffer.resize(index + 4);
309 try self.addTypeRelocGlobal(atom, ty.childType(), @intCast(u32, index));316 try self.addTypeRelocGlobal(atom_index, ty.childType(), @intCast(u32, index));
310 // DW.AT.subrange_type317 // DW.AT.subrange_type
311 try dbg_info_buffer.append(@enumToInt(AbbrevKind.array_dim));318 try dbg_info_buffer.append(@enumToInt(AbbrevKind.array_dim));
312 // DW.AT.type, DW.FORM.ref4319 // DW.AT.type, DW.FORM.ref4
313 index = dbg_info_buffer.items.len;320 index = dbg_info_buffer.items.len;
314 try dbg_info_buffer.resize(index + 4);321 try dbg_info_buffer.resize(index + 4);
315 try self.addTypeRelocGlobal(atom, Type.usize, @intCast(u32, index));322 try self.addTypeRelocGlobal(atom_index, Type.usize, @intCast(u32, index));
316 // DW.AT.count, DW.FORM.udata323 // DW.AT.count, DW.FORM.udata
317 const len = ty.arrayLenIncludingSentinel();324 const len = ty.arrayLenIncludingSentinel();
318 try leb128.writeULEB128(dbg_info_buffer.writer(), len);325 try leb128.writeULEB128(dbg_info_buffer.writer(), len);
...@@ -340,7 +347,7 @@ pub const DeclState = struct {...@@ -340,7 +347,7 @@ pub const DeclState = struct {
340 // DW.AT.type, DW.FORM.ref4347 // DW.AT.type, DW.FORM.ref4
341 var index = dbg_info_buffer.items.len;348 var index = dbg_info_buffer.items.len;
342 try dbg_info_buffer.resize(index + 4);349 try dbg_info_buffer.resize(index + 4);
343 try self.addTypeRelocGlobal(atom, field, @intCast(u32, index));350 try self.addTypeRelocGlobal(atom_index, field, @intCast(u32, index));
344 // DW.AT.data_member_location, DW.FORM.sdata351 // DW.AT.data_member_location, DW.FORM.sdata
345 const field_off = ty.structFieldOffset(field_index, target);352 const field_off = ty.structFieldOffset(field_index, target);
346 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);353 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
...@@ -372,7 +379,7 @@ pub const DeclState = struct {...@@ -372,7 +379,7 @@ pub const DeclState = struct {
372 // DW.AT.type, DW.FORM.ref4379 // DW.AT.type, DW.FORM.ref4
373 var index = dbg_info_buffer.items.len;380 var index = dbg_info_buffer.items.len;
374 try dbg_info_buffer.resize(index + 4);381 try dbg_info_buffer.resize(index + 4);
375 try self.addTypeRelocGlobal(atom, field.ty, @intCast(u32, index));382 try self.addTypeRelocGlobal(atom_index, field.ty, @intCast(u32, index));
376 // DW.AT.data_member_location, DW.FORM.sdata383 // DW.AT.data_member_location, DW.FORM.sdata
377 const field_off = ty.structFieldOffset(field_index, target);384 const field_off = ty.structFieldOffset(field_index, target);
378 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);385 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
...@@ -455,7 +462,7 @@ pub const DeclState = struct {...@@ -455,7 +462,7 @@ pub const DeclState = struct {
455 // DW.AT.type, DW.FORM.ref4462 // DW.AT.type, DW.FORM.ref4
456 const inner_union_index = dbg_info_buffer.items.len;463 const inner_union_index = dbg_info_buffer.items.len;
457 try dbg_info_buffer.resize(inner_union_index + 4);464 try dbg_info_buffer.resize(inner_union_index + 4);
458 try self.addTypeRelocLocal(atom, @intCast(u32, inner_union_index), 5);465 try self.addTypeRelocLocal(atom_index, @intCast(u32, inner_union_index), 5);
459 // DW.AT.data_member_location, DW.FORM.sdata466 // DW.AT.data_member_location, DW.FORM.sdata
460 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_offset);467 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_offset);
461 }468 }
...@@ -482,7 +489,7 @@ pub const DeclState = struct {...@@ -482,7 +489,7 @@ pub const DeclState = struct {
482 // DW.AT.type, DW.FORM.ref4489 // DW.AT.type, DW.FORM.ref4
483 const index = dbg_info_buffer.items.len;490 const index = dbg_info_buffer.items.len;
484 try dbg_info_buffer.resize(index + 4);491 try dbg_info_buffer.resize(index + 4);
485 try self.addTypeRelocGlobal(atom, field.ty, @intCast(u32, index));492 try self.addTypeRelocGlobal(atom_index, field.ty, @intCast(u32, index));
486 // DW.AT.data_member_location, DW.FORM.sdata493 // DW.AT.data_member_location, DW.FORM.sdata
487 try dbg_info_buffer.append(0);494 try dbg_info_buffer.append(0);
488 }495 }
...@@ -499,7 +506,7 @@ pub const DeclState = struct {...@@ -499,7 +506,7 @@ pub const DeclState = struct {
499 // DW.AT.type, DW.FORM.ref4506 // DW.AT.type, DW.FORM.ref4
500 const index = dbg_info_buffer.items.len;507 const index = dbg_info_buffer.items.len;
501 try dbg_info_buffer.resize(index + 4);508 try dbg_info_buffer.resize(index + 4);
502 try self.addTypeRelocGlobal(atom, union_obj.tag_ty, @intCast(u32, index));509 try self.addTypeRelocGlobal(atom_index, union_obj.tag_ty, @intCast(u32, index));
503 // DW.AT.data_member_location, DW.FORM.sdata510 // DW.AT.data_member_location, DW.FORM.sdata
504 try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset);511 try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset);
505512
...@@ -542,7 +549,7 @@ pub const DeclState = struct {...@@ -542,7 +549,7 @@ pub const DeclState = struct {
542 // DW.AT.type, DW.FORM.ref4549 // DW.AT.type, DW.FORM.ref4
543 var index = dbg_info_buffer.items.len;550 var index = dbg_info_buffer.items.len;
544 try dbg_info_buffer.resize(index + 4);551 try dbg_info_buffer.resize(index + 4);
545 try self.addTypeRelocGlobal(atom, payload_ty, @intCast(u32, index));552 try self.addTypeRelocGlobal(atom_index, payload_ty, @intCast(u32, index));
546 // DW.AT.data_member_location, DW.FORM.sdata553 // DW.AT.data_member_location, DW.FORM.sdata
547 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_off);554 try leb128.writeULEB128(dbg_info_buffer.writer(), payload_off);
548555
...@@ -555,7 +562,7 @@ pub const DeclState = struct {...@@ -555,7 +562,7 @@ pub const DeclState = struct {
555 // DW.AT.type, DW.FORM.ref4562 // DW.AT.type, DW.FORM.ref4
556 index = dbg_info_buffer.items.len;563 index = dbg_info_buffer.items.len;
557 try dbg_info_buffer.resize(index + 4);564 try dbg_info_buffer.resize(index + 4);
558 try self.addTypeRelocGlobal(atom, error_ty, @intCast(u32, index));565 try self.addTypeRelocGlobal(atom_index, error_ty, @intCast(u32, index));
559 // DW.AT.data_member_location, DW.FORM.sdata566 // DW.AT.data_member_location, DW.FORM.sdata
560 try leb128.writeULEB128(dbg_info_buffer.writer(), error_off);567 try leb128.writeULEB128(dbg_info_buffer.writer(), error_off);
561568
...@@ -588,12 +595,11 @@ pub const DeclState = struct {...@@ -588,12 +595,11 @@ pub const DeclState = struct {
588 self: *DeclState,595 self: *DeclState,
589 name: [:0]const u8,596 name: [:0]const u8,
590 ty: Type,597 ty: Type,
591 tag: File.Tag,
592 owner_decl: Module.Decl.Index,598 owner_decl: Module.Decl.Index,
593 loc: DbgInfoLoc,599 loc: DbgInfoLoc,
594 ) error{OutOfMemory}!void {600 ) error{OutOfMemory}!void {
595 const dbg_info = &self.dbg_info;601 const dbg_info = &self.dbg_info;
596 const atom = getDbgInfoAtom(tag, self.mod, owner_decl);602 const atom_index = self.di_atom_decls.get(owner_decl).?;
597 const name_with_null = name.ptr[0 .. name.len + 1];603 const name_with_null = name.ptr[0 .. name.len + 1];
598604
599 switch (loc) {605 switch (loc) {
...@@ -638,7 +644,7 @@ pub const DeclState = struct {...@@ -638,7 +644,7 @@ pub const DeclState = struct {
638 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);644 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
639 const index = dbg_info.items.len;645 const index = dbg_info.items.len;
640 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4646 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
641 try self.addTypeRelocGlobal(atom, ty, @intCast(u32, index)); // DW.AT.type, DW.FORM.ref4647 try self.addTypeRelocGlobal(atom_index, ty, @intCast(u32, index)); // DW.AT.type, DW.FORM.ref4
642 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string648 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
643 }649 }
644650
...@@ -646,13 +652,12 @@ pub const DeclState = struct {...@@ -646,13 +652,12 @@ pub const DeclState = struct {
646 self: *DeclState,652 self: *DeclState,
647 name: [:0]const u8,653 name: [:0]const u8,
648 ty: Type,654 ty: Type,
649 tag: File.Tag,
650 owner_decl: Module.Decl.Index,655 owner_decl: Module.Decl.Index,
651 is_ptr: bool,656 is_ptr: bool,
652 loc: DbgInfoLoc,657 loc: DbgInfoLoc,
653 ) error{OutOfMemory}!void {658 ) error{OutOfMemory}!void {
654 const dbg_info = &self.dbg_info;659 const dbg_info = &self.dbg_info;
655 const atom = getDbgInfoAtom(tag, self.mod, owner_decl);660 const atom_index = self.di_atom_decls.get(owner_decl).?;
656 const name_with_null = name.ptr[0 .. name.len + 1];661 const name_with_null = name.ptr[0 .. name.len + 1];
657 try dbg_info.append(@enumToInt(AbbrevKind.variable));662 try dbg_info.append(@enumToInt(AbbrevKind.variable));
658 const target = self.mod.getTarget();663 const target = self.mod.getTarget();
...@@ -782,7 +787,7 @@ pub const DeclState = struct {...@@ -782,7 +787,7 @@ pub const DeclState = struct {
782 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);787 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
783 const index = dbg_info.items.len;788 const index = dbg_info.items.len;
784 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4789 try dbg_info.resize(index + 4); // dw.at.type, dw.form.ref4
785 try self.addTypeRelocGlobal(atom, child_ty, @intCast(u32, index));790 try self.addTypeRelocGlobal(atom_index, child_ty, @intCast(u32, index));
786 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string791 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
787 }792 }
788793
...@@ -815,7 +820,7 @@ pub const DeclState = struct {...@@ -815,7 +820,7 @@ pub const DeclState = struct {
815};820};
816821
817pub const AbbrevEntry = struct {822pub const AbbrevEntry = struct {
818 atom: *const Atom,823 atom_index: Atom.Index,
819 type: Type,824 type: Type,
820 offset: u32,825 offset: u32,
821};826};
...@@ -824,7 +829,7 @@ pub const AbbrevRelocation = struct {...@@ -824,7 +829,7 @@ pub const AbbrevRelocation = struct {
824 /// If target is null, we deal with a local relocation that is based on simple offset + addend829 /// If target is null, we deal with a local relocation that is based on simple offset + addend
825 /// only.830 /// only.
826 target: ?u32,831 target: ?u32,
827 atom: *const Atom,832 atom_index: Atom.Index,
828 offset: u32,833 offset: u32,
829 addend: u32,834 addend: u32,
830};835};
...@@ -841,26 +846,6 @@ pub const ExprlocRelocation = struct {...@@ -841,26 +846,6 @@ pub const ExprlocRelocation = struct {
841 offset: u32,846 offset: u32,
842};847};
843848
844pub const SrcFn = struct {
845 /// Offset from the beginning of the Debug Line Program header that contains this function.
846 off: u32,
847 /// Size of the line number program component belonging to this function, not
848 /// including padding.
849 len: u32,
850
851 /// Points to the previous and next neighbors, based on the offset from .debug_line.
852 /// This can be used to find, for example, the capacity of this `SrcFn`.
853 prev: ?*SrcFn,
854 next: ?*SrcFn,
855
856 pub const empty: SrcFn = .{
857 .off = 0,
858 .len = 0,
859 .prev = null,
860 .next = null,
861 };
862};
863
864pub const PtrWidth = enum { p32, p64 };849pub const PtrWidth = enum { p32, p64 };
865850
866pub const AbbrevKind = enum(u8) {851pub const AbbrevKind = enum(u8) {
...@@ -910,16 +895,18 @@ pub fn init(allocator: Allocator, bin_file: *File, target: std.Target) Dwarf {...@@ -910,16 +895,18 @@ pub fn init(allocator: Allocator, bin_file: *File, target: std.Target) Dwarf {
910895
911pub fn deinit(self: *Dwarf) void {896pub fn deinit(self: *Dwarf) void {
912 const gpa = self.allocator;897 const gpa = self.allocator;
913 self.dbg_line_fn_free_list.deinit(gpa);898
914 self.atom_free_list.deinit(gpa);899 self.src_fn_free_list.deinit(gpa);
900 self.src_fns.deinit(gpa);
901 self.src_fn_decls.deinit(gpa);
902
903 self.di_atom_free_list.deinit(gpa);
904 self.di_atoms.deinit(gpa);
905 self.di_atom_decls.deinit(gpa);
906
915 self.strtab.deinit(gpa);907 self.strtab.deinit(gpa);
916 self.di_files.deinit(gpa);908 self.di_files.deinit(gpa);
917 self.global_abbrev_relocs.deinit(gpa);909 self.global_abbrev_relocs.deinit(gpa);
918
919 for (self.managed_atoms.items) |atom| {
920 gpa.destroy(atom);
921 }
922 self.managed_atoms.deinit(gpa);
923}910}
924911
925/// Initializes Decl's state and its matching output buffers.912/// Initializes Decl's state and its matching output buffers.
...@@ -935,15 +922,19 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)...@@ -935,15 +922,19 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
935 log.debug("initDeclState {s}{*}", .{ decl_name, decl });922 log.debug("initDeclState {s}{*}", .{ decl_name, decl });
936923
937 const gpa = self.allocator;924 const gpa = self.allocator;
938 var decl_state = DeclState.init(gpa, mod);925 var decl_state = DeclState.init(gpa, mod, &self.di_atom_decls);
939 errdefer decl_state.deinit();926 errdefer decl_state.deinit();
940 const dbg_line_buffer = &decl_state.dbg_line;927 const dbg_line_buffer = &decl_state.dbg_line;
941 const dbg_info_buffer = &decl_state.dbg_info;928 const dbg_info_buffer = &decl_state.dbg_info;
942929
930 const di_atom_index = try self.getOrCreateAtomForDecl(.di_atom, decl_index);
931
943 assert(decl.has_tv);932 assert(decl.has_tv);
944933
945 switch (decl.ty.zigTypeTag()) {934 switch (decl.ty.zigTypeTag()) {
946 .Fn => {935 .Fn => {
936 _ = try self.getOrCreateAtomForDecl(.src_fn, decl_index);
937
947 // For functions we need to add a prologue to the debug line program.938 // For functions we need to add a prologue to the debug line program.
948 try dbg_line_buffer.ensureTotalCapacity(26);939 try dbg_line_buffer.ensureTotalCapacity(26);
949940
...@@ -1003,8 +994,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)...@@ -1003,8 +994,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: Module.Decl.Index)
1003 dbg_info_buffer.items.len += 4; // DW.AT.high_pc, DW.FORM.data4994 dbg_info_buffer.items.len += 4; // DW.AT.high_pc, DW.FORM.data4
1004 //995 //
1005 if (fn_ret_has_bits) {996 if (fn_ret_has_bits) {
1006 const atom = getDbgInfoAtom(self.bin_file.tag, mod, decl_index);997 try decl_state.addTypeRelocGlobal(di_atom_index, fn_ret_type, @intCast(u32, dbg_info_buffer.items.len));
1007 try decl_state.addTypeRelocGlobal(atom, fn_ret_type, @intCast(u32, dbg_info_buffer.items.len));
1008 dbg_info_buffer.items.len += 4; // DW.AT.type, DW.FORM.ref4998 dbg_info_buffer.items.len += 4; // DW.AT.type, DW.FORM.ref4
1009 }999 }
10101000
...@@ -1076,26 +1066,23 @@ pub fn commitDeclState(...@@ -1076,26 +1066,23 @@ pub fn commitDeclState(
1076 // This logic is nearly identical to the logic below in `updateDeclDebugInfo` for1066 // This logic is nearly identical to the logic below in `updateDeclDebugInfo` for
1077 // `TextBlock` and the .debug_info. If you are editing this logic, you1067 // `TextBlock` and the .debug_info. If you are editing this logic, you
1078 // probably need to edit that logic too.1068 // probably need to edit that logic too.
1079 const src_fn = switch (self.bin_file.tag) {1069 const src_fn_index = self.src_fn_decls.get(decl_index).?;
1080 .elf => &decl.fn_link.elf,1070 const src_fn = self.getAtomPtr(.src_fn, src_fn_index);
1081 .macho => &decl.fn_link.macho,
1082 .wasm => &decl.fn_link.wasm.src_fn,
1083 else => unreachable, // TODO
1084 };
1085 src_fn.len = @intCast(u32, dbg_line_buffer.items.len);1071 src_fn.len = @intCast(u32, dbg_line_buffer.items.len);
10861072
1087 if (self.dbg_line_fn_last) |last| blk: {1073 if (self.src_fn_last_index) |last_index| blk: {
1088 if (src_fn == last) break :blk;1074 if (src_fn_index == last_index) break :blk;
1089 if (src_fn.next) |next| {1075 if (src_fn.next_index) |next_index| {
1076 const next = self.getAtomPtr(.src_fn, next_index);
1090 // Update existing function - non-last item.1077 // Update existing function - non-last item.
1091 if (src_fn.off + src_fn.len + min_nop_size > next.off) {1078 if (src_fn.off + src_fn.len + min_nop_size > next.off) {
1092 // It grew too big, so we move it to a new location.1079 // It grew too big, so we move it to a new location.
1093 if (src_fn.prev) |prev| {1080 if (src_fn.prev_index) |prev_index| {
1094 self.dbg_line_fn_free_list.put(gpa, prev, {}) catch {};1081 self.src_fn_free_list.put(gpa, prev_index, {}) catch {};
1095 prev.next = src_fn.next;1082 self.getAtomPtr(.src_fn, prev_index).next_index = src_fn.next_index;
1096 }1083 }
1097 next.prev = src_fn.prev;1084 next.prev_index = src_fn.prev_index;
1098 src_fn.next = null;1085 src_fn.next_index = null;
1099 // Populate where it used to be with NOPs.1086 // Populate where it used to be with NOPs.
1100 switch (self.bin_file.tag) {1087 switch (self.bin_file.tag) {
1101 .elf => {1088 .elf => {
...@@ -1118,33 +1105,42 @@ pub fn commitDeclState(...@@ -1118,33 +1105,42 @@ pub fn commitDeclState(
1118 else => unreachable,1105 else => unreachable,
1119 }1106 }
1120 // TODO Look at the free list before appending at the end.1107 // TODO Look at the free list before appending at the end.
1121 src_fn.prev = last;1108 src_fn.prev_index = last_index;
1122 last.next = src_fn;1109 const last = self.getAtomPtr(.src_fn, last_index);
1123 self.dbg_line_fn_last = src_fn;1110 last.next_index = src_fn_index;
1111 self.src_fn_last_index = src_fn_index;
11241112
1125 src_fn.off = last.off + padToIdeal(last.len);1113 src_fn.off = last.off + padToIdeal(last.len);
1126 }1114 }
1127 } else if (src_fn.prev == null) {1115 } else if (src_fn.prev_index == null) {
1128 // Append new function.1116 // Append new function.
1129 // TODO Look at the free list before appending at the end.1117 // TODO Look at the free list before appending at the end.
1130 src_fn.prev = last;1118 src_fn.prev_index = last_index;
1131 last.next = src_fn;1119 const last = self.getAtomPtr(.src_fn, last_index);
1132 self.dbg_line_fn_last = src_fn;1120 last.next_index = src_fn_index;
1121 self.src_fn_last_index = src_fn_index;
11331122
1134 src_fn.off = last.off + padToIdeal(last.len);1123 src_fn.off = last.off + padToIdeal(last.len);
1135 }1124 }
1136 } else {1125 } else {
1137 // This is the first function of the Line Number Program.1126 // This is the first function of the Line Number Program.
1138 self.dbg_line_fn_first = src_fn;1127 self.src_fn_first_index = src_fn_index;
1139 self.dbg_line_fn_last = src_fn;1128 self.src_fn_last_index = src_fn_index;
11401129
1141 src_fn.off = padToIdeal(self.dbgLineNeededHeaderBytes(&[0][]u8{}, &[0][]u8{}));1130 src_fn.off = padToIdeal(self.dbgLineNeededHeaderBytes(&[0][]u8{}, &[0][]u8{}));
1142 }1131 }
11431132
1144 const last_src_fn = self.dbg_line_fn_last.?;1133 const last_src_fn_index = self.src_fn_last_index.?;
1134 const last_src_fn = self.getAtom(.src_fn, last_src_fn_index);
1145 const needed_size = last_src_fn.off + last_src_fn.len;1135 const needed_size = last_src_fn.off + last_src_fn.len;
1146 const prev_padding_size: u32 = if (src_fn.prev) |prev| src_fn.off - (prev.off + prev.len) else 0;1136 const prev_padding_size: u32 = if (src_fn.prev_index) |prev_index| blk: {
1147 const next_padding_size: u32 = if (src_fn.next) |next| next.off - (src_fn.off + src_fn.len) else 0;1137 const prev = self.getAtom(.src_fn, prev_index);
1138 break :blk src_fn.off - (prev.off + prev.len);
1139 } else 0;
1140 const next_padding_size: u32 = if (src_fn.next_index) |next_index| blk: {
1141 const next = self.getAtom(.src_fn, next_index);
1142 break :blk next.off - (src_fn.off + src_fn.len);
1143 } else 0;
11481144
1149 // We only have support for one compilation unit so far, so the offsets are directly1145 // We only have support for one compilation unit so far, so the offsets are directly
1150 // from the .debug_line section.1146 // from the .debug_line section.
...@@ -1213,7 +1209,7 @@ pub fn commitDeclState(...@@ -1213,7 +1209,7 @@ pub fn commitDeclState(
1213 if (dbg_info_buffer.items.len == 0)1209 if (dbg_info_buffer.items.len == 0)
1214 return;1210 return;
12151211
1216 const atom = getDbgInfoAtom(self.bin_file.tag, module, decl_index);1212 const di_atom_index = self.di_atom_decls.get(decl_index).?;
1217 if (decl_state.abbrev_table.items.len > 0) {1213 if (decl_state.abbrev_table.items.len > 0) {
1218 // Now we emit the .debug_info types of the Decl. These will count towards the size of1214 // Now we emit the .debug_info types of the Decl. These will count towards the size of
1219 // the buffer, so we have to do it before computing the offset, and we can't perform the actual1215 // the buffer, so we have to do it before computing the offset, and we can't perform the actual
...@@ -1235,12 +1231,12 @@ pub fn commitDeclState(...@@ -1235,12 +1231,12 @@ pub fn commitDeclState(
1235 if (deferred) continue;1231 if (deferred) continue;
12361232
1237 symbol.offset = @intCast(u32, dbg_info_buffer.items.len);1233 symbol.offset = @intCast(u32, dbg_info_buffer.items.len);
1238 try decl_state.addDbgInfoType(module, atom, ty);1234 try decl_state.addDbgInfoType(module, di_atom_index, ty);
1239 }1235 }
1240 }1236 }
12411237
1242 log.debug("updateDeclDebugInfoAllocation for '{s}'", .{decl.name});1238 log.debug("updateDeclDebugInfoAllocation for '{s}'", .{decl.name});
1243 try self.updateDeclDebugInfoAllocation(atom, @intCast(u32, dbg_info_buffer.items.len));1239 try self.updateDeclDebugInfoAllocation(di_atom_index, @intCast(u32, dbg_info_buffer.items.len));
12441240
1245 while (decl_state.abbrev_relocs.popOrNull()) |reloc| {1241 while (decl_state.abbrev_relocs.popOrNull()) |reloc| {
1246 if (reloc.target) |target| {1242 if (reloc.target) |target| {
...@@ -1261,11 +1257,12 @@ pub fn commitDeclState(...@@ -1261,11 +1257,12 @@ pub fn commitDeclState(
1261 try self.global_abbrev_relocs.append(gpa, .{1257 try self.global_abbrev_relocs.append(gpa, .{
1262 .target = null,1258 .target = null,
1263 .offset = reloc.offset,1259 .offset = reloc.offset,
1264 .atom = reloc.atom,1260 .atom_index = reloc.atom_index,
1265 .addend = reloc.addend,1261 .addend = reloc.addend,
1266 });1262 });
1267 } else {1263 } else {
1268 const value = symbol.atom.off + symbol.offset + reloc.addend;1264 const atom = self.getAtom(.di_atom, symbol.atom_index);
1265 const value = atom.off + symbol.offset + reloc.addend;
1269 log.debug("{x}: [() => {x}] (%{d}, '{}')", .{ reloc.offset, value, target, ty.fmtDebug() });1266 log.debug("{x}: [() => {x}] (%{d}, '{}')", .{ reloc.offset, value, target, ty.fmtDebug() });
1270 mem.writeInt(1267 mem.writeInt(
1271 u32,1268 u32,
...@@ -1275,10 +1272,11 @@ pub fn commitDeclState(...@@ -1275,10 +1272,11 @@ pub fn commitDeclState(
1275 );1272 );
1276 }1273 }
1277 } else {1274 } else {
1275 const atom = self.getAtom(.di_atom, reloc.atom_index);
1278 mem.writeInt(1276 mem.writeInt(
1279 u32,1277 u32,
1280 dbg_info_buffer.items[reloc.offset..][0..@sizeOf(u32)],1278 dbg_info_buffer.items[reloc.offset..][0..@sizeOf(u32)],
1281 reloc.atom.off + reloc.offset + reloc.addend,1279 atom.off + reloc.offset + reloc.addend,
1282 target_endian,1280 target_endian,
1283 );1281 );
1284 }1282 }
...@@ -1294,7 +1292,7 @@ pub fn commitDeclState(...@@ -1294,7 +1292,7 @@ pub fn commitDeclState(
1294 .got_load => .got_load,1292 .got_load => .got_load,
1295 },1293 },
1296 .target = reloc.target,1294 .target = reloc.target,
1297 .offset = reloc.offset + atom.off,1295 .offset = reloc.offset + self.getAtom(.di_atom, di_atom_index).off,
1298 .addend = 0,1296 .addend = 0,
1299 .prev_vaddr = 0,1297 .prev_vaddr = 0,
1300 });1298 });
...@@ -1304,10 +1302,10 @@ pub fn commitDeclState(...@@ -1304,10 +1302,10 @@ pub fn commitDeclState(
1304 }1302 }
13051303
1306 log.debug("writeDeclDebugInfo for '{s}", .{decl.name});1304 log.debug("writeDeclDebugInfo for '{s}", .{decl.name});
1307 try self.writeDeclDebugInfo(atom, dbg_info_buffer.items);1305 try self.writeDeclDebugInfo(di_atom_index, dbg_info_buffer.items);
1308}1306}
13091307
1310fn updateDeclDebugInfoAllocation(self: *Dwarf, atom: *Atom, len: u32) !void {1308fn updateDeclDebugInfoAllocation(self: *Dwarf, atom_index: Atom.Index, len: u32) !void {
1311 const tracy = trace(@src());1309 const tracy = trace(@src());
1312 defer tracy.end();1310 defer tracy.end();
13131311
...@@ -1316,19 +1314,21 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom: *Atom, len: u32) !void {...@@ -1316,19 +1314,21 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom: *Atom, len: u32) !void {
1316 // probably need to edit that logic too.1314 // probably need to edit that logic too.
1317 const gpa = self.allocator;1315 const gpa = self.allocator;
13181316
1317 const atom = self.getAtomPtr(.di_atom, atom_index);
1319 atom.len = len;1318 atom.len = len;
1320 if (self.atom_last) |last| blk: {1319 if (self.di_atom_last_index) |last_index| blk: {
1321 if (atom == last) break :blk;1320 if (atom_index == last_index) break :blk;
1322 if (atom.next) |next| {1321 if (atom.next_index) |next_index| {
1322 const next = self.getAtomPtr(.di_atom, next_index);
1323 // Update existing Decl - non-last item.1323 // Update existing Decl - non-last item.
1324 if (atom.off + atom.len + min_nop_size > next.off) {1324 if (atom.off + atom.len + min_nop_size > next.off) {
1325 // It grew too big, so we move it to a new location.1325 // It grew too big, so we move it to a new location.
1326 if (atom.prev) |prev| {1326 if (atom.prev_index) |prev_index| {
1327 self.atom_free_list.put(gpa, prev, {}) catch {};1327 self.di_atom_free_list.put(gpa, prev_index, {}) catch {};
1328 prev.next = atom.next;1328 self.getAtomPtr(.di_atom, prev_index).next_index = atom.next_index;
1329 }1329 }
1330 next.prev = atom.prev;1330 next.prev_index = atom.prev_index;
1331 atom.next = null;1331 atom.next_index = null;
1332 // Populate where it used to be with NOPs.1332 // Populate where it used to be with NOPs.
1333 switch (self.bin_file.tag) {1333 switch (self.bin_file.tag) {
1334 .elf => {1334 .elf => {
...@@ -1351,31 +1351,33 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom: *Atom, len: u32) !void {...@@ -1351,31 +1351,33 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, atom: *Atom, len: u32) !void {
1351 else => unreachable,1351 else => unreachable,
1352 }1352 }
1353 // TODO Look at the free list before appending at the end.1353 // TODO Look at the free list before appending at the end.
1354 atom.prev = last;1354 atom.prev_index = last_index;
1355 last.next = atom;1355 const last = self.getAtomPtr(.di_atom, last_index);
1356 self.atom_last = atom;1356 last.next_index = atom_index;
1357 self.di_atom_last_index = atom_index;
13571358
1358 atom.off = last.off + padToIdeal(last.len);1359 atom.off = last.off + padToIdeal(last.len);
1359 }1360 }
1360 } else if (atom.prev == null) {1361 } else if (atom.prev_index == null) {
1361 // Append new Decl.1362 // Append new Decl.
1362 // TODO Look at the free list before appending at the end.1363 // TODO Look at the free list before appending at the end.
1363 atom.prev = last;1364 atom.prev_index = last_index;
1364 last.next = atom;1365 const last = self.getAtomPtr(.di_atom, last_index);
1365 self.atom_last = atom;1366 last.next_index = atom_index;
1367 self.di_atom_last_index = atom_index;
13661368
1367 atom.off = last.off + padToIdeal(last.len);1369 atom.off = last.off + padToIdeal(last.len);
1368 }1370 }
1369 } else {1371 } else {
1370 // This is the first Decl of the .debug_info1372 // This is the first Decl of the .debug_info
1371 self.atom_first = atom;1373 self.di_atom_first_index = atom_index;
1372 self.atom_last = atom;1374 self.di_atom_last_index = atom_index;
13731375
1374 atom.off = @intCast(u32, padToIdeal(self.dbgInfoHeaderBytes()));1376 atom.off = @intCast(u32, padToIdeal(self.dbgInfoHeaderBytes()));
1375 }1377 }
1376}1378}
13771379
1378fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void {1380fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []const u8) !void {
1379 const tracy = trace(@src());1381 const tracy = trace(@src());
1380 defer tracy.end();1382 defer tracy.end();
13811383
...@@ -1384,14 +1386,22 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void...@@ -1384,14 +1386,22 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void
1384 // probably need to edit that logic too.1386 // probably need to edit that logic too.
1385 const gpa = self.allocator;1387 const gpa = self.allocator;
13861388
1387 const last_decl = self.atom_last.?;1389 const atom = self.getAtom(.di_atom, atom_index);
1390 const last_decl_index = self.di_atom_last_index.?;
1391 const last_decl = self.getAtom(.di_atom, last_decl_index);
1388 // +1 for a trailing zero to end the children of the decl tag.1392 // +1 for a trailing zero to end the children of the decl tag.
1389 const needed_size = last_decl.off + last_decl.len + 1;1393 const needed_size = last_decl.off + last_decl.len + 1;
1390 const prev_padding_size: u32 = if (atom.prev) |prev| atom.off - (prev.off + prev.len) else 0;1394 const prev_padding_size: u32 = if (atom.prev_index) |prev_index| blk: {
1391 const next_padding_size: u32 = if (atom.next) |next| next.off - (atom.off + atom.len) else 0;1395 const prev = self.getAtom(.di_atom, prev_index);
1396 break :blk atom.off - (prev.off + prev.len);
1397 } else 0;
1398 const next_padding_size: u32 = if (atom.next_index) |next_index| blk: {
1399 const next = self.getAtom(.di_atom, next_index);
1400 break :blk next.off - (atom.off + atom.len);
1401 } else 0;
13921402
1393 // To end the children of the decl tag.1403 // To end the children of the decl tag.
1394 const trailing_zero = atom.next == null;1404 const trailing_zero = atom.next_index == null;
13951405
1396 // We only have support for one compilation unit so far, so the offsets are directly1406 // We only have support for one compilation unit so far, so the offsets are directly
1397 // from the .debug_info section.1407 // from the .debug_info section.
...@@ -1459,10 +1469,15 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void...@@ -1459,10 +1469,15 @@ fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void
1459 }1469 }
1460}1470}
14611471
1462pub fn updateDeclLineNumber(self: *Dwarf, decl: *const Module.Decl) !void {1472pub fn updateDeclLineNumber(self: *Dwarf, module: *Module, decl_index: Module.Decl.Index) !void {
1463 const tracy = trace(@src());1473 const tracy = trace(@src());
1464 defer tracy.end();1474 defer tracy.end();
14651475
1476 const atom_index = try self.getOrCreateAtomForDecl(.src_fn, decl_index);
1477 const atom = self.getAtom(.src_fn, atom_index);
1478 if (atom.len == 0) return;
1479
1480 const decl = module.declPtr(decl_index);
1466 const func = decl.val.castTag(.function).?.data;1481 const func = decl.val.castTag(.function).?.data;
1467 log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{1482 log.debug("decl.src_line={d}, func.lbrace_line={d}, func.rbrace_line={d}", .{
1468 decl.src_line,1483 decl.src_line,
...@@ -1477,78 +1492,80 @@ pub fn updateDeclLineNumber(self: *Dwarf, decl: *const Module.Decl) !void {...@@ -1477,78 +1492,80 @@ pub fn updateDeclLineNumber(self: *Dwarf, decl: *const Module.Decl) !void {
1477 .elf => {1492 .elf => {
1478 const elf_file = self.bin_file.cast(File.Elf).?;1493 const elf_file = self.bin_file.cast(File.Elf).?;
1479 const shdr = elf_file.sections.items(.shdr)[elf_file.debug_line_section_index.?];1494 const shdr = elf_file.sections.items(.shdr)[elf_file.debug_line_section_index.?];
1480 const file_pos = shdr.sh_offset + decl.fn_link.elf.off + self.getRelocDbgLineOff();1495 const file_pos = shdr.sh_offset + atom.off + self.getRelocDbgLineOff();
1481 try elf_file.base.file.?.pwriteAll(&data, file_pos);1496 try elf_file.base.file.?.pwriteAll(&data, file_pos);
1482 },1497 },
1483 .macho => {1498 .macho => {
1484 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;1499 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
1485 const sect = d_sym.getSection(d_sym.debug_line_section_index.?);1500 const sect = d_sym.getSection(d_sym.debug_line_section_index.?);
1486 const file_pos = sect.offset + decl.fn_link.macho.off + self.getRelocDbgLineOff();1501 const file_pos = sect.offset + atom.off + self.getRelocDbgLineOff();
1487 try d_sym.file.pwriteAll(&data, file_pos);1502 try d_sym.file.pwriteAll(&data, file_pos);
1488 },1503 },
1489 .wasm => {1504 .wasm => {
1490 const wasm_file = self.bin_file.cast(File.Wasm).?;1505 const wasm_file = self.bin_file.cast(File.Wasm).?;
1491 const offset = decl.fn_link.wasm.src_fn.off + self.getRelocDbgLineOff();1506 const offset = atom.off + self.getRelocDbgLineOff();
1492 const atom = wasm_file.debug_line_atom.?;1507 const atom_ = wasm_file.debug_line_atom.?;
1493 mem.copy(u8, atom.code.items[offset..], &data);1508 mem.copy(u8, atom_.code.items[offset..], &data);
1494 },1509 },
1495 else => unreachable,1510 else => unreachable,
1496 }1511 }
1497}1512}
14981513
1499pub fn freeAtom(self: *Dwarf, atom: *Atom) void {1514pub fn freeDecl(self: *Dwarf, decl_index: Module.Decl.Index) void {
1500 if (self.atom_first == atom) {1515 const gpa = self.allocator;
1501 self.atom_first = atom.next;
1502 }
1503 if (self.atom_last == atom) {
1504 // TODO shrink the .debug_info section size here
1505 self.atom_last = atom.prev;
1506 }
1507
1508 if (atom.prev) |prev| {
1509 prev.next = atom.next;
15101516
1511 // TODO the free list logic like we do for text blocks above1517 // Free SrcFn atom
1512 } else {1518 if (self.src_fn_decls.fetchRemove(decl_index)) |kv| {
1513 atom.prev = null;1519 const src_fn_index = kv.value;
1520 const src_fn = self.getAtom(.src_fn, src_fn_index);
1521 _ = self.src_fn_free_list.remove(src_fn_index);
1522
1523 if (src_fn.prev_index) |prev_index| {
1524 self.src_fn_free_list.put(gpa, prev_index, {}) catch {};
1525 const prev = self.getAtomPtr(.src_fn, prev_index);
1526 prev.next_index = src_fn.next_index;
1527 if (src_fn.next_index) |next_index| {
1528 self.getAtomPtr(.src_fn, next_index).prev_index = prev_index;
1529 } else {
1530 self.src_fn_last_index = prev_index;
1531 }
1532 } else if (src_fn.next_index) |next_index| {
1533 self.src_fn_first_index = next_index;
1534 self.getAtomPtr(.src_fn, next_index).prev_index = null;
1535 }
1536 if (self.src_fn_first_index == src_fn_index) {
1537 self.src_fn_first_index = src_fn.next_index;
1538 }
1539 if (self.src_fn_last_index == src_fn_index) {
1540 self.src_fn_last_index = src_fn.prev_index;
1541 }
1514 }1542 }
15151543
1516 if (atom.next) |next| {1544 // Free DI atom
1517 next.prev = atom.prev;1545 if (self.di_atom_decls.fetchRemove(decl_index)) |kv| {
1518 } else {1546 const di_atom_index = kv.value;
1519 atom.next = null;1547 const di_atom = self.getAtomPtr(.di_atom, di_atom_index);
1520 }
1521}
15221548
1523pub fn freeDecl(self: *Dwarf, decl: *Module.Decl) void {1549 if (self.di_atom_first_index == di_atom_index) {
1524 // TODO make this logic match freeTextBlock. Maybe abstract the logic out since the same thing1550 self.di_atom_first_index = di_atom.next_index;
1525 // is desired for both.1551 }
1526 const gpa = self.allocator;1552 if (self.di_atom_last_index == di_atom_index) {
1527 const fn_link = switch (self.bin_file.tag) {1553 // TODO shrink the .debug_info section size here
1528 .elf => &decl.fn_link.elf,1554 self.di_atom_last_index = di_atom.prev_index;
1529 .macho => &decl.fn_link.macho,1555 }
1530 .wasm => &decl.fn_link.wasm.src_fn,
1531 else => unreachable,
1532 };
1533 _ = self.dbg_line_fn_free_list.remove(fn_link);
15341556
1535 if (fn_link.prev) |prev| {1557 if (di_atom.prev_index) |prev_index| {
1536 self.dbg_line_fn_free_list.put(gpa, prev, {}) catch {};1558 self.getAtomPtr(.di_atom, prev_index).next_index = di_atom.next_index;
1537 prev.next = fn_link.next;1559 // TODO the free list logic like we do for SrcFn above
1538 if (fn_link.next) |next| {
1539 next.prev = prev;
1540 } else {1560 } else {
1541 self.dbg_line_fn_last = prev;1561 di_atom.prev_index = null;
1562 }
1563
1564 if (di_atom.next_index) |next_index| {
1565 self.getAtomPtr(.di_atom, next_index).prev_index = di_atom.prev_index;
1566 } else {
1567 di_atom.next_index = null;
1542 }1568 }
1543 } else if (fn_link.next) |next| {
1544 self.dbg_line_fn_first = next;
1545 next.prev = null;
1546 }
1547 if (self.dbg_line_fn_first == fn_link) {
1548 self.dbg_line_fn_first = fn_link.next;
1549 }
1550 if (self.dbg_line_fn_last == fn_link) {
1551 self.dbg_line_fn_last = fn_link.prev;
1552 }1569 }
1553}1570}
15541571
...@@ -2276,10 +2293,14 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2276,10 +2293,14 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2276 const needed_with_padding = padToIdeal(needed_bytes);2293 const needed_with_padding = padToIdeal(needed_bytes);
2277 const delta = needed_with_padding - dbg_line_prg_off;2294 const delta = needed_with_padding - dbg_line_prg_off;
22782295
2279 var src_fn = self.dbg_line_fn_first.?;2296 const first_fn_index = self.src_fn_first_index.?;
2280 const last_fn = self.dbg_line_fn_last.?;2297 const first_fn = self.getAtom(.src_fn, first_fn_index);
2298 const last_fn_index = self.src_fn_last_index.?;
2299 const last_fn = self.getAtom(.src_fn, last_fn_index);
2300
2301 var src_fn_index = first_fn_index;
22812302
2282 var buffer = try gpa.alloc(u8, last_fn.off + last_fn.len - src_fn.off);2303 var buffer = try gpa.alloc(u8, last_fn.off + last_fn.len - first_fn.off);
2283 defer gpa.free(buffer);2304 defer gpa.free(buffer);
22842305
2285 switch (self.bin_file.tag) {2306 switch (self.bin_file.tag) {
...@@ -2288,7 +2309,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2288,7 +2309,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2288 const shdr_index = elf_file.debug_line_section_index.?;2309 const shdr_index = elf_file.debug_line_section_index.?;
2289 const needed_size = elf_file.sections.items(.shdr)[shdr_index].sh_size + delta;2310 const needed_size = elf_file.sections.items(.shdr)[shdr_index].sh_size + delta;
2290 try elf_file.growNonAllocSection(shdr_index, needed_size, 1, true);2311 try elf_file.growNonAllocSection(shdr_index, needed_size, 1, true);
2291 const file_pos = elf_file.sections.items(.shdr)[shdr_index].sh_offset + src_fn.off;2312 const file_pos = elf_file.sections.items(.shdr)[shdr_index].sh_offset + first_fn.off;
22922313
2293 const amt = try elf_file.base.file.?.preadAll(buffer, file_pos);2314 const amt = try elf_file.base.file.?.preadAll(buffer, file_pos);
2294 if (amt != buffer.len) return error.InputOutput;2315 if (amt != buffer.len) return error.InputOutput;
...@@ -2300,7 +2321,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2300,7 +2321,7 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2300 const sect_index = d_sym.debug_line_section_index.?;2321 const sect_index = d_sym.debug_line_section_index.?;
2301 const needed_size = @intCast(u32, d_sym.getSection(sect_index).size + delta);2322 const needed_size = @intCast(u32, d_sym.getSection(sect_index).size + delta);
2302 try d_sym.growSection(sect_index, needed_size, true);2323 try d_sym.growSection(sect_index, needed_size, true);
2303 const file_pos = d_sym.getSection(sect_index).offset + src_fn.off;2324 const file_pos = d_sym.getSection(sect_index).offset + first_fn.off;
23042325
2305 const amt = try d_sym.file.preadAll(buffer, file_pos);2326 const amt = try d_sym.file.preadAll(buffer, file_pos);
2306 if (amt != buffer.len) return error.InputOutput;2327 if (amt != buffer.len) return error.InputOutput;
...@@ -2310,18 +2331,19 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2310,18 +2331,19 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2310 .wasm => {2331 .wasm => {
2311 const wasm_file = self.bin_file.cast(File.Wasm).?;2332 const wasm_file = self.bin_file.cast(File.Wasm).?;
2312 const debug_line = &wasm_file.debug_line_atom.?.code;2333 const debug_line = &wasm_file.debug_line_atom.?.code;
2313 mem.copy(u8, buffer, debug_line.items[src_fn.off..]);2334 mem.copy(u8, buffer, debug_line.items[first_fn.off..]);
2314 try debug_line.resize(self.allocator, debug_line.items.len + delta);2335 try debug_line.resize(self.allocator, debug_line.items.len + delta);
2315 mem.copy(u8, debug_line.items[src_fn.off + delta ..], buffer);2336 mem.copy(u8, debug_line.items[first_fn.off + delta ..], buffer);
2316 },2337 },
2317 else => unreachable,2338 else => unreachable,
2318 }2339 }
23192340
2320 while (true) {2341 while (true) {
2342 const src_fn = self.getAtomPtr(.src_fn, src_fn_index);
2321 src_fn.off += delta;2343 src_fn.off += delta;
23222344
2323 if (src_fn.next) |next| {2345 if (src_fn.next_index) |next_index| {
2324 src_fn = next;2346 src_fn_index = next_index;
2325 } else break;2347 } else break;
2326 }2348 }
2327 }2349 }
...@@ -2367,22 +2389,26 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {...@@ -2367,22 +2389,26 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void {
2367}2389}
23682390
2369fn getDebugInfoOff(self: Dwarf) ?u32 {2391fn getDebugInfoOff(self: Dwarf) ?u32 {
2370 const first = self.atom_first orelse return null;2392 const first_index = self.di_atom_first_index orelse return null;
2393 const first = self.getAtom(.di_atom, first_index);
2371 return first.off;2394 return first.off;
2372}2395}
23732396
2374fn getDebugInfoEnd(self: Dwarf) ?u32 {2397fn getDebugInfoEnd(self: Dwarf) ?u32 {
2375 const last = self.atom_last orelse return null;2398 const last_index = self.di_atom_last_index orelse return null;
2399 const last = self.getAtom(.di_atom, last_index);
2376 return last.off + last.len;2400 return last.off + last.len;
2377}2401}
23782402
2379fn getDebugLineProgramOff(self: Dwarf) ?u32 {2403fn getDebugLineProgramOff(self: Dwarf) ?u32 {
2380 const first = self.dbg_line_fn_first orelse return null;2404 const first_index = self.src_fn_first_index orelse return null;
2405 const first = self.getAtom(.src_fn, first_index);
2381 return first.off;2406 return first.off;
2382}2407}
23832408
2384fn getDebugLineProgramEnd(self: Dwarf) ?u32 {2409fn getDebugLineProgramEnd(self: Dwarf) ?u32 {
2385 const last = self.dbg_line_fn_last orelse return null;2410 const last_index = self.src_fn_last_index orelse return null;
2411 const last = self.getAtom(.src_fn, last_index);
2386 return last.off + last.len;2412 return last.off + last.len;
2387}2413}
23882414
...@@ -2457,23 +2483,14 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {...@@ -2457,23 +2483,14 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
2457 }2483 }
2458 error_set.names = names;2484 error_set.names = names;
24592485
2460 const atom = try gpa.create(Atom);
2461 errdefer gpa.destroy(atom);
2462 atom.* = .{
2463 .prev = null,
2464 .next = null,
2465 .off = 0,
2466 .len = 0,
2467 };
2468
2469 var dbg_info_buffer = std.ArrayList(u8).init(arena);2486 var dbg_info_buffer = std.ArrayList(u8).init(arena);
2470 try addDbgInfoErrorSet(arena, module, error_ty, self.target, &dbg_info_buffer);2487 try addDbgInfoErrorSet(arena, module, error_ty, self.target, &dbg_info_buffer);
24712488
2472 try self.managed_atoms.append(gpa, atom);2489 const di_atom_index = try self.createAtom(.di_atom);
2473 log.debug("updateDeclDebugInfoAllocation in flushModule", .{});2490 log.debug("updateDeclDebugInfoAllocation in flushModule", .{});
2474 try self.updateDeclDebugInfoAllocation(atom, @intCast(u32, dbg_info_buffer.items.len));2491 try self.updateDeclDebugInfoAllocation(di_atom_index, @intCast(u32, dbg_info_buffer.items.len));
2475 log.debug("writeDeclDebugInfo in flushModule", .{});2492 log.debug("writeDeclDebugInfo in flushModule", .{});
2476 try self.writeDeclDebugInfo(atom, dbg_info_buffer.items);2493 try self.writeDeclDebugInfo(di_atom_index, dbg_info_buffer.items);
24772494
2478 const file_pos = blk: {2495 const file_pos = blk: {
2479 switch (self.bin_file.tag) {2496 switch (self.bin_file.tag) {
...@@ -2494,22 +2511,23 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {...@@ -2494,22 +2511,23 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void {
2494 };2511 };
24952512
2496 var buf: [@sizeOf(u32)]u8 = undefined;2513 var buf: [@sizeOf(u32)]u8 = undefined;
2497 mem.writeInt(u32, &buf, atom.off, self.target.cpu.arch.endian());2514 mem.writeInt(u32, &buf, self.getAtom(.di_atom, di_atom_index).off, self.target.cpu.arch.endian());
24982515
2499 while (self.global_abbrev_relocs.popOrNull()) |reloc| {2516 while (self.global_abbrev_relocs.popOrNull()) |reloc| {
2517 const atom = self.getAtom(.di_atom, reloc.atom_index);
2500 switch (self.bin_file.tag) {2518 switch (self.bin_file.tag) {
2501 .elf => {2519 .elf => {
2502 const elf_file = self.bin_file.cast(File.Elf).?;2520 const elf_file = self.bin_file.cast(File.Elf).?;
2503 try elf_file.base.file.?.pwriteAll(&buf, file_pos + reloc.atom.off + reloc.offset);2521 try elf_file.base.file.?.pwriteAll(&buf, file_pos + atom.off + reloc.offset);
2504 },2522 },
2505 .macho => {2523 .macho => {
2506 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;2524 const d_sym = self.bin_file.cast(File.MachO).?.getDebugSymbols().?;
2507 try d_sym.file.pwriteAll(&buf, file_pos + reloc.atom.off + reloc.offset);2525 try d_sym.file.pwriteAll(&buf, file_pos + atom.off + reloc.offset);
2508 },2526 },
2509 .wasm => {2527 .wasm => {
2510 const wasm_file = self.bin_file.cast(File.Wasm).?;2528 const wasm_file = self.bin_file.cast(File.Wasm).?;
2511 const debug_info = wasm_file.debug_info_atom.?.code;2529 const debug_info = wasm_file.debug_info_atom.?.code;
2512 mem.copy(u8, debug_info.items[reloc.atom.off + reloc.offset ..], &buf);2530 mem.copy(u8, debug_info.items[atom.off + reloc.offset ..], &buf);
2513 },2531 },
2514 else => unreachable,2532 else => unreachable,
2515 }2533 }
...@@ -2627,12 +2645,62 @@ fn addDbgInfoErrorSet(...@@ -2627,12 +2645,62 @@ fn addDbgInfoErrorSet(
2627 try dbg_info_buffer.append(0);2645 try dbg_info_buffer.append(0);
2628}2646}
26292647
2630fn getDbgInfoAtom(tag: File.Tag, mod: *Module, decl_index: Module.Decl.Index) *Atom {2648const Kind = enum { src_fn, di_atom };
2631 const decl = mod.declPtr(decl_index);2649
2632 return switch (tag) {2650fn createAtom(self: *Dwarf, comptime kind: Kind) !Atom.Index {
2633 .elf => unreachable,2651 const index = blk: {
2634 .macho => unreachable,2652 switch (kind) {
2635 .wasm => &decl.link.wasm.dbg_info_atom,2653 .src_fn => {
2636 else => unreachable,2654 const index = @intCast(Atom.Index, self.src_fns.items.len);
2655 _ = try self.src_fns.addOne(self.allocator);
2656 break :blk index;
2657 },
2658 .di_atom => {
2659 const index = @intCast(Atom.Index, self.di_atoms.items.len);
2660 _ = try self.di_atoms.addOne(self.allocator);
2661 break :blk index;
2662 },
2663 }
2664 };
2665 const atom = self.getAtomPtr(kind, index);
2666 atom.* = .{
2667 .off = 0,
2668 .len = 0,
2669 .prev_index = null,
2670 .next_index = null,
2671 };
2672 return index;
2673}
2674
2675fn getOrCreateAtomForDecl(self: *Dwarf, comptime kind: Kind, decl_index: Module.Decl.Index) !Atom.Index {
2676 switch (kind) {
2677 .src_fn => {
2678 const gop = try self.src_fn_decls.getOrPut(self.allocator, decl_index);
2679 if (!gop.found_existing) {
2680 gop.value_ptr.* = try self.createAtom(kind);
2681 }
2682 return gop.value_ptr.*;
2683 },
2684 .di_atom => {
2685 const gop = try self.di_atom_decls.getOrPut(self.allocator, decl_index);
2686 if (!gop.found_existing) {
2687 gop.value_ptr.* = try self.createAtom(kind);
2688 }
2689 return gop.value_ptr.*;
2690 },
2691 }
2692}
2693
2694fn getAtom(self: *const Dwarf, comptime kind: Kind, index: Atom.Index) Atom {
2695 return switch (kind) {
2696 .src_fn => self.src_fns.items[index],
2697 .di_atom => self.di_atoms.items[index],
2698 };
2699}
2700
2701fn getAtomPtr(self: *Dwarf, comptime kind: Kind, index: Atom.Index) *Atom {
2702 return switch (kind) {
2703 .src_fn => &self.src_fns.items[index],
2704 .di_atom => &self.di_atoms.items[index],
2637 };2705 };
2638}2706}
src/link/Elf.zig+267-275
...@@ -344,9 +344,9 @@ pub fn deinit(self: *Elf) void {...@@ -344,9 +344,9 @@ pub fn deinit(self: *Elf) void {
344 self.relocs.deinit(gpa);344 self.relocs.deinit(gpa);
345 }345 }
346346
347 // if (self.dwarf) |*dw| {347 if (self.dwarf) |*dw| {
348 // dw.deinit();348 dw.deinit();
349 // }349 }
350}350}
351351
352pub fn getDeclVAddr(self: *Elf, decl_index: Module.Decl.Index, reloc_info: File.RelocInfo) !u64 {352pub fn getDeclVAddr(self: *Elf, decl_index: Module.Decl.Index, reloc_info: File.RelocInfo) !u64 {
...@@ -685,146 +685,146 @@ pub fn populateMissingMetadata(self: *Elf) !void {...@@ -685,146 +685,146 @@ pub fn populateMissingMetadata(self: *Elf) !void {
685 try self.writeSymbol(0);685 try self.writeSymbol(0);
686 }686 }
687687
688 // if (self.dwarf) |*dw| {688 if (self.dwarf) |*dw| {
689 // if (self.debug_str_section_index == null) {689 if (self.debug_str_section_index == null) {
690 // self.debug_str_section_index = @intCast(u16, self.sections.slice().len);690 self.debug_str_section_index = @intCast(u16, self.sections.slice().len);
691 // assert(dw.strtab.buffer.items.len == 0);691 assert(dw.strtab.buffer.items.len == 0);
692 // try dw.strtab.buffer.append(gpa, 0);692 try dw.strtab.buffer.append(gpa, 0);
693 // try self.sections.append(gpa, .{693 try self.sections.append(gpa, .{
694 // .shdr = .{694 .shdr = .{
695 // .sh_name = try self.shstrtab.insert(gpa, ".debug_str"),695 .sh_name = try self.shstrtab.insert(gpa, ".debug_str"),
696 // .sh_type = elf.SHT_PROGBITS,696 .sh_type = elf.SHT_PROGBITS,
697 // .sh_flags = elf.SHF_MERGE | elf.SHF_STRINGS,697 .sh_flags = elf.SHF_MERGE | elf.SHF_STRINGS,
698 // .sh_addr = 0,698 .sh_addr = 0,
699 // .sh_offset = 0,699 .sh_offset = 0,
700 // .sh_size = 0,700 .sh_size = 0,
701 // .sh_link = 0,701 .sh_link = 0,
702 // .sh_info = 0,702 .sh_info = 0,
703 // .sh_addralign = 1,703 .sh_addralign = 1,
704 // .sh_entsize = 1,704 .sh_entsize = 1,
705 // },705 },
706 // .phdr_index = undefined,706 .phdr_index = undefined,
707 // });707 });
708 // self.debug_strtab_dirty = true;708 self.debug_strtab_dirty = true;
709 // self.shdr_table_dirty = true;709 self.shdr_table_dirty = true;
710 // }710 }
711711
712 // if (self.debug_info_section_index == null) {712 if (self.debug_info_section_index == null) {
713 // self.debug_info_section_index = @intCast(u16, self.sections.slice().len);713 self.debug_info_section_index = @intCast(u16, self.sections.slice().len);
714714
715 // const file_size_hint = 200;715 const file_size_hint = 200;
716 // const p_align = 1;716 const p_align = 1;
717 // const off = self.findFreeSpace(file_size_hint, p_align);717 const off = self.findFreeSpace(file_size_hint, p_align);
718 // log.debug("found .debug_info free space 0x{x} to 0x{x}", .{718 log.debug("found .debug_info free space 0x{x} to 0x{x}", .{
719 // off,719 off,
720 // off + file_size_hint,720 off + file_size_hint,
721 // });721 });
722 // try self.sections.append(gpa, .{722 try self.sections.append(gpa, .{
723 // .shdr = .{723 .shdr = .{
724 // .sh_name = try self.shstrtab.insert(gpa, ".debug_info"),724 .sh_name = try self.shstrtab.insert(gpa, ".debug_info"),
725 // .sh_type = elf.SHT_PROGBITS,725 .sh_type = elf.SHT_PROGBITS,
726 // .sh_flags = 0,726 .sh_flags = 0,
727 // .sh_addr = 0,727 .sh_addr = 0,
728 // .sh_offset = off,728 .sh_offset = off,
729 // .sh_size = file_size_hint,729 .sh_size = file_size_hint,
730 // .sh_link = 0,730 .sh_link = 0,
731 // .sh_info = 0,731 .sh_info = 0,
732 // .sh_addralign = p_align,732 .sh_addralign = p_align,
733 // .sh_entsize = 0,733 .sh_entsize = 0,
734 // },734 },
735 // .phdr_index = undefined,735 .phdr_index = undefined,
736 // });736 });
737 // self.shdr_table_dirty = true;737 self.shdr_table_dirty = true;
738 // self.debug_info_header_dirty = true;738 self.debug_info_header_dirty = true;
739 // }739 }
740740
741 // if (self.debug_abbrev_section_index == null) {741 if (self.debug_abbrev_section_index == null) {
742 // self.debug_abbrev_section_index = @intCast(u16, self.sections.slice().len);742 self.debug_abbrev_section_index = @intCast(u16, self.sections.slice().len);
743743
744 // const file_size_hint = 128;744 const file_size_hint = 128;
745 // const p_align = 1;745 const p_align = 1;
746 // const off = self.findFreeSpace(file_size_hint, p_align);746 const off = self.findFreeSpace(file_size_hint, p_align);
747 // log.debug("found .debug_abbrev free space 0x{x} to 0x{x}", .{747 log.debug("found .debug_abbrev free space 0x{x} to 0x{x}", .{
748 // off,748 off,
749 // off + file_size_hint,749 off + file_size_hint,
750 // });750 });
751 // try self.sections.append(gpa, .{751 try self.sections.append(gpa, .{
752 // .shdr = .{752 .shdr = .{
753 // .sh_name = try self.shstrtab.insert(gpa, ".debug_abbrev"),753 .sh_name = try self.shstrtab.insert(gpa, ".debug_abbrev"),
754 // .sh_type = elf.SHT_PROGBITS,754 .sh_type = elf.SHT_PROGBITS,
755 // .sh_flags = 0,755 .sh_flags = 0,
756 // .sh_addr = 0,756 .sh_addr = 0,
757 // .sh_offset = off,757 .sh_offset = off,
758 // .sh_size = file_size_hint,758 .sh_size = file_size_hint,
759 // .sh_link = 0,759 .sh_link = 0,
760 // .sh_info = 0,760 .sh_info = 0,
761 // .sh_addralign = p_align,761 .sh_addralign = p_align,
762 // .sh_entsize = 0,762 .sh_entsize = 0,
763 // },763 },
764 // .phdr_index = undefined,764 .phdr_index = undefined,
765 // });765 });
766 // self.shdr_table_dirty = true;766 self.shdr_table_dirty = true;
767 // self.debug_abbrev_section_dirty = true;767 self.debug_abbrev_section_dirty = true;
768 // }768 }
769769
770 // if (self.debug_aranges_section_index == null) {770 if (self.debug_aranges_section_index == null) {
771 // self.debug_aranges_section_index = @intCast(u16, self.sections.slice().len);771 self.debug_aranges_section_index = @intCast(u16, self.sections.slice().len);
772772
773 // const file_size_hint = 160;773 const file_size_hint = 160;
774 // const p_align = 16;774 const p_align = 16;
775 // const off = self.findFreeSpace(file_size_hint, p_align);775 const off = self.findFreeSpace(file_size_hint, p_align);
776 // log.debug("found .debug_aranges free space 0x{x} to 0x{x}", .{776 log.debug("found .debug_aranges free space 0x{x} to 0x{x}", .{
777 // off,777 off,
778 // off + file_size_hint,778 off + file_size_hint,
779 // });779 });
780 // try self.sections.append(gpa, .{780 try self.sections.append(gpa, .{
781 // .shdr = .{781 .shdr = .{
782 // .sh_name = try self.shstrtab.insert(gpa, ".debug_aranges"),782 .sh_name = try self.shstrtab.insert(gpa, ".debug_aranges"),
783 // .sh_type = elf.SHT_PROGBITS,783 .sh_type = elf.SHT_PROGBITS,
784 // .sh_flags = 0,784 .sh_flags = 0,
785 // .sh_addr = 0,785 .sh_addr = 0,
786 // .sh_offset = off,786 .sh_offset = off,
787 // .sh_size = file_size_hint,787 .sh_size = file_size_hint,
788 // .sh_link = 0,788 .sh_link = 0,
789 // .sh_info = 0,789 .sh_info = 0,
790 // .sh_addralign = p_align,790 .sh_addralign = p_align,
791 // .sh_entsize = 0,791 .sh_entsize = 0,
792 // },792 },
793 // .phdr_index = undefined,793 .phdr_index = undefined,
794 // });794 });
795 // self.shdr_table_dirty = true;795 self.shdr_table_dirty = true;
796 // self.debug_aranges_section_dirty = true;796 self.debug_aranges_section_dirty = true;
797 // }797 }
798798
799 // if (self.debug_line_section_index == null) {799 if (self.debug_line_section_index == null) {
800 // self.debug_line_section_index = @intCast(u16, self.sections.slice().len);800 self.debug_line_section_index = @intCast(u16, self.sections.slice().len);
801801
802 // const file_size_hint = 250;802 const file_size_hint = 250;
803 // const p_align = 1;803 const p_align = 1;
804 // const off = self.findFreeSpace(file_size_hint, p_align);804 const off = self.findFreeSpace(file_size_hint, p_align);
805 // log.debug("found .debug_line free space 0x{x} to 0x{x}", .{805 log.debug("found .debug_line free space 0x{x} to 0x{x}", .{
806 // off,806 off,
807 // off + file_size_hint,807 off + file_size_hint,
808 // });808 });
809 // try self.sections.append(gpa, .{809 try self.sections.append(gpa, .{
810 // .shdr = .{810 .shdr = .{
811 // .sh_name = try self.shstrtab.insert(gpa, ".debug_line"),811 .sh_name = try self.shstrtab.insert(gpa, ".debug_line"),
812 // .sh_type = elf.SHT_PROGBITS,812 .sh_type = elf.SHT_PROGBITS,
813 // .sh_flags = 0,813 .sh_flags = 0,
814 // .sh_addr = 0,814 .sh_addr = 0,
815 // .sh_offset = off,815 .sh_offset = off,
816 // .sh_size = file_size_hint,816 .sh_size = file_size_hint,
817 // .sh_link = 0,817 .sh_link = 0,
818 // .sh_info = 0,818 .sh_info = 0,
819 // .sh_addralign = p_align,819 .sh_addralign = p_align,
820 // .sh_entsize = 0,820 .sh_entsize = 0,
821 // },821 },
822 // .phdr_index = undefined,822 .phdr_index = undefined,
823 // });823 });
824 // self.shdr_table_dirty = true;824 self.shdr_table_dirty = true;
825 // self.debug_line_header_dirty = true;825 self.debug_line_header_dirty = true;
826 // }826 }
827 // }827 }
828828
829 const shsize: u64 = switch (self.ptr_width) {829 const shsize: u64 = switch (self.ptr_width) {
830 .p32 => @sizeOf(elf.Elf32_Shdr),830 .p32 => @sizeOf(elf.Elf32_Shdr),
...@@ -956,26 +956,25 @@ pub fn growNonAllocSection(...@@ -956,26 +956,25 @@ pub fn growNonAllocSection(
956}956}
957957
958pub fn markDirty(self: *Elf, shdr_index: u16, phdr_index: ?u16) void {958pub fn markDirty(self: *Elf, shdr_index: u16, phdr_index: ?u16) void {
959 _ = shdr_index;
960 self.shdr_table_dirty = true; // TODO look into only writing one section959 self.shdr_table_dirty = true; // TODO look into only writing one section
961960
962 if (phdr_index) |_| {961 if (phdr_index) |_| {
963 self.phdr_table_dirty = true; // TODO look into making only the one program header dirty962 self.phdr_table_dirty = true; // TODO look into making only the one program header dirty
964 }963 }
965964
966 // if (self.dwarf) |_| {965 if (self.dwarf) |_| {
967 // if (self.debug_info_section_index.? == shdr_index) {966 if (self.debug_info_section_index.? == shdr_index) {
968 // self.debug_info_header_dirty = true;967 self.debug_info_header_dirty = true;
969 // } else if (self.debug_line_section_index.? == shdr_index) {968 } else if (self.debug_line_section_index.? == shdr_index) {
970 // self.debug_line_header_dirty = true;969 self.debug_line_header_dirty = true;
971 // } else if (self.debug_abbrev_section_index.? == shdr_index) {970 } else if (self.debug_abbrev_section_index.? == shdr_index) {
972 // self.debug_abbrev_section_dirty = true;971 self.debug_abbrev_section_dirty = true;
973 // } else if (self.debug_str_section_index.? == shdr_index) {972 } else if (self.debug_str_section_index.? == shdr_index) {
974 // self.debug_strtab_dirty = true;973 self.debug_strtab_dirty = true;
975 // } else if (self.debug_aranges_section_index.? == shdr_index) {974 } else if (self.debug_aranges_section_index.? == shdr_index) {
976 // self.debug_aranges_section_dirty = true;975 self.debug_aranges_section_dirty = true;
977 // }976 }
978 // }977 }
979}978}
980979
981pub fn flush(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {980pub fn flush(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
...@@ -1015,14 +1014,13 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1015,14 +1014,13 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1015 // TODO This linker code currently assumes there is only 1 compilation unit and it1014 // TODO This linker code currently assumes there is only 1 compilation unit and it
1016 // corresponds to the Zig source code.1015 // corresponds to the Zig source code.
1017 const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented;1016 const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented;
1018 _ = module;
10191017
1020 const target_endian = self.base.options.target.cpu.arch.endian();1018 const target_endian = self.base.options.target.cpu.arch.endian();
1021 const foreign_endian = target_endian != builtin.cpu.arch.endian();1019 const foreign_endian = target_endian != builtin.cpu.arch.endian();
10221020
1023 // if (self.dwarf) |*dw| {1021 if (self.dwarf) |*dw| {
1024 // try dw.flushModule(module);1022 try dw.flushModule(module);
1025 // }1023 }
10261024
1027 {1025 {
1028 var it = self.relocs.iterator();1026 var it = self.relocs.iterator();
...@@ -1068,43 +1066,43 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1068,43 +1066,43 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1068 self.logSymtab();1066 self.logSymtab();
1069 }1067 }
10701068
1071 // if (self.dwarf) |*dw| {1069 if (self.dwarf) |*dw| {
1072 // if (self.debug_abbrev_section_dirty) {1070 if (self.debug_abbrev_section_dirty) {
1073 // try dw.writeDbgAbbrev();1071 try dw.writeDbgAbbrev();
1074 // if (!self.shdr_table_dirty) {1072 if (!self.shdr_table_dirty) {
1075 // // Then it won't get written with the others and we need to do it.1073 // Then it won't get written with the others and we need to do it.
1076 // try self.writeSectHeader(self.debug_abbrev_section_index.?);1074 try self.writeSectHeader(self.debug_abbrev_section_index.?);
1077 // }1075 }
1078 // self.debug_abbrev_section_dirty = false;1076 self.debug_abbrev_section_dirty = false;
1079 // }1077 }
10801078
1081 // if (self.debug_info_header_dirty) {1079 if (self.debug_info_header_dirty) {
1082 // // Currently only one compilation unit is supported, so the address range is simply1080 // Currently only one compilation unit is supported, so the address range is simply
1083 // // identical to the main program header virtual address and memory size.1081 // identical to the main program header virtual address and memory size.
1084 // const text_phdr = &self.program_headers.items[self.phdr_load_re_index.?];1082 const text_phdr = &self.program_headers.items[self.phdr_load_re_index.?];
1085 // const low_pc = text_phdr.p_vaddr;1083 const low_pc = text_phdr.p_vaddr;
1086 // const high_pc = text_phdr.p_vaddr + text_phdr.p_memsz;1084 const high_pc = text_phdr.p_vaddr + text_phdr.p_memsz;
1087 // try dw.writeDbgInfoHeader(module, low_pc, high_pc);1085 try dw.writeDbgInfoHeader(module, low_pc, high_pc);
1088 // self.debug_info_header_dirty = false;1086 self.debug_info_header_dirty = false;
1089 // }1087 }
10901088
1091 // if (self.debug_aranges_section_dirty) {1089 if (self.debug_aranges_section_dirty) {
1092 // // Currently only one compilation unit is supported, so the address range is simply1090 // Currently only one compilation unit is supported, so the address range is simply
1093 // // identical to the main program header virtual address and memory size.1091 // identical to the main program header virtual address and memory size.
1094 // const text_phdr = &self.program_headers.items[self.phdr_load_re_index.?];1092 const text_phdr = &self.program_headers.items[self.phdr_load_re_index.?];
1095 // try dw.writeDbgAranges(text_phdr.p_vaddr, text_phdr.p_memsz);1093 try dw.writeDbgAranges(text_phdr.p_vaddr, text_phdr.p_memsz);
1096 // if (!self.shdr_table_dirty) {1094 if (!self.shdr_table_dirty) {
1097 // // Then it won't get written with the others and we need to do it.1095 // Then it won't get written with the others and we need to do it.
1098 // try self.writeSectHeader(self.debug_aranges_section_index.?);1096 try self.writeSectHeader(self.debug_aranges_section_index.?);
1099 // }1097 }
1100 // self.debug_aranges_section_dirty = false;1098 self.debug_aranges_section_dirty = false;
1101 // }1099 }
11021100
1103 // if (self.debug_line_header_dirty) {1101 if (self.debug_line_header_dirty) {
1104 // try dw.writeDbgLineHeader();1102 try dw.writeDbgLineHeader();
1105 // self.debug_line_header_dirty = false;1103 self.debug_line_header_dirty = false;
1106 // }1104 }
1107 // }1105 }
11081106
1109 if (self.phdr_table_dirty) {1107 if (self.phdr_table_dirty) {
1110 const phsize: u64 = switch (self.ptr_width) {1108 const phsize: u64 = switch (self.ptr_width) {
...@@ -1162,15 +1160,15 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1162,15 +1160,15 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1162 }1160 }
1163 }1161 }
11641162
1165 // if (self.dwarf) |dwarf| {1163 if (self.dwarf) |dwarf| {
1166 // const shdr_index = self.debug_str_section_index.?;1164 const shdr_index = self.debug_str_section_index.?;
1167 // if (self.debug_strtab_dirty or dwarf.strtab.buffer.items.len != self.sections.items(.shdr)[shdr_index].sh_size) {1165 if (self.debug_strtab_dirty or dwarf.strtab.buffer.items.len != self.sections.items(.shdr)[shdr_index].sh_size) {
1168 // try self.growNonAllocSection(shdr_index, dwarf.strtab.buffer.items.len, 1, false);1166 try self.growNonAllocSection(shdr_index, dwarf.strtab.buffer.items.len, 1, false);
1169 // const debug_strtab_sect = self.sections.items(.shdr)[shdr_index];1167 const debug_strtab_sect = self.sections.items(.shdr)[shdr_index];
1170 // try self.base.file.?.pwriteAll(dwarf.strtab.buffer.items, debug_strtab_sect.sh_offset);1168 try self.base.file.?.pwriteAll(dwarf.strtab.buffer.items, debug_strtab_sect.sh_offset);
1171 // self.debug_strtab_dirty = false;1169 self.debug_strtab_dirty = false;
1172 // }1170 }
1173 // }1171 }
11741172
1175 if (self.shdr_table_dirty) {1173 if (self.shdr_table_dirty) {
1176 const shsize: u64 = switch (self.ptr_width) {1174 const shsize: u64 = switch (self.ptr_width) {
...@@ -2100,10 +2098,6 @@ fn freeAtom(self: *Elf, atom_index: Atom.Index) void {...@@ -2100,10 +2098,6 @@ fn freeAtom(self: *Elf, atom_index: Atom.Index) void {
2100 self.getAtomPtr(atom_index).local_sym_index = 0;2098 self.getAtomPtr(atom_index).local_sym_index = 0;
21012099
2102 self.offset_table_free_list.append(self.base.allocator, atom.offset_table_index) catch {};2100 self.offset_table_free_list.append(self.base.allocator, atom.offset_table_index) catch {};
2103
2104 // if (self.dwarf) |*dw| {
2105 // dw.freeAtom(&atom.dbg_info_atom);
2106 // }
2107}2101}
21082102
2109fn shrinkAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64) void {2103fn shrinkAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64) void {
...@@ -2133,7 +2127,6 @@ pub fn createAtom(self: *Elf) !Atom.Index {...@@ -2133,7 +2127,6 @@ pub fn createAtom(self: *Elf) !Atom.Index {
2133 .offset_table_index = offset_table_index,2127 .offset_table_index = offset_table_index,
2134 .prev_index = null,2128 .prev_index = null,
2135 .next_index = null,2129 .next_index = null,
2136 .dbg_info_atom = undefined,
2137 };2130 };
2138 log.debug("creating ATOM(%{d}) at index {d}", .{ local_sym_index, atom_index });2131 log.debug("creating ATOM(%{d}) at index {d}", .{ local_sym_index, atom_index });
2139 return atom_index;2132 return atom_index;
...@@ -2219,16 +2212,16 @@ fn allocateAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignme...@@ -2219,16 +2212,16 @@ fn allocateAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignme
2219 try self.growAllocSection(sym.st_shndx, needed_size);2212 try self.growAllocSection(sym.st_shndx, needed_size);
2220 maybe_last_atom_index.* = atom_index;2213 maybe_last_atom_index.* = atom_index;
22212214
2222 // if (self.dwarf) |_| {2215 if (self.dwarf) |_| {
2223 // // The .debug_info section has `low_pc` and `high_pc` values which is the virtual address2216 // The .debug_info section has `low_pc` and `high_pc` values which is the virtual address
2224 // // range of the compilation unit. When we expand the text section, this range changes,2217 // range of the compilation unit. When we expand the text section, this range changes,
2225 // // so the DW_TAG.compile_unit tag of the .debug_info section becomes dirty.2218 // so the DW_TAG.compile_unit tag of the .debug_info section becomes dirty.
2226 // self.debug_info_header_dirty = true;2219 self.debug_info_header_dirty = true;
2227 // // This becomes dirty for the same reason. We could potentially make this more2220 // This becomes dirty for the same reason. We could potentially make this more
2228 // // fine-grained with the addition of support for more compilation units. It is planned to2221 // fine-grained with the addition of support for more compilation units. It is planned to
2229 // // model each package as a different compilation unit.2222 // model each package as a different compilation unit.
2230 // self.debug_aranges_section_dirty = true;2223 self.debug_aranges_section_dirty = true;
2231 // }2224 }
2232 }2225 }
2233 shdr.sh_addralign = math.max(shdr.sh_addralign, alignment);2226 shdr.sh_addralign = math.max(shdr.sh_addralign, alignment);
22342227
...@@ -2333,9 +2326,9 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {...@@ -2333,9 +2326,9 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {
2333 kv.value.exports.deinit(self.base.allocator);2326 kv.value.exports.deinit(self.base.allocator);
2334 }2327 }
23352328
2336 // if (self.dwarf) |*dw| {2329 if (self.dwarf) |*dw| {
2337 // dw.freeDecl(decl);2330 dw.freeDecl(decl_index);
2338 // }2331 }
2339}2332}
23402333
2341pub fn getOrCreateAtomForDecl(self: *Elf, decl_index: Module.Decl.Index) !Atom.Index {2334pub fn getOrCreateAtomForDecl(self: *Elf, decl_index: Module.Decl.Index) !Atom.Index {
...@@ -2471,15 +2464,15 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven...@@ -2471,15 +2464,15 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
2471 var code_buffer = std.ArrayList(u8).init(self.base.allocator);2464 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
2472 defer code_buffer.deinit();2465 defer code_buffer.deinit();
24732466
2474 // var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null;2467 var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null;
2475 // defer if (decl_state) |*ds| ds.deinit();2468 defer if (decl_state) |*ds| ds.deinit();
24762469
2477 // const res = if (decl_state) |*ds|2470 const res = if (decl_state) |*ds|
2478 // try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{2471 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{
2479 // .dwarf = ds,2472 .dwarf = ds,
2480 // })2473 })
2481 // else2474 else
2482 const res = try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none);2475 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none);
24832476
2484 const code = switch (res) {2477 const code = switch (res) {
2485 .ok => code_buffer.items,2478 .ok => code_buffer.items,
...@@ -2490,16 +2483,15 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven...@@ -2490,16 +2483,15 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
2490 },2483 },
2491 };2484 };
2492 const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_FUNC);2485 const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_FUNC);
2493 _ = local_sym;2486 if (decl_state) |*ds| {
2494 // if (decl_state) |*ds| {2487 try self.dwarf.?.commitDeclState(
2495 // try self.dwarf.?.commitDeclState(2488 module,
2496 // module,2489 decl_index,
2497 // decl_index,2490 local_sym.st_value,
2498 // local_sym.st_value,2491 local_sym.st_size,
2499 // local_sym.st_size,2492 ds,
2500 // ds,2493 );
2501 // );2494 }
2502 // }
25032495
2504 // Since we updated the vaddr and the size, each corresponding export2496 // Since we updated the vaddr and the size, each corresponding export
2505 // symbol also needs to be updated.2497 // symbol also needs to be updated.
...@@ -2536,27 +2528,27 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v...@@ -2536,27 +2528,27 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v
2536 var code_buffer = std.ArrayList(u8).init(self.base.allocator);2528 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
2537 defer code_buffer.deinit();2529 defer code_buffer.deinit();
25382530
2539 // var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null;2531 var decl_state: ?Dwarf.DeclState = if (self.dwarf) |*dw| try dw.initDeclState(module, decl_index) else null;
2540 // defer if (decl_state) |*ds| ds.deinit();2532 defer if (decl_state) |*ds| ds.deinit();
25412533
2542 // TODO implement .debug_info for global variables2534 // TODO implement .debug_info for global variables
2543 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;2535 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
2544 // const res = if (decl_state) |*ds|2536 const res = if (decl_state) |*ds|
2545 // try codegen.generateSymbol(&self.base, decl.srcLoc(), .{2537 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2546 // .ty = decl.ty,2538 .ty = decl.ty,
2547 // .val = decl_val,2539 .val = decl_val,
2548 // }, &code_buffer, .{2540 }, &code_buffer, .{
2549 // .dwarf = ds,2541 .dwarf = ds,
2550 // }, .{2542 }, .{
2551 // .parent_atom_index = atom.getSymbolIndex().?,2543 .parent_atom_index = atom.getSymbolIndex().?,
2552 // })2544 })
2553 // else2545 else
2554 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), .{2546 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2555 .ty = decl.ty,2547 .ty = decl.ty,
2556 .val = decl_val,2548 .val = decl_val,
2557 }, &code_buffer, .none, .{2549 }, &code_buffer, .none, .{
2558 .parent_atom_index = atom.getSymbolIndex().?,2550 .parent_atom_index = atom.getSymbolIndex().?,
2559 });2551 });
25602552
2561 const code = switch (res) {2553 const code = switch (res) {
2562 .ok => code_buffer.items,2554 .ok => code_buffer.items,
...@@ -2568,16 +2560,15 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v...@@ -2568,16 +2560,15 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v
2568 };2560 };
25692561
2570 const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_OBJECT);2562 const local_sym = try self.updateDeclCode(decl_index, code, elf.STT_OBJECT);
2571 _ = local_sym;2563 if (decl_state) |*ds| {
2572 // if (decl_state) |*ds| {2564 try self.dwarf.?.commitDeclState(
2573 // try self.dwarf.?.commitDeclState(2565 module,
2574 // module,2566 decl_index,
2575 // decl_index,2567 local_sym.st_value,
2576 // local_sym.st_value,2568 local_sym.st_size,
2577 // local_sym.st_size,2569 ds,
2578 // ds,2570 );
2579 // );2571 }
2580 // }
25812572
2582 // Since we updated the vaddr and the size, each corresponding export2573 // Since we updated the vaddr and the size, each corresponding export
2583 // symbol also needs to be updated.2574 // symbol also needs to be updated.
...@@ -2737,19 +2728,20 @@ pub fn updateDeclExports(...@@ -2737,19 +2728,20 @@ pub fn updateDeclExports(
2737}2728}
27382729
2739/// Must be called only after a successful call to `updateDecl`.2730/// Must be called only after a successful call to `updateDecl`.
2740pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl: *const Module.Decl) !void {2731pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl_index: Module.Decl.Index) !void {
2741 const tracy = trace(@src());2732 const tracy = trace(@src());
2742 defer tracy.end();2733 defer tracy.end();
27432734
2735 const decl = mod.declPtr(decl_index);
2744 const decl_name = try decl.getFullyQualifiedName(mod);2736 const decl_name = try decl.getFullyQualifiedName(mod);
2745 defer self.base.allocator.free(decl_name);2737 defer self.base.allocator.free(decl_name);
27462738
2747 log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl });2739 log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl });
27482740
2749 if (self.llvm_object) |_| return;2741 if (self.llvm_object) |_| return;
2750 // if (self.dwarf) |*dw| {2742 if (self.dwarf) |*dw| {
2751 // try dw.updateDeclLineNumber(decl);2743 try dw.updateDeclLineNumber(mod, decl_index);
2752 // }2744 }
2753}2745}
27542746
2755pub fn deleteDeclExport(self: *Elf, decl_index: Module.Decl.Index, name: []const u8) void {2747pub fn deleteDeclExport(self: *Elf, decl_index: Module.Decl.Index, name: []const u8) void {
src/link/Elf/Atom.zig-3
...@@ -4,7 +4,6 @@ const std = @import("std");...@@ -4,7 +4,6 @@ const std = @import("std");
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const elf = std.elf;5const elf = std.elf;
66
7const Dwarf = @import("../Dwarf.zig");
8const Elf = @import("../Elf.zig");7const Elf = @import("../Elf.zig");
98
10/// Each decl always gets a local symbol with the fully qualified name.9/// Each decl always gets a local symbol with the fully qualified name.
...@@ -23,8 +22,6 @@ offset_table_index: u32,...@@ -23,8 +22,6 @@ offset_table_index: u32,
23prev_index: ?Index,22prev_index: ?Index,
24next_index: ?Index,23next_index: ?Index,
2524
26dbg_info_atom: Dwarf.Atom,
27
28pub const Index = u32;25pub const Index = u32;
2926
30pub const Reloc = struct {27pub const Reloc = struct {
src/link/MachO.zig+59-71
...@@ -472,9 +472,9 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -472,9 +472,9 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
472472
473 const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented;473 const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented;
474474
475 // if (self.d_sym) |*d_sym| {475 if (self.d_sym) |*d_sym| {
476 // try d_sym.dwarf.flushModule(module);476 try d_sym.dwarf.flushModule(module);
477 // }477 }
478478
479 var libs = std.StringArrayHashMap(link.SystemLib).init(arena);479 var libs = std.StringArrayHashMap(link.SystemLib).init(arena);
480 try resolveLibSystem(480 try resolveLibSystem(
...@@ -664,10 +664,10 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -664,10 +664,10 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
664 try self.writeCodeSignature(comp, csig); // code signing always comes last664 try self.writeCodeSignature(comp, csig); // code signing always comes last
665 }665 }
666666
667 // if (self.d_sym) |*d_sym| {667 if (self.d_sym) |*d_sym| {
668 // // Flush debug symbols bundle.668 // Flush debug symbols bundle.
669 // try d_sym.flushModule(self);669 try d_sym.flushModule(self);
670 // }670 }
671671
672 // if (build_options.enable_link_snapshots) {672 // if (build_options.enable_link_snapshots) {
673 // if (self.base.options.enable_link_snapshots)673 // if (self.base.options.enable_link_snapshots)
...@@ -1089,7 +1089,6 @@ pub fn createAtom(self: *MachO) !Atom.Index {...@@ -1089,7 +1089,6 @@ pub fn createAtom(self: *MachO) !Atom.Index {
1089 .alignment = 0,1089 .alignment = 0,
1090 .prev_index = null,1090 .prev_index = null,
1091 .next_index = null,1091 .next_index = null,
1092 .dbg_info_atom = undefined,
1093 };1092 };
1094 log.debug("creating ATOM(%{d}) at index {d}", .{ sym_index, atom_index });1093 log.debug("creating ATOM(%{d}) at index {d}", .{ sym_index, atom_index });
1095 return atom_index;1094 return atom_index;
...@@ -1724,9 +1723,9 @@ pub fn deinit(self: *MachO) void {...@@ -1724,9 +1723,9 @@ pub fn deinit(self: *MachO) void {
1724 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);1723 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
1725 }1724 }
17261725
1727 // if (self.d_sym) |*d_sym| {1726 if (self.d_sym) |*d_sym| {
1728 // d_sym.deinit();1727 d_sym.deinit();
1729 // }1728 }
17301729
1731 self.got_entries.deinit(gpa);1730 self.got_entries.deinit(gpa);
1732 self.got_entries_free_list.deinit(gpa);1731 self.got_entries_free_list.deinit(gpa);
...@@ -1804,9 +1803,8 @@ pub fn deinit(self: *MachO) void {...@@ -1804,9 +1803,8 @@ pub fn deinit(self: *MachO) void {
1804}1803}
18051804
1806fn freeAtom(self: *MachO, atom_index: Atom.Index) void {1805fn freeAtom(self: *MachO, atom_index: Atom.Index) void {
1807 log.debug("freeAtom {d}", .{atom_index});
1808
1809 const gpa = self.base.allocator;1806 const gpa = self.base.allocator;
1807 log.debug("freeAtom {d}", .{atom_index});
18101808
1811 // Remove any relocs and base relocs associated with this Atom1809 // Remove any relocs and base relocs associated with this Atom
1812 Atom.freeRelocations(self, atom_index);1810 Atom.freeRelocations(self, atom_index);
...@@ -1876,9 +1874,9 @@ fn freeAtom(self: *MachO, atom_index: Atom.Index) void {...@@ -1876,9 +1874,9 @@ fn freeAtom(self: *MachO, atom_index: Atom.Index) void {
1876 };1874 };
1877 _ = self.got_entries_table.remove(got_target);1875 _ = self.got_entries_table.remove(got_target);
18781876
1879 // if (self.d_sym) |*d_sym| {1877 if (self.d_sym) |*d_sym| {
1880 // d_sym.swapRemoveRelocs(sym_index);1878 d_sym.swapRemoveRelocs(sym_index);
1881 // }1879 }
18821880
1883 log.debug(" adding GOT index {d} to free list (target local@{d})", .{ got_index, sym_index });1881 log.debug(" adding GOT index {d} to free list (target local@{d})", .{ got_index, sym_index });
1884 }1882 }
...@@ -1887,10 +1885,6 @@ fn freeAtom(self: *MachO, atom_index: Atom.Index) void {...@@ -1887,10 +1885,6 @@ fn freeAtom(self: *MachO, atom_index: Atom.Index) void {
1887 _ = self.atom_by_index_table.remove(sym_index);1885 _ = self.atom_by_index_table.remove(sym_index);
1888 log.debug(" adding local symbol index {d} to free list", .{sym_index});1886 log.debug(" adding local symbol index {d} to free list", .{sym_index});
1889 self.getAtomPtr(atom_index).sym_index = 0;1887 self.getAtomPtr(atom_index).sym_index = 0;
1890
1891 // if (self.d_sym) |*d_sym| {
1892 // d_sym.dwarf.freeAtom(&atom.dbg_info_atom);
1893 // }
1894}1888}
18951889
1896fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void {1890fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void {
...@@ -2020,23 +2014,22 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv...@@ -2020,23 +2014,22 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
2020 Atom.freeRelocations(self, atom_index);2014 Atom.freeRelocations(self, atom_index);
20212015
2022 const atom = self.getAtom(atom_index);2016 const atom = self.getAtom(atom_index);
2023 _ = atom;
20242017
2025 var code_buffer = std.ArrayList(u8).init(self.base.allocator);2018 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
2026 defer code_buffer.deinit();2019 defer code_buffer.deinit();
20272020
2028 // var decl_state = if (self.d_sym) |*d_sym|2021 var decl_state = if (self.d_sym) |*d_sym|
2029 // try d_sym.dwarf.initDeclState(module, decl_index)2022 try d_sym.dwarf.initDeclState(module, decl_index)
2030 // else2023 else
2031 // null;2024 null;
2032 // defer if (decl_state) |*ds| ds.deinit();2025 defer if (decl_state) |*ds| ds.deinit();
20332026
2034 // const res = if (decl_state) |*ds|2027 const res = if (decl_state) |*ds|
2035 // try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{2028 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{
2036 // .dwarf = ds,2029 .dwarf = ds,
2037 // })2030 })
2038 // else2031 else
2039 const res = try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none);2032 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .none);
20402033
2041 const code = switch (res) {2034 const code = switch (res) {
2042 .ok => code_buffer.items,2035 .ok => code_buffer.items,
...@@ -2048,11 +2041,10 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv...@@ -2048,11 +2041,10 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
2048 };2041 };
20492042
2050 const addr = try self.updateDeclCode(decl_index, code);2043 const addr = try self.updateDeclCode(decl_index, code);
2051 _ = addr;
20522044
2053 // if (decl_state) |*ds| {2045 if (decl_state) |*ds| {
2054 // try self.d_sym.?.dwarf.commitDeclState(module, decl_index, addr, atom.size, ds);2046 try self.d_sym.?.dwarf.commitDeclState(module, decl_index, addr, atom.size, ds);
2055 // }2047 }
20562048
2057 // Since we updated the vaddr and the size, each corresponding export symbol also2049 // Since we updated the vaddr and the size, each corresponding export symbol also
2058 // needs to be updated.2050 // needs to be updated.
...@@ -2154,29 +2146,29 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)...@@ -2154,29 +2146,29 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
2154 var code_buffer = std.ArrayList(u8).init(self.base.allocator);2146 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
2155 defer code_buffer.deinit();2147 defer code_buffer.deinit();
21562148
2157 // var decl_state: ?Dwarf.DeclState = if (self.d_sym) |*d_sym|2149 var decl_state: ?Dwarf.DeclState = if (self.d_sym) |*d_sym|
2158 // try d_sym.dwarf.initDeclState(module, decl_index)2150 try d_sym.dwarf.initDeclState(module, decl_index)
2159 // else2151 else
2160 // null;2152 null;
2161 // defer if (decl_state) |*ds| ds.deinit();2153 defer if (decl_state) |*ds| ds.deinit();
21622154
2163 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;2155 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
2164 // const res = if (decl_state) |*ds|2156 const res = if (decl_state) |*ds|
2165 // try codegen.generateSymbol(&self.base, decl.srcLoc(), .{2157 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2166 // .ty = decl.ty,2158 .ty = decl.ty,
2167 // .val = decl_val,2159 .val = decl_val,
2168 // }, &code_buffer, .{2160 }, &code_buffer, .{
2169 // .dwarf = ds,2161 .dwarf = ds,
2170 // }, .{2162 }, .{
2171 // .parent_atom_index = atom.getSymbolIndex().?,2163 .parent_atom_index = atom.getSymbolIndex().?,
2172 // })2164 })
2173 // else2165 else
2174 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), .{2166 try codegen.generateSymbol(&self.base, decl.srcLoc(), .{
2175 .ty = decl.ty,2167 .ty = decl.ty,
2176 .val = decl_val,2168 .val = decl_val,
2177 }, &code_buffer, .none, .{2169 }, &code_buffer, .none, .{
2178 .parent_atom_index = atom.getSymbolIndex().?,2170 .parent_atom_index = atom.getSymbolIndex().?,
2179 });2171 });
21802172
2181 const code = switch (res) {2173 const code = switch (res) {
2182 .ok => code_buffer.items,2174 .ok => code_buffer.items,
...@@ -2187,11 +2179,10 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)...@@ -2187,11 +2179,10 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
2187 },2179 },
2188 };2180 };
2189 const addr = try self.updateDeclCode(decl_index, code);2181 const addr = try self.updateDeclCode(decl_index, code);
2190 _ = addr;
21912182
2192 // if (decl_state) |*ds| {2183 if (decl_state) |*ds| {
2193 // try self.d_sym.?.dwarf.commitDeclState(module, decl_index, addr, atom.size, ds);2184 try self.d_sym.?.dwarf.commitDeclState(module, decl_index, addr, atom.size, ds);
2194 // }2185 }
21952186
2196 // Since we updated the vaddr and the size, each corresponding export symbol also2187 // Since we updated the vaddr and the size, each corresponding export symbol also
2197 // needs to be updated.2188 // needs to be updated.
...@@ -2432,13 +2423,10 @@ fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []const u8)...@@ -2432,13 +2423,10 @@ fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []const u8)
2432 return atom.getSymbol(self).n_value;2423 return atom.getSymbol(self).n_value;
2433}2424}
24342425
2435pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl: *const Module.Decl) !void {2426pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: Module.Decl.Index) !void {
2436 _ = decl;2427 if (self.d_sym) |*d_sym| {
2437 _ = self;2428 try d_sym.dwarf.updateDeclLineNumber(module, decl_index);
2438 _ = module;2429 }
2439 // if (self.d_sym) |*d_sym| {
2440 // try d_sym.dwarf.updateDeclLineNumber(decl);
2441 // }
2442}2430}
24432431
2444pub fn updateDeclExports(2432pub fn updateDeclExports(
...@@ -2611,9 +2599,9 @@ pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {...@@ -2611,9 +2599,9 @@ pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {
2611 kv.value.exports.deinit(self.base.allocator);2599 kv.value.exports.deinit(self.base.allocator);
2612 }2600 }
26132601
2614 // if (self.d_sym) |*d_sym| {2602 if (self.d_sym) |*d_sym| {
2615 // d_sym.dwarf.freeDecl(decl);2603 d_sym.dwarf.freeDecl(decl_index);
2616 // }2604 }
2617}2605}
26182606
2619pub fn getDeclVAddr(self: *MachO, decl_index: Module.Decl.Index, reloc_info: File.RelocInfo) !u64 {2607pub fn getDeclVAddr(self: *MachO, decl_index: Module.Decl.Index, reloc_info: File.RelocInfo) !u64 {
src/link/MachO/Atom.zig-3
...@@ -13,7 +13,6 @@ const trace = @import("../../tracy.zig").trace;...@@ -13,7 +13,6 @@ const trace = @import("../../tracy.zig").trace;
1313
14const Allocator = mem.Allocator;14const Allocator = mem.Allocator;
15const Arch = std.Target.Cpu.Arch;15const Arch = std.Target.Cpu.Arch;
16const Dwarf = @import("../Dwarf.zig");
17const MachO = @import("../MachO.zig");16const MachO = @import("../MachO.zig");
18const Relocation = @import("Relocation.zig");17const Relocation = @import("Relocation.zig");
19const SymbolWithLoc = MachO.SymbolWithLoc;18const SymbolWithLoc = MachO.SymbolWithLoc;
...@@ -43,8 +42,6 @@ alignment: u32,...@@ -43,8 +42,6 @@ alignment: u32,
43next_index: ?Index,42next_index: ?Index,
44prev_index: ?Index,43prev_index: ?Index,
4544
46dbg_info_atom: Dwarf.Atom,
47
48pub const Index = u32;45pub const Index = u32;
4946
50pub const Binding = struct {47pub const Binding = struct {
src/link/Plan9.zig+2-2
...@@ -1018,10 +1018,10 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {...@@ -1018,10 +1018,10 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
1018}1018}
10191019
1020/// Must be called only after a successful call to `updateDecl`.1020/// Must be called only after a successful call to `updateDecl`.
1021pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl: *const Module.Decl) !void {1021pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !void {
1022 _ = self;1022 _ = self;
1023 _ = mod;1023 _ = mod;
1024 _ = decl;1024 _ = decl_index;
1025}1025}
10261026
1027pub fn getDeclVAddr(1027pub fn getDeclVAddr(
src/link/Wasm.zig+6-11
...@@ -183,13 +183,9 @@ pub const Segment = struct {...@@ -183,13 +183,9 @@ pub const Segment = struct {
183pub const FnData = struct {183pub const FnData = struct {
184 /// Reference to the wasm type that represents this function.184 /// Reference to the wasm type that represents this function.
185 type_index: u32,185 type_index: u32,
186 /// Contains debug information related to this function.
187 /// For Wasm, the offset is relative to the code-section.
188 src_fn: Dwarf.SrcFn,
189186
190 pub const empty: FnData = .{187 pub const empty: FnData = .{
191 .type_index = undefined,188 .type_index = undefined,
192 .src_fn = Dwarf.SrcFn.empty,
193 };189 };
194};190};
195191
...@@ -1122,17 +1118,18 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi...@@ -1122,17 +1118,18 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
1122 return wasm.finishUpdateDecl(decl, code);1118 return wasm.finishUpdateDecl(decl, code);
1123}1119}
11241120
1125pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl: *const Module.Decl) !void {1121pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !void {
1126 if (wasm.llvm_object) |_| return;1122 if (wasm.llvm_object) |_| return;
1127 if (wasm.dwarf) |*dw| {1123 if (wasm.dwarf) |*dw| {
1128 const tracy = trace(@src());1124 const tracy = trace(@src());
1129 defer tracy.end();1125 defer tracy.end();
11301126
1127 const decl = mod.declPtr(decl_index);
1131 const decl_name = try decl.getFullyQualifiedName(mod);1128 const decl_name = try decl.getFullyQualifiedName(mod);
1132 defer wasm.base.allocator.free(decl_name);1129 defer wasm.base.allocator.free(decl_name);
11331130
1134 log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl });1131 log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl });
1135 try dw.updateDeclLineNumber(decl);1132 try dw.updateDeclLineNumber(mod, decl_index);
1136 }1133 }
1137}1134}
11381135
...@@ -1460,10 +1457,9 @@ pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {...@@ -1460,10 +1457,9 @@ pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {
1460 _ = wasm.resolved_symbols.swapRemove(atom.symbolLoc());1457 _ = wasm.resolved_symbols.swapRemove(atom.symbolLoc());
1461 _ = wasm.symbol_atom.remove(atom.symbolLoc());1458 _ = wasm.symbol_atom.remove(atom.symbolLoc());
14621459
1463 if (wasm.dwarf) |*dwarf| {1460 // if (wasm.dwarf) |*dwarf| {
1464 dwarf.freeDecl(decl);1461 // dwarf.freeDecl(decl_index);
1465 dwarf.freeAtom(&atom.dbg_info_atom);1462 // }
1466 }
14671463
1468 atom.deinit(wasm.base.allocator);1464 atom.deinit(wasm.base.allocator);
1469}1465}
...@@ -1882,7 +1878,6 @@ fn initializeCallCtorsFunction(wasm: *Wasm) !void {...@@ -1882,7 +1878,6 @@ fn initializeCallCtorsFunction(wasm: *Wasm) !void {
1882 .next = null,1878 .next = null,
1883 .prev = null,1879 .prev = null,
1884 .code = function_body.moveToUnmanaged(),1880 .code = function_body.moveToUnmanaged(),
1885 .dbg_info_atom = undefined,
1886 };1881 };
1887 try wasm.managed_atoms.append(wasm.base.allocator, atom);1882 try wasm.managed_atoms.append(wasm.base.allocator, atom);
1888 try wasm.appendAtomAtIndex(wasm.code_section_index.?, atom);1883 try wasm.appendAtomAtIndex(wasm.code_section_index.?, atom);
src/link/Wasm/Atom.zig-5
...@@ -4,7 +4,6 @@ const std = @import("std");...@@ -4,7 +4,6 @@ const std = @import("std");
4const types = @import("types.zig");4const types = @import("types.zig");
5const Wasm = @import("../Wasm.zig");5const Wasm = @import("../Wasm.zig");
6const Symbol = @import("Symbol.zig");6const Symbol = @import("Symbol.zig");
7const Dwarf = @import("../Dwarf.zig");
87
9const leb = std.leb;8const leb = std.leb;
10const log = std.log.scoped(.link);9const log = std.log.scoped(.link);
...@@ -39,9 +38,6 @@ prev: ?*Atom,...@@ -39,9 +38,6 @@ prev: ?*Atom,
39/// When the parent atom is being freed, it will also do so for all local atoms.38/// When the parent atom is being freed, it will also do so for all local atoms.
40locals: std.ArrayListUnmanaged(Atom) = .{},39locals: std.ArrayListUnmanaged(Atom) = .{},
4140
42/// Represents the debug Atom that holds all debug information of this Atom.
43dbg_info_atom: Dwarf.Atom,
44
45/// Represents a default empty wasm `Atom`41/// Represents a default empty wasm `Atom`
46pub const empty: Atom = .{42pub const empty: Atom = .{
47 .alignment = 0,43 .alignment = 0,
...@@ -51,7 +47,6 @@ pub const empty: Atom = .{...@@ -51,7 +47,6 @@ pub const empty: Atom = .{
51 .prev = null,47 .prev = null,
52 .size = 0,48 .size = 0,
53 .sym_index = 0,49 .sym_index = 0,
54 .dbg_info_atom = undefined,
55};50};
5651
57/// Frees all resources owned by this `Atom`.52/// Frees all resources owned by this `Atom`.