authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-18 14:54:12+02:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-08-21 01:43:21-04:00
log56e1ae21e42b63ea4409b68950691fb89bfd1d21
tree1ce47fe18c6dc4297f94e7a6fefa9464c24ee15d
parent41f2302865b92db81d839788393b126a34a56e62

elf: populate debug atoms on the linker side after Dwarf.flushModule


2 files changed, 38 insertions(+), 1 deletions(-)

src/link/Dwarf.zig+1-1
......@@ -201,7 +201,7 @@ const StringSection = struct {
201201};
202202
203203/// A linker section containing a sequence of `Unit`s.
204const Section = struct {
204pub const Section = struct {
205205 dirty: bool,
206206 pad_to_ideal: bool,
207207 alignment: InternPool.Alignment,
src/link/Elf/ZigObject.zig+37
......@@ -181,6 +181,43 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
181181 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };
182182 try dwarf.flushModule(pt);
183183
184 // TODO invert this logic so that we manage the output section with the atom, not the
185 // other way around
186 for ([_]u32{
187 self.debug_info_index.?,
188 self.debug_abbrev_index.?,
189 self.debug_str_index.?,
190 self.debug_aranges_index.?,
191 self.debug_line_index.?,
192 self.debug_line_str_index.?,
193 self.debug_loclists_index.?,
194 self.debug_rnglists_index.?,
195 }, [_]Dwarf.Section{
196 dwarf.debug_info.section,
197 dwarf.debug_abbrev.section,
198 dwarf.debug_str.section,
199 dwarf.debug_aranges.section,
200 dwarf.debug_line.section,
201 dwarf.debug_line_str.section,
202 dwarf.debug_loclists.section,
203 dwarf.debug_rnglists.section,
204 }) |sym_index, sect| {
205 const sym = self.symbol(sym_index);
206 const atom_ptr = self.atom(sym.ref.index).?;
207 if (!atom_ptr.alive) continue;
208 const shdr = elf_file.shdrs.items[sym.outputShndx(elf_file).?];
209 const esym = &self.symtab.items(.elf_sym)[sym.esym_index];
210 esym.st_size = shdr.sh_size;
211 atom_ptr.size = shdr.sh_size;
212 atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(shdr.sh_addralign);
213
214 const relocs = &self.relocs.items[atom_ptr.relocsShndx().?];
215 _ = relocs;
216 for (sect.units.items) |unit| {
217 _ = unit;
218 }
219 }
220
184221 self.debug_abbrev_section_dirty = false;
185222 self.debug_aranges_section_dirty = false;
186223 self.debug_rnglists_section_dirty = false;