diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-09-04 08:10:19 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-09-04 13:34:26 +0200 |
| commit | 64ad6eff16aac1f6154efa12406818efed57bf73 (patch) | |
| tree | 06bfaab8684ea4e9729a4e06748a319c15b754dc /src | |
| parent | 6ec8b15918dcd692f88875843a51a0514e315d9d (diff) | |
| download | zig-64ad6eff16aac1f6154efa12406818efed57bf73.tar.gz zig-64ad6eff16aac1f6154efa12406818efed57bf73.zip | |
elf: create back/forward links for atoms within section chunks
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Elf/Object.zig | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index 4a1ca685c5..0d063927ce 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -988,7 +988,25 @@ pub fn allocateAtoms(self: *Object, elf_file: *Elf) !void { if (expand_section) last_atom_ref.* = chunk.lastAtom(self).ref(); shdr.sh_addralign = @max(shdr.sh_addralign, chunk.alignment.toByteUnits().?); - // TODO create back and forward links + { + var idx: usize = 0; + while (idx < chunk.atoms.items.len) : (idx += 1) { + const curr_atom_ptr = self.atom(chunk.atoms.items[idx]).?; + if (idx > 0) { + curr_atom_ptr.prev_atom_ref = .{ .index = chunk.atoms.items[idx - 1], .file = self.index }; + } + if (idx + 1 < chunk.atoms.items.len) { + curr_atom_ptr.next_atom_ref = .{ .index = chunk.atoms.items[idx + 1], .file = self.index }; + } + } + } + + if (elf_file.atom(alloc_res.placement)) |placement_atom| { + chunk.firstAtom(self).prev_atom_ref = placement_atom.ref(); + chunk.lastAtom(self).next_atom_ref = placement_atom.next_atom_ref; + placement_atom.next_atom_ref = chunk.firstAtom(self).ref(); + } + // TODO if we had a link from Atom to parent Chunk we would not need to update Atom's value or osec index for (chunk.atoms.items) |atom_index| { const atom_ptr = self.atom(atom_index).?; |
