| ... | @@ -1678,7 +1678,11 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64 | ... | @@ -1678,7 +1678,11 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64 |
| 1678 | if (expand_section) { | 1678 | if (expand_section) { |
| 1679 | const needed_size = @intCast(u32, (vaddr + atom.size) - sect.addr); | 1679 | const needed_size = @intCast(u32, (vaddr + atom.size) - sect.addr); |
| 1680 | try self.growSection(match, needed_size); | 1680 | try self.growSection(match, needed_size); |
| | 1681 | sect.size = needed_size; |
| | 1682 | self.load_commands_dirty = true; |
| 1681 | } | 1683 | } |
| | 1684 | sect.@"align" = math.max(sect.@"align", atom.alignment); |
| | 1685 | |
| 1682 | const n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1); | 1686 | const n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1); |
| 1683 | sym.n_value = vaddr; | 1687 | sym.n_value = vaddr; |
| 1684 | sym.n_sect = n_sect; | 1688 | sym.n_sect = n_sect; |
| ... | @@ -3899,15 +3903,13 @@ fn growSection(self: *MachO, match: MatchingSection, new_size: u32) !void { | ... | @@ -3899,15 +3903,13 @@ fn growSection(self: *MachO, match: MatchingSection, new_size: u32) !void { |
| 3899 | }, @intCast(i64, offset_amt)); | 3903 | }, @intCast(i64, offset_amt)); |
| 3900 | } | 3904 | } |
| 3901 | } | 3905 | } |
| 3902 | | | |
| 3903 | sect.size = new_size; | | |
| 3904 | self.load_commands_dirty = true; | | |
| 3905 | } | 3906 | } |
| 3906 | | 3907 | |
| 3907 | fn allocatedSize(self: MachO, segment_id: u16, start: u64) u64 { | 3908 | fn allocatedSize(self: MachO, segment_id: u16, start: u64) u64 { |
| 3908 | const seg = self.load_commands.items[segment_id].Segment; | 3909 | const seg = self.load_commands.items[segment_id].Segment; |
| 3909 | assert(start >= seg.inner.fileoff); | 3910 | assert(start >= seg.inner.fileoff); |
| 3910 | var min_pos: u64 = seg.inner.fileoff + seg.inner.filesize; | 3911 | var min_pos: u64 = seg.inner.fileoff + seg.inner.filesize; |
| | 3912 | if (start > min_pos) return 0; |
| 3911 | for (seg.sections.items) |section| { | 3913 | for (seg.sections.items) |section| { |
| 3912 | if (section.offset <= start) continue; | 3914 | if (section.offset <= start) continue; |
| 3913 | if (section.offset < min_pos) min_pos = section.offset; | 3915 | if (section.offset < min_pos) min_pos = section.offset; |
| ... | @@ -4003,7 +4005,11 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64, | ... | @@ -4003,7 +4005,11 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64, |
| 4003 | const needed_size = @intCast(u32, (vaddr + new_block_size) - text_section.addr); | 4005 | const needed_size = @intCast(u32, (vaddr + new_block_size) - text_section.addr); |
| 4004 | try self.growSection(match, needed_size); | 4006 | try self.growSection(match, needed_size); |
| 4005 | _ = try self.blocks.put(self.base.allocator, match, text_block); | 4007 | _ = try self.blocks.put(self.base.allocator, match, text_block); |
| | 4008 | text_section.size = needed_size; |
| | 4009 | self.load_commands_dirty = true; |
| 4006 | } | 4010 | } |
| | 4011 | const align_pow = @intCast(u32, math.log2(alignment)); |
| | 4012 | text_section.@"align" = math.max(text_section.@"align", align_pow); |
| 4007 | text_block.size = new_block_size; | 4013 | text_block.size = new_block_size; |
| 4008 | | 4014 | |
| 4009 | if (text_block.prev) |prev| { | 4015 | if (text_block.prev) |prev| { |