authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-28 07:31:44+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-29 11:40:20+02:00
log0f02a1fcb0ea82c98de509e7ba9b7b8768f0d4ee
treea3ae2ca165baf0dab094bcacb88d8d65ffc1f1fe
parent8330065a99e057152a7c717066f66adbc622a04b

macho: fix 32bit compilation issues


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

src/link/MachO.zig+1-3
......@@ -927,9 +927,7 @@ fn parseDylib(
927927 const self_cpu_arch = link_options.target.cpu.arch;
928928
929929 const file_stat = try file.stat();
930 var file_size = math.cast(usize, file_stat.size) orelse return error.Overflow;
931
932 file_size -= offset;
930 const file_size = math.cast(usize, file_stat.size - offset) orelse return error.Overflow;
933931
934932 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);
935933 defer gpa.free(contents);
src/link/MachO/zld.zig+12-6
......@@ -703,7 +703,8 @@ fn writeAtoms(macho_file: *MachO) !void {
703703 log.debug(" (with padding {x})", .{padding_size});
704704 }
705705
706 const offset = this_sym.n_value - header.addr;
706 const offset = math.cast(usize, this_sym.n_value - header.addr) orelse
707 return error.Overflow;
707708 log.debug(" (at offset 0x{x})", .{offset});
708709
709710 const code = Atom.getAtomCode(macho_file, atom_index);
......@@ -749,7 +750,8 @@ fn writeThunks(macho_file: *MachO) !void {
749750
750751 for (macho_file.thunks.items, 0..) |*thunk, i| {
751752 if (thunk.getSize() == 0) continue;
752 var buffer = try std.ArrayList(u8).initCapacity(gpa, thunk.getSize());
753 const thunk_size = math.cast(usize, thunk.getSize()) orelse return error.Overflow;
754 var buffer = try std.ArrayList(u8).initCapacity(gpa, thunk_size);
753755 defer buffer.deinit();
754756 try thunks.writeThunkCode(macho_file, thunk, buffer.writer());
755757 const thunk_atom = macho_file.getAtom(thunk.getStartAtomIndex());
......@@ -763,7 +765,8 @@ fn writeThunks(macho_file: *MachO) !void {
763765fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void {
764766 const gpa = macho_file.base.allocator;
765767 const header = macho_file.sections.items(.header)[sect_id];
766 var buffer = try std.ArrayList(u8).initCapacity(gpa, header.size);
768 const capacity = math.cast(usize, header.size) orelse return error.Overflow;
769 var buffer = try std.ArrayList(u8).initCapacity(gpa, capacity);
767770 defer buffer.deinit();
768771 for (table.entries.items) |entry| {
769772 const sym = macho_file.getSymbol(entry);
......@@ -779,7 +782,8 @@ fn writeStubs(macho_file: *MachO) !void {
779782 const stubs_header = macho_file.sections.items(.header)[macho_file.stubs_section_index.?];
780783 const la_symbol_ptr_header = macho_file.sections.items(.header)[macho_file.la_symbol_ptr_section_index.?];
781784
782 var buffer = try std.ArrayList(u8).initCapacity(gpa, stubs_header.size);
785 const capacity = math.cast(usize, stubs_header.size) orelse return error.Overflow;
786 var buffer = try std.ArrayList(u8).initCapacity(gpa, capacity);
783787 defer buffer.deinit();
784788
785789 for (0..macho_file.stub_table.count()) |index| {
......@@ -799,7 +803,8 @@ fn writeStubHelpers(macho_file: *MachO) !void {
799803 const cpu_arch = macho_file.base.options.target.cpu.arch;
800804 const stub_helper_header = macho_file.sections.items(.header)[macho_file.stub_helper_section_index.?];
801805
802 var buffer = try std.ArrayList(u8).initCapacity(gpa, stub_helper_header.size);
806 const capacity = math.cast(usize, stub_helper_header.size) orelse return error.Overflow;
807 var buffer = try std.ArrayList(u8).initCapacity(gpa, capacity);
803808 defer buffer.deinit();
804809
805810 {
......@@ -842,7 +847,8 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void {
842847 const la_symbol_ptr_header = macho_file.sections.items(.header)[macho_file.la_symbol_ptr_section_index.?];
843848 const stub_helper_header = macho_file.sections.items(.header)[macho_file.stub_helper_section_index.?];
844849
845 var buffer = try std.ArrayList(u8).initCapacity(gpa, la_symbol_ptr_header.size);
850 const capacity = math.cast(usize, la_symbol_ptr_header.size) orelse return error.Overflow;
851 var buffer = try std.ArrayList(u8).initCapacity(gpa, capacity);
846852 defer buffer.deinit();
847853
848854 for (0..macho_file.stub_table.count()) |index| {