authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-02 09:08:37+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-04 13:34:26+02:00
log6b53dc946117110907867ee67425585ae3729750
tree56bacc1260f97c91827f2e2c357be1182d18b4fb
parent6a50a0f0ed3902b46afeda9c4a5b7f10cec60dba

elf: actually allocate atoms within each section chunk


2 files changed, 12 insertions(+), 2 deletions(-)

src/link/Elf.zig+5-1
......@@ -3505,8 +3505,12 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void {
35053505 }
35063506
35073507 for (self.objects.items) |index| {
3508 for (self.file(index).?.object.section_chunks.items) |*chunk| {
3508 const object = self.file(index).?.object;
3509 for (object.section_chunks.items) |*chunk| {
35093510 chunk.output_section_index = backlinks[chunk.output_section_index];
3511 for (chunk.atoms.items) |atom_index| {
3512 object.atom(atom_index).?.output_section_index = chunk.output_section_index;
3513 }
35103514 }
35113515 }
35123516
src/link/Elf/Object.zig+7-1
......@@ -975,6 +975,12 @@ pub fn allocateAtoms(self: *Object, elf_file: *Elf) !void {
975975 shdr.sh_addralign = @max(shdr.sh_addralign, chunk.alignment.toByteUnits().?);
976976
977977 // TODO create back and forward links
978 // TODO if we had a link from Atom to parent Chunk we would not need to update Atom's value or osec index
979 for (chunk.atoms.items) |atom_index| {
980 const atom_ptr = self.atom(atom_index).?;
981 atom_ptr.output_section_index = chunk.output_section_index;
982 atom_ptr.value += chunk.value;
983 }
978984 }
979985}
980986
......@@ -1008,7 +1014,7 @@ pub fn writeAtoms(self: *Object, elf_file: *Elf) !void {
10081014 const atom_ptr = self.atom(atom_index).?;
10091015 assert(atom_ptr.alive);
10101016
1011 const offset = math.cast(usize, atom_ptr.value) orelse return error.Overflow;
1017 const offset = math.cast(usize, atom_ptr.value - chunk.value) orelse return error.Overflow;
10121018 const size = math.cast(usize, atom_ptr.size) orelse return error.Overflow;
10131019
10141020 log.debug(" * atom({d}) at 0x{x}", .{ atom_index, chunk.offset(elf_file) + offset });