authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-28 19:14:55+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-28 19:14:55+01:00
log5b315f8a3a6c925bdcbbc182d5bdc14f5f726146
treeefaf01d25352a42617f1860ae8ef356f6836641f
parent17215bd2c8debedea2b98d78b0c09cd5fe8d386a

macho: fix 32bit builds


2 files changed, 9 insertions(+), 5 deletions(-)

src/link/MachO/InternalObject.zig+7-4
...@@ -169,13 +169,16 @@ pub fn getAtomData(self: *const InternalObject, atom: Atom, buffer: []u8) !void...@@ -169,13 +169,16 @@ pub fn getAtomData(self: *const InternalObject, atom: Atom, buffer: []u8) !void
169 const slice = self.sections.slice();169 const slice = self.sections.slice();
170 const sect = slice.items(.header)[atom.n_sect];170 const sect = slice.items(.header)[atom.n_sect];
171 const extra = slice.items(.extra)[atom.n_sect];171 const extra = slice.items(.extra)[atom.n_sect];
172 const data = if (extra.is_objc_methname)172 const data = if (extra.is_objc_methname) blk: {
173 self.objc_methnames.items[sect.offset..][0..sect.size]173 const size = std.math.cast(usize, sect.size) orelse return error.Overflow;
174 else if (extra.is_objc_selref)174 break :blk self.objc_methnames.items[sect.offset..][0..size];
175 } else if (extra.is_objc_selref)
175 &self.objc_selrefs176 &self.objc_selrefs
176 else177 else
177 @panic("ref to non-existent section");178 @panic("ref to non-existent section");
178 @memcpy(buffer, data[atom.off..][0..atom.size]);179 const off = std.math.cast(usize, atom.off) orelse return error.Overflow;
180 const size = std.math.cast(usize, atom.size) orelse return error.Overflow;
181 @memcpy(buffer, data[off..][0..size]);
179}182}
180183
181pub fn getAtomRelocs(self: *const InternalObject, atom: Atom) []const Relocation {184pub fn getAtomRelocs(self: *const InternalObject, atom: Atom) []const Relocation {
src/link/MachO/Object.zig+2-1
...@@ -1589,7 +1589,8 @@ fn getSectionData(self: *const Object, allocator: Allocator, index: u32) ![]u8 {...@@ -1589,7 +1589,8 @@ fn getSectionData(self: *const Object, allocator: Allocator, index: u32) ![]u8 {
1589 assert(index < slice.items(.header).len);1589 assert(index < slice.items(.header).len);
1590 const sect = slice.items(.header)[index];1590 const sect = slice.items(.header)[index];
1591 const offset = if (self.archive) |ar| ar.offset else 0;1591 const offset = if (self.archive) |ar| ar.offset else 0;
1592 const buffer = try allocator.alloc(u8, sect.size);1592 const size = math.cast(usize, sect.size) orelse return error.Overflow;
1593 const buffer = try allocator.alloc(u8, size);
1593 errdefer allocator.free(buffer);1594 errdefer allocator.free(buffer);
1594 const amt = try self.file.preadAll(buffer, sect.offset + offset);1595 const amt = try self.file.preadAll(buffer, sect.offset + offset);
1595 if (amt != buffer.len) return error.InputOutput;1596 if (amt != buffer.len) return error.InputOutput;