authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-07 20:18:48+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-07 20:37:58+02:00
log159e55dfd9b03a11f5eb1c79ec5d56cdfd6f7707
treedba76ada200be212d5ef73f9493abdb175c43423
parenta2279e7e209b5dab096af186fc692bd2acf5f4c8

macho: fix alignment of atoms which begin the section


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

src/link/MachO.zig+6-3
......@@ -1660,17 +1660,20 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64
16601660 const needs_padding = match.seg == self.text_segment_cmd_index.? and match.sect == self.text_section_index.?;
16611661
16621662 var atom_placement: ?*TextBlock = null;
1663 const atom_alignment = try math.powi(u32, 2, atom.alignment);
16631664
16641665 // TODO converge with `allocateTextBlock` and handle free list
16651666 var vaddr = if (self.blocks.get(match)) |last| blk: {
16661667 const last_atom_sym = self.locals.items[last.local_sym_index];
16671668 const ideal_capacity = if (needs_padding) padToIdeal(last.size) else last.size;
16681669 const ideal_capacity_end_vaddr = last_atom_sym.n_value + ideal_capacity;
1669 const last_atom_alignment = try math.powi(u32, 2, atom.alignment);
1670 const new_start_vaddr = mem.alignForwardGeneric(u64, ideal_capacity_end_vaddr, last_atom_alignment);
1670 const new_start_vaddr = mem.alignForwardGeneric(u64, ideal_capacity_end_vaddr, atom_alignment);
16711671 atom_placement = last;
16721672 break :blk new_start_vaddr;
1673 } else sect.addr;
1673 } else mem.alignForwardGeneric(u64, sect.addr, atom_alignment);
1674
1675 // TODO what if the section which was preallocated is not aligned to the maximum (section) alignment?
1676 // Should we move the section?
16741677
16751678 log.debug("allocating atom for symbol {s} at address 0x{x}", .{ self.getString(sym.n_strx), vaddr });
16761679