authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-01 00:01:57+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-01 00:06:43+02:00
logd0dc622638716583eb4d9de78dfc87bef7969bc0
tree0fd31fdf6c2821b4bd15964919e67286fe740e2e
parent50db993119d9b1031700be94b757eaf100f35857

macho: do not reset section's size after allocating atom


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

src/link/MachO.zig-12
......@@ -1950,8 +1950,6 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64
19501950 break :blk end_addr;
19511951 };
19521952 assert(needed_size <= end_addr); // TODO must expand the section
1953 sect.size = needed_size;
1954 self.load_commands_dirty = true;
19551953 }
19561954 const n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1);
19571955 sym.n_value = vaddr;
......@@ -4599,17 +4597,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
45994597 if (expand_text_section) {
46004598 const needed_size = (vaddr + new_block_size) - text_section.addr;
46014599 assert(needed_size <= text_segment.inner.filesize); // TODO must move the entire text section.
4602
46034600 _ = try self.blocks.put(self.base.allocator, match, text_block);
4604 text_section.size = needed_size;
4605 self.load_commands_dirty = true; // TODO Make more granular.
4606
4607 if (self.d_sym) |*ds| {
4608 const debug_text_seg = &ds.load_commands.items[ds.text_segment_cmd_index.?].Segment;
4609 const debug_text_sect = &debug_text_seg.sections.items[ds.text_section_index.?];
4610 debug_text_sect.size = needed_size;
4611 ds.load_commands_dirty = true;
4612 }
46134601 }
46144602 text_block.size = new_block_size;
46154603
src/link/MachO/commands.zig+4-4
......@@ -270,11 +270,11 @@ pub const SegmentCommand = struct {
270270 }
271271
272272 pub fn findFreeSpace(self: SegmentCommand, object_size: u64, min_alignment: u32, start: ?u64) u64 {
273 var st: u64 = if (start) |v| v else self.inner.fileoff;
274 while (self.detectAllocCollision(st, object_size)) |item_end| {
275 st = mem.alignForwardGeneric(u64, item_end, min_alignment);
273 var offset: u64 = if (start) |v| v else self.inner.fileoff;
274 while (self.detectAllocCollision(offset, object_size)) |item_end| {
275 offset = mem.alignForwardGeneric(u64, item_end, min_alignment);
276276 }
277 return st;
277 return offset;
278278 }
279279
280280 fn eql(self: SegmentCommand, other: SegmentCommand) bool {