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 {...@@ -4024,11 +4024,17 @@ pub fn populateMissingMetadata(self: *MachO) !void {
4024 .aarch64 => 2,4024 .aarch64 => 2,
4025 else => unreachable, // unhandled architecture type4025 else => unreachable, // unhandled architecture type
4026 };4026 };
4027 const needed_size: u6 = switch (self.base.options.target.cpu.arch) {4027 const preamble_size: u6 = switch (self.base.options.target.cpu.arch) {
4028 .x86_64 => 15,4028 .x86_64 => 15,
4029 .aarch64 => 6 * @sizeOf(u32),4029 .aarch64 => 6 * @sizeOf(u32),
4030 else => unreachable,4030 else => unreachable,
4031 };4031 };
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;
4032 const off = text_segment.findFreeSpace(needed_size, @alignOf(u64), self.header_pad);4038 const off = text_segment.findFreeSpace(needed_size, @alignOf(u64), self.header_pad);
4033 assert(off + needed_size <= text_segment.inner.fileoff + text_segment.inner.filesize); // TODO Must expand __TEXT segment.4039 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,...@@ -4420,7 +4426,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
4420 .seg = self.text_segment_cmd_index.?,4426 .seg = self.text_segment_cmd_index.?,
4421 .sect = self.text_section_index.?,4427 .sect = self.text_section_index.?,
4422 };4428 };
4423 const text_block_free_list = self.block_free_lists.getPtr(match).?;4429 var text_block_free_list = self.block_free_lists.get(match).?;
4424 const new_block_ideal_capacity = padToIdeal(new_block_size);4430 const new_block_ideal_capacity = padToIdeal(new_block_size);
44254431
4426 // We use these to indicate our intention to update metadata, placing the new block,4432 // 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,...@@ -4489,7 +4495,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
4489 const needed_size = (vaddr + new_block_size) - text_section.addr;4495 const needed_size = (vaddr + new_block_size) - text_section.addr;
4490 assert(needed_size <= text_segment.inner.filesize); // TODO must move the entire text section.4496 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);
4493 text_section.size = needed_size;4499 text_section.size = needed_size;
4494 self.load_commands_dirty = true; // TODO Make more granular.4500 self.load_commands_dirty = true; // TODO Make more granular.
44954501