| ... | ... | @@ -1757,6 +1757,58 @@ fn nextSegmentAddressAndOffset(self: *MachO) NextSegmentAddressAndOffset { |
| 1757 | 1757 | }; |
| 1758 | 1758 | } |
| 1759 | 1759 | |
| 1760 | fn allocatedSize(self: *MachO, segment: *const SegmentCommand, start: u64) u64 { |
| 1761 | assert(start > 0); |
| 1762 | var min_pos: u64 = std.math.maxInt(u64); |
| 1763 | |
| 1764 | if (parseAndCmpName(&segment.inner.segname, "__LINKEDIT")) { |
| 1765 | assert(segment.sections.items.len == 0); |
| 1766 | // __LINKEDIT is a weird segment where sections get their own load commands so we |
| 1767 | // special-case it. |
| 1768 | if (self.dyld_info_cmd_index) |idx| { |
| 1769 | const dyld_info = self.load_commands.items[idx].DyldInfoOnly; |
| 1770 | if (dyld_info.rebase_off > start and dyld_info.rebase_off < min_pos) min_pos = off; |
| 1771 | if (dyld_info.bind_off > start and dyld_info.bind_off < min_pos) min_pos = off; |
| 1772 | if (dyld_info.weak_bind_off > start and dyld_info.weak_bind_off < min_pos) min_pos = off; |
| 1773 | if (dyld_info.lazy_bind_off > start and dyld_info.lazy_bind_off < min_pos) min_pos = off; |
| 1774 | if (dyld_info.export_off > start and dyld_info.export_off < min_pos) min_pos = off; |
| 1775 | } |
| 1776 | |
| 1777 | if (self.function_starts_cmd_index) |idx| { |
| 1778 | const fstart = self.load_commands.items[idx].LinkeditData; |
| 1779 | if (fstart.dataoff > start and fstart.dataoff < min_pos) min_pos = off; |
| 1780 | } |
| 1781 | |
| 1782 | if (self.data_in_code_cmd_index) |idx| { |
| 1783 | const dic = self.load_commands.items[idx].LinkeditData; |
| 1784 | if (dic.dataoff > start and dic.dataoff < min_pos) min_pos = off; |
| 1785 | } |
| 1786 | |
| 1787 | if (self.dysymtab_cmd_index) |idx| { |
| 1788 | const dysymtab = self.load_commands.items[idx].Dysymtab; |
| 1789 | if (dysymtab.indirectsymoff > start and dysymtab.indirectsymoff < min_pos) min_pos = off; |
| 1790 | // TODO Handle more dynamic symbol table sections. |
| 1791 | } |
| 1792 | |
| 1793 | if (self.symtab_cmd_index) |idx| { |
| 1794 | const symtab = self.load_commands.items[idx].Symtab; |
| 1795 | if (symtab.symoff > start and symtab.symoff < min_pos) min_pos = off; |
| 1796 | if (symtab.stroff > start and symtab.stroff < min_pos) min_pos = off; |
| 1797 | } |
| 1798 | |
| 1799 | if (self.code_signature_cmd_index) |idx| { |
| 1800 | const codesig = self.load_commands.items[idx].LinkeditData; |
| 1801 | if (codesig.dataoff > start and codesig.dataoff < min_pos) min_pos = off; |
| 1802 | } |
| 1803 | } else { |
| 1804 | for (segment.sections.items) |section| { |
| 1805 | if (section.offset > start and sections.offset < min_pos) min_pos = off; |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | return min_pos - start; |
| 1810 | } |
| 1811 | |
| 1760 | 1812 | inline fn checkForCollision(start: u64, end: u64, off: u64, size: u64) ?u64 { |
| 1761 | 1813 | const increased_size = satMul(size, alloc_num) / alloc_den; |
| 1762 | 1814 | const test_end = off + increased_size; |
| ... | ... | @@ -1770,6 +1822,7 @@ fn detectAllocCollision(self: *MachO, segment: *const SegmentCommand, start: u64 |
| 1770 | 1822 | const end = start + satMul(size, alloc_num) / alloc_den; |
| 1771 | 1823 | |
| 1772 | 1824 | if (parseAndCmpName(&segment.inner.segname, "__LINKEDIT")) { |
| 1825 | assert(segment.sections.items.len == 0); |
| 1773 | 1826 | // __LINKEDIT is a weird segment where sections get their own load commands so we |
| 1774 | 1827 | // special-case it. |
| 1775 | 1828 | if (self.dyld_info_cmd_index) |idx| outer: { |