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 {...@@ -77,29 +77,29 @@ const DebugInfo = struct {
77 pub fn parseFromObject(allocator: Allocator, object: *const Object) !?DebugInfo {77 pub fn parseFromObject(allocator: Allocator, object: *const Object) !?DebugInfo {
78 var debug_info = blk: {78 var debug_info = blk: {
79 const index = object.dwarf_debug_info_index orelse return null;79 const index = object.dwarf_debug_info_index orelse return null;
80 break :blk object.getSectionContents(index);80 break :blk try object.getSectionContents(index);
81 };81 };
82 var debug_abbrev = blk: {82 var debug_abbrev = blk: {
83 const index = object.dwarf_debug_abbrev_index orelse return null;83 const index = object.dwarf_debug_abbrev_index orelse return null;
84 break :blk object.getSectionContents(index);84 break :blk try object.getSectionContents(index);
85 };85 };
86 var debug_str = blk: {86 var debug_str = blk: {
87 const index = object.dwarf_debug_str_index orelse return null;87 const index = object.dwarf_debug_str_index orelse return null;
88 break :blk object.getSectionContents(index);88 break :blk try object.getSectionContents(index);
89 };89 };
90 var debug_line = blk: {90 var debug_line = blk: {
91 const index = object.dwarf_debug_line_index orelse return null;91 const index = object.dwarf_debug_line_index orelse return null;
92 break :blk object.getSectionContents(index);92 break :blk try object.getSectionContents(index);
93 };93 };
94 var debug_line_str = blk: {94 var debug_line_str = blk: {
95 if (object.dwarf_debug_line_str_index) |ind| {95 if (object.dwarf_debug_line_str_index) |ind| {
96 break :blk object.getSectionContents(ind);96 break :blk try object.getSectionContents(ind);
97 }97 }
98 break :blk &[0]u8{};98 break :blk &[0]u8{};
99 };99 };
100 var debug_ranges = blk: {100 var debug_ranges = blk: {
101 if (object.dwarf_debug_ranges_index) |ind| {101 if (object.dwarf_debug_ranges_index) |ind| {
102 break :blk object.getSectionContents(ind);102 break :blk try object.getSectionContents(ind);
103 }103 }
104 break :blk &[0]u8{};104 break :blk &[0]u8{};
105 };105 };
...@@ -429,7 +429,7 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v...@@ -429,7 +429,7 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v
429 };429 };
430430
431 // Read section's code431 // 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
434 // Read section's list of relocations434 // Read section's list of relocations
435 const raw_relocs = self.contents[sect.reloff..][0 .. sect.nreloc * @sizeOf(macho.relocation_info)];435 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...@@ -475,10 +475,10 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v
475 break :blk sym_index;475 break :blk sym_index;
476 };476 };
477 const atom_size = first_sym.n_value - sect.addr;477 const atom_size = first_sym.n_value - sect.addr;
478 const atom_code: ?[]const u8 = if (code) |cc|478 const atom_code: ?[]const u8 = if (code) |cc| blk: {
479 cc[0..atom_size]479 const size = math.cast(usize, atom_size) orelse return error.Overflow;
480 else480 break :blk cc[0..size];
481 null;481 } else null;
482 const atom = try self.createAtomFromSubsection(482 const atom = try self.createAtomFromSubsection(
483 macho_file,483 macho_file,
484 object_id,484 object_id,
...@@ -515,10 +515,11 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v...@@ -515,10 +515,11 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v
515 sect.addr + sect.size;515 sect.addr + sect.size;
516 break :blk end_addr - addr;516 break :blk end_addr - addr;
517 };517 };
518 const atom_code: ?[]const u8 = if (code) |cc|518 const atom_code: ?[]const u8 = if (code) |cc| blk: {
519 cc[addr - sect.addr ..][0..atom_size]519 const start = math.cast(usize, addr - sect.addr) orelse return error.Overflow;
520 else520 const size = math.cast(usize, atom_size) orelse return error.Overflow;
521 null;521 break :blk cc[start..][0..size];
522 } else null;
522 const atom_align = if (addr > 0)523 const atom_align = if (addr > 0)
523 math.min(@ctz(u64, addr), sect.@"align")524 math.min(@ctz(u64, addr), sect.@"align")
524 else525 else
...@@ -760,15 +761,16 @@ fn parseDataInCode(self: *Object) void {...@@ -760,15 +761,16 @@ fn parseDataInCode(self: *Object) void {
760 );761 );
761}762}
762763
763fn getSectionContents(self: Object, sect_id: u16) []const u8 {764fn getSectionContents(self: Object, sect_id: u16) error{Overflow}![]const u8 {
764 const sect = self.getSection(sect_id);765 const sect = self.getSection(sect_id);
766 const size = math.cast(usize, sect.size) orelse return error.Overflow;
765 log.debug("getting {s},{s} data at 0x{x} - 0x{x}", .{767 log.debug("getting {s},{s} data at 0x{x} - 0x{x}", .{
766 sect.segName(),768 sect.segName(),
767 sect.sectName(),769 sect.sectName(),
768 sect.offset,770 sect.offset,
769 sect.offset + sect.size,771 sect.offset + sect.size,
770 });772 });
771 return self.contents[sect.offset..][0..sect.size];773 return self.contents[sect.offset..][0..size];
772}774}
773775
774pub fn getString(self: Object, off: u32) []const u8 {776pub fn getString(self: Object, off: u32) []const u8 {