| ... | ... | @@ -1660,17 +1660,20 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64 |
| 1660 | 1660 | const needs_padding = match.seg == self.text_segment_cmd_index.? and match.sect == self.text_section_index.?; |
| 1661 | 1661 | |
| 1662 | 1662 | var atom_placement: ?*TextBlock = null; |
| 1663 | const atom_alignment = try math.powi(u32, 2, atom.alignment); |
| 1663 | 1664 | |
| 1664 | 1665 | // TODO converge with `allocateTextBlock` and handle free list |
| 1665 | 1666 | var vaddr = if (self.blocks.get(match)) |last| blk: { |
| 1666 | 1667 | const last_atom_sym = self.locals.items[last.local_sym_index]; |
| 1667 | 1668 | const ideal_capacity = if (needs_padding) padToIdeal(last.size) else last.size; |
| 1668 | 1669 | 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); |
| 1671 | 1671 | atom_placement = last; |
| 1672 | 1672 | 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? |
| 1674 | 1677 | |
| 1675 | 1678 | log.debug("allocating atom for symbol {s} at address 0x{x}", .{ self.getString(sym.n_strx), vaddr }); |
| 1676 | 1679 | |