authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-04 08:10:19+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-04 13:34:26+02:00
log64ad6eff16aac1f6154efa12406818efed57bf73
tree06bfaab8684ea4e9729a4e06748a319c15b754dc
parent6ec8b15918dcd692f88875843a51a0514e315d9d

elf: create back/forward links for atoms within section chunks


1 files changed, 19 insertions(+), 1 deletions(-)

src/link/Elf/Object.zig+19-1
......@@ -988,7 +988,25 @@ pub fn allocateAtoms(self: *Object, elf_file: *Elf) !void {
988988 if (expand_section) last_atom_ref.* = chunk.lastAtom(self).ref();
989989 shdr.sh_addralign = @max(shdr.sh_addralign, chunk.alignment.toByteUnits().?);
990990
991 // TODO create back and forward links
991 {
992 var idx: usize = 0;
993 while (idx < chunk.atoms.items.len) : (idx += 1) {
994 const curr_atom_ptr = self.atom(chunk.atoms.items[idx]).?;
995 if (idx > 0) {
996 curr_atom_ptr.prev_atom_ref = .{ .index = chunk.atoms.items[idx - 1], .file = self.index };
997 }
998 if (idx + 1 < chunk.atoms.items.len) {
999 curr_atom_ptr.next_atom_ref = .{ .index = chunk.atoms.items[idx + 1], .file = self.index };
1000 }
1001 }
1002 }
1003
1004 if (elf_file.atom(alloc_res.placement)) |placement_atom| {
1005 chunk.firstAtom(self).prev_atom_ref = placement_atom.ref();
1006 chunk.lastAtom(self).next_atom_ref = placement_atom.next_atom_ref;
1007 placement_atom.next_atom_ref = chunk.firstAtom(self).ref();
1008 }
1009
9921010 // TODO if we had a link from Atom to parent Chunk we would not need to update Atom's value or osec index
9931011 for (chunk.atoms.items) |atom_index| {
9941012 const atom_ptr = self.atom(atom_index).?;