authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-25 23:00:58+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-25 23:00:58+02:00
logc12183b608c48ec4417c530916fc1a78b7d442f6
treebce110edf40501a72b313fc3e79456070cdea347
parentee786e5c3c1171af082f9463ca46b9ed08d2601e

macho: fix text atom allocation


1 files changed, 9 insertions(+), 3 deletions(-)

src/link/MachO.zig+9-3
......@@ -4024,11 +4024,17 @@ pub fn populateMissingMetadata(self: *MachO) !void {
40244024 .aarch64 => 2,
40254025 else => unreachable, // unhandled architecture type
40264026 };
4027 const needed_size: u6 = switch (self.base.options.target.cpu.arch) {
4027 const preamble_size: u6 = switch (self.base.options.target.cpu.arch) {
40284028 .x86_64 => 15,
40294029 .aarch64 => 6 * @sizeOf(u32),
40304030 else => unreachable,
40314031 };
4032 const stub_size: u4 = switch (self.base.options.target.cpu.arch) {
4033 .x86_64 => 10,
4034 .aarch64 => 3 * @sizeOf(u32),
4035 else => unreachable,
4036 };
4037 const needed_size = stub_size * self.base.options.symbol_count_hint + preamble_size;
40324038 const off = text_segment.findFreeSpace(needed_size, @alignOf(u64), self.header_pad);
40334039 assert(off + needed_size <= text_segment.inner.fileoff + text_segment.inner.filesize); // TODO Must expand __TEXT segment.
40344040
......@@ -4420,7 +4426,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
44204426 .seg = self.text_segment_cmd_index.?,
44214427 .sect = self.text_section_index.?,
44224428 };
4423 const text_block_free_list = self.block_free_lists.getPtr(match).?;
4429 var text_block_free_list = self.block_free_lists.get(match).?;
44244430 const new_block_ideal_capacity = padToIdeal(new_block_size);
44254431
44264432 // We use these to indicate our intention to update metadata, placing the new block,
......@@ -4489,7 +4495,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
44894495 const needed_size = (vaddr + new_block_size) - text_section.addr;
44904496 assert(needed_size <= text_segment.inner.filesize); // TODO must move the entire text section.
44914497
4492 _ = try self.blocks.getOrPutValue(self.base.allocator, match, text_block);
4498 _ = try self.blocks.put(self.base.allocator, match, text_block);
44934499 text_section.size = needed_size;
44944500 self.load_commands_dirty = true; // TODO Make more granular.
44954501