| ... | @@ -99,10 +99,11 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) | ... | @@ -99,10 +99,11 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) |
| 99 | }, | 99 | }, |
| 100 | .SYMTAB => { | 100 | .SYMTAB => { |
| 101 | const symtab = cmd.cast(macho.symtab_command).?; | 101 | const symtab = cmd.cast(macho.symtab_command).?; |
| 102 | self.in_symtab = @ptrCast( | 102 | // Sadly, SYMTAB may be at an unaligned offset within the object file. |
| 103 | [*]const macho.nlist_64, | 103 | self.in_symtab = @alignCast(@alignOf(macho.nlist_64), @ptrCast( |
| 104 | @alignCast(@alignOf(macho.nlist_64), &self.contents[symtab.symoff]), | 104 | [*]align(1) const macho.nlist_64, |
| 105 | )[0..symtab.nsyms]; | 105 | self.contents.ptr + symtab.symoff, |
| | 106 | ))[0..symtab.nsyms]; |
| 106 | self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize]; | 107 | self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize]; |
| 107 | try self.symtab.appendSlice(allocator, self.in_symtab); | 108 | try self.symtab.appendSlice(allocator, self.in_symtab); |
| 108 | }, | 109 | }, |
| ... | @@ -302,10 +303,10 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) | ... | @@ -302,10 +303,10 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) |
| 302 | const code: ?[]const u8 = if (!sect.isZerofill()) try self.getSectionContents(sect) else null; | 303 | const code: ?[]const u8 = if (!sect.isZerofill()) try self.getSectionContents(sect) else null; |
| 303 | | 304 | |
| 304 | // Read section's list of relocations | 305 | // Read section's list of relocations |
| 305 | const relocs = @ptrCast( | 306 | const relocs = @alignCast(@alignOf(macho.relocation_info), @ptrCast( |
| 306 | [*]const macho.relocation_info, | 307 | [*]align(1) const macho.relocation_info, |
| 307 | @alignCast(@alignOf(macho.relocation_info), &self.contents[sect.reloff]), | 308 | self.contents.ptr + sect.reloff, |
| 308 | )[0..sect.nreloc]; | 309 | ))[0..sect.nreloc]; |
| 309 | | 310 | |
| 310 | // Symbols within this section only. | 311 | // Symbols within this section only. |
| 311 | const filtered_syms = filterSymbolsByAddress( | 312 | const filtered_syms = filterSymbolsByAddress( |
| ... | @@ -548,10 +549,10 @@ pub fn parseDataInCode(self: Object) ?[]const macho.data_in_code_entry { | ... | @@ -548,10 +549,10 @@ pub fn parseDataInCode(self: Object) ?[]const macho.data_in_code_entry { |
| 548 | .DATA_IN_CODE => { | 549 | .DATA_IN_CODE => { |
| 549 | const dice = cmd.cast(macho.linkedit_data_command).?; | 550 | const dice = cmd.cast(macho.linkedit_data_command).?; |
| 550 | const ndice = @divExact(dice.datasize, @sizeOf(macho.data_in_code_entry)); | 551 | const ndice = @divExact(dice.datasize, @sizeOf(macho.data_in_code_entry)); |
| 551 | return @ptrCast( | 552 | return @alignCast(@alignOf(macho.data_in_code_entry), @ptrCast( |
| 552 | [*]const macho.data_in_code_entry, | 553 | [*]align(1) const macho.data_in_code_entry, |
| 553 | @alignCast(@alignOf(macho.data_in_code_entry), &self.contents[dice.dataoff]), | 554 | self.contents.ptr + dice.dataoff, |
| 554 | )[0..ndice]; | 555 | ))[0..ndice]; |
| 555 | }, | 556 | }, |
| 556 | else => {}, | 557 | else => {}, |
| 557 | } | 558 | } |