authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-07 10:06:01+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-07 10:07:09+02:00
logc35f668932df4d339b069acf0dbfccfe2faa56b6
tree72494a4889f2711e5a12f57ad299a2a028a0b5e8
parent6836cc473c3e75a71c0e6c0123c8afb23a79596d

macho: update max section alignment when inserting atoms


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

src/link/MachO.zig+9-3
......@@ -1678,7 +1678,11 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64
16781678 if (expand_section) {
16791679 const needed_size = @intCast(u32, (vaddr + atom.size) - sect.addr);
16801680 try self.growSection(match, needed_size);
1681 sect.size = needed_size;
1682 self.load_commands_dirty = true;
16811683 }
1684 sect.@"align" = math.max(sect.@"align", atom.alignment);
1685
16821686 const n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1);
16831687 sym.n_value = vaddr;
16841688 sym.n_sect = n_sect;
......@@ -3899,15 +3903,13 @@ fn growSection(self: *MachO, match: MatchingSection, new_size: u32) !void {
38993903 }, @intCast(i64, offset_amt));
39003904 }
39013905 }
3902
3903 sect.size = new_size;
3904 self.load_commands_dirty = true;
39053906}
39063907
39073908fn allocatedSize(self: MachO, segment_id: u16, start: u64) u64 {
39083909 const seg = self.load_commands.items[segment_id].Segment;
39093910 assert(start >= seg.inner.fileoff);
39103911 var min_pos: u64 = seg.inner.fileoff + seg.inner.filesize;
3912 if (start > min_pos) return 0;
39113913 for (seg.sections.items) |section| {
39123914 if (section.offset <= start) continue;
39133915 if (section.offset < min_pos) min_pos = section.offset;
......@@ -4003,7 +4005,11 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
40034005 const needed_size = @intCast(u32, (vaddr + new_block_size) - text_section.addr);
40044006 try self.growSection(match, needed_size);
40054007 _ = try self.blocks.put(self.base.allocator, match, text_block);
4008 text_section.size = needed_size;
4009 self.load_commands_dirty = true;
40064010 }
4011 const align_pow = @intCast(u32, math.log2(alignment));
4012 text_section.@"align" = math.max(text_section.@"align", align_pow);
40074013 text_block.size = new_block_size;
40084014
40094015 if (text_block.prev) |prev| {