commit 0524a3c83dcd5d630e762b0769de8057f75c68e5 (tree)
parent 04a7051c4bf26ea9a5ffd2e5b618726e8ec06837
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Fri, 29 Sep 2023 19:06:02 +0200
elf: fix calculating current allocated section size when growing alloc sections
Diffstat:
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
@@ -909,10 +909,7 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {
if (needed_size > self.allocatedSize(shdr.sh_offset) and !is_zerofill) {
// Must move the entire section.
const new_offset = self.findFreeSpace(needed_size, self.page_size);
- const existing_size = if (self.last_atom_and_free_list_table.get(shdr_index)) |meta| blk: {
- const last = self.atom(meta.last_atom_index) orelse break :blk 0;
- break :blk (last.value + last.size) - phdr.p_vaddr;
- } else shdr.sh_size;
+ const existing_size = shdr.sh_size;
shdr.sh_size = 0;
log.debug("new '{s}' file offset 0x{x} to 0x{x}", .{
@@ -922,6 +919,7 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {
});
const amt = try self.base.file.?.copyRangeAll(shdr.sh_offset, self.base.file.?, new_offset, existing_size);
+ // TODO figure out what to about this error condition - how to communicate it up.
if (amt != existing_size) return error.InputOutput;
shdr.sh_offset = new_offset;