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(...@@ -927,9 +927,7 @@ fn parseDylib(
927 const self_cpu_arch = link_options.target.cpu.arch;927 const self_cpu_arch = link_options.target.cpu.arch;
928928
929 const file_stat = try file.stat();929 const file_stat = try file.stat();
930 var file_size = math.cast(usize, file_stat.size) orelse return error.Overflow;930 const file_size = math.cast(usize, file_stat.size - offset) orelse return error.Overflow;
931
932 file_size -= offset;
933931
934 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);932 const contents = try file.readToEndAllocOptions(gpa, file_size, file_size, @alignOf(u64), null);
935 defer gpa.free(contents);933 defer gpa.free(contents);
src/link/MachO/zld.zig+12-6
...@@ -703,7 +703,8 @@ fn writeAtoms(macho_file: *MachO) !void {...@@ -703,7 +703,8 @@ fn writeAtoms(macho_file: *MachO) !void {
703 log.debug(" (with padding {x})", .{padding_size});703 log.debug(" (with padding {x})", .{padding_size});
704 }704 }
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;
707 log.debug(" (at offset 0x{x})", .{offset});708 log.debug(" (at offset 0x{x})", .{offset});
708709
709 const code = Atom.getAtomCode(macho_file, atom_index);710 const code = Atom.getAtomCode(macho_file, atom_index);
...@@ -749,7 +750,8 @@ fn writeThunks(macho_file: *MachO) !void {...@@ -749,7 +750,8 @@ fn writeThunks(macho_file: *MachO) !void {
749750
750 for (macho_file.thunks.items, 0..) |*thunk, i| {751 for (macho_file.thunks.items, 0..) |*thunk, i| {
751 if (thunk.getSize() == 0) continue;752 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);
753 defer buffer.deinit();755 defer buffer.deinit();
754 try thunks.writeThunkCode(macho_file, thunk, buffer.writer());756 try thunks.writeThunkCode(macho_file, thunk, buffer.writer());
755 const thunk_atom = macho_file.getAtom(thunk.getStartAtomIndex());757 const thunk_atom = macho_file.getAtom(thunk.getStartAtomIndex());
...@@ -763,7 +765,8 @@ fn writeThunks(macho_file: *MachO) !void {...@@ -763,7 +765,8 @@ fn writeThunks(macho_file: *MachO) !void {
763fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void {765fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void {
764 const gpa = macho_file.base.allocator;766 const gpa = macho_file.base.allocator;
765 const header = macho_file.sections.items(.header)[sect_id];767 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);
767 defer buffer.deinit();770 defer buffer.deinit();
768 for (table.entries.items) |entry| {771 for (table.entries.items) |entry| {
769 const sym = macho_file.getSymbol(entry);772 const sym = macho_file.getSymbol(entry);
...@@ -779,7 +782,8 @@ fn writeStubs(macho_file: *MachO) !void {...@@ -779,7 +782,8 @@ fn writeStubs(macho_file: *MachO) !void {
779 const stubs_header = macho_file.sections.items(.header)[macho_file.stubs_section_index.?];782 const stubs_header = macho_file.sections.items(.header)[macho_file.stubs_section_index.?];
780 const la_symbol_ptr_header = macho_file.sections.items(.header)[macho_file.la_symbol_ptr_section_index.?];783 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);
783 defer buffer.deinit();787 defer buffer.deinit();
784788
785 for (0..macho_file.stub_table.count()) |index| {789 for (0..macho_file.stub_table.count()) |index| {
...@@ -799,7 +803,8 @@ fn writeStubHelpers(macho_file: *MachO) !void {...@@ -799,7 +803,8 @@ fn writeStubHelpers(macho_file: *MachO) !void {
799 const cpu_arch = macho_file.base.options.target.cpu.arch;803 const cpu_arch = macho_file.base.options.target.cpu.arch;
800 const stub_helper_header = macho_file.sections.items(.header)[macho_file.stub_helper_section_index.?];804 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);
803 defer buffer.deinit();808 defer buffer.deinit();
804809
805 {810 {
...@@ -842,7 +847,8 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void {...@@ -842,7 +847,8 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void {
842 const la_symbol_ptr_header = macho_file.sections.items(.header)[macho_file.la_symbol_ptr_section_index.?];847 const la_symbol_ptr_header = macho_file.sections.items(.header)[macho_file.la_symbol_ptr_section_index.?];
843 const stub_helper_header = macho_file.sections.items(.header)[macho_file.stub_helper_section_index.?];848 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);
846 defer buffer.deinit();852 defer buffer.deinit();
847853
848 for (0..macho_file.stub_table.count()) |index| {854 for (0..macho_file.stub_table.count()) |index| {