From e22b3595c1af232372ebf3c70922e86e6f9e9076 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Tue, 7 Nov 2023 14:29:44 +0100 Subject: [PATCH] elf: update .rela section sizes --- src/link/Elf/Object.zig | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index 73bd3a7fb3..a2a551ed6a 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -664,13 +664,24 @@ pub fn initRelaSections(self: Object, elf_file: *Elf) !void { if (!atom.flags.alive) continue; const shndx = atom.relocsShndx() orelse continue; const shdr = self.shdrs.items[shndx]; - _ = try self.initOutputSection(elf_file, shdr); + const out_shndx = try self.initOutputSection(elf_file, shdr); + const out_shdr = &elf_file.shdrs.items[out_shndx]; + out_shdr.sh_addralign = @alignOf(elf.Elf64_Rela); + out_shdr.sh_entsize = @sizeOf(elf.Elf64_Rela); } } pub fn updateRelaSectionsSizes(self: Object, elf_file: *Elf) void { - _ = self; - _ = elf_file; + for (self.atoms.items) |atom_index| { + const atom = elf_file.atom(atom_index) orelse continue; + if (!atom.flags.alive) continue; + const shndx = atom.relocsShndx() orelse continue; + const shdr = self.shdrs.items[shndx]; + const out_shndx = self.initOutputSection(elf_file, shdr) catch unreachable; + const out_shdr = &elf_file.shdrs.items[out_shndx]; + const relocs = atom.relocs(elf_file); + out_shdr.sh_size += out_shdr.sh_entsize * relocs.len; + } } pub fn writeRelaSections(self: Object, elf_file: *Elf) !void {