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...@@ -1950,8 +1950,6 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64
1950 break :blk end_addr;1950 break :blk end_addr;
1951 };1951 };
1952 assert(needed_size <= end_addr); // TODO must expand the section1952 assert(needed_size <= end_addr); // TODO must expand the section
1953 sect.size = needed_size;
1954 self.load_commands_dirty = true;
1955 }1953 }
1956 const n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1);1954 const n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1);
1957 sym.n_value = vaddr;1955 sym.n_value = vaddr;
...@@ -4599,17 +4597,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,...@@ -4599,17 +4597,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
4599 if (expand_text_section) {4597 if (expand_text_section) {
4600 const needed_size = (vaddr + new_block_size) - text_section.addr;4598 const needed_size = (vaddr + new_block_size) - text_section.addr;
4601 assert(needed_size <= text_segment.inner.filesize); // TODO must move the entire text section.4599 assert(needed_size <= text_segment.inner.filesize); // TODO must move the entire text section.
4602
4603 _ = try self.blocks.put(self.base.allocator, match, text_block);4600 _ = 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 }
4613 }4601 }
4614 text_block.size = new_block_size;4602 text_block.size = new_block_size;
46154603
src/link/MachO/commands.zig+4-4
...@@ -270,11 +270,11 @@ pub const SegmentCommand = struct {...@@ -270,11 +270,11 @@ pub const SegmentCommand = struct {
270 }270 }
271271
272 pub fn findFreeSpace(self: SegmentCommand, object_size: u64, min_alignment: u32, start: ?u64) u64 {272 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;273 var offset: u64 = if (start) |v| v else self.inner.fileoff;
274 while (self.detectAllocCollision(st, object_size)) |item_end| {274 while (self.detectAllocCollision(offset, object_size)) |item_end| {
275 st = mem.alignForwardGeneric(u64, item_end, min_alignment);275 offset = mem.alignForwardGeneric(u64, item_end, min_alignment);
276 }276 }
277 return st;277 return offset;
278 }278 }
279279
280 fn eql(self: SegmentCommand, other: SegmentCommand) bool {280 fn eql(self: SegmentCommand, other: SegmentCommand) bool {