| ... | @@ -3121,6 +3121,11 @@ fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []const u8) | ... | @@ -3121,6 +3121,11 @@ fn updateDeclCode(self: *MachO, decl_index: Module.Decl.Index, code: []const u8) |
| 3121 | } | 3121 | } |
| 3122 | } else if (code_len < atom.size) { | 3122 | } else if (code_len < atom.size) { |
| 3123 | self.shrinkAtom(atom, code_len); | 3123 | self.shrinkAtom(atom, code_len); |
| | 3124 | } else if (atom.next == null) { |
| | 3125 | const header = &self.sections.items(.header)[sect_id]; |
| | 3126 | const segment = self.getSegment(sect_id); |
| | 3127 | const needed_size = (sym.n_value + code_len) - segment.vmaddr; |
| | 3128 | header.size = needed_size; |
| 3124 | } | 3129 | } |
| 3125 | atom.size = code_len; | 3130 | atom.size = code_len; |
| 3126 | } else { | 3131 | } else { |
| ... | @@ -4688,12 +4693,11 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 { | ... | @@ -4688,12 +4693,11 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 { |
| 4688 | | 4693 | |
| 4689 | const end = start + padToIdeal(size); | 4694 | const end = start + padToIdeal(size); |
| 4690 | | 4695 | |
| 4691 | for (self.sections.items(.segment_index)) |segment_index| { | 4696 | for (self.sections.items(.header)) |header| { |
| 4692 | const segment = self.segments.items[segment_index]; | 4697 | const tight_size = header.size; |
| 4693 | const tight_size = segment.filesize; | | |
| 4694 | const increased_size = padToIdeal(tight_size); | 4698 | const increased_size = padToIdeal(tight_size); |
| 4695 | const test_end = segment.fileoff + increased_size; | 4699 | const test_end = header.offset + increased_size; |
| 4696 | if (end > segment.fileoff and start < test_end) { | 4700 | if (end > header.offset and start < test_end) { |
| 4697 | return test_end; | 4701 | return test_end; |
| 4698 | } | 4702 | } |
| 4699 | } | 4703 | } |
| ... | @@ -4705,10 +4709,9 @@ fn allocatedSize(self: *MachO, start: u64) u64 { | ... | @@ -4705,10 +4709,9 @@ fn allocatedSize(self: *MachO, start: u64) u64 { |
| 4705 | if (start == 0) | 4709 | if (start == 0) |
| 4706 | return 0; | 4710 | return 0; |
| 4707 | var min_pos: u64 = std.math.maxInt(u64); | 4711 | var min_pos: u64 = std.math.maxInt(u64); |
| 4708 | for (self.sections.items(.segment_index)) |segment_index| { | 4712 | for (self.sections.items(.header)) |header| { |
| 4709 | const segment = self.segments.items[segment_index]; | 4713 | if (header.offset <= start) continue; |
| 4710 | if (segment.fileoff <= start) continue; | 4714 | if (header.offset < min_pos) min_pos = header.offset; |
| 4711 | if (segment.fileoff < min_pos) min_pos = segment.fileoff; | | |
| 4712 | } | 4715 | } |
| 4713 | return min_pos - start; | 4716 | return min_pos - start; |
| 4714 | } | 4717 | } |
| ... | @@ -4721,7 +4724,7 @@ fn findFreeSpace(self: *MachO, object_size: u64, min_alignment: u32) u64 { | ... | @@ -4721,7 +4724,7 @@ fn findFreeSpace(self: *MachO, object_size: u64, min_alignment: u32) u64 { |
| 4721 | return start; | 4724 | return start; |
| 4722 | } | 4725 | } |
| 4723 | | 4726 | |
| 4724 | fn allocatedVirtualSize(self: *MachO, start: u64) u64 { | 4727 | pub fn allocatedVirtualSize(self: *MachO, start: u64) u64 { |
| 4725 | if (start == 0) | 4728 | if (start == 0) |
| 4726 | return 0; | 4729 | return 0; |
| 4727 | var min_pos: u64 = std.math.maxInt(u64); | 4730 | var min_pos: u64 = std.math.maxInt(u64); |