| author | |
| committer | |
| log | 5de2aae63cd75322e58204a6be8df49754e4851a |
| tree | c8e61e82649f412b6a7c4b5bb422f9855df61665 |
| parent | d98fc53b8fbe479f828114b0276d5290146cc2a3 |
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 COFF | 5187 | // 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 state | 5190 | // 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 state | 5195 | // 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 argument | 203 | else => unreachable, // not a possible argument |
| 204 | 204 | ||
| 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 argument | 282 | else => unreachable, // not a possible argument |
| 283 | }; | 283 | }; |
| 284 | 284 | ||
| 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 { |
| 1615 | 1615 | ||
| 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 { |
| 3412 | 3412 | ||
| 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); |
| 5543 | 5543 | ||
| 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 parameter | 3837 | 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 | }; |
| 274 | 274 | ||
| 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 | } |
| 582 | 582 | ||
| 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 | } |
| 221 | 221 | ||
| 222 | pub fn updateDeclLineNumber(self: *C, module: *Module, decl: *Module.Decl) !void { | 222 | pub 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-generating | 223 | // 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 | } |
| 229 | 229 | ||
| 230 | pub fn flush(self: *C, comp: *Compilation, prog_node: *std.Progress.Node) !void { | 230 | pub 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 | }; |
| 198 | pub const SrcFn = void; | ||
| 199 | 198 | ||
| 200 | pub const SymbolWithLoc = struct { | 199 | pub 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 | } |
| 1547 | 1546 | ||
| 1548 | pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !void { | 1547 | pub 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 | } |
| 1554 | 1553 |
src/link/Dwarf.zig+292-224| ... | @@ -27,17 +27,21 @@ bin_file: *File, | ... | @@ -27,17 +27,21 @@ bin_file: *File, |
| 27 | ptr_width: PtrWidth, | 27 | ptr_width: PtrWidth, |
| 28 | target: std.Target, | 28 | target: std.Target, |
| 29 | 29 | ||
| 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. |
| 32 | dbg_line_fn_free_list: std.AutoHashMapUnmanaged(*SrcFn, void) = .{}, | 32 | src_fn_free_list: std.AutoHashMapUnmanaged(Atom.Index, void) = .{}, |
| 33 | dbg_line_fn_first: ?*SrcFn = null, | 33 | src_fn_first_index: ?Atom.Index = null, |
| 34 | dbg_line_fn_last: ?*SrcFn = null, | 34 | src_fn_last_index: ?Atom.Index = null, |
| 35 | src_fns: std.ArrayListUnmanaged(Atom) = .{}, | ||
| 36 | src_fn_decls: AtomTable = .{}, | ||
| 35 | 37 | ||
| 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. |
| 38 | atom_free_list: std.AutoHashMapUnmanaged(*Atom, void) = .{}, | 40 | di_atom_free_list: std.AutoHashMapUnmanaged(Atom.Index, void) = .{}, |
| 39 | atom_first: ?*Atom = null, | 41 | di_atom_first_index: ?Atom.Index = null, |
| 40 | atom_last: ?*Atom = null, | 42 | di_atom_last_index: ?Atom.Index = null, |
| 43 | di_atoms: std.ArrayListUnmanaged(Atom) = .{}, | ||
| 44 | di_atom_decls: AtomTable = .{}, | ||
| 41 | 45 | ||
| 42 | abbrev_table_offset: ?u64 = null, | 46 | abbrev_table_offset: ?u64 = null, |
| 43 | 47 | ||
| ... | @@ -51,22 +55,23 @@ strtab: StringTable(.strtab) = .{}, | ... | @@ -51,22 +55,23 @@ strtab: StringTable(.strtab) = .{}, |
| 51 | /// * []file_names | 55 | /// * []file_names |
| 52 | di_files: std.AutoArrayHashMapUnmanaged(*const Module.File, void) = .{}, | 56 | di_files: std.AutoArrayHashMapUnmanaged(*const Module.File, void) = .{}, |
| 53 | 57 | ||
| 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. | ||
| 57 | managed_atoms: std.ArrayListUnmanaged(*Atom) = .{}, | ||
| 58 | |||
| 59 | global_abbrev_relocs: std.ArrayListUnmanaged(AbbrevRelocation) = .{}, | 58 | global_abbrev_relocs: std.ArrayListUnmanaged(AbbrevRelocation) = .{}, |
| 60 | 59 | ||
| 61 | pub const Atom = struct { | 60 | const 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. | 62 | const 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 | }; |
| 71 | 76 | ||
| 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 { |
| 76 | pub const DeclState = struct { | 81 | pub 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) = .{}, |
| 91 | 97 | ||
| 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 { |
| 120 | 127 | ||
| 121 | /// Adds local type relocation of the form: @offset => @this + addend | 128 | /// 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 + 0 | 140 | /// Adds global type relocation of the form: @offset => @symbol + 0 |
| 134 | /// @symbol signifies a type abbreviation posititioned somewhere in the .debug_abbrev section | 141 | /// @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.ref4 | 235 | // 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.sdata | 239 | // 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.ref4 | 247 | // 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.sdata | 251 | // 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.sdata | 282 | // 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.ref4 | 290 | // 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.sdata | 294 | // 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.ref4 | 302 | // 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.ref4 | 313 | // 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_type | 317 | // 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.ref4 | 319 | // 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.udata | 323 | // 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.ref4 | 347 | // 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.sdata | 351 | // 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.ref4 | 379 | // 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.sdata | 383 | // 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.ref4 | 462 | // 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.sdata | 466 | // 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.ref4 | 489 | // 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.sdata | 493 | // 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.ref4 | 506 | // 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.sdata | 510 | // 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); |
| 505 | 512 | ||
| ... | @@ -542,7 +549,7 @@ pub const DeclState = struct { | ... | @@ -542,7 +549,7 @@ pub const DeclState = struct { |
| 542 | // DW.AT.type, DW.FORM.ref4 | 549 | // 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.sdata | 553 | // 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); |
| 548 | 555 | ||
| ... | @@ -555,7 +562,7 @@ pub const DeclState = struct { | ... | @@ -555,7 +562,7 @@ pub const DeclState = struct { |
| 555 | // DW.AT.type, DW.FORM.ref4 | 562 | // 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.sdata | 566 | // 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); |
| 561 | 568 | ||
| ... | @@ -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]; |
| 598 | 604 | ||
| 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.ref4 | 646 | 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.ref4 | 647 | 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.string | 648 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 643 | } | 649 | } |
| 644 | 650 | ||
| ... | @@ -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.ref4 | 789 | 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.string | 791 | dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string |
| 787 | } | 792 | } |
| 788 | 793 | ||
| ... | @@ -815,7 +820,7 @@ pub const DeclState = struct { | ... | @@ -815,7 +820,7 @@ pub const DeclState = struct { |
| 815 | }; | 820 | }; |
| 816 | 821 | ||
| 817 | pub const AbbrevEntry = struct { | 822 | pub 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 + addend | 829 | /// 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 | }; |
| 843 | 848 | ||
| 844 | pub 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 | |||
| 864 | pub const PtrWidth = enum { p32, p64 }; | 849 | pub const PtrWidth = enum { p32, p64 }; |
| 865 | 850 | ||
| 866 | pub const AbbrevKind = enum(u8) { | 851 | pub 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 { |
| 910 | 895 | ||
| 911 | pub fn deinit(self: *Dwarf) void { | 896 | pub 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 | } |
| 924 | 911 | ||
| 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 }); |
| 936 | 923 | ||
| 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; |
| 942 | 929 | ||
| 930 | const di_atom_index = try self.getOrCreateAtomForDecl(.di_atom, decl_index); | ||
| 931 | |||
| 943 | assert(decl.has_tv); | 932 | assert(decl.has_tv); |
| 944 | 933 | ||
| 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); |
| 949 | 940 | ||
| ... | @@ -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.data4 | 994 | 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.ref4 | 998 | dbg_info_buffer.items.len += 4; // DW.AT.type, DW.FORM.ref4 |
| 1009 | } | 999 | } |
| 1010 | 1000 | ||
| ... | @@ -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` for | 1066 | // This logic is nearly identical to the logic below in `updateDeclDebugInfo` for |
| 1077 | // `TextBlock` and the .debug_info. If you are editing this logic, you | 1067 | // `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); |
| 1086 | 1072 | ||
| 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; | ||
| 1124 | 1112 | ||
| 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; | ||
| 1133 | 1122 | ||
| 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; |
| 1140 | 1129 | ||
| 1141 | src_fn.off = padToIdeal(self.dbgLineNeededHeaderBytes(&[0][]u8{}, &[0][]u8{})); | 1130 | src_fn.off = padToIdeal(self.dbgLineNeededHeaderBytes(&[0][]u8{}, &[0][]u8{})); |
| 1142 | } | 1131 | } |
| 1143 | 1132 | ||
| 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; | ||
| 1148 | 1144 | ||
| 1149 | // We only have support for one compilation unit so far, so the offsets are directly | 1145 | // 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; |
| 1215 | 1211 | ||
| 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 of | 1214 | // 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 actual | 1215 | // 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; |
| 1236 | 1232 | ||
| 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 | } |
| 1241 | 1237 | ||
| 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)); |
| 1244 | 1240 | ||
| 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 | } |
| 1305 | 1303 | ||
| 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 | } |
| 1309 | 1307 | ||
| 1310 | fn updateDeclDebugInfoAllocation(self: *Dwarf, atom: *Atom, len: u32) !void { | 1308 | fn 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(); |
| 1313 | 1311 | ||
| ... | @@ -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; |
| 1318 | 1316 | ||
| 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; | ||
| 1357 | 1358 | ||
| 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; | ||
| 1366 | 1368 | ||
| 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_info | 1372 | // 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; |
| 1373 | 1375 | ||
| 1374 | atom.off = @intCast(u32, padToIdeal(self.dbgInfoHeaderBytes())); | 1376 | atom.off = @intCast(u32, padToIdeal(self.dbgInfoHeaderBytes())); |
| 1375 | } | 1377 | } |
| 1376 | } | 1378 | } |
| 1377 | 1379 | ||
| 1378 | fn writeDeclDebugInfo(self: *Dwarf, atom: *Atom, dbg_info_buf: []const u8) !void { | 1380 | fn 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(); |
| 1381 | 1383 | ||
| ... | @@ -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; |
| 1386 | 1388 | ||
| 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; | ||
| 1392 | 1402 | ||
| 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; |
| 1395 | 1405 | ||
| 1396 | // We only have support for one compilation unit so far, so the offsets are directly | 1406 | // 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 | } |
| 1461 | 1471 | ||
| 1462 | pub fn updateDeclLineNumber(self: *Dwarf, decl: *const Module.Decl) !void { | 1472 | pub 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(); |
| 1465 | 1475 | ||
| 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 | } |
| 1498 | 1513 | ||
| 1499 | pub fn freeAtom(self: *Dwarf, atom: *Atom) void { | 1514 | pub 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; | ||
| 1510 | 1516 | ||
| 1511 | // TODO the free list logic like we do for text blocks above | 1517 | // 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 | } |
| 1515 | 1543 | ||
| 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 | } | ||
| 1522 | 1548 | ||
| 1523 | pub 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 thing | 1550 | 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); | ||
| 1534 | 1556 | ||
| 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 | } |
| 1554 | 1571 | ||
| ... | @@ -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; |
| 2278 | 2295 | ||
| 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; | ||
| 2281 | 2302 | ||
| 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); |
| 2284 | 2305 | ||
| 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; |
| 2292 | 2313 | ||
| 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; |
| 2304 | 2325 | ||
| 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 | } |
| 2319 | 2340 | ||
| 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; |
| 2322 | 2344 | ||
| 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 | } |
| 2368 | 2390 | ||
| 2369 | fn getDebugInfoOff(self: Dwarf) ?u32 { | 2391 | fn 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 | } |
| 2373 | 2396 | ||
| 2374 | fn getDebugInfoEnd(self: Dwarf) ?u32 { | 2397 | fn 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 | } |
| 2378 | 2402 | ||
| 2379 | fn getDebugLineProgramOff(self: Dwarf) ?u32 { | 2403 | fn 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 | } |
| 2383 | 2408 | ||
| 2384 | fn getDebugLineProgramEnd(self: Dwarf) ?u32 { | 2409 | fn 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 | } |
| 2388 | 2414 | ||
| ... | @@ -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; |
| 2459 | 2485 | ||
| 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); |
| 2471 | 2488 | ||
| 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); |
| 2477 | 2494 | ||
| 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 | }; |
| 2495 | 2512 | ||
| 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()); |
| 2498 | 2515 | ||
| 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 | } |
| 2629 | 2647 | ||
| 2630 | fn getDbgInfoAtom(tag: File.Tag, mod: *Module, decl_index: Module.Decl.Index) *Atom { | 2648 | const Kind = enum { src_fn, di_atom }; |
| 2631 | const decl = mod.declPtr(decl_index); | 2649 | |
| 2632 | return switch (tag) { | 2650 | fn 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 | |||
| 2675 | fn 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 | |||
| 2694 | fn 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 | |||
| 2701 | fn 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 | } |
| 346 | 346 | ||
| 347 | // if (self.dwarf) |*dw| { | 347 | if (self.dwarf) |*dw| { |
| 348 | // dw.deinit(); | 348 | dw.deinit(); |
| 349 | // } | 349 | } |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | pub fn getDeclVAddr(self: *Elf, decl_index: Module.Decl.Index, reloc_info: File.RelocInfo) !u64 { | 352 | pub 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 | } |
| 687 | 687 | ||
| 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 | } |
| 711 | 711 | ||
| 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); |
| 714 | 714 | ||
| 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 | } |
| 740 | 740 | ||
| 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); |
| 743 | 743 | ||
| 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 | } |
| 769 | 769 | ||
| 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); |
| 772 | 772 | ||
| 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 | } |
| 798 | 798 | ||
| 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); |
| 801 | 801 | ||
| 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 | } |
| 828 | 828 | ||
| 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 | } |
| 957 | 957 | ||
| 958 | pub fn markDirty(self: *Elf, shdr_index: u16, phdr_index: ?u16) void { | 958 | pub 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 section | 959 | self.shdr_table_dirty = true; // TODO look into only writing one section |
| 961 | 960 | ||
| 962 | if (phdr_index) |_| { | 961 | if (phdr_index) |_| { |
| 963 | self.phdr_table_dirty = true; // TODO look into making only the one program header dirty | 962 | self.phdr_table_dirty = true; // TODO look into making only the one program header dirty |
| 964 | } | 963 | } |
| 965 | 964 | ||
| 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 | } |
| 980 | 979 | ||
| 981 | pub fn flush(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { | 980 | pub 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 it | 1014 | // 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; | ||
| 1019 | 1017 | ||
| 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(); |
| 1022 | 1020 | ||
| 1023 | // if (self.dwarf) |*dw| { | 1021 | if (self.dwarf) |*dw| { |
| 1024 | // try dw.flushModule(module); | 1022 | try dw.flushModule(module); |
| 1025 | // } | 1023 | } |
| 1026 | 1024 | ||
| 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 | } |
| 1070 | 1068 | ||
| 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 | } |
| 1080 | 1078 | ||
| 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 simply | 1080 | // 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 | } |
| 1090 | 1088 | ||
| 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 simply | 1090 | // 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 | } |
| 1102 | 1100 | ||
| 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 | } |
| 1108 | 1106 | ||
| 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 | } |
| 1164 | 1162 | ||
| 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 | } |
| 1174 | 1172 | ||
| 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; |
| 2101 | 2099 | ||
| 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 | } |
| 2108 | 2102 | ||
| 2109 | fn shrinkAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64) void { | 2103 | fn 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; |
| 2221 | 2214 | ||
| 2222 | // if (self.dwarf) |_| { | 2215 | if (self.dwarf) |_| { |
| 2223 | // // The .debug_info section has `low_pc` and `high_pc` values which is the virtual address | 2216 | // 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 more | 2220 | // 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 to | 2221 | // 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); |
| 2234 | 2227 | ||
| ... | @@ -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 | } |
| 2335 | 2328 | ||
| 2336 | // if (self.dwarf) |*dw| { | 2329 | if (self.dwarf) |*dw| { |
| 2337 | // dw.freeDecl(decl); | 2330 | dw.freeDecl(decl_index); |
| 2338 | // } | 2331 | } |
| 2339 | } | 2332 | } |
| 2340 | 2333 | ||
| 2341 | pub fn getOrCreateAtomForDecl(self: *Elf, decl_index: Module.Decl.Index) !Atom.Index { | 2334 | pub 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(); |
| 2473 | 2466 | ||
| 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(); |
| 2476 | 2469 | ||
| 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 | // else | 2474 | 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); |
| 2483 | 2476 | ||
| 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 | // } | ||
| 2503 | 2495 | ||
| 2504 | // Since we updated the vaddr and the size, each corresponding export | 2496 | // 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(); |
| 2538 | 2530 | ||
| 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(); |
| 2541 | 2533 | ||
| 2542 | // TODO implement .debug_info for global variables | 2534 | // 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 | // else | 2545 | 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 | }); |
| 2560 | 2552 | ||
| 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 | }; |
| 2569 | 2561 | ||
| 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 | // } | ||
| 2581 | 2572 | ||
| 2582 | // Since we updated the vaddr and the size, each corresponding export | 2573 | // 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 | } |
| 2738 | 2729 | ||
| 2739 | /// Must be called only after a successful call to `updateDecl`. | 2730 | /// Must be called only after a successful call to `updateDecl`. |
| 2740 | pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl: *const Module.Decl) !void { | 2731 | pub 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(); |
| 2743 | 2734 | ||
| 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); |
| 2746 | 2738 | ||
| 2747 | log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl }); | 2739 | log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl }); |
| 2748 | 2740 | ||
| 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 | } |
| 2754 | 2746 | ||
| 2755 | pub fn deleteDeclExport(self: *Elf, decl_index: Module.Decl.Index, name: []const u8) void { | 2747 | pub 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"); |
| 4 | const assert = std.debug.assert; | 4 | const assert = std.debug.assert; |
| 5 | const elf = std.elf; | 5 | const elf = std.elf; |
| 6 | 6 | ||
| 7 | const Dwarf = @import("../Dwarf.zig"); | ||
| 8 | const Elf = @import("../Elf.zig"); | 7 | const Elf = @import("../Elf.zig"); |
| 9 | 8 | ||
| 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, |
| 23 | prev_index: ?Index, | 22 | prev_index: ?Index, |
| 24 | next_index: ?Index, | 23 | next_index: ?Index, |
| 25 | 24 | ||
| 26 | dbg_info_atom: Dwarf.Atom, | ||
| 27 | |||
| 28 | pub const Index = u32; | 25 | pub const Index = u32; |
| 29 | 26 | ||
| 30 | pub const Reloc = struct { | 27 | pub 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 |
| 472 | 472 | ||
| 473 | const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented; | 473 | const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented; |
| 474 | 474 | ||
| 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 | } |
| 478 | 478 | ||
| 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 last | 664 | try self.writeCodeSignature(comp, csig); // code signing always comes last |
| 665 | } | 665 | } |
| 666 | 666 | ||
| 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 | } |
| 671 | 671 | ||
| 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 | } |
| 1726 | 1725 | ||
| 1727 | // if (self.d_sym) |*d_sym| { | 1726 | if (self.d_sym) |*d_sym| { |
| 1728 | // d_sym.deinit(); | 1727 | d_sym.deinit(); |
| 1729 | // } | 1728 | } |
| 1730 | 1729 | ||
| 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 | } |
| 1805 | 1804 | ||
| 1806 | fn freeAtom(self: *MachO, atom_index: Atom.Index) void { | 1805 | fn 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}); | ||
| 1810 | 1808 | ||
| 1811 | // Remove any relocs and base relocs associated with this Atom | 1809 | // 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); |
| 1878 | 1876 | ||
| 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 | } |
| 1882 | 1880 | ||
| 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 | } |
| 1895 | 1889 | ||
| 1896 | fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void { | 1890 | fn 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); |
| 2021 | 2015 | ||
| 2022 | const atom = self.getAtom(atom_index); | 2016 | const atom = self.getAtom(atom_index); |
| 2023 | _ = atom; | ||
| 2024 | 2017 | ||
| 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(); |
| 2027 | 2020 | ||
| 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 | // else | 2023 | else |
| 2031 | // null; | 2024 | null; |
| 2032 | // defer if (decl_state) |*ds| ds.deinit(); | 2025 | defer if (decl_state) |*ds| ds.deinit(); |
| 2033 | 2026 | ||
| 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 | // else | 2031 | 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); |
| 2040 | 2033 | ||
| 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 | }; |
| 2049 | 2042 | ||
| 2050 | const addr = try self.updateDeclCode(decl_index, code); | 2043 | const addr = try self.updateDeclCode(decl_index, code); |
| 2051 | _ = addr; | ||
| 2052 | 2044 | ||
| 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 | } |
| 2056 | 2048 | ||
| 2057 | // Since we updated the vaddr and the size, each corresponding export symbol also | 2049 | // 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(); |
| 2156 | 2148 | ||
| 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 | // else | 2151 | else |
| 2160 | // null; | 2152 | null; |
| 2161 | // defer if (decl_state) |*ds| ds.deinit(); | 2153 | defer if (decl_state) |*ds| ds.deinit(); |
| 2162 | 2154 | ||
| 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 | // else | 2165 | 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 | }); |
| 2180 | 2172 | ||
| 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; | ||
| 2191 | 2182 | ||
| 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 | } |
| 2195 | 2186 | ||
| 2196 | // Since we updated the vaddr and the size, each corresponding export symbol also | 2187 | // 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 | } |
| 2434 | 2425 | ||
| 2435 | pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl: *const Module.Decl) !void { | 2426 | pub 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 | } |
| 2443 | 2431 | ||
| 2444 | pub fn updateDeclExports( | 2432 | pub 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 | } |
| 2613 | 2601 | ||
| 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 | } |
| 2618 | 2606 | ||
| 2619 | pub fn getDeclVAddr(self: *MachO, decl_index: Module.Decl.Index, reloc_info: File.RelocInfo) !u64 { | 2607 | pub 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; |
| 13 | 13 | ||
| 14 | const Allocator = mem.Allocator; | 14 | const Allocator = mem.Allocator; |
| 15 | const Arch = std.Target.Cpu.Arch; | 15 | const Arch = std.Target.Cpu.Arch; |
| 16 | const Dwarf = @import("../Dwarf.zig"); | ||
| 17 | const MachO = @import("../MachO.zig"); | 16 | const MachO = @import("../MachO.zig"); |
| 18 | const Relocation = @import("Relocation.zig"); | 17 | const Relocation = @import("Relocation.zig"); |
| 19 | const SymbolWithLoc = MachO.SymbolWithLoc; | 18 | const SymbolWithLoc = MachO.SymbolWithLoc; |
| ... | @@ -43,8 +42,6 @@ alignment: u32, | ... | @@ -43,8 +42,6 @@ alignment: u32, |
| 43 | next_index: ?Index, | 42 | next_index: ?Index, |
| 44 | prev_index: ?Index, | 43 | prev_index: ?Index, |
| 45 | 44 | ||
| 46 | dbg_info_atom: Dwarf.Atom, | ||
| 47 | |||
| 48 | pub const Index = u32; | 45 | pub const Index = u32; |
| 49 | 46 | ||
| 50 | pub const Binding = struct { | 47 | pub 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 | } |
| 1019 | 1019 | ||
| 1020 | /// Must be called only after a successful call to `updateDecl`. | 1020 | /// Must be called only after a successful call to `updateDecl`. |
| 1021 | pub fn updateDeclLineNumber(self: *Plan9, mod: *Module, decl: *const Module.Decl) !void { | 1021 | pub 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 | } |
| 1026 | 1026 | ||
| 1027 | pub fn getDeclVAddr( | 1027 | pub fn getDeclVAddr( |
src/link/Wasm.zig+6-11| ... | @@ -183,13 +183,9 @@ pub const Segment = struct { | ... | @@ -183,13 +183,9 @@ pub const Segment = struct { |
| 183 | pub const FnData = struct { | 183 | pub 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, | ||
| 189 | 186 | ||
| 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 | }; |
| 195 | 191 | ||
| ... | @@ -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 | } |
| 1124 | 1120 | ||
| 1125 | pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Module, decl: *const Module.Decl) !void { | 1121 | pub 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(); |
| 1130 | 1126 | ||
| 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); |
| 1133 | 1130 | ||
| 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 | } |
| 1138 | 1135 | ||
| ... | @@ -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()); |
| 1462 | 1459 | ||
| 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 | } | ||
| 1467 | 1463 | ||
| 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"); |
| 4 | const types = @import("types.zig"); | 4 | const types = @import("types.zig"); |
| 5 | const Wasm = @import("../Wasm.zig"); | 5 | const Wasm = @import("../Wasm.zig"); |
| 6 | const Symbol = @import("Symbol.zig"); | 6 | const Symbol = @import("Symbol.zig"); |
| 7 | const Dwarf = @import("../Dwarf.zig"); | ||
| 8 | 7 | ||
| 9 | const leb = std.leb; | 8 | const leb = std.leb; |
| 10 | const log = std.log.scoped(.link); | 9 | const 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. |
| 40 | locals: std.ArrayListUnmanaged(Atom) = .{}, | 39 | locals: std.ArrayListUnmanaged(Atom) = .{}, |
| 41 | 40 | ||
| 42 | /// Represents the debug Atom that holds all debug information of this Atom. | ||
| 43 | dbg_info_atom: Dwarf.Atom, | ||
| 44 | |||
| 45 | /// Represents a default empty wasm `Atom` | 41 | /// Represents a default empty wasm `Atom` |
| 46 | pub const empty: Atom = .{ | 42 | pub 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 | }; |
| 56 | 51 | ||
| 57 | /// Frees all resources owned by this `Atom`. | 52 | /// Frees all resources owned by this `Atom`. |