authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-07-14 09:05:45+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-07-22 16:58:20+02:00
logeeb6d8f0457b42cef560c1e4efeca69c0fe276fe
treef7ebbb40e879e8a6c74e1b7a268c94acdc84ee20
parent9eb7e5182b963366da9415ff7efe7c0fa5b1ad62

macho: fix compilation issues on 32bit hosts


1 files changed, 19 insertions(+), 17 deletions(-)

src/link/MachO/Object.zig+19-17
......@@ -77,29 +77,29 @@ const DebugInfo = struct {
7777 pub fn parseFromObject(allocator: Allocator, object: *const Object) !?DebugInfo {
7878 var debug_info = blk: {
7979 const index = object.dwarf_debug_info_index orelse return null;
80 break :blk object.getSectionContents(index);
80 break :blk try object.getSectionContents(index);
8181 };
8282 var debug_abbrev = blk: {
8383 const index = object.dwarf_debug_abbrev_index orelse return null;
84 break :blk object.getSectionContents(index);
84 break :blk try object.getSectionContents(index);
8585 };
8686 var debug_str = blk: {
8787 const index = object.dwarf_debug_str_index orelse return null;
88 break :blk object.getSectionContents(index);
88 break :blk try object.getSectionContents(index);
8989 };
9090 var debug_line = blk: {
9191 const index = object.dwarf_debug_line_index orelse return null;
92 break :blk object.getSectionContents(index);
92 break :blk try object.getSectionContents(index);
9393 };
9494 var debug_line_str = blk: {
9595 if (object.dwarf_debug_line_str_index) |ind| {
96 break :blk object.getSectionContents(ind);
96 break :blk try object.getSectionContents(ind);
9797 }
9898 break :blk &[0]u8{};
9999 };
100100 var debug_ranges = blk: {
101101 if (object.dwarf_debug_ranges_index) |ind| {
102 break :blk object.getSectionContents(ind);
102 break :blk try object.getSectionContents(ind);
103103 }
104104 break :blk &[0]u8{};
105105 };
......@@ -429,7 +429,7 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v
429429 };
430430
431431 // Read section's code
432 const code: ?[]const u8 = if (!is_zerofill) self.getSectionContents(sect_id) else null;
432 const code: ?[]const u8 = if (!is_zerofill) try self.getSectionContents(sect_id) else null;
433433
434434 // Read section's list of relocations
435435 const raw_relocs = self.contents[sect.reloff..][0 .. sect.nreloc * @sizeOf(macho.relocation_info)];
......@@ -475,10 +475,10 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v
475475 break :blk sym_index;
476476 };
477477 const atom_size = first_sym.n_value - sect.addr;
478 const atom_code: ?[]const u8 = if (code) |cc|
479 cc[0..atom_size]
480 else
481 null;
478 const atom_code: ?[]const u8 = if (code) |cc| blk: {
479 const size = math.cast(usize, atom_size) orelse return error.Overflow;
480 break :blk cc[0..size];
481 } else null;
482482 const atom = try self.createAtomFromSubsection(
483483 macho_file,
484484 object_id,
......@@ -515,10 +515,11 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v
515515 sect.addr + sect.size;
516516 break :blk end_addr - addr;
517517 };
518 const atom_code: ?[]const u8 = if (code) |cc|
519 cc[addr - sect.addr ..][0..atom_size]
520 else
521 null;
518 const atom_code: ?[]const u8 = if (code) |cc| blk: {
519 const start = math.cast(usize, addr - sect.addr) orelse return error.Overflow;
520 const size = math.cast(usize, atom_size) orelse return error.Overflow;
521 break :blk cc[start..][0..size];
522 } else null;
522523 const atom_align = if (addr > 0)
523524 math.min(@ctz(u64, addr), sect.@"align")
524525 else
......@@ -760,15 +761,16 @@ fn parseDataInCode(self: *Object) void {
760761 );
761762}
762763
763fn getSectionContents(self: Object, sect_id: u16) []const u8 {
764fn getSectionContents(self: Object, sect_id: u16) error{Overflow}![]const u8 {
764765 const sect = self.getSection(sect_id);
766 const size = math.cast(usize, sect.size) orelse return error.Overflow;
765767 log.debug("getting {s},{s} data at 0x{x} - 0x{x}", .{
766768 sect.segName(),
767769 sect.sectName(),
768770 sect.offset,
769771 sect.offset + sect.size,
770772 });
771 return self.contents[sect.offset..][0..sect.size];
773 return self.contents[sect.offset..][0..size];
772774}
773775
774776pub fn getString(self: Object, off: u32) []const u8 {