aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf/Object.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-09-01 15:13:09 +0200
committerJakub Konka <kubkon@jakubkonka.com>2024-09-04 13:34:25 +0200
commit45e46f0fb9f9f8a314802c544e92d1ee865119ef (patch)
tree6a39cf64542c3e8e9a4f4160ffb61736bf3da8b6 /src/link/Elf/Object.zig
parent1ef96f05eb7806d7123919d30f4b672e82a64d75 (diff)
downloadzig-45e46f0fb9f9f8a314802c544e92d1ee865119ef.tar.gz
zig-45e46f0fb9f9f8a314802c544e92d1ee865119ef.zip
elf: allocate atom chunks using allocateChunk mechanics in objects
Diffstat (limited to 'src/link/Elf/Object.zig')
-rw-r--r--src/link/Elf/Object.zig41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig
index 3337bfb1a2..26c2f2585b 100644
--- a/src/link/Elf/Object.zig
+++ b/src/link/Elf/Object.zig
@@ -955,27 +955,26 @@ pub fn initOutputSections(self: *Object, elf_file: *Elf) !void {
}
pub fn allocateAtoms(self: *Object, elf_file: *Elf) !void {
- _ = elf_file;
for (self.section_chunks.items) |*chunk| {
chunk.updateSize(self);
}
-}
-pub fn addAtomsToOutputSections(self: *Object, elf_file: *Elf) !void {
- for (self.atoms_indexes.items) |atom_index| {
- const atom_ptr = self.atom(atom_index) orelse continue;
- if (!atom_ptr.alive) continue;
- const shdr = atom_ptr.inputShdr(elf_file);
- atom_ptr.output_section_index = elf_file.initOutputSection(.{
- .name = self.getString(shdr.sh_name),
- .flags = shdr.sh_flags,
- .type = shdr.sh_type,
- }) catch unreachable;
+ for (self.section_chunks.items) |*chunk| {
+ const alloc_res = try elf_file.allocateChunk(chunk.output_section_index, chunk.size, chunk.alignment);
+ chunk.value = @intCast(alloc_res.value);
- const comp = elf_file.base.comp;
- const gpa = comp.gpa;
- const atom_list = &elf_file.sections.items(.atom_list)[atom_ptr.output_section_index];
- try atom_list.append(gpa, .{ .index = atom_index, .file = self.index });
+ const slice = elf_file.sections.slice();
+ const shdr = &slice.items(.shdr)[chunk.output_section_index];
+ const last_atom_ref = &slice.items(.last_atom)[chunk.output_section_index];
+
+ const expand_section = if (elf_file.atom(alloc_res.placement)) |placement_atom|
+ placement_atom.nextAtom(elf_file) == null
+ else
+ true;
+ 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
}
}
@@ -1599,6 +1598,16 @@ const SectionChunk = struct {
}
}
+ fn firstAtom(chunk: SectionChunk, object: *Object) *Atom {
+ assert(chunk.atoms.items.len > 0);
+ return object.atom(chunk.atoms.items[0]).?;
+ }
+
+ fn lastAtom(chunk: SectionChunk, object: *Object) *Atom {
+ assert(chunk.atoms.items.len > 0);
+ return object.atom(chunk.atoms.items[chunk.atoms.items.len - 1]).?;
+ }
+
pub fn format(
chunk: SectionChunk,
comptime unused_fmt_string: []const u8,