From 56e1ae21e42b63ea4409b68950691fb89bfd1d21 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 18 Aug 2024 14:54:12 +0200 Subject: [PATCH] elf: populate debug atoms on the linker side after Dwarf.flushModule --- src/link/Dwarf.zig | 2 +- src/link/Elf/ZigObject.zig | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 60c0bac4a8..f74d8e82a4 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -201,7 +201,7 @@ const StringSection = struct { }; /// A linker section containing a sequence of `Unit`s. -const Section = struct { +pub const Section = struct { dirty: bool, pad_to_ideal: bool, alignment: InternPool.Alignment, diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index f951e7ea71..a82d1f8809 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -181,6 +181,43 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid }; try dwarf.flushModule(pt); + // TODO invert this logic so that we manage the output section with the atom, not the + // other way around + for ([_]u32{ + self.debug_info_index.?, + self.debug_abbrev_index.?, + self.debug_str_index.?, + self.debug_aranges_index.?, + self.debug_line_index.?, + self.debug_line_str_index.?, + self.debug_loclists_index.?, + self.debug_rnglists_index.?, + }, [_]Dwarf.Section{ + dwarf.debug_info.section, + dwarf.debug_abbrev.section, + dwarf.debug_str.section, + dwarf.debug_aranges.section, + dwarf.debug_line.section, + dwarf.debug_line_str.section, + dwarf.debug_loclists.section, + dwarf.debug_rnglists.section, + }) |sym_index, sect| { + const sym = self.symbol(sym_index); + const atom_ptr = self.atom(sym.ref.index).?; + if (!atom_ptr.alive) continue; + const shdr = elf_file.shdrs.items[sym.outputShndx(elf_file).?]; + const esym = &self.symtab.items(.elf_sym)[sym.esym_index]; + esym.st_size = shdr.sh_size; + atom_ptr.size = shdr.sh_size; + atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(shdr.sh_addralign); + + const relocs = &self.relocs.items[atom_ptr.relocsShndx().?]; + _ = relocs; + for (sect.units.items) |unit| { + _ = unit; + } + } + self.debug_abbrev_section_dirty = false; self.debug_aranges_section_dirty = false; self.debug_rnglists_section_dirty = false;