aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-09-29 19:06:02 +0200
committerJakub Konka <kubkon@jakubkonka.com>2023-09-29 19:06:02 +0200
commit0524a3c83dcd5d630e762b0769de8057f75c68e5 (patch)
treee4a8cd0f1021eeb1fd709039f7c64006675e2a8c
parent04a7051c4bf26ea9a5ffd2e5b618726e8ec06837 (diff)
downloadzig-0524a3c83dcd5d630e762b0769de8057f75c68e5.tar.gz
zig-0524a3c83dcd5d630e762b0769de8057f75c68e5.zip
elf: fix calculating current allocated section size when growing alloc sections
-rw-r--r--src/link/Elf.zig6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 313d72ba3a..29b882e9f6 100644
--- 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;