authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-01 23:44:01+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-09-01 23:44:01+02:00
log9dbad2d1888aae19f0411cc6de27171abc4e96f5
tree11aa0806e6060917660fc2fe24d0fcfe2d46a877
parent17066cc12e6fc3fb5349032dbcfbfd3552000a8d

macho: fix calculating file offset for atom when allocating


1 files changed, 13 insertions(+), 1 deletions(-)

src/link/MachO.zig+13-1
......@@ -1929,7 +1929,19 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64
19291929
19301930 const expand_section = atom_placement == null or atom_placement.?.next == null;
19311931 if (expand_section) {
1932 const max_size = seg.allocatedSize(vaddr - pagezero_vmsize);
1932 const sect_offset: u64 = blk: {
1933 if (self.data_segment_cmd_index.? == match.seg) {
1934 if (self.bss_section_index) |idx| {
1935 if (idx == match.sect) break :blk self.bss_file_offset.?;
1936 }
1937 if (self.tlv_bss_section_index) |idx| {
1938 if (idx == match.sect) break :blk self.tlv_bss_file_offset.?;
1939 }
1940 }
1941 break :blk sect.offset;
1942 };
1943 const file_offset = sect_offset + vaddr - sect.addr;
1944 const max_size = seg.allocatedSize(file_offset);
19331945 log.debug(" (atom size 0x{x}, max available size 0x{x})", .{ atom.size, max_size });
19341946 assert(atom.size <= max_size); // TODO must expand the section
19351947 }