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(...@@ -1028,21 +1028,15 @@ pub fn growNonAllocSection(
1028 const shdr = &self.shdrs.items[shdr_index];1028 const shdr = &self.shdrs.items[shdr_index];
10291029
1030 if (needed_size > self.allocatedSize(shdr.sh_offset)) {1030 if (needed_size > self.allocatedSize(shdr.sh_offset)) {
1031 const existing_size = if (self.symtab_section_index.? == shdr_index) blk: {1031 const existing_size = shdr.sh_size;
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;
1038 shdr.sh_size = 0;1032 shdr.sh_size = 0;
1039 // Move all the symbols to a new file location.1033 // Move all the symbols to a new file location.
1040 const new_offset = self.findFreeSpace(needed_size, min_alignment);1034 const new_offset = self.findFreeSpace(needed_size, min_alignment);
10411035
1042 log.debug("moving '{?s}' from 0x{x} to 0x{x}", .{1036 log.debug("new '{s}' file offset 0x{x} to 0x{x}", .{
1043 self.shstrtab.get(shdr.sh_name),1037 self.shstrtab.getAssumeExists(shdr.sh_name),
1044 shdr.sh_offset,
1045 new_offset,1038 new_offset,
1039 new_offset + existing_size,
1046 });1040 });
10471041
1048 if (requires_file_copy) {1042 if (requires_file_copy) {
...@@ -3505,6 +3499,7 @@ fn updateSymtabSize(self: *Elf) !void {...@@ -3505,6 +3499,7 @@ fn updateSymtabSize(self: *Elf) !void {
3505 .p64 => @alignOf(elf.Elf64_Sym),3499 .p64 => @alignOf(elf.Elf64_Sym),
3506 };3500 };
3507 const needed_size = (sizes.nlocals + sizes.nglobals + 1) * sym_size;3501 const needed_size = (sizes.nlocals + sizes.nglobals + 1) * sym_size;
3502 shdr.sh_size = needed_size;
3508 try self.growNonAllocSection(self.symtab_section_index.?, needed_size, sym_align, true);3503 try self.growNonAllocSection(self.symtab_section_index.?, needed_size, sym_align, true);
3509}3504}
35103505