authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-29 19:06:02+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-29 19:06:02+02:00
log0524a3c83dcd5d630e762b0769de8057f75c68e5
treee4a8cd0f1021eeb1fd709039f7c64006675e2a8c
parent04a7051c4bf26ea9a5ffd2e5b618726e8ec06837

elf: fix calculating current allocated section size when growing alloc sections


1 files changed, 2 insertions(+), 4 deletions(-)

src/link/Elf.zig+2-4
...@@ -909,10 +909,7 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {...@@ -909,10 +909,7 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {
909 if (needed_size > self.allocatedSize(shdr.sh_offset) and !is_zerofill) {909 if (needed_size > self.allocatedSize(shdr.sh_offset) and !is_zerofill) {
910 // Must move the entire section.910 // Must move the entire section.
911 const new_offset = self.findFreeSpace(needed_size, self.page_size);911 const new_offset = self.findFreeSpace(needed_size, self.page_size);
912 const existing_size = if (self.last_atom_and_free_list_table.get(shdr_index)) |meta| blk: {912 const existing_size = shdr.sh_size;
913 const last = self.atom(meta.last_atom_index) orelse break :blk 0;
914 break :blk (last.value + last.size) - phdr.p_vaddr;
915 } else shdr.sh_size;
916 shdr.sh_size = 0;913 shdr.sh_size = 0;
917914
918 log.debug("new '{s}' file offset 0x{x} to 0x{x}", .{915 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 {...@@ -922,6 +919,7 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {
922 });919 });
923920
924 const amt = try self.base.file.?.copyRangeAll(shdr.sh_offset, self.base.file.?, new_offset, existing_size);921 const amt = try self.base.file.?.copyRangeAll(shdr.sh_offset, self.base.file.?, new_offset, existing_size);
922 // TODO figure out what to about this error condition - how to communicate it up.
925 if (amt != existing_size) return error.InputOutput;923 if (amt != existing_size) return error.InputOutput;
926924
927 shdr.sh_offset = new_offset;925 shdr.sh_offset = new_offset;