authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-29 20:35:28+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-29 20:35:28+02:00
log304d38e844f5c2aeb42e3879a230f5916e704c0d
treefad54ab79f91eee15ffca149d246eed4a6fcdf50
parent0524a3c83dcd5d630e762b0769de8057f75c68e5

elf: simplify logic for growing non-alloc sections


1 files changed, 5 insertions(+), 10 deletions(-)

src/link/Elf.zig+5-10
......@@ -1028,21 +1028,15 @@ pub fn growNonAllocSection(
10281028 const shdr = &self.shdrs.items[shdr_index];
10291029
10301030 if (needed_size > self.allocatedSize(shdr.sh_offset)) {
1031 const existing_size = if (self.symtab_section_index.? == shdr_index) blk: {
1032 const sym_size: u64 = switch (self.ptr_width) {
1033 .p32 => @sizeOf(elf.Elf32_Sym),
1034 .p64 => @sizeOf(elf.Elf64_Sym),
1035 };
1036 break :blk @as(u64, shdr.sh_info) * sym_size;
1037 } else shdr.sh_size;
1031 const existing_size = shdr.sh_size;
10381032 shdr.sh_size = 0;
10391033 // Move all the symbols to a new file location.
10401034 const new_offset = self.findFreeSpace(needed_size, min_alignment);
10411035
1042 log.debug("moving '{?s}' from 0x{x} to 0x{x}", .{
1043 self.shstrtab.get(shdr.sh_name),
1044 shdr.sh_offset,
1036 log.debug("new '{s}' file offset 0x{x} to 0x{x}", .{
1037 self.shstrtab.getAssumeExists(shdr.sh_name),
10451038 new_offset,
1039 new_offset + existing_size,
10461040 });
10471041
10481042 if (requires_file_copy) {
......@@ -3505,6 +3499,7 @@ fn updateSymtabSize(self: *Elf) !void {
35053499 .p64 => @alignOf(elf.Elf64_Sym),
35063500 };
35073501 const needed_size = (sizes.nlocals + sizes.nglobals + 1) * sym_size;
3502 shdr.sh_size = needed_size;
35083503 try self.growNonAllocSection(self.symtab_section_index.?, needed_size, sym_align, true);
35093504}
35103505