From bfd36cbf97bfa012e5c399c16578b8756782e1d8 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 2 Dec 2022 13:17:52 +0100 Subject: [PATCH] dwarf: pass linker Tag and owner Decl.Index instead of *Atom --- src/arch/aarch64/CodeGen.zig | 31 +++++++++++++++---------------- src/arch/arm/CodeGen.zig | 14 +------------- src/arch/riscv64/CodeGen.zig | 22 +++++++--------------- src/arch/sparc64/CodeGen.zig | 21 +++++++-------------- src/arch/wasm/CodeGen.zig | 12 ++---------- src/arch/x86_64/CodeGen.zig | 18 ++---------------- src/link/Dwarf.zig | 18 ++++++++++++++++-- 7 files changed, 50 insertions(+), 86 deletions(-) diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 7bf0f99a84..9975e08ea9 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -182,8 +182,6 @@ const DbgInfoReloc = struct { } } fn genArgDbgInfo(reloc: DbgInfoReloc, function: Self) error{OutOfMemory}!void { - const atom = function.getDbgInfoAtomPtr(); - switch (function.debug_output) { .dwarf => |dw| { const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (reloc.mcv) { @@ -204,7 +202,13 @@ const DbgInfoReloc = struct { else => unreachable, // not a possible argument }; - try dw.genArgDbgInfo(reloc.name, reloc.ty, atom, loc); + try dw.genArgDbgInfo( + reloc.name, + reloc.ty, + function.bin_file.tag, + function.mod_fn.owner_decl, + loc, + ); }, .plan9 => {}, .none => {}, @@ -217,7 +221,6 @@ const DbgInfoReloc = struct { .dbg_var_val => false, else => unreachable, }; - const atom = function.getDbgInfoAtomPtr(); switch (function.debug_output) { .dwarf => |dw| { @@ -251,7 +254,14 @@ const DbgInfoReloc = struct { break :blk .nop; }, }; - try dw.genVarDbgInfo(reloc.name, reloc.ty, atom, is_ptr, loc); + try dw.genVarDbgInfo( + reloc.name, + reloc.ty, + function.bin_file.tag, + function.mod_fn.owner_decl, + is_ptr, + loc, + ); }, .plan9 => {}, .none => {}, @@ -259,17 +269,6 @@ const DbgInfoReloc = struct { } }; -fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; - return atom; -} - const Branch = struct { inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 0a19214e48..7a9e00b83f 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -4033,7 +4033,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe const mcv = self.args[arg_index]; const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - const atom = self.getDbgInfoAtom(); switch (self.debug_output) { .dwarf => |dw| { @@ -4055,24 +4054,13 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMe else => unreachable, // not a possible argument }; - try dw.genArgDbgInfo(name, ty, atom, loc); + try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc); }, .plan9 => {}, .none => {}, } } -fn getDbgInfoAtom(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; - return atom; -} - fn airArg(self: *Self, inst: Air.Inst.Index) !void { const arg_index = self.arg_index; self.arg_index += 1; diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index b2c7ac293f..6a54ffeea2 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -1605,13 +1605,16 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void { const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - const atom = self.getDbgIntoAtomPtr(); switch (self.debug_output) { .dwarf => |dw| switch (mcv) { - .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ - .register = reg.dwarfLocOp(), - }), + .register => |reg| try dw.genArgDbgInfo( + name, + ty, + self.bin_file.tag, + self.mod_fn.owner_decl, + .{ .register = reg.dwarfLocOp() }, + ), .stack_offset => {}, else => {}, }, @@ -1620,17 +1623,6 @@ fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) } } -fn getDbgIntoAtomPtr(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; - return atom; -} - fn airArg(self: *Self, inst: Air.Inst.Index) !void { const arg_index = self.arg_index; self.arg_index += 1; diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 66d14f755b..9f345767de 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -3255,29 +3255,22 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void { const ty = self.air.instructions.items(.data)[inst].ty; const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); - const atom = self.getDbgInfoAtomPtr(); switch (self.debug_output) { .dwarf => |dw| switch (mcv) { - .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{ - .register = reg.dwarfLocOp(), - }), + .register => |reg| try dw.genArgDbgInfo( + name, + ty, + self.bin_file.tag, + self.mod_fn.owner_decl, + .{ .register = reg.dwarfLocOp() }, + ), else => {}, }, else => {}, } } -fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - else => unreachable, - }; - return atom; -} - // TODO replace this to call to extern memcpy fn genInlineMemcpy( self: *Self, diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 6584ad2041..c424c7b59d 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -2341,8 +2341,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { .dwarf => |dwarf| { // TODO: Get the original arg index rather than wasm arg index const name = func.mod_fn.getParamName(func.bin_file.base.options.module.?, arg_index); - const atom = func.getDbgInfoAtom(); - try dwarf.genArgDbgInfo(name, arg_ty, atom, .{ + try dwarf.genArgDbgInfo(name, arg_ty, .wasm, func.mod_fn.owner_decl, .{ .wasm_local = arg.local.value, }); }, @@ -2352,12 +2351,6 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { func.finishAir(inst, arg, &.{}); } -fn getDbgInfoAtom(func: CodeGen) *link.File.Dwarf.Atom { - const mod = func.bin_file.base.options.module.?; - const fn_owner_decl = mod.declPtr(func.mod_fn.owner_decl); - return &fn_owner_decl.link.wasm.dbg_info_atom; -} - fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { const bin_op = func.air.instructions.items(.data)[inst].bin_op; if (func.liveness.isUnused(inst)) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs }); @@ -5326,7 +5319,6 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void { const name = func.air.nullTerminatedString(pl_op.payload); log.debug(" var name = ({s})", .{name}); - const atom = func.getDbgInfoAtom(); const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (operand) { .local => |local| .{ .wasm_local = local.value }, else => blk: { @@ -5334,7 +5326,7 @@ fn airDbgVar(func: *CodeGen, inst: Air.Inst.Index, is_ptr: bool) !void { break :blk .nop; }, }; - try func.debug_output.dwarf.genVarDbgInfo(name, ty, atom, is_ptr, loc); + try func.debug_output.dwarf.genVarDbgInfo(name, ty, .wasm, func.mod_fn.owner_decl, is_ptr, loc); func.finishAir(inst, .none, &.{}); } diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 8769b7ae61..ae7cbc762d 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -3815,8 +3815,6 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void { } fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { - const atom = self.getDbgInfoAtomPtr(); - switch (self.debug_output) { .dwarf => |dw| { const loc: link.File.Dwarf.DeclState.DbgInfoLoc = switch (mcv) { @@ -3830,7 +3828,7 @@ fn genArgDbgInfo(self: Self, ty: Type, name: [:0]const u8, mcv: MCValue) !void { }, else => unreachable, // not a valid function parameter }; - try dw.genArgDbgInfo(name, ty, atom, loc); + try dw.genArgDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, loc); }, .plan9 => {}, .none => {}, @@ -3849,7 +3847,6 @@ fn genVarDbgInfo( .dbg_var_val => false, else => unreachable, }; - const atom = self.getDbgInfoAtomPtr(); switch (self.debug_output) { .dwarf => |dw| { @@ -3871,24 +3868,13 @@ fn genVarDbgInfo( break :blk .nop; }, }; - try dw.genVarDbgInfo(name, ty, atom, is_ptr, loc); + try dw.genVarDbgInfo(name, ty, self.bin_file.tag, self.mod_fn.owner_decl, is_ptr, loc); }, .plan9 => {}, .none => {}, } } -fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom { - const mod = self.bin_file.options.module.?; - const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl); - const atom = switch (self.bin_file.tag) { - .elf => &fn_owner_decl.link.elf.dbg_info_atom, - .macho => &fn_owner_decl.link.macho.dbg_info_atom, - else => unreachable, - }; - return atom; -} - fn airBreakpoint(self: *Self) !void { _ = try self.addInst(.{ .tag = .interrupt, diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 8540b8a542..63ccb57e77 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -581,10 +581,12 @@ pub const DeclState = struct { self: *DeclState, name: [:0]const u8, ty: Type, - atom: *Atom, + tag: File.Tag, + owner_decl: Module.Decl.Index, loc: DbgInfoLoc, ) error{OutOfMemory}!void { const dbg_info = &self.dbg_info; + const atom = self.getDbgInfoAtom(tag, owner_decl); const name_with_null = name.ptr[0 .. name.len + 1]; switch (loc) { @@ -637,11 +639,13 @@ pub const DeclState = struct { self: *DeclState, name: [:0]const u8, ty: Type, - atom: *Atom, + tag: File.Tag, + owner_decl: Module.Decl.Index, is_ptr: bool, loc: DbgInfoLoc, ) error{OutOfMemory}!void { const dbg_info = &self.dbg_info; + const atom = self.getDbgInfoAtom(tag, owner_decl); const name_with_null = name.ptr[0 .. name.len + 1]; try dbg_info.append(@enumToInt(AbbrevKind.variable)); const target = self.mod.getTarget(); @@ -774,6 +778,16 @@ pub const DeclState = struct { try self.addTypeRelocGlobal(atom, child_ty, @intCast(u32, index)); dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string } + + fn getDbgInfoAtom(self: *DeclState, tag: File.Tag, decl_index: Module.Decl.Index) *Atom { + const decl = self.mod.declPtr(decl_index); + return switch (tag) { + .elf => &decl.link.elf.dbg_info_atom, + .macho => &decl.link.macho.dbg_info_atom, + .wasm => &decl.link.wasm.dbg_info_atom, + else => unreachable, + }; + } }; pub const AbbrevEntry = struct {